RpcMethod

class RpcMethod<T : RpcService, I, O>(val endpoint: String, val inputTransform: Transformer<I>, val outputTransform: Transformer<O>, method: ServiceExecutor, val metadata: List<MethodMetadata>, val errorMappings: List<KsErrorMapping> = emptyList(), val contextBindings: List<KsContextMapping> = emptyList())

A wrapper around calling into or from stubs/serialization.

The optional metadata list carries sibling-annotation metadata captured by the ksrpc compiler plugin from annotations on the source method that are themselves annotated @KsMethodMetadata. Transport layers can read it to customize how a call is serialized.

The optional errorMappings list carries @KsError(code, type) bindings captured by the compiler plugin on the source method. Each entry pairs a wire-level integer code with the @Serializable payload type and its KSerializer. Runtime routing (see forwardErrorMap / reverseErrorMap) uses these to translate between thrown exception data and wire-level error envelopes.

The optional contextBindings list carries @KsContext-meta-annotated bindings captured by the compiler plugin from the source method and its enclosing @KsService interface. Each entry holds a KsContextBinding singleton used to propagate per-call coroutine-context values across the wire. See KsContextMapping for details.

Constructors

Link copied to clipboard
constructor(endpoint: String, inputTransform: Transformer<I>, outputTransform: Transformer<O>, method: ServiceExecutor, metadata: List<MethodMetadata>, errorMappings: List<KsErrorMapping> = emptyList(), contextBindings: List<KsContextMapping> = emptyList())

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Forward lookup built from RpcMethod.errorMappings: code → mapping. Used by the client-side error-decoder to resolve an incoming wire-level code back to the captured KSerializer for deserializing the payload. Entries from later @KsError annotations that share a code overwrite earlier ones; duplicate codes on a single method are a programming error that transport validation can surface.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Reverse lookup built from RpcMethod.errorMappings: data::class → mapping. Used by the server-side error-encoder to resolve the thrown data::class back to its bound code + captured KSerializer. Later entries overwrite earlier ones for the same type.

Link copied to clipboard

Returns the timeout in milliseconds configured via @KsTimeout on the source method, or null if no timeout annotation was present.

Functions

Link copied to clipboard
suspend fun <S> call(channel: SerializedService<S>, service: RpcService, input: CallData<S>, callId: RpcCallId?): CallData<S>
Link copied to clipboard
suspend fun <S> callChannel(channel: SerializedService<S>, input: Any?): Any?
Link copied to clipboard

Client-side: convert a CallData.Error into a Throwable using this method's forwardErrorMap. When CallData.Error.errorCode matches a @KsError binding and CallData.Error.errorData decodes successfully with the bound serializer, the deserialized typed Throwable itself is returned (and re-thrown by callChannel) — callers catch (e: MyError) typed.

Link copied to clipboard

Server-side: convert a thrown exception into a CallData.Error using this method's reverseErrorMap. The thrown class IS the wire payload's class — when the throwable's runtime class is assignable to a @KsError-bound type, the bound code + serializer are used and the throwable itself is encoded into the wire format S for inclusion in the error frame. There is no KsrpcException wrapper involved on the server side; users throw MyTypedError(...) directly.

Link copied to clipboard
fun metadata(annotationFqName: String): MethodMetadata?

Look up the captured sibling-annotation metadata with the given fully qualified annotation name, or null if the method was not annotated with such a sibling annotation.