What is the default enumeration value in Protobuf?

Hi What is the default enum value (if no default value is specified in the Google protocol buffer) using Java?

+7
source share
2 answers

This is the first one defined in .proto order.

From the .proto language manual (since all implementations use the same logic here):

Additional fields and default values

(snip) For enumerations, the default value is the first value specified in the enumeration type definition.

+8
source

of official specification :

optional: the field may or may not be set. If the optional field value is not set, the default value is used. For simple types, you can specify your own default values, as was done for the phone number in this example. Otherwise, the default system is used: zero for numeric types, an empty string for strings, false for bools. For inline messages, the default value is always the "default instance" or "prototype" of the message, which does not have any of its fields. calling an accessory to get the value of an optional (or mandatory) field that has not been explicitly set always returns that default value for the field.

You can set the default value as follows:

optional PhoneType type = 2 [default = HOME]; 
+3
source

All Articles