[英]how do i define python's list with dict in grpc's protobuf?
在.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
定義?
我不認為protobuf python接受[{'a':'1'},{'b':'2'}]。 {'a':'1'}可以是protobuf中的map字段,[]是列表。 我們不支持重復的地圖字段。
如果數據為{'a':'1','b':'2'},則可以定義.proto文件,例如:message HelloReplyList {map map_field = 1; }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.