message Person {
required Empid = 1 [default = 100];
required string name = 2 [default = "Raju"];
optional string occupation = 3;
repeated string snippets = 4;
}
Can I give the default values as mentioned above?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With