kahon
A Rust writer for the Kahon binary format.
Goals
- Values are written as they arrive; containers reference children by back-offset. Memory stays bounded by tree depth, not document size.
- Arrays and objects are B+trees on disk: index into a million-element array, or look up a key in a million-key object, without scanning.
- Fixed-fanout for tight in-memory output, or page-aligned target-byte sizing for files that will be
pread-ed or memory-mapped. - Uses flexbuffer-like builder pattern API to construct the JSON object.
Usage
cargo add kahon
use Writer;
let mut buf: = Vecnew;
let mut w = new;
let mut monster = w.start_object;
monster.push_i64?;
monster.push_bool?;
monster.end?; // explicit close propagates errors
w.finish?; // writes the 12-byte trailer
Builders close themselves on Drop; use .end() when you want errors surfaced rather than swallowed into the writer's poison flag.
Tuning
use ;
// Disk-tuned: each B+tree node targets one page, trailer is page-aligned.
let opts = WriterOptions ;
let w = with_options?;
The default (BuildPolicy::compact(128)) produces the tightest output and is best for in-memory or network use. disk_aligned trades a small amount of unreferenced padding for layout that plays well with the page cache.
Status
Pre-1.0. The on-disk format is governed by an external spec; comments in the source cite section numbers. A reference reader lives under tests/common/ and is exercised by the golden-file and property tests.
License
All source code is licensed under MIT.
All contributions are to be licensed as MIT.