messages

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GateJsonMessageSetMsgHead added in v1.2.3

func GateJsonMessageSetMsgHead(msghead uint32) options

func GateJsonMessageSetMsgMaxLen added in v1.2.3

func GateJsonMessageSetMsgMaxLen(max uint16) options

func GateProtoMessageSetMsgHead added in v1.2.5

func GateProtoMessageSetMsgHead(msghead uint32) options

func GateProtoMessageSetMsgMaxLen added in v1.2.5

func GateProtoMessageSetMsgMaxLen(max uint16) options

func JsonMessageSetMsgHead

func JsonMessageSetMsgHead(msghead uint32) options

func JsonMessageSetMsgMaxLen

func JsonMessageSetMsgMaxLen(max uint16) options

Types

type GateChangeMsg added in v1.3.0

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

gate用来中转消息的结构

func (*GateChangeMsg) GetBuffByte added in v1.3.0

func (this *GateChangeMsg) GetBuffByte() *bytes.Buffer

func (*GateChangeMsg) SetBuffByte added in v1.3.0

func (this *GateChangeMsg) SetBuffByte(buff []byte)

type GateJsonMessageHandle added in v1.2.3

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

这个还没有完成

func GateJsonMessageHandleNew added in v1.2.3

func GateJsonMessageHandleNew(opts ...options) (msghandle *GateJsonMessageHandle)

func (*GateJsonMessageHandle) CheckMaxLenVaild added in v1.2.3

func (msghandle *GateJsonMessageHandle) CheckMaxLenVaild(buff []byte) (msglen uint32, ok bool)

一个消息是否收完了 返回这个消息应该的长度,和是否收完的信息

func (*GateJsonMessageHandle) GateMarshal added in v1.2.5

func (msghandle *GateJsonMessageHandle) GateMarshal(gate IGateMessage, data interface{}) ([]byte, error)

func (*GateJsonMessageHandle) GetRoute added in v1.2.3

func (msghandle *GateJsonMessageHandle) GetRoute(msgid uint32) (result interface{}, err error)

按消息拿出消息处理实例

func (*GateJsonMessageHandle) Marshal added in v1.2.3

func (msghandle *GateJsonMessageHandle) Marshal(msgid uint32, data interface{}) ([]byte, error)

编码

func (*GateJsonMessageHandle) SetRoute added in v1.2.3

func (msghandle *GateJsonMessageHandle) SetRoute(msgid uint32, msg interface{})

设置消息路由

func (*GateJsonMessageHandle) Unmarshal added in v1.2.3

func (msghandle *GateJsonMessageHandle) Unmarshal(buff []byte) (data interface{}, err error)

解码

type GateMessage added in v1.2.5

type GateMessage struct {
	MsgID    uint32 `json:"-"` //消息号
	MyID     uint32 `json:"-"` //消息源ID
	TargetID uint32 `json:"-"` //目标ID
}

func (*GateMessage) GateMarshal added in v1.3.0

func (msg *GateMessage) GateMarshal() ([]byte, uint32)

编码

func (*GateMessage) GateUnmarshal added in v1.3.0

func (msg *GateMessage) GateUnmarshal(buff []byte) ([]byte, uint32)

解码

func (*GateMessage) GetMsgID added in v1.2.5

func (msg *GateMessage) GetMsgID() uint32

func (*GateMessage) GetMyID added in v1.2.5

func (msg *GateMessage) GetMyID() uint32

func (*GateMessage) GetTargetID added in v1.2.5

func (msg *GateMessage) GetTargetID() uint32

func (*GateMessage) SetMsgID added in v1.2.5

func (msg *GateMessage) SetMsgID(msgid uint32)

func (*GateMessage) SetMyID added in v1.2.5

func (msg *GateMessage) SetMyID(myid uint32)

func (*GateMessage) SetTargetID added in v1.2.5

func (msg *GateMessage) SetTargetID(targetid uint32)

type GateProtoMessageHandle added in v1.2.5

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

func GateProtoMessageHandleNew added in v1.2.5

func GateProtoMessageHandleNew(opts ...options) (msghandle *GateProtoMessageHandle)

func (*GateProtoMessageHandle) CheckMaxLenVaild added in v1.2.5

