fn utf8_decode_be_u64<B: ByteStream>(src : &mut B) -> Result<Option<u64>> {
    // Read the first byte of the UTF8 encoded integer.
    let mut state = u64::from(src.read_u8()?);

    // UTF8 prefixes 1s followed by a 0 to indicate the total number of bytes within the multi-byte
    // sequence. Using ranges, determine the mask that will overlap the data bits within the first
    // byte of the sequence. For values 0-128, return the value immediately. If the value falls out
    // of range return None as this is either not the start of a UTF8 sequence or the prefix is
    // incorrect.
    let mask: u8 = match state {
        0x00..=0x7f => return Ok(Some(state)),
        0xc0..=0xdf => 0x1f,
        0xe0..=0xef => 0x0f,
        0xf0..=0xf7 => 0x07,
        0xf8..=0xfb => 0x03,
        0xfc..=0xfd => 0x01,
        0xfe        => 0x00,
        _           => return Ok(None)
    };

    // Obtain the data bits from the first byte by using the data mask.
    state &= u64::from(mask);

    // Read the remaining bytes within the UTF8 sequence. Since the mask 0s out the UTF8 prefix
    // of 1s which indicate the length of the multi-byte sequence in bytes, plus an additional 0
    // bit, the number of remaining bytes to read is the number of zeros in the mask minus 2.
    // To avoid extra computation, simply loop from 2 to the number of zeros.
    for _i in 2..mask.leading_zeros() {
        // Each subsequent byte after the first in UTF8 is prefixed with 0b10xx_xxxx, therefore
        // only 6 bits are useful. Append these six bits to the result by shifting the result left
        // by 6 bit positions, and appending the next subsequent byte with the first two high-order
        // bits masked out.
        state = (state << 6) | u64::from(src.read_u8()? & 0x3f);

        // TODO: Validation? Invalid if the byte is greater than 0x3f.
    }

    Ok(Some(state))
}
/// Decodes a big-endian unsigned integer encoded via extended UTF8. In this context, extended UTF8
/// simply means the encoded UTF8 value may be up to 7 bytes for a maximum integer bit width of
/// 36-bits.
Decodes a big-endian unsigned integer encoded via extended UTF8. In this context, extended UTF8
simply means the encoded UTF8 value may be up to 7 bytes for a maximum integer bit width of
36-bits.
Decodes a big - endian unsigned integer encoded via extended UTF8 . In this context extended UTF8 simply means the encoded UTF8 value may be up to 7 bytes for a maximum integer bit width of 36 - bits .
fn utf8_decode_be_u64<B: ByteStream>(src : &mut B) -> Result<Option<u64>> {
    // Read the first byte of the UTF8 encoded integer.
    let mut state = u64::from(src.read_u8()?);
    // UTF8 prefixes 1s followed by a 0 to indicate the total number of bytes within the multi-byte
    // sequence. Using ranges, determine the mask that will overlap the data bits within the first
    // byte of the sequence. For values 0-128, return the value immediately. If the value falls out
    // of range return None as this is either not the start of a UTF8 sequence or the prefix is
    // incorrect.
    let mask: u8 = match state {
        0x00..=0x7f => return Ok(Some(state)),
        0xc0..=0xdf => 0x1f,
        0xe0..=0xef => 0x0f,
        0xf0..=0xf7 => 0x07,
        0xf8..=0xfb => 0x03,
        0xfc..=0xfd => 0x01,
        0xfe        => 0x00,
        _           => return Ok(None)
    };
    // Obtain the data bits from the first byte by using the data mask.
    state &= u64::from(mask);
    // Read the remaining bytes within the UTF8 sequence. Since the mask 0s out the UTF8 prefix
    // of 1s which indicate the length of the multi-byte sequence in bytes, plus an additional 0
    // bit, the number of remaining bytes to read is the number of zeros in the mask minus 2.
    // To avoid extra computation, simply loop from 2 to the number of zeros.
    for _i in 2..mask.leading_zeros() {
        // Each subsequent byte after the first in UTF8 is prefixed with 0b10xx_xxxx, therefore
        // only 6 bits are useful. Append these six bits to the result by shifting the result left
        // by 6 bit positions, and appending the next subsequent byte with the first two high-order
        // bits masked out.
        state = (state << 6) | u64::from(src.read_u8()? & 0x3f);
        // TODO: Validation? Invalid if the byte is greater than 0x3f.
    }
    Ok(Some(state))
}
fn utf8_decode_be_u64 < B : ByteStream > ( src : & mut B ) -> Result < Option < u64 > > { // Read the first byte of the UTF8 encoded integer. let mut state = u64 :: from ( src . read_u8 ( ) ? ) ; // UTF8 prefixes 1s followed by a 0 to indicate the total number of bytes within the multi-byte // sequence. Using ranges, determine the mask that will overlap the data bits within the first // byte of the sequence. For values 0-128, return the value immediately. If the value falls out // of range return None as this is either not the start of a UTF8 sequence or the prefix is // incorrect. let mask : u8 = match state { 0x00 ..= 0x7f => return Ok ( Some ( state ) ) , 0xc0 ..= 0xdf => 0x1f , 0xe0 ..= 0xef => 0x0f , 0xf0 ..= 0xf7 => 0x07 , 0xf8 ..= 0xfb => 0x03 , 0xfc ..= 0xfd => 0x01 , 0xfe => 0x00 , _ => return Ok ( None ) } ; // Obtain the data bits from the first byte by using the data mask. state &= u64 :: from ( mask ) ; // Read the remaining bytes within the UTF8 sequence. Since the mask 0s out the UTF8 prefix // of 1s which indicate the length of the multi-byte sequence in bytes, plus an additional 0 // bit, the number of remaining bytes to read is the number of zeros in the mask minus 2. // To avoid extra computation, simply loop from 2 to the number of zeros. for _i in 2 .. mask . leading_zeros ( ) { // Each subsequent byte after the first in UTF8 is prefixed with 0b10xx_xxxx, therefore // only 6 bits are useful. Append these six bits to the result by shifting the result left // by 6 bit positions, and appending the next subsequent byte with the first two high-order // bits masked out. state = ( state << 6 ) | u64 :: from ( src . read_u8 ( ) ? & 0x3f ) ; // TODO: Validation? Invalid if the byte is greater than 0x3f. } Ok ( Some ( state ) ) }
Decodes a big-endian unsigned integer encoded via extended UTF8.
Decodes a big - endian unsigned integer encoded via extended UTF8 .
src
&mut B
src
&mut B