use crate::*;
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Copyright {
pub country_indicator: u16,
pub language_indicator: u16,
pub text: String,
}
impl Atom for Copyright {
const KIND: FourCC = FourCC::new(b"cprt");
fn decode_body<B: Buf>(buf: &mut B) -> Result<Self> {
let data = super::data::decode_text(buf)?;
Ok(Copyright {
country_indicator: data.country_indicator,
language_indicator: data.language_indicator,
text: data.text,
})
}
fn encode_body<B: BufMut>(&self, buf: &mut B) -> Result<()> {
super::data::encode_text(
self.country_indicator,
self.language_indicator,
&self.text,
buf,
)
}
}
#[cfg(test)]
mod tests {
use super::*;
const ENCODED_CPRT_LONG: &[u8] = &[
0x00, 0x00, 0x00, 0x22, b'c', b'p', b'r', b't', 0x00, 0x00, 0x00, 0x1A, b'd', b'a', b't', b'a', 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, b'(', b'c', b')', b' ', b'2', b'0', b'2', b'6', b' ', b'x',
];
#[test]
fn test_copyright_long_style() {
let decoded = Copyright::decode(&mut &ENCODED_CPRT_LONG[..]).unwrap();
assert_eq!(decoded.country_indicator, 0);
assert_eq!(decoded.language_indicator, 0);
assert_eq!(decoded.text, "(c) 2026 x");
let mut out = Vec::new();
decoded.encode(&mut out).unwrap();
assert_eq!(out, ENCODED_CPRT_LONG);
}
#[test]
fn test_copyright_short_style() {
let buf = [
0x00, 0x00, 0x00, 0x14, b'c', b'p', b'r', b't', 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, b'2', b'0', b'2', b'6',
];
let decoded = Copyright::decode(&mut &buf[..]).unwrap();
assert_eq!(decoded.country_indicator, 0);
assert_eq!(decoded.language_indicator, 0);
assert_eq!(decoded.text, "2026");
}
}