#![no_std]
extern crate alloc;
pub mod tlv;
type Result<T> = core::result::Result<T, TlvError>;
#[derive(Debug)]
pub enum TlvError {
TruncatedTlv,
InvalidLength,
InvalidTagNumber,
TooShortBody { expected: usize, found: usize },
ValExpected { tag_number: usize },
TagPathError,
}
use core::fmt;
impl fmt::Display for TlvError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use TlvError::*;
match self {
TruncatedTlv => write!(f, "Too short input vector"),
InvalidLength => writeln!(f, "Invalid length value"),
InvalidTagNumber => write!(f, "Invalid tag number"),
TooShortBody { expected, found } => {
write!(f, "Too short body: expected {expected}, found {found}")
}
ValExpected { tag_number } => write!(
f,
"Tag number defines primitive TLV, but value is not Value::Val: {tag_number}"
),
TagPathError => write!(f, "Provided 'tag-path' has error"),
}
}
}
impl core::error::Error for TlvError {}