I know this is an old thread, but I will still be responsible for the offspring:
Firstly, as you know, it is impossible to determine the type of protocol buffer message only from its serialized form. The only information in serialized form that you have access to is field numbers and their serialized values.
Secondly, the βrightβ way to do this should consist of a proto that contains both, for example
message Parent { required int32 FormatVersion = 1; optional bool SomeFlag [default = true] = 2; optional Common CommonSettings = 3; oneof letters_of_alphabet { A a_specific = 4; B b_specific = 5; } }
So there is no ambiguity: you just parse the same proto ( Parent ) every time.
In any case, if it is too late to change this, then what I recommend to you is to define a new message with only common fields, for example
message Shared { required int32 FormatVersion = 1; optional bool SomeFlag [default = true] = 2; optional Common CommonSettings = 3; }
Then you can pretend that the message (either A or B ) is actually Shared , and analyze it accordingly. Unknown fields will be irrelevant.
Robert Martin
source share