继承的类 C2 流序列化后如下所示:
0x5a 0x03
0x08 0x97 0x01
0x08 0x96 0x01
我不明白那是第一组字节(5a 03)?我相信它必须是第二和第三只代表 Z1 和 Z2 值?
我的代码:
[ProtoContract]
class C1
{
[ProtoMember(1, DataFormat = DataFormat.Default)]
public int Z1 { get; set; }
}
[ProtoContract]
class C2 : C1
{
[ProtoMember(1, DataFormat = DataFormat.Default)]
public int Z2 { get; set; }
}
public static void Main()
{
MemoryStream stream = new MemoryStream();
ProtoBuf.Meta.RuntimeTypeModel.Default.Add(typeof(C1), true).AddSubType(11, typeof(C2));
C2 c2 = new C2() {Z1 = 150, Z2 = 151};
Serializer.Serialize(stream, c2);
}