You should send the type of the message along with the actual message data
and use it to tell what type is the message in the receiving side.
Or you can define and send such a message:
message FooOrBarOrLogon {
  optional Foo foo_value = 1;
  optional Bar bar_value = 2;
  optional Logon logon_value = 3;
}

On Tue, Sep 17, 2013 at 11:08 PM, Sverre Moe <sverre....@gmail.com> wrote:

> Having multiple proto files with multiple messages within each.
>
> Standing with a String read from a Socket. My processor class gets a
> String from a socket connection.
> This String I need to convert to a Message and forward it to a listener.
>
> I need to create a message withouth knowing which message I have.
>
> Must be a better way than this?
> [CODE]
> String text;
> byte[] data = text.getBytes();
>
> Message message = null;
> try {
>    message = Systems.Foo.parseFrom(data);
> } catch (InvalidProtocolBufferException e) {
>
> }
>
> try {
>     message = Systems.Bar.parseFrom(data);
> } catch (InvalidProtocolBufferException e) {
>
> }
>
> try {
>     message = Users.Logon.parseFrom(data);
> } catch (InvalidProtocolBufferException e) {
>
> }
>
> return message;
> [/CODE]
>
> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to protobuf+unsubscr...@googlegroups.com.
> To post to this group, send email to protobuf@googlegroups.com.
> Visit this group at http://groups.google.com/group/protobuf.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to