Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle the enum option allow_alias = true
This option allows several enumerators to have the same numeric value. For langages where the enum symbol is really an integer value, this causes no problems, but for gpb, which maps numeric values to atoms, it has been solved this way: Given this example: enum e { option allow_alias = true; x = 1; y = 1; }; message m { required e field1 = 1; }; - encoding accepts all atoms, ie: #m{field1 = x} and #m{field1 = y} would encode to the same. - on decoding, it decodes to the first defined enum symbol: seeing an 1 on the wire would decode to #{field1 = x}. In the introspection functions, such an option field is a three-tuple in list of enumerator values returned: find_enum_def(e) will return the following: [{option, allow_alias, true}, {x, 1}, {y, 1}] The enum_symbol_by_value/2 and enum_symbol_by_value_e/1 will return the atom x for the value 1. This option is true in gpb, regardless of actual option setting. It appeared in google protobuf 2.5.0, and the plan to make it default to true in some future has been advertized. Having it always true in gpb means we won't be generating a compile time error for the case that the option is set to false, and more than enum have the same numeric value.
- Loading branch information
1 parent
f43b727
commit 34423df
Showing
4 changed files
with
53 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters