52 lines
1.3 KiB
C++
52 lines
1.3 KiB
C++
/***
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: BlobWriter.hpp
|
|
Date: 2021-6-10
|
|
Author: Reece
|
|
***/
|
|
#pragma once
|
|
|
|
namespace Aurora::IO::Buffered
|
|
{
|
|
struct BlobWriter : IStreamWriter
|
|
{
|
|
AU_NO_COPY_NO_MOVE(BlobWriter)
|
|
|
|
inline BlobWriter(const AuSPtr<Memory::ByteBuffer> &buffer) : buffer_(buffer) {}
|
|
inline BlobWriter() : buffer_(AuMakeShared<Memory::ByteBuffer>()) {}
|
|
inline ~BlobWriter() {}
|
|
|
|
inline virtual EStreamError IsOpen() override
|
|
{
|
|
return this->buffer_ ? EStreamError::eErrorNone : EStreamError::eErrorStreamNotOpen;
|
|
}
|
|
|
|
inline virtual EStreamError Write(const Memory::MemoryViewStreamRead ¶meters) override
|
|
{
|
|
if (!this->buffer_)
|
|
{
|
|
return EStreamError::eErrorStreamNotOpen;
|
|
}
|
|
|
|
parameters.outVariable = this->buffer_->Write(parameters.ptr, parameters.length);
|
|
return EStreamError::eErrorNone;
|
|
}
|
|
|
|
inline virtual void Flush() override
|
|
{
|
|
}
|
|
|
|
inline virtual void Close() override
|
|
{
|
|
}
|
|
|
|
inline AuSPtr<Memory::ByteBuffer> GetBuffer()
|
|
{
|
|
return this->buffer_;
|
|
}
|
|
|
|
private:
|
|
AuSPtr<Memory::ByteBuffer> buffer_;
|
|
};
|
|
} |