1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use cpclib_tokens::CrunchType;
use crate::crunchers;
use crate::error::AssemblerError;
pub trait Cruncher {
fn crunch(&self, raw: &[u8]) -> Result<Vec<u8>, AssemblerError>;
}
impl Cruncher for CrunchType {
fn crunch(&self, raw: &[u8]) -> Result<Vec<u8>, AssemblerError> {
if raw.is_empty() {
return Err(AssemblerError::NoDataToCrunch);
}
match self {
CrunchType::LZ48 => Ok(crunchers::lz48::lz48_encode_legacy(raw)),
CrunchType::LZ49 => Ok(crunchers::lz49::lz49_encode_legacy(raw)),
CrunchType::LZ4 => {
Err(AssemblerError::AssemblingError {
msg: "LZ4 compression not implemented".to_owned()
})
}
CrunchType::LZX7 => {
Err(AssemblerError::AssemblingError {
msg: "LZX7 compression not implemented".to_owned()
})
}
CrunchType::LZEXO => {
Err(AssemblerError::AssemblingError {
msg: "LZEXO compression not implemented".to_owned()
})
}
#[cfg(not(target_arch = "wasm32"))]
CrunchType::LZAPU => Ok(crunchers::apultra::compress(raw))
}
}
}