Home

Awesome

Protobuf.Generate

CI Hex.pm Version

protobuf.generate is a mix task that allows you to generate Elixir code using Protobuf without using the protoc-gen-elixir plugin.

The generator calls protoc using descriptor_set_out to output a FileDescriptorSet into a temporary file for input to Protobuf.

The difference between protobuf.generate and protoc-gen-elixir is that protoc-gen-elixir is called as a plugin to protoc and therefor executes in a global context while protobuf.generate executes in the context of the local project.

By executing in the context of the local project:

Prerequisites

Installation

This package can be installed by adding protobuf_generate to your list of dependencies in mix.exs:

def deps do
  [
    {:protobuf_generate, "~> 0.1.0"}
  ]
end

Usage

mix protobuf.generate supports the same options as protoc-gen-elixir

Arguments

Required options

Optional options

$ mix protobuf.generate --output-path=./lib --include-path=./priv/protos helloworld.proto
$ mix protobuf.generate \
  --include-path=priv/proto \
  --include-path=deps/googleapis \
  --generate-descriptors=true \
  --output-path=./lib \
  --plugins=ProtobufGenerate.Plugins.GRPCWithOptions \
  google/api/annotations.proto google/api/http.proto helloworld.proto

Available plugins

Extensions

Extensions in the current project are loaded automatically when running mix protobuf.generate. However they need to be already generated in order for Protobuf.load_extensions/0 to pick them up.

Acknowledgements