bufwasm

package
v1.23.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 30, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const CustomSectionName = ".bufplugin"

CustomSectionName is the name of the custom wasm section we look into for buf extensions.

Variables

This section is empty.

Functions

func EncodeBufSection

func EncodeBufSection(config *wasmpluginv1.ExecConfig) ([]byte, error)

EncodeBufSection encodes the ExecConfig message as a custom wasm section. The resulting bytes can be appended to any valid wasm file to add the new section to that file.

Types

type CompiledPlugin

type CompiledPlugin struct {

	// Metadata parsed from custom sections of the wasm file. May be nil if
	// no buf specific sections were found.
	ExecConfig *wasmpluginv1.ExecConfig
	// contains filtered or unexported fields
}

CompiledPlugin is the compiled representation of loading wasm bytes.

func (*CompiledPlugin) ABI

func (*CompiledPlugin) Close added in v1.17.0

func (c *CompiledPlugin) Close() error

type PluginExecutionError

type PluginExecutionError struct {
	Stderr   string
	Exitcode uint32
}

PluginExecutionError is a wrapper for WASM plugin execution errors.

func NewPluginExecutionError

func NewPluginExecutionError(stderr string, exitcode uint32) *PluginExecutionError

NewPluginExecutionError constructs a new execution error.

func (*PluginExecutionError) Error

func (e *PluginExecutionError) Error() string

type PluginExecutor

type PluginExecutor interface {
	CompilePlugin(ctx context.Context, plugin []byte) (_ *CompiledPlugin, retErr error)
	Run(ctx context.Context, plugin *CompiledPlugin, stdin io.Reader, stdout io.Writer) (retErr error)
}

PluginExecutor wraps a wazero end exposes functions to compile and run wasm plugins.

type PluginExecutorOption

type PluginExecutorOption func(*WASMPluginExecutor)

PluginExecutorOption configuration options for the PluginExecutor.

func WithMemoryLimitPages

func WithMemoryLimitPages(memoryLimitPages uint32) PluginExecutorOption

WithMemoryLimitPages provides a custom per memory limit for a plugin executor. The default is 8192 pages for 512MB.

type WASMPluginExecutor

type WASMPluginExecutor struct {
	// contains filtered or unexported fields
}

func NewPluginExecutor

func NewPluginExecutor(compilationCacheDir string, options ...PluginExecutorOption) (*WASMPluginExecutor, error)

NewPluginExecutor creates a new pluginExecutor with a compilation cache dir and other buf defaults.

func (*WASMPluginExecutor) CompilePlugin

func (e *WASMPluginExecutor) CompilePlugin(ctx context.Context, plugin []byte) (_ *CompiledPlugin, retErr error)

CompilePlugin takes a byte slice with a valid wasm module, compiles it and optionally reads out buf plugin metadata.

func (*WASMPluginExecutor) Run

func (e *WASMPluginExecutor) Run(
	ctx context.Context,
	plugin *CompiledPlugin,
	stdin io.Reader,
	stdout io.Writer,
) (retErr error)

Run executes a plugin. If the plugin exited with non-zero status, this returns a *PluginExecutionError.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL