Rust Crate borsh包
官网:https://borsh.io/
https://github.com/near/borsh-rs
文档:https://docs.rs/borsh/0.9.1/borsh/index.html#
borsh-rs是Borsh二进制序列化格式的Rust 实现。
Borsh代表散列的二进制对象表示序列化器。 它意味着在安全关键项目中使用,因为它优先于一致性,安全,速度以及严格的规范。
use borsh::{BorshSerialize, BorshDeserialize};
#[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug)]
struct A {
x: u64,
y: String,
}
#[test]
fn test_simple_struct() {
let a = A {
x: 3301,
y: "liber primus".to_string(),
};
let encoded_a = a.try_to_vec().unwrap();
let decoded_a = A::try_from_slice(&encoded_a).unwrap();
assert_eq!(a, decoded_a);
}