ResultTransformer

Transformer emitted by the ksrpc compiler plugin for @KsMethod functions whose return type is kotlin.Result<O> (issue #133).

Result<O> is purely a client/server ergonomic transform over the existing O-method protocol — kotlin.Result itself is never serialized (it has no kotlinx serializer). On the wire a Result<O> method is byte-for-byte identical to a plain O method:

  • Server: a returned Result.success serializes the inner O exactly as a plain O method would (via inner); a returned Result.failure is encoded through the SAME @KsError/RpcMethod.encodeError path as a thrown exception, so Result.failure(e) is indistinguishable on the wire from throw e.

  • Client: an error response decodes to Result.failure (NOT thrown); a success response decodes to Result.success. A Result-returning stub never throws except for cancellation.

  • Cancellation: CancellationException is never folded into the Result — it propagates on both sides to preserve structured concurrency.

This type is @KsrpcInternal — user code does not reference it directly; the compiler plugin emits constructor calls to it in codegen.

Constructors

Link copied to clipboard
constructor(inner: Transformer<O>)

Properties

Link copied to clipboard
open override val hasContent: Boolean
Link copied to clipboard

Functions

Link copied to clipboard
open suspend override fun <S> transform(input: Result<O>, channel: SerializedService<S>): CallData<S>
Link copied to clipboard
open suspend override fun <S> transformOutcome(output: Result<O>, channel: SerializedService<S>, encodeError: (Throwable) -> CallData.Error<S>): CallData<S>

Server-side boundary hook (issue #133). Invoked by RpcMethod.call with the value returned by the handler. The default implementation simply delegates to transform; transformers that need to observe the failure channel (e.g. ResultTransformer for Result<O> return types) override this to fold a returned failure into the wire-level error frame via encodeError.

Link copied to clipboard
open suspend override fun <S> untransform(data: CallData<S>, channel: SerializedService<S>): Result<O>
Link copied to clipboard
open suspend override fun <S> untransformOutcome(data: CallData<S>, channel: SerializedService<S>, decodeError: (CallData.Error<S>) -> Throwable): Result<O>

Client-side boundary hook (issue #133). Invoked by RpcMethod.callChannel with the raw wire response (which may be a CallData.Error). The default implementation throws the decoded error — preserving today's behaviour — and otherwise delegates to untransform. ResultTransformer overrides this to wrap the outcome in a kotlin.Result instead of throwing.