From 0f27c7e7e707fd3c901a43ac6de4ce072758d918 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 30 Aug 2022 13:24:29 +0200 Subject: [PATCH] extend data wrapper --- src/fsfw/util/dataWrapper.h | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/fsfw/util/dataWrapper.h b/src/fsfw/util/dataWrapper.h index f5dab447..5ae2c043 100644 --- a/src/fsfw/util/dataWrapper.h +++ b/src/fsfw/util/dataWrapper.h @@ -10,19 +10,19 @@ namespace util { struct RawData { - const uint8_t* data; - size_t len; + const uint8_t* data = nullptr; + size_t len = 0; }; -enum DataTypes { RAW, SERIALIZABLE }; +enum DataTypes { NONE, RAW, SERIALIZABLE }; union DataUnion { RawData raw; - SerializeIF* serializable; + SerializeIF* serializable = nullptr; }; struct DataWrapper { - DataTypes type; + DataTypes type = DataTypes::NONE; DataUnion dataUnion; using BufPairT = std::pair; @@ -35,6 +35,14 @@ struct DataWrapper { 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) { type = DataTypes::RAW; dataUnion.raw.data = bufPair.first;