forked from protohaus/ESP_UUID
-
Notifications
You must be signed in to change notification settings - Fork 0
/
esp_uuid.h
98 lines (80 loc) · 2.1 KB
/
esp_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#pragma once
#include <Arduino.h>
#include <ArduinoJson.h>
#include <array>
namespace esp_uuid {
/**
* Holds a UUID and allows it to be used as a key in STL containers. It can be
* constructed from a string or creates a new UUID. Allows printing the UUID
* through the Printable interface (Serial and co.). See isValid for the
* currently supported UUID types.
*/
class UUID : public Printable {
public:
/**
* Create a new UUID
*/
UUID();
/**
* Construct the UUID from the given string
*/
UUID(const char* uuid);
/**
* Construct the UUID from the given string
*/
UUID(const String& uuid);
/**
* Construct the UUID from the given JsonVariantConst as a string
*/
UUID(const JsonVariantConst& uuid);
virtual ~UUID() = default;
bool operator<(const UUID& rhs) const;
bool operator>(const UUID& rhs) const;
bool operator<=(const UUID& rhs) const;
bool operator>=(const UUID& rhs) const;
bool operator==(const UUID& rhs) const;
bool operator!=(const UUID& rhs) const;
/**
* Prints the UUID with the printable interface
*
* \param p Object to print the UUID to
* \return The number of bytes printed
*/
size_t printTo(Print& p) const final;
/**
* Creates a string representation of the UUID
*/
String toString() const;
/**
* Tries to change to the UUID string provided
*
* \see isValid() for the validity constraints
*
* \param uuid The UUID in string form (Hex 8-4-4-4-12)
* \return True if it is a valid UUID string
*/
bool fromString(const char* uuid);
/**
* Tries to change to the UUID string provided
*
* \see fromString(const char*)
*
* \param uuid The UUID in string form (Hex 8-4-4-4-12)
* \return True if it is a valid UUID string
*/
bool fromString(const String& uuid);
/**
* Clears the UUID and makes it invalid
*/
void clear();
/**
* Checks if the UUID is valid (currently only V4)
*
* \return True if it is valid
*/
bool isValid() const;
private:
/// The internal binary buffer holding the UUID
std::array<uint8_t, 16> buffer_;
};
} // namespace utils