use std::fmt;
use std::error;
use httlib_huffman::{DecoderError as HuffmanError};
#[derive(Debug, PartialEq)]
pub enum DecoderError {
InvalidInput,
InvalidIndex,
InvalidPrefix,
IntegerOverflow,
IntegerUnderflow,
InvalidMaxDynamicSize,
}
impl From<HuffmanError> for DecoderError {
fn from(err: HuffmanError) -> Self {
match err {
HuffmanError::InvalidInput => Self::InvalidInput
}
}
}
impl fmt::Display for DecoderError {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::InvalidInput => write!(fmt, "Invalid input character."),
Self::InvalidIndex => write!(fmt, "Invalid index."),
Self::InvalidPrefix => write!(fmt, "Invalid prefix."),
Self::IntegerOverflow => write!(fmt, "Too many bytes."),
Self::IntegerUnderflow => write!(fmt, "Not enough bytes."),
Self::InvalidMaxDynamicSize => write!(fmt, "New size exceeds hard limit."),
}
}
}
impl error::Error for DecoderError {}