I have a scenario where I'm trying to create a Serializer and
Deserializer class that can handle any general Message, given a stream
(InputStream or OutputStream) and an instance of a particular Message
implementation.

How can I use this information to serialize and deserialize?  I will
break things down slightly more:

Serializing:
This seems easy.  Given a stream and an instance, just call
Message#writeTo(output) on the instance.

Deserializing:
More tricky.  Given a stream and an instance, I'm trying to get the
Descriptor by calling Message#getDescriptorForType() on the instance
and passing the return value, along with an input stream, to
DynamicMessage#parseFrom(Descriptor,input).  I then cast the
DynamicMessage that is returned by parseFrom to the same type of the
instance that is given to me.

The problem that I'm encountering is during deserialization.  I'm
getting an InvalidProtocolBufferException.  Here's the trace:

com.google.protobuf.InvalidProtocolBufferException: Protocol message
contained an invalid tag (zero).
        at
com.google.protobuf.InvalidProtocolBufferException.invalidTag(InvalidProtocolBufferException.java:
52)
        at
com.google.protobuf.CodedInputStream.readTag(CodedInputStream.java:67)
        at com.google.protobuf.FieldSet.mergeFrom(FieldSet.java:397)
        at com.google.protobuf.DynamicMessage
$Builder.mergeFrom(DynamicMessage.java:289)
        at com.google.protobuf.DynamicMessage
$Builder.mergeFrom(DynamicMessage.java:213)
        at com.google.protobuf.AbstractMessage
$Builder.mergeFrom(AbstractMessage.java:240)
        at com.google.protobuf.AbstractMessage
$Builder.mergeFrom(AbstractMessage.java:329)
        at
com.google.protobuf.DynamicMessage.parseFrom(DynamicMessage.java:102)

What's curious about this is that my .proto files each only have one
field in each Message, and each of those fields has a tag of 1.  None
of my tags are 0.

I have a feeling that I'm probably misusing the API for
deserialization, or perhaps I may have mis-defined my .proto files.
Here's an example of a .proto file that I'm using:

message LongMessage {
  required int64 value = 1;
}

Any and all help is greatly appreciated.  Thanks ahead of time for
your help :).

Alex

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