common

package
v0.0.0-...-52204ac Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2023 License: AGPL-3.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeMap

func DecodeMap(rawData []byte) map[string]string

DecodeMap decode map from rawData.

func EncodeMap

func EncodeMap(m map[string]string) []byte

EncodeMap encode map into bytes.

Types

type CommonBuffer

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

CommonBuffer is a simple implementation of IoBuffer.

func (*CommonBuffer) Bytes

func (c *CommonBuffer) Bytes() []byte

func (*CommonBuffer) Drain

func (c *CommonBuffer) Drain(offset int)

func (*CommonBuffer) Len

func (c *CommonBuffer) Len() int

func (*CommonBuffer) Write

func (c *CommonBuffer) Write(p []byte) (int, error)

type CommonHeader

type CommonHeader map[string]string

CommonHeader is a simple implementation of HeaderMap.

func (CommonHeader) Add

func (h CommonHeader) Add(key string, value string)

func (CommonHeader) ByteSize

func (h CommonHeader) ByteSize() uint64

func (CommonHeader) Clone

func (h CommonHeader) Clone() HeaderMap

func (CommonHeader) Del

func (h CommonHeader) Del(key string)

func (CommonHeader) Get

func (h CommonHeader) Get(key string) (value string, ok bool)

func (CommonHeader) Range

func (h CommonHeader) Range(f func(key, value string) bool)

func (CommonHeader) Set

func (h CommonHeader) Set(key string, value string)

type HeaderMap

type HeaderMap interface {
	// Get value of key
	// If multiple values associated with this key, first one will be returned.
	Get(key string) (string, bool)

	// Set key-value pair in header map, the previous pair will be replaced if exists
	Set(key, value string)

	// Add value for given key.
	// Multiple headers with the same key may be added with this function.
	// Use Set for setting a single header for the given key.
	Add(key, value string)

	// Del delete pair of specified key
	Del(key string)

	// Range calls f sequentially for each key and value present in the map.
	// If f returns false, range stops the iteration.
	Range(f func(key, value string) bool)

	// Clone used to deep copy header's map
	Clone() HeaderMap

	// ByteSize return size of HeaderMap
	ByteSize() uint64
}

HeaderMap is a interface to provide operation facade with user-value headers.

type IoBuffer

type IoBuffer interface {
	// Len returns the number of bytes of the unread portion of the buffer;
	// b.Len() == len(b.Bytes()).
	Len() int

	// Bytes returns all bytes from buffer, without draining any buffered data.
	// It can be used to get fixed-length content, such as headers, body.
	// Note: do not change content in return bytes, use write instead
	Bytes() []byte

	// Write appends the contents of p to the buffer, growing the buffer as
	// needed. The return value n is the length of p; err is always nil. If the
	// buffer becomes too large, Write will panic with ErrTooLarge.
	Write(p []byte) (n int, err error)

	// Drain drains a offset length of bytes in buffer.
	// It can be used with Bytes(), after consuming a fixed-length of data
	Drain(offset int)
}

func NewIoBufferBytes

func NewIoBufferBytes(data []byte) IoBuffer

type WasmFunction

type WasmFunction interface {
	// Call invokes the wasm func
	Call(args ...interface{}) (interface{}, error)
}

WasmFunction is the func exported by wasm module

type WasmInstance

type WasmInstance interface {
	// RegisterImports adds host functions used by the guest for the given
	// proxy-wasm ABI name. This must be called prior to Start.
	RegisterImports(abiName string) error

	// Start starts the wasm instance
	Start() error

	// Stop stops the wasm instance
	Stop()

	// GetExportsFunc returns the exported func of the wasm instance
	GetExportsFunc(funcName string) (WasmFunction, error)

	// GetExportsMem returns the exported mem of the wasm instance
	GetExportsMem(memName string) ([]byte, error)

	// GetMemory returns wasm mem bytes from specified addr and size
	GetMemory(addr uint64, size uint64) ([]byte, error)

	// PutMemory sets wasm mem bytes to specified addr and size
	PutMemory(addr uint64, size uint64, content []byte) error

	// GetByte returns one wasm byte from specified addr
	GetByte(addr uint64) (byte, error)

	// PutByte sets one wasms bytes to specified addr
	PutByte(addr uint64, b byte) error

	// GetUint32 returns uint32 from specified addr
	GetUint32(addr uint64) (uint32, error)

	// PutUint32 set uint32 to specified addr
	PutUint32(addr uint64, value uint32) error

	// Malloc allocates size of mem from wasm default memory
	Malloc(size int32) (uint64, error)

	// GetData returns user-defined data
	GetData() interface{}

	// SetData sets user-defined data into the wasm instance
	SetData(data interface{})

	// Acquire increases the ref count of the wasm instance
	Acquire() bool

	// Release decreases the ref count of the wasm instance
	Release()

	// Lock gets the exclusive ownership of the wasm instance
	// and sets the user-defined data
	Lock(data interface{})

	// Unlock releases the exclusive ownership of the wasm instance
	// and sets the users-defined data to nil
	Unlock()

	// GetModule returns the wasm module of current instance
	GetModule() WasmModule

	// HandlerError processes the encountered err
	HandleError(err error)
}

WasmInstance represents the wasm instance

type WasmModule

type WasmModule interface {
	// Init got called when creating a new wasm module
	Init()

	// NewInstance instantiates and returns a new wasm instance
	NewInstance() WasmInstance

	// GetABINameList returns the abi name list exported by wasm module
	//
	// Note: These are the only valid choices for WasmInstance.RegisterImports.
	GetABINameList() []string
}

WasmModule represents the wasm module

type WasmVM

type WasmVM interface {
	// Name returns the name of wasm vm(engine)
	Name() string

	// Init got called when creating a new wasm vm(engine)
	Init()

	// NewModule compiles the 'guest' into a wasm module
	NewModule(guest []byte) WasmModule

	// Close avoids leaking resources such as memory-mapped files.
	Close() error
}

WasmVM represents the wasm vm(engine)

Jump to

Keyboard shortcuts

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