rpcObject
Helper to get RpcObject for a given RpcService
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
// Any @Serializable class can be used as input or output to @KsMethod.
// The compiler plugin handles serializer plumbing automatically.
val rpcObj = rpcObject<UserService>()
val endpoint = rpcObj.findEndpoint("create")
//sampleEnd
}Resolution order:
If
T::classhas a companion that is an RpcObject, return it directly.If
T::classhas a companion that is an RpcObjectFactory, use the type arguments fromtypeOf<T>()to build the concrete RpcObject.Otherwise walk the supertypes of
T(preserving type arguments) and return the first supertype whose classifier's companion is an RpcObject or an RpcObjectFactory. For a factory, the type arguments used are taken from THAT supertype's kotlin.reflect.KType (so e.g.interface TypedStream : KsStream<Info>correctly supplies<Info>to the parent's factory even thoughTypedStreamitself has no type parameters).