LZSS Decompression

I have a binary file that's got LZSS compression against all of its data, and I'm trying to use the compression crate to decode the data. I've got the compressed data loaded into a Vec<u8>, but I haven't figured out how to use the decoder from the library. Here's the link to the decoder's source. I tried to pass a new instance of the decoder to the iterator's .decode() method, but I keep getting the following compiler errors:

error[E0271]: type mismatch resolving `<compression::prelude::LzssDecoder as compression::prelude::Decoder>::Input == u8`
   --> src\main.rs:104:5
    |
104 |             .decode(&mut LzssDecoder::new(0x1_0000))
    |              ^^^^^^ expected enum `compression::prelude::LzssCode`, found u8
    |
    = note: expected type `compression::prelude::LzssCode`
               found type `u8`

error[E0599]: no method named `collect` found for type `compression::prelude::DecodeIterator<'_, std::iter::Cloned<std::slice::Iter<'_, u8>>, compression::prelude::LzssDecoder, std::iter::Cloned<std::slice::Iter<'_, u8>>>` in the current scope
   --> src\main.rs:105:5
    |
105 |             .collect::<Result<Vec<_>, _>>()
    |              ^^^^^^^ method not found in `compression::prelude::DecodeIterator<'_, std::iter::Cloned<std::slice::Iter<'_, u8>>, compression::prelude::LzssDecoder, std::iter::Cloned<std::slice::Iter<'_, u8>>>`

A friend suggested that I needed to map over my data, and wrap each element in my vector in a LzssCode enum, but I'm not sure how to easily determine which variant to use per byte.

Any ideas of what I should do?

LZSS is not really a binary format, but a technique involving some sequence of bytes and backreferences. It doesn't specify how those bytes and backreferences should be encoded as bytes, and if you have "LZSS encoded data", you need to figure out how they encoded the lzss symbols in binary, and convert it to a sequence of enums in the correct way before you can use the lzss decoder.

I was kind of wondering about that because I guess LZSS was primarily intended to work well with compressing textual content (which is still binary). It sounds like I'll need to map over all of those bytes, and figure out whether each one is a symbol or a reference, and if it's a reference, I'll have to provide additional logic for that. I just wanted to check because it feels like quite a bit of boilerplate before the crate could decompress the data. I didn't realize that LZSS doesn't spec out how symbols and references should be encoded, so the "boilerplate" effort makes a lot of sense now.

Thanks for the help, @alice. I think I can take it from here :slight_smile: