pub struct SlipDecoder { /* private fields */ }Expand description
A SLIP decoder which supports split up packets. This occurs when for example the first half of a
SLIP packet is transmitted at the end of a UART DMA read and the other half in the next
UART DMA read. Also works over multiple calls of Self::decode. Decoded
packets are available via Self::are_decoded_packets_available and Self::get_packets.
§Example
use rusty_slip::slip::{encode, SlipDecoder};
use std::str;
// encode a slice
let data = "hello world!";
// make sure tx_buf is large enough
let mut tx_buf: [u8; 256] = [0; 256];
encode(&mut tx_buf, data.as_bytes());///
// decode packet
let mut decoder = SlipDecoder::new();
decoder.decode(&tx_buf);
let packets = decoder.get_packets();
let first_packet = packets.first().unwrap();
// decode Vec<u8> into a string
let packet_message = str::from_utf8(first_packet).expect("Could not convert decoded SLIP packet into a string!");
println!("{}", packet_message);
assert_eq!(data, packet_message);Implementations§
Source§impl SlipDecoder
impl SlipDecoder
Sourcepub fn new() -> SlipDecoder
pub fn new() -> SlipDecoder
Instantiates a SlipDecoder.
Sourcepub fn are_decoded_packets_available(&self) -> bool
pub fn are_decoded_packets_available(&self) -> bool
This method indicates whether new decoded SLIP packets are available.
Sourcepub fn get_packets(&mut self) -> Vec<Vec<u8>>
pub fn get_packets(&mut self) -> Vec<Vec<u8>>
This method returns all decoded packets and removes them from the decoders memory.
Sourcepub fn decode(&mut self, encoded_data: &[u8])
pub fn decode(&mut self, encoded_data: &[u8])
This method tries to decode the given SLIP data into one or more packets. Packets which
are not terminated at the end of the given slice are stored in the internal buffer
of the decoder. The decoder continues decoding these packets on the next call(s) of this method
with the new data supplied. Decoded packets are signaled via Self::are_decoded_packets_available and
can be fetched via Self::get_packets