Maybe I did miss some key point in the documentation, but I am struggling to find some easy, pythonic way to read repeated gRPC fields.
Let's suppose we have some protodef:
message Bar
{
repeated float vals = 1;
}
message Foo
{
repeated Bar bars = 1;
}
service FooService
{
rpc GetFoo(Foo) returns (Foo) {}
}
What would be an easy, pythonic way to read Foo and Foo's Bar values in GetFoo (servicer side)?
Goal is to read the encapsulated repeated floats into separated lists or NumPy arrays.
I tried to access by index or loop through iterator-style, like:
...
def GetFoo(self, request, context):
bar1 = request.bars[0]
...
Unfortunately, this raises exceptions that the message object ...has no len() and simply iterating over the points:
...
def GetFoo(self, request, context):
point_lists = list()
for bar in request.bars:
points = [v for v in bar]
point_lists.append(points)
...
...raises an exception Bar object is not iterable so that I cannot loop through the single points (though I do not get atm why it says that Bar is not iterable when Foo is also a repeated type and is iterable).