Documentation
¶
Index ¶
- Constants
- Variables
- func FreeMsg(msg *Message)
- type CompressType
- type Compressor
- type GzipCompressor
- type Header
- func (h Header) CheckMagicNumber() bool
- func (h Header) CompressType() CompressType
- func (h Header) IsHeartbeat() bool
- func (h Header) IsOneway() bool
- func (h Header) MessageStatusType() MessageStatusType
- func (h Header) MessageType() MessageType
- func (h Header) Seq() uint64
- func (h Header) SerializeType() SerializeType
- func (h *Header) SetCompressType(ct CompressType)
- func (h *Header) SetHeartbeat(hb bool)
- func (h *Header) SetMessageStatusType(mt MessageStatusType)
- func (h *Header) SetMessageType(mt MessageType)
- func (h *Header) SetOneway(oneway bool)
- func (h *Header) SetSeq(seq uint64)
- func (h *Header) SetSerializeType(st SerializeType)
- func (h *Header) SetVersion(v byte)
- func (h Header) Version() byte
- type Message
- type MessageStatusType
- type MessageType
- type RawDataCompressor
- type SerializeType
Constants ¶
const ( // ServiceError contains error info of service invocation ServiceError = "__rpcx_error__" // 服务调用的错误 一般到存到metadata或context )
Variables ¶
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") // 不支持的压缩类型 )
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{}, } )
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 ¶
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 ¶
通用的压缩接口 Compressor defines a common compression interface.
type Header ¶
type Header [12]byte
Header is the first part of Message and has fixed size. Format:
func (Header) CheckMagicNumber ¶
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 ¶
IsHeartbeat returns whether the message is heartbeat message.
func (Header) IsOneway ¶
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) 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 ¶
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) SetSerializeType ¶
func (h *Header) SetSerializeType(st SerializeType)
SetSerializeType sets the serialization type.
func (*Header) SetVersion ¶
SetVersion sets version for this header.
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 NewMessage ¶
func NewMessage() *Message
NewMessage creates an empty message. 新建消息:对应的消息对象属性需要自行设置 添加
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 { }
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 )