Skip to main content

Crate nativeview_codec

Crate nativeview_codec 

Source
Expand description

Zero-unsafe, zero-runtime-dependency Tier-2 little-endian binary codec primitives (ByteReader, ByteWriter, SliceWriter, ByteSink, ByteBuf, CodecError, NvEncode, NvDecode) and #[derive(NvCodec)].

Sits strictly below nativeview-abi in the workspace dependency DAG (depends only on zero-dep nativeview-abi-macros) so every core, framework, backend, and module crate shares one canonical, bounds-checked, DoS-hardened Tier-2 codec.

Re-exports§

pub use transport::call_sync_decode;
pub use transport::decode_opt_raw_str;
pub use transport::encode_f32_stack;
pub use transport::encode_f64_stack;
pub use transport::encode_opt_raw_str;
pub use transport::try_with_stack_writer;
pub use transport::with_stack_writer;
pub use transport::ByteTransport;
pub use transport::StackWriter;
pub use transport::TransportDoneFn;
pub use transport::TransportError;

Modules§

transport
Framework- and runtime-agnostic binary byte transport (ByteTransport), error model (TransportError), and zero-waste stack-first request encoding helpers (StackWriter, with_stack_writer, try_with_stack_writer, and canonical float stack encoders).

Structs§

ByteBuf
Owned binary byte buffer (u32 length prefix + raw bytes, capped at DEFAULT_MAX_BYTES = 16 MiB and encoded/decoded in one bulk slice copy).
ByteReader
Strictly bounds-checked little-endian binary reader.
ByteWriter
Reusable little-endian binary writer.
FlatOpDesc
Derives NvEncode and NvDecode for Tier-2 little-endian structs and enums.
FlatOpFieldDesc
Derives NvEncode and NvDecode for Tier-2 little-endian structs and enums.
FlatOpScopeDesc
Derives NvEncode and NvDecode for Tier-2 little-endian structs and enums.
FlatOpStreamDesc
Derives NvEncode and NvDecode for Tier-2 little-endian structs and enums.
SliceWriter
Zero-allocation little-endian binary writer over a caller-owned &mut [u8] slice.

Enums§

CodecError
Typed, allocation-free error produced by ByteReader, ByteWriter, SliceWriter, and #[derive(NvCodec)].
FlatOpFieldType
Derives NvEncode and NvDecode for Tier-2 little-endian structs and enums.
FlatOpStrError
Error returned when validating or decoding a word-padded UTF-8 crate::FlatOpFieldType::StrSlice.
FloatConstraint
Derives NvEncode and NvDecode for Tier-2 little-endian structs and enums.

Constants§

CANONICAL_F32_NAN_BITS
Canonical quiet NaN bit pattern for f32 (IEEE-754 little-endian deterministic encoding).
CANONICAL_F64_NAN_BITS
Canonical quiet NaN bit pattern for f64 (IEEE-754 little-endian deterministic encoding).
DEFAULT_MAX_BYTES
Default upper bound on byte/string lengths encoded/decoded by NvEncode/NvDecode (16 MiB).
DEFAULT_MAX_DEPTH
Default maximum container nesting depth (read_vec / read_opt) guarding against stack-overflow DoS on recursive #[derive(NvCodec)] types.
DEFAULT_MAX_ITEMS
Default upper bound on element counts encoded/decoded by NvEncode/NvDecode for Vec<T>.

Traits§

ByteSink
Shared little-endian primitive writing sink implemented by ByteWriter, SliceWriter, and [StackWriter], enabling wire types to share one zero-alloc serialization path.
NvDecode
Trait for Tier-2 little-endian binary deserialization from a ByteReader.
NvEncode
Trait for Tier-2 little-endian binary serialization into any ByteSink.

Functions§

canonical_f32_bits
Canonicalizes an f32 (-0.0 -> +0.0, any NaN -> canonical quiet NaN).
canonical_f64_bits
Canonicalizes an f64 (-0.0 -> +0.0, any NaN -> canonical quiet NaN).
check_flat_op_bytes_words
Validates the framing, length bound, bounds, and zero trailing padding of a word-padded byte block starting at words[pos], returning (payload_start, block_end, byte_len) on success.
flat_op_str_pad_mask
Bitmask of the trailing padding bytes in the final u32 word for byte_len bytes (0 when byte_len is already 4-byte aligned).
flat_op_str_padded_bytes
Padded byte length (multiple of 4) required for byte_len bytes, or None on overflow.
flat_op_str_word_len
Number of u32 payload words required for byte_len bytes (ceil(byte_len / 4)).
for_each_padded_le_word
Visits bytes as little-endian u32 words, zero-padding the final partial word (flat_op_str_word_len(bytes.len()) calls; the payload half of a StrSlice block, e.g. for hashing it without materializing the words). Zero-allocation.
hex_nibble
Decodes one ASCII hexadecimal digit (0-9, a-f, A-F) into its 4-bit value 0..=15.
read_flat_op_padded_bytes
Validates and borrows the raw payload of a [byte_len: u32 LE, bytes..., zero_pad...] block (the byte form of write_flat_op_bytes_words) at bytes[*pos], advancing *pos past the 4-byte-padded block on success.
read_flat_op_str_bytes
Validates and borrows a zero-copy &str from a little-endian byte buffer at bytes[*pos], advancing *pos past the 4-byte-padded block on success.
read_flat_op_str_words
Validates and decodes a word-padded UTF-8 string block at words[*pos] into an owned String, advancing *pos past the block on success.
read_flat_op_str_words_into
Validates and decodes a word-padded UTF-8 string block at words[*pos] into out in a single pass, clearing out first and advancing *pos past the block on success.
try_write_fixed
Fallible zero-allocation helper for fixed-size wire layouts (N bytes exact).
validate_flat_op_str_bytes
Validates a word-padded UTF-8 string block in a little-endian byte buffer at bytes[*pos], advancing *pos past the 4-byte-padded block on success.
validate_flat_op_str_words
Validates a word-padded UTF-8 string block at words[*pos] (enforcing len <= max_bytes, sufficient words, zeroed trailing padding bytes, and strict UTF-8) and advances *pos past it.
write_fixed
Zero-allocation helper for infallible fixed-size wire layouts (N bytes exact).
write_fixed_into
Zero-allocation helper filling a caller-owned [u8; N] fixed-size wire buffer.
write_flat_op_bytes_words
Appends [byte_len: u32, zero_padded_le_words...] for raw bytes to out.
write_flat_op_str_bytes
Appends [byte_len: u32 LE, utf8_bytes..., zero_pad...] to out.
write_flat_op_str_words
Appends [byte_len: u32, zero_padded_utf8_le_words...] to out.

Derive Macros§

NvCodec
Derives nativeview_codec::{NvEncode, NvDecode} for Tier-2 little-endian binary structs and enums.
ReprEnum
Zero-dependency derive for unit-only #[repr(u8|u16|u32|u64|i8|i16|i32|i64)] enums emitting COUNT, ALL, as_<repr>, try_from_<repr>, and (only with #[repr_enum(fallback = V)]) from_<repr>.