> ## Documentation Index
> Fetch the complete documentation index at: https://docs.apich.org/llms.txt
> Use this file to discover all available pages before exploring further.

# bincode-next

> High-performance binary serialization for Rust with SIMD varints, zero-copy relative pointers, bit-packing, schema fingerprints, and CBOR.

**bincode-next** is the actively maintained continuation of `bincode` on Rust edition 2024: a compact, zero-fluff binary encoder and decoder pair with no field names or padding on the wire.

> [!NOTE]
>
> For complete trait signatures, migration guides from `bincode` 1.x/2.x, and wire specification details, refer to [docs.rs/bincode-next](https://docs.rs/bincode-next) and [docs/spec.md](https://github.com/Apich-Organization/bincode/blob/main/docs/spec.md).

> [card] [Full API Reference](https://docs.rs/bincode-next)
>
> Generated rustdoc for `bincode-next` and `bincode_derive-next`.

> [card] [Project Homepage](https://apich.org/projects/bincode/)
>
> Format overview, feature matrix, and Open Collective budget on apich.org.

> [card] [GitHub Repository](https://github.com/Apich-Organization/bincode)
>
> Source code, `docs/spec.md`, `docs/migration_guide.md`, and compatibility tests.

> [card] [Figshare DOI](https://doi.org/10.6084/m9.figshare.31410402)
>
> Persistent citation (`10.6084/m9.figshare.31410402`) and OpenSSF Best Practices.

## Architecture & Layered Capabilities

`bincode-next` separates its core `no_std` codec from optional std/alloc, SIMD, zero-copy, and async-fiber layers. Every encode/decode call takes an explicit `Configuration` value so the wire format is always a property of the call site.

```mermaid theme={null}
flowchart LR
    Core["Core Codec (no_std, Encode / Decode, Configuration)"] --> Varint["SIMD Varints (SSE2 x86_64 · NEON AArch64)"]
    Core --> ZeroCopy["zero-copy (ZeroBuilder · RelativePtr · DeepValidator)"]
    Core --> BitPack["BitPacked + static-size (MAX_SIZE / PACKED_MAX_SIZE)"]
    Core --> Fingerprint["64-bit Schema + Config Fingerprint"]
    Core --> CBOR["RFC 8949 CBOR + Deterministic Modes"]
    Core --> Async["async-fiber (UFA zero-cost async decoding)"]
```

## Repository Structure

| Path | Role |
| - | - |
| `src/enc/` & `src/de/` | `Encode`/`Decode` traits, `bit_writer`/`bit_reader`, `cbor`, `deterministic`, and `async_fiber` |
| `src/varint/` | SIMD varint scanning (SSE2 on `x86_64`, NEON on `AArch64`) |
| `src/config.rs` & `src/fingerprint.rs` | Explicit `Configuration` builders and 64-bit schema + config hashing |
| `src/features/` | Feature-gated `std`, `alloc`, `serde`, `zero-copy`, `static-size`, and `bounded` modules |
| `derive/` (`bincode_derive-next`) | Derive macros (`Encode`, `Decode`, `BitPacked`, `Fingerprint`, `StaticSize`, `ZeroCopy`) built on `virtue-next` |
| `compatibility/` | Cross-version wire compatibility tests against `bincode` 1.x (`config::legacy()`) and 2.x |

## Cargo Features at a Glance

| Feature | Default | What It Enables |
| - | - | - |
| `std` / `alloc` | Yes (`std`) | `std::io` reader/writer streams and `alloc` owned containers (`no_std` when disabled) |
| `derive` | Yes | Procedural derives via `bincode_derive-next` |
| `simd` | Yes | Hardware-accelerated varint scanning on `x86_64` and `AArch64` |
| `zero-copy` | No | `#[derive(ZeroCopy)]`, `ZeroBuilder`, `RelativePtr`, and `DeepValidator` |
| `static-size` | No | Compile-time `MAX_SIZE` and `PACKED_MAX_SIZE` bounds for stack/embedded buffers |
| `serde` | No | `bincode_next::serde::*` entry points and `#[bincode(with_serde)]` field routing |
| `async-fiber` | No | Zero-cost async decoding via Unified Fiber-backed Async (UFA) |

## Quick Example

```rust Bit-Packing + Fingerprinting theme={null}
use bincode_next::{config, BitPacked, Fingerprint, StaticSize};

#[derive(BitPacked, StaticSize, Fingerprint, PartialEq, Debug)]
struct Telemetry {
    #[bincode(bits = 1)]
    is_active: bool,
    #[bincode(bits = 1)]
    has_error: bool,
    #[bincode(bits = 3)]
    mode: u8,
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let cfg = config::standard().with_bit_packing().with_fingerprint();
    let t = Telemetry { is_active: true, has_error: false, mode: 5 };

    let bytes = bincode_next::encode_to_vec(&t, cfg)?;
    let (decoded, _): (Telemetry, usize) = bincode_next::decode_from_slice(&bytes, cfg)?;
    assert_eq!(decoded, t);
    Ok(())
}
```

```rust Zero-Copy Packet theme={null}
use bincode_next::{ZeroBuilder, ZeroCopyBuilder};

#[derive(bincode_derive_next::ZeroCopy, Debug, PartialEq, Eq)]
#[repr(C, u8)]
enum Packet {
    Ping,
    Data { seq: u32, value: u64 },
}

fn main() {
    let mut builder = ZeroBuilder::new();
    let offset = builder.reserve::<Packet>();
    let view = PacketBuilder::Data { seq: 7, value: 0xDEAD_BEEF }
        .build_to_target(&mut builder, offset);
    assert!(matches!(view, Packet::Data { seq: 7, .. }));
}
```


## Related topics

- [Stack Architecture & Project Map](https://docs.apich.org/guides/architecture.md)
- [virtue](https://docs.apich.org/projects/virtue.md)
- [Quickstart](https://docs.apich.org/quickstart.md)
- [Security Policy & Release Standards](https://docs.apich.org/guides/security-and-releases.md)
- [Apich Organization Documentation](https://docs.apich.org/index.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.