Expand description
An implementation of Binn - https://github.com/liteserver/binn
Project
- License: GNU Lesser General Public License, either version 3, or (at your option) any later version.
- This project follows Semantic Versioning 2.0.0
Features
- All official types are supported.
- User defined types are not yet supported.
Notes
IR
stands for implementation in Rust.- Documentation is built with all features. Some of them are optional. If you see components from other crates, you can view source to see what features are required.
Security notes
To prevent attacks when decoding from Read
, consider limiting your source via Read::take()
.
Quick examples
This example demonstrates a simple file container:
use binn_ir::{Blob, Decoder, Encoder, Map, Value};
const MAGIC_NUMBER: u64 = 0xABCD;
// Buffer
let mut buf: Vec<u8> = vec![];
// Magic number
buf.encode_u64(MAGIC_NUMBER)?;
// A single file header contains: name and hash
let mut file_header = binn_ir::map();
file_header.map_insert(0, "the-sun")?; // name
file_header.map_insert(1, 0_u64)?; // hash
let file_content = Value::Blob(b"is hot".to_vec());
// Encode data
file_header.encode(&mut buf)?;
file_content.encode(&mut buf)?;
// Now decode data back
let mut cursor = std::io::Cursor::new(buf);
assert_eq!(cursor.decode_u64()?, Some(MAGIC_NUMBER));
assert_eq!(cursor.decode_map()?, Some(Map::try_from(file_header)?));
assert_eq!(cursor.decode_blob()?, Some(Blob::try_from(file_content)?));
assert_eq!(cursor.decode()?, None);
Thanks
Special thanks to Binn’s authors for their hard work.
Thank you,
Modules
Structs
Error
Enums
Values
Constants
Crate code name
ID of this crate
Crate name
Crate release date (year/month/day)
Tag, which can be used for logging…
Crate version
Traits
Functions
Makes new blob
Makes new blob with capacity
Decodes a value from source
Decodes a
Blob
Decodes a boolean value
Decodes a
Date
Decodes a
DateTime
Decodes a
DecimalStr
Decodes a
Double
valueDecodes a
Float
valueDecodes an
i8
valueDecodes an
i16
valueDecodes an
i32
valueDecodes an
i64
valueDecodes a
List
Decodes a
Map
Decodes a
Null
Decodes an
Object
Decodes a
Text
Decodes a
Time
Decodes a
u8
valueDecodes a
u16
valueDecodes a
u32
valueDecodes a
u64
valueEncodes a value
Encodes a
Blob
Encodes a
Date
Encodes a
DateTime
Encodes a
DecimalStr
Encodes a
Double
Encodes a
Float
Encodes an
I16
Encodes an
I32
Encodes an
I64
Encodes a
List
Encodes a
Map
Encodes a
Null
Encodes an
Object
Encodes a
Text
Encodes a
Time
Encodes a
U16
Encodes a
U32
Encodes a
U64
Makes new list
Makes new list with capacity
Makes new map
Makes new map from one pair of key/value
Inserts new item into a map
Makes new object
Makes new object from one pair of key/value
Inserts new item into an object
Pushes new value into a list