Skip to main content

Module binary

Module binary 

Source
Expand description

ASUN Binary Format (ASUN-BIN)

A high-performance binary encoding for ASUN data structures. Provides encode_binary and decode_binary for zero-overhead struct ↔ bytes conversion.

§Wire Format (all integers little-endian)

bool      → 1 byte  (0x00=false, 0x01=true)
i8        → 1 byte (signed)
i16       → 2 bytes LE
i32       → 4 bytes LE
i64       → 8 bytes LE
u8        → 1 byte
u16       → 2 bytes LE
u32       → 4 bytes LE
u64       → 8 bytes LE
f32       → 4 bytes LE (IEEE 754 bit-cast)
f64       → 8 bytes LE (IEEE 754 bit-cast)
char      → 4 bytes LE (Unicode scalar as u32)
str       → u32 LE length + UTF-8 bytes  ← ZERO-COPY on decode (&'de str)
bytes     → u32 LE length + raw bytes
Option<T> → u8 tag (0=None, 1=Some) + [T payload if Some]
Vec<T>    → u32 LE count + [element × count]
struct    → fields in declaration order (no length prefix — known from schema)
tuple     → elements in order (no length prefix)
enum      → u32 LE variant_index + [payload for non-unit variants]
unit      → 0 bytes
newtype   → inner value directly (no wrapper)

§Key Features

  • Zero-copy string decode: borrowed &'de str slices directly reference input bytes.
  • No type tags for struct fields: schema drives layout (like Protobuf binary, not CBOR).
  • SIMD-accelerated bulk byte copy for large string payloads (≥ 32 bytes).
  • All primitives written/read via to_le_bytes / from_le_bytes — compiler typically emits a single STR/LDR instruction on aarch64 / MOV/MOV on x86-64.

Structs§

BinSeqEnc
BinaryDecoder
BinaryEncoder

Functions§

decode_binary
Decode a value from ASUN binary bytes.
encode_binary
Encode value to a Vec<u8> using the ASUN binary format.