pub fn read_bin_block_len<Reader>(reader: &mut Reader) -> Result<usize, LoadFileError>
    where
        Reader: std::io::Read
{
    let mut first_byte_buf = [0];
    if reader.read(&mut first_byte_buf)? < 1 {
        return Ok(0);
    }

    if first_byte_buf[0] & 0b11111100 != 0 {
        return Err(LoadFileError::WrongFirstByte);
    }

    let len_of_len = first_byte_buf[0];

    let len =  if len_of_len == U8_LEN {
        let mut len_buf = [0; 1];
        reader.read_exact(&mut len_buf)?;
        u8::from_le_bytes(len_buf) as usize
    } else if len_of_len == U16_LEN {
        let mut len_buf = [0; 2];
        reader.read_exact(&mut len_buf)?;
        u16::from_le_bytes(len_buf) as usize
    } else if len_of_len == U32_LEN {          // if len in 4 bytes
        let mut len_buf = [0; 4];
        reader.read_exact(&mut len_buf)?;
        u32::from_le_bytes(len_buf) as usize
    } else {                             // if len in 8 bytes
        let mut len_buf = [0; 8];
        reader.read_exact(&mut len_buf)?;
        u64::from_le_bytes(len_buf) as usize
    };

    if len == 0 {
        return Err(LoadFileError::WrongMinBinBlockLen);
    }

    Ok(len)
}
/// Returns len of binary data block. Returns 0 if end of file.
/// Errors if file read error or unexpected file termination.
Returns len of binary data block. Returns 0 if end of file.
Errors if file read error or unexpected file termination.
Returns len of binary data block . Returns 0 if end of file . Errors if file read error or unexpected file termination .
pub fn read_bin_block_len<Reader>(reader: &mut Reader) -> Result<usize, LoadFileError>
    where
        Reader: std::io::Read
{
    let mut first_byte_buf = [0];
    if reader.read(&mut first_byte_buf)? < 1 {
        return Ok(0);
    }
    if first_byte_buf[0] & 0b11111100 != 0 {
        return Err(LoadFileError::WrongFirstByte);
    }
    let len_of_len = first_byte_buf[0];
    let len =  if len_of_len == U8_LEN {
        let mut len_buf = [0; 1];
        reader.read_exact(&mut len_buf)?;
        u8::from_le_bytes(len_buf) as usize
    } else if len_of_len == U16_LEN {
        let mut len_buf = [0; 2];
        reader.read_exact(&mut len_buf)?;
        u16::from_le_bytes(len_buf) as usize
    } else if len_of_len == U32_LEN {          // if len in 4 bytes
        let mut len_buf = [0; 4];
        reader.read_exact(&mut len_buf)?;
        u32::from_le_bytes(len_buf) as usize
    } else {                             // if len in 8 bytes
        let mut len_buf = [0; 8];
        reader.read_exact(&mut len_buf)?;
        u64::from_le_bytes(len_buf) as usize
    };
    if len == 0 {
        return Err(LoadFileError::WrongMinBinBlockLen);
    }
    Ok(len)
}
pub fn read_bin_block_len < Reader > ( reader : & mut Reader ) -> Result < usize , LoadFileError > where Reader : std :: io :: Read { let mut first_byte_buf = [ 0 ] ; if reader . read ( & mut first_byte_buf ) ? < 1 { return Ok ( 0 ) ; } if first_byte_buf [ 0 ] & 0b11111100 != 0 { return Err ( LoadFileError :: WrongFirstByte ) ; } let len_of_len = first_byte_buf [ 0 ] ; let len = if len_of_len == U8_LEN { let mut len_buf = [ 0 ; 1 ] ; reader . read_exact ( & mut len_buf ) ? ; u8 :: from_le_bytes ( len_buf ) as usize } else if len_of_len == U16_LEN { let mut len_buf = [ 0 ; 2 ] ; reader . read_exact ( & mut len_buf ) ? ; u16 :: from_le_bytes ( len_buf ) as usize } else if len_of_len == U32_LEN { // if len in 4 bytes let mut len_buf = [ 0 ; 4 ] ; reader . read_exact ( & mut len_buf ) ? ; u32 :: from_le_bytes ( len_buf ) as usize } else { // if len in 8 bytes let mut len_buf = [ 0 ; 8 ] ; reader . read_exact ( & mut len_buf ) ? ; u64 :: from_le_bytes ( len_buf ) as usize } ; if len == 0 { return Err ( LoadFileError :: WrongMinBinBlockLen ) ; } Ok ( len ) }
Returns len of binary data block.
Returns len of binary data block .
reader
&mut Reader
reader
&mut Reader