donet_core::datagram::iterator

Struct DatagramIterator

source
pub struct DatagramIterator {
    datagram: Datagram,
    index: usize,
}
Expand description

Utility for iterating value by value of a datagram message.

Fields§

§datagram: Datagram§index: usize

Implementations§

source§

impl DatagramIterator

source

pub fn check_read_length(&mut self, bytes: usize) -> Result<(), IteratorError>

source

pub fn tell(&mut self) -> usize

Returns the value of self.index, which is in bytes.

source

pub fn seek(&mut self, index: usize)

Manually sets the index position.

source

pub fn skip(&mut self, bytes: usize) -> Result<(), IteratorError>

Increments the index by bytes length. Returns DgError.DatagramIteratorEOF if it’s past the end of the buffer.

source

pub fn get_remaining(&mut self) -> usize

Returns the number of unread bytes left in the datagram

source

pub fn read_data(&mut self, bytes: usize) -> Result<Vec<u8>, IteratorError>

Reads the next number of bytes in the datagram.

source

pub fn read_u8(&mut self) -> Result<u8, IteratorError>

source

pub fn read_u16(&mut self) -> Result<u16, IteratorError>

source

pub fn read_u32(&mut self) -> Result<u32, IteratorError>

source

pub fn read_u64(&mut self) -> Result<u64, IteratorError>

source

pub fn read_i8(&mut self) -> Result<i8, IteratorError>

source

pub fn read_i16(&mut self) -> Result<i16, IteratorError>

source

pub fn read_i32(&mut self) -> Result<i32, IteratorError>

source

pub fn read_i64(&mut self) -> Result<i64, IteratorError>

source

pub fn read_f32(&mut self) -> Result<f32, IteratorError>

32-bit IEEE 754 floating point in native endianness.

source

pub fn read_f64(&mut self) -> Result<f64, IteratorError>

64-bit IEEE 754 floating point in native endianness.

source

pub fn read_bool(&mut self) -> Result<bool, IteratorError>

source

pub fn read_string(&mut self) -> Result<String, IteratorError>

Attempts to read a String data type from the datagram as a UTF-8 string. Returns a String if OK.

If the string type payload is not of UTF-8 format, a IteratorError::Utf8Error variant will be returned.

source

pub fn read_size(&mut self) -> Result<DgSizeTag, IteratorError>

source

pub fn read_channel(&mut self) -> Result<Channel, IteratorError>

source

pub fn read_doid(&mut self) -> Result<DoId, IteratorError>

source

pub fn read_zone(&mut self) -> Result<Zone, IteratorError>

source

pub fn read_datagram(&mut self) -> Result<Datagram, IteratorError>

Reads a blob data type and returns a Datagram.

source

pub fn read_recipient_count(&mut self) -> Result<u8, IteratorError>

Get the recipient count in a datagram message.

Alias of [Datagram::read_u8].

source

pub fn read_msg_type(&mut self) -> Result<Protocol, IteratorError>

Returns the datagram’s message type as a Protocol variant.

source

pub fn peek_recipient_count(&mut self) -> Result<u8, IteratorError>

Get the recipient count in a datagram message. Does not advance the index.

source

pub fn peek_msg_type(&mut self) -> Result<Protocol, IteratorError>

Returns the datagram’s message type. Does not advance the index. Useful for if index needs to be saved or if next field isn’t msg type. If iterating through a fresh datagram, use Self::read_msg_type.

Trait Implementations§

source§

impl Debug for DatagramIterator

source§

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

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

impl From<Datagram> for DatagramIterator

Create a new DatagramIterator from a Datagram.

source§

fn from(value: Datagram) -> Self

Converts to this type from the input type.

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.