move uuid gen to util

This commit is contained in:
Green Sky 2024-04-12 19:44:24 +02:00
parent 9e30983b22
commit a5e67d0ee8
No known key found for this signature in database
5 changed files with 2 additions and 97 deletions

@ -1 +1 @@
Subproject commit bee42d4688e873115d578032970f0d5b84c41605
Subproject commit 2420af464f270afaf07391ab51cc94a8b979e00c

View File

@ -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

View File

@ -3,7 +3,7 @@
#include <solanaceae/object_store/object_store.hpp>
#include <solanaceae/object_store/meta_components.hpp>
#include "./uuid_generator.hpp"
#include <solanaceae/util/uuid_generator.hpp>
#include "./message_serializer.hpp"

View File

@ -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<uint8_t, 16>& uuid_namespace) :
_uuid_namespace(uuid_namespace)
{
}
std::vector<uint8_t> UUIDGenerator_128_128::operator()(void) {
std::vector<uint8_t> 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;
}

View File

@ -1,24 +0,0 @@
#pragma once
#include <vector>
#include <array>
#include <random>
#include <cstdint>
struct UUIDGeneratorI {
virtual std::vector<uint8_t> operator()(void) = 0;
};
// TODO: templates?
struct UUIDGenerator_128_128 final : public UUIDGeneratorI {
private:
std::array<uint8_t, 16> _uuid_namespace;
std::minstd_rand _rng{std::random_device{}()};
public:
UUIDGenerator_128_128(void); // default randomly initializes namespace
UUIDGenerator_128_128(const std::array<uint8_t, 16>& uuid_namespace);
std::vector<uint8_t> operator()(void) override;
};