Reece Wilson
ad4c18abe7
[*] Various compression related bugs under the 1/4th of the AuCompression platform related to compression stream objects. Now all 1/4ths match up.
105 lines
2.9 KiB
C++
105 lines
2.9 KiB
C++
/***
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: BaseStream.cpp
|
|
Date: 2022-2-14
|
|
Author: Reece
|
|
***/
|
|
#include <Source/RuntimeInternal.hpp>
|
|
#include "Compression.hpp"
|
|
#include "IngestableReadBase.hpp"
|
|
#include "BaseStream.hpp"
|
|
|
|
namespace Aurora::Compression
|
|
{
|
|
AuStreamReadWrittenPair_t BaseStream::ReadEx(const Memory::MemoryViewWrite & /*opt*/ destination, bool ingestUntilEOS)
|
|
{
|
|
AU_LOCK_GUARD(this->_spinlock);
|
|
|
|
AuUInt32 read {}, len {};
|
|
|
|
if (!destination.length && !destination.ptr)
|
|
{
|
|
return {0, this->_outbuffer.RemainingBytes()};
|
|
}
|
|
|
|
if (ingestUntilEOS)
|
|
{
|
|
while (this->_outbuffer.RemainingBytes() < destination.length)
|
|
{
|
|
auto toRead = destination.length ? AuUInt32(destination.length - this->_outbuffer.RemainingBytes()) : 10 * 1024;
|
|
|
|
if (Ingest_s(toRead).second == 0)
|
|
{
|
|
if (!this->_outbuffer.RemainingBytes(true))
|
|
{
|
|
return {};
|
|
}
|
|
|
|
break;
|
|
}
|
|
|
|
read += toRead;
|
|
}
|
|
}
|
|
|
|
len = this->_outbuffer.Read(destination.ptr, destination.length, destination.ptr == nullptr);
|
|
return {read, len};
|
|
}
|
|
|
|
AuUInt32 BaseStream::GetAvailableProcessedBytes()
|
|
{
|
|
AU_LOCK_GUARD(this->_spinlock);
|
|
return this->_outbuffer.RemainingBytes(true);
|
|
}
|
|
|
|
AuUInt32 BaseStream::Read(const Memory::MemoryViewWrite & /*opt*/ destination)
|
|
{
|
|
AU_LOCK_GUARD(this->_spinlock);
|
|
if (!destination.length && !destination.ptr)
|
|
{
|
|
return this->_outbuffer.RemainingBytes();
|
|
}
|
|
return this->_outbuffer.Read(destination.ptr, destination.length, destination.ptr == nullptr);
|
|
}
|
|
|
|
bool BaseStream::GoBackByProcessedN(AuUInt32 offset)
|
|
{
|
|
AU_LOCK_GUARD(this->_spinlock);
|
|
return this->_outbuffer.ReaderTryGoBack(offset);
|
|
}
|
|
|
|
bool BaseStream::GoForwardByProcessedN(AuUInt32 offset)
|
|
{
|
|
AU_LOCK_GUARD(this->_spinlock);
|
|
if (!offset)
|
|
{
|
|
return true;
|
|
}
|
|
return this->_outbuffer.ReaderTryGoForward(offset);
|
|
}
|
|
|
|
AuStreamReadWrittenPair_t BaseStream::Ingest(AuUInt32 bytesFromUnprocessedInputSource)
|
|
{
|
|
AU_LOCK_GUARD(this->_spinlock);
|
|
|
|
if (!bytesFromUnprocessedInputSource)
|
|
{
|
|
return {};
|
|
}
|
|
|
|
return Ingest_s(bytesFromUnprocessedInputSource);
|
|
}
|
|
|
|
bool BaseStream::Write(const void *a, AuUInt32 length)
|
|
{
|
|
auto written = this->_outbuffer.Write(reinterpret_cast<const AuUInt8 *>(a),
|
|
length);
|
|
return written == length;
|
|
}
|
|
|
|
AuUInt32 BaseStream::GetInternalBufferSize()
|
|
{
|
|
return this->_outbuffer.allocSize;
|
|
}
|
|
} |