#buffer #binary #better #b3 #type #item-key

nightly no-std b3-rs

A Rust implementation of B3 (Better Binary Buffers)

4 releases

0.1.0 Jul 6, 2020
0.1.0-alpha.2 Jul 5, 2020
0.0.0 Jul 3, 2020

#1926 in Encoding

MIT license

60KB
1.5K SLoC

b3-rs

A Rust implementation of B3 (Better Binary Buffers).

This library is in very early stages of development! There is no guarantee of API stability until we reach v1.0.0.

Parts of this library are heavily based on the original Python B3 implementation.

Usage

use b3_rs::{Item, ItemKey, ItemValue};

// Creating an item for a simple type
let string_item = Item::from("item value").with_key(ItemKey::from("item key"));
let integer_item = Item::from(123456u64).with_key(ItemKey::from(0u64));

// Creating an item collection
let dict_item = Item::new(
    ItemKey::NoKey,
    ItemValue::CompositeDict(
        vec![string_item, integer_item]
    ),
);

// Encoding items into the wire format
let encoded = dict_item.encode()?;

// Decoding items from the wire format
let (decoded, byte_count) = Item::decode(&encoded)?;
assert_eq!(byte_count, encoded.len());
assert_eq!(dict_item, decoded);

Caveats

Unimplemented item types

The following item types are currently unimplemented:

  • Decimal (type 10)
  • Sched (type 13)
  • Complex (type 16)

The error b3_rs::Error::UnimplementedB3TypeError will be returned when a message contains any of these types.

References

License

The code in this project is licensed under the MIT license. See the LICENSE file in the root of the repository for more information.

Dependencies

~67KB