uuid: Slightly better docs on ulid

This commit is contained in:
rhy 2023-01-09 14:01:46 -03:00
parent 228620d61c
commit 04d658d601

View File

@ -29,7 +29,7 @@ function uuid.uuid4(rng)
return out return out
end end
-- Crockford's Base32 https://en.wikipedia.org/wiki/Base32 -- crockford's base32 https://en.wikipedia.org/wiki/Base32
local _encoding = { local _encoding = {
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "M", "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "M",
@ -60,6 +60,7 @@ local function _encode_time(time)
return table.concat(out) return table.concat(out)
end end
--generate the random part of an ulid
local function _encode_random(rng) local function _encode_random(rng)
local out = {} local out = {}
@ -70,7 +71,8 @@ local function _encode_random(rng)
return table.concat(out) return table.concat(out)
end end
--generate an ULID (see https://github.com/ulid/spec) --generate an ULID using this rng at this time
--see https://github.com/ulid/spec
--implementation based on https://github.com/Tieske/ulid.lua --implementation based on https://github.com/Tieske/ulid.lua
function uuid.ulid(rng, time_func) function uuid.ulid(rng, time_func)
return _encode_time() .. _encode_random() return _encode_time() .. _encode_random()