Crate binn_ir

Source
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§

Decoder
Decoder
Encoder
Encoder

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 via True or False
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

Type Aliases§

Blob
Blob
IoResult
Result for I/O functions
List
List
Map
Map
MapKey
Map key
Object
Object
ObjectKey
Object key
Result
Result type used in this crate
Size
Size