19#include <netinet/in.h>
25static_assert(
sizeof(
RandomUuid) == 128/8,
"RandomUuid has RFC 4122-prescribed 128-bit size");
31 const auto rnd1 = rng();
32 const auto rnd2 = rng();
38 static_assert(
sizeof(rnd1) +
sizeof(rnd2) ==
sizeof(*this),
"random bits fill a UUID");
39 memcpy(
raw(), &rnd1,
sizeof(rnd1));
40 memcpy(
raw() +
sizeof(rnd1), &rnd2,
sizeof(rnd2));
57 static_assert(
sizeof(*this) ==
sizeof(
Serialized),
"RandomUuid is deserialized with 128/8 bytes");
58 memcpy(
raw(), bytes.data(),
sizeof(*
this));
82 auto toNetwork =
clone();
85 toNetwork.timeLow = htonl(
timeLow);
86 toNetwork.timeMid = htons(
timeMid);
88 return *
reinterpret_cast<const Serialized *
>(toNetwork.raw());
101 for (
size_t i = 0; i <
sizeof(
node); ++i)
108 return memcmp(
raw(), other.
raw(),
sizeof(*
this)) == 0;
#define Here()
source code location of the caller
AsHex< Integer > asHex(const Integer n)
a helper to ease AsHex object creation
std::ostream & operator<<(std::ostream &os, const RandomUuid &uuid)
std::mt19937_64::result_type RandomSeed64()
a 64-bit version of RandomSeed32()
RandomUuid()
creates a new unique ID (i.e. not a "nil UUID" in RFC 4122 terminology)
uint8_t clockSeqHiAndReserved
void print(std::ostream &os) const
writes a human-readable representation
bool sane() const
whether this (being constructed) object follows UUID version 4 variant 1 format
Serialized serialize() const
exports UUID value; suitable for long-term storage
std::array< uint8_t, 128/8 > Serialized
UUID representation independent of machine byte-order architecture.
RandomUuid clone() const
creates a UUID object with the same value as this UUID
bool operator==(const RandomUuid &) const
char * raw()
read/write access to storage bytes
uint16_t timeHiAndVersion
an std::runtime_error with thrower location info
#define EBIT_CLR(flag, bit)
#define EBIT_SET(flag, bit)
#define EBIT_TEST(flag, bit)