Bincode-Next

Bincode-Next is a high-performance binary encoder/decoder pair that uses a zero-fluff encoding scheme. It is a modernized fork of the original bincode library, maintained by the Apich Organization to ensure continued development and extreme performance optimizations for the Rust ecosystem.

The size of the encoded object will be the same or smaller than the size that the object takes up in memory in a running Rust program.

Key Features

Getting Started

Add bincode-next to your Cargo.toml:

Basic Encode / Decode


Serde Compatibility

Bincode-Next works with any type that already derives serde::Serialize / serde::Deserialize — no need to re-derive Encode/Decode at all. Enable the serde feature and use the bincode_next::serde::* entry points.

You can also mix: derive both Serialize and Encode on the same type, then use #[bincode(with_serde)] on individual fields to route specific fields through their serde impl (useful for types that only implement Serialize, not Encode).


Bit-Packing

Enable bit-packing in your configuration to pack fields at bit granularity. Consecutive #[bincode(bits = N)] fields share bytes — 3 bits + 5 bits = exactly 1 byte on the wire.


Zero-Copy Structures

The zero-copy feature lets you build flat byte blobs that can be accessed as typed Rust references without any deserialization step — ideal for memory-mapped files, shared memory, and IPC.

#[derive(ZeroCopy)] on a #[repr(C, u8)] enum generates a companion *Builder type that mirrors every variant. Use ZeroBuilder to accumulate bytes, reserve::<T>() to claim space, and build_to_target() to write and get back a live typed reference directly into the buffer.

For lower-level use, RelativePtr<T, OFFSET_SIZE> lets you embed self-relative pointers inside any #[repr(C)] struct:


Compile-time Memory Bounds (StaticSize)

StaticSize gives a compile-time upper bound on encoded size — useful for stack allocation and no_std fixed-size buffers. Enable with the static-size feature.

MAX_SIZE assumes worst-case varint encoding; PACKED_MAX_SIZE is tighter when bit-packing is active (consecutive #[bincode(bits = N)] fields share bytes).


Schema Fingerprinting

Fingerprinting embeds a 64-bit schema hash into each encoded message. The hash covers field names, types, ordering, and the full configuration — including format (Bincode vs CBOR), endianness, integer encoding, and all CBOR options. Any mismatch between encoder and decoder returns a DecodeError::SchemaHashMismatch.


CBOR Format

Bincode-Next implements full RFC 8949 CBOR encoding. Switch formats with a single config call; all existing derives work unchanged.


Async Fiber Decoding

Bincode-Next supports true zero-cost asynchronous decoding using Unified Fiber-backed Async (UFA). Synchronous Decode traits run on a dedicated lightweight fiber stack, avoiding state-machine code generation overhead entirely.


Performance Optimizations

Bincode-Next includes advanced optimizations for extreme performance:

TL;DR: Please visit https://bincode-next.apich.org/bench.html for more detailed information.

CBOR Encoding & Decoding

ImplementationEncode (µs)Relative Speed (Enc)Decode (µs)Relative Speed (Dec)
bincode-next5.641.00x30.471.00x
bincode-next (det.)5.681.01x30.491.00x
minicbor9.361.66x41.421.36x
cbor4ii11.982.12x63.542.09x

Complex World Benchmarks

Baseline: bincode-next (fixed) for encoding, bincode-next (varint) for decoding.

ImplementationEncode (µs)Rel. SpeedDecode (µs)Rel. Speed
bincode-next (fixed)3.231.00x20.631.10x
bincode-next (varint)3.441.07x18.741.00x
bincode-v1 (serde)3.311.02x18.961.01x
bincode-v2 (fixed)3.431.06x18.711.00x
bincode-v2 (varint)4.221.31x25.001.33x
bincode-next (cbor)5.991.85x24.821.32x
bincode-next (cbor-det)6.011.86x24.681.32x

Postcard Comparison

ImplementationEncode (µs)Rel. Speed (Enc)Decode (µs)Rel. Speed (Dec)
bincode-next (fixed)3.581.00x25.031.00x
bincode-next (varint)5.061.41x25.491.02x
postcard8.382.34x30.961.24x

About Security and Code Quality

For security issues, please visit the Security Team Homepage for more details on reporting.

All code tests passed miri and all main crate source code passed clippy without errors.

We remain committed to code security and welcomed security reporting.

And please notice that contributors shall follow the community guide lines of bincode-next.

Specification

The formal wire-format specification is available in docs/spec.html.

FAQ

Why Bincode-Next?

Bincode-Next was created to continue the legacy of the original Bincode project while pushing the boundaries of what's possible with modern Rust performance techniques and AI-assisted development.

Is it compatible with Bincode 1.x / 2.x?

Yes, Bincode-Next is designed to be wire-compatible with Bincode 2.x when using the same configurations. It also supports legacy 1.x formats via configuration.

Contributing

We welcome contributions! Please see CONTRIBUTING.html for more details.

License

Bincode-Next is licensed under either of:

See LICENSE.html for details.