Merge remote-tracking branch 'upstream/mueller/data-wrapper' into develop
This commit is contained in:
commit
6ebd6a965b
@ -9,6 +9,8 @@
|
|||||||
|
|
||||||
namespace util {
|
namespace util {
|
||||||
|
|
||||||
|
using BufPair = std::pair<const uint8_t*, size_t>;
|
||||||
|
|
||||||
struct RawData {
|
struct RawData {
|
||||||
RawData() = default;
|
RawData() = default;
|
||||||
const uint8_t* data = nullptr;
|
const uint8_t* data = nullptr;
|
||||||
@ -23,7 +25,6 @@ union DataUnion {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct DataWrapper {
|
struct DataWrapper {
|
||||||
using BufPairT = std::pair<const uint8_t*, size_t>;
|
|
||||||
|
|
||||||
DataWrapper() = default;
|
DataWrapper() = default;
|
||||||
|
|
||||||
@ -31,7 +32,7 @@ struct DataWrapper {
|
|||||||
setRawData({data, size});
|
setRawData({data, size});
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit DataWrapper(BufPairT raw): type(DataTypes::RAW) {
|
explicit DataWrapper(BufPair raw): type(DataTypes::RAW) {
|
||||||
setRawData(raw);
|
setRawData(raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,7 +43,6 @@ struct DataWrapper {
|
|||||||
DataTypes type = DataTypes::NONE;
|
DataTypes type = DataTypes::NONE;
|
||||||
DataUnion dataUnion;
|
DataUnion dataUnion;
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]] size_t getLength() const {
|
[[nodiscard]] size_t getLength() const {
|
||||||
if (type == DataTypes::RAW) {
|
if (type == DataTypes::RAW) {
|
||||||
return dataUnion.raw.len;
|
return dataUnion.raw.len;
|
||||||
@ -59,8 +59,12 @@ struct DataWrapper {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
<<<<<<< HEAD
|
||||||
|
|
||||||
void setRawData(BufPairT bufPair) {
|
void setRawData(BufPairT bufPair) {
|
||||||
|
=======
|
||||||
|
void setRawData(BufPair bufPair) {
|
||||||
|
>>>>>>> upstream/mueller/data-wrapper
|
||||||
type = DataTypes::RAW;
|
type = DataTypes::RAW;
|
||||||
dataUnion.raw.data = bufPair.first;
|
dataUnion.raw.data = bufPair.first;
|
||||||
dataUnion.raw.len = bufPair.second;
|
dataUnion.raw.len = bufPair.second;
|
||||||
|
@ -12,21 +12,48 @@ TEST_CASE("Data Wrapper", "[util]") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Set Raw Data") {
|
SECTION("Set Raw Data") {
|
||||||
|
util::DataWrapper* instance = &wrapper;
|
||||||
|
bool deleteInst = false;
|
||||||
REQUIRE(wrapper.isNull());
|
REQUIRE(wrapper.isNull());
|
||||||
std::array<uint8_t, 4> data = {1, 2, 3, 4};
|
std::array<uint8_t, 4> data = {1, 2, 3, 4};
|
||||||
wrapper.setRawData({data.data(), data.size()});
|
SECTION("Setter") {
|
||||||
REQUIRE(not wrapper.isNull());
|
wrapper.setRawData({data.data(), data.size()});
|
||||||
REQUIRE(wrapper.type == util::DataTypes::RAW);
|
}
|
||||||
REQUIRE(wrapper.dataUnion.raw.data == data.data());
|
SECTION("Direct Construction Pair") {
|
||||||
REQUIRE(wrapper.dataUnion.raw.len == data.size());
|
instance = new util::DataWrapper(util::BufPair(data.data(), data.size()));
|
||||||
|
deleteInst = true;
|
||||||
|
}
|
||||||
|
SECTION("Direct Construction Single Args") {
|
||||||
|
instance = new util::DataWrapper(data.data(), data.size());
|
||||||
|
deleteInst = true;
|
||||||
|
}
|
||||||
|
REQUIRE(not instance->isNull());
|
||||||
|
REQUIRE(instance->type == util::DataTypes::RAW);
|
||||||
|
REQUIRE(instance->dataUnion.raw.data == data.data());
|
||||||
|
REQUIRE(instance->dataUnion.raw.len == data.size());
|
||||||
|
if(deleteInst) {
|
||||||
|
delete instance;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Simple Serializable") {
|
SECTION("Simple Serializable") {
|
||||||
REQUIRE(wrapper.isNull());
|
util::DataWrapper* instance = &wrapper;
|
||||||
|
bool deleteInst = false;
|
||||||
|
REQUIRE(instance->isNull());
|
||||||
SimpleSerializable serializable;
|
SimpleSerializable serializable;
|
||||||
wrapper.setSerializable(serializable);
|
SECTION("Setter") {
|
||||||
REQUIRE(not wrapper.isNull());
|
wrapper.setSerializable(serializable);
|
||||||
REQUIRE(wrapper.type == util::DataTypes::SERIALIZABLE);
|
}
|
||||||
REQUIRE(wrapper.dataUnion.serializable == &serializable);
|
SECTION("Direct Construction") {
|
||||||
|
instance = new util::DataWrapper(serializable);
|
||||||
|
deleteInst = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
REQUIRE(not instance->isNull());
|
||||||
|
REQUIRE(instance->type == util::DataTypes::SERIALIZABLE);
|
||||||
|
REQUIRE(instance->dataUnion.serializable == &serializable);
|
||||||
|
if(deleteInst) {
|
||||||
|
delete instance;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user