在.proto文件中,枚举变量是否必须大写?

huangapple go评论89阅读模式
英文:

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;
> }
>

huangapple
  • 本文由 发表于 2022年12月23日 13:02:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/74896282.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定