SlipDecoder

Struct SlipDecoder 

Source
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

Source

pub fn new() -> SlipDecoder

Instantiates a SlipDecoder.

Source

pub fn are_decoded_packets_available(&self) -> bool

This method indicates whether new decoded SLIP packets are available.

Source

pub fn get_packets(&mut self) -> Vec<Vec<u8>>

This method returns all decoded packets and removes them from the decoders memory.

Source

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

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.