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

// 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")
// 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)