rpcx: github.com/smallnest/rpcx/protocol Index | Files

package protocol

import "github.com/smallnest/rpcx/protocol"

Index

Package Files

compressor.go message.go pool.go

Constants

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

Variables

var (
    // ErrMetaKVMissing some keys or values are mssing.
    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.

func FreeMsg Uses

func FreeMsg(msg *Message)

FreeMsg puts a msg into the pool.

func MagicNumber Uses

func MagicNumber() byte

type CompressType Uses

type CompressType byte

CompressType defines decompression type.

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

type Compressor Uses

type Compressor interface {
    Zip([]byte) ([]byte, error)
    Unzip([]byte) ([]byte, error)
}

Compressor defines a common compression interface.

type GzipCompressor Uses

type GzipCompressor struct {
}

GzipCompressor implements gzip compressor.

func (GzipCompressor) Unzip Uses

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

func (GzipCompressor) Zip Uses

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 Uses

func (h Header) CheckMagicNumber() bool

CheckMagicNumber checks whether header starts rpcx magic number.

func (Header) CompressType Uses

func (h Header) CompressType() CompressType

CompressType returns compression type of messages.

func (Header) IsHeartbeat Uses

func (h Header) IsHeartbeat() bool

IsHeartbeat returns whether the message is heartbeat message.

func (Header) IsOneway Uses

func (h Header) IsOneway() bool

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

func (Header) MessageStatusType Uses

func (h Header) MessageStatusType() MessageStatusType

MessageStatusType returns the message status type.

func (Header) MessageType Uses

func (h Header) MessageType() MessageType

MessageType returns the message type.

func (Header) Seq Uses

func (h Header) Seq() uint64

Seq returns sequence number of messages.

func (Header) SerializeType Uses

func (h Header) SerializeType() SerializeType

SerializeType returns serialization type of payload.

func (*Header) SetCompressType Uses

func (h *Header) SetCompressType(ct CompressType)

SetCompressType sets the compression type.

func (*Header) SetHeartbeat Uses

func (h *Header) SetHeartbeat(hb bool)

SetHeartbeat sets the heartbeat flag.

func (*Header) SetMessageStatusType Uses

func (h *Header) SetMessageStatusType(mt MessageStatusType)

SetMessageStatusType sets message status type.

func (*Header) SetMessageType Uses

func (h *Header) SetMessageType(mt MessageType)

SetMessageType sets message type.

func (*Header) SetOneway Uses

func (h *Header) SetOneway(oneway bool)

SetOneway sets the oneway flag.

func (*Header) SetSeq Uses

func (h *Header) SetSeq(seq uint64)

SetSeq sets sequence number.

func (*Header) SetSerializeType Uses

func (h *Header) SetSerializeType(st SerializeType)

SetSerializeType sets the serialization type.

func (*Header) SetVersion Uses

func (h *Header) SetVersion(v byte)

SetVersion sets version for this header.

func (Header) Version Uses

func (h Header) Version() byte

Version returns version of rpcx protocol.

type Message Uses

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 Uses

func GetPooledMsg() *Message

GetPooledMsg gets a pooled message.

func NewMessage Uses

func NewMessage() *Message

NewMessage creates an empty message.

func Read Uses

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

Read reads a message from r.

func (Message) Clone Uses

func (m Message) Clone() *Message

Clone clones from an message.

func (*Message) Decode Uses

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

Decode decodes a message from reader.

func (Message) Encode Uses

func (m Message) Encode() []byte

Encode encodes messages.

func (*Message) Reset Uses

func (m *Message) Reset()

Reset clean data of this message but keep allocated data

func (Message) WriteTo Uses

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

WriteTo writes message to writers.

type MessageStatusType Uses

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 Uses

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 Uses

type RawDataCompressor struct {
}

func (RawDataCompressor) Unzip Uses

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

func (RawDataCompressor) Zip Uses

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

type SerializeType Uses

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
)

Package protocol imports 7 packages (graph) and is imported by 18 packages. Updated 2019-08-27. Refresh now. Tools for package owners.