20 releases (breaking)

✓ Uses Rust 2018 edition

0.14.3 May 1, 2020
0.14.2 Dec 31, 2019
0.13.1 Aug 15, 2019
0.13.0 Jun 14, 2019
0.9.0 Jul 21, 2018

#173 in Data structures

Download history 38/week @ 2020-03-16 76/week @ 2020-03-23 4/week @ 2020-03-30 67/week @ 2020-04-06 92/week @ 2020-04-13 10/week @ 2020-04-20 15/week @ 2020-04-27 7/week @ 2020-05-04 4/week @ 2020-05-18 22/week @ 2020-05-25 64/week @ 2020-06-01 4/week @ 2020-06-08 21/week @ 2020-06-15 1/week @ 2020-06-22 22/week @ 2020-06-29

154 downloads per month
Used in 2 crates

Custom license

125KB
2K SLoC

Binn-IR




lib.rs:

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

Project


Features

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

Notes

  • IR stands for implementation in Rust.
  • The crate uses #![no_std] by default. Documentation is built with all features, which include std. If you see some components from std crate, you have to use that feature.

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 core::convert::TryFrom;
# #[cfg(feature="std")]
use binn_ir::{Blob, Decoder, Encoder, Map, Value};

const MAGIC_NUMBER: u64 = 0xABCD;

# #[cfg(feature="std")]
# fn test() -> binn_ir::IoResult<()> {
// 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);
# Ok(()) }
# #[cfg(feature="std")]
# test().unwrap();
# Ok::<_, binn_ir::Error>(())

Thanks

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

Thank you,

No runtime deps