46 lines
1.6 KiB
C++
46 lines
1.6 KiB
C++
|
/***
|
||
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
||
|
|
||
|
File: BlobSeekableReader.hpp
|
||
|
Date: 2021-6-10
|
||
|
Author: Reece
|
||
|
***/
|
||
|
#pragma once
|
||
|
|
||
|
namespace Aurora::IO::Buffered
|
||
|
{
|
||
|
struct BlobSeekableReader : public ISeekingReader
|
||
|
{
|
||
|
AU_NO_COPY_NO_MOVE(BlobSeekableReader)
|
||
|
|
||
|
inline BlobSeekableReader(const AuSPtr<Memory::ByteBuffer> &buffer) : buffer_(buffer) {}
|
||
|
inline BlobSeekableReader(Memory::ByteBuffer &&buffer) : buffer_(AuMakeShared<Memory::ByteBuffer>(buffer)) {}
|
||
|
inline BlobSeekableReader(const Memory::ByteBuffer &buffer) : buffer_(AuMakeShared<Memory::ByteBuffer>(buffer)) {}
|
||
|
|
||
|
inline BlobSeekableReader() {}
|
||
|
inline ~BlobSeekableReader(){}
|
||
|
|
||
|
inline virtual EStreamError Open() override
|
||
|
{
|
||
|
if (!buffer_) return EStreamError::eErrorStreamNotOpen;
|
||
|
return EStreamError::eErrorNone;
|
||
|
}
|
||
|
|
||
|
inline virtual EStreamError ArbitraryRead(AuUInt offset, const Memory::MemoryViewStreamWrite ¶meters) override
|
||
|
{
|
||
|
if (!buffer_) return EStreamError::eErrorStreamNotOpen;
|
||
|
if (buffer_->empty()) return EStreamError::eErrorEndOfStream;
|
||
|
buffer_->readPtr = buffer_->base + offset;
|
||
|
parameters.outVariable = buffer_->Read(parameters.ptr, parameters.length);
|
||
|
return parameters.outVariable == 0 ? EStreamError::eErrorEndOfStream : EStreamError::eErrorNone;
|
||
|
}
|
||
|
|
||
|
inline virtual void Close() override
|
||
|
{
|
||
|
if (buffer_) buffer_->clear();
|
||
|
}
|
||
|
|
||
|
private:
|
||
|
AuSPtr<Memory::ByteBuffer> buffer_;
|
||
|
};
|
||
|
}
|