Skip to main content

osdp/reply/
busy.rs

1//! `osdp_BUSY` (`0x79`) — PD is busy. Empty body. SQN must always be `0`.
2//!
3//! # Spec: §7.18
4
5use crate::error::Error;
6use crate::payload_util::require_exact_len;
7use alloc::vec::Vec;
8
9/// `osdp_BUSY` body.
10#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
11pub struct Busy;
12
13impl Busy {
14    /// Encode.
15    pub fn encode(&self) -> Result<Vec<u8>, Error> {
16        Ok(Vec::new())
17    }
18
19    /// Decode.
20    pub fn decode(data: &[u8]) -> Result<Self, Error> {
21        require_exact_len(data, 0, 0x79)?;
22        Ok(Self)
23    }
24}
25
26#[cfg(test)]
27mod tests {
28    use super::*;
29
30    #[test]
31    fn roundtrip_empty() {
32        assert!(Busy.encode().unwrap().is_empty());
33        assert_eq!(Busy::decode(&[]).unwrap(), Busy);
34    }
35
36    #[test]
37    fn decode_rejects_payload() {
38        assert!(matches!(
39            Busy::decode(&[0xFF]),
40            Err(Error::PayloadLength { code: 0x79, .. })
41        ));
42    }
43}