commonMain.com.caesarealabs.rpc4k.generated.LoggyServiceRouter.kt Maven / Gradle / Ivy
The newest version!
@file:Suppress("UNCHECKED_CAST")
@file:OptIn(ExperimentalUnsignedTypes::class, ExperimentalSerializationApi::class)
package com.caesarealabs.rpc4k.generated
import com.caesarealabs.loggy.shared.Invocation
import com.caesarealabs.loggy.shared.LoggyService
import com.caesarealabs.loggy.shared.Query
import com.caesarealabs.loggy.shared.SearchResult
import com.caesarealabs.rpc4k.runtime.api.HandlerConfig
import com.caesarealabs.rpc4k.runtime.api.RpcRouter
import com.caesarealabs.rpc4k.runtime.implementation.GeneratedCodeUtils.invokeEvent
import com.caesarealabs.rpc4k.runtime.implementation.GeneratedCodeUtils.respond
import com.caesarealabs.rpc4k.runtime.user.RPCContext
import com.caesarealabs.rpc4k.runtime.user.RPCContext.Companion.Default
import com.caesarealabs.rpc4k.runtime.user.Rpc4kIndex
import kotlin.ByteArray
import kotlin.ExperimentalUnsignedTypes
import kotlin.OptIn
import kotlin.String
import kotlin.Suppress
import kotlin.collections.Set
import kotlin.collections.listOf
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.builtins.ListSerializer
import kotlinx.serialization.builtins.nullable
import kotlinx.serialization.builtins.serializer
public val LoggyService.Companion.rpc4k:
Rpc4kIndex
get() = object: Rpc4kIndex {
override val createInvoker = ::LoggyServiceEventInvoker
override val createNetworkClient = ::LoggyServiceNetworkClient
override val router = LoggyServiceRouter
}
public object LoggyServiceRouter : RpcRouter {
override suspend fun routeRequest(
request: ByteArray,
method: String,
config: HandlerConfig,
context: RPCContext,
): ByteArray? = when(method) {
"getEndpoints" -> respond(config, request, listOf(), ListSerializer(String.serializer()),
context) {
with(config.handler) {
getEndpoints()
}
}
"getDataValuesForKeyInQuery" -> respond(config, request, listOf(String.serializer(),
String.serializer(), String.serializer()), ListSerializer(String.serializer()).nullable,
context) {
with(config.handler) {
getDataValuesForKeyInQuery(it[0] as String, it[1] as String, it[2] as String)
}
}
"getInvocations" -> respond(config, request, listOf(Query.serializer(), String.serializer()),
SearchResult.serializer(Invocation.serializer()), context) {
with(config.handler) {
getInvocations(it[0] as Query, it[1] as String)
}
}
else -> null
}
}
public class LoggyServiceEventInvoker(
private val config: HandlerConfig,
) {
/**
* @param participants Listeners that will not be invoked as they have caused the event.
*/
public suspend fun invokeOnInvocationAdded(
invocation: Invocation,
rpcContext: RPCContext = Default,
participants: Set = setOf(),
) {
invokeEvent(config, "onInvocationAdded", listOf(String.serializer().nullable,
Query.serializer()), Invocation.serializer(), rpcContext, participants, ) {
config.handler.onInvocationAdded(invocation, it[0] as String?, it[1] as Query)
}
}
}