[LIB] Protocol stuff; Testing compression and encoding
This commit is contained in:
parent
f7f582bc69
commit
9073ac2db8
|
@ -19,7 +19,7 @@ pub struct Push<T> {
|
|||
length_comp: i64,
|
||||
comp_format: String,
|
||||
attributes: Option<T>,
|
||||
data: String,
|
||||
data: Vec<u8>,
|
||||
}
|
||||
|
||||
pub struct Response {
|
||||
|
@ -29,3 +29,32 @@ pub struct Response {
|
|||
hashmap_id: 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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<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 {
|
||||
Some(Commands::Start { role }) => {
|
||||
|
|
Loading…
Reference in a new issue