Skip to main content

osdp/command/
cap.rs

1//! `osdp_CAP` (`0x62`) — request PD capabilities list.
2//!
3//! # Spec: §6.3
4
5use crate::error::Error;
6use alloc::vec::Vec;
7
8/// `osdp_CAP` body.
9#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
10pub struct Cap {
11    /// Reserved byte; spec mandates `0x00`.
12    pub reserved: u8,
13}
14
15impl Cap {
16    /// Standard request.
17    pub const fn standard() -> Self {
18        Self { reserved: 0 }
19    }
20
21    /// Encode.
22    pub fn encode(&self) -> Result<Vec<u8>, Error> {
23        Ok(alloc::vec![self.reserved])
24    }
25
26    /// Decode.
27    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}