Protocol Buffer optional integer, distinct from zero -


in protocol buffer version 3, i'm trying figure out best way have optional integer value, 0 , absent should distinct cases. best can figure making type:

message int64option {     oneof option {         bool empty = 14;         int64 value = 15;     } } 

is idea, or there better way?

there 2 main options in proto3. first use oneof suggested, need have 1 item in oneof:

oneof option {   int64 value = 15; } 

oneof fields have notion of presence can still determine whether value absent or zero. other alternative use 1 of wrapper types in google/protobuf/wrappers.proto. each of these wrappers takes primitive type , wraps in message, , helps in situation because submessage fields have presence. here int64 wrapper looks example:

// wrapper message `int64`. // // json representation `int64value` json string. message int64value {   // int64 value.   int64 value = 1; } 

finally, 1 other thing consider can keep using proto2. both proto2 , proto3 styles supported in protobuf versions 3.0 , , plan continue supporting proto2 indefinitely.


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -