osdp/command/
keep_active.rs1use crate::error::Error;
8use alloc::vec::Vec;
9
10#[derive(Debug, Clone, Copy, PartialEq, Eq)]
12pub struct KeepActive {
13 pub duration_ms: u16,
15}
16
17impl KeepActive {
18 pub fn encode(&self) -> Result<Vec<u8>, Error> {
20 Ok(self.duration_ms.to_le_bytes().to_vec())
21 }
22
23 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}