blob: 0387a4b5c2909c27af118a47655755605120f4ba [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
Brian Silverman1f345222020-09-24 21:14:48 -070016 static UUID Zero();
17
Austin Schuh64fab802020-09-09 22:47:47 -070018 std::string_view string_view() const {
19 return std::string_view(data_.data(), data_.size());
20 }
21
22 bool operator==(const UUID &other) const {
23 return other.string_view() == string_view();
24 }
25 bool operator!=(const UUID &other) const {
26 return other.string_view() != string_view();
27 }
28
29 private:
30 UUID() {}
31
32 // Fixed size storage for the data. Non-null terminated.
33 std::array<char, 36> data_;
34};
35
36} // namespace aos
37
38#endif // AOS_EVENTS_LOGGING_UUID_H_