Skip to main content

cc_data/
error.rs

1//! Error type for cc_data parsing.
2
3/// Result alias.
4pub type Result<T> = core::result::Result<T, Error>;
5
6/// A cc_data parse error.
7#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
8#[non_exhaustive]
9pub enum Error {
10    /// Input shorter than required.
11    #[error("buffer too short: need {need}, have {have} ({what})")]
12    BufferTooShort {
13        /// Bytes required.
14        need: usize,
15        /// Bytes available.
16        have: usize,
17        /// What was being parsed.
18        what: &'static str,
19    },
20    /// Output buffer too small for serialization.
21    #[error("output buffer too small: need {need}, have {have}")]
22    OutputBufferTooSmall {
23        /// Bytes required.
24        need: usize,
25        /// Bytes available.
26        have: usize,
27    },
28    /// More than 31 triplets — cc_count is a 5-bit field.
29    #[error("too many cc triplets: {0} (cc_count is 5-bit, max 31)")]
30    TooManyTriplets(usize),
31    /// A bit Table B.9 fixes to a constant value didn't have that value.
32    #[error(
33        "invalid fixed bits in {what}: got 0x{got:02X}, expected 0x{expected:02X} (mask 0x{mask:02X})"
34    )]
35    InvalidFixedBits {
36        /// Which fixed field failed (`"reserved/zero_bit"`, `"one_bit/reserved"`,
37        /// `"marker_bits"`).
38        what: &'static str,
39        /// The masked bits as received.
40        got: u8,
41        /// The masked bits Table B.9 requires.
42        expected: u8,
43        /// The mask applied before comparing.
44        mask: u8,
45    },
46}