aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/util
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-07-26 23:59:24 +0200
committernea <nea@nea.moe>2023-07-26 23:59:24 +0200
commitd4b254ea11798a8ba4b891d31c433496b7c53bb3 (patch)
treefb94f03b5d3c5f1f25e5d9c9e94ecd85588f8ccb /src/main/kotlin/moe/nea/firmament/util
parent3375907c44704b968f06ac996cb389c4e29b3826 (diff)
downloadFirmament-d4b254ea11798a8ba4b891d31c433496b7c53bb3.tar.gz
Firmament-d4b254ea11798a8ba4b891d31c433496b7c53bb3.tar.bz2
Firmament-d4b254ea11798a8ba4b891d31c433496b7c53bb3.zip
Fix storage not saving properly
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/util')
-rw-r--r--src/main/kotlin/moe/nea/firmament/util/SortedMapSerializer.kt23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/util/SortedMapSerializer.kt b/src/main/kotlin/moe/nea/firmament/util/SortedMapSerializer.kt
new file mode 100644
index 0000000..6f4ff2e
--- /dev/null
+++ b/src/main/kotlin/moe/nea/firmament/util/SortedMapSerializer.kt
@@ -0,0 +1,23 @@
+package moe.nea.firmament.util
+
+import java.util.SortedMap
+import kotlinx.serialization.KSerializer
+import kotlinx.serialization.builtins.MapSerializer
+import kotlinx.serialization.descriptors.SerialDescriptor
+import kotlinx.serialization.encoding.Decoder
+import kotlinx.serialization.encoding.Encoder
+
+class SortedMapSerializer<K : Comparable<K>, V>(val keyDelegate: KSerializer<K>, val valueDelegate: KSerializer<V>) :
+ KSerializer<SortedMap<K, V>> {
+ val mapSerializer = MapSerializer(keyDelegate, valueDelegate)
+ override val descriptor: SerialDescriptor
+ get() = mapSerializer.descriptor
+
+ override fun deserialize(decoder: Decoder): SortedMap<K, V> {
+ return (mapSerializer.deserialize(decoder).toSortedMap(Comparator.naturalOrder()))
+ }
+
+ override fun serialize(encoder: Encoder, value: SortedMap<K, V>) {
+ mapSerializer.serialize(encoder, value)
+ }
+}