Rust implementation of the multicodec specification.
First add this to your Cargo.toml
toml
[dependencies]
rust_multicodec = "0.2.0"
Then run cargo build
.
``` extern crate rust_multicodec;
extern crate serde_derive;
struct Person { name: String }
fn main(){ let tobeencoded=Person{name:String::from("sanyi")}; let encoded=rustmulticodec::encode(rustmulticodec::codec::CodecType::JSON, &tobeencoded).unwrap(); println!("{:?}",encoded); // it will print: Ok([129, 30, 123, 34, 110, 97, 109, 101, 34, 58, 34, 115, 97, 110, 121, 105, 34, 125])
let decoded:Person=rust_multicodec::decode(encoded.as_ref()).unwrap().data;
println!("{:?}",decoded);
// it will print: Person { name: "sanyi" }
} ```
Contributions are welcome :)
Licensed under the Apache License, Version 2.0