static AbstractRequest.Builder<OffsetsForLeaderEpochRequest> prepareRequest(
            Map<TopicPartition, SubscriptionState.FetchPosition> requestData) {
        OffsetForLeaderTopicCollection topics = new OffsetForLeaderTopicCollection(requestData.size());
        requestData.forEach((topicPartition, fetchPosition) ->
                fetchPosition.offsetEpoch.ifPresent(fetchEpoch -> {
                    OffsetForLeaderTopic topic = topics.find(topicPartition.topic());
                    if (topic == null) {
                        topic = new OffsetForLeaderTopic().setTopic(topicPartition.topic());
                        topics.add(topic);
                    }
                    topic.partitions().add(new OffsetForLeaderPartition()
                            .setPartition(topicPartition.partition())
                            .setLeaderEpoch(fetchEpoch)
                            .setCurrentLeaderEpoch(fetchPosition.currentLeader.epoch
                                    .orElse(RecordBatch.NO_PARTITION_LEADER_EPOCH))
                    );
                })
        );
        return OffsetsForLeaderEpochRequest.Builder.forConsumer(topics);
    }
Utility methods for preparing requests to the OffsetsForLeaderEpoch API and handling responses.
clients/src/main/java/org/apache/kafka/clients/consumer/internals/OffsetsForLeaderEpochUtils.java