mp4_atom/meta/ilst/
mod.rs1mod covr;
2mod desc;
3mod name;
4mod year;
5
6pub use covr::*;
7pub use desc::*;
8pub use name::*;
9pub use year::*;
10
11use crate::*;
12
13#[derive(Debug, Clone, PartialEq, Eq, Default)]
14#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
15pub struct Ilst {
16 pub name: Option<Name>,
17 pub year: Option<Year>, pub covr: Option<Covr>,
19 pub desc: Option<Desc>,
20}
21
22impl Atom for Ilst {
23 const KIND: FourCC = FourCC::new(b"ilst");
24
25 fn decode_body<B: Buf>(buf: &mut B) -> Result<Self> {
26 let mut name = None;
27 let mut year = None;
28 let mut covr = None;
29 let mut desc = None;
30
31 while let Some(atom) = Any::decode_maybe(buf)? {
32 match atom {
33 Any::Name(atom) => name = atom.into(),
34 Any::Year(atom) => year = atom.into(),
35 Any::Covr(atom) => covr = atom.into(),
36 Any::Desc(atom) => desc = atom.into(),
37 Any::Unknown(kind, _) => tracing::warn!("unknown atom: {:?}", kind),
38 atom => return Err(Error::UnexpectedBox(atom.kind())),
39 }
40 }
41
42 Ok(Ilst {
43 name,
44 year,
45 covr,
46 desc,
47 })
48 }
49
50 fn encode_body<B: BufMut>(&self, buf: &mut B) -> Result<()> {
51 self.name.encode(buf)?;
52 self.year.encode(buf)?;
53 self.covr.encode(buf)?;
54 self.desc.encode(buf)?;
55 Ok(())
56 }
57}
58
59#[cfg(test)]
60mod tests {
61 use super::*;
62
63 #[test]
64 fn test_ilst() {
65 let expected = Ilst {
66 year: Year("src_year".to_string()).into(),
67 ..Default::default()
68 };
69
70 let mut buf = Vec::new();
71 expected.encode(&mut buf).unwrap();
72
73 let mut buf = buf.as_ref();
74 let decoded = Ilst::decode(&mut buf).unwrap();
75 assert_eq!(decoded, expected);
76 }
77
78 #[test]
79 fn test_ilst_empty() {
80 let expected = Ilst::default();
81 let mut buf = Vec::new();
82 expected.encode(&mut buf).unwrap();
83
84 let mut buf = buf.as_ref();
85 let decoded = Ilst::decode(&mut buf).unwrap();
86 assert_eq!(decoded, expected);
87 }
88}