blob: d7ec33a8f8cac3cbf0f1ecf0e9b86195162601c6 [file] [log] [blame]
Austin Schuh64fab802020-09-09 22:47:47 -07001#ifndef AOS_EVENTS_LOGGING_UUID_H_
2#define AOS_EVENTS_LOGGING_UUID_H_
3
4#include <array>
5#include <random>
6#include <string_view>
7
8namespace aos {
9
10// Class to generate and hold a UUID.
11class UUID {
12 public:
13 // Returns a randomly generated UUID. This is known as a UUID4.
14 static UUID Random();
15
Austin Schuh20ac95d2020-12-05 17:24:19 -080016 // Returns a uuid with all '0' characters.
Brian Silverman1f345222020-09-24 21:14:48 -070017 static UUID Zero();
18
Austin Schuh20ac95d2020-12-05 17:24:19 -080019 static UUID FromString(std::string_view);
20
21 static UUID BootUUID();
22
23 // Size of a UUID.
24 static constexpr size_t kSize = 36;
25
Austin Schuh64fab802020-09-09 22:47:47 -070026 std::string_view string_view() const {
27 return std::string_view(data_.data(), data_.size());
28 }
29
30 bool operator==(const UUID &other) const {
31 return other.string_view() == string_view();
32 }
33 bool operator!=(const UUID &other) const {
34 return other.string_view() != string_view();
35 }
36
37 private:
38 UUID() {}
39
40 // Fixed size storage for the data. Non-null terminated.
Austin Schuh20ac95d2020-12-05 17:24:19 -080041 std::array<char, kSize> data_;
Austin Schuh64fab802020-09-09 22:47:47 -070042};
43
44} // namespace aos
45
46#endif // AOS_EVENTS_LOGGING_UUID_H_