@@ -159,7 +159,6 @@ class PackedEncoder(
159159 @ExperimentalSerializationApi
160160 override fun encodeNotNullMark () {
161161 if (inStructure && isCollection) {
162- // Inline not-null marker for collections (0 = present)
163162 PackedUtils .writeVarLong(0L , dataBuffer)
164163 } else if (! inStructure) {
165164 PackedUtils .writeVarLong(0L , output)
@@ -204,8 +203,6 @@ class PackedEncoder(
204203 nullableIndices = intArrayOf()
205204 }
206205
207- // --- Element Encoding Delegates ---
208-
209206 private fun booleanPos (index : Int ): Int {
210207 for (i in booleanIndices.indices) if (booleanIndices[i] == index) return i
211208 return - 1
@@ -224,11 +221,21 @@ class PackedEncoder(
224221
225222 override fun encodeIntElement (descriptor : SerialDescriptor , index : Int , value : Int ) {
226223 val anns = descriptor.getElementAnnotations(index)
224+ val hasFixedInt = anns.hasFixedInt()
227225 val hasVarInt = anns.hasVarInt()
228226 val hasVarUInt = anns.hasVarUInt()
229227
230- val zigZag = hasVarInt || (config.defaultZigZag && ! hasVarUInt)
231- val isVar = hasVarUInt || zigZag || config.defaultVarInt
228+ val isVar = when {
229+ hasFixedInt -> false
230+ hasVarInt || hasVarUInt -> true
231+ else -> config.defaultVarInt || config.defaultZigZag
232+ }
233+
234+ val zigZag = when {
235+ hasVarInt -> true
236+ hasVarUInt || hasFixedInt -> false
237+ else -> config.defaultZigZag
238+ }
232239
233240 if (isVar) {
234241 val v = if (zigZag) PackedUtils .zigZagEncodeInt(value) else value
@@ -240,11 +247,21 @@ class PackedEncoder(
240247
241248 override fun encodeLongElement (descriptor : SerialDescriptor , index : Int , value : Long ) {
242249 val anns = descriptor.getElementAnnotations(index)
250+ val hasFixedInt = anns.hasFixedInt()
243251 val hasVarInt = anns.hasVarInt()
244252 val hasVarUInt = anns.hasVarUInt()
245253
246- val zigZag = hasVarInt || (config.defaultZigZag && ! hasVarUInt)
247- val isVar = hasVarUInt || zigZag || config.defaultVarInt
254+ val isVar = when {
255+ hasFixedInt -> false
256+ hasVarInt || hasVarUInt -> true
257+ else -> config.defaultVarInt || config.defaultZigZag
258+ }
259+
260+ val zigZag = when {
261+ hasVarInt -> true
262+ hasVarUInt || hasFixedInt -> false
263+ else -> config.defaultZigZag
264+ }
248265
249266 if (isVar) {
250267 val v = if (zigZag) PackedUtils .zigZagEncodeLong(value) else value
0 commit comments