Giter VIP home page Giter VIP logo

elixir-thrift's Introduction

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, 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

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. For the moment, only an Erlang lexer is available, but the goal is to provide more advanced parser support over time.

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.