nativeview-codec 0.1.0-rc.1

Zero-unsafe, zero-runtime-dependency Tier-2 little-endian binary codec primitives and #[derive(NvCodec)]
Documentation

nativeview-codec

Zero-unsafe (#![forbid(unsafe_code)]), zero-runtime-dependency Tier-2 little-endian binary framing primitives (ByteReader, ByteWriter, CodecError, NvEncode, NvDecode) and #[derive(NvCodec)] (packages/core/codec, Core Foundation layer, strictly below nativeview-abi).

Key Public API

  • ByteReader<'a> — strictly bounds-checked LE reader (strict 0|1 bools, canonical LE floats, bounded read_bytes/read_str/read_vec, expect_magic, expect_zero, finish()).
  • ByteWriter — reusable LE writer (clear(), with_buf(), checked patch_u32 / write_zeroes, length-prefixed slices/strings/sequences).
  • SliceWriter<'a> — zero-allocation fixed-slice LE writer over &mut [u8] with exact-fill finish().
  • StackWriter<'a>, with_stack_writer<N>, try_with_stack_writer<N>, and canonical float stack encoders (encode_f32_stack, encode_f64_stack) — zero-allocation fast-path encoding into [u8; N] spilling to Vec<u8> only on overflow.
  • ByteTransport & TransportError — pluggable binary sync/async byte transport with zero-copy borrowed reply delivery (call_sync_decode).
  • CodecError — typed, allocation-free binary framing error (Truncated, BadMagic, BadVersion, BadEnum, BadBool, NonZeroReserved, LenOverflow, TrailingBytes, InvalidUtf8).
  • NvEncode / NvDecode and #[derive(NvCodec)].
use nativeview_codec::{ByteReader, ByteWriter, NvCodec, NvDecode, NvEncode};

#[derive(Debug, PartialEq, NvCodec)]
struct Ping {
    seq: u32,
    ok: bool,
    label: String,
}

let msg = Ping { seq: 7, ok: true, label: "nv".into() };
let bytes = msg.encode_to_vec().unwrap();
assert_eq!(Ping::decode_exact(&bytes).unwrap(), msg);

let mut w = ByteWriter::with_capacity(16);
w.write_u32(42);
let mut r = ByteReader::new(w.as_slice());
assert_eq!(r.read_u32().unwrap(), 42);
r.finish().unwrap();

Dependency Invariants

  • Depends ONLY on: nativeview-abi-macros (zero-dependency proc-macro crate), keeping the core DAG strictly acyclic below nativeview-abi.
  • Must NOT depend on: nativeview-abi, serde*, platform crates, or packages/modules/*.

Verification

cargo test -p nativeview-codec
cargo bench -p nativeview-codec --no-run