Skip to content

Commit de3931f

Browse files
denizzzkathewilsonator
authored andcommitted
UUIDv7: fix for big-endian
1 parent 491e4cc commit de3931f

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

std/uuid.d

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -325,15 +325,14 @@ public struct UUID
325325
*/
326326
@safe pure this(SysTime timestamp, ubyte[10] random = generateV7RandomData())
327327
{
328-
ulong epoch = (timestamp - SysTime.fromUnixTime(0)).total!"msecs";
329-
this.data[6 .. $] = random[];
330-
331-
this.data[0] = cast(ubyte)((epoch >> 40) & 0xFF);
332-
this.data[1] = cast(ubyte)((epoch >> 32) & 0xFF);
333-
this.data[2] = cast(ubyte)((epoch >> 24) & 0xFF);
334-
this.data[3] = cast(ubyte)((epoch >> 16) & 0xFF);
335-
this.data[4] = cast(ubyte)((epoch >> 8) & 0xFF);
336-
this.data[5] = cast(ubyte)(epoch & 0xFF);
328+
import std.bitmanip : nativeToBigEndian;
329+
330+
ubyte[8] epoch = (timestamp - SysTime.fromUnixTime(0))
331+
.total!"msecs"
332+
.nativeToBigEndian;
333+
334+
this.data[0 .. 6] = epoch[2 .. 8];
335+
this.data[6 .. $] = random;
337336

338337
// version and variant
339338
this.data[6] = (this.data[6] & 0x0F) | 0x70;

0 commit comments

Comments
 (0)