All Projects → elixir-protobuf → Protobuf

elixir-protobuf / Protobuf

Licence: mit
A pure Elixir implementation of Google Protobuf

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to Protobuf

protobuf-d
Protocol Buffers Compiler Plugin and Support Library for D
Stars: ✭ 32 (-92.76%)
Mutual labels:  serialization, protobuf, protocol-buffers, protoc
Protobuf
Protocol Buffers - Google's data interchange format
Stars: ✭ 52,305 (+11733.71%)
Mutual labels:  protobuf, protocol-buffers, protoc, serialization
protopatch
protoc-gen-go patch utility
Stars: ✭ 58 (-86.88%)
Mutual labels:  protobuf, protocol-buffers, protoc
Protoc Jar Maven Plugin
Protocol Buffers protobuf maven plugin - based on protoc-jar multi-platform executable protoc JAR
Stars: ✭ 177 (-59.95%)
Mutual labels:  protobuf, protocol-buffers, protoc
protocell
Conjures up convenient OCaml types and serialization functions based on protobuf definition files
Stars: ✭ 18 (-95.93%)
Mutual labels:  protobuf, protocol-buffers, protoc
Protobuf Java Format
Provide serialization and de-serialization of different formats based on Google’s protobuf Message. Enables overriding the default (byte array) output to text based formats such as XML, JSON and HTML.
Stars: ✭ 134 (-69.68%)
Mutual labels:  protobuf, protocol-buffers, serialization
Pb And K
Kotlin Code Generator and Runtime for Protocol Buffers
Stars: ✭ 137 (-69%)
Mutual labels:  protobuf, protocol-buffers, protoc
Rules protobuf
Bazel rules for building protocol buffers and gRPC services (java, c++, go, ...)
Stars: ✭ 206 (-53.39%)
Mutual labels:  protobuf, protocol-buffers, protoc
Protoc Jar
Protocol Buffers protobuf compiler - multi-platform executable protoc JAR and API
Stars: ✭ 103 (-76.7%)
Mutual labels:  protobuf, protocol-buffers, protoc
makego
Makefile setup for our Golang projects.
Stars: ✭ 65 (-85.29%)
Mutual labels:  protobuf, protocol-buffers, protoc
kafka-protobuf-serde
Serializer/Deserializer for Kafka to serialize/deserialize Protocol Buffers messages
Stars: ✭ 52 (-88.24%)
Mutual labels:  serialization, protobuf, protocol-buffers
protoc-plugin
A protoc compiler plugin for Clojure applications
Stars: ✭ 28 (-93.67%)
Mutual labels:  serialization, protobuf, protocol-buffers
nimpb
Protocol Buffers for Nim
Stars: ✭ 29 (-93.44%)
Mutual labels:  serialization, protobuf, protocol-buffers
Protodot
transforming your .proto files into .dot files (and .svg, .png if you happen to have graphviz installed)
Stars: ✭ 107 (-75.79%)
Mutual labels:  protobuf, protocol-buffers, protoc
ocaml-pb-plugin
A protoc plugin for generating OCaml code from protobuf (.proto) files.
Stars: ✭ 18 (-95.93%)
Mutual labels:  serialization, protobuf, protocol-buffers
Protobuf Dynamic
Protocol Buffers Dynamic Schema - create protobuf schemas programmatically
Stars: ✭ 186 (-57.92%)
Mutual labels:  protobuf, protocol-buffers, protoc
Protobuf Swift
Google ProtocolBuffers for Apple Swift
Stars: ✭ 925 (+109.28%)
Mutual labels:  protobuf, protocol-buffers, protoc
Protobuf Nim
Protobuf implementation in pure Nim that leverages the power of the macro system to not depend on any external tools
Stars: ✭ 90 (-79.64%)
Mutual labels:  protobuf, protocol-buffers, serialization
elm-protobuf
protobuf plugin for elm
Stars: ✭ 93 (-78.96%)
Mutual labels:  serialization, protobuf, protocol-buffers
Protolock
Protocol Buffer companion tool. Track your .proto files and prevent changes to messages and services which impact API compatibility.
Stars: ✭ 394 (-10.86%)
Mutual labels:  protobuf, protocol-buffers, protoc

