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§
- specification
- Specification
- storage
- Storages
- value
- Values
- version_
info 0.17.3
(February 14th, 2023)
Structs§
- Error
- Error
Enums§
- Value
- Values
Constants§
- CODE_
NAME - Crate code name
- ID
- ID of this crate
- NAME
- Crate name
- RELEASE_
DATE - Crate release date (year/month/day)
- TAG
- Tag, which can be used for logging…
- VERSION
- Crate version
Traits§
Functions§
- blob
- Makes new blob
- blob_
with_ capacity - Makes new blob with capacity
- decode
- Decodes a value from source
- decode_
blob - Decodes a
Blob
- decode_
bool - Decodes a boolean value
- decode_
date - Decodes a
Date
- decode_
date_ time - Decodes a
DateTime
- decode_
decimal_ str - Decodes a
DecimalStr
- decode_
double - Decodes a
Double
value - decode_
float - Decodes a
Float
value - decode_
i8 - Decodes an
i8
value - decode_
i16 - Decodes an
i16
value - decode_
i32 - Decodes an
i32
value - decode_
i64 - Decodes an
i64
value - decode_
list - Decodes a
List
- decode_
map - Decodes a
Map
- decode_
null - Decodes a
Null
- decode_
object - Decodes an
Object
- decode_
text - Decodes a
Text
- decode_
time - Decodes a
Time
- decode_
u8 - Decodes a
u8
value - decode_
u16 - Decodes a
u16
value - decode_
u32 - Decodes a
u32
value - decode_
u64 - Decodes a
u64
value - encode
- Encodes a value
- encode_
blob - Encodes a
Blob
- encode_
bool - Encodes a
bool
viaTrue
orFalse
- encode_
date - Encodes a
Date
- encode_
date_ time - Encodes a
DateTime
- encode_
decimal_ str - Encodes a
DecimalStr
- encode_
double - Encodes a
Double
- encode_
float - Encodes a
Float
- encode_
i8 - Encodes an
I8
- encode_
i16 - Encodes an
I16
- encode_
i32 - Encodes an
I32
- encode_
i64 - Encodes an
I64
- encode_
list - Encodes a
List
- encode_
map - Encodes a
Map
- encode_
null - Encodes a
Null
- encode_
object - Encodes an
Object
- encode_
text - Encodes a
Text
- encode_
time - Encodes a
Time
- encode_
u8 - Encodes a
U8
- encode_
u16 - Encodes a
U16
- encode_
u32 - Encodes a
U32
- encode_
u64 - Encodes a
U64
- list
- Makes new list
- list_
with_ capacity - Makes new list with capacity
- map
- Makes new map
- map_
from - Makes new map from one pair of key/value
- map_
insert - Inserts new item into a map
- object
- Makes new object
- object_
from - Makes new object from one pair of key/value
- object_
insert - Inserts new item into an object
- push
- Pushes new value into a list