[−][src]Struct rubble::bytes::ByteReader
Allows reading values from a borrowed byte slice.
Methods
impl<'a> ByteReader<'a>
[src]
pub fn new(bytes: &'a [u8]) -> Self
[src]
Creates a new ByteReader
that will read from the given byte slice.
pub fn as_raw_bytes(&self) -> &'a [u8]
[src]
Returns a reference to the raw bytes in self
, without advancing self
or reading any
data.
pub fn into_rest(self) -> &'a [u8]
[src]
Consumes self
and returns the part of the contained buffer that has not yet been read
from.
pub fn skip(&mut self, bytes: usize) -> Result<(), Error>
[src]
Skips the given number of bytes in the input data without inspecting them.
This is a potentially dangerous operation that should only be used when the bytes really do not matter.
#[must_use]
pub fn split_off(&mut self, len: usize) -> Result<Self, Error>
[src]
Creates and returns another ByteReader
that will read from the next len
Bytes in the
buffer.
self
will be modified to point after the split-off bytes, and will continue reading from
there.
Note that if the created ByteReader
is not used, the bytes will be ignored. If you are
really sure you want that, skip
is a more explicit way of accomplishing that.
pub fn bytes_left(&self) -> usize
[src]
Returns the number of bytes that can still be read from self
.
pub fn is_empty(&self) -> bool
[src]
Returns whether self
is at the end of the underlying buffer (EOF).
If this returns true
, no data can be read from self
anymore.
pub fn read_slice(&mut self, len: usize) -> Result<&'a [u8], Error>
[src]
Reads a byte slice of length len
from self
.
If self
contains less than len
bytes, Error::Eof
will be returned and self
will not
be modified.
pub fn read_array<S>(&mut self) -> Result<S, Error> where
S: Default + AsMut<[u8]>,
[src]
S: Default + AsMut<[u8]>,
Reads a byte-array-like type S
from self
.
S
must implement Default
and AsMut<[u8]>
, which allows using small arrays up to 32
bytes as well as datastructures from alloc
(eg. Box<[u8]>
or Vec<u8>
).
pub fn read_rest(&mut self) -> &'a [u8]
[src]
Reads the remaining bytes from self
.
pub fn read_u8(&mut self) -> Result<u8, Error>
[src]
Reads a single byte from self
.
Returns Error::Eof
when self
is empty.
pub fn read_u16_le(&mut self) -> Result<u16, Error>
[src]
Reads a u16
from self
, using Little Endian byte order.
pub fn read_u32_le(&mut self) -> Result<u32, Error>
[src]
Reads a u32
from self
, using Little Endian byte order.
pub fn read_u64_le(&mut self) -> Result<u64, Error>
[src]
Reads a u64
from self
, using Little Endian byte order.
Auto Trait Implementations
impl<'a> Send for ByteReader<'a>
impl<'a> Sync for ByteReader<'a>
Blanket Implementations
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,