blob: a7aaad99c28be79abded88afac254fc1a162fbfd (
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
30
31
32
33
34
35
36
37
38
|
#ifndef DECODER_H
#define DECODER_H
#include <boost/cstdint.hpp>
#include <boost/function.hpp>
#include <boost/functional/factory.hpp>
#include <boost/functional/value_factory.hpp>
#include <boost/iostreams/concepts.hpp>
#include <boost/iostreams/operations.hpp>
#include <string>
class DecoderBase {
public:
virtual size_t decode(const uint8_t *input, size_t input_size, uint8_t *output, size_t output_size) = 0;
};
class DecoderFilter : public boost::iostreams::multichar_input_filter {
private:
DecoderBase& decoder;
public:
DecoderFilter(DecoderBase& decoder_) : decoder(decoder_) {};
template<typename Source>
std::streamsize read(Source& src, char *s, std::streamsize n) {
char src_data[0x2000];
std::streamsize src_read = boost::iostreams::read(src, src_data, 0x2000);
if(src_read < 0)
src_read = 0;
return decoder.decode((const uint8_t*)src_data, src_read, (uint8_t*)s, n);
};
};
namespace decoder {
void init();
DecoderBase *get_decoder(const std::string& name);
};
#endif
|