Reece Wilson
267c2216b0
(...missing send) [+] AuIO::Buffer::ViewReader [+] AuIO::Buffer::ViewSeekableReadable [+] AuIO::Buffer::ViewWriter [*] Clean up AuCompression [*[ AuLog messages must always crunch for memory [*] Various bug fixes [*] Refactor+clean up
71 lines
1.8 KiB
C++
71 lines
1.8 KiB
C++
/***
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: ViewSeekableReadable.hpp
|
|
Date: 2022-12-11
|
|
Author: Reece
|
|
***/
|
|
#pragma once
|
|
|
|
namespace Aurora::IO::Buffered
|
|
{
|
|
struct ViewSeekableReadable : ISeekingReader
|
|
{
|
|
AU_NO_COPY(ViewSeekableReadable)
|
|
|
|
inline ViewSeekableReadable(const AuSPtr<Memory::MemoryViewRead> &view) : view_(view)
|
|
{ }
|
|
|
|
inline ViewSeekableReadable()
|
|
{ }
|
|
|
|
inline ~ViewSeekableReadable()
|
|
{ }
|
|
|
|
inline virtual EStreamError IsOpen() override
|
|
{
|
|
if (!this->view_)
|
|
{
|
|
return EStreamError::eErrorStreamNotOpen;
|
|
}
|
|
|
|
if (!(*this->view_.get()))
|
|
{
|
|
return EStreamError::eErrorStreamNotOpen;
|
|
}
|
|
|
|
return EStreamError::eErrorNone;
|
|
}
|
|
|
|
inline virtual EStreamError ArbitraryRead(AuUInt uOffset, const Memory::MemoryViewStreamWrite ¶meters) override
|
|
{
|
|
if (!this->view_)
|
|
{
|
|
return EStreamError::eErrorStreamNotOpen;
|
|
}
|
|
|
|
if (!(*this->view_.get()))
|
|
{
|
|
return EStreamError::eErrorStreamNotOpen;
|
|
}
|
|
|
|
if (this->view_->length < uOffset)
|
|
{
|
|
return EStreamError::eErrorEndOfStream;
|
|
}
|
|
|
|
auto uToRead = AuMin(this->view_->length - uOffset, parameters.length);
|
|
parameters.outVariable = uToRead;
|
|
AuMemcpy(parameters.ptr, this->view_->Begin<AuUInt8>() + uOffset, uToRead);
|
|
return parameters.outVariable == 0 ? EStreamError::eErrorEndOfStream : EStreamError::eErrorNone;
|
|
}
|
|
|
|
inline virtual void Close() override
|
|
{
|
|
this->view_.reset();
|
|
}
|
|
|
|
private:
|
|
AuSPtr<Memory::MemoryViewRead> view_;
|
|
};
|
|
} |