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

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

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

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.FieldSet.mergeFrom(FieldSet.java:397)
        at com.google.protobuf.DynamicMessage
        at com.google.protobuf.DynamicMessage
        at com.google.protobuf.AbstractMessage
        at com.google.protobuf.AbstractMessage

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 :).


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 

Reply via email to