message

package
v0.0.0-...-242f3d8 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2020 License: Apache-2.0 Imports: 9 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMessagePointerRequired represents an error require a pointer.
	ErrMessagePointerRequired = errors.New("message pointer required")
	// ErrUnnamedMessage represent an error that register message with an empty name.
	ErrUnnamedMessage = errors.New("Unnamed message")
)

Functions

This section is empty.

Types

type Meta

type Meta interface {
	// ID return message ID
	ID() interface{}

	// CreateInstance returns the zero value as an interface{} of the Meta's type
	CreateInstance() interface{}

	// SetCodec enable special codec for some protocol message.
	// If an codec is specified for meta,it will use the setted codec and ignore common codec setting
	SetCodec(c encoding.Codec)

	// Codec returns setted codec
	// It returns nil if codec not setted.
	Codec() encoding.Codec
}

Meta stores the information of a application layer's registered message. such as packetID, codec and the type information of stored message.

type MsgID2ProcessorMap

type MsgID2ProcessorMap map[interface{}]*Processor

MsgID2ProcessorMap is an map which holds the mapping relation of message ID and its processor.

type Packet

type Packet interface {
	ID() interface{}
	Payload() interface{}
}

Packet represents the serialized form of a network message.

the structure of a packet defined in nginet:

  • Length: Represents the length of the whole packet in byte array.

  • PacketID: The application layer defines the mapping of packet ID, one packetID one network message.

  • msg_payload: The payload of the packet.

    Packet --------------|-------------|--------------- | Length | PacketID | msg_payload | --------------|-------------|---------------

type PacketIDParser

type PacketIDParser interface {
	// SetByteOrder specifies how to convert byte sequences into
	// 16-bit, 32-bit, or 64-bit unsigned integers.
	SetByteOrder(order binary.ByteOrder) PacketIDParser

	IDLen() int

	// Encode encodes the packet ID to bytes array.
	Encode(packetID interface{}, buf bytes.WriteOnlyBuffer) error

	// Decode decodes a packet ID from bytes array.
	Decode(rob bytes.ReadOnlyBuffer) (interface{}, error)
}

PacketIDParser represents the parser to encode&decode a packet ID.

type Processor

type Processor struct {
	// contains filtered or unexported fields
}

Processor represents a wrapper of the msgID with processor callback.

func (*Processor) Call

func (p *Processor) Call(ctx *core.ChannelContext, msg interface{}, args ...interface{})

Call calls the handler function with ctx and msg as parameters. Not safe

func (*Processor) SafeCall

func (p *Processor) SafeCall(ctx *core.ChannelContext, msg interface{}, args ...interface{})

type ProcessorFunc

type ProcessorFunc func(ctx *core.ChannelContext, msg interface{}, args ...interface{})

type ProcessorMgr

type ProcessorMgr interface {
	RegisterProcessor(msg interface{}, h ProcessorFunc) error
	RegisterProcessorByID(msgID interface{}, hf ProcessorFunc) error
	GetProcessorByID(msgID interface{}) *Processor
}

func NewProcessorMgr

func NewProcessorMgr(register Register) ProcessorMgr

NewProcessorMgr creates a new ProcessorMgr instance and returns the pointer.

type Register

type Register interface {
	RegisterMsg(msg interface{}) (meta Meta)
	RegisterMsgByID(assignID interface{}, msg interface{}) Meta
	GetMetaByMsg(msg interface{}) Meta
	GetMetaByID(id interface{}) Meta
}

func NewRegister

func NewRegister() Register

NewRegister creates a new register instance and return the pointer.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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