aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/uuid.zig
diff options
context:
space:
mode:
authorGravatar Ai Hoshino <ambiguous404@gmail.com> 2023-07-09 22:20:52 +0800
committerGravatar GitHub <noreply@github.com> 2023-07-09 07:20:52 -0700
commit565d1689e9f2c1f6b657f14b07fa9b95e50a5a56 (patch)
tree8534cb81892929de7846b9cdc2056ce68d02e5a9 /src/bun.js/uuid.zig
parent59570fe237f91dd04ce8f37779902cffa4352010 (diff)
downloadbun-565d1689e9f2c1f6b657f14b07fa9b95e50a5a56.tar.gz
bun-565d1689e9f2c1f6b657f14b07fa9b95e50a5a56.tar.zst
bun-565d1689e9f2c1f6b657f14b07fa9b95e50a5a56.zip
fix metadata bits of uuid (`randomUUID()`) (#3583)
* fix uuid version Close: https://github.com/oven-sh/bun/issues/3575 * add unittest * small fix * avoid unnecessary copying
Diffstat (limited to 'src/bun.js/uuid.zig')
-rw-r--r--src/bun.js/uuid.zig10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/bun.js/uuid.zig b/src/bun.js/uuid.zig
index e8bdff661..e38ed567f 100644
--- a/src/bun.js/uuid.zig
+++ b/src/bun.js/uuid.zig
@@ -18,6 +18,16 @@ pub fn init() UUID {
uuid.bytes[6] = (uuid.bytes[6] & 0x0f) | 0x40;
// Variant 1
uuid.bytes[8] = (uuid.bytes[8] & 0x3f) | 0x80;
+
+ return uuid;
+}
+
+pub fn initWith(bytes: *const [16]u8) UUID {
+ var uuid = UUID{ .bytes = bytes.* };
+
+ uuid.bytes[6] = (uuid.bytes[6] & 0x0f) | 0x40;
+ uuid.bytes[8] = (uuid.bytes[8] & 0x3f) | 0x80;
+
return uuid;
}