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

source

pub fn new_from_regions( mem: &GuestMemory, readable_regions: SmallVec<[MemRegion; 2]> ) -> Reader

Construct a new Reader wrapper over readable_regions.

source

pub fn peek_obj<T: FromBytes>(&self) -> Result<T>

Reads an object from the descriptor chain buffer without consuming it.

source

pub fn read_obj<T: FromBytes>(&mut self) -> Result<T>

Reads and consumes an object from the descriptor chain buffer.

source

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.

source

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.

source

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.

source

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 VolatileSlices to the callback cb.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

pub fn bytes_read(&self) -> usize

Returns number of bytes already read from the descriptor chain buffer.

source

pub fn get_remaining_regions(&self) -> MemRegionIter<'_>

source

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.

source

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.

source

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

source§

fn read(&mut self, buf: &mut [u8]) -> Result<usize>

Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
1.36.0 · source§

fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>

Like read, except that it reads into a slice of buffers. Read more
source§

fn is_read_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Reader has an efficient read_vectored implementation. Read more
1.0.0 · source§

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>

Read all bytes until EOF in this source, placing them into buf. Read more
1.0.0 · source§

fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>

Read all bytes until EOF in this source, appending them to buf. Read more
1.6.0 · source§

fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>

Read the exact number of bytes required to fill buf. Read more
source§

fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Pull some bytes from this source into the specified buffer. Read more
source§

fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Read the exact number of bytes required to fill cursor. Read more
1.0.0 · source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adaptor for this instance of Read. Read more
1.0.0 · source§

fn bytes(self) -> Bytes<Self>
where Self: Sized,

Transforms this Read instance to an Iterator over its bytes. Read more
1.0.0 · source§

fn chain<R>(self, next: R) -> Chain<Self, R>
where R: Read, Self: Sized,

Creates an adapter which will chain this stream with another. Read more
1.0.0 · source§

fn take(self, limit: u64) -> Take<Self>
where Self: Sized,

Creates an adapter which will read at most limit bytes from it. Read more
source§

impl Reader for Reader

source§

fn read_struct<T>(&mut self) -> Result<T, Error>
where T: AsBytes + FromBytes + FromZeroes,

source§

impl ZeroCopyReader for Reader

source§

fn read_to(&mut self, f: &mut File, count: usize, off: u64) -> Result<usize>

Copies at most 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 more
source§

fn read_exact_to( &mut self, f: &mut File, count: usize, off: u64 ) -> Result<(), Error>

Copies exactly count bytes of data from self into f at offset off. off + count must be less than u64::MAX. Read more
source§

fn copy_to_end(&mut self, f: &mut File, off: u64) -> Result<usize, Error>

Copies all remaining bytes from self into f at offset off. Equivalent to repeatedly calling read_to until it returns either Ok(0) or a non-ErrorKind::Interrupted error. Read more

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
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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.

§

impl<R> ReadBytesExt for R
where R: Read + ?Sized,

§

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

Reads an unsigned 8 bit integer from the underlying reader. Read more
§

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

Reads a signed 8 bit integer from the underlying reader. Read more
§

fn read_u16<T>(&mut self) -> Result<u16, Error>
where T: ByteOrder,

Reads an unsigned 16 bit integer from the underlying reader. Read more
§

fn read_i16<T>(&mut self) -> Result<i16, Error>
where T: ByteOrder,

Reads a signed 16 bit integer from the underlying reader. Read more
§

fn read_u24<T>(&mut self) -> Result<u32, Error>
where T: ByteOrder,

Reads an unsigned 24 bit integer from the underlying reader. Read more
§

fn read_i24<T>(&mut self) -> Result<i32, Error>
where T: ByteOrder,

Reads a signed 24 bit integer from the underlying reader. Read more
§

fn read_u32<T>(&mut self) -> Result<u32, Error>
where T: ByteOrder,

Reads an unsigned 32 bit integer from the underlying reader. Read more
§

fn read_i32<T>(&mut self) -> Result<i32, Error>
where T: ByteOrder,

Reads a signed 32 bit integer from the underlying reader. Read more
§

fn read_u48<T>(&mut self) -> Result<u64, Error>
where T: ByteOrder,

Reads an unsigned 48 bit integer from the underlying reader. Read more
§

fn read_i48<T>(&mut self) -> Result<i64, Error>
where T: ByteOrder,

Reads a signed 48 bit integer from the underlying reader. Read more
§

fn read_u64<T>(&mut self) -> Result<u64, Error>
where T: ByteOrder,

