Serialize

August 2, 2026 ยท View on GitHub

Glyph Ribbon

Serialize

Encode a glyph as a portable string. Decode back to a Glyph.

Serialize(value)

Accepts Glyph, GlyphSignature, or GlyphRecord.

import { Create, Serialize } from "@koda.oss/glyph";

const record = Create("some text");

Serialize(record.glyph); // g1.<payload>
Serialize(record);       // r1.<version>.<createdAt>.<payload>
Serialize({
  version: record.version,
  glyph: record.glyph,
});                      // s1.<version>.<payload>

String formats

KindPatternExample prefix
Glyphg1.<base64url>g1.
Signatures1.<version>.<base64url>s1.1.
Recordr1.<version>.<createdAt>.<base64url>r1.1.1710...

Payload = raw little-endian Uint32Array bytes, base64url-encoded.

Deserialize(string)

Always returns a Glyph. Metadata on records and signatures is not restored.

import { Create, Serialize, Deserialize, Compare } from "@koda.oss/glyph";

const record = Create("some text");
const glyph = Deserialize(Serialize(record));

Compare(record, glyph); // similarity: 1

Errors

ConditionResult
Malformed stringThrows
Unsupported format versionThrows
Invalid base64 or bad byte lengthThrows

Use cases

CaseAction
Database cacheStore encoded glyph, skip source text
Wire transferSend compact fingerprint string
LoggingPrint signature without hex dumps

Related links ranked by Glyph.