Hello!
I read a lot about delimiting messages by VarInt32 number before each
serialized message. It requires some additional coding. In the same time I
guess that parsing code of GPB must understand when it must stop
deserialization. Maybe someone who is close to sources can help me. I
assume two conditions for that:
1) End of stream
2) End of message
3) Other?
Option 1) we do not consider since our stream must receive multiple
messages like socket stream.
Option 2) well can be detected. GPB encode data in order of TAG numbers. So
if we add the last field in message (say)
required bool eom = MAX_POSSIBLE_TAG_NUMBER
a message parser must stop parsing after reading this field since no fields
more expected.
I have several message types and union them into one. It looks like this:
message M1
{
required int32 ri32 = 1;
optional bool b = 2;
}
message M2
{
optional string s = 1;
optional int64 i64 = 2;
}
message ServerMessage
{
enum Type {
M1 = 1;
M2 = 2;
}
optional M1 m1 = 1;
optional M2 m2 = 2;
required eom bool = 1000;
}
So can I do the following:
// On sender
CodedOutputStream os;
ServerMessage m1;
m1.set_type(ServerType::M1);
m1.set_eom(true);
...
m1.SerializeToCodedStream(os);
ServerMessage m2;
m2.set_type(ServerType::M2);
m2.set_eom(true);
...
m2.SerializeToCodedStream(os);
// On receiver
CodedInputStream os;
ServerMessage m1;
m1.ParseFromCodedStream(os);
ServerMessage m2;
m2.ParseFromCodedStream(os);
Opinions?
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/protobuf?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.