Reputation: 4548
I am using Protobuf-net with DataContracts. I register types this way:
RuntimeTypeModel.Default[typeA].AddSubType(fieldNumber, typeB);
The problem is that fieldNumber
is explicitly restricted inside protobuf-net code to accept integers which are > 0
and < Int32.Max/4
.
internal static void WriteHeaderCore(int fieldNumber, WireType wireType, ProtoWriter writer)
{
uint header = (((uint)fieldNumber) << 3)
| (((uint)wireType) & 7);
WriteUInt32Variant(header, writer);
}
What was the reason doing it this way? Backward compatibility? CrossPlatform compatibility? Possible bug?
UPDATE to show how I use 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; }
}
Upvotes: 2
Views: 112
Reputation: 17749
It is per the protobuf spec
The smallest tag number you can specify is 1, and the largest is 2^29 - 1, or 536,870,911. You also cannot use the numbers 19000 though 19999
Upvotes: 2