diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2011-01-02 22:17:26 +0100 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2011-01-02 22:17:40 +0100 |
commit | 237c3e226b7c2ac391b0e8d354e5fc6f587a41ba (patch) | |
tree | e1f0c89792e2baccb1d1ed21b913445d6e330715 /encoder.h | |
parent | b72175dab679c14be80b6e5db7129f8d3b518079 (diff) |
Use a filtering_istream with custom filters to chain file -> decoder -> encoder.
Diffstat (limited to 'encoder.h')
-rw-r--r-- | encoder.h | 19 |
1 files changed, 18 insertions, 1 deletions
@@ -5,15 +5,32 @@ #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 EncoderBase { public: - virtual size_t encode(uint8_t *input, size_t input_size, uint8_t *output, size_t output_size) = 0; + virtual size_t encode(const uint8_t *input, size_t input_size, uint8_t *output, size_t output_size) = 0; virtual size_t flush(uint8_t *output, size_t output_size) = 0; }; +class EncoderFilter : public boost::iostreams::multichar_input_filter { + private: + EncoderBase& encoder; + public: + EncoderFilter(EncoderBase& encoder_) : encoder(encoder_) {}; + 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 encoder.encode((const uint8_t*)src_data, src_read, (uint8_t*)s, n); + }; +}; + namespace encoder { void init(); EncoderBase *get_encoder(const std::string& name); |