pbc icon indicating copy to clipboard operation
pbc copied to clipboard

关于解析repeated的message问题请教!

Open chenshuojia opened this issue 9 years ago • 4 comments

对于repeated的嵌套字段,例如

message REquips{ repeated REquip equips = 1 ;
}

message REquip{ required uint64 id = 1; required string name =2 ; required uint32 generalsId=3; required uint32 star = 4; repeated MAttributeEffect mAttributeEffect = 5; repeated MAttributeEffect ownerEffect = 6; required REquipSys equipSys = 7; }

对于服务器发送过来的equips进行解析,能正确解析出数据但并不是按照服务器发送array的顺序,即equips里面的各个equip的顺序是混乱的。 想请教下云大侠是无法按照顺序解析的吗?

chenshuojia avatar Aug 27 '16 09:08 chenshuojia

protobuf的官方文档的白皮书里特别指明了。repeated是不保证顺序的。https://developers.google.com/protocol-buffers/docs/encoding#optional

owent avatar Mar 07 '17 10:03 owent

protobuf的官方文档的白皮书里特别指明了。repeated是不保证顺序的。https://developers.google.com/protocol-buffers/docs/encoding#optional 白皮书的意思是,repeated字段内各个元素的顺序是保证的,但是这个字段与其他字段之间的顺序不能保证。我的理解是这样的~

kuanzi avatar Jul 23 '19 02:07 kuanzi

@kuanzi 以前写的是repeated字段不保证顺序,但是parse的时候会收到的顺序来push_back,但是有些实现可能会调整这个repeated的顺序也是不违背protobuf规范的。

owent avatar Jul 23 '19 08:07 owent

protobuf的官方文档的白皮书里特别指明了。repeated是不保证顺序的。https://developers.google.com/protocol-buffers/docs/encoding#optional 白皮书的意思是,repeated字段内各个元素的顺序是保证的,但是这个字段与其他字段之间的顺序不能保证。我的理解是这样的~

我也是这样理解的

selfboot avatar Dec 20 '19 08:12 selfboot