-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: convert EmojyTemplates to serialize as a Map instead of List
- Loading branch information
Showing
5 changed files
with
57 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
core/src/main/kotlin/com/mineinabyss/emojy/config/InnerSerializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.mineinabyss.emojy.config | ||
|
||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.descriptors.PrimitiveKind | ||
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor | ||
import kotlinx.serialization.descriptors.SerialDescriptor | ||
import kotlinx.serialization.encoding.Decoder | ||
import kotlinx.serialization.encoding.Encoder | ||
|
||
abstract class InnerSerializer<I, O>( | ||
val serialName: String, | ||
val inner: KSerializer<I>, | ||
val transform: Decoder.(I) -> O, | ||
val inverseTransform: (O) -> I, | ||
) : KSerializer<O> { | ||
override val descriptor = | ||
if (inner.descriptor.kind is PrimitiveKind) | ||
PrimitiveSerialDescriptor(serialName, inner.descriptor.kind as PrimitiveKind) | ||
else SerialDescriptor(serialName, inner.descriptor) | ||
|
||
override fun deserialize(decoder: Decoder): O { | ||
return transform(decoder, inner.deserialize(decoder)) | ||
} | ||
|
||
override fun serialize(encoder: Encoder, value: O) { | ||
inner.serialize(encoder, inverseTransform(value)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
group=com.mineinabyss | ||
version=0.9 | ||
idofrontVersion=0.24.12 | ||
idofrontVersion=0.24.21 |