https://github.com/SoftbearStudios/bitcode
A binary encoder/decoder for Rust
https://github.com/SoftbearStudios/bitcode
rust rust-lang serde serialization
Last synced: 3 months ago
JSON representation
A binary encoder/decoder for Rust
- Host: GitHub
- URL: https://github.com/SoftbearStudios/bitcode
- Owner: SoftbearStudios
- License: mit
- Created: 2023-04-16T02:04:20.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-06-10T13:03:38.000Z (4 months ago)
- Last Synced: 2025-07-11T13:48:50.520Z (3 months ago)
- Topics: rust, rust-lang, serde, serialization
- Language: Rust
- Homepage: https://crates.io/crates/bitcode/
- Size: 280 KB
- Stars: 487
- Watchers: 8
- Forks: 32
- Open Issues: 31
-
Metadata Files:
- Readme: README.md
- License: LICENSE-MIT
Awesome Lists containing this project
README
# Bitcode
[](https://docs.rs/bitcode)
[](https://crates.io/crates/bitcode)
[](https://github.com/SoftbearStudios/bitcode/actions/workflows/build.yml)A binary encoder/decoder with the following goals:
- 🔥 Blazingly fast
- 🐁 Tiny serialized size
- 💎 Highly compressible by Deflate/LZ4/ZstdIn contrast, these are non-goals:
- Stable format across major versions
- Self describing format
- Compatibility with languages other than RustSee [rust_serialization_benchmark](https://github.com/djkoloski/rust_serialization_benchmark) for benchmarks.
## Example
```rust
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 = bitcode::encode(&original); // No error
let decoded: Foo<'_> = bitcode::decode(&encoded).unwrap();
assert_eq!(original, decoded);
```## Adding Support for Libraries
See the instructions [here](https://github.com/SoftbearStudios/bitcode/wiki/Adding-library-support)!
## Implementation Details
- Heavily inspired by
- 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](https://github.com/SoftbearStudios/bitcode/wiki/Serde) to learn more.## `#![no_std]`
All `std`-only functionality is gated behind the (default) `"std"` feature.`alloc` is required.
## License
Licensed under either of
* Apache License, Version 2.0
([LICENSE-APACHE](LICENSE-APACHE) or )
* MIT license
([LICENSE-MIT](LICENSE-MIT) or )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.