Reads canonical hex, urn:uuid:hex, or {hex}; e.g. id, err := parse_uuid(text).
Fixed maximum input size is 45 bytes; parsing never allocates.
#import "Extensions/Uuid";
UUIDs as defined by RFC 9562: parsing, formatting, comparing and generating versions 3, 4, 5 and 7. A Uuid is 16 bytes with no owned memory, stored in network byte order.
#import "Extensions/Uuid";
id, error := parse_uuid("123e4567-e89b-12d3-a456-426614174000");
assert(error.kind == .NONE && uuid_version(id) == 1);
assert(format_uuid(id) == "123e4567-e89b-12d3-a456-426614174000");Procedures#
Appends lowercase canonical text; e.g. append_uuid(*builder, UUID_NIL).
Returns owned canonical text; e.g. text := format_uuid(id); defer free(text).
Reads the version nibble even for reserved variants; e.g. uuid_version(UUID_NIL) == 0.
Classifies the variant prefix; e.g. uuid_variant(UUID_NIL) == .NCS.
Network-byte lexicographic order (-1/0/1); e.g. uuid_compare(UUID_NIL, UUID_MAX) == -1.
Value equality; e.g. Map.Map(Uuid, int, uuid_hash, uuid_equal).
Value equality operator; e.g. id == UUID_NIL.
Hashes all 16 bytes; e.g. Map.Map(Uuid, int, uuid_hash, uuid_equal).
System CSPRNG v4; e.g. id, err := uuid_v4(); failure returns nil.
Process-monotonic v7, RFC method 1; e.g. id, err := uuid_v7().
A 12-bit counter follows the timestamp; exhaustion returns an error without waiting.
Json with=uuid_json encoder; e.g. id: Uuid; @json(with=uuid_json) with aliases in the struct.
Json with=uuid_json decoder; e.g. uuid_json_decode :: U.uuid_json_decode in the struct.
Types#
A 128-bit universally unique identifier.
Uuid :: struct {
bytes: [16] u8;
}Why parsing or generating a UUID failed.
Uuid_Error_Kind :: enum u8 {
NONE;
LENGTH;
SYNTAX;
RANDOM;
CLOCK;
EXHAUSTED;
}Messages are static; offsets are zero-based bytes. No error needs freeing.
Uuid_Error :: struct {
kind: Uuid_Error_Kind;
message: string;
offset: int;
}The layout family a UUID belongs to, from its top bits. RFC 9562 UUIDs are .RFC.
Uuid_Variant :: enum u8 {
NCS;
RFC;
MICROSOFT;
FUTURE;
}Constants#
The all-zero UUID.
The all-ones UUID.