1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#pragma once
4
5#include <iomanip>
6#include <ostream>
7#include <string.h>
8
9struct UUID
10{
11 explicit UUID(const unsigned char full[16]) : full{}
12 {
13 memcpy(dest: this->full, src: full, size: 16);
14 }
15
16 friend std::ostream &operator<<(std::ostream &os, const UUID &guid)
17 {
18 const auto flags = os.flags();
19 os << std::uppercase << std::hex;
20
21 for (size_t i : { 3, 2, 1, 0, /**/ 5, 4, /**/ 7, 6, /**/ 8, 9, /**/ 10, 11, 12, 13, 14, 15 }) // little endian
22 {
23 if (i == 5 || i == 7 || i == 8 || i == 10)
24 os << '-';
25
26 os << std::setw(2) << std::setfill('0') << (int) guid.full[i];
27 }
28
29 return os << std::resetiosflags(mask: flags);
30 }
31
32 private:
33 unsigned char full[16];
34};
35