Iconvex.CodecSupport.SingleByte (iconvex v0.1.1)

Copy Markdown View Source

Allocation-conscious callbacks for codecs with one octet per source unit.

Leaf packages can keep their reviewed mapping data in module attributes and share this native engine without depending on another feature package.

A decode table is a 256-element tuple containing a Unicode scalar or nil for each byte. decode_to_utf8/2 accepts the corresponding tuple of UTF-8 fragments (ASCII integers or binaries). An encode table maps Unicode scalars to their canonical byte. The caller remains responsible for choosing a deterministic inverse when multiple bytes decode to the same scalar.

Summary

Types

A 256-element byte-indexed tuple; nil marks an undefined byte.

The standard external-codec encode policy.

A Unicode-scalar-to-canonical-byte inverse.

Functions

Decodes all bytes or returns the first invalid byte and absolute offset.

Stateless single-byte decode-chunk callback.

Decodes all assigned bytes and discards undefined bytes.

Decodes directly to UTF-8 using a byte-indexed fragment table.

Encodes all scalars or returns the first unrepresentable scalar.

Stateless single-byte encode-chunk callback.

Encodes representable scalars and discards all others.

Validates UTF-8 and encodes it without changing first-error ordering.

Encodes scalars, invoking replacer once for each unrepresentable scalar.

Types

decode_table()

@type decode_table() :: tuple()

A 256-element byte-indexed tuple; nil marks an undefined byte.

encode_policy()

@type encode_policy() :: :error | :discard | {:replace, (integer() -> [integer()])}

The standard external-codec encode policy.

encode_table()

@type encode_table() :: %{optional(non_neg_integer()) => 0..255}

A Unicode-scalar-to-canonical-byte inverse.

Functions

decode(input, table)

@spec decode(binary(), decode_table()) :: {:ok, [integer()]} | tuple()

Decodes all bytes or returns the first invalid byte and absolute offset.

decode_chunk(input, table)

@spec decode_chunk(binary(), decode_table()) :: {:ok, [integer()], <<_::0>>} | tuple()

Stateless single-byte decode-chunk callback.

decode_discard(input, table)

@spec decode_discard(binary(), decode_table()) :: {:ok, [integer()]}

Decodes all assigned bytes and discards undefined bytes.

decode_to_utf8(input, table)

@spec decode_to_utf8(binary(), decode_table()) :: {:ok, binary()} | tuple()

Decodes directly to UTF-8 using a byte-indexed fragment table.

encode(codepoints, table)

@spec encode([integer()], encode_table()) :: {:ok, binary()} | tuple()

Encodes all scalars or returns the first unrepresentable scalar.

encode_chunk(codepoints, table, arg3)

@spec encode_chunk([integer()], encode_table(), encode_policy()) ::
  {:ok, binary(), []} | tuple()

Stateless single-byte encode-chunk callback.

encode_discard(codepoints, table)

@spec encode_discard([integer()], encode_table()) :: {:ok, binary()}

Encodes representable scalars and discards all others.

encode_from_utf8(input, table)

@spec encode_from_utf8(binary(), encode_table()) :: {:ok, binary()} | tuple()

Validates UTF-8 and encodes it without changing first-error ordering.

encode_substitute(codepoints, table, replacer)

@spec encode_substitute([integer()], encode_table(), (integer() -> [integer()])) ::
  {:ok, binary()} | tuple()

Encodes scalars, invoking replacer once for each unrepresentable scalar.