VLink  2.0.0
A high-performance communication middleware
vlink::Uuid类 参考final

Value-typed RFC 4122 UUID. 更多...

#include <uuid.h>

vlink::Uuid 的协作图:

Public 类型

enum class  Variant : uint8_t { kNcs = 0 , kRfc = 1 , kMicrosoft = 2 , kReserved = 3 }
 UUID variant inferred from the high bits of octet 8. 更多...
 
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. 更多...
 
using value_type = uint8_t
 Underlying byte type used by the 16-byte payload. 更多...
 

Public 成员函数

constexpr Uuid () noexcept
 Default-constructs a nil UUID (all 16 bytes zero). 更多...
 
constexpr Uuid (const std::array< value_type, kByteSize > &data) noexcept
 Constructs from a 16-byte array. 更多...
 
constexpr Uuid (const value_type(&arr)[kByteSize]) noexcept
 Constructs from a raw C array reference of exactly 16 bytes. 更多...
 
template<typename ForwardIteratorT >
 Uuid (ForwardIteratorT first, ForwardIteratorT last)
 Constructs from a forward-iterator range of exactly 16 bytes. 更多...
 
constexpr Variant variant () const noexcept
 Returns the variant field inferred from octet 8. 更多...
 
constexpr Version version () const noexcept
 Returns the version field inferred from the high nibble of octet 6. 更多...
 
constexpr bool is_nil () const noexcept
 Reports whether every byte is zero (the nil UUID). 更多...
 
constexpr const std::array< value_type, kByteSize > & bytes () const noexcept
 Provides read-only access to the underlying 16-byte payload. 更多...
 
std::string to_string () const noexcept
 Formats the UUID as the canonical 36-character lowercase hyphenated string. 更多...
 
std::string to_compact_string () const noexcept
 Formats the UUID as a 32-character lowercase hex string without hyphens. 更多...
 
void swap (Uuid &other) noexcept
 Swaps contents with other in noexcept fashion. 更多...
 

静态 Public 成员函数

static bool is_valid (std::string_view str) noexcept
 Validates whether str is a well-formed UUID literal. 更多...
 
static bool is_valid (const char *str) noexcept
 Null-safe C-string overload of is_valid(). 更多...
 
static std::optional< Uuidfrom_string (std::string_view str) noexcept
 Parses a UUID literal and returns the resulting value. 更多...
 
static std::optional< Uuidfrom_string (const char *str) noexcept
 Null-safe C-string overload of from_string(). 更多...
 
static Uuid generate_random () noexcept
 Generates a random v4 UUID using a thread-local seeded engine. 更多...
 
static Uuid generate_random (std::mt19937 &engine) noexcept
 Generates a random v4 UUID from a caller-managed engine. 更多...
 
static std::vector< value_typerandom_bytes (size_t count) noexcept
 Produces count random-device-seeded pseudo-random bytes. 更多...
 
static std::string random_hex (size_t byte_count=16U) noexcept
 Produces byte_count pseudo-random bytes encoded as a lowercase hex string. 更多...
 

静态 Public 属性

static constexpr size_t kByteSize = 16U
 UUID payload length (16 bytes per RFC 4122). 更多...
 
static constexpr size_t kStringSize = 36U
 Canonical 36-character textual length: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx. 更多...
 

友元

bool operator== (const Uuid &lhs, const Uuid &rhs) noexcept
 Equality comparison over the 16-byte payload. 更多...
 
bool operator!= (const Uuid &lhs, const Uuid &rhs) noexcept
 Inequality comparison over the 16-byte payload. 更多...
 
bool operator< (const Uuid &lhs, const Uuid &rhs) noexcept
 Lexicographic less-than comparison over the 16-byte payload. 更多...
 
VLINK_EXPORT friend std::ostream & operator<< (std::ostream &ostream, const Uuid &id)
 Stream insertion delegating to to_string(). 更多...
 

详细描述

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.

成员类型定义说明

◆ value_type

using vlink::Uuid::value_type = uint8_t

Underlying byte type used by the 16-byte payload.

成员枚举类型说明

◆ Variant

enum vlink::Uuid::Variant : uint8_t
strong

UUID variant inferred from the high bits of octet 8.

枚举值
kNcs 

NCS backward compatibility (0xxx).

kRfc 

RFC 4122 / DCE 1.1 (10xx).

kMicrosoft 

Microsoft GUID (110x).

kReserved 

Reserved for future use (111x).

◆ Version

enum vlink::Uuid::Version : uint8_t
strong

UUID version inferred from the high nibble of octet 6.

枚举值
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 generate_random).

kNameBasedSha1 

v5 Name-based SHA-1.

构造及析构函数说明

◆ Uuid() [1/4]

constexpr vlink::Uuid::Uuid ( )
inlineconstexprdefaultnoexcept

Default-constructs a nil UUID (all 16 bytes zero).

◆ Uuid() [2/4]

constexpr vlink::Uuid::Uuid ( const std::array< value_type, kByteSize > &  data)
inlineexplicitconstexprnoexcept

Constructs from a 16-byte array.

参数
dataNetwork-order UUID payload.

◆ Uuid() [3/4]

