@@ -31,12 +31,14 @@ class PackedDecoder(
3131 inStructure = true
3232 currentDescriptor = descriptor
3333
34- val boolIdx = (0 until descriptor.elementsCount)
35- .filter { descriptor.getElementDescriptor(it).kind == PrimitiveKind .BOOLEAN }
34+ val boolIdx = (0 until descriptor.elementsCount).filter {
35+ descriptor.getElementDescriptor(it).kind == PrimitiveKind .BOOLEAN
36+ }
3637 booleanIndices = boolIdx.toIntArray()
3738
38- val nullableIdx = (0 until descriptor.elementsCount)
39- .filter { descriptor.getElementDescriptor(it).isNullable }
39+ val nullableIdx = (0 until descriptor.elementsCount).filter {
40+ descriptor.getElementDescriptor(it).isNullable
41+ }
4042 nullableIndices = nullableIdx.toIntArray()
4143
4244 val (flagsLong, bytesRead) = PackedUtils .decodeVarLong(input, position)
@@ -47,7 +49,8 @@ class PackedDecoder(
4749 booleanValues = BooleanArray (0 )
4850 nullValues = BooleanArray (0 )
4951 } else {
50- val allFlags = PackedUtils .unpackFlagsFromLong(flagsLong, totalFlags)
52+ val allFlags =
53+ PackedUtils .unpackFlagsFromLong(flagsLong, totalFlags)
5154 booleanValues = if (booleanIndices.isEmpty()) {
5255 BooleanArray (0 )
5356 } else {
@@ -211,17 +214,15 @@ class PackedDecoder(
211214 }
212215
213216 override fun decodeBooleanElement (
214- descriptor : SerialDescriptor ,
215- index : Int
217+ descriptor : SerialDescriptor , index : Int
216218 ): Boolean {
217219 val pos = booleanPos(index)
218220 if (pos == - 1 ) error(" Element $index is not a boolean" )
219221 return booleanValues[pos]
220222 }
221223
222224 override fun decodeIntElement (
223- descriptor : SerialDescriptor ,
224- index : Int
225+ descriptor : SerialDescriptor , index : Int
225226 ): Int {
226227 val anns = descriptor.getElementAnnotations(index)
227228 val zigZag = anns.hasVarInt()
@@ -237,8 +238,7 @@ class PackedDecoder(
237238 }
238239
239240 override fun decodeLongElement (
240- descriptor : SerialDescriptor ,
241- index : Int
241+ descriptor : SerialDescriptor , index : Int
242242 ): Long {
243243 val anns = descriptor.getElementAnnotations(index)
244244 val zigZag = anns.hasVarInt()
@@ -254,8 +254,7 @@ class PackedDecoder(
254254 }
255255
256256 override fun decodeByteElement (
257- descriptor : SerialDescriptor ,
258- index : Int
257+ descriptor : SerialDescriptor , index : Int
259258 ): Byte {
260259 require(position < input.size) {
261260 " Unexpected EOF while decoding Byte element at index $index "
@@ -264,41 +263,36 @@ class PackedDecoder(
264263 }
265264
266265 override fun decodeShortElement (
267- descriptor : SerialDescriptor ,
268- index : Int
266+ descriptor : SerialDescriptor , index : Int
269267 ): Short {
270268 return readShortPos()
271269 }
272270
273271 override fun decodeCharElement (
274- descriptor : SerialDescriptor ,
275- index : Int
272+ descriptor : SerialDescriptor , index : Int
276273 ): Char {
277274 return readUtf8Char()
278275 }
279276
280277 override fun decodeFloatElement (
281- descriptor : SerialDescriptor ,
282- index : Int
278+ descriptor : SerialDescriptor , index : Int
283279 ): Float {
284280 return java.lang.Float .intBitsToFloat(readIntPos())
285281 }
286282
287283 override fun decodeDoubleElement (
288- descriptor : SerialDescriptor ,
289- index : Int
284+ descriptor : SerialDescriptor , index : Int
290285 ): Double {
291286 return java.lang.Double .longBitsToDouble(readLongPos())
292287 }
293288
294289 override fun decodeStringElement (
295- descriptor : SerialDescriptor ,
296- index : Int
290+ descriptor : SerialDescriptor , index : Int
297291 ): String {
298292 val (len, bytesRead) = PackedUtils .decodeVarInt(input, position)
299293 position + = bytesRead
300294 require(len >= 0 && position + len <= input.size) {
301- " Unexpected EOF while decoding String element at index $index : need $len bytes from position=$position , size=${input.size} "
295+ " Unexpected EOF while decoding String element at index $index : " + " need $len bytes from position=$position , size=${input.size} "
302296 }
303297 val bytes = input.copyOfRange(position, position + len)
304298 position + = len
@@ -307,8 +301,7 @@ class PackedDecoder(
307301
308302 @ExperimentalSerializationApi
309303 override fun decodeInlineElement (
310- descriptor : SerialDescriptor ,
311- index : Int
304+ descriptor : SerialDescriptor , index : Int
312305 ): Decoder {
313306 currentIndex = index
314307 return this
@@ -324,12 +317,7 @@ class PackedDecoder(
324317
325318 if (! deserializer.descriptor.isInline) {
326319 val kind = deserializer.descriptor.kind
327- if (kind is StructureKind .CLASS ||
328- kind is StructureKind .OBJECT ||
329- kind is StructureKind .LIST ||
330- kind is StructureKind .MAP ||
331- kind is PolymorphicKind
332- ) {
320+ if (kind is StructureKind .CLASS || kind is StructureKind .OBJECT || kind is StructureKind .LIST || kind is StructureKind .MAP || kind is PolymorphicKind ) {
333321 error(" Nested objects/collections are not supported" )
334322 }
335323 }
@@ -407,8 +395,7 @@ class PackedDecoder(
407395 " Invalid UTF-8 continuation byte: 0x${b1.toString(16 )} "
408396 }
409397 val codePoint =
410- ((b0 and 0b0001_1111 ) shl 6 ) or
411- (b1 and 0b0011_1111 )
398+ ((b0 and 0b0001_1111 ) shl 6 ) or (b1 and 0b0011_1111 )
412399 2 to codePoint
413400 }
414401
@@ -419,19 +406,22 @@ class PackedDecoder(
419406 }
420407 val b1 = input[position + 1 ].toInt() and 0xFF
421408 val b2 = input[position + 2 ].toInt() and 0xFF
422- require((b1 and 0b1100_0000 ) == 0b1000_0000 &&
423- (b2 and 0b1100_0000 ) == 0b1000_0000 ) {
409+ require(
410+ (b1 and 0b1100_0000 ) == 0b1000_0000 && (b2 and 0b1100_0000 ) == 0b1000_0000
411+ ) {
424412 " Invalid UTF-8 continuation byte in 3-byte char"
425413 }
426414 val codePoint =
427- ((b0 and 0b0000_1111 ) shl 12 ) or
428- ((b1 and 0b0011_1111 ) shl 6 ) or
429- (b2 and 0b0011_1111 )
415+ ((b0 and 0b0000_1111 ) shl 12 ) or ((b1 and 0b0011_1111 ) shl 6 ) or (b2 and 0b0011_1111 )
430416 3 to codePoint
431417 }
432418
433419 else -> throw IllegalArgumentException (
434- " UTF-8 sequence too long for Char (leading byte: 0x${b0.toString(16 )} )"
420+ " UTF-8 sequence too long for Char (leading byte: 0x${
421+ b0.toString(
422+ 16
423+ )
424+ } )"
435425 )
436426 }
437427
0 commit comments