From 1dfe1af4c81ad0b25f1f6a5bfcc3f5613bea8613 Mon Sep 17 00:00:00 2001 From: netcrns Date: Sat, 20 Feb 2021 20:35:49 +0100 Subject: [PATCH] feat: derive serde traits on ffmpeg types refactor: address requested changes --- src/util/channel_layout.rs | 2 ++ src/util/chroma/location.rs | 2 ++ src/util/color/primaries.rs | 2 ++ src/util/color/range.rs | 2 ++ src/util/color/space.rs | 2 ++ src/util/color/transfer_characteristic.rs | 2 ++ src/util/format/pixel.rs | 2 ++ src/util/format/sample.rs | 4 ++++ src/util/rational.rs | 2 ++ 9 files changed, 20 insertions(+) diff --git a/src/util/channel_layout.rs b/src/util/channel_layout.rs index 75aa866..107b8fa 100644 --- a/src/util/channel_layout.rs +++ b/src/util/channel_layout.rs @@ -3,6 +3,8 @@ use libc::c_ulonglong; use crate::ffi::*; bitflags! { + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] + #[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] pub struct ChannelLayout: c_ulonglong { const FRONT_LEFT = AV_CH_FRONT_LEFT; const FRONT_RIGHT = AV_CH_FRONT_RIGHT; diff --git a/src/util/chroma/location.rs b/src/util/chroma/location.rs index 3bb9997..802be15 100644 --- a/src/util/chroma/location.rs +++ b/src/util/chroma/location.rs @@ -1,6 +1,8 @@ use crate::ffi::{AVChromaLocation::*, *}; #[derive(Eq, PartialEq, Clone, Copy, Debug)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] pub enum Location { Unspecified, Left, diff --git a/src/util/color/primaries.rs b/src/util/color/primaries.rs index 3d26b41..3b69b75 100644 --- a/src/util/color/primaries.rs +++ b/src/util/color/primaries.rs @@ -1,6 +1,8 @@ use crate::ffi::{AVColorPrimaries::*, *}; #[derive(Eq, PartialEq, Clone, Copy, Debug)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] pub enum Primaries { Reserved0, BT709, diff --git a/src/util/color/range.rs b/src/util/color/range.rs index b1a5f44..2b97807 100644 --- a/src/util/color/range.rs +++ b/src/util/color/range.rs @@ -1,6 +1,8 @@ use crate::ffi::{AVColorRange::*, *}; #[derive(Eq, PartialEq, Clone, Copy, Debug)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] pub enum Range { Unspecified, MPEG, diff --git a/src/util/color/space.rs b/src/util/color/space.rs index 40d8159..3464552 100644 --- a/src/util/color/space.rs +++ b/src/util/color/space.rs @@ -3,6 +3,8 @@ use std::{ffi::CStr, str::from_utf8_unchecked}; use crate::ffi::{AVColorSpace::*, *}; #[derive(Eq, PartialEq, Clone, Copy, Debug)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] pub enum Space { RGB, BT709, diff --git a/src/util/color/transfer_characteristic.rs b/src/util/color/transfer_characteristic.rs index 3d2476b..ec48503 100644 --- a/src/util/color/transfer_characteristic.rs +++ b/src/util/color/transfer_characteristic.rs @@ -1,6 +1,8 @@ use crate::ffi::{AVColorTransferCharacteristic::*, *}; #[derive(Eq, PartialEq, Clone, Copy, Debug)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] pub enum TransferCharacteristic { Reserved0, BT709, diff --git a/src/util/format/pixel.rs b/src/util/format/pixel.rs index f21b8b7..a8b336a 100644 --- a/src/util/format/pixel.rs +++ b/src/util/format/pixel.rs @@ -8,6 +8,8 @@ use thiserror::Error; use crate::ffi::{AVPixelFormat::*, *}; #[derive(Eq, PartialEq, Copy, Clone, Debug)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] pub enum Pixel { None, diff --git a/src/util/format/sample.rs b/src/util/format/sample.rs index 9755b78..4cfebb4 100644 --- a/src/util/format/sample.rs +++ b/src/util/format/sample.rs @@ -11,6 +11,8 @@ use libc::c_int; use crate::ffi::{AVSampleFormat::*, *}; #[derive(Eq, PartialEq, Copy, Clone, Debug)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] pub enum Sample { None, @@ -22,6 +24,8 @@ pub enum Sample { F64(Type), } +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] #[derive(Eq, PartialEq, Copy, Clone, Debug)] pub enum Type { Packed, diff --git a/src/util/rational.rs b/src/util/rational.rs index bf5ce88..b4497c9 100644 --- a/src/util/rational.rs +++ b/src/util/rational.rs @@ -9,6 +9,8 @@ use libc::c_int; use crate::ffi::*; #[derive(Copy, Clone)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] pub struct Rational(pub i32, pub i32); impl Rational {