Skip to main content

Crate rustbinary

Crate rustbinary 

Source
Expand description

RustBinary is a bounded Serde binary codec with explicit wire profiles.

The top-level functions retain a fixed-width migration profile. options selects the strict compact profile: canonical marker varints, ZigZag signed integers, bounded collections, and rejected trailing bytes. 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

  • Config is the core binary profile.
  • adaptive contains canonical cost-selected string and integer frames.
  • bitpack provides generated bit-level layouts.
  • cbor provides RFC 8949 payloads and deterministic map ordering.
  • evolution provides stable-field-ID schema evolution.
  • compression and encryption form an ordered transform pipeline.
  • parallel encodes 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;adaptive
pub use adaptive::CollectionStrategy;adaptive
pub use adaptive::StringStrategy;adaptive
pub use bitpack::BitPack;bit-packing
pub use bitpack::BitPackedConfig;bit-packing
pub use bitpack::BitReader;bit-packing
pub use bitpack::BitValue;bit-packing
pub use bitpack::BitWriter;bit-packing
pub use cbor::CborConfig;cbor
pub use cbor::FingerprintedCborConfig;cbor and fingerprint
pub use compression::CompressedConfig;compression
pub use config::Config;
pub use config::Endian;
pub use config::IntEncoding;
pub use config::Options;
pub use config::TrailingBytes;
pub use encryption::EncryptedConfig;encryption
pub use encryption::EncryptionKey;encryption
pub use error::Error;
pub use error::Result;
pub use evolution::EvolutionConfig;schema-evolution
pub use evolution::FieldDecoder;schema-evolution
pub use evolution::FieldEncoder;schema-evolution
pub use evolution::SchemaDecode;schema-evolution
pub use evolution::SchemaEncode;schema-evolution
pub use evolution::UnknownField;schema-evolution
pub use parallel::ParallelConfig;parallel
pub use reflection::FieldInfo;reflection
pub use reflection::Reflect;reflection
pub use reflection::TypeShape;reflection
pub use reflection::VariantInfo;reflection
pub use schema::Fingerprint;fingerprint
pub use schema::FingerprintedConfig;fingerprint
pub use simd::hardware_capabilities;simd
pub use simd::simd_backend;simd
pub use simd::HardwareCapabilities;simd
pub use simd::SimdBackend;simd
pub use static_size::StaticSize;static-size

Modules§

adaptiveadaptive
Canonical data-aware encodings for strings and integer collections.
bitpackbit-packing
Bit-level caller-buffer codecs and the BitPack contract.
cborcbor
RFC 8949 CBOR configuration and deterministic encoding.
compressioncompression
Adaptive Zstandard framing.
config
Core wire-profile configuration.
encryptionencryption
Authenticated XChaCha20-Poly1305 framing.
error
Codec result and error types.
evolutionschema-evolution
Stable-field-ID schema evolution.
parallelparallel
Ordered multi-core batch encoding and decoding.
reflectionreflection
Allocation-free structural metadata generated by Reflect.
schemafingerprint
Compile-time schema identity and fingerprinted frame support.
simdsimd
Runtime-dispatched SIMD primitives used by codec hot paths.
static_sizestatic-size
Compile-time upper bounds for statically sized data.

Functions§

deserialize
Deserializes from a slice with the legacy compatibility profile.
deserialize_from
Deserializes an owned value from a reader with the legacy profile.
legacy_options
Returns the fixed-width compatibility profile used by the top-level API.
options
Returns the standard compact profile.
serialize
Serializes a value with the legacy compatibility profile.
serialize_into
Serializes a value directly into a writer with the legacy 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§

BitPackedbit-packing and derive
Derives rustbinary::BitPack for structs and enums.
Fingerprintderive and fingerprint
Derives rustbinary::Fingerprint from structural type metadata.
Reflectderive and reflection
Derives allocation-free structural reflection metadata.
StaticSizederive and static-size
Derives compile-time normal and bit-packed size bounds.