how to give default values in protocol buffer?
For proto3
, custom default values are disallowed.
Update: The below answer is for proto2 only, proto3 doesn't allow custom default values.
Yes, you can give default values as you had written. default
is optional for required
, but for optional
you have to mention the default
values else type specific value is automatically assigned. Moreover you forgot to mention the type for Empid
.
protobuf language guide states that
If the default value is not specified for an
optional
element, a type-specific default value is used instead: forstrings
, the default value is the empty string. Forbool
s, the default value is false. For numeric types, the default value is zero. Forenums
, the default value is the first value listed in the enum's type definition. This means care must be taken when adding a value to the beginning of an enum value list.