[*] Update bytebuffer io stream wrappers

This commit is contained in:
Reece Wilson 2023-10-29 10:47:31 +00:00
parent 4f275184d3
commit ccf3ce3ec0
3 changed files with 42 additions and 22 deletions

View File

@ -22,33 +22,40 @@ namespace Aurora::IO::Buffered
inline virtual EStreamError IsOpen() override
{
if (!this->buffer_)
auto pBuffer = this->buffer_;
if (!pBuffer)
{
return EStreamError::eErrorStreamNotOpen;
}
if (pBuffer->HasStreamError())
{
return EStreamError::eErrorByteBuffer;
}
return EStreamError::eErrorNone;
}
inline virtual EStreamError Read(const Memory::MemoryViewStreamWrite &parameters) override
{
if (!this->buffer_)
auto pBuffer = this->buffer_;
if (!pBuffer)
{
return EStreamError::eErrorStreamNotOpen;
}
parameters.outVariable = this->buffer_->Read(parameters.ptr, parameters.length);
if (pBuffer->HasStreamError())
{
return EStreamError::eErrorByteBuffer;
}
parameters.outVariable = pBuffer->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();
AuResetMember(this->buffer_);
}
protected:

View File

@ -49,12 +49,7 @@ namespace Aurora::IO::Buffered
inline virtual void Close() override
{
if (!this->buffer_)
{
return;
}
this->buffer_->clear();
AuResetMember(this->buffer_);
}
private:

View File

@ -19,17 +19,34 @@ namespace Aurora::IO::Buffered
inline virtual EStreamError IsOpen() override
{
return this->buffer_ ? EStreamError::eErrorNone : EStreamError::eErrorStreamNotOpen;
}
inline virtual EStreamError Write(const Memory::MemoryViewStreamRead &parameters) override
{
if (!this->buffer_)
auto pBuffer = this->buffer_;
if (!pBuffer)
{
return EStreamError::eErrorStreamNotOpen;
}
parameters.outVariable = this->buffer_->Write(parameters.ptr, parameters.length);
if (pBuffer->HasStreamError())
{
return EStreamError::eErrorByteBuffer;
}
return EStreamError::eErrorNone;
}
inline virtual EStreamError Write(const Memory::MemoryViewStreamRead &parameters) override
{
auto pBuffer = this->buffer_;
if (!pBuffer)
{
return EStreamError::eErrorStreamNotOpen;
}
if (pBuffer->HasStreamError())
{
return EStreamError::eErrorByteBuffer;
}
parameters.outVariable = pBuffer->Write(parameters.ptr, parameters.length);
return EStreamError::eErrorNone;
}
@ -39,6 +56,7 @@ namespace Aurora::IO::Buffered
inline virtual void Close() override
{
AuResetMember(this->buffer_);
}
inline AuSPtr<Memory::ByteBuffer> GetBuffer()