1use crate::error::Error;
6use alloc::vec::Vec;
7
8#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
10pub struct Cap {
11 pub reserved: u8,
13}
14
15impl Cap {
16 pub const fn standard() -> Self {
18 Self { reserved: 0 }
19 }
20
21 pub fn encode(&self) -> Result<Vec<u8>, Error> {
23 Ok(alloc::vec![self.reserved])
24 }
25
26 pub fn decode(data: &[u8]) -> Result<Self, Error> {
28 if data.len() != 1 {
29 return Err(Error::MalformedPayload {
30 code: 0x62,
31 reason: "CAP requires 1-byte reserved field",
32 });
33 }
34 Ok(Self { reserved: data[0] })
35 }
36}