message

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrWrongMessageType  = errors.New("wrong message type")
	ErrInvalidMessage    = errors.New("invalid message")
	ErrRouteInfoNotFound = errors.New("route info not found in dictionary")
)

Errors that could be occurred in message codec

Functions

func GetDictionary

func GetDictionary() map[string]uint16

GetDictionary gets the routes map which is used to compress route.

func SetDictionary

func SetDictionary(dict map[string]uint16) error

SetDictionary set routes map which be used to compress route.

Types

type Encoder

type Encoder interface {
	IsCompressionEnabled() bool
	Encode(message *Message) ([]byte, error)
}

Encoder interface

type Message

type Message struct {
	Type  Type   // message type
	ID    uint   // unique id, zero while notify mode
	Route string // route for locating service
	Data  []byte // payload

	Err bool // is an error message
	// contains filtered or unexported fields
}

Message represents a unmarshaled message or a message which to be marshaled

func Decode

func Decode(data []byte) (*Message, error)

Decode unmarshal the bytes slice to a message See ref: https://github.com/topfreegames/pitaya/blob/master/docs/communication_protocol.md

func New

func New(err ...bool) *Message

New returns a new message instance

func (*Message) String

func (m *Message) String() string

String, implementation of fmt.Stringer interface

type MessagesEncoder

type MessagesEncoder struct {
	DataCompression bool
}

MessagesEncoder implements MessageEncoder interface

func NewMessagesEncoder

func NewMessagesEncoder(dataCompression bool) *MessagesEncoder

NewMessagesEncoder returns a new message encoder

func (*MessagesEncoder) Decode

func (me *MessagesEncoder) Decode(data []byte) (*Message, error)

Decode decodes the message

func (*MessagesEncoder) Encode

func (me *MessagesEncoder) Encode(message *Message) ([]byte, error)

Encode marshals message to binary format. Different message types is corresponding to different message header, message types is identified by 2-4 bit of flag field. The relationship between message types and message header is presented as follows: ------------------------------------------ | type | flag | other | |----------|--------|--------------------| | request |----000-|<message id>|<route>| | notify |----001-|<route> | | response |----010-|<message id> | | push |----011-|<route> | ------------------------------------------ The figure above indicates that the bit does not affect the type of message. See ref: https://github.com/topfreegames/pitaya/blob/master/docs/communication_protocol.md

func (*MessagesEncoder) IsCompressionEnabled

func (me *MessagesEncoder) IsCompressionEnabled() bool

IsCompressionEnabled returns wether the compression is enabled or not

type Type

type Type byte

Type represents the type of message, which could be Request/Notify/Response/Push

const (
	Request  Type = 0x00
	Notify   Type = 0x01
	Response Type = 0x02
	Push     Type = 0x03
)

Message types

func (*Type) String

func (t *Type) String() string

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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