v1

package
v0.0.0-...-83fd405 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PH              = 0
	SizeofMessageID = 2
)
View Source
const DefaultMinDispatchInterval = 100 * time.Millisecond

Variables

View Source
var (
	ByteOrder = binary.LittleEndian // 小端
)

Functions

This section is empty.

Types

type IMessage

type IMessage interface {
	proto.Message
	V1()
	MessageID() MessageID
	Size() int
	MarshalTo([]byte) (int, error)
	Unmarshal([]byte) error
	ResetEx()
	String() string
	Once() bool
	MinInterval() time.Duration
}

type IMessageDispatcher

type IMessageDispatcher interface {
	Register(id MessageID, handler MessageHandler)
	RegisterWithLimit(id MessageID, handler MessageHandler, minDispatchInterval time.Duration)
	Dispatch(iMsg IMessage, args ...interface{}) error
	SetLimit(id MessageID, minInterval time.Duration) error
}

func NewMessageDispatcher

func NewMessageDispatcher() IMessageDispatcher

type IMessageFactoryManager

type IMessageFactoryManager interface {
	Register(iMsg IMessage, producer messageProducer, recycler messageRecycler)
	Produce(id MessageID) (IMessage, error)
	Recycle(iMsg IMessage) error
	ReflectType(id MessageID) reflect.Type
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

func NewMessageFactoryManager

func NewMessageFactoryManager() IMessageFactoryManager

type IProtocol

type IProtocol interface {
	IMessageFactoryManager
	Alloc(size int) []byte
	Free(buffer []byte)
	Encrypt(data []byte) (err error)
	Decrypt(data []byte) (err error)
	EncodeTo(iMsg IMessage, data []byte) (err error)
	Encode(iMsg IMessage) (data []byte, err error)
	Decode(data []byte) (IMessage, error)
}

func New

func New(allocator p.IAllocator, encryptor p.IEncryptor, decryptor p.IDecryptor) IProtocol

type MessageDispatcher

type MessageDispatcher struct {
	Dispatchers map[MessageID]*OneMessageDispatcher
}

func (*MessageDispatcher) Dispatch

func (md *MessageDispatcher) Dispatch(iMsg IMessage, args ...interface{}) error

func (*MessageDispatcher) Register

func (md *MessageDispatcher) Register(id MessageID, handler MessageHandler)

func (*MessageDispatcher) RegisterWithLimit

func (md *MessageDispatcher) RegisterWithLimit(id MessageID, handler MessageHandler, minDispatchInterval time.Duration)

func (*MessageDispatcher) SetLimit

func (md *MessageDispatcher) SetLimit(id MessageID, minInterval time.Duration) error

type MessageHandler

type MessageHandler func(IMessage, ...interface{})

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

type MessageID

type MessageID = uint16

type OneMessageDispatcher

type OneMessageDispatcher struct {
	Handlers            []MessageHandler
	MinDispatchInterval time.Duration
	LastDispatchTime    time.Time
}

Jump to

Keyboard shortcuts

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