Skip to content

Commit dc84fd7

Browse files
committed
v7Timestamp: demystifying bitwise magic
1 parent de3931f commit dc84fd7

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

std/uuid.d

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -565,12 +565,15 @@ public struct UUID
565565
throw new UUIDParsingException("The UUID is not of version" ~
566566
" v7 therefore no timestamp exist", 0);
567567
}
568-
ulong milli = (cast(ulong)(this.data[0]) << 40) |
569-
(cast(ulong)(this.data[1]) << 32) |
570-
(cast(ulong)(this.data[2]) << 24) |
571-
(cast(ulong)(this.data[3]) << 16) |
572-
(cast(ulong)(this.data[4]) << 8) |
573-
(cast(ulong)(this.data[5]));
568+
569+
import std.bitmanip : bigEndianToNative;
570+
571+
ubyte[8] tmp = void;
572+
tmp[0 .. 2] = 0;
573+
tmp[2 .. 8] = data[0 .. 6];
574+
575+
ulong milli = tmp.bigEndianToNative!ulong;
576+
574577
return SysTime(DateTime(1970, 1, 1), UTC()) + dur!"msecs"(milli);
575578
}
576579

0 commit comments

Comments
 (0)