Do enum variables in .proto files have to be uppercase?

WBOY
Release: 2024-02-09 12:20:23
forward
974 people have browsed it

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

In .proto files, whether enumeration variables must be capitalized is a common question. According to the official documentation of Google Protocol Buffers, there is no clear requirement that the naming of enumeration variables must be capitalized. However, it is customary to use uppercase for enumeration variables to increase readability and code consistency. Additionally, if you generate code in another language, such as Java or C, it is common to convert enum variables to uppercase. In general, although there is no strict rule on whether enumeration variables in .proto files must be uppercase, it is recommended to use uppercase to comply with common programming norms and habits.

Question content

I want to create an enum in the following format, but my prototype extension throws an error, do I force the enum to be uppercase and only use 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;

}
Copy after login

Solution

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

ident = letter {letter | decimal places | “_”}

The following are the enumerations recommended by the Google Developer Style Guide. While style guides are not technically mandatory, in most cases you should take care to adhere to naming conventions unless you have a compelling reason to deviate from them.

Use camelcase (first letter capitalized) for enumeration type names, and use capitals_with_underscores for value names:

enum FooBar {
  FOO_BAR_UNSPECIFIED = 0;
  FOO_BAR_FIRST_VALUE = 1;
  FOO_BAR_SECOND_VALUE = 2;
}
Copy after login

The above is the detailed content of Do enum variables in .proto files have to be uppercase?. For more information, please follow other related articles on the PHP Chinese website!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!