readUnsignedInt method

int readUnsignedInt()

Converts a variable amount of bytes from the read buffer to an unsigned int.

The first bit is for continuation info, the other seven bits are for data.

@return the int value.

Implementation

int readUnsignedInt() {
  assert(_bufferPosition <= _bufferData.length);
  int variableByteDecode = 0;
  int variableByteShift = 0;

  // check if the continuation bit is set
  while ((this._bufferData[this._bufferPosition] & 0x80) != 0) {
    variableByteDecode |= (this._bufferData[this._bufferPosition] & 0x7f) << variableByteShift;
    variableByteShift += 7;
    ++_bufferPosition;
  }

  // read the seven data bits from the last byte
  variableByteDecode |= (this._bufferData[this._bufferPosition] & 0x7f) << variableByteShift;
  variableByteShift += 7;
  ++_bufferPosition;
  return variableByteDecode;
}