Element type selectors and raw numeric encoding helpers.
Element types cover the fixed-width numeric types shared by TypedArray
payloads and Schema fields (:int8, :uint8, :int16, :uint16,
:int32, :uint32, :int64, :uint64, :float32, :float64) plus
the composite types used only by Schema fields (:null, :bool,
:string, :binary, :array, :object).
All multi-byte values are little-endian (see ToonEx.Btoon design notes).
Deterministic type selection
detect_type/1 maps a homogeneous numeric list to the narrowest signed
integer type that represents every value losslessly, or :float32 when
every float survives the float32 round-trip and :float64 otherwise.
Every list therefore has exactly one encoding.
Summary
Functions
Decodes a raw buffer into a list of numbers.
Decodes the first element of a buffer, returning {value, rest}.
Detects whether a list of maps is a valid columnar object table.
Detects the narrowest element type for a homogeneous numeric list.
Alias of size/1 for numeric types (raises for composite types).
Encodes a single number to its raw little-endian representation.
Whether a double survives the IEEE-754 float32 round-trip exactly.
Integer range for a numeric type: {min, max} for integer types,
nil for float types.
Encodes a list of numbers into a contiguous raw buffer.
Whether the type is a fixed-width numeric type.
Element size in bytes (0 for variable-length composite types).
Maps a wire selector byte to a type atom. Raises ArgumentError for
unknown selectors.
Maps a wire selector byte to a type atom or nil.
Maps a numeric type atom to its wire selector byte.
Whether the type may appear as a TypedArray element type.
Types
Functions
@spec buffer_to_list(ToonEx.Btoon.Types.element_type(), binary()) :: [number()]
Decodes a raw buffer into a list of numbers.
@spec decode_raw(ToonEx.Btoon.Types.element_type(), binary()) :: {number(), binary()}
Decodes the first element of a buffer, returning {value, rest}.
@spec detect_object_table([%{optional(String.t()) => term()}]) :: {:ok, [String.t()], [ToonEx.Btoon.Types.element_type()], [[number()]]} | :error
Detects whether a list of maps is a valid columnar object table.
All maps must share the same (sorted) key set and each column must be a
homogeneous numeric column. Returns {:ok, names, types, columns} or :error.
@spec detect_type([number()]) :: {:ok, ToonEx.Btoon.Types.element_type()} | :error
Detects the narrowest element type for a homogeneous numeric list.
Returns {:ok, type} or :error when the list is empty, mixed, or
contains integers outside the int64 range.
@spec element_size(ToonEx.Btoon.Types.element_type()) :: pos_integer()
Alias of size/1 for numeric types (raises for composite types).
@spec encode_raw(ToonEx.Btoon.Types.element_type(), number()) :: binary()
Encodes a single number to its raw little-endian representation.
Whether a double survives the IEEE-754 float32 round-trip exactly.
@spec int_range(ToonEx.Btoon.Types.element_type()) :: {integer(), integer()} | nil
Integer range for a numeric type: {min, max} for integer types,
nil for float types.
@spec list_to_buffer(ToonEx.Btoon.Types.element_type(), [number()]) :: binary()
Encodes a list of numbers into a contiguous raw buffer.
@spec numeric?(ToonEx.Btoon.Types.element_type()) :: boolean()
Whether the type is a fixed-width numeric type.
@spec size(ToonEx.Btoon.Types.element_type()) :: non_neg_integer()
Element size in bytes (0 for variable-length composite types).
@spec type_atom(byte()) :: ToonEx.Btoon.Types.element_type()
Maps a wire selector byte to a type atom. Raises ArgumentError for
unknown selectors.
@spec type_atom_or_nil(byte()) :: ToonEx.Btoon.Types.element_type() | nil
Maps a wire selector byte to a type atom or nil.
@spec type_byte(ToonEx.Btoon.Types.element_type()) :: byte() | nil
Maps a numeric type atom to its wire selector byte.
Returns nil for unknown or composite types.
@spec typed_array_type?(ToonEx.Btoon.Types.element_type()) :: boolean()
Whether the type may appear as a TypedArray element type.