diff --git a/compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RpcIrContext.kt b/compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RpcIrContext.kt index 31c723653..8763b4fc6 100644 --- a/compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RpcIrContext.kt +++ b/compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RpcIrContext.kt @@ -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 { diff --git a/core/src/commonMain/kotlin/kotlinx/rpc/descriptor/RpcServiceDescriptor.kt b/core/src/commonMain/kotlin/kotlinx/rpc/descriptor/RpcServiceDescriptor.kt index aaa9b4fc2..3ace7facc 100644 --- a/core/src/commonMain/kotlin/kotlinx/rpc/descriptor/RpcServiceDescriptor.kt +++ b/core/src/commonMain/kotlin/kotlinx/rpc/descriptor/RpcServiceDescriptor.kt @@ -19,23 +19,23 @@ public inline fun <@Rpc reified T : Any> serviceDescriptorOf(): RpcServiceDescri @ExperimentalRpcApi public fun <@Rpc T : Any> serviceDescriptorOf(kType: KType): RpcServiceDescriptor { - return serviceDescriptorOf(kType.kClass()) + return serviceDescriptorOf(kType.rpcInternalKClass()) } @ExperimentalRpcApi public fun <@Rpc T : Any> serviceDescriptorOf(kClass: KClass): RpcServiceDescriptor { 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 } - 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) ) } diff --git a/core/src/commonMain/kotlin/kotlinx/rpc/internal/ReflectionUtils.kt b/core/src/commonMain/kotlin/kotlinx/rpc/internal/ReflectionUtils.kt index f14870369..74ae6f9ae 100644 --- a/core/src/commonMain/kotlin/kotlinx/rpc/internal/ReflectionUtils.kt +++ b/core/src/commonMain/kotlin/kotlinx/rpc/internal/ReflectionUtils.kt @@ -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 @@ -10,7 +10,7 @@ import kotlin.reflect.KType @InternalRpcApi @Suppress("UNCHECKED_CAST") -public fun KType.kClass(): KClass { +public fun KType.rpcInternalKClass(): KClass { val classifier = classifier ?: error("Expected denotable type, found $this") val classifierClass = classifier as? KClass<*> ?: error("Expected class type, found $this") @@ -18,16 +18,16 @@ public fun KType.kClass(): KClass { } @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") diff --git a/core/src/commonMain/kotlin/kotlinx/rpc/internal/dataCast.kt b/core/src/commonMain/kotlin/kotlinx/rpc/internal/rpcInternalDataCast.kt similarity index 74% rename from core/src/commonMain/kotlin/kotlinx/rpc/internal/dataCast.kt rename to core/src/commonMain/kotlin/kotlinx/rpc/internal/rpcInternalDataCast.kt index 01bb6a9f3..d76e04fce 100644 --- a/core/src/commonMain/kotlin/kotlinx/rpc/internal/dataCast.kt +++ b/core/src/commonMain/kotlin/kotlinx/rpc/internal/rpcInternalDataCast.kt @@ -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 @@ -7,7 +7,7 @@ package kotlinx.rpc.internal import kotlinx.rpc.internal.utils.InternalRpcApi @InternalRpcApi -public inline fun Any?.dataCast(methodName: String, serviceName: String): T { +public inline fun Any?.rpcInternalDataCast(methodName: String, serviceName: String): T { return this as? T ?: throw IllegalArgumentException( "Wrong data type for $methodName in service $serviceName. " + diff --git a/core/src/commonMain/kotlin/kotlinx/rpc/withService.kt b/core/src/commonMain/kotlin/kotlinx/rpc/withService.kt index b82e6e519..73df9f149 100644 --- a/core/src/commonMain/kotlin/kotlinx/rpc/withService.kt +++ b/core/src/commonMain/kotlin/kotlinx/rpc/withService.kt @@ -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 @@ -7,7 +7,7 @@ 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 @@ -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()) } /** diff --git a/core/src/jsMain/kotlin/kotlinx/rpc/internal/ReflectionUtils.js.kt b/core/src/jsMain/kotlin/kotlinx/rpc/internal/ReflectionUtils.js.kt index 7c5988b47..64a7ea786 100644 --- a/core/src/jsMain/kotlin/kotlinx/rpc/internal/ReflectionUtils.js.kt +++ b/core/src/jsMain/kotlin/kotlinx/rpc/internal/ReflectionUtils.js.kt @@ -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") @@ -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 diff --git a/core/src/jvmMain/kotlin/kotlinx/rpc/internal/ReflectionUtils.jvm.kt b/core/src/jvmMain/kotlin/kotlinx/rpc/internal/ReflectionUtils.jvm.kt index 43c88957a..3d6e48961 100644 --- a/core/src/jvmMain/kotlin/kotlinx/rpc/internal/ReflectionUtils.jvm.kt +++ b/core/src/jvmMain/kotlin/kotlinx/rpc/internal/ReflectionUtils.jvm.kt @@ -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") @@ -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 diff --git a/core/src/nativeMain/kotlin/kotlinx/rpc/internal/ReflectionUtils.native.kt b/core/src/nativeMain/kotlin/kotlinx/rpc/internal/ReflectionUtils.native.kt index 38d856587..791b3ec6b 100644 --- a/core/src/nativeMain/kotlin/kotlinx/rpc/internal/ReflectionUtils.native.kt +++ b/core/src/nativeMain/kotlin/kotlinx/rpc/internal/ReflectionUtils.native.kt @@ -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") @@ -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 diff --git a/core/src/wasmJsMain/kotlin/kotlinx/rpc/internal/ReflectionUtils.wasm.kt b/core/src/wasmJsMain/kotlin/kotlinx/rpc/internal/ReflectionUtils.wasm.kt index 7c5988b47..64a7ea786 100644 --- a/core/src/wasmJsMain/kotlin/kotlinx/rpc/internal/ReflectionUtils.wasm.kt +++ b/core/src/wasmJsMain/kotlin/kotlinx/rpc/internal/ReflectionUtils.wasm.kt @@ -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") @@ -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 diff --git a/core/src/wasmWasiMain/kotlin/kotlinx/rpc/internal/ReflectionUtils.wasi.kt b/core/src/wasmWasiMain/kotlin/kotlinx/rpc/internal/ReflectionUtils.wasi.kt index 7c5988b47..64a7ea786 100644 --- a/core/src/wasmWasiMain/kotlin/kotlinx/rpc/internal/ReflectionUtils.wasi.kt +++ b/core/src/wasmWasiMain/kotlin/kotlinx/rpc/internal/ReflectionUtils.wasi.kt @@ -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") @@ -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 diff --git a/krpc/krpc-client/api/krpc-client.api b/krpc/krpc-client/api/krpc-client.api index f93f0a4ad..42ce07884 100644 --- a/krpc/krpc-client/api/krpc-client.api +++ b/krpc/krpc-client/api/krpc-client.api @@ -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; } diff --git a/krpc/krpc-client/src/commonMain/kotlin/kotlinx/rpc/krpc/client/KrpcClient.kt b/krpc/krpc-client/src/commonMain/kotlin/kotlinx/rpc/krpc/client/KrpcClient.kt index 3a31eeacc..cd65fabcb 100644 --- a/krpc/krpc-client/src/commonMain/kotlin/kotlinx/rpc/krpc/client/KrpcClient.kt +++ b/krpc/krpc-client/src/commonMain/kotlin/kotlinx/rpc/krpc/client/KrpcClient.kt @@ -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 @@ -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> = CompletableDeferred() @@ -79,7 +79,7 @@ public abstract class KrpcClient( private var clientCancelled = false // callId to serviceTypeString - private val cancellingRequests = ConcurrentHashMap() + private val cancellingRequests = RpcInternalConcurrentHashMap() init { coroutineContext.job.invokeOnCompletion(onCancelling = true) { @@ -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(serviceScope.coroutineContext.job) + val deferred = RpcInternalSupervisedCompletableDeferred(serviceScope.coroutineContext.job) /** * Launched on the service scope (receiver) @@ -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() + val callCompletableResult = RpcInternalSupervisedCompletableDeferred() val rpcCall = call(call, callable, callCompletableResult) val result = callCompletableResult.await() diff --git a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/StreamScope.kt b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/StreamScope.kt index a52ba6150..8cfb1968f 100644 --- a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/StreamScope.kt +++ b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/StreamScope.kt @@ -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.krpc @@ -7,7 +7,7 @@ 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 @@ -40,7 +40,7 @@ public class StreamScope internal constructor( private val scopeJob = SupervisorJob(parentContext.job) - private val requests = ConcurrentHashMap() + private val requests = RpcInternalConcurrentHashMap() init { scopeJob.invokeOnCompletion { diff --git a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/CancellationType.kt b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/CancellationType.kt index 4922db079..9855e3c6f 100644 --- a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/CancellationType.kt +++ b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/CancellationType.kt @@ -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), diff --git a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/ExceptionUtils.kt b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/ExceptionUtils.kt index c1615260f..29f3dba64 100644 --- a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/ExceptionUtils.kt +++ b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/ExceptionUtils.kt @@ -1,10 +1,10 @@ /* - * 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 @@ -12,7 +12,7 @@ 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) } diff --git a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcConnector.kt b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcConnector.kt index a5fe988f0..ed1b04829 100644 --- a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcConnector.kt +++ b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcConnector.kt @@ -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 @@ -47,14 +47,14 @@ public class KrpcConnector( 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>() private val subscriptions = mutableMapOf() - private val dumpLogger by lazy { DumpLoggerContainer.provide() } + private val dumpLogger by lazy { RpcInternalDumpLoggerContainer.provide() } override suspend fun sendMessage(message: KrpcMessage) { val transportMessage = when (serialFormat) { diff --git a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcPlugin.kt b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcPlugin.kt index 134fc27bb..6804eeb14 100644 --- a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcPlugin.kt +++ b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcPlugin.kt @@ -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 /** @@ -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 @@ -66,7 +66,7 @@ public enum class KrpcPlugin( } } -private class KrpcPluginSerializer : ShortEnumKSerializer( +private class KrpcPluginSerializer : RpcInternalShortEnumKSerializer( kClass = KrpcPlugin::class, unknownValue = KrpcPlugin.UNKNOWN, allValues = KrpcPlugin.ALL, diff --git a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcPluginKey.kt b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcPluginKey.kt index 4cd9b7258..d95526d3f 100644 --- a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcPluginKey.kt +++ b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcPluginKey.kt @@ -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 /** @@ -21,7 +21,10 @@ import kotlinx.serialization.Serializable */ @InternalRpcApi @Serializable(with = KrpcPluginKeySerializer::class) -public enum class KrpcPluginKey(override val uniqueIndex: Int, private val associatedPlugin: KrpcPlugin): IndexedEnum { +public enum class KrpcPluginKey( + override val uniqueIndex: Int, + private val associatedPlugin: KrpcPlugin, +): RpcInternalIndexedEnum { /** * Failed to decode key, possible due to different endpoint versions. */ @@ -65,7 +68,7 @@ public enum class KrpcPluginKey(override val uniqueIndex: Int, private val assoc } } -private class KrpcPluginKeySerializer : ShortEnumKSerializer( +private class KrpcPluginKeySerializer : RpcInternalShortEnumKSerializer( kClass = KrpcPluginKey::class, unknownValue = KrpcPluginKey.UNKNOWN, allValues = KrpcPluginKey.ALL, diff --git a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcServiceHandler.kt b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcServiceHandler.kt index 17b5aa038..487327fd6 100644 --- a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcServiceHandler.kt +++ b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcServiceHandler.kt @@ -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.krpc.internal @@ -14,7 +14,7 @@ import kotlinx.rpc.descriptor.RpcCallable import kotlinx.rpc.descriptor.RpcInvokator import kotlinx.rpc.internal.utils.InternalRpcApi import kotlinx.rpc.krpc.KrpcConfig -import kotlinx.rpc.krpc.internal.logging.CommonLogger +import kotlinx.rpc.krpc.internal.logging.RpcInternalCommonLogger import kotlinx.serialization.BinaryFormat import kotlinx.serialization.KSerializer import kotlinx.serialization.SerialFormat @@ -25,7 +25,7 @@ import kotlinx.serialization.modules.SerializersModule public abstract class KrpcServiceHandler { protected abstract val sender: KrpcMessageSender protected abstract val config: KrpcConfig - protected abstract val logger: CommonLogger + protected abstract val logger: RpcInternalCommonLogger protected suspend fun handleIncomingHotFlows(streamContext: KrpcStreamContext) { for (hotFlow in streamContext.incomingHotFlows) { diff --git a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcStreamContext.kt b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcStreamContext.kt index ba9a09ed3..73fbd3a24 100644 --- a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcStreamContext.kt +++ b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcStreamContext.kt @@ -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.krpc.internal @@ -15,7 +15,7 @@ import kotlinx.coroutines.selects.select import kotlinx.rpc.internal.utils.InternalRpcApi import kotlinx.rpc.internal.utils.getDeferred import kotlinx.rpc.internal.utils.getOrNull -import kotlinx.rpc.internal.utils.map.ConcurrentHashMap +import kotlinx.rpc.internal.utils.map.RpcInternalConcurrentHashMap import kotlinx.rpc.internal.utils.set import kotlinx.rpc.krpc.KrpcConfig import kotlinx.rpc.krpc.StreamScope @@ -62,7 +62,7 @@ public class KrpcStreamContext( private val closed = CompletableDeferred() // thread-safe set - private val closedStreams = ConcurrentHashMap>() + private val closedStreams = RpcInternalConcurrentHashMap>() @InternalRpcApi public inline fun launchIf( @@ -99,13 +99,13 @@ public class KrpcStreamContext( private var incomingStreamsInitialized: Boolean = false private val incomingStreams by lazy { incomingStreamsInitialized = true - ConcurrentHashMap>() + RpcInternalConcurrentHashMap>() } private var incomingChannelsInitialized: Boolean = false private val incomingChannels by lazy { incomingChannelsInitialized = true - ConcurrentHashMap?>>() + RpcInternalConcurrentHashMap?>>() } private var outgoingStreamsInitialized: Boolean = false diff --git a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/ObjectId.kt b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/ObjectId.kt index f93c63c6b..19c6c4054 100644 --- a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/ObjectId.kt +++ b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/ObjectId.kt @@ -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.krpc.internal @@ -9,7 +9,7 @@ import kotlinx.rpc.internal.utils.InternalRpcApi private const val HEX_RADIX = 16 @InternalRpcApi -public fun Any.objectId(vararg tags: String): String { +public fun Any.rpcInternalObjectId(vararg tags: String): String { val tagsString = tags.takeIf { it.isNotEmpty() }?.joinToString { "[$it]" } ?: "" return "${this::class.simpleName}$tagsString[${hashCode().toString(HEX_RADIX)}]" } diff --git a/krpc/krpc-logging/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/logging/CommonLogger.kt b/krpc/krpc-logging/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/logging/RpcInternalCommonLogger.kt similarity index 57% rename from krpc/krpc-logging/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/logging/CommonLogger.kt rename to krpc/krpc-logging/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/logging/RpcInternalCommonLogger.kt index fd658dc83..2b763aa27 100644 --- a/krpc/krpc-logging/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/logging/CommonLogger.kt +++ b/krpc/krpc-logging/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/logging/RpcInternalCommonLogger.kt @@ -1,22 +1,22 @@ /* - * 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.logging import kotlinx.rpc.internal.utils.InternalRpcApi -import kotlinx.rpc.krpc.internal.logging.impl.CommonLoggerFactoryImpl +import kotlinx.rpc.krpc.internal.logging.impl.RpcInternalCommonLoggerFactoryImpl import kotlin.reflect.KClass @InternalRpcApi -public interface CommonLoggerFactory { - public fun getLogger(name: String): CommonLogger +public interface RpcInternalCommonLoggerFactory { + public fun getLogger(name: String): RpcInternalCommonLogger - public fun getLogger(func: () -> Unit): CommonLogger + public fun getLogger(func: () -> Unit): RpcInternalCommonLogger } @InternalRpcApi -public interface CommonLogger { +public interface RpcInternalCommonLogger { public fun debug(msg: () -> Any?) public fun debug(t: Throwable?, msg: () -> Any?) @@ -39,21 +39,21 @@ public interface CommonLogger { @InternalRpcApi public companion object { - private val factory = CommonLoggerFactoryImpl + private val factory = RpcInternalCommonLoggerFactoryImpl - public fun logger(name: String): CommonLogger { + public fun logger(name: String): RpcInternalCommonLogger { return factory.getLogger(name) } - public fun logger(kClass: KClass): CommonLogger { + public fun logger(kClass: KClass): RpcInternalCommonLogger { return logger(kClass::class.simpleName ?: kClass.toString()) } - public inline fun logger(): CommonLogger { + public inline fun logger(): RpcInternalCommonLogger { return logger(T::class) } - public fun logger(func: () -> Unit = {}): CommonLogger { + public fun logger(func: () -> Unit = {}): RpcInternalCommonLogger { return factory.getLogger(func) } } diff --git a/krpc/krpc-logging/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/logging/DumpLogger.kt b/krpc/krpc-logging/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/logging/RpcInternalDumpLogger.kt similarity index 59% rename from krpc/krpc-logging/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/logging/DumpLogger.kt rename to krpc/krpc-logging/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/logging/RpcInternalDumpLogger.kt index 4a10231e3..1405167fe 100644 --- a/krpc/krpc-logging/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/logging/DumpLogger.kt +++ b/krpc/krpc-logging/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/logging/RpcInternalDumpLogger.kt @@ -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.krpc.internal.logging @@ -7,22 +7,22 @@ package kotlinx.rpc.krpc.internal.logging import kotlinx.rpc.internal.utils.InternalRpcApi @InternalRpcApi -public interface DumpLogger { +public interface RpcInternalDumpLogger { public val isEnabled: Boolean public fun dump(vararg tags: String, message: () -> String) } @InternalRpcApi -public object DumpLoggerContainer { - private var logger: DumpLogger? = null +public object RpcInternalDumpLoggerContainer { + private var logger: RpcInternalDumpLogger? = null - public fun set(logger: DumpLogger?) { - DumpLoggerContainer.logger = logger + public fun set(logger: RpcInternalDumpLogger?) { + RpcInternalDumpLoggerContainer.logger = logger } - public fun provide(): DumpLogger { - return object : DumpLogger { + public fun provide(): RpcInternalDumpLogger { + return object : RpcInternalDumpLogger { override val isEnabled: Boolean get() = logger?.isEnabled ?: false override fun dump(vararg tags: String, message: () -> String) { diff --git a/krpc/krpc-logging/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/logging/impl/CommonLoggerImpl.kt b/krpc/krpc-logging/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/logging/impl/RpcInternalCommonLoggerImpl.kt similarity index 61% rename from krpc/krpc-logging/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/logging/impl/CommonLoggerImpl.kt rename to krpc/krpc-logging/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/logging/impl/RpcInternalCommonLoggerImpl.kt index 1b0e8481f..b46ab91c7 100644 --- a/krpc/krpc-logging/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/logging/impl/CommonLoggerImpl.kt +++ b/krpc/krpc-logging/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/logging/impl/RpcInternalCommonLoggerImpl.kt @@ -1,25 +1,25 @@ /* - * 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.logging.impl import io.github.oshai.kotlinlogging.KLogger import io.github.oshai.kotlinlogging.KotlinLogging -import kotlinx.rpc.krpc.internal.logging.CommonLogger -import kotlinx.rpc.krpc.internal.logging.CommonLoggerFactory +import kotlinx.rpc.krpc.internal.logging.RpcInternalCommonLogger +import kotlinx.rpc.krpc.internal.logging.RpcInternalCommonLoggerFactory -internal object CommonLoggerFactoryImpl : CommonLoggerFactory { - override fun getLogger(name: String): CommonLogger { - return CommonLoggerImpl(KotlinLogging.logger(name)) +internal object RpcInternalCommonLoggerFactoryImpl : RpcInternalCommonLoggerFactory { + override fun getLogger(name: String): RpcInternalCommonLogger { + return RpcInternalCommonLoggerImpl(KotlinLogging.logger(name)) } - override fun getLogger(func: () -> Unit): CommonLogger { - return CommonLoggerImpl(KotlinLogging.logger(func)) + override fun getLogger(func: () -> Unit): RpcInternalCommonLogger { + return RpcInternalCommonLoggerImpl(KotlinLogging.logger(func)) } } -internal class CommonLoggerImpl(private val logger: KLogger) : CommonLogger { +internal class RpcInternalCommonLoggerImpl(private val logger: KLogger) : RpcInternalCommonLogger { override fun debug(msg: () -> Any?) { logger.debug(msg) } diff --git a/krpc/krpc-server/src/commonMain/kotlin/kotlinx/rpc/krpc/server/KrpcServer.kt b/krpc/krpc-server/src/commonMain/kotlin/kotlinx/rpc/krpc/server/KrpcServer.kt index 46ae5cc77..8782071d4 100644 --- a/krpc/krpc-server/src/commonMain/kotlin/kotlinx/rpc/krpc/server/KrpcServer.kt +++ b/krpc/krpc-server/src/commonMain/kotlin/kotlinx/rpc/krpc/server/KrpcServer.kt @@ -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.krpc.server @@ -10,11 +10,11 @@ import kotlinx.rpc.annotations.Rpc import kotlinx.rpc.descriptor.RpcServiceDescriptor import kotlinx.rpc.descriptor.serviceDescriptorOf import kotlinx.rpc.internal.utils.InternalRpcApi -import kotlinx.rpc.internal.utils.map.ConcurrentHashMap +import kotlinx.rpc.internal.utils.map.RpcInternalConcurrentHashMap import kotlinx.rpc.krpc.KrpcConfig import kotlinx.rpc.krpc.KrpcTransport import kotlinx.rpc.krpc.internal.* -import kotlinx.rpc.krpc.internal.logging.CommonLogger +import kotlinx.rpc.krpc.internal.logging.RpcInternalCommonLogger import kotlinx.rpc.krpc.server.internal.KrpcServerConnector import kotlinx.rpc.krpc.server.internal.KrpcServerService import kotlin.coroutines.CoroutineContext @@ -49,7 +49,7 @@ public abstract class KrpcServer( // we make a child here, so we can send cancellation messages before closing the connection final override val coroutineContext: CoroutineContext = SupervisorJob(transport.coroutineContext.job) - private val logger = CommonLogger.logger(objectId()) + private val logger = RpcInternalCommonLogger.logger(rpcInternalObjectId()) private val connector by lazy { KrpcServerConnector( @@ -66,10 +66,10 @@ public abstract class KrpcServer( final override var supportedPlugins: Set = emptySet() private set - private val rpcServices = ConcurrentHashMap>() + private val rpcServices = RpcInternalConcurrentHashMap>() // compatibility with clients that do not have serviceId - private var nullRpcServices = ConcurrentHashMap>() + private var nullRpcServices = RpcInternalConcurrentHashMap>() private var cancelledByClient = false diff --git a/krpc/krpc-server/src/commonMain/kotlin/kotlinx/rpc/krpc/server/internal/KrpcServerService.kt b/krpc/krpc-server/src/commonMain/kotlin/kotlinx/rpc/krpc/server/internal/KrpcServerService.kt index 320329d04..2b7785a01 100644 --- a/krpc/krpc-server/src/commonMain/kotlin/kotlinx/rpc/krpc/server/internal/KrpcServerService.kt +++ b/krpc/krpc-server/src/commonMain/kotlin/kotlinx/rpc/krpc/server/internal/KrpcServerService.kt @@ -9,11 +9,11 @@ import kotlinx.coroutines.flow.Flow import kotlinx.rpc.annotations.Rpc import kotlinx.rpc.descriptor.RpcInvokator import kotlinx.rpc.descriptor.RpcServiceDescriptor -import kotlinx.rpc.internal.utils.map.ConcurrentHashMap +import kotlinx.rpc.internal.utils.map.RpcInternalConcurrentHashMap import kotlinx.rpc.krpc.KrpcConfig import kotlinx.rpc.krpc.callScoped import kotlinx.rpc.krpc.internal.* -import kotlinx.rpc.krpc.internal.logging.CommonLogger +import kotlinx.rpc.krpc.internal.logging.RpcInternalCommonLogger import kotlinx.rpc.krpc.streamScopeOrNull import kotlinx.rpc.krpc.withServerStreamScope import kotlinx.serialization.BinaryFormat @@ -29,13 +29,13 @@ internal class KrpcServerService<@Rpc T : Any>( private val connector: KrpcServerConnector, coroutineContext: CoroutineContext, ) : KrpcServiceHandler(), CoroutineScope { - override val logger = CommonLogger.logger(objectId(descriptor.fqName)) + override val logger = RpcInternalCommonLogger.logger(rpcInternalObjectId(descriptor.fqName)) override val sender: KrpcMessageSender get() = connector private val scope: CoroutineScope = this override val coroutineContext: CoroutineContext = coroutineContext.withServerStreamScope() - private val requestMap = ConcurrentHashMap() + private val requestMap = RpcInternalConcurrentHashMap() init { coroutineContext.job.invokeOnCompletion { diff --git a/krpc/krpc-test/src/commonTest/kotlin/kotlinx/rpc/krpc/test/ProtocolTestBase.kt b/krpc/krpc-test/src/commonTest/kotlin/kotlinx/rpc/krpc/test/ProtocolTestBase.kt index f1388db8d..2ca024a48 100644 --- a/krpc/krpc-test/src/commonTest/kotlin/kotlinx/rpc/krpc/test/ProtocolTestBase.kt +++ b/krpc/krpc-test/src/commonTest/kotlin/kotlinx/rpc/krpc/test/ProtocolTestBase.kt @@ -11,12 +11,12 @@ import kotlinx.coroutines.test.TestResult import kotlinx.coroutines.test.TestScope import kotlinx.rpc.RemoteService import kotlinx.rpc.annotations.Rpc -import kotlinx.rpc.internal.utils.hex.hexToReadableBinary +import kotlinx.rpc.internal.utils.hex.rpcInternalHexToReadableBinary import kotlinx.rpc.krpc.KrpcConfig import kotlinx.rpc.krpc.client.KrpcClient -import kotlinx.rpc.krpc.internal.logging.CommonLogger -import kotlinx.rpc.krpc.internal.logging.DumpLogger -import kotlinx.rpc.krpc.internal.logging.DumpLoggerContainer +import kotlinx.rpc.krpc.internal.logging.RpcInternalCommonLogger +import kotlinx.rpc.krpc.internal.logging.RpcInternalDumpLogger +import kotlinx.rpc.krpc.internal.logging.RpcInternalDumpLoggerContainer import kotlinx.rpc.krpc.rpcClientConfig import kotlinx.rpc.krpc.rpcServerConfig import kotlinx.rpc.krpc.serialization.json.json @@ -52,15 +52,15 @@ abstract class ProtocolTestBase { serverConfig: KrpcConfig.Server, private val scope: TestScope ) : CoroutineScope by scope { - private val logger = object : DumpLogger { - private val _log = CommonLogger.logger("ProtocolTestDump") + private val logger = object : RpcInternalDumpLogger { + private val _log = RpcInternalCommonLogger.logger("ProtocolTestDump") override val isEnabled: Boolean = true private val isBinary = clientConfig.serialFormatInitializer.build() is BinaryFormat override fun dump(vararg tags: String, message: () -> String) { val text = if (isBinary) { val hex = message() - "$hex (readable: ${hex.hexToReadableBinary()})" + "$hex (readable: ${hex.rpcInternalHexToReadableBinary()})" } else { message() } @@ -70,7 +70,7 @@ abstract class ProtocolTestBase { } init { - DumpLoggerContainer.set(logger) + RpcInternalDumpLoggerContainer.set(logger) } val transport = LocalTransport() diff --git a/krpc/krpc-test/src/commonTest/kotlin/kotlinx/rpc/krpc/test/TransportTest.kt b/krpc/krpc-test/src/commonTest/kotlin/kotlinx/rpc/krpc/test/TransportTest.kt index 63b7ebc58..c85f45d91 100644 --- a/krpc/krpc-test/src/commonTest/kotlin/kotlinx/rpc/krpc/test/TransportTest.kt +++ b/krpc/krpc-test/src/commonTest/kotlin/kotlinx/rpc/krpc/test/TransportTest.kt @@ -8,13 +8,12 @@ import kotlinx.atomicfu.atomic import kotlinx.coroutines.* import kotlinx.coroutines.test.TestResult import kotlinx.coroutines.test.TestScope -import kotlinx.coroutines.test.runTest import kotlinx.rpc.* import kotlinx.rpc.annotations.Rpc import kotlinx.rpc.krpc.KrpcConfigBuilder -import kotlinx.rpc.krpc.internal.logging.CommonLogger -import kotlinx.rpc.krpc.internal.logging.DumpLogger -import kotlinx.rpc.krpc.internal.logging.DumpLoggerContainer +import kotlinx.rpc.krpc.internal.logging.RpcInternalCommonLogger +import kotlinx.rpc.krpc.internal.logging.RpcInternalDumpLogger +import kotlinx.rpc.krpc.internal.logging.RpcInternalDumpLoggerContainer import kotlinx.rpc.krpc.rpcClientConfig import kotlinx.rpc.krpc.rpcServerConfig import kotlinx.rpc.krpc.serialization.json.json @@ -79,9 +78,9 @@ class TransportTest { } private fun runTest(block: suspend TestScope.() -> Unit): TestResult = kotlinx.coroutines.test.runTest { - val logger = CommonLogger.logger("TransportTest") + val logger = RpcInternalCommonLogger.logger("TransportTest") - DumpLoggerContainer.set(object : DumpLogger { + RpcInternalDumpLoggerContainer.set(object : RpcInternalDumpLogger { override val isEnabled: Boolean = true override fun dump(vararg tags: String, message: () -> String) { @@ -91,7 +90,7 @@ class TransportTest { block() - DumpLoggerContainer.set(null) + RpcInternalDumpLoggerContainer.set(null) } @Test diff --git a/krpc/krpc-test/src/commonTest/kotlin/kotlinx/rpc/krpc/test/cancellation/CancellationToolkit.kt b/krpc/krpc-test/src/commonTest/kotlin/kotlinx/rpc/krpc/test/cancellation/CancellationToolkit.kt index 430abff7e..1614ff10d 100644 --- a/krpc/krpc-test/src/commonTest/kotlin/kotlinx/rpc/krpc/test/cancellation/CancellationToolkit.kt +++ b/krpc/krpc-test/src/commonTest/kotlin/kotlinx/rpc/krpc/test/cancellation/CancellationToolkit.kt @@ -8,9 +8,9 @@ import kotlinx.coroutines.* import kotlinx.coroutines.test.TestResult import kotlinx.coroutines.test.runTest import kotlinx.rpc.krpc.KrpcConfigBuilder -import kotlinx.rpc.krpc.internal.logging.CommonLogger -import kotlinx.rpc.krpc.internal.logging.DumpLogger -import kotlinx.rpc.krpc.internal.logging.DumpLoggerContainer +import kotlinx.rpc.krpc.internal.logging.RpcInternalCommonLogger +import kotlinx.rpc.krpc.internal.logging.RpcInternalDumpLogger +import kotlinx.rpc.krpc.internal.logging.RpcInternalDumpLoggerContainer import kotlinx.rpc.krpc.rpcClientConfig import kotlinx.rpc.krpc.rpcServerConfig import kotlinx.rpc.krpc.serialization.json.json @@ -28,10 +28,10 @@ fun runCancellationTest(body: suspend CancellationToolkit.() -> Unit): TestResul } class CancellationToolkit(scope: CoroutineScope) : CoroutineScope by scope { - private val logger = CommonLogger.logger("CancellationTest") + private val logger = RpcInternalCommonLogger.logger("CancellationTest") init { - DumpLoggerContainer.set(object : DumpLogger { + RpcInternalDumpLoggerContainer.set(object : RpcInternalDumpLogger { override val isEnabled: Boolean = true override fun dump(vararg tags: String, message: () -> String) { diff --git a/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/api/ApiModel.kt b/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/api/ApiModel.kt index 982229933..b4cb92c86 100644 --- a/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/api/ApiModel.kt +++ b/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/api/ApiModel.kt @@ -1,11 +1,11 @@ /* - * 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.test.api -import kotlinx.rpc.internal.kClass -import kotlinx.rpc.internal.qualifiedClassName +import kotlinx.rpc.internal.rpcInternalKClass +import kotlinx.rpc.internal.rpcInternalQualifiedClassName import kotlinx.rpc.krpc.test.api.util.GoldUtils.NewLine import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -21,7 +21,7 @@ inline fun checkProtocolApi(): ApiTestContext { @PublishedApi internal fun ApiTestContext.traverseClasses(rootType: KType) { - traverseClasses(rootType.kClass(), rootType) + traverseClasses(rootType.rpcInternalKClass(), rootType) } private fun ApiTestContext.traverseClasses(root: KClass<*>, rootType: KType) { @@ -53,7 +53,7 @@ private fun ApiTestContext.checkSealed(clazz: KClass<*>) { } private fun ApiTestContext.checkType(kClass: KClass<*>, type: KType) { - val name = kClass.qualifiedClassName + val name = kClass.rpcInternalQualifiedClassName when { name in stdLibTypes -> {} // ignore @@ -114,7 +114,7 @@ private fun ApiTestContext.serialProperties(kClass: KClass<*>): List { private fun ApiTestContext.serialProperty(property: KProperty<*>): String { traverseClasses(property.returnType) val type = property.returnType - val kClass = type.kClass() + val kClass = type.rpcInternalKClass() val nullable = if (type.isMarkedNullable) "Nullable" else null return lines( @@ -130,7 +130,7 @@ private fun KClass<*>.serialAndDeclaredName(): String { } private fun KClass<*>.serialName(): String { - return serialName(qualifiedClassName) + return serialName(rpcInternalQualifiedClassName) } private fun KProperty<*>.serialName(): String { @@ -142,7 +142,7 @@ private fun KAnnotatedElement.serialName(original: String): String { } private fun KClass<*>.declaredName(): String? { - return declaredName(qualifiedClassName) + return declaredName(rpcInternalQualifiedClassName) } private fun KProperty<*>.declaredName(): String? { diff --git a/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/api/IndexedEnumTest.kt b/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/api/IndexedEnumTest.kt index 162af9c21..cad263d6a 100644 --- a/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/api/IndexedEnumTest.kt +++ b/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/api/IndexedEnumTest.kt @@ -1,10 +1,10 @@ /* - * 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.test.api -import kotlinx.rpc.internal.utils.IndexedEnum +import kotlinx.rpc.internal.utils.RpcInternalIndexedEnum import kotlinx.rpc.krpc.test.api.ApiVersioningTest.Companion.INDEXED_ENUM_DUMPS_DIR import kotlinx.rpc.krpc.test.api.util.GoldComparable import kotlinx.rpc.krpc.test.api.util.GoldComparisonResult @@ -13,7 +13,7 @@ import kotlinx.rpc.krpc.test.api.util.checkGold import kotlin.test.assertTrue import kotlin.test.fail -inline fun testEnum() where E : IndexedEnum, E : Enum { +inline fun testEnum() where E : RpcInternalIndexedEnum, E : Enum { testEnum(enumValues(), E::class.simpleName!!) { EnumGoldContent.fromText(it) } } @@ -21,7 +21,7 @@ fun testEnum( values: Array, name: String, fromText: (String) -> EnumGoldContent, -) where E : IndexedEnum, E : Enum { +) where E : RpcInternalIndexedEnum, E : Enum { val indexes = values.map { it.uniqueIndex } for (i in indexes) { assertTrue("All indexes should be in [0..65500] range") { i in 0..65500 } @@ -53,7 +53,7 @@ fun testEnum( } class EnumGoldContent(private val values: Set) : - GoldComparable> where E : IndexedEnum, E : Enum { + GoldComparable> where E : RpcInternalIndexedEnum, E : Enum { override fun compare(other: EnumGoldContent): GoldComparisonResult { val diff = values - other.values return if (diff.isEmpty()) { @@ -70,7 +70,9 @@ class EnumGoldContent(private val values: Set) : } companion object { - inline fun fromText(text: String): EnumGoldContent where E : IndexedEnum, E : Enum { + inline fun fromText( + text: String, + ): EnumGoldContent where E : RpcInternalIndexedEnum, E : Enum { return fromText(text, E::class.simpleName!!) { enumValueOf(it) } } @@ -78,7 +80,7 @@ class EnumGoldContent(private val values: Set) : text: String, enumName: String, enumValueOf: (String) -> E - ): EnumGoldContent where E : IndexedEnum, E : Enum { + ): EnumGoldContent where E : RpcInternalIndexedEnum, E : Enum { val values = text.split(GoldUtils.NewLine).map { val (name, index) = it.split(" - ") val enum = try { diff --git a/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/api/WireSamplingTestScope.kt b/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/api/WireSamplingTestScope.kt index 46f9b0578..60ab4e205 100644 --- a/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/api/WireSamplingTestScope.kt +++ b/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/api/WireSamplingTestScope.kt @@ -12,11 +12,11 @@ import kotlinx.coroutines.test.TestResult import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.runTest import kotlinx.rpc.annotations.Rpc -import kotlinx.rpc.internal.utils.hex.hexToReadableBinary +import kotlinx.rpc.internal.utils.hex.rpcInternalHexToReadableBinary import kotlinx.rpc.krpc.KrpcTransportMessage -import kotlinx.rpc.krpc.internal.logging.CommonLogger -import kotlinx.rpc.krpc.internal.logging.DumpLogger -import kotlinx.rpc.krpc.internal.logging.DumpLoggerContainer +import kotlinx.rpc.krpc.internal.logging.RpcInternalCommonLogger +import kotlinx.rpc.krpc.internal.logging.RpcInternalDumpLogger +import kotlinx.rpc.krpc.internal.logging.RpcInternalDumpLoggerContainer import kotlinx.rpc.krpc.rpcClientConfig import kotlinx.rpc.krpc.rpcServerConfig import kotlinx.rpc.krpc.serialization.KrpcSerialFormatConfiguration @@ -52,7 +52,7 @@ fun wireSamplingTest(name: String, sampling: suspend WireSamplingTestScope.() -> } class WireSamplingTestScope(private val sampleName: String, scope: TestScope) : CoroutineScope by scope { - private val logger = CommonLogger.logger("[WireTest] [$sampleName]") + private val logger = RpcInternalCommonLogger.logger("[WireTest] [$sampleName]") private var clientSampling: (suspend SamplingService.() -> Unit)? = null suspend fun sample( @@ -193,7 +193,7 @@ class WireSamplingTestScope(private val sampleName: String, scope: TestScope) : } } -private class WireToolkit(scope: CoroutineScope, format: SamplingFormat, val logger: CommonLogger? = null) { +private class WireToolkit(scope: CoroutineScope, format: SamplingFormat, val logger: RpcInternalCommonLogger? = null) { val transport = LocalTransport(scope) val client by lazy { @@ -220,14 +220,14 @@ private class WireToolkit(scope: CoroutineScope, format: SamplingFormat, val log val logs = mutableListOf() - val dumpLogger = object : DumpLogger { + val dumpLogger = object : RpcInternalDumpLogger { override val isEnabled: Boolean = true override fun dump(vararg tags: String, message: () -> String) { if (logger != null) { val log = when (format) { SamplingFormat.Json -> message() - SamplingFormat.Protobuf -> message().hexToReadableBinary() + SamplingFormat.Protobuf -> message().rpcInternalHexToReadableBinary() } logger.info { "DumpLog: ${tags.joinToString(" ") { "[$it]" }} $log" } @@ -239,11 +239,11 @@ private class WireToolkit(scope: CoroutineScope, format: SamplingFormat, val log suspend fun stop() { transport.coroutineContext.job.cancelAndJoin() - DumpLoggerContainer.set(null) + RpcInternalDumpLoggerContainer.set(null) } init { - DumpLoggerContainer.set(dumpLogger) + RpcInternalDumpLoggerContainer.set(dumpLogger) } private inline fun <@Rpc reified Service : Any> Service.withConsistentServiceId(): Service = apply { @@ -354,7 +354,7 @@ private class WireContent( val base = "[${dump.role}] [${dump.phase}] $ ${dump.log}" if (commentBinaryOutput) { - val decodedBytes = dump.log.hexToReadableBinary() + val decodedBytes = dump.log.rpcInternalHexToReadableBinary() "// decoded: $decodedBytes" + GoldUtils.NewLine + base } else { diff --git a/tests/compiler-plugin-tests/src/testData/box/customParameterTypes.fir.ir.txt b/tests/compiler-plugin-tests/src/testData/box/customParameterTypes.fir.ir.txt index 7536f8fe3..c456f8e0c 100644 --- a/tests/compiler-plugin-tests/src/testData/box/customParameterTypes.fir.ir.txt +++ b/tests/compiler-plugin-tests/src/testData/box/customParameterTypes.fir.ir.txt @@ -385,7 +385,7 @@ FILE fqName: fileName:/customParameterTypes.kt VALUE_PARAMETER name:data index:1 type:kotlin.Any? BLOCK_BODY VAR IR_TEMPORARY_VARIABLE name:tmp_10 type:.BoxService.$rpcServiceStub.test1$rpcMethod [val] - CALL 'public final fun dataCast (methodName: kotlin.String, serviceName: kotlin.String): T of kotlinx.rpc.internal.dataCast declared in kotlinx.rpc.internal' type=.BoxService.$rpcServiceStub.test1$rpcMethod origin=null + CALL 'public final fun rpcInternalDataCast (methodName: kotlin.String, serviceName: kotlin.String): T of kotlinx.rpc.internal.rpcInternalDataCast declared in kotlinx.rpc.internal' type=.BoxService.$rpcServiceStub.test1$rpcMethod origin=null : .BoxService.$rpcServiceStub.test1$rpcMethod $receiver: GET_VAR 'data: kotlin.Any? declared in .BoxService.$rpcServiceStub.Companion.test1Invokator.' type=kotlin.Any? origin=null methodName: CONST String type=kotlin.String value="test1" @@ -412,7 +412,7 @@ FILE fqName: fileName:/customParameterTypes.kt VALUE_PARAMETER name:data index:1 type:kotlin.Any? BLOCK_BODY VAR IR_TEMPORARY_VARIABLE name:tmp_11 type:.BoxService.$rpcServiceStub.test2$rpcMethod [val] - CALL 'public final fun dataCast (methodName: kotlin.String, serviceName: kotlin.String): T of kotlinx.rpc.internal.dataCast declared in kotlinx.rpc.internal' type=.BoxService.$rpcServiceStub.test2$rpcMethod origin=null + CALL 'public final fun rpcInternalDataCast (methodName: kotlin.String, serviceName: kotlin.String): T of kotlinx.rpc.internal.rpcInternalDataCast declared in kotlinx.rpc.internal' type=.BoxService.$rpcServiceStub.test2$rpcMethod origin=null : .BoxService.$rpcServiceStub.test2$rpcMethod $receiver: GET_VAR 'data: kotlin.Any? declared in .BoxService.$rpcServiceStub.Companion.test2Invokator.' type=kotlin.Any? origin=null methodName: CONST String type=kotlin.String value="test2" diff --git a/tests/compiler-plugin-tests/src/testData/box/flowParameter.fir.ir.txt b/tests/compiler-plugin-tests/src/testData/box/flowParameter.fir.ir.txt index 58410c0f9..97af63102 100644 --- a/tests/compiler-plugin-tests/src/testData/box/flowParameter.fir.ir.txt +++ b/tests/compiler-plugin-tests/src/testData/box/flowParameter.fir.ir.txt @@ -73,7 +73,7 @@ FILE fqName: fileName:/flowParameter.kt VALUE_PARAMETER name:data index:1 type:kotlin.Any? BLOCK_BODY VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:.BoxService.$rpcServiceStub.stream$rpcMethod [val] - CALL 'public final fun dataCast (methodName: kotlin.String, serviceName: kotlin.String): T of kotlinx.rpc.internal.dataCast declared in kotlinx.rpc.internal' type=.BoxService.$rpcServiceStub.stream$rpcMethod origin=null + CALL 'public final fun rpcInternalDataCast (methodName: kotlin.String, serviceName: kotlin.String): T of kotlinx.rpc.internal.rpcInternalDataCast declared in kotlinx.rpc.internal' type=.BoxService.$rpcServiceStub.stream$rpcMethod origin=null : .BoxService.$rpcServiceStub.stream$rpcMethod $receiver: GET_VAR 'data: kotlin.Any? declared in .BoxService.$rpcServiceStub.Companion.streamInvokator.' type=kotlin.Any? origin=null methodName: CONST String type=kotlin.String value="stream" diff --git a/tests/compiler-plugin-tests/src/testData/box/multiModule.fir.ir.txt b/tests/compiler-plugin-tests/src/testData/box/multiModule.fir.ir.txt index 14f1a0c39..4f9de7d61 100644 --- a/tests/compiler-plugin-tests/src/testData/box/multiModule.fir.ir.txt +++ b/tests/compiler-plugin-tests/src/testData/box/multiModule.fir.ir.txt @@ -74,7 +74,7 @@ FILE fqName: fileName:/module_lib_multiModule.kt VALUE_PARAMETER name:data index:1 type:kotlin.Any? BLOCK_BODY VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:.BoxService.$rpcServiceStub.simple$rpcMethod [val] - CALL 'public final fun dataCast (methodName: kotlin.String, serviceName: kotlin.String): T of kotlinx.rpc.internal.dataCast declared in kotlinx.rpc.internal' type=.BoxService.$rpcServiceStub.simple$rpcMethod origin=null + CALL 'public final fun rpcInternalDataCast (methodName: kotlin.String, serviceName: kotlin.String): T of kotlinx.rpc.internal.rpcInternalDataCast declared in kotlinx.rpc.internal' type=.BoxService.$rpcServiceStub.simple$rpcMethod origin=null : .BoxService.$rpcServiceStub.simple$rpcMethod $receiver: GET_VAR 'data: kotlin.Any? declared in .BoxService.$rpcServiceStub.Companion.simpleInvokator.' type=kotlin.Any? origin=null methodName: CONST String type=kotlin.String value="simple" diff --git a/tests/compiler-plugin-tests/src/testData/box/simple.fir.ir.txt b/tests/compiler-plugin-tests/src/testData/box/simple.fir.ir.txt index befa0d70e..f10778d16 100644 --- a/tests/compiler-plugin-tests/src/testData/box/simple.fir.ir.txt +++ b/tests/compiler-plugin-tests/src/testData/box/simple.fir.ir.txt @@ -73,7 +73,7 @@ FILE fqName: fileName:/simple.kt VALUE_PARAMETER name:data index:1 type:kotlin.Any? BLOCK_BODY VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:.BoxService.$rpcServiceStub.simple$rpcMethod [val] - CALL 'public final fun dataCast (methodName: kotlin.String, serviceName: kotlin.String): T of kotlinx.rpc.internal.dataCast declared in kotlinx.rpc.internal' type=.BoxService.$rpcServiceStub.simple$rpcMethod origin=null + CALL 'public final fun rpcInternalDataCast (methodName: kotlin.String, serviceName: kotlin.String): T of kotlinx.rpc.internal.rpcInternalDataCast declared in kotlinx.rpc.internal' type=.BoxService.$rpcServiceStub.simple$rpcMethod origin=null : .BoxService.$rpcServiceStub.simple$rpcMethod $receiver: GET_VAR 'data: kotlin.Any? declared in .BoxService.$rpcServiceStub.Companion.simpleInvokator.' type=kotlin.Any? origin=null methodName: CONST String type=kotlin.String value="simple" diff --git a/utils/build.gradle.kts b/utils/build.gradle.kts index 35bbe4335..23b50d830 100644 --- a/utils/build.gradle.kts +++ b/utils/build.gradle.kts @@ -1,8 +1,7 @@ /* - * 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. */ -import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode import util.applyAtomicfuPlugin plugins { @@ -20,6 +19,4 @@ kotlin { } } } - - explicitApi = ExplicitApiMode.Disabled } diff --git a/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/InternalRpcApi.kt b/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/InternalRpcApi.kt index c030f2372..0c96f7ae2 100644 --- a/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/InternalRpcApi.kt +++ b/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/InternalRpcApi.kt @@ -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.utils @@ -8,5 +8,4 @@ package kotlinx.rpc.internal.utils message = "This is internal kotlinx.rpc api that is subject to change and should not be used", level = RequiresOptIn.Level.ERROR, ) -@InternalRpcApi public annotation class InternalRpcApi diff --git a/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/ShortEnumKSerializer.kt b/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/RpcInternalShortEnumKSerializer.kt similarity index 76% rename from utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/ShortEnumKSerializer.kt rename to utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/RpcInternalShortEnumKSerializer.kt index caaa6c143..c7a277a00 100644 --- a/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/ShortEnumKSerializer.kt +++ b/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/RpcInternalShortEnumKSerializer.kt @@ -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.utils @@ -16,19 +16,19 @@ import kotlin.reflect.KClass * Better unique value holder than ordinal. Easier for testing and maintaining. */ @InternalRpcApi -interface IndexedEnum { +public interface RpcInternalIndexedEnum { /** * Values between 0 and 65500 are allowed, other are reserved for testing. */ - val uniqueIndex: Int + public val uniqueIndex: Int } @InternalRpcApi -abstract class ShortEnumKSerializer( +public abstract class RpcInternalShortEnumKSerializer( kClass: KClass, - val unknownValue: E, - val allValues: Iterable, -) : KSerializer where E : Enum, E : IndexedEnum { + public val unknownValue: E, + public val allValues: Iterable, +) : KSerializer where E : Enum, E : RpcInternalIndexedEnum { override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor( serialName = "ShortEnumKSerializer<${kClass.simpleName}>", kind = PrimitiveKind.SHORT, // short can hold 65536 entries, should be more than enough @@ -44,7 +44,7 @@ abstract class ShortEnumKSerializer( encoder.encodeShort(shortValue) } - companion object { - const val MODULO: Int = 32768 + public companion object { + public const val MODULO: Int = 32768 } } diff --git a/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/SupervisedCompletableDeferred.kt b/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/RpcInternalSupervisedCompletableDeferred.kt similarity index 60% rename from utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/SupervisedCompletableDeferred.kt rename to utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/RpcInternalSupervisedCompletableDeferred.kt index 51e83a6c5..969cb2277 100644 --- a/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/SupervisedCompletableDeferred.kt +++ b/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/RpcInternalSupervisedCompletableDeferred.kt @@ -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.utils @@ -13,7 +13,9 @@ import kotlinx.coroutines.job * Cancels when parent is canceled, but not otherwise */ @InternalRpcApi -class SupervisedCompletableDeferred(parent: Job) : CompletableDeferred by CompletableDeferred() { +public class RpcInternalSupervisedCompletableDeferred( + parent: Job, +) : CompletableDeferred by CompletableDeferred() { init { val handle = parent.invokeOnCompletion { cause -> if (cause != null) { @@ -28,6 +30,6 @@ class SupervisedCompletableDeferred(parent: Job) : CompletableDeferred by } @InternalRpcApi -suspend fun SupervisedCompletableDeferred(): SupervisedCompletableDeferred { - return SupervisedCompletableDeferred(currentCoroutineContext().job) +public suspend fun RpcInternalSupervisedCompletableDeferred(): RpcInternalSupervisedCompletableDeferred { + return RpcInternalSupervisedCompletableDeferred(currentCoroutineContext().job) } diff --git a/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/deferredUtil.kt b/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/deferredUtil.kt index 80fef37cf..978c8c38d 100644 --- a/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/deferredUtil.kt +++ b/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/deferredUtil.kt @@ -1,23 +1,25 @@ /* - * 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.utils import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.rpc.internal.utils.map.ConcurrentHashMap +import kotlinx.rpc.internal.utils.map.RpcInternalConcurrentHashMap @InternalRpcApi -fun ConcurrentHashMap>.getDeferred(key: K): CompletableDeferred { +public fun RpcInternalConcurrentHashMap>.getDeferred( + key: K, +): CompletableDeferred { return computeIfAbsent(key) { CompletableDeferred() } } @InternalRpcApi -operator fun ConcurrentHashMap>.set(key: K, value: V) { +public operator fun RpcInternalConcurrentHashMap>.set(key: K, value: V) { getDeferred(key).complete(value) } @InternalRpcApi @OptIn(ExperimentalCoroutinesApi::class) -fun CompletableDeferred?.getOrNull() = if (this != null && isCompleted) this.getCompleted() else null +public fun CompletableDeferred?.getOrNull() = if (this != null && isCompleted) this.getCompleted() else null diff --git a/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/hex/HexBytes.kt b/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/hex/HexBytes.kt index 67568b6ed..beaeed660 100644 --- a/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/hex/HexBytes.kt +++ b/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/hex/HexBytes.kt @@ -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.utils.hex @@ -8,7 +8,7 @@ import kotlinx.rpc.internal.utils.InternalRpcApi @OptIn(ExperimentalStdlibApi::class) @InternalRpcApi -fun String.hexToReadableBinary(): String { +public fun String.rpcInternalHexToReadableBinary(): String { return hexToByteArray().joinToString("") { byte -> byte.toInt().toChar().display() } diff --git a/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/kClassSafeCast.kt b/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/kClassSafeCast.kt deleted file mode 100644 index b58cb271a..000000000 --- a/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/kClassSafeCast.kt +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package kotlinx.rpc.internal.utils - -import kotlin.reflect.KClass - -@Suppress("UNCHECKED_CAST") -fun KClass<*>.safeCast() = this as R diff --git a/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/map/ConcurrentHashMap.kt b/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/map/ConcurrentHashMap.kt deleted file mode 100644 index b22c758a3..000000000 --- a/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/map/ConcurrentHashMap.kt +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. - */ - -package kotlinx.rpc.internal.utils.map - -import kotlinx.rpc.internal.utils.InternalRpcApi - -@InternalRpcApi -interface ConcurrentHashMap { - fun put(key: K, value: V): V? - - operator fun set(key: K, value: V) { - put(key, value) - } - - fun computeIfAbsent(key: K, computeValue: () -> V): V - - operator fun get(key: K): V? - - fun remove(key: K): V? - - fun clear() - - fun containsKey(key: K): Boolean - - val entries: Set> - - val keys: Collection - - val values: Collection - - data class Entry( - val key: K, - val value: V, - ) -} - -@InternalRpcApi -expect fun ConcurrentHashMap(initialSize: Int = 32): ConcurrentHashMap diff --git a/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/map/RpcInternalConcurrentHashMap.kt b/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/map/RpcInternalConcurrentHashMap.kt new file mode 100644 index 000000000..6fb7d6672 --- /dev/null +++ b/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/map/RpcInternalConcurrentHashMap.kt @@ -0,0 +1,42 @@ +/* + * 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.utils.map + +import kotlinx.rpc.internal.utils.InternalRpcApi + +@InternalRpcApi +public interface RpcInternalConcurrentHashMap { + public fun put(key: K, value: V): V? + + public operator fun set(key: K, value: V) { + put(key, value) + } + + public fun computeIfAbsent(key: K, computeValue: () -> V): V + + public operator fun get(key: K): V? + + public fun remove(key: K): V? + + public fun clear() + + public fun containsKey(key: K): Boolean + + public val entries: Set> + + public val keys: Collection + + public val values: Collection + + public data class Entry( + val key: K, + val value: V, + ) +} + +@InternalRpcApi +public expect fun RpcInternalConcurrentHashMap( + initialSize: Int = 32, +): RpcInternalConcurrentHashMap diff --git a/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/map/SynchronizedHashMap.kt b/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/map/SynchronizedHashMap.kt index 39182e496..ae588405c 100644 --- a/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/map/SynchronizedHashMap.kt +++ b/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/map/SynchronizedHashMap.kt @@ -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.utils.map @@ -7,7 +7,7 @@ package kotlinx.rpc.internal.utils.map import kotlinx.atomicfu.locks.SynchronizedObject import kotlinx.atomicfu.locks.synchronized -internal class SynchronizedHashMap : ConcurrentHashMap, SynchronizedObject() { +internal class SynchronizedHashMap : RpcInternalConcurrentHashMap, SynchronizedObject() { private val map = hashMapOf() override fun put(key: K, value: V): V? = synchronized(this) { @@ -34,8 +34,8 @@ internal class SynchronizedHashMap : ConcurrentHashMap, S map.containsKey(key) } - override val entries: Set> - get() = synchronized(this) { map.entries }.map { ConcurrentHashMap.Entry(it.key, it.value) }.toSet() + override val entries: Set> + get() = synchronized(this) { map.entries }.map { RpcInternalConcurrentHashMap.Entry(it.key, it.value) }.toSet() override val keys: Collection get() = synchronized(this) { map.keys } diff --git a/utils/src/jsMain/kotlin/kotlinx/rpc/internal/utils/map/ConcurrentHashMap.js.kt b/utils/src/jsMain/kotlin/kotlinx/rpc/internal/utils/map/ConcurrentHashMap.js.kt index 7de0eaee3..f53a53d35 100644 --- a/utils/src/jsMain/kotlin/kotlinx/rpc/internal/utils/map/ConcurrentHashMap.js.kt +++ b/utils/src/jsMain/kotlin/kotlinx/rpc/internal/utils/map/ConcurrentHashMap.js.kt @@ -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.utils.map @@ -7,6 +7,8 @@ package kotlinx.rpc.internal.utils.map import kotlinx.rpc.internal.utils.InternalRpcApi @InternalRpcApi -actual fun ConcurrentHashMap(initialSize: Int): ConcurrentHashMap { +public actual fun RpcInternalConcurrentHashMap( + initialSize: Int, +): RpcInternalConcurrentHashMap { return SynchronizedHashMap() } diff --git a/utils/src/jvmMain/kotlin/kotlinx/rpc/internal/utils/map/ConcurrentHashMap.jvm.kt b/utils/src/jvmMain/kotlin/kotlinx/rpc/internal/utils/map/ConcurrentHashMap.jvm.kt index c3222fe98..5aa01899f 100644 --- a/utils/src/jvmMain/kotlin/kotlinx/rpc/internal/utils/map/ConcurrentHashMap.jvm.kt +++ b/utils/src/jvmMain/kotlin/kotlinx/rpc/internal/utils/map/ConcurrentHashMap.jvm.kt @@ -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.utils.map @@ -7,11 +7,13 @@ package kotlinx.rpc.internal.utils.map import kotlinx.rpc.internal.utils.InternalRpcApi @InternalRpcApi -actual fun ConcurrentHashMap(initialSize: Int): ConcurrentHashMap { +public actual fun RpcInternalConcurrentHashMap( + initialSize: Int, +): RpcInternalConcurrentHashMap { return ConcurrentHashMapJvm(initialSize) } -private class ConcurrentHashMapJvm(initialSize: Int) : ConcurrentHashMap { +private class ConcurrentHashMapJvm(initialSize: Int) : RpcInternalConcurrentHashMap { private val map = java.util.concurrent.ConcurrentHashMap(initialSize) override fun put(key: K, value: V): V? { @@ -38,8 +40,8 @@ private class ConcurrentHashMapJvm(initialSize: Int) : Concurre return map.containsKey(key) } - override val entries: Set> - get() = map.entries.map { ConcurrentHashMap.Entry(it.key, it.value) }.toSet() + override val entries: Set> + get() = map.entries.map { RpcInternalConcurrentHashMap.Entry(it.key, it.value) }.toSet() override val keys: Collection get() = map.keys diff --git a/utils/src/nativeMain/kotlin/kotlinx/rpc/internal/utils/map/ConcurrentHashMap.native.kt b/utils/src/nativeMain/kotlin/kotlinx/rpc/internal/utils/map/ConcurrentHashMap.native.kt index 7de0eaee3..f53a53d35 100644 --- a/utils/src/nativeMain/kotlin/kotlinx/rpc/internal/utils/map/ConcurrentHashMap.native.kt +++ b/utils/src/nativeMain/kotlin/kotlinx/rpc/internal/utils/map/ConcurrentHashMap.native.kt @@ -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.utils.map @@ -7,6 +7,8 @@ package kotlinx.rpc.internal.utils.map import kotlinx.rpc.internal.utils.InternalRpcApi @InternalRpcApi -actual fun ConcurrentHashMap(initialSize: Int): ConcurrentHashMap { +public actual fun RpcInternalConcurrentHashMap( + initialSize: Int, +): RpcInternalConcurrentHashMap { return SynchronizedHashMap() } diff --git a/utils/src/wasmJsMain/kotlin/kotlinx/rpc/internal/utils/map/ConcurrentHashMap.wasm.kt b/utils/src/wasmJsMain/kotlin/kotlinx/rpc/internal/utils/map/ConcurrentHashMap.wasm.kt index 7de0eaee3..579f19afa 100644 --- a/utils/src/wasmJsMain/kotlin/kotlinx/rpc/internal/utils/map/ConcurrentHashMap.wasm.kt +++ b/utils/src/wasmJsMain/kotlin/kotlinx/rpc/internal/utils/map/ConcurrentHashMap.wasm.kt @@ -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.utils.map @@ -7,6 +7,6 @@ package kotlinx.rpc.internal.utils.map import kotlinx.rpc.internal.utils.InternalRpcApi @InternalRpcApi -actual fun ConcurrentHashMap(initialSize: Int): ConcurrentHashMap { +public actual fun RpcInternalConcurrentHashMap(initialSize: Int): RpcInternalConcurrentHashMap { return SynchronizedHashMap() } diff --git a/utils/src/wasmWasiMain/kotlin/kotlinx/rpc/internal/utils/map/ConcurrentHashMap.wasi.kt b/utils/src/wasmWasiMain/kotlin/kotlinx/rpc/internal/utils/map/ConcurrentHashMap.wasi.kt index 7de0eaee3..579f19afa 100644 --- a/utils/src/wasmWasiMain/kotlin/kotlinx/rpc/internal/utils/map/ConcurrentHashMap.wasi.kt +++ b/utils/src/wasmWasiMain/kotlin/kotlinx/rpc/internal/utils/map/ConcurrentHashMap.wasi.kt @@ -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.utils.map @@ -7,6 +7,6 @@ package kotlinx.rpc.internal.utils.map import kotlinx.rpc.internal.utils.InternalRpcApi @InternalRpcApi -actual fun ConcurrentHashMap(initialSize: Int): ConcurrentHashMap { +public actual fun RpcInternalConcurrentHashMap(initialSize: Int): RpcInternalConcurrentHashMap { return SynchronizedHashMap() }