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