func (msghandle *GateProtoMessageHandle) CheckMaxLenVaild(buff []byte) (msglen uint32, ok bool)

一个消息是否收完了 返回这个消息应该的长度,和是否收完的信息

func (*GateProtoMessageHandle) GateMarshal added in v1.2.5

func (msghandle *GateProtoMessageHandle) GateMarshal(gate IGateMessage, data interface{}) ([]byte, error)

func (*GateProtoMessageHandle) GetRoute added in v1.2.5

func (msghandle *GateProtoMessageHandle) GetRoute(msgid uint32) (result interface{}, err error)

按消息拿出消息处理实例

func (*GateProtoMessageHandle) Marshal added in v1.2.5

func (msghandle *GateProtoMessageHandle) Marshal(msgid uint32, data interface{}) ([]byte, error)

编码

func (*GateProtoMessageHandle) SetRoute added in v1.2.5

func (msghandle *GateProtoMessageHandle) SetRoute(msgid uint32, msg interface{})

设置消息路由

func (*GateProtoMessageHandle) Unmarshal added in v1.2.5

func (msghandle *GateProtoMessageHandle) Unmarshal(buff []byte) (data interface{}, err error)

解码

type HttpJsonMessageHandle

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

func HttpJsonMessageHandleNew

func HttpJsonMessageHandleNew(opts ...options) (msghandle *HttpJsonMessageHandle)

func (*HttpJsonMessageHandle) CheckMaxLenVaild

func (msghandle *HttpJsonMessageHandle) CheckMaxLenVaild(buff []byte) (msglen uint32, ok bool)

一个消息是否收完了 返回这个消息应该的长度,和是否收完的信息

func (*HttpJsonMessageHandle) GateMarshal added in v1.2.5

func (msghandle *HttpJsonMessageHandle) GateMarshal(gate IGateMessage, data interface{}) ([]byte, error)

func (*HttpJsonMessageHandle) GetRoute

func (msghandle *HttpJsonMessageHandle) GetRoute(msgid uint32) (result interface{}, err error)

按消息拿出消息处理实例

func (*HttpJsonMessageHandle) Marshal

func (msghandle *HttpJsonMessageHandle) Marshal(msgid uint32, data interface{}) ([]byte, error)

编码

func (*HttpJsonMessageHandle) SetRoute

func (msghandle *HttpJsonMessageHandle) SetRoute(msgid uint32, msg interface{})

设置消息路由

func (*HttpJsonMessageHandle) Unmarshal

func (msghandle *HttpJsonMessageHandle) Unmarshal(buff []byte) (data interface{}, err error)

解码

type IDataBaseMessage

type IDataBaseMessage interface {
	//所在DB协程
	DBThreadID() int
	/*数据表,如果你的表放入时,不是马上保存的,那么后续可以用这个KEY来进行覆盖,
	这样就可以实现多次修改一次保存的功能
	所以这个字段建议是:用户ID+数据表名+数据主键
	*/
	GetDataKey() string

	//调用方法
	SaveDB(conn model.IConnDB) error
}

DataBase的处理接口

type IGateChange added in v1.3.0

type IGateChange interface {
	//获取中转数据
	GetBuffByte() *bytes.Buffer
	//设置中转数据
	SetBuffByte(buff []byte)
}

type IGateMessage added in v1.2.5

type IGateMessage interface {

	// SetMsgID(msgid uint32)
	// SetMyID(myid uint32)
	// SetTargetID(targetid uint32)
	//编码,传出编码的数据和数据的长度
	GateMarshal() ([]byte, uint32)
	//解码,传入数据,传出使用后剩下的数据,和使用了多少字节
	GateUnmarshal(buff []byte) ([]byte, uint32)
}

路由消息接口

type IHttpMessageHandle

type IHttpMessageHandle interface {
	IMessage
	//HTTP的回调
	HttpDirectCall(w http.ResponseWriter, req *http.Request)
}

type ILogicMessage

type ILogicMessage interface {
	//所在协程的KEY
	LogicThreadID() int
	//调用方法
	MessageHandle()
}

LogicMessage 逻辑委托

type IMessage

type IMessage interface {
	GetAction() uint32
	SetAction(msgid uint32)
}

type IMessageHandle

