A Pure Elixir Thrift Implementation
Go to file
Steve Cohen fd8600815d Booleans can have integer default values (#143)
Booleans can have 1 and 0 as default values. This converts them into
true and false, so we can deal with them properly.

Fixes #142
2017-01-03 14:18:47 -08:00
bench Remove UnionSerializationBenchmark (#101) 2016-12-29 14:10:37 -08:00
ci Pure elixir implementation (#54) 2016-11-30 11:31:59 -08:00
config Disable Logger console output in the test env 2016-12-26 16:48:52 -08:00
lib Booleans can have integer default values (#143) 2017-01-03 14:18:47 -08:00
src Handle empty and non-empty default containers (#135) 2017-01-03 09:09:26 -08:00
test Booleans can have integer default values (#143) 2017-01-03 14:18:47 -08:00
.credo.exs Add a custom Credo configuration file 2016-12-23 14:09:27 -08:00
.ebert.yml Remove the Apache Thrift Erlang runtime library (#122) 2016-12-31 09:02:51 -08:00
.gitignore The Thrift compiler task now uses Thrift.Generator (#124) 2016-12-31 17:02:47 -08:00
.travis.yml Bump our minimum Elixir version to 1.3 (#126) 2017-01-02 14:32:46 -08:00
coveralls.json Remove the Apache Thrift Erlang runtime library (#122) 2016-12-31 09:02:51 -08:00
LICENSE Remove license appendix text 2016-09-22 08:06:09 -07:00
mix.exs Bump our minimum Elixir version to 1.3 (#126) 2017-01-02 14:32:46 -08:00
mix.lock Binary Framed server (#116) 2017-01-02 14:06:55 -08:00
README.md The Thrift compiler task now uses Thrift.Generator (#124) 2016-12-31 17:02:47 -08:00
TODO.md Pure elixir implementation (#54) 2016-11-30 11:31:59 -08:00

Thrift Utilities for Elixir

Build Status Coverage Status

This package contains a handful of useful utilities for working with Thrift in Elixir.

Setup

Start by adding this package to your project as a dependency:

{:thrift, "~> 1.3"}

Or to track the GitHub master branch:

{:thrift, github: "pinterest/elixir-thrift"}

Mix

This package includes a Mix compiler task that can be used to automate Thrift code generation. Start by adding :thrift to your project's :compilers list. For example:

compilers: [:thrift | Mix.compilers]

It's important to add :thrift before the :elixir entry. The Thrift compiler will generate Elixir source files, and we currently rely on this ordering to ensure those generated source files get compiled.

Next, define the list of :thrift_files that should be compiled. In this example, we gather all of the .thrift files under the thrift directory:

thrift_files: Mix.Utils.extract_files(["thrift"], [:thrift])

By default, the generated source files will be written to the lib directory, but you can change that using the thrift_output option.

Thrift IDL Parsing

This package also contains experimental support for parsing Thrift IDL files. It is built on a low-level Erlang lexer and parser:

{:ok, tokens, _} = :thrift_lexer.string('enum Colors { RED, GREEN, BLUE}')
{:ok,
 [{:enum, 1}, {:ident, 1, 'Colors'}, {:symbol, 1, '{'}, {:ident, 1, 'RED'},
  {:symbol, 1, ','}, {:ident, 1, 'GREEN'}, {:symbol, 1, ','},
  {:ident, 1, 'BLUE'}, {:symbol, 1, '}'}], 1}

{:ok, schema} = :thrift_parser.parse(tokens)
{:ok,
 %Thrift.Parser.Models.Schema{constants: %{},
  enums: %{Colors: %Thrift.Parser.Models.TEnum{name: :Colors,
     values: [RED: 1, GREEN: 2, BLUE: 3]}}, exceptions: %{}, includes: [],
  namespaces: %{}, services: %{}, structs: %{}, thrift_namespace: nil,
  typedefs: %{}, unions: %{}}}

But also provides a high-level Elixir parsing interface:

Thrift.Parser.parse("enum Colors { RED, GREEN, BLUE}")
%Thrift.Parser.Models.Schema{constants: %{},
 enums: %{Colors: %Thrift.Parser.Models.TEnum{name: :Colors,
    values: [RED: 1, GREEN: 2, BLUE: 3]}}, exceptions: %{}, includes: [],
 namespaces: %{}, services: %{}, structs: %{}, thrift_namespace: nil,
 typedefs: %{}, unions: %{}}