Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
quuid_p.h
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// Copyright (C) 2021 Intel Corporation.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#ifndef QUUID_P_H
6#define QUUID_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists for the convenience
13// of the QLibrary class. This header file may change from
14// version to version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include "quuid.h"
20
21#include <QtCore/qrandom.h>
22
23#include <chrono>
24
25QT_BEGIN_NAMESPACE
26
27#ifndef QT_BOOTSTRAPPED
28static inline QUuid createUuidV7_internal(
29 std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> tp)
30{
31 QUuid result;
32
33 using namespace std::chrono;
34 const nanoseconds nsecSinceEpoch = tp.time_since_epoch();
35 const auto msecSinceEpoch = floor<milliseconds>(nsecSinceEpoch);
36 const quint64 frac = (nsecSinceEpoch - msecSinceEpoch).count();
37 // Lower 48 bits of the timestamp
38 const quint64 msecs = quint64(msecSinceEpoch.count()) & 0xffffffffffff;
39 result.data1 = uint(msecs >> 16);
40 result.data2 = ushort(msecs);
41 // rand_a: use a 12-bit sub-millisecond timestamp for additional monotonicity
42 // https://datatracker.ietf.org/doc/html/rfc9562#monotonicity_counters (Method 3)
43
44 // "frac" is a number between 0 and 999,999, so the lowest 20 bits
45 // should be roughly random. Use the high 12 of those for additional
46 // monotonicity.
47 result.data3 = frac >> 8;
48 result.data3 &= 0x0FFF;
49 result.data3 |= ushort(7) << 12;
50
51 // rand_b: 62 bits of random data (64 - 2 bits for the variant)
52 const quint64 random = QRandomGenerator::system()->generate64();
53 memcpy(result.data4, &random, sizeof(quint64));
54 result.data4[0] = (result.data4[0] & 0x3F) | 0x80; // UV_DCE
55 return result;
56}
57#endif
58
59QT_END_NAMESPACE
60
61#endif // QUUID_P_H
Combined button and popup list for selecting options.
QDataStream & operator>>(QDataStream &s, QKeyCombination &combination)
QDebug operator<<(QDebug dbg, const QFileInfo &fi)
constexpr size_t qHash(const QSize &s, size_t seed=0) noexcept
Definition qsize.h:191
bool _q_fromHex(const char *&src, Integral &value)
Definition quuid.cpp:41
static char * _q_uuidToHex(const QUuid &uuid, char *dst, QUuid::StringFormat mode=QUuid::WithBraces)
Definition quuid.cpp:57
void _q_toHex(char *&dst, Integral value)
Definition quuid.cpp:25
@ MaxStringUuidLength
Definition quuid.cpp:22
static QUuid uuidFromString(QStringView text) noexcept
Definition quuid.cpp:498
static QUuid createFromName(QUuid ns, QByteArrayView baseData, QCryptographicHash::Algorithm algorithm, int version) noexcept
Definition quuid.cpp:123