Yep, that's the best thing to do right now.

We're thinking of introducing a separate "Parser" interface, which would
allow you to do:

  message = prototype.getParserForType().parse(data);

On Tue, Jan 18, 2011 at 7:34 AM, koert <koertkuip...@gmail.com> wrote:

> A very common situation for me is when i get handed a Message
> prototype plus a byte[] data, and then i am supposed to create the
> Message object from it.
>
> Since my prototype is just a Message i cannot use parseFrom(), and i
> have to resort to:
> try {
>    message = prototype.newBuilderForType().mergeFrom(data).build();
> } catch (InvalidProtocolBufferException e2) {
>    // do something
> } catch (UninitializedMessageException e3) {
>    // do something
> }
>
> Is this the right way to go about?
> Documents seem to suggest to first do builder =
> newBuilderForType().mergeFrom(), then check if it builder is
> initialized, and then do build(). However this is more verbose and i
> do not see the benefit.
>
> Best Koert
>
> --
> 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
> protobuf+unsubscr...@googlegroups.com<protobuf%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/protobuf?hl=en.
>
>

-- 
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 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.

Reply via email to