Clean up some test files.
This commit is contained in:
parent
1adc9272f8
commit
b45385e8c7
51 changed files with 485 additions and 281 deletions
|
@ -51,7 +51,7 @@ std::string ZlibEncoder::toString(CompressionMethod method) const
|
|||
|
||||
void ZlibEncoder::parseCompressionMethod(unsigned char method)
|
||||
{
|
||||
std::cout << "Got compression input " << static_cast<int>(method) << std::endl;
|
||||
//std::cout << "Got compression input " << static_cast<int>(method) << std::endl;
|
||||
mCompressionMethod = static_cast<CompressionMethod>(ByteUtils::getLowerNBits(method, 4));
|
||||
auto compression_info = ByteUtils::getHigherNBits(method, 4);
|
||||
|
||||
|
@ -63,12 +63,12 @@ void ZlibEncoder::parseCompressionMethod(unsigned char method)
|
|||
|
||||
void ZlibEncoder::parseExtraFlags(unsigned char extraFlags, unsigned char compression_byte)
|
||||
{
|
||||
std::cout << "Got flags " << static_cast<int>(extraFlags) << std::endl;
|
||||
//std::cout << "Got flags " << static_cast<int>(extraFlags) << std::endl;
|
||||
|
||||
auto mod = ((static_cast<unsigned>(compression_byte) << 8) | extraFlags) % 31;
|
||||
if (mod != 0)
|
||||
{
|
||||
std::cout << "Invalid header. Mod is " << mod << std::endl;
|
||||
//std::cout << "Invalid header. Mod is " << mod << std::endl;
|
||||
}
|
||||
|
||||
mFlagCheck = ByteUtils::getLowerNBits(extraFlags, 5);
|
||||
|
@ -111,7 +111,7 @@ bool ZlibEncoder::encode()
|
|||
auto compression_info = static_cast<unsigned char>(log2(mWindowSize) - 8);
|
||||
const unsigned char compression_byte = (compression_info << 4) | static_cast<unsigned char>(mCompressionMethod);
|
||||
|
||||
std::cout << "ZlibEncoder Writing compression byte " << static_cast<int>(compression_byte) << " with info " << static_cast<int>(compression_info) << std::endl;
|
||||
//std::cout << "ZlibEncoder Writing compression byte " << static_cast<int>(compression_byte) << " with info " << static_cast<int>(compression_info) << std::endl;
|
||||
mOutputStream->writeByte(compression_byte);
|
||||
|
||||
unsigned char flag_byte{0};
|
||||
|
@ -121,7 +121,7 @@ bool ZlibEncoder::encode()
|
|||
const auto mod = (unsigned(compression_byte)*256 + flag_byte) % 31;
|
||||
flag_byte += (31 - mod);
|
||||
|
||||
std::cout << "ZlibEncoder Writing Flag byte " << static_cast<int>(flag_byte) << std::endl;
|
||||
//std::cout << "ZlibEncoder Writing Flag byte " << static_cast<int>(flag_byte) << std::endl;
|
||||
mOutputStream->writeByte(flag_byte);
|
||||
|
||||
if(!mWorkingEncoder->encode())
|
||||
|
@ -131,7 +131,7 @@ bool ZlibEncoder::encode()
|
|||
}
|
||||
|
||||
const auto checksum = mChecksumCalculator->getChecksum();
|
||||
std::cout << "ZlibEncoder Writing Adler32 Checksum " << checksum << std::endl;
|
||||
//std::cout << "ZlibEncoder Writing Adler32 Checksum " << checksum << std::endl;
|
||||
mOutputStream->write(checksum);
|
||||
return true;
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ bool ZlibEncoder::decode()
|
|||
unsigned char byte3 = *mInputStream->readNextByte();
|
||||
|
||||
uint32_t adler32 = (byte0 << 24) | (byte1 << 16) | (byte2 << 8) | byte3;
|
||||
std::cout << "Got adler 32 checksum " << adler32 << std::endl;
|
||||
//std::cout << "Got adler 32 checksum " << adler32 << std::endl;
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
|
|
@ -39,8 +39,8 @@ bool DeflateBlock::read()
|
|||
{
|
||||
auto working_byte = *mInputStream->readNextByte();
|
||||
|
||||
std::cout << mInputStream->logNextNBytes(60);
|
||||
std::cout << "DeflateBlock::read location " << mInputStream->logLocation();
|
||||
//std::cout << mInputStream->logNextNBytes(60);
|
||||
//std::cout << "DeflateBlock::read location " << mInputStream->logLocation();
|
||||
|
||||
unsigned char final_block{0};
|
||||
mInputStream->readNextNBits(1, final_block);
|
||||
|
@ -78,8 +78,8 @@ bool DeflateBlock::readUncompressedStream()
|
|||
auto byte3 = *mInputStream->readNextByte();
|
||||
uint16_t len_check = (byte2 << 8) | byte3;
|
||||
|
||||
std::cout << "Check block 2: " << ByteUtils::toString(byte2) << std::endl;
|
||||
std::cout << "Check block 3: " << ByteUtils::toString(byte3) << std::endl;
|
||||
//std::cout << "Check block 2: " << ByteUtils::toString(byte2) << std::endl;
|
||||
//std::cout << "Check block 3: " << ByteUtils::toString(byte3) << std::endl;
|
||||
//if (!(byte0 ==(~byte2) && byte1 ==(~byte3)))
|
||||
//{
|
||||
//std::cout << "Uncompressed block length check failed - aborting." << std::endl;
|
||||
|
@ -97,7 +97,7 @@ bool DeflateBlock::readUncompressedStream()
|
|||
|
||||
bool DeflateBlock::readFixedHuffmanStream()
|
||||
{
|
||||
std::cout << "Reading fixed huffman stream" << std::endl;
|
||||
//std::cout << "Reading fixed huffman stream" << std::endl;
|
||||
mHuffmanStream = std::make_unique<HuffmanStream>(mInputStream, mOutputStream);
|
||||
|
||||
mHuffmanStream->generateFixedCodeMapping();
|
||||
|
@ -139,13 +139,13 @@ void DeflateBlock::write(uint16_t datalength)
|
|||
|
||||
void DeflateBlock::writeUncompressedStream(unsigned char working_byte, uint16_t datalength)
|
||||
{
|
||||
std::cout << "Writing compression block header " << ByteUtils::toString(working_byte) << std::endl;
|
||||
//std::cout << "Writing compression block header " << ByteUtils::toString(working_byte) << std::endl;
|
||||
mOutputStream->writeByte(working_byte);
|
||||
|
||||
std::cout << "Writing data length " << mUncompressedBlockLength << " " << ByteUtils::toString(mUncompressedBlockLength) << std::endl;
|
||||
//std::cout << "Writing data length " << mUncompressedBlockLength << " " << ByteUtils::toString(mUncompressedBlockLength) << std::endl;
|
||||
mOutputStream->writeWord(datalength);
|
||||
|
||||
std::cout << "Writing iverse data length " << ~mUncompressedBlockLength << " " << ByteUtils::toString(~mUncompressedBlockLength) << std::endl;
|
||||
//std::cout << "Writing iverse data length " << ~mUncompressedBlockLength << " " << ByteUtils::toString(~mUncompressedBlockLength) << std::endl;
|
||||
mOutputStream->writeWord(static_cast<uint16_t>(~mUncompressedBlockLength));
|
||||
|
||||
for(unsigned idx=0; idx<mUncompressedBlockLength;idx++)
|
||||
|
|
|
@ -28,7 +28,7 @@ bool DeflateEncoder::encode()
|
|||
AbstractChecksumCalculator* checksum_calc;
|
||||
if (mChecksumCalculators.size() > 0)
|
||||
{
|
||||
std::cout << "Setting checksum calculator " << std::endl;
|
||||
//std::cout << "Setting checksum calculator " << std::endl;
|
||||
mOutputStream->setChecksumCalculator(mChecksumCalculators[0]);
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ bool DeflateEncoder::encode()
|
|||
{
|
||||
if (count == mMaxBlockSize)
|
||||
{
|
||||
std::cout << working_block->getMetaData();
|
||||
//std::cout << working_block->getMetaData();
|
||||
working_block->write(count);
|
||||
|
||||
working_block = std::make_unique<DeflateBlock>(&stream, mOutputStream);
|
||||
|
@ -46,7 +46,7 @@ bool DeflateEncoder::encode()
|
|||
|
||||
if (auto byte = mInputStream->readNextByte())
|
||||
{
|
||||
std::cout << "Adding byte " << ByteUtils::toString(*byte) << " to deflate block input" << std::endl;
|
||||
//std::cout << "Adding byte " << ByteUtils::toString(*byte) << " to deflate block input" << std::endl;
|
||||
stream.writeByte(*byte);
|
||||
}
|
||||
else
|
||||
|
@ -59,7 +59,7 @@ bool DeflateEncoder::encode()
|
|||
stream.resetOffsets();
|
||||
working_block->setIsFinalBlock(true);
|
||||
|
||||
std::cout << working_block->getMetaData();
|
||||
//std::cout << working_block->getMetaData();
|
||||
working_block->write(count);
|
||||
break;
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ bool DeflateEncoder::decode()
|
|||
auto working_block = std::make_unique<DeflateBlock>(mInputStream, mOutputStream);
|
||||
working_block->read();
|
||||
|
||||
std::cout << working_block->getMetaData() << std::endl;
|
||||
//std::cout << working_block->getMetaData() << std::endl;
|
||||
|
||||
DeflateBlock* raw_block = working_block.get();
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ void HuffmanCodeLengthTable::buildCompressedLengthSequence()
|
|||
|
||||
for (const auto& entry : rle_encoded)
|
||||
{
|
||||
std::cout << "Got rle " << static_cast<int>(entry.first) << " | " << entry.second << std::endl;
|
||||
//std::cout << "Got rle " << static_cast<int>(entry.first) << " | " << entry.second << std::endl;
|
||||
}
|
||||
mCompressedLengthSequence.clear();
|
||||
|
||||
|
@ -152,7 +152,7 @@ bool HuffmanCodeLengthTable::readNextSymbol(unsigned& result, BitStream* stream)
|
|||
}
|
||||
else
|
||||
{
|
||||
std::cout << "SYMBOL NOT FOUND " << " with bits " << ByteUtils::toString(working_bits) << " and index " << working_index << std::endl;
|
||||
//std::cout << "SYMBOL NOT FOUND " << " with bits " << ByteUtils::toString(working_bits) << " and index " << working_index << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -193,7 +193,7 @@ void HuffmanCodeLengthTable::buildPrefixCodes()
|
|||
}
|
||||
}
|
||||
mTree.sortTable();
|
||||
std::cout << dumpPrefixCodes();
|
||||
//std::cout << dumpPrefixCodes();
|
||||
}
|
||||
|
||||
const PrefixCode& HuffmanCodeLengthTable::getCode(std::size_t index) const
|
||||
|
|
|
@ -22,18 +22,18 @@ void HuffmanEncoder::dumpNode(RawNode<CountPair>* node, unsigned depth) const
|
|||
|
||||
if (node->isLeaf())
|
||||
{
|
||||
std::cout << prefix << "Leaf with value: " << data.first << " and sum " << data.second << std::endl;
|
||||
//std::cout << prefix << "Leaf with value: " << data.first << " and sum " << data.second << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << prefix << "Intermediate with sum " << data.second << std::endl;
|
||||
std::cout << prefix << "Doing Left.." << std::endl;
|
||||
//std::cout << prefix << "Intermediate with sum " << data.second << std::endl;
|
||||
//std::cout << prefix << "Doing Left.." << std::endl;
|
||||
dumpNode(node->getLeftChild(), depth+1);
|
||||
|
||||
std::cout << prefix << "Doing Right.." << std::endl;
|
||||
//std::cout << prefix << "Doing Right.." << std::endl;
|
||||
dumpNode(node->getRightChild(), depth+1);
|
||||
|
||||
std::cout << prefix << "*****" << std::endl;
|
||||
//std::cout << prefix << "*****" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,9 +84,9 @@ void HuffmanEncoder::encode(const std::vector<unsigned>& counts)
|
|||
|
||||
//using TableEntry = std::tuple<>
|
||||
|
||||
dumpTree(tree);
|
||||
//dumpTree(tree);
|
||||
|
||||
std::cout << "********" << std::endl;
|
||||
//std::cout << "********" << std::endl;
|
||||
}
|
||||
|
||||
void HuffmanEncoder::encode(const std::unordered_map<unsigned char, unsigned>& counts)
|
||||
|
@ -165,7 +165,7 @@ void HuffmanEncoder::initializeLiteralLengthTable(const std::vector<Hit>& hits)
|
|||
{
|
||||
if (counts[idx]>0)
|
||||
{
|
||||
std::cout << "Count for " << idx << " is " << counts[idx] << std::endl;
|
||||
//std::cout << "Count for " << idx << " is " << counts[idx] << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -106,7 +106,7 @@ void HuffmanStream::readCodeLengths()
|
|||
|
||||
if (!valid)
|
||||
{
|
||||
std::cout << "Hit unknown symbol - bailing out" << std::endl;
|
||||
//std::cout << "Hit unknown symbol - bailing out" << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -119,7 +119,7 @@ void HuffmanStream::readCodeLengths()
|
|||
unsigned char num_reps{0};
|
||||
mInputStream->readNextNBits(2, num_reps);
|
||||
|
||||
std::cout << "Got val 16 doing " << 3 + num_reps << std::endl;
|
||||
//std::cout << "Got val 16 doing " << 3 + num_reps << std::endl;
|
||||
for(unsigned idx=0; idx< 3 + num_reps; idx++)
|
||||
{
|
||||
addValue(last_value, count, last_value, literal_lengths, mNumLiterals, distance_lengths);
|
||||
|
@ -130,7 +130,7 @@ void HuffmanStream::readCodeLengths()
|
|||
unsigned char num_reps{0};
|
||||
mInputStream->readNextNBits(3, num_reps);
|
||||
|
||||
std::cout << "Got val 17 doing " << 3 + num_reps << std::endl;
|
||||
//std::cout << "Got val 17 doing " << 3 + num_reps << std::endl;
|
||||
for(unsigned idx=0; idx< 3 + num_reps; idx++)
|
||||
{
|
||||
addValue(0, count, last_value, literal_lengths, mNumLiterals, distance_lengths);
|
||||
|
@ -141,7 +141,7 @@ void HuffmanStream::readCodeLengths()
|
|||
unsigned char num_reps{0};
|
||||
mInputStream->readNextNBits(7, num_reps);
|
||||
|
||||
std::cout << "Got val 18 doing " << 11 + num_reps << std::endl;
|
||||
//std::cout << "Got val 18 doing " << 11 + num_reps << std::endl;
|
||||
for(unsigned idx=0; idx< 11 + num_reps; idx++)
|
||||
{
|
||||
addValue(0, count, last_value, literal_lengths, mNumLiterals, distance_lengths);
|
||||
|
@ -149,19 +149,19 @@ void HuffmanStream::readCodeLengths()
|
|||
}
|
||||
}
|
||||
|
||||
std::cout << "Got final literal length sequence " << std::endl;
|
||||
//std::cout << "Got final literal length sequence " << std::endl;
|
||||
for(unsigned idx=0; idx<literal_lengths.size(); idx++)
|
||||
{
|
||||
std::cout << static_cast<int>(literal_lengths[idx]) << "," ;
|
||||
//std::cout << static_cast<int>(literal_lengths[idx]) << "," ;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
//std::cout << std::endl;
|
||||
|
||||
std::cout << "Got final distance length sequence " << std::endl;
|
||||
//std::cout << "Got final distance length sequence " << std::endl;
|
||||
for(unsigned idx=0; idx<distance_lengths.size(); idx++)
|
||||
{
|
||||
std::cout << static_cast<int>(distance_lengths[idx]) << "," ;
|
||||
//std::cout << static_cast<int>(distance_lengths[idx]) << "," ;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
//std::cout << std::endl;
|
||||
|
||||
mLiteralTable.setInputLengthSequence(literal_lengths, false);
|
||||
mLiteralTable.buildPrefixCodes();
|
||||
|
@ -192,11 +192,11 @@ void HuffmanStream::readSymbols()
|
|||
const auto valid = readNextLiteralSymbol(symbol);
|
||||
if (!valid)
|
||||
{
|
||||
std::cout << "Hit unknown symbol - bailing out" << std::endl;
|
||||
//std::cout << "Hit unknown symbol - bailing out" << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
std::cout << "Got symbol " << symbol << std::endl;
|
||||
//std::cout << "Got symbol " << symbol << std::endl;
|
||||
|
||||
if(symbol <= 255)
|
||||
{
|
||||
|
@ -269,7 +269,7 @@ void HuffmanStream::readSymbols()
|
|||
|
||||
if (hit_end_stream)
|
||||
{
|
||||
std::cout << "Found end of stream ok" << std::endl;
|
||||
//std::cout << "Found end of stream ok" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -281,7 +281,7 @@ bool HuffmanStream::decode()
|
|||
|
||||
readSymbols();
|
||||
|
||||
std::cout << "Got final buffer size " << mBuffer.size() << std::endl;
|
||||
//std::cout << "Got final buffer size " << mBuffer.size() << std::endl;
|
||||
for(unsigned idx=0; idx< 100; idx++)
|
||||
{
|
||||
//std::cout << idx << " | " << mBuffer[idx] << std::endl;
|
||||
|
@ -297,7 +297,7 @@ bool HuffmanStream::decode()
|
|||
|
||||
if (!valid)
|
||||
{
|
||||
std::cout << "Hit unknown symbol - bailing out" << std::endl;
|
||||
//std::cout << "Hit unknown symbol - bailing out" << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -317,25 +317,25 @@ void HuffmanStream::readCodingsTable()
|
|||
unsigned char h_lit{0};
|
||||
mInputStream->readNextNBits(5, h_lit);
|
||||
mNumLiterals = h_lit + 257;
|
||||
std::cout << "Got HLIT " << mNumLiterals << std::endl;
|
||||
//std::cout << "Got HLIT " << mNumLiterals << std::endl;
|
||||
|
||||
unsigned char h_dist{0};
|
||||
mInputStream->readNextNBits(5, h_dist);
|
||||
mNumDistances = h_dist + 1;
|
||||
std::cout << "Got HDIST " << mNumDistances << std::endl;
|
||||
//std::cout << "Got HDIST " << mNumDistances << std::endl;
|
||||
|
||||
unsigned char h_clen{0};
|
||||
mInputStream->readNextNBits(4, h_clen);
|
||||
|
||||
auto num_code_lengths = h_clen + 4;
|
||||
std::cout << "Got HCLEN " << num_code_lengths << std::endl;
|
||||
//std::cout << "Got HCLEN " << num_code_lengths << std::endl;
|
||||
|
||||
auto sequence = std::vector<unsigned char>(num_code_lengths, 0);
|
||||
unsigned char buffer{0};
|
||||
for(unsigned idx = 0; idx< num_code_lengths; idx++)
|
||||
{
|
||||
mInputStream->readNextNBits(3, buffer);
|
||||
std::cout << "Got coding table value " << idx << " | " << static_cast<int>(buffer) << " | " << ByteUtils::toString(buffer) << std::endl;
|
||||
//std::cout << "Got coding table value " << idx << " | " << static_cast<int>(buffer) << " | " << ByteUtils::toString(buffer) << std::endl;
|
||||
sequence[idx] = buffer;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue