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
impl DatagramIterator
pub fn check_read_length(&mut self, bytes: usize) -> Result<(), IteratorError>
sourcepub fn skip(&mut self, bytes: usize) -> Result<(), IteratorError>
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.
sourcepub fn get_remaining(&mut self) -> usize
pub fn get_remaining(&mut self) -> usize
Returns the number of unread bytes left in the datagram
sourcepub fn read_data(&mut self, bytes: usize) -> Result<Vec<u8>, IteratorError>
pub fn read_data(&mut self, bytes: usize) -> Result<Vec<u8>, IteratorError>
Reads the next number of bytes in the datagram.
pub fn read_u8(&mut self) -> Result<u8, IteratorError>
pub fn read_u16(&mut self) -> Result<u16, IteratorError>
pub fn read_u32(&mut self) -> Result<u32, IteratorError>
pub fn read_u64(&mut self) -> Result<u64, IteratorError>
pub fn read_i8(&mut self) -> Result<i8, IteratorError>
pub fn read_i16(&mut self) -> Result<i16, IteratorError>
pub fn read_i32(&mut self) -> Result<i32, IteratorError>
pub fn read_i64(&mut self) -> Result<i64, IteratorError>
sourcepub fn read_f32(&mut self) -> Result<f32, IteratorError>
pub fn read_f32(&mut self) -> Result<f32, IteratorError>
32-bit IEEE 754 floating point in native endianness.
sourcepub fn read_f64(&mut self) -> Result<f64, IteratorError>
pub fn read_f64(&mut self) -> Result<f64, IteratorError>
64-bit IEEE 754 floating point in native endianness.
pub fn read_bool(&mut self) -> Result<bool, IteratorError>
sourcepub fn read_string(&mut self) -> Result<String, IteratorError>
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.
pub fn read_size(&mut self) -> Result<DgSizeTag, IteratorError>
pub fn read_channel(&mut self) -> Result<Channel, IteratorError>
pub fn read_doid(&mut self) -> Result<DoId, IteratorError>
pub fn read_zone(&mut self) -> Result<Zone, IteratorError>
sourcepub fn read_datagram(&mut self) -> Result<Datagram, IteratorError>
pub fn read_datagram(&mut self) -> Result<Datagram, IteratorError>
Reads a blob
data type and returns a Datagram
.
sourcepub fn read_recipient_count(&mut self) -> Result<u8, IteratorError>
pub fn read_recipient_count(&mut self) -> Result<u8, IteratorError>
Get the recipient count in a datagram message.
Alias of [Datagram::read_u8
].
sourcepub fn read_msg_type(&mut self) -> Result<Protocol, IteratorError>
pub fn read_msg_type(&mut self) -> Result<Protocol, IteratorError>
Returns the datagram’s message type as a Protocol
variant.
sourcepub fn peek_recipient_count(&mut self) -> Result<u8, IteratorError>
pub fn peek_recipient_count(&mut self) -> Result<u8, IteratorError>
Get the recipient count in a datagram message. Does not advance the index.
sourcepub fn peek_msg_type(&mut self) -> Result<Protocol, IteratorError>
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
.