Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added gated serde support for metadata behind serde feature flag #251

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ All metadata readers are provided by the `symphonia-metadata` crate.
| Vorbis comment (FLAC) | Perfect |
| Vorbis comment (OGG) | Perfect |

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:
Expand Down
9 changes: 9 additions & 0 deletions symphonia-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,22 @@ opt-simd = [
"opt-simd-neon",
]

# Enable Serde support.
serde = ["dep:serde"]

[dependencies]
arrayvec = "0.7.1"
bitflags = "1.2.1"
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
Expand Down
14 changes: 14 additions & 0 deletions symphonia-core/src/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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]>),
Expand Down Expand Up @@ -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`.
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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<Tag>,
visuals: Vec<Visual>,
Expand Down Expand Up @@ -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<MetadataRevision>,
}
Expand Down
3 changes: 3 additions & 0 deletions symphonia/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ opt-simd = [
"opt-simd-neon",
]

# Enable Serde support.
serde = ["symphonia-core/serde"]

[dependencies]
lazy_static = "1.4.0"

Expand Down