@Override
    int responseSize(LinkedHashMap<TopicIdPartition, PartitionData> updates, short version) {
        if (!isSubsequent)
            return ShareFetchResponse.sizeOf(version, updates.entrySet().iterator());
        synchronized (session) {
            int expectedEpoch = ShareFetchMetadata.nextEpoch(reqMetadata.epoch());
            if (session.epoch != expectedEpoch) {
                return ShareFetchResponse.sizeOf(version, Collections.emptyIterator());
            }
            // Pass the partition iterator which updates neither the share fetch context nor the partition map.
            return ShareFetchResponse.sizeOf(version, new PartitionIterator(updates.entrySet().iterator(), false));
        }
    }
Iterator that goes over the given partition map and selects partitions that need to be included in the response.
If updateShareContextAndRemoveUnselected is set to true, the share context will be updated for the selected
partitions and also remove unselected ones as they are encountered.
core/src/main/java/kafka/server/share/ShareSessionContext.java