()
| 52 | } |
| 53 | |
| 54 | func (c *Decoder) forward() error { |
| 55 | header := c.buf.Next(HeadLength) |
| 56 | c.typ = header[0] |
| 57 | if c.typ < packet.Handshake || c.typ > packet.Kick { |
| 58 | return packet.ErrWrongPacketType |
| 59 | } |
| 60 | c.size = bytesToInt(header[1:]) |
| 61 | |
| 62 | // packet length limitation |
| 63 | if c.size > MaxPacketSize { |
| 64 | return ErrPacketSizeExcced |
| 65 | } |
| 66 | return nil |
| 67 | } |
| 68 | |
| 69 | // Decode decode the network bytes slice to packet.Packet(s) |
| 70 | // TODO(Warning): shared slice |