Skip to main content

st12_1/
error.rs

1//! Error type for LTC codeword parsing/serialization.
2//!
3//! Field-by-field semantics are documented in the curated spec oracle,
4//! `st12-1/docs/st12-1.md` (SMPTE ST 12-1:2014 §8/§9).
5
6/// Result alias for `st12-1` parsing/serialization.
7pub type Result<T> = core::result::Result<T, Error>;
8
9/// An LTC codeword parse / serialize error.
10#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
11#[non_exhaustive]
12pub enum Error {
13    /// Input (on parse) or output buffer (on serialize) shorter than the
14    /// fixed 10-byte (80-bit) LTC codeword.
15    #[error("buffer too short: need {need}, have {have} ({what})")]
16    BufferTooShort {
17        /// Bytes required.
18        need: usize,
19        /// Bytes available.
20        have: usize,
21        /// What was being parsed/serialized.
22        what: &'static str,
23    },
24    /// Bits 64–79 did not match the fixed synchronization word (§9.2.5,
25    /// Table 5: bytes `0xFC 0xBF` under this crate's bit-to-byte packing —
26    /// see `docs/st12-1.md`'s "Byte packing convention" section).
27    #[error("sync word mismatch: expected {expected:02X?}, found {found:02X?} (ST 12-1 §9.2.5)")]
28    SyncWordMismatch {
29        /// The fixed sync word bytes (see [`crate::SYNC_WORD`]).
30        expected: [u8; 2],
31        /// The bytes actually found at positions 8/9 (bits 64–79).
32        found: [u8; 2],
33    },
34    /// A time-address field (`hours`/`minutes`/`seconds`/`frames`) exceeded
35    /// its valid range (§5.2/§6.2/§7.2, §9.2.1 Table 2).
36    #[error("field {field} value {value} invalid: {reason}")]
37    InvalidValue {
38        /// The offending field name.
39        field: &'static str,
40        /// The offending value.
41        value: u8,
42        /// Why it is invalid.
43        reason: &'static str,
44    },
45    /// One of the eight 4-bit binary groups ("user bits", §8.1/Table 4) held
46    /// a value outside `0x0..=0xF`.
47    #[error("binary group {index} value {value:#X} invalid: must be 0x0-0xF")]
48    InvalidBinaryGroup {
49        /// The binary group's index, `0..8` (first..eighth, Table 4 order).
50        index: usize,
51        /// The offending value.
52        value: u8,
53    },
54}