rpcObject

expect inline fun <T : RpcService> rpcObject(): RpcObject<T>

Helper to get RpcObject for a given RpcService

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")
// 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")
actual inline fun <T : RpcService> rpcObject(): RpcObject<T>

Helper to get RpcObject for a given RpcService

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")
// 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")
actual inline fun <T : RpcService> rpcObject(): RpcObject<T>

Resolve the RpcObject for T.

Resolution order:

  1. If T::class has a companion that is an RpcObject, return it directly.

  2. If T::class has a companion that is an RpcObjectFactory, use the type arguments from typeOf<T>() to build the concrete RpcObject.

  3. 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 though TypedStream itself has no type parameters).

actual inline fun <T : RpcService> rpcObject(): RpcObject<T>

Helper to get RpcObject for a given RpcService

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