Skip to main content

osdp/command/
acu_rx_size.rs

1//! `osdp_ACURXSIZE` (`0x7B`) — inform the PD of the ACU's max receive size.
2//!
3//! # Spec: §6.19
4//!
5//! Body is a 16-bit little-endian byte count.
6
7use crate::error::Error;
8use alloc::vec::Vec;
9
10/// `osdp_ACURXSIZE` body.
11#[derive(Debug, Clone, Copy, PartialEq, Eq)]
12pub struct AcuRxSize {
13    /// Bytes the ACU can receive in one packet.
14    pub max_size: u16,
15}
16
17impl AcuRxSize {
18    /// Encode.
19    pub fn encode(&self) -> Result<Vec<u8>, Error> {
20        Ok(self.max_size.to_le_bytes().to_vec())
21    }
22
23    /// Decode.
24    pub fn decode(data: &[u8]) -> Result<Self, Error> {
25        if data.len() != 2 {
26            return Err(Error::MalformedPayload {
27                code: 0x7B,
28                reason: "ACURXSIZE requires 2 bytes",
29            });
30        }
31        Ok(Self {
32            max_size: u16::from_le_bytes([data[0], data[1]]),
33        })
34    }
35}