feat: add hk::Dataset::deSerializeWithValidityBlob

- Counterpart of serializing with validity blob: sets each member's validity from the blob
- Checks the stream length up front, a short stream leaves the dataset untouched
- deSerialize keeps ignoring the blob

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Tobias BaumgartlandClaude Opus 5.5 committed 2026-10-07 23:10:22 +02:00
1 parent 03d3b6cd68
commit 29b57aa718
3 files changed
+78

No files matched your search

+48
View File
@@ -82,4 +82,52 @@ TEST_CASE("Pool Dataset Test", "[datapool]") {
CHECK(buf[31] == 0b10000000);
CHECK(buf[32] == 0);
}
SECTION("Pool Dataset Deserialization With Validity") {
uint8_t buf[64]{};
TestDatasetLarger source;
source.setChildrenValidity(true);
source.test1 = 502392;
source.test1.setValid(false);
source.test7 = -5;
source.test8.entry[1] = 1234;
source.test8.setValid(false);
source.serializeWithValidityBlob = true;
size_t serLen = 0;
uint8_t* dataPtr = buf;
REQUIRE(source.serialize(&dataPtr, &serLen, sizeof(buf), SerializeIF::Endianness::NETWORK) ==
returnvalue::OK);
TestDatasetLarger target;
target.setChildrenValidity(true);
const uint8_t* readPtr = buf;
size_t remaining = serLen;
CHECK(target.deSerializeWithValidityBlob(&readPtr, &remaining,
SerializeIF::Endianness::NETWORK) == returnvalue::OK);
CHECK(remaining == 0);
CHECK(readPtr == buf + serLen);
CHECK(target.test0.isValid());
CHECK(!target.test1.isValid());
CHECK(target.test1.get() == 502392);
CHECK(target.test7.isValid());
CHECK(target.test7.get() == -5);
CHECK(!target.test8.isValid());
CHECK(target.test8.entry[1] == 1234);
}
SECTION("Pool Dataset Deserialization With Validity Short Stream") {
uint8_t buf[64]{};
TestDatasetSmall target;
target.test0 = 7;
target.test0.setValid(true);
const uint8_t* readPtr = buf;
// One byte short of the 5 value bytes and the 1 byte validity blob
size_t remaining = 5;
CHECK(target.deSerializeWithValidityBlob(&readPtr, &remaining,
SerializeIF::Endianness::NETWORK) ==
SerializeIF::STREAM_TOO_SHORT);
CHECK(remaining == 5);
CHECK(target.test0.get() == 7);
CHECK(target.test0.isValid());
}
}