I think union types are the best choice for a "small" number of possible
messages. However, if you really need to support *any* type of message,
you could consider adding a "header" message of a known type that
includes the fully-qualified message name as returned by
message->GetDescriptor()->full_name(), or some other unique "message
Union types in combination with 'extensions' seems like the right solution
for this problem in almost all cases, whether the number of message types
is large or small.
Using a separate header message adds lots of complications as you then need
to write additional code to instantiate the 'payload' message type etc... I
was using a header message a while back, and migrated to union types with
great success. Granted, I do still have a fairly small number of message
types, but I am not aware of any issues which would arise from scaling to a
very large set of messages. Are there known issues which arise from a union
type with a large number of extensions?
You received this message because you are subscribed to the Google Groups "Protocol
To post to this group, send email to proto...@googlegroups.com.
To unsubscribe from this group, send email to
For more options, visit this group at