pub(crate) fn decode_variable_byte_integer(buf: &[u8]) -> Result<(u32, u8), DeserError> {
    let mut multiplier: u32 = 1;
    let mut value: u32 = 0;

    let mut buf_iter = buf.iter();
    let mut n_bytes: u8 = 0;

    loop {
        let encoded_byte: u8 = *buf_iter.next().ok_or(DeserError::Fragment)?;
        n_bytes += 1;
        value += u32::from(encoded_byte & 0x7F) * multiplier;
        if multiplier > 128 * 128 * 128 {
            return Err(DeserError::Decode);
        }
        multiplier *= 128;

        if encoded_byte & 0x80 == 0 {
            break;
        }
    }

    Ok((value, n_bytes))
}
/// Decode a variable byte integer.
///
/// Returns `None` when there is a decoding error.
Decode a variable byte integer.
Returns `None` when there is a decoding error.
Decode a variable byte integer . Returns ` None ` when there is a decoding error .
pub(crate) fn decode_variable_byte_integer(buf: &[u8]) -> Result<(u32, u8), DeserError> {
    let mut multiplier: u32 = 1;
    let mut value: u32 = 0;
    let mut buf_iter = buf.iter();
    let mut n_bytes: u8 = 0;
    loop {
        let encoded_byte: u8 = *buf_iter.next().ok_or(DeserError::Fragment)?;
        n_bytes += 1;
        value += u32::from(encoded_byte & 0x7F) * multiplier;
        if multiplier > 128 * 128 * 128 {
            return Err(DeserError::Decode);
        }
        multiplier *= 128;
        if encoded_byte & 0x80 == 0 {
            break;
        }
    }
    Ok((value, n_bytes))
}
pub ( crate ) fn decode_variable_byte_integer ( buf : & [ u8 ] ) -> Result < ( u32 , u8 ) , DeserError > { let mut multiplier : u32 = 1 ; let mut value : u32 = 0 ; let mut buf_iter = buf . iter ( ) ; let mut n_bytes : u8 = 0 ; loop { let encoded_byte : u8 = * buf_iter . next ( ) . ok_or ( DeserError :: Fragment ) ? ; n_bytes += 1 ; value += u32 :: from ( encoded_byte & 0x7F ) * multiplier ; if multiplier > 128 * 128 * 128 { return Err ( DeserError :: Decode ) ; } multiplier *= 128 ; if encoded_byte & 0x80 == 0 { break ; } } Ok ( ( value , n_bytes ) ) }
Decode a variable byte integer.
Decode a variable byte integer .
buf
&[u8]
buf
&[u8]