All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.io.polywrap.plugin.PluginWrapper.kt Maven / Gradle / Ivy

There is a newer version: 0.10.4
Show newest version
package io.polywrap.plugin

import io.polywrap.core.Invoker
import io.polywrap.core.Wrapper
import kotlinx.coroutines.runBlocking
import uniffi.polywrap_native.FfiInvoker

/**
 * Represents a plugin wrapper, allowing the plugin module to be invoked as a [Wrapper].
 *
 * @param TConfig The type of the configuration object used by the plugin module.
 * @property module The plugin module instance associated with the wrapper.
 */
@OptIn(ExperimentalUnsignedTypes::class)
data class PluginWrapper(val module: PluginModule) : Wrapper {

    override fun invoke(
        method: String,
        args: List?,
        env: List?,
        invoker: FfiInvoker
    ): List = this.invoke(
        method = method,
        args = args?.toUByteArray()?.asByteArray(),
        env = env?.toUByteArray()?.asByteArray(),
        invoker = Invoker(invoker)
    ).getOrThrow().asUByteArray().toList()

    override fun invoke(
        method: String,
        args: ByteArray?,
        env: ByteArray?,
        invoker: Invoker
    ): Result = runCatching {
        return runBlocking { module.wrapInvoke(method, args, env, invoker) }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy