Hi Ilia,

Am Montag, 24. Juni 2013 20:26:47 UTC+2 schrieb Ilia Mirkin:
>
> Try 
>
> x = packetMessage.checkMessage.balanceUpdates.add() 
> x.tid = 111 
> x.amount = 222 
>

works like a charm, thank you so much!
 

>
> See https://developers.google.com/protocol-buffers/docs/pythontutorial 
> for more info. 
>
> On Sun, Jun 23, 2013 at 9:49 AM, Lotte R. Leben 
> <lo...@zombietetris.de<javascript:>> 
> wrote: 
> > 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). ) 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups 
> > "Protocol Buffers" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an 
> > email to protobuf+u...@googlegroups.com <javascript:>. 
> > To post to this group, send email to prot...@googlegroups.com<javascript:>. 
>
> > Visit this group at http://groups.google.com/group/protobuf. 
> > For more options, visit https://groups.google.com/groups/opt_out. 
> > 
> > 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to