CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
suid.h
Go to the documentation of this file.
1#pragma once
2
5
39
40#include <cx/platform/base.h>
41#include <cx/platform/cpp.h>
42#include <cx/stype/stype.h>
43
44CX_C_BEGIN
45
47typedef struct SUID {
48 uint64 high;
49 uint64 low;
51
58_meta_inline bool suidEq(_In_ const SUID* a, _In_ const SUID* b)
59{
60 return (a->high == b->high) && (a->low == b->low);
61}
62
70_meta_inline int suidCmp(_In_ const SUID* a, _In_ const SUID* b)
71{
72 // can't just subtract since it might overflow even a signed int64
73 if (a->high > b->high)
74 return 1;
75 if (a->high < b->high)
76 return -1;
77 if (a->low > b->low)
78 return 1;
79 if (a->low > b->low)
80 return -1;
81 return 0;
82}
83
93void suidGen(_Out_ SUID* out, uint8 idtype);
94
104void suidGenPrivate(_Out_ SUID* out, uint8 idtype);
105
114void suidEncode(_Inout_ string* out, _In_ const SUID* id);
115
124void suidEncodeBytes(_Out_writes_all_(26) uint8 buf[26], _In_ const SUID* id);
125
126#define _suidRetAnno _Success_(return) _Check_return_
127
137_suidRetAnno bool suidDecode(_Out_ SUID* out, _In_ strref str);
138
147_suidRetAnno bool suidDecodeBytes(_Out_ SUID* out, _In_reads_(26) const char buf[26]);
148
150
151CX_C_END
Compiler and platform detection macros.
void suidEncode(string *out, const SUID *id)
void suidGen(SUID *out, uint8 idtype)
void suidEncodeBytes(_Out_writes_all_(26) uint8 buf[26], const SUID *id)
int suidCmp(const SUID *a, const SUID *b)
Definition suid.h:70
bool suidDecodeBytes(SUID *out, _In_reads_(26) const char buf[26])
bool suidEq(const SUID *a, const SUID *b)
Definition suid.h:58
void suidGenPrivate(SUID *out, uint8 idtype)
bool suidDecode(SUID *out, strref str)
128-bit sortable unique identifier
Definition suid.h:47
uint64 low
Low 64 bits: host ID low (32) + random/sequence (32)
Definition suid.h:49
uint64 high
High 64 bits: type (8) + timestamp (48) + host ID high (8)
Definition suid.h:48
Runtime type system and type descriptor infrastructure.