Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for raw bytes, UUID and int128 forms #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

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