You can create a message like this:

message Container {
  // One of the following will be filled in.
  optional Ping ping = 1;
  optional StatusUpdate status_update = 2;
  optional FindWorker find_worker = 3;
}

Now send Containers over the wire instead of instances of the individual
message types.

On Tue, Oct 14, 2008 at 11:37 AM, <[EMAIL PROTECTED]> wrote:

>
> Hi,
>
> I was wondering if it was possible to extract the contents of a
> serialized string without knowing ahead of time what kind of message
> it is?
>
> For example: I'm using tcp to send data back and fourth.  On one side
> I create a message and serialize the data, and on the receiving side I
> 'ParseFromString' and check the information.  However, I have
> different types of messages being sent so the receiving side has no
> idea what it is actually getting.
>
> example .proto file [messages actually contain field, taken out for
> simplicity] which creates 'dtm_pb2' after compiling
>
> package dtm;
> message ping {
> }
> message statusUpdate {
> }
> message findWorker {
> }
>
> so in my code on the receiving end I have:
> msg = dtm_pb2()
> msg.ParseFromString(message)
>
> this gives an error.
>
> Is there any way to initialize the msg variable and extract the
> information??
> If I knew what kind of message it was I could always use:
> msg = dtm_pb2.statusUpdate()
> msg.ParseFromString(message)
> and this would work fine, but this is no a viable solution for me.
>
> thanks,
>
> Nima
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to protobuf@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to