Package-level declarations

Transport-agnostic abstractions: Connection, SerializedService, ChannelHost, RpcBinaryData, CallData, RpcCallId, CancellationSupport, and WireContextMap. These interfaces form the contract that every transport module implements.

Types

Link copied to clipboard
class ByteArrayBinaryData(data: ByteArray, offset: Int = 0, length: Int = data.size - offset) : RpcBinaryData

RpcBinaryData backed by an in-memory ByteArray. Avoids all streaming and coroutine overhead — transferTo delivers the entire buffer in a single callback, and toByteArray returns the array directly.

Link copied to clipboard
sealed class CallData<T>

Wrapper around data being serialized through calls.

Link copied to clipboard

Transport-level cancellation primitive.

Link copied to clipboard

A SerializedChannel that can call into sub-services.

Link copied to clipboard
Link copied to clipboard
data class ChannelId(val id: String)
Link copied to clipboard

A bidirectional channel that can both host and call services/sub-services.

Link copied to clipboard

Generic interface for things that hold a context that is used when interacting with them.

Link copied to clipboard

Coroutine-context element describing the RPC call currently being handled by a ksrpc dispatcher. Installed at the single chokepoint where the user's handler body is invoked (RpcMethod.call) so that the handler can introspect its own call identity (for correlating progress notifications, streaming side-channels, etc.) via currentRpcCall.

Link copied to clipboard

Transport-agnostic binary data source. Implementations adapt user-facing types (ByteReadChannel, kotlinx.io.Source, okio.BufferedSource, ...) to a shape the ksrpc wire protocol can consume.

Link copied to clipboard
interface RpcCallId

A transport-agnostic identifier for an in-flight RPC call.

Link copied to clipboard

A multi-channel interface for serialized communication, generally shouldn't need to interact directly with this, instead use either ChannelClient or ChannelHost to reference a SerializedService instead.

Link copied to clipboard

Serialized version of a service. This can be transformed to and from a service using serialized and SerializedService.toStub.

Link copied to clipboard

A wrapper around a communication pathway that can be turned into a primary SerializedService.

Link copied to clipboard

A bidirectional channel that can host one service in each direction (1 host and 1 client).

Link copied to clipboard

A wrapper around a communication pathway that can be turned into a primary SerializedService.

Link copied to clipboard
class WireContextCallId(val delegate: RpcCallId?, val wireContextMap: WireContextMap?) : RpcCallId

An RpcCallId wrapper that carries a WireContextMap alongside the original (possibly null) call id. Used by com.monkopedia.ksrpc.RpcMethod.callChannel to forward wire-encoded context values through the call chain without depending on coroutine context propagation, which may not survive through intermediate withContext switches in the in-process channel path.

Link copied to clipboard

Coroutine-context element that carries wire-encoded @KsContext values through the call chain. The stub-side com.monkopedia.ksrpc.RpcMethod.callChannel builds a WireContextMap from the caller's coroutine context (encoding each present com.monkopedia.ksrpc.KsContextBinding via toWire) and installs it so transports can read the values and propagate them across the wire.

Functions

Link copied to clipboard
suspend fun <T> CancellationSupport.awaitRequestCancellable(callId: RpcCallId, response: Deferred<T>): T

Await response and, if the awaiting coroutine is cancelled before completion, invoke CancellationSupport.sendCancel for callId before re-throwing.

Link copied to clipboard
inline suspend fun <T : RpcService, R : RpcService, S> SingleChannelConnection<S>.connect(crossinline host: suspend (R) -> T)

Connects both default channels for a connection (incoming and outgoing).

@JvmName(name = "connectSerialized")
suspend fun <T> SingleChannelConnection<T>.connect(host: suspend (SerializedService<T>) -> SerializedService<T>)

Raw version of connect, performing the same functionality with SerializedService directly.

Link copied to clipboard

Returns the CurrentRpcCallElement installed by the dispatcher for the currently executing handler, or null when not running inside an RPC handler.

Link copied to clipboard
inline suspend fun <T : RpcService, S> SingleChannelHost<S>.registerDefault(service: T)
suspend fun <T : RpcService, S> SingleChannelHost<S>.registerDefault(service: T, obj: RpcObject<T>)

Register a service to be hosted on the default channel.

Link copied to clipboard
inline suspend fun <T : RpcService, S> ChannelHost<S>.registerHost(service: T): ChannelId
suspend fun <T : RpcService, S> ChannelHost<S>.registerHost(service: T, obj: RpcObject<T>): ChannelId

Register a service to be hosted, the ChannelId ollocated to this service is returned. Generally this should not be called directly, as it will happen automatically when services are returned from KsMethod tagged methods.

Link copied to clipboard
inline suspend fun <T> CancellationSupport.withHandlerRegistered(callId: RpcCallId, block: () -> T): T

Utility to bind the currently executing coroutine's Job to callId on a CancellationSupport so that an incoming remote cancel signal cancels this coroutine.