C# 将变量添加到序列化缓冲区,而不使用protobuf.net将其序列化
所以我有一个我想要序列化的类,除了一个特定的值“key”,它 将用于标识要反序列化它的类 现在我明白了,这可以手动完成,但我创建了一个处理序列化/反序列化的类,我希望使它尽可能通用 示例代码C# 将变量添加到序列化缓冲区,而不使用protobuf.net将其序列化,c#,protobuf-net,C#,Protobuf Net,所以我有一个我想要序列化的类,除了一个特定的值“key”,它 将用于标识要反序列化它的类 现在我明白了,这可以手动完成,但我创建了一个处理序列化/反序列化的类,我希望使它尽可能通用 示例代码 [ProtoContract] public class GeneralPacket { public uint Identity; [ProtoMember(1, IsRequired = true)] public uint Arg1; [ProtoMember(2, IsRe
[ProtoContract]
public class GeneralPacket
{
public uint Identity;
[ProtoMember(1, IsRequired = true)]
public uint Arg1;
[ProtoMember(2, IsRequired = true)]
public uint Arg2;
[ProtoMember(3, IsRequired = true)]
public uint Arg3;
}
我希望在流中包含标识,但不序列化。听起来您需要一个“鉴别器”。Protobuf net目前没有任何代码支持这一点,特别是在反序列化方面(简单地编写额外的值是相当容易的:难的部分是在读取时使用它)。protobuf net支持的是:
- 具有共同祖先和键控子类型的各种继承场景
- 通过SerializeWithLengthPrefix手动使用,允许在序列化时指定数字键,并在反序列化时提供类型解析程序(从键到类型)