read method
Reads an int from the stream of length bytes
and bits
Implementation
int read({int bytes = 0, int bits = 0}) {
var len = (bytes * 8) + bits;
var thisByte = _cursor ~/ 8;
var thisBit = _cursor % 8;
int output = 0;
while (len > 0) {
var thisLen = min(len, 8 - thisBit);
var all = pow(2, thisLen).toInt() - 1;
var bit = _stream[thisByte];
if (thisBit + thisLen < 8) {
bit = bit >> (8 - (thisBit + thisLen));
}
output = output << thisLen | (bit & all);
len -= thisLen;
_cursor += thisLen;
thisBit = 0;
thisByte++;
}
return output;
}