module

package
v0.0.0-...-979fa9e Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2024 License: MPL-2.0 Imports: 3 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LenByteOrder = binary.LittleEndian

LenByteOrder is the byte order in which the byte length is written to memory.

This is independent to the system byte order, and does not have to match it.

View Source
var LenSize int32 = 4

LenSize is the size in bytes of `LenType`

View Source
var TypeIdByteOrder = binary.LittleEndian

LenByteOrder is the byte order in which the byte length is written to memory.

This is independent to the system byte order, and does not have to match it.

View Source
var TypeIdSize int32 = 1

TypeIdSize is the size in bytes of `TypeIdType`

Functions

This section is empty.

Types

type BytesMemory

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

BytesMemory converts a byte slice into a module Memory.

func NewBytesMemory

func NewBytesMemory(data []byte) *BytesMemory

NewBytesMemory returns a ReadWriterAt that reads from the given bytes.

func (*BytesMemory) ReadAt

func (s *BytesMemory) ReadAt(dst []byte, offset int64) (int, error)

Read implements the io.ReaderAt interface.

func (*BytesMemory) WriteAt

func (s *BytesMemory) WriteAt(src []byte, offset int64) (int, error)

Write implements the io.WriterAt interface.

type Instance

type Instance struct {
	// Alloc allocates the given number of bytes in memory and returns the start index to the allocated block.
	Alloc func(size MemSize) (MemSize, error)

	// Transform transforms the data stored at the given start index, returning the start index of the result.
	//
	// The next function provided should return a wasm memory pointer to the next source item to be transformed.
	Transform func(next func() MemSize) (MemSize, error)

	// Memory returns an interface that can be used to read or write to the
	// linear memory that this module uses.
	//
	// Values written to memory will be made available to this module, however changes made by the
	// module after this function has been called are not guaranteed to be visible to the returned io.Reader.
	Memory func() Memory

	// OwnedBy hosts a reference to any object(s) that may be required to live in memory for the lifetime of this Module.
	//
	// This is very important when working with some libraries (such as wasmer-go), as without this, dependencies of other members
	// of this Module may be garbage collected prematurely.
	OwnedBy any
}

Instance is the representation of loaded lens module. This will often be sourced from a WASM binary but it does not have to be.

type LenType

type LenType uint32

LenType is the type used to represent the byte length of an item transmitted to/from a lens module.

type MemSize

type MemSize = int32

MemSize is the memory size of the module runtime.

This is independent to the host system memory size and does not have to match it. This type must only be alias, otherwise calling the wasm funcs will fail.

type Memory

type Memory interface {
	io.ReaderAt
	io.WriterAt
}

Memory is an interface for reading and writing to a module's shared linear memory.

type Module

type Module interface {
	// NewInstance returns a new lens instance from this module, hosted
	// within the parent runtime.
	NewInstance(string, ...map[string]any) (Instance, error)
}

Module represents a lens module loaded into a runtime.

Multiple instances can be generated from the same module.

type Runtime

type Runtime interface {
	// NewModule instantiates a new module from the given WAT code.
	//
	// This is a fairly expensive operation.
	NewModule([]byte) (Module, error)
}

Runtime represents the runtime hosting lens instances.

type TypeIdType

type TypeIdType int8

TypeIdType is the type used to represent the type of an item transmitted to/from a lens module.

Positive values represent valid values, negative values represent errors, 0 is undefined.

const (
	ErrTypeID  TypeIdType = -1
	NilTypeID  TypeIdType = 0
	JSONTypeID TypeIdType = 1

	// A type id that denotes the end of stream.
	//
	// If recieved it signals that the end of the stream has been reached and that the source will no longer yield
	// new values.
	EOSTypeID TypeIdType = math.MaxInt8
)

func (TypeIdType) IsEOS

func (typeId TypeIdType) IsEOS() bool

IsEOS returns true if the given typeId declares that the end of stream has been reached.

Otherwise returns false.

func (TypeIdType) IsError

func (typeId TypeIdType) IsError() bool

IsError returns true if the given typeId is an error type.

Otherwise returns false.

Jump to

Keyboard shortcuts

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