From 71c3be13fcdc4aebf3cfa03803966da3aca07c68 Mon Sep 17 00:00:00 2001 From: Nicolay Korslund Date: Tue, 29 Dec 2009 16:52:47 +0100 Subject: [PATCH] Started buffer_stream.h, WIP --- stream/filters/buffer_stream.h | 23 +++++++++++++++++++++++ stream/servers/memory_stream.h | 17 +++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 stream/filters/buffer_stream.h diff --git a/stream/filters/buffer_stream.h b/stream/filters/buffer_stream.h new file mode 100644 index 0000000000..f8290ea5eb --- /dev/null +++ b/stream/filters/buffer_stream.h @@ -0,0 +1,23 @@ +#ifndef MANGLE_STREAM_BUFFER_H +#define MANGLE_STREAM_BUFFER_H + +#include "../servers/memory_stream.h" +#include "../clients/iwrapper.h" + +namespace Mangle { +namespace Stream { + +/** A Stream that reads another Stream into a buffer, and serves it as + a MemoryStream. + */ +class BufferStream : public MemoryStream +{ + public: + BufferStream(Stream *input) + { + // Allocate memory, read the stream into it. Then call set() + } +}; + +}} // namespaces +#endif diff --git a/stream/servers/memory_stream.h b/stream/servers/memory_stream.h index f6e878dd15..c47ffa5358 100644 --- a/stream/servers/memory_stream.h +++ b/stream/servers/memory_stream.h @@ -32,8 +32,17 @@ class MemoryStream : public Stream hasSize = true; } + MemoryStream() + : data(NULL), length(0), pos(0); + { + isSeekable = true; + hasPosition = true; + hasSize = true; + } + size_t read(void *buf, size_t count) { + assert(data != NULL); assert(pos <= length); // Don't read more than we have @@ -63,6 +72,14 @@ class MemoryStream : public Stream // New members in MemoryStream: + /// Set a new buffer and length. This will rewind the position to zero. + void set(const void* _data, size_t _length) + { + data = _data; + length = _length; + pos = 0; + } + /// Get the base pointer to the entire buffer const void *getPtr() const { return data; }