@@ -11,16 +11,15 @@ import kotlinx.serialization.descriptors.PolymorphicKind
1111import kotlinx.serialization.descriptors.SerialDescriptor
1212import kotlinx.serialization.descriptors.StructureKind
1313
14- actual fun FirebaseDecoder.structureDecoder (descriptor : SerialDescriptor , decodeDouble : (value: Any? ) -> Double? ): CompositeDecoder =
15- when (descriptor.kind) {
16- StructureKind .CLASS , StructureKind .OBJECT , PolymorphicKind .SEALED -> (value as Map <* , * >).let { map ->
17- FirebaseClassDecoder (decodeDouble, map.size, { map.containsKey(it) }) { desc, index -> map[desc.getElementName(index)] }
18- }
19- StructureKind .LIST , PolymorphicKind .SEALED -> (value as List <* >).let {
20- FirebaseCompositeDecoder (decodeDouble, it.size) { _, index -> it[index] }
21- }
22- StructureKind .MAP -> (value as Map <* , * >).entries.toList().let {
23- FirebaseCompositeDecoder (decodeDouble, it.size) { _, index -> it[index/ 2 ].run { if (index % 2 == 0 ) key else value } }
24- }
25- else -> TODO (" The firebase-kotlin-sdk does not support $descriptor for serialization yet" )
26- }
14+ actual fun FirebaseDecoder.structureDecoder (descriptor : SerialDescriptor , decodeDouble : (value: Any? ) -> Double? ): CompositeDecoder = when (descriptor.kind) {
15+ StructureKind .CLASS , StructureKind .OBJECT , PolymorphicKind .SEALED -> (value as Map <* , * >).let { map ->
16+ FirebaseClassDecoder (decodeDouble, map.size, { map.containsKey(it) }) { desc, index -> map[desc.getElementName(index)] }
17+ }
18+ StructureKind .LIST , PolymorphicKind .SEALED -> (value as List <* >).let {
19+ FirebaseCompositeDecoder (decodeDouble, it.size) { _, index -> it[index] }
20+ }
21+ StructureKind .MAP -> (value as Map <* , * >).entries.toList().let {
22+ FirebaseCompositeDecoder (decodeDouble, it.size) { _, index -> it[index/ 2 ].run { if (index % 2 == 0 ) key else value } }
23+ }
24+ else -> TODO (" The firebase-kotlin-sdk does not support $descriptor for serialization yet" )
25+ }
0 commit comments