Answer the question
In order to leave comments, you need to log in
How to organize nested messages in protobuf?
Good afternoon!
I need to read the message type and, depending on its type, already parse, in which I would do this
type Message strcut {
typeMessage string
Body interface {}// Суда я могу положить что угодно , так и в protobuf хотелось бы
}
var msg {
typeMsg: user_info,
body: user{
id : 564,
name:dwadswa
},
}
message Message {
string typeMessage = 1;
bytes body = 2;
}
Answer the question
In order to leave comments, you need to log in
Use google.protobuf.Any if the type is not known
or use oneof if there are a limited number of types and they are known
In the protobuffer, you will have to make several fields, one for each type of message. After receiving the type ID, access the required field.
I would suggest using google.protobuf.Struct - it's just a prototype representation of a JSON object. Any proto3 message can be mechanically converted to JSON and embedded in a field of this type. It is a very flexible type and gives the benefits of dynamic typing for protobuf.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question