json-slabs
Read and write JsonSlabs (JSLB) files — a binary container format for JSON-shaped data with embedded typed-array slabs. The array data is stored out-of-line and at its natural alignment, so it can be read as a zero-copy view into the file buffer and its size doesn't affect the parsing cost of the object structure.
This crate contains no JSON parser or writer. For JSON slabs it works with raw bytes and leaves parsing and placeholder substitution to the consumer.
Writing
use Builder;
let mut b = new;
let numbers = b.add_slab;
let sub_json = b.add_json_slab;
// `{:#}` on a placeholder prints the whole `{"$s": N}` reference.
let skeleton = format!;
let bytes = b.finish;
The slice passed to Builder::add_slab needs to outlive the builder.
You can use Builder::add_slab_from_vec(values) instead if you want the
builder to hold on to the data.
For columns that don't already exist in memory, use
Builder::add_slab_from_iter(count, iter). The iterator is consumed during
Builder::finish / Builder::to_writer when the file bytes are written.
Reading
use ;
let parsed = parse.unwrap;
// The root JSON slab, as raw JSON bytes:
// br#"{"numbers":{"$s":1},"splitOutArray":{"$s":2}}"#
let root: & = parsed.root_json_bytes;
// In practice you'd parse that JSON and get the slab index from the
// parsed `{"$s": N}` placeholder.
let numbers: = parsed.read.unwrap;
assert_eq!;
See the API docs for the full API, and FORMAT.md for the on-disk layout.
License
MIT. See LICENSE.