Skip to content

Commit

Permalink
fixup java access for plugin info deserialization
Browse files Browse the repository at this point in the history
Co-authored-by: viztea <[email protected]>
  • Loading branch information
topi314 and viztea committed Oct 12, 2023
1 parent 0300521 commit 5781161
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ sealed interface LoadResult {
companion object {
fun trackLoaded(track: Track) = TrackLoaded(track)

fun playlistLoaded(playlistInfo: PlaylistInfo, pluginInfo: PluginData, tracks: List<Track>) =
fun playlistLoaded(playlistInfo: PlaylistInfo, pluginInfo: JsonObject, tracks: List<Track>) =
PlaylistLoaded(
Playlist(
playlistInfo,
Expand Down Expand Up @@ -133,9 +133,11 @@ data class PlaylistInfo(
@Serializable
data class Playlist(
val info: PlaylistInfo,
val pluginInfo: PluginData,
val pluginInfo: JsonObject,
val tracks: List<Track>
) : LoadResult.Data
) : LoadResult.Data {
fun <T> deserialize(deserializer: DeserializationStrategy<T>): T = pluginInfo.deserialize(deserializer)
}

@Serializable
data class Exception(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.serializer
import kotlin.jvm.JvmInline

@Serializable
@JvmInline
value class PluginData(private val obj: JsonObject){
inline fun <reified T> deserialize(): T = deserialize(json.serializersModule.serializer<T>())
fun <T> deserialize(deserializer: DeserializationStrategy<T>): T = json.decodeFromJsonElement(deserializer, obj)
}
inline fun <reified T> JsonObject.deserialize(): T =
deserialize(json.serializersModule.serializer<T>())

fun <T> JsonObject.deserialize(deserializer: DeserializationStrategy<T>): T =
json.decodeFromJsonElement(deserializer, this)

@Serializable
@JvmInline
Expand All @@ -32,8 +31,10 @@ data class Player(
data class Track(
val encoded: String,
val info: TrackInfo,
val pluginInfo: PluginData
) : LoadResult.Data
val pluginInfo: JsonObject
) : LoadResult.Data {
fun <T> deserialize(deserializer: DeserializationStrategy<T>): T = pluginInfo.deserialize(deserializer)
}

@Serializable
@JvmInline
Expand Down
2 changes: 1 addition & 1 deletion protocol/src/commonTest/kotlin/LoadResultSerializerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class LoadResultSerializerTest {
loadType shouldBe ResultStatus.PLAYLIST
assertIs<LoadResult.PlaylistLoaded>(this)
data {
pluginInfo shouldBe JsonObject(emptyMap())
pluginInfo shouldBe emptyMap()
info {
name shouldBe "Example YouTube Playlist"
selectedTrack shouldBe 3
Expand Down

0 comments on commit 5781161

Please sign in to comment.