use thiserror::Error;
pub type Result<T> = core::result::Result<T, Error>;
#[derive(Debug, Error, PartialEq, Eq)]
#[non_exhaustive]
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 splice_info_section (expected 0xFC)")]
UnexpectedTableId {
table_id: u8,
},
#[error("unexpected splice_descriptor_tag {tag:#04x} for {what} (expected {expected:#04x})")]
UnexpectedDescriptorTag {
tag: u8,
what: &'static str,
expected: u8,
},
#[error("unexpected splice_command_type {got:#04x} for {what} (expected {expected:#04x})")]
UnexpectedCommandType {
got: u8,
what: &'static str,
expected: u8,
},
#[error("invalid value for {field}: {reason}")]
InvalidValue {
field: &'static str,
reason: &'static str,
},
#[error("length {declared} exceeds remaining buffer ({available} bytes) for {what}")]
LengthOverflow {
declared: usize,
available: usize,
what: &'static str,
},
#[error("serialize: output buffer too small — need {need}, have {have}")]
OutputBufferTooSmall {
need: usize,
have: usize,
},
}