/*** Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved. File: IngestableReadBase.inl Date: 2022-2-14 Author: Reece ***/ #pragma once namespace Aurora::Compression { template void IngestableReadBase::SetArray(T(&array)[Z]) { this->internalInBuffer_ = reinterpret_cast(array); this->internalInLength_ = Z; } void IngestableReadBase::SetPointer(void *pointer, AuUInt32 length) { this->internalInBuffer_ = reinterpret_cast(pointer); this->internalInLength_ = length; } // Given a zlib-like interface input paremeters, a stream source, and a buffer... // // ...reads template AuUInt32 IngestableReadBase::IngestForInPointer(const AuSPtr &reader, T *&in, Z &inAlreadyAvailable, AuUInt32 amount) { if (inAlreadyAvailable > this->internalInLength_) { SysPanic("Invalid Buffer Position"); } AuUInt32 currentOffset {}; if (in && inAlreadyAvailable) { currentOffset = reinterpret_cast(in) - this->internalInBuffer_; } currentOffset += inAlreadyAvailable; AuUInt32 currentLength = this->internalInLength_ - currentOffset; if (currentLength > this->internalInLength_) { SysPanic("Invalid Buffer Position"); } auto nextStreamRead = this->internalInBuffer_ + currentOffset; auto nextStreamSegment = this->internalInBuffer_ + inAlreadyAvailable; AuUInt read = AuMin(amount, currentLength); if (reader->Read(AuMemoryViewStreamWrite(this->internalInBuffer_ + currentOffset, this->internalInBuffer_ + read, read)) != IO::EStreamError::eErrorNone) { return 0; } in = (T *)(this->internalInBuffer_ + currentOffset); inAlreadyAvailable += read; return read; } }