Skip to content
This repository was archived by the owner on Apr 23, 2021. It is now read-only.

mudlee/rust-multicodec

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rust_multicodec

Rust implementation of the multicodec specification.

Install

First add this to your Cargo.toml

[dependencies]
rust_multicodec = "0.2.0"

Then run cargo build.

Usage

Encode / Decode

extern crate rust_multicodec;

#[macro_use]
extern crate serde_derive;

use rust_multicodec::{codec, encode, decode};

#[derive(Serialize)]
#[derive(Debug)]
struct Person {
    name: String
}

fn main(){
    let to_be_encoded = Person{ name: String::from("sanyi") };
    let encoded = encode(codec::CodecType::JSON, &to_be_encoded).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 = decode(encoded.as_ref()).unwrap().data;
    println!("{:?}", decoded);
    // it will print: Person { name: "sanyi" }
}

Contribute

Contributions are welcome :)

More reading

License

Licensed under the Apache License, Version 2.0

About

This library is a Rust implementation of the multicodec project.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages