use thiserror::Error;
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct HaveSetDecodeBudget(usize);
impl HaveSetDecodeBudget {
#[must_use]
pub const fn new(max_dots: usize) -> Self {
Self(max_dots)
}
#[must_use]
pub const fn max_dots(self) -> usize {
self.0
}
}
#[non_exhaustive]
#[derive(Error, Debug, Clone, Copy, PartialEq, Eq)]
pub enum HaveSetDecodeError {
#[error("unknown have-set wire version: {0:#04x}")]
UnknownVersion(u8),
#[error("unexpected have-set frame length: expected at least {expected}, found {found}")]
UnexpectedLength {
expected: usize,
found: usize,
},
#[error("non-canonical have-set: empty entry for station {station}")]
EmptyStation {
station: u32,
},
#[error("non-canonical have-set: station {found} is not strictly after {previous}")]
NonAscendingStations {
previous: u32,
found: u32,
},
#[error("non-canonical have-set: zero-length run for station {station}")]
ZeroLengthRun {
station: u32,
},
#[error("non-canonical have-set: non-maximal run for station {station} starting at {start}")]
NonMaximalRun {
station: u32,
start: u64,
},
#[error("have-set run for station {station} overflows u64: start {start}, len {len}")]
RunOverflow {
station: u32,
start: u64,
len: u64,
},
#[error(
"have-set run for station {station} exceeds the decode dot budget: start {start}, len {len}"
)]
RunTooLong {
station: u32,
start: u64,
len: u64,
},
}