Skip to main content

osdp/command/
abort.rs

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