11#include <boost/uuid/uuid_generators.hpp>
18 using Uid = std::array<std::uint8_t, 16>;
26 thread_local boost::uuids::random_generator generator;
27 const auto uuid = generator();
29 std::copy(uuid.begin(), uuid.end(), result.begin());
38 inline std::string
hex(
41 if (std::none_of(uid.begin(), uid.end(), [](std::uint8_t
byte) { return byte != 0; }))
43 static constexpr char digits[] =
"0123456789abcdef";
46 for (
const auto byte : uid)
48 result.push_back(digits[
byte >> 4]);
49 result.push_back(digits[
byte & 15]);
60 const std::string& uid)
62 return uid.size() == 32 &&
63 std::all_of(uid.begin(), uid.end(), [](
char c) { return (c >=
'0' && c <=
'9') || (c >=
'a' && c <=
'f'); }) &&
64 std::any_of(uid.begin(), uid.end(), [](
char c) { return c !=
'0'; });
std::array< std::uint8_t, 16 > Uid
A 128-bit identifier shared by routing and stored entries.
std::string hex(const Uid &uid)
Formats a routing UID as lowercase hexadecimal.
Uid generate()
Generates a random, globally unique identifier.
bool valid(const std::string &uid)
Validates the canonical text form of an assigned UID.