-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuuid.h
61 lines (48 loc) · 1.04 KB
/
uuid.h
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 _CEPH_UUID_H
#define _CEPH_UUID_H
/*
* Thin C++ wrapper around libuuid.
*/
#include "encoding.h"
#include <ostream>
extern "C" {
#include <uuid/uuid.h>
#include <unistd.h>
}
struct uuid_d {
uuid_t uuid;
uuid_d() {
memset(&uuid, 0, sizeof(uuid));
}
bool is_zero() const {
return uuid_is_null(uuid);
}
void generate_random() {
uuid_generate(uuid);
}
bool parse(const char *s) {
return uuid_parse(s, uuid) == 0;
}
void print(char *s) {
return uuid_unparse(uuid, s);
}
void encode(bufferlist& bl) const {
::encode_raw(uuid, bl);
}
void decode(bufferlist::iterator& p) const {
::decode_raw(uuid, p);
}
};
WRITE_CLASS_ENCODER(uuid_d)
inline std::ostream& operator<<(std::ostream& out, const uuid_d& u) {
char b[37];
uuid_unparse(u.uuid, b);
return out << b;
}
inline bool operator==(const uuid_d& l, const uuid_d& r) {
return uuid_compare(l.uuid, r.uuid) == 0;
}
inline bool operator!=(const uuid_d& l, const uuid_d& r) {
return uuid_compare(l.uuid, r.uuid) != 0;
}
#endif