//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(); } an/encoding-fix Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
path: root/src/node-fallbacks/buffer.js (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2023-07-19fix `make headers`Gravatar Dylan Conway 1-7/+15
2023-07-20Better error for workspace dependency not found (#3678)Gravatar Jarred Sumner 2-21/+85
2023-07-18Fix crash in postMessage that repro'd after ~100,000 messagesGravatar Jarred Sumner 6-21/+57
2023-07-18more progress on fixing gc issueGravatar Jarred Sumner 6-61/+162
2023-07-18add padding bytesGravatar Dylan Conway 1-1/+1
2023-07-18feature(constants) add constants/node:constants module and tests(prisma) use ...Gravatar Ciro Spaciari 16-20/+529
2023-07-18patch checkServerIdentity (#3671)Gravatar Ciro Spaciari 3-3/+9
2023-07-18Update workers.mdGravatar Jarred Sumner 1-2/+2
2023-07-18[jest] execute lifecycle hooks on empty blocks (#3663)Gravatar Alex Lam S.L 2-19/+79
2023-07-18ClarifyGravatar Jarred Sumner 1-0/+2
2023-07-18Fixes #3669Gravatar Jarred Sumner 4-13/+35
2023-07-18zig upgrade (#3667)Gravatar Dylan Conway 154-4894/+4857
2023-07-17Enable postgres prisma testGravatar Jarred Sumner 1-1/+1
2023-07-17Emit writeBarrier in `napi_module_register`Gravatar Jarred Sumner 1-6/+14
2023-07-17Fix potential crash in process.dlopen()Gravatar Jarred Sumner 2-5/+27
2023-07-17Implement `process.{stdout, stderr}.{columns, rows, getWindowSize}`Gravatar Jarred Sumner 4-32/+108
2023-07-17[tls] General compatibility improvements (#3596)Gravatar Ciro Spaciari 23-298/+2907
2023-07-17package json `main` field extension order (#3664)Gravatar Dylan Conway 3-3/+96
2023-07-17[install] handle duplicated workspace declarations gracefully (#3662)Gravatar Alex Lam S.L 2-6/+197
2023-07-17Clean up worker docsGravatar Colin McDonnell 1-65/+69
2023-07-17Tweak test docsGravatar Colin McDonnell 2-4/+3
2023-07-17workaround `readable-stream` compatibility (#3626)Gravatar Alex Lam S.L 3-4/+5
2023-07-17Fix flaky process testGravatar Jarred SUmner 1-2/+2
2023-07-17Fix test with incorrect textGravatar Jarred Sumner 1-3/+3
2023-07-17Fix incorrect nameGravatar Jarred Sumner 2-4/+4
2023-07-17Fix speculative crashes in console.log(formData) and console.log(headers)Gravatar Jarred Sumner 2-30/+24
2023-07-17Fix crash in console.log(urlSearchParams) on a URLSearchParams object with a ...Gravatar Jarred Sumner 2-4/+99
2023-07-17Fix memory leak in `await new Response(latin1String).arrayBuffer()` and `awai...Gravatar Jarred Sumner 16-102/+361
2023-07-1720% faster `deserialize` (#3655)Gravatar Jarred Sumner 2-12/+197
2023-07-16Document `--smol`Gravatar Jarred Sumner 1-70/+59
2023-07-16Add `--smol` to bunfigGravatar Jarred Sumner 1-0/+12
2023-07-16Document serialize/deserializeGravatar Jarred Sumner 1-0/+14