handler

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: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ExtraMsgLength defines the max length of extra message
	// ExtraMsgLength = ExtraMsgFlagLength + extra message ID length + extra message body length.
	ExtraMsgLength = 4

	// ExtraMsgFlagLength defines 4 as the extra message flag to avoid repeat with Msg ID.
	ExtraMsgFlagLength = 4

	// ExtraMsgFlag depends on ExtraMsgFlagLength, the max value can be describes by ExtraMsgFlagLength bytes.
	ExtraMsgFlag = 2 ^ (ExtraMsgFlagLength * 8) - 1
)
View Source
const (
	ReadTimeout  = iota
	WriteTimeout = iota
	AllTimeout   = iota
)
View Source
const (
	MaxPacketLen = 8
	MaxExtraLen  = 8
)

Variables

View Source
var (
	ErrFrameTooLong     = errors.New("LengthFieldBasedFrameDecoder: frame too long")
	ErrInBoundEventType = errors.New("Invalid type for OnInboundEvent args")
	ErrInBoundMsgID     = errors.New("Invalid id for OnInboundEvent msg")
	ErrInBoundRPCSeq    = errors.New("Invalid rpc seq for OnInboundEvent msg")
	ErrNoMetaFound      = errors.New("No meta found")
)
View Source
var ErrOutBoundEventType = errors.New("Invalid type for OnOutboundEvent args")

Functions

This section is empty.

Types

type CombinedDecoder

type CombinedDecoder struct {
	*core.DefaultInboundHandler
	// contains filtered or unexported fields
}

func NewCombinedDecoder

func NewCombinedDecoder(messageDeserializer *MessageDeserializer, idParser *IDParser) *CombinedDecoder

func (*CombinedDecoder) OnRead

func (cd *CombinedDecoder) OnRead(ctx *core.ChannelContext, msg interface{})

type CombinedEncoder

type CombinedEncoder struct {
	*core.DefaultOutboundHandler
	// contains filtered or unexported fields
}

func NewCombinedEncoder

func NewCombinedEncoder(messageSerializer *MessageSerializer, idParser *IDParser) *CombinedEncoder

func (*CombinedEncoder) OnWrite

func (ce *CombinedEncoder) OnWrite(ctx *core.ChannelContext, msg interface{})

type DefaultMessageHandler

type DefaultMessageHandler struct {
	*core.DefaultInboundHandler
	// contains filtered or unexported fields
}

DefaultMessageHandler represents a default implementation of MessageHandler.

func NewDefaultMessageHandler

func NewDefaultMessageHandler(mgr message.ProcessorMgr) *DefaultMessageHandler

NewDefaultMessageHandler creates and return a pointer to the instance of DefaultMessageHandler

func (*DefaultMessageHandler) OnRead

func (mh *DefaultMessageHandler) OnRead(ctx *core.ChannelContext, msg interface{})

OnRead InboundHandler

type IDParser

type IDParser struct {
	*core.DefaultInboundHandler
	*core.DefaultOutboundHandler
	// contains filtered or unexported fields
}

IDParser parses message ID.

func NewIDParser

func NewIDParser(register message.Register, parser message.PacketIDParser) *IDParser

NewIDParser creates new IDParser instance.

func (*IDParser) DecodeID

func (ip *IDParser) DecodeID(msg bytes.ReadOnlyBuffer) (interface{}, bytes.ReadOnlyBuffer, error)

func (*IDParser) EncodeID

func (ip *IDParser) EncodeID(msg interface{}) (bytes.WriteOnlyBuffer, interface{}, error)

func (*IDParser) OnConnect

func (ip *IDParser) OnConnect(ctx *core.ChannelContext, channel core.Channel)

func (*IDParser) OnDisconnect

func (ip *IDParser) OnDisconnect(ctx *core.ChannelContext)

OnDisconnect called when channel disconnected.

func (*IDParser) OnRead

func (ip *IDParser) OnRead(ctx *core.ChannelContext, msg interface{})

OnRead implements InboundHandler

