
Microservices Communication in .NET Using gRPC
By :

Natively, there are no nullable data types in Protobuf. Any primitive non-message data type, such as string
or int32
, has a default value. The default value will be used if the field hasn't been deliberately set to anything. Therefore, if a field of a particular data type in Protobuf returns its default value, it's not easy to determine whether this value was set deliberately or whether the field hasn't been set to anything at all.
The proto2
version of Protobuf dealt with this option by having the optional
keyword. However, this keyword was removed from the proto3
syntax.
Another way of determining whether or not a particular field has been deliberately set is by using a oneof
block. For example, such a block may have two fields, one carrying the value we are interested in and one telling us whether this value has been set. If the second field is set, then we know that the original field hasn't been set.
But this solution...