WIP: MVP
This commit is contained in:
78
main.cpp
78
main.cpp
@ -9,6 +9,7 @@
|
||||
|
||||
#include "bitstream.h"
|
||||
#include "huffman_table.h"
|
||||
#include "MashZip.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -201,18 +202,18 @@ int main(int argc, char **argv)
|
||||
// // 10111010 11110101
|
||||
// // ^^
|
||||
// int a = ibs.getbits(2);
|
||||
// cout << bitset<2>(a) << endl;
|
||||
// cout << bitset<2>(a) << endl; // 01
|
||||
|
||||
// // 10111010 11110101
|
||||
// // ^^^^
|
||||
// int b = ibs.getbits(4);
|
||||
// cout << bitset<4>(b) << endl;
|
||||
// cout << bitset<4>(b) << endl; // 0111
|
||||
|
||||
|
||||
// // 10111010 11110101
|
||||
// // ^^ ^^^^^^^
|
||||
// b = ibs.getbits(9);
|
||||
// cout << bitset<9>(b) << endl;
|
||||
// cout << bitset<9>(b) << endl; // 011010111
|
||||
|
||||
// // 10111010 11110101
|
||||
// // ^ + overflow
|
||||
@ -230,11 +231,13 @@ int main(int argc, char **argv)
|
||||
// cout << "After 3 bits: " << so.str() << endl;
|
||||
// // cache here: 00000111
|
||||
|
||||
// obs.writebits(0xf5, 7);
|
||||
// // here: Flush: 10101111
|
||||
|
||||
// // de = 11011110
|
||||
// obs.writebits(0xde, 7);
|
||||
// // here: Flush: 11101111
|
||||
// cout << "After 7 bits: " << so.str() << endl;
|
||||
// obs.flush();
|
||||
// // here: Flush: 00000011
|
||||
// // here: Flush: 00000001
|
||||
// cout << "After flush: " << so.str() << endl;
|
||||
|
||||
|
||||
@ -245,34 +248,59 @@ int main(int argc, char **argv)
|
||||
// cout << "After flush: " << so.str() << endl;
|
||||
|
||||
|
||||
string s = "Some long text!!!!\x01\x02\x03\x04";
|
||||
// string s = ;
|
||||
|
||||
stringstream ss1(s);
|
||||
stringstream ss1("Some long text!!!!\x01\x02\x03\x04\n123123456789 privet, masha!");
|
||||
stringstream ss2("Some long text!!!!\x01\x02\x03\x04\n123123456789 privet, masha!");
|
||||
stringstream so1;
|
||||
stringstream so2;
|
||||
|
||||
HuffmanTable ht(ss1);
|
||||
MashZip mz;
|
||||
|
||||
uint8_t *header = ht.to_header();
|
||||
// for (size_t i = 0; i < 128; i++)
|
||||
// {
|
||||
// cout << "Code for " << 2 * i << " and " << 2 * i + 1 << ": " << bitset<8>(header[i]) << endl;
|
||||
// }
|
||||
mz.mashzip_file(ss1, ss2, so1);
|
||||
|
||||
std::cout << "After mashzip: " << so1.str();
|
||||
|
||||
mz.unmashzip_stream(so1, so2);
|
||||
|
||||
std::cout << "After unmashzip: " << so2.str();
|
||||
|
||||
// HuffmanTable ht(ss1);
|
||||
|
||||
// char *header = ht.to_header();
|
||||
// // for (size_t i = 0; i < 128; i++)
|
||||
// // {
|
||||
// // cout << "Code for " << 2 * i << " and " << 2 * i + 1 << ": " << bitset<8>(header[i]) << endl;
|
||||
// // }
|
||||
|
||||
ostringstream test;
|
||||
// stringstream test;
|
||||
|
||||
test << "MASH"; // magic
|
||||
// // test << "MASH"; // magic
|
||||
|
||||
for (size_t i = 0; i < 128; i++) {
|
||||
test << header[i];
|
||||
}
|
||||
// // for (size_t i = 0; i < 128; i++) {
|
||||
// // test << header[i];
|
||||
// // }
|
||||
|
||||
obitstream some_stream(test);
|
||||
// obitstream some_stream(test);
|
||||
|
||||
for (char c : s) {
|
||||
ht.write_symbol(some_stream, c);
|
||||
}
|
||||
some_stream.flush();
|
||||
// for (char c : s) {
|
||||
// ht.write_symbol(some_stream, c);
|
||||
// }
|
||||
// some_stream.flush();
|
||||
|
||||
std::cout << test.str();
|
||||
// std::cout << test.str() << endl;
|
||||
|
||||
// ibitstream some_instream(test);
|
||||
|
||||
// while(true) {
|
||||
// char sym = (char) ht.decode_one_symbol(some_instream);
|
||||
// if (sym < 0)
|
||||
// {
|
||||
// std::cout << "Read all" << std::endl;
|
||||
// break;
|
||||
// }
|
||||
// std::cerr << "Sym: " << sym << std::endl;
|
||||
// }
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user