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
buffer
ReadOnlySpan<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
data
stringThe 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
length
ulongThe 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
typeInfo
JsonTypeInfo<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
level
LogLevelThe log level for the message.
block
MemoryBlockThe 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
key
stringThe 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
request
HttpRequestThe HTTP request to send.
Returns
- HttpResponse
The HTTP response received from the host.
SetError(string)
Set plugin error
public static void SetError(string errorMessage)
Parameters
errorMessage
string
SetOutput(MemoryBlock)
Set the output data to be sent back to the host.
public static void SetOutput(MemoryBlock block)
Parameters
block
MemoryBlockThe 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
data
ReadOnlySpan<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
data
stringThe 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
output
TtypeInfo
JsonTypeInfo<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
key
stringvalue
MemoryBlock
SetVar(string, ReadOnlySpan<byte>)
Set a variable value persisted by the host.
public static void SetVar(string key, ReadOnlySpan<byte> bytes)
Parameters
key
stringThe key for the persisted variable.
bytes
ReadOnlySpan<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
key
stringThe key for the persisted variable.
value
stringA 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
key
stringThe key for the configuration value.
value
stringThe retrieved configuration value as a string.
Returns
- bool
True if the configuration value was retrieved successfully; otherwise, false.
TryGetVar(string, out MemoryBlock)
Log a message with the specified log level to the host.
public static bool TryGetVar(string key, out MemoryBlock block)
Parameters
key
stringThe log level for the message.
block
MemoryBlockThe log message as a string.