AuroraRuntime/Include/Aurora/IO/Buffered/BlobReader.hpp

57 lines
1.6 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: BlobReader.hpp
Date: 2021-6-10
Author: Reece
***/
#pragma once
namespace Aurora::IO::Buffered
{
struct BlobReader : IStreamReader
{
AU_NO_COPY(BlobReader)
inline BlobReader(const AuSPtr<Memory::ByteBuffer> &buffer) : buffer_(buffer) {}
inline BlobReader(Memory::ByteBuffer &&buffer) : buffer_(AuMakeShared<Memory::ByteBuffer>(buffer)) {}
inline BlobReader(const Memory::ByteBuffer &buffer) : buffer_(AuMakeShared<Memory::ByteBuffer>(buffer)) {}
inline BlobReader() {}
inline ~BlobReader() {}
inline virtual EStreamError IsOpen() override
{
if (!this->buffer_)
{
return EStreamError::eErrorStreamNotOpen;
}
return EStreamError::eErrorNone;
}
inline virtual EStreamError Read(const Memory::MemoryViewStreamWrite &parameters) override
{
if (!this->buffer_)
{
return EStreamError::eErrorStreamNotOpen;
}
parameters.outVariable = this->buffer_->Read(parameters.ptr, parameters.length);
return parameters.outVariable == 0 ? EStreamError::eErrorEndOfStream : EStreamError::eErrorNone;
}
inline virtual void Close() override
{
if (!this->buffer_)
{
return;
}
this->buffer_->clear();
}
protected:
AuSPtr<Memory::ByteBuffer> buffer_;
};
}