zon-lib crate provides the core primitives for zero-copy reading and writing.
Installation
Cargo.toml
ZonWriter
bulder-pattern struct for creating ZON binaries. It manages the byte buffer and ensures 64-byte alignment.Constructor
Creates a new writer with an empty buffer.
Writing Primitives
Writes a 32-bit unsigned integer to the buffer.Returns: The offset (pointer) to the written value.
Writes a UTF-8 string to the buffer, prefixed by its length.Returns: The offset (pointer) to the length prefix.
Finalizing
Sets the entry point of the ZON file. This writes the offset into the file header.Critical: Every ZON file must have a root set before it is valid.
Returns the underlying byte slice. Use this to write the file to disk.
ZonReader
Zero-copy reader that wraps a byte slice.Constructor
Validates the file header (Magic bytes
ZON1) and creates a reader.Note: This operation is O(1). It does not scan the file.Reading Primitives
Reads a u32 from the absolute offset.
Reads a string from the offset. Returns a
&str reference pointing directly into the original buffer (Zero-Copy).