use crate::encoding;
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "thiserror", derive(thiserror_no_std::Error))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[non_exhaustive]
pub enum DecodeError {
#[cfg_attr(feature = "thiserror", error("Unable to decode varint: the last byte overflowed a 64-bit integer. The buffer is likely corrupt"))]
InvalidVarint,
#[cfg_attr(feature = "thiserror", error("Varint larger than expected: {0}"))]
VarintTooLarge(u64),
#[cfg_attr(feature = "thiserror", error("Provided buffer is too short"))]
BufferUnderflow,
#[cfg_attr(feature = "thiserror", error("End group tag encountered without matching start group tag"))]
UnexpectedEndGroupTag,
#[cfg_attr(feature = "thiserror", error("Wire type value too large: {0}"))]
InvalidWireTypeValue(u64),
#[cfg_attr(feature = "thiserror",
error("Unexpected wire type: {}. Expected: {}", *actual as u8, *expected as u8))]
UnexpectedWireTypeValue {
actual: encoding::WireType,
expected: encoding::WireType,
},
#[cfg_attr(feature = "thiserror", error("Unexpected tag value: {0}"))]
UnexpectedTagValue(u32),
#[cfg_attr(feature = "thiserror", error("Key value out of range: {0}"))]
InvalidKeyValue(u64),
#[cfg_attr(feature = "thiserror", error("Key value out of range: {0}"))]
InvalidTagValue(u32),
#[cfg_attr(feature = "thiserror",
error("Invalid UTF-8 data: Valid up to {}. Error length: {}",
valid_up_to,
error_len.map_or("N/A", |value| "{value}")))]
InvalidUtf8 {
valid_up_to: usize,
error_len: Option<usize>,
},
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "thiserror", derive(thiserror_no_std::Error))]
#[cfg_attr(feature = "thiserror", error("encode error: required {required} bytes but only {remaining} remaining"))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct EncodeError {
pub required: usize,
pub remaining: usize,
}
impl EncodeError {
pub fn new(required: usize, remaining: usize) -> Self {
Self {
required,
remaining,
}
}
}