protocol

package
v0.0.0-...-b9d6073 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2018 License: Apache-2.0 Imports: 10 Imported by: 3

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
)

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"
)
View Source
const (
	Hessian = iota
	GrpcPb
	JSON
	Msgpack
	Hprose
	Pb
	Simple
	GrpcJSON
)

serialize

View Source
const (
	Normal = iota
	Exception
)

message status

Variables

This section is empty.

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) ([]byte, error)

DecodeGzip : decode gzip

func DecodeGzipBody

func DecodeGzipBody(body []byte) []byte

func EncodeGzip

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

EncodeGzip : encode gzip

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

func BuildRequestHeader

func BuildRequestHeader(requestID uint64) *Header

BuildRequestHeader build a proxy request header

func BuildResponseHeader

func BuildResponseHeader(requestID uint64, msgStatus int) *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 map[string]string
	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 (*Message) Encode

func (msg *Message) Encode() (buf *bytes.Buffer)

Jump to

Keyboard shortcuts

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