hyperuuid 0.0.1-aarch64-linux → 0.1.0-aarch64-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +14 -6
- data/lib/hyperuuid/native/linux-arm64/libhyperuuid.so +0 -0
- data/lib/hyperuuid/native/linux-x64/libhyperuuid.so +0 -0
- data/lib/hyperuuid/native/osx-arm64/libhyperuuid.dylib +0 -0
- data/lib/hyperuuid/native/osx-x64/libhyperuuid.dylib +0 -0
- data/lib/hyperuuid/native/win-arm64/hyperuuid.dll +0 -0
- data/lib/hyperuuid/native/win-x64/hyperuuid.dll +0 -0
- data/lib/hyperuuid/uuid.rb +8 -2
- data/lib/hyperuuid.rb +26 -15
- data/lib/hyperuuid_native.so +0 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2892b5a876b4e3cad50f46aad3f4a778f89b6d72e4c523b6c711979c6c87ef30
|
|
4
|
+
data.tar.gz: 61ca11315cb9a92e2221dfa9a752eb83ce9c8c276b4dcf292bf5ce425c66fc55
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a8e44ec99f418bf148a9611952c64872d933ca2786a760cbb228cfe118c1635a87d7b13d0c2c491b14d0a7f22d68dad482c0f2ef33e73cc952bd2b7ff66e8eda
|
|
7
|
+
data.tar.gz: 59e0a033d956900a43f010765a00a3edd79def7863c29b01e9cfbbe8c45339e72afe4dec9c544db26057359011a76b5cc22ac2a22bcae7f4f51bf0ca4f201c67
|
data/README.md
CHANGED
|
@@ -23,6 +23,7 @@ id3 = HyperUuid.new_v6
|
|
|
23
23
|
id4 = HyperUuid.new_v7
|
|
24
24
|
|
|
25
25
|
id4.timestamp # recover the embedded UTC Time
|
|
26
|
+
id4.timestamp(raise_on_mismatch: false) # nil instead of raising if id4 isn't v6/v7
|
|
26
27
|
id4.to_sql_order # byte order SQL Server's uniqueidentifier needs to sort by creation order
|
|
27
28
|
|
|
28
29
|
# One native call, one random-bytes fetch, one counter reservation for the whole batch:
|
|
@@ -32,7 +33,9 @@ batch = HyperUuid.new_v7_batch(1000)
|
|
|
32
33
|
Returns `HyperUuid::Uuid`, a minimal value object (`#bytes`, `#to_s`, `#version`, `#variant`,
|
|
33
34
|
comparable/hashable) — this gem has no runtime dependency on the `uuid` gem.
|
|
34
35
|
`HyperUuid::Namespaces::DNS`/`URL`/`OID`/`X500` are RFC 9562 Section 6.6's well-known
|
|
35
|
-
namespaces. `#timestamp` recovers the embedded UTC `Time` from a version 6 or 7 UUID
|
|
36
|
+
namespaces. `#timestamp` recovers the embedded UTC `Time` from a version 6 or 7 UUID; pass
|
|
37
|
+
`raise_on_mismatch: false` to get `nil` back for any other version instead of raising.
|
|
38
|
+
`.new_v6`/`.new_v7` also accept a `Time` directly in place of a raw millisecond count.
|
|
36
39
|
`#to_sql_order`/`#from_sql_order` convert a version 6 or 7 UUID to and from the byte order SQL
|
|
37
40
|
Server's `uniqueidentifier` needs on the wire to sort by creation order (`#to_sql_order`
|
|
38
41
|
dispatches on the UUID's own version, matching `#timestamp`'s convention) — computed once in
|
|
@@ -90,10 +93,15 @@ The batch multiplier shrank from 11x to ~3.8x for the best reason available: the
|
|
|
90
93
|
|
|
91
94
|
## Install
|
|
92
95
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
```sh
|
|
97
|
+
gem install hyperuuid
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Published to [RubyGems.org](https://rubygems.org/gems/hyperuuid) as real precompiled
|
|
101
|
+
"platform gems" — `bundle`/`gem install` auto-selects the matching one for
|
|
102
|
+
linux-x64/arm64 or osx-x64/arm64 (the compiled Magnus native extension, `backend: :native`),
|
|
103
|
+
falling back automatically to the universal `ruby`-platform gem (pure Fiddle, zero compile,
|
|
104
|
+
bundles all 6 platforms' native libs) everywhere else — Windows included, since Magnus
|
|
105
|
+
doesn't target it. No extra configuration needed either way.
|
|
98
106
|
|
|
99
107
|
See [the repo root README](../README.md) for the full RFC 9562 coverage table and the state of every other language binding.
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
data/lib/hyperuuid/uuid.rb
CHANGED
|
@@ -52,12 +52,18 @@ module HyperUuid
|
|
|
52
52
|
# when `version` is 6 or 7 — the RFC 9562 bit layout doesn't distinguish "not a time-based
|
|
53
53
|
# UUID" from "time-based UUID with a very early timestamp", so the caller is responsible
|
|
54
54
|
# for checking `version` first if that matters.
|
|
55
|
-
|
|
55
|
+
#
|
|
56
|
+
# Raises by default for any other version; pass `raise_on_mismatch: false` to get `nil`
|
|
57
|
+
# back instead — for a caller that doesn't already know (or want to separately check)
|
|
58
|
+
# whether this UUID is time-based.
|
|
59
|
+
def timestamp(raise_on_mismatch: true)
|
|
56
60
|
millis =
|
|
57
61
|
case version
|
|
58
62
|
when 6 then Runtime.v6_unix_millis(bytes)
|
|
59
63
|
when 7 then Runtime.v7_unix_millis(bytes)
|
|
60
|
-
else
|
|
64
|
+
else
|
|
65
|
+
raise ArgumentError, "timestamp is only defined for version 6 or 7 UUIDs, got version #{version}" if raise_on_mismatch
|
|
66
|
+
return nil
|
|
61
67
|
end
|
|
62
68
|
Time.at(millis / 1000, millis % 1000, :millisecond).utc
|
|
63
69
|
end
|
data/lib/hyperuuid.rb
CHANGED
|
@@ -33,38 +33,49 @@ module HyperUuid
|
|
|
33
33
|
Uuid.new(Runtime.new_v5(namespace.bytes, name_bytes))
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
+
# Converts +value+ to a Unix-epoch millisecond integer: +nil+ becomes the current time, a
|
|
37
|
+
# +Time+ is converted exactly (via its own Rational seconds, avoiding float rounding), and
|
|
38
|
+
# anything else (an Integer millisecond count) passes through unchanged. Shared by every
|
|
39
|
+
# `new_v6`/`new_v7`/batch door below so a caller can pass either a `Time` or a raw
|
|
40
|
+
# millisecond count interchangeably.
|
|
41
|
+
private_class_method def self.unix_millis_from(value)
|
|
42
|
+
case value
|
|
43
|
+
when nil then Process.clock_gettime(Process::CLOCK_REALTIME, :millisecond)
|
|
44
|
+
when Time then (value.to_r * 1000).to_i
|
|
45
|
+
else value
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
36
49
|
# Creates a time-sortable UUID version 6 (RFC 9562 §5.6), a field-compatible reordering of
|
|
37
50
|
# version 1 for better sort/index locality. Defaults to the current time; pass an explicit
|
|
38
|
-
# Unix-epoch millisecond
|
|
39
|
-
# are randomly generated on every call — unlike version 7, there is no monotonic
|
|
40
|
-
# calls within the same millisecond are not guaranteed to sort in creation order.
|
|
51
|
+
# `Time` or Unix-epoch millisecond integer to embed a specific time instead. `clock_seq` and
|
|
52
|
+
# `node` are randomly generated on every call — unlike version 7, there is no monotonic
|
|
53
|
+
# counter, so calls within the same millisecond are not guaranteed to sort in creation order.
|
|
41
54
|
def self.new_v6(unix_millis = nil)
|
|
42
|
-
|
|
43
|
-
Uuid.new(Runtime.new_v6(unix_millis))
|
|
55
|
+
Uuid.new(Runtime.new_v6(unix_millis_from(unix_millis)))
|
|
44
56
|
end
|
|
45
57
|
|
|
46
58
|
# Creates `count` time-sortable version 6 UUIDs sharing one timestamp capture — one FFI call
|
|
47
|
-
# and one random-bytes fetch instead of `count` of each. Defaults to the current time
|
|
59
|
+
# and one random-bytes fetch instead of `count` of each. Defaults to the current time; pass
|
|
60
|
+
# an explicit `Time` or Unix-epoch millisecond integer to embed a specific time instead.
|
|
48
61
|
def self.new_v6_batch(count, unix_millis = nil)
|
|
49
|
-
|
|
50
|
-
bytes = Runtime.new_v6_batch(count, unix_millis)
|
|
62
|
+
bytes = Runtime.new_v6_batch(count, unix_millis_from(unix_millis))
|
|
51
63
|
Array.new(count) { |i| Uuid.new(bytes[i * 16, 16]) }
|
|
52
64
|
end
|
|
53
65
|
|
|
54
66
|
# Creates a time-sortable UUID version 7 (RFC 9562 §6.2). Defaults to the current time; pass
|
|
55
|
-
# an explicit Unix-epoch millisecond
|
|
56
|
-
# specific time instead.
|
|
67
|
+
# an explicit `Time` or Unix-epoch millisecond integer (non-negative, fitting in 48 bits) to
|
|
68
|
+
# embed a specific time instead.
|
|
57
69
|
def self.new_v7(unix_millis = nil)
|
|
58
|
-
|
|
59
|
-
Uuid.new(Runtime.new_v7(unix_millis))
|
|
70
|
+
Uuid.new(Runtime.new_v7(unix_millis_from(unix_millis)))
|
|
60
71
|
end
|
|
61
72
|
|
|
62
73
|
# Creates `count` time-sortable version 7 UUIDs sharing one timestamp capture and one
|
|
63
74
|
# contiguous block of the monotonic counter — one FFI call and one random-bytes fetch
|
|
64
|
-
# instead of `count` of each. Defaults to the current time
|
|
75
|
+
# instead of `count` of each. Defaults to the current time; pass an explicit `Time` or
|
|
76
|
+
# Unix-epoch millisecond integer to embed a specific time instead.
|
|
65
77
|
def self.new_v7_batch(count, unix_millis = nil)
|
|
66
|
-
|
|
67
|
-
bytes = Runtime.new_v7_batch(count, unix_millis)
|
|
78
|
+
bytes = Runtime.new_v7_batch(count, unix_millis_from(unix_millis))
|
|
68
79
|
Array.new(count) { |i| Uuid.new(bytes[i * 16, 16]) }
|
|
69
80
|
end
|
|
70
81
|
end
|
data/lib/hyperuuid_native.so
CHANGED
|
Binary file
|