49 lines
937 B
C++
49 lines
937 B
C++
#include "BufferBitStream.h"
|
|
|
|
bool BufferBitStream::isFinished() const
|
|
{
|
|
return mByteOffset == mBuffer.size();
|
|
}
|
|
|
|
std::vector<unsigned char> BufferBitStream::peekNextNBytes(unsigned n) const
|
|
{
|
|
std::vector<unsigned char> ret (n, 0);
|
|
unsigned count = 0;
|
|
for(unsigned idx=mByteOffset; idx<mByteOffset + n; idx++)
|
|
{
|
|
if (idx == mBuffer.size())
|
|
{
|
|
break;
|
|
}
|
|
|
|
ret[count] = mBuffer[idx];
|
|
count ++;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
std::optional<unsigned char> BufferBitStream::readNextByte()
|
|
{
|
|
if (mByteOffset + 1 == mBuffer.size())
|
|
{
|
|
return std::nullopt;
|
|
}
|
|
else
|
|
{
|
|
mByteOffset++;
|
|
mCurrentByte = mBuffer[mByteOffset];
|
|
return mCurrentByte;
|
|
}
|
|
}
|
|
|
|
void BufferBitStream::setBuffer(const std::vector<unsigned char>& data)
|
|
{
|
|
mBuffer = data;
|
|
}
|
|
|
|
void BufferBitStream::writeByte(unsigned char data)
|
|
{
|
|
mBuffer.push_back(data);
|
|
}
|
|
|
|
|