Packages
protocol_buffers
0.6.3
A pure Elixir implementation of Google Protobuf. A fork of tony612's package.
Current section
Files
Jump to
Current section
Files
lib/protobuf.ex
defmodule Protobuf do
defmacro __using__(opts) do
quote do
import Protobuf.DSL, only: [field: 3, field: 2, oneof: 2]
Module.register_attribute(__MODULE__, :fields, accumulate: true)
Module.register_attribute(__MODULE__, :oneofs, accumulate: true)
@options unquote(opts)
unquote(encode_decode())
@before_compile Protobuf.DSL
def new() do
Protobuf.Builder.new(__MODULE__)
end
def new(attrs) do
Protobuf.Builder.new(__MODULE__, attrs)
end
end
end
defp encode_decode() do
quote do
def decode(data), do: Protobuf.Decoder.decode(data, __MODULE__)
def encode(struct), do: Protobuf.Encoder.encode(struct)
end
end
def decode(data, %mod{}) do
Protobuf.Decoder.decode(data, mod)
end
def encode(struct) do
Protobuf.Encoder.encode(struct)
end
end