本文整理汇总了C++中BitStream::read_bytes方法的典型用法代码示例。如果您正苦于以下问题:C++ BitStream::read_bytes方法的具体用法?C++ BitStream::read_bytes怎么用?C++ BitStream::read_bytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BitStream
的用法示例。
在下文中一共展示了BitStream::read_bytes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: string
std::vector<unsigned char> Compressor::decompress(void* data, unsigned length)
{
BitStream bs;
bs.insert(data, length);
bs.read_bytes(&length, 3);
if (!mIsLittleEndian)
length = (unsigned)reverseEndianess((int)length);
unsigned char bits;
bs.read_bits(bits, 3);
if (bits < 1 || bits > 7)
{
char bStr[4];
throw (std::string("Bit-size of enconding isn't valid: ") + std::string(itoa(bits, bStr, 10)));
}
unsigned char byte;
int bitsRead = 27;
int i;
std::vector<char> charTable;
std::vector<char> compressedChars;
for (i = 1; i <= (1 << bits) - 1; i++)
{
bs.read_bits(byte, 8);
charTable.push_back(byte);
bitsRead += 8;
if (!bs.canRead())
throw std::string ("Bad file for decompression [1]");
}
for (unsigned j = 1; j <= length; j++)
{
bs.read_bits(byte, bits);
bitsRead += bits;
compressedChars.push_back(byte);
if (!bs.canRead())
throw std::string ("Bad file for decompression [2]");
}
std::vector<unsigned char> result(length, 0);
for (i = 0; i < (int)compressedChars.size(); i++)
{
if (compressedChars[i] == 0 || (unsigned char)compressedChars[i] > charTable.size())
{
if (!bs.canRead())
throw std::string ("Bad file for decompression [3]");
bs.read_bits(result[i], 8);
bitsRead += 8;
}
else
{
result[i] = charTable[compressedChars[i] - 1];
}
}
return result;
}