【发布时间】:2021-09-21 18:34:15
【问题描述】:
我对 protobuf 和所有这一切都很陌生,但我正在尝试获取字典列表并使用 RPC/protobuf 将它们写入服务。这是原型:
syntax = "proto3";
package twittercontent.v1;
message TwitterContentRequest {
string messageId = 1;
bool isPrivate = 2;
string handleId = 3;
}
message TwitterContentResponse {
string response = 1;
}
service TwitterContentService {
rpc TwitterContent(TwitterContentRequest) returns (TwitterContentResponse) {}
}
我也有以下 dicts 列表(这里只是测试数据):
test = [
{"messageId": "23452345324", "isPrivate": False, "handleId": "q35jmefn"},
{"messageId": "wegwer", "isPrivate": False, "handleId": "webwerbtetny"}
]
我不知道从这里开始做什么,我尝试过这样的事情:
from twittercontentservice import twittercontent_pb2
def sendMsg(test):
result = []
for i in test:
unit = twittercontent_pb2.TwitterContentRequest()
unit.messageId = i['messageId']
unit.isPrivate = i['isPrivate']
unit.handleId = i['handleId']
result.append(unit)
return result
sendMsg(test)
但我认为这不起作用,当我打印函数的结果时,它只是test 列表中最后一个元素的列表。任何来自这里的指针都会很棒
【问题讨论】:
标签: python protocol-buffers proto