#serialization #encode #field #decode #codec #benchmark #deserialize #auto-vectorized

macro bitcode_derive

Implementation of #[derive(Encode, Decode)] for bitcode

16 releases

0.6.9 Dec 18, 2025
0.6.7 Aug 13, 2025
0.6.5 Feb 20, 2025
0.6.3 Jul 14, 2024
0.1.4 May 14, 2023

#63 in #decode

Download history 29711/week @ 2026-03-03 238600/week @ 2026-03-10 175668/week @ 2026-03-17 175024/week @ 2026-03-24 175089/week @ 2026-03-31 213765/week @ 2026-04-07 207632/week @ 2026-04-14 224826/week @ 2026-04-21 253124/week @ 2026-04-28 149071/week @ 2026-05-05 163820/week @ 2026-05-12 224197/week @ 2026-05-19 227609/week @ 2026-05-26 229264/week @ 2026-06-02

867,763 downloads per month
Used in 10 crates (2 directly)

MIT/Apache

52KB
1K SLoC

Bitcode

Documentation crates.io Build

A binary encoder/decoder with the following goals:

  • 🔥 Blazingly fast
  • 🐁 Tiny serialized size
  • 💎 Highly compressible by Deflate/LZ4/Zstd

In contrast, these are non-goals:

  • Stable format across major versions
  • Self describing format
  • Compatibility with languages other than Rust

See rust_serialization_benchmark for benchmarks.

Example

use bitcode::{Encode, Decode};

#[derive(Encode, Decode, PartialEq, Debug)]
struct Foo<'a> {
    x: u32,
    y: &'a str,
}

let original = Foo {
    x: 10,
    y: "abc",
};

let encoded: Vec<u8> = bitcode::encode(&original); // No error
let decoded: Foo<'_> = bitcode::decode(&encoded).unwrap();
assert_eq!(original, decoded);

Adding Support for Libraries

See the instructions here!

Implementation Details

  • Heavily inspired by https://github.com/That3Percent/tree-buf
  • All instances of each field are grouped together making compression easier
  • Uses smaller integers where possible all the way down to 1 bit
  • Validation is performed up front on typed vectors before deserialization
  • Code is designed to be auto-vectorized by LLVM

serde

A serde integration is gated behind the "serde" feature flag. Click here to learn more.

#![no_std]

All std-only functionality is gated behind the (default) "std" feature.

alloc is required.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~88–425KB
~10K SLoC