Function nix_compat::wire::bytes::read_bytes
source · pub async fn read_bytes<R>(
r: &mut R,
allowed_size: RangeInclusive<usize>,
) -> Result<Vec<u8>>
Expand description
Read a “bytes wire packet” from the AsyncRead.
Rejects reading more than allowed_size
bytes of payload.
The packet is made up of three parts:
- a length header, u64, LE-encoded
- the payload itself
- null bytes to the next 8 byte boundary
Ensures the payload size fits into the allowed_size
passed,
and that the padding is actual null bytes.
On success, the returned Vec<u8>
only contains the payload itself.
On failure (for example if a too large byte packet was sent), the reader
becomes unusable.
This buffers the entire payload into memory, a streaming version is available at crate::wire::bytes::BytesReader.