diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2f36920e..2a968521 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -102,7 +102,7 @@ A few things to remember: * Every public API (including functions, classes, objects and so on) should be documented, every parameter, property, return types and exceptions should be described properly. * A Public API that is not intended to be used by end-users that couldn't be made private/internal due to technical reasons, - should be marked with `@InternalRPCApi` annotation. + should be marked with `@InternalRpcApi` annotation. ### Commit messages diff --git a/README.md b/README.md index 125e43e3..c7ac24f5 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ Then, choose how do you want your service to communicate. For example, you can u ```kotlin fun main() { embeddedServer(Netty, 8080) { - install(RPC) + install(Krpc) routing { rpc("/awesome") { rpcConfig { @@ -61,7 +61,7 @@ fun main() { ``` To connect to the server use the following [Ktor Client](https://ktor.io/docs/create-client.html) setup: ```kotlin -val rpcClient = HttpClient { installRPC() }.rpc { +val rpcClient = HttpClient { installKrpc() }.rpc { url("ws://localhost:8080/awesome") rpcConfig { diff --git a/compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RPCDeclarationScanner.kt b/compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RpcDeclarationScanner.kt similarity index 96% rename from compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RPCDeclarationScanner.kt rename to compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RpcDeclarationScanner.kt index 241b01a6..3f1766b6 100644 --- a/compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RPCDeclarationScanner.kt +++ b/compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RpcDeclarationScanner.kt @@ -16,13 +16,13 @@ import org.jetbrains.kotlin.ir.util.dumpKotlinLike /** * This class scans user declared RPC service - * and returns all necessary information for code generation by [RPCStubGenerator]. + * and returns all necessary information for code generation by [RpcStubGenerator]. * * Some checks are preformed during scanning, * but all user-friendly errors are expected to be thrown by frontend plugins */ -internal object RPCDeclarationScanner { - fun scanServiceDeclaration(service: IrClass, ctx: RPCIrContext, logger: MessageCollector): ServiceDeclaration { +internal object RpcDeclarationScanner { + fun scanServiceDeclaration(service: IrClass, ctx: RpcIrContext, logger: MessageCollector): ServiceDeclaration { var stubClass: IrClass? = null val declarations = service.declarations.memoryOptimizedMap { declaration -> 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 similarity index 98% rename from compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RPCIrContext.kt rename to compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RpcIrContext.kt index 6d9fcee3..e268443e 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 @@ -19,7 +19,7 @@ import org.jetbrains.kotlin.ir.util.properties import org.jetbrains.kotlin.platform.konan.isNative import org.jetbrains.kotlin.types.Variance -internal class RPCIrContext( +internal class RpcIrContext( val pluginContext: IrPluginContext, val versionSpecificApi: VersionSpecificApi, ) { @@ -98,7 +98,7 @@ internal class RPCIrContext( } val rpcEagerFieldAnnotation by lazy { - getRpcIrClassSymbol("RPCEagerField") + getRpcIrClassSymbol("RpcEagerField") } val rpcServiceDescriptor by lazy { @@ -200,7 +200,7 @@ internal class RPCIrContext( val lazyGetValue by lazy { namedFunction("kotlin", "getValue") { - it.owner.extensionReceiverParameter?.type?.classOrNull == this@RPCIrContext.lazy + it.owner.extensionReceiverParameter?.type?.classOrNull == this@RpcIrContext.lazy } } diff --git a/compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RPCIrExtension.kt b/compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RpcIrExtension.kt similarity index 82% rename from compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RPCIrExtension.kt rename to compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RpcIrExtension.kt index f528b676..a5222064 100644 --- a/compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RPCIrExtension.kt +++ b/compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RpcIrExtension.kt @@ -11,16 +11,16 @@ import org.jetbrains.kotlin.cli.common.messages.MessageCollector import org.jetbrains.kotlin.config.CompilerConfiguration import org.jetbrains.kotlin.ir.declarations.IrModuleFragment -class RPCIrExtension(configuration: CompilerConfiguration) : IrGenerationExtension { +class RpcIrExtension(configuration: CompilerConfiguration) : IrGenerationExtension { private val logger = configuration.get(VersionSpecificApi.INSTANCE.messageCollectorKey, MessageCollector.NONE) override fun generate( moduleFragment: IrModuleFragment, pluginContext: IrPluginContext, ) { - val context = RPCIrContext(pluginContext, VersionSpecificApi.INSTANCE) + val context = RpcIrContext(pluginContext, VersionSpecificApi.INSTANCE) - val processor = RPCIrServiceProcessor(logger) + val processor = RpcIrServiceProcessor(logger) moduleFragment.transform(processor, context) } } diff --git a/compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RPCIrServiceProcessor.kt b/compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RpcIrServiceProcessor.kt similarity index 70% rename from compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RPCIrServiceProcessor.kt rename to compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RpcIrServiceProcessor.kt index e450eb7f..b2d8dd78 100644 --- a/compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RPCIrServiceProcessor.kt +++ b/compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RpcIrServiceProcessor.kt @@ -11,11 +11,11 @@ import org.jetbrains.kotlin.ir.declarations.IrClass import org.jetbrains.kotlin.ir.util.hasAnnotation import org.jetbrains.kotlin.ir.visitors.IrElementTransformer -internal class RPCIrServiceProcessor( +internal class RpcIrServiceProcessor( @Suppress("unused") private val logger: MessageCollector, -) : IrElementTransformer { - override fun visitClass(declaration: IrClass, data: RPCIrContext): IrStatement { +) : IrElementTransformer { + override fun visitClass(declaration: IrClass, data: RpcIrContext): IrStatement { if (declaration.hasAnnotation(RpcClassId.rpcAnnotation)) { processService(declaration, data) } @@ -23,8 +23,8 @@ internal class RPCIrServiceProcessor( return super.visitClass(declaration, data) } - private fun processService(service: IrClass, context: RPCIrContext) { - val declaration = RPCDeclarationScanner.scanServiceDeclaration(service, context, logger) - RPCStubGenerator(declaration, context, logger).generate() + private fun processService(service: IrClass, context: RpcIrContext) { + val declaration = RpcDeclarationScanner.scanServiceDeclaration(service, context, logger) + RpcStubGenerator(declaration, context, logger).generate() } } diff --git a/compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RPCStubGenerator.kt b/compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RpcStubGenerator.kt similarity index 99% rename from compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RPCStubGenerator.kt rename to compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RpcStubGenerator.kt index 1be0da76..177c4c7e 100644 --- a/compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RPCStubGenerator.kt +++ b/compiler-plugin/compiler-plugin-backend/src/main/core/kotlinx/rpc/codegen/extension/RpcStubGenerator.kt @@ -45,9 +45,9 @@ private object Descriptor { } @Suppress("detekt.LargeClass", "detekt.TooManyFunctions") -internal class RPCStubGenerator( +internal class RpcStubGenerator( private val declaration: ServiceDeclaration, - private val ctx: RPCIrContext, + private val ctx: RpcIrContext, @Suppress("unused") private val logger: MessageCollector, ) { @@ -253,7 +253,7 @@ internal class RPCStubGenerator( /** * RPC fields. - * Can be of two kinds: Lazy and Eager (defined by `@RPCEagerField` annotation) + * Can be of two kinds: Lazy and Eager (defined by `@RpcEagerField` annotation) * * Lazy: * ``` kotlin @@ -623,7 +623,7 @@ internal class RPCStubGenerator( * ``` * * This method generates missing getters and backing fields' values. - * And adds RPCMethodClassArguments supertype with `asArray` method implemented. + * And adds RpcMethodClassArguments supertype with `asArray` method implemented. * * Resulting class: * ```kotlin @@ -631,7 +631,7 @@ internal class RPCStubGenerator( * class hello$rpcMethod( * val arg1: String, * val arg2: Int, - * ) : RPCMethodClassArguments { + * ) : RpcMethodClassArguments { * // or emptyArray when no arguments * override fun asArray(): Array = arrayOf(arg1, arg2) * } diff --git a/compiler-plugin/compiler-plugin-cli/src/main-resources/latest/META-INF/services/org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor b/compiler-plugin/compiler-plugin-cli/src/main-resources/latest/META-INF/services/org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor index 61cf7463..faa9c245 100644 --- a/compiler-plugin/compiler-plugin-cli/src/main-resources/latest/META-INF/services/org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor +++ b/compiler-plugin/compiler-plugin-cli/src/main-resources/latest/META-INF/services/org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor @@ -2,4 +2,4 @@ # Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. # -kotlinx.rpc.codegen.RPCCommandLineProcessor +kotlinx.rpc.codegen.RpcCommandLineProcessor diff --git a/compiler-plugin/compiler-plugin-cli/src/main-resources/latest/META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar b/compiler-plugin/compiler-plugin-cli/src/main-resources/latest/META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar index 04b0b782..1df6db12 100644 --- a/compiler-plugin/compiler-plugin-cli/src/main-resources/latest/META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar +++ b/compiler-plugin/compiler-plugin-cli/src/main-resources/latest/META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar @@ -2,4 +2,4 @@ # Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. # -kotlinx.rpc.codegen.RPCCompilerPlugin +kotlinx.rpc.codegen.RpcCompilerPlugin diff --git a/compiler-plugin/compiler-plugin-cli/src/main/latest/kotlinx/rpc/codegen/RPCCompilerPlugin.kt b/compiler-plugin/compiler-plugin-cli/src/main/latest/kotlinx/rpc/codegen/RpcCompilerPlugin.kt similarity index 85% rename from compiler-plugin/compiler-plugin-cli/src/main/latest/kotlinx/rpc/codegen/RPCCompilerPlugin.kt rename to compiler-plugin/compiler-plugin-cli/src/main/latest/kotlinx/rpc/codegen/RpcCompilerPlugin.kt index aa701011..3fae78fd 100644 --- a/compiler-plugin/compiler-plugin-cli/src/main/latest/kotlinx/rpc/codegen/RPCCompilerPlugin.kt +++ b/compiler-plugin/compiler-plugin-cli/src/main/latest/kotlinx/rpc/codegen/RpcCompilerPlugin.kt @@ -4,7 +4,7 @@ package kotlinx.rpc.codegen -import kotlinx.rpc.codegen.extension.RPCIrExtension +import kotlinx.rpc.codegen.extension.RpcIrExtension import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension import org.jetbrains.kotlin.compiler.plugin.CliOption import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor @@ -14,14 +14,14 @@ import org.jetbrains.kotlin.config.CompilerConfiguration import org.jetbrains.kotlin.fir.extensions.FirExtensionRegistrarAdapter @OptIn(ExperimentalCompilerApi::class) -class RPCCommandLineProcessor : CommandLineProcessor { +class RpcCommandLineProcessor : CommandLineProcessor { override val pluginId = "kotlinx.rpc.compiler-plugin" override val pluginOptions = emptyList() } @OptIn(ExperimentalCompilerApi::class) -class RPCCompilerPlugin : CompilerPluginRegistrar() { +class RpcCompilerPlugin : CompilerPluginRegistrar() { override val supportsK2: Boolean = true override fun ExtensionStorage.registerExtensions(configuration: CompilerConfiguration) { @@ -33,6 +33,6 @@ class RPCCompilerPlugin : CompilerPluginRegistrar() { fun CompilerPluginRegistrar.ExtensionStorage.registerRpcExtensions(configuration: CompilerConfiguration) { VersionSpecificApi.INSTANCE = VersionSpecificApiImpl - IrGenerationExtension.registerExtension(RPCIrExtension(configuration)) + IrGenerationExtension.registerExtension(RpcIrExtension(configuration)) FirExtensionRegistrarAdapter.registerExtension(FirRpcExtensionRegistrar(configuration)) } diff --git a/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/FirGenerationKeys.kt b/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/FirGenerationKeys.kt index ebe25d34..6dd60983 100644 --- a/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/FirGenerationKeys.kt +++ b/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/FirGenerationKeys.kt @@ -12,30 +12,30 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlinx.serialization.compiler.fir.SerializationPluginKey -internal class RPCGeneratedStubKey( +internal class RpcGeneratedStubKey( private val serviceName: Name, val functions: List>, ) : GeneratedDeclarationKey() { override fun toString(): String { - return "RPCGeneratedStubKey.$serviceName" + return "RpcGeneratedStubKey.$serviceName" } } -internal val FirBasedSymbol<*>.generatedRpcServiceStubKey: RPCGeneratedStubKey? get() = - (origin as? FirDeclarationOrigin.Plugin)?.key as? RPCGeneratedStubKey +internal val FirBasedSymbol<*>.generatedRpcServiceStubKey: RpcGeneratedStubKey? get() = + (origin as? FirDeclarationOrigin.Plugin)?.key as? RpcGeneratedStubKey -internal class RPCGeneratedRpcMethodClassKey( +internal class RpcGeneratedRpcMethodClassKey( val rpcMethod: FirFunctionSymbol<*>, ) : GeneratedDeclarationKey() { val isObject = rpcMethod.valueParameterSymbols.isEmpty() override fun toString(): String { - return "RPCGeneratedRpcMethodClassKey.${rpcMethod.name}" + return "RpcGeneratedRpcMethodClassKey.${rpcMethod.name}" } } -internal val FirBasedSymbol<*>.generatedRpcMethodClassKey: RPCGeneratedRpcMethodClassKey? get() = - (origin as? FirDeclarationOrigin.Plugin)?.key as? RPCGeneratedRpcMethodClassKey +internal val FirBasedSymbol<*>.generatedRpcMethodClassKey: RpcGeneratedRpcMethodClassKey? get() = + (origin as? FirDeclarationOrigin.Plugin)?.key as? RpcGeneratedRpcMethodClassKey internal object FirRpcServiceStubCompanionObject : GeneratedDeclarationKey() { override fun toString(): String { diff --git a/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/FirRPCExtensionRegistrar.kt b/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/FirRpcExtensionRegistrar.kt similarity index 100% rename from compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/FirRPCExtensionRegistrar.kt rename to compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/FirRpcExtensionRegistrar.kt diff --git a/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/FirRPCServiceGenerator.kt b/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/FirRpcServiceGenerator.kt similarity index 97% rename from compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/FirRPCServiceGenerator.kt rename to compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/FirRpcServiceGenerator.kt index ea301564..aacd4837 100644 --- a/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/FirRPCServiceGenerator.kt +++ b/compiler-plugin/compiler-plugin-k2/src/main/core/kotlinx/rpc/codegen/FirRpcServiceGenerator.kt @@ -84,7 +84,7 @@ class FirRpcServiceGenerator( * * - Companion object of the service stub and method classes. * If we generate this companion object, we will have [FirClassSymbol.origin] - * of [classSymbol] be set to [RPCGeneratedStubKey], + * of [classSymbol] be set to [RpcGeneratedStubKey], * because we're inside the previously generated service stub class. * The same goes for method classes too. * So we return [SpecialNames.DEFAULT_NAME_FOR_COMPANION_OBJECT] @@ -92,7 +92,7 @@ class FirRpcServiceGenerator( * * - Inside method classes. * Method classes will too have their nested declarations. - * We detect them by using [RPCGeneratedRpcMethodClassKey]. + * We detect them by using [RpcGeneratedRpcMethodClassKey]. * Nested declarations for these classes are provided by the serialization plugin. * These declarations can be of two types: serializable object and serializable classes. * In the case of objects, @@ -183,11 +183,11 @@ class FirRpcServiceGenerator( private fun generateRpcMethodClass( owner: FirClassSymbol<*>, name: Name, - rpcServiceStubKey: RPCGeneratedStubKey, + rpcServiceStubKey: RpcGeneratedStubKey, ): FirClassLikeSymbol<*> { val methodName = name.rpcMethodName val rpcMethod = rpcServiceStubKey.functions.single { it.name == methodName } - val rpcMethodClassKey = RPCGeneratedRpcMethodClassKey(rpcMethod) + val rpcMethodClassKey = RpcGeneratedRpcMethodClassKey(rpcMethod) val classKind = if (rpcMethodClassKey.isObject) ClassKind.OBJECT else ClassKind.CLASS val rpcMethodClass = createNestedClass( @@ -261,7 +261,7 @@ class FirRpcServiceGenerator( .filterIsInstance() .map { it.symbol } - return createNestedClass(owner, RpcNames.SERVICE_STUB_NAME, RPCGeneratedStubKey(owner.name, functions)) { + return createNestedClass(owner, RpcNames.SERVICE_STUB_NAME, RpcGeneratedStubKey(owner.name, functions)) { visibility = Visibilities.Public modality = Modality.FINAL }.symbol @@ -293,7 +293,7 @@ class FirRpcServiceGenerator( private fun getCallableNamesForRpcMethodClass( classSymbol: FirClassSymbol<*>, context: MemberGenerationContext, - rpcMethodClassKey: RPCGeneratedRpcMethodClassKey, + rpcMethodClassKey: RpcGeneratedRpcMethodClassKey, ): Set { return if (rpcMethodClassKey.isObject) { // add .serializer() method for a serializable object @@ -321,7 +321,7 @@ class FirRpcServiceGenerator( */ private fun generateConstructorsForRpcMethodClass( context: MemberGenerationContext, - rpcMethodClassKey: RPCGeneratedRpcMethodClassKey, + rpcMethodClassKey: RpcGeneratedRpcMethodClassKey, ): List { if (rpcMethodClassKey.isObject) { return createDefaultPrivateConstructor(context.owner, rpcMethodClassKey).symbol.let(::listOf) @@ -366,7 +366,7 @@ class FirRpcServiceGenerator( private fun generatePropertiesForRpcMethodClass( callableId: CallableId, owner: FirClassSymbol<*>, - rpcMethodClassKey: RPCGeneratedRpcMethodClassKey, + rpcMethodClassKey: RpcGeneratedRpcMethodClassKey, ): List { val valueParam = rpcMethodClassKey.rpcMethod.valueParameterSymbols.find { it.name == callableId.callableName diff --git a/core/api/core.api b/core/api/core.api index 6432b7a0..76243050 100644 --- a/core/api/core.api +++ b/core/api/core.api @@ -3,16 +3,6 @@ public final class kotlinx/rpc/AwaitFieldInitializationKt { public static final fun awaitFieldInitialization (Lkotlinx/rpc/RemoteService;Lkotlin/reflect/KClass;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } -public abstract interface class kotlinx/rpc/RPC : kotlinx/coroutines/CoroutineScope { -} - -public abstract interface annotation class kotlinx/rpc/RPCEagerField : java/lang/annotation/Annotation { -} - -public abstract interface class kotlinx/rpc/RPCServer : kotlinx/coroutines/CoroutineScope { - public abstract fun registerService (Lkotlin/reflect/KClass;Lkotlin/jvm/functions/Function1;)V -} - public final class kotlinx/rpc/RegisterFieldKt { public static final fun registerPlainFlowField (Lkotlinx/rpc/RpcClient;Lkotlinx/coroutines/CoroutineScope;Lkotlinx/rpc/descriptor/RpcServiceDescriptor;Ljava/lang/String;J)Lkotlinx/coroutines/flow/Flow; public static final fun registerSharedFlowField (Lkotlinx/rpc/RpcClient;Lkotlinx/coroutines/CoroutineScope;Lkotlinx/rpc/descriptor/RpcServiceDescriptor;Ljava/lang/String;J)Lkotlinx/coroutines/flow/SharedFlow; @@ -45,7 +35,14 @@ public abstract interface class kotlinx/rpc/RpcClient : kotlinx/coroutines/Corou public abstract fun provideStubContext (J)Lkotlin/coroutines/CoroutineContext; } -public final class kotlinx/rpc/UninitializedRPCFieldException : java/lang/Exception { +public abstract interface annotation class kotlinx/rpc/RpcEagerField : java/lang/annotation/Annotation { +} + +public abstract interface class kotlinx/rpc/RpcServer : kotlinx/coroutines/CoroutineScope { + public abstract fun registerService (Lkotlin/reflect/KClass;Lkotlin/jvm/functions/Function1;)V +} + +public final class kotlinx/rpc/UninitializedRpcFieldException : java/lang/Exception { public fun (Ljava/lang/String;Lkotlin/reflect/KProperty;)V public fun getMessage ()Ljava/lang/String; } @@ -87,7 +84,6 @@ public final class kotlinx/rpc/descriptor/RpcParameter { public abstract interface class kotlinx/rpc/descriptor/RpcServiceDescriptor { public abstract fun createInstance (JLkotlinx/rpc/RpcClient;)Lkotlinx/rpc/RemoteService; public abstract fun getCallable (Ljava/lang/String;)Lkotlinx/rpc/descriptor/RpcCallable; - public abstract fun getFields (Lkotlinx/rpc/RemoteService;)Ljava/util/List; public abstract fun getFqName ()Ljava/lang/String; } diff --git a/core/src/commonMain/kotlin/kotlinx/rpc/RemoteService.kt b/core/src/commonMain/kotlin/kotlinx/rpc/RemoteService.kt index ce41e270..71f3ceae 100644 --- a/core/src/commonMain/kotlin/kotlinx/rpc/RemoteService.kt +++ b/core/src/commonMain/kotlin/kotlinx/rpc/RemoteService.kt @@ -16,10 +16,3 @@ import kotlinx.rpc.annotations.Rpc * @see Rpc */ public interface RemoteService : CoroutineScope - -@Deprecated( - message = "Deprecated in favor of RemoteService. Will be removed in 0.5.0", - replaceWith = ReplaceWith("RemoteService", "kotlinx.rpc.RemoteService"), - level = DeprecationLevel.ERROR, -) -public interface RPC : CoroutineScope diff --git a/core/src/commonMain/kotlin/kotlinx/rpc/RPCEagerField.kt b/core/src/commonMain/kotlin/kotlinx/rpc/RpcEagerField.kt similarity index 59% rename from core/src/commonMain/kotlin/kotlinx/rpc/RPCEagerField.kt rename to core/src/commonMain/kotlin/kotlinx/rpc/RpcEagerField.kt index 3413f49c..4d3e313f 100644 --- a/core/src/commonMain/kotlin/kotlinx/rpc/RPCEagerField.kt +++ b/core/src/commonMain/kotlin/kotlinx/rpc/RpcEagerField.kt @@ -8,4 +8,7 @@ package kotlinx.rpc * The field marked with this annotation will be initialized with the service creation. */ @Target(AnnotationTarget.PROPERTY) -public annotation class RPCEagerField +public annotation class RpcEagerField + +@Deprecated("Use RpcEagerField instead", ReplaceWith("RpcEagerField"), level = DeprecationLevel.ERROR) +public typealias RPCEagerField = RpcEagerField diff --git a/core/src/commonMain/kotlin/kotlinx/rpc/RPCServer.kt b/core/src/commonMain/kotlin/kotlinx/rpc/RpcServer.kt similarity index 67% rename from core/src/commonMain/kotlin/kotlinx/rpc/RPCServer.kt rename to core/src/commonMain/kotlin/kotlinx/rpc/RpcServer.kt index 1aa49218..fa260af0 100644 --- a/core/src/commonMain/kotlin/kotlinx/rpc/RPCServer.kt +++ b/core/src/commonMain/kotlin/kotlinx/rpc/RpcServer.kt @@ -8,18 +8,21 @@ import kotlinx.coroutines.CoroutineScope import kotlin.coroutines.CoroutineContext import kotlin.reflect.KClass +@Deprecated("Use RpcServer instead", ReplaceWith("RpcServer"), level = DeprecationLevel.ERROR) +public typealias RPCServer = RpcServer + /** - * RPCServer is used to accept RPC messages, route them to a specific service and process given responses. + * RpcServer is used to accept RPC messages, route them to a specific service, and process given responses. * Server may contain multiple services. * [CoroutineScope] defines server lifetime. */ -public interface RPCServer : CoroutineScope { +public interface RpcServer : CoroutineScope { /** * Registers new service to the server. Server will route all designated messages to it. - * Service of any type should be unique on the server, but RPCServer does not specify the actual retention policy. + * Service of any type should be unique on the server, but RpcServer doesn't specify the actual retention policy. * * @param Service the exact type of the server to be registered. - * For example for service with `MyService` interface and `MyServiceImpl` implementation, + * For example, for service with `MyService` interface and `MyServiceImpl` implementation, * type `MyService` should be specified explicitly. * @param serviceKClass [KClass] of the [Service]. * @param serviceFactory function that produces the actual implementation of the service that will handle the calls. @@ -32,14 +35,14 @@ public interface RPCServer : CoroutineScope { /** * Registers new service to the server. Server will route all designated messages to it. - * Service of any type should be unique on the server, but RPCServer does not specify the actual retention policy. + * Service of any type should be unique on the server, but RpcServer doesn't specify the actual retention policy. * * @param Service the exact type of the server to be registered. - * For example for service with `MyService` interface and `MyServiceImpl` implementation, + * For example, for service with `MyService` interface and `MyServiceImpl` implementation, * type `MyService` should be specified explicitly. * @param serviceFactory function that produces the actual implementation of the service that will handle the calls. */ -public inline fun RPCServer.registerService( +public inline fun RpcServer.registerService( noinline serviceFactory: (CoroutineContext) -> Service, ) { registerService(Service::class, serviceFactory) diff --git a/core/src/commonMain/kotlin/kotlinx/rpc/UninitializedRPCFieldException.kt b/core/src/commonMain/kotlin/kotlinx/rpc/UninitializedRpcFieldException.kt similarity index 56% rename from core/src/commonMain/kotlin/kotlinx/rpc/UninitializedRPCFieldException.kt rename to core/src/commonMain/kotlin/kotlinx/rpc/UninitializedRpcFieldException.kt index dcf42b18..f27cffd4 100644 --- a/core/src/commonMain/kotlin/kotlinx/rpc/UninitializedRPCFieldException.kt +++ b/core/src/commonMain/kotlin/kotlinx/rpc/UninitializedRpcFieldException.kt @@ -6,11 +6,18 @@ package kotlinx.rpc import kotlin.reflect.KProperty +@Deprecated( + "Use UninitializedRpcFieldException instead", + ReplaceWith("UninitializedRpcFieldException"), + level = DeprecationLevel.ERROR, +) +public typealias UninitializedRPCFieldException = UninitializedRpcFieldException + /** * Thrown when an uninitialized field of an RPC service is accessed. * * Use [awaitFieldInitialization] to await for the field initialization */ -public class UninitializedRPCFieldException(serviceName: String, property: KProperty<*>): Exception() { +public class UninitializedRpcFieldException(serviceName: String, property: KProperty<*>) : Exception() { override val message: String = "${property.name} field of RPC service \"$serviceName\" in not initialized" } diff --git a/core/src/commonMain/kotlin/kotlinx/rpc/annotations/Rpc.kt b/core/src/commonMain/kotlin/kotlinx/rpc/annotations/Rpc.kt index a42a4830..3f4a07c7 100644 --- a/core/src/commonMain/kotlin/kotlinx/rpc/annotations/Rpc.kt +++ b/core/src/commonMain/kotlin/kotlinx/rpc/annotations/Rpc.kt @@ -32,7 +32,7 @@ import kotlinx.rpc.RemoteService * return "Hello, $firstName $lastName, of age $age. I am your server!" * } * } - * val server: RPCServer + * val server: RpcServer * server.registerService { ctx -> MyServiceImpl(ctx) } * ``` * diff --git a/core/src/commonMain/kotlin/kotlinx/rpc/awaitFieldInitialization.kt b/core/src/commonMain/kotlin/kotlinx/rpc/awaitFieldInitialization.kt index ca8b1f24..30dcf39e 100644 --- a/core/src/commonMain/kotlin/kotlinx/rpc/awaitFieldInitialization.kt +++ b/core/src/commonMain/kotlin/kotlinx/rpc/awaitFieldInitialization.kt @@ -34,7 +34,7 @@ public suspend fun T.awaitFieldInitialization(getter: T.( return (field as RpcDeferredField).await() } - error("Please choose required field for a valid RPC client generated by RPCClient.withService method") + error("Please choose required field for a valid RPC client generated by RpcClient.withService method") } /** diff --git a/core/src/commonMain/kotlin/kotlinx/rpc/descriptor/RpcServiceDescriptor.kt b/core/src/commonMain/kotlin/kotlinx/rpc/descriptor/RpcServiceDescriptor.kt index a4cb3573..68af6f3b 100644 --- a/core/src/commonMain/kotlin/kotlinx/rpc/descriptor/RpcServiceDescriptor.kt +++ b/core/src/commonMain/kotlin/kotlinx/rpc/descriptor/RpcServiceDescriptor.kt @@ -7,22 +7,22 @@ package kotlinx.rpc.descriptor import kotlinx.rpc.RemoteService import kotlinx.rpc.RpcClient import kotlinx.rpc.internal.* -import kotlinx.rpc.internal.utils.ExperimentalRPCApi -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.ExperimentalRpcApi +import kotlinx.rpc.internal.utils.InternalRpcApi import kotlin.reflect.KClass import kotlin.reflect.KType -@ExperimentalRPCApi +@ExperimentalRpcApi public inline fun serviceDescriptorOf(): RpcServiceDescriptor { return serviceDescriptorOf(T::class) } -@ExperimentalRPCApi +@ExperimentalRpcApi public fun serviceDescriptorOf(kType: KType): RpcServiceDescriptor { return serviceDescriptorOf(kType.kClass()) } -@ExperimentalRPCApi +@ExperimentalRpcApi public fun serviceDescriptorOf(kClass: KClass): RpcServiceDescriptor { val maybeDescriptor = internalServiceDescriptorOf(kClass) ?: internalError("Unable to find a service descriptor of the $kClass") @@ -39,11 +39,11 @@ public fun serviceDescriptorOf(kClass: KClass): RpcServic ) } -@ExperimentalRPCApi +@ExperimentalRpcApi public interface RpcServiceDescriptor { public val fqName: String - @InternalRPCApi + @InternalRpcApi public fun getFields(service: T): List> public fun getCallable(name: String): RpcCallable? @@ -51,7 +51,7 @@ public interface RpcServiceDescriptor { public fun createInstance(serviceId: Long, client: RpcClient): T } -@ExperimentalRPCApi +@ExperimentalRpcApi public class RpcCallable( public val name: String, public val dataType: KType, @@ -60,18 +60,18 @@ public class RpcCallable( public val parameters: Array, ) -@ExperimentalRPCApi +@ExperimentalRpcApi public sealed interface RpcInvokator { - @ExperimentalRPCApi + @ExperimentalRpcApi public fun interface Method : RpcInvokator { public suspend fun call(service: T, data: Any?): Any? } - @ExperimentalRPCApi + @ExperimentalRpcApi public fun interface Field : RpcInvokator { public fun call(service: T): Any? } } -@ExperimentalRPCApi +@ExperimentalRpcApi public class RpcParameter(public val name: String, public val type: KType) diff --git a/core/src/commonMain/kotlin/kotlinx/rpc/internal/FieldDataObject.kt b/core/src/commonMain/kotlin/kotlinx/rpc/internal/FieldDataObject.kt index 9140766a..64007f9d 100644 --- a/core/src/commonMain/kotlin/kotlinx/rpc/internal/FieldDataObject.kt +++ b/core/src/commonMain/kotlin/kotlinx/rpc/internal/FieldDataObject.kt @@ -4,12 +4,12 @@ package kotlinx.rpc.internal -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi import kotlinx.serialization.Serializable /** * Used for field initialization call */ @Serializable -@InternalRPCApi +@InternalRpcApi public object FieldDataObject diff --git a/core/src/commonMain/kotlin/kotlinx/rpc/internal/ReflectionUtils.kt b/core/src/commonMain/kotlin/kotlinx/rpc/internal/ReflectionUtils.kt index ef6f5ef1..f1487036 100644 --- a/core/src/commonMain/kotlin/kotlinx/rpc/internal/ReflectionUtils.kt +++ b/core/src/commonMain/kotlin/kotlinx/rpc/internal/ReflectionUtils.kt @@ -4,11 +4,11 @@ package kotlinx.rpc.internal -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi import kotlin.reflect.KClass import kotlin.reflect.KType -@InternalRPCApi +@InternalRpcApi @Suppress("UNCHECKED_CAST") public fun KType.kClass(): KClass { val classifier = classifier ?: error("Expected denotable type, found $this") @@ -17,17 +17,17 @@ public fun KType.kClass(): KClass { return classifierClass as KClass } -@InternalRPCApi +@InternalRpcApi public fun internalError(message: String): Nothing { error("Internal kotlinx.rpc error: $message") } -@InternalRPCApi +@InternalRpcApi public expect val KClass<*>.typeName: String? -@InternalRPCApi +@InternalRpcApi public expect val KClass<*>.qualifiedClassNameOrNull: String? -@InternalRPCApi +@InternalRpcApi public val KClass<*>.qualifiedClassName: String get() = qualifiedClassNameOrNull ?: error("Expected qualifiedClassName for $this") diff --git a/core/src/commonMain/kotlin/kotlinx/rpc/internal/RpcDeferredField.kt b/core/src/commonMain/kotlin/kotlinx/rpc/internal/RpcDeferredField.kt index 61dfea9c..ff165133 100644 --- a/core/src/commonMain/kotlin/kotlinx/rpc/internal/RpcDeferredField.kt +++ b/core/src/commonMain/kotlin/kotlinx/rpc/internal/RpcDeferredField.kt @@ -4,9 +4,9 @@ package kotlinx.rpc.internal -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi -@InternalRPCApi +@InternalRpcApi public interface RpcDeferredField { public suspend fun await(): Self } diff --git a/core/src/commonMain/kotlin/kotlinx/rpc/internal/RpcFieldProvider.kt b/core/src/commonMain/kotlin/kotlinx/rpc/internal/RpcFieldProvider.kt index 7067212a..2b58f865 100644 --- a/core/src/commonMain/kotlin/kotlinx/rpc/internal/RpcFieldProvider.kt +++ b/core/src/commonMain/kotlin/kotlinx/rpc/internal/RpcFieldProvider.kt @@ -7,7 +7,7 @@ package kotlinx.rpc.internal import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.Deferred import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.rpc.UninitializedRPCFieldException +import kotlinx.rpc.UninitializedRpcFieldException import kotlin.reflect.KProperty internal class RpcFieldProvider( @@ -21,7 +21,7 @@ internal class RpcFieldProvider( return deferred.getCompleted().getter() } - throw UninitializedRPCFieldException(serviceName, property) + throw UninitializedRpcFieldException(serviceName, property) } } diff --git a/core/src/commonMain/kotlin/kotlinx/rpc/internal/RpcMethodClass.kt b/core/src/commonMain/kotlin/kotlinx/rpc/internal/RpcMethodClass.kt index 3ba3a155..36ffa2c3 100644 --- a/core/src/commonMain/kotlin/kotlinx/rpc/internal/RpcMethodClass.kt +++ b/core/src/commonMain/kotlin/kotlinx/rpc/internal/RpcMethodClass.kt @@ -4,9 +4,9 @@ package kotlinx.rpc.internal -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi -@InternalRPCApi +@InternalRpcApi public interface RpcMethodClass { public fun asArray(): Array } diff --git a/core/src/commonMain/kotlin/kotlinx/rpc/internal/ServiceScope.kt b/core/src/commonMain/kotlin/kotlinx/rpc/internal/ServiceScope.kt index 22886ca7..3c496a66 100644 --- a/core/src/commonMain/kotlin/kotlinx/rpc/internal/ServiceScope.kt +++ b/core/src/commonMain/kotlin/kotlinx/rpc/internal/ServiceScope.kt @@ -7,20 +7,20 @@ package kotlinx.rpc.internal import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.currentCoroutineContext import kotlinx.coroutines.withContext -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi import kotlin.contracts.ExperimentalContracts import kotlin.contracts.InvocationKind import kotlin.contracts.contract import kotlin.coroutines.CoroutineContext -@InternalRPCApi +@InternalRpcApi public class ServiceScope(public val serviceCoroutineScope: CoroutineScope) : CoroutineContext.Element { internal companion object Key : CoroutineContext.Key override val key: CoroutineContext.Key<*> = Key } -@InternalRPCApi +@InternalRpcApi public suspend fun createServiceScope(serviceCoroutineScope: CoroutineScope): ServiceScope { val context = currentCoroutineContext() @@ -31,12 +31,12 @@ public suspend fun createServiceScope(serviceCoroutineScope: CoroutineScope): Se return ServiceScope(serviceCoroutineScope) } -@InternalRPCApi +@InternalRpcApi public suspend fun serviceScopeOrNull(): ServiceScope? { return currentCoroutineContext()[ServiceScope.Key] } -@InternalRPCApi +@InternalRpcApi @OptIn(ExperimentalContracts::class) public suspend inline fun serviceScoped( serviceCoroutineScope: CoroutineScope, diff --git a/core/src/commonMain/kotlin/kotlinx/rpc/internal/dataCast.kt b/core/src/commonMain/kotlin/kotlinx/rpc/internal/dataCast.kt index d9ce0761..01bb6a9f 100644 --- a/core/src/commonMain/kotlin/kotlinx/rpc/internal/dataCast.kt +++ b/core/src/commonMain/kotlin/kotlinx/rpc/internal/dataCast.kt @@ -4,9 +4,9 @@ package kotlinx.rpc.internal -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi -@InternalRPCApi +@InternalRpcApi public inline fun Any?.dataCast(methodName: String, serviceName: String): T { return this as? T ?: throw IllegalArgumentException( diff --git a/core/src/commonMain/kotlin/kotlinx/rpc/internal/scopedClientCall.kt b/core/src/commonMain/kotlin/kotlinx/rpc/internal/scopedClientCall.kt index 6e4791ee..8a47691e 100644 --- a/core/src/commonMain/kotlin/kotlinx/rpc/internal/scopedClientCall.kt +++ b/core/src/commonMain/kotlin/kotlinx/rpc/internal/scopedClientCall.kt @@ -5,14 +5,14 @@ package kotlinx.rpc.internal import kotlinx.coroutines.CoroutineScope -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi /** * Scopes client RPC call from a service with [serviceScope]. * * Used by code generators. */ -@InternalRPCApi +@InternalRpcApi @Suppress("unused") public suspend inline fun scopedClientCall(serviceScope: CoroutineScope, crossinline body: suspend () -> T): T { return serviceScoped(serviceScope) { 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 f24dc855..7c5988b4 100644 --- a/core/src/jsMain/kotlin/kotlinx/rpc/internal/ReflectionUtils.js.kt +++ b/core/src/jsMain/kotlin/kotlinx/rpc/internal/ReflectionUtils.js.kt @@ -6,13 +6,13 @@ package kotlinx.rpc.internal -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi import kotlin.reflect.KClass -@InternalRPCApi +@InternalRpcApi public actual val KClass<*>.qualifiedClassNameOrNull: String? get() = toString() -@InternalRPCApi +@InternalRpcApi public actual val KClass<*>.typeName: String? get() = qualifiedClassNameOrNull diff --git a/core/src/jsMain/kotlin/kotlinx/rpc/internal/internalServiceDescriptorOf.js.kt b/core/src/jsMain/kotlin/kotlinx/rpc/internal/internalServiceDescriptorOf.js.kt index a4050778..ecd75e40 100644 --- a/core/src/jsMain/kotlin/kotlinx/rpc/internal/internalServiceDescriptorOf.js.kt +++ b/core/src/jsMain/kotlin/kotlinx/rpc/internal/internalServiceDescriptorOf.js.kt @@ -9,13 +9,13 @@ package kotlinx.rpc.internal import js.objects.Object import kotlinx.rpc.RemoteService import kotlinx.rpc.descriptor.RpcServiceDescriptor -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi import kotlin.reflect.AssociatedObjectKey import kotlin.reflect.ExperimentalAssociatedObjects import kotlin.reflect.KClass import kotlin.reflect.findAssociatedObject -@InternalRPCApi +@InternalRpcApi @AssociatedObjectKey @OptIn(ExperimentalAssociatedObjects::class) @Target(AnnotationTarget.CLASS) 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 801ccdbb..43c88957 100644 --- a/core/src/jvmMain/kotlin/kotlinx/rpc/internal/ReflectionUtils.jvm.kt +++ b/core/src/jvmMain/kotlin/kotlinx/rpc/internal/ReflectionUtils.jvm.kt @@ -6,13 +6,13 @@ package kotlinx.rpc.internal -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi import kotlin.reflect.KClass -@InternalRPCApi +@InternalRpcApi public actual val KClass<*>.qualifiedClassNameOrNull: String? get() = qualifiedName -@InternalRPCApi +@InternalRpcApi public actual val KClass<*>.typeName: 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 db1cb6f1..38d85658 100644 --- a/core/src/nativeMain/kotlin/kotlinx/rpc/internal/ReflectionUtils.native.kt +++ b/core/src/nativeMain/kotlin/kotlinx/rpc/internal/ReflectionUtils.native.kt @@ -6,13 +6,13 @@ package kotlinx.rpc.internal -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi import kotlin.reflect.KClass -@InternalRPCApi +@InternalRpcApi public actual val KClass<*>.qualifiedClassNameOrNull: String? get() = qualifiedName -@InternalRPCApi +@InternalRpcApi public actual val KClass<*>.typeName: String? get() = qualifiedClassNameOrNull diff --git a/core/src/nativeMain/kotlin/kotlinx/rpc/internal/internalServiceDescriptorOf.native.kt b/core/src/nativeMain/kotlin/kotlinx/rpc/internal/internalServiceDescriptorOf.native.kt index 7bd0085c..9ddbdf8c 100644 --- a/core/src/nativeMain/kotlin/kotlinx/rpc/internal/internalServiceDescriptorOf.native.kt +++ b/core/src/nativeMain/kotlin/kotlinx/rpc/internal/internalServiceDescriptorOf.native.kt @@ -8,13 +8,13 @@ package kotlinx.rpc.internal import kotlinx.rpc.RemoteService import kotlinx.rpc.descriptor.RpcServiceDescriptor -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi import kotlin.reflect.AssociatedObjectKey import kotlin.reflect.ExperimentalAssociatedObjects import kotlin.reflect.KClass import kotlin.reflect.findAssociatedObject -@InternalRPCApi +@InternalRpcApi @AssociatedObjectKey @OptIn(ExperimentalAssociatedObjects::class) @Target(AnnotationTarget.CLASS) 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 f24dc855..7c5988b4 100644 --- a/core/src/wasmJsMain/kotlin/kotlinx/rpc/internal/ReflectionUtils.wasm.kt +++ b/core/src/wasmJsMain/kotlin/kotlinx/rpc/internal/ReflectionUtils.wasm.kt @@ -6,13 +6,13 @@ package kotlinx.rpc.internal -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi import kotlin.reflect.KClass -@InternalRPCApi +@InternalRpcApi public actual val KClass<*>.qualifiedClassNameOrNull: String? get() = toString() -@InternalRPCApi +@InternalRpcApi public actual val KClass<*>.typeName: String? get() = qualifiedClassNameOrNull diff --git a/core/src/wasmJsMain/kotlin/kotlinx/rpc/internal/internalServiceDescriptorOf.wasmJs.kt b/core/src/wasmJsMain/kotlin/kotlinx/rpc/internal/internalServiceDescriptorOf.wasmJs.kt index 7635bbea..4206ffd7 100644 --- a/core/src/wasmJsMain/kotlin/kotlinx/rpc/internal/internalServiceDescriptorOf.wasmJs.kt +++ b/core/src/wasmJsMain/kotlin/kotlinx/rpc/internal/internalServiceDescriptorOf.wasmJs.kt @@ -6,13 +6,13 @@ package kotlinx.rpc.internal import kotlinx.rpc.RemoteService import kotlinx.rpc.descriptor.RpcServiceDescriptor -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi import kotlin.reflect.AssociatedObjectKey import kotlin.reflect.ExperimentalAssociatedObjects import kotlin.reflect.KClass import kotlin.reflect.findAssociatedObject -@InternalRPCApi +@InternalRpcApi @AssociatedObjectKey @OptIn(ExperimentalAssociatedObjects::class) @Target(AnnotationTarget.CLASS) 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 f24dc855..7c5988b4 100644 --- a/core/src/wasmWasiMain/kotlin/kotlinx/rpc/internal/ReflectionUtils.wasi.kt +++ b/core/src/wasmWasiMain/kotlin/kotlinx/rpc/internal/ReflectionUtils.wasi.kt @@ -6,13 +6,13 @@ package kotlinx.rpc.internal -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi import kotlin.reflect.KClass -@InternalRPCApi +@InternalRpcApi public actual val KClass<*>.qualifiedClassNameOrNull: String? get() = toString() -@InternalRPCApi +@InternalRpcApi public actual val KClass<*>.typeName: String? get() = qualifiedClassNameOrNull diff --git a/core/src/wasmWasiMain/kotlin/kotlinx/rpc/internal/internalServiceDescriptorOf.wasmWasi.kt b/core/src/wasmWasiMain/kotlin/kotlinx/rpc/internal/internalServiceDescriptorOf.wasmWasi.kt index 7635bbea..4206ffd7 100644 --- a/core/src/wasmWasiMain/kotlin/kotlinx/rpc/internal/internalServiceDescriptorOf.wasmWasi.kt +++ b/core/src/wasmWasiMain/kotlin/kotlinx/rpc/internal/internalServiceDescriptorOf.wasmWasi.kt @@ -6,13 +6,13 @@ package kotlinx.rpc.internal import kotlinx.rpc.RemoteService import kotlinx.rpc.descriptor.RpcServiceDescriptor -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi import kotlin.reflect.AssociatedObjectKey import kotlin.reflect.ExperimentalAssociatedObjects import kotlin.reflect.KClass import kotlin.reflect.findAssociatedObject -@InternalRPCApi +@InternalRpcApi @AssociatedObjectKey @OptIn(ExperimentalAssociatedObjects::class) @Target(AnnotationTarget.CLASS) diff --git a/detekt/baseline.xml b/detekt/baseline.xml index 2c1473cc..7641be34 100644 --- a/detekt/baseline.xml +++ b/detekt/baseline.xml @@ -5,10 +5,10 @@ - CyclomaticComplexMethod:RPCServerService.kt$RPCServerService$@Suppress("detekt.ThrowsCount", "detekt.LongMethod") private fun handleCall(callData: RPCCallMessage.CallData) - LongMethod:RPCServerService.kt$RPCServerService$@OptIn(InternalCoroutinesApi::class) private fun handleCall(callData: RPCCallMessage.CallData) - RethrowCaughtException:KRPCTransportTestBase.kt$KRPCTransportTestBase$throw e - GlobalCoroutineUsage:Broadcast.kt$<no name provided>$GlobalScope.launch { val job = receiver.coroutineContext.job job.join() val cause = if (!job.isActive) job.getCancellationException() else null mutex.withLock { if (cause == null) return@withLock if (waiting.isEmpty()) return@withLock logger.warn { "Cancelling service with unprocessed messages. Cause: $cause" } for (call in waiting) { val message = RPCMessage.CallException(call.callId, call.serviceType, serializeException(cause)) runCatching { send(message) } } } } + CyclomaticComplexMethod:KrpcServerService.kt$KrpcServerService$@Suppress("detekt.ThrowsCount", "detekt.LongMethod") private fun handleCall(callData: KrpcCallMessage.CallData) + LongMethod:KrpcServerService.kt$KrpcServerService$@OptIn(InternalCoroutinesApi::class) private fun handleCall(callData: KrpcCallMessage.CallData) + RethrowCaughtException:KrpcTransportTestBase.kt$KrpcTransportTestBase$throw e + GlobalCoroutineUsage:Broadcast.kt$<no name provided>$GlobalScope.launch { val job = receiver.coroutineContext.job job.join() val cause = if (!job.isActive) job.getCancellationException() else null mutex.withLock { if (cause == null) return@withLock if (waiting.isEmpty()) return@withLock logger.warn { "Cancelling service with unprocessed messages. Cause: $cause" } for (call in waiting) { val message = KrpcMessage.CallException(call.callId, call.serviceType, serializeException(cause)) runCatching { send(message) } } } } GlobalCoroutineUsage:KtorTransport.kt$KtorTransport$GlobalScope.launch { webSocketSession.close() } diff --git a/docs/pages/kotlinx-rpc/topics/configuration.topic b/docs/pages/kotlinx-rpc/topics/configuration.topic index 3f733cff..49d7864d 100644 --- a/docs/pages/kotlinx-rpc/topics/configuration.topic +++ b/docs/pages/kotlinx-rpc/topics/configuration.topic @@ -8,17 +8,17 @@ -

RPCConfig is a class used to configure KRPCClient and KRPCServer - (not to be confused with RPCClient and RPCServer). - It has two children: RPCConfig.Client and RPCConfig.Server. +

KrpcConfig is a class used to configure KrpcClient and KrpcServer + (not to be confused with KrpcClient and KrpcServer). + It has two children: KrpcConfig.Client and KrpcConfig.Server. Client and Server may have shared properties as well as distinct ones. To create instances of these configurations, DSL builders are provided - (RPCConfigBuilder.Client class with rpcClientConfig function - and RPCConfigBuilder.Server class with rpcServerConfig function respectively): + (KrpcConfigBuilder.Client class with rpcClientConfig function + and KrpcConfigBuilder.Server class with rpcServerConfig function respectively):

- val config: RPCConfig.Client = rpcClientConfig { // same for RPCConfig.Server with rpcServerConfig + val config: KrpcConfig.Client = rpcClientConfig { // same for KrpcConfig.Server with rpcServerConfig waitForServices = true // default parameter } @@ -81,7 +81,7 @@ But instances of these flows when deserialized should be created somehow, so to overcome this - configuration parameter is created. Configuration builder allows defining these parameters - and produces a builder function that is then placed into the RPCConfig.

+ and produces a builder function that is then placed into the KrpcConfig.

@@ -90,10 +90,10 @@ <p><code>waitForServices</code> parameter is available for both client and server. It specifies the behavior for an endpoint in situations when the message for a service is received, - but the service is not present in <code>RPCClient</code> or <code>RPCServer</code>. + but the service is not present in <code>KrpcClient</code> or <code>KrpcServer</code>. If set to <code>true</code>, the message will be stored in memory, otherwise, the error will be sent to a peer endpoint, saying that the message was not handled. Default value is <code>true</code>.</p> </chapter> -</topic> \ No newline at end of file +</topic> diff --git a/docs/pages/kotlinx-rpc/topics/features.topic b/docs/pages/kotlinx-rpc/topics/features.topic index 9a611edb..707d8879 100644 --- a/docs/pages/kotlinx-rpc/topics/features.topic +++ b/docs/pages/kotlinx-rpc/topics/features.topic @@ -145,7 +145,7 @@ <control>fields</control> (<code>replayCache</code> for <code>SharedFlow</code> and <code>StateFlow</code>, and <code>value</code> for <code>StateFlow</code>) - you will get a <code>UninitializedRPCFieldException</code>. + you will get a <code>UninitializedRpcFieldException</code>. If you call a suspend <code>collect</code> method on them, execution will suspend until the state is <emphasis>initialized</emphasis> @@ -164,7 +164,7 @@ // ### Somewhere in client code ### val myService: MyService = rpcClient.withService<MyService>() - val value = myService.flow.value // throws UninitializedRPCFieldException + val value = myService.flow.value // throws UninitializedRpcFieldException val value = myService.awaitFieldInitialization { flow }.value // OK // or val value = myService.awaitFieldInitialization().flow.value // OK @@ -173,7 +173,7 @@ </code-block> <p>Secondly, we provide you with an instrument to make initialization faster. By default, all fields are lazy. - By adding <code>@RPCEagerField</code> annotation, you can change this behavior, + By adding <code>@RpcEagerField</code> annotation, you can change this behavior, so that fields will be initialized when the service in created (when <code>withService</code> method is called):</p> @@ -182,7 +182,7 @@ interface MyService : RemoteService { val lazyFlow: Flow<Int> // initialized on first access - @RPCEagerField + @RpcEagerField val eagerFlow: Flow<Int> // initialized on service creation } </code-block> diff --git a/docs/pages/kotlinx-rpc/topics/rpc-clients.topic b/docs/pages/kotlinx-rpc/topics/rpc-clients.topic index f5293588..7aa8c202 100644 --- a/docs/pages/kotlinx-rpc/topics/rpc-clients.topic +++ b/docs/pages/kotlinx-rpc/topics/rpc-clients.topic @@ -23,35 +23,35 @@ In this case, you can use the generated code. </tip> <p> - To be able to obtain an instance of your service, you need to have an <code>RPCClient</code>. + To be able to obtain an instance of your service, you need to have an <code>RpcClient</code>. You can call the <code>withService()</code> method on your client: </p> <code-block lang="kotlin"> - val rpcClient: RPCClient + val rpcClient: RpcClient val myService: MyService = rpcClient.withService<MyService>() </code-block> <p> Now you have your client instance that is able to send RPC requests to your server. - <code>RPCClient</code> can have multiple services that communicate through it. - Conceptually, <code>RPCClient</code> is an abstraction of a client, + <code>RpcClient</code> can have multiple services that communicate through it. + Conceptually, <code>RpcClient</code> is an abstraction of a client, that is able to convent service requests - (represented by <code>RPCCall</code> and <code>RPCField</code> classes) + (represented by the <code>RpcCall</code> class) into actual network requests. </p> <p> - You can provide your own implementations of the <code>RPCClient</code>. + You can provide your own implementations of the <code>RpcClient</code>. But <code>kotlinx.rpc</code> already provides one out-of-the-box solution that uses in-house RPC protocol (called kRPC), and we are working on supporting more protocols (with priority on gRPC). </p> - <chapter title="KRPCClient — RPCClient for kRPC Protocol" id="krpcclient-rpcclient-for-krpc-protocol"> - <p><code>KRPCClient</code> is an abstract class that implements <code>RPCClient</code> and kRPC protocol + <chapter title="KrpcClient — RpcClient for kRPC Protocol" id="krpcclient-rpcclient-for-krpc-protocol"> + <p><code>KrpcClient</code> is an abstract class that implements <code>RpcClient</code> and kRPC protocol logic. The only thing required to be implemented is the transporting of the raw data. - Abstract transport is represented by <code>RPCTransport</code> interface.</p> - <p>To implement your own <code>RPCTransport</code> + Abstract transport is represented by <code>KrpcTransport</code> interface.</p> + <p>To implement your own <code>KrpcTransport</code> you need to be able to transfer strings and/or raw bytes (Kotlin's <code>ByteArray</code>). Additionally, the library will provide you with <a href="transport.topic">integrations with different libraries</a> that are used to work with the network. @@ -59,25 +59,25 @@ <p>See below an example usage of kRPC with a custom transport:</p> <code-block lang="kotlin"> - class MySimpleRPCTransport : RPCTransport { - val outChannel = Channel<RPCTransportMessage>() - val inChannel = Channel<RPCTransportMessage>() + class MySimpleRpcTransport : KrpcTransport { + val outChannel = Channel<KrpcTransportMessage>() + val inChannel = Channel<KrpcTransportMessage>() override val coroutineContext: CoroutineContext = Job() - override suspend fun send(message: RPCTransportMessage) { + override suspend fun send(message: KrpcTransportMessage) { outChannel.send(message) } - override suspend fun receive(): RPCTransportMessage { + override suspend fun receive(): KrpcTransportMessage { return inChannel.receive() } } - class MySimpleRPCClient : KRPCClient(rpcClientConfig(), MySimpleRPCTransport()) + class MySimpleRpcClient : KrpcClient(rpcClientConfig(), MySimpleRpcTransport()) - val client = MySimpleRPCClient() + val client = MySimpleRpcClient() val service: MyService = client.withService<MyService>() </code-block> </chapter> -</topic> \ No newline at end of file +</topic> diff --git a/docs/pages/kotlinx-rpc/topics/rpc-servers.topic b/docs/pages/kotlinx-rpc/topics/rpc-servers.topic index d6b5f634..7f2e3b97 100644 --- a/docs/pages/kotlinx-rpc/topics/rpc-servers.topic +++ b/docs/pages/kotlinx-rpc/topics/rpc-servers.topic @@ -8,12 +8,12 @@ <topic xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://resources.jetbrains.com/writerside/1.0/topic.v2.xsd" title="RPC Servers" id="rpc-servers"> - <p><code>RPCServer</code> interface represents an RPC server, + <p><code>RpcServer</code> interface represents an RPC server, that accepts RPC messages and may contain multiple services to route to. - <code>RPCServer</code> uses data from incoming RPC messages + <code>RpcServer</code> uses data from incoming RPC messages and routes it to the designated service and sends service's response back to the corresponding client. </p> - <p>You can provide your own <code>RPCServer</code> implementation + <p>You can provide your own <code>RpcServer</code> implementation or use the one provided out of the box. Note that client and server must use the same RPC protocol to communicate.</p> <p>Use <code>registerService</code> function to add your own factory for implemented RPC services. @@ -23,7 +23,7 @@ <p>Example usage:</p> <code-block lang="kotlin"> - val server: RPCServer + val server: RpcServer server.registerService<MyService> { ctx: CoroutineContext -> MyServiceImpl(ctx) } </code-block> @@ -36,18 +36,18 @@ server.registerService<MyServiceImpl> { ctx: CoroutineContext -> MyServiceImpl(ctx) } </code-block> - <chapter title="KRPCServer — RPCServer for kRPC Protocol" id="krpcserver-rpcserver-for-krpc-protocol"> - <p><code>KRPCServer</code> abstract class implements <code>RPCServer</code> + <chapter title="KrpcServer — RpcServer for kRPC Protocol" id="krpcserver-rpcserver-for-krpc-protocol"> + <p><code>KrpcServer</code> abstract class implements <code>RpcServer</code> and all the logic for processing RPC messages - and again leaves <code>RPCTransport</code> methods for the specific implementations + and again leaves <code>RpcTransport</code> methods for the specific implementations (see <a href="transport.topic">transports</a>).</p> <p>Example usage with custom transport:</p> <code-block lang="kotlin"> - // same MySimpleRPCTransport as in the client example above - class MySimpleRPCServer : KRPCServer(rpcServerConfig(), MySimpleRPCTransport()) + // same MySimpleRpcTransport as in the client example above + class MySimpleRpcServer : KrpcServer(rpcServerConfig(), MySimpleRpcTransport()) - val server = MySimpleRPCServer() + val server = MySimpleRpcServer() server.registerService<MyService> { ctx -> MyServiceImpl(ctx) } </code-block> <p>Note that here we pass explicit <code>MyService</code> type parameter to the <code>registerService</code> @@ -55,4 +55,4 @@ You must explicitly specify the type of the service interface here, otherwise the server service will not be found.</p> </chapter> -</topic> \ No newline at end of file +</topic> diff --git a/docs/pages/kotlinx-rpc/topics/transport.topic b/docs/pages/kotlinx-rpc/topics/transport.topic index 17547d0f..8eb26bd7 100644 --- a/docs/pages/kotlinx-rpc/topics/transport.topic +++ b/docs/pages/kotlinx-rpc/topics/transport.topic @@ -11,7 +11,7 @@ <p>Transport layer exists to abstract from the RPC requests logic and focus on delivering and receiving encoded RPC messages in kRPC Protocol. - This layer is represented by <code>RPCTransport</code> interface. + This layer is represented by <code>KrpcTransport</code> interface. It supports two message formats — string and binary, and depending on which <a href="configuration.topic" anchor="serialization-dsl">serialization</a> format you choose, one or the other will be used.</p> @@ -22,21 +22,21 @@ protocol. This includes both server and client APIs. Under the hood, the library uses <a href="https://ktor.io/docs/websocket.html">WebSocket</a> plugin - to create a <code>RPCTransport</code> and send and receive messages through it.</p> + to create a <code>KrpcTransport</code> and send and receive messages through it.</p> <chapter title="Client" id="client"> <p><code>kotlinx.rpc</code> provides a way to plug-in into existing Ktor clients with your RPC services. To do that, the following DSL can be used:</p> <code-block lang="kotlin"> val ktorClient = HttpClient { - installRPC { // this: RPCConfigBuilder.Client + installKrpc { // this: KrpcConfigBuilder.Client waitForServices = true } } - val rpcClient: KtorRPCClient = + val rpcClient: KtorKrpcClient = ktorClient.rpc("ws://localhost:4242/services") { // this: HttpRequestBuilder - rpcConfig { // this: RPCConfigBuilder.Client + rpcConfig { // this: KrpcConfigBuilder.Client waitForServices = false } } @@ -47,7 +47,7 @@ // create RPC service val myService: MyService = rpcClient.withService<MyService>() </code-block> - <p>Note that in this example, only the latter defined <code>RPCConfig</code> will be used.</p> + <p>Note that in this example, only the latter defined <code>KrpcConfig</code> will be used.</p> </chapter> <chapter title="Server" id="server"> <p><code>kotlinx.rpc</code> provides a way to plug-in into existing server routing with your RPC @@ -56,13 +56,13 @@ <code-block lang="kotlin"> fun Application.module() { - install(RPC) { // this: RPCConfigBuilder.Server + install(Krpc) { // this: KrpcConfigBuilder.Server waitForServices = true } routing { - rpc("/services") { // this RPCRoute, inherits WebSocketSession - rpcConfig { // this: RPCConfigBuilder.Server + rpc("/services") { // this KrpcRoute, inherits WebSocketSession + rpcConfig { // this: KrpcConfigBuilder.Server waitForServices = false } @@ -94,7 +94,7 @@ // ### CLIENT CODE ### val client = HttpClient { - installRPC { + installKrpc { serialization { json() } @@ -124,7 +124,7 @@ fun main() { embeddedServer(Netty, port = 8080) { - install(RPC) { + install(Krpc) { serialization { json() } diff --git a/gradle-conventions/common/src/main/kotlin/util/OptInForInternalApi.kt b/gradle-conventions/common/src/main/kotlin/util/OptInForInternalApi.kt index 6d980798..190e9749 100644 --- a/gradle-conventions/common/src/main/kotlin/util/OptInForInternalApi.kt +++ b/gradle-conventions/common/src/main/kotlin/util/OptInForInternalApi.kt @@ -6,9 +6,9 @@ package util import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension -fun KotlinProjectExtension.optInForRPCApi() { +fun KotlinProjectExtension.optInForRpcApi() { sourceSets.all { - languageSettings.optIn("kotlinx.rpc.internal.utils.InternalRPCApi") - languageSettings.optIn("kotlinx.rpc.internal.utils.ExperimentalRPCApi") + languageSettings.optIn("kotlinx.rpc.internal.utils.InternalRpcApi") + languageSettings.optIn("kotlinx.rpc.internal.utils.ExperimentalRpcApi") } } diff --git a/gradle-conventions/common/src/main/kotlin/util/apiValidation.kt b/gradle-conventions/common/src/main/kotlin/util/apiValidation.kt index e2f68ed3..bf277e84 100644 --- a/gradle-conventions/common/src/main/kotlin/util/apiValidation.kt +++ b/gradle-conventions/common/src/main/kotlin/util/apiValidation.kt @@ -23,6 +23,6 @@ fun Project.configureApiValidation() { ) ) - nonPublicMarkers.add("kotlinx.rpc.internal.utils.InternalRPCApi") + nonPublicMarkers.add("kotlinx.rpc.internal.utils.InternalRpcApi") } } diff --git a/gradle-conventions/src/main/kotlin/conventions-jvm.gradle.kts b/gradle-conventions/src/main/kotlin/conventions-jvm.gradle.kts index 4e6f30c9..1e02cada 100644 --- a/gradle-conventions/src/main/kotlin/conventions-jvm.gradle.kts +++ b/gradle-conventions/src/main/kotlin/conventions-jvm.gradle.kts @@ -4,7 +4,7 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension import util.configureJvm -import util.optInForRPCApi +import util.optInForRpcApi plugins { id("conventions-common") @@ -20,7 +20,7 @@ configure<KotlinJvmProjectExtension> { languageVersion.set(JavaLanguageVersion.of(8)) } - optInForRPCApi() + optInForRpcApi() explicitApi() } diff --git a/gradle-conventions/src/main/kotlin/conventions-kmp.gradle.kts b/gradle-conventions/src/main/kotlin/conventions-kmp.gradle.kts index 8862d093..1c26e2cf 100644 --- a/gradle-conventions/src/main/kotlin/conventions-kmp.gradle.kts +++ b/gradle-conventions/src/main/kotlin/conventions-kmp.gradle.kts @@ -11,7 +11,7 @@ plugins { } configure<KotlinMultiplatformExtension> { - optInForRPCApi() + optInForRpcApi() explicitApi() } diff --git a/gradle-plugin/build.gradle.kts b/gradle-plugin/build.gradle.kts index ea652c77..61ec1f9f 100644 --- a/gradle-plugin/build.gradle.kts +++ b/gradle-plugin/build.gradle.kts @@ -37,7 +37,7 @@ gradlePlugin { id = "org.jetbrains.kotlinx.rpc.plugin" displayName = "kotlinx.rpc Gradle Plugin" - implementationClass = "kotlinx.rpc.RPCGradlePlugin" + implementationClass = "kotlinx.rpc.RpcGradlePlugin" description = """ The plugin ensures correct RPC configurations for your project, that will allow proper code generation. """.trimIndent() diff --git a/gradle-plugin/src/main/kotlin/kotlinx/rpc/KotlinCompilerPluginBuilder.kt b/gradle-plugin/src/main/kotlin/kotlinx/rpc/KotlinCompilerPluginBuilder.kt index 79668135..831dcfcb 100644 --- a/gradle-plugin/src/main/kotlin/kotlinx/rpc/KotlinCompilerPluginBuilder.kt +++ b/gradle-plugin/src/main/kotlin/kotlinx/rpc/KotlinCompilerPluginBuilder.kt @@ -4,10 +4,10 @@ package kotlinx.rpc -import kotlinx.rpc.RPCPluginConst.COMPILER_PLUGIN_ARTIFACT_ID -import kotlinx.rpc.RPCPluginConst.GROUP_ID -import kotlinx.rpc.RPCPluginConst.PLUGIN_ID -import kotlinx.rpc.RPCPluginConst.libraryKotlinPrefixedVersion +import kotlinx.rpc.RpcPluginConst.COMPILER_PLUGIN_ARTIFACT_ID +import kotlinx.rpc.RpcPluginConst.GROUP_ID +import kotlinx.rpc.RpcPluginConst.PLUGIN_ID +import kotlinx.rpc.RpcPluginConst.libraryKotlinPrefixedVersion import org.gradle.api.Project import org.gradle.api.provider.Provider import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation diff --git a/gradle-plugin/src/main/kotlin/kotlinx/rpc/RPCGradlePlugin.kt b/gradle-plugin/src/main/kotlin/kotlinx/rpc/RpcGradlePlugin.kt similarity index 90% rename from gradle-plugin/src/main/kotlin/kotlinx/rpc/RPCGradlePlugin.kt rename to gradle-plugin/src/main/kotlin/kotlinx/rpc/RpcGradlePlugin.kt index fbbbdaa6..67efffba 100644 --- a/gradle-plugin/src/main/kotlin/kotlinx/rpc/RPCGradlePlugin.kt +++ b/gradle-plugin/src/main/kotlin/kotlinx/rpc/RpcGradlePlugin.kt @@ -7,7 +7,8 @@ package kotlinx.rpc import org.gradle.api.Plugin import org.gradle.api.Project -class RPCGradlePlugin : Plugin<Project> { +@Suppress("unused") +class RpcGradlePlugin : Plugin<Project> { override fun apply(target: Project) { applyCompilerPlugin(target) } diff --git a/gradle-plugin/src/main/kotlin/kotlinx/rpc/RPCPluginConst.kt b/gradle-plugin/src/main/kotlin/kotlinx/rpc/RpcPluginConst.kt similarity index 84% rename from gradle-plugin/src/main/kotlin/kotlinx/rpc/RPCPluginConst.kt rename to gradle-plugin/src/main/kotlin/kotlinx/rpc/RpcPluginConst.kt index 66f172cd..f5ae75d0 100644 --- a/gradle-plugin/src/main/kotlin/kotlinx/rpc/RPCPluginConst.kt +++ b/gradle-plugin/src/main/kotlin/kotlinx/rpc/RpcPluginConst.kt @@ -4,12 +4,12 @@ package kotlinx.rpc -import kotlinx.rpc.RPCPluginConst.INTERNAL_DEVELOPMENT_PROPERTY +import kotlinx.rpc.RpcPluginConst.INTERNAL_DEVELOPMENT_PROPERTY import org.gradle.api.Project import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion import org.jetbrains.kotlin.gradle.utils.loadPropertyFromResources -object RPCPluginConst { +object RpcPluginConst { const val GROUP_ID = "org.jetbrains.kotlinx" const val PLUGIN_ID = "org.jetbrains.kotlinx.rpc.plugin" const val COMPILER_PLUGIN_ARTIFACT_ID = "kotlinx-rpc-compiler-plugin" @@ -24,8 +24,6 @@ object RPCPluginConst { /** * Same as [getKotlinPluginVersion] but without logger - * - * Cannot use with [Project] because [libraryKotlinPrefixedVersion] is called in [RPCKotlinCompilerPlugin] in -all module */ private fun loadKotlinVersion(): String { return object {} diff --git a/krpc/krpc-client/api/krpc-client.api b/krpc/krpc-client/api/krpc-client.api index efb6a309..c4e9ddcc 100644 --- a/krpc/krpc-client/api/krpc-client.api +++ b/krpc/krpc-client/api/krpc-client.api @@ -1,9 +1,9 @@ -public abstract class kotlinx/rpc/krpc/client/KRPCClient : kotlinx/rpc/krpc/internal/RPCServiceHandler, kotlinx/rpc/RpcClient, kotlinx/rpc/krpc/internal/RPCEndpoint { - public fun <init> (Lkotlinx/rpc/krpc/RPCConfig$Client;Lkotlinx/rpc/krpc/RPCTransport;)V +public abstract class kotlinx/rpc/krpc/client/KrpcClient : kotlinx/rpc/krpc/internal/KrpcServiceHandler, kotlinx/rpc/RpcClient, kotlinx/rpc/krpc/internal/KrpcEndpoint { + public fun <init> (Lkotlinx/rpc/krpc/KrpcConfig$Client;Lkotlinx/rpc/krpc/KrpcTransport;)V public final fun call (Lkotlinx/rpc/RpcCall;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun callAsync (Lkotlinx/coroutines/CoroutineScope;Lkotlinx/rpc/RpcCall;)Lkotlinx/coroutines/Deferred; - protected final fun getConfig ()Lkotlinx/rpc/krpc/RPCConfig$Client; - public synthetic fun getConfig ()Lkotlinx/rpc/krpc/RPCConfig; + 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; } 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 similarity index 84% rename from krpc/krpc-client/src/commonMain/kotlin/kotlinx/rpc/krpc/client/KRPCClient.kt rename to krpc/krpc-client/src/commonMain/kotlin/kotlinx/rpc/krpc/client/KrpcClient.kt index 3cbeab11..28816c4d 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 @@ -10,12 +10,12 @@ import kotlinx.rpc.RpcCall import kotlinx.rpc.RpcClient import kotlinx.rpc.descriptor.RpcCallable import kotlinx.rpc.internal.serviceScopeOrNull -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi import kotlinx.rpc.internal.utils.SupervisedCompletableDeferred import kotlinx.rpc.internal.utils.getOrNull import kotlinx.rpc.internal.utils.map.ConcurrentHashMap import kotlinx.rpc.krpc.* -import kotlinx.rpc.krpc.client.internal.RPCClientConnector +import kotlinx.rpc.krpc.client.internal.KrpcClientConnector import kotlinx.rpc.krpc.internal.* import kotlinx.rpc.krpc.internal.logging.CommonLogger import kotlinx.serialization.BinaryFormat @@ -24,6 +24,9 @@ import kotlinx.serialization.StringFormat import kotlin.coroutines.CoroutineContext import kotlin.coroutines.cancellation.CancellationException +@Deprecated("Use KrpcClient instead", ReplaceWith("KrpcClient"), level = DeprecationLevel.ERROR) +public typealias KRPCClient = KrpcClient + /** * Default implementation of [RpcClient]. * Takes care of tracking requests and responses, @@ -32,41 +35,41 @@ import kotlin.coroutines.cancellation.CancellationException * * A simple example of how this client may be implemented: * ```kotlin - * class MyTransport : RPCTransport { /*...*/ } + * class MyTransport : RpcTransport { /*...*/ } * - * class MyClient(config: RPCConfig.Client): KRPCClient(config, MyTransport()) + * class MyClient(config: RpcConfig.Client): KrpcClient(config, MyTransport()) * ``` * * @property config configuration provided for that specific client. Applied to all services that use this client. - * @param transport [RPCTransport] instance that will be used to send and receive RPC messages. + * @param transport [KrpcTransport] instance that will be used to send and receive RPC messages. * IMPORTANT: Must be exclusive to this client, otherwise unexpected behavior may occur. */ @OptIn(InternalCoroutinesApi::class) -public abstract class KRPCClient( - final override val config: RPCConfig.Client, - transport: RPCTransport, -) : RPCServiceHandler(), RpcClient, RPCEndpoint { +public abstract class KrpcClient( + final override val config: KrpcConfig.Client, + transport: KrpcTransport, +) : KrpcServiceHandler(), RpcClient, KrpcEndpoint { // 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 connector by lazy { - RPCClientConnector(config.serialFormatInitializer.build(), transport, config.waitForServices) + KrpcClientConnector(config.serialFormatInitializer.build(), transport, config.waitForServices) } private var connectionId: Long? = null - @InternalRPCApi - final override val sender: RPCMessageSender + @InternalRpcApi + final override val sender: KrpcMessageSender get() = connector private val callCounter = atomic(0L) override val logger: CommonLogger = CommonLogger.logger(objectId()) - private val serverSupportedPlugins: CompletableDeferred<Set<RPCPlugin>> = CompletableDeferred() + private val serverSupportedPlugins: CompletableDeferred<Set<KrpcPlugin>> = CompletableDeferred() - @InternalRPCApi - final override val supportedPlugins: Set<RPCPlugin> + @InternalRpcApi + final override val supportedPlugins: Set<KrpcPlugin> get() = serverSupportedPlugins.getOrNull() ?: emptySet() private var clientCancelled = false @@ -87,7 +90,7 @@ public abstract class KRPCClient( } @OptIn(InternalCoroutinesApi::class) - @InternalRPCApi + @InternalRpcApi final override fun provideStubContext(serviceId: Long): CoroutineContext { val childContext = SupervisorJob(coroutineContext.job).withClientStreamScope() @@ -102,7 +105,7 @@ public abstract class KRPCClient( } private val initHandshake: Job = launch { - connector.sendMessage(RPCProtocolMessage.Handshake(RPCPlugin.ALL)) + connector.sendMessage(KrpcProtocolMessage.Handshake(KrpcPlugin.ALL)) connector.subscribeToProtocolMessages(::handleProtocolMessage) } @@ -116,15 +119,15 @@ public abstract class KRPCClient( serverSupportedPlugins.await() } - private fun handleProtocolMessage(message: RPCProtocolMessage) { + private fun handleProtocolMessage(message: KrpcProtocolMessage) { when (message) { - is RPCProtocolMessage.Handshake -> { + is KrpcProtocolMessage.Handshake -> { connectionId = message.connectionId serverSupportedPlugins.complete(message.supportedPlugins) } - is RPCProtocolMessage.Failure -> { + is KrpcProtocolMessage.Failure -> { logger.error { "Server [${message.connectionId}] failed to process protocol message ${message.failedMessage}: " + message.errorMessage @@ -186,7 +189,7 @@ public abstract class KRPCClient( call: RpcCall, callable: RpcCallable<*>, callResult: CompletableDeferred<T>, - ): RPCCallStreamContextFormatAndId { + ): RpcCallStreamContextFormatAndId { val wrappedCallResult = RequestCompletableDeferred(callResult) val rpcCall = prepareAndExecuteCall(call, callable, wrappedCallResult) @@ -240,7 +243,7 @@ public abstract class KRPCClient( call: RpcCall, callable: RpcCallable<*>, callResult: RequestCompletableDeferred<*>, - ): RPCCallStreamContextFormatAndId { + ): RpcCallStreamContextFormatAndId { // we should wait for the handshake to finish awaitHandshakeCompletion() @@ -256,8 +259,8 @@ public abstract class KRPCClient( ?.serviceCoroutineScope ?.let { streamScopeOrNull(it) } - val streamContext = LazyRPCStreamContext(streamScopeOrNull(), fallbackScope) { - RPCStreamContext(callId, config, connectionId, call.serviceId, it) + val streamContext = LazyKrpcStreamContext(streamScopeOrNull(), fallbackScope) { + KrpcStreamContext(callId, config, connectionId, call.serviceId, it) } val serialFormat = prepareSerialFormat(streamContext) val firstMessage = serializeRequest(callId, call, callable, serialFormat) @@ -273,21 +276,21 @@ public abstract class KRPCClient( callResult = callResult as RequestCompletableDeferred<Any?> ) - return RPCCallStreamContextFormatAndId(streamContext, serialFormat, callId) + return RpcCallStreamContextFormatAndId(streamContext, serialFormat, callId) } - private data class RPCCallStreamContextFormatAndId( - val streamContext: LazyRPCStreamContext, + private data class RpcCallStreamContextFormatAndId( + val streamContext: LazyKrpcStreamContext, val serialFormat: SerialFormat, val callId: String, ) private suspend fun executeCall( callId: String, - streamContext: LazyRPCStreamContext, + streamContext: LazyKrpcStreamContext, call: RpcCall, callable: RpcCallable<*>, - firstMessage: RPCCallMessage, + firstMessage: KrpcCallMessage, serialFormat: SerialFormat, callResult: RequestCompletableDeferred<Any?>, ) { @@ -303,18 +306,18 @@ public abstract class KRPCClient( } private suspend fun handleMessage( - message: RPCCallMessage, - streamContext: LazyRPCStreamContext, + message: KrpcCallMessage, + streamContext: LazyKrpcStreamContext, callable: RpcCallable<*>, serialFormat: SerialFormat, callResult: RequestCompletableDeferred<Any?>, ) { when (message) { - is RPCCallMessage.CallData -> { + is KrpcCallMessage.CallData -> { error("Unexpected message") } - is RPCCallMessage.CallException -> { + is KrpcCallMessage.CallException -> { val cause = runCatching { message.cause.deserialize() } @@ -329,7 +332,7 @@ public abstract class KRPCClient( callResult.completeExceptionally(result) } - is RPCCallMessage.CallSuccess -> { + is KrpcCallMessage.CallSuccess -> { val value = runCatching { val serializerResult = serialFormat.serializersModule.rpcSerializerForType(callable.returnType) @@ -339,29 +342,29 @@ public abstract class KRPCClient( callResult.completeWith(value) } - is RPCCallMessage.StreamCancel -> { + is KrpcCallMessage.StreamCancel -> { streamContext.awaitInitialized().cancelStream(message) } - is RPCCallMessage.StreamFinished -> { + is KrpcCallMessage.StreamFinished -> { streamContext.awaitInitialized().closeStream(message) } - is RPCCallMessage.StreamMessage -> { + is KrpcCallMessage.StreamMessage -> { streamContext.awaitInitialized().send(message, serialFormat) } } } - @InternalRPCApi - final override suspend fun handleCancellation(message: RPCGenericMessage) { + @InternalRpcApi + final override suspend fun handleCancellation(message: KrpcGenericMessage) { when (val type = message.cancellationType()) { CancellationType.ENDPOINT -> { cancel("Closing client after server cancellation") // we cancel this client } CancellationType.CANCELLATION_ACK -> { - val callId = message[RPCPluginKey.CANCELLATION_ID] + val callId = message[KrpcPluginKey.CANCELLATION_ID] ?: error("Expected CANCELLATION_ID for cancellation of type 'request'") val serviceTypeString = cancellingRequests.remove(callId) ?: return @@ -370,7 +373,7 @@ public abstract class KRPCClient( else -> { logger.warn { - "Unsupported ${RPCPluginKey.CANCELLATION_TYPE} $type for client, " + + "Unsupported ${KrpcPluginKey.CANCELLATION_TYPE} $type for client, " + "only 'endpoint' type may be sent by a server" } } @@ -382,12 +385,12 @@ public abstract class KRPCClient( call: RpcCall, callable: RpcCallable<*>, serialFormat: SerialFormat, - ): RPCCallMessage { + ): KrpcCallMessage { val serializerData = serialFormat.serializersModule.rpcSerializerForType(callable.dataType) return when (serialFormat) { is StringFormat -> { val stringValue = serialFormat.encodeToString(serializerData, call.data) - RPCCallMessage.CallDataString( + KrpcCallMessage.CallDataString( callId = callId, serviceType = call.descriptor.fqName, callableName = call.callableName, @@ -400,7 +403,7 @@ public abstract class KRPCClient( is BinaryFormat -> { val binaryValue = serialFormat.encodeToByteArray(serializerData, call.data) - RPCCallMessage.CallDataBinary( + KrpcCallMessage.CallDataBinary( callId = callId, serviceType = call.descriptor.fqName, callableName = call.callableName, diff --git a/krpc/krpc-client/src/commonMain/kotlin/kotlinx/rpc/krpc/client/internal/RPCClientConnector.kt b/krpc/krpc-client/src/commonMain/kotlin/kotlinx/rpc/krpc/client/internal/KrpcClientConnector.kt similarity index 63% rename from krpc/krpc-client/src/commonMain/kotlin/kotlinx/rpc/krpc/client/internal/RPCClientConnector.kt rename to krpc/krpc-client/src/commonMain/kotlin/kotlinx/rpc/krpc/client/internal/KrpcClientConnector.kt index b298c645..105ead2e 100644 --- a/krpc/krpc-client/src/commonMain/kotlin/kotlinx/rpc/krpc/client/internal/RPCClientConnector.kt +++ b/krpc/krpc-client/src/commonMain/kotlin/kotlinx/rpc/krpc/client/internal/KrpcClientConnector.kt @@ -4,7 +4,7 @@ package kotlinx.rpc.krpc.client.internal -import kotlinx.rpc.krpc.RPCTransport +import kotlinx.rpc.krpc.KrpcTransport import kotlinx.rpc.krpc.internal.* import kotlinx.serialization.SerialFormat @@ -19,19 +19,19 @@ internal sealed interface CallSubscriptionId { data object Generic : CallSubscriptionId } -internal class RPCClientConnector private constructor( - private val connector: RPCConnector<CallSubscriptionId> -) : RPCMessageSender by connector { +internal class KrpcClientConnector private constructor( + private val connector: KrpcConnector<CallSubscriptionId> +) : KrpcMessageSender by connector { constructor( serialFormat: SerialFormat, - transport: RPCTransport, + transport: KrpcTransport, waitForServices: Boolean = false, ) : this( - RPCConnector(serialFormat, transport, waitForServices, isServer = false) { + KrpcConnector(serialFormat, transport, waitForServices, isServer = false) { when (this) { - is RPCCallMessage -> CallSubscriptionId.Service(serviceType, callId) - is RPCProtocolMessage -> CallSubscriptionId.Protocol - is RPCGenericMessage -> CallSubscriptionId.Generic + is KrpcCallMessage -> CallSubscriptionId.Service(serviceType, callId) + is KrpcProtocolMessage -> CallSubscriptionId.Protocol + is KrpcGenericMessage -> CallSubscriptionId.Generic } } ) @@ -44,23 +44,23 @@ internal class RPCClientConnector private constructor( suspend fun subscribeToCallResponse( serviceTypeString: String, callId: String, - subscription: suspend (RPCCallMessage) -> Unit, + subscription: suspend (KrpcCallMessage) -> Unit, ) { connector.subscribeToMessages(CallSubscriptionId.Service(serviceTypeString, callId)) { - subscription(it as RPCCallMessage) + subscription(it as KrpcCallMessage) } } - suspend fun subscribeToProtocolMessages(subscription: suspend (RPCProtocolMessage) -> Unit) { + suspend fun subscribeToProtocolMessages(subscription: suspend (KrpcProtocolMessage) -> Unit) { connector.subscribeToMessages(CallSubscriptionId.Protocol) { - subscription(it as RPCProtocolMessage) + subscription(it as KrpcProtocolMessage) } } @Suppress("unused") - suspend fun subscribeToGenericMessages(subscription: suspend (RPCGenericMessage) -> Unit) { + suspend fun subscribeToGenericMessages(subscription: suspend (KrpcGenericMessage) -> Unit) { connector.subscribeToMessages(CallSubscriptionId.Generic) { - subscription(it as RPCGenericMessage) + subscription(it as KrpcGenericMessage) } } } diff --git a/krpc/krpc-core/api/krpc-core.api b/krpc/krpc-core/api/krpc-core.api index 5b0242da..517af2dd 100644 --- a/krpc/krpc-core/api/krpc-core.api +++ b/krpc/krpc-core/api/krpc-core.api @@ -1,42 +1,42 @@ -public abstract interface class kotlinx/rpc/krpc/RPCConfig { - public abstract fun getSerialFormatInitializer ()Lkotlinx/rpc/krpc/serialization/RPCSerialFormatBuilder; +public abstract interface class kotlinx/rpc/krpc/KrpcConfig { + public abstract fun getSerialFormatInitializer ()Lkotlinx/rpc/krpc/serialization/KrpcSerialFormatBuilder; public abstract fun getSharedFlowBuilder ()Lkotlin/jvm/functions/Function0; public abstract fun getWaitForServices ()Z } -public final class kotlinx/rpc/krpc/RPCConfig$Client : kotlinx/rpc/krpc/RPCConfig { - public fun getSerialFormatInitializer ()Lkotlinx/rpc/krpc/serialization/RPCSerialFormatBuilder; +public final class kotlinx/rpc/krpc/KrpcConfig$Client : kotlinx/rpc/krpc/KrpcConfig { + public fun getSerialFormatInitializer ()Lkotlinx/rpc/krpc/serialization/KrpcSerialFormatBuilder; public fun getSharedFlowBuilder ()Lkotlin/jvm/functions/Function0; public fun getWaitForServices ()Z } -public final class kotlinx/rpc/krpc/RPCConfig$Server : kotlinx/rpc/krpc/RPCConfig { - public fun getSerialFormatInitializer ()Lkotlinx/rpc/krpc/serialization/RPCSerialFormatBuilder; +public final class kotlinx/rpc/krpc/KrpcConfig$Server : kotlinx/rpc/krpc/KrpcConfig { + public fun getSerialFormatInitializer ()Lkotlinx/rpc/krpc/serialization/KrpcSerialFormatBuilder; public fun getSharedFlowBuilder ()Lkotlin/jvm/functions/Function0; public fun getWaitForServices ()Z } -public abstract class kotlinx/rpc/krpc/RPCConfigBuilder { +public abstract class kotlinx/rpc/krpc/KrpcConfigBuilder { protected final fun getSharedFlowBuilder ()Lkotlin/jvm/functions/Function0; public final fun getWaitForServices ()Z - protected final fun rpcSerialFormat ()Lkotlinx/rpc/krpc/serialization/RPCSerialFormatBuilder; + protected final fun rpcSerialFormat ()Lkotlinx/rpc/krpc/serialization/KrpcSerialFormatBuilder; public final fun serialization (Lkotlin/jvm/functions/Function1;)V protected final fun setSharedFlowBuilder (Lkotlin/jvm/functions/Function0;)V public final fun setWaitForServices (Z)V public final fun sharedFlowParameters (Lkotlin/jvm/functions/Function1;)V } -public final class kotlinx/rpc/krpc/RPCConfigBuilder$Client : kotlinx/rpc/krpc/RPCConfigBuilder { +public final class kotlinx/rpc/krpc/KrpcConfigBuilder$Client : kotlinx/rpc/krpc/KrpcConfigBuilder { public fun <init> ()V - public final fun build ()Lkotlinx/rpc/krpc/RPCConfig$Client; + public final fun build ()Lkotlinx/rpc/krpc/KrpcConfig$Client; } -public final class kotlinx/rpc/krpc/RPCConfigBuilder$Server : kotlinx/rpc/krpc/RPCConfigBuilder { +public final class kotlinx/rpc/krpc/KrpcConfigBuilder$Server : kotlinx/rpc/krpc/KrpcConfigBuilder { public fun <init> ()V - public final fun build ()Lkotlinx/rpc/krpc/RPCConfig$Server; + public final fun build ()Lkotlinx/rpc/krpc/KrpcConfig$Server; } -public final class kotlinx/rpc/krpc/RPCConfigBuilder$SharedFlowParametersBuilder { +public final class kotlinx/rpc/krpc/KrpcConfigBuilder$SharedFlowParametersBuilder { public static final field DEFAULT_EXTRA_BUFFER_CAPACITY I public static final field DEFAULT_REPLAY I public final fun getExtraBufferCapacity ()I @@ -47,32 +47,32 @@ public final class kotlinx/rpc/krpc/RPCConfigBuilder$SharedFlowParametersBuilder public final fun setReplay (I)V } -public final class kotlinx/rpc/krpc/RPCConfigKt { - public static final fun rpcClientConfig (Lkotlin/jvm/functions/Function1;)Lkotlinx/rpc/krpc/RPCConfig$Client; - public static synthetic fun rpcClientConfig$default (Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lkotlinx/rpc/krpc/RPCConfig$Client; - public static final fun rpcServerConfig (Lkotlin/jvm/functions/Function1;)Lkotlinx/rpc/krpc/RPCConfig$Server; - public static synthetic fun rpcServerConfig$default (Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lkotlinx/rpc/krpc/RPCConfig$Server; +public final class kotlinx/rpc/krpc/KrpcConfigKt { + public static final fun rpcClientConfig (Lkotlin/jvm/functions/Function1;)Lkotlinx/rpc/krpc/KrpcConfig$Client; + public static synthetic fun rpcClientConfig$default (Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lkotlinx/rpc/krpc/KrpcConfig$Client; + public static final fun rpcServerConfig (Lkotlin/jvm/functions/Function1;)Lkotlinx/rpc/krpc/KrpcConfig$Server; + public static synthetic fun rpcServerConfig$default (Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lkotlinx/rpc/krpc/KrpcConfig$Server; } -public abstract interface class kotlinx/rpc/krpc/RPCTransport : kotlinx/coroutines/CoroutineScope { +public abstract interface class kotlinx/rpc/krpc/KrpcTransport : kotlinx/coroutines/CoroutineScope { public abstract fun receive (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public abstract fun receiveCatching-IoAF18A (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; - public abstract fun send (Lkotlinx/rpc/krpc/RPCTransportMessage;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public abstract fun send (Lkotlinx/rpc/krpc/KrpcTransportMessage;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } -public final class kotlinx/rpc/krpc/RPCTransport$DefaultImpls { - public static fun receiveCatching-IoAF18A (Lkotlinx/rpc/krpc/RPCTransport;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; +public final class kotlinx/rpc/krpc/KrpcTransport$DefaultImpls { + public static fun receiveCatching-IoAF18A (Lkotlinx/rpc/krpc/KrpcTransport;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; } -public abstract interface class kotlinx/rpc/krpc/RPCTransportMessage { +public abstract interface class kotlinx/rpc/krpc/KrpcTransportMessage { } -public final class kotlinx/rpc/krpc/RPCTransportMessage$BinaryMessage : kotlinx/rpc/krpc/RPCTransportMessage { +public final class kotlinx/rpc/krpc/KrpcTransportMessage$BinaryMessage : kotlinx/rpc/krpc/KrpcTransportMessage { public fun <init> ([B)V public final fun getValue ()[B } -public final class kotlinx/rpc/krpc/RPCTransportMessage$StringMessage : kotlinx/rpc/krpc/RPCTransportMessage { +public final class kotlinx/rpc/krpc/KrpcTransportMessage$StringMessage : kotlinx/rpc/krpc/KrpcTransportMessage { public fun <init> (Ljava/lang/String;)V public final fun getValue ()Ljava/lang/String; } diff --git a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/RPCConfig.kt b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/KrpcConfig.kt similarity index 65% rename from krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/RPCConfig.kt rename to krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/KrpcConfig.kt index 513a1a0e..76c34924 100644 --- a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/RPCConfig.kt +++ b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/KrpcConfig.kt @@ -7,15 +7,18 @@ package kotlinx.rpc.krpc import kotlinx.coroutines.channels.BufferOverflow import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.SharedFlow -import kotlinx.rpc.internal.utils.InternalRPCApi -import kotlinx.rpc.krpc.serialization.RPCSerialFormat -import kotlinx.rpc.krpc.serialization.RPCSerialFormatBuilder -import kotlinx.rpc.krpc.serialization.RPCSerialFormatConfiguration +import kotlinx.rpc.internal.utils.InternalRpcApi +import kotlinx.rpc.krpc.serialization.KrpcSerialFormat +import kotlinx.rpc.krpc.serialization.KrpcSerialFormatBuilder +import kotlinx.rpc.krpc.serialization.KrpcSerialFormatConfiguration + +@Deprecated("Use KrpcConfigBuilder instead", ReplaceWith("KrpcConfigBuilder"), level = DeprecationLevel.ERROR) +public typealias RPCConfigBuilder = KrpcConfigBuilder /** - * Builder for [RPCConfig]. Provides DSL to configure parameters for KRPCClient and/or KRPCServer. + * Builder for [KrpcConfig]. Provides DSL to configure parameters for KrpcClient and/or KrpcServer. */ -public sealed class RPCConfigBuilder private constructor() { +public sealed class KrpcConfigBuilder private constructor() { /** * DSL for parameters of [MutableSharedFlow] and [SharedFlow]. * @@ -49,7 +52,7 @@ public sealed class RPCConfigBuilder private constructor() { */ public var onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND - @InternalRPCApi + @InternalRpcApi public fun builder(): () -> MutableSharedFlow<Any?> = { MutableSharedFlow(replay, extraBufferCapacity, onBufferOverflow) } @@ -75,14 +78,14 @@ public sealed class RPCConfigBuilder private constructor() { sharedFlowBuilder = SharedFlowParametersBuilder().apply(builder).builder() } - private var serialFormatInitializer: RPCSerialFormatBuilder<*, *>? = null + private var serialFormatInitializer: KrpcSerialFormatBuilder<*, *>? = null - private val configuration = object : RPCSerialFormatConfiguration { - override fun register(rpcSerialFormatInitializer: RPCSerialFormatBuilder.Binary<*, *>) { + private val configuration = object : KrpcSerialFormatConfiguration { + override fun register(rpcSerialFormatInitializer: KrpcSerialFormatBuilder.Binary<*, *>) { serialFormatInitializer = rpcSerialFormatInitializer } - override fun register(rpcSerialFormatInitializer: RPCSerialFormatBuilder.String<*, *>) { + override fun register(rpcSerialFormatInitializer: KrpcSerialFormatBuilder.String<*, *>) { serialFormatInitializer = rpcSerialFormatInitializer } } @@ -99,14 +102,14 @@ public sealed class RPCConfigBuilder private constructor() { * } * ``` * - * @see RPCSerialFormatConfiguration - * @see RPCSerialFormat + * @see KrpcSerialFormatConfiguration + * @see KrpcSerialFormat */ - public fun serialization(builder: RPCSerialFormatConfiguration.() -> Unit) { + public fun serialization(builder: KrpcSerialFormatConfiguration.() -> Unit) { configuration.builder() } - protected fun rpcSerialFormat(): RPCSerialFormatBuilder<*, *> { + protected fun rpcSerialFormat(): KrpcSerialFormatBuilder<*, *> { return when (val format = serialFormatInitializer) { null -> error("Please, choose serialization format") else -> format @@ -122,11 +125,11 @@ public sealed class RPCConfigBuilder private constructor() { public var waitForServices: Boolean = true /** - * @see [RPCConfigBuilder] + * @see [KrpcConfigBuilder] */ - public class Client : RPCConfigBuilder() { - public fun build(): RPCConfig.Client { - return RPCConfig.Client( + public class Client : KrpcConfigBuilder() { + public fun build(): KrpcConfig.Client { + return KrpcConfig.Client( sharedFlowBuilder = sharedFlowBuilder, serialFormatInitializer = rpcSerialFormat(), waitForServices = waitForServices, @@ -135,11 +138,11 @@ public sealed class RPCConfigBuilder private constructor() { } /** - * @see [RPCConfigBuilder] + * @see [KrpcConfigBuilder] */ - public class Server : RPCConfigBuilder() { - public fun build(): RPCConfig.Server { - return RPCConfig.Server( + public class Server : KrpcConfigBuilder() { + public fun build(): KrpcConfig.Server { + return KrpcConfig.Server( sharedFlowBuilder = sharedFlowBuilder, serialFormatInitializer = rpcSerialFormat(), waitForServices = waitForServices, @@ -148,46 +151,49 @@ public sealed class RPCConfigBuilder private constructor() { } } +@Deprecated("Use KrpcConfig instead", ReplaceWith("KrpcConfig"), level = DeprecationLevel.ERROR) +public typealias RPCConfig = KrpcConfig + /** - * Configuration class that is used by kRPC protocol's client and server (KRPCClient and KRPCServer). + * Configuration class that is used by kRPC protocol's client and server (KrpcClient and KrpcServer). */ -public sealed interface RPCConfig { - @InternalRPCApi +public sealed interface KrpcConfig { + @InternalRpcApi public val sharedFlowBuilder: () -> MutableSharedFlow<Any?> - @InternalRPCApi - public val serialFormatInitializer: RPCSerialFormatBuilder<*, *> - @InternalRPCApi + @InternalRpcApi + public val serialFormatInitializer: KrpcSerialFormatBuilder<*, *> + @InternalRpcApi public val waitForServices: Boolean /** - * @see [RPCConfig] + * @see [KrpcConfig] */ public class Client internal constructor( override val sharedFlowBuilder: () -> MutableSharedFlow<Any?>, - override val serialFormatInitializer: RPCSerialFormatBuilder<*, *>, + override val serialFormatInitializer: KrpcSerialFormatBuilder<*, *>, override val waitForServices: Boolean, - ) : RPCConfig + ) : KrpcConfig /** - * @see [RPCConfig] + * @see [KrpcConfig] */ public class Server internal constructor( override val sharedFlowBuilder: () -> MutableSharedFlow<Any?>, - override val serialFormatInitializer: RPCSerialFormatBuilder<*, *>, + override val serialFormatInitializer: KrpcSerialFormatBuilder<*, *>, override val waitForServices: Boolean, - ) : RPCConfig + ) : KrpcConfig } /** - * Creates [RPCConfig.Client] using [RPCConfigBuilder.Client] DSL + * Creates [KrpcConfig.Client] using [KrpcConfigBuilder.Client] DSL */ -public fun rpcClientConfig(builder: RPCConfigBuilder.Client.() -> Unit = {}): RPCConfig.Client { - return RPCConfigBuilder.Client().apply(builder).build() +public fun rpcClientConfig(builder: KrpcConfigBuilder.Client.() -> Unit = {}): KrpcConfig.Client { + return KrpcConfigBuilder.Client().apply(builder).build() } /** - * Creates [RPCConfig.Server] using [RPCConfigBuilder.Server] DSL. + * Creates [KrpcConfig.Server] using [KrpcConfigBuilder.Server] DSL. */ -public fun rpcServerConfig(builder: RPCConfigBuilder.Server.() -> Unit = {}): RPCConfig.Server { - return RPCConfigBuilder.Server().apply(builder).build() +public fun rpcServerConfig(builder: KrpcConfigBuilder.Server.() -> Unit = {}): KrpcConfig.Server { + return KrpcConfigBuilder.Server().apply(builder).build() } diff --git a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/RPCTransport.kt b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/KrpcTransport.kt similarity index 62% rename from krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/RPCTransport.kt rename to krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/KrpcTransport.kt index 590e048f..0a5b1567 100644 --- a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/RPCTransport.kt +++ b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/KrpcTransport.kt @@ -6,50 +6,56 @@ package kotlinx.rpc.krpc import kotlinx.coroutines.CoroutineScope +@Deprecated("Use KrpcTransportMessage instead", ReplaceWith("KrpcTransportMessage"), level = DeprecationLevel.ERROR) +public typealias RPCTransportMessage = KrpcTransportMessage + /** * A single message that can be transferred from one RPC endpoint to another. * Can be either of string or binary type. */ -public sealed interface RPCTransportMessage { - public class StringMessage(public val value: String) : RPCTransportMessage +public sealed interface KrpcTransportMessage { + public class StringMessage(public val value: String) : KrpcTransportMessage - public class BinaryMessage(public val value: ByteArray) : RPCTransportMessage + public class BinaryMessage(public val value: ByteArray) : KrpcTransportMessage } +@Deprecated("Use KrpcTransport instead", ReplaceWith("KrpcTransport"), level = DeprecationLevel.ERROR) +public typealias RPCTransport = KrpcTransport + /** - * An abstraction of transport capabilities for KRPCClient and KRPCServer. + * An abstraction of transport capabilities for KrpcClient and KrpcServer. * * For developers of custom transports: * - The implementation should be able to handle both binary and string formats, * though not necessary if you absolutely sure that only one will be supplied and received. - * - The KRPCClient and KRPCServer suppose that they have exclusive instance of transport. + * - The KrpcClient and KrpcServer suppose that they have exclusive instance of transport. * That means that each client or/and server should have only one transport instance, * otherwise some messages may be lost or processed incorrectly. * - The implementation should manage lifetime of the connection using its [CoroutineScope]. * * Good example of the implementation is KtorTransport, that uses websocket protocol to deliver messages. */ -public interface RPCTransport : CoroutineScope { +public interface KrpcTransport : CoroutineScope { /** * Sends a single encoded RPC message over network (or any other medium) to a peer endpoint. * * @param message a message to send. Either of string or binary type. */ - public suspend fun send(message: RPCTransportMessage) + public suspend fun send(message: KrpcTransportMessage) /** * Suspends until next RPC message from a peer endpoint is received and then returns it. * * @return received RPC message. */ - public suspend fun receive(): RPCTransportMessage + public suspend fun receive(): KrpcTransportMessage /** * Suspends until next RPC message from a peer endpoint is received and then returns it. * * @return received RPC message as a [Result]. */ - public suspend fun receiveCatching(): Result<RPCTransportMessage> { + public suspend fun receiveCatching(): Result<KrpcTransportMessage> { return runCatching { receive() } } } 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 d68c479f..a52ba615 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 @@ -5,8 +5,8 @@ package kotlinx.rpc.krpc import kotlinx.coroutines.* -import kotlinx.rpc.internal.utils.ExperimentalRPCApi -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.ExperimentalRpcApi +import kotlinx.rpc.internal.utils.InternalRpcApi import kotlinx.rpc.internal.utils.map.ConcurrentHashMap import kotlin.contracts.ExperimentalContracts import kotlin.contracts.InvocationKind @@ -48,23 +48,23 @@ public class StreamScope internal constructor( } } - @InternalRPCApi + @InternalRpcApi public fun onScopeCompletion(handler: (Throwable?) -> Unit) { scopeJob.invokeOnCompletion(handler) } - @InternalRPCApi + @InternalRpcApi public fun onScopeCompletion(callId: String, handler: (Throwable?) -> Unit) { getRequestScope(callId).coroutineContext.job.invokeOnCompletion(onCancelling = true, handler = handler) } - @InternalRPCApi + @InternalRpcApi public fun cancelRequestScopeById(callId: String, message: String, cause: Throwable?): Job? { return requests.remove(callId)?.apply { cancel(message, cause) }?.coroutineContext?.job } // Group stream launches by callId. In case one fails, so do others - @InternalRPCApi + @InternalRpcApi public fun launch(callId: String, block: suspend CoroutineScope.() -> Unit): Job { return getRequestScope(callId).launch(block = block) } @@ -84,16 +84,16 @@ public class StreamScope internal constructor( override val key: CoroutineContext.Key<*> = Key } - @InternalRPCApi + @InternalRpcApi public enum class Role { Client, Server; } } -@InternalRPCApi +@InternalRpcApi public fun CoroutineContext.withClientStreamScope(): CoroutineContext = withStreamScope(StreamScope.Role.Client) -@InternalRPCApi +@InternalRpcApi public fun CoroutineContext.withServerStreamScope(): CoroutineContext = withStreamScope(StreamScope.Role.Server) @OptIn(InternalCoroutinesApi::class) @@ -103,12 +103,12 @@ internal fun CoroutineContext.withStreamScope(role: StreamScope.Role): Coroutine } } -@InternalRPCApi +@InternalRpcApi public suspend fun streamScopeOrNull(): StreamScope? { return currentCoroutineContext()[StreamScope.Element.Key]?.scope } -@InternalRPCApi +@InternalRpcApi public fun streamScopeOrNull(scope: CoroutineScope): StreamScope? { return scope.coroutineContext[StreamScope.Element.Key]?.scope } @@ -121,7 +121,7 @@ internal fun noStreamScopeError(): Nothing { ) } -@InternalRPCApi +@InternalRpcApi public suspend fun <T> callScoped(callId: String, block: suspend CoroutineScope.() -> T): T { val context = currentCoroutineContext() @@ -204,7 +204,7 @@ private fun CoroutineContext.checkContextForStreamScope() { * Creates a [StreamScope] entity for manual stream management. */ @JsName("StreamScope_fun") -@ExperimentalRPCApi +@ExperimentalRpcApi public fun StreamScope(parent: CoroutineContext): StreamScope { parent.checkContextForStreamScope() @@ -215,7 +215,7 @@ public fun StreamScope(parent: CoroutineContext): StreamScope { * Adds manually managed [StreamScope] to the current context. */ @OptIn(ExperimentalContracts::class) -@ExperimentalRPCApi +@ExperimentalRpcApi public suspend fun <T> withStreamScope(scope: StreamScope, block: suspend CoroutineScope.() -> T): T { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) @@ -251,7 +251,7 @@ public suspend fun <T> withStreamScope(scope: StreamScope, block: suspend Corout * } * ``` */ -@ExperimentalRPCApi +@ExperimentalRpcApi public suspend fun invokeOnStreamScopeCompletion(throwIfNoScope: Boolean = true, block: (Throwable?) -> Unit) { val streamScope = streamScopeOrNull() ?: noStreamScopeError() 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 ce038da2..4922db07 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 @@ -5,9 +5,10 @@ package kotlinx.rpc.krpc.internal import kotlinx.rpc.internal.utils.IndexedEnum -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi +import kotlinx.rpc.krpc.internal.CancellationType.entries -@InternalRPCApi +@InternalRpcApi @Suppress("detekt.MagicNumber") public enum class CancellationType(override val uniqueIndex: Int) : IndexedEnum { ENDPOINT(0), @@ -23,9 +24,9 @@ public enum class CancellationType(override val uniqueIndex: Int) : IndexedEnum } } -@InternalRPCApi -public fun RPCMessage.cancellationType(): CancellationType? { - return get(RPCPluginKey.CANCELLATION_TYPE)?.let { value -> +@InternalRpcApi +public fun KrpcMessage.cancellationType(): CancellationType? { + return get(KrpcPluginKey.CANCELLATION_TYPE)?.let { value -> CancellationType.valueOfNull(value) } } 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 20d574ef..c1615260 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 @@ -5,9 +5,9 @@ package kotlinx.rpc.krpc.internal import kotlinx.rpc.internal.typeName -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi -@InternalRPCApi +@InternalRpcApi public fun serializeException(cause: Throwable): SerializedException { val message = cause.message ?: "Unknown exception" val stacktrace = cause.stackElements() @@ -19,7 +19,7 @@ public fun serializeException(cause: Throwable): SerializedException { internal expect fun Throwable.stackElements(): List<StackElement> -@InternalRPCApi +@InternalRpcApi public expect fun SerializedException.deserialize(): Throwable internal expect class DeserializedException( diff --git a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/RPCConnector.kt b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcConnector.kt similarity index 75% rename from krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/RPCConnector.kt rename to krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcConnector.kt index 96667604..08bdcf32 100644 --- a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/RPCConnector.kt +++ b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcConnector.kt @@ -9,62 +9,61 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock -import kotlinx.rpc.internal.utils.InternalRPCApi -import kotlinx.rpc.krpc.RPCTransport -import kotlinx.rpc.krpc.RPCTransportMessage +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.serialization.* -import kotlin.collections.set -@InternalRPCApi -public interface RPCMessageSender : CoroutineScope { - public suspend fun sendMessage(message: RPCMessage) +@InternalRpcApi +public interface KrpcMessageSender : CoroutineScope { + public suspend fun sendMessage(message: KrpcMessage) } -private typealias RPCMessageHandler = suspend (RPCMessage) -> Unit +private typealias KrpcMessageHandler = suspend (KrpcMessage) -> Unit /** * Represents a connector for remote procedure call (RPC) communication. - * This class is responsible for sending and receiving [RPCMessage] over a specified transport. + * This class is responsible for sending and receiving [KrpcMessage] over a specified transport. * * @param SubscriptionKey the type of the subscription key used for message subscriptions. - * @param serialFormat the serial format used for encoding and decoding [RPCMessage]. + * @param serialFormat the serial format used for encoding and decoding [KrpcMessage]. * @param transport the transport used for sending and receiving encoded RPC messages. * @param waitForSubscribers a flag indicating whether the connector should wait for subscribers * if no service is available to process the message immediately. - * If false, the endpoint that sent the message will receive a [RPCCallMessage.CallException] + * If false, the endpoint that sent the message will receive a [KrpcCallMessage.CallException] * that says that there were no services to process its message. * @param isServer flag indication whether this is a server or a client. - * @param getKey a lambda function that returns the subscription key for a given [RPCCallMessage]. + * @param getKey a lambda function that returns the subscription key for a given [KrpcCallMessage]. * DO NOT use actual dumper in production! */ -@InternalRPCApi -public class RPCConnector<SubscriptionKey>( +@InternalRpcApi +public class KrpcConnector<SubscriptionKey>( private val serialFormat: SerialFormat, - private val transport: RPCTransport, + private val transport: KrpcTransport, private val waitForSubscribers: Boolean = true, isServer: Boolean, - private val getKey: RPCMessage.() -> SubscriptionKey, -) : RPCMessageSender, CoroutineScope by transport { + 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 mutex = Mutex() - private val waiting = mutableMapOf<SubscriptionKey, MutableList<RPCMessage>>() - private val subscriptions = mutableMapOf<SubscriptionKey, RPCMessageHandler>() + private val waiting = mutableMapOf<SubscriptionKey, MutableList<KrpcMessage>>() + private val subscriptions = mutableMapOf<SubscriptionKey, KrpcMessageHandler>() private val dumpLogger by lazy { DumpLoggerContainer.provide() } - override suspend fun sendMessage(message: RPCMessage) { + override suspend fun sendMessage(message: KrpcMessage) { val transportMessage = when (serialFormat) { is StringFormat -> { - RPCTransportMessage.StringMessage(serialFormat.encodeToString(message)) + KrpcTransportMessage.StringMessage(serialFormat.encodeToString(message)) } is BinaryFormat -> { - RPCTransportMessage.BinaryMessage(serialFormat.encodeToByteArray(message)) + KrpcTransportMessage.BinaryMessage(serialFormat.encodeToByteArray(message)) } else -> { @@ -83,7 +82,7 @@ public class RPCConnector<SubscriptionKey>( launch { mutex.withLock { subscriptions.remove(key) } } } - public suspend fun subscribeToMessages(key: SubscriptionKey, handler: RPCMessageHandler) { + public suspend fun subscribeToMessages(key: SubscriptionKey, handler: KrpcMessageHandler) { mutex.withLock { subscriptions[key] = handler processWaiters(key, handler) @@ -98,13 +97,13 @@ public class RPCConnector<SubscriptionKey>( } } - private suspend fun processMessage(transportMessage: RPCTransportMessage) { - val message: RPCMessage = when { - serialFormat is StringFormat && transportMessage is RPCTransportMessage.StringMessage -> { + private suspend fun processMessage(transportMessage: KrpcTransportMessage) { + val message: KrpcMessage = when { + serialFormat is StringFormat && transportMessage is KrpcTransportMessage.StringMessage -> { serialFormat.decodeFromString(transportMessage.value) } - serialFormat is BinaryFormat && transportMessage is RPCTransportMessage.BinaryMessage -> { + serialFormat is BinaryFormat && transportMessage is KrpcTransportMessage.BinaryMessage -> { serialFormat.decodeFromByteArray(transportMessage.value) } @@ -120,17 +119,17 @@ public class RPCConnector<SubscriptionKey>( processMessage(message) } - private suspend fun processMessage(message: RPCMessage) = mutex.withLock { + private suspend fun processMessage(message: KrpcMessage) = mutex.withLock { when (message) { - is RPCCallMessage -> processServiceMessage(message) - is RPCProtocolMessage, is RPCGenericMessage -> processNonServiceMessage(message) + is KrpcCallMessage -> processServiceMessage(message) + is KrpcProtocolMessage, is KrpcGenericMessage -> processNonServiceMessage(message) } } - private suspend fun processNonServiceMessage(message: RPCMessage) { + private suspend fun processNonServiceMessage(message: KrpcMessage) { when (val result = tryHandle(message)) { is HandlerResult.Failure -> { - val failure = RPCProtocolMessage.Failure( + val failure = KrpcProtocolMessage.Failure( connectionId = message.connectionId, errorMessage = "Failed to process ${message::class.simpleName}, error: ${result.cause?.message}", failedMessage = message, @@ -147,7 +146,7 @@ public class RPCConnector<SubscriptionKey>( } } - private suspend fun processServiceMessage(message: RPCCallMessage) { + private suspend fun processServiceMessage(message: KrpcCallMessage) { val result = tryHandle(message) // todo better exception processing probably @@ -171,7 +170,7 @@ public class RPCConnector<SubscriptionKey>( initialCause, ) - val callException = RPCCallMessage.CallException( + val callException = KrpcCallMessage.CallException( callId = message.callId, serviceType = message.serviceType, cause = serializeException(cause), @@ -184,8 +183,8 @@ public class RPCConnector<SubscriptionKey>( } private suspend fun tryHandle( - message: RPCMessage, - handler: RPCMessageHandler? = null, + message: KrpcMessage, + handler: KrpcMessageHandler? = null, ): HandlerResult { val key = message.getKey() val subscriber = handler ?: subscriptions[key] ?: return HandlerResult.NoSubscription @@ -209,7 +208,7 @@ public class RPCConnector<SubscriptionKey>( } } - private suspend fun processWaiters(key: SubscriptionKey, handler: RPCMessageHandler) { + private suspend fun processWaiters(key: SubscriptionKey, handler: KrpcMessageHandler) { if (waiting.isEmpty()) return val iterator = waiting[key]?.iterator() ?: return @@ -230,10 +229,10 @@ public class RPCConnector<SubscriptionKey>( const val CLIENT_ROLE = "Client" @OptIn(ExperimentalStdlibApi::class) - private fun RPCTransportMessage.dump(): String { + private fun KrpcTransportMessage.dump(): String { return when (this) { - is RPCTransportMessage.StringMessage -> value - is RPCTransportMessage.BinaryMessage -> value.toHexString() + is KrpcTransportMessage.StringMessage -> value + is KrpcTransportMessage.BinaryMessage -> value.toHexString() } } } diff --git a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/RPCEndpoint.kt b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcEndpoint.kt similarity index 55% rename from krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/RPCEndpoint.kt rename to krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcEndpoint.kt index 6397b0b2..88c8f107 100644 --- a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/RPCEndpoint.kt +++ b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcEndpoint.kt @@ -6,23 +6,23 @@ package kotlinx.rpc.krpc.internal import kotlinx.coroutines.cancel import kotlinx.coroutines.launch -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi -@InternalRPCApi -public interface RPCEndpoint { - @InternalRPCApi - public val sender: RPCMessageSender - @InternalRPCApi - public val supportedPlugins: Set<RPCPlugin> +@InternalRpcApi +public interface KrpcEndpoint { + @InternalRpcApi + public val sender: KrpcMessageSender + @InternalRpcApi + public val supportedPlugins: Set<KrpcPlugin> - @InternalRPCApi + @InternalRpcApi public fun sendCancellation( type: CancellationType, serviceId: String?, cancellationId: String?, closeTransportAfterSending: Boolean = false, ) { - if (!supportedPlugins.contains(RPCPlugin.CANCELLATION)) { + if (!supportedPlugins.contains(KrpcPlugin.CANCELLATION)) { if (closeTransportAfterSending) { sender.cancel("Transport finished") } @@ -31,13 +31,13 @@ public interface RPCEndpoint { } val sendJob = sender.launch { - val message = RPCGenericMessage( + val message = KrpcGenericMessage( connectionId = null, pluginParams = listOfNotNull( - RPCPluginKey.GENERIC_MESSAGE_TYPE to RPCGenericMessage.CANCELLATION_TYPE, - RPCPluginKey.CANCELLATION_TYPE to type.toString(), - serviceId?.let { RPCPluginKey.CLIENT_SERVICE_ID to serviceId }, - cancellationId?.let { RPCPluginKey.CANCELLATION_ID to cancellationId }, + KrpcPluginKey.GENERIC_MESSAGE_TYPE to KrpcGenericMessage.CANCELLATION_TYPE, + KrpcPluginKey.CANCELLATION_TYPE to type.toString(), + serviceId?.let { KrpcPluginKey.CLIENT_SERVICE_ID to serviceId }, + cancellationId?.let { KrpcPluginKey.CANCELLATION_ID to cancellationId }, ).toMap() ) @@ -51,11 +51,11 @@ public interface RPCEndpoint { } } - @InternalRPCApi - public suspend fun handleGenericMessage(message: RPCGenericMessage) { + @InternalRpcApi + public suspend fun handleGenericMessage(message: KrpcGenericMessage) { try { - when (message.pluginParams?.get(RPCPluginKey.GENERIC_MESSAGE_TYPE)) { - RPCGenericMessage.CANCELLATION_TYPE -> { + when (message.pluginParams?.get(KrpcPluginKey.GENERIC_MESSAGE_TYPE)) { + KrpcGenericMessage.CANCELLATION_TYPE -> { handleCancellation(message) } @@ -64,7 +64,7 @@ public interface RPCEndpoint { } } } catch (e: IllegalStateException) { - val failure = RPCProtocolMessage.Failure( + val failure = KrpcProtocolMessage.Failure( errorMessage = e.message ?: "Unknown error", connectionId = message.connectionId, ) @@ -73,6 +73,6 @@ public interface RPCEndpoint { } } - @InternalRPCApi - public suspend fun handleCancellation(message: RPCGenericMessage) + @InternalRpcApi + public suspend fun handleCancellation(message: KrpcGenericMessage) } diff --git a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/RPCMessage.kt b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcMessage.kt similarity index 75% rename from krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/RPCMessage.kt rename to krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcMessage.kt index 4aba70fd..63ba30f3 100644 --- a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/RPCMessage.kt +++ b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcMessage.kt @@ -4,14 +4,14 @@ package kotlinx.rpc.krpc.internal -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable -@InternalRPCApi +@InternalRpcApi @Serializable @SerialName("org.jetbrains.krpc.internal.transport.RPCMessage") -public sealed interface RPCMessage { +public sealed interface KrpcMessage { //NOTE: It turned out that the connectionId is not necessary when we have // * 1-to-1 client-server connections. // * But I left it for future usages, and now it is always null. @@ -25,100 +25,100 @@ public sealed interface RPCMessage { * Map is much easier to update without breaking compatibility, * thought being more limiting in terms of content. * - * Use [RPCPluginKey] to retrieve a value. + * Use [KrpcPluginKey] to retrieve a value. * The structure of the values should not change over time to ensure compatibility. */ - public val pluginParams: Map<RPCPluginKey, String>? + public val pluginParams: Map<KrpcPluginKey, String>? } /** * Use this message to add new message types without adding new classes to the protocol hierarchy. */ -@InternalRPCApi +@InternalRpcApi @Serializable @SerialName("org.jetbrains.krpc.internal.transport.RPCGenericMessage") -public data class RPCGenericMessage( +public data class KrpcGenericMessage( override val connectionId: Long?, - override val pluginParams: Map<RPCPluginKey, String>? -) : RPCMessage { - @InternalRPCApi + override val pluginParams: Map<KrpcPluginKey, String>? +) : KrpcMessage { + @InternalRpcApi public companion object { public const val CANCELLATION_TYPE: String = "cancellation" } } -@InternalRPCApi +@InternalRpcApi @Serializable @SerialName("org.jetbrains.krpc.internal.transport.RPCProtocolMessage") -public sealed interface RPCProtocolMessage : RPCMessage { - override val pluginParams: Map<RPCPluginKey, String> +public sealed interface KrpcProtocolMessage : KrpcMessage { + override val pluginParams: Map<KrpcPluginKey, String> - @InternalRPCApi + @InternalRpcApi @Serializable @SerialName("org.jetbrains.krpc.internal.transport.RPCProtocolMessage.Handshake") public data class Handshake( - val supportedPlugins: Set<RPCPlugin>, + val supportedPlugins: Set<KrpcPlugin>, override val connectionId: Long? = null, - override val pluginParams: Map<RPCPluginKey, String> = emptyMap(), - ) : RPCProtocolMessage + override val pluginParams: Map<KrpcPluginKey, String> = emptyMap(), + ) : KrpcProtocolMessage - @InternalRPCApi + @InternalRpcApi @Serializable @SerialName("org.jetbrains.krpc.internal.transport.RPCProtocolMessage.Failure") public data class Failure( val errorMessage: String, override val connectionId: Long? = null, - val failedMessage: RPCMessage? = null, - override val pluginParams: Map<RPCPluginKey, String> = emptyMap(), - ) : RPCProtocolMessage + val failedMessage: KrpcMessage? = null, + override val pluginParams: Map<KrpcPluginKey, String> = emptyMap(), + ) : KrpcProtocolMessage } /** * Only service messages (method calls, streams, etc.), name is kept for easier compatibility. */ -@InternalRPCApi +@InternalRpcApi @Serializable @SerialName("org.jetbrains.krpc.RPCMessage") -public sealed interface RPCCallMessage : RPCMessage { +public sealed interface KrpcCallMessage : KrpcMessage { public val callId: String public val serviceType: String public val serviceId: Long? - @InternalRPCApi + @InternalRpcApi @SerialName("org.jetbrains.krpc.internal.transport.RPCMessage.Data") public sealed interface Data { - @InternalRPCApi + @InternalRpcApi public sealed interface BinaryData : Data { public val data: ByteArray } - @InternalRPCApi + @InternalRpcApi public sealed interface StringData : Data { public val data: String } } - @InternalRPCApi + @InternalRpcApi @Serializable @SerialName("org.jetbrains.krpc.RPCMessage.CallResult") - public sealed interface CallResult : RPCCallMessage + public sealed interface CallResult : KrpcCallMessage - @InternalRPCApi + @InternalRpcApi @Serializable @SerialName("org.jetbrains.krpc.internal.transport.RPCMessage.CallData") - public sealed interface CallData : RPCCallMessage, Data { + public sealed interface CallData : KrpcCallMessage, Data { public val callableName: String public val callType: CallType? } - @InternalRPCApi + @InternalRpcApi @Serializable @SerialName("org.jetbrains.krpc.internal.transport.RPCMessage.CallType") public enum class CallType { Method, Field, } - @InternalRPCApi + @InternalRpcApi @Serializable @SerialName("org.jetbrains.krpc.RPCMessage.CallData") public data class CallDataString( @@ -130,10 +130,10 @@ public sealed interface RPCCallMessage : RPCMessage { override val data: String, override val connectionId: Long? = null, override val serviceId: Long? = null, - override val pluginParams: Map<RPCPluginKey, String>? = emptyMap(), + override val pluginParams: Map<KrpcPluginKey, String>? = emptyMap(), ) : CallData, Data.StringData - @InternalRPCApi + @InternalRpcApi @Suppress("ArrayInDataClass") @Serializable @SerialName("org.jetbrains.krpc.internal.transport.RPCMessage.CallDataBinary") @@ -146,15 +146,15 @@ public sealed interface RPCCallMessage : RPCMessage { override val data: ByteArray, override val connectionId: Long? = null, override val serviceId: Long? = null, - override val pluginParams: Map<RPCPluginKey, String>? = emptyMap(), + override val pluginParams: Map<KrpcPluginKey, String>? = emptyMap(), ) : CallData, Data.BinaryData - @InternalRPCApi + @InternalRpcApi @Serializable @SerialName("org.jetbrains.krpc.internal.transport.RPCMessage.CallSuccess") public sealed interface CallSuccess : CallResult, Data - @InternalRPCApi + @InternalRpcApi @Serializable @SerialName("org.jetbrains.krpc.RPCMessage.CallSuccess") public data class CallSuccessString( @@ -163,10 +163,10 @@ public sealed interface RPCCallMessage : RPCMessage { override val data: String, override val connectionId: Long? = null, override val serviceId: Long? = null, - override val pluginParams: Map<RPCPluginKey, String>? = emptyMap(), + override val pluginParams: Map<KrpcPluginKey, String>? = emptyMap(), ) : CallSuccess, Data.StringData - @InternalRPCApi + @InternalRpcApi @Suppress("ArrayInDataClass") @Serializable @SerialName("org.jetbrains.krpc.internal.transport.RPCMessage.CallSuccessBinary") @@ -176,13 +176,13 @@ public sealed interface RPCCallMessage : RPCMessage { override val data: ByteArray, override val connectionId: Long? = null, override val serviceId: Long? = null, - override val pluginParams: Map<RPCPluginKey, String>? = emptyMap(), + override val pluginParams: Map<KrpcPluginKey, String>? = emptyMap(), ) : CallSuccess, Data.BinaryData /** * Both for client and server */ - @InternalRPCApi + @InternalRpcApi @Serializable @SerialName("org.jetbrains.krpc.RPCMessage.CallException") public data class CallException( @@ -191,17 +191,17 @@ public sealed interface RPCCallMessage : RPCMessage { val cause: SerializedException, override val connectionId: Long? = null, override val serviceId: Long? = null, - override val pluginParams: Map<RPCPluginKey, String>? = emptyMap(), + override val pluginParams: Map<KrpcPluginKey, String>? = emptyMap(), ) : CallResult - @InternalRPCApi + @InternalRpcApi @Serializable @SerialName("org.jetbrains.krpc.internal.transport.RPCMessage.StreamMessage") - public sealed interface StreamMessage : RPCCallMessage, Data { + public sealed interface StreamMessage : KrpcCallMessage, Data { public val streamId: String } - @InternalRPCApi + @InternalRpcApi @Serializable @SerialName("org.jetbrains.krpc.RPCMessage.StreamMessage") public data class StreamMessageString( @@ -212,10 +212,10 @@ public sealed interface RPCCallMessage : RPCMessage { override val data: String, override val connectionId: Long? = null, override val serviceId: Long? = null, - override val pluginParams: Map<RPCPluginKey, String>? = emptyMap(), + override val pluginParams: Map<KrpcPluginKey, String>? = emptyMap(), ) : StreamMessage, Data.StringData - @InternalRPCApi + @InternalRpcApi @Suppress("ArrayInDataClass") @Serializable @SerialName("org.jetbrains.krpc.internal.transport.RPCMessage.StreamMessageBinary") @@ -227,10 +227,10 @@ public sealed interface RPCCallMessage : RPCMessage { override val data: ByteArray, override val connectionId: Long? = null, override val serviceId: Long? = null, - override val pluginParams: Map<RPCPluginKey, String>? = emptyMap(), + override val pluginParams: Map<KrpcPluginKey, String>? = emptyMap(), ) : StreamMessage, Data.BinaryData - @InternalRPCApi + @InternalRpcApi @Serializable @SerialName("org.jetbrains.krpc.RPCMessage.StreamCancel") public data class StreamCancel( @@ -241,10 +241,10 @@ public sealed interface RPCCallMessage : RPCMessage { val cause: SerializedException, override val connectionId: Long? = null, override val serviceId: Long? = null, - override val pluginParams: Map<RPCPluginKey, String>? = emptyMap(), - ) : RPCCallMessage + override val pluginParams: Map<KrpcPluginKey, String>? = emptyMap(), + ) : KrpcCallMessage - @InternalRPCApi + @InternalRpcApi @Serializable @SerialName("org.jetbrains.krpc.RPCMessage.StreamFinished") public data class StreamFinished( @@ -254,9 +254,9 @@ public sealed interface RPCCallMessage : RPCMessage { val streamId: String, override val connectionId: Long? = null, override val serviceId: Long? = null, - override val pluginParams: Map<RPCPluginKey, String>? = emptyMap(), - ) : RPCCallMessage + override val pluginParams: Map<KrpcPluginKey, String>? = emptyMap(), + ) : KrpcCallMessage } -@InternalRPCApi -public operator fun RPCMessage.get(key: RPCPluginKey): String? = pluginParams?.get(key) +@InternalRpcApi +public operator fun KrpcMessage.get(key: KrpcPluginKey): String? = pluginParams?.get(key) diff --git a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/RPCPlugin.kt b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcPlugin.kt similarity index 75% rename from krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/RPCPlugin.kt rename to krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcPlugin.kt index f2303f1a..e39e3ef7 100644 --- a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/RPCPlugin.kt +++ b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcPlugin.kt @@ -5,7 +5,7 @@ package kotlinx.rpc.krpc.internal import kotlinx.rpc.internal.utils.IndexedEnum -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi import kotlinx.rpc.internal.utils.ShortEnumKSerializer import kotlinx.serialization.Serializable @@ -17,14 +17,14 @@ import kotlinx.serialization.Serializable * * Only entries with ordinals from 0 to 65500 are allowed, others are reserved for tests. */ -@InternalRPCApi -@Serializable(with = RPCPluginSerializer::class) -public enum class RPCPlugin( +@InternalRpcApi +@Serializable(with = KrpcPluginSerializer::class) +public enum class KrpcPlugin( override val uniqueIndex: Int, /** * Only for maintenance purposes. Indicates when the plugin was added. */ - @Suppress("unused") private val since: RPCVersion, + @Suppress("unused") private val since: KrpcVersion, ) : IndexedEnum { /** * Represents all unknown plugins. @@ -33,7 +33,7 @@ public enum class RPCPlugin( * * Can be safely ignored. Endpoint must only handle the plugins it knows of. */ - UNKNOWN(0, RPCVersion.V_0_1_0_BETA), + UNKNOWN(0, KrpcVersion.V_0_1_0_BETA), /** * Represents the handshake plugin of the kRPC protocol. @@ -44,25 +44,25 @@ public enum class RPCPlugin( * However, servers will be able to communicate with clients that do not support handshake, * BUT not the other way around. */ - HANDSHAKE(1, RPCVersion.V_0_1_0_BETA), + HANDSHAKE(1, KrpcVersion.V_0_1_0_BETA), /** * This feature adds support for proper service/request cancellation over the network. */ - CANCELLATION(2, RPCVersion.V_0_1_0_BETA), + CANCELLATION(2, KrpcVersion.V_0_1_0_BETA), ; - @InternalRPCApi + @InternalRpcApi public companion object { /** * A set of all plugins for the current version of the library. */ - public val ALL: Set<RPCPlugin> = RPCPlugin.entries.toSet() - UNKNOWN + public val ALL: Set<KrpcPlugin> = KrpcPlugin.entries.toSet() - UNKNOWN } } -private class RPCPluginSerializer : ShortEnumKSerializer<RPCPlugin>( - kClass = RPCPlugin::class, - unknownValue = RPCPlugin.UNKNOWN, - allValues = RPCPlugin.ALL, +private class KrpcPluginSerializer : ShortEnumKSerializer<KrpcPlugin>( + 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 new file mode 100644 index 00000000..703995ba --- /dev/null +++ b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcPluginKey.kt @@ -0,0 +1,67 @@ +/* + * 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.krpc.internal + +import kotlinx.rpc.internal.utils.IndexedEnum +import kotlinx.rpc.internal.utils.InternalRpcApi +import kotlinx.rpc.internal.utils.ShortEnumKSerializer +import kotlinx.serialization.Serializable + +/** + * Keys for [KrpcMessage.pluginParams] map. + * + * [associatedPlugin] is a [KrpcPlugin] that introduces this key into the map. + * One [KrpcPlugin] can introduce multiple keys. + * + * IMPORTANT: Enum [uniqueIndex] MUST NOT be changed once set! This will cause unexpected behavior. + * + * Only entries with ordinals from 0 to 65500 are allowed, other are reserved for tests. + */ +@InternalRpcApi +@Serializable(with = KrpcPluginKeySerializer::class) +public enum class KrpcPluginKey(override val uniqueIndex: Int, private val associatedPlugin: KrpcPlugin): IndexedEnum { + /** + * Failed to decode key, possible due to different endpoint versions. + */ + UNKNOWN(0, KrpcPlugin.UNKNOWN), + + GENERIC_MESSAGE_TYPE(1, KrpcPlugin.HANDSHAKE), + + /** + * Represents the type of resource that is being canceled. + * Possible values: 'request', 'service', 'endpoint'. + */ + CANCELLATION_TYPE(2, KrpcPlugin.CANCELLATION), + + /** + * Represents id of the resource that is being canceled. + * It can be a service type name, service id, request call id or nothing (for endpoint cancellation). + */ + CANCELLATION_ID(3, KrpcPlugin.CANCELLATION), + + /** + * Represents a service id that is unique to a current connection. + */ + CLIENT_SERVICE_ID(4, KrpcPlugin.CANCELLATION), + ; + + init { + require(ordinal == 0 || associatedPlugin != KrpcPlugin.UNKNOWN) { + error("associatedPlugin must not be $KrpcPlugin.${KrpcPlugin.UNKNOWN} " + + "for anything other than $KrpcPluginKey.UNKNOWN") + } + } + + @InternalRpcApi + public companion object { + public val ALL: Set<KrpcPluginKey> = KrpcPluginKey.entries.toSet() - UNKNOWN + } +} + +private class KrpcPluginKeySerializer : ShortEnumKSerializer<KrpcPluginKey>( + kClass = KrpcPluginKey::class, + unknownValue = KrpcPluginKey.UNKNOWN, + allValues = KrpcPluginKey.ALL, +) diff --git a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/RPCServiceHandler.kt b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcServiceHandler.kt similarity index 85% rename from krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/RPCServiceHandler.kt rename to krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcServiceHandler.kt index 080b5325..17b5aa03 100644 --- a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/RPCServiceHandler.kt +++ b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcServiceHandler.kt @@ -12,8 +12,8 @@ import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import kotlinx.rpc.descriptor.RpcCallable import kotlinx.rpc.descriptor.RpcInvokator -import kotlinx.rpc.internal.utils.InternalRPCApi -import kotlinx.rpc.krpc.RPCConfig +import kotlinx.rpc.internal.utils.InternalRpcApi +import kotlinx.rpc.krpc.KrpcConfig import kotlinx.rpc.krpc.internal.logging.CommonLogger import kotlinx.serialization.BinaryFormat import kotlinx.serialization.KSerializer @@ -21,23 +21,23 @@ import kotlinx.serialization.SerialFormat import kotlinx.serialization.StringFormat import kotlinx.serialization.modules.SerializersModule -@InternalRPCApi -public abstract class RPCServiceHandler { - protected abstract val sender: RPCMessageSender - protected abstract val config: RPCConfig +@InternalRpcApi +public abstract class KrpcServiceHandler { + protected abstract val sender: KrpcMessageSender + protected abstract val config: KrpcConfig protected abstract val logger: CommonLogger - protected suspend fun handleIncomingHotFlows(streamContext: RPCStreamContext) { + protected suspend fun handleIncomingHotFlows(streamContext: KrpcStreamContext) { for (hotFlow in streamContext.incomingHotFlows) { streamContext.launch { - /** Start consuming incoming requests, see [RPCIncomingHotFlow.emit] */ + /** Start consuming incoming requests, see [KrpcIncomingHotFlow.emit] */ hotFlow.emit(null) } } } protected suspend fun handleOutgoingStreams( - streamContext: RPCStreamContext, + streamContext: KrpcStreamContext, serialFormat: SerialFormat, serviceTypeString: String, ) { @@ -64,7 +64,7 @@ public abstract class RPCServiceHandler { } catch (@Suppress("detekt.TooGenericExceptionCaught") cause: Throwable) { mutex.withLock { val serializedReason = serializeException(cause) - val message = RPCCallMessage.StreamCancel( + val message = KrpcCallMessage.StreamCancel( callId = outgoingStream.callId, serviceType = serviceTypeString, streamId = outgoingStream.streamId, @@ -78,7 +78,7 @@ public abstract class RPCServiceHandler { } mutex.withLock { - val message = RPCCallMessage.StreamFinished( + val message = KrpcCallMessage.StreamFinished( callId = outgoingStream.callId, serviceType = serviceTypeString, streamId = outgoingStream.streamId, @@ -98,7 +98,7 @@ public abstract class RPCServiceHandler { serialFormat: SerialFormat, flow: Flow<*>, serviceTypeString: String, - outgoingStream: RPCStreamCall, + outgoingStream: KrpcStreamCall, ) { flow.collect { // because we can send new message for the new flow, @@ -107,7 +107,7 @@ public abstract class RPCServiceHandler { val message = when (serialFormat) { is StringFormat -> { val stringData = serialFormat.encodeToString(outgoingStream.elementSerializer, it) - RPCCallMessage.StreamMessageString( + KrpcCallMessage.StreamMessageString( callId = outgoingStream.callId, serviceType = serviceTypeString, streamId = outgoingStream.streamId, @@ -119,7 +119,7 @@ public abstract class RPCServiceHandler { is BinaryFormat -> { val binaryData = serialFormat.encodeToByteArray(outgoingStream.elementSerializer, it) - RPCCallMessage.StreamMessageBinary( + KrpcCallMessage.StreamMessageBinary( callId = outgoingStream.callId, serviceType = serviceTypeString, streamId = outgoingStream.streamId, @@ -139,7 +139,7 @@ public abstract class RPCServiceHandler { } } - protected fun prepareSerialFormat(rpcFlowContext: LazyRPCStreamContext): SerialFormat { + protected fun prepareSerialFormat(rpcFlowContext: LazyKrpcStreamContext): SerialFormat { val module = SerializersModule { contextual(Flow::class) { @Suppress("UNCHECKED_CAST") @@ -160,10 +160,10 @@ public abstract class RPCServiceHandler { return config.serialFormatInitializer.applySerializersModuleAndBuild(module) } - protected fun RpcCallable<*>.toMessageCallType(): RPCCallMessage.CallType { + protected fun RpcCallable<*>.toMessageCallType(): KrpcCallMessage.CallType { return when (invokator) { - is RpcInvokator.Method -> RPCCallMessage.CallType.Method - is RpcInvokator.Field -> RPCCallMessage.CallType.Field + is RpcInvokator.Method -> KrpcCallMessage.CallType.Method + is RpcInvokator.Field -> KrpcCallMessage.CallType.Field } } } diff --git a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/RPCStreamCall.kt b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcStreamCall.kt similarity index 91% rename from krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/RPCStreamCall.kt rename to krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcStreamCall.kt index 5e65b219..6d22b4f2 100644 --- a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/RPCStreamCall.kt +++ b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcStreamCall.kt @@ -6,7 +6,7 @@ package kotlinx.rpc.krpc.internal import kotlinx.serialization.KSerializer -internal data class RPCStreamCall( +internal data class KrpcStreamCall( val callId: String, val streamId: String, val stream: Any, diff --git a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/RPCStreamContext.kt b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcStreamContext.kt similarity index 86% rename from krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/RPCStreamContext.kt rename to krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcStreamContext.kt index 8335a38e..ba9a09ed 100644 --- a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/RPCStreamContext.kt +++ b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcStreamContext.kt @@ -12,25 +12,25 @@ import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.flow import kotlinx.coroutines.selects.select -import kotlinx.rpc.internal.utils.InternalRPCApi +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.set -import kotlinx.rpc.krpc.RPCConfig +import kotlinx.rpc.krpc.KrpcConfig import kotlinx.rpc.krpc.StreamScope import kotlinx.rpc.krpc.noStreamScopeError import kotlinx.serialization.KSerializer import kotlinx.serialization.SerialFormat import kotlin.coroutines.CoroutineContext -@InternalRPCApi -public class LazyRPCStreamContext( +@InternalRpcApi +public class LazyKrpcStreamContext( public val streamScopeOrNull: StreamScope?, private val fallbackScope: StreamScope? = null, - private val initializer: (StreamScope) -> RPCStreamContext, + private val initializer: (StreamScope) -> KrpcStreamContext, ) { - private val deferred = CompletableDeferred<RPCStreamContext>() + private val deferred = CompletableDeferred<KrpcStreamContext>() private val lazyValue by lazy(LazyThreadSafetyMode.SYNCHRONIZED) { if (streamScopeOrNull == null && (STREAM_SCOPES_ENABLED || fallbackScope == null)) { noStreamScopeError() @@ -41,17 +41,17 @@ public class LazyRPCStreamContext( initializer(streamScope).also { deferred.complete(it) } } - public suspend fun awaitInitialized(): RPCStreamContext = deferred.await() + public suspend fun awaitInitialized(): KrpcStreamContext = deferred.await() - public val valueOrNull: RPCStreamContext? get() = if (deferred.isCompleted) lazyValue else null + public val valueOrNull: KrpcStreamContext? get() = if (deferred.isCompleted) lazyValue else null - public fun initialize(): RPCStreamContext = lazyValue + public fun initialize(): KrpcStreamContext = lazyValue } -@InternalRPCApi -public class RPCStreamContext( +@InternalRpcApi +public class KrpcStreamContext( private val callId: String, - private val config: RPCConfig, + private val config: KrpcConfig, private val connectionId: Long?, private val serviceId: Long?, public val streamScope: StreamScope, @@ -64,19 +64,19 @@ public class RPCStreamContext( // thread-safe set private val closedStreams = ConcurrentHashMap<String, CompletableDeferred<Unit>>() - @InternalRPCApi + @InternalRpcApi public inline fun launchIf( - condition: RPCStreamContext.() -> Boolean, - noinline block: suspend CoroutineScope.(RPCStreamContext) -> Unit, + condition: KrpcStreamContext.() -> Boolean, + noinline block: suspend CoroutineScope.(KrpcStreamContext) -> Unit, ) { if (condition(this)) { launch(block) } } - public fun launch(block: suspend CoroutineScope.(RPCStreamContext) -> Unit) { + public fun launch(block: suspend CoroutineScope.(KrpcStreamContext) -> Unit) { streamScope.launch(callId) { - block(this@RPCStreamContext) + block(this@KrpcStreamContext) } } @@ -99,7 +99,7 @@ public class RPCStreamContext( private var incomingStreamsInitialized: Boolean = false private val incomingStreams by lazy { incomingStreamsInitialized = true - ConcurrentHashMap<String, CompletableDeferred<RPCStreamCall>>() + ConcurrentHashMap<String, CompletableDeferred<KrpcStreamCall>>() } private var incomingChannelsInitialized: Boolean = false @@ -109,7 +109,7 @@ public class RPCStreamContext( } private var outgoingStreamsInitialized: Boolean = false - internal val outgoingStreams: Channel<RPCStreamCall> by lazy { + internal val outgoingStreams: Channel<KrpcStreamCall> by lazy { outgoingStreamsInitialized = true Channel(capacity = Channel.UNLIMITED) } @@ -127,7 +127,7 @@ public class RPCStreamContext( ): String { val id = "$STREAM_ID_PREFIX${streamIdCounter.getAndIncrement()}" outgoingStreams.trySend( - RPCStreamCall( + KrpcStreamCall( callId = callId, streamId = id, stream = stream, @@ -150,7 +150,7 @@ public class RPCStreamContext( incomingChannels[streamId] = incoming val stream = streamOf<StreamT>(streamId, streamKind, stateFlowInitialValue, incoming) - incomingStreams[streamId] = RPCStreamCall( + incomingStreams[streamId] = KrpcStreamCall( callId = callId, streamId = streamId, stream = stream, @@ -211,7 +211,7 @@ public class RPCStreamContext( StreamKind.SharedFlow -> { val sharedFlow: MutableSharedFlow<Any?> = config.sharedFlowBuilder() - object : RPCIncomingHotFlow(sharedFlow, ::consumeFlow), MutableSharedFlow<Any?> by sharedFlow { + object : RpcIncomingHotFlow(sharedFlow, ::consumeFlow), MutableSharedFlow<Any?> by sharedFlow { override suspend fun collect(collector: FlowCollector<Any?>): Nothing { super.collect(collector) } @@ -225,7 +225,7 @@ public class RPCStreamContext( StreamKind.StateFlow -> { val stateFlow = MutableStateFlow(stateFlowInitialValue) - object : RPCIncomingHotFlow(stateFlow, ::consumeFlow), MutableStateFlow<Any?> by stateFlow { + object : RpcIncomingHotFlow(stateFlow, ::consumeFlow), MutableStateFlow<Any?> by stateFlow { override suspend fun collect(collector: FlowCollector<Any?>): Nothing { super.collect(collector) } @@ -238,16 +238,16 @@ public class RPCStreamContext( } as StreamT } - public suspend fun closeStream(message: RPCCallMessage.StreamFinished) { + public suspend fun closeStream(message: KrpcCallMessage.StreamFinished) { incomingChannelOf(message.streamId)?.send(StreamEnd) } - public suspend fun cancelStream(message: RPCCallMessage.StreamCancel) { + public suspend fun cancelStream(message: KrpcCallMessage.StreamCancel) { incomingChannelOf(message.streamId)?.send(StreamCancel(message.cause.deserialize())) } - public suspend fun send(message: RPCCallMessage.StreamMessage, serialFormat: SerialFormat) { - val info: RPCStreamCall? = select { + public suspend fun send(message: KrpcCallMessage.StreamMessage, serialFormat: SerialFormat) { + val info: KrpcStreamCall? = select { incomingStreams.getDeferred(message.streamId).onAwait { it } closedStreams.getDeferred(message.streamId).onAwait { null } closed.onAwait { null } @@ -294,7 +294,7 @@ public class RPCStreamContext( if (incomingStreamsInitialized) { incomingStreams.values .mapNotNull { it.getOrNull()?.stream } - .filterIsInstance<RPCIncomingHotFlow>() + .filterIsInstance<RpcIncomingHotFlow>() .forEach { stream -> stream.subscriptionContexts.forEach { it.cancel(CancellationException("Stream closed", cause)) @@ -320,7 +320,7 @@ private object StreamEnd private class StreamCancel(val cause: Throwable? = null) -private abstract class RPCIncomingHotFlow( +private abstract class RpcIncomingHotFlow( private val rawFlow: MutableSharedFlow<Any?>, private val consume: suspend (FlowCollector<Any?>, onError: (Throwable) -> Unit) -> Unit, ) : MutableSharedFlow<Any?> { diff --git a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/RPCVersion.kt b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcVersion.kt similarity index 88% rename from krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/RPCVersion.kt rename to krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcVersion.kt index a15e7e56..71e5f7ff 100644 --- a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/RPCVersion.kt +++ b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/KrpcVersion.kt @@ -7,7 +7,7 @@ package kotlinx.rpc.krpc.internal /** * Release versions of the library */ -internal enum class RPCVersion { +internal enum class KrpcVersion { /** * Version 0.1.0 */ 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 72e7c330..f93c63c6 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 @@ -4,11 +4,11 @@ package kotlinx.rpc.krpc.internal -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi private const val HEX_RADIX = 16 -@InternalRPCApi +@InternalRpcApi public fun Any.objectId(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-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/RPCPluginKey.kt b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/RPCPluginKey.kt deleted file mode 100644 index 6e96221f..00000000 --- a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/RPCPluginKey.kt +++ /dev/null @@ -1,67 +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.krpc.internal - -import kotlinx.rpc.internal.utils.IndexedEnum -import kotlinx.rpc.internal.utils.InternalRPCApi -import kotlinx.rpc.internal.utils.ShortEnumKSerializer -import kotlinx.serialization.Serializable - -/** - * Keys for [RPCMessage.pluginParams] map. - * - * [associatedPlugin] is a [RPCPlugin] that introduces this key into the map. - * One [RPCPlugin] can introduce multiple keys. - * - * IMPORTANT: Enum [uniqueIndex] MUST NOT be changed once set! This will cause unexpected behavior. - * - * Only entries with ordinals from 0 to 65500 are allowed, other are reserved for tests. - */ -@InternalRPCApi -@Serializable(with = RPCPluginKeySerializer::class) -public enum class RPCPluginKey(override val uniqueIndex: Int, private val associatedPlugin: RPCPlugin): IndexedEnum { - /** - * Failed to decode key, possible due to different endpoint versions. - */ - UNKNOWN(0, RPCPlugin.UNKNOWN), - - GENERIC_MESSAGE_TYPE(1, RPCPlugin.HANDSHAKE), - - /** - * Represents the type of resource that is being canceled. - * Possible values: 'request', 'service', 'endpoint'. - */ - CANCELLATION_TYPE(2, RPCPlugin.CANCELLATION), - - /** - * Represents id of the resource that is being canceled. - * It can be a service type name, service id, request call id or nothing (for endpoint cancellation). - */ - CANCELLATION_ID(3, RPCPlugin.CANCELLATION), - - /** - * Represents a service id that is unique to a current connection. - */ - CLIENT_SERVICE_ID(4, RPCPlugin.CANCELLATION), - ; - - init { - require(ordinal == 0 || associatedPlugin != RPCPlugin.UNKNOWN) { - error("associatedPlugin must not be $RPCPlugin.${RPCPlugin.UNKNOWN} " + - "for anything other than $RPCPluginKey.UNKNOWN") - } - } - - @InternalRPCApi - public companion object { - public val ALL: Set<RPCPluginKey> = RPCPluginKey.entries.toSet() - UNKNOWN - } -} - -private class RPCPluginKeySerializer : ShortEnumKSerializer<RPCPluginKey>( - kClass = RPCPluginKey::class, - unknownValue = RPCPluginKey.UNKNOWN, - allValues = RPCPluginKey.ALL, -) diff --git a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/SerializationUtils.kt b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/SerializationUtils.kt index 6691fc58..2fb38e81 100644 --- a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/SerializationUtils.kt +++ b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/SerializationUtils.kt @@ -7,7 +7,7 @@ package kotlinx.rpc.krpc.internal import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.StateFlow -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi import kotlinx.serialization.* import kotlinx.serialization.modules.SerializersModule import kotlin.reflect.KClass @@ -27,7 +27,7 @@ internal fun SerializersModule.buildContextual(type: KType): KSerializer<Any?> { return result as? KSerializer<Any?> ?: error("No serializer found for $type") } -@InternalRPCApi +@InternalRpcApi public fun SerializersModule.rpcSerializerForType(type: KType): KSerializer<Any?> { return when (type.classifier) { Flow::class, SharedFlow::class, StateFlow::class -> buildContextual(type) @@ -35,13 +35,13 @@ public fun SerializersModule.rpcSerializerForType(type: KType): KSerializer<Any? } } -@InternalRPCApi +@InternalRpcApi public fun unsupportedSerialFormatError(serialFormat: SerialFormat): Nothing { error("Unsupported serial format ${serialFormat::class}, only StringFormat and BinaryFormats are supported") } internal fun unexpectedDataFormatForProvidedSerialFormat( - data: RPCCallMessage.Data, + data: KrpcCallMessage.Data, shouldBeBinary: Boolean, ): Nothing { val (expected, actual) = when { @@ -53,15 +53,15 @@ internal fun unexpectedDataFormatForProvidedSerialFormat( "message is in $actual format (${data::class}), but provided SerialFormat is $expected") } -@InternalRPCApi +@InternalRpcApi public fun decodeMessageData( serialFormat: SerialFormat, dataSerializer: KSerializer<Any?>, - data: RPCCallMessage.Data, + data: KrpcCallMessage.Data, ): Any? { return when (serialFormat) { is StringFormat -> { - if (data !is RPCCallMessage.Data.StringData) { + if (data !is KrpcCallMessage.Data.StringData) { unexpectedDataFormatForProvidedSerialFormat(data, shouldBeBinary = false) } @@ -69,7 +69,7 @@ public fun decodeMessageData( } is BinaryFormat -> { - if (data !is RPCCallMessage.Data.BinaryData) { + if (data !is KrpcCallMessage.Data.BinaryData) { unexpectedDataFormatForProvidedSerialFormat(data, shouldBeBinary = true) } diff --git a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/SerializedException.kt b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/SerializedException.kt index e112ed33..ef9512e4 100644 --- a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/SerializedException.kt +++ b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/SerializedException.kt @@ -4,11 +4,11 @@ package kotlinx.rpc.krpc.internal -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable -@InternalRPCApi +@InternalRpcApi @Serializable @SerialName("org.jetbrains.krpc.StackElement") public data class StackElement( @@ -18,7 +18,7 @@ public data class StackElement( val lineNumber: Int ) -@InternalRPCApi +@InternalRpcApi @Serializable @SerialName("org.jetbrains.krpc.SerializedException") public data class SerializedException( diff --git a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/StreamSerializer.kt b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/StreamSerializer.kt index a83d06cc..f34e22c7 100644 --- a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/StreamSerializer.kt +++ b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/StreamSerializer.kt @@ -20,7 +20,7 @@ internal sealed class StreamSerializer<StreamT : Any>(private val streamKind: St private const val STATE_FLOW_INITIAL_VALUE_SERIAL_NAME = "stateFlowInitialValue" } - protected abstract val context: RPCStreamContext + protected abstract val context: KrpcStreamContext protected abstract val elementType: KSerializer<Any?> protected open fun ClassSerialDescriptorBuilder.descriptorExtension() { } @@ -53,17 +53,17 @@ internal sealed class StreamSerializer<StreamT : Any>(private val streamKind: St } class Flow( - override val context: RPCStreamContext, + override val context: KrpcStreamContext, override val elementType: KSerializer<Any?>, ) : StreamSerializer<kotlinx.coroutines.flow.Flow<Any?>>(StreamKind.Flow) class SharedFlow( - override val context: RPCStreamContext, + override val context: KrpcStreamContext, override val elementType: KSerializer<Any?>, ) : StreamSerializer<kotlinx.coroutines.flow.SharedFlow<Any?>>(StreamKind.SharedFlow) class StateFlow( - override val context: RPCStreamContext, + override val context: KrpcStreamContext, override val elementType: KSerializer<Any?>, ) : StreamSerializer<kotlinx.coroutines.flow.StateFlow<Any?>>(StreamKind.StateFlow) { override fun ClassSerialDescriptorBuilder.descriptorExtension() { diff --git a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/devStreamScope.kt b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/devStreamScope.kt index c3ba0e53..ca89f135 100644 --- a/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/devStreamScope.kt +++ b/krpc/krpc-core/src/commonMain/kotlin/kotlinx/rpc/krpc/internal/devStreamScope.kt @@ -4,7 +4,7 @@ package kotlinx.rpc.krpc.internal -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi /** * For legacy internal users ONLY. @@ -14,5 +14,5 @@ import kotlinx.rpc.internal.utils.InternalRPCApi * is replaced with service's [kotlinx.rpc.krpc.StreamScope] * obtained via [kotlinx.rpc.krpc.withClientStreamScope]. */ -@InternalRPCApi +@InternalRpcApi public const val STREAM_SCOPES_ENABLED: Boolean = true diff --git a/krpc/krpc-core/src/jsMain/kotlin/kotlinx/rpc/krpc/internal/ExceptionUtils.js.kt b/krpc/krpc-core/src/jsMain/kotlin/kotlinx/rpc/krpc/internal/ExceptionUtils.js.kt index 67babd76..a3a1017b 100644 --- a/krpc/krpc-core/src/jsMain/kotlin/kotlinx/rpc/krpc/internal/ExceptionUtils.js.kt +++ b/krpc/krpc-core/src/jsMain/kotlin/kotlinx/rpc/krpc/internal/ExceptionUtils.js.kt @@ -6,7 +6,7 @@ package kotlinx.rpc.krpc.internal -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi internal actual class DeserializedException actual constructor( private val toStringMessage: String, @@ -24,7 +24,7 @@ internal actual class DeserializedException actual constructor( internal actual fun Throwable.stackElements(): List<StackElement> = emptyList() -@InternalRPCApi +@InternalRpcApi public actual fun SerializedException.deserialize(): Throwable { return DeserializedException(toStringMessage, message, stacktrace, cause, className) } diff --git a/krpc/krpc-core/src/jvmMain/kotlin/kotlinx/rpc/krpc/internal/ExceptionUtils.jvm.kt b/krpc/krpc-core/src/jvmMain/kotlin/kotlinx/rpc/krpc/internal/ExceptionUtils.jvm.kt index ea357ba5..53ccb464 100644 --- a/krpc/krpc-core/src/jvmMain/kotlin/kotlinx/rpc/krpc/internal/ExceptionUtils.jvm.kt +++ b/krpc/krpc-core/src/jvmMain/kotlin/kotlinx/rpc/krpc/internal/ExceptionUtils.jvm.kt @@ -4,7 +4,7 @@ package kotlinx.rpc.krpc.internal -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi import java.lang.reflect.Constructor import java.lang.reflect.Modifier @@ -37,7 +37,7 @@ internal actual fun Throwable.stackElements(): List<StackElement> = stackTrace.m ) } -@InternalRPCApi +@InternalRpcApi public actual fun SerializedException.deserialize(): Throwable { try { val clazz = Class.forName(className) diff --git a/krpc/krpc-core/src/wasmJsMain/kotlin/kotlinx/rpc/krpc/internal/ExceptionUtils.wasm.kt b/krpc/krpc-core/src/wasmJsMain/kotlin/kotlinx/rpc/krpc/internal/ExceptionUtils.wasm.kt index 67babd76..a3a1017b 100644 --- a/krpc/krpc-core/src/wasmJsMain/kotlin/kotlinx/rpc/krpc/internal/ExceptionUtils.wasm.kt +++ b/krpc/krpc-core/src/wasmJsMain/kotlin/kotlinx/rpc/krpc/internal/ExceptionUtils.wasm.kt @@ -6,7 +6,7 @@ package kotlinx.rpc.krpc.internal -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi internal actual class DeserializedException actual constructor( private val toStringMessage: String, @@ -24,7 +24,7 @@ internal actual class DeserializedException actual constructor( internal actual fun Throwable.stackElements(): List<StackElement> = emptyList() -@InternalRPCApi +@InternalRpcApi public actual fun SerializedException.deserialize(): Throwable { return DeserializedException(toStringMessage, message, stacktrace, cause, className) } diff --git a/krpc/krpc-ktor/krpc-ktor-client/api/krpc-ktor-client.api b/krpc/krpc-ktor/krpc-ktor-client/api/krpc-ktor-client.api index 8dccbf23..2cc3957b 100644 --- a/krpc/krpc-ktor/krpc-ktor-client/api/krpc-ktor-client.api +++ b/krpc/krpc-ktor/krpc-ktor-client/api/krpc-ktor-client.api @@ -1,3 +1,12 @@ +public final class kotlinx/rpc/krpc/ktor/client/KrpcKt { + public static final fun getKrpc ()Lio/ktor/client/plugins/api/ClientPlugin; + public static final fun getRPC ()Lio/ktor/client/plugins/api/ClientPlugin; + public static final fun installKrpc (Lio/ktor/client/HttpClientConfig;Lkotlin/jvm/functions/Function1;)V + public static synthetic fun installKrpc$default (Lio/ktor/client/HttpClientConfig;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V + public static final fun installRPC (Lio/ktor/client/HttpClientConfig;Lkotlin/jvm/functions/Function1;)V + public static synthetic fun installRPC$default (Lio/ktor/client/HttpClientConfig;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V +} + public final class kotlinx/rpc/krpc/ktor/client/KtorClientDslKt { public static final fun rpc (Lio/ktor/client/HttpClient;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static final fun rpc (Lio/ktor/client/HttpClient;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; @@ -7,13 +16,7 @@ public final class kotlinx/rpc/krpc/ktor/client/KtorClientDslKt { public static synthetic fun rpcConfig$default (Lio/ktor/client/request/HttpRequestBuilder;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V } -public abstract interface class kotlinx/rpc/krpc/ktor/client/KtorRPCClient : kotlinx/rpc/RpcClient { +public abstract interface class kotlinx/rpc/krpc/ktor/client/KtorRpcClient : kotlinx/rpc/RpcClient { public abstract fun getWebSocketSession ()Lio/ktor/websocket/WebSocketSession; } -public final class kotlinx/rpc/krpc/ktor/client/RPCKt { - public static final fun getRPC ()Lio/ktor/client/plugins/api/ClientPlugin; - public static final fun installRPC (Lio/ktor/client/HttpClientConfig;Lkotlin/jvm/functions/Function1;)V - public static synthetic fun installRPC$default (Lio/ktor/client/HttpClientConfig;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V -} - diff --git a/krpc/krpc-ktor/krpc-ktor-client/src/commonMain/kotlin/kotlinx/rpc/krpc/ktor/client/Krpc.kt b/krpc/krpc-ktor/krpc-ktor-client/src/commonMain/kotlin/kotlinx/rpc/krpc/ktor/client/Krpc.kt new file mode 100644 index 00000000..204c8b3c --- /dev/null +++ b/krpc/krpc-ktor/krpc-ktor-client/src/commonMain/kotlin/kotlinx/rpc/krpc/ktor/client/Krpc.kt @@ -0,0 +1,38 @@ +/* + * 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.krpc.ktor.client + +import io.ktor.client.* +import io.ktor.client.plugins.api.* +import io.ktor.client.plugins.websocket.* +import io.ktor.util.* +import kotlinx.rpc.krpc.KrpcConfigBuilder + +internal val KrpcClientPluginAttributesKey = AttributeKey<KrpcConfigBuilder.Client>("KrpcClientPluginAttributesKey") + +@Deprecated("Use Krpc instead", ReplaceWith("Krpc"), level = DeprecationLevel.ERROR) +public val RPC: ClientPlugin<KrpcConfigBuilder.Client> get() = Krpc + +/** + * Ktor client plugin that allows to configure RPC globally for all instances obtained via [rpc] functions. + */ +public val Krpc: ClientPlugin<KrpcConfigBuilder.Client> = createClientPlugin("Krpc", { KrpcConfigBuilder.Client() }) { + client.attributes.put(KrpcClientPluginAttributesKey, pluginConfig) +} + +@Deprecated("Use installKrpc instead", ReplaceWith("installKrpc"), level = DeprecationLevel.ERROR) +public fun HttpClientConfig<*>.installRPC( + configure: KrpcConfigBuilder.Client.() -> Unit = {} +) = installKrpc(configure) + +/** + * Installs [WebSockets] and [Krpc] client plugins + */ +public fun HttpClientConfig<*>.installKrpc( + configure: KrpcConfigBuilder.Client.() -> Unit = {} +) { + install(WebSockets) + install(Krpc, configure) +} diff --git a/krpc/krpc-ktor/krpc-ktor-client/src/commonMain/kotlin/kotlinx/rpc/krpc/ktor/client/KtorClientDsl.kt b/krpc/krpc-ktor/krpc-ktor-client/src/commonMain/kotlin/kotlinx/rpc/krpc/ktor/client/KtorClientDsl.kt index d10e1441..f54ee0a3 100644 --- a/krpc/krpc-ktor/krpc-ktor-client/src/commonMain/kotlin/kotlinx/rpc/krpc/ktor/client/KtorClientDsl.kt +++ b/krpc/krpc-ktor/krpc-ktor-client/src/commonMain/kotlin/kotlinx/rpc/krpc/ktor/client/KtorClientDsl.kt @@ -10,22 +10,22 @@ import io.ktor.client.plugins.websocket.* import io.ktor.client.request.* import io.ktor.util.* import kotlinx.rpc.RpcClient -import kotlinx.rpc.krpc.RPCConfigBuilder +import kotlinx.rpc.krpc.KrpcConfigBuilder import kotlinx.rpc.krpc.rpcClientConfig -private val RPCRequestConfigAttributeKey = AttributeKey<RPCConfigBuilder.Client.() -> Unit>( - name = "RPCRequestConfigAttributeKey" +private val KrpcRequestConfigAttributeKey = AttributeKey<KrpcConfigBuilder.Client.() -> Unit>( + name = "KrpcRequestConfigAttributeKey" ) /** * Extension function for the [HttpRequestBuilder] that allows to configure RPC for the call. * Usually used with the [rpc] functions. - * Overrides [RPC] plugin configuration. + * Overrides [Krpc] plugin configuration. * * @param configBuilder The function that configures RPC. */ -public fun HttpRequestBuilder.rpcConfig(configBuilder: RPCConfigBuilder.Client.() -> Unit = {}) { - attributes.put(RPCRequestConfigAttributeKey, configBuilder) +public fun HttpRequestBuilder.rpcConfig(configBuilder: KrpcConfigBuilder.Client.() -> Unit = {}) { + attributes.put(KrpcRequestConfigAttributeKey, configBuilder) } /** @@ -39,7 +39,7 @@ public fun HttpRequestBuilder.rpcConfig(configBuilder: RPCConfigBuilder.Client.( public suspend fun HttpClient.rpc( urlString: String, block: HttpRequestBuilder.() -> Unit = {}, -): KtorRPCClient { +): KtorRpcClient { return rpc { url(urlString) block() @@ -55,22 +55,22 @@ public suspend fun HttpClient.rpc( */ public suspend fun HttpClient.rpc( block: HttpRequestBuilder.() -> Unit = {}, -): KtorRPCClient { +): KtorRpcClient { pluginOrNull(WebSockets) ?: error("RPC for client requires $WebSockets plugin to be installed firstly") - var requestConfigBuilder: RPCConfigBuilder.Client.() -> Unit = {} + var requestConfigBuilder: KrpcConfigBuilder.Client.() -> Unit = {} val session = webSocketSession { block() - attributes.getOrNull(RPCRequestConfigAttributeKey)?.let { + attributes.getOrNull(KrpcRequestConfigAttributeKey)?.let { requestConfigBuilder = it } } - val pluginConfigBuilder = attributes.getOrNull(RPCClientPluginAttributesKey) + val pluginConfigBuilder = attributes.getOrNull(KrpcClientPluginAttributesKey) val rpcConfig = pluginConfigBuilder?.apply(requestConfigBuilder)?.build() ?: rpcClientConfig(requestConfigBuilder) - return KtorRPCClientImpl(session, rpcConfig) + return KtorKrpcClientImpl(session, rpcConfig) } diff --git a/krpc/krpc-ktor/krpc-ktor-client/src/commonMain/kotlin/kotlinx/rpc/krpc/ktor/client/KtorRPCClient.kt b/krpc/krpc-ktor/krpc-ktor-client/src/commonMain/kotlin/kotlinx/rpc/krpc/ktor/client/KtorRpcClient.kt similarity index 66% rename from krpc/krpc-ktor/krpc-ktor-client/src/commonMain/kotlin/kotlinx/rpc/krpc/ktor/client/KtorRPCClient.kt rename to krpc/krpc-ktor/krpc-ktor-client/src/commonMain/kotlin/kotlinx/rpc/krpc/ktor/client/KtorRpcClient.kt index 359e1688..922f8844 100644 --- a/krpc/krpc-ktor/krpc-ktor-client/src/commonMain/kotlin/kotlinx/rpc/krpc/ktor/client/KtorRPCClient.kt +++ b/krpc/krpc-ktor/krpc-ktor-client/src/commonMain/kotlin/kotlinx/rpc/krpc/ktor/client/KtorRpcClient.kt @@ -6,20 +6,20 @@ package kotlinx.rpc.krpc.ktor.client import io.ktor.websocket.* import kotlinx.rpc.RpcClient -import kotlinx.rpc.krpc.RPCConfig -import kotlinx.rpc.krpc.client.KRPCClient +import kotlinx.rpc.krpc.KrpcConfig +import kotlinx.rpc.krpc.client.KrpcClient import kotlinx.rpc.krpc.ktor.KtorTransport /** * [RpcClient] implementation for Ktor, containing [webSocketSession] object, * that is used to maintain connection. */ -public interface KtorRPCClient : RpcClient { +public interface KtorRpcClient : RpcClient { public val webSocketSession: WebSocketSession } -internal class KtorRPCClientImpl( +internal class KtorKrpcClientImpl( override val webSocketSession: WebSocketSession, - config: RPCConfig.Client, -): KRPCClient(config, KtorTransport(webSocketSession)), KtorRPCClient + config: KrpcConfig.Client, +): KrpcClient(config, KtorTransport(webSocketSession)), KtorRpcClient diff --git a/krpc/krpc-ktor/krpc-ktor-client/src/commonMain/kotlin/kotlinx/rpc/krpc/ktor/client/RPC.kt b/krpc/krpc-ktor/krpc-ktor-client/src/commonMain/kotlin/kotlinx/rpc/krpc/ktor/client/RPC.kt deleted file mode 100644 index 54c29007..00000000 --- a/krpc/krpc-ktor/krpc-ktor-client/src/commonMain/kotlin/kotlinx/rpc/krpc/ktor/client/RPC.kt +++ /dev/null @@ -1,30 +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.krpc.ktor.client - -import io.ktor.client.* -import io.ktor.client.plugins.api.* -import io.ktor.client.plugins.websocket.* -import io.ktor.util.* -import kotlinx.rpc.krpc.RPCConfigBuilder - -internal val RPCClientPluginAttributesKey = AttributeKey<RPCConfigBuilder.Client>("RPCClientPluginAttributesKey") - -/** - * Ktor client plugin that allows to configure RPC globally for all instances obtained via [rpc] functions. - */ -public val RPC: ClientPlugin<RPCConfigBuilder.Client> = createClientPlugin("RPC", { RPCConfigBuilder.Client() }) { - client.attributes.put(RPCClientPluginAttributesKey, pluginConfig) -} - -/** - * Installs [WebSockets] and [RPC] client plugins - */ -public fun HttpClientConfig<*>.installRPC( - configure: RPCConfigBuilder.Client.() -> Unit = {} -) { - install(WebSockets) - install(RPC, configure) -} diff --git a/krpc/krpc-ktor/krpc-ktor-core/src/commonMain/kotlin/kotlinx/rpc/krpc/ktor/KtorTransport.kt b/krpc/krpc-ktor/krpc-ktor-core/src/commonMain/kotlin/kotlinx/rpc/krpc/ktor/KtorTransport.kt index 7ed18be1..ed12adc7 100644 --- a/krpc/krpc-ktor/krpc-ktor-core/src/commonMain/kotlin/kotlinx/rpc/krpc/ktor/KtorTransport.kt +++ b/krpc/krpc-ktor/krpc-ktor-core/src/commonMain/kotlin/kotlinx/rpc/krpc/ktor/KtorTransport.kt @@ -6,27 +6,27 @@ package kotlinx.rpc.krpc.ktor import io.ktor.websocket.* import kotlinx.coroutines.CoroutineScope -import kotlinx.rpc.internal.utils.InternalRPCApi -import kotlinx.rpc.krpc.RPCTransport -import kotlinx.rpc.krpc.RPCTransportMessage +import kotlinx.rpc.internal.utils.InternalRpcApi +import kotlinx.rpc.krpc.KrpcTransport +import kotlinx.rpc.krpc.KrpcTransportMessage -@InternalRPCApi +@InternalRpcApi public class KtorTransport( private val webSocketSession: WebSocketSession, -) : RPCTransport, CoroutineScope by webSocketSession { +) : KrpcTransport, CoroutineScope by webSocketSession { /** * Sends a single encoded RPC message over network (or any other medium) to a peer endpoint. * * @param message a message to send. Either of string or binary type. */ - override suspend fun send(message: RPCTransportMessage) { + override suspend fun send(message: KrpcTransportMessage) { when (message) { - is RPCTransportMessage.StringMessage -> { + is KrpcTransportMessage.StringMessage -> { webSocketSession.send(message.value) } - is RPCTransportMessage.BinaryMessage -> { + is KrpcTransportMessage.BinaryMessage -> { webSocketSession.send(message.value) } } @@ -37,14 +37,14 @@ public class KtorTransport( * * @return received RPC message. */ - override suspend fun receive(): RPCTransportMessage { + override suspend fun receive(): KrpcTransportMessage { return when (val message = webSocketSession.incoming.receive()) { is Frame.Text -> { - RPCTransportMessage.StringMessage(message.readText()) + KrpcTransportMessage.StringMessage(message.readText()) } is Frame.Binary -> { - RPCTransportMessage.BinaryMessage(message.readBytes()) + KrpcTransportMessage.BinaryMessage(message.readBytes()) } else -> { diff --git a/krpc/krpc-ktor/krpc-ktor-core/src/jvmTest/kotlin/kotlinx/rpc/krpc/ktor/KtorTransportTest.kt b/krpc/krpc-ktor/krpc-ktor-core/src/jvmTest/kotlin/kotlinx/rpc/krpc/ktor/KtorTransportTest.kt index 5e9d4eb8..21ae3d0c 100644 --- a/krpc/krpc-ktor/krpc-ktor-core/src/jvmTest/kotlin/kotlinx/rpc/krpc/ktor/KtorTransportTest.kt +++ b/krpc/krpc-ktor/krpc-ktor-core/src/jvmTest/kotlin/kotlinx/rpc/krpc/ktor/KtorTransportTest.kt @@ -11,10 +11,10 @@ import io.ktor.server.testing.* import kotlinx.coroutines.cancel import kotlinx.rpc.RemoteService import kotlinx.rpc.annotations.Rpc -import kotlinx.rpc.krpc.ktor.client.installRPC +import kotlinx.rpc.krpc.ktor.client.installKrpc import kotlinx.rpc.krpc.ktor.client.rpc import kotlinx.rpc.krpc.ktor.client.rpcConfig -import kotlinx.rpc.krpc.ktor.server.RPC +import kotlinx.rpc.krpc.ktor.server.Krpc import kotlinx.rpc.krpc.ktor.server.rpc import kotlinx.rpc.krpc.serialization.json.json import kotlinx.rpc.withService @@ -40,7 +40,7 @@ class NewServiceImpl( class KtorTransportTest { @Test fun testEcho() = testApplication { - install(RPC) + install(Krpc) routing { rpc("/rpc") { rpcConfig { @@ -58,19 +58,19 @@ class KtorTransportTest { } val clientWithGlobalConfig = createClient { - installRPC { + installKrpc { serialization { json() } } } - val ktorRPCClient = clientWithGlobalConfig + val ktorRpcClient = clientWithGlobalConfig .rpc("/rpc") { headers["TestHeader"] = "test-header" } - val serviceWithGlobalConfig = ktorRPCClient.withService<NewService>() + val serviceWithGlobalConfig = ktorRpcClient.withService<NewService>() val firstActual = serviceWithGlobalConfig.echo("Hello, world!") @@ -80,7 +80,7 @@ class KtorTransportTest { clientWithGlobalConfig.cancel() val clientWithNoConfig = createClient { - installRPC() + installKrpc() } val serviceWithLocalConfig = clientWithNoConfig.rpc("/rpc") { diff --git a/krpc/krpc-ktor/krpc-ktor-server/api/krpc-ktor-server.api b/krpc/krpc-ktor/krpc-ktor-server/api/krpc-ktor-server.api index 7cd4d2da..7ed6450b 100644 --- a/krpc/krpc-ktor/krpc-ktor-server/api/krpc-ktor-server.api +++ b/krpc/krpc-ktor/krpc-ktor-server/api/krpc-ktor-server.api @@ -1,13 +1,9 @@ -public final class kotlinx/rpc/krpc/ktor/server/KtorServerDslKt { - public static final fun rpc (Lio/ktor/server/routing/Route;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V - public static final fun rpc (Lio/ktor/server/routing/Route;Lkotlin/jvm/functions/Function1;)V -} - -public final class kotlinx/rpc/krpc/ktor/server/RPCKt { +public final class kotlinx/rpc/krpc/ktor/server/KrpcKt { + public static final fun getKrpc ()Lio/ktor/server/application/ApplicationPlugin; public static final fun getRPC ()Lio/ktor/server/application/ApplicationPlugin; } -public final class kotlinx/rpc/krpc/ktor/server/RPCRoute : io/ktor/server/websocket/DefaultWebSocketServerSession { +public final class kotlinx/rpc/krpc/ktor/server/KrpcRoute : io/ktor/server/websocket/DefaultWebSocketServerSession { public fun <init> (Lio/ktor/server/websocket/DefaultWebSocketServerSession;)V public fun flush (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun getCall ()Lio/ktor/server/application/ApplicationCall; @@ -31,3 +27,8 @@ public final class kotlinx/rpc/krpc/ktor/server/RPCRoute : io/ktor/server/websoc public fun terminate ()V } +public final class kotlinx/rpc/krpc/ktor/server/KtorServerDslKt { + public static final fun rpc (Lio/ktor/server/routing/Route;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V + public static final fun rpc (Lio/ktor/server/routing/Route;Lkotlin/jvm/functions/Function1;)V +} + diff --git a/krpc/krpc-ktor/krpc-ktor-server/src/jvmMain/kotlin/kotlinx/rpc/krpc/ktor/server/Krpc.kt b/krpc/krpc-ktor/krpc-ktor-server/src/jvmMain/kotlin/kotlinx/rpc/krpc/ktor/server/Krpc.kt new file mode 100644 index 00000000..4f5922d1 --- /dev/null +++ b/krpc/krpc-ktor/krpc-ktor-server/src/jvmMain/kotlin/kotlinx/rpc/krpc/ktor/server/Krpc.kt @@ -0,0 +1,26 @@ +/* + * 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.krpc.ktor.server + +import io.ktor.server.application.* +import io.ktor.server.websocket.* +import io.ktor.util.* +import kotlinx.rpc.krpc.KrpcConfigBuilder + +internal val KrpcServerPluginAttributesKey = AttributeKey<KrpcConfigBuilder.Server>("KrpcServerPluginAttributesKey") + +@Deprecated("Use Krpc instead", ReplaceWith("Krpc"), level = DeprecationLevel.ERROR) +public val RPC: ApplicationPlugin<KrpcConfigBuilder.Server> get() = Krpc + +/** + * Ktor server plugin that allows to configure RPC globally for all mounted servers. + */ +public val Krpc: ApplicationPlugin<KrpcConfigBuilder.Server> = createApplicationPlugin( + name = "Krpc", + createConfiguration = { KrpcConfigBuilder.Server() }, +) { + application.install(WebSockets) + application.attributes.put(KrpcServerPluginAttributesKey, pluginConfig) +} diff --git a/krpc/krpc-ktor/krpc-ktor-server/src/jvmMain/kotlin/kotlinx/rpc/krpc/ktor/server/RPCRoute.kt b/krpc/krpc-ktor/krpc-ktor-server/src/jvmMain/kotlin/kotlinx/rpc/krpc/ktor/server/KrpcRoute.kt similarity index 77% rename from krpc/krpc-ktor/krpc-ktor-server/src/jvmMain/kotlin/kotlinx/rpc/krpc/ktor/server/RPCRoute.kt rename to krpc/krpc-ktor/krpc-ktor-server/src/jvmMain/kotlin/kotlinx/rpc/krpc/ktor/server/KrpcRoute.kt index 2fb71d0d..d653ef1e 100644 --- a/krpc/krpc-ktor/krpc-ktor-server/src/jvmMain/kotlin/kotlinx/rpc/krpc/ktor/server/RPCRoute.kt +++ b/krpc/krpc-ktor/krpc-ktor-server/src/jvmMain/kotlin/kotlinx/rpc/krpc/ktor/server/KrpcRoute.kt @@ -5,36 +5,39 @@ package kotlinx.rpc.krpc.ktor.server import io.ktor.server.websocket.* -import kotlinx.rpc.RPCServer import kotlinx.rpc.RemoteService -import kotlinx.rpc.krpc.RPCConfigBuilder +import kotlinx.rpc.RpcServer +import kotlinx.rpc.krpc.KrpcConfigBuilder import kotlin.coroutines.CoroutineContext import kotlin.reflect.KClass +@Deprecated("Use KrpcRoute instead", ReplaceWith("KrpcRoute"), level = DeprecationLevel.ERROR) +public typealias RPCRoute = KrpcRoute + /** - * RPCRoute class represents an RPC server that is mounted in Ktor routing. + * RpcRoute class represents an RPC server that is mounted in Ktor routing. * This class provides API to register services and optionally setup configuration. */ -public class RPCRoute( +public class KrpcRoute( webSocketSession: DefaultWebSocketServerSession ) : DefaultWebSocketServerSession by webSocketSession { - internal var configBuilder: RPCConfigBuilder.Server.() -> Unit = {} + internal var configBuilder: KrpcConfigBuilder.Server.() -> Unit = {} /** * Optionally configures the declared RPC server. - * Overrides [RPC] plugin configuration. + * Overrides [Krpc] plugin configuration. * * @param configBuilder The function that configures RPC. */ - public fun rpcConfig(configBuilder: RPCConfigBuilder.Server.() -> Unit) { + public fun rpcConfig(configBuilder: KrpcConfigBuilder.Server.() -> Unit) { this.configBuilder = configBuilder } - internal val registrations = mutableListOf<(RPCServer) -> Unit>() + internal val registrations = mutableListOf<(RpcServer) -> Unit>() /** * Registers new service to the server. Server will route all designated messages to it. - * Service of any type should be unique on the server, but RPCServer does not specify the actual retention policy. + * Service of any type should be unique on the server, but RpcServer does not specify the actual retention policy. * * @param Service the exact type of the server to be registered. * For example for service with `MyService` interface and `MyServiceImpl` implementation, @@ -53,7 +56,7 @@ public class RPCRoute( /** * Registers new service to the server. Server will route all designated messages to it. - * Service of any type should be unique on the server, but RPCServer does not specify the actual retention policy. + * Service of any type should be unique on the server, but RpcServer does not specify the actual retention policy. * * @param Service the exact type of the server to be registered. * For example for service with `MyService` interface and `MyServiceImpl` implementation, diff --git a/krpc/krpc-ktor/krpc-ktor-server/src/jvmMain/kotlin/kotlinx/rpc/krpc/ktor/server/KtorRPCServer.kt b/krpc/krpc-ktor/krpc-ktor-server/src/jvmMain/kotlin/kotlinx/rpc/krpc/ktor/server/KtorKrpcServer.kt similarity index 58% rename from krpc/krpc-ktor/krpc-ktor-server/src/jvmMain/kotlin/kotlinx/rpc/krpc/ktor/server/KtorRPCServer.kt rename to krpc/krpc-ktor/krpc-ktor-server/src/jvmMain/kotlin/kotlinx/rpc/krpc/ktor/server/KtorKrpcServer.kt index d2cddef2..11431d83 100644 --- a/krpc/krpc-ktor/krpc-ktor-server/src/jvmMain/kotlin/kotlinx/rpc/krpc/ktor/server/KtorRPCServer.kt +++ b/krpc/krpc-ktor/krpc-ktor-server/src/jvmMain/kotlin/kotlinx/rpc/krpc/ktor/server/KtorKrpcServer.kt @@ -5,11 +5,11 @@ package kotlinx.rpc.krpc.ktor.server import io.ktor.websocket.* -import kotlinx.rpc.krpc.RPCConfig +import kotlinx.rpc.krpc.KrpcConfig import kotlinx.rpc.krpc.ktor.KtorTransport -import kotlinx.rpc.krpc.server.KRPCServer +import kotlinx.rpc.krpc.server.KrpcServer -internal class KtorRPCServer( +internal class KtorKrpcServer( webSocketSession: WebSocketSession, - config: RPCConfig.Server, -) : KRPCServer(config, KtorTransport(webSocketSession)) + config: KrpcConfig.Server, +) : KrpcServer(config, KtorTransport(webSocketSession)) diff --git a/krpc/krpc-ktor/krpc-ktor-server/src/jvmMain/kotlin/kotlinx/rpc/krpc/ktor/server/KtorServerDsl.kt b/krpc/krpc-ktor/krpc-ktor-server/src/jvmMain/kotlin/kotlinx/rpc/krpc/ktor/server/KtorServerDsl.kt index 0a93956d..db259b87 100644 --- a/krpc/krpc-ktor/krpc-ktor-server/src/jvmMain/kotlin/kotlinx/rpc/krpc/ktor/server/KtorServerDsl.kt +++ b/krpc/krpc-ktor/krpc-ktor-server/src/jvmMain/kotlin/kotlinx/rpc/krpc/ktor/server/KtorServerDsl.kt @@ -13,14 +13,14 @@ import kotlinx.rpc.krpc.rpcServerConfig /** * Adds an RPC route to the specified [Route]. - * Provides builder to configure [kotlinx.rpc.RPCServer] that will be used internally. + * Provides builder to configure [kotlinx.rpc.RpcServer] that will be used internally. * Note that the [WebSockets] plugin is required for such a route to work. * * @param path The relative path on which RPC server should mount. * @param builder Builder function to configure RPC server. */ @KtorDsl -public fun Route.rpc(path: String, builder: RPCRoute.() -> Unit) { +public fun Route.rpc(path: String, builder: KrpcRoute.() -> Unit) { route(path) { rpc(builder) } @@ -28,27 +28,27 @@ public fun Route.rpc(path: String, builder: RPCRoute.() -> Unit) { /** * Adds an RPC route to the specified [Route]. - * Provides builder to configure [kotlinx.rpc.RPCServer] that will be used internally. + * Provides builder to configure [kotlinx.rpc.RpcServer] that will be used internally. * Note that the [WebSockets] plugin is required for such a route to work. * * @param builder Builder function to configure RPC server. */ @KtorDsl -public fun Route.rpc(builder: RPCRoute.() -> Unit) { - createRPCServer(builder) +public fun Route.rpc(builder: KrpcRoute.() -> Unit) { + createRpcServer(builder) } -private fun Route.createRPCServer(rpcRouteBuilder: RPCRoute.() -> Unit) { +private fun Route.createRpcServer(rpcRouteBuilder: KrpcRoute.() -> Unit) { application.pluginOrNull(WebSockets) ?: error("RPC for server requires $WebSockets plugin to be installed firstly") webSocket { - val rpcRoute = RPCRoute(this).apply(rpcRouteBuilder) - val pluginConfigBuilder = application.attributes.getOrNull(RPCServerPluginAttributesKey) + val rpcRoute = KrpcRoute(this).apply(rpcRouteBuilder) + val pluginConfigBuilder = application.attributes.getOrNull(KrpcServerPluginAttributesKey) val rpcConfig = pluginConfigBuilder?.apply(rpcRoute.configBuilder)?.build() ?: rpcServerConfig(rpcRoute.configBuilder) - val server = KtorRPCServer(this, rpcConfig) + val server = KtorKrpcServer(this, rpcConfig) rpcRoute.registrations.forEach { registration -> registration(server) diff --git a/krpc/krpc-ktor/krpc-ktor-server/src/jvmMain/kotlin/kotlinx/rpc/krpc/ktor/server/RPC.kt b/krpc/krpc-ktor/krpc-ktor-server/src/jvmMain/kotlin/kotlinx/rpc/krpc/ktor/server/RPC.kt deleted file mode 100644 index dc26501d..00000000 --- a/krpc/krpc-ktor/krpc-ktor-server/src/jvmMain/kotlin/kotlinx/rpc/krpc/ktor/server/RPC.kt +++ /dev/null @@ -1,23 +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.krpc.ktor.server - -import io.ktor.server.application.* -import io.ktor.server.websocket.* -import io.ktor.util.* -import kotlinx.rpc.krpc.RPCConfigBuilder - -internal val RPCServerPluginAttributesKey = AttributeKey<RPCConfigBuilder.Server>("RPCServerPluginAttributesKey") - -/** - * Ktor server plugin that allows to configure RPC globally for all mounted servers. - */ -public val RPC: ApplicationPlugin<RPCConfigBuilder.Server> = createApplicationPlugin( - name = "RPC", - createConfiguration = { RPCConfigBuilder.Server() }, -) { - application.install(WebSockets) - application.attributes.put(RPCServerPluginAttributesKey, pluginConfig) -} 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/CommonLogger.kt index 791fc55c..fd658dc8 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/CommonLogger.kt @@ -4,18 +4,18 @@ package kotlinx.rpc.krpc.internal.logging -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi import kotlinx.rpc.krpc.internal.logging.impl.CommonLoggerFactoryImpl import kotlin.reflect.KClass -@InternalRPCApi +@InternalRpcApi public interface CommonLoggerFactory { public fun getLogger(name: String): CommonLogger public fun getLogger(func: () -> Unit): CommonLogger } -@InternalRPCApi +@InternalRpcApi public interface CommonLogger { public fun debug(msg: () -> Any?) @@ -37,7 +37,7 @@ public interface CommonLogger { public fun warn(t: Throwable?, msg: () -> Any?) - @InternalRPCApi + @InternalRpcApi public companion object { private val factory = CommonLoggerFactoryImpl 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/DumpLogger.kt index 5b6616c0..4a10231e 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/DumpLogger.kt @@ -4,16 +4,16 @@ package kotlinx.rpc.krpc.internal.logging -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi -@InternalRPCApi +@InternalRpcApi public interface DumpLogger { public val isEnabled: Boolean public fun dump(vararg tags: String, message: () -> String) } -@InternalRPCApi +@InternalRpcApi public object DumpLoggerContainer { private var logger: DumpLogger? = null diff --git a/krpc/krpc-serialization/krpc-serialization-cbor/api/krpc-serialization-cbor.api b/krpc/krpc-serialization/krpc-serialization-cbor/api/krpc-serialization-cbor.api index e61c53ba..5e58791e 100644 --- a/krpc/krpc-serialization/krpc-serialization-cbor/api/krpc-serialization-cbor.api +++ b/krpc/krpc-serialization/krpc-serialization-cbor/api/krpc-serialization-cbor.api @@ -1,5 +1,5 @@ -public final class kotlinx/rpc/krpc/serialization/cbor/RPCCborSerialFormatKt { - public static final fun cbor (Lkotlinx/rpc/krpc/serialization/RPCSerialFormatConfiguration;Lkotlinx/serialization/cbor/Cbor;Lkotlin/jvm/functions/Function1;)V - public static synthetic fun cbor$default (Lkotlinx/rpc/krpc/serialization/RPCSerialFormatConfiguration;Lkotlinx/serialization/cbor/Cbor;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V +public final class kotlinx/rpc/krpc/serialization/cbor/KrpcCborSerialFormatKt { + public static final fun cbor (Lkotlinx/rpc/krpc/serialization/KrpcSerialFormatConfiguration;Lkotlinx/serialization/cbor/Cbor;Lkotlin/jvm/functions/Function1;)V + public static synthetic fun cbor$default (Lkotlinx/rpc/krpc/serialization/KrpcSerialFormatConfiguration;Lkotlinx/serialization/cbor/Cbor;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V } diff --git a/krpc/krpc-serialization/krpc-serialization-cbor/src/commonMain/kotlin/kotlinx/rpc/krpc/serialization/cbor/RPCCborSerialFormat.kt b/krpc/krpc-serialization/krpc-serialization-cbor/src/commonMain/kotlin/kotlinx/rpc/krpc/serialization/cbor/KrpcCborSerialFormat.kt similarity index 66% rename from krpc/krpc-serialization/krpc-serialization-cbor/src/commonMain/kotlin/kotlinx/rpc/krpc/serialization/cbor/RPCCborSerialFormat.kt rename to krpc/krpc-serialization/krpc-serialization-cbor/src/commonMain/kotlin/kotlinx/rpc/krpc/serialization/cbor/KrpcCborSerialFormat.kt index 1fbacca1..94d738c6 100644 --- a/krpc/krpc-serialization/krpc-serialization-cbor/src/commonMain/kotlin/kotlinx/rpc/krpc/serialization/cbor/RPCCborSerialFormat.kt +++ b/krpc/krpc-serialization/krpc-serialization-cbor/src/commonMain/kotlin/kotlinx/rpc/krpc/serialization/cbor/KrpcCborSerialFormat.kt @@ -6,16 +6,16 @@ package kotlinx.rpc.krpc.serialization.cbor -import kotlinx.rpc.krpc.serialization.RPCSerialFormat -import kotlinx.rpc.krpc.serialization.RPCSerialFormatBuilder -import kotlinx.rpc.krpc.serialization.RPCSerialFormatConfiguration +import kotlinx.rpc.krpc.serialization.KrpcSerialFormat +import kotlinx.rpc.krpc.serialization.KrpcSerialFormatBuilder +import kotlinx.rpc.krpc.serialization.KrpcSerialFormatConfiguration import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.cbor.Cbor import kotlinx.serialization.cbor.CborBuilder import kotlinx.serialization.modules.SerializersModule import kotlinx.serialization.modules.plus -internal object RPCCborSerialFormat : RPCSerialFormat<Cbor, CborBuilder> { +internal object KrpcCborSerialFormat : KrpcSerialFormat<Cbor, CborBuilder> { override fun withBuilder(from: Cbor?, builderConsumer: CborBuilder.() -> Unit): Cbor { return Cbor(from ?: Cbor.Default) { builderConsumer() } } @@ -29,7 +29,7 @@ internal object RPCCborSerialFormat : RPCSerialFormat<Cbor, CborBuilder> { * Extension function that allows to configure CBOR kotlinx.rpc serial format * Usage: * ```kotlin - * // this: RPCConfig + * // this: KrpcConfig * serialization { * cbor { * // custom params @@ -37,6 +37,6 @@ internal object RPCCborSerialFormat : RPCSerialFormat<Cbor, CborBuilder> { * } * ``` */ -public fun RPCSerialFormatConfiguration.cbor(from: Cbor = Cbor.Default, builderConsumer: CborBuilder.() -> Unit = {}) { - register(RPCSerialFormatBuilder.Binary(RPCCborSerialFormat, from, builderConsumer)) +public fun KrpcSerialFormatConfiguration.cbor(from: Cbor = Cbor.Default, builderConsumer: CborBuilder.() -> Unit = {}) { + register(KrpcSerialFormatBuilder.Binary(KrpcCborSerialFormat, from, builderConsumer)) } diff --git a/krpc/krpc-serialization/krpc-serialization-core/api/krpc-serialization-core.api b/krpc/krpc-serialization/krpc-serialization-core/api/krpc-serialization-core.api index 48ffe970..0382934a 100644 --- a/krpc/krpc-serialization/krpc-serialization-core/api/krpc-serialization-core.api +++ b/krpc/krpc-serialization/krpc-serialization-core/api/krpc-serialization-core.api @@ -1,29 +1,29 @@ -public abstract interface class kotlinx/rpc/krpc/serialization/RPCSerialFormat { +public abstract interface class kotlinx/rpc/krpc/serialization/KrpcSerialFormat { public abstract fun applySerializersModule (Ljava/lang/Object;Lkotlinx/serialization/modules/SerializersModule;)V public abstract fun withBuilder (Lkotlinx/serialization/SerialFormat;Lkotlin/jvm/functions/Function1;)Lkotlinx/serialization/SerialFormat; } -public final class kotlinx/rpc/krpc/serialization/RPCSerialFormat$DefaultImpls { - public static synthetic fun withBuilder$default (Lkotlinx/rpc/krpc/serialization/RPCSerialFormat;Lkotlinx/serialization/SerialFormat;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lkotlinx/serialization/SerialFormat; +public final class kotlinx/rpc/krpc/serialization/KrpcSerialFormat$DefaultImpls { + public static synthetic fun withBuilder$default (Lkotlinx/rpc/krpc/serialization/KrpcSerialFormat;Lkotlinx/serialization/SerialFormat;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lkotlinx/serialization/SerialFormat; } -public abstract class kotlinx/rpc/krpc/serialization/RPCSerialFormatBuilder { - public synthetic fun <init> (Lkotlinx/rpc/krpc/serialization/RPCSerialFormat;Lkotlinx/serialization/SerialFormat;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V - public synthetic fun <init> (Lkotlinx/rpc/krpc/serialization/RPCSerialFormat;Lkotlinx/serialization/SerialFormat;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/internal/DefaultConstructorMarker;)V +public abstract class kotlinx/rpc/krpc/serialization/KrpcSerialFormatBuilder { + public synthetic fun <init> (Lkotlinx/rpc/krpc/serialization/KrpcSerialFormat;Lkotlinx/serialization/SerialFormat;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public synthetic fun <init> (Lkotlinx/rpc/krpc/serialization/KrpcSerialFormat;Lkotlinx/serialization/SerialFormat;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/internal/DefaultConstructorMarker;)V } -public final class kotlinx/rpc/krpc/serialization/RPCSerialFormatBuilder$Binary : kotlinx/rpc/krpc/serialization/RPCSerialFormatBuilder { - public fun <init> (Lkotlinx/rpc/krpc/serialization/RPCSerialFormat;Lkotlinx/serialization/BinaryFormat;Lkotlin/jvm/functions/Function1;)V - public synthetic fun <init> (Lkotlinx/rpc/krpc/serialization/RPCSerialFormat;Lkotlinx/serialization/BinaryFormat;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V +public final class kotlinx/rpc/krpc/serialization/KrpcSerialFormatBuilder$Binary : kotlinx/rpc/krpc/serialization/KrpcSerialFormatBuilder { + public fun <init> (Lkotlinx/rpc/krpc/serialization/KrpcSerialFormat;Lkotlinx/serialization/BinaryFormat;Lkotlin/jvm/functions/Function1;)V + public synthetic fun <init> (Lkotlinx/rpc/krpc/serialization/KrpcSerialFormat;Lkotlinx/serialization/BinaryFormat;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V } -public final class kotlinx/rpc/krpc/serialization/RPCSerialFormatBuilder$String : kotlinx/rpc/krpc/serialization/RPCSerialFormatBuilder { - public fun <init> (Lkotlinx/rpc/krpc/serialization/RPCSerialFormat;Lkotlinx/serialization/StringFormat;Lkotlin/jvm/functions/Function1;)V - public synthetic fun <init> (Lkotlinx/rpc/krpc/serialization/RPCSerialFormat;Lkotlinx/serialization/StringFormat;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V +public final class kotlinx/rpc/krpc/serialization/KrpcSerialFormatBuilder$String : kotlinx/rpc/krpc/serialization/KrpcSerialFormatBuilder { + public fun <init> (Lkotlinx/rpc/krpc/serialization/KrpcSerialFormat;Lkotlinx/serialization/StringFormat;Lkotlin/jvm/functions/Function1;)V + public synthetic fun <init> (Lkotlinx/rpc/krpc/serialization/KrpcSerialFormat;Lkotlinx/serialization/StringFormat;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V } -public abstract interface class kotlinx/rpc/krpc/serialization/RPCSerialFormatConfiguration { - public abstract fun register (Lkotlinx/rpc/krpc/serialization/RPCSerialFormatBuilder$Binary;)V - public abstract fun register (Lkotlinx/rpc/krpc/serialization/RPCSerialFormatBuilder$String;)V +public abstract interface class kotlinx/rpc/krpc/serialization/KrpcSerialFormatConfiguration { + public abstract fun register (Lkotlinx/rpc/krpc/serialization/KrpcSerialFormatBuilder$Binary;)V + public abstract fun register (Lkotlinx/rpc/krpc/serialization/KrpcSerialFormatBuilder$String;)V } diff --git a/krpc/krpc-serialization/krpc-serialization-core/src/commonMain/kotlin/kotlinx/rpc/krpc/serialization/RPCSerialFormat.kt b/krpc/krpc-serialization/krpc-serialization-core/src/commonMain/kotlin/kotlinx/rpc/krpc/serialization/KrpcSerialFormat.kt similarity index 60% rename from krpc/krpc-serialization/krpc-serialization-core/src/commonMain/kotlin/kotlinx/rpc/krpc/serialization/RPCSerialFormat.kt rename to krpc/krpc-serialization/krpc-serialization-core/src/commonMain/kotlin/kotlinx/rpc/krpc/serialization/KrpcSerialFormat.kt index 4ddf97af..3f1f129a 100644 --- a/krpc/krpc-serialization/krpc-serialization-core/src/commonMain/kotlin/kotlinx/rpc/krpc/serialization/RPCSerialFormat.kt +++ b/krpc/krpc-serialization/krpc-serialization-core/src/commonMain/kotlin/kotlinx/rpc/krpc/serialization/KrpcSerialFormat.kt @@ -4,18 +4,21 @@ package kotlinx.rpc.krpc.serialization -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi import kotlinx.serialization.BinaryFormat import kotlinx.serialization.SerialFormat import kotlinx.serialization.StringFormat import kotlinx.serialization.modules.SerializersModule +@Deprecated("Use KrpcSerialFormat instead", ReplaceWith("KrpcSerialFormat"), level = DeprecationLevel.ERROR) +public typealias RPCSerialFormat<Format, FormatBuilder> = KrpcSerialFormat<Format, FormatBuilder> + /** - * [RPCSerialFormat] interface defines an object which helps kRPC protocol to work with various serialization formats + * [KrpcSerialFormat] interface defines an object which helps kRPC protocol to work with various serialization formats * - * Each serialization that can be used with kRPC protocol should define an object of [RPCSerialFormat] + * Each serialization that can be used with kRPC protocol should define an object of [KrpcSerialFormat] */ -public interface RPCSerialFormat<Format : SerialFormat, FormatBuilder : Any> { +public interface KrpcSerialFormat<Format : SerialFormat, FormatBuilder : Any> { /** * Generalization of kotlinx.serialization approach to configure serial formats * @@ -32,18 +35,25 @@ public interface RPCSerialFormat<Format : SerialFormat, FormatBuilder : Any> { public fun FormatBuilder.applySerializersModule(serializersModule: SerializersModule) } +@Deprecated( + "Use KrpcSerialFormatBuilder instead", + ReplaceWith("KrpcSerialFormatBuilder"), + level = DeprecationLevel.ERROR, +) +public typealias RPCSerialFormatBuilder<Format, FormatBuilder> = KrpcSerialFormatBuilder<Format, FormatBuilder> + /** - * Special wrapper class that is used to register serialization format in [RPCSerialFormatConfiguration] - * Comes in two instances: [RPCSerialFormatBuilder.Binary] and [RPCSerialFormatBuilder.String] + * Special wrapper class that is used to register serialization format in [KrpcSerialFormatConfiguration] + * Comes in two instances: [KrpcSerialFormatBuilder.Binary] and [KrpcSerialFormatBuilder.String] * * @param Format [SerialFormat] type that this builder should create for RPC * @param FormatBuilder builder class for [Format] - * @param rpcSerialFormat - instance of [RPCSerialFormat] + * @param rpcSerialFormat - instance of [KrpcSerialFormat] * @param from - optional default format instance * @param builder - builder function for format configuration */ -public sealed class RPCSerialFormatBuilder<Format : SerialFormat, FormatBuilder : Any>( - rpcSerialFormat: RPCSerialFormat<Format, FormatBuilder>, +public sealed class KrpcSerialFormatBuilder<Format : SerialFormat, FormatBuilder : Any>( + rpcSerialFormat: KrpcSerialFormat<Format, FormatBuilder>, from: Format? = null, builder: FormatBuilder.() -> Unit, ) { @@ -56,29 +66,29 @@ public sealed class RPCSerialFormatBuilder<Format : SerialFormat, FormatBuilder } } - @InternalRPCApi + @InternalRpcApi public fun build(): SerialFormat = builder(null) - @InternalRPCApi + @InternalRpcApi public fun applySerializersModuleAndBuild(serializersModule: SerializersModule): SerialFormat { return builder(serializersModule) } /** - * @see RPCSerialFormatBuilder + * @see KrpcSerialFormatBuilder */ public class Binary<Format : BinaryFormat, FormatBuilder : Any>( - rpcSerialFormat: RPCSerialFormat<Format, FormatBuilder>, + rpcSerialFormat: KrpcSerialFormat<Format, FormatBuilder>, from: Format? = null, builder: FormatBuilder.() -> Unit, - ): RPCSerialFormatBuilder<Format, FormatBuilder>(rpcSerialFormat, from, builder) + ) : KrpcSerialFormatBuilder<Format, FormatBuilder>(rpcSerialFormat, from, builder) /** - * @see RPCSerialFormatBuilder + * @see KrpcSerialFormatBuilder */ public class String<Format : StringFormat, FormatBuilder : Any>( - rpcSerialFormat: RPCSerialFormat<Format, FormatBuilder>, + rpcSerialFormat: KrpcSerialFormat<Format, FormatBuilder>, from: Format? = null, builder: FormatBuilder.() -> Unit, - ): RPCSerialFormatBuilder<Format, FormatBuilder>(rpcSerialFormat, from, builder) + ) : KrpcSerialFormatBuilder<Format, FormatBuilder>(rpcSerialFormat, from, builder) } diff --git a/krpc/krpc-serialization/krpc-serialization-core/src/commonMain/kotlin/kotlinx/rpc/krpc/serialization/KrpcSerialFormatConfiguration.kt b/krpc/krpc-serialization/krpc-serialization-core/src/commonMain/kotlin/kotlinx/rpc/krpc/serialization/KrpcSerialFormatConfiguration.kt new file mode 100644 index 00000000..3e777102 --- /dev/null +++ b/krpc/krpc-serialization/krpc-serialization-core/src/commonMain/kotlin/kotlinx/rpc/krpc/serialization/KrpcSerialFormatConfiguration.kt @@ -0,0 +1,39 @@ +/* + * 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.krpc.serialization + +@Deprecated( + "Use KrpcSerialFormatConfiguration instead", + ReplaceWith("KrpcSerialFormatConfiguration"), + level = DeprecationLevel.ERROR, +) +public typealias RPCSerialFormatConfiguration = KrpcSerialFormatConfiguration + +/** + * Special interface to configure serialization for a kRPC protocol in KrpcConfig + * ```kotlin + * // this: KrpcConfigBuilder + * serialization { // this: KrpcSerialFormatConfiguration + * // register serialization here + * } + * ``` + */ +public interface KrpcSerialFormatConfiguration { + /** + * Register a serialization format in the KrpcSerialFormatConfiguration. + * + * @param rpcSerialFormatInitializer The serialization format initializer of String type. + * It is used to configure the serialization format for a kRPC protocol. + */ + public fun register(rpcSerialFormatInitializer: KrpcSerialFormatBuilder.String<*, *>) + + /** + * Register a serialization format in the KrpcSerialFormatConfiguration. + * + * @param rpcSerialFormatInitializer The serialization format initializer of Binary type. + * It is used to configure the serialization format for a kRPC protocol. + */ + public fun register(rpcSerialFormatInitializer: KrpcSerialFormatBuilder.Binary<*, *>) +} diff --git a/krpc/krpc-serialization/krpc-serialization-core/src/commonMain/kotlin/kotlinx/rpc/krpc/serialization/RPCSerialFormatConfiguration.kt b/krpc/krpc-serialization/krpc-serialization-core/src/commonMain/kotlin/kotlinx/rpc/krpc/serialization/RPCSerialFormatConfiguration.kt deleted file mode 100644 index 5572b1ac..00000000 --- a/krpc/krpc-serialization/krpc-serialization-core/src/commonMain/kotlin/kotlinx/rpc/krpc/serialization/RPCSerialFormatConfiguration.kt +++ /dev/null @@ -1,32 +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.krpc.serialization - -/** - * Special interface to configure serialization for a kRPC protocol in RPCConfig - * ```kotlin - * // this: RPCConfigBuilder - * serialization { // this: RPCSerialFormatConfiguration - * // register serialization here - * } - * ``` - */ -public interface RPCSerialFormatConfiguration { - /** - * Register a serialization format in the RPCSerialFormatConfiguration. - * - * @param rpcSerialFormatInitializer The serialization format initializer of String type. - * It is used to configure the serialization format for a kRPC protocol. - */ - public fun register(rpcSerialFormatInitializer: RPCSerialFormatBuilder.String<*, *>) - - /** - * Register a serialization format in the RPCSerialFormatConfiguration. - * - * @param rpcSerialFormatInitializer The serialization format initializer of Binary type. - * It is used to configure the serialization format for a kRPC protocol. - */ - public fun register(rpcSerialFormatInitializer: RPCSerialFormatBuilder.Binary<*, *>) -} diff --git a/krpc/krpc-serialization/krpc-serialization-json/api/krpc-serialization-json.api b/krpc/krpc-serialization/krpc-serialization-json/api/krpc-serialization-json.api index 8bcbe636..8e3038ac 100644 --- a/krpc/krpc-serialization/krpc-serialization-json/api/krpc-serialization-json.api +++ b/krpc/krpc-serialization/krpc-serialization-json/api/krpc-serialization-json.api @@ -1,5 +1,5 @@ -public final class kotlinx/rpc/krpc/serialization/json/RPCJsonSerialFormatKt { - public static final fun json (Lkotlinx/rpc/krpc/serialization/RPCSerialFormatConfiguration;Lkotlinx/serialization/json/Json;Lkotlin/jvm/functions/Function1;)V - public static synthetic fun json$default (Lkotlinx/rpc/krpc/serialization/RPCSerialFormatConfiguration;Lkotlinx/serialization/json/Json;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V +public final class kotlinx/rpc/krpc/serialization/json/KrpcJsonSerialFormatKt { + public static final fun json (Lkotlinx/rpc/krpc/serialization/KrpcSerialFormatConfiguration;Lkotlinx/serialization/json/Json;Lkotlin/jvm/functions/Function1;)V + public static synthetic fun json$default (Lkotlinx/rpc/krpc/serialization/KrpcSerialFormatConfiguration;Lkotlinx/serialization/json/Json;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V } diff --git a/krpc/krpc-serialization/krpc-serialization-json/src/commonMain/kotlin/kotlinx/rpc/krpc/serialization/json/RPCJsonSerialFormat.kt b/krpc/krpc-serialization/krpc-serialization-json/src/commonMain/kotlin/kotlinx/rpc/krpc/serialization/json/KrpcJsonSerialFormat.kt similarity index 63% rename from krpc/krpc-serialization/krpc-serialization-json/src/commonMain/kotlin/kotlinx/rpc/krpc/serialization/json/RPCJsonSerialFormat.kt rename to krpc/krpc-serialization/krpc-serialization-json/src/commonMain/kotlin/kotlinx/rpc/krpc/serialization/json/KrpcJsonSerialFormat.kt index 9f6a0868..a3d555ef 100644 --- a/krpc/krpc-serialization/krpc-serialization-json/src/commonMain/kotlin/kotlinx/rpc/krpc/serialization/json/RPCJsonSerialFormat.kt +++ b/krpc/krpc-serialization/krpc-serialization-json/src/commonMain/kotlin/kotlinx/rpc/krpc/serialization/json/KrpcJsonSerialFormat.kt @@ -4,15 +4,15 @@ package kotlinx.rpc.krpc.serialization.json -import kotlinx.rpc.krpc.serialization.RPCSerialFormat -import kotlinx.rpc.krpc.serialization.RPCSerialFormatBuilder -import kotlinx.rpc.krpc.serialization.RPCSerialFormatConfiguration +import kotlinx.rpc.krpc.serialization.KrpcSerialFormat +import kotlinx.rpc.krpc.serialization.KrpcSerialFormatBuilder +import kotlinx.rpc.krpc.serialization.KrpcSerialFormatConfiguration import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonBuilder import kotlinx.serialization.modules.SerializersModule import kotlinx.serialization.modules.plus -internal object RPCJsonSerialFormat : RPCSerialFormat<Json, JsonBuilder> { +internal object KrpcJsonSerialFormat : KrpcSerialFormat<Json, JsonBuilder> { override fun withBuilder(from: Json?, builderConsumer: JsonBuilder.() -> Unit): Json { return Json(from ?: Json.Default) { builderConsumer() } } @@ -26,7 +26,7 @@ internal object RPCJsonSerialFormat : RPCSerialFormat<Json, JsonBuilder> { * Extension function that allows to configure JSON kotlinx.rpc serial format * Usage: * ```kotlin - * // this: RPCConfig + * // this: KrpcConfig * serialization { * json { * // custom params @@ -34,6 +34,6 @@ internal object RPCJsonSerialFormat : RPCSerialFormat<Json, JsonBuilder> { * } * ``` */ -public fun RPCSerialFormatConfiguration.json(from: Json = Json.Default, builderConsumer: JsonBuilder.() -> Unit = {}) { - register(RPCSerialFormatBuilder.String(RPCJsonSerialFormat, from, builderConsumer)) +public fun KrpcSerialFormatConfiguration.json(from: Json = Json.Default, builderConsumer: JsonBuilder.() -> Unit = {}) { + register(KrpcSerialFormatBuilder.String(KrpcJsonSerialFormat, from, builderConsumer)) } diff --git a/krpc/krpc-serialization/krpc-serialization-protobuf/api/krpc-serialization-protobuf.api b/krpc/krpc-serialization/krpc-serialization-protobuf/api/krpc-serialization-protobuf.api index c308f635..f9fe750f 100644 --- a/krpc/krpc-serialization/krpc-serialization-protobuf/api/krpc-serialization-protobuf.api +++ b/krpc/krpc-serialization/krpc-serialization-protobuf/api/krpc-serialization-protobuf.api @@ -1,5 +1,5 @@ -public final class kotlinx/rpc/krpc/serialization/protobuf/RPCProtobufSerialFormatKt { - public static final fun protobuf (Lkotlinx/rpc/krpc/serialization/RPCSerialFormatConfiguration;Lkotlinx/serialization/protobuf/ProtoBuf;Lkotlin/jvm/functions/Function1;)V - public static synthetic fun protobuf$default (Lkotlinx/rpc/krpc/serialization/RPCSerialFormatConfiguration;Lkotlinx/serialization/protobuf/ProtoBuf;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V +public final class kotlinx/rpc/krpc/serialization/protobuf/KrpcProtobufSerialFormatKt { + public static final fun protobuf (Lkotlinx/rpc/krpc/serialization/KrpcSerialFormatConfiguration;Lkotlinx/serialization/protobuf/ProtoBuf;Lkotlin/jvm/functions/Function1;)V + public static synthetic fun protobuf$default (Lkotlinx/rpc/krpc/serialization/KrpcSerialFormatConfiguration;Lkotlinx/serialization/protobuf/ProtoBuf;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V } diff --git a/krpc/krpc-serialization/krpc-serialization-protobuf/src/commonMain/kotlin/kotlinx/rpc/krpc/serialization/protobuf/RPCProtobufSerialFormat.kt b/krpc/krpc-serialization/krpc-serialization-protobuf/src/commonMain/kotlin/kotlinx/rpc/krpc/serialization/protobuf/KrpcProtobufSerialFormat.kt similarity index 71% rename from krpc/krpc-serialization/krpc-serialization-protobuf/src/commonMain/kotlin/kotlinx/rpc/krpc/serialization/protobuf/RPCProtobufSerialFormat.kt rename to krpc/krpc-serialization/krpc-serialization-protobuf/src/commonMain/kotlin/kotlinx/rpc/krpc/serialization/protobuf/KrpcProtobufSerialFormat.kt index ff976b47..4b4aa43f 100644 --- a/krpc/krpc-serialization/krpc-serialization-protobuf/src/commonMain/kotlin/kotlinx/rpc/krpc/serialization/protobuf/RPCProtobufSerialFormat.kt +++ b/krpc/krpc-serialization/krpc-serialization-protobuf/src/commonMain/kotlin/kotlinx/rpc/krpc/serialization/protobuf/KrpcProtobufSerialFormat.kt @@ -6,16 +6,16 @@ package kotlinx.rpc.krpc.serialization.protobuf -import kotlinx.rpc.krpc.serialization.RPCSerialFormat -import kotlinx.rpc.krpc.serialization.RPCSerialFormatBuilder -import kotlinx.rpc.krpc.serialization.RPCSerialFormatConfiguration +import kotlinx.rpc.krpc.serialization.KrpcSerialFormat +import kotlinx.rpc.krpc.serialization.KrpcSerialFormatBuilder +import kotlinx.rpc.krpc.serialization.KrpcSerialFormatConfiguration import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.modules.SerializersModule import kotlinx.serialization.modules.plus import kotlinx.serialization.protobuf.ProtoBuf import kotlinx.serialization.protobuf.ProtoBufBuilder -internal object RPCProtobufSerialFormat : RPCSerialFormat<ProtoBuf, ProtoBufBuilder> { +internal object KrpcProtobufSerialFormat : KrpcSerialFormat<ProtoBuf, ProtoBufBuilder> { override fun withBuilder(from: ProtoBuf?, builderConsumer: ProtoBufBuilder.() -> Unit): ProtoBuf { return ProtoBuf(from ?: ProtoBuf.Default) { builderConsumer() } } @@ -29,7 +29,7 @@ internal object RPCProtobufSerialFormat : RPCSerialFormat<ProtoBuf, ProtoBufBuil * Extension function that allows to configure ProtoBuf kotlinx.rpc serial format * Usage: * ```kotlin - * // this: RPCConfig + * // this: KrpcConfig * serialization { * protobuf { * // custom params @@ -37,9 +37,9 @@ internal object RPCProtobufSerialFormat : RPCSerialFormat<ProtoBuf, ProtoBufBuil * } * ``` */ -public fun RPCSerialFormatConfiguration.protobuf( +public fun KrpcSerialFormatConfiguration.protobuf( from: ProtoBuf = ProtoBuf.Default, builderConsumer: ProtoBufBuilder.() -> Unit = {}, ) { - register(RPCSerialFormatBuilder.Binary(RPCProtobufSerialFormat, from, builderConsumer)) + register(KrpcSerialFormatBuilder.Binary(KrpcProtobufSerialFormat, from, builderConsumer)) } diff --git a/krpc/krpc-server/api/krpc-server.api b/krpc/krpc-server/api/krpc-server.api index 1a70be14..41b38da4 100644 --- a/krpc/krpc-server/api/krpc-server.api +++ b/krpc/krpc-server/api/krpc-server.api @@ -1,5 +1,5 @@ -public abstract class kotlinx/rpc/krpc/server/KRPCServer : kotlinx/rpc/RPCServer, kotlinx/rpc/krpc/internal/RPCEndpoint { - public fun <init> (Lkotlinx/rpc/krpc/RPCConfig$Server;Lkotlinx/rpc/krpc/RPCTransport;)V +public abstract class kotlinx/rpc/krpc/server/KrpcServer : kotlinx/rpc/RpcServer, kotlinx/rpc/krpc/internal/KrpcEndpoint { + public fun <init> (Lkotlinx/rpc/krpc/KrpcConfig$Server;Lkotlinx/rpc/krpc/KrpcTransport;)V public final fun getCoroutineContext ()Lkotlin/coroutines/CoroutineContext; public final fun registerService (Lkotlin/reflect/KClass;Lkotlin/jvm/functions/Function1;)V } 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 similarity index 71% rename from krpc/krpc-server/src/commonMain/kotlin/kotlinx/rpc/krpc/server/KRPCServer.kt rename to krpc/krpc-server/src/commonMain/kotlin/kotlinx/rpc/krpc/server/KrpcServer.kt index 47b37872..7c89fb93 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 @@ -5,23 +5,26 @@ package kotlinx.rpc.krpc.server import kotlinx.coroutines.* -import kotlinx.rpc.RPCServer import kotlinx.rpc.RemoteService +import kotlinx.rpc.RpcServer import kotlinx.rpc.descriptor.RpcServiceDescriptor import kotlinx.rpc.descriptor.serviceDescriptorOf -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi import kotlinx.rpc.internal.utils.map.ConcurrentHashMap -import kotlinx.rpc.krpc.RPCConfig -import kotlinx.rpc.krpc.RPCTransport +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.server.internal.RPCServerConnector -import kotlinx.rpc.krpc.server.internal.RPCServerService +import kotlinx.rpc.krpc.server.internal.KrpcServerConnector +import kotlinx.rpc.krpc.server.internal.KrpcServerService import kotlin.coroutines.CoroutineContext import kotlin.reflect.KClass +@Deprecated("Use KrpcServer instead", ReplaceWith("KrpcServer"), level = DeprecationLevel.ERROR) +public typealias KRPCServer = KrpcServer + /** - * Default implementation of [RPCServer]. + * Default implementation of [RpcServer]. * Takes care of tracking requests and responses, * serializing data, tracking streams, processing exceptions, and other protocol responsibilities. * Routes resulting messages to the proper registered services. @@ -29,44 +32,44 @@ import kotlin.reflect.KClass * * A simple example of how this server may be implemented: * ```kotlin - * class MyTransport : RPCTransport { /*...*/ } + * class MyTransport : KrpcTransport { /*...*/ } * - * class MyServer(config: RPCConfig.Server): KRPCServer(config, MyTransport()) + * class MyServer(config: KrpcConfig.Server): KrpcServer(config, MyTransport()) * ``` * * @param config configuration provided for that specific server. Applied to all services that use this server. - * @param transport [RPCTransport] instance that will be used to send and receive RPC messages. + * @param transport [KrpcTransport] instance that will be used to send and receive RPC messages. * IMPORTANT: Must be exclusive to this server, otherwise unexpected behavior may occur. */ @OptIn(InternalCoroutinesApi::class) -public abstract class KRPCServer( - private val config: RPCConfig.Server, - transport: RPCTransport, -) : RPCServer, RPCEndpoint { +public abstract class KrpcServer( + private val config: KrpcConfig.Server, + transport: KrpcTransport, +) : RpcServer, KrpcEndpoint { // 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 connector by lazy { - RPCServerConnector( + KrpcServerConnector( serialFormat = config.serialFormatInitializer.build(), transport = transport, waitForServices = config.waitForServices, ) } - @InternalRPCApi - final override val sender: RPCMessageSender get() = connector + @InternalRpcApi + final override val sender: KrpcMessageSender get() = connector - @InternalRPCApi - final override var supportedPlugins: Set<RPCPlugin> = emptySet() + @InternalRpcApi + final override var supportedPlugins: Set<KrpcPlugin> = emptySet() private set - private val rpcServices = ConcurrentHashMap<Long, RPCServerService<*>>() + private val rpcServices = ConcurrentHashMap<Long, KrpcServerService<*>>() // compatibility with clients that do not have serviceId - private var nullRpcServices = ConcurrentHashMap<String, RPCServerService<*>>() + private var nullRpcServices = ConcurrentHashMap<String, KrpcServerService<*>>() private var cancelledByClient = false @@ -84,14 +87,14 @@ public abstract class KRPCServer( } } - private suspend fun handleProtocolMessage(message: RPCProtocolMessage) { + private suspend fun handleProtocolMessage(message: KrpcProtocolMessage) { when (message) { - is RPCProtocolMessage.Handshake -> { + is KrpcProtocolMessage.Handshake -> { supportedPlugins = message.supportedPlugins - connector.sendMessage(RPCProtocolMessage.Handshake(RPCPlugin.ALL, connectionId = 1)) + connector.sendMessage(KrpcProtocolMessage.Handshake(KrpcPlugin.ALL, connectionId = 1)) } - is RPCProtocolMessage.Failure -> { + is KrpcProtocolMessage.Failure -> { logger.error { "Client [${message.connectionId}] failed to handle protocol message ${message.failedMessage}: " + message.errorMessage @@ -126,10 +129,10 @@ public abstract class KRPCServer( private fun <Service : RemoteService> createNewServiceInstance( descriptor: RpcServiceDescriptor<Service>, serviceFactory: (CoroutineContext) -> Service, - ): RPCServerService<Service> { + ): KrpcServerService<Service> { val serviceInstanceContext = SupervisorJob(coroutineContext.job) - return RPCServerService( + return KrpcServerService( service = serviceFactory(serviceInstanceContext), descriptor = descriptor, config = config, @@ -142,8 +145,8 @@ public abstract class KRPCServer( } } - @InternalRPCApi - final override suspend fun handleCancellation(message: RPCGenericMessage) { + @InternalRpcApi + final override suspend fun handleCancellation(message: KrpcGenericMessage) { when (val type = message.cancellationType()) { CancellationType.ENDPOINT -> { cancelledByClient = true @@ -153,17 +156,17 @@ public abstract class KRPCServer( } CancellationType.SERVICE -> { - val serviceId = message[RPCPluginKey.CLIENT_SERVICE_ID]?.toLongOrNull() + val serviceId = message[KrpcPluginKey.CLIENT_SERVICE_ID]?.toLongOrNull() ?: error("Expected CLIENT_SERVICE_ID for cancellation of type 'service' as Long value") rpcServices[serviceId]?.cancel("Service cancelled by client") } CancellationType.REQUEST -> { - val serviceId = message[RPCPluginKey.CLIENT_SERVICE_ID]?.toLongOrNull() + val serviceId = message[KrpcPluginKey.CLIENT_SERVICE_ID]?.toLongOrNull() ?: error("Expected CLIENT_SERVICE_ID for cancellation of type 'request' as Long value") - val callId = message[RPCPluginKey.CANCELLATION_ID] + val callId = message[KrpcPluginKey.CANCELLATION_ID] ?: error("Expected CANCELLATION_ID for cancellation of type 'request'") rpcServices[serviceId]?.cancelRequest(callId, "Request cancelled by client") @@ -171,7 +174,7 @@ public abstract class KRPCServer( else -> { logger.warn { - "Unsupported ${RPCPluginKey.CANCELLATION_TYPE} $type for server, " + + "Unsupported ${KrpcPluginKey.CANCELLATION_TYPE} $type for server, " + "only 'endpoint' type may be sent by a server" } } diff --git a/krpc/krpc-server/src/commonMain/kotlin/kotlinx/rpc/krpc/server/internal/RPCServerConnector.kt b/krpc/krpc-server/src/commonMain/kotlin/kotlinx/rpc/krpc/server/internal/KrpcServerConnector.kt similarity index 61% rename from krpc/krpc-server/src/commonMain/kotlin/kotlinx/rpc/krpc/server/internal/RPCServerConnector.kt rename to krpc/krpc-server/src/commonMain/kotlin/kotlinx/rpc/krpc/server/internal/KrpcServerConnector.kt index 0323a115..804c9d24 100644 --- a/krpc/krpc-server/src/commonMain/kotlin/kotlinx/rpc/krpc/server/internal/RPCServerConnector.kt +++ b/krpc/krpc-server/src/commonMain/kotlin/kotlinx/rpc/krpc/server/internal/KrpcServerConnector.kt @@ -4,7 +4,7 @@ package kotlinx.rpc.krpc.server.internal -import kotlinx.rpc.krpc.RPCTransport +import kotlinx.rpc.krpc.KrpcTransport import kotlinx.rpc.krpc.internal.* import kotlinx.serialization.SerialFormat @@ -16,19 +16,19 @@ internal sealed interface MessageKey { data object Generic: MessageKey } -internal class RPCServerConnector private constructor( - private val connector: RPCConnector<MessageKey>, -): RPCMessageSender by connector { +internal class KrpcServerConnector private constructor( + private val connector: KrpcConnector<MessageKey>, +): KrpcMessageSender by connector { constructor( serialFormat: SerialFormat, - transport: RPCTransport, + transport: KrpcTransport, waitForServices: Boolean = false, ) : this( - RPCConnector(serialFormat, transport, waitForServices, isServer = true) { + KrpcConnector(serialFormat, transport, waitForServices, isServer = true) { when (this) { - is RPCCallMessage -> MessageKey.Service(serviceType) - is RPCProtocolMessage -> MessageKey.Protocol - is RPCGenericMessage -> MessageKey.Generic + is KrpcCallMessage -> MessageKey.Service(serviceType) + is KrpcProtocolMessage -> MessageKey.Protocol + is KrpcGenericMessage -> MessageKey.Generic } } ) @@ -39,23 +39,23 @@ internal class RPCServerConnector private constructor( suspend fun subscribeToServiceMessages( serviceTypeString: String, - subscription: suspend (RPCCallMessage) -> Unit, + subscription: suspend (KrpcCallMessage) -> Unit, ) { connector.subscribeToMessages(MessageKey.Service(serviceTypeString)) { - subscription(it as RPCCallMessage) + subscription(it as KrpcCallMessage) } } - suspend fun subscribeToProtocolMessages(subscription: suspend (RPCProtocolMessage) -> Unit) { + suspend fun subscribeToProtocolMessages(subscription: suspend (KrpcProtocolMessage) -> Unit) { connector.subscribeToMessages(MessageKey.Protocol) { - subscription(it as RPCProtocolMessage) + subscription(it as KrpcProtocolMessage) } } @Suppress("unused") - suspend fun subscribeToGenericMessages(subscription: suspend (RPCGenericMessage) -> Unit) { + suspend fun subscribeToGenericMessages(subscription: suspend (KrpcGenericMessage) -> Unit) { connector.subscribeToMessages(MessageKey.Generic) { - subscription(it as RPCGenericMessage) + subscription(it as KrpcGenericMessage) } } } diff --git a/krpc/krpc-server/src/commonMain/kotlin/kotlinx/rpc/krpc/server/internal/RPCServerService.kt b/krpc/krpc-server/src/commonMain/kotlin/kotlinx/rpc/krpc/server/internal/KrpcServerService.kt similarity index 81% rename from krpc/krpc-server/src/commonMain/kotlin/kotlinx/rpc/krpc/server/internal/RPCServerService.kt rename to krpc/krpc-server/src/commonMain/kotlin/kotlinx/rpc/krpc/server/internal/KrpcServerService.kt index eee1cf3b..1814a1bb 100644 --- a/krpc/krpc-server/src/commonMain/kotlin/kotlinx/rpc/krpc/server/internal/RPCServerService.kt +++ b/krpc/krpc-server/src/commonMain/kotlin/kotlinx/rpc/krpc/server/internal/KrpcServerService.kt @@ -9,7 +9,7 @@ import kotlinx.rpc.RemoteService import kotlinx.rpc.descriptor.RpcInvokator import kotlinx.rpc.descriptor.RpcServiceDescriptor import kotlinx.rpc.internal.utils.map.ConcurrentHashMap -import kotlinx.rpc.krpc.RPCConfig +import kotlinx.rpc.krpc.KrpcConfig import kotlinx.rpc.krpc.callScoped import kotlinx.rpc.krpc.internal.* import kotlinx.rpc.krpc.internal.logging.CommonLogger @@ -19,20 +19,20 @@ import kotlinx.serialization.BinaryFormat import kotlinx.serialization.StringFormat import kotlin.coroutines.CoroutineContext -internal class RPCServerService<T : RemoteService>( +internal class KrpcServerService<T : RemoteService>( private val service: T, private val descriptor: RpcServiceDescriptor<T>, - override val config: RPCConfig.Server, - private val connector: RPCServerConnector, + override val config: KrpcConfig.Server, + private val connector: KrpcServerConnector, coroutineContext: CoroutineContext, -) : RPCServiceHandler(), CoroutineScope { +) : KrpcServiceHandler(), CoroutineScope { override val logger = CommonLogger.logger(objectId(descriptor.fqName)) - override val sender: RPCMessageSender get() = connector + override val sender: KrpcMessageSender get() = connector private val scope: CoroutineScope = this override val coroutineContext: CoroutineContext = coroutineContext.withServerStreamScope() - private val requestMap = ConcurrentHashMap<String, RPCRequest>() + private val requestMap = ConcurrentHashMap<String, RpcRequest>() init { coroutineContext.job.invokeOnCompletion { @@ -40,7 +40,7 @@ internal class RPCServerService<T : RemoteService>( } } - suspend fun accept(message: RPCCallMessage) { + suspend fun accept(message: KrpcCallMessage) { val result = runCatching { processMessage(message) } @@ -60,7 +60,7 @@ internal class RPCServerService<T : RemoteService>( } val error = serializeException(exception) - val errorMessage = RPCCallMessage.CallException( + val errorMessage = KrpcCallMessage.CallException( callId = message.callId, serviceType = message.serviceType, cause = error, @@ -71,39 +71,39 @@ internal class RPCServerService<T : RemoteService>( } } - private suspend fun processMessage(message: RPCCallMessage) { + private suspend fun processMessage(message: KrpcCallMessage) { logger.trace { "Incoming message $message" } when (message) { - is RPCCallMessage.CallData -> { + is KrpcCallMessage.CallData -> { handleCall(message) } - is RPCCallMessage.CallException -> { + is KrpcCallMessage.CallException -> { cancelRequest( callId = message.callId, - message = "Cancelled after RPCCallMessage.CallException received", + message = "Cancelled after KrpcCallMessage.CallException received", cause = message.cause.deserialize(), ) } - is RPCCallMessage.CallSuccess -> { + is KrpcCallMessage.CallSuccess -> { error("Unexpected success message: $message") } - is RPCCallMessage.StreamCancel -> { + is KrpcCallMessage.StreamCancel -> { // if no stream is present, it probably was already canceled getAndAwaitStreamContext(message) ?.cancelStream(message) } - is RPCCallMessage.StreamFinished -> { + is KrpcCallMessage.StreamFinished -> { // if no stream is present, it probably was already finished getAndAwaitStreamContext(message) ?.closeStream(message) } - is RPCCallMessage.StreamMessage -> { + is KrpcCallMessage.StreamMessage -> { requestMap[message.callId]?.streamContext?.apply { awaitInitialized().send(message, prepareSerialFormat(this)) } ?: error("Invalid request call id: ${message.callId}") @@ -111,22 +111,22 @@ internal class RPCServerService<T : RemoteService>( } } - private suspend fun getAndAwaitStreamContext(message: RPCCallMessage): RPCStreamContext? { + private suspend fun getAndAwaitStreamContext(message: KrpcCallMessage): KrpcStreamContext? { return requestMap[message.callId]?.streamContext?.awaitInitialized() } @Suppress("detekt.ThrowsCount", "detekt.LongMethod") - private fun handleCall(callData: RPCCallMessage.CallData) { + private fun handleCall(callData: KrpcCallMessage.CallData) { val callId = callData.callId - val streamContext = LazyRPCStreamContext(streamScopeOrNull(scope)) { - RPCStreamContext(callId, config, callData.connectionId, callData.serviceId, it) + val streamContext = LazyKrpcStreamContext(streamScopeOrNull(scope)) { + KrpcStreamContext(callId, config, callData.connectionId, callData.serviceId, it) } val serialFormat = prepareSerialFormat(streamContext) val isMethod = when (callData.callType) { - RPCCallMessage.CallType.Method -> true - RPCCallMessage.CallType.Field -> false + KrpcCallMessage.CallType.Method -> true + KrpcCallMessage.CallType.Field -> false else -> callData.callableName .endsWith("\$method") // compatibility with beta-4.2 clients } @@ -170,7 +170,7 @@ internal class RPCServerService<T : RemoteService>( when (serialFormat) { is StringFormat -> { val stringValue = serialFormat.encodeToString(returnSerializer, value) - RPCCallMessage.CallSuccessString( + KrpcCallMessage.CallSuccessString( callId = callData.callId, serviceType = descriptor.fqName, data = stringValue, @@ -181,7 +181,7 @@ internal class RPCServerService<T : RemoteService>( is BinaryFormat -> { val binaryValue = serialFormat.encodeToByteArray(returnSerializer, value) - RPCCallMessage.CallSuccessBinary( + KrpcCallMessage.CallSuccessBinary( callId = callData.callId, serviceType = descriptor.fqName, data = binaryValue, @@ -200,7 +200,7 @@ internal class RPCServerService<T : RemoteService>( failure = cause val serializedCause = serializeException(cause) - RPCCallMessage.CallException( + KrpcCallMessage.CallException( callId = callId, serviceType = descriptor.fqName, cause = serializedCause, @@ -228,7 +228,7 @@ internal class RPCServerService<T : RemoteService>( } } - requestMap[callId] = RPCRequest(requestJob, streamContext) + requestMap[callId] = RpcRequest(requestJob, streamContext) requestJob.start() } @@ -243,19 +243,19 @@ internal class RPCServerService<T : RemoteService>( // acknowledge the cancellation sender.sendMessage( - RPCGenericMessage( + KrpcGenericMessage( connectionId = null, pluginParams = mapOf( - RPCPluginKey.GENERIC_MESSAGE_TYPE to RPCGenericMessage.CANCELLATION_TYPE, - RPCPluginKey.CANCELLATION_TYPE to CancellationType.CANCELLATION_ACK.toString(), - RPCPluginKey.CANCELLATION_ID to callId, + KrpcPluginKey.GENERIC_MESSAGE_TYPE to KrpcGenericMessage.CANCELLATION_TYPE, + KrpcPluginKey.CANCELLATION_TYPE to CancellationType.CANCELLATION_ACK.toString(), + KrpcPluginKey.CANCELLATION_ID to callId, ) ) ) } } -private class RPCRequest(val handlerJob: Job, val streamContext: LazyRPCStreamContext) { +private class RpcRequest(val handlerJob: Job, val streamContext: LazyKrpcStreamContext) { suspend fun cancelAndClose( callId: String, message: String? = null, diff --git a/krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KRPCTestClient.kt b/krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KRPCTestClient.kt deleted file mode 100644 index c691ef78..00000000 --- a/krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KRPCTestClient.kt +++ /dev/null @@ -1,20 +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.krpc.test - -import kotlinx.rpc.krpc.RPCConfig -import kotlinx.rpc.krpc.RPCTransport -import kotlinx.rpc.krpc.client.KRPCClient - -/** - * Implementation of [KRPCClient] that can be used to test custom [RPCTransport]. - * - * NOTE: one [RPCTransport] is meant to be used by only one client, - * but this class allows for abuse. Be cautious about how you handle [RPCTransport] with this class. - */ -class KRPCTestClient( - config: RPCConfig.Client, - transport: RPCTransport, -) : KRPCClient(config, transport) diff --git a/krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KRPCTestServer.kt b/krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KRPCTestServer.kt deleted file mode 100644 index 2d65a5f4..00000000 --- a/krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KRPCTestServer.kt +++ /dev/null @@ -1,20 +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.krpc.test - -import kotlinx.rpc.krpc.RPCConfig -import kotlinx.rpc.krpc.RPCTransport -import kotlinx.rpc.krpc.server.KRPCServer - -/** - * Implementation of [KRPCServer] that can be used to test custom [RPCTransport]. - * - * NOTE: one [RPCTransport] is meant to be used by only one server, - * but this class allows for abuse. Be cautious about how you handle [RPCTransport] with this class. - */ -class KRPCTestServer( - config: RPCConfig.Server, - transport: RPCTransport, -) : KRPCServer(config, transport) diff --git a/krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KrpcTestClient.kt b/krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KrpcTestClient.kt new file mode 100644 index 00000000..f2ccc1f4 --- /dev/null +++ b/krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KrpcTestClient.kt @@ -0,0 +1,20 @@ +/* + * 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.krpc.test + +import kotlinx.rpc.krpc.KrpcConfig +import kotlinx.rpc.krpc.KrpcTransport +import kotlinx.rpc.krpc.client.KrpcClient + +/** + * Implementation of [KrpcClient] that can be used to test custom [KrpcTransport]. + * + * NOTE: one [KrpcTransport] is meant to be used by only one client, + * but this class allows for abuse. Be cautious about how you handle [KrpcTransport] with this class. + */ +class KrpcTestClient( + config: KrpcConfig.Client, + transport: KrpcTransport, +) : KrpcClient(config, transport) diff --git a/krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KrpcTestServer.kt b/krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KrpcTestServer.kt new file mode 100644 index 00000000..5176f091 --- /dev/null +++ b/krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KrpcTestServer.kt @@ -0,0 +1,20 @@ +/* + * 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.krpc.test + +import kotlinx.rpc.krpc.KrpcConfig +import kotlinx.rpc.krpc.KrpcTransport +import kotlinx.rpc.krpc.server.KrpcServer + +/** + * Implementation of [KrpcServer] that can be used to test custom [KrpcTransport]. + * + * NOTE: one [KrpcTransport] is meant to be used by only one server, + * but this class allows for abuse. Be cautious about how you handle [KrpcTransport] with this class. + */ +class KrpcTestServer( + config: KrpcConfig.Server, + transport: KrpcTransport, +) : KrpcServer(config, transport) diff --git a/krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KRPCTestService.kt b/krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KrpcTestService.kt similarity index 98% rename from krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KRPCTestService.kt rename to krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KrpcTestService.kt index ddd6ca0d..ec522edb 100644 --- a/krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KRPCTestService.kt +++ b/krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KrpcTestService.kt @@ -12,7 +12,7 @@ import kotlinx.rpc.annotations.Rpc @Suppress("detekt.TooManyFunctions") @Rpc -interface KRPCTestService : RemoteService { +interface KrpcTestService : RemoteService { suspend fun empty() suspend fun returnType(): String suspend fun simpleWithParams(name: String): String diff --git a/krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KRPCTestServiceBackend.kt b/krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KrpcTestServiceBackend.kt similarity index 98% rename from krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KRPCTestServiceBackend.kt rename to krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KrpcTestServiceBackend.kt index 4a4afe7d..8be81217 100644 --- a/krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KRPCTestServiceBackend.kt +++ b/krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KrpcTestServiceBackend.kt @@ -12,7 +12,7 @@ import kotlin.coroutines.resumeWithException import kotlin.test.assertEquals @OptIn(ExperimentalCoroutinesApi::class) -class KRPCTestServiceBackend(override val coroutineContext: CoroutineContext) : KRPCTestService { +class KrpcTestServiceBackend(override val coroutineContext: CoroutineContext) : KrpcTestService { companion object { const val SHARED_FLOW_REPLAY = 5 } diff --git a/krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KRPCTransportTestBase.kt b/krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KrpcTransportTestBase.kt similarity index 95% rename from krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KRPCTransportTestBase.kt rename to krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KrpcTransportTestBase.kt index d894331a..7041ea81 100644 --- a/krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KRPCTransportTestBase.kt +++ b/krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/KrpcTransportTestBase.kt @@ -10,11 +10,11 @@ import kotlinx.coroutines.* import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.* import kotlinx.rpc.awaitFieldInitialization -import kotlinx.rpc.krpc.RPCTransport +import kotlinx.rpc.krpc.KrpcTransport import kotlinx.rpc.krpc.rpcClientConfig import kotlinx.rpc.krpc.rpcServerConfig -import kotlinx.rpc.krpc.serialization.RPCSerialFormatConfiguration -import kotlinx.rpc.krpc.server.KRPCServer +import kotlinx.rpc.krpc.serialization.KrpcSerialFormatConfiguration +import kotlinx.rpc.krpc.server.KrpcServer import kotlinx.rpc.krpc.streamScoped import kotlinx.rpc.registerService import kotlinx.rpc.withService @@ -27,13 +27,13 @@ import java.util.concurrent.atomic.AtomicBoolean import kotlin.coroutines.cancellation.CancellationException import kotlin.test.* -abstract class KRPCTransportTestBase { - protected abstract val serializationConfig: RPCSerialFormatConfiguration.() -> Unit +abstract class KrpcTransportTestBase { + protected abstract val serializationConfig: KrpcSerialFormatConfiguration.() -> Unit private val serverConfig by lazy { rpcServerConfig { sharedFlowParameters { - replay = KRPCTestServiceBackend.SHARED_FLOW_REPLAY + replay = KrpcTestServiceBackend.SHARED_FLOW_REPLAY } serialization { @@ -45,7 +45,7 @@ abstract class KRPCTransportTestBase { private val clientConfig by lazy { rpcClientConfig { sharedFlowParameters { - replay = KRPCTestServiceBackend.SHARED_FLOW_REPLAY + replay = KrpcTestServiceBackend.SHARED_FLOW_REPLAY } serialization { @@ -54,18 +54,18 @@ abstract class KRPCTransportTestBase { } } - abstract val clientTransport: RPCTransport - abstract val serverTransport: RPCTransport + abstract val clientTransport: KrpcTransport + abstract val serverTransport: KrpcTransport - private lateinit var backend: KRPCServer - private lateinit var client: KRPCTestService + private lateinit var backend: KrpcServer + private lateinit var client: KrpcTestService @BeforeTest fun start() { - backend = KRPCTestServer(serverConfig, serverTransport) - backend.registerService<KRPCTestService> { KRPCTestServiceBackend(it) } + backend = KrpcTestServer(serverConfig, serverTransport) + backend.registerService<KrpcTestService> { KrpcTestServiceBackend(it) } - client = KRPCTestClient(clientConfig, clientTransport).withService() + client = KrpcTestClient(clientConfig, clientTransport).withService() } @AfterTest @@ -387,7 +387,7 @@ abstract class KRPCTransportTestBase { } try { client.throwsSerializableWithMessageAndCause("me") - } catch (e: KRPCTestServiceBackend.SerializableTestException) { + } catch (e: KrpcTestServiceBackend.SerializableTestException) { assertEquals("me", e.message) assertEquals("cause: me", e.cause?.message) } diff --git a/krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/Payloads.kt b/krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/Payloads.kt index ee31b4f3..883012c3 100644 --- a/krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/Payloads.kt +++ b/krpc/krpc-test/src/jvmMain/kotlin/kotlinx/rpc/krpc/test/Payloads.kt @@ -58,7 +58,7 @@ fun <T> plainFlow(count: Int = 5, get: (Int) -> T): Flow<T> { private fun <T, FlowT : MutableSharedFlow<T>> CoroutineScope.runSharedFlow( flow: FlowT, - count: Int = KRPCTestServiceBackend.SHARED_FLOW_REPLAY, + count: Int = KrpcTestServiceBackend.SHARED_FLOW_REPLAY, getter: (Int) -> T, ) = apply { launch { @@ -69,7 +69,7 @@ private fun <T, FlowT : MutableSharedFlow<T>> CoroutineScope.runSharedFlow( } fun <T> CoroutineScope.sharedFlowOfT(getter: (Int) -> T): MutableSharedFlow<T> { - return MutableSharedFlow<T>(KRPCTestServiceBackend.SHARED_FLOW_REPLAY).also { flow -> + return MutableSharedFlow<T>(KrpcTestServiceBackend.SHARED_FLOW_REPLAY).also { flow -> runSharedFlow(flow) { getter(it) } } } diff --git a/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/LocalTransport.kt b/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/LocalTransport.kt index 0bda4528..4250b105 100644 --- a/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/LocalTransport.kt +++ b/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/LocalTransport.kt @@ -9,37 +9,37 @@ import kotlinx.coroutines.Job import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.job -import kotlinx.rpc.krpc.RPCTransport -import kotlinx.rpc.krpc.RPCTransportMessage +import kotlinx.rpc.krpc.KrpcTransport +import kotlinx.rpc.krpc.KrpcTransportMessage import kotlin.coroutines.CoroutineContext class LocalTransport(parentScope: CoroutineScope? = null) : CoroutineScope { override val coroutineContext = parentScope?.run { SupervisorJob(coroutineContext.job) } ?: SupervisorJob() - private val clientIncoming = Channel<RPCTransportMessage>() - private val serverIncoming = Channel<RPCTransportMessage>() + private val clientIncoming = Channel<KrpcTransportMessage>() + private val serverIncoming = Channel<KrpcTransportMessage>() - val client: RPCTransport = object : RPCTransport { + val client: KrpcTransport = object : KrpcTransport { override val coroutineContext: CoroutineContext = Job(this@LocalTransport.coroutineContext.job) - override suspend fun send(message: RPCTransportMessage) { + override suspend fun send(message: KrpcTransportMessage) { serverIncoming.send(message) } - override suspend fun receive(): RPCTransportMessage { + override suspend fun receive(): KrpcTransportMessage { return clientIncoming.receive() } } - val server: RPCTransport = object : RPCTransport { + val server: KrpcTransport = object : KrpcTransport { override val coroutineContext: CoroutineContext = Job(this@LocalTransport.coroutineContext) - override suspend fun send(message: RPCTransportMessage) { + override suspend fun send(message: KrpcTransportMessage) { clientIncoming.send(message) } - override suspend fun receive(): RPCTransportMessage { + override suspend fun receive(): KrpcTransportMessage { return serverIncoming.receive() } } diff --git a/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/LocalTransportTest.kt b/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/LocalTransportTest.kt index 23e76938..b5b73247 100644 --- a/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/LocalTransportTest.kt +++ b/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/LocalTransportTest.kt @@ -4,32 +4,32 @@ package kotlinx.rpc.krpc.test -import kotlinx.rpc.krpc.RPCTransport -import kotlinx.rpc.krpc.serialization.RPCSerialFormatConfiguration +import kotlinx.rpc.krpc.KrpcTransport +import kotlinx.rpc.krpc.serialization.KrpcSerialFormatConfiguration import kotlinx.rpc.krpc.serialization.cbor.cbor import kotlinx.rpc.krpc.serialization.json.json import kotlinx.rpc.krpc.serialization.protobuf.protobuf import kotlinx.serialization.ExperimentalSerializationApi -abstract class LocalTransportTest : KRPCTransportTestBase() { +abstract class LocalTransportTest : KrpcTransportTestBase() { private val transport = LocalTransport() - override val clientTransport: RPCTransport + override val clientTransport: KrpcTransport get() = transport.client - override val serverTransport: RPCTransport + override val serverTransport: KrpcTransport get() = transport.server } class JsonLocalTransportTest : LocalTransportTest() { - override val serializationConfig: RPCSerialFormatConfiguration.() -> Unit = { + override val serializationConfig: KrpcSerialFormatConfiguration.() -> Unit = { json() } } class CborLocalTransportTest : LocalTransportTest() { @OptIn(ExperimentalSerializationApi::class) - override val serializationConfig: RPCSerialFormatConfiguration.() -> Unit = { + override val serializationConfig: KrpcSerialFormatConfiguration.() -> Unit = { cbor() } } @@ -37,7 +37,7 @@ class CborLocalTransportTest : LocalTransportTest() { @Suppress("detekt.EmptyFunctionBlock") class ProtoBufLocalTransportTest : LocalTransportTest() { @OptIn(ExperimentalSerializationApi::class) - override val serializationConfig: RPCSerialFormatConfiguration.() -> Unit = { + override val serializationConfig: KrpcSerialFormatConfiguration.() -> Unit = { protobuf() } diff --git a/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/ProtocolTest.kt b/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/ProtocolTest.kt index 9fbaaf5a..e7842312 100644 --- a/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/ProtocolTest.kt +++ b/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/ProtocolTest.kt @@ -6,8 +6,8 @@ package kotlinx.rpc.krpc.test import junit.framework.TestCase.assertEquals import kotlinx.coroutines.launch -import kotlinx.rpc.krpc.RPCTransportMessage -import kotlinx.rpc.krpc.internal.RPCPlugin +import kotlinx.rpc.krpc.KrpcTransportMessage +import kotlinx.rpc.krpc.internal.KrpcPlugin import kotlinx.rpc.krpc.rpcClientConfig import kotlinx.rpc.krpc.rpcServerConfig import kotlinx.rpc.krpc.serialization.protobuf.protobuf @@ -28,8 +28,8 @@ class ProtocolTest : ProtocolTestBase() { service.sendRequest() // after a call is finished - all handshake data should be exchanged - assertEquals(RPCPlugin.ALL, defaultClient.supportedPlugins) - assertEquals(RPCPlugin.ALL, defaultServer.supportedPlugins) + assertEquals(KrpcPlugin.ALL, defaultClient.supportedPlugins) + assertEquals(KrpcPlugin.ALL, defaultServer.supportedPlugins) } // old client: pre 5.3-beta (including) @@ -38,13 +38,13 @@ class ProtocolTest : ProtocolTestBase() { // init defaultServer - val message = RPCTransportMessage.StringMessage( + val message = KrpcTransportMessage.StringMessage( "{\"type\":\"org.jetbrains.krpc.RPCMessage.CallData\",\"callId\":\"1:kotlinx.rpc.ProtocolTestServiceClient.SendRequest_RPCData:1\",\"serviceType\":\"kotlinx.rpc.krpc.test.ProtocolTestService\",\"method\":\"sendRequest\",\"callType\":\"Method\",\"data\":\"{}\"}", ) transport.client.send(message) - val response = transport.client.receive() as RPCTransportMessage.StringMessage + val response = transport.client.receive() as KrpcTransportMessage.StringMessage assertEquals( "{\"type\":\"org.jetbrains.krpc.RPCMessage.CallSuccess\",\"callId\":\"1:kotlinx.rpc.ProtocolTestServiceClient.SendRequest_RPCData:1\",\"serviceType\":\"kotlinx.rpc.krpc.test.ProtocolTestService\",\"data\":\"{}\"}", response.value @@ -62,7 +62,7 @@ class ProtocolTest : ProtocolTestBase() { val connectionId = 1 - val serverHandshakeMessage = RPCTransportMessage.StringMessage( + val serverHandshakeMessage = KrpcTransportMessage.StringMessage( "{\"type\":\"org.jetbrains.krpc.internal.transport.RPCProtocolMessage.Handshake\",\"connectionId\":$connectionId,\"supportedPlugins\":[-32767, 32766, 32767]}" // 32766 and 32767 are unknown to the client ) @@ -71,7 +71,7 @@ class ProtocolTest : ProtocolTestBase() { transport.server.receive() // callId changes here are always compatible - val serverResponseMessage = RPCTransportMessage.StringMessage( + val serverResponseMessage = KrpcTransportMessage.StringMessage( "{\"type\":\"org.jetbrains.krpc.RPCMessage.CallSuccess\",\"callId\":\"$connectionId:kotlinx.rpc.krpc.test.ProtocolTestService.`\$rpcServiceStub`.`sendRequest\$rpcMethod`:1\",\"serviceType\":\"kotlinx.rpc.krpc.test.ProtocolTestService\",\"data\":\"{}\"}" ) @@ -79,7 +79,7 @@ class ProtocolTest : ProtocolTestBase() { job.join() - assertContentEquals(listOf(RPCPlugin.HANDSHAKE, RPCPlugin.UNKNOWN), defaultClient.supportedPlugins) + assertContentEquals(listOf(KrpcPlugin.HANDSHAKE, KrpcPlugin.UNKNOWN), defaultClient.supportedPlugins) } @Test @@ -87,7 +87,7 @@ class ProtocolTest : ProtocolTestBase() { // init defaultServer - val clientHandshakeMessage = RPCTransportMessage.StringMessage( + val clientHandshakeMessage = KrpcTransportMessage.StringMessage( "{\"type\":\"org.jetbrains.krpc.internal.transport.RPCProtocolMessage.Handshake\",\"connectionId\":null,\"supportedPlugins\":[-32767, 32766, 32767]}" // 32766 and 32767 are unknown to server ) @@ -95,7 +95,7 @@ class ProtocolTest : ProtocolTestBase() { transport.client.receive() - assertContentEquals(listOf(RPCPlugin.HANDSHAKE, RPCPlugin.UNKNOWN), defaultServer.supportedPlugins) + assertContentEquals(listOf(KrpcPlugin.HANDSHAKE, KrpcPlugin.UNKNOWN), defaultServer.supportedPlugins) } @Test @@ -103,7 +103,7 @@ class ProtocolTest : ProtocolTestBase() { // init defaultServer - val clientHandshakeMessage = RPCTransportMessage.StringMessage( + val clientHandshakeMessage = KrpcTransportMessage.StringMessage( "{\"type\":\"org.jetbrains.krpc.internal.transport.RPCProtocolMessage.Handshake\",\"connectionId\":null,\"supportedPlugins\":[-32767],\"pluginParams\":{32766:\"from 32766\", 32767:\"from 32767\"}}" // 32766 and 32767 are unknown to server ) @@ -131,7 +131,7 @@ class ProtocolTest : ProtocolTestBase() { defaultServer // same value as testMultipleUnknownPluginParamEntriesForServer but in protobuf format - val clientHandshakeMessage = RPCTransportMessage.BinaryMessage( + val clientHandshakeMessage = KrpcTransportMessage.BinaryMessage( "0a426f72672e6a6574627261696e732e6b7270632e696e7465726e616c2e7472616e73706f72742e52504350726f746f636f6c4d6573736167652e48616e647368616b6512310801108180feffffffffffff011a1008feff01120a66726f6d2033323736361a1008ffff01120a66726f6d203332373637".hexToByteArray() // 32766 and 32767 are unknown to server ) diff --git a/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/ProtocolTestBase.kt b/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/ProtocolTestBase.kt index 02e67ad2..e84a37f4 100644 --- a/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/ProtocolTestBase.kt +++ b/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/ProtocolTestBase.kt @@ -12,15 +12,15 @@ import kotlinx.coroutines.test.TestScope import kotlinx.rpc.RemoteService import kotlinx.rpc.annotations.Rpc import kotlinx.rpc.internal.utils.hex.hexToReadableBinary -import kotlinx.rpc.krpc.RPCConfig -import kotlinx.rpc.krpc.client.KRPCClient +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.rpcClientConfig import kotlinx.rpc.krpc.rpcServerConfig import kotlinx.rpc.krpc.serialization.json.json -import kotlinx.rpc.krpc.server.KRPCServer +import kotlinx.rpc.krpc.server.KrpcServer import kotlinx.rpc.registerService import kotlinx.rpc.withService import kotlinx.serialization.BinaryFormat @@ -29,12 +29,12 @@ import kotlin.coroutines.CoroutineContext abstract class ProtocolTestBase { @Suppress("RedundantUnitReturnType") protected fun runTest( - clientConfig: RPCConfig.Client = rpcClientConfig { + clientConfig: KrpcConfig.Client = rpcClientConfig { serialization { json() } }, - serverConfig: RPCConfig.Server = rpcServerConfig { + serverConfig: KrpcConfig.Server = rpcServerConfig { serialization { json() } @@ -49,8 +49,8 @@ abstract class ProtocolTestBase { } class TestBody( - clientConfig: RPCConfig.Client, - serverConfig: RPCConfig.Server, + clientConfig: KrpcConfig.Client, + serverConfig: KrpcConfig.Server, private val scope: TestScope ) : CoroutineScope by scope { private val logger = object : DumpLogger { @@ -105,11 +105,11 @@ private class ProtocolTestServiceImpl( } class ProtocolTestServer( - config: RPCConfig.Server, + config: KrpcConfig.Server, transport: LocalTransport, -) : KRPCServer(config, transport.server) +) : KrpcServer(config, transport.server) class ProtocolTestClient( - config: RPCConfig.Client, + config: KrpcConfig.Client, transport: LocalTransport, -) : KRPCClient(config, transport.client) +) : KrpcClient(config, transport.client) diff --git a/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/TransportTest.kt b/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/TransportTest.kt index 4fba632a..48db081b 100644 --- a/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/TransportTest.kt +++ b/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/TransportTest.kt @@ -8,7 +8,7 @@ import junit.framework.TestCase.assertEquals import kotlinx.coroutines.* import kotlinx.rpc.* import kotlinx.rpc.annotations.Rpc -import kotlinx.rpc.krpc.RPCConfigBuilder +import kotlinx.rpc.krpc.KrpcConfigBuilder import kotlinx.rpc.krpc.rpcClientConfig import kotlinx.rpc.krpc.rpcServerConfig import kotlinx.rpc.krpc.serialization.json.json @@ -61,22 +61,22 @@ class TransportTest { } private fun clientOf(localTransport: LocalTransport): RpcClient { - return KRPCTestClient(clientConfig, localTransport.client) + return KrpcTestClient(clientConfig, localTransport.client) } private fun serverOf( localTransport: LocalTransport, - config: (RPCConfigBuilder.Server.() -> Unit)? = null - ): RPCServer { + config: (KrpcConfigBuilder.Server.() -> Unit)? = null + ): RpcServer { val serverConfig = config?.let { rpcServerConfig(it) } ?: serverConfig - return KRPCTestServer(serverConfig, localTransport.server) + return KrpcTestServer(serverConfig, localTransport.server) } @Test fun testUsingWrongService(): Unit = runBlocking { val transports = LocalTransport() - val client = clientOf(transports).withService<KRPCTestService>() + val client = clientOf(transports).withService<KrpcTestService>() val result = async { assertFailsWith<IllegalStateException> { client.simpleWithParams("foo") @@ -225,7 +225,7 @@ class TransportTest { fun testCancelFromClientToServer() = runBlocking { val transports = LocalTransport() - val client = clientOf(transports).withService<KRPCTestService>() + val client = clientOf(transports).withService<KrpcTestService>() val server = serverOf(transports) val echoServices = server.registerServiceAndReturn<Echo, _> { EchoImpl(it) } @@ -235,7 +235,7 @@ class TransportTest { assertTrue(echoServices.single().coroutineContext.job.isCancelled) } - private inline fun <reified Service : RemoteService, reified Impl : Service> RPCServer.registerServiceAndReturn( + private inline fun <reified Service : RemoteService, reified Impl : Service> RpcServer.registerServiceAndReturn( crossinline body: (CoroutineContext) -> Impl, ): List<Impl> { val instances = mutableListOf<Impl>() diff --git a/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/api/ApiVersioningTest.kt b/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/api/ApiVersioningTest.kt index cd96fce2..9c0e1fee 100644 --- a/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/api/ApiVersioningTest.kt +++ b/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/api/ApiVersioningTest.kt @@ -9,9 +9,9 @@ import kotlinx.coroutines.flow.take import kotlinx.coroutines.flow.toList import kotlinx.rpc.awaitFieldInitialization import kotlinx.rpc.krpc.internal.CancellationType -import kotlinx.rpc.krpc.internal.RPCMessage -import kotlinx.rpc.krpc.internal.RPCPlugin -import kotlinx.rpc.krpc.internal.RPCPluginKey +import kotlinx.rpc.krpc.internal.KrpcMessage +import kotlinx.rpc.krpc.internal.KrpcPlugin +import kotlinx.rpc.krpc.internal.KrpcPluginKey import kotlinx.rpc.krpc.test.api.util.GoldUtils.NewLine import kotlinx.rpc.krpc.test.plainFlow import org.jetbrains.krpc.test.api.util.SamplingData @@ -28,19 +28,19 @@ import kotlin.test.fail class ApiVersioningTest { @Test fun testProtocolApiVersion() { - val context = checkProtocolApi<RPCMessage>() + val context = checkProtocolApi<KrpcMessage>() context.fails.failIfAnyCauses() } @Test - fun testRPCPluginEnum() { - testEnum<RPCPlugin>() + fun testRpcPluginEnum() { + testEnum<KrpcPlugin>() } @Test - fun testRPCPluginKeyEnum() { - testEnum<RPCPluginKey>() + fun testRpcPluginKeyEnum() { + testEnum<KrpcPluginKey>() } @Test @@ -171,7 +171,7 @@ class ApiVersioningTest { val INDEXED_ENUM_DUMPS_DIR: Path = Path("src/jvmTest/resources/indexed_enum_dumps/") private fun String.versionToDirName(): String { - return replace('.', '_').replace('-', '_') + return replace('.', '_').replace('-', '_').substringBefore("-") } fun Path.latestVersionOrCurrent(): Path { @@ -184,7 +184,7 @@ class ApiVersioningTest { aBeta && bBeta -> a.compareTo(b) aBeta -> -1 bBeta -> 1 - else -> a.compareTo(b) + else -> a.name.substringBefore("-").compareTo(b.name.substringBefore("-")) } }.lastOrNull() ?: resolve(LIBRARY_VERSION_DIR) 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 594bfda9..5f68d462 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 @@ -13,18 +13,18 @@ import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.runTest import kotlinx.rpc.RemoteService import kotlinx.rpc.internal.utils.hex.hexToReadableBinary -import kotlinx.rpc.krpc.RPCTransportMessage +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.rpcClientConfig import kotlinx.rpc.krpc.rpcServerConfig -import kotlinx.rpc.krpc.serialization.RPCSerialFormatConfiguration +import kotlinx.rpc.krpc.serialization.KrpcSerialFormatConfiguration import kotlinx.rpc.krpc.serialization.json.json import kotlinx.rpc.krpc.serialization.protobuf.protobuf -import kotlinx.rpc.krpc.test.KRPCTestClient -import kotlinx.rpc.krpc.test.KRPCTestServer -import kotlinx.rpc.krpc.test.KRPCTestServiceBackend +import kotlinx.rpc.krpc.test.KrpcTestClient +import kotlinx.rpc.krpc.test.KrpcTestServer +import kotlinx.rpc.krpc.test.KrpcTestServiceBackend import kotlinx.rpc.krpc.test.LocalTransport import kotlinx.rpc.krpc.test.api.ApiVersioningTest.Companion.latestVersionOrCurrent import kotlinx.rpc.krpc.test.api.util.GoldComparable @@ -173,10 +173,10 @@ class WireSamplingTestScope(private val sampleName: String, scope: TestScope) : } @OptIn(ExperimentalStdlibApi::class) - private fun String.toTransportMessage(format: SamplingFormat): RPCTransportMessage { + private fun String.toTransportMessage(format: SamplingFormat): KrpcTransportMessage { return when (format) { - SamplingFormat.Json -> RPCTransportMessage.StringMessage(this) - SamplingFormat.Protobuf -> RPCTransportMessage.BinaryMessage(hexToByteArray()) + SamplingFormat.Json -> KrpcTransportMessage.StringMessage(this) + SamplingFormat.Protobuf -> KrpcTransportMessage.BinaryMessage(hexToByteArray()) } } @@ -197,13 +197,13 @@ private class WireToolkit(scope: CoroutineScope, format: SamplingFormat, val log val transport = LocalTransport(scope) val client by lazy { - KRPCTestClient(rpcClientConfig { + KrpcTestClient(rpcClientConfig { serialization { format.init(this) } sharedFlowParameters { - replay = KRPCTestServiceBackend.SHARED_FLOW_REPLAY + replay = KrpcTestServiceBackend.SHARED_FLOW_REPLAY } }, transport.client) } @@ -213,7 +213,7 @@ private class WireToolkit(scope: CoroutineScope, format: SamplingFormat, val log } val server by lazy { - KRPCTestServer(rpcServerConfig { serialization { format.init(this) } }, transport.server).apply { + KrpcTestServer(rpcServerConfig { serialization { format.init(this) } }, transport.server).apply { registerService<SamplingService> { SamplingServiceImpl(it) } } } @@ -258,7 +258,7 @@ private class WireToolkit(scope: CoroutineScope, format: SamplingFormat, val log } @OptIn(ExperimentalSerializationApi::class) -enum class SamplingFormat(val commentBinaryOutput: Boolean, val init: RPCSerialFormatConfiguration.() -> Unit) { +enum class SamplingFormat(val commentBinaryOutput: Boolean, val init: KrpcSerialFormatConfiguration.() -> Unit) { Json(false, { json() }), diff --git a/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/cancellation/CancellationToolkit.kt b/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/cancellation/CancellationToolkit.kt index 8d927ffe..b16359a6 100644 --- a/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/cancellation/CancellationToolkit.kt +++ b/krpc/krpc-test/src/jvmTest/kotlin/kotlinx/rpc/krpc/test/cancellation/CancellationToolkit.kt @@ -7,16 +7,16 @@ package kotlinx.rpc.krpc.test.cancellation import kotlinx.coroutines.* import kotlinx.coroutines.test.TestResult import kotlinx.coroutines.test.runTest -import kotlinx.rpc.krpc.RPCConfigBuilder +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.rpcClientConfig import kotlinx.rpc.krpc.rpcServerConfig import kotlinx.rpc.krpc.serialization.json.json -import kotlinx.rpc.krpc.test.KRPCTestClient -import kotlinx.rpc.krpc.test.KRPCTestServer -import kotlinx.rpc.krpc.test.KRPCTestServiceBackend +import kotlinx.rpc.krpc.test.KrpcTestClient +import kotlinx.rpc.krpc.test.KrpcTestServer +import kotlinx.rpc.krpc.test.KrpcTestServiceBackend import kotlinx.rpc.krpc.test.LocalTransport import kotlinx.rpc.registerService import kotlinx.rpc.withService @@ -41,7 +41,7 @@ class CancellationToolkit(scope: CoroutineScope) : CoroutineScope by scope { }) } - private val serializationConfig: RPCConfigBuilder.() -> Unit = { + private val serializationConfig: KrpcConfigBuilder.() -> Unit = { serialization { json() } @@ -50,11 +50,11 @@ class CancellationToolkit(scope: CoroutineScope) : CoroutineScope by scope { val transport = LocalTransport(this) val client by lazy { - KRPCTestClient(rpcClientConfig { + KrpcTestClient(rpcClientConfig { serializationConfig() sharedFlowParameters { - replay = KRPCTestServiceBackend.SHARED_FLOW_REPLAY + replay = KrpcTestServiceBackend.SHARED_FLOW_REPLAY } }, transport.client) } @@ -65,7 +65,7 @@ class CancellationToolkit(scope: CoroutineScope) : CoroutineScope by scope { private val firstServerInstance = CompletableDeferred<CancellationServiceImpl>() suspend fun serverInstance(): CancellationServiceImpl = firstServerInstance.await() - val server = KRPCTestServer(rpcServerConfig { serializationConfig() }, transport.server).apply { + val server = KrpcTestServer(rpcServerConfig { serializationConfig() }, transport.server).apply { registerService<CancellationService> { CancellationServiceImpl(it).also { impl -> if (!firstServerInstance.isCompleted) { diff --git a/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/CallData.gold b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/CallData.gold new file mode 100644 index 00000000..d4581352 --- /dev/null +++ b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/CallData.gold @@ -0,0 +1,18 @@ +org.jetbrains.krpc.internal.transport.RPCMessage.CallData [Declared name: kotlinx.rpc.krpc.internal.KrpcCallMessage.CallData] + - callType: org.jetbrains.krpc.internal.transport.RPCMessage.CallType + - Nullable + - Declared name: kotlinx.rpc.krpc.internal.KrpcCallMessage.CallType + - callableName: kotlin.String + - callId: kotlin.String + - connectionId: kotlin.Long + - Nullable + - pluginParams: kotlin.collections.Map + - Nullable + - serviceId: kotlin.Long + - Nullable + - serviceType: kotlin.String + + org.jetbrains.krpc.internal.transport.RPCMessage.CallDataBinary + - Declared name: kotlinx.rpc.krpc.internal.KrpcCallMessage.CallDataBinary + org.jetbrains.krpc.RPCMessage.CallData + - Declared name: kotlinx.rpc.krpc.internal.KrpcCallMessage.CallDataString \ No newline at end of file diff --git a/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/CallDataBinary.gold b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/CallDataBinary.gold new file mode 100644 index 00000000..b0edd5b4 --- /dev/null +++ b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/CallDataBinary.gold @@ -0,0 +1,15 @@ +org.jetbrains.krpc.internal.transport.RPCMessage.CallDataBinary [Declared name: kotlinx.rpc.krpc.internal.KrpcCallMessage.CallDataBinary] + - callId: kotlin.String + - callType: org.jetbrains.krpc.internal.transport.RPCMessage.CallType + - Nullable + - Declared name: kotlinx.rpc.krpc.internal.KrpcCallMessage.CallType + - method: kotlin.String + - Declared name: callableName + - connectionId: kotlin.Long + - Nullable + - data: kotlin.ByteArray + - pluginParams: kotlin.collections.Map + - Nullable + - serviceId: kotlin.Long + - Nullable + - serviceType: kotlin.String \ No newline at end of file diff --git a/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/CallDataString.gold b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/CallDataString.gold new file mode 100644 index 00000000..b9ba5971 --- /dev/null +++ b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/CallDataString.gold @@ -0,0 +1,15 @@ +org.jetbrains.krpc.RPCMessage.CallData [Declared name: kotlinx.rpc.krpc.internal.KrpcCallMessage.CallDataString] + - callId: kotlin.String + - callType: org.jetbrains.krpc.internal.transport.RPCMessage.CallType + - Nullable + - Declared name: kotlinx.rpc.krpc.internal.KrpcCallMessage.CallType + - method: kotlin.String + - Declared name: callableName + - connectionId: kotlin.Long + - Nullable + - data: kotlin.String + - pluginParams: kotlin.collections.Map + - Nullable + - serviceId: kotlin.Long + - Nullable + - serviceType: kotlin.String \ No newline at end of file diff --git a/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/CallException.gold b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/CallException.gold new file mode 100644 index 00000000..3b7dfc0e --- /dev/null +++ b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/CallException.gold @@ -0,0 +1,11 @@ +org.jetbrains.krpc.RPCMessage.CallException [Declared name: kotlinx.rpc.krpc.internal.KrpcCallMessage.CallException] + - callId: kotlin.String + - cause: org.jetbrains.krpc.SerializedException + - Declared name: kotlinx.rpc.krpc.internal.SerializedException + - connectionId: kotlin.Long + - Nullable + - pluginParams: kotlin.collections.Map + - Nullable + - serviceId: kotlin.Long + - Nullable + - serviceType: kotlin.String \ No newline at end of file diff --git a/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/CallResult.gold b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/CallResult.gold new file mode 100644 index 00000000..2e7672b9 --- /dev/null +++ b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/CallResult.gold @@ -0,0 +1,14 @@ +org.jetbrains.krpc.RPCMessage.CallResult [Declared name: kotlinx.rpc.krpc.internal.KrpcCallMessage.CallResult] + - callId: kotlin.String + - connectionId: kotlin.Long + - Nullable + - pluginParams: kotlin.collections.Map + - Nullable + - serviceId: kotlin.Long + - Nullable + - serviceType: kotlin.String + + org.jetbrains.krpc.RPCMessage.CallException + - Declared name: kotlinx.rpc.krpc.internal.KrpcCallMessage.CallException + org.jetbrains.krpc.internal.transport.RPCMessage.CallSuccess + - Declared name: kotlinx.rpc.krpc.internal.KrpcCallMessage.CallSuccess \ No newline at end of file diff --git a/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/CallSuccess.gold b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/CallSuccess.gold new file mode 100644 index 00000000..f34c74a7 --- /dev/null +++ b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/CallSuccess.gold @@ -0,0 +1,14 @@ +org.jetbrains.krpc.internal.transport.RPCMessage.CallSuccess [Declared name: kotlinx.rpc.krpc.internal.KrpcCallMessage.CallSuccess] + - callId: kotlin.String + - connectionId: kotlin.Long + - Nullable + - pluginParams: kotlin.collections.Map + - Nullable + - serviceId: kotlin.Long + - Nullable + - serviceType: kotlin.String + + org.jetbrains.krpc.internal.transport.RPCMessage.CallSuccessBinary + - Declared name: kotlinx.rpc.krpc.internal.KrpcCallMessage.CallSuccessBinary + org.jetbrains.krpc.RPCMessage.CallSuccess + - Declared name: kotlinx.rpc.krpc.internal.KrpcCallMessage.CallSuccessString \ No newline at end of file diff --git a/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/CallSuccessBinary.gold b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/CallSuccessBinary.gold new file mode 100644 index 00000000..e8cd5890 --- /dev/null +++ b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/CallSuccessBinary.gold @@ -0,0 +1,10 @@ +org.jetbrains.krpc.internal.transport.RPCMessage.CallSuccessBinary [Declared name: kotlinx.rpc.krpc.internal.KrpcCallMessage.CallSuccessBinary] + - callId: kotlin.String + - connectionId: kotlin.Long + - Nullable + - data: kotlin.ByteArray + - pluginParams: kotlin.collections.Map + - Nullable + - serviceId: kotlin.Long + - Nullable + - serviceType: kotlin.String \ No newline at end of file diff --git a/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/CallSuccessString.gold b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/CallSuccessString.gold new file mode 100644 index 00000000..34c96185 --- /dev/null +++ b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/CallSuccessString.gold @@ -0,0 +1,10 @@ +org.jetbrains.krpc.RPCMessage.CallSuccess [Declared name: kotlinx.rpc.krpc.internal.KrpcCallMessage.CallSuccessString] + - callId: kotlin.String + - connectionId: kotlin.Long + - Nullable + - data: kotlin.String + - pluginParams: kotlin.collections.Map + - Nullable + - serviceId: kotlin.Long + - Nullable + - serviceType: kotlin.String \ No newline at end of file diff --git a/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/CallType.gold b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/CallType.gold new file mode 100644 index 00000000..84b5971b --- /dev/null +++ b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/CallType.gold @@ -0,0 +1,3 @@ +org.jetbrains.krpc.internal.transport.RPCMessage.CallType [Declared name: kotlinx.rpc.krpc.internal.KrpcCallMessage.CallType] + Method + Field \ No newline at end of file diff --git a/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/Failure.gold b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/Failure.gold new file mode 100644 index 00000000..f01da216 --- /dev/null +++ b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/Failure.gold @@ -0,0 +1,8 @@ +org.jetbrains.krpc.internal.transport.RPCProtocolMessage.Failure [Declared name: kotlinx.rpc.krpc.internal.KrpcProtocolMessage.Failure] + - connectionId: kotlin.Long + - Nullable + - errorMessage: kotlin.String + - failedMessage: org.jetbrains.krpc.internal.transport.RPCMessage + - Nullable + - Declared name: kotlinx.rpc.krpc.internal.KrpcMessage + - pluginParams: kotlin.collections.Map \ No newline at end of file diff --git a/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/Handshake.gold b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/Handshake.gold new file mode 100644 index 00000000..2f5e2be8 --- /dev/null +++ b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/Handshake.gold @@ -0,0 +1,5 @@ +org.jetbrains.krpc.internal.transport.RPCProtocolMessage.Handshake [Declared name: kotlinx.rpc.krpc.internal.KrpcProtocolMessage.Handshake] + - connectionId: kotlin.Long + - Nullable + - pluginParams: kotlin.collections.Map + - supportedPlugins: kotlin.collections.Set \ No newline at end of file diff --git a/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/KrpcCallMessage.gold b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/KrpcCallMessage.gold new file mode 100644 index 00000000..0273b93a --- /dev/null +++ b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/KrpcCallMessage.gold @@ -0,0 +1,20 @@ +org.jetbrains.krpc.RPCMessage [Declared name: kotlinx.rpc.krpc.internal.KrpcCallMessage] + - callId: kotlin.String + - serviceId: kotlin.Long + - Nullable + - serviceType: kotlin.String + - connectionId: kotlin.Long + - Nullable + - pluginParams: kotlin.collections.Map + - Nullable + + org.jetbrains.krpc.internal.transport.RPCMessage.CallData + - Declared name: kotlinx.rpc.krpc.internal.KrpcCallMessage.CallData + org.jetbrains.krpc.RPCMessage.CallResult + - Declared name: kotlinx.rpc.krpc.internal.KrpcCallMessage.CallResult + org.jetbrains.krpc.RPCMessage.StreamCancel + - Declared name: kotlinx.rpc.krpc.internal.KrpcCallMessage.StreamCancel + org.jetbrains.krpc.RPCMessage.StreamFinished + - Declared name: kotlinx.rpc.krpc.internal.KrpcCallMessage.StreamFinished + org.jetbrains.krpc.internal.transport.RPCMessage.StreamMessage + - Declared name: kotlinx.rpc.krpc.internal.KrpcCallMessage.StreamMessage \ No newline at end of file diff --git a/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/KrpcGenericMessage.gold b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/KrpcGenericMessage.gold new file mode 100644 index 00000000..b27a3f00 --- /dev/null +++ b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/KrpcGenericMessage.gold @@ -0,0 +1,5 @@ +org.jetbrains.krpc.internal.transport.RPCGenericMessage [Declared name: kotlinx.rpc.krpc.internal.KrpcGenericMessage] + - connectionId: kotlin.Long + - Nullable + - pluginParams: kotlin.collections.Map + - Nullable \ No newline at end of file diff --git a/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/KrpcMessage.gold b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/KrpcMessage.gold new file mode 100644 index 00000000..6924a1c4 --- /dev/null +++ b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/KrpcMessage.gold @@ -0,0 +1,12 @@ +org.jetbrains.krpc.internal.transport.RPCMessage [Declared name: kotlinx.rpc.krpc.internal.KrpcMessage] + - connectionId: kotlin.Long + - Nullable + - pluginParams: kotlin.collections.Map + - Nullable + + org.jetbrains.krpc.RPCMessage + - Declared name: kotlinx.rpc.krpc.internal.KrpcCallMessage + org.jetbrains.krpc.internal.transport.RPCGenericMessage + - Declared name: kotlinx.rpc.krpc.internal.KrpcGenericMessage + org.jetbrains.krpc.internal.transport.RPCProtocolMessage + - Declared name: kotlinx.rpc.krpc.internal.KrpcProtocolMessage \ No newline at end of file diff --git a/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/KrpcPlugin.gold b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/KrpcPlugin.gold new file mode 100644 index 00000000..a3d03ab4 --- /dev/null +++ b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/KrpcPlugin.gold @@ -0,0 +1,4 @@ +kotlinx.rpc.krpc.internal.KrpcPlugin + UNKNOWN + HANDSHAKE + CANCELLATION \ No newline at end of file diff --git a/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/KrpcPluginKey.gold b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/KrpcPluginKey.gold new file mode 100644 index 00000000..34f58e6f --- /dev/null +++ b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/KrpcPluginKey.gold @@ -0,0 +1,6 @@ +kotlinx.rpc.krpc.internal.KrpcPluginKey + UNKNOWN + GENERIC_MESSAGE_TYPE + CANCELLATION_TYPE + CANCELLATION_ID + CLIENT_SERVICE_ID \ No newline at end of file diff --git a/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/KrpcProtocolMessage.gold b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/KrpcProtocolMessage.gold new file mode 100644 index 00000000..7e80aac1 --- /dev/null +++ b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/KrpcProtocolMessage.gold @@ -0,0 +1,9 @@ +org.jetbrains.krpc.internal.transport.RPCProtocolMessage [Declared name: kotlinx.rpc.krpc.internal.KrpcProtocolMessage] + - pluginParams: kotlin.collections.Map + - connectionId: kotlin.Long + - Nullable + + org.jetbrains.krpc.internal.transport.RPCProtocolMessage.Failure + - Declared name: kotlinx.rpc.krpc.internal.KrpcProtocolMessage.Failure + org.jetbrains.krpc.internal.transport.RPCProtocolMessage.Handshake + - Declared name: kotlinx.rpc.krpc.internal.KrpcProtocolMessage.Handshake \ No newline at end of file diff --git a/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/SerializedException.gold b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/SerializedException.gold new file mode 100644 index 00000000..427993cb --- /dev/null +++ b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/SerializedException.gold @@ -0,0 +1,8 @@ +org.jetbrains.krpc.SerializedException [Declared name: kotlinx.rpc.krpc.internal.SerializedException] + - cause: org.jetbrains.krpc.SerializedException + - Nullable + - Declared name: kotlinx.rpc.krpc.internal.SerializedException + - className: kotlin.String + - message: kotlin.String + - stacktrace: kotlin.collections.List + - toStringMessage: kotlin.String \ No newline at end of file diff --git a/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/StackElement.gold b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/StackElement.gold new file mode 100644 index 00000000..d67b9597 --- /dev/null +++ b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/StackElement.gold @@ -0,0 +1,6 @@ +org.jetbrains.krpc.StackElement [Declared name: kotlinx.rpc.krpc.internal.StackElement] + - clazz: kotlin.String + - fileName: kotlin.String + - Nullable + - lineNumber: kotlin.Int + - method: kotlin.String \ No newline at end of file diff --git a/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/StreamCancel.gold b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/StreamCancel.gold new file mode 100644 index 00000000..8e6bd5e5 --- /dev/null +++ b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/StreamCancel.gold @@ -0,0 +1,13 @@ +org.jetbrains.krpc.RPCMessage.StreamCancel [Declared name: kotlinx.rpc.krpc.internal.KrpcCallMessage.StreamCancel] + - callId: kotlin.String + - cause: org.jetbrains.krpc.SerializedException + - Declared name: kotlinx.rpc.krpc.internal.SerializedException + - connectionId: kotlin.Long + - Nullable + - pluginParams: kotlin.collections.Map + - Nullable + - serviceId: kotlin.Long + - Nullable + - serviceType: kotlin.String + - flowId: kotlin.String + - Declared name: streamId \ No newline at end of file diff --git a/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/StreamFinished.gold b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/StreamFinished.gold new file mode 100644 index 00000000..a260d7d7 --- /dev/null +++ b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/StreamFinished.gold @@ -0,0 +1,11 @@ +org.jetbrains.krpc.RPCMessage.StreamFinished [Declared name: kotlinx.rpc.krpc.internal.KrpcCallMessage.StreamFinished] + - callId: kotlin.String + - connectionId: kotlin.Long + - Nullable + - pluginParams: kotlin.collections.Map + - Nullable + - serviceId: kotlin.Long + - Nullable + - serviceType: kotlin.String + - flowId: kotlin.String + - Declared name: streamId \ No newline at end of file diff --git a/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/StreamMessage.gold b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/StreamMessage.gold new file mode 100644 index 00000000..e0748591 --- /dev/null +++ b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/StreamMessage.gold @@ -0,0 +1,15 @@ +org.jetbrains.krpc.internal.transport.RPCMessage.StreamMessage [Declared name: kotlinx.rpc.krpc.internal.KrpcCallMessage.StreamMessage] + - streamId: kotlin.String + - callId: kotlin.String + - connectionId: kotlin.Long + - Nullable + - pluginParams: kotlin.collections.Map + - Nullable + - serviceId: kotlin.Long + - Nullable + - serviceType: kotlin.String + + org.jetbrains.krpc.internal.transport.RPCMessage.StreamMessageBinary + - Declared name: kotlinx.rpc.krpc.internal.KrpcCallMessage.StreamMessageBinary + org.jetbrains.krpc.RPCMessage.StreamMessage + - Declared name: kotlinx.rpc.krpc.internal.KrpcCallMessage.StreamMessageString \ No newline at end of file diff --git a/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/StreamMessageBinary.gold b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/StreamMessageBinary.gold new file mode 100644 index 00000000..6da67510 --- /dev/null +++ b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/StreamMessageBinary.gold @@ -0,0 +1,12 @@ +org.jetbrains.krpc.internal.transport.RPCMessage.StreamMessageBinary [Declared name: kotlinx.rpc.krpc.internal.KrpcCallMessage.StreamMessageBinary] + - callId: kotlin.String + - connectionId: kotlin.Long + - Nullable + - data: kotlin.ByteArray + - pluginParams: kotlin.collections.Map + - Nullable + - serviceId: kotlin.Long + - Nullable + - serviceType: kotlin.String + - flowId: kotlin.String + - Declared name: streamId \ No newline at end of file diff --git a/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/StreamMessageString.gold b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/StreamMessageString.gold new file mode 100644 index 00000000..3316fc14 --- /dev/null +++ b/krpc/krpc-test/src/jvmTest/resources/class_dumps/0_5_0/StreamMessageString.gold @@ -0,0 +1,12 @@ +org.jetbrains.krpc.RPCMessage.StreamMessage [Declared name: kotlinx.rpc.krpc.internal.KrpcCallMessage.StreamMessageString] + - callId: kotlin.String + - connectionId: kotlin.Long + - Nullable + - data: kotlin.String + - pluginParams: kotlin.collections.Map + - Nullable + - serviceId: kotlin.Long + - Nullable + - serviceType: kotlin.String + - flowId: kotlin.String + - Declared name: streamId \ No newline at end of file diff --git a/krpc/krpc-test/src/jvmTest/resources/indexed_enum_dumps/KrpcPlugin.gold b/krpc/krpc-test/src/jvmTest/resources/indexed_enum_dumps/KrpcPlugin.gold new file mode 100644 index 00000000..c913726f --- /dev/null +++ b/krpc/krpc-test/src/jvmTest/resources/indexed_enum_dumps/KrpcPlugin.gold @@ -0,0 +1,3 @@ +UNKNOWN - 0 +HANDSHAKE - 1 +CANCELLATION - 2 \ No newline at end of file diff --git a/krpc/krpc-test/src/jvmTest/resources/indexed_enum_dumps/KrpcPluginKey.gold b/krpc/krpc-test/src/jvmTest/resources/indexed_enum_dumps/KrpcPluginKey.gold new file mode 100644 index 00000000..1558b947 --- /dev/null +++ b/krpc/krpc-test/src/jvmTest/resources/indexed_enum_dumps/KrpcPluginKey.gold @@ -0,0 +1,5 @@ +UNKNOWN - 0 +GENERIC_MESSAGE_TYPE - 1 +CANCELLATION_TYPE - 2 +CANCELLATION_ID - 3 +CLIENT_SERVICE_ID - 4 \ No newline at end of file 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 32e2ce6c..511f7a13 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 @@ -315,7 +315,7 @@ FILE fqName:<root> fileName:/customParameterTypes.kt annotations: Rpc $this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.BoxService - CLASS GENERATED[kotlinx.rpc.codegen.RPCGeneratedStubKey] CLASS name:$rpcServiceStub modality:FINAL visibility:public superTypes:[<root>.BoxService] + CLASS GENERATED[kotlinx.rpc.codegen.RpcGeneratedStubKey] CLASS name:$rpcServiceStub modality:FINAL visibility:public superTypes:[<root>.BoxService] $this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.BoxService.$rpcServiceStub PROPERTY name:__rpc_stub_id visibility:private modality:FINAL [val] FIELD PROPERTY_BACKING_FIELD name:__rpc_stub_id type:kotlin.Long visibility:private [final] @@ -532,7 +532,7 @@ FILE fqName:<root> fileName:/customParameterTypes.kt TYPE_OP type=kotlin.collections.List<kotlinx.rpc.internal.RpcDeferredField<*>> origin=CAST typeOperand=kotlin.collections.List<kotlinx.rpc.internal.RpcDeferredField<*>> CALL 'public final fun emptyList <T> (): kotlin.collections.List<T of kotlin.collections.emptyList> declared in kotlin.collections' type=kotlin.collections.List<kotlin.Any?> origin=null <T>: kotlin.Any? - CLASS GENERATED[kotlinx.rpc.codegen.RPCGeneratedRpcMethodClassKey] CLASS name:test1$rpcMethod modality:FINAL visibility:public superTypes:[kotlin.Any; kotlinx.rpc.internal.RpcMethodClass] + CLASS GENERATED[kotlinx.rpc.codegen.RpcGeneratedRpcMethodClassKey] CLASS name:test1$rpcMethod modality:FINAL visibility:public superTypes:[kotlin.Any; kotlinx.rpc.internal.RpcMethodClass] annotations: Serializable(with = <null>) $this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.BoxService.$rpcServiceStub.test1$rpcMethod @@ -739,11 +739,11 @@ FILE fqName:<root> fileName:/customParameterTypes.kt CALL 'public abstract fun endStructure (descriptor: kotlinx.serialization.descriptors.SerialDescriptor): kotlin.Unit declared in kotlinx.serialization.encoding.CompositeEncoder' type=kotlin.Unit origin=null $this: GET_VAR 'val tmp_20: kotlinx.serialization.encoding.CompositeEncoder declared in <root>.BoxService.$rpcServiceStub.test1$rpcMethod.$serializer.serialize' type=kotlinx.serialization.encoding.CompositeEncoder origin=null descriptor: GET_VAR 'val tmp_19: kotlinx.serialization.descriptors.SerialDescriptor declared in <root>.BoxService.$rpcServiceStub.test1$rpcMethod.$serializer.serialize' type=kotlinx.serialization.descriptors.SerialDescriptor origin=null - CONSTRUCTOR GENERATED[kotlinx.rpc.codegen.RPCGeneratedRpcMethodClassKey] visibility:public <> (testData:<root>.TestData) returnType:<root>.BoxService.$rpcServiceStub.test1$rpcMethod [primary] - VALUE_PARAMETER GENERATED[kotlinx.rpc.codegen.RPCGeneratedRpcMethodClassKey] name:testData index:0 type:<root>.TestData + CONSTRUCTOR GENERATED[kotlinx.rpc.codegen.RpcGeneratedRpcMethodClassKey] visibility:public <> (testData:<root>.TestData) returnType:<root>.BoxService.$rpcServiceStub.test1$rpcMethod [primary] + VALUE_PARAMETER GENERATED[kotlinx.rpc.codegen.RpcGeneratedRpcMethodClassKey] name:testData index:0 type:<root>.TestData BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in kotlin.Any' - INSTANCE_INITIALIZER_CALL classDescriptor='CLASS GENERATED[kotlinx.rpc.codegen.RPCGeneratedRpcMethodClassKey] CLASS name:test1$rpcMethod modality:FINAL visibility:public superTypes:[kotlin.Any; kotlinx.rpc.internal.RpcMethodClass]' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS GENERATED[kotlinx.rpc.codegen.RpcGeneratedRpcMethodClassKey] CLASS name:test1$rpcMethod modality:FINAL visibility:public superTypes:[kotlin.Any; kotlinx.rpc.internal.RpcMethodClass]' CONSTRUCTOR KOTLINX_SERIALIZATION visibility:internal <> (seen0:kotlin.Int, testData:<root>.TestData?, serializationConstructorMarker:kotlinx.serialization.internal.SerializationConstructorMarker?) returnType:<root>.BoxService.$rpcServiceStub.test1$rpcMethod VALUE_PARAMETER KOTLINX_SERIALIZATION name:seen0 index:0 type:kotlin.Int VALUE_PARAMETER KOTLINX_SERIALIZATION name:testData index:1 type:<root>.TestData? @@ -805,7 +805,7 @@ FILE fqName:<root> fileName:/customParameterTypes.kt elements: VARARG type=kotlin.Array<kotlin.Any?> varargElementType=kotlin.Any? CALL 'public final fun <get-testData> (): <root>.TestData declared in <root>.BoxService.$rpcServiceStub.test1$rpcMethod' type=<root>.TestData origin=GET_PROPERTY $this: GET_VAR '<this>: <root>.BoxService.$rpcServiceStub.test1$rpcMethod declared in <root>.BoxService.$rpcServiceStub.test1$rpcMethod.asArray' type=<root>.BoxService.$rpcServiceStub.test1$rpcMethod origin=null - CLASS GENERATED[kotlinx.rpc.codegen.RPCGeneratedRpcMethodClassKey] CLASS name:test2$rpcMethod modality:FINAL visibility:public superTypes:[kotlin.Any; kotlinx.rpc.internal.RpcMethodClass] + CLASS GENERATED[kotlinx.rpc.codegen.RpcGeneratedRpcMethodClassKey] CLASS name:test2$rpcMethod modality:FINAL visibility:public superTypes:[kotlin.Any; kotlinx.rpc.internal.RpcMethodClass] annotations: Serializable(with = <null>) $this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.BoxService.$rpcServiceStub.test2$rpcMethod @@ -1012,11 +1012,11 @@ FILE fqName:<root> fileName:/customParameterTypes.kt CALL 'public abstract fun endStructure (descriptor: kotlinx.serialization.descriptors.SerialDescriptor): kotlin.Unit declared in kotlinx.serialization.encoding.CompositeEncoder' type=kotlin.Unit origin=null $this: GET_VAR 'val tmp_29: kotlinx.serialization.encoding.CompositeEncoder declared in <root>.BoxService.$rpcServiceStub.test2$rpcMethod.$serializer.serialize' type=kotlinx.serialization.encoding.CompositeEncoder origin=null descriptor: GET_VAR 'val tmp_28: kotlinx.serialization.descriptors.SerialDescriptor declared in <root>.BoxService.$rpcServiceStub.test2$rpcMethod.$serializer.serialize' type=kotlinx.serialization.descriptors.SerialDescriptor origin=null - CONSTRUCTOR GENERATED[kotlinx.rpc.codegen.RPCGeneratedRpcMethodClassKey] visibility:public <> (testData:<root>.TestData) returnType:<root>.BoxService.$rpcServiceStub.test2$rpcMethod [primary] - VALUE_PARAMETER GENERATED[kotlinx.rpc.codegen.RPCGeneratedRpcMethodClassKey] name:testData index:0 type:<root>.TestData + CONSTRUCTOR GENERATED[kotlinx.rpc.codegen.RpcGeneratedRpcMethodClassKey] visibility:public <> (testData:<root>.TestData) returnType:<root>.BoxService.$rpcServiceStub.test2$rpcMethod [primary] + VALUE_PARAMETER GENERATED[kotlinx.rpc.codegen.RpcGeneratedRpcMethodClassKey] name:testData index:0 type:<root>.TestData BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in kotlin.Any' - INSTANCE_INITIALIZER_CALL classDescriptor='CLASS GENERATED[kotlinx.rpc.codegen.RPCGeneratedRpcMethodClassKey] CLASS name:test2$rpcMethod modality:FINAL visibility:public superTypes:[kotlin.Any; kotlinx.rpc.internal.RpcMethodClass]' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS GENERATED[kotlinx.rpc.codegen.RpcGeneratedRpcMethodClassKey] CLASS name:test2$rpcMethod modality:FINAL visibility:public superTypes:[kotlin.Any; kotlinx.rpc.internal.RpcMethodClass]' CONSTRUCTOR KOTLINX_SERIALIZATION visibility:internal <> (seen0:kotlin.Int, testData:<root>.TestData?, serializationConstructorMarker:kotlinx.serialization.internal.SerializationConstructorMarker?) returnType:<root>.BoxService.$rpcServiceStub.test2$rpcMethod VALUE_PARAMETER KOTLINX_SERIALIZATION name:seen0 index:0 type:kotlin.Int VALUE_PARAMETER KOTLINX_SERIALIZATION name:testData index:1 type:<root>.TestData? @@ -1083,7 +1083,7 @@ FILE fqName:<root> fileName:/customParameterTypes.kt VALUE_PARAMETER name:__rpc_client index:1 type:kotlinx.rpc.RpcClient BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in kotlin.Any' - INSTANCE_INITIALIZER_CALL classDescriptor='CLASS GENERATED[kotlinx.rpc.codegen.RPCGeneratedStubKey] CLASS name:$rpcServiceStub modality:FINAL visibility:public superTypes:[<root>.BoxService]' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS GENERATED[kotlinx.rpc.codegen.RpcGeneratedStubKey] CLASS name:$rpcServiceStub modality:FINAL visibility:public superTypes:[<root>.BoxService]' FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] overridden: public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in <root>.BoxService diff --git a/tests/compiler-plugin-tests/src/testData/box/fields.fir.ir.txt b/tests/compiler-plugin-tests/src/testData/box/fields.fir.ir.txt index 91b5e43d..c5f815a6 100644 --- a/tests/compiler-plugin-tests/src/testData/box/fields.fir.ir.txt +++ b/tests/compiler-plugin-tests/src/testData/box/fields.fir.ir.txt @@ -3,7 +3,7 @@ FILE fqName:<root> fileName:/fields.kt annotations: Rpc $this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.BoxService - CLASS GENERATED[kotlinx.rpc.codegen.RPCGeneratedStubKey] CLASS name:$rpcServiceStub modality:FINAL visibility:public superTypes:[<root>.BoxService] + CLASS GENERATED[kotlinx.rpc.codegen.RpcGeneratedStubKey] CLASS name:$rpcServiceStub modality:FINAL visibility:public superTypes:[<root>.BoxService] $this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.BoxService.$rpcServiceStub PROPERTY name:__rpc_stub_id visibility:private modality:FINAL [val] FIELD PROPERTY_BACKING_FIELD name:__rpc_stub_id type:kotlin.Long visibility:private [final] @@ -336,7 +336,7 @@ FILE fqName:<root> fileName:/fields.kt VALUE_PARAMETER name:__rpc_client index:1 type:kotlinx.rpc.RpcClient BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in kotlin.Any' - INSTANCE_INITIALIZER_CALL classDescriptor='CLASS GENERATED[kotlinx.rpc.codegen.RPCGeneratedStubKey] CLASS name:$rpcServiceStub modality:FINAL visibility:public superTypes:[<root>.BoxService]' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS GENERATED[kotlinx.rpc.codegen.RpcGeneratedStubKey] CLASS name:$rpcServiceStub modality:FINAL visibility:public superTypes:[<root>.BoxService]' FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] overridden: public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in <root>.BoxService 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 df74a6bf..dccd0791 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 @@ -3,7 +3,7 @@ FILE fqName:<root> fileName:/flowParameter.kt annotations: Rpc $this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.BoxService - CLASS GENERATED[kotlinx.rpc.codegen.RPCGeneratedStubKey] CLASS name:$rpcServiceStub modality:FINAL visibility:public superTypes:[<root>.BoxService] + CLASS GENERATED[kotlinx.rpc.codegen.RpcGeneratedStubKey] CLASS name:$rpcServiceStub modality:FINAL visibility:public superTypes:[<root>.BoxService] $this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.BoxService.$rpcServiceStub PROPERTY name:__rpc_stub_id visibility:private modality:FINAL [val] FIELD PROPERTY_BACKING_FIELD name:__rpc_stub_id type:kotlin.Long visibility:private [final] @@ -173,7 +173,7 @@ FILE fqName:<root> fileName:/flowParameter.kt TYPE_OP type=kotlin.collections.List<kotlinx.rpc.internal.RpcDeferredField<*>> origin=CAST typeOperand=kotlin.collections.List<kotlinx.rpc.internal.RpcDeferredField<*>> CALL 'public final fun emptyList <T> (): kotlin.collections.List<T of kotlin.collections.emptyList> declared in kotlin.collections' type=kotlin.collections.List<kotlin.Any?> origin=null <T>: kotlin.Any? - CLASS GENERATED[kotlinx.rpc.codegen.RPCGeneratedRpcMethodClassKey] CLASS name:stream$rpcMethod modality:FINAL visibility:public superTypes:[kotlin.Any; kotlinx.rpc.internal.RpcMethodClass] + CLASS GENERATED[kotlinx.rpc.codegen.RpcGeneratedRpcMethodClassKey] CLASS name:stream$rpcMethod modality:FINAL visibility:public superTypes:[kotlin.Any; kotlinx.rpc.internal.RpcMethodClass] annotations: Serializable(with = <null>) $this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.BoxService.$rpcServiceStub.stream$rpcMethod @@ -413,11 +413,11 @@ FILE fqName:<root> fileName:/flowParameter.kt CALL 'public abstract fun endStructure (descriptor: kotlinx.serialization.descriptors.SerialDescriptor): kotlin.Unit declared in kotlinx.serialization.encoding.CompositeEncoder' type=kotlin.Unit origin=null $this: GET_VAR 'val tmp_11: kotlinx.serialization.encoding.CompositeEncoder declared in <root>.BoxService.$rpcServiceStub.stream$rpcMethod.$serializer.serialize' type=kotlinx.serialization.encoding.CompositeEncoder origin=null descriptor: GET_VAR 'val tmp_10: kotlinx.serialization.descriptors.SerialDescriptor declared in <root>.BoxService.$rpcServiceStub.stream$rpcMethod.$serializer.serialize' type=kotlinx.serialization.descriptors.SerialDescriptor origin=null - CONSTRUCTOR GENERATED[kotlinx.rpc.codegen.RPCGeneratedRpcMethodClassKey] visibility:public <> (flow:kotlinx.coroutines.flow.Flow<kotlin.String>) returnType:<root>.BoxService.$rpcServiceStub.stream$rpcMethod [primary] - VALUE_PARAMETER GENERATED[kotlinx.rpc.codegen.RPCGeneratedRpcMethodClassKey] name:flow index:0 type:kotlinx.coroutines.flow.Flow<kotlin.String> + CONSTRUCTOR GENERATED[kotlinx.rpc.codegen.RpcGeneratedRpcMethodClassKey] visibility:public <> (flow:kotlinx.coroutines.flow.Flow<kotlin.String>) returnType:<root>.BoxService.$rpcServiceStub.stream$rpcMethod [primary] + VALUE_PARAMETER GENERATED[kotlinx.rpc.codegen.RpcGeneratedRpcMethodClassKey] name:flow index:0 type:kotlinx.coroutines.flow.Flow<kotlin.String> BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in kotlin.Any' - INSTANCE_INITIALIZER_CALL classDescriptor='CLASS GENERATED[kotlinx.rpc.codegen.RPCGeneratedRpcMethodClassKey] CLASS name:stream$rpcMethod modality:FINAL visibility:public superTypes:[kotlin.Any; kotlinx.rpc.internal.RpcMethodClass]' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS GENERATED[kotlinx.rpc.codegen.RpcGeneratedRpcMethodClassKey] CLASS name:stream$rpcMethod modality:FINAL visibility:public superTypes:[kotlin.Any; kotlinx.rpc.internal.RpcMethodClass]' CONSTRUCTOR KOTLINX_SERIALIZATION visibility:internal <> (seen0:kotlin.Int, flow:kotlinx.coroutines.flow.Flow<kotlin.String>?, serializationConstructorMarker:kotlinx.serialization.internal.SerializationConstructorMarker?) returnType:<root>.BoxService.$rpcServiceStub.stream$rpcMethod VALUE_PARAMETER KOTLINX_SERIALIZATION name:seen0 index:0 type:kotlin.Int VALUE_PARAMETER KOTLINX_SERIALIZATION name:flow index:1 type:kotlinx.coroutines.flow.Flow<kotlin.String>? @@ -489,7 +489,7 @@ FILE fqName:<root> fileName:/flowParameter.kt VALUE_PARAMETER name:__rpc_client index:1 type:kotlinx.rpc.RpcClient BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in kotlin.Any' - INSTANCE_INITIALIZER_CALL classDescriptor='CLASS GENERATED[kotlinx.rpc.codegen.RPCGeneratedStubKey] CLASS name:$rpcServiceStub modality:FINAL visibility:public superTypes:[<root>.BoxService]' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS GENERATED[kotlinx.rpc.codegen.RpcGeneratedStubKey] CLASS name:$rpcServiceStub modality:FINAL visibility:public superTypes:[<root>.BoxService]' FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] overridden: public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in <root>.BoxService 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 a74628ac..66f3ab8d 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 @@ -4,7 +4,7 @@ FILE fqName:<root> fileName:/module_lib_multiModule.kt annotations: Rpc $this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.BoxService - CLASS GENERATED[kotlinx.rpc.codegen.RPCGeneratedStubKey] CLASS name:$rpcServiceStub modality:FINAL visibility:public superTypes:[<root>.BoxService] + CLASS GENERATED[kotlinx.rpc.codegen.RpcGeneratedStubKey] CLASS name:$rpcServiceStub modality:FINAL visibility:public superTypes:[<root>.BoxService] $this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.BoxService.$rpcServiceStub PROPERTY name:__rpc_stub_id visibility:private modality:FINAL [val] FIELD PROPERTY_BACKING_FIELD name:__rpc_stub_id type:kotlin.Long visibility:private [final] @@ -167,7 +167,7 @@ FILE fqName:<root> fileName:/module_lib_multiModule.kt TYPE_OP type=kotlin.collections.List<kotlinx.rpc.internal.RpcDeferredField<*>> origin=CAST typeOperand=kotlin.collections.List<kotlinx.rpc.internal.RpcDeferredField<*>> CALL 'public final fun emptyList <T> (): kotlin.collections.List<T of kotlin.collections.emptyList> declared in kotlin.collections' type=kotlin.collections.List<kotlin.Any?> origin=null <T>: kotlin.Any? - CLASS GENERATED[kotlinx.rpc.codegen.RPCGeneratedRpcMethodClassKey] OBJECT name:simple$rpcMethod modality:FINAL visibility:public superTypes:[kotlin.Any; kotlinx.rpc.internal.RpcMethodClass] + CLASS GENERATED[kotlinx.rpc.codegen.RpcGeneratedRpcMethodClassKey] OBJECT name:simple$rpcMethod modality:FINAL visibility:public superTypes:[kotlin.Any; kotlinx.rpc.internal.RpcMethodClass] annotations: Serializable(with = <null>) $this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.BoxService.$rpcServiceStub.simple$rpcMethod @@ -185,7 +185,7 @@ FILE fqName:<root> fileName:/module_lib_multiModule.kt CONSTRUCTOR_CALL 'internal constructor <init> (serialName: kotlin.String, objectInstance: T of kotlinx.serialization.internal.ObjectSerializer, classAnnotations: kotlin.Array<kotlin.Annotation>) declared in kotlinx.serialization.internal.ObjectSerializer' type=kotlinx.serialization.internal.ObjectSerializer<<root>.BoxService.$rpcServiceStub.simple$rpcMethod> origin=null <class: T>: <none> serialName: CONST String type=kotlin.String value="BoxService.$rpcServiceStub.simple$rpcMethod" - objectInstance: GET_OBJECT 'CLASS GENERATED[kotlinx.rpc.codegen.RPCGeneratedRpcMethodClassKey] OBJECT name:simple$rpcMethod modality:FINAL visibility:public superTypes:[kotlin.Any; kotlinx.rpc.internal.RpcMethodClass]' type=<root>.BoxService.$rpcServiceStub.simple$rpcMethod + objectInstance: GET_OBJECT 'CLASS GENERATED[kotlinx.rpc.codegen.RpcGeneratedRpcMethodClassKey] OBJECT name:simple$rpcMethod modality:FINAL visibility:public superTypes:[kotlin.Any; kotlinx.rpc.internal.RpcMethodClass]' type=<root>.BoxService.$rpcServiceStub.simple$rpcMethod classAnnotations: CALL 'public final fun arrayOf <T> (vararg elements: T of kotlin.arrayOf): kotlin.Array<T of kotlin.arrayOf> declared in kotlin' type=kotlin.Array<kotlin.Annotation> origin=null <T>: kotlin.Annotation elements: VARARG type=kotlin.Array<kotlin.Annotation> varargElementType=kotlin.Annotation @@ -199,10 +199,10 @@ FILE fqName:<root> fileName:/module_lib_multiModule.kt CALL 'public abstract fun <get-value> (): T of kotlin.Lazy declared in kotlin.Lazy' type=kotlinx.serialization.KSerializer<kotlin.Any> origin=null $this: GET_FIELD 'FIELD KOTLINX_SERIALIZATION name:$cachedSerializer$delegate type:kotlin.Lazy<kotlinx.serialization.KSerializer<kotlin.Any>> visibility:private [final] declared in <root>.BoxService.$rpcServiceStub.simple$rpcMethod' type=kotlin.Lazy<kotlinx.serialization.KSerializer<kotlin.Any>> origin=null receiver: GET_VAR '<this>: <root>.BoxService.$rpcServiceStub.simple$rpcMethod declared in <root>.BoxService.$rpcServiceStub.simple$rpcMethod.<get-$cachedSerializer>' type=<root>.BoxService.$rpcServiceStub.simple$rpcMethod origin=null - CONSTRUCTOR GENERATED[kotlinx.rpc.codegen.RPCGeneratedRpcMethodClassKey] visibility:private <> () returnType:<root>.BoxService.$rpcServiceStub.simple$rpcMethod [primary] + CONSTRUCTOR GENERATED[kotlinx.rpc.codegen.RpcGeneratedRpcMethodClassKey] visibility:private <> () returnType:<root>.BoxService.$rpcServiceStub.simple$rpcMethod [primary] BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in kotlin.Any' - INSTANCE_INITIALIZER_CALL classDescriptor='CLASS GENERATED[kotlinx.rpc.codegen.RPCGeneratedRpcMethodClassKey] OBJECT name:simple$rpcMethod modality:FINAL visibility:public superTypes:[kotlin.Any; kotlinx.rpc.internal.RpcMethodClass]' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS GENERATED[kotlinx.rpc.codegen.RpcGeneratedRpcMethodClassKey] OBJECT name:simple$rpcMethod modality:FINAL visibility:public superTypes:[kotlin.Any; kotlinx.rpc.internal.RpcMethodClass]' FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] overridden: public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any @@ -235,7 +235,7 @@ FILE fqName:<root> fileName:/module_lib_multiModule.kt VALUE_PARAMETER name:__rpc_client index:1 type:kotlinx.rpc.RpcClient BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in kotlin.Any' - INSTANCE_INITIALIZER_CALL classDescriptor='CLASS GENERATED[kotlinx.rpc.codegen.RPCGeneratedStubKey] CLASS name:$rpcServiceStub modality:FINAL visibility:public superTypes:[<root>.BoxService]' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS GENERATED[kotlinx.rpc.codegen.RpcGeneratedStubKey] CLASS name:$rpcServiceStub modality:FINAL visibility:public superTypes:[<root>.BoxService]' FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] overridden: public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in <root>.BoxService @@ -269,7 +269,7 @@ FILE fqName:<root> fileName:/module_lib_multiModule.kt call: CONSTRUCTOR_CALL 'public constructor <init> (descriptor: kotlinx.rpc.descriptor.RpcServiceDescriptor<*>, callableName: kotlin.String, data: kotlin.Any, serviceId: kotlin.Long) declared in kotlinx.rpc.RpcCall' type=kotlinx.rpc.RpcCall origin=null descriptor: GET_OBJECT 'CLASS GENERATED[kotlinx.rpc.codegen.FirRpcServiceStubCompanionObject] OBJECT name:Companion modality:FINAL visibility:public [companion] superTypes:[kotlinx.rpc.descriptor.RpcServiceDescriptor<<root>.BoxService>]' type=<root>.BoxService.$rpcServiceStub.Companion callableName: CONST String type=kotlin.String value="simple" - data: GET_OBJECT 'CLASS GENERATED[kotlinx.rpc.codegen.RPCGeneratedRpcMethodClassKey] OBJECT name:simple$rpcMethod modality:FINAL visibility:public superTypes:[kotlin.Any; kotlinx.rpc.internal.RpcMethodClass]' type=<root>.BoxService.$rpcServiceStub.simple$rpcMethod + data: GET_OBJECT 'CLASS GENERATED[kotlinx.rpc.codegen.RpcGeneratedRpcMethodClassKey] OBJECT name:simple$rpcMethod modality:FINAL visibility:public superTypes:[kotlin.Any; kotlinx.rpc.internal.RpcMethodClass]' type=<root>.BoxService.$rpcServiceStub.simple$rpcMethod serviceId: CALL 'private final fun <get-__rpc_stub_id> (): kotlin.Long declared in <root>.BoxService.$rpcServiceStub' type=kotlin.Long origin=GET_PROPERTY $this: GET_VAR '<this>: <root>.BoxService.$rpcServiceStub declared in <root>.BoxService.$rpcServiceStub.simple' type=<root>.BoxService.$rpcServiceStub origin=null FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] 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 85252e8d..24bf86fb 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 @@ -3,7 +3,7 @@ FILE fqName:<root> fileName:/simple.kt annotations: Rpc $this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.BoxService - CLASS GENERATED[kotlinx.rpc.codegen.RPCGeneratedStubKey] CLASS name:$rpcServiceStub modality:FINAL visibility:public superTypes:[<root>.BoxService] + CLASS GENERATED[kotlinx.rpc.codegen.RpcGeneratedStubKey] CLASS name:$rpcServiceStub modality:FINAL visibility:public superTypes:[<root>.BoxService] $this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.BoxService.$rpcServiceStub PROPERTY name:__rpc_stub_id visibility:private modality:FINAL [val] FIELD PROPERTY_BACKING_FIELD name:__rpc_stub_id type:kotlin.Long visibility:private [final] @@ -166,7 +166,7 @@ FILE fqName:<root> fileName:/simple.kt TYPE_OP type=kotlin.collections.List<kotlinx.rpc.internal.RpcDeferredField<*>> origin=CAST typeOperand=kotlin.collections.List<kotlinx.rpc.internal.RpcDeferredField<*>> CALL 'public final fun emptyList <T> (): kotlin.collections.List<T of kotlin.collections.emptyList> declared in kotlin.collections' type=kotlin.collections.List<kotlin.Any?> origin=null <T>: kotlin.Any? - CLASS GENERATED[kotlinx.rpc.codegen.RPCGeneratedRpcMethodClassKey] OBJECT name:simple$rpcMethod modality:FINAL visibility:public superTypes:[kotlin.Any; kotlinx.rpc.internal.RpcMethodClass] + CLASS GENERATED[kotlinx.rpc.codegen.RpcGeneratedRpcMethodClassKey] OBJECT name:simple$rpcMethod modality:FINAL visibility:public superTypes:[kotlin.Any; kotlinx.rpc.internal.RpcMethodClass] annotations: Serializable(with = <null>) $this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.BoxService.$rpcServiceStub.simple$rpcMethod @@ -184,7 +184,7 @@ FILE fqName:<root> fileName:/simple.kt CONSTRUCTOR_CALL 'internal constructor <init> (serialName: kotlin.String, objectInstance: T of kotlinx.serialization.internal.ObjectSerializer, classAnnotations: kotlin.Array<kotlin.Annotation>) declared in kotlinx.serialization.internal.ObjectSerializer' type=kotlinx.serialization.internal.ObjectSerializer<<root>.BoxService.$rpcServiceStub.simple$rpcMethod> origin=null <class: T>: <none> serialName: CONST String type=kotlin.String value="BoxService.$rpcServiceStub.simple$rpcMethod" - objectInstance: GET_OBJECT 'CLASS GENERATED[kotlinx.rpc.codegen.RPCGeneratedRpcMethodClassKey] OBJECT name:simple$rpcMethod modality:FINAL visibility:public superTypes:[kotlin.Any; kotlinx.rpc.internal.RpcMethodClass]' type=<root>.BoxService.$rpcServiceStub.simple$rpcMethod + objectInstance: GET_OBJECT 'CLASS GENERATED[kotlinx.rpc.codegen.RpcGeneratedRpcMethodClassKey] OBJECT name:simple$rpcMethod modality:FINAL visibility:public superTypes:[kotlin.Any; kotlinx.rpc.internal.RpcMethodClass]' type=<root>.BoxService.$rpcServiceStub.simple$rpcMethod classAnnotations: CALL 'public final fun arrayOf <T> (vararg elements: T of kotlin.arrayOf): kotlin.Array<T of kotlin.arrayOf> declared in kotlin' type=kotlin.Array<kotlin.Annotation> origin=null <T>: kotlin.Annotation elements: VARARG type=kotlin.Array<kotlin.Annotation> varargElementType=kotlin.Annotation @@ -198,10 +198,10 @@ FILE fqName:<root> fileName:/simple.kt CALL 'public abstract fun <get-value> (): T of kotlin.Lazy declared in kotlin.Lazy' type=kotlinx.serialization.KSerializer<kotlin.Any> origin=null $this: GET_FIELD 'FIELD KOTLINX_SERIALIZATION name:$cachedSerializer$delegate type:kotlin.Lazy<kotlinx.serialization.KSerializer<kotlin.Any>> visibility:private [final] declared in <root>.BoxService.$rpcServiceStub.simple$rpcMethod' type=kotlin.Lazy<kotlinx.serialization.KSerializer<kotlin.Any>> origin=null receiver: GET_VAR '<this>: <root>.BoxService.$rpcServiceStub.simple$rpcMethod declared in <root>.BoxService.$rpcServiceStub.simple$rpcMethod.<get-$cachedSerializer>' type=<root>.BoxService.$rpcServiceStub.simple$rpcMethod origin=null - CONSTRUCTOR GENERATED[kotlinx.rpc.codegen.RPCGeneratedRpcMethodClassKey] visibility:private <> () returnType:<root>.BoxService.$rpcServiceStub.simple$rpcMethod [primary] + CONSTRUCTOR GENERATED[kotlinx.rpc.codegen.RpcGeneratedRpcMethodClassKey] visibility:private <> () returnType:<root>.BoxService.$rpcServiceStub.simple$rpcMethod [primary] BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in kotlin.Any' - INSTANCE_INITIALIZER_CALL classDescriptor='CLASS GENERATED[kotlinx.rpc.codegen.RPCGeneratedRpcMethodClassKey] OBJECT name:simple$rpcMethod modality:FINAL visibility:public superTypes:[kotlin.Any; kotlinx.rpc.internal.RpcMethodClass]' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS GENERATED[kotlinx.rpc.codegen.RpcGeneratedRpcMethodClassKey] OBJECT name:simple$rpcMethod modality:FINAL visibility:public superTypes:[kotlin.Any; kotlinx.rpc.internal.RpcMethodClass]' FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] overridden: public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any @@ -234,7 +234,7 @@ FILE fqName:<root> fileName:/simple.kt VALUE_PARAMETER name:__rpc_client index:1 type:kotlinx.rpc.RpcClient BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in kotlin.Any' - INSTANCE_INITIALIZER_CALL classDescriptor='CLASS GENERATED[kotlinx.rpc.codegen.RPCGeneratedStubKey] CLASS name:$rpcServiceStub modality:FINAL visibility:public superTypes:[<root>.BoxService]' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS GENERATED[kotlinx.rpc.codegen.RpcGeneratedStubKey] CLASS name:$rpcServiceStub modality:FINAL visibility:public superTypes:[<root>.BoxService]' FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] overridden: public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in <root>.BoxService @@ -268,7 +268,7 @@ FILE fqName:<root> fileName:/simple.kt call: CONSTRUCTOR_CALL 'public constructor <init> (descriptor: kotlinx.rpc.descriptor.RpcServiceDescriptor<*>, callableName: kotlin.String, data: kotlin.Any, serviceId: kotlin.Long) declared in kotlinx.rpc.RpcCall' type=kotlinx.rpc.RpcCall origin=null descriptor: GET_OBJECT 'CLASS GENERATED[kotlinx.rpc.codegen.FirRpcServiceStubCompanionObject] OBJECT name:Companion modality:FINAL visibility:public [companion] superTypes:[kotlinx.rpc.descriptor.RpcServiceDescriptor<<root>.BoxService>]' type=<root>.BoxService.$rpcServiceStub.Companion callableName: CONST String type=kotlin.String value="simple" - data: GET_OBJECT 'CLASS GENERATED[kotlinx.rpc.codegen.RPCGeneratedRpcMethodClassKey] OBJECT name:simple$rpcMethod modality:FINAL visibility:public superTypes:[kotlin.Any; kotlinx.rpc.internal.RpcMethodClass]' type=<root>.BoxService.$rpcServiceStub.simple$rpcMethod + data: GET_OBJECT 'CLASS GENERATED[kotlinx.rpc.codegen.RpcGeneratedRpcMethodClassKey] OBJECT name:simple$rpcMethod modality:FINAL visibility:public superTypes:[kotlin.Any; kotlinx.rpc.internal.RpcMethodClass]' type=<root>.BoxService.$rpcServiceStub.simple$rpcMethod serviceId: CALL 'private final fun <get-__rpc_stub_id> (): kotlin.Long declared in <root>.BoxService.$rpcServiceStub' type=kotlin.Long origin=GET_PROPERTY $this: GET_VAR '<this>: <root>.BoxService.$rpcServiceStub declared in <root>.BoxService.$rpcServiceStub.simple' type=<root>.BoxService.$rpcServiceStub origin=null FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] diff --git a/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/ExperimentalRPCApi.kt b/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/ExperimentalRpcApi.kt similarity index 87% rename from utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/ExperimentalRPCApi.kt rename to utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/ExperimentalRpcApi.kt index 578d8745..86c7419e 100644 --- a/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/ExperimentalRPCApi.kt +++ b/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/ExperimentalRpcApi.kt @@ -8,4 +8,4 @@ package kotlinx.rpc.internal.utils message = "This API is experimental and can be changed or removed at any time.", level = RequiresOptIn.Level.ERROR, ) -public annotation class ExperimentalRPCApi +public annotation class ExperimentalRpcApi diff --git a/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/InternalRPCApi.kt b/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/InternalRpcApi.kt similarity index 85% rename from utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/InternalRPCApi.kt rename to utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/InternalRpcApi.kt index e346c936..c030f237 100644 --- a/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/InternalRPCApi.kt +++ b/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/InternalRpcApi.kt @@ -8,5 +8,5 @@ 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 +@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/ShortEnumKSerializer.kt index 7cd0f22b..caaa6c14 100644 --- a/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/ShortEnumKSerializer.kt +++ b/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/ShortEnumKSerializer.kt @@ -15,7 +15,7 @@ import kotlin.reflect.KClass /** * Better unique value holder than ordinal. Easier for testing and maintaining. */ -@InternalRPCApi +@InternalRpcApi interface IndexedEnum { /** * Values between 0 and 65500 are allowed, other are reserved for testing. @@ -23,7 +23,7 @@ interface IndexedEnum { val uniqueIndex: Int } -@InternalRPCApi +@InternalRpcApi abstract class ShortEnumKSerializer<E>( kClass: KClass<E>, val unknownValue: E, diff --git a/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/SupervisedCompletableDeferred.kt b/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/SupervisedCompletableDeferred.kt index c8e96e6b..51e83a6c 100644 --- a/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/SupervisedCompletableDeferred.kt +++ b/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/SupervisedCompletableDeferred.kt @@ -12,7 +12,7 @@ import kotlinx.coroutines.job /** * Cancels when parent is canceled, but not otherwise */ -@InternalRPCApi +@InternalRpcApi class SupervisedCompletableDeferred<T>(parent: Job) : CompletableDeferred<T> by CompletableDeferred() { init { val handle = parent.invokeOnCompletion { cause -> @@ -27,7 +27,7 @@ class SupervisedCompletableDeferred<T>(parent: Job) : CompletableDeferred<T> by } } -@InternalRPCApi +@InternalRpcApi suspend fun <T> SupervisedCompletableDeferred(): SupervisedCompletableDeferred<T> { return SupervisedCompletableDeferred(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 26b0ee7a..80fef37c 100644 --- a/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/deferredUtil.kt +++ b/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/deferredUtil.kt @@ -8,16 +8,16 @@ import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.rpc.internal.utils.map.ConcurrentHashMap -@InternalRPCApi +@InternalRpcApi fun <K : Any, V> ConcurrentHashMap<K, CompletableDeferred<V>>.getDeferred(key: K): CompletableDeferred<V> { return computeIfAbsent(key) { CompletableDeferred() } } -@InternalRPCApi +@InternalRpcApi operator fun <K : Any, V> ConcurrentHashMap<K, CompletableDeferred<V>>.set(key: K, value: V) { getDeferred(key).complete(value) } -@InternalRPCApi +@InternalRpcApi @OptIn(ExperimentalCoroutinesApi::class) fun <T> CompletableDeferred<T>?.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 fc23ed68..67568b6e 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 @@ -4,10 +4,10 @@ package kotlinx.rpc.internal.utils.hex -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi @OptIn(ExperimentalStdlibApi::class) -@InternalRPCApi +@InternalRpcApi fun String.hexToReadableBinary(): String { return hexToByteArray().joinToString("") { byte -> byte.toInt().toChar().display() 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 index 28c23265..b22c758a 100644 --- a/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/map/ConcurrentHashMap.kt +++ b/utils/src/commonMain/kotlin/kotlinx/rpc/internal/utils/map/ConcurrentHashMap.kt @@ -4,9 +4,9 @@ package kotlinx.rpc.internal.utils.map -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi -@InternalRPCApi +@InternalRpcApi interface ConcurrentHashMap<K : Any, V : Any> { fun put(key: K, value: V): V? @@ -36,5 +36,5 @@ interface ConcurrentHashMap<K : Any, V : Any> { ) } -@InternalRPCApi +@InternalRpcApi expect fun <K : Any, V : Any> ConcurrentHashMap(initialSize: Int = 32): ConcurrentHashMap<K, V> 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 0a01e1ce..7de0eaee 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 @@ -4,9 +4,9 @@ package kotlinx.rpc.internal.utils.map -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi -@InternalRPCApi +@InternalRpcApi actual fun <K : Any, V : Any> ConcurrentHashMap(initialSize: Int): ConcurrentHashMap<K, V> { 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 90641065..c3222fe9 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 @@ -4,9 +4,9 @@ package kotlinx.rpc.internal.utils.map -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi -@InternalRPCApi +@InternalRpcApi actual fun <K : Any, V : Any> ConcurrentHashMap(initialSize: Int): ConcurrentHashMap<K, V> { return ConcurrentHashMapJvm(initialSize) } 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 0a01e1ce..7de0eaee 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 @@ -4,9 +4,9 @@ package kotlinx.rpc.internal.utils.map -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi -@InternalRPCApi +@InternalRpcApi actual fun <K : Any, V : Any> ConcurrentHashMap(initialSize: Int): ConcurrentHashMap<K, V> { 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 0a01e1ce..7de0eaee 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 @@ -4,9 +4,9 @@ package kotlinx.rpc.internal.utils.map -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi -@InternalRPCApi +@InternalRpcApi actual fun <K : Any, V : Any> ConcurrentHashMap(initialSize: Int): ConcurrentHashMap<K, V> { 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 0a01e1ce..7de0eaee 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 @@ -4,9 +4,9 @@ package kotlinx.rpc.internal.utils.map -import kotlinx.rpc.internal.utils.InternalRPCApi +import kotlinx.rpc.internal.utils.InternalRpcApi -@InternalRPCApi +@InternalRpcApi actual fun <K : Any, V : Any> ConcurrentHashMap(initialSize: Int): ConcurrentHashMap<K, V> { return SynchronizedHashMap() }