1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:07:45 +00:00

AK: Remove OutputMemoryStream for DuplexMemoryStream.

OutputMemoryStream was originally a proxy for DuplexMemoryStream that
did not expose any reading API.

Now I need to add another class that is like OutputMemoryStream but only
for static buffers. My first idea was to make OutputMemoryStream do that
too, but I think it's much better to have a distinct class for that.

I originally wanted to call that class FixedOutputMemoryStream but that
name is really cumbersome and it's a bit unintuitive because
InputMemoryStream is already reading from a fixed buffer.

So let's just use DuplexMemoryStream instead of OutputMemoryStream for
any dynamic stuff and create a new OutputMemoryStream for static
buffers.
This commit is contained in:
asynts 2020-09-15 11:48:54 +02:00 committed by Andreas Kling
parent c9a3a5b488
commit f18e927827
6 changed files with 10 additions and 28 deletions

View file

@ -185,7 +185,7 @@ public:
Optional<size_t> offset_of(ReadonlyBytes value) const
{
if (value.size() > remaining())
if (value.size() > size())
return {};
// First, find which chunk we're in.
@ -288,7 +288,7 @@ public:
ByteBuffer copy_into_contiguous_buffer() const
{
auto buffer = ByteBuffer::create_uninitialized(remaining());
auto buffer = ByteBuffer::create_uninitialized(size());
const auto nread = read_without_consuming(buffer);
ASSERT(nread == buffer.size());
@ -299,7 +299,7 @@ public:
size_t roffset() const { return m_read_offset; }
size_t woffset() const { return m_write_offset; }
size_t remaining() const { return m_write_offset - m_read_offset; }
size_t size() const { return m_write_offset - m_read_offset; }
private:
void try_discard_chunks()
@ -316,24 +316,8 @@ private:
size_t m_base_offset { 0 };
};
class OutputMemoryStream final : public OutputStream {
public:
size_t write(ReadonlyBytes bytes) override { return m_stream.write(bytes); }
bool write_or_error(ReadonlyBytes bytes) override { return m_stream.write_or_error(bytes); }
ByteBuffer copy_into_contiguous_buffer() const { return m_stream.copy_into_contiguous_buffer(); }
Optional<size_t> offset_of(ReadonlyBytes value) const { return m_stream.offset_of(value); }
size_t size() const { return m_stream.woffset(); }
private:
DuplexMemoryStream m_stream;
};
}
using AK::DuplexMemoryStream;
using AK::InputMemoryStream;
using AK::InputStream;
using AK::OutputMemoryStream;