readSignedInt method
Converts a variable amount of bytes from the read buffer to a signed int.
The first bit is for continuation info, the other six (last byte) or seven (all other bytes) bits are for data. The second bit in the last byte indicates the sign of the number.
@return the int value.
Implementation
int readSignedInt() {
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;
}
variableByteDecode |= (this._bufferData[this._bufferPosition] & 0x3f) << variableByteShift;
variableByteShift += 6;
// read the six data bits from the last byte
if ((this._bufferData[this._bufferPosition] & 0x40) != 0) {
// negative
++_bufferPosition;
return -1 * variableByteDecode;
}
// positive
++_bufferPosition;
return variableByteDecode;
}