A Pure Elixir Thrift Implementation
Go to file
Jon Parise 5a6504aa6b Move skip_field/2 to the Binary protocol module (#103)
We were previously generating private copies of the "skip" functions in
each generated struct module. These functions are generic and have been
moved to the top-level Binary protocol module instead. The reduces the
size of the generated modules by a nice amount.

We only skip unrecognized fields so this code shouldn't be called very
often. In practice, however, we can't predict how often this case will
arise, so the performance of these function is important. Fortunately,
this change doesn't introduce a measurable performance cost.

Lastly, this change adds Binary module documentation and some initial
typespecs.
2016-12-29 21:58:53 -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
ext Update our Thrift reference to version 0.9.3. 2015-10-16 09:35:34 -07:00
lib Move skip_field/2 to the Binary protocol module (#103) 2016-12-29 21:58:53 -08:00
src Pure elixir implementation (#54) 2016-11-30 11:31:59 -08:00
test Remove UnionSerializationBenchmark (#101) 2016-12-29 14:10:37 -08:00
.credo.exs Add a custom Credo configuration file 2016-12-23 14:09:27 -08:00
.ebert.yml Add a custom Credo configuration file 2016-12-23 14:09:27 -08:00
.gitignore Pure elixir implementation (#54) 2016-11-30 11:31:59 -08:00
.gitmodules Initial revision. 2015-01-06 17:51:59 -08:00
.travis.yml Simplify the Travis build matrix (#87) 2016-12-29 09:18:26 -08:00
coveralls.json Pure elixir implementation (#54) 2016-11-30 11:31:59 -08:00
LICENSE Remove license appendix text 2016-09-22 08:06:09 -07:00
mix.exs Merge branch 'master' into thrift_tng 2016-12-29 09:46:06 -08:00
mix.lock Generated Thrift client (#72) 2016-12-24 17:29:44 -08:00
README.md Preparing the 1.3.1 release 2016-11-15 16:12:35 -08:00
TODO.md Pure elixir implementation (#54) 2016-11-30 11:31:59 -08:00

Thrift Utilities for Elixir

Build Status Coverage Status License

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

In particular, it includes a copy of the Erlang Thrift runtime library.

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", submodules: true}

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 :erlang entry. The Thrift compiler will generate Erlang 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 src directory, but you can change that using the thrift_output option.

You can also pass additional options to the Thrift compiler by listing them in the thrift_options option:

thrift_options: ~w[-I my/include/dir]

If you require a specific version of the Thrift compiler, you can specify a version requirement using the thrift_version option. Version requirements use the SemVer 2.0 schema. For example:

thrift_version: ">= 0.9.3"  # Erlang maps support

You can also override the name of the Thrift compiler executable itself:

thrift_executable: "thrift-0.9.3"

If you get something like type set() undefined when compiling the generated files you can try:

thrift_options: ~w[--gen erl:maps]

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: %{}}