func (msg *gatewayMsg) Unmarshal(r *binary.Reader) error { msg.Command = r.ReadUint8() // DEBUG("收到:" + strconv.Itoa(int(msg.Command))) switch msg.Command { case CMD_NEW_1: msg.ClientId = r.ReadUint64BE() msg.Data = r.ReadPacket(binary.SplitByUint8) case CMD_NEW_2: msg.ClientId = r.ReadUint64BE() msg.ClientIds = []uint64{r.ReadUint64BE()} case CMD_NEW_3: msg.ClientId = r.ReadUint64BE() case CMD_DEL: msg.ClientId = r.ReadUint64BE() case CMD_MSG: msg.ClientId = r.ReadUint64BE() msg.Data = r.ReadPacket(binary.SplitByUvarint) case CMD_BRD: num := int(r.ReadUvarint()) msg.ClientIds = make([]uint64, num) for i := 0; i < num; i++ { msg.ClientIds[i] = r.ReadUvarint() } msg.Data = r.ReadPacket(binary.SplitByUvarint) } return nil }
func (msg *TestMessage) Unmarshal(r *binary.Reader) error { *msg = r.ReadPacket(binary.SplitByUvarint) return nil }
func (msg *gatewayMsg) BinaryDecode(r *binary.Reader) error { msg.Command = r.ReadUint8() switch msg.Command { case CMD_NEW_1: msg.ClientId = r.ReadUint64BE() msg.Data = r.ReadPacket(binary.SplitByUint8) case CMD_NEW_2: msg.ClientId = r.ReadUint64BE() msg.ClientIds = []uint64{r.ReadUint64BE()} case CMD_DEL: msg.ClientId = r.ReadUint64BE() case CMD_MSG: msg.ClientId = r.ReadUint64BE() msg.Data = r.ReadPacket(binary.SplitByUvarint) case CMD_BRD: num := int(r.ReadUvarint()) msg.ClientIds = make([]uint64, num) for i := 0; i < num; i++ { msg.ClientIds[i] = r.ReadUvarint() } msg.Data = r.ReadPacket(binary.SplitByUvarint) } return nil }
func (obj *TestObject) BinaryDecode(r *binary.Reader) error { obj.X = int(r.ReadVarint()) obj.Y = int(r.ReadVarint()) obj.Z = int(r.ReadVarint()) return nil }