GitHub user dhull opened a pull request:
https://github.com/apache/thrift/pull/1320
THRIFT-4270: Generate Erlang mapping functions for const maps and lists
The Erlang generator now creates a new constants module containing two
functions for each const map and list.
The first function takes a single argument, the key for a const map or the
index for a const list, and returns the corresponding value for that key or
index; it throws an exception if the key does not exist or the index is out of
range.
The second function is similar to the first but takes a default second
element, and returns this default instead of throwing an exception if the key
does not exist or the index is out of range.
For example, if example.thrift contains the following Thrift definitions:
```thrift
const map<string, string> ALPHABET = { "a" : "apple", "b" : "banana" }
const list<string> NUMBER = [ "one", "two", "three" ]
```
then these calls will succeed:
```erlang
"apple" = example_constants:alphabet("a"),
"three" = example_constants:number(3),
```
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/dhull/thrift
thrift-4270-erlang-mapping-functions
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/thrift/pull/1320.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #1320
----
commit 3ec8e6a542c1f59908deabafd7ce94f459dfa038
Author: David Hull <[email protected]>
Date: 2017-07-28T21:13:23Z
Remove unused t_erl_generator::export_types_function function.
commit 3d1ec6131268a803c701f02480ac758c4cbcb5f2
Author: David Hull <[email protected]>
Date: 2017-07-28T18:52:21Z
THRIFT-4270: Generate Erlang mapping functions for const maps and lists.
The Erlang generator now creates a new constants module containing two
functions for each const map and list.
The first function takes a single argument, the key for a const map or
the index for a const list, and returns the corresponding value for
that key or index; it throws an exception if the key does not exist or
the index is out of range.
The second function is similar to the first but takes a default second
element, and returns this default instead of throwing an exception if
the key does not exist or the index is out of range.
For example, if example.thrift contains the following Thrift definitions:
const map<string, string> ALPHABET = { "a" : "apple", "b" : "banana" }
const list<string> NUMBER = [ "one", "two", "three" ]
these calls will succeed:
"apple" = example_constants:alphabet("a"),
"three" = example_constants:number(3),
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---