Crate binn_ir[][src]

An implementation of https://github.com/liteserver/binn

Project


Features

  • All official types are supported.
  • User defined types are not yet supported.

Notes

  • #![no_std] might be supported when alloc crate is stabilized.
  • IR stands for implementation in Rust.
  • Core encoder and decoder are almost done (except ones for user defined types). However API might change, as the project is still in early development phase.
  • There is absolutely no plan to support secure encoder/decoder via cryptography. The author considers that another field for experts.
  • However, simple API for safe encoder/decoder will be supported. For example: option to limit container size to be decoded...

Quick examples

Most functionalities are provided via 2 traits: Encoder, Decoder.

This example demonstrates a simple file container:

extern crate binn_ir;

use std::collections::HashMap;
use std::io::Cursor;

use binn_ir::value::{Value, Encoder, Decoder};

const MAGIC_NUMBER: u64 = 0xABCD;

// Buffer
let mut buf: Vec<u8> = vec![];

// Magic number
buf.encode_u64(MAGIC_NUMBER).unwrap();

// A single file header contains: name and hash
let file_header = {
    let mut map = HashMap::new();
    map.insert(String::from("name"), Value::from("sun"));
    map.insert(String::from("hash"), Value::U64(0));
    map
};
let file_content = "is hot";

// Write data (using ::clone() to use the variable later in assertions)
buf.encode_object(file_header.clone());
buf.encode_blob(file_content.as_bytes());

// Now read data back
let mut cursor = Cursor::new(&buf);
assert_eq!(cursor.decode_u64().unwrap(), MAGIC_NUMBER);
assert_eq!(cursor.decode_object().unwrap(), file_header);
assert_eq!(cursor.decode_blob().unwrap(), file_content.as_bytes());
assert_eq!(cursor.position(), buf.len() as u64);

Special thanks to Binn's authors for their hard work.

Modules

storage

Storages

value

Values

Constants

CRATE_CODE_NAME

Crate code name

CRATE_NAME

Crate name

CRATE_RELEASE_DATE

Crate release date (year/month/day)

CRATE_VERSION

Crate version

TAG

Tag, which can be used for logging...

UUID

Unique universally identifier of this crate. Its CRC-32 is 149dc8a5.