private static int Read7Bit(ReadBuffer readBuffer)
{
var position = readBuffer.Position;
readBuffer.Fill(1);
byte currentByte;
var result = 0;
while (((currentByte = readBuffer[readBuffer.Index++]) & 0x80) > 0)
{
result |= currentByte & 0x7F;
// - 1 accounts for the fact that we must not overwrite the sign bit by shifting in bits
const int DiscardBitsMask =
Constants.AllBitsSetInt << (Constants.BitsPerInt - Constants.BitsPerEncodedByte - 1);
if ((result & DiscardBitsMask) != 0)
{
throw CreateEmberException(
"The identifier number or subidentifier at position {0} exceeds the expected range.", position);
}
result <<= Constants.BitsPerEncodedByte;
readBuffer.Fill(1);
}
result |= currentByte;
return result;
}