SimpleCoder
SimpleCoder

Reputation: 1293

Protobuf fields where a value of 0 is valid

We are using protobufs to model our networking software. There are many instances, like priorities, where 0 is a valid value. But, when we transport, the fields with 0 values are suppressed. Is there a way to change this behavior? That is, differentiate a filed with a valid value of 0, from a field which has not been set, which can be suppressed?

Our client is gRPC-Java and server is gRPC-Python.

Thank you for your time.

Upvotes: 1

Views: 390

Answers (1)

for_stack
for_stack

Reputation: 22886

You can use Protobuf version 2, which can distinguish whether the field has been set. However, gRPC recommend to use Protobuf version 3.

An alternative is to set the field to an invalid value, e.g. -1, if the field is NOT set.

Upvotes: 2

Related Questions