protocol

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2021 License: Apache-2.0 Imports: 13 Imported by: 7

Documentation

Overview

Package protocol is motan2 protocol codec implements.

Index

Constants

View Source
const (
	Req = iota
	Res
)

message type

View Source
const (
	MotanMagic   = 0xf1f1
	HeaderLength = 13
	Version2     = 1
)

message magic

View Source
const (
	MPath          = "M_p"
	MMethod        = "M_m"
	MExceptionn    = "M_e"
	MProcessTime   = "M_pt"
	MMethodDesc    = "M_md"
	MGroup         = "M_g"
	MProxyProtocol = "M_pp"
	MVersion       = "M_v"
	MModule        = "M_mdu"
	MSource        = "M_s"
	MRequestID     = "M_rid"
	MTimeout       = "M_tmo"
)
View Source
const (
	Hessian = iota
	GrpcPb
	JSON
	Msgpack
	Hprose
	Pb
	Simple
	GrpcJSON
)

serialize

View Source
const (
	Normal = iota
	Exception
)

message status

View Source
const (
	DefaultMetaSize = 16
)

Variables

View Source
var (
	ErrVersion        = errors.New("message version not correct")
	ErrMagicNum       = errors.New("message magic number not correct")
	ErrStatus         = errors.New("message status not correct")
	ErrMetadata       = errors.New("decode meta data fail")
	ErrSerializeNum   = errors.New("message serialize number not correct")
	ErrSerializeNil   = errors.New("message serialize not found")
	ErrSerializedData = errors.New("message serialized data not correct")
)

errors

View Source
var (
	DefaultGzipLevel = gzip.BestSpeed
)

Functions

func ConvertToRequest

func ConvertToRequest(request *Message, serialize motan.Serialization) (motan.Request, error)

ConvertToRequest convert motan2 protocol request message to motan Request

func ConvertToResponse

func ConvertToResponse(response *Message, serialize motan.Serialization) (motan.Response, error)

ConvertToResponse convert protocol response to motan Response

func DecodeGzip

func DecodeGzip(data []byte) (ret []byte, err error)

func DecodeGzipBody

func DecodeGzipBody(body []byte) []byte

func EncodeGzip

func EncodeGzip(data []byte) ([]byte, error)

func EncodeMessageGzip

func EncodeMessageGzip(msg *Message, gzipSize int)

func ExceptionToJSON

func ExceptionToJSON(e *motan.Exception) string

Types

type Header struct {
	Magic         uint16
	MsgType       uint8
	VersionStatus uint8
	Serialize     uint8
	RequestID     uint64
}

func BuildHeader

func BuildHeader(msgType int, proxy bool, serialize int, requestID uint64, msgStatus int) *Header

BuildHeader build header with common set TODO: remove 'requestID' parameter

func BuildRequestHeader

func BuildRequestHeader(requestID uint64) *Header

BuildRequestHeader build a proxy request header

func BuildResponseHeader

func BuildResponseHeader(requestID uint64, msgStatus int) *Header

func (*Header) Clone

func (h *Header) Clone() *Header

func (*Header) GetSerialize

func (h *Header) GetSerialize() int

func (*Header) GetStatus

func (h *Header) GetStatus() int

func (*Header) GetVersion

func (h *Header) GetVersion() int

func (*Header) IsGzip

func (h *Header) IsGzip() bool

func (*Header) IsHeartbeat

func (h *Header) IsHeartbeat() bool

func (*Header) IsOneWay

func (h *Header) IsOneWay() bool

func (*Header) IsProxy

func (h *Header) IsProxy() bool

func (*Header) SetGzip

func (h *Header) SetGzip(isgzip bool)

func (*Header) SetHeartbeat

func (h *Header) SetHeartbeat(isHeartbeat bool)

func (*Header) SetOneWay

func (h *Header) SetOneWay(isOneWay bool)

func (*Header) SetProxy

func (h *Header) SetProxy(isProxy bool)

func (*Header) SetRequest

func (h *Header) SetRequest(isRequest bool)

func (*Header) SetSerialize

func (h *Header) SetSerialize(serialize int) error

func (*Header) SetStatus

func (h *Header) SetStatus(status int) error

func (*Header) SetVersion

func (h *Header) SetVersion(version int) error

type Message

type Message struct {
	Header   *Header
	Metadata *motan.StringMap
	Body     []byte
	Type     int
}

func BuildExceptionResponse

func BuildExceptionResponse(requestID uint64, errmsg string) *Message

func BuildHeartbeat

func BuildHeartbeat(requestID uint64, msgType int) *Message

func ConvertToReqMessage

func ConvertToReqMessage(request motan.Request, serialize motan.Serialization) (*Message, error)

ConvertToReqMessage convert motan Request to protocol request

func ConvertToResMessage

func ConvertToResMessage(response motan.Response, serialize motan.Serialization) (*Message, error)

ConvertToResMessage convert motan Response to protocol response

func Decode

func Decode(buf *bufio.Reader) (msg *Message, err error)

func DecodeWithTime

func DecodeWithTime(buf *bufio.Reader) (msg *Message, start time.Time, err error)

func (*Message) Clone

func (msg *Message) Clone() interface{}

func (*Message) Encode

func (msg *Message) Encode() (buf *motan.BytesBuffer)

Jump to

Keyboard shortcuts

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