func (*IDParser) OnWrite

func (ip *IDParser) OnWrite(ctx *core.ChannelContext, msg interface{})

OnWrite implements OutboundHandler outputs:

an array arr
	arr[0] is bytes.WriteOnlyBuffer with message ID.
	arr[1] is original message object.

type IdleEvent

type IdleEvent struct {
	TimeoutType int
}

type IdleStateHandler

type IdleStateHandler struct {
	*core.DefaultInboundHandler
	*core.DefaultOutboundHandler
	// contains filtered or unexported fields
}

func NewIdleStateHandler

func NewIdleStateHandler(readTimeoutSec, writeTimeoutSec int, needAllTimeout bool) *IdleStateHandler

func (*IdleStateHandler) OnConnect

func (ish *IdleStateHandler) OnConnect(ctx *core.ChannelContext, channel core.Channel)

func (*IdleStateHandler) OnDisconnect

func (ish *IdleStateHandler) OnDisconnect(ctx *core.ChannelContext)

func (*IdleStateHandler) OnRead

func (ish *IdleStateHandler) OnRead(ctx *core.ChannelContext, msg interface{})

func (*IdleStateHandler) OnWrite

func (ish *IdleStateHandler) OnWrite(ctx *core.ChannelContext, msg interface{})

type MessageDecoder

type MessageDecoder struct {
	*core.DefaultInboundHandler
	// contains filtered or unexported fields
}

MessageDecoder deserializers packet, and *io.Buffer is required for type of input message.

func NewMessageDecoder

func NewMessageDecoder(messageDeserializer *MessageDeserializer, idParser *IDParser) *MessageDecoder

NewMessageDecoder creates new MessageDecoder instance.

func (*MessageDecoder) OnRead

func (md *MessageDecoder) OnRead(ctx *core.ChannelContext, msg interface{})

OnRead ipdlements InboundHandler.

type MessageDeserializer

type MessageDeserializer struct {
	*core.DefaultInboundHandler
	// contains filtered or unexported fields
}

func NewMessageDeserializer

func NewMessageDeserializer(register message.Register, codec encoding.Codec) *MessageDeserializer

func (*MessageDeserializer) DecodePayload

func (md *MessageDeserializer) DecodePayload(msgID interface{}, data bytes.ReadOnlyBuffer) (interface{}, error)

func (*MessageDeserializer) OnRead

func (md *MessageDeserializer) OnRead(ctx *core.ChannelContext, msg interface{})

OnRead ipdlements InboundHandler.

type MessageEncoder

type MessageEncoder struct {
	*core.DefaultOutboundHandler
	// contains filtered or unexported fields
}

MessageEncoder serializes packet. If input message is raw data, codec operation will be aborted.

func NewMessageEncoder

func NewMessageEncoder(messageSerializer *MessageSerializer, idParser *IDParser) *MessageEncoder

NewMessageEncoder creates new MessageEncoder instance.

func (*MessageEncoder) OnWrite

func (me *MessageEncoder) OnWrite(ctx *core.ChannelContext, msg interface{})

type MessageSerializer

type MessageSerializer struct {
	*core.DefaultOutboundHandler
	// contains filtered or unexported fields
}

func NewMessageSerializer

func NewMessageSerializer(register message.Register, codec encoding.Codec) *MessageSerializer

NewMessageSerializer creates new PacketSerializer instance.

func (*MessageSerializer) EncodePayload

func (ms *MessageSerializer) EncodePayload(bufWithID bytes.WriteOnlyBuffer, msg interface{}, msgID interface{}) error

func (*MessageSerializer) OnWrite

func (ms *MessageSerializer) OnWrite(ctx *core.ChannelContext, msg interface{})

type PacketLengthDecoder

type PacketLengthDecoder struct {
	*core.DefaultInboundHandler
	// contains filtered or unexported fields
}

transport layer message format, append size information to the head of Packet.

	size: segment size
 id_header: msg id,defined by logic
 msg_payload: msg content

					Segment

