Packed transports for codecs that expose one fixed-width unit per octet.
pack/2 returns an exact MSB-first Elixir bitstring. pack_lsb/2 returns a
byte-backed stream plus its exact bit length because LSB-first padding lives
in the high bits of the final octet and cannot be represented by an Elixir
bitstring without changing wire order.
Summary
Functions
MSB-first unpacks units, then converts them from the named codec to UTF-8.
Unpacks an LSB stream, then converts its units from the named codec to UTF-8.
Converts UTF-8 through an octet-backed codec, then MSB-first packs its units.
Converts UTF-8 through an octet-backed codec, then LSB-first packs its units.
Packs one byte-backed unit at a time into an exact MSB-first bitstring.
Packs units LSB-first and returns byte data plus its exact meaningful bit count.
Unpacks an exact MSB-first bitstring into one unit per byte.
Unpacks validated LSB-first byte data using an explicit meaningful bit count.
Types
@type error_result() :: {:error, :invalid_unit_bits | :invalid_bit_size | :nonzero_padding_bits} | {:error, :bit_order_mismatch} | {:error, :incomplete_unit, non_neg_integer(), bitstring() | non_neg_integer()} | {:error, :unit_out_of_range, non_neg_integer(), byte()}
@type width() :: 1..8
Functions
@spec decode_to_utf8(bitstring(), Iconvex.encoding(), width()) :: {:ok, binary()} | {:error, term()}
MSB-first unpacks units, then converts them from the named codec to UTF-8.
Semantic conversion failures use physical bit offsets. Their sequence is the exact MSB-first packed bitstring occupied by the failing units.
@spec decode_to_utf8_lsb(Iconvex.Packed.LSB.t(), Iconvex.encoding()) :: {:ok, binary()} | {:error, term()}
Unpacks an LSB stream, then converts its units from the named codec to UTF-8.
Semantic conversion failures use physical bit offsets. Their sequence is a
self-describing Iconvex.Packed.LSB fragment so its wire order and exact
meaningful bit length survive error reporting.
@spec encode_from_utf8(binary(), Iconvex.encoding(), width()) :: {:ok, bitstring()} | {:error, term()}
Converts UTF-8 through an octet-backed codec, then MSB-first packs its units.
@spec encode_from_utf8_lsb(binary(), Iconvex.encoding(), width()) :: {:ok, Iconvex.Packed.LSB.t()} | {:error, term()}
Converts UTF-8 through an octet-backed codec, then LSB-first packs its units.
@spec pack(binary(), width()) :: {:ok, bitstring()} | error_result()
Packs one byte-backed unit at a time into an exact MSB-first bitstring.
@spec pack_lsb(binary(), width()) :: {:ok, Iconvex.Packed.LSB.t()} | error_result()
Packs units LSB-first and returns byte data plus its exact meaningful bit count.
@spec unpack(bitstring(), width()) :: {:ok, binary()} | error_result()
Unpacks an exact MSB-first bitstring into one unit per byte.
@spec unpack_lsb(binary(), non_neg_integer(), width()) :: {:ok, binary()} | error_result()
Unpacks validated LSB-first byte data using an explicit meaningful bit count.