@@ -23,15 +23,12 @@ keys.
2323
2424## Overview
2525
26- KEncode provides three standalone entry points:
27-
28- 1 . ** ByteEncoding** text codecs: Base62, Base36, Base64, and Base85 encoders
29- for raw binary data.
30- 2 . ** PackedFormat** : A binary format serializer that supports nested objects,
31- lists, and maps. It uses bitsets for booleans and nullability to minimize
32- overhead.
33- 3 . ** EncodedFormat** : A string format serializer that wraps the above to produce
34- small deterministic string identifiers.
26+ KEncode has three standalone entry points. ByteEncoding is a set of text codecs
27+ (Base62, Base36, Base64, Base85) for raw binary data. PackedFormat is a
28+ kotlinx.serialization BinaryFormat that produces compact byte payloads for
29+ Kotlin classes, including nested objects, lists, and maps. EncodedFormat layers
30+ a text codec and optional payload transforms over a binary format to produce
31+ short, deterministic string identifiers.
3532
3633For a walkthrough of the bit-packing layout and design choices, see the
3734[ technical deep dive] ( https://eignex.com/posts/kencode-packing-data-for-strict-limits/ ) .
@@ -74,16 +71,13 @@ val decoded = EncodedFormat.decodeFromString<Payload>(encoded)
7471
7572## PackedFormat
7673
77- PackedFormat is a ` BinaryFormat ` for Kotlin classes that emits compact byte
78- payloads.
79-
80- * Bit-Packing: Booleans and nullability markers share a single bit-header
81- (~ 1 bit per field).
82- * VarInts: annotate ` Int ` /` Long ` fields with ` @PackedType(IntPacking.DEFAULT) `
83- (unsigned varint) or ` @PackedType(IntPacking.SIGNED) ` (ZigZag). ` @ProtoType `
84- is recognized as a fallback.
85- * Full Graph Support: nested objects, lists, maps, and polymorphism are
86- handled recursively.
74+ PackedFormat is a BinaryFormat for Kotlin classes that emits compact byte
75+ payloads. Booleans and nullability markers share a single bit-header (about one
76+ bit per field), and nested objects, lists, maps, and polymorphism are handled
77+ recursively. Int and Long fields can be annotated with
78+ ` @PackedType(IntPacking.DEFAULT) ` for unsigned varint or
79+ ` @PackedType(IntPacking.SIGNED) ` for ZigZag; ` @ProtoType ` is recognized as a
80+ fallback.
8781
8882``` kotlin
8983val compactFormat = PackedFormat {
@@ -99,15 +93,14 @@ val bytes = compactFormat.encodeToByteArray(payload)
9993
10094## EncodedFormat
10195
102- EncodedFormat provides a StringFormat API that produces short tokens by
103- composing three layers:
104-
105- 1 . Binary Layer: PackedFormat (default) or ProtoBuf (recommended for
106- cross-language compatibility).
107- 2 . Transform Layer: Optional ` PayloadTransform ` applied after serialization
108- (e.g. ` CompactZeros ` , ` Checksum.asTransform() ` , or a custom transform for
109- encryption or ECC). Chain transforms with ` PayloadTransform.then ` .
110- 3 . Text Layer: Base62 (default), Base36, Base64, or Base85.
96+ EncodedFormat is a StringFormat that produces short tokens by composing three
97+ layers. The binary layer is PackedFormat by default, but ProtoBuf is a good
98+ choice when cross-language compatibility matters. After serialization, an
99+ optional PayloadTransform can manipulate the bytes — for example ` CompactZeros `
100+ to strip leading zeros, ` Checksum.asTransform() ` to append an integrity check,
101+ or a custom transform for encryption or error correction; transforms compose
102+ with ` PayloadTransform.then ` . Finally a text codec turns the bytes into a
103+ string, with Base62 as the default and Base36, Base64, and Base85 available.
111104
112105``` kotlin
113106val customFormat = EncodedFormat {
@@ -128,13 +121,11 @@ val withBoth = EncodedFormat {
128121
129122## Base Encoders
130123
131- KEncode includes standalone codecs for byte-to-text conversion. All
132- implementations support custom alphabets.
133-
134- * Base62 / Base36: fixed-block encoding with predictable lengths and no
135- padding; alpha-numeric output, with or without upper-case.
136- * Base85: high-density encoding (4 bytes → 5 characters).
137- * Base64 / Base64Url: RFC 4648 compatible.
124+ KEncode ships standalone byte-to-text codecs, all of which accept custom
125+ alphabets. Base62 and Base36 use fixed-block encoding for predictable lengths
126+ without padding, and produce purely alpha-numeric output (with or without
127+ upper-case). Base85 trades alphabet size for density, encoding four bytes into
128+ five characters. Base64 and Base64Url are RFC 4648 compatible.
138129
139130Encoding ` "any byte data" ` (13 bytes):
140131
0 commit comments