Skip to main content

Crate flatwire

Crate flatwire 

Source
Expand description

flatwire - streaming JSON serialization that keeps memory flat and time linear.

The array helpers are the point: a large collection is written and read one element at a time, so peak memory is bounded by the largest single element rather than the whole collection. Wire format is plain JSON via serde_json.

Modules§

cbor
Streaming CBOR (RFC 8949 binary) format for flatwire, mirroring the Python reference. flatwire’s CBOR wire is a stream of concatenated CBOR data items (not a length-prefixed array), so encoding needs no upfront count and decoding reads one item at a time. The encoding is deterministic (shortest heads, map keys sorted by UTF-8 bytes, 64-bit floats), so output is byte-identical across all six flatwire languages. Covers the JSON data model (null/bool/int/float/str/array/map); no tags.
checked
Partial-stream failure semantics for flatwire (checked streams), matching the Python/Node reference. A streamed collection is wrapped in an envelope whose terminal status is written LAST:
msgpack
Streaming MessagePack (binary) format for flatwire, mirroring the Python reference. flatwire’s binary wire is a stream of concatenated MessagePack values (not a length-prefixed array), so encoding needs no upfront count and decoding reads one value at a time. Wire-compatible with standard MessagePack for the JSON data model (null/bool/int/float/str/bin/array/map); no ext types.
xml
Streaming XML format for flatwire, mirroring the JSON path and the Python/JS reference. XML has no native types, so flatwire uses an explicit, typed, fully round-trippable convention (see docs/FORMATS.md):

Structs§

ArrayIter
A lazy iterator over the elements of a top-level JSON array read from a reader. Tracks bracket/brace depth and string state to find element boundaries without materializing the whole array; each element is parsed individually, so memory stays proportional to the largest element.

Functions§

decode
Decode UTF-8 JSON bytes to a serde_json::Value.
decode_array
decode_from
Read a whole value from a reader.
encode
Encode a whole value to UTF-8 JSON bytes.
encode_array
Stream a large collection as a JSON array, one element at a time. Peak memory is bounded by the largest single element, not the collection length. Returns the number of elements written.
encode_to
Stream a value straight to a writer (no intermediate String).