Score
0
Watch 5 Star 35 Fork 16

ryanduan / wsPoolGoMIT

Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
Clone or download
private.go 1.51 KB
Copy Edit Web IDE Raw Blame History
ryanduan authored 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
}

Comment ( 0 )

Sign in for post a comment