本文整理汇总了Golang中github.com/davyxu/cellnet.ParsePacket函数的典型用法代码示例。如果您正苦于以下问题:Golang ParsePacket函数的具体用法?Golang ParsePacket怎么用?Golang ParsePacket使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ParsePacket函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: RegisterSessionMessage
// 注册连接消息
func RegisterSessionMessage(eq cellnet.EventQueue, msgIns interface{}, userHandler func(interface{}, cellnet.Session)) *cellnet.MessageMeta {
msgMeta := cellnet.NewMessageMeta(msgIns)
// 将消息注册到mapper中, 提供反射用
MapNameID(msgMeta.Name, msgMeta.ID)
eq.RegisterCallback(msgMeta.ID, func(data interface{}) {
if ev, ok := data.(*SessionEvent); ok {
rawMsg, err := cellnet.ParsePacket(ev.Packet, msgMeta.Type)
if err != nil {
log.Printf("[cellnet] unmarshaling error:\n", err)
return
}
userHandler(rawMsg, ev.Ses)
}
})
return msgMeta
}
示例2: RegisterSessionMessage
// 注册连接消息
func RegisterSessionMessage(msgIns interface{}, userHandler func(interface{}, cellnet.Session, int64)) {
msgMeta := cellnet.NewMessageMeta(msgIns)
// 将消息注册到mapper中, 提供反射用
socket.MapNameID(msgMeta.Name, msgMeta.ID)
for _, conn := range gateConnArray {
conn.RegisterCallback(msgMeta.ID, func(data interface{}) {
if ev, ok := data.(*relayEvent); ok {
rawMsg, err := cellnet.ParsePacket(ev.Packet, msgMeta.Type)
if err != nil {
log.Errorln("[gate] unmarshaling error:\n", err)
return
}
userHandler(rawMsg, ev.Ses, ev.ClientID)
}
})
}
}
示例3: RegisterMessage
// 注册连接消息
func RegisterMessage(eq cellnet.EventQueue, msgIns interface{}, userHandler func(Response, interface{})) {
msgMeta := cellnet.NewMessageMeta(msgIns)
// 将消息注册到mapper中, 提供反射用
socket.MapNameID(msgMeta.Name, msgMeta.ID)
eq.RegisterCallback(msgMeta.ID, func(data interface{}) {
if ev, ok := data.(*response); ok {
rawMsg, err := cellnet.ParsePacket(&cellnet.Packet{
MsgID: ev.req.GetMsgID(),
Data: ev.req.Data,
}, msgMeta.Type)
if err != nil {
log.Errorln("[cellnet] unmarshaling error:\n", err)
return
}
userHandler(ev, rawMsg)
}
})
}
示例4: RegisterSessionMessage
// 注册连接消息
func RegisterSessionMessage(eq cellnet.EventQueue, msgName string, userHandler func(interface{}, cellnet.Session)) *cellnet.MessageMeta {
msgMeta := cellnet.MessageMetaByName(msgName)
if msgMeta == nil {
log.Errorf("message register failed, %s", msgName)
return nil
}
eq.RegisterCallback(msgMeta.ID, func(data interface{}) {
if ev, ok := data.(*SessionEvent); ok {
rawMsg, err := cellnet.ParsePacket(ev.Packet, msgMeta.Type)
if err != nil {
log.Errorln("unmarshaling error:\n", err)
return
}
userHandler(rawMsg, ev.Ses)
}
})
return msgMeta
}
示例5: RegisterMessage
// 将PB消息解析封装到闭包中
func RegisterMessage(disp *PacketDispatcher, msgIns interface{}, userHandler func(cellnet.CellID, interface{})) {
msgType := reflect.TypeOf(msgIns)
msgName := msgType.String()
msgID := cellnet.Name2ID(msgName)
// 将消息注册到mapper中, 提供反射用
addMapper(msgName, msgID)
//log.Printf("[dispatcher] #regmsg %s(%d 0x%x)", msgName, msgID, msgID)
disp.RegisterCallback(msgID, func(ses cellnet.CellID, pkt *cellnet.Packet) {
rawMsg, err := cellnet.ParsePacket(pkt, msgType)
if err != nil {
log.Printf("[cellnet] unmarshaling error:\n", err)
return
}
userHandler(ses, rawMsg)
})
}
示例6: RegisterSessionMessage
// 注册连接消息
func RegisterSessionMessage(eq cellnet.EventQueue, msgIns interface{}, userHandler func(interface{}, cellnet.Session)) *cellnet.MessageMeta {
msgMeta := cellnet.NewMessageMeta(msgIns)
eq.RegisterCallback(msgMeta.ID, func(data interface{}) {
if ev, ok := data.(*SessionEvent); ok {
rawMsg, err := cellnet.ParsePacket(ev.Packet, msgMeta.Type)
if err != nil {
log.Errorln("unmarshaling error:\n", err)
return
}
log.Debugf("#recv(%s) sid: %d %s(%d)|%s", ev.Ses.FromPeer().Name(), ev.Ses.ID(), msgMeta.Name, len(ev.Packet.Data), rawMsg.(proto.Message).String())
userHandler(rawMsg, ev.Ses)
}
})
return msgMeta
}
示例7: RegisterMessage
// 注册连接消息
func RegisterMessage(eq cellnet.EventQueue, msgName string, userHandler func(Response, interface{})) {
msgMeta := cellnet.MessageMetaByName(msgName)
eq.RegisterCallback(msgMeta.ID, func(data interface{}) {
if ev, ok := data.(*response); ok {
rawMsg, err := cellnet.ParsePacket(&cellnet.Packet{
MsgID: ev.req.MsgID,
Data: ev.req.Data,
}, msgMeta.Type)
if err != nil {
log.Errorln("unmarshaling error:", err)
return
}
userHandler(ev, rawMsg)
}
})
}
示例8: MsgString
func (self *MessageLogInfo) MsgString() string {
if self.meta == nil {
return fmt.Sprintf("%v", self.pkt.Data)
}
rawMsg, err := cellnet.ParsePacket(self.pkt, self.meta.Type)
if err != nil {
return err.Error()
}
return rawMsg.(proto.Message).String()
}
示例9: done
func (self *request) done(msg *coredef.RemoteCallACK) {
rawType, err := cellnet.ParsePacket(&cellnet.Packet{
MsgID: msg.GetMsgID(),
Data: msg.Data,
}, self.replyType)
defer removeCall(self.id)
if err != nil {
log.Errorln(err)
return
}
self.callback.Call([]reflect.Value{reflect.ValueOf(rawType)})
}
示例10: RegisterMessage
// 注册连接消息
func RegisterMessage(eq cellnet.EventQueue, msgName string, userHandler func(interface{}, Response)) {
if needRegisterServer {
// 服务端
socket.RegisterSessionMessage(eq, "gamedef.RemoteCallREQ", func(content interface{}, ses cellnet.Session) {
msg := content.(*gamedef.RemoteCallREQ)
eq.CallData(&response{
ses: ses,
req: msg,
})
})
needRegisterServer = false
}
msgMeta := cellnet.MessageMetaByName(msgName)
eq.RegisterCallback(msgMeta.ID, func(data interface{}) {
if ev, ok := data.(*response); ok {
rawMsg, err := cellnet.ParsePacket(&cellnet.Packet{
MsgID: ev.req.MsgID,
Data: ev.req.Data,
}, msgMeta.Type)
if err != nil {
log.Errorln("unmarshaling error:", err)
return
}
userHandler(rawMsg, ev)
}
})
}
示例11: RegisterSessionMessage
// 注册连接消息
func RegisterSessionMessage(eq cellnet.EventQueue, msgName string, userHandler func(interface{}, cellnet.Session)) *cellnet.MessageMeta {
msgMeta := cellnet.MessageMetaByName(msgName)
if msgMeta == nil {
log.Errorf("message register failed, %s", msgName)
return nil
}
eq.RegisterCallback(msgMeta.ID, func(data interface{}) {
if ev, ok := data.(*SessionEvent); ok {
rawMsg, err := cellnet.ParsePacket(ev.Packet, msgMeta.Type)
if err != nil {
log.Errorln("unmarshaling error:\n", err)
return
}
if EnableMessageLog {
msgLog(&MessageLogInfo{
Dir: "recv",
PeerName: ev.Ses.FromPeer().Name(),
SessionID: ev.Ses.ID(),
Name: msgMeta.Name,
ID: msgMeta.ID,
Size: int32(len(ev.Packet.Data)),
Data: rawMsg.(proto.Message).String(),
})
}
userHandler(rawMsg, ev.Ses)
}
})
return msgMeta
}
示例12: done
func (self *request) done(msg *gamedef.RemoteCallACK) {
rawType, err := cellnet.ParsePacket(&cellnet.Packet{
MsgID: msg.MsgID,
Data: msg.Data,
}, self.replyType)
defer removeCall(self.id)
if err != nil {
log.Errorln(err)
return
}
// 这里的反射, 会影响非常少的效率, 但因为外部写法简单, 就算了
self.callback.Call([]reflect.Value{reflect.ValueOf(rawType)})
if self.recvied != nil {
self.recvied <- true
}
}
示例13: RegisterMessage
// 注册从网关接收到的消息
func RegisterMessage(msgName string, userHandler func(interface{}, cellnet.Session, int64)) {
msgMeta := cellnet.MessageMetaByName(msgName)
if msgMeta == nil {
log.Errorf("message register failed, %s", msgName)
return
}
for _, conn := range routerConnArray {
conn.RegisterCallback(msgMeta.ID, func(data interface{}) {
if ev, ok := data.(*relayEvent); ok {
rawMsg, err := cellnet.ParsePacket(ev.Packet, msgMeta.Type)
if err != nil {
log.Errorln("unmarshaling error:\n", err)
return
}
msgContent := rawMsg.(interface {
String() string
}).String()
log.Debugf("router->backend clientid: %d %s(%d) size: %d|%s", ev.ClientID, getMsgName(ev.MsgID), ev.MsgID, len(ev.Packet.Data), msgContent)
userHandler(rawMsg, ev.Ses, ev.ClientID)
}
})
}
}