Skip to main content

osdp/command/
local_status.rs

1//! Status-request commands with empty payloads:
2//!
3//! - `osdp_LSTAT` (`0x64`) — local (tamper/power) status.
4//! - `osdp_ISTAT` (`0x65`) — input contact status.
5//! - `osdp_OSTAT` (`0x66`) — output status.
6//! - `osdp_RSTAT` (`0x67`) — reader-tamper status.
7//!
8//! # Spec: §6.4 – §6.7
9
10use crate::error::Error;
11use alloc::vec::Vec;
12
13macro_rules! empty_status {
14    ($Ty:ident, $code:expr, $name:literal) => {
15        #[doc = concat!("`", $name, "` body (empty).")]
16        #[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
17        pub struct $Ty;
18
19        impl $Ty {
20            /// Encode (always empty).
21            pub fn encode(&self) -> Result<Vec<u8>, Error> {
22                Ok(Vec::new())
23            }
24
25            /// Decode (must be empty).
26            pub fn decode(data: &[u8]) -> Result<Self, Error> {
27                if !data.is_empty() {
28                    return Err(Error::MalformedPayload {
29                        code: $code,
30                        reason: concat!($name, " has no payload"),
31                    });
32                }
33                Ok(Self)
34            }
35        }
36    };
37}
38
39empty_status!(LocalStatus, 0x64, "osdp_LSTAT");
40empty_status!(InputStatus, 0x65, "osdp_ISTAT");
41empty_status!(OutputStatus, 0x66, "osdp_OSTAT");
42empty_status!(ReaderStatus, 0x67, "osdp_RSTAT");