|
VLink
2.0.0
A high-performance communication middleware
|
Value-typed RFC 4122 UUID. More...
#include <uuid.h>
Public Types | |
| enum class | Variant : uint8_t { kNcs = 0 , kRfc = 1 , kMicrosoft = 2 , kReserved = 3 } |
| UUID variant inferred from the high bits of octet 8. More... | |
| enum class | Version : uint8_t { kNone = 0 , kTimeBased = 1 , kDceSecurity = 2 , kNameBasedMd5 = 3 , kRandomBased = 4 , kNameBasedSha1 = 5 } |
| UUID version inferred from the high nibble of octet 6. More... | |
| using | value_type = uint8_t |
| Underlying byte type used by the 16-byte payload. More... | |
Public Member Functions | |
| constexpr | Uuid () noexcept |
| Default-constructs a nil UUID (all 16 bytes zero). More... | |
| constexpr | Uuid (const std::array< value_type, kByteSize > &data) noexcept |
| Constructs from a 16-byte array. More... | |
| constexpr | Uuid (const value_type(&arr)[kByteSize]) noexcept |
| Constructs from a raw C array reference of exactly 16 bytes. More... | |
| template<typename ForwardIteratorT > | |
| Uuid (ForwardIteratorT first, ForwardIteratorT last) | |
| Constructs from a forward-iterator range of exactly 16 bytes. More... | |
| constexpr Variant | variant () const noexcept |
| Returns the variant field inferred from octet 8. More... | |
| constexpr Version | version () const noexcept |
| Returns the version field inferred from the high nibble of octet 6. More... | |
| constexpr bool | is_nil () const noexcept |
| Reports whether every byte is zero (the nil UUID). More... | |
| constexpr const std::array< value_type, kByteSize > & | bytes () const noexcept |
| Provides read-only access to the underlying 16-byte payload. More... | |
| std::string | to_string () const noexcept |
| Formats the UUID as the canonical 36-character lowercase hyphenated string. More... | |
| std::string | to_compact_string () const noexcept |
| Formats the UUID as a 32-character lowercase hex string without hyphens. More... | |
| void | swap (Uuid &other) noexcept |
Swaps contents with other in noexcept fashion. More... | |
Static Public Member Functions | |
| static bool | is_valid (std::string_view str) noexcept |
Validates whether str is a well-formed UUID literal. More... | |
| static bool | is_valid (const char *str) noexcept |
Null-safe C-string overload of is_valid(). More... | |
| static std::optional< Uuid > | from_string (std::string_view str) noexcept |
| Parses a UUID literal and returns the resulting value. More... | |
| static std::optional< Uuid > | from_string (const char *str) noexcept |
Null-safe C-string overload of from_string(). More... | |
| static Uuid | generate_random () noexcept |
| Generates a random v4 UUID using a thread-local seeded engine. More... | |
| static Uuid | generate_random (std::mt19937 &engine) noexcept |
| Generates a random v4 UUID from a caller-managed engine. More... | |
| static std::vector< value_type > | random_bytes (size_t count) noexcept |
Produces count random-device-seeded pseudo-random bytes. More... | |
| static std::string | random_hex (size_t byte_count=16U) noexcept |
Produces byte_count pseudo-random bytes encoded as a lowercase hex string. More... | |
Static Public Attributes | |
| static constexpr size_t | kByteSize = 16U |
| UUID payload length (16 bytes per RFC 4122). More... | |
| static constexpr size_t | kStringSize = 36U |
Canonical 36-character textual length: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx. More... | |
Friends | |
| bool | operator== (const Uuid &lhs, const Uuid &rhs) noexcept |
| Equality comparison over the 16-byte payload. More... | |
| bool | operator!= (const Uuid &lhs, const Uuid &rhs) noexcept |
| Inequality comparison over the 16-byte payload. More... | |
| bool | operator< (const Uuid &lhs, const Uuid &rhs) noexcept |
| Lexicographic less-than comparison over the 16-byte payload. More... | |
| VLINK_EXPORT friend std::ostream & | operator<< (std::ostream &ostream, const Uuid &id) |
Stream insertion delegating to to_string(). More... | |
Value-typed RFC 4122 UUID.
Stores 16 bytes in network byte order. Trivially copyable and comparable; provides canonical/compact text I/O and a v4 random generator built on top of a thread-local std::mt19937 engine.
| using vlink::Uuid::value_type = uint8_t |
Underlying byte type used by the 16-byte payload.
|
strong |
|
strong |
UUID version inferred from the high nibble of octet 6.
| Enumerator | |
|---|---|
| kNone | Nil UUID or invalid version nibble. |
| kTimeBased | v1 time-based. |
| kDceSecurity | v2 DCE Security. |
| kNameBasedMd5 | v3 Name-based MD5. |
| kRandomBased | v4 random (produced by |
| kNameBasedSha1 | v5 Name-based SHA-1. |
|
inlineconstexprdefaultnoexcept |
Default-constructs a nil UUID (all 16 bytes zero).
|
inlineexplicitconstexprnoexcept |
Constructs from a 16-byte array.
| data | Network-order UUID payload. |
|
inlineexplicitconstexprnoexcept |
Constructs from a raw C array reference of exactly 16 bytes.
| arr | Reference to a 16-byte array. |
|
inline |
Constructs from a forward-iterator range of exactly 16 bytes.
Details.
When std::distance(first, last) is not 16 the resulting UUID is the nil value. A static_assert enforces forward-iterator capability so input-only iterators do not silently produce a misaligned UUID.
| ForwardIteratorT | Forward iterator yielding uint8_t-convertible values. |
| first | Begin iterator. |
| last | End iterator. |
|
inlineconstexprnoexcept |
Provides read-only access to the underlying 16-byte payload.
|
staticnoexcept |
Null-safe C-string overload of from_string().
| str | NUL-terminated candidate string, or nullptr. |
std::nullopt on malformed/null input.
|
staticnoexcept |
Parses a UUID literal and returns the resulting value.
Accepts the same shapes as is_valid().
| str | Candidate string. |
std::nullopt on malformed input.
|
staticnoexcept |
Generates a random v4 UUID using a thread-local seeded engine.
The engine is lazily seeded on first use from eight std::random_device samples fed through a std::seed_seq, then reused for the rest of the thread's lifetime. Sets the RFC variant and v4 version bits before returning.
|
staticnoexcept |
Generates a random v4 UUID from a caller-managed engine.
Useful for deterministic test fixtures. Sets the RFC variant and v4 version bits identically to the no-argument overload.
| engine | Caller-managed engine. |
|
inlineconstexprnoexcept |
Reports whether every byte is zero (the nil UUID).
true when the payload is all zeros.
|
staticnoexcept |
Null-safe C-string overload of is_valid().
| str | NUL-terminated candidate string, or nullptr. |
true when str is non-null and a valid UUID literal.
|
staticnoexcept |
Validates whether str is a well-formed UUID literal.
Accepts the canonical 36-character form, the 32-character compact form, and either form wrapped in an outer brace pair "{...}". Hyphen positions are not enforced: any 32 hex digits within the allowed shape pass.
| str | Candidate string. |
true when str is valid.
|
staticnoexcept |
Produces count random-device-seeded pseudo-random bytes.
Uses the same pipeline as generate_random(): std::seed_seq from eight std::random_device samples, then std::mt19937 plus std::uniform_int_distribution<uint32_t> emitting four bytes per draw. Byte extraction uses explicit shifts so the output is endian-deterministic. Returns an empty vector when count is 0 or allocation fails.
std::mt19937 engine is not a CSPRNG. Observing 624 consecutive 32-bit outputs allows the engine state to be reconstructed. Do not use this for long-term secrets; prefer a dedicated CSPRNG (for example OpenSSL RAND_bytes).| count | Number of bytes to emit. |
count pseudo-random bytes.
|
staticnoexcept |
Produces byte_count pseudo-random bytes encoded as a lowercase hex string.
Length is always byte_count * 2. The default of 16 bytes matches the 128-bit auth-token width used by the proxy handshake. Returns an empty string when byte_count is 0 or allocation fails. Same non-CSPRNG caveat as random_bytes().
| byte_count | Number of underlying bytes. |
|
inlinenoexcept |
Swaps contents with other in noexcept fashion.
| other | UUID to swap with. |
|
noexcept |
Formats the UUID as a 32-character lowercase hex string without hyphens.
|
noexcept |
Formats the UUID as the canonical 36-character lowercase hyphenated string.
|
inlineconstexprnoexcept |
Returns the variant field inferred from octet 8.
|
inlineconstexprnoexcept |
Returns the version field inferred from the high nibble of octet 6.
Inequality comparison over the 16-byte payload.
| lhs | Left operand. |
| rhs | Right operand. |
true when the payloads differ in any byte. Lexicographic less-than comparison over the 16-byte payload.
| lhs | Left operand. |
| rhs | Right operand. |
true when lhs sorts strictly before rhs.
|
friend |
Stream insertion delegating to to_string().
| ostream | Output stream. |
| id | UUID to format. |
ostream. Equality comparison over the 16-byte payload.
| lhs | Left operand. |
| rhs | Right operand. |
true when both payloads compare byte-equal.
|
staticconstexpr |
UUID payload length (16 bytes per RFC 4122).
|
staticconstexpr |
Canonical 36-character textual length: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.