readPadding method
Reads the padding and returns the amount of bits read. If the current
buffer is not at the padding position, it will return false
without
changing the internal buffer's status or position.
Implementation
int readPadding() {
if (_bitsBufferLength == 0) {
final initPos = _bytesBuffer.position;
var b = _bytesBuffer.readByte();
if (b == (1 << 7)) {
return 8;
} else {
_bytesBuffer.seek(initPos);
return 0;
}
}
final initBitsBuffer = _bitsBuffer;
final initBitsBufferLength = _bitsBufferLength;
final paddingBits = _bitsBufferLength;
assert(paddingBits > 0);
var head = readBits(1);
if (head != 1) {
_bitsBuffer = initBitsBuffer;
_bitsBufferLength = initBitsBufferLength;
return 0;
}
for (var i = 1; i < paddingBits; ++i) {
var tailBit = readBits(1);
if (tailBit != 0) {
_bitsBuffer = initBitsBuffer;
_bitsBufferLength = initBitsBufferLength;
return 0;
}
}
assert(_bitsBufferLength == 0);
return paddingBits;
}