File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
content/programming-guides Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -187,6 +187,28 @@ some languages don't support an enum being defined inside a "struct" type,
187187preferring prefixed values ensures a consistent approach across binding
188188languages.
189189
190+ When prefixing enum values, the remainder of the name with the prefix stripped
191+ should still be a legal and style-conformant enum name. For example, avoid the
192+ following:
193+
194+ ```
195+ enum DeviceTier {
196+ DEVICE_TIER_UNKNOWN = 0;
197+ DEVICE_TIER_1 = 1;
198+ DEVICE_TIER_2 = 2;
199+ }
200+ ```
201+
202+ Instead, use a value name like ` DEVICE_TIER_TIER1 ` , where the ` DEVICE_TIER_ `
203+ portion is viewed as scoping the enum value rather than as part of the
204+ individual enum value name. Some Protobuf implementations automatically strip
205+ the prefix that matches the containing enum name where it is safe to do so, but
206+ could not in this example since a bare ` 1 ` is not a legal enum value name.
207+
208+ A future Edition will add support for scoped enums, which will eliminate the
209+ need to manually prefix each enum value and enable this to be written succinctly
210+ as ` TIER1 = 1 ` .
211+
190212## Services {#services}
191213
192214Use TitleCase for service names and method names.
You can’t perform that action at this time.
0 commit comments