Class Plugin
Represents a WASM Extism plugin.
public class Plugin : IDisposable
- Inheritance
-
Plugin
- Implements
- Inherited Members
Constructors
Plugin(Manifest, HostFunction[], PluginIntializationOptions)
Initialize a plugin from a Manifest.
public Plugin(Manifest manifest, HostFunction[] functions, PluginIntializationOptions options)
Parameters
manifest
Manifestfunctions
HostFunction[]options
PluginIntializationOptions
Plugin(Manifest, HostFunction[], bool)
Create a plugin from a Manifest.
public Plugin(Manifest manifest, HostFunction[] functions, bool withWasi)
Parameters
manifest
Manifestfunctions
HostFunction[]withWasi
bool
Plugin(ReadOnlySpan<byte>, HostFunction[], bool)
Create and load a plugin from a byte array.
public Plugin(ReadOnlySpan<byte> wasm, HostFunction[] functions, bool withWasi)
Parameters
wasm
ReadOnlySpan<byte>A WASM module (wat or wasm) or a JSON encoded manifest.
functions
HostFunction[]List of host functions expected by the plugin.
withWasi
boolEnable/Disable WASI.
Properties
Id
Get the plugin's ID.
public Guid Id { get; }
Property Value
Methods
AllowHttpResponseHeaders()
Enable HTTP response headers in plugins using extism:host/env::http_request
public void AllowHttpResponseHeaders()
Call(string, ReadOnlySpan<byte>, CancellationToken?)
Calls a function in the current plugin and returns the output as a byte buffer.
public ReadOnlySpan<byte> Call(string functionName, ReadOnlySpan<byte> input, CancellationToken? cancellationToken = null)
Parameters
functionName
stringName of the function in the plugin to invoke.
input
ReadOnlySpan<byte>A buffer to provide as input to the function.
cancellationToken
CancellationToken?CancellationToken used for cancelling the Extism call.
Returns
- ReadOnlySpan<byte>
The output of the function call
Exceptions
Call(string, string, CancellationToken?)
Calls a function in the current plugin and returns the output as a UTF8 encoded string.
public string Call(string functionName, string input, CancellationToken? cancellationToken = null)
Parameters
functionName
stringName of the function in the plugin to invoke.
input
stringA string that will be UTF8 encoded and passed to the plugin.
cancellationToken
CancellationToken?CancellationToken used for cancelling the Extism call.
Returns
- string
The output of the function as a UTF8 encoded string
CallWithHostContext<T>(string, ReadOnlySpan<byte>, T, CancellationToken?)
Calls a function in the current plugin and returns the output as a byte buffer.
public ReadOnlySpan<byte> CallWithHostContext<T>(string functionName, ReadOnlySpan<byte> input, T hostContext, CancellationToken? cancellationToken = null)
Parameters
functionName
stringName of the function in the plugin to invoke.
input
ReadOnlySpan<byte>A buffer to provide as input to the function.
hostContext
TAn object that will be passed back to HostFunctions
cancellationToken
CancellationToken?CancellationToken used for cancelling the Extism call.
Returns
- ReadOnlySpan<byte>
The output of the function call
Type Parameters
T
Exceptions
Call<TOutput>(string, string, JsonSerializerOptions?, CancellationToken?)
Calls a function on the plugin and deserializes the output as UTF8 encoded JSON.
public TOutput? Call<TOutput>(string functionName, string input, JsonSerializerOptions? serializerOptions = null, CancellationToken? cancellationToken = null)
Parameters
functionName
stringName of the function in the plugin to invoke.
input
stringFunction input.
serializerOptions
JsonSerializerOptionsJSON serialization options used for serialization/derserialization.
cancellationToken
CancellationToken?CancellationToken used for cancelling the Extism call.
Returns
- TOutput
Type Parameters
TOutput
Type of the output payload returned by the function.
Call<TOutput>(string, string, JsonTypeInfo<TOutput?>, CancellationToken?)
Calls a function on the plugin with a payload. The payload is serialized into JSON and encoded in UTF8.
public TOutput? Call<TOutput>(string functionName, string input, JsonTypeInfo<TOutput?> outputJsonInfo, CancellationToken? cancellationToken = null)
Parameters
functionName
stringName of the function in the plugin to invoke.
input
stringFunction input.
outputJsonInfo
JsonTypeInfo<TOutput>Metadata about output type.
cancellationToken
CancellationToken?CancellationToken used for cancelling the Extism call.
Returns
- TOutput
Type Parameters
TOutput
Type of the output payload returned by the function.
Call<TInput, TOutput>(string, TInput, JsonSerializerOptions?, CancellationToken?)
Calls a function on the plugin with a payload. The payload is serialized into JSON and encoded in UTF8.
public TOutput? Call<TInput, TOutput>(string functionName, TInput input, JsonSerializerOptions? serializerOptions = null, CancellationToken? cancellationToken = null)
Parameters
functionName
stringName of the function in the plugin to invoke.
input
TInputAn object that will be serialized into JSON and passed into the function as a UTF8 encoded string.
serializerOptions
JsonSerializerOptionsJSON serialization options used for serialization/derserialization
cancellationToken
CancellationToken?CancellationToken used for cancelling the Extism call.
Returns
- TOutput
Type Parameters
TInput
Type of the input payload.
TOutput
Type of the output payload returned by the function.
Call<TInput, TOutput>(string, TInput, JsonTypeInfo<TInput>, JsonTypeInfo<TOutput?>, CancellationToken?)
Calls a function on the plugin with a payload. The payload is serialized into JSON and encoded in UTF8.
public TOutput? Call<TInput, TOutput>(string functionName, TInput input, JsonTypeInfo<TInput> inputJsonInfo, JsonTypeInfo<TOutput?> outputJsonInfo, CancellationToken? cancellationToken = null)
Parameters
functionName
stringName of the function in the plugin to invoke.
input
TInputAn object that will be serialized into JSON and passed into the function as a UTF8 encoded string.
inputJsonInfo
JsonTypeInfo<TInput>Metadata about input type.
outputJsonInfo
JsonTypeInfo<TOutput>Metadata about output type.
cancellationToken
CancellationToken?CancellationToken used for cancelling the Extism call.
Returns
- TOutput
Type Parameters
TInput
Type of the input payload.
TOutput
Type of the output payload returned by the function.
CheckNotDisposed()
Throw an appropriate exception if the plugin has been disposed.
protected void CheckNotDisposed()
Exceptions
ConfigureCustomLogging(LogLevel)
Enable a custom log handler, this will buffer logs until DrainCustomLogs(LoggingSink) is called.
public static void ConfigureCustomLogging(LogLevel level)
Parameters
level
LogLevel
ConfigureFileLogging(string, LogLevel)
Set log file and level
public static void ConfigureFileLogging(string path, LogLevel level)
Parameters
Dispose()
Frees all resources held by this Plugin.
public void Dispose()
Dispose(bool)
Frees all resources held by this Plugin.
protected virtual void Dispose(bool disposing)
Parameters
disposing
bool
DrainCustomLogs(LoggingSink)
Calls the provided callback function for each buffered log line. This only needed when ConfigureCustomLogging(LogLevel) is used.
public static void DrainCustomLogs(LoggingSink callback)
Parameters
callback
LoggingSink
ExtismVersion()
Get Extism Runtime version.
public static string ExtismVersion()
Returns
~Plugin()
Destructs the current Plugin and frees all resources used by it.
protected ~Plugin()
FunctionExists(string)
Checks if a specific function exists in the current plugin.
public bool FunctionExists(string name)
Parameters
name
string
Returns
Reset()
Reset the Extism runtime, this will invalidate all allocated memory
public bool Reset()
Returns
UpdateConfig(Dictionary<string, string>, JsonSerializerOptions)
Update plugin config values, this will merge with the existing values.
public bool UpdateConfig(Dictionary<string, string> value, JsonSerializerOptions serializerOptions)
Parameters
value
Dictionary<string, string>serializerOptions
JsonSerializerOptions
Returns
UpdateConfig(ReadOnlySpan<byte>)
Update plugin config values, this will merge with the existing values.
public bool UpdateConfig(ReadOnlySpan<byte> json)
Parameters
json
ReadOnlySpan<byte>The configuration JSON encoded in UTF8.