PHP Classes

File: docs/base-encoding.rst

Recommend this page to a friend!
  Packages of A. B. M. Mahmudul Hasan   UID (UUID, ULID, Snowflake, Sonyflake, Nano, CUID, KSUID, XID, TBSL)   docs/base-encoding.rst   Download  
File: docs/base-encoding.rst
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: UID (UUID, ULID, Snowflake, Sonyflake, Nano, CUID, KSUID, XID, TBSL)
Generate, parse, validate unique identifiers
Author: By
Last change:
Date: 8 days ago
Size: 1,605 bytes
 

Contents

Class file image Download
Base Encoding ============= UID exposes base conversion through algorithm-specific APIs and a shared ``Infocyph\\UID\\Support\\BaseEncoder`` utility. Supported Bases --------------- - ``16``: lowercase hexadecimal alphabet - ``32``: ``0-9a-v`` alphabet - ``36``: ``0-9a-z`` alphabet - ``58``: Bitcoin-style Base58 alphabet - ``62``: ``0-9A-Za-z`` alphabet Algorithm APIs -------------- Prefer the algorithm-specific methods when converting IDs, because they validate the canonical input and restore the canonical output type: - ``UUID::toBase($uuid, $base)`` / ``UUID::fromBase($encoded, $base)`` - ``ULID::toBase($ulid, $base)`` / ``ULID::fromBase($encoded, $base)`` - ``Snowflake::toBase($id, $base)`` / ``Snowflake::fromBase($encoded, $base)`` - ``Sonyflake::toBase($id, $base)`` / ``Sonyflake::fromBase($encoded, $base)`` - ``TBSL::toBase($id, $base)`` / ``TBSL::fromBase($encoded, $base)`` .. code-block:: php <?php use Infocyph\UID\UUID; $uuid = UUID::v7(); $base58 = UUID::toBase($uuid, 58); $canonical = UUID::fromBase($base58, 58); Low-Level Encoder ----------------- ``BaseEncoder`` works with raw bytes: .. code-block:: php <?php use Infocyph\UID\Support\BaseEncoder; $bytes = random_bytes(16); $encoded = BaseEncoder::encodeBytes($bytes, 62); $decoded = BaseEncoder::decodeToBytes($encoded, 62, 16); ``decodeToBytes()`` requires the expected byte length so the decoded value can be left-padded and validated consistently. Notes ----- Alternate-base values are transport encodings. They do not replace each algorithm's canonical representation.