Documentation ¶
Overview ¶
Package protocol is motan2 protocol codec implements.
Index ¶
- Constants
- Variables
- func ConvertToRequest(request *Message, serialize motan.Serialization) (motan.Request, error)
- func ConvertToResponse(response *Message, serialize motan.Serialization) (motan.Response, error)
- func DecodeGzip(data []byte) (ret []byte, err error)
- func DecodeGzipBody(body []byte) []byte
- func EncodeGzip(data []byte) ([]byte, error)
- func EncodeMessageGzip(msg *Message, gzipSize int)
- func ExceptionToJSON(e *motan.Exception) string
- type Header
- func (h *Header) Clone() *Header
- func (h *Header) GetSerialize() int
- func (h *Header) GetStatus() int
- func (h *Header) GetVersion() int
- func (h *Header) IsGzip() bool
- func (h *Header) IsHeartbeat() bool
- func (h *Header) IsOneWay() bool
- func (h *Header) IsProxy() bool
- func (h *Header) SetGzip(isgzip bool)
- func (h *Header) SetHeartbeat(isHeartbeat bool)
- func (h *Header) SetOneWay(isOneWay bool)
- func (h *Header) SetProxy(isProxy bool)
- func (h *Header) SetRequest(isRequest bool)
- func (h *Header) SetSerialize(serialize int) error
- func (h *Header) SetStatus(status int) error
- func (h *Header) SetVersion(version int) error
- type Message
- func BuildExceptionResponse(requestID uint64, errmsg string) *Message
- func BuildHeartbeat(requestID uint64, msgType int) *Message
- func ConvertToReqMessage(request motan.Request, serialize motan.Serialization) (*Message, error)
- func ConvertToResMessage(response motan.Response, serialize motan.Serialization) (*Message, error)
- func Decode(buf *bufio.Reader) (msg *Message, err error)
- func DecodeWithTime(buf *bufio.Reader) (msg *Message, start time.Time, err error)
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 ¶
ConvertToRequest convert motan2 protocol request message to motan Request
func ConvertToResponse ¶
ConvertToResponse convert protocol response to motan Response
func DecodeGzip ¶
func DecodeGzipBody ¶
func EncodeGzip ¶
func EncodeMessageGzip ¶
func ExceptionToJSON ¶
Types ¶
type Header ¶
type Header struct { Magic uint16 MsgType uint8 VersionStatus uint8 Serialize uint8 RequestID uint64 }
func BuildHeader ¶
BuildHeader build header with common set TODO: remove 'requestID' parameter
func BuildRequestHeader ¶
BuildRequestHeader build a proxy request header
func BuildResponseHeader ¶
func (*Header) GetSerialize ¶
func (*Header) GetVersion ¶
func (*Header) IsHeartbeat ¶
func (*Header) SetHeartbeat ¶
func (*Header) SetRequest ¶
func (*Header) SetSerialize ¶
func (*Header) SetVersion ¶
type Message ¶
func BuildExceptionResponse ¶
func BuildHeartbeat ¶
func ConvertToReqMessage ¶
ConvertToReqMessage convert motan Request to protocol request
func ConvertToResMessage ¶
ConvertToResMessage convert motan Response to protocol response
func DecodeWithTime ¶
func (*Message) Encode ¶
func (msg *Message) Encode() (buf *motan.BytesBuffer)
Click to show internal directories.
Click to hide internal directories.