AuroraRuntime/Source/Compression/BaseStream.hpp

62 lines
1.8 KiB
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: BaseStream.hpp
Date: 2022-2-14
Author: Reece
***/
#pragma once
#include "IngestableReadBase.hpp"
namespace Aurora::Compression
{
struct BaseStream : ICompressionStream, protected IngestableReadBase
{
inline BaseStream(AuUInt32 bufferSize = 4096 * 4) : _outbufferOwned(bufferSize, true), uBufferSize_(bufferSize)
{
SetBuffer({});
}
inline virtual ~BaseStream()
{}
virtual bool Init(const AuSPtr<IO::IStreamReader> &reader) = 0;
virtual AuUInt32 GetAvailableProcessedBytes() override;
virtual AuStreamReadWrittenPair_t ReadEx(const Memory::MemoryViewWrite & /*opt*/ destination, bool ingestUntilEOS) override;
virtual AuUInt32 Read(const Memory::MemoryViewWrite & /*opt*/ destination) override;
virtual bool GoBackByProcessedN(AuUInt32 offset) override;
virtual bool GoForwardByProcessedN(AuUInt32 offset) override;
virtual AuUInt32 GetInternalBufferSize() override;
bool Write(const void *a, AuUInt32 length);
virtual AuStreamReadWrittenPair_t Ingest(AuUInt32 bytesFromUnprocessedInputSource) override;
inline virtual bool Flush() override
{
return false;
}
inline virtual bool Finish() override
{
return false;
}
bool IsValid();
AuSPtr<Memory::ByteBuffer> GetBuffer();
void SetBuffer(const AuSPtr<Memory::ByteBuffer> &pBuffer);
protected:
virtual AuStreamReadWrittenPair_t Ingest_s(AuUInt32 bytesFromUnprocessedInputSource) = 0;
AuSPtr<Memory::ByteBuffer> pOutputBuffer_;
Memory::ByteBuffer _outbufferOwned;
AuThreadPrimitives::SpinLock _spinlock;
AuUInt32 uBufferSize_;
};
}