mp4_atom/meta/properties/
ispe.rs1use crate::*;
2
3#[derive(Debug, Clone, PartialEq, Eq, Default)]
7#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8pub struct Ispe {
9 pub width: u32,
10 pub height: u32,
11}
12
13impl AtomExt for Ispe {
14 type Ext = ();
15
16 const KIND_EXT: FourCC = FourCC::new(b"ispe");
17
18 fn decode_body_ext<B: Buf>(buf: &mut B, _ext: ()) -> Result<Self> {
19 let width = u32::decode(buf)?;
20 let height = u32::decode(buf)?;
21 Ok(Ispe { width, height })
22 }
23
24 fn encode_body_ext<B: BufMut>(&self, buf: &mut B) -> Result<()> {
25 self.width.encode(buf)?;
26 self.height.encode(buf)?;
27 Ok(())
28 }
29}
30
31#[cfg(test)]
32mod tests {
33 use super::*;
34
35 #[test]
36 fn test_ispe() {
37 let expected = Ispe {
38 width: 1024,
39 height: 768,
40 };
41 let mut buf = Vec::new();
42 expected.encode(&mut buf).unwrap();
43
44 let mut buf = buf.as_ref();
45 assert_eq!(
46 buf,
47 [0, 0, 0, 20, b'i', b's', b'p', b'e', 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 3, 0]
48 );
49 let decoded = Ispe::decode(&mut buf).unwrap();
50 assert_eq!(decoded, expected);
51 }
52}