use thiserror::Error;
pub type Result<T> = core::result::Result<T, Error>;
#[derive(Debug, Error)]
pub enum Error {
#[error("buffer too short: need {need} bytes, have {have} (while parsing {what})")]
BufferTooShort {
need: usize,
have: usize,
what: &'static str,
},
#[error("CRC-32 mismatch: computed {computed:#010x}, expected {expected:#010x}")]
CrcMismatch {
computed: u32,
expected: u32,
},
#[error("unexpected table_id {table_id:#04x} for {what} (expected one of {expected:?})")]
UnexpectedTableId {
table_id: u8,
what: &'static str,
expected: &'static [u8],
},
#[error("invalid descriptor (tag {tag:#04x}): {reason}")]
InvalidDescriptor {
tag: u8,
reason: &'static str,
},
#[error("invalid BCD in {field}: bytes {bytes:02x?}")]
InvalidBcd {
field: &'static str,
bytes: [u8; 4],
},
#[error("section_length {declared} exceeds remaining buffer ({available} bytes)")]
SectionLengthOverflow {
declared: usize,
available: usize,
},
#[error("reserved bits violation in {field}: {reason}")]
ReservedBitsViolation {
field: &'static str,
reason: &'static str,
},
#[error("serialize: output buffer too small — need {need}, have {have}")]
OutputBufferTooSmall {
need: usize,
have: usize,
},
#[error("invalid TS sync byte: expected 0x47, got {found:#04x}")]
InvalidSyncByte {
found: u8,
},
}