From 6d8510b4a75c9ae42c59b520a033ff341806193c Mon Sep 17 00:00:00 2001 From: fallenoak Date: Sun, 11 Jan 2026 23:48:16 -0600 Subject: [PATCH] feat(util): add SmartGUID --- src/util/SmartGUID.cpp | 29 +++++++++++++++++++++++++++++ src/util/SmartGUID.hpp | 17 +++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 src/util/SmartGUID.cpp create mode 100644 src/util/SmartGUID.hpp diff --git a/src/util/SmartGUID.cpp b/src/util/SmartGUID.cpp new file mode 100644 index 0000000..b165e35 --- /dev/null +++ b/src/util/SmartGUID.cpp @@ -0,0 +1,29 @@ +#include "util/SmartGUID.hpp" +#include + +SmartGUID::operator uint64_t() const { + return this->guid; +} + +SmartGUID& SmartGUID::operator=(uint64_t guid) { + this->guid = guid; + return *this; +} + +CDataStore& operator>>(CDataStore& msg, SmartGUID& guid) { + guid = 0; + + uint8_t mask; + msg.Get(mask); + + for (int32_t i = 0; i < 8; i++) { + if (mask & (1 << i)) { + uint8_t byte; + msg.Get(byte); + + guid.guid |= static_cast(byte) << (i * 8); + } + } + + return msg; +} diff --git a/src/util/SmartGUID.hpp b/src/util/SmartGUID.hpp new file mode 100644 index 0000000..fef46c8 --- /dev/null +++ b/src/util/SmartGUID.hpp @@ -0,0 +1,17 @@ +#ifndef UTIL_SMART_GUID_HPP +#define UTIL_SMART_GUID_HPP + +#include + +class CDataStore; + +struct SmartGUID { + uint64_t guid; + + operator uint64_t() const; + SmartGUID& operator=(uint64_t value); +}; + +CDataStore& operator>>(CDataStore& msg, SmartGUID& guid); + +#endif