Skip to content
TinyChain-IncPublic

About

Rust library for asynchronous stream (de)serialization

Resources

Contributing

Stars

28 stars

Watchers

1 watching

Forks

Latest commit

 

History

94 Commits

Folders and files

Repository files navigation

destream

Rust library for asynchronous stream (de)serialization.

Built-in fixed-length sequence visitors, including Duration, require exact cardinality and sequence completion. Invalid duration nanoseconds reject before completion validation.

Use FromStream, ToStream, and IntoStream for ordinary typed values; fixed-schema types can implement visitors and delegate their fields to these traits.

For data whose nesting is determined by input, use iterative traversal with an explicit frame stack. This avoids call-stack exhaustion through uncontrolled recursion (CWE-674). Depth and allocation limits remain necessary to bound heap usage and work. Recursive value owners must also make destruction and other structural operations stack-safe.

  • Decoding uses a container cursor: peek_kind, open_container, and finish_child let the owner drive its frame stack and delegate typed leaves through FromStream. Complete each child before advancing its cursor; discard the decoder after failed or interrupted traversal.
  • Encoding uses a pull-based structural event stream: encode_events consumes sequence/map starts, leaves, and container ends. For example, [[1], 2] emits SeqStart, SeqStart, Value(1), End, Value(2), End (size hints omitted). Event::Value delegates a leaf's ordinary encoding; recursive containers must be emitted as events. The codec retains one active leaf stream, accepting borrowed input without requiring Unpin or 'static.

Events describe traversal; stack safety comes from the iterative implementation. Arbitrary recursive visitors or leaf encoders do not become stack-safe automatically.

Each codec owns root/container validation, byte framing, and leaf encoding. inspect_any supplies structural observations without constructing decoded payloads; value owners supply allocation policy.

Encoder::encode_str accepts borrowed or owned AsRef<str> + Send inputs for the encoding lifetime, including &str, String, and shared strings. An encoder may retain the input without copying it. collect_str instead formats immediately; its input need not outlive the returned stream, and formatting errors are returned synchronously. Its default implementation owns the formatted text; codecs may format directly into their output buffer.

Encoder output is format-specific: Encoder::Ok and the container builders' matching output types may be streams, futures, or completed values. Generic consumers that poll output as a stream declare that bound explicitly; input streams and structural events remain pull-driven.

About

Rust library for asynchronous stream (de)serialization

Resources

Contributing

Stars

28 stars

Watchers

1 watching

Forks

Sponsor this project

Used by

Contributors

Languages