mirror of
https://github.com/thunderbrewhq/common.git
synced 2025-12-12 11:12:29 +00:00
feat(datastore): add getter for uint32_t
This commit is contained in:
parent
42384cbf77
commit
28e59a11ef
3 changed files with 29 additions and 0 deletions
|
|
@ -58,6 +58,22 @@ CDataStore& CDataStore::Get(uint8_t& val) {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CDataStore& CDataStore::Get(uint32_t& val) {
|
||||||
|
STORM_ASSERT(this->IsFinal());
|
||||||
|
|
||||||
|
auto bytes = sizeof(val);
|
||||||
|
|
||||||
|
if (this->FetchRead(this->m_read, bytes)) {
|
||||||
|
auto ofs = this->m_read - this->m_base;
|
||||||
|
auto ptr = &this->m_data[ofs];
|
||||||
|
val = *reinterpret_cast<uint32_t*>(ptr);
|
||||||
|
|
||||||
|
this->m_read += bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
void CDataStore::GetBufferParams(const void** data, uint32_t* size, uint32_t* alloc) const {
|
void CDataStore::GetBufferParams(const void** data, uint32_t* size, uint32_t* alloc) const {
|
||||||
if (data) {
|
if (data) {
|
||||||
*data = this->m_data;
|
*data = this->m_data;
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ class CDataStore {
|
||||||
int32_t FetchRead(uint32_t pos, uint32_t bytes);
|
int32_t FetchRead(uint32_t pos, uint32_t bytes);
|
||||||
int32_t FetchWrite(uint32_t pos, uint32_t bytes, const char* fileName, int32_t lineNumber);
|
int32_t FetchWrite(uint32_t pos, uint32_t bytes, const char* fileName, int32_t lineNumber);
|
||||||
CDataStore& Get(uint8_t& val);
|
CDataStore& Get(uint8_t& val);
|
||||||
|
CDataStore& Get(uint32_t& val);
|
||||||
CDataStore& GetDataInSitu(void*& val, uint32_t bytes);
|
CDataStore& GetDataInSitu(void*& val, uint32_t bytes);
|
||||||
int32_t IsFinal();
|
int32_t IsFinal();
|
||||||
CDataStore& Put(uint8_t val);
|
CDataStore& Put(uint8_t val);
|
||||||
|
|
|
||||||
|
|
@ -20,4 +20,16 @@ TEST_CASE("CDataStore::Get", "[datastore]") {
|
||||||
|
|
||||||
REQUIRE(readVal == writeVal);
|
REQUIRE(readVal == writeVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SECTION("gets uint32_t") {
|
||||||
|
uint32_t writeVal = 0x12345678;
|
||||||
|
uint32_t readVal = 0x12345678;
|
||||||
|
|
||||||
|
CDataStore msg;
|
||||||
|
msg.Put(writeVal);
|
||||||
|
msg.Finalize();
|
||||||
|
msg.Get(readVal);
|
||||||
|
|
||||||
|
REQUIRE(readVal == writeVal);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue