Class Pdk
- Namespace
- Extism
- Assembly
- Extism.Pdk.dll
Provides interop functions for communication between guests and the host.
public static class Pdk
- Inheritance
-
Pdk
- Inherited Members
Methods
Allocate(ReadOnlySpan<byte>)
Allocate a byte buffer into memory.
public static MemoryBlock Allocate(ReadOnlySpan<byte> buffer)
Parameters
bufferReadOnlySpan<byte>The byte buffer to allocate into memory.
Returns
- MemoryBlock
A MemoryBlock instance representing the allocated memory.
Allocate(string)
Encodes a string as UTF-8 and stores it in memory.
public static MemoryBlock Allocate(string data)
Parameters
datastringThe string to allocate into memory.
Returns
- MemoryBlock
A MemoryBlock instance representing the allocated memory.
Allocate(ulong)
Allocate a block of memory with the specified length.
public static MemoryBlock Allocate(ulong length)
Parameters
lengthulongThe size of the memory block in bytes.
Returns
- MemoryBlock
A MemoryBlock instance representing the allocated memory.
GetInput()
Read the input data sent by the host.
public static byte[] GetInput()
Returns
- byte[]
The input data as a byte array.
GetInputJson<T>(JsonTypeInfo<T>)
Read the input data sent by the host as a UTF-8 encoded string and then deserialize it as JSON.
public static T? GetInputJson<T>(JsonTypeInfo<T> typeInfo)
Parameters
typeInfoJsonTypeInfo<T>
Returns
- T
Type Parameters
T
GetInputString()
Read the input data sent by the host as a UTF-8 encoded string.
public static string GetInputString()
Returns
Log(LogLevel, MemoryBlock)
Log a message with the specified log level to the host.
public static void Log(LogLevel level, MemoryBlock block)
Parameters
levelLogLevelThe log level for the message.
blockMemoryBlockThe memory block containing the log message.
Log(LogLevel, string)
Logs a message to the host.
public static void Log(LogLevel level, string message)
Parameters
RemoveVar(string)
Remove a variable from host memory.
public static void RemoveVar(string key)
Parameters
keystringThe key of the variable to remove.
SendRequest(HttpRequest)
Send an HTTP request synchronously and get the response from the host.
public static HttpResponse SendRequest(HttpRequest request)
Parameters
requestHttpRequestThe HTTP request to send.
Returns
- HttpResponse
The HTTP response received from the host. The plugin takes ownership of the memory block and is expected to free it.
SetError(string)
Set plugin error
public static void SetError(string errorMessage)
Parameters
errorMessagestring
SetOutput(MemoryBlock)
Set the output data to be sent back to the host.
public static void SetOutput(MemoryBlock block)
Parameters
blockMemoryBlockThe memory block containing the output data.
SetOutput(ReadOnlySpan<byte>)
Set the output data to be sent back to the host as a byte buffer.
public static void SetOutput(ReadOnlySpan<byte> data)
Parameters
dataReadOnlySpan<byte>The byte buffer to set as output data.
SetOutput(string)
Set the output data to be sent back to the host as a UTF-8 encoded string.
public static void SetOutput(string data)
Parameters
datastringThe UTF-8 encoded string to set as output data.
SetOutputJson<T>(T, JsonTypeInfo<T>)
Serialize the output data as JSON to be sent back to the host as a UTF-8 encoded string.
public static void SetOutputJson<T>(T output, JsonTypeInfo<T> typeInfo)
Parameters
outputTtypeInfoJsonTypeInfo<T>
Type Parameters
T
SetVar(string, MemoryBlock)
Set a var that will be persisted by the host.
public static void SetVar(string key, MemoryBlock value)
Parameters
keystringvalueMemoryBlock
SetVar(string, ReadOnlySpan<byte>)
Set a variable value persisted by the host.
public static void SetVar(string key, ReadOnlySpan<byte> bytes)
Parameters
keystringThe key for the persisted variable.
bytesReadOnlySpan<byte>The byte buffer to set as the variable value.
SetVar(string, string)
Set a variable value persisted by the host.
public static void SetVar(string key, string value)
Parameters
keystringThe key for the persisted variable.
valuestringA string value that will be UTF8 encoded.
TryGetConfig(string, out string)
Try to get a configuration value from the host.
public static bool TryGetConfig(string key, out string value)
Parameters
keystringThe key for the configuration value.
valuestringThe retrieved configuration value as a string.
Returns
- bool
True if the configuration value was retrieved successfully; otherwise, false.
TryGetVar(string, out MemoryBlock)
Read a var that's persisted by the host. See SetVar(string, MemoryBlock)
public static bool TryGetVar(string key, out MemoryBlock block)
Parameters
keystringThe variable name.
blockMemoryBlockThe value of the variable. The plugin should take ownership of the block and free it after reading the data.
Returns
- bool
true if the variable is found, false otherwise.