-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: value manager serializable support
- Loading branch information
1 parent
a4b0afb
commit 1740f08
Showing
6 changed files
with
82 additions
and
0 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
24 changes: 24 additions & 0 deletions
24
core/common/src/dev/programadorthi/state/core/serialization/ValueManagerSerializer.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,24 @@ | ||
package dev.programadorthi.state.core.serialization | ||
|
||
import dev.programadorthi.state.core.ValueManager | ||
import dev.programadorthi.state.core.extension.basicValueManager | ||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.descriptors.SerialDescriptor | ||
import kotlinx.serialization.encoding.Decoder | ||
import kotlinx.serialization.encoding.Encoder | ||
|
||
internal class ValueManagerSerializer<T>( | ||
private val valueSerializer: KSerializer<T> | ||
) : KSerializer<ValueManager<T>> { | ||
|
||
override val descriptor: SerialDescriptor = valueSerializer.descriptor | ||
|
||
override fun deserialize(decoder: Decoder): ValueManager<T> { | ||
val value = valueSerializer.deserialize(decoder) | ||
return basicValueManager(value) | ||
} | ||
|
||
override fun serialize(encoder: Encoder, value: ValueManager<T>) { | ||
valueSerializer.serialize(encoder, value.value) | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
core/common/test/dev/programadorthi/state/core/SerializableValueManager.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,14 @@ | ||
package dev.programadorthi.state.core | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
internal data class Color(val name: String) | ||
|
||
@Serializable | ||
internal data class SerializableValueManager( | ||
val intValue: ValueManager<Int>, | ||
val stringValue: ValueManager<String>, | ||
val color: ValueManager<Color>, | ||
val composite: ValueManager<ValueManager<List<Color>>> | ||
) |
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