diff options
| author | Feoramund <161657516+Feoramund@users.noreply.github.com> | 2024-06-21 12:04:45 -0400 |
|---|---|---|
| committer | Feoramund <161657516+Feoramund@users.noreply.github.com> | 2024-06-22 18:21:31 -0400 |
| commit | 4cfbd83b10ff17b6c7ca4b01dac249bfbea0da84 (patch) | |
| tree | f18dc3b825e1317ef4dcdfd5c6e2a190b2dda589 /core/encoding/uuid/reading.odin | |
| parent | fee81985b4b7ade3cddc7038360efcd32555d879 (diff) | |
Add version 7 UUID generation
Diffstat (limited to 'core/encoding/uuid/reading.odin')
| -rw-r--r-- | core/encoding/uuid/reading.odin | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/core/encoding/uuid/reading.odin b/core/encoding/uuid/reading.odin index 0c0274e53..c72f5791e 100644 --- a/core/encoding/uuid/reading.odin +++ b/core/encoding/uuid/reading.odin @@ -95,3 +95,34 @@ variant :: proc "contextless" (id: Identifier) -> (variant: Variant_Type) #no_bo return .Unknown } } + +/* +Get the timestamp of a version 7 UUID. + +Inputs: +- id: The identifier. + +Returns: +- timestamp: The timestamp, in milliseconds since the UNIX epoch. +*/ +time_v7 :: proc "contextless" (id: Identifier) -> (timestamp: u64) { + time_bits := transmute(u128be)id & VERSION_7_TIME_MASK + return cast(u64)(time_bits >> VERSION_7_TIME_SHIFT) +} + +/* +Get the 12-bit counter value of a version 7 UUID. + +The UUID must have been generated with a counter, otherwise this procedure will +return random bits. + +Inputs: +- id: The identifier. + +Returns: +- counter: The 12-bit counter value. +*/ +counter_v7 :: proc "contextless" (id: Identifier) -> (counter: u16) { + counter_bits := transmute(u128be)id & VERSION_7_COUNTER_MASK + return cast(u16)(counter_bits >> VERSION_7_COUNTER_SHIFT) +} |