@@ -27,6 +27,17 @@ internal abstract class AbstractMapConfigDecoder(
27
27
override fun decodeChar (): Char = decodeString().single()
28
28
override fun decodeByte (): Byte = decodeString().toByte()
29
29
override fun decodeShort (): Short = decodeString().toShort()
30
+ override fun decodeEnum (enumDescriptor : SerialDescriptor ): Int =
31
+ enumDescriptor.getElementIndex(decodeString())
32
+
33
+ protected fun beginStructure (descriptor : SerialDescriptor , path : String ): CompositeDecoder {
34
+ val kind = descriptor.kind as ? StructureKind ? : error(" Expected structure but found ${descriptor.kind} " )
35
+ return when (kind) {
36
+ StructureKind .LIST -> ListMapConfigDecoder (map, path, map.listSize(path), serializersModule)
37
+ StructureKind .MAP -> SubMapConfigDecoder (map, path, serializersModule)
38
+ else -> MapConfigDecoder (map, path, serializersModule)
39
+ }
40
+ }
30
41
}
31
42
32
43
@OptIn(ExperimentalSerializationApi ::class )
@@ -59,17 +70,8 @@ internal class MapConfigDecoder(
59
70
override fun decodeString (): String = map[currentPath]
60
71
? : throw SerializationException (" Property $currentPath not found" )
61
72
62
- override fun decodeEnum (enumDescriptor : SerialDescriptor ): Int =
63
- enumDescriptor.getElementIndex(decodeString())
64
-
65
- override fun beginStructure (descriptor : SerialDescriptor ): CompositeDecoder {
66
- val kind = descriptor.kind as StructureKind
67
- return when (kind) {
68
- StructureKind .LIST -> ListMapConfigDecoder (map, currentPath, map.listSize(currentPath), serializersModule)
69
- StructureKind .MAP -> SubMapConfigDecoder (map, currentPath, serializersModule)
70
- else -> MapConfigDecoder (map, currentPath, serializersModule)
71
- }
72
- }
73
+ override fun beginStructure (descriptor : SerialDescriptor ): CompositeDecoder =
74
+ beginStructure(descriptor, currentPath)
73
75
}
74
76
75
77
@OptIn(ExperimentalSerializationApi ::class )
@@ -90,18 +92,8 @@ private class ListMapConfigDecoder(
90
92
return map[key] ? : throw SerializationException (" Missing list element at \" $key \" " )
91
93
}
92
94
93
- override fun decodeEnum (enumDescriptor : SerialDescriptor ): Int =
94
- enumDescriptor.getElementIndex(decodeString())
95
-
96
- override fun beginStructure (descriptor : SerialDescriptor ): CompositeDecoder {
97
- val currentKey = " $path .${index - 1 } "
98
- val kind = descriptor.kind as StructureKind
99
- return when (kind) {
100
- StructureKind .LIST -> ListMapConfigDecoder (map, currentKey, map.listSize(currentKey), serializersModule)
101
- StructureKind .MAP -> SubMapConfigDecoder (map, currentKey, serializersModule)
102
- else -> MapConfigDecoder (map, currentKey, serializersModule)
103
- }
104
- }
95
+ override fun beginStructure (descriptor : SerialDescriptor ): CompositeDecoder =
96
+ beginStructure(descriptor, " $path .${index - 1 } " )
105
97
}
106
98
107
99
@OptIn(ExperimentalSerializationApi ::class )
@@ -141,15 +133,8 @@ private class SubMapConfigDecoder(
141
133
}
142
134
}
143
135
144
- override fun beginStructure (descriptor : SerialDescriptor ): CompositeDecoder {
145
- val key = " $path .$currentKey "
146
- val kind = descriptor.kind as StructureKind
147
- return when (kind) {
148
- StructureKind .LIST -> ListMapConfigDecoder (map, key, map.listSize(key), serializersModule)
149
- StructureKind .MAP -> SubMapConfigDecoder (map, key, serializersModule)
150
- else -> MapConfigDecoder (map, key, serializersModule)
151
- }
152
- }
136
+ override fun beginStructure (descriptor : SerialDescriptor ): CompositeDecoder =
137
+ beginStructure(descriptor, " $path .$currentKey " )
153
138
}
154
139
155
140
private fun Map <String , String >.listSize (path : String ): Int =
0 commit comments