On Tue, Aug 18, 2009 at 6:55 PM, Oliver Jowett <oliver.jow...@gmail.com>wrote:

>
> Hi
>
> Using 2.2.0, the compiler doesn't seem to be generating Java code for
> the parseFrom(byte[],int,int) and
> parseFrom(byte[],int,int,ExtensionRegistryLite) static methods.


Did it ever generate those methods?  I don't remember if it did, but I
definitely don't remember removing them.


> Is this deliberate, or just an oversight?


An oversight.  Although the proliferation of generated parse helpers worries
me.


> Also, it seems a bit awkward for a user of the generated code to
> reimplement something equivalent to the parseFrom() variants. For
> example, to parse a message from a flat array using a Message.Builder
> determined at runtime, with the same semantics as parseFrom(), I have to
> do something like this:
>
>  try {
>    message = builder.mergeFrom(array, offset, length).build();
>  } catch (UninitializedMessageException e) {
>    throw e.asInvalidProtocolBufferException();
>  }
>
> The try-to-build-and-catch-and-rethrow is a bit horrible. Is there a
> better way to do this?


I suppose we could introduce a (public) variant of build() for this.

Arguably your code should look like:

  message = builder.mergeFrom(array, offset, length).buildPartial();
  if (!message.isInitialized()) {
    throw new InvalidProtocolBufferException(...);
  }

It's a little bit nicer than the try/catch...

--~--~---------~--~----~------------~-------~--~----~
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