use crate::JceType;
use std::{error::Error, fmt::Display};
pub type JceResult<T> = Result<T, JceError>;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum JceError {
ReadTagError(u8, u8),
ReadTypeError(JceType, JceType),
ReadLenError(JceType),
Utf8Error,
TagNotFound(u8),
ReadError(&'static str),
WriteError(&'static str),
}
impl Display for JceError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::ReadTagError(etag, gtag) => write!(
f,
"Jce read tag error, expected tag: {}, get tag: {}",
etag, gtag
),
Self::ReadTypeError(ety, gty) => write!(
f,
"Jce read type error, expected type: {}, get type: {}",
ety, gty
),
Self::ReadLenError(ty) => write!(f, "Jce read len error, get type: {}", ty),
Self::Utf8Error => write!(f, "Jce read utf8 error"),
Self::TagNotFound(tag) => write!(f, "Jce tag not found, tag: {}", tag),
Self::ReadError(s) => write!(f, "Jce read error: {}", s),
Self::WriteError(s) => write!(f, "Jce write error: {}", s),
}
}
}
impl Error for JceError {}