【发布时间】:2012-12-01 17:21:57
【问题描述】:
继承的类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);
}
【问题讨论】:
标签: protobuf-net