summaryrefslogtreecommitdiff
path: root/decoder.h
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2011-01-02 22:17:26 +0100
committerJon Bergli Heier <snakebite@jvnv.net>2011-01-02 22:17:40 +0100
commit237c3e226b7c2ac391b0e8d354e5fc6f587a41ba (patch)
treee1f0c89792e2baccb1d1ed21b913445d6e330715 /decoder.h
parentb72175dab679c14be80b6e5db7129f8d3b518079 (diff)
Use a filtering_istream with custom filters to chain file -> decoder -> encoder.
Diffstat (limited to 'decoder.h')
-rw-r--r--decoder.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/decoder.h b/decoder.h
index b4dcdb6..a7aaad9 100644
--- a/decoder.h
+++ b/decoder.h
@@ -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);