Skip to main content

osdp/reply/
ack.rs

1//! `osdp_ACK` (`0x40`). Empty body.
2//!
3//! # Spec: ยง7.1
4
5use crate::error::Error;
6use crate::payload_util::require_exact_len;
7use alloc::vec::Vec;
8
9/// `osdp_ACK` body.
10#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
11pub struct Ack;
12
13impl Ack {
14    /// Encode (always empty).
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, 0x40)?;
22        Ok(Self)
23    }
24}
25
26#[cfg(test)]
27mod tests {
28    use super::*;
29
30    #[test]
31    fn roundtrip_empty() {
32        assert!(Ack.encode().unwrap().is_empty());
33        assert_eq!(Ack::decode(&[]).unwrap(), Ack);
34    }
35
36    #[test]
37    fn decode_rejects_payload() {
38        assert!(matches!(
39            Ack::decode(&[0x00]),
40            Err(Error::PayloadLength { code: 0x40, .. })
41        ));
42    }
43}