Expand description
RustBinary is a bounded Serde binary codec with explicit wire profiles.
The top-level functions and options select the strict compact profile:
canonical marker varints, ZigZag signed integers, bounded input, and rejected
trailing bytes. legacy_options explicitly selects the old fixed-width,
unbounded migration profile. Format-changing
systems are explicit wrappers, so enabling a Cargo feature never silently
changes an existing payload.
§Quick start
use serde::{Deserialize, Serialize};
#[derive(Debug, PartialEq, Serialize, Deserialize)]
struct Packet<'a> {
sequence: u64,
topic: &'a str,
#[serde(borrow)]
payload: &'a [u8],
}
let config = rustbinary::options()
.with_limit(4096)
.with_collection_limit(256);
let packet = Packet {
sequence: 42,
topic: "telemetry/temperature",
payload: b"23.5",
};
let mut frame = [0_u8; 128];
let written = config.serialize_into_slice(&mut frame, &packet)?;
let decoded: Packet<'_> = config.deserialize(&frame[..written])?;
assert_eq!(decoded, packet);Borrowed strings and byte slices point into the input frame. Owned targets
such as String and Vec<T> may allocate as required by their type.
§Format selection
Configis the core binary profile.adaptivecontains canonical cost-selected string and integer frames.bitpackprovides generated bit-level layouts.cborprovides RFC 8949 payloads and deterministic map ordering.evolutionprovides stable-field-ID schema evolution.compressionandencryptionform an ordered transform pipeline.parallelencodes independent records into deterministic batch frames.
§Untrusted input
Always set both Config::with_limit and
Config::with_collection_limit at trust boundaries. Encryption authenticates
bytes but does not replace resource limits. Schema fingerprints detect
accidental type/configuration drift; they are not cryptographic hashes.
Re-exports§
pub use adaptive::AdaptiveConfig;adaptivepub use adaptive::CollectionStrategy;adaptivepub use adaptive::StringStrategy;adaptivepub use bitpack::BitPack;bit-packingpub use bitpack::BitPackedConfig;bit-packingpub use bitpack::BitReader;bit-packingpub use bitpack::BitValue;bit-packingpub use bitpack::BitWriter;bit-packingpub use cbor::CborConfig;cborpub use cbor::FingerprintedCborConfig;cborandfingerprintpub use compression::CompressedConfig;compressionpub use config::Config;pub use config::Endian;pub use config::IntEncoding;pub use config::Options;pub use config::TrailingBytes;pub use config::DEFAULT_COLLECTION_LIMIT;pub use config::DEFAULT_SIZE_LIMIT;pub use encryption::EncryptedConfig;encryptionpub use encryption::EncryptionKey;encryptionpub use error::Error;pub use error::ErrorCategory;pub use error::Result;pub use evolution::EvolutionConfig;schema-evolutionpub use evolution::FieldDecoder;schema-evolutionpub use evolution::FieldEncoder;schema-evolutionpub use evolution::SchemaDecode;schema-evolutionpub use evolution::SchemaEncode;schema-evolutionpub use evolution::UnknownField;schema-evolutionpub use parallel::ParallelConfig;parallelpub use reflection::FieldInfo;reflectionpub use reflection::Reflect;reflectionpub use reflection::TypeShape;reflectionpub use reflection::VariantInfo;reflectionpub use schema::Fingerprint;fingerprintpub use schema::FingerprintedConfig;fingerprintpub use simd::hardware_capabilities;simdpub use simd::simd_backend;simdpub use simd::HardwareCapabilities;simdpub use simd::SimdBackend;simdpub use static_size::StaticSize;static-sizepub use writer::CountWriter;pub use writer::EncodeWriter;pub use writer::SliceWriter;
Modules§
- adapters
std - Bridges between the slice-based core and
std::ioreaders and writers. Standard-library adapters around theno_stdCompact V1 core. - adaptive
adaptive - Canonical data-aware encodings for strings and integer collections.
- bitpack
bit-packing - Bit-level caller-buffer codecs and the
BitPackcontract. - cbor
cbor - RFC 8949 CBOR configuration and deterministic encoding.
- compression
compression - Adaptive Zstandard framing.
- config
- Core wire-profile configuration.
- core
- Minimal stable binary codec product surface. Minimal stable binary format and resource-policy API.
- encryption
encryption - Authenticated XChaCha20-Poly1305 framing.
- error
- Codec result and error types.
- evolution
schema-evolution - Stable-field-ID schema evolution.
- parallel
parallel - Ordered multi-core batch encoding and decoding.
- pipeline
- Optional transform product surface. Opt-in CBOR, compression, encryption, and parallel transform APIs.
- protocol
- Schema and wire-governance product surface. Opt-in schema, compatibility, and compact-layout governance APIs.
- reflection
reflection - Allocation-free structural metadata generated by
Reflect. - schema
fingerprint - Compile-time schema identity and fingerprinted frame support.
- simd
simd - Runtime-dispatched SIMD primitives used by codec hot paths.
- static_
size static-size - Compile-time upper bounds for statically sized data.
- writer
- Core output sinks for caller-owned and counting serialization.
Functions§
- deserialize
- Deserializes from a slice with the bounded compact Core profile.
- deserialize_
from std - Deserializes an owned value from a reader with the bounded compact Core profile.
- legacy_
options - Returns the fixed-width compatibility profile used by the top-level API.
- options
- Returns the standard compact profile.
- serialize
alloc - Serializes a value with the bounded compact Core profile.
- serialize_
into std - Serializes a value directly into a writer with the bounded compact Core profile.
- serialize_
into_ slice - Serializes into a caller-owned slice without codec-owned heap allocation.
- serialized_
size - Computes the exact serialized byte count without allocating an output buffer.
Derive Macros§
- BitPacked
bit-packingandderive - Derives
rustbinary::BitPackfor structs and enums. - Fingerprint
deriveandfingerprint - Derives
rustbinary::Fingerprintfrom structural type metadata. - Reflect
deriveandreflection - Derives allocation-free structural reflection metadata.
- Static
Size deriveandstatic-size - Derives compile-time normal and bit-packed size bounds.