A common issue with Protobufs is that the way that nil values are represented: a zero-valued primitive field isn't encoded into the binary representation, this means that applications cannot distinguish between zero and not-set for primitive fields.
entproto generates a Protobuf message definition, it uses these wrapper types to represent "Optional" ent fields.
Let's see this in action, modifying our ent schema to include an optional field:
go generate ./..., observe that our Protobuf definition for
User now looks like:
The generated service implementation also utilize this field. Observe in
To use the wrapper types in our client code, we can use helper methods supplied by the wrapperspb
package to easily build instances of these types. For example in