use foyer_common::error::{Error, ErrorKind};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
pub enum Compression {
#[default]
None,
Zstd,
Lz4,
}
impl Compression {
pub fn to_u8(&self) -> u8 {
match self {
Self::None => 0,
Self::Zstd => 1,
Self::Lz4 => 2,
}
}
}
impl From<Compression> for u8 {
fn from(value: Compression) -> Self {
match value {
Compression::None => 0,
Compression::Zstd => 1,
Compression::Lz4 => 2,
}
}
}
impl TryFrom<u8> for Compression {
type Error = Error;
fn try_from(value: u8) -> Result<Self, Self::Error> {
match value {
0 => Ok(Self::None),
1 => Ok(Self::Zstd),
2 => Ok(Self::Lz4),
_ => Err(Error::new(ErrorKind::Parse, "failed to parse Compression").with_context("value", value)),
}
}
}