You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Background: Our team is recently planning to switch from go to rust and lz4 is being used to decompress the payload sent from our app. In order to ensure the switch is smooth, we need to ensure the compressed binaries can be correctly decompressed by the rust counterpart.
For this we wrapped some code that mimics our original code behaviour, which retries whenever the output buffer is insufficient.
use lz4::block;
use std::io::Result;
fn compress(src: &[u8]) -> Result<Vec<u8>> {
return block::compress(src, None, false);
}
fn decompress(src: &[u8]) -> Result<Vec<u8>> {
let mut factor = 3;
loop {
let result = block::decompress(src, Some((src.len() as i32) * factor));
factor *= 2;
match result {
Ok(mut v) => {
// truncate trailing zeros
if let Some(i) = v.iter().rposition(|x| *x != 0) {
let new_len = i + 1;
v.truncate(new_len);
}
return Ok(v);
}
Err(e) => {
// lz4 theoretical compression limit is 255, if buffer size exceed
// the limit, just return result
if factor >= 255 {
return Err(e);
}
if e.kind() != std::io::ErrorKind::InvalidData {
return Err(e);
};
}
};
}
}
However we noticed that, when we're testing the cases, the output compressed with rust can't get the correct result after decompression, there's always extra 1's in the rust compressed and uncompressed output.
Background: Our team is recently planning to switch from go to rust and lz4 is being used to decompress the payload sent from our app. In order to ensure the switch is smooth, we need to ensure the compressed binaries can be correctly decompressed by the rust counterpart.
For this we wrapped some code that mimics our original code behaviour, which retries whenever the output buffer is insufficient.
However we noticed that, when we're testing the cases, the output compressed with rust can't get the correct result after decompression, there's always extra 1's in the rust compressed and uncompressed output.
The text was updated successfully, but these errors were encountered: