Skip to content

Conversation

@colinbendell
Copy link

@colinbendell colinbendell commented May 24, 2024

A ULID is nothing more than an uInt128 with encoding convenience. This PR enables the conversion to / from UUID forms to a ULID. Likewise enables support of the BigNum (int128) decimal form.

The following are all the same:

ULID.new(1777022035688232904178850488005232350)
ULID.new("\x01V=\xF3c\x00\xD2\x19\\C\xB6\xCA\xFF\x95\x06\xDE")
ULID.new("01563df3-6300-d219-5c43-b6caff9506de")
ULID.new("01ARYZ6RR0T8CNRGXPSBZSA1PY")

Likewise:

token = ULID.new("01ARYZ6RR0T8CNRGXPSBZSA1PY")
token.ulid    # "01ARYZ6RR0T8CNRGXPSBZSA1PY"
token.to_uuid # "01563df3-6300-d219-5c43-b6caff9506de"
token.to_i    # 1777022035688232904178850488005232350
token.bytes   # "\x01V=\xF3c\x00\xD2\x19\\C\xB6\xCA\xFF\x95\x06\xDE"

# 01ARYZ6RR0T8CNRGXPSBZSA1PY

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant