diff --git a/common/datastore/CDataStore.cpp b/common/datastore/CDataStore.cpp index aff618b..99e02d4 100644 --- a/common/datastore/CDataStore.cpp +++ b/common/datastore/CDataStore.cpp @@ -58,6 +58,22 @@ CDataStore& CDataStore::Get(uint8_t& val) { 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(ptr); + + this->m_read += bytes; + } + + return *this; +} + void CDataStore::GetBufferParams(const void** data, uint32_t* size, uint32_t* alloc) const { if (data) { *data = this->m_data; diff --git a/common/datastore/CDataStore.hpp b/common/datastore/CDataStore.hpp index acba417..9027692 100644 --- a/common/datastore/CDataStore.hpp +++ b/common/datastore/CDataStore.hpp @@ -30,6 +30,7 @@ class CDataStore { int32_t FetchRead(uint32_t pos, uint32_t bytes); int32_t FetchWrite(uint32_t pos, uint32_t bytes, const char* fileName, int32_t lineNumber); CDataStore& Get(uint8_t& val); + CDataStore& Get(uint32_t& val); CDataStore& GetDataInSitu(void*& val, uint32_t bytes); int32_t IsFinal(); CDataStore& Put(uint8_t val); diff --git a/test/DataStore.cpp b/test/DataStore.cpp index 8767ed1..1a45974 100644 --- a/test/DataStore.cpp +++ b/test/DataStore.cpp @@ -20,4 +20,16 @@ TEST_CASE("CDataStore::Get", "[datastore]") { 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); + } }