Skip to content

Commit 513054d

Browse files
authored
feat(AIP-126): Clarify enum prefixing (#1025)
1 parent fbb5336 commit 513054d

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

aip/general/0126.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,16 @@ message Book {
5555
- An exception to this rule is if there is a clearly useful zero value. In
5656
particular, if an enum needs to present an `UNKNOWN`, it is usually clearer
5757
and more useful for it to be a zero value rather than having both.
58-
- The other values **should not** be prefixed by the name of the enum itself.
59-
This generally requires users to write `MyState.MYSTATE_ACTIVE` in their
60-
code, which is unnecessarily verbose.
61-
- Note that some languages (including C++) hoist enum values into the parent
62-
namespace, which can result in conflicts for enums with the same values in
63-
the same proto package. To avoid this, multiple enums in the same proto
64-
package **must not** share any values. To avoid sharing values, APIs
65-
**may** prefix enum values with the name of the enum. In this case, they
66-
**must** do so consistently within the enum.
67-
- Enums which will only be used in a single message **should** be nested within
68-
that message. In this case, the enum **should** be declared immediately
69-
before it is used.
58+
- Enums which will only be used in a single message **should** be nested within that message.
59+
In this case, the enum **should** be declared immediately before it is used.
60+
- The non-zero values of such a nested enum definition **should not** be prefixed by the name
61+
of the enum itself. This generally requires users to write `MyState.MYSTATE_ACTIVE` in their
62+
code, which is unnecessarily verbose.
63+
- Enums which will be used by multiple messages **should** be defined at the package level and
64+
**should** be defined at the bottom of the proto file (see [AIP-191][]).
65+
- Some languages (including C++) hoist enum values into the parent namespace, which can result
66+
in conflicts for enums with the same values in the same proto package. To avoid sharing values,
67+
APIs **should** prefix package-level enum values with the name of the enum.
7068
- Enums **should** document whether the enum is frozen or they expect to add
7169
values in the future.
7270

@@ -111,6 +109,7 @@ choice (although `google.protobuf.BoolValue` is also available).
111109

112110
- For states, a special type of enum, see [AIP-216][].
113111

112+
[aip-191]: ./0191.md
114113
[aip-216]: ./0216.md
115114
[bcp-47]: https://en.wikipedia.org/wiki/IETF_language_tag
116115
[media types]: https://en.wikipedia.org/wiki/Media_type

0 commit comments

Comments
 (0)