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
Storages
Values
0.17.3 (February 14th, 2023)

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

Decoder
Encoder

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 Double value
Decodes a Float value
Decodes an i8 value
Decodes an i16 value
Decodes an i32 value
Decodes an i64 value
Decodes a List
Decodes a Map
Decodes a Null
Decodes a Text
Decodes a Time
Decodes a u8 value
Decodes a u16 value
Decodes a u32 value
Decodes a u64 value
Encodes a value
Encodes a Blob
Encodes a bool via True or False
Encodes a Date
Encodes an I8
Encodes an I16
Encodes an I32
Encodes an I64
Encodes a List
Encodes a Map
Encodes a Null
Encodes a Text
Encodes a Time
Encodes a U8
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

Type Definitions

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