Skip to main content

Module codepoint

Module codepoint 

Source
Expand description

Unicode transport encoding — embeds an emoji’s blocks in a plain String that survives text-only channels (chat, MCP tool results).

§Scheme (self-describing envelope, one per block)

[TAG char]  [2 × plane-15 length chars]  [ceil(len/2) × plane-16 data chars]
  • Tag char: U+E0061 + block-type index (TAG glyphs U+E0061..U+E006A for the 10 block types). Marks the start of a block and names its type.
  • Length: payload length (bytes) as two 12-bit chunks, big-endian, each stored in plane 15 (U+F0000..U+FFFFF, the Supplementary Private Use Area-A): U+F0000 + block-type index × 4096 + chunk. Plane 15 is split into 16 sub-ranges of 4096; the block type occupies sub-range index, so length chars are type-checked against the tag char.
  • Data: the JSON payload bytes, two bytes (big-endian u16) per codepoint in plane 16 (U+100000..U+10FFFF, Supplementary PUA-B): U+100000 + u16. Odd payloads are zero-padded; the length field trims the pad.

Max payload is 2^24 - 1 bytes (24-bit length). All codepoints used are valid Unicode scalar values (no surrogates), so the output is a well-formed UTF-8/UTF-16 string on any platform. Decoders skip any non-marker text, so envelopes can ride inside ordinary prose.

Constants§

MAX_PAYLOAD
Maximum payload size (24-bit length field).
PLANE15_BASE
Base of plane 15 (Supplementary PUA-A).
PLANE16_BASE
Base of plane 16 (Supplementary PUA-B).
SUBRANGE_SIZE
Plane-15 sub-range size (16 sub-ranges of 4096 cover the plane).
TAG_CHAR_BASE
Base of the TAG block-type marker chars (U+E0061 + index).

Functions§

decode_blocks
Decodes all block envelopes found in s. Non-marker chars are skipped, so the emoji may be embedded in arbitrary text. Any started envelope that is malformed (bad length chars, truncated data, bad JSON) is an error — never a panic.
encode_blocks
Encodes blocks to the Unicode envelope string (concatenated per block).
tag_char
The tag char marking the start of a block of type tag.
tag_from_char
Inverse of tag_char; None for any other char.