protocol

package
v0.0.0-...-564fdec Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ServiceError contains error info of service invocation
	ServiceError = "__rpcx_error__" // 服务调用的错误 一般到存到metadata或context
)

Variables

View Source
var (
	// ErrMetaKVMissing some keys or values are mssing.
	ErrMetaKVMissing = errors.New("wrong metadata lines. some keys or values are missing") // 请求消息中MetaData中key-value丢失
	// ErrMessageTooLong message is too long
	ErrMessageTooLong = errors.New("message is too long") // 消息太长

	ErrUnsupportedCompressor = errors.New("unsupported compressor") // 不支持的压缩类型
)
View Source
var (
	// Compressors are compressors supported by rpcx. You can add customized compressor in Compressors.
	// RPCX提供的请求压缩类型:None(未压缩)、Gzip(一般请求大于1KB,且指定对应的压缩类型)
	Compressors = map[CompressType]Compressor{
		None: &RawDataCompressor{},
		Gzip: &GzipCompressor{},
	}
)
View Source
var MaxMessageLength = 0

MaxMessageLength is the max length of a message. Default is 0 that means does not limit length of messages. It is used to validate when read messages from io.Reader. 用于执行请求消息的大小,默认=0 表示不限制,使用时需要根据实际情况进行设定同时结合对应的压缩类型 提供系统性能(及时性、吞吐量)

Functions

func FreeMsg

func FreeMsg(msg *Message)

复用请求消息 会放到对应的对象池 FreeMsg puts a msg into the pool.

Types

type CompressType

type CompressType byte // 压缩类型(原始或GZIP)

CompressType defines decompression type.

const (
	// None does not compress.
	None CompressType = iota
	// Gzip uses gzip compression.
	Gzip
)

type Compressor

type Compressor interface {
	Zip([]byte) ([]byte, error)   // 压缩
	Unzip([]byte) ([]byte, error) // 解压
}

通用的压缩接口 Compressor defines a common compression interface.

type GzipCompressor

type GzipCompressor struct {
}

GzipCompressor implements gzip compressor.

func (GzipCompressor) Unzip

func (c GzipCompressor) Unzip(data []byte) ([]byte, error)

func (GzipCompressor) Zip

func (c GzipCompressor) Zip(data []byte) ([]byte, error)
type Header [12]byte

Header is the first part of Message and has fixed size. Format:

func (Header) CheckMagicNumber

func (h Header) CheckMagicNumber() bool

CheckMagicNumber checks whether header starts rpcx magic number.

func (Header) CompressType

func (h Header) CompressType() CompressType

CompressType returns compression type of messages.

func (Header) IsHeartbeat

func (h Header) IsHeartbeat() bool

IsHeartbeat returns whether the message is heartbeat message.

func (Header) IsOneway

func (h Header) IsOneway() bool

IsOneway returns whether the message is one-way message. If true, server won't send responses.

func (Header) MessageStatusType

func (h Header) MessageStatusType() MessageStatusType

MessageStatusType returns the message status type.

func (Header) MessageType

func (h Header) MessageType() MessageType

MessageType returns the message type.

func (Header) Seq

func (h Header) Seq() uint64

Seq returns sequence number of messages.

func (Header) SerializeType

func (h Header) SerializeType() SerializeType

SerializeType returns serialization type of payload.

func (*Header) SetCompressType

func (h *Header) SetCompressType(ct CompressType)

SetCompressType sets the compression type.

func (*Header) SetHeartbeat

func (h *Header) SetHeartbeat(hb bool)

SetHeartbeat sets the heartbeat flag.

func (*Header) SetMessageStatusType

func (h *Header) SetMessageStatusType(mt MessageStatusType)

SetMessageStatusType sets message status type.

func (*Header) SetMessageType

func (h *Header) SetMessageType(mt MessageType)

SetMessageType sets message type.

func (*Header) SetOneway

func (h *Header) SetOneway(oneway bool)

SetOneway sets the oneway flag.

func (*Header) SetSeq

func (h *Header) SetSeq(seq uint64)

SetSeq sets sequence number.

func (*Header) SetSerializeType

func (h *Header) SetSerializeType(st SerializeType)

SetSerializeType sets the serialization type.

func (*Header) SetVersion

func (h *Header) SetVersion(v byte)

SetVersion sets version for this header.

func (Header) Version

func (h Header) Version() byte

Version returns version of rpcx protocol.

type Message

type Message struct {
	*Header                         // 消息头 = 4bytes
	ServicePath   string            // 服务名
	ServiceMethod string            // 服务方法
	Metadata      map[string]string // 元数据
	Payload       []byte            // 消息体
	// contains filtered or unexported fields
}

Message is the generic type of Request and Response. 消息

func GetPooledMsg

func GetPooledMsg() *Message

GetPooledMsg gets a pooled message. 获取请求消息

func NewMessage

func NewMessage() *Message

NewMessage creates an empty message. 新建消息:对应的消息对象属性需要自行设置 添加

func Read

func Read(r io.Reader) (*Message, error)

读Message Read reads a message from r.

func (Message) Clone

func (m Message) Clone() *Message

Clone clones from an message.

func (*Message) Decode

func (m *Message) Decode(r io.Reader) error

解码message Decode decodes a message from reader.

func (Message) Encode

func (m Message) Encode() []byte

Encode encodes messages.

func (*Message) Reset

func (m *Message) Reset()

清空Message内容 Reset clean data of this message but keep allocated data

func (Message) WriteTo

func (m Message) WriteTo(w io.Writer) error

WriteTo writes message to writers.

type MessageStatusType

type MessageStatusType byte // 响应消息状态:正常或错误

MessageStatusType is status of messages.

const (
	// Normal is normal requests and responses.
	Normal MessageStatusType = iota
	// Error indicates some errors occur.
	Error
)

type MessageType

type MessageType byte

MessageType is message type of requests and resposnes. 消息类型(请求和响应两种)

const (
	// Request is message type of request
	Request MessageType = iota // 请求
	// Response is message type of response
	Response // 响应
)

type RawDataCompressor

type RawDataCompressor struct {
}

func (RawDataCompressor) Unzip

func (c RawDataCompressor) Unzip(data []byte) ([]byte, error)

func (RawDataCompressor) Zip

func (c RawDataCompressor) Zip(data []byte) ([]byte, error)

type SerializeType

type SerializeType byte //消息体 编解码类型

SerializeType defines serialization type of payload.

const (
	// SerializeNone uses raw []byte and don't serialize/deserialize 直接使用[]byte
	SerializeNone SerializeType = iota
	// JSON for payload.
	JSON
	// ProtoBuffer for payload.
	ProtoBuffer
	// MsgPack for payload
	MsgPack
	// Thrift
	// Thrift for payload
	Thrift
)

Jump to

Keyboard shortcuts

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