flatwire 0.3.0

Streaming JSON and XML serialization that keeps memory flat and time linear - stream large collections element-by-element.
Documentation

flatwire (Rust)

Streaming JSON serialization that keeps memory flat and time linear. Stream large collections element-by-element instead of materializing the whole payload, so peak memory is bounded by the largest single element — not the collection size. Built on serde_json; wire format is plain JSON.

Part of the cross-language flatwire project (identical API in Python, Node, .NET, Rust, Go, and Java).

Install

cargo add flatwire

Usage

use flatwire::{encode, decode, encode_array, decode_array};
use std::io::Cursor;

// Whole value
let bytes = encode(&value)?;
let value = decode(&bytes)?;

// Stream a large collection — flat memory
let mut out = Vec::new();
encode_array(items.iter(), &mut out)?;

for element in decode_array(Cursor::new(out)) {
    let element = element?; // one at a time; whole array never held at once
}

decode_array(reader).with_max_depth(200) bounds how deeply a single element may nest before the iterator rejects the input (DoS guard); with_max_depth(0) disables it.

API

Function Description
encode(&value) value → Vec<u8>
decode(&bytes) bytes → serde_json::Value
encode_to(&value, &mut writer) stream a single value out
decode_from(reader) read a single value
encode_array(items, &mut writer) stream a large collection
decode_array(reader) lazy Iterator over a large array

License

Apache-2.0 — see the repository.

Changelog

See CHANGELOG.md.