CallData

sealed class CallData<T>

Wrapper around data being serialized through calls.

Has three variants:

  • Serialized — a normal successful payload encoded in the wire format T.

  • Binary — a binary payload (streamed via RpcBinaryData).

  • Error — an error response carrying an integer code, a human-readable message, and an optional typed payload encoded in T (matching the successful-payload encoding so a transport can reuse the same serialization machinery for both).

The variant is the discriminator. Transports must natively encode and decode each variant rather than smuggling errors through Serialized with out-of-band markers.

Inheritors

Types

Link copied to clipboard
data class Binary<T>(value: RpcBinaryData) : CallData<T>
Link copied to clipboard
object Companion
Link copied to clipboard
data class Error<T>(val errorCode: Int, val errorMessage: String, val errorData: T? = null) : CallData<T>

Error response. errorCode discriminates the error type — typically a @KsError-bound user code, with sentinels com.monkopedia.ksrpc.KsrpcException.ENDPOINT_NOT_FOUND_CODE and com.monkopedia.ksrpc.KsrpcException.INTERNAL_ERROR_CODE for the built-in cases. errorMessage is human-readable. errorData is the optional typed payload encoded in the wire format's native type Tnull when no @KsError binding matched. readSerialized returns errorData (it is the same wire-format T as a Serialized payload — naturally reusable by transports / serializers).

Link copied to clipboard
data class Serialized<T>(value: T) : CallData<T>

Properties

Link copied to clipboard
open val errorCode: Int?

Code for Error variants; null otherwise. Lets transports populate native error fields without pattern-matching on the variant.

Link copied to clipboard
open val errorMessage: String?

Human-readable message for Error variants; null otherwise.

Link copied to clipboard
abstract val isBinary: Boolean
Link copied to clipboard
open val isError: Boolean

Convenience: true iff this is an Error variant.

Functions

Link copied to clipboard
abstract fun readBinary(): RpcBinaryData

Get the RpcBinaryData for the binary data held by this call. If this is not binary data then throws IllegalStateException.

Link copied to clipboard
abstract fun readSerialized(): T

Read the serialized content of this object. If this is binary data then throws IllegalStateException.