feat(util): add SmartGUID

This commit is contained in:
fallenoak 2026-01-11 23:48:16 -06:00
parent 9162978b4f
commit 6d8510b4a7
No known key found for this signature in database
GPG Key ID: 7628F8E61AEA070D
2 changed files with 46 additions and 0 deletions

29
src/util/SmartGUID.cpp Normal file
View File

@ -0,0 +1,29 @@
#include "util/SmartGUID.hpp"
#include <common/DataStore.hpp>
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<uint64_t>(byte) << (i * 8);
}
}
return msg;
}

17
src/util/SmartGUID.hpp Normal file
View File

@ -0,0 +1,17 @@
#ifndef UTIL_SMART_GUID_HPP
#define UTIL_SMART_GUID_HPP
#include <cstdint>
class CDataStore;
struct SmartGUID {
uint64_t guid;
operator uint64_t() const;
SmartGUID& operator=(uint64_t value);
};
CDataStore& operator>>(CDataStore& msg, SmartGUID& guid);
#endif