use thiserror::Error;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct RefoundMapDecodeBudget {
max_stations: usize,
max_entries: usize,
}
impl RefoundMapDecodeBudget {
#[must_use]
pub const fn new(max_stations: usize, max_entries: usize) -> Self {
Self {
max_stations,
max_entries,
}
}
#[must_use]
pub const fn max_stations(self) -> usize {
self.max_stations
}
#[must_use]
pub const fn max_entries(self) -> usize {
self.max_entries
}
}
#[non_exhaustive]
#[derive(Error, Debug, Clone, Copy, PartialEq, Eq)]
pub enum RefoundMapDecodeError {
#[error("unknown refound-map wire version: {0:#04x}")]
UnknownVersion(u8),
#[error("unexpected refound-map frame length: expected at least {expected}, found {found}")]
UnexpectedLength {
expected: usize,
found: usize,
},
#[error("refound-map frame declares {count} station rows, past the budget's {budget}")]
TooManyStations {
count: u64,
budget: u64,
},
#[error("refound-map frame declares {count} translation entries, past the budget's {budget}")]
TooManyEntries {
count: u64,
budget: u64,
},
#[error("non-canonical refound map: station {found} is not strictly after {previous}")]
NonAscendingStations {
previous: u32,
found: u32,
},
#[error("non-canonical refound map: zero ceiling for station {station}")]
ZeroCeiling {
station: u32,
},
#[error(
"non-canonical refound map: station {station} declares {live} live entries over ceiling {ceiling}"
)]
LiveExceedsCeiling {
station: u32,
live: u64,
ceiling: u64,
},
#[error(
"non-canonical refound map: station {station} entry {index} outside the compacted domain 1..={ceiling}"
)]
IndexOutOfRange {
station: u32,
index: u64,
ceiling: u64,
},
#[error("non-canonical refound map: station {station} names old index {index} twice")]
DuplicateIndex {
station: u32,
index: u64,
},
}