Skip to content

Commit

Permalink
allow for deserialization of plugin info into data classes
Browse files Browse the repository at this point in the history
  • Loading branch information
topi314 committed Oct 12, 2023
1 parent 8df70c2 commit a8cc33a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 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: JsonObject, tracks: List<Track>) =
fun playlistLoaded(playlistInfo: PlaylistInfo, pluginInfo: PluginData, tracks: List<Track>) =
PlaylistLoaded(
Playlist(
playlistInfo,
Expand Down Expand Up @@ -133,7 +133,7 @@ data class PlaylistInfo(
@Serializable
data class Playlist(
val info: PlaylistInfo,
val pluginInfo: JsonObject,
val pluginInfo: PluginData,
val tracks: List<Track>
) : LoadResult.Data

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
package dev.arbjerg.lavalink.protocol.v4

import kotlinx.serialization.DeserializationStrategy
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.serializer
import kotlin.jvm.JvmInline

@Serializable()
@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)
}

@Serializable
@JvmInline
value class Players(val players: List<Player>)

Expand All @@ -23,7 +32,7 @@ data class Player(
data class Track(
val encoded: String,
val info: TrackInfo,
val pluginInfo: JsonObject
val pluginInfo: PluginData
) : LoadResult.Data

@Serializable
Expand Down

0 comments on commit a8cc33a

Please sign in to comment.