mirror of
https://github.com/thunderbrewhq/common.git
synced 2025-12-12 03:02:29 +00:00
feat(datastore): add getter and setter for size
This commit is contained in:
parent
08725b8455
commit
f98814690c
3 changed files with 38 additions and 0 deletions
|
|
@ -346,6 +346,14 @@ CDataStore& CDataStore::Set(uint32_t pos, uint16_t val) {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CDataStore::SetSize(uint32_t size) {
|
||||||
|
this->m_size = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t CDataStore::Size() {
|
||||||
|
return this->m_size;
|
||||||
|
}
|
||||||
|
|
||||||
bool CDataStore::Sub8CBBF0(uint32_t a2) {
|
bool CDataStore::Sub8CBBF0(uint32_t a2) {
|
||||||
return this->m_read <= this->m_size && this->m_size - this->m_read >= a2;
|
return this->m_read <= this->m_size && this->m_size - this->m_read >= a2;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,8 @@ class CDataStore {
|
||||||
CDataStore& PutData(const void* val, uint32_t bytes);
|
CDataStore& PutData(const void* val, uint32_t bytes);
|
||||||
CDataStore& PutString(const char* val);
|
CDataStore& PutString(const char* val);
|
||||||
CDataStore& Set(uint32_t pos, uint16_t val);
|
CDataStore& Set(uint32_t pos, uint16_t val);
|
||||||
|
void SetSize(uint32_t size);
|
||||||
|
uint32_t Size();
|
||||||
bool Sub8CBBF0(uint32_t a2);
|
bool Sub8CBBF0(uint32_t a2);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -108,3 +108,31 @@ TEST_CASE("CDataStore::Get", "[datastore]") {
|
||||||
REQUIRE(msg.m_read == 0);
|
REQUIRE(msg.m_read == 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("CDataStore::SetSize", "[datastore]") {
|
||||||
|
SECTION("sets size") {
|
||||||
|
uint8_t writeVal = 8;
|
||||||
|
|
||||||
|
CDataStore msg;
|
||||||
|
msg.Put(writeVal);
|
||||||
|
|
||||||
|
CHECK(msg.Size() == 1);
|
||||||
|
|
||||||
|
msg.SetSize(0);
|
||||||
|
|
||||||
|
CHECK(msg.Size() == 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("CDataStore::Size", "[datastore]") {
|
||||||
|
SECTION("gets size") {
|
||||||
|
uint8_t writeVal1 = 8;
|
||||||
|
uint16_t writeVal2 = 9;
|
||||||
|
|
||||||
|
CDataStore msg;
|
||||||
|
msg.Put(writeVal1);
|
||||||
|
msg.Put(writeVal2);
|
||||||
|
|
||||||
|
REQUIRE(msg.Size() == 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue