Skip to main content

osdp/command/
poll.rs

1//! `osdp_POLL` (`0x60`) — general inquiry; no payload.
2//!
3//! # Spec: §6.1
4
5use crate::error::Error;
6use crate::payload_util::require_exact_len;
7use alloc::vec::Vec;
8
9/// Empty body of the POLL command.
10#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
11pub struct Poll;
12
13impl Poll {
14    /// Encode (always empty).
15    pub fn encode(&self) -> Result<Vec<u8>, Error> {
16        Ok(Vec::new())
17    }
18
19    /// Decode (must be empty).
20    pub fn decode(data: &[u8]) -> Result<Self, Error> {
21        require_exact_len(data, 0, 0x60)?;
22        Ok(Self)
23    }
24}
25
26#[cfg(test)]
27mod tests {
28    use super::*;
29
30    #[test]
31    fn encode_is_empty() {
32        assert!(Poll.encode().unwrap().is_empty());
33    }
34
35    #[test]
36    fn decode_empty() {
37        assert_eq!(Poll::decode(&[]).unwrap(), Poll);
38    }
39
40    #[test]
41    fn decode_rejects_payload() {
42        assert!(matches!(
43            Poll::decode(&[0x00]),
44            Err(Error::PayloadLength { code: 0x60, .. })
45        ));
46    }
47}