protobuf-elixir

Hex.pm Build Status

A pure Elixir implementation of Google Protobuf

Why this instead of exprotobuf(gpb)?

It has some must-have and other cool features like:

  1. A protoc plugin to generate Elixir code just like what other official libs do, which is powerful and reliable.
  2. Generate simple and explicit code with the power of Macro. (see test/support/test_msg.ex)
  3. Plugins support. Only grpc is supported now.
  4. Use structs for messages instead of Erlang records.
  5. Support Typespec in generated code.

Installation

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

def deps do
  [
    {:protobuf, "~> 0.7.1"},
    # Only for files generated from Google's protos.
    # Can be ignored if you don't use Google's protos.
    # Or you can generate the code by yourself.
    {:google_protos, "~> 0.1"}
  ]
end

Features

  • [x] Define messages with DSL
  • [x] Decode basic messages
  • [x] Skip unknown fields
  • [x] Decode embedded messages
  • [x] Decode packed and repeated fields
  • [x] Encode messages
  • [x] protoc plugin
  • [x] map
  • [x] Support default values
  • [x] Validate values
  • [x] Generate typespecs
  • [x] oneof
  • [x] (proto2) Extension (Experiment, see Protobuf.Extension)

Usage

Generate Elixir code

  1. Install protoc(cpp) here or brew install protobuf on MacOS.
  2. Install protoc plugin protoc-gen-elixir for Elixir . NOTE: You have to make sure protoc-gen-elixir(this name is important) is in your PATH.
$ mix escript.install hex protobuf
  1. Generate Elixir code using protoc
$ protoc --elixir_out=./lib helloworld.proto
  1. Files helloworld.pb.ex will be generated, like:
defmodule Helloworld.HelloRequest do
  use Protobuf, syntax: :proto3

  @type t :: %__MODULE__{
    name: String.t
  }
  defstruct [:name]

  field :name, 1, type: :string
end

defmodule Helloworld.HelloReply do
  use Protobuf, syntax: :proto3

  @type t :: %__MODULE__{
    message: String.t
  }
  defstruct [:message]

  field :message, 1, type: :string
end

Encode and decode in your code

struct = Foo.new(a: 3.2, c: Foo.Bar.new())
encoded = Foo.encode(struct)
struct = Foo.decode(encoded)

Note:

  • You should use YourModule.new instead of using the struct directly because default values will be set for all fields.
  • Validation is done in encode. An error will be raised if the struct is invalid(like type is not matched).

Descriptor support

If you use any custom options in your protobufs then to gain access to them you'll need to include the raw descriptors in the generated modules. You can generate the descriptors by passing gen_descriptors=true in --elixir_out.

The descriptors will be available on each module from the descriptor/0 function.

$ protoc --elixir_out=gen_descriptors=true:./lib/ *.proto
$ protoc --elixir_out=gen_descriptors=true,plugins=grpc:./lib/ *.proto

gRPC Support

If you write services in protobuf, you can generate gRPC code by passing plugins=grpc in --elixir_out:

$ protoc --elixir_out=plugins=grpc:./lib/ *.proto

Tips for protoc

  • Custom protoc-gen-elixir name or path using --plugin
$ protoc --elixir_out=./lib --plugin=./protoc-gen-elixir *.proto
  • Pass -I argument if you import other protobuf files
$ protoc -I protos --elixir_out=./lib protos/hello.proto

Custom options

Since extensions(Protobuf.Extension) is supported now, some options are defined, like custom module_prefix.

  1. Copy src/elixirpb.proto to your protos path
  2. Import elixirpb.proto and use the options
syntax = "proto2";

package your.pkg;

import "elixirpb.proto";

option (elixirpb.file).module_prefix = "Foo.Bar";
  1. Generate code as before

More options will be added in the future, see elixirpb.proto comments for details.

Tests

Before you can run the test suite, you must install eqc_gen:

$ mix eqc.install --mini

Sponsors

Acknowledgements

Many thanks to gpb and golang/protobuf as good examples of writing Protobuf decoder/encoder.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].