MCPcopy Index your code
hub / github.com/SoftbearStudios/bitcode

github.com/SoftbearStudios/bitcode @0.6.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.6.0 ↗ · + Follow
551 symbols 1,275 edges 43 files 67 documented · 12%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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);

Library Example

Add bitcode to libraries without specifying the major version so binary crates can pick the version. This is a minimal stable subset of the bitcode API so avoid using any other functionality.

bitcode = { version = "0", features = ["derive"], default-features = false, optional = true }
#[cfg_attr(feature = "bitcode", derive(bitcode::Encode, bitcode::Decode))]
pub struct Vec2 {
    x: f32,
    y: f32,
}

Tuple vs Array

If you have multiple values of the same type: - Use a tuple or struct when the values are semantically different: x: u32, y: u32 - Use an array when all values are semantically similar: pixels: [u8; 16]

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

License

Licensed under either of * Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0) * MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)

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.

Extension points exported contracts — how you extend this code

Buffer (Interface)
TODO pick different name because it aliases with [`crate::buffer::Buffer`]. [15 implementers]
src/coder.rs
Encode (Interface)
A type which can be encoded to bytes with [`encode`]. Use `#[derive(Encode)]` to implement. [15 implementers]
src/derive/mod.rs
SizedUInt (Interface)
A [`SizedInt`] that is unsigned. [5 implementers]
src/pack_ints.rs
PushUnchecked (Interface)
(no doc) [3 implementers]
src/fast.rs
Byte (Interface)
(no doc) [2 implementers]
src/pack.rs
Derive (Interface)
(no doc) [2 implementers]
bitcode_derive/src/shared.rs
NonStaticAny (Interface)
(no doc) [1 implementers]
src/buffer.rs
Len (Interface)
(no doc) [1 implementers]
src/length.rs

Core symbols most depended-on inside this repo

len
called by 66
src/fast.rs
collect
called by 45
src/serde/ser.rs
as_slice
called by 31
src/fast.rs
clear
called by 23
src/fast.rs
write
called by 19
src/pack.rs
err
called by 15
src/error.rs
push_unchecked
called by 12
src/fast.rs
as_ptr
called by 10
src/fast.rs

Shape

Method 264
Function 179
Class 71
Interface 19
Enum 18

Languages

Rust100%

Modules by API surface

src/fast.rs51 symbols
src/serde/ser.rs46 symbols
src/serde/de.rs38 symbols
src/pack_ints.rs31 symbols
src/pack.rs31 symbols
src/derive/mod.rs24 symbols
src/buffer.rs22 symbols
src/benches.rs20 symbols
src/length.rs19 symbols
src/str.rs15 symbols
src/derive/vec.rs15 symbols
src/derive/variant.rs15 symbols

For agents

$ claude mcp add bitcode \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact