Skip to content

Commit

Permalink
feat: remove cereal; implement own serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
devanbenz committed Nov 27, 2024
1 parent 0074f0e commit 8d276ca
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 1,149 deletions.
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ add_library(spray_paint_lib
src/heap/heap.h
src/heap/min_heap.h
src/heap/max_heap.h
src/cereal.hpp
)

add_executable(spray_paint_test
tests/sp_test.cpp
)
Expand Down
52 changes: 36 additions & 16 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,52 @@
// Encode the tree - we’ll need to include this in the output file so we can decode it.
// Write the encoded tree and text to an output field

void usage() {
std::cout << "Usage: ./spraypaint <flag> <filename> <output>\n"
<< "\n"
<< "spraypaint is a file compression and decompression tool.\n"
<< "\n"
<< "Arguments:\n"
<< " <flag> d or c for [d]ecompress or [c]ompress.\n"
<< " <filename> The name of the file to compress or decompress.\n"
<< " <output> The name of the output file for compression"
<< "\n"
<< "Example:\n"
<< " ./spraypaint example.txt example.spz\n\n"
<< "Note:\n"
<< " - If the file is already compressed, spraypaint will attempt to decompress it.\n"
<< " - If the file is uncompressed, spraypaint will compress it.\n";
}

int main(int argc, char* argv[]) {
if (argc != 3) {
std::cout << "Usage: ./spraypaint <filename> <output>\n"
<< "\n"
<< "spraypaint is a file compression and decompression tool.\n"
<< "\n"
<< "Arguments:\n"
<< " <filename> The name of the file to compress or decompress.\n"
<< " <output> The name of the output file for compression"
<< "\n"
<< "Example:\n"
<< " ./spraypaint example.txt example.spz\n\n"
<< "Note:\n"
<< " - If the file is already compressed, spraypaint will attempt to decompress it.\n"
<< " - If the file is uncompressed, spraypaint will compress it.\n";
if (argc != 4) {
usage();
return 0;
}

auto flag = argv[1];
auto filename = argv[2];
auto output= argv[3];

if (strcmp(flag, "d") != 0 || strcmp(flag, "c") != 0) {
usage();
return 0;
}

auto filename = argv[1];
auto output= argv[2];
std::ifstream input_file(filename);
if (!input_file.is_open()) {
throw std::runtime_error("Invalid file. Please make sure the file exists.");
}

auto char_map = build_char_map(std::move(input_file));
SprayPaintTree tree;

tree.register_charset(char_map);
tree.build();

std::ofstream outfile (output,std::ofstream::binary);
tree.serialize(outfile);
outfile.close();

return 0;
}
Loading

0 comments on commit 8d276ca

Please sign in to comment.