private static ProduceResponseData toData(Map<TopicPartition, PartitionResponse> responses, int throttleTimeMs, List<Node> nodeEndpoints) {
        ProduceResponseData data = new ProduceResponseData().setThrottleTimeMs(throttleTimeMs);
        responses.forEach((tp, response) -> {
            ProduceResponseData.TopicProduceResponse tpr = data.responses().find(tp.topic());
            if (tpr == null) {
                tpr = new ProduceResponseData.TopicProduceResponse().setName(tp.topic());
                data.responses().add(tpr);
            }
            tpr.partitionResponses()
                .add(new ProduceResponseData.PartitionProduceResponse()
                    .setIndex(tp.partition())
                    .setBaseOffset(response.baseOffset)
                    .setLogStartOffset(response.logStartOffset)
                    .setLogAppendTimeMs(response.logAppendTime)
                    .setErrorMessage(response.errorMessage)
                    .setErrorCode(response.error.code())
                    .setCurrentLeader(response.currentLeader != null ? response.currentLeader : new LeaderIdAndEpoch())
                    .setRecordErrors(response.recordErrors
                        .stream()
                        .map(e -> new ProduceResponseData.BatchIndexAndErrorMessage()
                            .setBatchIndex(e.batchIndex)
                            .setBatchIndexErrorMessage(e.message))
                        .collect(Collectors.toList())));
        });
        nodeEndpoints.forEach(endpoint -> data.nodeEndpoints()
                .add(new ProduceResponseData.NodeEndpoint()
                        .setNodeId(endpoint.id())
                        .setHost(endpoint.host())
                        .setPort(endpoint.port())
                        .setRack(endpoint.rack())));
        return data;
    }
Constructor for the latest version
This is deprecated in favor of using the ProduceResponseData constructor, KafkaApis should switch to that
in KAFKA-10730
@param responses Produced data grouped by topic-partition
@param throttleTimeMs Time in milliseconds the response was throttled
@param nodeEndpoints List of node endpoints
clients/src/main/java/org/apache/kafka/common/requests/ProduceResponse.java