dvb_si/traits.rs
1//! SI-specific traits. `Parse` / `Serialize` are provided by `dvb_common`
2//! and imported directly at call sites.
3
4use dvb_common::{Parse, Serialize};
5
6/// Contract every DVB descriptor implements.
7///
8/// Descriptors are length-prefixed payloads inside tables. The
9/// `TAG` constant ties a struct to its wire identifier.
10pub trait Descriptor<'a>: Parse<'a> + Serialize {
11 /// Descriptor tag byte — the wire identifier.
12 const TAG: u8;
13
14 /// Length of the payload portion (NOT including the 2 header bytes).
15 fn descriptor_length(&self) -> u8;
16}
17
18/// Implemented by every typed descriptor; drives [`crate::descriptors::AnyDescriptor`]
19/// dispatch. `TAG` is the wire descriptor_tag this type parses.
20pub trait DescriptorDef<'a>: Parse<'a, Error = crate::error::Error> {
21 /// Wire descriptor_tag.
22 const TAG: u8;
23 /// Diagnostic name. Convention (workspace-wide): SCREAMING_SNAKE,
24 /// suffix-free — `SHORT_EVENT`, `EXTENSION`, `NETWORK_NAME`
25 /// (no `_descriptor` suffix).
26 const NAME: &'static str;
27}
28
29/// Implemented by every typed table; drives [`crate::tables::AnyTable`]
30/// dispatch. `TABLE_ID_RANGES` lists the inclusive `(lo, hi)` table_id ranges
31/// this type accepts.
32pub trait TableDef<'a>: dvb_common::Parse<'a, Error = crate::error::Error> {
33 /// Inclusive `(lo, hi)` table_id ranges this type parses.
34 ///
35 /// Single-id types use a single-element slice `&[(id, id)]`.
36 /// Multi-range types (e.g. SDT `[(0x42,0x42),(0x46,0x46)]`) list each
37 /// contiguous run separately.
38 const TABLE_ID_RANGES: &'static [(u8, u8)];
39 /// Spec name for diagnostics. SCREAMING_SNAKE, suffix-free:
40 /// `PROGRAM_ASSOCIATION`, `EVENT_INFORMATION`, `SERVICE_DESCRIPTION`.
41 ///
42 /// Deliberate exceptions: `DSM_CC_SECTION` and `MPE_DATAGRAM_SECTION` keep
43 /// `_SECTION` because it is part of the spec entity name, not a type suffix.
44 const NAME: &'static str;
45}
46
47/// Contract every section-carried table implements.
48pub trait Table<'a>: Parse<'a> + Serialize {
49 /// Expected `table_id` for this table.
50 ///
51 /// Tables that occupy a range of table_ids (e.g. EIT schedule which covers
52 /// 0x50..=0x5F) expose a range helper on the type itself rather than a
53 /// single `TABLE_ID` constant.
54 const TABLE_ID: u8;
55
56 /// PID on which this table is typically carried.
57 ///
58 /// Some tables (PMT) use per-programme PIDs signalled by PAT; those
59 /// return `0x0000` here and the consumer is expected to know better.
60 const PID: u16;
61}