type IMessageHandle interface {
	//带Gateway的编码
	GateMarshal(gate IGateMessage, data interface{}) ([]byte, error)
	//编码
	Marshal(msgid uint32, data interface{}) ([]byte, error)
	//解码
	Unmarshal(buff []byte) (data interface{}, err error)
	//设置消息路由
	SetRoute(msgid uint32, msg interface{})
	//按消息拿出消息处理实例
	GetRoute(msgid uint32) (result interface{}, err error)
	//一个消息是否收完了
	CheckMaxLenVaild(buff []byte) (msglen uint32, ok bool)
}

消息收发接口

type INsqMessageHandle

type INsqMessageHandle interface {
	INsqdResultMessage
	//Nsq的回调
	NsqDirectCall()
}

type INsqdResultMessage

type INsqdResultMessage interface {
	//消息
	IMessage
	//消息来源的用户ID
	GetSendUserID() int
	//消息来源的服务ID
	GetSendSID() string
	//设置来源服务ID
	SetSendSID(sid string)
	//目标服务器ID
	GetTopic() string
}

type ISocketMessageHandle

type ISocketMessageHandle interface {
	ISocketResultMessage
	//socket的回调
	SocketDirectCall(ws *SocketModel)
}

type ISocketResultMessage

type ISocketResultMessage interface {
	//消息
	IMessage
	//消息来源的用户ID
	GetSendUserID() int
	//消息来源的服务ID
	GetSendSID() string
	//设置来源服务ID
	SetSendSID(sid string)
	//目标服务器ID
	GetTopic() string
}

type IWebSocketMessageHandle

type IWebSocketMessageHandle interface {
	IMessage
	//ws的回调
	WebSocketDirectCall(ws *WebSocketModel)
}

type JsonArray added in v1.2.2

type JsonArray []interface{}

JsonArray JSON数组

func (JsonArray) GetArray added in v1.2.2

func (js JsonArray) GetArray(index int) JsonArray

func (JsonArray) GetIntArray added in v1.2.2

func (js JsonArray) GetIntArray() []int

func (JsonArray) GetMap added in v1.2.2

func (js JsonArray) GetMap(index int) JsonMap

type JsonMap added in v1.2.2

type JsonMap map[string]interface{}

JsonMap 收到的JSON数据

func (JsonMap) GetAction added in v1.2.2

func (js JsonMap) GetAction() uint32

GetAction 消息号

func (JsonMap) GetActionKey added in v1.2.2

func (js JsonMap) GetActionKey() int

GetActionKey int32 //消息序号

func (JsonMap) GetArray added in v1.2.2

func (js JsonMap) GetArray(key string) JsonArray

返回一个JsonArray

func (JsonMap) GetHash added in v1.2.2

func (js JsonMap) GetHash() string

GetHash string //发回给用户信息用的钥匙

func (JsonMap) GetIntArray added in v1.2.2

func (js JsonMap) GetIntArray(key string) []int

返回[]int

func (JsonMap) GetMap added in v1.2.2

func (js JsonMap) GetMap(key string) JsonMap

返回一个JsonMap

func (JsonMap) GetMemberID added in v1.2.2

func (js JsonMap) GetMemberID() int

GetMemberID int32 //用户ID

type JsonMessageHandle

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

func JsonMessageHandleNew

func JsonMessageHandleNew(opts ...options) (msghandle *JsonMessageHandle)

func (*JsonMessageHandle) CheckMaxLenVaild

func (msghandle *JsonMessageHandle) CheckMaxLenVaild(buff []byte) (msglen uint32, ok bool)

一个消息是否收完了 返回这个消息应该的长度,和是否收完的信息

func (*JsonMessageHandle) GateMarshal added in v1.2.5

func (msghandle *JsonMessageHandle) GateMarshal(gate IGateMessage, data interface{}) ([]byte, error)

给gate发消息的编码

func (*JsonMessageHandle) GetRoute

func (msghandle *JsonMessageHandle) GetRoute(msgid uint32) (result interface{}, err error)

按消息拿出消息处理实例

func (*JsonMessageHandle) Marshal

func (msghandle *JsonMessageHandle) Marshal(msgid uint32, data interface{}) ([]byte, error)

编码

