EtcPal  HEAD (unstable)
ETC Platform Abstraction Layer (EtcPal)
View other versions:
uuid (UUIDs)

Overview

C++ utilities for the uuid (UUIDs) module.

Provides a class Uuid for generating and inspecting Universal Unique Identifiers (UUIDs).

Default-constructed Uuid instances will be all-zeros ("null"):

EXPECT_TRUE(uuid.IsNull());
A wrapper class for the EtcPal UUID type.
Definition: uuid.h:88
bool IsNull() const noexcept
Check if a UUID is null (all 0's).
Definition: uuid.h:174

To generate a specific type of UUID, use the static generator functions:

auto uuid1 = etcpal::Uuid::V1(); // Generate a V1 (MAC + time based) UUID.
auto uuid3 = etcpal::Uuid::V3(namespace_uuid, name_data, name_size); // Generate a V3 (name-based, MD5) UUID.
auto uuid4 = etcpal::Uuid::V4(); // Generate a V4 (random) UUID.k
auto uuid5 = etcpal::Uuid::V5(namespace_uuid, name_data, name_size); // Generate a V5 (name-based, SHA-1)
auto uuid_os = etcpal::Uuid::OsPreferred(); // Generate the UUID type preferred by the underlying OS
auto uuid_dev = etcpal::Uuid::Device("My Device Type", dev_mac_address, 0); // Generate a UUID representing an embedded device
static Uuid V1() noexcept
Generate and return a Version 1 UUID.
Definition: uuid.h:233
static Uuid Device(const std::string &device_str, const uint8_t *mac_addr, uint32_t uuid_num) noexcept
Generate and return a Device UUID.
Definition: uuid.h:324
static Uuid V4() noexcept
Generate and return a Version 4 UUID.
Definition: uuid.h:273
static Uuid V3(const Uuid &ns, const void *name, size_t name_len) noexcept
Generate and return a Version 3 UUID.
Definition: uuid.h:243
static Uuid OsPreferred() noexcept
Generate and return a UUID of the version preferred by the underlying OS.
Definition: uuid.h:314
static Uuid V5(const Uuid &ns, const void *name, size_t name_len) noexcept
Generate and return a Version 5 UUID.
Definition: uuid.h:283

Note: Uuid::V3(), Uuid::V5() and Uuid::Device() are guaranteed to be implemented on all systems. Uuid::V1(), Uuid::V4() and Uuid::OsPreferred() may not be available on embedded devices. If not implemented, these functions will return a null Uuid. For more information, see the uuid (UUIDs) module.

You can also convert UUIDs to and from strings:

auto uuid = etcpal::Uuid::FromString("1b0c096d-9baa-476d-866d-4e0cad18f5a4");
std::string uuid_str = uuid.ToString();
std::string ToString() const
Convert the UUID to a string representation formatted per RFC 4122.
Definition: uuid.h:165
static Uuid FromString(const char *uuid_str) noexcept
Create a UUID from a string representation.
Definition: uuid.h:216

Data Structures

class  Uuid
 A wrapper class for the EtcPal UUID type. More...
 

UUID Relational Operators

bool operator== (const EtcPalUuid &c_uuid, const Uuid &uuid) noexcept
 
bool operator!= (const EtcPalUuid &c_uuid, const Uuid &uuid) noexcept
 
bool operator== (const Uuid &uuid, const EtcPalUuid &c_uuid) noexcept
 
bool operator!= (const Uuid &uuid, const EtcPalUuid &c_uuid) noexcept
 
bool operator== (const Uuid &a, const Uuid &b) noexcept
 
bool operator!= (const Uuid &a, const Uuid &b) noexcept
 
bool operator< (const Uuid &a, const Uuid &b) noexcept
 
bool operator> (const Uuid &a, const Uuid &b) noexcept
 
bool operator<= (const Uuid &a, const Uuid &b) noexcept
 
bool operator>= (const Uuid &a, const Uuid &b) noexcept