سؤال

I have these .NET serialized objects stored in couchbase that I'm trying to read using a Java program. The objects were serialized using protobuf-net, and changing that code is not possible. I've attached the code snippet below that shows the annotated class that gets serialized.

[ProtoContract]
[VersionType(Version = VersionNumbers.V3)]
public class A : B
{
    [ProtoMember(1)]
    public UInt16 field1 { get; set; }

    [ProtoMember(2)]
    public UInt16 field2 { get; set; }

    [ProtoMember(3)]
    public UInt16 field3 { get; set; }

    [ProtoMember(4, IsPacked = true)]
    public List<UInt32> field4 { get; set; }

    [ProtoMember(5, IsPacked = true)]
    public byte[] field5 { get; set; }

    [ProtoMember(6, IsPacked = true)]
    public List<UInt16> field6 { get; set; }
}

I followed some of the other posts here and tried to create a .proto file that looks like this -

message A {
optional uint32 field1 = 1;
optional uint32 field2 = 2;
optional uint32 field3 = 3;
repeated uint64 field4 = 4 [packed=true];
optional bytes field5 = 5;
repeated uint32 field6 = 6 [packed=true];
}

However, when I try to de-serialize it, I get an error saying "Protocol message contained an invalid tag (zero)". I think there's something wrong with the way I've defined my .proto file, but I can't figure out what the problem is. Am I making a mistake here?

Thanks! Vivek

هل كانت مفيدة؟

المحلول

Your best bet is to use Serializer.GetProto<A>() to see what protobuf-net thinks the matching .proto looks like. If I assume nothing about B, I get:

message A {
   optional uint32 field1 = 1 [default = 0];
   optional uint32 field2 = 2 [default = 0];
   optional uint32 field3 = 3 [default = 0];
   repeated uint32 field4 = 4 [packed=true];
   optional bytes field5 = 5;
   repeated uint32 field6 = 6 [packed=true];
}

The main difference seems to be the uint64 vs uint32.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top