pub struct SharedAlignedBufferReader<'a, A>where
A: Alignment,{ /* private fields */ }Expand description
Reads the contents of a SharedAlignedBuffer front to back, see
SharedAlignedBuffer::reader().
Bytes are borrowed from the buffer for as long as the buffer is borrowed, so any number of them
can be held at once, while Self::read_buffer() creates buffers that reference a part of the
contents without copying them.
A read that fails leaves the reader unchanged.
Implementations§
Sourcepub fn read_to_alignment<B>(&mut self) -> Result<&'a [u8], ReadError>where
B: Alignment,
pub fn read_to_alignment<B>(&mut self) -> Result<&'a [u8], ReadError>where
B: Alignment,
Read padding up to the next multiple of B bytes from the beginning of the contents.
Returns padding bytes, which are empty if the position is already a multiple of B, so
that formats that require zero padding can check them.
Sourcepub fn read_bytes_array<const N: usize>(
&mut self,
) -> Result<&'a [u8; N], ReadError>
pub fn read_bytes_array<const N: usize>( &mut self, ) -> Result<&'a [u8; N], ReadError>
Read the next N bytes
Sourcepub fn read_buffer<B>(
&mut self,
len: u32,
) -> Result<SharedAlignedBuffer<B>, ReadError>where
B: Alignment,
pub fn read_buffer<B>(
&mut self,
len: u32,
) -> Result<SharedAlignedBuffer<B>, ReadError>where
B: Alignment,
Create a buffer that references the next len bytes without copying them.
The bytes must be aligned to B in memory, Self::read_to_alignment() reads padding in
front of them if necessary. The new buffer keeps the whole allocation alive unless it is
empty, see SharedAlignedBuffer::into_standalone().
Sourcepub fn read_trivial<T>(&mut self) -> Result<&'a T, ReadError>where
T: AnyBitPattern,
pub fn read_trivial<T>(&mut self) -> Result<&'a T, ReadError>where
T: AnyBitPattern,
Read a value of a trivial type.
The bytes must be aligned for T in memory, Self::read_to_alignment() reads padding in
front of them if necessary. Unaligned reads values that are not aligned.
Sourcepub fn read_trivial_array<T, const N: usize>(
&mut self,
) -> Result<&'a [T; N], ReadError>where
[T; N]: AnyBitPattern,
pub fn read_trivial_array<T, const N: usize>(
&mut self,
) -> Result<&'a [T; N], ReadError>where
[T; N]: AnyBitPattern,
Read N values of a trivial type, like Self::read_trivial()
Sourcepub fn read_trivial_slice<T>(
&mut self,
count: u32,
) -> Result<&'a [T], ReadError>where
T: AnyBitPattern,
pub fn read_trivial_slice<T>(
&mut self,
count: u32,
) -> Result<&'a [T], ReadError>where
T: AnyBitPattern,
Read count values of a trivial type, like Self::read_trivial()