flyte wrote:
Now, if I pass in a byte[] of a protocol buffer that is of a type that
I do not expect, the parseFrom() still returns correctly, (I would
have though the IOException would have been thrown or something), and
some of the fields get merged (the fields with the same IDs?)

Due to the way the protocol buffer wire format is defined, this is how it works. Fields with the same ids will be treated as the same, and unknown fields will be parsed as well. This is part of what permits them to be "extensible", and work with different software versions.

I am confused on how to detect this scenario, and ultimately prevent
such things occurring.

You will need to redesign your application so you don't try to parse MessageA as a MessageB. For example, union types may solve your problem if you have some set of acceptable types that your application must handle:

Alternatively, you may wish to add a "header" describing the type, before the type itself.

Hope this helps,


Evan Jones

You received this message because you are subscribed to the Google Groups "Protocol 
Buffers" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

Reply via email to