protobuf-net, in v1, made a "zero defaults" assumption. Probably not a decision I would make again, if I was starting from scratch, and indeed this behaviour can be disabled in v2. But as it stands, in many cases it assumes zero as an implicit default. I'm guessing that your command
is a non-nullable enum, in which case it will apply this logic (as a side-note: if it was nullable, it would not do this - it would use the null
check for the include/exclude decision).
Because of this, it has decided that the second field (field number 2, encoded as varint) doesn't need to be serialized. Hence no [16, 0]
.
Options:
- use a nullable member (equivalent to
optional
) - i.e.public SomeEnum? Command {get;set;}
- mark the member as required (
IsRequired=true
on theProtoMemberAttribute
) - turn off implicit zero default behaviour (
UseImplicitZeroDefaults
on aRuntimeTypeModel
instance)