.proto中的
message HelloReplyList { repeated string message = 1; }
以下代码可以正常工作
def SayHelloList(self, request, context):
l = ['a', 'b', 'c']
return helloworld_pb2.HelloReplyList(message=l)
以下代码有效: TypeError:{'a':'1'}的类型为dict,但预期其中之一:字节,Unicode
def SayHelloList(self, request, context):
d = [{'a': '1'}, {'b': '2'}]
return helloworld_pb2.HelloReplyList(message=d)
如果我想使用[{'a':'1'},{'b':'2'}]
。如何在.proto
中定义?
答案 0 :(得分:0)
我不认为protobuf python接受[{'a':'1'},{'b':'2'}]。 {'a':'1'}可以是protobuf中的map字段,[]是列表。我们不支持重复的地图字段。
如果数据为{'a':'1','b':'2'},则可以定义.proto文件,例如: 消息HelloReplyList {map map_field = 1; }