pub fn try_read_len<R>(reader: &mut R, check_integrity: bool) -> Result<Option<usize>>
where
    R: Read,
{
    let len_buf = {
        let len_buf = [0u8; std::mem::size_of::<u64>()];
        let len_buf = try_read_exact(reader, len_buf)?;
        match len_buf {
            Some(buf) => buf,
            None => return Ok(None),
        }
    };
    let len = u64::from_le_bytes(len_buf);
    let expect_cksum = {
        let mut buf = [0; std::mem::size_of::<u32>()];
        reader.read_exact(&mut buf)?;
        u32::from_le_bytes(buf)
    };

    if check_integrity {
        crate::utils::verify_checksum(&len_buf, expect_cksum)?;
    }

    Ok(Some(len as usize))
}
/// Try to read the record length from a generic reader.
///
/// It is internally called by [try_read_record]. It returns `Ok(None)` if reaching the end of file.
Try to read the record length from a generic reader.
It is internally called by [try_read_record]. It returns `Ok(None)` if reaching the end of file.
Try to read the record length from a generic reader . It is internally called by [ try_read_record ] . It returns ` Ok ( None ) ` if reaching the end of file .
pub fn try_read_len<R>(reader: &mut R, check_integrity: bool) -> Result<Option<usize>>
where
    R: Read,
{
    let len_buf = {
        let len_buf = [0u8; std::mem::size_of::<u64>()];
        let len_buf = try_read_exact(reader, len_buf)?;
        match len_buf {
            Some(buf) => buf,
            None => return Ok(None),
        }
    };
    let len = u64::from_le_bytes(len_buf);
    let expect_cksum = {
        let mut buf = [0; std::mem::size_of::<u32>()];
        reader.read_exact(&mut buf)?;
        u32::from_le_bytes(buf)
    };
    if check_integrity {
        crate::utils::verify_checksum(&len_buf, expect_cksum)?;
    }
    Ok(Some(len as usize))
}
pub fn try_read_len < R > ( reader : & mut R , check_integrity : bool ) -> Result < Option < usize > > where R : Read , { let len_buf = { let len_buf = [ 0u8 ; std :: mem :: size_of :: < u64 > ( ) ] ; let len_buf = try_read_exact ( reader , len_buf ) ? ; match len_buf { Some ( buf ) => buf , None => return Ok ( None ) , } } ; let len = u64 :: from_le_bytes ( len_buf ) ; let expect_cksum = { let mut buf = [ 0 ; std :: mem :: size_of :: < u32 > ( ) ] ; reader . read_exact ( & mut buf ) ? ; u32 :: from_le_bytes ( buf ) } ; if check_integrity { crate :: utils :: verify_checksum ( & len_buf , expect_cksum ) ? ; } Ok ( Some ( len as usize ) ) }
Try to read the record length from a generic reader.
Try to read the record length from a generic reader .
reader
&mut R
check_integrity
bool
reader
&mut R
check_integrity
bool