pub struct Reader {
mem: GuestMemory,
regions: DescriptorChainRegions,
}
Expand description
Provides high-level interface over the sequence of memory regions defined by readable descriptors in the descriptor chain.
Note that virtio spec requires driver to place any device-writable descriptors after any device-readable descriptors (2.6.4.2 in Virtio Spec v1.1). Reader will skip iterating over descriptor chain when first writable descriptor is encountered.
Fields§
§mem: GuestMemory
§regions: DescriptorChainRegions
Implementations§
source§impl Reader
impl Reader
sourcepub fn new_from_regions(
mem: &GuestMemory,
readable_regions: SmallVec<[MemRegion; 2]>
) -> Reader ⓘ
pub fn new_from_regions( mem: &GuestMemory, readable_regions: SmallVec<[MemRegion; 2]> ) -> Reader ⓘ
Construct a new Reader wrapper over readable_regions
.
sourcepub fn peek_obj<T: FromBytes>(&self) -> Result<T>
pub fn peek_obj<T: FromBytes>(&self) -> Result<T>
Reads an object from the descriptor chain buffer without consuming it.
sourcepub fn read_obj<T: FromBytes>(&mut self) -> Result<T>
pub fn read_obj<T: FromBytes>(&mut self) -> Result<T>
Reads and consumes an object from the descriptor chain buffer.
sourcepub fn collect<C: FromIterator<Result<T>>, T: FromBytes>(&mut self) -> C
pub fn collect<C: FromIterator<Result<T>>, T: FromBytes>(&mut self) -> C
Reads objects by consuming all the remaining data in the descriptor chain buffer and returns
them as a collection. Returns an error if the size of the remaining data is indivisible by
the size of an object of type T
.
sourcepub fn iter<T: FromBytes>(&mut self) -> ReaderIterator<'_, T> ⓘ
pub fn iter<T: FromBytes>(&mut self) -> ReaderIterator<'_, T> ⓘ
Creates an iterator for sequentially reading FromBytes
objects from the Reader
.
Unlike collect
, this doesn’t consume all the remaining data in the Reader
and
doesn’t require the objects to be stored in a separate collection.
sourcepub fn read_to_volatile_slice(&mut self, slice: VolatileSlice<'_>) -> usize
pub fn read_to_volatile_slice(&mut self, slice: VolatileSlice<'_>) -> usize
Reads data into a volatile slice up to the minimum of the slice’s length or the number of bytes remaining. Returns the number of bytes read.
sourcepub fn read_to_cb<C: FnOnce(&[VolatileSlice<'_>]) -> usize>(
&mut self,
cb: C,
count: usize
) -> usize
pub fn read_to_cb<C: FnOnce(&[VolatileSlice<'_>]) -> usize>( &mut self, cb: C, count: usize ) -> usize
Reads data from the descriptor chain buffer and passes the VolatileSlice
s to the callback
cb
.
sourcepub fn read_to<F: FileReadWriteVolatile>(
&mut self,
dst: F,
count: usize
) -> Result<usize>
pub fn read_to<F: FileReadWriteVolatile>( &mut self, dst: F, count: usize ) -> Result<usize>
Reads data from the descriptor chain buffer into a writable object.
Returns the number of bytes read from the descriptor chain buffer.
The number of bytes read can be less than count
if there isn’t
enough data in the descriptor chain buffer.
sourcepub fn read_to_at<F: FileReadWriteAtVolatile>(
&mut self,
dst: &F,
count: usize,
off: u64
) -> Result<usize>
pub fn read_to_at<F: FileReadWriteAtVolatile>( &mut self, dst: &F, count: usize, off: u64 ) -> Result<usize>
Reads data from the descriptor chain buffer into a File at offset off
.
Returns the number of bytes read from the descriptor chain buffer.
The number of bytes read can be less than count
if there isn’t
enough data in the descriptor chain buffer.
sourcepub fn read_exact_to<F: FileReadWriteVolatile>(
&mut self,
dst: F,
count: usize
) -> Result<()>
pub fn read_exact_to<F: FileReadWriteVolatile>( &mut self, dst: F, count: usize ) -> Result<()>
Reads data from the descriptor chain similar to ‘read_to’ except reading ‘count’ or returning an error if ‘count’ bytes can’t be read.
sourcepub fn read_exact_to_at<F: FileReadWriteAtVolatile>(
&mut self,
dst: &F,
count: usize,
off: u64
) -> Result<()>
pub fn read_exact_to_at<F: FileReadWriteAtVolatile>( &mut self, dst: &F, count: usize, off: u64 ) -> Result<()>
Reads data from the descriptor chain similar to ‘read_to_at’ except reading ‘count’ or returning an error if ‘count’ bytes can’t be read.
sourcepub async fn read_to_at_fut<F: AsyncDisk + ?Sized>(
&mut self,
dst: &F,
count: usize,
off: u64
) -> Result<usize>
pub async fn read_to_at_fut<F: AsyncDisk + ?Sized>( &mut self, dst: &F, count: usize, off: u64 ) -> Result<usize>
Reads data from the descriptor chain buffer into an AsyncDisk
at offset off
.
Returns the number of bytes read from the descriptor chain buffer.
The number of bytes read can be less than count
if there isn’t
enough data in the descriptor chain buffer.
sourcepub async fn read_exact_to_at_fut<F: AsyncDisk + ?Sized>(
&mut self,
dst: &F,
count: usize,
off: u64
) -> Result<()>
pub async fn read_exact_to_at_fut<F: AsyncDisk + ?Sized>( &mut self, dst: &F, count: usize, off: u64 ) -> Result<()>
Reads exactly count
bytes from the chain to the disk asynchronously or returns an error if
not enough data can be read.
sourcepub fn available_bytes(&self) -> usize
pub fn available_bytes(&self) -> usize
Returns number of bytes available for reading. May return an error if the combined lengths of all the buffers in the DescriptorChain would cause an integer overflow.
sourcepub fn bytes_read(&self) -> usize
pub fn bytes_read(&self) -> usize
Returns number of bytes already read from the descriptor chain buffer.
pub fn get_remaining_regions(&self) -> MemRegionIter<'_>
sourcepub fn get_remaining(&self) -> SmallVec<[VolatileSlice<'_>; 16]>
pub fn get_remaining(&self) -> SmallVec<[VolatileSlice<'_>; 16]>
Returns a &[VolatileSlice]
that represents all the remaining data in this Reader
.
Calling this method does not actually consume any data from the Reader
and callers should
call consume
to advance the Reader
.
sourcepub fn consume(&mut self, amt: usize)
pub fn consume(&mut self, amt: usize)
Consumes amt
bytes from the underlying descriptor chain. If amt
is larger than the
remaining data left in this Reader
, then all remaining data will be consumed.
sourcepub fn split_at(&mut self, offset: usize) -> Reader ⓘ
pub fn split_at(&mut self, offset: usize) -> Reader ⓘ
Splits this Reader
into two at the given offset in the DescriptorChain
buffer. After the
split, self
will be able to read up to offset
bytes while the returned Reader
can read
up to available_bytes() - offset
bytes. If offset > self.available_bytes()
, then the
returned Reader
will not be able to read any bytes.
Trait Implementations§
source§impl Read for Reader
impl Read for Reader
source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read
, except that it reads into a slice of buffers. Read moresource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)1.0.0 · source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf
. Read more1.0.0 · source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf
. Read more1.6.0 · source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf
. Read moresource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)cursor
. Read more1.0.0 · source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read moresource§impl Reader for Reader
impl Reader for Reader
fn read_struct<T>(&mut self) -> Result<T, Error>where
T: AsBytes + FromBytes + FromZeroes,
source§impl ZeroCopyReader for Reader
impl ZeroCopyReader for Reader
source§fn read_to(&mut self, f: &mut File, count: usize, off: u64) -> Result<usize>
fn read_to(&mut self, f: &mut File, count: usize, off: u64) -> Result<usize>
count
bytes from self
directly into f
at offset off
without storing
it in any intermediate buffers. If the return value is Ok(n)
then it must be guaranteed
that 0 <= n <= count
. If n
is 0
, then it can indicate one of 3 possibilities: Read moreAuto Trait Implementations§
impl RefUnwindSafe for Reader
impl Send for Reader
impl Sync for Reader
impl Unpin for Reader
impl UnwindSafe for Reader
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<R> ReadBytesExt for R
impl<R> ReadBytesExt for R
§fn read_u8(&mut self) -> Result<u8, Error>
fn read_u8(&mut self) -> Result<u8, Error>
§fn read_i8(&mut self) -> Result<i8, Error>
fn read_i8(&mut self) -> Result<i8, Error>
§fn read_u16<T>(&mut self) -> Result<u16, Error>where
T: ByteOrder,
fn read_u16<T>(&mut self) -> Result<u16, Error>where
T: ByteOrder,
§fn read_i16<T>(&mut self) -> Result<i16, Error>where
T: ByteOrder,
fn read_i16<T>(&mut self) -> Result<i16, Error>where
T: ByteOrder,
§fn read_u24<T>(&mut self) -> Result<u32, Error>where
T: ByteOrder,
fn read_u24<T>(&mut self) -> Result<u32, Error>where
T: ByteOrder,
§fn read_i24<T>(&mut self) -> Result<i32, Error>where
T: ByteOrder,
fn read_i24<T>(&mut self) -> Result<i32, Error>where
T: ByteOrder,
§fn read_u32<T>(&mut self) -> Result<u32, Error>where
T: ByteOrder,
fn read_u32<T>(&mut self) -> Result<u32, Error>where
T: ByteOrder,
§fn read_i32<T>(&mut self) -> Result<i32, Error>where
T: ByteOrder,
fn read_i32<T>(&mut self) -> Result<i32, Error>where
T: ByteOrder,
§fn read_u48<T>(&mut self) -> Result<u64, Error>where
T: ByteOrder,
fn read_u48<T>(&mut self) -> Result<u64, Error>where
T: ByteOrder,
§fn read_i48<T>(&mut self) -> Result<i64, Error>where
T: ByteOrder,
fn read_i48<T>(&mut self) -> Result<i64, Error>where
T: ByteOrder,
§fn read_u64<T>(&mut self) -> Result<u64, Error>where
T: ByteOrder,
fn read_u64<T>(&mut self) -> Result<u64, Error>where
T: ByteOrder,
§fn read_i64<T>(&mut self) -> Result<i64, Error>where
T: ByteOrder,
fn read_i64<T>(&mut self) -> Result<i64, Error>where
T: ByteOrder,
§fn read_u128<T>(&mut self) -> Result<u128, Error>where
T: ByteOrder,
fn read_u128<T>(&mut self) -> Result<u128, Error>where
T: ByteOrder,
§fn read_i128<T>(&mut self) -> Result<i128, Error>where
T: ByteOrder,
fn read_i128<T>(&mut self) -> Result<i128, Error>where
T: ByteOrder,
§fn read_uint<T>(&mut self, nbytes: usize) -> Result<u64, Error>where
T: ByteOrder,
fn read_uint<T>(&mut self, nbytes: usize) -> Result<u64, Error>where
T: ByteOrder,
§fn read_int<T>(&mut self, nbytes: usize) -> Result<i64, Error>where
T: ByteOrder,
fn read_int<T>(&mut self, nbytes: usize) -> Result<i64, Error>where
T: ByteOrder,
§fn read_uint128<T>(&mut self, nbytes: usize) -> Result<u128, Error>where
T: ByteOrder,
fn read_uint128<T>(&mut self, nbytes: usize) -> Result<u128, Error>where
T: ByteOrder,
§fn read_int128<T>(&mut self, nbytes: usize) -> Result<i128, Error>where
T: ByteOrder,
fn read_int128<T>(&mut self, nbytes: usize) -> Result<i128, Error>where
T: ByteOrder,
§fn read_f32<T>(&mut self) -> Result<f32, Error>where
T: ByteOrder,
fn read_f32<T>(&mut self) -> Result<f32, Error>where
T: ByteOrder,
§fn read_f64<T>(&mut self) -> Result<f64, Error>where
T: ByteOrder,
fn read_f64<T>(&mut self) -> Result<f64, Error>where
T: ByteOrder,
§fn read_u16_into<T>(&mut self, dst: &mut [u16]) -> Result<(), Error>where
T: ByteOrder,
fn read_u16_into<T>(&mut self, dst: &mut [u16]) -> Result<(), Error>where
T: ByteOrder,
§fn read_u32_into<T>(&mut self, dst: &mut [u32]) -> Result<(), Error>where
T: ByteOrder,
fn read_u32_into<T>(&mut self, dst: &mut [u32]) -> Result<(), Error>where
T: ByteOrder,
§fn read_u64_into<T>(&mut self, dst: &mut [u64]) -> Result<(), Error>where
T: ByteOrder,
fn read_u64_into<T>(&mut self, dst: &mut [u64]) -> Result<(), Error>where
T: ByteOrder,
§fn read_u128_into<T>(&mut self, dst: &mut [u128]) -> Result<(), Error>where
T: ByteOrder,
fn read_u128_into<T>(&mut self, dst: &mut [u128]) -> Result<(), Error>where
T: ByteOrder,
§fn read_i8_into(&mut self, dst: &mut [i8]) -> Result<(), Error>
fn read_i8_into(&mut self, dst: &mut [i8]) -> Result<(), Error>
§fn read_i16_into<T>(&mut self, dst: &mut [i16]) -> Result<(), Error>where
T: ByteOrder,
fn read_i16_into<T>(&mut self, dst: &mut [i16]) -> Result<(), Error>where
T: ByteOrder,
§fn read_i32_into<T>(&mut self, dst: &mut [i32]) -> Result<(), Error>where
T: ByteOrder,
fn read_i32_into<T>(&mut self, dst: &mut [i32]) -> Result<(), Error>where
T: ByteOrder,
§fn read_i64_into<T>(&mut self, dst: &mut [i64]) -> Result<(), Error>where
T: ByteOrder,
fn read_i64_into<T>(&mut self, dst: &mut [i64]) -> Result<(), Error>where
T: ByteOrder,
§fn read_i128_into<T>(&mut self, dst: &mut [i128]) -> Result<(), Error>where
T: ByteOrder,
fn read_i128_into<T>(&mut self, dst: &mut [i128]) -> Result<(), Error>where
T: ByteOrder,
§fn read_f32_into<T>(&mut self, dst: &mut [f32]) -> Result<(), Error>where
T: ByteOrder,
fn read_f32_into<T>(&mut self, dst: &mut [f32]) -> Result<(), Error>where
T: ByteOrder,
§fn read_f32_into_unchecked<T>(&mut self, dst: &mut [f32]) -> Result<(), Error>where
T: ByteOrder,
fn read_f32_into_unchecked<T>(&mut self, dst: &mut [f32]) -> Result<(), Error>where
T: ByteOrder,
read_f32_into
instead