Git Product home page Git Product logo

exprotoc's Introduction

Exprotoc

Elixir protocol buffers compiler

Mix project options

To use exprotoc, first include exprotoc in your mixfile as a dependency. Then, in the project property of your mix project, add :exprotoc to the list of compilers (e.g. compilers: [:exprotoc, :elixir, :app).

To configure the :exprotoc compiler prepass, there are three exposed options: proto_out, proto_files, and proto_path.

proto_out

Binary string that represents the directory generated code should be output to. Defaults to the lib folder.

proto_files

This should be a list of all the proto files you wish to turn into elixir code.

proto_path

List of directories in the order exprotoc should visit to look for proto files and imports.

Example mix.exs file

defmodule Example.Mixfile do
  use Mix.Project

  def project do
    [ app: :example,
      version: "0.0.1",
      elixir: "~> 0.12.5",
      compilers: [:exprotoc, :elixir, :app],
      proto_files: ["example.proto"],
      proto_path: ["priv"],
      deps: deps ]
  end

  defp deps do
    [{ :exprotoc, github: "jeremyong/exprotoc" }]
  end
end

This will compile the Example application with the generated code for the proto file example.proto. Because no proto_out option is specified, the generated code will be output to the lib folder.

Usage

Just access your message modules as you would a standard Elixir dict.

For example, with the following proto message:

package Example;
message Foo {
  enum Bar {
    Zap = 150;
  }
  required Foo a = 1;
  required uint32 b = 2;
}

exprotoc will create a module Example.Foo and submodule Example.Foo.Bar.

You can create a new message simply with Example.Foo.new or Example.Foo.new a: Example.Foo.Bar.zap.

You can access your message with the access protocol. For example:

message = Example.Foo.new a: Example.Foo.Bar.zap
IO.inspect message[:a] # Will output { Example.Foo.Bar, :zap }
IO.inspect message[:b] # Will output nil
message = Example.Foo.put message, :b, 150
IO.inspect message[:b] # Will output 150

All message modules export the encode and decode functions to turn a message into an iolist or turn binary into a message.

Default values work as expected.

Repeated fields are represented as lists.

exprotoc's People

Contributors

eliaw avatar jeremyong avatar pma avatar

Watchers

 avatar  avatar

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.