We can be pretty smart around this implementation by optimizing for locations where marker values can be used to represent an optional value. The simplest example is an out of bounds number: if the serialized value for zap.optional(zap.u8(1, 50)) is 0 that can mark the value as nil without needing a boolean flag to be sent.
This optimization can and should apply in other less trivial places, such as encoding 0 in an optional array, set, or map length to mean nil, and for all other values subtracting 1 get the actual length.
We can be pretty smart around this implementation by optimizing for locations where marker values can be used to represent an optional value. The simplest example is an out of bounds number: if the serialized value for
zap.optional(zap.u8(1, 50))is0that can mark the value asnilwithout needing a boolean flag to be sent.This optimization can and should apply in other less trivial places, such as encoding
0in an optional array, set, or map length to meannil, and for all other values subtracting1get the actual length.