random ids
This commit is contained in:
parent
267f8dffc1
commit
98ab974515
@ -27,6 +27,21 @@ static const char* metaFileTypeSuffix(MetaFileType mft) {
|
||||
}
|
||||
|
||||
FragmentStore::FragmentStore(void) {
|
||||
{ // random namespace
|
||||
const auto num0 = _rng();
|
||||
const auto num1 = _rng();
|
||||
|
||||
_session_uuid_namespace[0] = (num0 >> 0) & 0xff;
|
||||
_session_uuid_namespace[1] = (num0 >> 8) & 0xff;
|
||||
_session_uuid_namespace[2] = (num0 >> 16) & 0xff;
|
||||
_session_uuid_namespace[3] = (num0 >> 24) & 0xff;
|
||||
|
||||
_session_uuid_namespace[4] = (num1 >> 0) & 0xff;
|
||||
_session_uuid_namespace[5] = (num1 >> 8) & 0xff;
|
||||
_session_uuid_namespace[6] = (num1 >> 16) & 0xff;
|
||||
_session_uuid_namespace[7] = (num1 >> 24) & 0xff;
|
||||
|
||||
}
|
||||
registerSerializers();
|
||||
}
|
||||
|
||||
@ -40,6 +55,30 @@ entt::basic_handle<entt::basic_registry<FragmentID>> FragmentStore::fragmentHand
|
||||
return {_reg, fid};
|
||||
}
|
||||
|
||||
std::vector<uint8_t> FragmentStore::generateNewUID(std::array<uint8_t, 8>& uuid_namespace) {
|
||||
std::vector<uint8_t> new_uid(uuid_namespace.cbegin(), uuid_namespace.cend());
|
||||
new_uid.resize(new_uid.size() + 8);
|
||||
|
||||
const auto num0 = _rng();
|
||||
const auto num1 = _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] = (num1 >> 0) & 0xff;
|
||||
new_uid[uuid_namespace.size()+5] = (num1 >> 8) & 0xff;
|
||||
new_uid[uuid_namespace.size()+6] = (num1 >> 16) & 0xff;
|
||||
new_uid[uuid_namespace.size()+7] = (num1 >> 24) & 0xff;
|
||||
|
||||
return new_uid;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> FragmentStore::generateNewUID(void) {
|
||||
return generateNewUID(_session_uuid_namespace);
|
||||
}
|
||||
|
||||
FragmentID FragmentStore::newFragmentMemoryOwned(
|
||||
const std::vector<uint8_t>& id,
|
||||
size_t initial_size
|
||||
@ -126,6 +165,12 @@ FragmentID FragmentStore::newFragmentFile(
|
||||
|
||||
return new_frag;
|
||||
}
|
||||
FragmentID FragmentStore::newFragmentFile(
|
||||
std::string_view store_path,
|
||||
MetaFileType mft
|
||||
) {
|
||||
return newFragmentFile(store_path, mft, generateNewUID());
|
||||
}
|
||||
|
||||
FragmentID FragmentStore::getFragmentByID(
|
||||
const std::vector<uint8_t>& id
|
||||
|
@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "./fragment_store_i.hpp"
|
||||
#include "entt/entity/fwd.hpp"
|
||||
|
||||
#include <entt/core/fwd.hpp>
|
||||
#include <entt/core/type_info.hpp>
|
||||
@ -14,6 +13,7 @@
|
||||
#include <vector>
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <random>
|
||||
|
||||
enum class Encryption : uint8_t {
|
||||
NONE = 0x00,
|
||||
@ -99,6 +99,7 @@ struct SerializerCallbacks {
|
||||
struct FragmentStore : public FragmentStoreI {
|
||||
entt::basic_registry<FragmentID> _reg;
|
||||
|
||||
std::minstd_rand _rng{std::random_device{}()};
|
||||
std::array<uint8_t, 8> _session_uuid_namespace;
|
||||
|
||||
std::string _default_store_path;
|
||||
@ -116,6 +117,9 @@ struct FragmentStore : public FragmentStoreI {
|
||||
|
||||
// TODO: make the frags ref counted
|
||||
|
||||
std::vector<uint8_t> generateNewUID(std::array<uint8_t, 8>& uuid_namespace);
|
||||
std::vector<uint8_t> generateNewUID(void);
|
||||
|
||||
// ========== new fragment ==========
|
||||
|
||||
// memory backed owned
|
||||
|
@ -36,7 +36,9 @@ int main(void) {
|
||||
|
||||
const auto frag0 = fs.newFragmentFile("", MetaFileType::TEXT_JSON, {0xff, 0xf1, 0xf2, 0xf0, 0xff, 0xff, 0xff, 0xf9});
|
||||
|
||||
const auto frag1 = fs.newFragmentFile("", MetaFileType::BINARY_MSGPACK, {0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xf9});
|
||||
const auto frag1 = fs.newFragmentFile("", MetaFileType::BINARY_MSGPACK);
|
||||
|
||||
const auto frag2 = fs.newFragmentFile("", MetaFileType::BINARY_MSGPACK);
|
||||
|
||||
{
|
||||
auto frag0h = fs.fragmentHandle(frag0);
|
||||
@ -62,7 +64,6 @@ int main(void) {
|
||||
|
||||
frag1h.emplace_or_replace<Components::DataCompressionType>();
|
||||
frag1h.emplace_or_replace<Components::DataEncryptionType>();
|
||||
//frag1h.emplace_or_replace<Components::Ephemeral::MetaFileType>(MetaFileType::BINARY_MSGPACK);
|
||||
|
||||
std::function<FragmentStore::write_to_storage_fetch_data_cb> fn_cb = [read = 0ul](uint8_t* request_buffer, uint64_t buffer_size) mutable -> uint64_t {
|
||||
static constexpr std::string_view text = "This is some random data";
|
||||
|
Loading…
Reference in New Issue
Block a user