code: func (cli *Client) handlePacket(p packet.Packet) error {
  	// Get the MQTT Control Packet type.
  	ptype, err := p.Type()
  	if err != nil {
  		return err
  	}
  
  	switch ptype {
  	case packet.TypeCONNACK:
  		cli.handleCONNACK()
  		return nil
  	case packet.TypePUBLISH:
  		return cli.handlePUBLISH(p)
  	case packet.TypePUBACK:
  		return cli.handlePUBACK(p)
  	case packet.TypePUBREC:
  		return cli.handlePUBREC(p)
  	case packet.TypePUBREL:
  		return cli.handlePUBREL(p)
  	case packet.TypePUBCOMP:
  		return cli.handlePUBCOMP(p)
  	case packet.TypeSUBACK:
  		return cli.handleSUBACK(p)
  	case packet.TypeUNSUBACK:
  		return cli.handleUNSUBACK(p)
  	case packet.TypePINGRESP:
  		return cli.handlePINGRESP()
  	default:
  		return packet.ErrInvalidPacketType
  	}
  }
docs: // handlePacket handles the Packet.