commonMain.com.funkatronics.rpccore.JsonRpcDriver.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rpc-core-jvm Show documentation
Show all versions of rpc-core-jvm Show documentation
Multiplatform JSON RPC Library using Kotlin Serialization
package com.funkatronics.rpccore
import kotlinx.serialization.KSerializer
import kotlinx.serialization.json.JsonElement
interface JsonRpcDriver {
suspend fun makeRequest(request: RpcRequest, resultSerializer: KSerializer): RpcResponse
}
suspend inline fun JsonRpcDriver.get(
request: RpcRequest,
serializer: KSerializer
): Result =
this.makeRequest(request, serializer).let { response ->
(response.result)?.let { result ->
return Result.success(result)
}
response.error?.let {
return Result.failure(Error(it.message))
}
// an empty error and empty result means we did not find anything, return null
return Result.success(null)
}
suspend fun JsonRpcDriver.makeRequest(request: RpcRequest): DefaultRpcResponse =
makeRequest(request, JsonElement.serializer())
© 2015 - 2025 Weber Informatics LLC | Privacy Policy