protocol

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const HeadSize = 29
View Source
const LightHandshakeSt = 0x09 // Handshake 起始符
View Source
const LightSt = 0x05 // 起始符

Variables

View Source
var Crc32 = false

var MaxPayloadMemory = 10 << 20 // 每个请求体最大 10M 超过进行拆分

Functions

func EncodeHandshake added in v0.0.3

func EncodeHandshake(key, token, err []byte) []byte

EncodeHandshake 编码握手函数

func EncodeMessage

func EncodeMessage(magicStr string, server, method, metaData []byte, respType, compressorType, serializationType byte, payload []byte) (magic string, data []byte, err error)

EncodeMessage 基础编码

Types

type Handshake added in v0.0.3

type Handshake struct {
	Key   []byte
	Token []byte
	Error []byte
}

func (*Handshake) Handshake added in v0.0.3

func (h *Handshake) Handshake(r io.Reader) error

Handshake 解码握手函数

type Header struct {
	St                byte
	Version           byte
	Crc32             uint32
	MagicNumberSize   uint32
	ServerNameSize    uint32
	ServerMethodSize  uint32
	MetaDataSize      uint32
	PayloadSize       uint32
	RespType          byte
	CompressorType    byte
	SerializationType byte
}

func DecodeHeader

func DecodeHeader(data []byte) (*Header, error)

type LightVersion

type LightVersion byte
const (
	V1 LightVersion = iota
)

type Message

type Message struct {
	Header        *Header
	MagicNumber   string
	ServiceName   string
	ServiceMethod string
	MetaData      []byte
	Payload       []byte
}

func DecodeMessage

func DecodeMessage(data []byte) (*Message, error)

DecodeMessage 完整Decode

func DecodeMessageV2

func DecodeMessageV2(data []byte, header *Header, headSize uint32) (*Message, error)

type Protocol

type Protocol struct{}

func NewProtocol

func NewProtocol() *Protocol

func (*Protocol) IODecode

func (m *Protocol) IODecode(r io.Reader) (*Message, error)

type RequestType

type RequestType byte
const (
	Request RequestType = iota
	Response
	HeartBeat
)

Jump to

Keyboard shortcuts

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