KsService
annotation class KsService
Annotation tagging an interface for processing by the compiler plugin.
interfaces tagged with this are expected to extend com.monkopedia.ksrpc.RpcService, and will have a companion generated for them that implements com.monkopedia.ksrpc.RpcObject for itself.
Samples
import com.monkopedia.ksrpc.RpcService
import com.monkopedia.ksrpc.annotation.KsMethod
import com.monkopedia.ksrpc.annotation.KsService
import com.monkopedia.ksrpc.ksrpcEnvironment
import com.monkopedia.ksrpc.rpcObject
import com.monkopedia.ksrpc.serialized
import com.monkopedia.ksrpc.toStub
import kotlinx.serialization.Serializable
fun main() {
//sampleStart
// Define a service interface with @KsService and @KsMethod annotations.
// The compiler plugin generates a companion RpcObject and stub automatically.
val rpcObj = rpcObject<GreetingService>()
val endpoint = rpcObj.findEndpoint("greet")
//sampleEnd
}import com.monkopedia.ksrpc.RpcService
import com.monkopedia.ksrpc.annotation.KsMethod
import com.monkopedia.ksrpc.annotation.KsService
import com.monkopedia.ksrpc.ksrpcEnvironment
import com.monkopedia.ksrpc.rpcObject
import com.monkopedia.ksrpc.serialized
import com.monkopedia.ksrpc.toStub
import kotlinx.serialization.Serializable
fun main() {
//sampleStart
// Implement the service interface
val service = object : GreetingService {
override suspend fun greet(name: String): String = "Hello, $name!"
}
// Serialize for hosting on any transport
val env = ksrpcEnvironment { }
val serialized = service.serialized(env)
//sampleEnd
}