KsIntrospectable

annotation class KsIntrospectable

Annotation tagging an interface for processing by the compiler plugin.

This should be placed on interfaces which extend IntrospectableRpcService.

Samples

import com.monkopedia.ksrpc.IntrospectableRpcService
import com.monkopedia.ksrpc.annotation.KsIntrospectable
import com.monkopedia.ksrpc.annotation.KsMethod
import com.monkopedia.ksrpc.annotation.KsService
import com.monkopedia.ksrpc.ksrpcEnvironment
import com.monkopedia.ksrpc.serialized
import com.monkopedia.ksrpc.toStub

fun main() { 
   //sampleStart 
   // Extend IntrospectableRpcService and add @KsIntrospectable.
// The compiler plugin generates a getIntrospection() implementation
// that returns metadata about the service and its endpoints. 
   //sampleEnd
}
import com.monkopedia.ksrpc.IntrospectableRpcService
import com.monkopedia.ksrpc.annotation.KsIntrospectable
import com.monkopedia.ksrpc.annotation.KsMethod
import com.monkopedia.ksrpc.annotation.KsService
import com.monkopedia.ksrpc.ksrpcEnvironment
import com.monkopedia.ksrpc.serialized
import com.monkopedia.ksrpc.toStub

fun main() { 
   //sampleStart 
   val service = object : CatalogService {
    override suspend fun search(query: String): String = "result"
    override suspend fun count(): Int = 42
}

val env = ksrpcEnvironment { }
val serialized = service.serialized(env)
val stub = serialized.toStub<CatalogService, String>()

// Get the IntrospectionService for this service.
val introspection = stub.getIntrospection()

// Query the service name.
val name = introspection.getServiceName()

// List all endpoints.
val endpoints = introspection.getEndpoints()

// Get detailed info about a specific endpoint (input/output types).
val searchInfo = introspection.getEndpointInfo("search")
val inputType = searchInfo.input
val outputType = searchInfo.output 
   //sampleEnd
}