Expand description
§pack-io
Compact binary wire format for Rust. Combines speed, schema evolution, and zero-copy deserialization under a single coherent contract.
§At a glance (v0.3.0)
- Tier 1 —
encodeanddecode: one line each direction. - Tier 2 —
Encoder/Decoderfor in-memory buffers.IoEncoder/IoDecoderforstd::io::Write/Readstreams (std-gated).encode_into/decode_fromconvenience helpers over Read/Write.
- Tier 3 — implement
Serialize/Deserializeon your own types. Both traits are generic over theEncode/Decodebehaviour traits, so one impl works through every encoder / decoder the crate ships.
§Primitive support
Integers (u8 … u128, i8 … i128, usize / isize), bool,
f32, f64, String / &str, fixed-size arrays [T; N], tuples of
arity 1…12, Option<T>, Result<T, E>, and ().
§Collection support (new in v0.3)
Vec<T> / &[T], BTreeMap<K, V>, BTreeSet<T>, and (with the default
std feature) HashMap<K, V> and HashSet<T>. Hash-based collections
encode in canonical key-sorted order so that hashing, signing, or
content-addressing the output is safe regardless of insertion order or
hash randomisation.
§Wire-format freeze
Starting at v0.3.0 the wire format is frozen for the 1.x line.
See docs/WIRE_FORMAT.md
for the normative byte-level spec.
§Quick start
use pack_io::{encode, decode};
let bytes = encode(&(7_u64, true, String::from("hello"))).unwrap();
let back: (u64, bool, String) = decode(&bytes).unwrap();
assert_eq!(back, (7, true, String::from("hello")));§Invariants
- Round-trip integrity —
decode(encode(v)) == vfor every supported type, under any input. - Determinism — the same value always produces the same bytes, regardless of insertion order, platform, or build flags.
- Safe decode — no panic, no unbounded allocation, no read past the input, on any byte sequence.
- Wire-format stability — frozen at
0.3.0; any1.xdecoder reads any1.x-or-earlier encoding.
§no_std
pack-io is no_std-capable. The default build enables std for the
std::error::Error impl, HashMap / HashSet integration, and the
io module. Disable the default feature to compile against core +
alloc only:
pack-io = { version = "0.3", default-features = false }Re-exports§
pub use crate::io::IoDecoder;stdpub use crate::io::IoEncoder;stdpub use crate::io::decode_from;stdpub use crate::io::encode_into;std
Modules§
- io
std std::io::Read/std::io::Writeintegration: the streaming Tier-2 encoder and decoder pair, plus convenience free functions.
Structs§
- Config
- Configuration for a decode session.
- Decoder
- In-memory decoder. Borrows from an input slice and advances a position pointer as values are read. Bounds-checked on every operation.
- Encoder
- In-memory encoder. Writes into an owned
Vec<u8>; the buffer can be reused across encodes by callingEncoder::taketo swap it out.
Enums§
- Serial
Error - Every error returned by the codec.
Constants§
- VERSION
- Semantic version of this crate, as declared in
Cargo.toml.
Traits§
- Decode
- Source that a
Deserializeimplementation reads its wire-format bytes from. - Deserialize
- Types that know how to read themselves from any
Decodesource. - Encode
- Sink that a
Serializeimplementation writes its wire-format bytes into. - Serialize
- Types that know how to write themselves into any
Encodesink.
Functions§
- decode
- Decode a value of type
Tfrombytes, requiring the input to be fully consumed. - encode
- Encode
valueinto a freshly allocatedVec<u8>.
Type Aliases§
- Result
- Convenience alias for
Result<T, SerialError>.