How to organize a sub-message in protobuf?

0 like 0 dislike
97 views
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 | 97 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

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
24,509 questions
45,932 answers
0 comments
352 users