2018-05-03 11:28:17 +00:00
|
|
|
#include "io.hh"
|
2018-06-09 01:18:28 +00:00
|
|
|
#include "bitpack.hh"
|
2018-05-25 10:00:58 +00:00
|
|
|
#include <array>
|
2018-05-03 11:28:17 +00:00
|
|
|
|
2018-06-05 09:38:27 +00:00
|
|
|
using std::uint16_t;
|
2018-06-21 15:38:51 +00:00
|
|
|
using std::vector;
|
2018-06-05 09:38:27 +00:00
|
|
|
using vuint16 = vector<uint16_t>;
|
|
|
|
using vvuint16 = vector<vuint16>;
|
2018-05-25 10:00:58 +00:00
|
|
|
|
2018-06-21 15:38:51 +00:00
|
|
|
void write_file(std::ofstream &t_out, const vvuint16 &t_chunks) {
|
|
|
|
const auto nr_chunks = static_cast<uint16_t>(t_chunks.size());
|
|
|
|
#ifdef Debug
|
|
|
|
std::printf("Number of chunks: %u\n", nr_chunks);
|
|
|
|
#endif
|
|
|
|
t_out.write(reinterpret_cast<const char *>(&nr_chunks), sizeof(nr_chunks));
|
|
|
|
for (const auto &chunk : t_chunks) {
|
2018-05-25 10:00:58 +00:00
|
|
|
write_chunk(t_out, chunk);
|
2018-05-03 11:28:17 +00:00
|
|
|
}
|
2018-05-25 10:00:58 +00:00
|
|
|
}
|
|
|
|
|
2018-06-21 15:38:51 +00:00
|
|
|
void write_chunk(std::ofstream &t_out, const vuint16 &t_chunk) {
|
2018-06-09 01:18:28 +00:00
|
|
|
const auto output = pack(t_chunk);
|
2018-06-11 19:26:05 +00:00
|
|
|
const auto chunk_size = static_cast<uint32_t>(output.size());
|
2018-06-21 15:38:51 +00:00
|
|
|
t_out.write(reinterpret_cast<const char *>(&chunk_size), sizeof(chunk_size));
|
|
|
|
t_out.write(reinterpret_cast<const char *>(output.data()),
|
|
|
|
sizeof(output[0]) * output.size());
|
2018-05-03 11:28:17 +00:00
|
|
|
}
|