sdk

package module
Version: v0.0.0-...-dd4f625 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

README

LensVM Go SDK

The Go SDK for LensVM, enables developers to write LensVM Modules in Go, which are compiled to WASM and can be run on any LensVM Host runtime.

Currently this repo only contains an example of how to use the SDK as a point of reference for the design of the SDK implementation.

lens-vm-go-sdk is powered by TinyGo, and compiles to the WASI interface specifically.

Design

The SDK is consumed by the users implementing the ModuleContext interface. Then the SDK wraps up the implementation and hooks it into the correct WASM exports so its compliant with the LensVM ABI.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exec

func Exec(contextID ContextID, forward bool, argBuffer *byte, argSize int32, dataBuffer *byte, dataSize int32) types.Status

func GetInputArgBuffer

func GetInputArgBuffer(start, maxsize int32) ([]byte, error)

func GetInputDataBuffer

func GetInputDataBuffer(start, maxsize int32) ([]byte, error)

func GetTempArgBuffer

func GetTempArgBuffer(start, maxsize int32) ([]byte, error)

func GetTempDataBuffer

func GetTempDataBuffer(start, maxsize int32) ([]byte, error)

func RawBytePtrToByteSlice

func RawBytePtrToByteSlice(raw *byte, size int32) []byte

RawBytePtrToByteSlice takes a pointer and a size argument and returns a byte slice Note: It uses the TinyGo internal representation of a Byte slice (https://tinygo.org/compiler-internals/datatypes/)

func RegisterContext

func RegisterContext(contextID ContextID, module ModuleContext) error

func SetOutputPatchBuffer

func SetOutputPatchBuffer(patch []byte) error

func SetTempArgBuffer

func SetTempArgBuffer(buf []byte) error

func SetTempDataBuffer

func SetTempDataBuffer(buf []byte) error

Types

type ContextID

type ContextID int32

type Data

type Data interface {
	Get(keys ...string) (interface{}, bool)

	GetObject(keys ...string) (Data, bool)
	MustGetObject(keys ...string) Data

	GetArray(keys ...string) (DataArray, bool)
	MustGetArray(keys ...string) DataArray

	GetString(keys ...string) (string, bool)
	MustGetString(keys ...string) string

	GetInt32(keys ...string) (int32, bool)
	MustGetInt32(keys ...string) int32

	GetFloat32(keys ...string) (float32, bool)
	MustGetFloat32(keys ...string) float32

	Merge(Patch) Data
}

func DataFrom

func DataFrom(d map[string]interface{}) Data

type DataArray

type DataArray []Data

type DefaultModuleContext

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

func (*DefaultModuleContext) GetImport

func (ctx *DefaultModuleContext) GetImport(name string) (ImportedModuleContext, error)

Get the function handler for a named import. Any import accessed through this function must be defined in the Imports() method.

func (*DefaultModuleContext) Imports

func (ctx *DefaultModuleContext) Imports() []string

Imports returns a list of modules to import.

func (*DefaultModuleContext) Init

func (ctx *DefaultModuleContext) Init()

func (*DefaultModuleContext) Name

func (ctx *DefaultModuleContext) Name() string

Name returns the name of the lens module

func (*DefaultModuleContext) OnContextCreate

func (ctx *DefaultModuleContext) OnContextCreate()

OnContextCreate implements the Module ABI lifecycle

func (*DefaultModuleContext) ResolveImports

func (ctx *DefaultModuleContext) ResolveImports() []Import

ResolveImports links the import name to the WASM import function

func (*DefaultModuleContext) Run

func (ctx *DefaultModuleContext) Run(forward bool, args Data, data Data) (Data, error)

Run is responsible for parsing arguments and executing the actual lens transformation function.

type DefaultWrappedContext

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

func NewWrappedContext

func NewWrappedContext(ctx ModuleContext) *DefaultWrappedContext

func (*DefaultWrappedContext) Init

func (ctx *DefaultWrappedContext) Init()

type ExecFn

type ExecFn = func(ContextID, bool, *byte, int32, *byte, int32) types.Status

ExecFn matches the named exec func ABI: lensvm_exec_<name>

type Import

type Import struct {
	ExecFn ExecFn
	// contains filtered or unexported fields
}

func NewImport

func NewImport(name string, fn ...ExecFn) Import

type ImportedModuleContext

type ImportedModuleContext interface {
	Run(forward bool, args Data, data Data) (Patch, error)
}

type ModuleContext

type ModuleContext interface {
	Init()

	// Name returns the name of the lens module
	Name() string

	// OnContextCreate is called when a new module context is created
	OnContextCreate()

	// ResolveImports dynamically links the import name
	// to the imported WASM module function.
	// This function should be autogenerated
	// See github.com/lens-vm/lens-vm-go-sdk#GeneratedImportResolver
	ResolveImports() []Import

	// Imports returns a list of modules to import.
	// Any imports returned here must also be defined in the
	// module file import section
	// (https://github.com/lens-vm/spec#module-file-modulejsonyaml).
	// Additionally, we rely on the module file for the version
	// info, so the runtime can resolve the correct version and
	// dynamically link it into the module.
	Imports() []string

	// Get the function handler for a named import.
	// Any import accessed through this function must be defined
	// in the Imports() method.
	GetImport(string) (ImportedModuleContext, error)

	// Run is responsible for parsing arguments and executing
	// the actual lens transformation function.
	Run(forward bool, args Data, data Data) (Patch, error)
}

func GetContext

func GetContext(contextID ContextID) ModuleContext

type Patch

type Patch interface {
	Set(string, interface{})
}

func NewPatch

func NewPatch(d ...map[string]interface{}) Patch

type WrappedModuleContext

type WrappedModuleContext interface {
	ModuleContext
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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