On Mon, Sep 8, 2008 at 6:27 PM, Kenton Varda <[EMAIL PROTECTED]> wrote:

>
>
> On Mon, Sep 8, 2008 at 6:18 PM, Alex Loddengaard <
> [EMAIL PROTECTED]> wrote:
>
>> On Tue, Sep 9, 2008 at 1:16 AM, Kenton Varda <[EMAIL PROTECTED]> wrote:
>>
>>> That won't work.  DynamicMessage is a different class; it does not know
>>> how to instantiate the protocol-compiler-generated version of the class.
>>>  Instead, you should do:
>>>
>>>   Message result =
>>>     messageInstance.newBuilderForType().mergeFrom(input).build();
>>>
>>> Actually, you should check isInitialized() before calling build(), or use
>>> buildPartial() instead, but that's a separate issue.
>>>
>>
>> I changed my deserializing code to use the above, but I'm getting the same
>> exception.  I also tried to call isInitialized() on the instance given to
>> me, and the instance is not initialized.
>>
>
> That message instance is probably a default instance.  isInitialized() will
> always be false on those, unless it has no required fields at all.
>

To clarify:  In my original message I was saying that you should call
isInitialized() on the builder returned by mergeFrom(), to make sure the
parsed message is complete, before you call build().


>
>>
>>
>>>  The protocol compiler would not allow you to use tag zero anyway.  It
>>> looks like your input data is not identical to the data written by the
>>> sender.
>>>
>>
>> I'm confident that the sender data is the same data that is created when I
>> serialize.
>>
>
> The exceptions that you're reporting strongly suggest that you are *not*
> seeing the same data on both ends.  Try this:  serialize to a byte array or
> ByteString, compute a checksum of some sort for debugging, then write the
> bytes to your output.  On the other end, read the bytes back into a
> ByteString or byte array, checksum again, and see if it's the same.  Then
> parse from that.  I'm pretty confident that if the checksums are the same,
> you will not see the error you're seeing.
>
>
>>   Perhaps I'm serializing incorrectly?  I'm creating a CodedOutputStream
>> given an OutputStream and passing that to writeTo.
>>
>
> This is redundant -- you can just pass the OutputStream to writeTo().
>
>
>>   However, I'm not using a CodedInputStream to deserialize.  Should I be
>> using Coded or non-Coded streams?
>>
>
> It doesn't matter.  If given a normal stream, mergeFrom() / writeTo() will
> wrap it in a coded stream on their own.
>
>

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