Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the default enum value in Protobuf?

Hello What's the default enum value (if there isn't any default value defined) in Google Protocol buffer using with Java?

like image 527
why Avatar asked Mar 20 '11 14:03

why


People also ask

What is enum in protobuf?

enum is one of the composite datatypes of Protobuf. It translates to an enum in the languages that we use, for example, Java.

How do I set default value in protobuf?

For bool s, the default value is false. For numeric types, the default value is zero. For enums , 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.

Do enums have default values?

The default value for an enum is zero. If an enum does not define an item with a value of zero, its default value will be zero.

What is Google protobuf value?

WellKnownTypes. Value. Value represents a dynamically typed value which can be either null, a number, a string, a boolean, a recursive struct value, or a list of values.

How do you declare a nested enum in Protobuf?

Nested enumerations—like nested messages—will be declared within the .Types static class in the generated message class. There's no way to apply the [Flags] attribute to a Protobuf-generated enum, and Protobuf doesn't understand bitwise enum combinations.

What are the requirements for a Protobuf enumeration?

For example, in the following Protobuf enumeration, the fields are prefixed with ACCOUNT_STATUS. This prefix is equivalent to the Pascal-case enum name, AccountStatus. The generator creates a C# enum equivalent to the following code: Protobuf enumeration definitions must have a zero constant as their first field.

What is the default value of an enum or Bool?

For bools, the default value is false. For numeric types, the default value is zero. For enums, the default value is the first value listed in the enum's type definition.

How to declare multiple fields with the same value in Protobuf?

The generator creates a C# enum equivalent to the following code: Protobuf enumeration definitions must have a zero constant as their first field. As in C#, you can declare multiple fields with the same value. But you must explicitly enable this option by using the allow_alias option in the enum:


1 Answers

It is the first one defined in .proto order.

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

Optional Fields And Default Values

(snip) For enums, the default value is the first value listed in the enum's type definition.

like image 69
Marc Gravell Avatar answered Oct 11 '22 02:10

Marc Gravell