In this case, if an older version of the protocol that only knows about Field0 sends a packet with Field0 = 1, the packet data will consist of one byte, 0x80. The problem is that the newer protocol version will infer from the one-byte size that it has a valid Field1 value and read it out as zero, overwriting the default of 1.
My suggestion would be to throw a warning for any bitfields with default values. One could argue that the default could be forced to zero, but I think there may be valid usecases for non-zero defaults.
In addition if you have multiple default bitfields in the same byte the size check is unnecessarily repeated.
I just realized that default values for bitfields don't always make sense if adding a new bitfield to the packet doesn't increase the size. Example:
In this case, if an older version of the protocol that only knows about
Field0
sends a packet withField0 = 1
, the packet data will consist of one byte,0x80
. The problem is that the newer protocol version will infer from the one-byte size that it has a validField1
value and read it out as zero, overwriting the default of 1.My suggestion would be to throw a warning for any bitfields with default values. One could argue that the default could be forced to zero, but I think there may be valid usecases for non-zero defaults.
In addition if you have multiple default bitfields in the same byte the size check is unnecessarily repeated.