Trait libp2prs_traits::ReadEx [−][src]
Read Trait for async/await
Required methods
#[must_use]fn read2<'life0, 'life1, 'async_trait>(
&'life0 mut self,
buf: &'life1 mut [u8]
) -> Pin<Box<dyn Future<Output = Result<usize, Error>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
[src]
&'life0 mut self,
buf: &'life1 mut [u8]
) -> Pin<Box<dyn Future<Output = Result<usize, Error>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Reads some bytes from the byte stream.
On success, returns the total number of bytes read.
If the return value is Ok(n)
, then it must be guaranteed that
0 <= n <= buf.len()
. A nonzero n
value indicates that the buffer has been
filled with n
bytes of data. If n
is 0
, then it can indicate one of two
scenarios:
- This reader has reached its “end of file” and will likely no longer be able to produce bytes. Note that this does not mean that the reader will always no longer be able to produce bytes.
- The buffer specified was 0 bytes in length.
Attempt to read bytes from underlying stream object.
On success, returns Ok(n)
.
Otherwise, returns Err(io:Error)
Provided methods
#[must_use]fn read_exact2<'a, 'async_trait>(
&'a mut self,
buf: &'a mut [u8]
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>> where
'a: 'async_trait,
Self: 'async_trait,
[src]
&'a mut self,
buf: &'a mut [u8]
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>> where
'a: 'async_trait,
Self: 'async_trait,
Reads the exact number of bytes requested.
On success, returns Ok(())
.
Otherwise, returns Err(io:Error)
.
#[must_use]fn read_fixed_u32<'life0, 'async_trait>(
&'life0 mut self
) -> Pin<Box<dyn Future<Output = Result<usize, Error>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
[src]
&'life0 mut self
) -> Pin<Box<dyn Future<Output = Result<usize, Error>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
Reads a fixed-length integer from the underlying IO.
On success, return Ok(n)
.
Otherwise, returns Err(io:Error)
.
#[must_use]fn read_varint<'life0, 'async_trait>(
&'life0 mut self
) -> Pin<Box<dyn Future<Output = Result<usize, Error>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
[src]
&'life0 mut self
) -> Pin<Box<dyn Future<Output = Result<usize, Error>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
Reads a variable-length integer from the underlying IO.
As a special exception, if the IO
is empty and EOFs right at the beginning, then we
return Ok(0)
.
On success, return Ok(n)
.
Otherwise, returns Err(io:Error)
.
Note: This function reads bytes one by one from the underlying IO. It is therefore encouraged to use some sort of buffering mechanism.
#[must_use]fn read_one_fixed<'life0, 'async_trait>(
&'life0 mut self,
max_size: usize
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, Error>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
[src]
&'life0 mut self,
max_size: usize
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, Error>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
Reads a fixed length-prefixed message from the underlying IO.
The max_size
parameter is the maximum size in bytes of the message that we accept. This is
necessary in order to avoid DoS attacks where the remote sends us a message of several
gigabytes.
Note: Assumes that a fixed-length prefix indicates the length of the message. This is compatible with what
write_one_fixed
does.
#[must_use]fn read_one<'life0, 'async_trait>(
&'life0 mut self,
max_size: usize
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, Error>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
[src]
&'life0 mut self,
max_size: usize
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, Error>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
Reads a variable length-prefixed message from the underlying IO.
The max_size
parameter is the maximum size in bytes of the message that we accept. This is
necessary in order to avoid DoS attacks where the remote sends us a message of several
gigabytes.
On success, returns Ok(Vec<u8>)
.
Otherwise, returns Err(io:Error)
.
Note: Assumes that a variable-length prefix indicates the length of the message. This is compatible with what
write_one
does.