1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
//! Rust implementation of [B3 (Better Binary Buffers)][b3]. //! //! Parts of this library are heavily based on the original Python B3 //! implementation. //! //! [b3]: https://github.com/oddy/b3 //! //! # Usage //! //! ``` //! # use b3_rs::*; //! # fn main() -> Result<(), b3_rs::Error> { //! // 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); //! //! # Ok(()) //! # } //! ``` //! //! # Caveats //! //! ## Unimplemented item types //! //! The following item types are currently unimplemented: //! //! - [`datatypes::KnownType::Decimal`] (type 10) //! - [`datatypes::KnownType::Sched`] (type 13) //! - [`datatypes::KnownExtendedType::Complex`] (type 16) //! //! [`Error::UnimplementedB3TypeError`] will be returned when a message //! contains any of these types. #![cfg_attr(not(feature = "std"), no_std)] #![feature(alloc_prelude)] #[cfg(feature = "std")] #[allow(unused_imports)] #[macro_use] extern crate std; #[cfg(feature = "std")] #[allow(unused_imports)] use std::prelude::v1 as alloc_prelude; #[cfg(not(feature = "std"))] #[allow(unused_imports)] #[macro_use] extern crate alloc; #[cfg(not(feature = "std"))] #[allow(unused_imports)] use alloc::prelude::v1 as alloc_prelude; mod error; pub use self::error::Error; pub mod datatypes; mod key; pub use self::key::ItemKey; mod value; pub use self::value::ItemValue; mod header; pub use self::header::ItemHeader; mod item; pub use self::item::Item;