On Sun, Feb 19, 2017 at 5:26 PM pbaranov <bender44e...@gmail.com> wrote:

> It's probably something trivial but I can't figure it out :( I have 2
> messages that have similar structure and when I try to encode message #1
> and decode it as message #2 it works just fine. Why??? If that's how it is
> supposed to work how to distinguish between them? Please advise.

You're not missing anything; the standard wire format for protocol buffers
does not include the names of anything, only the fields and types.  Your
communication protocol will need some higher level coordination to handle
what types of message should be sent.

One possible way of encoding this sort of information into a protocol
buffer is to use a container message, such as

message OuterMessage {
  oneof messages {
     Msg1 msg1 = 1;
     Msg2 msg2 = 2;

Where each possible message is specified in the oneof group. Then in your
C++ code handling the received outer message, you can switch on the result
of messages_case() to know which inner message was actually sent.

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 protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to