Skip to main content

osdp/command/
id.rs

1//! `osdp_ID` (`0x61`) — request PD identification.
2//!
3//! # Spec: §6.2
4//!
5//! Body is a single `Reserved` byte (always `0x00`).
6
7use crate::error::Error;
8use alloc::vec::Vec;
9
10/// `osdp_ID` body.
11#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
12pub struct Id {
13    /// Reserved byte; spec mandates `0x00`.
14    pub reserved: u8,
15}
16
17impl Id {
18    /// Standard request: `reserved = 0x00`.
19    pub const fn standard() -> Self {
20        Self { reserved: 0 }
21    }
22
23    /// Encode.
24    pub fn encode(&self) -> Result<Vec<u8>, Error> {
25        Ok(alloc::vec![self.reserved])
26    }
27
28    /// Decode.
29    pub fn decode(data: &[u8]) -> Result<Self, Error> {
30        if data.len() != 1 {
31            return Err(Error::MalformedPayload {
32                code: 0x61,
33                reason: "ID requires 1-byte reserved field",
34            });
35        }
36        Ok(Self { reserved: data[0] })
37    }
38}