use broadcast_common::bits::BitError;
pub type Result<T> = core::result::Result<T, Error>;
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error("buffer too short: need {need}, have {have} ({what})")]
BufferTooShort {
need: usize,
have: usize,
what: &'static str,
},
#[error("bit-level error decoding/encoding {what}: {source}")]
Bits {
what: &'static str,
source: BitError,
},
#[error("Plex-coded field {field} read the unrepresentable escape value 0xFFFFFFFF")]
PlexUnrepresentable {
field: &'static str,
},
#[error("field {field} value {value} invalid: {reason}")]
InvalidValue {
field: &'static str,
value: u64,
reason: &'static str,
},
#[error("reserved field {field} must be {expected:#x}, found {found:#x}")]
InvalidReserved {
field: &'static str,
expected: u64,
found: u64,
},
#[error("expected ElementID {expected:#x}, found {found:#x}")]
UnexpectedElementId {
expected: u32,
found: u32,
},
}
pub(crate) trait BitResultExt<T> {
fn ctx(self, what: &'static str) -> Result<T>;
}
impl<T> BitResultExt<T> for core::result::Result<T, BitError> {
fn ctx(self, what: &'static str) -> Result<T> {
self.map_err(|source| Error::Bits { what, source })
}
}