use core::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum EncodeError {
LengthOverflow {
what: &'static str,
len: usize,
},
ValueOutOfRange {
message: &'static str,
},
}
impl fmt::Display for EncodeError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::LengthOverflow { what, len } => {
write!(f, "{what} length {len} exceeds OPC-UA Int32 ceiling")
}
Self::ValueOutOfRange { message } => write!(f, "value out of range: {message}"),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for EncodeError {}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DecodeError {
UnexpectedEof {
needed: usize,
remaining: usize,
},
InvalidUtf8,
InvalidDiscriminant {
field: &'static str,
value: u32,
},
NegativeLength {
field: &'static str,
},
MalformedMessage {
message: &'static str,
},
}
impl fmt::Display for DecodeError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::UnexpectedEof { needed, remaining } => write!(
f,
"unexpected end of input: needed {needed} bytes, {remaining} remaining"
),
Self::InvalidUtf8 => write!(f, "invalid UTF-8 in string body"),
Self::InvalidDiscriminant { field, value } => {
write!(f, "invalid discriminant for {field}: {value}")
}
Self::NegativeLength { field } => {
write!(f, "negative length for non-nullable field {field}")
}
Self::MalformedMessage { message } => write!(f, "malformed UADP message: {message}"),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for DecodeError {}