nano: Index | Files

package message

import ""


Package Files

message.go util.go


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

Message types


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

Errors that could be occurred in message codec

func Encode Uses

func Encode(m *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:

func Serialize Uses

func Serialize(v interface{}) ([]byte, error)

func SetDictionary Uses

func SetDictionary(dict map[string]uint16)

SetDictionary set routes map which be used to compress route. TODO(warning): set dictionary in runtime would be a dangerous operation!!!!!!

type Message Uses

type Message struct {
    Type  Type   // message type
    ID    uint64 // unique id, zero while notify mode
    Route string // route for locating service
    Data  []byte // payload
    // contains filtered or unexported fields

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

func Decode Uses

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

Decode unmarshal the bytes slice to a message See ref:

func New Uses

func New() *Message

New returns a new message instance

func (*Message) Encode Uses

func (m *Message) Encode() ([]byte, error)

Encode marshals message to binary format.

func (*Message) String Uses

func (m *Message) String() string

String, implementation of fmt.Stringer interface

type Type Uses

type Type byte

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

func (Type) String Uses

func (t Type) String() string

Package message imports 6 packages (graph). Updated 2019-09-11. Refresh now. Tools for package owners.