import "github.com/smallnest/rpcx/protocol"
compressor.go message.go pool.go
const ( // ServiceError contains error info of service invocation ServiceError = "__rpcx_error__" )
var ( // ErrMetaKVMissing some keys or values are missing. ErrMetaKVMissing = errors.New("wrong metadata lines. some keys or values are missing") // 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. 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.
FreeMsg puts a msg into the pool.
PutData puts the byte slice into pool.
CompressType defines decompression type.
const ( // None does not compress. None CompressType = iota // Gzip uses gzip compression. Gzip )
Compressor defines a common compression interface.
type GzipCompressor struct { }
GzipCompressor implements gzip compressor.
func (c GzipCompressor) Unzip(data []byte) ([]byte, error)
func (c GzipCompressor) Zip(data []byte) ([]byte, error)
Header is the first part of Message and has fixed size. Format:
CheckMagicNumber checks whether header starts rpcx magic number.
func (h Header) CompressType() CompressType
CompressType returns compression type of messages.
IsHeartbeat returns whether the message is heartbeat message.
IsOneway returns whether the message is one-way message. If true, server won't send responses.
func (h Header) MessageStatusType() MessageStatusType
MessageStatusType returns the message status type.
func (h Header) MessageType() MessageType
MessageType returns the message type.
Seq returns sequence number of messages.
func (h Header) SerializeType() SerializeType
SerializeType returns serialization type of payload.
func (h *Header) SetCompressType(ct CompressType)
SetCompressType sets the compression type.
SetHeartbeat sets the heartbeat flag.
func (h *Header) SetMessageStatusType(mt MessageStatusType)
SetMessageStatusType sets message status type.
func (h *Header) SetMessageType(mt MessageType)
SetMessageType sets message type.
SetOneway sets the oneway flag.
SetSeq sets sequence number.
func (h *Header) SetSerializeType(st SerializeType)
SetSerializeType sets the serialization type.
SetVersion sets version for this header.
Version returns version of rpcx protocol.
type Message struct { *Header ServicePath string ServiceMethod string Metadata map[string]string Payload []byte // contains filtered or unexported fields }
Message is the generic type of Request and Response.
GetPooledMsg gets a pooled message.
NewMessage creates an empty message.
Read reads a message from r.
Clone clones from an message.
Decode decodes a message from reader.
Encode encodes messages.
EncodeSlicePointer encodes messages as a byte slice poiter we we can use pool to improve.
Reset clean data of this message but keep allocated data
WriteTo writes message to writers.
MessageStatusType is status of messages.
const ( // Normal is normal requests and responses. Normal MessageStatusType = iota // Error indicates some errors occur. Error )
MessageType is message type of requests and responses.
const ( // Request is message type of request Request MessageType = iota // Response is message type of response Response )
type RawDataCompressor struct { }
func (c RawDataCompressor) Unzip(data []byte) ([]byte, error)
func (c RawDataCompressor) Zip(data []byte) ([]byte, error)
SerializeType defines serialization type of payload.
const ( // SerializeNone uses raw []byte and don't serialize/deserialize SerializeNone SerializeType = iota // JSON for payload. JSON // ProtoBuffer for payload. ProtoBuffer // MsgPack for payload MsgPack // Thrift // Thrift for payload Thrift )
type SnappyCompressor struct { }
SnappyCompressor implements snappy compressor
func (c *SnappyCompressor) Unzip(data []byte) ([]byte, error)
func (c *SnappyCompressor) Zip(data []byte) ([]byte, error)
Package protocol imports 9 packages (graph) and is imported by 39 packages. Updated 2020-12-09. Refresh now. Tools for package owners.