aboutsummaryrefslogtreecommitdiffstats
path: root/src/decoder/DecoderBuffer.hxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/decoder/DecoderBuffer.hxx')
-rw-r--r--src/decoder/DecoderBuffer.hxx112
1 files changed, 54 insertions, 58 deletions
diff --git a/src/decoder/DecoderBuffer.hxx b/src/decoder/DecoderBuffer.hxx
index 79db7401d..4ed6abce3 100644
--- a/src/decoder/DecoderBuffer.hxx
+++ b/src/decoder/DecoderBuffer.hxx
@@ -22,12 +22,12 @@
#include "Compiler.h"
#include "util/DynamicFifoBuffer.hxx"
+#include "util/ConstBuffer.hxx"
#include <stddef.h>
struct Decoder;
class InputStream;
-template<typename T> struct ConstBuffer;
/**
* This objects handles buffered reads in decoder plugins easily. You
@@ -51,70 +51,66 @@ struct DecoderBuffer {
DecoderBuffer(Decoder *_decoder, InputStream &_is,
size_t _size)
:decoder(_decoder), is(_is), buffer(_size) {}
-};
-gcc_pure
-const InputStream &
-decoder_buffer_get_stream(const DecoderBuffer *buffer);
+ const InputStream &GetStream() const {
+ return is;
+ }
-void
-decoder_buffer_clear(DecoderBuffer *buffer);
+ void Clear() {
+ buffer.Clear();
+ }
-/**
- * Read data from the input_stream and append it to the buffer.
- *
- * @return true if data was appended; false if there is no data
- * available (yet), end of file, I/O error or a decoder command was
- * received
- */
-bool
-decoder_buffer_fill(DecoderBuffer *buffer);
+ /**
+ * Read data from the #InputStream and append it to the buffer.
+ *
+ * @return true if data was appended; false if there is no
+ * data available (yet), end of file, I/O error or a decoder
+ * command was received
+ */
+ bool Fill();
-/**
- * How many bytes are stored in the buffer?
- */
-gcc_pure
-size_t
-decoder_buffer_available(const DecoderBuffer *buffer);
+ /**
+ * How many bytes are stored in the buffer?
+ */
+ gcc_pure
+ size_t GetAvailable() const {
+ return buffer.GetAvailable();
+ }
-/**
- * Reads data from the buffer. This data is not yet consumed, you
- * have to call decoder_buffer_consume() to do that. The returned
- * buffer becomes invalid after a decoder_buffer_fill() or a
- * decoder_buffer_consume() call.
- *
- * @param buffer the decoder_buffer object
- */
-gcc_pure
-ConstBuffer<void>
-decoder_buffer_read(const DecoderBuffer *buffer);
+ /**
+ * Reads data from the buffer. This data is not yet consumed,
+ * you have to call Consume() to do that. The returned buffer
+ * becomes invalid after a Fill() or a Consume() call.
+ */
+ ConstBuffer<void> Read() const {
+ auto r = buffer.Read();
+ return { r.data, r.size };
+ }
-/**
- * Wait until this number of bytes are available. Returns nullptr on
- * error.
- */
-ConstBuffer<void>
-decoder_buffer_need(DecoderBuffer *buffer, size_t min_size);
+ /**
+ * Wait until this number of bytes are available. Returns nullptr on
+ * error.
+ */
+ ConstBuffer<void> Need(size_t min_size);
-/**
- * Consume (delete, invalidate) a part of the buffer. The "nbytes"
- * parameter must not be larger than the length returned by
- * decoder_buffer_read().
- *
- * @param buffer the decoder_buffer object
- * @param nbytes the number of bytes to consume
- */
-void
-decoder_buffer_consume(DecoderBuffer *buffer, size_t nbytes);
+ /**
+ * Consume (delete, invalidate) a part of the buffer. The
+ * "nbytes" parameter must not be larger than the length
+ * returned by Read().
+ *
+ * @param nbytes the number of bytes to consume
+ */
+ void Consume(size_t nbytes) {
+ buffer.Consume(nbytes);
+ }
-/**
- * Skips the specified number of bytes, discarding its data.
- *
- * @param buffer the decoder_buffer object
- * @param nbytes the number of bytes to skip
- * @return true on success, false on error
- */
-bool
-decoder_buffer_skip(DecoderBuffer *buffer, size_t nbytes);
+ /**
+ * Skips the specified number of bytes, discarding its data.
+ *
+ * @param nbytes the number of bytes to skip
+ * @return true on success, false on error
+ */
+ bool Skip(size_t nbytes);
+};
#endif