class RestRowCountReceiver implements ResultReceiver<XContentBuilder> {

    private final long startTimeNs;
    private final boolean includeTypes;
    private final ResultToXContentBuilder builder;
    private final CompletableFuture<XContentBuilder> result = new CompletableFuture<>();

    private long rowCount;

    RestRowCountReceiver(XContentBuilder builder,
                         long startTimeNs,
                         boolean includeTypes) throws IOException {
        this.startTimeNs = startTimeNs;
        this.includeTypes = includeTypes;
        this.builder = ResultToXContentBuilder.builder(builder);
    }

    @Override
    public void setNextRow(Row row) {
        rowCount = (long) row.get(0);
    }

    @Override
    public void batchFinished() {
        fail(new IllegalStateException("Incremental result streaming not supported via HTTP"));
    }

    XContentBuilder finishBuilder() throws IOException {<FILL_FUNCTION_BODY>}

    @Override
    public void allFinished() {
        try {
            result.complete(finishBuilder());
        } catch (IOException e) {
            result.completeExceptionally(e);
        }
    }

    @Override
    public void fail(Throwable t) {
        result.completeExceptionally(t);
    }

    @Override
    public CompletableFuture<XContentBuilder> completionFuture() {
        return result;
    }
}

        builder.cols(Collections.emptyList());
        if (includeTypes) {
            builder.colTypes(Collections.emptyList());
        }
        builder.startRows()
            .addRow(Row.EMPTY, 0)
            .finishRows()
            .rowCount(rowCount)
            .duration(startTimeNs);
        return builder.build();
    
<no_super_class>