From f13606d8515181b9ccd2fb7bcca84d4495542e8e Mon Sep 17 00:00:00 2001 From: Rafael Caricio Date: Sun, 1 May 2022 15:49:28 +0200 Subject: [PATCH] Allow modification before encoding --- README.md | 4 +--- src/descriptors/mod.rs | 2 +- src/info.rs | 34 +++++++++++++++++++++++++++++++--- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 67cde9d..3be9822 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,7 @@ other purposes. More information can be found at - Parsing of SCTE-35 data - Encoding of SCTE-35 data -- `no_std` support -- Serde integration for serialization and deserialization in other formats - +- Serde integration for serialization into JSON or any other [serde supported formats](https://docs.rs/serde/1.0.137/serde/#data-formats). ## Implementation Overview diff --git a/src/descriptors/mod.rs b/src/descriptors/mod.rs index 1fad41d..3f54729 100644 --- a/src/descriptors/mod.rs +++ b/src/descriptors/mod.rs @@ -7,7 +7,7 @@ use std::io; #[cfg(feature = "serde")] use serde::Serialize; -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serde", derive(Serialize))] pub enum SpliceDescriptor { Avail, diff --git a/src/info.rs b/src/info.rs index fc8760a..cd60c51 100644 --- a/src/info.rs +++ b/src/info.rs @@ -91,6 +91,34 @@ where encoded: NotEncoded, } } + + pub fn set_sap_type(&mut self, sap_type: SAPType) { + self.state.sap_type = sap_type; + } + + pub fn set_pts_adjustment(&mut self, pts_adjustment: u64) { + self.state.pts_adjustment = pts_adjustment; + } + + pub fn set_tier(&mut self, tier: u16) { + self.state.tier = tier; + } + + pub fn add_descriptor(&mut self, descriptor: SpliceDescriptor) { + self.state.descriptors.push(descriptor); + } + + pub fn remove_descriptor(&mut self, index: usize) { + self.state.descriptors.remove(index); + } + + pub fn descriptor_index(&self, descriptor: &SpliceDescriptor) -> Option { + self.state.descriptors.iter().position(|d| d == descriptor) + } + + pub fn get_descriptor_mut(&mut self, index: usize) -> Option<&mut SpliceDescriptor> { + self.state.descriptors.get_mut(index) + } } impl SpliceInfoSection @@ -285,7 +313,7 @@ mod serde_serialization { "descriptor_loop_length", &self.encoded.descriptor_loop_length, )?; - state.serialize_field("descriptor_loop", &self.state.descriptors)?; + state.serialize_field("descriptors", &self.state.descriptors)?; state.serialize_field("crc_32", &as_hex(self.encoded.crc32))?; state.end() } @@ -300,7 +328,7 @@ mod tests { use assert_json_diff::assert_json_eq; #[test] - fn write_null_splice() -> Result<()> { + fn write_splice_null_as_base64() -> Result<()> { let splice = SpliceInfoSection::new(SpliceNull::new()); assert_eq!( @@ -334,7 +362,7 @@ mod tests { "splice_command_type": 0, "splice_command": {}, "descriptor_loop_length": 0, - "descriptor_loop": [], + "descriptors": [], "crc_32": "0x7a4fbfff" }) );