Mooncore.Util.Deflist (mooncore v0.2.5)

Copy Markdown

Converts between role lists and bitmask integers. Used for compact JWT role encoding.

How it works

Given an ordered role list ["admin", "manager", "user"]:

  • ["user"] → binary "100" → integer 4
  • ["admin", "user"] → binary "101" → integer 5
  • ["admin", "manager", "user"] → binary "111" → integer 7

The integer is then Base58-encoded for the JWT token.

Summary

Functions

Decode an integer bitmask back into a list of role strings.

Encode a list of role strings into an integer bitmask.

Functions

from_integer(number, list)

Decode an integer bitmask back into a list of role strings.

number is the bitmask integer. list is the full ordered list of possible roles.

to_integer(roles, list)

Encode a list of role strings into an integer bitmask.

roles is the full ordered list of possible roles. list is the user's active roles.