extend data wrapper
This commit is contained in:
parent
20d42add03
commit
0f27c7e7e7
@ -10,19 +10,19 @@
|
|||||||
namespace util {
|
namespace util {
|
||||||
|
|
||||||
struct RawData {
|
struct RawData {
|
||||||
const uint8_t* data;
|
const uint8_t* data = nullptr;
|
||||||
size_t len;
|
size_t len = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum DataTypes { RAW, SERIALIZABLE };
|
enum DataTypes { NONE, RAW, SERIALIZABLE };
|
||||||
|
|
||||||
union DataUnion {
|
union DataUnion {
|
||||||
RawData raw;
|
RawData raw;
|
||||||
SerializeIF* serializable;
|
SerializeIF* serializable = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DataWrapper {
|
struct DataWrapper {
|
||||||
DataTypes type;
|
DataTypes type = DataTypes::NONE;
|
||||||
DataUnion dataUnion;
|
DataUnion dataUnion;
|
||||||
using BufPairT = std::pair<const uint8_t*, size_t>;
|
using BufPairT = std::pair<const uint8_t*, size_t>;
|
||||||
|
|
||||||
@ -35,6 +35,14 @@ struct DataWrapper {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] bool isNull() const {
|
||||||
|
if (type == DataTypes::RAW and dataUnion.raw.data == nullptr or
|
||||||
|
(type == DataTypes::SERIALIZABLE and dataUnion.serializable == nullptr) or
|
||||||
|
(type == DataTypes::NONE)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
void setRawData(BufPairT bufPair) {
|
void setRawData(BufPairT bufPair) {
|
||||||
type = DataTypes::RAW;
|
type = DataTypes::RAW;
|
||||||
dataUnion.raw.data = bufPair.first;
|
dataUnion.raw.data = bufPair.first;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user