Erlang atoms and tuples in land

What is the appropriate type of Thrift for:

  • Erlang tuple (I can imagine the structure)
  • Erlang atom (if there is one?)

Is there any documentation available with direct mappings between the Erlang and Thrift IDL types?

+4
source share
1 answer

Ok, I will try to answer myself :)

There seems to be no direct translation of Erlang tuples into Thrift. What you can do is to include the type definitions created by Thrift in your Erlang module and write your Erlang code so that it uses the generated Erlang entries as parameters and / or returns values ​​for your functions.

Erlang atoms must be converted to Trrift binaries (or, ultimately, strings).

So, if you want to have something like:

-spec cool_function() -> {atom(), atom()}. cool_function() -> {foo, bar} 

You need to specify what.thrift in your file:

 struct MyTuple { 1: binary first, 2: binary second } service myService { MyTuple cool_function() } 

In addition, you need to write your Erlang function as:

 [...] -include("whatever_types.hrl"). [...] -spec cool_function() -> #myTuple{}. cool_function() -> #myTuple{ first = atom_to_binary(foo, utf8), second = atom_to_binary(bar, utf8) }. 

Please correct me if I am wrong.

+3
source

Source: https://habr.com/ru/post/1300775/


All Articles