|
CX Framework
Cross-platform C utility framework
|
Data Structures | |
| struct | SUID |
| 128-bit sortable unique identifier More... | |
Typedefs | |
| typedef struct SUID | SUID |
| 128-bit sortable unique identifier | |
Functions | |
| bool | suidEq (const SUID *a, const SUID *b) |
| int | suidCmp (const SUID *a, const SUID *b) |
| void | suidGen (SUID *out, uint8 idtype) |
| void | suidGenPrivate (SUID *out, uint8 idtype) |
| void | suidEncode (string *out, const SUID *id) |
| void | suidEncodeBytes (_Out_writes_all_(26) uint8 buf[26], const SUID *id) |
| bool | suidDecode (SUID *out, strref str) |
| bool | suidDecodeBytes (SUID *out, _In_reads_(26) const char buf[26]) |
SUID (Sortable Unique ID) is a 128-bit identifier loosely based on Alizain Feerasta's ULID. It provides lexicographically sortable unique identifiers with the following structure:
SUIDs are designed to be:
Example usage:
See https://github.com/ulid/spec for ULID specification details.
int suidCmp(const SUID *a, const SUID *b);
Compare two SUIDs for sorting order. SUIDs are compared lexicographically, with earlier timestamps sorting first.
| bool suidDecode | ( | SUID * | out, |
| strref | str | ||
| ) |
Decode a SUID from a string.
Decodes a 26-character base32 encoded string back into a SUID structure. The decoder is case-insensitive and accepts the Crockford base32 alphabet. Ambiguous characters (i/l become 1, o becomes 0) are automatically normalized.
| out | Output SUID structure to populate |
| str | String containing encoded SUID (must be at least 26 characters) |
| bool suidDecodeBytes | ( | SUID * | out, |
| _In_reads_(26) const char | buf[26] | ||
| ) |
Decode a SUID from a byte buffer.
Similar to suidDecode() but reads from a 26-byte buffer instead of a string object. The buffer must contain exactly 26 bytes of valid base32 encoded data.
| void suidEncode | ( | string * | out, |
| const SUID * | id | ||
| ) |
Encode a SUID into a string.
Encodes the SUID as a 26-character lowercase base32 string using the Crockford base32 alphabet (0-9, a-z excluding i, l, o, u). The encoding is lexicographically sortable - earlier SUIDs will sort before later ones when compared as strings.
| out | String to receive the encoded result (will be cleared first) |
| id | SUID to encode |
| void suidEncodeBytes | ( | _Out_writes_all_(26) uint8 | buf[26], |
| const SUID * | id | ||
| ) |
Encode a SUID into a byte buffer.
Similar to suidEncode() but writes the 26-character encoded result directly to a byte buffer instead of a string object. The buffer must be at least 26 bytes long.
| buf | Output buffer for 26-byte encoded result |
| id | SUID to encode |
bool suidEq(const SUID *a, const SUID *b);
Compare two SUIDs for equality.
| void suidGen | ( | SUID * | out, |
| uint8 | idtype | ||
| ) |
Generate a unique SUID using the system's host ID.
Generates a new SUID with the current timestamp and the machine's host ID. The host ID is derived from hardware identifiers (MAC address, disk serial, etc.) to ensure uniqueness across different machines. Multiple SUIDs generated within the same millisecond will have monotonically increasing sequence numbers.
| out | Output SUID structure to populate |
| idtype | Application-specific identifier (stored in high 8 bits) |
| void suidGenPrivate | ( | SUID * | out, |
| uint8 | idtype | ||
| ) |
Generate a unique SUID using a random host ID.
Similar to suidGen(), but uses a randomly generated host ID instead of the system's hardware-derived host ID. This is useful for privacy-sensitive applications where you don't want to leak hardware identifiers, or for temporary/ephemeral identifiers.
| out | Output SUID structure to populate |
| idtype | Application-specific identifier (stored in high 8 bits) |