15 releases

new 0.6.4 Feb 8, 2025
0.6.3 Jul 14, 2024
0.6.0 Mar 24, 2024
0.5.0 Oct 17, 2023
0.4.0 May 14, 2023

#13 in Compression

Download history 9328/week @ 2024-10-23 6665/week @ 2024-10-30 7816/week @ 2024-11-06 7912/week @ 2024-11-13 6733/week @ 2024-11-20 6506/week @ 2024-11-27 6653/week @ 2024-12-04 10070/week @ 2024-12-11 6667/week @ 2024-12-18 4335/week @ 2024-12-25 7782/week @ 2025-01-01 11683/week @ 2025-01-08 9917/week @ 2025-01-15 12362/week @ 2025-01-22 12752/week @ 2025-01-29 21831/week @ 2025-02-05

58,127 downloads per month
Used in 61 crates (41 directly)

MIT/Apache

275KB
7K 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

~0.1–1.2MB
~35K SLoC