1 Star 0 Fork 26

指尖-网站开发/wsPool

forked from ryanduan/wsPool 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
private.go 1.51 KB
一键复制 编辑 原始数据 按行查看 历史
ryanduan 提交于 2020-11-24 16:39 . 修复bug
package wsPool
import (
"github.com/golang/protobuf/proto"
)
/*
client连接对象的私有方法
*/
func dump() {
rcv_err := recover()
if rcv_err == nil {
return
}
wsSever.ErrFun(rcv_err)
//log.Error("运行过程中出现异常,错误信息如下:",rcv_err)
}
/*
如果消息指定发送的目标连接ToClientId的对象与指定广播的频道Channel在同一频道时,只进行广播就行了
消息体格式使用protobuf进行交互
*/
/*type SendMsg struct {
Cmd int32
Timestamp int64
FromClientId string //消息的来源id
ToClientId string //消息指定发送的目标连接id
CmdData []byte
MsgId string
Status int32
CallbackMsg string
Cmdkey string
Priority int32
PageKey string
Channel []int32 //指定广播的频道
PageId string
}
*/
// 将发送的对象转为protobuf结果
func marshal(msg *SendMsg) ([]byte, error) {
return proto.Marshal(msg) // msg.Marshal()
/*data, err :=proto.Marshal(msg)// msg.Marshal()
defer func() {
msg.Reset()
proto.ClearAllExtensions(msg)
data=nil
msg=nil
}()
return data, err*/
}
// 将取到的protobuf的数据转换成发送对象
func unMarshal(data []byte) (*SendMsg, error) {
msg := &SendMsg{}
err := proto.Unmarshal(data, msg)
if err != nil {
return nil, err
}
defer func() {
data = nil
}()
return msg, err
}
func searchStrArray(arr []string, ch string) bool {
result := -1
for index, v := range arr {
if v == ch {
result = index
break
}
}
return result != -1
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/ptzzycode/wsPool.git
[email protected]:ptzzycode/wsPool.git
ptzzycode
wsPool
wsPool
v1.1.8

搜索帮助