Please enable / Bitte aktiviere JavaScript!
Veuillez activer / Por favor activa el Javascript![ ? ]
How to organize a sub-message in protobuf? - Q&A

How to organize a sub-message in protobuf?

0 like 0 dislike
Good day!
I need to read the message type and, depending on its type already to parse, th I would do so
type Message strcut { string typeMessage Body interface {}// Court I can put anything and protobuf would like }

or an example of JSON
var msg { typeMsg: user_info, body: user{ id : 564, name:dwadswa }, }

as a variant I see
message Message { string typeMessage = 1; bytes body = 2; }

but I think it's a bad idea is better. Google did not give results, or I did not understand them.Thank you
asked by | 127 views

2 Answers

0 like 0 dislike
Use google.protobuf.Any, if the type is not known
or use oneof, if the limited number and they are known
answered by
0 like 0 dislike
In protobuf have to do multiple fields, one for each message type. After receiving the ID type, refer to the appropriate field.
answered by
Welcome to Bug-code Q&A, where you can ask questions and receive answers from other members of the community.

24.8k questions

46.2k answers


12.8k users

24,788 questions
46,220 answers
12,813 users