1#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6#[repr(u8)]
7pub enum CompressionAlgo {
8 None = 0,
10 Lz4 = 1,
12 Zstd = 2,
14 Custom = 3,
16}
17
18impl TryFrom<u8> for CompressionAlgo {
19 type Error = u8;
20
21 fn try_from(value: u8) -> Result<Self, Self::Error> {
22 match value {
23 0 => Ok(Self::None),
24 1 => Ok(Self::Lz4),
25 2 => Ok(Self::Zstd),
26 3 => Ok(Self::Custom),
27 other => Err(other),
28 }
29 }
30}
31
32#[cfg(test)]
33mod tests {
34 use super::*;
35
36 #[test]
37 fn round_trip() {
38 for raw in 0..=3u8 {
39 let algo = CompressionAlgo::try_from(raw).unwrap();
40 assert_eq!(algo as u8, raw);
41 }
42 }
43
44 #[test]
45 fn invalid_value() {
46 assert_eq!(CompressionAlgo::try_from(4), Err(4));
47 }
48}