codec

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Proto = iota
	Thrift
	Arvo
)

协议protocol打包类型.

View Source
const (
	GeneralMsg = 0x0
	HeartMsg   = 0x1
)

消息类型.

View Source
const (
	SendAndRecv = iota
	SendOnly
	LongConn
	StreamTrans
)

请求类型.

View Source
const DefaultBufferLength = 1024
View Source
const FrameHeaderLen = 15
View Source
const Magic = 0x12
View Source
const MaxPayloadLength = 4 * 1024 * 1024
View Source
const (
	NoneCompress = iota
)

压缩类型.

View Source
const Version = 0

Variables

View Source
var (
	ErrorFrameHeaderRead  = errors.New("frame header read error")
	ErrorMagicNumber      = errors.New("magic number error ")
	ErrorRPCVersion       = errors.New("version error")
	ErrorPayloadOutLength = errors.New("payload beyond max length")
	ErrorPayloadRead      = errors.New("read payload error")
)
View Source
var DefaultCodec = NewDefaultCodec()
View Source
var MsgBuilder = &messageBuilder{
	msg: &msg{},
}
View Source
var NewDefaultCodec = func() Codec {
	return &codec{}
}

Functions

func RegisterCodeC

func RegisterCodeC(name string, codec Codec)

func StrToCompressType

func StrToCompressType(t string) uint8

strToCompressType 解析string类型为uint8类型的compressType帧头.

func StrToPackageType

func StrToPackageType(t string) uint8

StrToPackageType string类型转到uint8放到帧头压缩.

Types

type Codec

type Codec interface {
	Encode(Msg, []byte) ([]byte, error)
	Decode(Msg, []byte) ([]byte, error)
}

Codec

func Get

func Get(name string) Codec

type FrameHeader

type FrameHeader struct {
	// Magic 魔数.
	Magic uint8
	// Version 版本号.
	Version uint8
	// MsgType 消息类型.
	MsgType uint8
	// ReqType 请求类型.
	ReqType uint8
	// CompressType 压缩类型.
	CompressType uint8
	// StreamID 暂时没用,后续扩展.
	StreamID uint8
	// PackageType 用于包头压缩类型
	PackageType uint8
	// Length 帧长度.
	Length uint32
	// Reserved 保留位.
	Reserved uint32
}

FrameHeader 帧头.

type Framer

type Framer interface {
	ReadFrame() ([]byte, error)
}

type FramerBuilder

type FramerBuilder interface {
	New(conn net.Conn) Framer
}
var DefaultFramerBuilder FramerBuilder

type MessageBuilder

type MessageBuilder interface {
	WithSerializerType(string) MessageBuilder
	WithCompressType(string) MessageBuilder
	WithPackageType(string) MessageBuilder
	WithMsgType(uint8) MessageBuilder
	WithReqType(uint8) MessageBuilder
	WithClientServiceName(string) MessageBuilder
	WithServerServiceName(string) MessageBuilder
	WithRPCMethodName(string) MessageBuilder
	WithRequestID(id uint8) MessageBuilder
	WithRetCode(uint32) MessageBuilder
	WithRetMsg(string) MessageBuilder
	Build() Msg
}

func NewMsgBuilder

func NewMsgBuilder() MessageBuilder

type Msg

type Msg interface {
	SerializerType() string
	CompressType() uint8
	PackageType() uint8
	MsgType() uint8
	ReqType() uint8
	ClientServiceName() string
	ServerServiceName() string
	RPCMethodName() string
	RequestID() uint8
	RetCode() uint32
	RetMsg() string

	WithSerializerType(string)
	WithCompressType(uint8)
	WithPackageType(uint8)
	WithMsgType(uint8)
	WithReqType(uint8)
	WithClientServiceName(string)
	WithServerServiceName(string)
	WithRPCMethodName(string)
	WithRequestID(uint8)
	WithRetCode(uint32)
	WithRetMsg(string)
}

TODO msg

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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