Skip to main content

scte35_splice/commands/
bandwidth_reservation.rs

1//! bandwidth_reservation() — ANSI/SCTE 35 2023r1 §9.7.5, Table 12
2//! (splice_command_type 0x07).
3//!
4//! An empty command body, distinct from splice_null() so receivers can handle
5//! it uniquely (e.g. remove it from the multiplex).
6
7use crate::error::{Error, Result};
8use crate::traits::CommandDef;
9use broadcast_common::{Parse, Serialize};
10
11/// `splice_command_type` for bandwidth_reservation (§9.6.1, Table 7).
12pub const COMMAND_TYPE: u8 = 0x07;
13
14/// bandwidth_reservation() command (empty body).
15#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
16#[cfg_attr(feature = "serde", derive(serde::Serialize))]
17pub struct BandwidthReservation;
18
19impl<'a> Parse<'a> for BandwidthReservation {
20    type Error = Error;
21    fn parse(_bytes: &'a [u8]) -> Result<Self> {
22        Ok(Self)
23    }
24}
25
26impl Serialize for BandwidthReservation {
27    type Error = Error;
28    fn serialized_len(&self) -> usize {
29        0
30    }
31    fn serialize_into(&self, _buf: &mut [u8]) -> Result<usize> {
32        Ok(0)
33    }
34}
35
36impl<'a> CommandDef<'a> for BandwidthReservation {
37    const COMMAND_TYPE: u8 = COMMAND_TYPE;
38    const NAME: &'static str = "BANDWIDTH_RESERVATION";
39}
40
41#[cfg(test)]
42mod tests {
43    use super::*;
44
45    #[test]
46    fn round_trip_empty() {
47        let cmd = BandwidthReservation;
48        assert_eq!(cmd.serialized_len(), 0);
49        assert_eq!(BandwidthReservation::parse(&cmd.to_bytes()).unwrap(), cmd);
50    }
51}