There are several ways to do it, on eis called unions and the other is to 
use extensions. My blog entry here covers the latter and has links to the 
union method.

You are on the right track though you just put all the messages as optional 
in the one message with the header, so you only need to decode once.

On Sunday, March 18, 2012 3:41:34 PM UTC-7, Jens Rantil wrote:
> Hi, 
> I'm a newcomer to protobuf and am trying to wrap my head around some 
> things. Let's say I have a message receiver of some kind. It can 
> receive different types requests. All messages are encoded in protobuf 
> and my receiver has all *.proto message definitions necessary be able 
> to decode all incoming requests. 
> My question is, does protobuf come with any bells and whistles that 
> let me decode a random incoming message, given all possible message 
> definitions? If not, how do you generally cope with this situation? 
> Because I feel it's a common one. 
> I guess one possible solution is to create another message definition: 
> message GenericMessage { 
>   enum MessageType { 
>     SET_NAME = 0; 
>   } 
>   required MessageType type = 0; 
>   required bytes protobuf_data = 1; 
> } 
> However, this would require me to do two deserializations. Is this the 
> prefered way to go? I'm curious to hear you input. Please pinpoint me 
> if this has been answered previously in forum or in the documentation. 
> Regards, 
> Jens

You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To view this discussion on the web visit
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