static Directories makeDirectories(List<Pmtiles.Entry> entries) throws IOException {
    int maxEntriesRootOnly = 16384;
    int attemptNum = 1;
    if (entries.size() < maxEntriesRootOnly) {
      byte[] testBytes = Pmtiles.directoryToBytes(entries, 0, entries.size());
      testBytes = Gzip.gzip(testBytes);

      if (testBytes.length < INIT_SECTION - Pmtiles.HEADER_LEN) {
        return new Directories(testBytes, new byte[0], 0, 0, attemptNum);
      }
    }

    double estimatedLeafSize = entries.size() / 3_500d;
    int leafSize = (int) Math.max(estimatedLeafSize, 4096);

    while (true) {
      Directories temp = makeDirectoriesWithLeaves(entries, leafSize, attemptNum++);
      if (temp.root.length < INIT_SECTION - Pmtiles.HEADER_LEN) {
        return temp;
      }
      leafSize *= 1.2;
    }
  }
Serialize all entries into bytes, choosing the # of leaf directories to ensure the header+root fits in 16 KB.

@param entries a sorted ObjectArrayList of all entries in the tileset.
@return byte arrays of the root and all leaf directories, and the # of leaves.
@throws IOException if compression fails
planetiler-core/src/main/java/com/onthegomap/planetiler/pmtiles/WriteablePmtiles.java