@@ -5,11 +5,58 @@ package com.eignex.kencode
55import kotlinx.serialization.ExperimentalSerializationApi
66import kotlinx.serialization.SerialInfo
77
8+ /* *
9+ * Marks an `Int` or `Long` property to be encoded using **signed varint** encoding.
10+ *
11+ * Behavior:
12+ * - Values are ZigZag–transformed, so small negative numbers encode compactly.
13+ * - Serialized using a variable-length LEB128-style varint.
14+ * - Applies only to `Int` and `Long` fields inside `PackedFormat` structures.
15+ *
16+ * Decoding:
17+ * - Automatically applies ZigZag decode.
18+ *
19+ * Usage:
20+ * ```
21+ * @Serializable
22+ * data class Example(
23+ * @VarInt val delta: Int, // small negatives become very compact
24+ * @VarInt val offset: Long
25+ * )
26+ * ```
27+ *
28+ * Has no effect for primitive types outside `PackedFormat`.
29+ */
830@SerialInfo
931@Target(AnnotationTarget .PROPERTY )
1032@Retention(AnnotationRetention .RUNTIME )
1133annotation class VarInt
1234
35+ /* *
36+ * Marks an `Int` or `Long` property to be encoded using **unsigned varint** encoding.
37+ *
38+ * Behavior:
39+ * - No ZigZag transform; values are treated as non-negative.
40+ * - Serialized using a variable-length LEB128-style varint.
41+ * - Applies only to `Int` and `Long` fields inside `PackedFormat` structures.
42+ *
43+ * Recommended for:
44+ * - IDs
45+ * - version counters
46+ * - monotonic sequence numbers
47+ * - any value that is always `>= 0`
48+ *
49+ * Usage:
50+ * ```
51+ * @Serializable
52+ * data class Example(
53+ * @VarUInt val id: Long, // compact for small and medium positive values
54+ * @VarUInt val count: Int
55+ * )
56+ * ```
57+ *
58+ * Has no effect for primitive types outside `PackedFormat`.
59+ */
1360@SerialInfo
1461@Target(AnnotationTarget .PROPERTY )
1562@Retention(AnnotationRetention .RUNTIME )
0 commit comments