ksrpcEnvironment



fun ksrpcEnvironment(stringFormat: StringFormat = Json, builder: KsrpcEnvironmentBuilder<String>.() -> Unit): KsrpcEnvironment<String>

Creates a string-based KsrpcEnvironment using the given stringFormat (JSON by default).

The builder lambda configures optional settings such as the KsrpcEnvironmentBuilder.errorListener. Pass a custom kotlinx.serialization.StringFormat to control how payloads are encoded on the wire.

Samples

import com.monkopedia.ksrpc.ErrorListener
import com.monkopedia.ksrpc.ksrpcEnvironment
import com.monkopedia.ksrpc.reconfigure
import kotlinx.serialization.json.Json

fun main() { 
   //sampleStart 
   // Create an environment with default settings (JSON serialization).
val env = ksrpcEnvironment { }

// Create an environment with a custom Json configuration.
val customEnv = ksrpcEnvironment(
    Json {
        ignoreUnknownKeys = true
        prettyPrint = true
    }
) { } 
   //sampleEnd
}
import com.monkopedia.ksrpc.ErrorListener
import com.monkopedia.ksrpc.ksrpcEnvironment
import com.monkopedia.ksrpc.reconfigure
import kotlinx.serialization.json.Json

fun main() { 
   //sampleStart 
   // Set an error listener to handle transport-level errors.
val env = ksrpcEnvironment {
    errorListener = ErrorListener { throwable ->
        println("ksrpc error: ${throwable.message}")
    }
}

// Reconfigure an existing environment with a new error listener.
val reconfigured = env.reconfigure {
    errorListener = ErrorListener { throwable ->
        println("Reconfigured handler: ${throwable.message}")
    }
} 
   //sampleEnd
}