1use crate::*;
2
3ext! {
7 name: Pitm,
8 versions: [0, 1],
9 flags: {}
10}
11
12#[derive(Debug, Clone, PartialEq, Eq, Default)]
13#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
14pub struct Pitm {
15 pub item_id: u32,
16}
17
18impl AtomExt for Pitm {
19 type Ext = PitmExt;
20
21 const KIND_EXT: FourCC = FourCC::new(b"pitm");
22
23 fn decode_body_ext<B: Buf>(buf: &mut B, ext: PitmExt) -> Result<Self> {
24 if ext.version == PitmVersion::V0 {
25 Ok(Pitm {
26 item_id: u16::decode(buf)?.into(),
27 })
28 } else {
29 Ok(Pitm {
30 item_id: u32::decode(buf)?,
31 })
32 }
33 }
34
35 fn encode_body_ext<B: BufMut>(&self, buf: &mut B) -> Result<PitmExt> {
36 if self.item_id <= u16::MAX.into() {
37 let id = self.item_id as u16;
38 id.encode(buf)?;
39 Ok(PitmExt {
40 version: PitmVersion::V0,
41 })
42 } else {
43 self.item_id.encode(buf)?;
44 Ok(PitmExt {
45 version: PitmVersion::V1,
46 })
47 }
48 }
49}