Home > Software engineering >  Is it mandatory to capitalize the enum variables in .proto files?
Is it mandatory to capitalize the enum variables in .proto files?

Time:12-27

I want to create a enum of the following format but my proto extension throws an error, is it mandatory to capitalise enums and use only underscores ?

enum Language {
    en = 0;
    en-uk =1;
    en-gb =2;
    en-au =3;
    en-us =4;
    fil-en =5;
    en-in =6;
    fr =7;

}

CodePudding user response:

According to the proto3 language specification, identifiers (including enums) must begin with a letter and then can contain only letters, decimal digits and underscores.

ident = letter { letter | decimalDigit | "_" }


Here's what Google's developer style guide recommends for enums. While the style guide is technically not mandatory, you should take care to conform to naming conventions in most situations, unless you have a compelling reason to depart from them.

Use CamelCase (with an initial capital) for enum type names and CAPITALS_WITH_UNDERSCORES for value names:

enum FooBar {
  FOO_BAR_UNSPECIFIED = 0;
  FOO_BAR_FIRST_VALUE = 1;
  FOO_BAR_SECOND_VALUE = 2;
}
  • Related