World
Reference
Resource IDs

WorldResourceId.sol constants

Git Source (opens in a new tab)

NAMESPACE_BYTES

uint256 constant NAMESPACE_BYTES = 14;

NAMESPACE_BITS

uint256 constant NAMESPACE_BITS = 14 * 8;

NAME_BITS

uint256 constant NAME_BITS = 16 * 8;

NAMESPACE_MASK

bytes32 constant NAMESPACE_MASK = bytes32(~bytes14("")) >> (TYPE_BITS);

WorldResourceIdInstance

Git Source (opens in a new tab)

A library for handling instances of World Resource IDs.

Functions

getNamespace

Get the namespace from a resource ID.

function getNamespace(ResourceId resourceId) internal pure returns (bytes14);

Parameters

NameTypeDescription
resourceIdResourceIdThe resource ID.

Returns

NameTypeDescription
<none>bytes14A 14-byte namespace.

getNamespaceId

Get the namespace ID from a resource ID.

function getNamespaceId(ResourceId resourceId) internal pure returns (ResourceId);

Parameters

NameTypeDescription
resourceIdResourceIdThe resource ID.

Returns

NameTypeDescription
<none>ResourceIdA 32-byte namespace resource ID.

getName

Get the name from a resource ID.

function getName(ResourceId resourceId) internal pure returns (bytes16);

Parameters

NameTypeDescription
resourceIdResourceIdThe resource ID.

Returns

NameTypeDescription
<none>bytes16A 16-byte name.

toString

Convert a resource ID to a string.

function toString(ResourceId resourceId) internal pure returns (string memory);

Parameters

NameTypeDescription
resourceIdResourceIdThe resource ID.

Returns

NameTypeDescription
<none>stringA string representation of the resource ID.

WorldResourceIdLib

Git Source (opens in a new tab)

A library for handling World Resource ID encoding and decoding.

Functions

encode

Encode a resource ID.

function encode(bytes2 typeId, bytes14 namespace, bytes16 name) internal pure returns (ResourceId);

Parameters

NameTypeDescription
typeIdbytes2The resource type ID.
namespacebytes14The namespace of the resource.
namebytes16The name of the resource.

Returns

NameTypeDescription
<none>ResourceIdA 32-byte resource ID.

encodeNamespace

Usage Sample

Encode a namespace to resource ID.

function encodeNamespace(bytes14 namespace) internal pure returns (ResourceId);

Parameters

NameTypeDescription
namespacebytes14The namespace to be encoded.

Returns

NameTypeDescription
<none>ResourceIdA 32-byte resource ID with the namespace encoded.

toTrimmedString

Convert a padded string to a trimmed string.

function toTrimmedString(bytes16 paddedString) internal pure returns (string memory);

Parameters

NameTypeDescription
paddedStringbytes16The input string with potential padding.

Returns

NameTypeDescription
<none>stringA string without trailing null ASCII characters.

worldResourceTypes.sol constants

Git Source (opens in a new tab)

RESOURCE_NAMESPACE

Constants used to work with world resource types.

bytes2 constant RESOURCE_NAMESPACE = "ns";

RESOURCE_SYSTEM

bytes2 constant RESOURCE_SYSTEM = "sy";

MASK_RESOURCE_NAMESPACE

bytes32 constant MASK_RESOURCE_NAMESPACE = bytes32(RESOURCE_NAMESPACE);