-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecode.cpp
More file actions
39 lines (29 loc) · 867 Bytes
/
decode.cpp
File metadata and controls
39 lines (29 loc) · 867 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <fstream>
#include <iostream>
#include "Packet.hpp"
int main(int argc, char** argv)
{
if (argc == 1) {
std::cerr << "Not enough arguments. Provide the file to read." << std::endl;
return 1;
}
std::vector<unsigned char> buffer;
std::vector<Packet> packets;
std::string filename(argv[1]);
std::ifstream input(filename);
for (unsigned i = 0; i < Packet::PACKETS; i++) {
for (unsigned n = 0; n < sizeof(Packet); n++) {
unsigned char c = input.get();
if (input.eof()) {
std::cerr << "Reached EOF early" << std::endl;
return 1;
}
buffer.emplace_back(c);
}
packets.emplace_back(Packet(buffer));
buffer.clear();
}
Packet::writeImage(packets, "output.png");
input.close();
return 0;
}