ToonEx.Btoon.Decode (toon_ex v1.3.1)

Copy Markdown View Source

BTOON decoder.

Parses the BTOON wire format back into the data model:

  • Envelope: "BTON" magic, version, flags, optional per-message string table and embedded schema, then an 8-byte-aligned body.
  • Tagged values with inline SmallInt, fixed-width little-endian integers/floats, zero-copy strings and binaries (BEAM sub-binaries).
  • StringRef ids resolved against the session dictionary first, then the per-message string table.
  • TypedArray and ObjectTable payloads materialized as lists or exposed as zero-copy views (typed_arrays: :views).
  • Schema mode: SchemaID followed by ordered, tagless fixed-width fields decoded strictly according to the (embedded or supplied) schema.

API

iex> {:ok, value} = Btoon.Decode.decode(<<66, 84, 79, 78, 1, 0, 0, 0, 106>>)
iex> value
42

Summary

Functions

Decodes a BTOON binary.

Decodes a BTOON binary, raising Btoon.DecodeError on error.

Decodes a BTOON binary using pre-validated options.

Decodes a BTOON binary using pre-validated options, raising Btoon.DecodeError on error.

Functions

decode(binary, opts \\ [])

@spec decode(
  binary(),
  keyword()
) :: {:ok, term()} | {:error, ToonEx.Btoon.DecodeError.t()}

Decodes a BTOON binary.

Returns {:ok, value} or {:error, ToonEx.Btoon.DecodeError.t()}.

decode!(binary, opts \\ [])

@spec decode!(
  binary(),
  keyword()
) :: term()

Decodes a BTOON binary, raising Btoon.DecodeError on error.

decode_validated(binary, validated_opts)

@spec decode_validated(binary(), ToonEx.Btoon.Decode.Options.validated()) ::
  {:ok, term()} | {:error, ToonEx.Btoon.DecodeError.t()}

Decodes a BTOON binary using pre-validated options.

This skips option re-validation, improving throughput for repeated decoding with the same options. Returns {:ok, value} or {:error, Btoon.DecodeError.t()}.

decode_validated!(binary, validated_opts)

@spec decode_validated!(binary(), ToonEx.Btoon.Decode.Options.validated()) :: term()

Decodes a BTOON binary using pre-validated options, raising Btoon.DecodeError on error.