feat(datastore): add getter for uint8_t

This commit is contained in:
fallenoak 2023-01-08 00:03:52 -06:00 committed by GitHub
parent 1c4d306a7f
commit 30c34ca015
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 0 deletions

View file

@ -8,6 +8,22 @@ void CDataStore::DetachBuffer(void** data, uint32_t* size, uint32_t* alloc) {
// TODO
}
int32_t CDataStore::FetchRead(uint32_t pos, uint32_t bytes) {
if (pos + bytes <= this->m_size) {
if (pos >= this->m_base && pos + bytes <= this->m_base + this->m_alloc) {
return 1;
}
if (this->InternalFetchRead(pos, bytes, this->m_data, this->m_base, this->m_alloc)) {
return 1;
}
}
this->m_read = this->m_size + 1;
return 0;
}
int32_t CDataStore::FetchWrite(uint32_t pos, uint32_t bytes, const char* fileName, int32_t lineNumber) {
if (pos >= this->m_base && pos + bytes <= this->m_base + this->m_alloc) {
return 1;
@ -26,6 +42,20 @@ void CDataStore::Finalize() {
this->m_read = 0;
}
CDataStore& CDataStore::Get(uint8_t& val) {
STORM_ASSERT(this->IsFinal());
if (this->FetchRead(this->m_read, 1)) {
auto ofs = this->m_read - this->m_base;
auto ptr = &this->m_data[ofs];
val = *reinterpret_cast<uint8_t*>(ptr);
this->m_read += sizeof(val);
}
return *this;
}
void CDataStore::GetBufferParams(const void** data, uint32_t* size, uint32_t* alloc) const {
if (data) {
*data = this->m_data;