From 99f612c8d75aa832d6ae5c67f41b38e5ac607941 Mon Sep 17 00:00:00 2001 From: Dustin Sweigart Date: Sun, 14 Jan 2024 11:37:05 -0500 Subject: [PATCH 1/3] added gated serde support for metadata behind `serde` feature flag --- README.md | 2 ++ symphonia-core/Cargo.toml | 9 +++++++++ symphonia-core/src/meta.rs | 14 ++++++++++++++ symphonia/Cargo.toml | 3 +++ 4 files changed, 28 insertions(+) diff --git a/README.md b/README.md index b4ab1a51..3c5377d7 100644 --- a/README.md +++ b/README.md @@ -144,6 +144,8 @@ All metadata readers are provided by the `symphonia-metadata` crate. | Vorbis comment (FLAC) | Perfect | | Vorbis comment (OGG) | Perfect | +Serialization/deserialization for metadata can be anbled with the `serde` feature flag. + ## Quality In addition to the safety guarantees afforded by Rust, Symphonia aims to: diff --git a/symphonia-core/Cargo.toml b/symphonia-core/Cargo.toml index 4db81690..caa6d6ef 100644 --- a/symphonia-core/Cargo.toml +++ b/symphonia-core/Cargo.toml @@ -27,6 +27,9 @@ opt-simd = [ "opt-simd-neon", ] +# Enable Serde support. +serde = ["dep:serde"] + [dependencies] arrayvec = "0.7.1" bitflags = "1.2.1" @@ -34,6 +37,12 @@ bytemuck = "1.7" lazy_static = "1.4.0" log = "0.4" +[dependencies.serde] +version = "1.0.195" +features = ["derive", "alloc"] +optional = true +default-features = false + [dependencies.rustfft] version = "6.1.0" optional = true diff --git a/symphonia-core/src/meta.rs b/symphonia-core/src/meta.rs index c1e30fd8..4a36b207 100644 --- a/symphonia-core/src/meta.rs +++ b/symphonia-core/src/meta.rs @@ -12,6 +12,8 @@ use std::collections::VecDeque; use std::convert::From; use std::fmt; use std::num::NonZeroU32; +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; use crate::errors::Result; use crate::io::MediaSourceStream; @@ -24,6 +26,7 @@ use crate::io::MediaSourceStream; /// All limits can be defaulted to a reasonable value specific to the situation. These defaults will /// generally not break any normal streams. #[derive(Copy, Clone, Debug)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum Limit { /// Do not impose any limit. None, @@ -53,6 +56,7 @@ impl Default for Limit { /// `MetadataOptions` is a common set of options that all metadata readers use. #[derive(Copy, Clone, Debug, Default)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct MetadataOptions { /// The maximum size limit in bytes that a tag may occupy in memory once decoded. Tags exceeding /// this limit will be skipped by the demuxer. Take note that tags in-memory are stored as UTF-8 @@ -70,6 +74,7 @@ pub struct MetadataOptions { /// The visual types listed here are derived from, though do not entirely cover, the ID3v2 APIC /// frame specification. #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum StandardVisualKey { FileIcon, OtherIcon, @@ -96,6 +101,7 @@ pub enum StandardVisualKey { /// A tag reader may assign a `StandardTagKey` to a `Tag` if the tag's key is generally /// accepted to map to a specific usage. #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum StandardTagKey { AcoustidFingerprint, AcoustidId, @@ -216,6 +222,7 @@ pub enum StandardTagKey { /// format, the actual data type a specific tag may have a lesser width or encoding than the data /// type in this enumeration. #[derive(Clone, Debug)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum Value { /// A binary buffer. Binary(Box<[u8]>), @@ -291,6 +298,7 @@ impl fmt::Display for Value { /// A `Tag` encapsulates a key-value pair of metadata. #[derive(Clone, Debug)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Tag { /// If the `Tag`'s key string is commonly associated with a typical type, meaning, or purpose, /// then if recognized a `StandardTagKey` will be assigned to this `Tag`. @@ -333,6 +341,7 @@ impl fmt::Display for Tag { /// A 2 dimensional (width and height) size type. #[derive(Copy, Clone, Debug, Default)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Size { /// The width in pixels. pub width: u32, @@ -342,6 +351,7 @@ pub struct Size { /// `ColorMode` indicates how the color of a pixel is encoded in a `Visual`. #[derive(Copy, Clone, Debug)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum ColorMode { /// Each pixel in the `Visual` stores its own color information. Discrete, @@ -353,6 +363,7 @@ pub enum ColorMode { /// A `Visual` is any 2 dimensional graphic. #[derive(Clone, Debug)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Visual { /// The Media Type (MIME Type) used to encode the `Visual`. pub media_type: String, @@ -381,6 +392,7 @@ pub struct Visual { /// `VendorData` is any binary metadata that is proprietary to a certain application or vendor. #[derive(Clone, Debug)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct VendorData { /// A text representation of the vendor's application identifier. pub ident: String, @@ -390,6 +402,7 @@ pub struct VendorData { /// `Metadata` is a container for a single discrete revision of metadata information. #[derive(Clone, Debug, Default)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct MetadataRevision { tags: Vec, visuals: Vec, @@ -492,6 +505,7 @@ impl<'a> Metadata<'a> { /// `MetadataLog` is a container for time-ordered `Metadata` revisions. #[derive(Clone, Debug, Default)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct MetadataLog { revisions: VecDeque, } diff --git a/symphonia/Cargo.toml b/symphonia/Cargo.toml index 223f6a33..eec658e9 100644 --- a/symphonia/Cargo.toml +++ b/symphonia/Cargo.toml @@ -77,6 +77,9 @@ opt-simd = [ "opt-simd-neon", ] +# Enable Serde support. +serde = ["symphonia-core/serde"] + [dependencies] lazy_static = "1.4.0" From 7349d5e0e035b58d8081c257d6776411a32bc61f Mon Sep 17 00:00:00 2001 From: Dustin Sweigart Date: Tue, 16 Jan 2024 13:12:44 -0500 Subject: [PATCH 2/3] fixed README.md typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3c5377d7..19de0b51 100644 --- a/README.md +++ b/README.md @@ -144,7 +144,7 @@ All metadata readers are provided by the `symphonia-metadata` crate. | Vorbis comment (FLAC) | Perfect | | Vorbis comment (OGG) | Perfect | -Serialization/deserialization for metadata can be anbled with the `serde` feature flag. +Serialization/deserialization for metadata can be enbled with the `serde` feature flag. ## Quality From 0ac1db841a07c899b54747294fd131c7ef390582 Mon Sep 17 00:00:00 2001 From: Dustin Sweigart Date: Mon, 19 Feb 2024 06:19:40 -0500 Subject: [PATCH 3/3] updatd README.md with serialization note --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 19de0b51..660cf1e5 100644 --- a/README.md +++ b/README.md @@ -146,6 +146,8 @@ All metadata readers are provided by the `symphonia-metadata` crate. Serialization/deserialization for metadata can be enbled with the `serde` feature flag. +> **Note:** Serialization/Deserialization is highly dependent on Symphonia versions. There are no guarantees of compatibility between versions. + ## Quality In addition to the safety guarantees afforded by Rust, Symphonia aims to: