public static byte[] directoryToBytes(List<Entry> slice) {
    ByteArrayList dir = new ByteArrayList();

    VarInt.putVarLong(slice.size(), dir);

    long lastId = 0;
    for (var entry : slice) {
      VarInt.putVarLong(entry.tileId - lastId, dir);
      lastId = entry.tileId;
    }

    for (var entry : slice) {
      VarInt.putVarLong(entry.runLength, dir);
    }

    for (var entry : slice) {
      VarInt.putVarLong(entry.length, dir);
    }

    Entry last = null;
    for (var entry : slice) {
      if (last != null && entry.offset == last.offset + last.length) {
        VarInt.putVarLong(0, dir);
      } else {
        VarInt.putVarLong(entry.offset + 1, dir);
      }
      last = entry;
    }

    return dir.toArray();
  }
Convert a directory of entries to bytes.

@param slice a list of entries sorted by ascending {@code tileId} with size > 0.
@return the uncompressed bytes of the directory.
planetiler-core/src/main/java/com/onthegomap/planetiler/pmtiles/Pmtiles.java