defmt_decoder/stream/
raw.rs1use super::StreamDecoder;
2use crate::{DecodeError, Frame, Table};
3
4pub struct Raw<'a> {
5 table: &'a Table,
6 data: Vec<u8>,
7}
8
9impl<'a> Raw<'a> {
10 pub fn new(table: &'a Table) -> Self {
11 Self {
12 table,
13 data: Vec::new(),
14 }
15 }
16}
17
18impl StreamDecoder for Raw<'_> {
19 fn received(&mut self, data: &[u8]) {
20 self.data.extend_from_slice(data);
21 }
22
23 fn decode(&mut self) -> Result<Frame<'_>, DecodeError> {
24 match self.table.decode(&self.data) {
25 Ok((frame, consumed)) => {
26 self.data.drain(0..consumed);
27 Ok(frame)
28 }
29 Err(e) => Err(e),
30 }
31 }
32}