func (*JsonMessageHandle) SetRoute

func (msghandle *JsonMessageHandle) SetRoute(msgid uint32, msg interface{})

设置消息路由

func (*JsonMessageHandle) Unmarshal

func (msghandle *JsonMessageHandle) Unmarshal(buff []byte) (data interface{}, err error)

解码

type LogicMessage

type LogicMessage struct {
	UserID int `json:"-"`
}

func (*LogicMessage) LogicThreadID

func (msg *LogicMessage) LogicThreadID() int

func (*LogicMessage) MessageHandle added in v1.2.2

func (msg *LogicMessage) MessageHandle()

调用方法

type Message added in v1.3.0

type Message struct {
	ActionID uint32 `json:"ACTIONID"` //消息号
}

func (*Message) GetAction added in v1.3.0

func (msg *Message) GetAction() uint32

func (*Message) SetAction added in v1.3.0

func (msg *Message) SetAction(msgid uint32)

type MessageJson added in v1.3.0

type MessageJson struct {
	ActionID uint32 `json:"ACTIONID"`
}

type NsqdMessage

type NsqdMessage struct {
	Message
	SendUserID int    `json:"SENDUID"` //发信息用户ID
	SendSID    string `json:"SENDSID"` //发信息服务器(回复用的信息)
	Topic      string `json:"TOPIC"`   //目标
}

nsqd消息的基础结构

func (*NsqdMessage) GetSendSID

func (msg *NsqdMessage) GetSendSID() string

func (*NsqdMessage) GetSendUserID

func (msg *NsqdMessage) GetSendUserID() int

func (*NsqdMessage) GetTopic

func (msg *NsqdMessage) GetTopic() string

func (*NsqdMessage) SetSendSID

func (msg *NsqdMessage) SetSendSID(sid string)

type ScoketMessage added in v1.2.2

type ScoketMessage struct {
	Message
	SendUserID int    `json:"SENDUID"` //发信息用户ID
	SendSID    string `json:"SENDSID"` //发信息服务器(回复用的信息)
	Topic      string `json:"TOPIC"`   //目标
}

func (*ScoketMessage) GetSendSID added in v1.2.2

func (msg *ScoketMessage) GetSendSID() string

func (*ScoketMessage) GetSendUserID added in v1.2.2

func (msg *ScoketMessage) GetSendUserID() int

func (*ScoketMessage) GetTopic added in v1.2.2

func (msg *ScoketMessage) GetTopic() string

func (*ScoketMessage) SetSendSID added in v1.2.2

func (msg *ScoketMessage) SetSendSID(sid string)

type SocketModel

type SocketModel struct {
	Conn     net.Conn                //连接信息
	CloseFun func(skmd *SocketModel) //关闭连接时的方法
	ConInfo  interface{}             //自定义的连接信息,给上层逻辑使用
	KeyID    int                     //用来标记的ID
}

SocketModel 用户连接对象

type WebMessage added in v1.2.2

type WebMessage struct {
	Message
	MemberID int `json:"MEMBERID"`
}

func (*WebMessage) HttpDirectCall added in v1.2.2

func (msg *WebMessage) HttpDirectCall(w http.ResponseWriter, req *http.Request)

HTTP的回调

type WebScoketMessage added in v1.2.2

type WebScoketMessage struct {
	Message
	MemberID int    `json:"MEMBERID"`
	Hash     string `json:"HASH"`
}

func (*WebScoketMessage) WebSocketDirectCall added in v1.2.2

func (msg *WebScoketMessage) WebSocketDirectCall(ws *WebSocketModel)

ws的回调

type WebSocketModel

type WebSocketModel struct {
	Conn     *websocket.Conn
	CloseFun func(wsmd *WebSocketModel) //关闭连接时的方法
	ConInfo  interface{}                //自定义的连接信息,给上层逻辑使用
	KeyID    int                        //用来标记的ID
}

WebSocketModel 用户连接对象

func (*WebSocketModel) SendByte added in v1.2.4

func (ws *WebSocketModel) SendByte(data []byte) error

发的是二进制数据

func (*WebSocketModel) SendStr added in v1.2.4

func (ws *WebSocketModel) SendStr(data string) error

发的是字符串

Jump to

Keyboard shortcuts

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