Skip to main content

01_roundtrip/
01_roundtrip.rs

1use compression::{compress, decompress, Algorithm};
2
3fn pseudo_random_bytes(len: usize) -> Vec<u8> {
4    let mut state = 0x0123_4567_89ab_cdef_u64;
5    let mut bytes = Vec::with_capacity(len);
6    for _ in 0..len {
7        state ^= state << 7;
8        state ^= state >> 9;
9        state ^= state << 8;
10        bytes.push(state.to_le_bytes()[0]);
11    }
12    bytes
13}
14
15fn main() -> Result<(), Box<dyn std::error::Error>> {
16    let input = pseudo_random_bytes(64 * 1024);
17    let compressed = compress(&input, Algorithm::Lzfse)?;
18    let decompressed = decompress(&compressed, Algorithm::Lzfse)?;
19
20    assert_eq!(decompressed, input);
21    println!("input={} compressed={}", input.len(), compressed.len());
22    println!("✅ compression round-trip OK");
23    Ok(())
24}