wasm

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2023 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ResponseType              = 0
	RequestType               = 1
	RequestOneWayType         = 2
	HeartBeatFlag        byte = 1 << 5
	RpcHeaderLength           = 16
	RpcMagic                  = 0xAF
	RpcVersion                = 1
	RpcRequestFlag       byte = 1 << 6
	RpcOneWayRequestFlag byte = 1<<6 | 1<<7
	RpcResponseFlag      byte = 0
	RpcIdIndex                = 4
	RpcTimeout                = "timeout"
	RpcResponseStatus         = 0
	UnKnownMagicType          = "unknown magic type"
	UnKnownProtocolType       = "unknown protocol code type"
	UnKnownRpcFlagType        = "unknown protocol flag type"
)
View Source
const (
	BufferTypeDecodeData proxywasm.BufferType = 13
	BufferTypeEncodeData proxywasm.BufferType = 14
	StatusNeedMoreData   proxywasm.WasmResult = 99
)

extension for protocol

Variables

This section is empty.

Functions

func DecodeMap

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

DecodeMap decode map from byte slice see EncodeMap for more detail.

func EncodeMap

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

EncodeMap encode map to bytes encoded bytes format: pairs number + all key/value length + all key/value bytes

eg: {"key1": "value1", "hello": "world"} 2(pairs number) + 4(key1 length) + 6(value1 length) => { "key1": "value1" } length

  • 5(hello length) + 5(world length) => { "hello": "world" } length
  • key1 bytes + nil byte + value1 bytes + nil byte => { "key1": "value1" } bytes
  • hello bytes + nil byte + world bytes + nil byte => { "hello": "world" } bytes

func NewWasmRpcProtocol

func NewWasmRpcProtocol(pw types.WasmPluginWrapper, wrapper *protocolWrapper) *wasmProtocol

Types

type AbiV2Impl

type AbiV2Impl struct {
	v1.ABIContext
}

easy for extension

func (*AbiV2Impl) Name

func (a *AbiV2Impl) Name() string

func (*AbiV2Impl) ProxyDecodeBufferBytes

func (a *AbiV2Impl) ProxyDecodeBufferBytes(contextId int32, buf types.IoBuffer) error

func (*AbiV2Impl) ProxyEncodeRequestBufferBytes

func (a *AbiV2Impl) ProxyEncodeRequestBufferBytes(contextId int32, cmd api.XFrame) error

func (*AbiV2Impl) ProxyEncodeResponseBufferBytes

func (a *AbiV2Impl) ProxyEncodeResponseBufferBytes(contextId int32, cmd api.XRespFrame) error

func (*AbiV2Impl) ProxyHijackBufferBytes

func (a *AbiV2Impl) ProxyHijackBufferBytes(contextId int32, cmd api.XFrame, statusCode uint32) error

func (*AbiV2Impl) ProxyKeepAliveBufferBytes

func (a *AbiV2Impl) ProxyKeepAliveBufferBytes(contextId int32, id uint64) error

func (*AbiV2Impl) ProxyReplyKeepAliveBufferBytes

func (a *AbiV2Impl) ProxyReplyKeepAliveBufferBytes(contextId int32, cmd api.XFrame) error

type Context

type Context struct {
	v1.DefaultImportsHandler
	// contains filtered or unexported fields
}

func (*Context) ContextId

func (c *Context) ContextId() int32

func (*Context) GetCustomBuffer

func (c *Context) GetCustomBuffer(bufferType proxywasm.BufferType) common.IoBuffer

func (*Context) GetDecodeBuffer

func (c *Context) GetDecodeBuffer() api.IoBuffer

func (*Context) GetDecodeCmd

func (c *Context) GetDecodeCmd() api.XFrame

func (*Context) GetEncodeBuffer

func (c *Context) GetEncodeBuffer() api.IoBuffer

func (*Context) GetEncodeCmd

func (c *Context) GetEncodeCmd() api.XFrame

func (*Context) SetDecodeBuffer

func (c *Context) SetDecodeBuffer(buf api.IoBuffer)

func (*Context) SetDecodeCmd

func (c *Context) SetDecodeCmd(cmd api.XFrame)

func (*Context) SetEncodeBuffer

func (c *Context) SetEncodeBuffer(buf api.IoBuffer)

func (*Context) SetEncodeCmd

func (c *Context) SetEncodeCmd(cmd api.XFrame)

type ContextCallback

type ContextCallback interface {
	// extension for abi 0_1_0
	proxywasm.ImportsHandler

	//DrainLength() uint32
	GetDecodeCmd() api.XFrame
	SetDecodeCmd(cmd api.XFrame)
	GetDecodeBuffer() api.IoBuffer

	GetEncodeCmd() api.XFrame
	SetEncodeBuffer(buf api.IoBuffer)
	GetEncodeBuffer() api.IoBuffer
}

