Struct w5500_hl::TcpReader

source ·
pub struct TcpReader<'w, W5500> { /* private fields */ }
Expand description

Streaming reader for a TCP socket buffer.

This implements the Read and Seek traits.

Created with Tcp::tcp_reader.

Example

use w5500_hl::{
    io::Read,
    ll::{Registers, Sn, SocketInterrupt},
    net::{Ipv4Addr, SocketAddrV4},
    Tcp, TcpReader,
};

const MQTT_SOCKET: Sn = Sn::Sn0;
const MQTT_SOURCE_PORT: u16 = 33650;
const MQTT_SERVER: SocketAddrV4 = SocketAddrV4::new(Ipv4Addr::new(192, 168, 2, 10), 1883);

w5500.tcp_connect(MQTT_SOCKET, MQTT_SOURCE_PORT, &MQTT_SERVER)?;

// ... wait for a CON interrupt

const CONNECT: [u8; 14] = [
    0x10, 0x0C, 0x00, 0x04, b'M', b'Q', b'T', b'T', 0x04, 0x02, 0x0E, 0x10, 0x00, 0x00,
];
let tx_bytes: u16 = w5500.tcp_write(MQTT_SOCKET, &CONNECT)?;
assert_eq!(usize::from(tx_bytes), CONNECT.len());

// ... wait for a RECV interrupt

let mut reader: TcpReader<_> = w5500.tcp_reader(MQTT_SOCKET)?;
let mut buf = [0; 2];

// read the first two bytes
reader.read_exact(&mut buf)?;
// ... do something with the data

// read another two bytes into the same buffer
reader.read_exact(&mut buf)?;
// ... do something with the data

// mark the data as read
reader.done()?;

Trait Implementations§

source§

impl<'w, W5500: Debug> Debug for TcpReader<'w, W5500>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'w, W5500> Format for TcpReader<'w, W5500>where W5500: Format,

source§

fn format(&self, f: Formatter<'_>)

Writes the defmt representation of self to fmt.
source§

impl<'a, W5500: Registers> Read<<W5500 as Registers>::Error> for TcpReader<'a, W5500>

source§

fn read(&mut self, buf: &mut [u8]) -> Result<u16, W5500::Error>

Read data from the UDP socket, and return the number of bytes read.
source§

fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error<W5500::Error>>

Read the exact number of bytes required to fill buf. Read more
source§

fn done(self) -> Result<(), W5500::Error>

Mark the data as read, removing the data from the queue. Read more
source§

impl<'w, W5500> Seek for TcpReader<'w, W5500>

source§

fn seek<E>(&mut self, pos: SeekFrom) -> Result<(), Error<E>>

Seek to an offset, in bytes, within the socket buffer. Read more
source§

fn rewind(&mut self)

Rewind to the beginning of the stream. Read more
source§

fn stream_len(&self) -> u16

Return the length of the stream, in bytes. Read more
source§

fn stream_position(&self) -> u16

Returns the current seek position from the start of the stream.
source§

fn remain(&self) -> u16

Remaining bytes in the socket buffer from the current seek position.

Auto Trait Implementations§

§

impl<'w, W5500> RefUnwindSafe for TcpReader<'w, W5500>where W5500: RefUnwindSafe,

§

impl<'w, W5500> Send for TcpReader<'w, W5500>where W5500: Send,

§

impl<'w, W5500> Sync for TcpReader<'w, W5500>where W5500: Sync,

§

impl<'w, W5500> Unpin for TcpReader<'w, W5500>

§

impl<'w, W5500> !UnwindSafe for TcpReader<'w, W5500>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.