12#if qStroika_Platform_MacOS
14 : GUID{FromRFC9562Bytes (as_bytes (span<const unsigned char, 16>{src}))}
17#elif qStroika_Platform_Windows
18 constexpr GUID::GUID (const ::GUID& src) noexcept
23 for (
size_t i = 0; i < std::size (Data4); ++i) {
24 Data4[i] = src.Data4[i];
31 auto b = [&] (
size_t i) {
return static_cast<uint32_t
> (bytes[i]); };
33 r.Data1 = (b (0) << 24) | (b (1) << 16) | (b (2) << 8) | b (3);
34 r.Data2 =
static_cast<uint16_t
> ((b (4) << 8) | b (5));
35 r.Data3 =
static_cast<uint16_t
> ((b (6) << 8) | b (7));
36 for (
size_t i = 0; i < std::size (r.Data4); ++i) {
37 r.Data4[i] =
static_cast<uint8_t
> (bytes[8 + i]);
44 r[0] =
static_cast<byte> (Data1 >> 24);
45 r[1] =
static_cast<byte> (Data1 >> 16);
46 r[2] =
static_cast<byte> (Data1 >> 8);
47 r[3] =
static_cast<byte> (Data1);
48 r[4] =
static_cast<byte> (Data2 >> 8);
49 r[5] =
static_cast<byte> (Data2);
50 r[6] =
static_cast<byte> (Data3 >> 8);
51 r[7] =
static_cast<byte> (Data3);
52 for (
size_t i = 0; i < std::size (Data4); ++i) {
53 r[8 + i] =
static_cast<byte> (Data4[i]);
58 template <Characters::IConvertibleToString STRISH_TYPE>
59 inline string AsAscii (STRISH_TYPE&& src)
63 if constexpr (same_as<STRISH_TYPE, Characters::String>) {
64 return src.AsASCII ();
66 if constexpr (IAnyOf<STRISH_TYPE, const char*, string_view, string>) {
67 return forward<STRISH_TYPE> (src);
72 template <Characters::IConvertibleToString STRISH_TYPE>
74 : GUID{mk_ (Private_::AsAscii (src))}
79 ::memcpy (
this, src.data (), 16);
83 return reinterpret_cast<const byte*
> (
this);
87 return reinterpret_cast<const byte*
> (
this) + 16;
89 constexpr size_t GUID::size () const noexcept
95 return reinterpret_cast<const uint8_t*
> (
this);
97 template <IAnyOf<Characters::String, std::
string, Memory::BLOB, array<
byte, 16>, array<u
int8_t, 16>> T>
100 if constexpr (same_as<T, Characters::String>) {
102 Verify (::snprintf (buf, std::size (buf),
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", Data1, Data2, Data3, Data4[0],
103 Data4[1], Data4[2], Data4[3], Data4[4], Data4[5], Data4[6], Data4[7]) > 0);
106 else if constexpr (same_as<T, std::string>) {
108 Verify (::snprintf (buf, std::size (buf),
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", Data1, Data2, Data3, Data4[0],
109 Data4[1], Data4[2], Data4[3], Data4[4], Data4[5], Data4[6], Data4[7]) > 0);
112 else if constexpr (same_as<T, array<byte, 16>> or same_as<T, array<uint8_t, 16>>) {
113 return *
reinterpret_cast<const T*
> (
this);
115 else if constexpr (same_as<T, Memory::BLOB>) {
116 return T{begin (), end ()};
127template <
class FmtContext>
128inline typename FmtContext::iterator qStroika_Foundation_Characters_FMT_PREFIX_::formatter<Stroika::Foundation::Common::GUID, wchar_t>::format (
133template <
class FmtContext>
134inline typename FmtContext::iterator
136 FmtContext& ctx)
const
138 return inherited::format (s.
As<std::string> (), ctx);
String is like std::u32string, except it is much easier to use, often much more space efficient,...
nonvirtual T AsASCII() const
constexpr array< byte, 16 > AsRFC9562Bytes() const noexcept
Its 16 bytes in RFC 9562's order - the order its text is written in (.
constexpr GUID() noexcept=default
static constexpr GUID FromRFC9562Bytes(span< const byte, 16 > bytes) noexcept
From its 16 bytes in RFC 9562's order: network byte order, the order its text is written in - as a uu...
nonvirtual const byte * end() const noexcept
nonvirtual const byte * begin() const noexcept
nonvirtual const uint8_t * data() const noexcept