Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ internal class RpcIrContext(
}

val dataCast by lazy {
namedFunction("kotlinx.rpc.internal", "dataCast")
namedFunction("kotlinx.rpc.internal", "rpcInternalDataCast")
}

val rpcClientCall by lazy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@ public inline fun <@Rpc reified T : Any> serviceDescriptorOf(): RpcServiceDescri

@ExperimentalRpcApi
public fun <@Rpc T : Any> serviceDescriptorOf(kType: KType): RpcServiceDescriptor<T> {
return serviceDescriptorOf(kType.kClass())
return serviceDescriptorOf(kType.rpcInternalKClass())
}

@ExperimentalRpcApi
public fun <@Rpc T : Any> serviceDescriptorOf(kClass: KClass<T>): RpcServiceDescriptor<T> {
val maybeDescriptor = internalServiceDescriptorOf(kClass)
?: internalError("Unable to find a service descriptor of the $kClass")
?: internalRpcError("Unable to find a service descriptor of the $kClass")

if (maybeDescriptor is RpcServiceDescriptor<*>) {
@Suppress("UNCHECKED_CAST")
return maybeDescriptor as RpcServiceDescriptor<T>
}

internalError(
internalRpcError(
"Located descriptor object is not of a desired type ${RpcServiceDescriptor::class}, " +
"instead found $maybeDescriptor of the class " +
(maybeDescriptor::class.qualifiedClassNameOrNull ?: maybeDescriptor::class)
(maybeDescriptor::class.rpcInternalQualifiedClassNameOrNull ?: maybeDescriptor::class)
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package kotlinx.rpc.internal
Expand All @@ -10,24 +10,24 @@ import kotlin.reflect.KType

@InternalRpcApi
@Suppress("UNCHECKED_CAST")
public fun <T : Any> KType.kClass(): KClass<T> {
public fun <T : Any> KType.rpcInternalKClass(): KClass<T> {
val classifier = classifier ?: error("Expected denotable type, found $this")
val classifierClass = classifier as? KClass<*> ?: error("Expected class type, found $this")

return classifierClass as KClass<T>
}

@InternalRpcApi
public fun internalError(message: String): Nothing {
public fun internalRpcError(message: String): Nothing {
error("Internal kotlinx.rpc error: $message")
}

@InternalRpcApi
public expect val KClass<*>.typeName: String?
public expect val KClass<*>.rpcInternalTypeName: String?

@InternalRpcApi
public expect val KClass<*>.qualifiedClassNameOrNull: String?
public expect val KClass<*>.rpcInternalQualifiedClassNameOrNull: String?

@InternalRpcApi
public val KClass<*>.qualifiedClassName: String get() = qualifiedClassNameOrNull
public val KClass<*>.rpcInternalQualifiedClassName: String get() = rpcInternalQualifiedClassNameOrNull
?: error("Expected qualifiedClassName for $this")
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package kotlinx.rpc.internal

import kotlinx.rpc.internal.utils.InternalRpcApi

@InternalRpcApi
public inline fun <reified T> Any?.dataCast(methodName: String, serviceName: String): T {
public inline fun <reified T> Any?.rpcInternalDataCast(methodName: String, serviceName: String): T {
return this as? T
?: throw IllegalArgumentException(
"Wrong data type for $methodName in service $serviceName. " +
Expand Down
6 changes: 3 additions & 3 deletions core/src/commonMain/kotlin/kotlinx/rpc/withService.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package kotlinx.rpc

import kotlinx.atomicfu.atomic
import kotlinx.rpc.annotations.Rpc
import kotlinx.rpc.descriptor.serviceDescriptorOf
import kotlinx.rpc.internal.kClass
import kotlinx.rpc.internal.rpcInternalKClass
import kotlin.reflect.KClass
import kotlin.reflect.KType

Expand All @@ -33,7 +33,7 @@ public inline fun <@Rpc reified T : Any> RpcClient.withService(): T {
* @return instance of the generated service.
*/
public fun <@Rpc T : Any> RpcClient.withService(serviceKType: KType): T {
return withService(serviceKType.kClass())
return withService(serviceKType.rpcInternalKClass())
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

@file:Suppress("detekt.MatchingDeclarationName")
Expand All @@ -10,9 +10,9 @@ import kotlinx.rpc.internal.utils.InternalRpcApi
import kotlin.reflect.KClass

@InternalRpcApi
public actual val KClass<*>.qualifiedClassNameOrNull: String?
public actual val KClass<*>.rpcInternalQualifiedClassNameOrNull: String?
get() = toString()

@InternalRpcApi
public actual val KClass<*>.typeName: String?
get() = qualifiedClassNameOrNull
public actual val KClass<*>.rpcInternalTypeName: String?
get() = rpcInternalQualifiedClassNameOrNull
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

@file:Suppress("detekt.MatchingDeclarationName")
Expand All @@ -10,9 +10,9 @@ import kotlinx.rpc.internal.utils.InternalRpcApi
import kotlin.reflect.KClass

@InternalRpcApi
public actual val KClass<*>.qualifiedClassNameOrNull: String?
public actual val KClass<*>.rpcInternalQualifiedClassNameOrNull: String?
get() = qualifiedName

@InternalRpcApi
public actual val KClass<*>.typeName: String?
public actual val KClass<*>.rpcInternalTypeName: String?
get() = java.typeName
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

@file:Suppress("detekt.MatchingDeclarationName")
Expand All @@ -10,9 +10,9 @@ import kotlinx.rpc.internal.utils.InternalRpcApi
import kotlin.reflect.KClass

@InternalRpcApi
public actual val KClass<*>.qualifiedClassNameOrNull: String?
public actual val KClass<*>.rpcInternalQualifiedClassNameOrNull: String?
get() = qualifiedName

@InternalRpcApi
public actual val KClass<*>.typeName: String?
get() = qualifiedClassNameOrNull
public actual val KClass<*>.rpcInternalTypeName: String?
get() = rpcInternalQualifiedClassNameOrNull
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

@file:Suppress("detekt.MatchingDeclarationName")
Expand All @@ -10,9 +10,9 @@ import kotlinx.rpc.internal.utils.InternalRpcApi
import kotlin.reflect.KClass

@InternalRpcApi
public actual val KClass<*>.qualifiedClassNameOrNull: String?
public actual val KClass<*>.rpcInternalQualifiedClassNameOrNull: String?
get() = toString()

@InternalRpcApi
public actual val KClass<*>.typeName: String?
get() = qualifiedClassNameOrNull
public actual val KClass<*>.rpcInternalTypeName: String?
get() = rpcInternalQualifiedClassNameOrNull
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

@file:Suppress("detekt.MatchingDeclarationName")
Expand All @@ -10,9 +10,9 @@ import kotlinx.rpc.internal.utils.InternalRpcApi
import kotlin.reflect.KClass

@InternalRpcApi
public actual val KClass<*>.qualifiedClassNameOrNull: String?
public actual val KClass<*>.rpcInternalQualifiedClassNameOrNull: String?
get() = toString()

@InternalRpcApi
public actual val KClass<*>.typeName: String?
get() = qualifiedClassNameOrNull
public actual val KClass<*>.rpcInternalTypeName: String?
get() = rpcInternalQualifiedClassNameOrNull
2 changes: 1 addition & 1 deletion krpc/krpc-client/api/krpc-client.api
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ public abstract class kotlinx/rpc/krpc/client/KrpcClient : kotlinx/rpc/krpc/inte
protected final fun getConfig ()Lkotlinx/rpc/krpc/KrpcConfig$Client;
public synthetic fun getConfig ()Lkotlinx/rpc/krpc/KrpcConfig;
public final fun getCoroutineContext ()Lkotlin/coroutines/CoroutineContext;
protected fun getLogger ()Lkotlinx/rpc/krpc/internal/logging/CommonLogger;
protected final fun getLogger ()Lkotlinx/rpc/krpc/internal/logging/RpcInternalCommonLogger;
}

Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import kotlinx.rpc.annotations.Rpc
import kotlinx.rpc.descriptor.RpcCallable
import kotlinx.rpc.internal.serviceScopeOrNull
import kotlinx.rpc.internal.utils.InternalRpcApi
import kotlinx.rpc.internal.utils.SupervisedCompletableDeferred
import kotlinx.rpc.internal.utils.RpcInternalSupervisedCompletableDeferred
import kotlinx.rpc.internal.utils.getOrNull
import kotlinx.rpc.internal.utils.map.ConcurrentHashMap
import kotlinx.rpc.internal.utils.map.RpcInternalConcurrentHashMap
import kotlinx.rpc.krpc.*
import kotlinx.rpc.krpc.client.internal.KrpcClientConnector
import kotlinx.rpc.krpc.internal.*
import kotlinx.rpc.krpc.internal.logging.CommonLogger
import kotlinx.rpc.krpc.internal.logging.RpcInternalCommonLogger
import kotlinx.serialization.BinaryFormat
import kotlinx.serialization.SerialFormat
import kotlinx.serialization.StringFormat
Expand Down Expand Up @@ -68,7 +68,7 @@ public abstract class KrpcClient(

private val callCounter = atomic(0L)

override val logger: CommonLogger = CommonLogger.logger(objectId())
final override val logger: RpcInternalCommonLogger = RpcInternalCommonLogger.logger(rpcInternalObjectId())

private val serverSupportedPlugins: CompletableDeferred<Set<KrpcPlugin>> = CompletableDeferred()

Expand All @@ -79,7 +79,7 @@ public abstract class KrpcClient(
private var clientCancelled = false

// callId to serviceTypeString
private val cancellingRequests = ConcurrentHashMap<String, String>()
private val cancellingRequests = RpcInternalConcurrentHashMap<String, String>()

init {
coroutineContext.job.invokeOnCompletion(onCancelling = true) {
Expand Down Expand Up @@ -155,7 +155,7 @@ public abstract class KrpcClient(
val callable = call.descriptor.getCallable(call.callableName)
?: error("Unexpected callable '${call.callableName}' for ${call.descriptor.fqName} service")

val deferred = SupervisedCompletableDeferred<T>(serviceScope.coroutineContext.job)
val deferred = RpcInternalSupervisedCompletableDeferred<T>(serviceScope.coroutineContext.job)

/**
* Launched on the service scope (receiver)
Expand All @@ -181,7 +181,7 @@ public abstract class KrpcClient(
val callable = call.descriptor.getCallable(call.callableName)
?: error("Unexpected callable '${call.callableName}' for ${call.descriptor.fqName} service")

val callCompletableResult = SupervisedCompletableDeferred<T>()
val callCompletableResult = RpcInternalSupervisedCompletableDeferred<T>()
val rpcCall = call(call, callable, callCompletableResult)
val result = callCompletableResult.await()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package kotlinx.rpc.krpc

import kotlinx.coroutines.*
import kotlinx.rpc.internal.utils.ExperimentalRpcApi
import kotlinx.rpc.internal.utils.InternalRpcApi
import kotlinx.rpc.internal.utils.map.ConcurrentHashMap
import kotlinx.rpc.internal.utils.map.RpcInternalConcurrentHashMap
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
Expand Down Expand Up @@ -40,7 +40,7 @@ public class StreamScope internal constructor(

private val scopeJob = SupervisorJob(parentContext.job)

private val requests = ConcurrentHashMap<String, CoroutineScope>()
private val requests = RpcInternalConcurrentHashMap<String, CoroutineScope>()

init {
scopeJob.invokeOnCompletion {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package kotlinx.rpc.krpc.internal

import kotlinx.rpc.internal.utils.IndexedEnum
import kotlinx.rpc.internal.utils.RpcInternalIndexedEnum
import kotlinx.rpc.internal.utils.InternalRpcApi
import kotlinx.rpc.krpc.internal.CancellationType.entries

@InternalRpcApi
@Suppress("detekt.MagicNumber")
public enum class CancellationType(override val uniqueIndex: Int) : IndexedEnum {
public enum class CancellationType(override val uniqueIndex: Int) : RpcInternalIndexedEnum {
ENDPOINT(0),
SERVICE(1),
REQUEST(2),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package kotlinx.rpc.krpc.internal

import kotlinx.rpc.internal.typeName
import kotlinx.rpc.internal.rpcInternalTypeName
import kotlinx.rpc.internal.utils.InternalRpcApi

@InternalRpcApi
public fun serializeException(cause: Throwable): SerializedException {
val message = cause.message ?: "Unknown exception"
val stacktrace = cause.stackElements()
val serializedCause = cause.cause?.let { serializeException(it) }
val className = cause::class.typeName ?: ""
val className = cause::class.rpcInternalTypeName ?: ""

return SerializedException(cause.toString(), message, stacktrace, serializedCause, className)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import kotlinx.coroutines.sync.withLock
import kotlinx.rpc.internal.utils.InternalRpcApi
import kotlinx.rpc.krpc.KrpcTransport
import kotlinx.rpc.krpc.KrpcTransportMessage
import kotlinx.rpc.krpc.internal.logging.CommonLogger
import kotlinx.rpc.krpc.internal.logging.DumpLoggerContainer
import kotlinx.rpc.krpc.internal.logging.RpcInternalCommonLogger
import kotlinx.rpc.krpc.internal.logging.RpcInternalDumpLoggerContainer
import kotlinx.serialization.*

@InternalRpcApi
Expand Down Expand Up @@ -47,14 +47,14 @@ public class KrpcConnector<SubscriptionKey>(
private val getKey: KrpcMessage.() -> SubscriptionKey,
) : KrpcMessageSender, CoroutineScope by transport {
private val role = if (isServer) SERVER_ROLE else CLIENT_ROLE
private val logger = CommonLogger.logger(objectId(role))
private val logger = RpcInternalCommonLogger.logger(rpcInternalObjectId(role))

private val mutex = Mutex()

private val waiting = mutableMapOf<SubscriptionKey, MutableList<KrpcMessage>>()
private val subscriptions = mutableMapOf<SubscriptionKey, KrpcMessageHandler>()

private val dumpLogger by lazy { DumpLoggerContainer.provide() }
private val dumpLogger by lazy { RpcInternalDumpLoggerContainer.provide() }

override suspend fun sendMessage(message: KrpcMessage) {
val transportMessage = when (serialFormat) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

package kotlinx.rpc.krpc.internal

import kotlinx.rpc.internal.utils.IndexedEnum
import kotlinx.rpc.internal.utils.RpcInternalIndexedEnum
import kotlinx.rpc.internal.utils.InternalRpcApi
import kotlinx.rpc.internal.utils.ShortEnumKSerializer
import kotlinx.rpc.internal.utils.RpcInternalShortEnumKSerializer
import kotlinx.serialization.Serializable

/**
Expand All @@ -25,7 +25,7 @@ public enum class KrpcPlugin(
* Only for maintenance purposes. Indicates when the plugin was added.
*/
@Suppress("unused") private val since: KrpcVersion,
) : IndexedEnum {
) : RpcInternalIndexedEnum {
/**
* Represents all unknown plugins.
* Endpoint may get this value from a peer, when peer has a newer version and with it some new plugins
Expand Down Expand Up @@ -66,7 +66,7 @@ public enum class KrpcPlugin(
}
}

private class KrpcPluginSerializer : ShortEnumKSerializer<KrpcPlugin>(
private class KrpcPluginSerializer : RpcInternalShortEnumKSerializer<KrpcPlugin>(
kClass = KrpcPlugin::class,
unknownValue = KrpcPlugin.UNKNOWN,
allValues = KrpcPlugin.ALL,
Expand Down
Loading