Struct w5500_hl::UdpReader

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

Streaming reader for a UDP socket buffer.

This implements the Read and Seek traits.

Created with Udp::udp_reader.

Example

use w5500_hl::{
    io::Read,
    ll::{Registers, Sn::Sn0},
    net::{Ipv4Addr, SocketAddrV4},
    Udp, UdpReader,
};

const DEST: SocketAddrV4 = SocketAddrV4::new(Ipv4Addr::new(192, 0, 2, 1), 8081);

w5500.udp_bind(Sn0, 8080)?;

let mut reader: UdpReader<_> = w5500.udp_reader(Sn0)?;

let mut buf: [u8; 8] = [0; 8];
reader.read_exact(&mut buf)?;

let mut other_buf: [u8; 16] = [0; 16];
reader.read_exact(&mut buf)?;

// mark the datagram as done, removing it from the queue
reader.done()?;

Implementations§

source§

impl<'a, W: Registers> UdpReader<'a, W>

source

pub fn header(&self) -> &UdpHeader

Get the UDP header.

Example
use w5500_hl::{
    ll::{Registers, Sn::Sn0},
    net::{Ipv4Addr, SocketAddrV4},
    Udp, UdpHeader, UdpReader,
};

const DEST: SocketAddrV4 = SocketAddrV4::new(Ipv4Addr::new(192, 0, 2, 1), 8081);

w5500.udp_bind(Sn0, 8080)?;

let reader: UdpReader<_> = w5500.udp_reader(Sn0)?;
let header: &UdpHeader = reader.header();

Trait Implementations§

source§

impl<'w, W5500: Debug> Debug for UdpReader<'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 UdpReader<'w, W5500>where W5500: Format,

source§

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

Writes the defmt representation of self to fmt.
source§

impl<'w, W5500: Registers> Read<<W5500 as Registers>::Error> for UdpReader<'w, 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 UdpReader<'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 UdpReader<'w, W5500>where W5500: RefUnwindSafe,

§

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

§

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

§

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

§

impl<'w, W5500> !UnwindSafe for UdpReader<'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.