codec

package
v0.0.0-...-02b4230 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

*

*
* @author liangjf
* @create on 2020/5/26
* @version 1.0

Index

Constants

View Source
const (
	FrameHeadLen = 21
	Magic        = 0x45
	Version      = 0
)
View Source
const (
	GeneralMsg     = 0x00
	HeartbeatMsg   = 0x01
	MsgAckMsg      = 0x02
	SyncOfflineMsg = 0x03
)
View Source
const (
	Default = "default"
)

Variables

View Source
var (
	DefaultCodec = NewDefaultCodec()
)
View Source
var (
	ErrDataEmpty = errors.New("data is empty")
)

Functions

func CheckMagic

func CheckMagic(framer []byte) bool

func GetDataLen

func GetDataLen(framer []byte) uint32

func GetMsgType

func GetMsgType(framer []byte) byte

func GetVersion

func GetVersion(framer []byte) byte

func RegisterCodec

func RegisterCodec(name string, codec ICodec)

Types

type FrameHeader

type FrameHeader struct {
	Magic        uint8  //1 magic
	Version      uint8  //1 version
	MsgType      uint8  //1 msg type, 0x0: general req,  0x1: heartbeat
	ReqType      uint8  //1 request type, 0x0: send and receive,   0x1: send but not receive
	CompressType uint8  //1 compression or not,  0x0: not compression,  0x1: compression
	StreamID     uint64 //8 stream ID
	Length       uint32 //4 total packet length
	Reserved     uint32 //4 4 bytes reserved
}

FrameHeader 帧头

type ICodec

type ICodec interface {
	Encode(*FrameHeader, []byte) ([]byte, error)
	Decode([]byte) ([]byte, error)
}

ICodec 编解码

func GetCodec

func GetCodec(name string) ICodec

func NewDefaultCodec

func NewDefaultCodec() ICodec

Jump to

Keyboard shortcuts

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