Skip to main content

osdp/command/
keep_active.rs

1//! `osdp_KEEPACTIVE` (`0xA7`) — instruct the PD to keep its reader active.
2//!
3//! # Spec: §6.27
4//!
5//! Body is a 16-bit little-endian millisecond duration.
6
7use crate::error::Error;
8use alloc::vec::Vec;
9
10/// `osdp_KEEPACTIVE` body.
11#[derive(Debug, Clone, Copy, PartialEq, Eq)]
12pub struct KeepActive {
13    /// Hold duration in milliseconds.
14    pub duration_ms: u16,
15}
16
17impl KeepActive {
18    /// Encode.
19    pub fn encode(&self) -> Result<Vec<u8>, Error> {
20        Ok(self.duration_ms.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: 0xA7,
28                reason: "KEEPACTIVE requires 2 bytes",
29            });
30        }
31        Ok(Self {
32            duration_ms: u16::from_le_bytes([data[0], data[1]]),
33        })
34    }
35}