diff options
Diffstat (limited to 'decoder.h')
-rw-r--r-- | decoder.h | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -5,6 +5,8 @@ #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> @@ -13,6 +15,21 @@ class DecoderBase { 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); |