--------------|--------------|-------------- | length | id_header | msg_payload | --------------|--------------|--------------

binary data decoder based on head size and payload body netty-like PacketLengthDecoder

func NewPacketLengthDecoder

func NewPacketLengthDecoder(sizeOfLengthField uint) *PacketLengthDecoder

NewPacketLengthDecoder return new LengthFieldBasedFrameDecoder

maxFrameLength: max size of msg
lengthFieldOffset: the location of "lenght field" need offset
lengthFieldLength: the length of "lenght field"
initialBytesToStrip: how many bytes need to be strip before delivering to next processor

func (*PacketLengthDecoder) OnRead

func (pld *PacketLengthDecoder) OnRead(ctx *core.ChannelContext, msg interface{})

OnRead implements OutboundHandler.

func (*PacketLengthDecoder) SetByteOrder

func (pld *PacketLengthDecoder) SetByteOrder(byteorder binary.ByteOrder) *PacketLengthDecoder

SetByteOrder Set byte order, default is binary.BigEndian

byteorder:
	binary.BigEndian
	binary.LittleEndian

func (*PacketLengthDecoder) SetInitialBytesToStrip

func (pld *PacketLengthDecoder) SetInitialBytesToStrip(initialBytesToStrip uint) *PacketLengthDecoder

SetInitialBytesToStrip set the number to skip when pass to next processor.

func (*PacketLengthDecoder) SetLengthFieldOffset

func (pld *PacketLengthDecoder) SetLengthFieldOffset(lengthFieldOffset uint) *PacketLengthDecoder

SetLengthFieldOffset set the offset of length field, previous value maybe version or other value.

func (*PacketLengthDecoder) SetMaxFrameLength

func (pld *PacketLengthDecoder) SetMaxFrameLength(maxFrameLength uint64) *PacketLengthDecoder

SetMaxFrameLength set the max value of package length.

type PacketLengthPrepender

type PacketLengthPrepender struct {
	*core.DefaultOutboundHandler
	// contains filtered or unexported fields
}

transport layer message format, append size information to the head of Packet.

	size: segment size
 id_header: msg id,defined by logic
 msg_payload: msg content

					Segment

--------------|--------------|-------------- | length | msg serialized payload | --------------|--------------|--------------

binary data encoder will append packet length to the header. netty-like PacketLengthPrepender

func NewPacketLengthPrepender

func NewPacketLengthPrepender(lengthFieldLength uint) *PacketLengthPrepender

func (*PacketLengthPrepender) OnWrite

func (plp *PacketLengthPrepender) OnWrite(ctx *core.ChannelContext, msg interface{})

OnOutboundEvent process outbound event.

func (*PacketLengthPrepender) SetByteOrder

func (plp *PacketLengthPrepender) SetByteOrder(byteorder binary.ByteOrder) *PacketLengthPrepender

SetByteOrder Set byte order, default is binary.BigEndian

byteorder:
	binary.BigEndian
	binary.LittleEndian

type Rc4Cipher

type Rc4Cipher struct {
	*core.DefaultInboundHandler
	*core.DefaultOutboundHandler
	// contains filtered or unexported fields
}

func NewRc4Cipher

func NewRc4Cipher(key string) *Rc4Cipher

func (*Rc4Cipher) OnRead

func (rc *Rc4Cipher) OnRead(ctx *core.ChannelContext, msg interface{})

func (*Rc4Cipher) OnWrite

func (rc *Rc4Cipher) OnWrite(ctx *core.ChannelContext, msg interface{})

type StringEncoder

type StringEncoder struct {
	*core.DefaultInboundHandler
	*core.DefaultOutboundHandler
}

func NewStringEncoder

func NewStringEncoder() *StringEncoder

func (*StringEncoder) OnRead

func (sc *StringEncoder) OnRead(ctx *core.ChannelContext, msg interface{})

func (*StringEncoder) OnWrite

func (sc *StringEncoder) OnWrite(ctx *core.ChannelContext, msg interface{})

Jump to

Keyboard shortcuts

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