tea_codec/
lib.rs

1
2//! tea-codec
3//!
4//! This codec library is an enhanced version of Kevin Hoffman's original [waSCC Codec](https://github.com/wascc/wascc-codec) 
5//! with the support of [tea-kvp-provider](https://github.com/tearust/tea-kvp-provider).
6//! 
7//! # About the Tea Project
8//! 
9//! Tea Project (Trusted Execution & Attestation) is a Wasm runtime build on top of RoT(Root of Trust)
10//! from both trusted hardware environment and blockchain technologies. Developer, Host and Consumer 
11//! do not have to trust any others to not only protecting privacy but also preventing cyber attacks. 
12//! The execution environment under remoted attestation can be verified by blockchain consensys. 
13//! Crypto economy is used as motivation that hosts are willing run trusted computing nodes. This 
14//! platform can be used by CDN providers, IPFS Nodes or existing cloud providers to enhance existing 
15//! infrastructure to be more secure and trustless.
16//! 
17//! Introduction [blog post](https://medium.com/@pushbar/0-of-n-cover-letter-of-the-trusted-webassembly-runtime-on-ipfs-12a4fd8c4338) 
18//! 
19//! Project [repo](http://github.com/tearust). More and more repo will be exposed soon. 
20//! 
21//! Yet to come //! project site [( not completed yet) http://www.t-rust.com/](http://www.t-rust.com/) 
22//! 
23//! Contact: kevin.zhang.canada_at_gmail_dot_com. 
24//! 
25//! We are just started, all kinds of help are welcome! 
26//! 
27
28/// The version of the codec as seen on crates.io
29pub const VERSION: &str = env!("CARGO_PKG_VERSION");
30
31#[macro_use]
32extern crate serde_derive;
33extern crate log;
34
35extern crate rmp_serde as rmps;
36use rmps::{Deserializer, Serializer};
37use serde::{Deserialize, Serialize};
38use std::io::Cursor;
39
40/// The standard function for serializing codec structs into a format that can be
41/// used for message exchange between actor and host. Use of any other function to
42/// serialize could result in breaking incompatibilities.
43pub fn serialize<T>(item: T) -> ::std::result::Result<Vec<u8>, Box<dyn ::std::error::Error>>
44where
45    T: Serialize,
46{
47    let mut buf = Vec::new();
48    item.serialize(&mut Serializer::new(&mut buf).with_struct_map())?;
49    Ok(buf)
50}
51
52/// The standard function for de-serializing codec structs from a format suitable
53/// for message exchange between actor and host. Use of any other function to
54/// deserialize could result in breaking incompatibilities.
55pub fn deserialize<'de, T: Deserialize<'de>>(
56    buf: &[u8],
57) -> ::std::result::Result<T, Box<dyn ::std::error::Error>> {
58    let mut de = Deserializer::new(Cursor::new(buf));
59    match Deserialize::deserialize(&mut de) {
60        Ok(t) => Ok(t),
61        Err(e) => Err(format!("Failed to de-serialize: {}", e).into()),
62    }
63}
64
65pub mod keyvalue;