type ProtocolConfig

type ProtocolConfig struct {
	VmConfig    *v2.WasmVmConfig `json:"vm_config,omitempty"`
	InstanceNum int              `json:"instance_num,omitempty"`

	SubProtocol       string `json:"protocol,omitempty"`
	FromWasmPlugin    string `json:"from_wasm_plugin,omitempty"`
	RootContextID     int32  `json:"root_id,omitempty"`
	PoolMode          string `json:"pool_mode,omitempty"`
	DisableWorkerPool bool   `json:"disable_worker_pool,omitempty"`
	PluginGenerateID  bool   `json:"plugin_generate_id,omitempty"`
	// contains filtered or unexported fields
}

func ParseProtocolConfig

func ParseProtocolConfig(cfg map[string]interface{}) (*ProtocolConfig, error)

type ProxyProtocolManager

type ProxyProtocolManager interface {

	// AddOrUpdateProtocolConfig map the key to streamFilter chain wrapper.
	AddOrUpdateProtocolConfig(config map[string]interface{}) error

	// GetWasmProtocolFactory return StreamFilterFactory indexed by key.
	GetWasmProtocolFactory(key string) ProxyProtocolWrapper
}

func GetProxyProtocolManager

func GetProxyProtocolManager() ProxyProtocolManager

type ProxyProtocolWrapper

type ProxyProtocolWrapper interface {
	Name() string
}

type Request

type Request struct {
	RequestHeader

	Data types.IoBuffer // wrapper of data

	PayLoad        types.IoBuffer // wrapper of payload
	PayloadChanged bool           // check if payload if modified
	// contains filtered or unexported fields
}

func NewWasmRequestWithId

func NewWasmRequestWithId(id uint64, headers *xprotocol.Header, payload types.IoBuffer) *Request

func (*Request) GetData

func (r *Request) GetData() types.IoBuffer

func (*Request) GetHeader

func (r *Request) GetHeader() types.HeaderMap

func (*Request) GetId

func (r *Request) GetId() uint64

func (*Request) GetRequestId

func (r *Request) GetRequestId() uint64

func (*Request) GetStreamType

func (r *Request) GetStreamType() api.StreamType

func (*Request) GetTimeout

func (r *Request) GetTimeout() int32

func (*Request) IsHeartbeatFrame

func (r *Request) IsHeartbeatFrame() bool

func (*Request) SetData

func (r *Request) SetData(data types.IoBuffer)

func (*Request) SetRequestId

func (r *Request) SetRequestId(id uint64)

type RequestHeader

type RequestHeader struct {
	RpcHeader        // common rpc header
	Timeout   uint32 // request timeout
}

func (*RequestHeader) Clone

func (h *RequestHeader) Clone() types.HeaderMap

type Response

type Response struct {
	ResponseHeader

	Data types.IoBuffer // wrapper of data

	PayLoad        types.IoBuffer // wrapper of payload
	PayloadChanged bool           // check if payload if modified
	// contains filtered or unexported fields
}

func NewWasmResponseWithId

func NewWasmResponseWithId(requestId uint64, headers *xprotocol.Header, payload types.IoBuffer) *Response

func (*Response) GetData

func (r *Response) GetData() types.IoBuffer

func (*Response) GetHeader

func (r *Response) GetHeader() types.HeaderMap

func (*Response) GetId

func (r *Response) GetId() uint64

func (*Response) GetRequestId

func (r *Response) GetRequestId() uint64

func (*Response) GetStatusCode

func (r *Response) GetStatusCode() uint32

func (*Response) GetStreamType

func (r *Response) GetStreamType() api.StreamType

func (*Response) GetTimeout

func (r *Response) GetTimeout() int32

func (*Response) IsHeartbeatFrame

func (r *Response) IsHeartbeatFrame() bool

func (*Response) SetData

func (r *Response) SetData(data types.IoBuffer)

func (*Response) SetRequestId

func (r *Response) SetRequestId(id uint64)

type ResponseHeader

type ResponseHeader struct {
	RpcHeader        // common rpc header
	Status    uint32 // response status
}

func (*ResponseHeader) Clone

func (h *ResponseHeader) Clone() types.HeaderMap

type RpcHeader

type RpcHeader struct {
	Flag         byte   // rpc request or response flag
	Id           uint64 // request or response id
	RpcId        uint64 // request or response id (replaced by stream)
	IsReplacedId bool   // check if the id has been replaced
	HeaderLen    uint32 // header length

	xprotocol.Header
}

Jump to

Keyboard shortcuts

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