/// Reads the next record from `stream`
Reads the next record from `stream`
Reads the next record from ` stream `
pub fn read_next(mut stream: impl Read) -> Result<(Header, Vec<u8>), Box<dyn Error + 'static>> {
	// Read the header using `try_read_exact` - useful to resume later in case of an error
	let mut header_raw = raw::header::raw();
	stream.read_exact(&mut header_raw)?;
	// Parse the header and get the payload lengths
	let header = Header::parse(header_raw)?;
	let payload_len = header.size;
	let payload_total_len = payload_len.ceil_to_multiple_of(BLOCK_LEN as u64);
	// Read the payload using `try_read_exact` - useful to resume later in case of an error
	let mut payload = vec![0; usize::try_from(payload_len)?];
	stream.read_exact(&mut payload)?;
	// Drain the padding and return the record
	let padding_len = usize::try_from(payload_total_len - payload_len)?;
	stream.try_drain(padding_len, |_| {})?;
	Ok((header, payload))
}
pub fn read_next ( mut stream : impl Read ) -> Result < ( Header , Vec < u8 > ) , Box < dyn Error + ' static > > { // Read the header using `try_read_exact` - useful to resume later in case of an error let mut header_raw = raw :: header :: raw ( ) ; stream . read_exact ( & mut header_raw ) ? ; // Parse the header and get the payload lengths let header = Header :: parse ( header_raw ) ? ; let payload_len = header . size ; let payload_total_len = payload_len . ceil_to_multiple_of ( BLOCK_LEN as u64 ) ; // Read the payload using `try_read_exact` - useful to resume later in case of an error let mut payload = vec ! [ 0 usize try_from ( payload_len ) ] ; stream . read_exact ( & mut payload ) ? ; // Drain the padding and return the record let padding_len = usize :: try_from ( payload_total_len - payload_len ) ? ; stream . try_drain ( padding_len , | _ | { } ) ? ; Ok ( ( header , payload ) ) }
Reads the next record from `stream`
Reads the next record from ` stream `
stream
impl Read