英文:
Is it mandatory to capitalize the enum variables in .proto files?
问题
我想创建一个以下格式的枚举,但我的proto扩展会报错,是否必须将枚举值大写并只使用下划线?
enum Language {
en = 0;
en_uk =1;
en_gb =2;
en_au =3;
en_us =4;
fil_en =5;
en_in =6;
fr =7;
}
英文:
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;
}
答案1
得分: 2
根据proto3语言规范,标识符(包括枚举)必须以字母开头,然后只能包含字母、十进制数字和下划线。
ident = letter { letter | decimalDigit | "_" }
以下是Google的开发者风格指南对于枚举的建议。虽然风格指南在技术上并非强制性的,但在大多数情况下,除非有充分的理由违反命名约定,否则应该遵守它们。
对于枚举类型名称使用驼峰命名法(首字母大写),对于值名称使用大写字母和下划线:
enum FooBar { FOO_BAR_UNSPECIFIED = 0; FOO_BAR_FIRST_VALUE = 1; FOO_BAR_SECOND_VALUE = 2; }
英文:
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:
> protobuf
> enum FooBar {
> FOO_BAR_UNSPECIFIED = 0;
> FOO_BAR_FIRST_VALUE = 1;
> FOO_BAR_SECOND_VALUE = 2;
> }
>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论