Protobufs field masks are one way.
https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.FieldMask
https://github.com/golang/protobuf/issues/225
But if you use grpc , then there is a (kind of) built-in way.
Grpc Wrappers
Since proto3 (protobufs v3) there was no difference between a primitive that was not installed and a primitive that was set to "zero" (false, 0, "", etc.).
Instead, you can use objects or the protobufs language as a "message", since objects can be nil / null. You did not mention what language you work in, but I hope these examples make sense.
For an RPC service, for example:
import "google/protobuf/wrappers.proto"; service Users { rpc UpdateUser(UpdateUserRequest) returns (UpdateUserResponse) } message UpdateUserRequest { int32 user_id = 1; google.protobuf.StringValue email = 2; } message UpdateUserResponse {}
Note important import "google/protobuf/wrappers.proto"; . This gave you access to google protobufs covers here . These are not objects that have methods that allow you to check for availability.
The java generated Grpc code gives you methods like .hasEmail() , which returns true if this value is present. The receiver at an undefined value will still return you a null value. I think the golang version uses pointers that you can check for nil instead of the hasX() explicit method.
Further info / discussion on this github issue
source share