1 package kotlinx.serialization.protobuf.internal 2 3 import kotlinx.serialization.* 4 import kotlinx.serialization.descriptors.* 5 import kotlinx.serialization.encoding.* 6 import kotlinx.serialization.protobuf.* 7 8 @OptIn(ExperimentalSerializationApi::class) 9 internal class PackedArrayDecoder( 10 proto: ProtoBuf, 11 reader: ProtobufReader, 12 descriptor: SerialDescriptor, 13 ) : ProtobufDecoder(proto, reader, descriptor) { 14 private var nextIndex: Int = 0 15 16 // Tags are omitted in the packed array format getTagnull17 override fun SerialDescriptor.getTag(index: Int): ProtoDesc = MISSING_TAG 18 19 override fun beginStructure(descriptor: SerialDescriptor): CompositeDecoder { 20 throw SerializationException("Packing only supports primitive number types. The input type however was a struct: $descriptor") 21 } 22 decodeElementIndexnull23 override fun decodeElementIndex(descriptor: SerialDescriptor): Int { 24 // We need eof here as there is no tag to read in packed form. 25 if (reader.eof) return CompositeDecoder.DECODE_DONE 26 return nextIndex++ 27 } 28 decodeTaggedStringnull29 override fun decodeTaggedString(tag: ProtoDesc): String { 30 throw SerializationException("Packing only supports primitive number types. The actual reading is for string.") 31 } 32 }