summaryrefslogtreecommitdiff
path: root/decoder.h
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2011-01-06 02:12:25 +0100
committerVegard Storheil Eriksen <zyp@jvnv.net>2011-01-06 02:12:25 +0100
commitb5452bc9bc09e66121aae35adbd5c504a3f90466 (patch)
tree30fe30d724772e94b3f590f2a582d19aba40ed24 /decoder.h
parent70f111b184928feab0c94f762954b5ec83a441c6 (diff)
Let decoders read a dynamic amount through a Source object.decoder_api_change
Diffstat (limited to 'decoder.h')
-rw-r--r--decoder.h26
1 files changed, 20 insertions, 6 deletions
diff --git a/decoder.h b/decoder.h
index 9faabc1..31986f7 100644
--- a/decoder.h
+++ b/decoder.h
@@ -7,12 +7,29 @@
#include <string>
+class Source {
+ public:
+ virtual std::streamsize read(char* buf, std::streamsize buf_size) = 0;
+};
+
+template<class T>
+class StreamSource : public Source {
+ private:
+ T& s;
+
+ public:
+ StreamSource(T& s_) : s(s_) {}
+ std::streamsize read(char* buf, std::streamsize buf_size) {
+ return boost::iostreams::read(s, buf, buf_size);
+ }
+};
+
class DecoderBase {
public:
typedef boost::shared_ptr<DecoderBase> p;
- virtual size_t decode(const uint8_t *input, size_t input_size, uint8_t *output, size_t output_size) = 0;
virtual ~DecoderBase() {}
+ virtual size_t decode(Source& input, uint8_t *output, size_t output_size) = 0;
};
//! Input filter to hold a decoder in a filter chain.
@@ -26,11 +43,8 @@ class DecoderFilter : public boost::iostreams::multichar_input_filter {
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);
+ StreamSource<Source> src_f(src);
+ return decoder->decode(src_f, (uint8_t*)s, n);
}
};