Should we not set default values in optional protobuf fields to minimize data sent over the wire?
I want to minimize my message byte size sent over the wire. To accomplish this, one optimization which I could think of was:
if( message->my_optional_field() != value )
message->set_my_optional_field(value);
This prevents has_my_optional_field()
to be called when the intended value is equal to the default value and hence, prevent the field to appear in the serialization array. Is this a good practice? Does protobuf provide something like this out of the box?
The question is similar to how do has_field() methods relate to default values in protobuf? In fact, it has been answered in one of the comments to the accepted answer. However, subsequent comments have disputed the claim.