Message from discussion
Receiving multiple message types
Received: by 10.224.207.137 with SMTP id fy9mr5969537qab.6.1332188055615;
Mon, 19 Mar 2012 13:14:15 -0700 (PDT)
X-BeenThere: protobuf@googlegroups.com
Received: by 10.229.246.18 with SMTP id lw18ls6083574qcb.5.gmail; Mon, 19 Mar
2012 13:14:12 -0700 (PDT)
Received: by 10.224.203.133 with SMTP id fi5mr5995955qab.8.1332188052123;
Mon, 19 Mar 2012 13:14:12 -0700 (PDT)
Received: by 10.224.180.136 with SMTP id bu8msqab;
Mon, 19 Mar 2012 12:46:17 -0700 (PDT)
Received: by 10.52.38.231 with SMTP id j7mr1114319vdk.5.1332186377749;
Mon, 19 Mar 2012 12:46:17 -0700 (PDT)
Date: Mon, 19 Mar 2012 12:46:16 -0700 (PDT)
From: Jim Morris <wolfma...@gmail.com>
To: protobuf@googlegroups.com
Message-ID: <16384733.3636.1332186376922.JavaMail.geo-discussion-forums@pbcr5>
In-Reply-To: <da806534-cc56-49bb-8950-1450fc11f006@do4g2000vbb.googlegroups.com>
References: <da806534-cc56-49bb-8950-1450fc11f006@do4g2000vbb.googlegroups.com>
Subject: Re: Receiving multiple message types
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_3634_29960742.1332186376921"
------=_Part_3634_29960742.1332186376921
Content-Type: multipart/alternative;
boundary="----=_Part_3635_32395466.1332186376921"
------=_Part_3635_32395466.1332186376921
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
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.
http://blog.wolfman.com/articles/2011/11/23/how-to-implement-polymorphic-protocol-buffers-in-java
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;
> CREATE_CUSTOMER = 1;
> }
> 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
------=_Part_3635_32395466.1332186376921
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 7bit
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.<br><br>http://blog.wolfman.com/articles/2011/11/23/how-to-implement-polymorphic-protocol-buffers-in-java<br><br>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.<br><br>On Sunday, March 18, 2012 3:41:34 PM UTC-7, Jens Rantil wrote:<blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">Hi,
<br>
<br>I'm a newcomer to protobuf and am trying to wrap my head around some
<br>things. Let's say I have a message receiver of some kind. It can
<br>receive different types requests. All messages are encoded in protobuf
<br>and my receiver has all *.proto message definitions necessary be able
<br>to decode all incoming requests.
<br>
<br>My question is, does protobuf come with any bells and whistles that
<br>let me decode a random incoming message, given all possible message
<br>definitions? If not, how do you generally cope with this situation?
<br>Because I feel it's a common one.
<br>
<br>I guess one possible solution is to create another message definition:
<br>message GenericMessage {
<br> enum MessageType {
<br> SET_NAME = 0;
<br> CREATE_CUSTOMER = 1;
<br> }
<br> required MessageType type = 0;
<br> required bytes protobuf_data = 1;
<br>}
<br>
<br>However, this would require me to do two deserializations. Is this the
<br>prefered way to go? I'm curious to hear you input. Please pinpoint me
<br>if this has been answered previously in forum or in the documentation.
<br>
<br>Regards,
<br>Jens</blockquote>
------=_Part_3635_32395466.1332186376921--
------=_Part_3634_29960742.1332186376921--