43 const Byte l =
byte & 0x0F;
44 const Byte h = (
byte & 0xF0) >> 4;
63 const size_t & src_size)
const
66 <<
"Buffer size is not enough";
68 auto this_str = (
char *)
this;
69 char *ret_val = buffer;
72 for (
int i = 0; i <
sizeof(
Uid); ++i)
75 assert(this_str - (
char*)
this ==
sizeof(
Uid));
84 auto this_str =
reinterpret_cast<char *
>(
this);
87 for (
int i = 0; i <
sizeof(
Uid); ++i)
93 const uint64_t & _counter,
94 const uint32_t & _port_number)
95 : ipAddr(_ipAddr), port_number(_port_number), counter(_counter)
101 std::random_device rd;
105 const auto high =
static_cast<decltype(
random_number)
>(rd());
116 const size_t len = std::strlen(str);
118 <<
"String too short for Uid (expected " << (
stringSize - 1) <<
" chars)";
121 for (
size_t i = 0; i < static_cast<size_t>(
stringSize - 1); ++i)
123 <<
"Invalid hex character in Uid string at index " << i;
130 return (ipAddr == uid.ipAddr and
131 port_number == uid.port_number and
132 counter == uid.counter and
133 random_number == uid.random_number);
139 <<
"Buffer size too small for UID string representation";
Exception handling system with formatted messages for Aleph-w.
#define ah_invalid_argument_if(C)
Throws std::invalid_argument if condition holds.
#define ah_range_error_if(C)
Throws std::range_error if condition holds.
Unique identifier for distributed systems.
static constexpr int stringSize
Required buffer size for string representation.
char * stringficate(char *buffer, const size_t &src_size) const
Convert UID components to hexadecimal string.
char * getStringUid(char *str, const size_t &size) const
Convert UID to hexadecimal string representation.
uint64_t random_number
Random number component.
void destringficate(char *str)
Parse hexadecimal string and populate UID components.
Uid()=default
Default constructor.
bool operator==(const Uid &uid) const noexcept
Compare two UIDs for equality.
uint32_t IPv4_Address
Type alias for IPv4 addresses stored as 32-bit integers.
char nibble_to_char(const int i)
Convert a 4-bit nibble stored in an int to its hex character.
int char_to_nibble(const char c)
Convert a hex character in 0..9A..F to its 4-bit nibble value.
static char * hexadecimalize(const Byte &byte, char *&str)
static char unhexadecimalize(char *&str)
Unique identifier generation for distributed systems.