protocol

package
v6.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2021 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// ServiceError contains error info of service invocation
	ServiceError = "__rpcx_error__"
)

Variables

View Source
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")
)
View Source
var (
	// Compressors are compressors supported by rpcx. You can add customized compressor in Compressors.
	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.

Functions

func FreeMsg

func FreeMsg(msg *Message)

FreeMsg puts a msg into the pool.

func MagicNumber

func MagicNumber() byte

func PutData

func PutData(data *[]byte)

PutData puts the byte slice into pool.

Types

type CompressType

type CompressType byte

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
	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)

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

Decode decodes a message from reader.

func (Message) Encode

func (m Message) Encode() []byte

Encode encodes messages.

func (Message) EncodeSlicePointer

func (m Message) EncodeSlicePointer() *[]byte

EncodeSlicePointer encodes messages as a byte slice poiter we we can use pool to improve.

func (*Message) Reset

func (m *Message) Reset()

Reset clean data of this message but keep allocated data

func (Message) WriteTo

func (m Message) WriteTo(w io.Writer) (int64, 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 responses.

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
	SerializeNone SerializeType = iota
	// JSON for payload.
	JSON
	// ProtoBuffer for payload.
	ProtoBuffer
	// MsgPack for payload
	MsgPack
	// Thrift
	// Thrift for payload
	Thrift
)

type SnappyCompressor

type SnappyCompressor struct {
}

SnappyCompressor implements snappy compressor

func (*SnappyCompressor) Unzip

func (c *SnappyCompressor) Unzip(data []byte) ([]byte, error)

func (*SnappyCompressor) Zip

func (c *SnappyCompressor) Zip(data []byte) ([]byte, error)

Jump to

Keyboard shortcuts

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