SendMsg Send messages to the client, mainly serializing and sending the protobuf data of the pb Message (发送消息给客户端,主要是将pb的protobuf数据序列化之后发送)
(msgID uint32, data proto.Message)
| 392 | // |
| 393 | // (发送消息给客户端,主要是将pb的protobuf数据序列化之后发送) |
| 394 | func (p *Player) SendMsg(msgID uint32, data proto.Message) { |
| 395 | if p.Conn == nil { |
| 396 | fmt.Println("connection in player is nil") |
| 397 | return |
| 398 | } |
| 399 | |
| 400 | // fmt.Printf("before Marshal data = %+v\n", data) |
| 401 | |
| 402 | // Serialize the proto Message structure |
| 403 | // 将proto Message结构体序列化 |
| 404 | msg, err := proto.Marshal(data) |
| 405 | if err != nil { |
| 406 | fmt.Println("marshal msg err: ", err) |
| 407 | return |
| 408 | } |
| 409 | |
| 410 | // fmt.Printf("after Marshal data = %+v\n", msg) |
| 411 | |
| 412 | // Call the Zinx framework's SendMsg to send the packet |
| 413 | // 调用Zinx框架的SendMsg发包 |
| 414 | if err := p.Conn.SendMsg(msgID, msg); err != nil { |
| 415 | fmt.Println("Player SendMsg error !") |
| 416 | return |
| 417 | } |
| 418 | |
| 419 | return |
| 420 | } |
no test coverage detected