codec

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: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProtocolName api.ProtocolName = "x_example" // protocol

	Magic       byte = 'x' //magic
	MagicIdx         = 0   //magicIndex
	DirRequest  byte = 0   // dir
	DirResponse byte = 1   // dir

	TypeHeartbeat byte = 0 // cmd code
	TypeMessage   byte = 1
	TypeGoAway    byte = 2

	ResponseStatusSuccess uint16 = 0 // 0x00 response status
	ResponseStatusError   uint16 = 1 // 0x01

	RequestHeaderLen  int = 11 // protocol header fields length
	ResponseHeaderLen int = 13
	MinimalDecodeLen  int = RequestHeaderLen // minimal length for decoding

	RequestIdIndex       = 3
	RequestPayloadIndex  = 7
	ResponsePayloadIndex = 9
	TypeIndex            = 1
	DirIndex             = 2
	RequestIdEnd         = 6
)

protocol constants

Variables

This section is empty.

Functions

This section is empty.

Types

type Matcher

type Matcher struct{}

func (*Matcher) ExampleMatcher

func (exampleMatcher *Matcher) ExampleMatcher(data []byte) api.MatchResult

predicate codec header len and compare magic number

type MessageAckCommand

type MessageAckCommand struct {
	Response

	// TODO: pb deserialize target, extract from Payload
	Message interface{}
}

type MessageCommand

type MessageCommand struct {
	Request

	// TODO: pb deserialize target, extract from Payload
	Message interface{}
}

type Proto

type Proto struct{}

func (*Proto) Decode

func (proto *Proto) Decode(ctx context.Context, data api.IoBuffer) (interface{}, error)

读取二进制流,然后判断判断是否符合协议,再根据是request 还是responce 读取二进制流信息 返回封装好的request responce对象

func (*Proto) EnableWorkerPool

func (proto *Proto) EnableWorkerPool() bool

func (*Proto) Encode

func (proto *Proto) Encode(ctx context.Context, model interface{}) (api.IoBuffer, error)

判断是request还是responce对象,然后添加协议部分,比如magic dir type payloadlen ,然后返回二进制流

func (*Proto) GenerateRequestID

func (proto *Proto) GenerateRequestID(streamID *uint64) uint64

func (*Proto) GoAway added in v0.27.0

func (proto *Proto) GoAway(ctx context.Context) api.XFrame

func (*Proto) Hijack

func (proto *Proto) Hijack(context context.Context, request api.XFrame, statusCode uint32) api.XRespFrame

Hijacker

func (*Proto) Mapping

func (proto *Proto) Mapping(httpStatusCode uint32) uint32

func (*Proto) Name

func (proto *Proto) Name() api.ProtocolName

func (*Proto) PoolMode

func (proto *Proto) PoolMode() api.PoolMode

PoolMode returns whether pingpong or multiplex

func (*Proto) Reply

func (proto *Proto) Reply(context context.Context, request api.XFrame) api.XRespFrame

func (*Proto) Trigger

func (proto *Proto) Trigger(context context.Context, requestId uint64) api.XFrame

Heartbeater

type Request

type Request struct {
	Type       byte
	RequestId  uint32
	PayloadLen uint32
	Payload    api.IoBuffer
	header.CommonHeader
}

func NewRpcRequest

func NewRpcRequest(headers header.CommonHeader, data api.IoBuffer) *Request

NewRpcRequest is a utility function which build rpc Request object of codec protocol.

func (*Request) GetData

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

func (*Request) GetHeader

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

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) IsGoAwayFrame added in v0.27.0

func (r *Request) IsGoAwayFrame() bool

func (*Request) IsHeartbeatFrame

func (r *Request) IsHeartbeatFrame() bool

func (*Request) SetData

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

func (*Request) SetRequestId

func (r *Request) SetRequestId(id uint64)

type Response

type Response struct {
	Request
	Status uint16
}

func NewRpcResponse

func NewRpcResponse(headers header.CommonHeader, data api.IoBuffer) *Response

NewRpcResponse is a utility function which build rpc Response object of codec protocol.

func (*Response) GetHeader

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

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) SetRequestId

func (r *Response) SetRequestId(id uint64)

type StatusMapping

type StatusMapping struct{}

func (*StatusMapping) MappingHeaderStatusCode

func (m *StatusMapping) MappingHeaderStatusCode(ctx context.Context, headers api.HeaderMap) (int, error)

Jump to

Keyboard shortcuts

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