Skip to main content

scte35_splice/commands/
splice_null.rs

1//! splice_null() — ANSI/SCTE 35 2023r1 §9.7.1, Table 8 (splice_command_type 0x00).
2//!
3//! An empty command body; lets a section carry descriptors with no other
4//! command, or act as a heartbeat. Parses/serializes to zero body bytes.
5
6use crate::error::{Error, Result};
7use crate::traits::CommandDef;
8use broadcast_common::{Parse, Serialize};
9
10/// `splice_command_type` for splice_null (§9.6.1, Table 7).
11pub const COMMAND_TYPE: u8 = 0x00;
12
13/// splice_null() command (empty body).
14#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
15#[cfg_attr(feature = "serde", derive(serde::Serialize))]
16pub struct SpliceNull;
17
18impl<'a> Parse<'a> for SpliceNull {
19    type Error = Error;
20    fn parse(_bytes: &'a [u8]) -> Result<Self> {
21        Ok(Self)
22    }
23}
24
25impl Serialize for SpliceNull {
26    type Error = Error;
27    fn serialized_len(&self) -> usize {
28        0
29    }
30    fn serialize_into(&self, _buf: &mut [u8]) -> Result<usize> {
31        Ok(0)
32    }
33}
34
35impl<'a> CommandDef<'a> for SpliceNull {
36    const COMMAND_TYPE: u8 = COMMAND_TYPE;
37    const NAME: &'static str = "SPLICE_NULL";
38}
39
40#[cfg(test)]
41mod tests {
42    use super::*;
43
44    #[test]
45    fn round_trip_empty() {
46        let cmd = SpliceNull;
47        assert_eq!(cmd.serialized_len(), 0);
48        let bytes = cmd.to_bytes();
49        assert!(bytes.is_empty());
50        assert_eq!(SpliceNull::parse(&bytes).unwrap(), cmd);
51    }
52}