//https://github.com/dmgk/zig-uuid const std = @import("std"); const crypto = std.crypto; const fmt = std.fmt; const testing = std.testing; const bun = @import("root").bun; pub const Error = error{InvalidUUID}; const UUID = @This(); bytes: [16]u8 = undefined, pub fn init() UUID { var uuid = UUID{ .bytes = undefined }; bun.rand(&uuid.bytes); // Version 4 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; } // Indices in the UUID string representation for each byte. const encoded_pos = [16]u8{ 0, 2, 4, 6, 9, 11, 14, 16, 19, 21, 24, 26, 28, 30, 32, 34 }; // Hex to nibble mapping. const hex_to_nibble = [256]u8{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, }; pub fn format( self: UUID, comptime layout: []const u8, options: fmt.FormatOptions, writer: anytype, ) !void { _ = options; // currently unused if (comptime layout.len != 0 and layout[0] != 's') @compileError("Unsupported format specifier for UUID type: '" ++ layout ++ "'."); var buf: [36]u8 = undefined; self.print(&buf); try fmt.format(writer, "{s}", .{buf}); } pub fn print( self: UUID, buf: *[36]u8, ) void { const hex = "0123456789abcdef"; const bytes = self.bytes; buf[8] = '-'; buf[13] = '-'; buf[18] = '-'; buf[23] = '-'; inline for (encoded_pos, 0..) |i, j| { buf[comptime i + 0] = hex[bytes[j] >> 4]; buf[comptime i + 1] = hex[bytes[j] & 0x0f]; } } pub fn parse(buf: []const u8) Error!UUID { var uuid = UUID{ .bytes = undefined }; if (buf.len != 36 or buf[8] != '-' or buf[13] != '-' or buf[18] != '-' or buf[23] != '-') return Error.InvalidUUID; inline for (encoded_pos, 0..) |i, j| { const hi = hex_to_nibble[buf[i + 0]]; const lo = hex_to_nibble[buf[i + 1]]; if (hi == 0xff or lo == 0xff) { return Error.InvalidUUID; } uuid.bytes[j] = hi << 4 | lo; } return uuid; } // Zero UUID pub const zero: UUID = .{ .bytes = .{0} ** 16 }; // Convenience function to return a new v4 UUID. pub fn newV4() UUID { return UUID.init(); } ing-fix Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
path: root/bench/snippets/deep-equals.js (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2023-08-20Fixes #1675 (#4230)Gravatar Jarred Sumner 8-70/+297
2023-08-20Implement `--inspect-brk` (#4222)Gravatar Jarred Sumner 17-41/+101
2023-08-20Fix test failures from 3a9a6c63a (#4231)Gravatar Jarred Sumner 4-32/+34
2023-08-20Fix(bundler): use different alias mappings based on the target. (#4163)Gravatar Ai Hoshino 8-18/+90
2023-08-19Update BunDebugger.cppGravatar Jarred Sumner 1-1/+3
2023-08-19Introduce `bun --inspect-wait`Gravatar Jarred Sumner 3-19/+47
2023-08-19misc non-posix fixesGravatar Jarred Sumner 2-3/+3
2023-08-19Update lockfile.mdGravatar Jarred Sumner 1-1/+8
2023-08-19Update lockfile.mdGravatar Jarred Sumner 1-4/+4
2023-08-19Update lockfile.mdGravatar Jarred Sumner 1-1/+29
2023-08-19Update Dockerfile-distroless (#4210)Gravatar Omar 1-0/+1
2023-08-19Fix symbol visibilityGravatar Jarred Sumner 1-0/+1
2023-08-19[napi] Implement `node_api_create_syntax_error`, `node_api_symbol_for`, `nod...Gravatar Jarred Sumner 5-1/+70
2023-08-19Fix crash impacting sharp & resvg (#4221)Gravatar Jarred Sumner 5-73/+73
2023-08-19Fixes #172 (#4220)Gravatar Jarred Sumner 7-9/+87
2023-08-19Add inline sourcemaps when `--inspect` is enabled (#4213)Gravatar Jarred Sumner 3-3/+64
2023-08-19tty `ReadStream`, `WriteStream`, and readline rawmode (#4179)Gravatar Dylan Conway 23-722/+821
2023-08-18Fix make headers (again)Gravatar Jarred Sumner 1-0/+2