fn read_word(b: u8, r: &mut BinaryReader) -> Integral {
  if 0 == (b & 0b1000) {
    // Bit 3 is 0 marks that 4 following bits contain the value
    return Integral::Small((b as SWord) >> 4);
  }
  // Bit 3 is 1, but...
  if 0 == (b & 0b1_0000) {
    // Bit 4 is 0, marks that the following 3 bits (most significant) and
    // the following byte (least significant) will contain the 11-bit value
    let r = ((b as Word) & 0b1110_0000) << 3 | (r.read_u8() as Word);
    Integral::Small(r as SWord)
  } else {
    // Bit 4 is 1 means that bits 5-6-7 contain amount of bytes+2 to store
    // the value
    let mut n_bytes = (b >> 5) as Word + 2;
    if n_bytes == 9 {
      // bytes=9 means upper 5 bits were set to 1, special case 0b11111xxx
      // which means that following nested tagged value encodes size,
      // followed by the bytes (Size+9)
      let bnext = r.read_u8();
      if let Integral::Small(tmp) = read_word(bnext, r) {
        n_bytes = tmp as Word + 9;
      } else {
        panic!("{}read word encountered a wrong byte length", module())
      }
    }

    // Read the remaining big endian bytes and convert to int
    let long_bytes = r.read_bytes(n_bytes).unwrap();
    let sign = if long_bytes[0] & 0x80 == 0x80 {
      bigint::Sign::Minus
    } else {
      bigint::Sign::Plus
    };
    let r = bigint::BigInt::from_bytes_be(sign, &long_bytes);
    Integral::from_big(r)
  } // if larger than 11 bits
}
/// Given the first byte, parse an integer encoded after the 3-bit tag,
/// read more bytes from stream if needed.
Given the first byte, parse an integer encoded after the 3-bit tag,
read more bytes from stream if needed.
Given the first byte parse an integer encoded after the 3 - bit tag read more bytes from stream if needed .
fn read_word(b: u8, r: &mut BinaryReader) -> Integral {
  if 0 == (b & 0b1000) {
    // Bit 3 is 0 marks that 4 following bits contain the value
    return Integral::Small((b as SWord) >> 4);
  }
  // Bit 3 is 1, but...
  if 0 == (b & 0b1_0000) {
    // Bit 4 is 0, marks that the following 3 bits (most significant) and
    // the following byte (least significant) will contain the 11-bit value
    let r = ((b as Word) & 0b1110_0000) << 3 | (r.read_u8() as Word);
    Integral::Small(r as SWord)
  } else {
    // Bit 4 is 1 means that bits 5-6-7 contain amount of bytes+2 to store
    // the value
    let mut n_bytes = (b >> 5) as Word + 2;
    if n_bytes == 9 {
      // bytes=9 means upper 5 bits were set to 1, special case 0b11111xxx
      // which means that following nested tagged value encodes size,
      // followed by the bytes (Size+9)
      let bnext = r.read_u8();
      if let Integral::Small(tmp) = read_word(bnext, r) {
        n_bytes = tmp as Word + 9;
      } else {
        panic!("{}read word encountered a wrong byte length", module())
      }
    }
    // Read the remaining big endian bytes and convert to int
    let long_bytes = r.read_bytes(n_bytes).unwrap();
    let sign = if long_bytes[0] & 0x80 == 0x80 {
      bigint::Sign::Minus
    } else {
      bigint::Sign::Plus
    };
    let r = bigint::BigInt::from_bytes_be(sign, &long_bytes);
    Integral::from_big(r)
  } // if larger than 11 bits
}
fn read_word ( b : u8 , r : & mut BinaryReader ) -> Integral { if 0 == ( b & 0b1000 ) { // Bit 3 is 0 marks that 4 following bits contain the value return Integral :: Small ( ( b as SWord ) >> 4 ) ; } // Bit 3 is 1, but... if 0 == ( b & 0b1_0000 ) { // Bit 4 is 0, marks that the following 3 bits (most significant) and // the following byte (least significant) will contain the 11-bit value let r = ( ( b as Word ) & 0b1110_0000 ) << 3 | ( r . read_u8 ( ) as Word ) ; Integral :: Small ( r as SWord ) } else { // Bit 4 is 1 means that bits 5-6-7 contain amount of bytes+2 to store // the value let mut n_bytes = ( b >> 5 ) as Word + 2 ; if n_bytes == 9 { // bytes=9 means upper 5 bits were set to 1, special case 0b11111xxx // which means that following nested tagged value encodes size, // followed by the bytes (Size+9) let bnext = r . read_u8 ( ) ; if let Integral :: Small ( tmp ) = read_word ( bnext , r ) { n_bytes = tmp as Word + 9 ; } else { panic ! ( " " module ( ) ) } } // Read the remaining big endian bytes and convert to int let long_bytes = r . read_bytes ( n_bytes ) . unwrap ( ) ; let sign = if long_bytes [ 0 ] & 0x80 == 0x80 { bigint :: Sign :: Minus } else { bigint :: Sign :: Plus } ; let r = bigint :: BigInt :: from_bytes_be ( sign , & long_bytes ) ; Integral :: from_big ( r ) } // if larger than 11 bits }
Given the first byte, parse an integer encoded after the 3-bit tag,
read more bytes from stream if needed.
Given the first byte parse an integer encoded after the 3 - bit tag read more bytes from stream if needed .
b
u8
r
&mut BinaryReader