Crates.io | rust-fr |
lib.rs | rust-fr |
version | 1.0.1 |
source | src |
created_at | 2024-02-20 22:32:59.238751 |
updated_at | 2024-02-28 13:40:57.917698 |
description | a simple, non-self-describing data-interchange format. |
homepage | |
repository | https://github.com/is-it-ayush/rust-fr |
max_upload_size | |
id | 1147293 |
size | 59,285 |
'rust-fr' (aka rust for real
) is a simple, non-self-describing data-interchange format.
You can use either of these methods.
cargo add rust-fr
Cargo.toml
[dependencies]
rust-fr = "1"
use serde::{Serialize, Deserialize};
use rust_fr::{serializer, deserializer};
// define some data
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
struct Human {
name: String,
age: u8
};
let human = Human {
name: "Ayush".to_string(),
age: 19
};
// serialize the data to bytes (Vec<u8>)
let human_bytes = serializer::to_bytes(&human).unwrap();
// deserialize the data from serialized bytes.
let deserialized_human = deserializer::from_bytes::<Human>(&human_bytes).unwrap();
assert_eq!(human, deserialized_human);
cargo test -- --nocapture --ignored
to run the benchmark tests.running 3 tests
---- Small Data ----
rust_fr: 218 bytes
serde_json: 332 bytes
rmp_serde: 146 bytes
ciborium: 170 bytes
test tests::length_test_small_data ... ok
---- Medium Data ----
rust_fr: 14264 bytes
serde_json: 30125 bytes
rmp_serde: 10731 bytes
ciborium: 18347 bytes
test tests::length_test_medium_data ... ok
---- Large Data ----
rust_fr: 139214 bytes
serde_json: 367595 bytes
rmp_serde: 157219 bytes
ciborium: 198277 bytes
test tests::length_test_large_data ... ok
test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 4 filtered out; finished in 0.01s
The goal was to learn/understand. I wrote this so I can learn how serde internally works and how to encode data into bytes that can ultimately be transferred over the wire or elsewhere.
tuple: seq()
struct: map()
It's MIT so you can do whatever you want. You can still read it here.