diff options
author | rtk0c <[email protected]> | 2022-06-03 23:26:44 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2022-06-03 23:26:44 -0700 |
commit | 60ccc62f4934e44ad5b905fdbcf458302b8d8a09 (patch) | |
tree | 02ec83cc8387abfd08bd5ee7ea4e8115f1bfb8d0 /source/10-common/Uid.cpp | |
parent | c2ef7737536bf1f8c81fcfae95c0183b21c9753f (diff) |
Changeset: 63 [WIP] Rename directories
Diffstat (limited to 'source/10-common/Uid.cpp')
-rw-r--r-- | source/10-common/Uid.cpp | 58 |
1 files changed, 0 insertions, 58 deletions
diff --git a/source/10-common/Uid.cpp b/source/10-common/Uid.cpp deleted file mode 100644 index 1930cd8..0000000 --- a/source/10-common/Uid.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include "Uid.hpp" - -#include "RapidJsonHelper.hpp" - -#include <rapidjson/document.h> -#include <cstring> -#include <random> - -Uid Uid::Create() { - std::random_device rd; - std::mt19937_64 gen(rd()); - std::uniform_int_distribution<uint64_t> dist( - std::numeric_limits<uint64_t>::min(), - std::numeric_limits<uint64_t>::max()); - - Uid uid; - uid.upper = dist(gen); - uid.lower = dist(gen); - return uid; -} - -bool Uid::IsNull() const { - return upper == 0 && lower == 0; -} - -void Uid::ReadString(std::string_view str) { - sscanf(str.data(), BRUSSEL_Uid_SCAN_STR, &upper, &lower); -} - -std::string Uid::WriteString() { - char buf[256]; - snprintf(buf, sizeof(buf), BRUSSEL_Uid_FORMAT_STR, upper, lower); - return std::string(buf); -} - -void Uid::Read(const rapidjson::Value& value) { - assert(value.IsArray()); - assert(value.Size() == 2); - auto& upper = value[0]; - assert(upper.IsUint64()); - auto& lower = value[1]; - assert(lower.IsUint64()); - - this->upper = upper.GetUint64(); - this->lower = lower.GetUint64(); -} - -void Uid::WriteInto(rapidjson::Value& value, rapidjson::Document& root) { - value.Reserve(2, root.GetAllocator()); - value.PushBack((uint64_t)upper, root.GetAllocator()); - value.PushBack((uint64_t)lower, root.GetAllocator()); -} - -rapidjson::Value Uid::Write(rapidjson::Document& root) { - rapidjson::Value result(rapidjson::kArrayType); - WriteInto(result, root); - return result; -} |