Flatbuffer (flatbuffer v0.2.0)
Flatbuffer binary serialization for Elixir.
Provides functions to read from and write to Flatbuffer binaries using schema definitions. Supports direct access to nested data without parsing the entire buffer.
Usage
# Read/Write
{:ok, data} = Flatbuffer.read(buffer, schema)
binary = Flatbuffer.to_binary(map, schema)
# Direct access
{:ok, value} = Flatbuffer.get(buffer, [:table, :field], schema)
# With schema file
def YourThing do
use Flatbuffer, file: "schema.fbs"
end
# Read/Write
{:ok, data} = YourThing.read(buffer)
binary = YourThing.to_binary(map)
Summary
Functions
Generates schema-aware functions (read, get, to_iolist, etc.) in the caller module. Options
Retrieves a value from a path without decoding the entire buffer. Returns {:ok, value} or {:error, :index_out_of_range}.
Same as get/3 but raises on error.
Reads a Flatbuffer into a map using the given schema. Returns {:ok, map} or {:error, reason}.
Same as read/2 but raises on error.
Serializes a map into a Flatbuffer binary using the schema.
Serializes a map into a Flatbuffer iolist using the schema.
Functions
Generates schema-aware functions (read, get, to_iolist, etc.) in the caller module. Options:
- :file - Required schema file path.
- :path - Base path for schema includes.
@spec get(buffer :: iodata(), [atom() | integer()], Flatbuffer.Schema.t()) :: {:ok, any()} | {:error, :index_out_of_range}
Retrieves a value from a path without decoding the entire buffer. Returns {:ok, value} or {:error, :index_out_of_range}.
@spec get!(buffer :: iodata(), [atom() | integer()], Flatbuffer.Schema.t()) :: any()
Same as get/3 but raises on error.
@spec read(buffer :: iodata(), Flatbuffer.Schema.t()) :: {:ok, map()} | {:error, {:id_mismatch, %{buffer_id: binary(), schema_id: binary()}}}
Reads a Flatbuffer into a map using the given schema. Returns {:ok, map} or {:error, reason}.
@spec read!(buffer :: iodata(), Flatbuffer.Schema.t()) :: map()
Same as read/2 but raises on error.
@spec to_binary(map(), Flatbuffer.Schema.t()) :: binary()
Serializes a map into a Flatbuffer binary using the schema.
@spec to_iolist(map(), Flatbuffer.Schema.t()) :: iolist()
Serializes a map into a Flatbuffer iolist using the schema.