use thiserror::Error;
use crate::PacketType;
#[derive(Debug, Clone, PartialEq, Eq, Error)]
#[non_exhaustive]
pub enum DecodeError {
#[error("insufficient bytes: need {needed} more")]
InsufficientBytes {
needed: usize,
},
#[error("malformed remaining length")]
MalformedRemainingLength,
#[error("invalid utf-8 string: {reason}")]
InvalidUtf8 {
reason: &'static str,
},
#[error("invalid packet type: {value}")]
InvalidPacketType {
value: u8,
},
#[error("invalid packet flags: type={packet_type:?}, flags=0x{flags:02x}")]
InvalidFlags {
packet_type: PacketType,
flags: u8,
},
#[error("protocol error: {reason}")]
ProtocolError {
reason: &'static str,
},
#[error("trailing bytes after packet body: {count} unconsumed")]
TrailingBytes {
count: usize,
},
#[error("invalid property {id:#04x} for {packet_type:?}")]
InvalidProperty {
packet_type: PacketType,
id: u8,
},
#[error("duplicate property {id:#04x}")]
DuplicateProperty {
id: u8,
},
#[error("invalid reason code {value:#04x} for {packet_type:?}")]
InvalidReasonCode {
packet_type: PacketType,
value: u8,
},
}
#[derive(Debug, Clone, PartialEq, Eq, Error)]
#[non_exhaustive]
pub enum EncodeError {
#[error("packet too large: remaining length would exceed 268_435_455")]
PacketTooLarge,
#[error("string too long: {len} bytes exceeds 65535 limit")]
StringTooLong {
len: usize,
},
#[error("string contains null character (U+0000)")]
StringContainsNull,
#[error("invalid packet state: {reason}")]
InvalidState {
reason: &'static str,
},
}