A binary encoder/decoder for Rust
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Balazs Horvath 18f3bb551f Move arrayvec, glam, uuid and the derive macro deps onto the Sly Pact
Un-pins four dependencies so they follow their forks' default branches instead
of a registry version that will drift from them. glam gains scalar-math, which
the fork needs and the registry release did not expose under this feature set.

Verified with the default feature set: 69 tests pass. The opt-in
unstable_bench feature does not build, for two independent reasons, both
recorded in the follow-up todo rather than papered over here -- rand_chacha was
never a declared dependency so that feature was already broken, and lz4_flex
0.14 moved compress_prepend_size behind alloc and deprecated it, which the
default-features = false dev-dependency hides.
2026-10-04 11:57:41 +02:00
.cargo Bitcode rewrite (#19) 2024-03-15 21:10:27 -07:00
bitcode_derive Move arrayvec, glam, uuid and the derive macro deps onto the Sly Pact 2026-10-04 11:57:41 +02:00
fuzz chore: sync dependencies (monorepo) 2026-04-07 18:06:05 +02:00
src chore: sync dependencies (monorepo) 2026-04-04 22:33:22 +02:00
.gitignore Bitcode rewrite (#19) 2024-03-15 21:10:27 -07:00
Cargo.toml Move arrayvec, glam, uuid and the derive macro deps onto the Sly Pact 2026-10-04 11:57:41 +02:00
LICENSE-MIT Initial commit. 2023-04-15 21:33:51 -07:00
README.md chore: sync dependencies (monorepo) 2026-03-26 16:24:06 +01:00

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.