-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathuuid.h
More file actions
61 lines (47 loc) · 1.09 KB
/
uuid.h
File metadata and controls
61 lines (47 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef BASE_UUID_H
#define BASE_UUID_H
// modify from https://github.com/ddnet/ddnet
#ifdef __cplusplus
extern "C" {
#endif
enum
{
UUID_MAXSTRSIZE = 37, // 12345678-0123-5678-0123-567890123456
UUID_INVALID = -2,
UUID_UNKNOWN = -1,
OFFSET_UUID = 1 << 16,
};
typedef struct
{
unsigned char m_aData[16];
} Uuid;
extern const Uuid UUID_ZEROED;
Uuid random_uuid();
Uuid calculate_uuid(const char *name);
// The buffer length should be at least UUID_MAXSTRSIZE.
void format_uuid(Uuid uuid, char *buffer, int size);
// Returns nonzero on failure.
int parse_uuid(Uuid *uuid, const char *buffer);
int uuid_comp(Uuid uuid1, Uuid uuid2);
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
inline bool operator==(const Uuid &that, const Uuid &other)
{
return uuid_comp(that, other) == 0;
}
inline bool operator!=(const Uuid &that, const Uuid &other)
{
return !(that == other);
}
inline bool operator<(const Uuid &that, const Uuid &other)
{
return uuid_comp(that, other) < 0;
}
inline bool operator<=(const Uuid &that, const Uuid &other)
{
return uuid_comp(that, other) < 1;
}
#endif
#endif // BASE_UUID_H