/* */ #ifndef D_STREAM_FILTER_H #define D_STREAM_FILTER_H #include "common.h" #include #include namespace aria2 { class BinaryStream; class Segment; // Interface for basic decoding functionality. class StreamFilter { private: std::unique_ptr delegate_; public: StreamFilter(std::unique_ptr delegate = nullptr); virtual ~StreamFilter(); // init() must be called before calling decode(). virtual void init() = 0; // Returns the number of bytes written to sink virtual ssize_t transform(const std::shared_ptr& out, const std::shared_ptr& segment, const unsigned char* inbuf, size_t inlen) = 0; virtual bool finished() = 0; // The call of release() will free allocated resources. // After calling release(), the object can be reused by calling init(). virtual void release() = 0; virtual const std::string& getName() const = 0; // Returns the number of input bytes processed in the last // transform() invocation. virtual size_t getBytesProcessed() const = 0; virtual bool installDelegate(std::unique_ptr filter); const std::unique_ptr& getDelegate() const { return delegate_; } }; } // namespace aria2 #endif // D_STREAM_FILTER_H