mirror of
https://github.com/whoahq/whoa.git
synced 2026-02-02 00:32:45 +03:00
feat(util): add SmartGUID
This commit is contained in:
parent
9162978b4f
commit
6d8510b4a7
29
src/util/SmartGUID.cpp
Normal file
29
src/util/SmartGUID.cpp
Normal 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
17
src/util/SmartGUID.hpp
Normal 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
|
||||||
Loading…
Reference in New Issue
Block a user