// Path: src/main/java/kafka/common/TopicAndPartition.java
// public class TopicAndPartition {
//     public final String topic;
//     public final int partition;
// 
//     public TopicAndPartition(String topic, int partition) {
//         this.topic = topic;
//         this.partition = partition;
//     }
// 
//     public TopicAndPartition(Tuple2<String, Integer> tuple) {
//         this(tuple._1, tuple._2);
//     }
// 
//     public TopicAndPartition(Partition partition) {
//         this(partition.topic, partition.partitionId);
//     }
// 
//     public TopicAndPartition(Replica replica) {
//         this(replica.topic, replica.partitionId);
//     }
// 
//     public Tuple2<String, Integer> asTuple() {
//         return Tuple2.make(topic, partition);
//     }
// 
//     @Override
//     public String toString() {
//         return String.format("[%s,%d]", topic, partition);
//     }
// 
//     @Override
//     public boolean equals(Object o) {
//         if (this == o) return true;
//         if (o == null || getClass() != o.getClass()) return false;
// 
//         TopicAndPartition that = (TopicAndPartition) o;
// 
//         if (partition != that.partition) return false;
//         if (topic != null ? !topic.equals(that.topic) : that.topic != null) return false;
// 
//         return true;
//     }
// 
//     @Override
//     public int hashCode() {
//         int result = topic != null ? topic.hashCode() : 0;
//         result = 31 * result + partition;
//         return result;
//     }
// }
// 
// Path: src/main/java/kafka/utils/Function2.java
// public interface Function2<A1,A2,B> {
//     B apply(A1 arg1, A2 arg2);
// }


import kafka.common.TopicAndPartition;
import kafka.network.MultiSend;
import kafka.network.Send;
import kafka.utils.Function2;
import kafka.utils.Tuple2;
import kafka.utils.Utils;
import java.nio.ByteBuffer;
import java.nio.channels.GatheringByteChannel;
import java.util.List;
import java.util.Map;
package kafka.api;



public class FetchResponseSend extends Send {
    public FetchResponse fetchResponse;


    public static class FetchResponseDataSend extends MultiSend<TopicDataSend> {
        protected FetchResponseDataSend(FetchResponse fetchResponse, List<TopicDataSend> sends) {
            super(sends);

            expectedBytesToWrite = fetchResponse.sizeInBytes() - FetchResponse.headerSize;
        }
    }

    public FetchResponseSend(FetchResponse fetchResponse) {
        this.fetchResponse = fetchResponse;
        size = fetchResponse.sizeInBytes();
        sendSize = 4 /* for size */ + size;
        buffer = ByteBuffer.allocate(4 /* for size */ + FetchResponse.headerSize);
        buffer.putInt(size);
        buffer.putInt(fetchResponse.correlationId);
        buffer.putInt(fetchResponse.dataGroupedByTopic.size()); // topic count
        buffer.rewind();

        sends = new FetchResponseDataSend(fetchResponse, Utils.mapList(fetchResponse.dataGroupedByTopic,
// Path: src/main/java/kafka/common/TopicAndPartition.java
// public class TopicAndPartition {
//     public final String topic;
//     public final int partition;
// 
//     public TopicAndPartition(String topic, int partition) {
//         this.topic = topic;
//         this.partition = partition;
//     }
// 
//     public TopicAndPartition(Tuple2<String, Integer> tuple) {
//         this(tuple._1, tuple._2);
//     }
// 
//     public TopicAndPartition(Partition partition) {
//         this(partition.topic, partition.partitionId);
//     }
// 
//     public TopicAndPartition(Replica replica) {
//         this(replica.topic, replica.partitionId);
//     }
// 
//     public Tuple2<String, Integer> asTuple() {
//         return Tuple2.make(topic, partition);
//     }
// 
//     @Override
//     public String toString() {
//         return String.format("[%s,%d]", topic, partition);
//     }
// 
//     @Override
//     public boolean equals(Object o) {
//         if (this == o) return true;
//         if (o == null || getClass() != o.getClass()) return false;
// 
//         TopicAndPartition that = (TopicAndPartition) o;
// 
//         if (partition != that.partition) return false;
//         if (topic != null ? !topic.equals(that.topic) : that.topic != null) return false;
// 
//         return true;
//     }
// 
//     @Override
//     public int hashCode() {
//         int result = topic != null ? topic.hashCode() : 0;
//         result = 31 * result + partition;
//         return result;
//     }
// }
// 
// Path: src/main/java/kafka/utils/Function2.java
// public interface Function2<A1,A2,B> {
//     B apply(A1 arg1, A2 arg2);
// }


// Path: src/main/java/kafka/api/FetchResponseSend.java
import kafka.common.TopicAndPartition;
import kafka.network.MultiSend;
import kafka.network.Send;
import kafka.utils.Function2;
import kafka.utils.Tuple2;
import kafka.utils.Utils;
import java.nio.ByteBuffer;
import java.nio.channels.GatheringByteChannel;
import java.util.List;
import java.util.Map;

package kafka.api;



public class FetchResponseSend extends Send {
    public FetchResponse fetchResponse;


    public static class FetchResponseDataSend extends MultiSend<TopicDataSend> {
        protected FetchResponseDataSend(FetchResponse fetchResponse, List<TopicDataSend> sends) {
            super(sends);

            expectedBytesToWrite = fetchResponse.sizeInBytes() - FetchResponse.headerSize;
        }
    }

    public FetchResponseSend(FetchResponse fetchResponse) {
        this.fetchResponse = fetchResponse;
        size = fetchResponse.sizeInBytes();
        sendSize = 4 /* for size */ + size;
        buffer = ByteBuffer.allocate(4 /* for size */ + FetchResponse.headerSize);
        buffer.putInt(size);
        buffer.putInt(fetchResponse.correlationId);
        buffer.putInt(fetchResponse.dataGroupedByTopic.size()); // topic count
        buffer.rewind();

        sends = new FetchResponseDataSend(fetchResponse, Utils.mapList(fetchResponse.dataGroupedByTopic,
                new Function2<String, Map<TopicAndPartition, FetchResponsePartitionData>, TopicDataSend>() {