Ion binary is a library written in safe rust for parsing, encoding and hashing Amazon's Ion binary format.
It should be able to parse, encode and hash anything you throw at it. Any failure to do so is a bug that we will fix and we will be very happy if you report them.
First of all, you need to be aware of the trade offs that we took for this library:
We have implemented the whole amazon ion test-suite for parsing. Encoding and Hashing fully tested. We are working in expading the coverage. We would appreciate any bug you can report. You can check all the test for examples.
```rust,no_run
use ionbinaryrs::IonParser;
// This is the response from Amazon's QLDB introduction example using Rusoto let ion_test = b"\xe0\x01\0\xea\xee\xa6\x81\x83\xde\xa2\x87\xbe\x9f\x83VIN\x84Type\x84Year\x84Make\x85Model\x85Color\xde\xb9\x8a\x8e\x911C4RJFAG0FC625797\x8b\x85Sedan\x8c\"\x07\xe3\x8d\x88Mercedes\x8e\x87CLK 350\x8f\x85White";
let mut parser = IonParser::new(&ion_test[..]);
println!("Decoded Ion: {:?}", parser.consume_all().unwrap()) // Decoded Ion: [Struct({"Color": String("White"), "Year": Integer(2019), "VIN": String("1C4RJFAG0FC625797"), "Make": String("Mercedes"), "Model": String("CLK 350"), "Type": String("Sedan")})]
```
```rust,no_run
use ionbinaryrs::{IonEncoder, IonParser, IonValue}; use std::collections::HashMap;
let mut ion_struct = HashMap::new();
ionstruct.insert("Model".tostring(), IonValue::String("CLK 350".tostring())); ionstruct.insert("Type".tostring(), IonValue::String("Sedan".tostring())); ionstruct.insert("Color".tostring(), IonValue::String("White".tostring())); ionstruct.insert( "VIN".tostring(), IonValue::String("1C4RJFAG0FC625797".tostring()), ); ionstruct.insert("Make".tostring(), IonValue::String("Mercedes".tostring())); ionstruct.insert("Year".to_string(), IonValue::Integer(2019));
let ionvalue = IonValue::Struct(ionstruct);
let mut encoder = IonEncoder::new();
encoder.add(ion_value.clone()); let bytes = encoder.encode();
let resultingionvalue = IonParser::new(&bytes[..]).consume_value().unwrap().0;
asserteq!(ionvalue, resultingionvalue); ```
```rust,norun use sha2::Sha256; use ionbinary_rs::{IonHash, IonValue}; use std::collections::HashMap;
let mut ion_struct = HashMap::new();
ionstruct.insert("Model".tostring(), IonValue::String("CLK 350".tostring())); ionstruct.insert("Type".tostring(), IonValue::String("Sedan".tostring())); ionstruct.insert("Color".tostring(), IonValue::String("White".tostring())); ionstruct.insert( "VIN".tostring(), IonValue::String("1C4RJFAG0FC625797".tostring()), ); ionstruct.insert("Make".tostring(), IonValue::String("Mercedes".tostring())); ionstruct.insert("Year".to_string(), IonValue::Integer(2019));
let ionvalue = IonValue::Struct(ionstruct);
let hash = IonHash::digest::
println!("{:X?}", hash); ```
No unsafe code was directly used in this crate. You can check in lib.rs
the #![deny(unsafe_code)]
line.
We would be thrilled if you decide to check the library and/or contribute to it! Just open an issue or pull request and we can check what you would like to implement. Bug hunting and proposals are always welcomed. And of course, feel free to ask anything.
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.