BRL-CAD
|
Routines to generate and work with universally unique identifiers. More...
Files | |
file | uuid.h |
Macros | |
#define | STATIC_ARRAY(x) (x) |
Functions | |
int | bu_uuid_create (uint8_t uuid[STATIC_ARRAY(16)], size_t nbytes, const uint8_t *bytes, const uint8_t namespace_uuid[STATIC_ARRAY(16)]) |
int | bu_uuid_compare (const void *uuid_left, const void *uuid_right) |
int | bu_uuid_encode (const uint8_t uuid[STATIC_ARRAY(16)], uint8_t cp[STATIC_ARRAY(37)]) |
int | bu_uuid_decode (const char *cp, uint8_t uuid[STATIC_ARRAY(16)]) |
Routines to generate and work with universally unique identifiers.
int bu_uuid_create | ( | uint8_t | uuid[STATIC_ARRAY(16)], |
size_t | nbytes, | ||
const uint8_t * | bytes, | ||
const uint8_t | namespace_uuid[STATIC_ARRAY(16)] | ||
) |
Create a UUID (a 128-bit identifier) that conforms with RFC4122, version 4 or 5, in big endian network order. Version 4 UUIDs are suitable for a random object identifier (with 122 bits of random entropy). Providing a byte array and namespace will create a (SHA1-based) version 5 UUID suitable for repeatable identifier hashing.
int bu_uuid_compare | ( | const void * | uuid_left, |
const void * | uuid_right | ||
) |
This is a convenience UUID comparison routine compatible with stdlib sorting functions (e.g., bu_sort()). The function expects both left and right UUIDs to be uint8_t[16] arrays.
Returns:
<0 if a < b 0 if a == b >0 if a > b
int bu_uuid_encode | ( | const uint8_t | uuid[STATIC_ARRAY(16)], |
uint8_t | cp[STATIC_ARRAY(37)] | ||
) |
Converts a UUID into a string representation of the following style: "00112233-4455-6677-8899-AABBCCDDEEFF"
The caller must provide a 36-byte + 1-byte (for nul) array to write the result and will need to manually convert this into a string or add braces as desired by the calling application. For example:
int bu_uuid_decode | ( | const char * | cp, |
uint8_t | uuid[STATIC_ARRAY(16)] | ||
) |
Converts a string (e.g., "{12B01234-f543-39d9-BFE0-0098765432F1}") into a UUID. The input string must be nul-terminated. Brackets are optional and are ignored. Hyphens can appear anywhere or be missing. The hex digits can be any mixture of upper or lower case.