(rust) ciborium!
This commit is contained in:
+7
-4
@@ -3,7 +3,7 @@
|
||||
use chrono::{DateTime, Local, Utc};
|
||||
use dirs::config_dir;
|
||||
use serde::{self, Deserialize, Serialize};
|
||||
use serde_json;
|
||||
use ciborium;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct TestStruct {
|
||||
@@ -20,6 +20,7 @@ pub struct SubStruct {
|
||||
}
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let mut buffer: Vec<u8> = Vec::new();
|
||||
let test = TestStruct {
|
||||
name: "ronald yellowegger".to_owned(),
|
||||
id: 029854u128,
|
||||
@@ -27,10 +28,12 @@ fn main() -> anyhow::Result<()> {
|
||||
pos: SubStruct { x: 8, y: -3 },
|
||||
};
|
||||
|
||||
let json = serde_json::to_string(&test)?;
|
||||
_ = ciborium::into_writer(&test, &mut buffer)?;
|
||||
|
||||
println!("json = \\");
|
||||
println!("{}", json);
|
||||
println!("{:02x?}", buffer);
|
||||
|
||||
let cbor: TestStruct = ciborium::from_reader(std::io::Cursor::new(&mut buffer))?;
|
||||
println!("deserialised cbor struct = {:#?}", cbor);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user