pub struct ByteStreamReader { /* private fields */ }Expand description
A helper struct to read defined lengths of data from a BytesStream
Implementations§
Source§impl ByteStreamReader
impl ByteStreamReader
Sourcepub fn new(stream: ByteStream) -> Self
pub fn new(stream: ByteStream) -> Self
Creates a new ByteStreamReader from a ByteStream
Sourcepub fn read_exact(&mut self, read_len: usize) -> ByteStreamReadExact<'_> ⓘ
pub fn read_exact(&mut self, read_len: usize) -> ByteStreamReadExact<'_> ⓘ
Read exactly read_len bytes from the underlying stream
(returns a future)
Sourcepub fn read_exact_or_eos(&mut self, read_len: usize) -> ByteStreamReadExact<'_> ⓘ
pub fn read_exact_or_eos(&mut self, read_len: usize) -> ByteStreamReadExact<'_> ⓘ
Read at most read_len bytes from the underlying stream, or less
if the end of the stream is reached (returns a future)
Sourcepub async fn read_u8(&mut self) -> Result<u8, ReadExactError>
pub async fn read_u8(&mut self) -> Result<u8, ReadExactError>
Read exactly one byte from the underlying stream and returns it as an u8
Sourcepub async fn read_u16(&mut self) -> Result<u16, ReadExactError>
pub async fn read_u16(&mut self) -> Result<u16, ReadExactError>
Read exactly two bytes from the underlying stream and returns them as an u16 (using big-endian decoding)
Sourcepub async fn read_u32(&mut self) -> Result<u32, ReadExactError>
pub async fn read_u32(&mut self) -> Result<u32, ReadExactError>
Read exactly four bytes from the underlying stream and returns them as an u32 (using big-endian decoding)
Sourcepub fn into_stream(self) -> ByteStream
pub fn into_stream(self) -> ByteStream
Transforms the stream reader back into the underlying stream (starting after everything that the reader has read)
Sourcepub async fn fill_buffer(&mut self)
pub async fn fill_buffer(&mut self)
Tries to fill the internal read buffer from the underlying stream if it is empty.
Calling this might be necessary to ensure that .eos() returns a correct
result, otherwise the reader might not be aware that the underlying
stream has nothing left to return.
Sourcepub fn take_buffer(&mut self) -> Bytes
pub fn take_buffer(&mut self) -> Bytes
Clears the internal read buffer and returns its content