constexpr vlink::Uuid::Uuid ( const value_type(&)  arr[kByteSize])
inlineexplicitconstexprnoexcept

Constructs from a raw C array reference of exactly 16 bytes.

参数
arrReference to a 16-byte array.

◆ Uuid() [4/4]

template<typename ForwardIteratorT >
vlink::Uuid::Uuid ( ForwardIteratorT  first,
ForwardIteratorT  last 
)
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.

模板参数
ForwardIteratorTForward iterator yielding uint8_t-convertible values.
参数
firstBegin iterator.
lastEnd iterator.

成员函数说明

◆ bytes()

constexpr const std::array< Uuid::value_type, Uuid::kByteSize > & vlink::Uuid::bytes ( ) const
inlineconstexprnoexcept

Provides read-only access to the underlying 16-byte payload.

返回
Const reference to the byte array.

◆ from_string() [1/2]

static std::optional<Uuid> vlink::Uuid::from_string ( const char *  str)
staticnoexcept

Null-safe C-string overload of from_string().

参数
strNUL-terminated candidate string, or nullptr.
返回
Parsed UUID, or std::nullopt on malformed/null input.

◆ from_string() [2/2]

static std::optional<Uuid> vlink::Uuid::from_string ( std::string_view  str)
staticnoexcept

Parses a UUID literal and returns the resulting value.

Accepts the same shapes as is_valid().

参数
strCandidate string.
返回
Parsed UUID, or std::nullopt on malformed input.

◆ generate_random() [1/2]

static Uuid vlink::Uuid::generate_random ( )
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.

返回
Fresh v4 UUID.

◆ generate_random() [2/2]

static Uuid vlink::Uuid::generate_random ( std::mt19937 &  engine)
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.

参数
engineCaller-managed engine.
返回
Fresh v4 UUID.

◆ is_nil()

constexpr bool vlink::Uuid::is_nil ( ) const
inlineconstexprnoexcept

Reports whether every byte is zero (the nil UUID).

返回
true when the payload is all zeros.

◆ is_valid() [1/2]

static bool vlink::Uuid::is_valid ( const char *  str)
staticnoexcept

Null-safe C-string overload of is_valid().

参数
strNUL-terminated candidate string, or nullptr.
返回
true when str is non-null and a valid UUID literal.

◆ is_valid() [2/2]

static bool vlink::Uuid::is_valid ( std::string_view  str)
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.

参数
strCandidate string.
返回
true when str is valid.

◆ random_bytes()

static std::vector<value_type> vlink::Uuid::random_bytes ( size_t  count)
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.

警告
The underlying 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).
参数
countNumber of bytes to emit.
返回
Vector containing exactly count pseudo-random bytes.

◆ random_hex()

static std::string vlink::Uuid::random_hex ( size_t  byte_count = 16U)
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_countNumber of underlying bytes.
返回
Lowercase hex string.

◆ swap()

void vlink::Uuid::swap ( Uuid other)
inlinenoexcept

Swaps contents with other in noexcept fashion.

参数
otherUUID to swap with.

◆ to_compact_string()

std::string vlink::Uuid::to_compact_string ( ) const
noexcept

Formats the UUID as a 32-character lowercase hex string without hyphens.

返回
Compact text representation.

◆ to_string()

std::string vlink::Uuid::to_string ( ) const
noexcept

Formats the UUID as the canonical 36-character lowercase hyphenated string.

返回
Canonical text representation.

◆ variant()

constexpr Uuid::Variant vlink::Uuid::variant ( ) const
inlineconstexprnoexcept

Returns the variant field inferred from octet 8.

返回
Variant enumerator.

◆ version()

constexpr Uuid::Version vlink::Uuid::version ( ) const
inlineconstexprnoexcept

Returns the version field inferred from the high nibble of octet 6.

返回
Version enumerator.

友元及相关函数文档

◆ operator!=

bool operator!= ( const Uuid lhs,
const Uuid rhs 
)
friend

Inequality comparison over the 16-byte payload.

参数
lhsLeft operand.
rhsRight operand.
返回
true when the payloads differ in any byte.

◆ operator<

bool operator< ( const Uuid lhs,
const Uuid rhs 
)
friend

Lexicographic less-than comparison over the 16-byte payload.

参数
lhsLeft operand.
rhsRight operand.
返回
true when lhs sorts strictly before rhs.

◆ operator<<

VLINK_EXPORT friend std::ostream& operator<< ( std::ostream &  ostream,
const Uuid id 
)
friend

Stream insertion delegating to to_string().

参数
ostreamOutput stream.
idUUID to format.
返回
Reference to ostream.

◆ operator==

bool operator== ( const Uuid lhs,
const Uuid rhs 
)
friend

Equality comparison over the 16-byte payload.

参数
lhsLeft operand.
rhsRight operand.
返回
true when both payloads compare byte-equal.

类成员变量说明

◆ kByteSize

constexpr size_t vlink::Uuid::kByteSize = 16U
staticconstexpr

UUID payload length (16 bytes per RFC 4122).

◆ kStringSize

constexpr size_t vlink::Uuid::kStringSize = 36U
staticconstexpr

Canonical 36-character textual length: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.


该类的文档由以下文件生成: