libaprs_engine/
transport.rs1#[derive(Clone, Debug, Eq, PartialEq)]
3pub struct LineTransport<'a> {
4 input: &'a [u8],
5}
6
7impl<'a> LineTransport<'a> {
8 #[must_use]
10 pub fn new(input: &'a [u8]) -> Self {
11 Self { input }
12 }
13
14 #[must_use]
16 pub fn packets(&self) -> Vec<&'a [u8]> {
17 self.input
18 .split(|byte| *byte == b'\n')
19 .map(trim_trailing_carriage_return)
20 .filter(|line| !line.is_empty())
21 .collect()
22 }
23}
24
25fn trim_trailing_carriage_return(line: &[u8]) -> &[u8] {
26 line.strip_suffix(b"\r").unwrap_or(line)
27}