From a5e67d0ee8c33ed4480458d591f2ea927a2ee04b Mon Sep 17 00:00:00 2001 From: Green Sky Date: Fri, 12 Apr 2024 19:44:24 +0200 Subject: [PATCH] move uuid gen to util --- external/solanaceae_util | 2 +- src/CMakeLists.txt | 3 - src/fragment_store/message_fragment_store.hpp | 2 +- src/fragment_store/uuid_generator.cpp | 68 ------------------- src/fragment_store/uuid_generator.hpp | 24 ------- 5 files changed, 2 insertions(+), 97 deletions(-) delete mode 100644 src/fragment_store/uuid_generator.cpp delete mode 100644 src/fragment_store/uuid_generator.hpp diff --git a/external/solanaceae_util b/external/solanaceae_util index bee42d46..2420af46 160000 --- a/external/solanaceae_util +++ b/external/solanaceae_util @@ -1 +1 @@ -Subproject commit bee42d4688e873115d578032970f0d5b84c41605 +Subproject commit 2420af464f270afaf07391ab51cc94a8b979e00c diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7715e3e4..23d91384 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,9 +3,6 @@ cmake_minimum_required(VERSION 3.9 FATAL_ERROR) ######################################## add_library(message_fragment_store - ./fragment_store/uuid_generator.hpp - ./fragment_store/uuid_generator.cpp - ./json/message_components.hpp # TODO: move ./json/tox_message_components.hpp # TODO: move diff --git a/src/fragment_store/message_fragment_store.hpp b/src/fragment_store/message_fragment_store.hpp index 6a26c4e1..1ac4402a 100644 --- a/src/fragment_store/message_fragment_store.hpp +++ b/src/fragment_store/message_fragment_store.hpp @@ -3,7 +3,7 @@ #include #include -#include "./uuid_generator.hpp" +#include #include "./message_serializer.hpp" diff --git a/src/fragment_store/uuid_generator.cpp b/src/fragment_store/uuid_generator.cpp deleted file mode 100644 index cc07985b..00000000 --- a/src/fragment_store/uuid_generator.cpp +++ /dev/null @@ -1,68 +0,0 @@ -#include "./uuid_generator.hpp" - -UUIDGenerator_128_128::UUIDGenerator_128_128(void) { - { // random namespace - const auto num0 = _rng(); - const auto num1 = _rng(); - const auto num2 = _rng(); - const auto num3 = _rng(); - - _uuid_namespace[0+0] = (num0 >> 0) & 0xff; - _uuid_namespace[0+1] = (num0 >> 8) & 0xff; - _uuid_namespace[0+2] = (num0 >> 16) & 0xff; - _uuid_namespace[0+3] = (num0 >> 24) & 0xff; - - _uuid_namespace[4+0] = (num1 >> 0) & 0xff; - _uuid_namespace[4+1] = (num1 >> 8) & 0xff; - _uuid_namespace[4+2] = (num1 >> 16) & 0xff; - _uuid_namespace[4+3] = (num1 >> 24) & 0xff; - - _uuid_namespace[8+0] = (num2 >> 0) & 0xff; - _uuid_namespace[8+1] = (num2 >> 8) & 0xff; - _uuid_namespace[8+2] = (num2 >> 16) & 0xff; - _uuid_namespace[8+3] = (num2 >> 24) & 0xff; - - _uuid_namespace[12+0] = (num3 >> 0) & 0xff; - _uuid_namespace[12+1] = (num3 >> 8) & 0xff; - _uuid_namespace[12+2] = (num3 >> 16) & 0xff; - _uuid_namespace[12+3] = (num3 >> 24) & 0xff; - } -} - -UUIDGenerator_128_128::UUIDGenerator_128_128(const std::array& uuid_namespace) : - _uuid_namespace(uuid_namespace) -{ -} - -std::vector UUIDGenerator_128_128::operator()(void) { - std::vector new_uid(_uuid_namespace.cbegin(), _uuid_namespace.cend()); - new_uid.resize(new_uid.size() + 16); - - const auto num0 = _rng(); - const auto num1 = _rng(); - const auto num2 = _rng(); - const auto num3 = _rng(); - - new_uid[_uuid_namespace.size()+0] = (num0 >> 0) & 0xff; - new_uid[_uuid_namespace.size()+1] = (num0 >> 8) & 0xff; - new_uid[_uuid_namespace.size()+2] = (num0 >> 16) & 0xff; - new_uid[_uuid_namespace.size()+3] = (num0 >> 24) & 0xff; - - new_uid[_uuid_namespace.size()+4+0] = (num1 >> 0) & 0xff; - new_uid[_uuid_namespace.size()+4+1] = (num1 >> 8) & 0xff; - new_uid[_uuid_namespace.size()+4+2] = (num1 >> 16) & 0xff; - new_uid[_uuid_namespace.size()+4+3] = (num1 >> 24) & 0xff; - - new_uid[_uuid_namespace.size()+8+0] = (num2 >> 0) & 0xff; - new_uid[_uuid_namespace.size()+8+1] = (num2 >> 8) & 0xff; - new_uid[_uuid_namespace.size()+8+2] = (num2 >> 16) & 0xff; - new_uid[_uuid_namespace.size()+8+3] = (num2 >> 24) & 0xff; - - new_uid[_uuid_namespace.size()+12+0] = (num3 >> 0) & 0xff; - new_uid[_uuid_namespace.size()+12+1] = (num3 >> 8) & 0xff; - new_uid[_uuid_namespace.size()+12+2] = (num3 >> 16) & 0xff; - new_uid[_uuid_namespace.size()+12+3] = (num3 >> 24) & 0xff; - - return new_uid; -} - diff --git a/src/fragment_store/uuid_generator.hpp b/src/fragment_store/uuid_generator.hpp deleted file mode 100644 index b0a1f999..00000000 --- a/src/fragment_store/uuid_generator.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -struct UUIDGeneratorI { - virtual std::vector operator()(void) = 0; -}; - -// TODO: templates? -struct UUIDGenerator_128_128 final : public UUIDGeneratorI { - private: - std::array _uuid_namespace; - std::minstd_rand _rng{std::random_device{}()}; - - public: - UUIDGenerator_128_128(void); // default randomly initializes namespace - UUIDGenerator_128_128(const std::array& uuid_namespace); - - std::vector operator()(void) override; -}; -