message

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Request  byte = 0x00
	Notify        = 0x01
	Response      = 0x02
	Push          = 0x03
)

*

  • ==========================
  • Message Type Flags
  • ========================== *
  • ------------------------------------------
  • | type | flag | other |
  • |----------|--------|--------------------|
  • | request |----000-|<message id>|<route>|
  • | notify |----001-|<route> |
  • | response |----010-|<message id> |
  • | push |----011-|<route> |
  • ------------------------------------------ *

Variables

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

*

  • ==========================
  • Message Error Types
  • ========================== *
  • ErrWrongMessageType
  • ErrInvalidMessage
  • ErrRouteInfoNotFound *

Functions

func Encode

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: https://github.com/lonnng/nano/blob/master/docs/communication_protocol.md

Types

type Message

type Message struct {
	Type  byte   // message type
	ID    uint   // 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

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

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

func New

func New() *Message

New --

func (*Message) Encode

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

Encode --

func (*Message) String

func (m *Message) String() string

String --

Jump to

Keyboard shortcuts

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