docs: public static int sendRewriteCmd(final PacketOutputStream pos, final List<byte[]> queryParts,
        int currentIndex,
        int paramCount, List<ParameterHolder[]> parameterList, boolean rewriteValues)
        throws IOException {
      pos.startPacket(0);
      pos.write(Packet.COM_QUERY);
      int index = currentIndex;
      ParameterHolder[] parameters = parameterList.get(index++);
  
      byte[] firstPart = queryParts.get(0);
      byte[] secondPart = queryParts.get(1);
  
      if (!rewriteValues) {
        //write first
        pos.write(firstPart, 0, firstPart.length);
        pos.write(secondPart, 0, secondPart.length);
  
        int staticLength = 1;
        for (byte[] queryPart : queryParts) {
          staticLength += queryPart.length;
        }
  
        for (int i = 0; i < paramCount; i++) {
          parameters[i].writeTo(pos);
          pos.write(queryParts.get(i + 2));
        }
        pos.write(queryParts.get(paramCount + 2));
  
        // write other, separate by ";"
        while (index < parameterList.size()) {
          parameters = parameterList.get(index);
  
          //check packet length so to separate in multiple packet
          int parameterLength = 0;
          boolean knownParameterSize = true;
          for (ParameterHolder parameter : parameters) {
            long paramSize = parameter.getApproximateTextProtocolLength();
            if (paramSize == -1) {
              knownParameterSize = false;
              break;
            }
            parameterLength += paramSize;
          }
  
          if (knownParameterSize) {
            //We know the additional query part size. This permit :
            // - to resize buffer size if needed (to avoid resize test every write)
            // - if this query will be separated in a new packet.
            if (pos.checkRemainingSize(staticLength + parameterLength)) {
              pos.write((byte) ';');
              pos.write(firstPart, 0, firstPart.length);
              pos.write(secondPart, 0, secondPart.length);
              for (int i = 0; i < paramCount; i++) {
                parameters[i].writeTo(pos);
                pos.write(queryParts.get(i + 2));
              }
              pos.write(queryParts.get(paramCount + 2));
              index++;
            } else {
              break;
            }
          } else {
            //we cannot know the additional query part size.
            pos.write(';');
            pos.write(firstPart, 0, firstPart.length);
            pos.write(secondPart, 0, secondPart.length);
            for (int i = 0; i < paramCount; i++) {
              parameters[i].writeTo(pos);
              pos.write(queryParts.get(i + 2));
            }
            pos.write(queryParts.get(paramCount + 2));
            index++;
            break;
          }
        }
  
      } else {
        pos.write(firstPart, 0, firstPart.length);
        pos.write(secondPart, 0, secondPart.length);
        int lastPartLength = queryParts.get(paramCount + 2).length;
        int intermediatePartLength = queryParts.get(1).length;
  
        for (int i = 0; i < paramCount; i++) {
          parameters[i].writeTo(pos);
          pos.write(queryParts.get(i + 2));
          intermediatePartLength += queryParts.get(i + 2).length;
        }
  
        while (index < parameterList.size()) {
          parameters = parameterList.get(index);
  
          //check packet length so to separate in multiple packet
          int parameterLength = 0;
          boolean knownParameterSize = true;
          for (ParameterHolder parameter : parameters) {
            long paramSize = parameter.getApproximateTextProtocolLength();
            if (paramSize == -1) {
              knownParameterSize = false;
              break;
            }
            parameterLength += paramSize;
          }
  
          if (knownParameterSize) {
            //We know the additional query part size. This permit :
            // - to resize buffer size if needed (to avoid resize test every write)
            // - if this query will be separated in a new packet.
            if (pos
                .checkRemainingSize(1 + parameterLength + intermediatePartLength + lastPartLength)) {
              pos.write((byte) ',');
              pos.write(secondPart, 0, secondPart.length);
  
              for (int i = 0; i < paramCount; i++) {
                parameters[i].writeTo(pos);
                byte[] addPart = queryParts.get(i + 2);
                pos.write(addPart, 0, addPart.length);
              }
              index++;
            } else {
              break;
            }
          } else {
            pos.write((byte) ',');
            pos.write(secondPart, 0, secondPart.length);
  
            for (int i = 0; i < paramCount; i++) {
              parameters[i].writeTo(pos);
              pos.write(queryParts.get(i + 2));
            }
            index++;
            break;
          }
        }
        pos.write(queryParts.get(paramCount + 2));
      }
  
      pos.flush();
      return index;
    }