osdp/command/
acu_rx_size.rs1use crate::error::Error;
8use crate::payload_util::require_exact_len;
9use alloc::vec::Vec;
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13pub struct AcuRxSize {
14 pub max_size: u16,
16}
17
18impl AcuRxSize {
19 pub fn encode(&self) -> Result<Vec<u8>, Error> {
21 Ok(self.max_size.to_le_bytes().to_vec())
22 }
23
24 pub fn decode(data: &[u8]) -> Result<Self, Error> {
26 require_exact_len(data, 2, 0x7B)?;
27 Ok(Self {
28 max_size: u16::from_le_bytes([data[0], data[1]]),
29 })
30 }
31}
32
33#[cfg(test)]
34mod tests {
35 use super::*;
36
37 #[test]
38 fn roundtrip() {
39 let body = AcuRxSize { max_size: 0x0123 };
40 let bytes = body.encode().unwrap();
41 assert_eq!(bytes, [0x23, 0x01]);
42 assert_eq!(AcuRxSize::decode(&bytes).unwrap(), body);
43 }
44
45 #[test]
46 fn decode_rejects_short() {
47 assert!(matches!(
48 AcuRxSize::decode(&[0x10]),
49 Err(Error::PayloadLength { code: 0x7B, .. })
50 ));
51 }
52}