message

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: May 16, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	PublicTopic = NewTopic("")
	// 用户保留主题 不会进行广播
	InnerTopic = NewTopic("inner")
	// 系统保留主题 不会触发任何注册的回调函数
	SysTopic = NewTopic("sys")
)
View Source
var (
	TopicBase = SysTopic.Child("base")
	// 日志
	TopicSysLog = TopicBase.Child("log")
	// 连接权限验证
	TopicAuth = TopicBase.Child("auth")
)
View Source
var (
	TopicTopic = SysTopic.Child("topic")
	// 订阅指令
	TopicSubscribe = TopicTopic.Child("subscribe")
	// 取消订阅指令
	TopicCancel = TopicTopic.Child("cancel")
	// 取消所有订阅指令
	TopicCancelAll = TopicTopic.Child("cancel_all")
	// 敏感操作 需要通过判定
	TopicSubscribeAll = TopicTopic.Child("subscribe_all/admin")
	TopicGetAllTopics = TopicTopic.Child("get_all_topics/admin")
	TopicGetAllNodes  = TopicTopic.Child("get_all_nodes/admin")
	TopicStopNode     = TopicTopic.Child("stop_node/admin")
)
View Source
var (
	TopicCluster = SysTopic.Child("cluster")
	// 三次同步过程建立节点连接
	TopicClusterLateral  = TopicCluster.Child("lateral")
	TopicClusterSuperior = TopicCluster.Child("superior")
	TopicClusterInfo     = TopicCluster.Child("info")
	TopicClusterRedirect = TopicCluster.Child("redirect")
)
View Source
var (
	ErrNotAllowedTopic = errors.New("this topic is not allowed to subscribe or publish")
	ErrUnformedMsg     = errors.New("unformed Msg")
)
View Source
var DefaultMsgPrefix = []byte("ws")
View Source
var InvalidMessage = errors.New("invalid message")
View Source
var InvalidTopic = errors.New("invalid topic")

Functions

func IsInnerTopic

func IsInnerTopic(t Topic) bool

func IsPublicTopic

func IsPublicTopic(t Topic) bool

func IsSysTopic

func IsSysTopic(t Topic) bool

func MsgTypeName added in v0.2.3

func MsgTypeName(m MsgType) string

Types

type Func added in v0.2.2

type Func interface{}

A callback which should receives one parameter of type string, int, bool or any valid JSON/Go struct

type FuncBlank added in v0.2.2

type FuncBlank = func()

type FuncBool added in v0.2.2

type FuncBool = func(bool)

type FuncBytes added in v0.2.2

type FuncBytes = func([]byte)

type FuncDefault added in v0.2.2

type FuncDefault = func(interface{})

type FuncError added in v0.2.4

type FuncError = func(error)

type FuncInt added in v0.2.2

type FuncInt = func(int)

type FuncString added in v0.2.2

type FuncString = func(string)

type FuncTransfer added in v0.2.3

type FuncTransfer = func([]byte, string, string)

type MsgType added in v0.2.2

type MsgType = byte
const (
	MsgTypeString MsgType = '0'
	MsgTypeInt    MsgType = '1'
	MsgTypeBool   MsgType = '2'
	MsgTypeBytes  MsgType = '3'
	MsgTypeJSON   MsgType = '4'
)

The same values are exists on client side too.

type Publisher added in v0.2.4

type Publisher interface {
	// Pub sends a message on a particular topic
	Pub(interface{})
}

Publisher is the message manager

type Serializer

type Serializer struct {
	// contains filtered or unexported fields
}

func NewSerializer

func NewSerializer(messagePrefix []byte) *Serializer

格式: prefix(n)type(1)random_tag(4)source_idx(4)target_topic;msg

func (*Serializer) Deserialize

func (ms *Serializer) Deserialize(websocketMessage []byte) (interface{}, error)

deserialize deserializes a custom websocket message from the client such as prefix;topic;0;abc_msg Supported data types are: string, int, bool, bytes and JSON. 格式: prefix(n)type(1)random_tag(4)source_idx(4)target_topic;msg

func (*Serializer) GetMsgTopic

func (ms *Serializer) GetMsgTopic(websocketMessage []byte) Topic

getWebsocketCustomEvent return empty string when the websocketMessage is native message 格式: prefix(n)type(1)random_tag(4)source_idx(4)target_topic;msg

func (*Serializer) GetMsgType added in v0.2.4

func (ms *Serializer) GetMsgType(msg []byte) MsgType

func (*Serializer) GetRandomID added in v0.2.4

func (ms *Serializer) GetRandomID(msg []byte) uint32

func (*Serializer) GetSourceID added in v0.2.4

func (ms *Serializer) GetSourceID(msg []byte) uint32

格式: prefix(n)type(1)random_tag(4)source_idx(4)target_topic;msg

func (*Serializer) Prefix added in v0.2.5

func (ms *Serializer) Prefix() []byte

func (*Serializer) ResetRandomTag added in v0.2.4

func (ms *Serializer) ResetRandomTag(msg []byte, randomTag int)

func (*Serializer) ResetSourceID added in v0.2.4

func (ms *Serializer) ResetSourceID(msg []byte, sourceId int)

func (*Serializer) Serialize

func (ms *Serializer) Serialize(t Topic, data interface{}) ([]byte, error)

格式: prefix(n)type(1)random_tag(4)source_idx(4)target_topic;msg

type Subscriber added in v0.2.4

type Subscriber interface {
	Do(data interface{})
	Valid() bool
	SetMax(uint)
	SetOnce()
	Cancel()
}

type SubscriberList added in v0.2.4

type SubscriberList interface {
	Add(callback Func) Subscriber
	Range(func(s Subscriber))
	Len() int
}

func NewSubscriberList added in v0.2.4

func NewSubscriberList() SubscriberList

type Topic

type Topic interface {
	String() string
	Bytes() []byte
	FirstFragment() string
	Fragment(int) string
	Since(int) string
	Child(string) Topic
	IsChildOf(p Topic) bool
	Len() int
}

func NewTopic

func NewTopic(t string) Topic

Jump to

Keyboard shortcuts

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