From 9073ac2db8fe3104cd7ec6c5cb04a56fdc641a17 Mon Sep 17 00:00:00 2001 From: xqtc Date: Wed, 4 Sep 2024 14:49:43 +0200 Subject: [PATCH] [LIB] Protocol stuff; Testing compression and encoding --- lib-uwusched/src/data/mod.rs | 31 ++++++++++++++++++++++++++++++- uwusched/src/main.rs | 14 ++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/lib-uwusched/src/data/mod.rs b/lib-uwusched/src/data/mod.rs index d6497dc..11778f0 100644 --- a/lib-uwusched/src/data/mod.rs +++ b/lib-uwusched/src/data/mod.rs @@ -19,7 +19,7 @@ pub struct Push { length_comp: i64, comp_format: String, attributes: Option, - data: String, + data: Vec, } pub struct Response { @@ -29,3 +29,32 @@ pub struct Response { hashmap_id: String, status: String, } + +impl Push { + fn new( + protocol_id: ProtocolId, + node_id: String, + uuid: String, + hashmap_id: String, + length_decomp: i64, + length_comp: i64, + comp_format: Option, + attributes: Option, + data: Vec, + ) -> Self { + Push { + protocol_id, + node_id, + uuid, + hashmap_id, + length_decomp, + length_comp, + comp_format: match comp_format { + Some(c) => c, + None => String::from("lz4"), + }, + attributes, + data, + } + } +} diff --git a/uwusched/src/main.rs b/uwusched/src/main.rs index db4e1eb..20b5daa 100644 --- a/uwusched/src/main.rs +++ b/uwusched/src/main.rs @@ -26,6 +26,20 @@ fn main() { pretty_env_logger::init(); // debug!("{:?}", CONFIG.node); let cli = Cli::parse(); + let target = Some(b"uwuaaaaaaaaaaazzzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaazzzodwiahjfowahodifwahjdiowahoidhawkjfsdkjfhshj3qu420749238749287fjksnfskaaa".to_vec()); + let encoded = bincode::serialize(&target).unwrap(); + let decoded: Option> = bincode::deserialize(&encoded[..]).unwrap(); + dbg!(&encoded); + // dbg!(&decoded == &Some(String::from("uwu"))); + // + // let compr = lz4_flex::compress(&encoded); + // dbg!(&decoded == lz4_flex:: + use lz4_flex::block::{compress_prepend_size, decompress_size_prepended}; + let compressed = compress_prepend_size(&encoded); + let uncompressed = decompress_size_prepended(&compressed).unwrap(); + dbg!(compressed.len(), encoded.len()); + dbg!(compressed.len() < encoded.len()); + dbg!(&uncompressed == &encoded); match &cli.command { Some(Commands::Start { role }) => {