@@ -31,6 +31,88 @@ class FBJSRuntime;
31
31
namespace facebook {
32
32
namespace jsi {
33
33
34
+ // / UUID version 1 implementation. This should be constructed with constant
35
+ // / arguments to identify fixed UUIDs.
36
+ class JSI_EXPORT UUID {
37
+ public:
38
+ // Construct from raw parts
39
+ constexpr UUID (
40
+ uint32_t timeLow,
41
+ uint16_t timeMid,
42
+ uint16_t timeHighAndVersion,
43
+ uint16_t variantAndClockSeq,
44
+ uint64_t node)
45
+ : high(
46
+ ((uint64_t )(timeLow) << 32) | ((uint64_t )(timeMid) << 16) |
47
+ ((uint64_t )(timeHighAndVersion))),
48
+ low(((uint64_t )(variantAndClockSeq) << 48) | node) {}
49
+
50
+ // Default constructor (zero UUID)
51
+ constexpr UUID () : high(0 ), low(0 ) {}
52
+
53
+ constexpr UUID (const UUID&) = default;
54
+ constexpr UUID& operator =(const UUID&) = default ;
55
+
56
+ constexpr bool operator ==(const UUID& other) const {
57
+ return high == other.high && low == other.low ;
58
+ }
59
+ constexpr bool operator !=(const UUID& other) const {
60
+ return !(*this == other);
61
+ }
62
+
63
+ // Ordering (for std::map, sorting, etc.)
64
+ constexpr bool operator <(const UUID& other) const {
65
+ return (high < other.high ) || (high == other.high && low < other.low );
66
+ }
67
+
68
+ // Hash support for UUID (for unordered_map compatibility)
69
+ struct Hash {
70
+ std::size_t operator ()(const UUID& uuid) const noexcept {
71
+ return std::hash<uint64_t >{}(uuid.high ) ^
72
+ (std::hash<uint64_t >{}(uuid.low ) << 1 );
73
+ }
74
+ };
75
+
76
+ // UUID format: 8-4-4-4-12
77
+ std::string toString () const {
78
+ std::string buffer (36 , ' ' );
79
+ std::snprintf (
80
+ buffer.data (),
81
+ buffer.size () + 1 ,
82
+ " %08x-%04x-%04x-%04x-%012llx" ,
83
+ getTimeLow (),
84
+ getTimeMid (),
85
+ getTimeHighAndVersion (),
86
+ getVariantAndClockSeq (),
87
+ (unsigned long long )getNode ());
88
+ return buffer;
89
+ }
90
+
91
+ constexpr uint32_t getTimeLow () const {
92
+ return (uint32_t )(high >> 32 );
93
+ }
94
+
95
+ constexpr uint16_t getTimeMid () const {
96
+ return (uint16_t )(high >> 16 );
97
+ }
98
+
99
+ constexpr uint16_t getTimeHighAndVersion () const {
100
+ return (uint16_t )high;
101
+ }
102
+
103
+ constexpr uint16_t getVariantAndClockSeq () const {
104
+ return (uint16_t )(low >> 48 );
105
+ }
106
+
107
+ constexpr uint64_t getNode () const {
108
+ return low & 0xFFFFFFFFFFFF ;
109
+ }
110
+
111
+ private:
112
+ uint64_t high;
113
+ uint64_t low;
114
+ };
115
+
34
116
// / Base class for buffers of data or bytecode that need to be passed to the
35
117
// / runtime. The buffer is expected to be fully immutable, so the result of
36
118
// / size(), data(), and the contents of the pointer returned by data() must not
0 commit comments