1use crate::*;
2
3ext! {
4 name: Ainf,
5 versions: [0],
6 flags: {
7 hidden = 0,
8 }
9}
10
11#[derive(Debug, Clone, PartialEq, Eq, Default)]
12#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
13pub struct Ainf {
14 pub hidden: bool,
15 pub profile_version: u32,
17 pub apid: String,
18}
19
20impl AtomExt for Ainf {
21 const KIND_EXT: FourCC = FourCC::new(b"ainf");
22
23 type Ext = AinfExt;
24
25 fn decode_body_ext<B: Buf>(buf: &mut B, ext: AinfExt) -> Result<Self> {
26 let profile_version = u32::decode(buf)?;
27 let apid = String::decode(buf)?;
28 let remaining = buf.remaining();
29 if remaining != 0 {
30 tracing::warn!("Found additional data in ainf box, which could be additional private boxes, and that data is being ignored.");
31 buf.advance(remaining);
32 }
33 Ok(Ainf {
34 hidden: ext.hidden,
35 profile_version,
36 apid,
37 })
38 }
39
40 fn encode_body_ext<B: BufMut>(&self, buf: &mut B) -> Result<AinfExt> {
41 let ext = AinfExt {
42 hidden: self.hidden,
43 version: AinfVersion::V0,
44 };
45 self.profile_version.encode(buf)?;
46 self.apid.as_str().encode(buf)?;
47 Ok(ext)
48 }
49}
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 const ENCODED_AINF: &[u8] = &[
56 0x00, 0x00, 0x00, 0x38, 0x61, 0x69, 0x6e, 0x66, 0x00, 0x00, 0x00, 0x00, 0x68, 0x31, 0x30,
57 0x37, 0x75, 0x72, 0x6e, 0x3a, 0x64, 0x65, 0x63, 0x65, 0x3a, 0x61, 0x70, 0x69, 0x64, 0x3a,
58 0x6f, 0x72, 0x67, 0x3a, 0x64, 0x65, 0x63, 0x65, 0x63, 0x76, 0x70, 0x3a, 0x64, 0x65, 0x76,
59 0x69, 0x63, 0x65, 0x30, 0x30, 0x32, 0x2d, 0x34, 0x76, 0x37, 0x00,
60 ];
61
62 #[test]
63 fn test_ainf_decode() {
64 let buf: &mut std::io::Cursor<&&[u8]> = &mut std::io::Cursor::new(&ENCODED_AINF);
65 let ainf = Ainf::decode(buf).expect("failed to decode ainf");
66 assert_eq!(
67 ainf,
68 Ainf {
69 hidden: false,
70 profile_version: 1748054071,
71 apid: "urn:dece:apid:org:dececvp:device002-4v7".into(),
72 }
73 );
74 }
75
76 #[test]
77 fn test_ainf_encode() {
78 let ainf = Ainf {
79 hidden: false,
80 profile_version: 1748054071,
81 apid: "urn:dece:apid:org:dececvp:device002-4v7".into(),
82 };
83
84 let mut buf = Vec::new();
85 ainf.encode(&mut buf).unwrap();
86 assert_eq!(buf, ENCODED_AINF);
87 }
88}