Table of Contents

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 string

The 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 ulong

The 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

string

Log(LogLevel, MemoryBlock)

Log a message with the specified log level to the host.

public static void Log(LogLevel level, MemoryBlock block)

Parameters

level LogLevel

The log level for the message.

block MemoryBlock

The memory block containing the log message.

Log(LogLevel, string)

Logs a message to the host.

public static void Log(LogLevel level, string message)

Parameters

level LogLevel
message string

RemoveVar(string)

Remove a variable from host memory.

public static void RemoveVar(string key)

Parameters

key string

The 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 HttpRequest

The 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 MemoryBlock

The 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 string

The 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 T
typeInfo 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 string
value MemoryBlock

SetVar(string, ReadOnlySpan<byte>)

Set a variable value persisted by the host.

public static void SetVar(string key, ReadOnlySpan<byte> bytes)

Parameters

key string

The 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 string

The key for the persisted variable.

value string

A 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 string

The key for the configuration value.

value string

The 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 string

The log level for the message.

block MemoryBlock

The log message as a string.

Returns

bool