我正在使用带有DataContracts的Protobuf-net。我这样注册类型:
RuntimeTypeModel.Default[typeA].AddSubType(fieldNumber, typeB);
问题是fieldNumber
在protobuf-net代码中被明确限制为接受> 0
和< Int32.Max/4
的整数。
internal static void WriteHeaderCore(int fieldNumber, WireType wireType, ProtoWriter writer)
{
uint header = (((uint)fieldNumber) << 3)
| (((uint)wireType) & 7);
WriteUInt32Variant(header, writer);
}
这样做的原因是什么?向后兼容性? CrossPlatform兼容性?可能的错误?
更新以显示我如何使用DataContracts
// this guid is transformed to integer and it is a special one so brotobuf-net does not blow up.
// That way I can safely rename the class whenever I want. Same for properies.
[DataContract(Name = "c8978654-4380-44d2-8ebe-ae17a463dfb6")]
public class UserState
{
UserState() { }
[DataMember(Order = 1)]
public override UserId Id { get; set; }
[DataMember(Order = 2)]
public string Firstname { get; private set; }
}