Skip to main content

aprs_decode/
capabilities.rs

1/// An APRS Station Capabilities report.
2///
3/// DTI: `<`
4///
5/// Lists the capabilities of the station, typically as a comma-separated
6/// list of `KEY=VALUE` pairs or bare tokens (e.g. `IGATE,MSG_CNT=0`).
7/// The content is stored verbatim — the spec doesn't define a normative format.
8#[derive(Debug, Clone, PartialEq, Eq)]
9#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
10pub struct AprsCapabilities {
11    /// Raw capability string (everything after the `<` DTI byte).
12    pub raw: Vec<u8>,
13}
14
15impl AprsCapabilities {
16    /// Decode from the information field (including the leading `<` DTI byte).
17    pub(crate) fn parse(info: &[u8]) -> Self {
18        Self { raw: info.get(1..).unwrap_or_default().to_vec() }
19    }
20
21    pub fn encode(&self) -> Vec<u8> {
22        let mut out = vec![b'<'];
23        out.extend_from_slice(&self.raw);
24        out
25    }
26}
27
28#[cfg(test)]
29mod tests {
30    use super::*;
31
32    #[test]
33    fn round_trip() {
34        let raw = b"<IGATE,MSG_CNT=10,LOC_CNT=20";
35        let cap = AprsCapabilities::parse(raw);
36        assert_eq!(cap.raw, b"IGATE,MSG_CNT=10,LOC_CNT=20");
37        assert_eq!(cap.encode().as_slice(), raw.as_slice());
38    }
39
40    #[test]
41    fn empty_capabilities() {
42        let cap = AprsCapabilities::parse(b"<");
43        assert!(cap.raw.is_empty());
44    }
45}