OmniBuf (omnibuf v0.1.0)

Copy Markdown View Source

OmniBuf v0.1 binary wire format for Elixir.

Supports all four OmniBuf implementation tiers:

  • Tier 1 (Plugin): protoc-gen-omnibuf-elixir generated structs, iodata codecs, and lazy Opaque zero-decode views with in-place iodata wire splicing.
  • Tier 2 (Protobuf): OmniBuf.Protobuf direct serialization/deserialization of standard elixir-protobuf (use Protobuf) message structs.
  • Tier 3 (Declarative Schema): use OmniBuf.Schema compile-time struct DSL.
  • Tier 4 (Blind): OmniBuf.Blind.decode/1 and OmniBuf.Blind.decode_json/1 for schema-less inspection with Field #0 SchemaMeta name resolution.

Summary

Functions

Decodes an OmniBuf binary into a fresh struct of mod (replace mode).

Decodes an OmniBuf binary without a schema (Tier 4).

Decodes an OmniBuf binary without a schema and serializes to JSON (Tier 4).

Decodes OmniBuf wire bytes into a standard elixir-protobuf struct (Tier 2).

Encodes an OmniBuf.Schema or generated Tier 1 struct to an OmniBuf binary.

Encodes an OmniBuf.Schema or generated Tier 1 struct to iodata.

Encodes a standard elixir-protobuf struct into OmniBuf wire bytes (Tier 2).

Merges an OmniBuf binary onto an existing struct (merge mode).

Functions

decode(bin, mod)

@spec decode(binary(), module()) :: {:ok, struct()} | {:error, OmniBuf.Error.t()}

Decodes an OmniBuf binary into a fresh struct of mod (replace mode).

decode_blind(bin, opts \\ [])

@spec decode_blind(binary(), keyword()) :: {:ok, map()} | {:error, OmniBuf.Error.t()}

Decodes an OmniBuf binary without a schema (Tier 4).

decode_blind_json(bin, opts \\ [])

@spec decode_blind_json(binary(), keyword()) ::
  {:ok, String.t()} | {:error, OmniBuf.Error.t()}

Decodes an OmniBuf binary without a schema and serializes to JSON (Tier 4).

decode_proto(bin, mod)

@spec decode_proto(binary(), module()) ::
  {:ok, struct()} | {:error, OmniBuf.Error.t()}

Decodes OmniBuf wire bytes into a standard elixir-protobuf struct (Tier 2).

encode(msg, opts \\ [])

@spec encode(struct(), keyword()) :: binary()

Encodes an OmniBuf.Schema or generated Tier 1 struct to an OmniBuf binary.

encode_iodata(msg, opts \\ [])

@spec encode_iodata(struct(), keyword()) :: iodata()

Encodes an OmniBuf.Schema or generated Tier 1 struct to iodata.

encode_proto(msg, opts \\ [])

@spec encode_proto(struct(), keyword()) :: binary()

Encodes a standard elixir-protobuf struct into OmniBuf wire bytes (Tier 2).

merge(existing, bin)

@spec merge(struct(), binary()) :: {:ok, struct()} | {:error, OmniBuf.Error.t()}

Merges an OmniBuf binary onto an existing struct (merge mode).