A small set of routines for manipulating the base 36 IDs used in GCF block headers.
int gcf_base36_decode |
( |
uint32_t |
code, |
|
|
char * |
id |
|
) |
| |
Decode a base36 integer into a string.
- Parameters
-
| code | The integer value to decode. |
[out] | id | Buffer into which the string (null-terminated) is written. |
- Return values
-
0 | on success. |
-1 | on error (and see gcf_errstr). |
Decodes the base-36 encoded string in code, storing the result in id. The buffer id must have at least 7 bytes free (6 for the decoded ID, and one for the terminating null). The operation can only fail if the topmost bit of code is set (since the ID is defined as being 31-bit).
int gcf_base36_encode |
( |
const char * |
id, |
|
|
uint32_t * |
code |
|
) |
| |
Encode a string to a base36 integer.
- Parameters
-
| id | The string to encode. |
[out] | code | The encoded base 36 integer. |
- Return values
-
0 | on success. |
-1 | on error (and see gcf_errstr). |
Encodes the string id into a base 36 integer, which is stored in code. The operation will fail if the string is too long or contains characters not in the set A-Z or 0-9. The result will only ever use 31 bits. The operation is not case sensitive. If the string cannot be encoded, -1 will be returned, nothing will be written to code.