UUID

UUID — v4 (random) and v5 (namespace) UUID generation

Functions

Types and Values

Description

Functions

nk_uuid_generate ()

void
nk_uuid_generate (NkUuid *uuid);

Generates a v4 (random) UUID.

Parameters

uuid

an NkUuid.

[out caller-allocates]

nk_uuid_parse ()

gboolean
nk_uuid_parse (NkUuid *uuid,
               const gchar *string);

Parses an UUID stirng.

Parameters

uuid

an NkUuid.

[out caller-allocates]

string

a string containing an UUID in the xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx format

 

Returns

TRUE if parsing succeeded, FALSE otherwise


nk_uuid_from_name ()

void
nk_uuid_from_name (NkUuid *uuid,
                   const gchar *name,
                   gssize length);

Generates a v5 (namespace) UUID.

uuid must contains the namespace UUID and will be updated to the new UUID.

Parameters

uuid

an NkUuid.

[inout]

name

an arbritrary name

 

length

the length of name . If length < 0,

 

Types and Values

NK_UUID_LENGTH

#define NK_UUID_LENGTH 16

NK_UUID_FORMATTED_LENGTH

#define NK_UUID_FORMATTED_LENGTH 36

NkUuid

typedef struct {
    guchar data[NK_UUID_LENGTH];
    gchar string[NK_UUID_FORMATTED_LENGTH + 1];
} NkUuid;

Members

guchar data[NK_UUID_LENGTH];

the UUID has raw bytes

 

gchar string[NK_UUID_FORMATTED_LENGTH + 1];

the UUID as a string using the xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx format

 

NK_UUID_INIT

#define NK_UUID_INIT { .data = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, .string = "00000000-0000-0000-0000-000000000000" }

You can use this macro to initialize an NkUuid structure:

1
NkUuid uuid = NK_UUID_INIT;