Reads an unsigned 64 bit integer from the underlying reader. Read more
§

fn read_i64<T>(&mut self) -> Result<i64, Error>
where T: ByteOrder,

Reads a signed 64 bit integer from the underlying reader. Read more
§

fn read_u128<T>(&mut self) -> Result<u128, Error>
where T: ByteOrder,

Reads an unsigned 128 bit integer from the underlying reader. Read more
§

fn read_i128<T>(&mut self) -> Result<i128, Error>
where T: ByteOrder,

Reads a signed 128 bit integer from the underlying reader. Read more
§

fn read_uint<T>(&mut self, nbytes: usize) -> Result<u64, Error>
where T: ByteOrder,

Reads an unsigned n-bytes integer from the underlying reader. Read more
§

fn read_int<T>(&mut self, nbytes: usize) -> Result<i64, Error>
where T: ByteOrder,

Reads a signed n-bytes integer from the underlying reader. Read more
§

fn read_uint128<T>(&mut self, nbytes: usize) -> Result<u128, Error>
where T: ByteOrder,

Reads an unsigned n-bytes integer from the underlying reader.
§

fn read_int128<T>(&mut self, nbytes: usize) -> Result<i128, Error>
where T: ByteOrder,

Reads a signed n-bytes integer from the underlying reader.
§

fn read_f32<T>(&mut self) -> Result<f32, Error>
where T: ByteOrder,

Reads a IEEE754 single-precision (4 bytes) floating point number from the underlying reader. Read more
§

fn read_f64<T>(&mut self) -> Result<f64, Error>
where T: ByteOrder,

Reads a IEEE754 double-precision (8 bytes) floating point number from the underlying reader. Read more
§

fn read_u16_into<T>(&mut self, dst: &mut [u16]) -> Result<(), Error>
where T: ByteOrder,

Reads a sequence of unsigned 16 bit integers from the underlying reader. Read more
§

fn read_u32_into<T>(&mut self, dst: &mut [u32]) -> Result<(), Error>
where T: ByteOrder,

Reads a sequence of unsigned 32 bit integers from the underlying reader. Read more
§

fn read_u64_into<T>(&mut self, dst: &mut [u64]) -> Result<(), Error>
where T: ByteOrder,

Reads a sequence of unsigned 64 bit integers from the underlying reader. Read more
§

fn read_u128_into<T>(&mut self, dst: &mut [u128]) -> Result<(), Error>
where T: ByteOrder,

Reads a sequence of unsigned 128 bit integers from the underlying reader. Read more
§

fn read_i8_into(&mut self, dst: &mut [i8]) -> Result<(), Error>

Reads a sequence of signed 8 bit integers from the underlying reader. Read more
§

fn read_i16_into<T>(&mut self, dst: &mut [i16]) -> Result<(), Error>
where T: ByteOrder,

Reads a sequence of signed 16 bit integers from the underlying reader. Read more
§

fn read_i32_into<T>(&mut self, dst: &mut [i32]) -> Result<(), Error>
where T: ByteOrder,

Reads a sequence of signed 32 bit integers from the underlying reader. Read more
§

fn read_i64_into<T>(&mut self, dst: &mut [i64]) -> Result<(), Error>
where T: ByteOrder,

Reads a sequence of signed 64 bit integers from the underlying reader. Read more
§

fn read_i128_into<T>(&mut self, dst: &mut [i128]) -> Result<(), Error>
where T: ByteOrder,

Reads a sequence of signed 128 bit integers from the underlying reader. Read more
§

fn read_f32_into<T>(&mut self, dst: &mut [f32]) -> Result<(), Error>
where T: ByteOrder,

Reads a sequence of IEEE754 single-precision (4 bytes) floating point numbers from the underlying reader. Read more
§

fn read_f32_into_unchecked<T>(&mut self, dst: &mut [f32]) -> Result<(), Error>
where T: ByteOrder,

👎Deprecated since 1.2.0: please use read_f32_into instead
DEPRECATED. Read more
§

fn read_f64_into<T>(&mut self, dst: &mut [f64]) -> Result<(), Error>
where T: ByteOrder,

Reads a sequence of IEEE754 double-precision (8 bytes) floating point numbers from the underlying reader. Read more
§

fn read_f64_into_unchecked<T>(&mut self, dst: &mut [f64]) -> Result<(), Error>
where T: ByteOrder,

👎Deprecated since 1.2.0: please use read_f64_into instead
DEPRECATED. Read more
source§

impl<T, U> TryFrom<U> for T
where 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 T
where 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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V