Hi,
this might be quite the newbie question, but I haven't been able to find any hints through googling, so here it goes:
What I'm trying to to is send orotobuf messages between an Android App a Python Script containing (among other things) a list of key-value pairs (if ints).
The solution that I came up with was just defining my own “tuple” as another protobuf message and then including a repated field of said type, like so:
message CheckMessage {
message BalanceUpdateMessage{
required int32 transactionID = 1;
required sint32 amount = 2;
}
required int32 amount = 3;
required sint32 newBalance = 5;
repeated BalanceUpdateMessage balanceUpdates = 4;
}
and then try to fill the balaceUpdates in Python (the checkMessages are embedded in another packetMessage):
balanceUpdateMessage = protoPackets_pb2.CheckMessage.BalanceUpdateMessage()
balanceUpdateMessage.transactionID = 1111
balanceUpdateMessage.amount = 2222
packetMessage.checkMessage.balanceUpdates.append(balanceUpdateMessage)
But when I run this, I get the error:
AttributeError: 'RepeatedCompositeFieldContainer' object has no attribute 'append'
... I kind of expected my approach to fail, but not with an error message like this :D
So my question is: Is it even possible to send multiple key,value - pairs with protobuf and if yes, how? Or if I'm on the right track: what is my mistake?
( I know that one usually would set the contents of a “nested” message with packetMessage.checkMessage.balanceUpdateMessage.transactionID = 333 (or so), but since I'm dealing with a repeated field that neither works nor would it make sense (to me, at least). )