I am pretty new to protobuf and all of this, but I am trying to take a list of dictionaries and write them to a service using RPC/protobuf. Here is the proto:
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) {}
}
I have the following list of dicts as well (just test data here):
test = [
{"messageId": "23452345324", "isPrivate": False, "handleId": "q35jmefn"},
{"messageId": "wegwer", "isPrivate": False, "handleId": "webwerbtetny"}
]
I'm not sure what to do from here, I've tried something like this:
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)
But I don't think this works, when I print the result of the function, it's just a list of the very last element in the test
list. Any pointers from here would be great