blob: 0a1698e4a74751e4e9fb8c5d33a4c9aa9193c2d6 (
plain)
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
|
#include "MIODecoder.h"
extern "C" {
#include <libmio0/mio0.h>
}
#include <stdexcept>
#include <cstdint>
std::unordered_map<uint32_t, std::vector<char>> MIO0Decoder::gCachedChunks;
std::vector<char>& MIO0Decoder::Decode(std::vector<uint8_t>& buffer, uint32_t offset) {
const unsigned char* in_buf = buffer.data() + offset;
mio0_header_t head;
if(!mio0_decode_header(in_buf, &head)){
throw std::runtime_error("Failed to decode MIO0 header");
}
uint8_t* decompressed = new uint8_t[head.dest_size];
mio0_decode(in_buf, decompressed, nullptr);
gCachedChunks[offset] = std::vector<char>(decompressed, decompressed + head.dest_size);
delete[] decompressed;
return gCachedChunks[offset];
}
void MIO0Decoder::ClearCache() {
gCachedChunks.clear();
}
|