[LIB] Protocol stuff; Testing compression and encoding
All checks were successful
/ build (push) Successful in 1m28s
/ clippy (push) Successful in 1m29s

This commit is contained in:
xqtc 2024-09-04 14:49:43 +02:00
parent f7f582bc69
commit 9073ac2db8
2 changed files with 44 additions and 1 deletions

View file

@ -19,7 +19,7 @@ pub struct Push<T> {
length_comp: i64, length_comp: i64,
comp_format: String, comp_format: String,
attributes: Option<T>, attributes: Option<T>,
data: String, data: Vec<u8>,
} }
pub struct Response { pub struct Response {
@ -29,3 +29,32 @@ pub struct Response {
hashmap_id: String, hashmap_id: String,
status: String, status: String,
} }
impl<T> Push<T> {
fn new(
protocol_id: ProtocolId,
node_id: String,
uuid: String,
hashmap_id: String,
length_decomp: i64,
length_comp: i64,
comp_format: Option<String>,
attributes: Option<T>,
data: Vec<u8>,
) -> 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,
}
}
}

View file

@ -26,6 +26,20 @@ fn main() {
pretty_env_logger::init(); pretty_env_logger::init();
// debug!("{:?}", CONFIG.node); // debug!("{:?}", CONFIG.node);
let cli = Cli::parse(); let cli = Cli::parse();
let target = Some(b"uwuaaaaaaaaaaazzzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaazzzodwiahjfowahodifwahjdiowahoidhawkjfsdkjfhshj3qu420749238749287fjksnfskaaa".to_vec());
let encoded = bincode::serialize(&target).unwrap();
let decoded: Option<Vec<u8>> = 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 { match &cli.command {
Some(Commands::Start { role }) => { Some(Commands::Start { role }) => {