// 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;
//     }
// }


import kafka.common.TopicAndPartition;
import kafka.message.ByteBufferMessageSet;
import kafka.utils.Function0;
import kafka.utils.Tuple2;
import kafka.utils.Utils;
import java.nio.ByteBuffer;
import java.util.Map;
import static kafka.api.ApiUtils.readShortString;
package kafka.api;




public class ProducerRequestReader implements RequestReader {
    public static final RequestReader instance = new ProducerRequestReader();

    public final static short CurrentVersion = 0;


    @Override
    public RequestOrResponse readFrom(final ByteBuffer buffer) {
        final short versionId = buffer.getShort();
        final int correlationId = buffer.getInt();
        final String clientId = readShortString(buffer);
        final short requiredAcks = buffer.getShort();
        final int ackTimeoutMs = buffer.getInt();
        //build the topic structure
        int topicCount = buffer.getInt();

        final Map<TopicAndPartition, ByteBufferMessageSet> partitionData =
                Utils.flatMaps(1, topicCount, new Function0<Map<TopicAndPartition, ByteBufferMessageSet>>() {

                    @Override
                    public Map<TopicAndPartition, ByteBufferMessageSet> apply() {
                        // process topic
                        final String topic = readShortString(buffer);
                        int partitionCount = buffer.getInt();

// 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/api/ProducerRequestReader.java
import kafka.common.TopicAndPartition;
import kafka.message.ByteBufferMessageSet;
import kafka.utils.Function0;
import kafka.utils.Tuple2;
import kafka.utils.Utils;
import java.nio.ByteBuffer;
import java.util.Map;
import static kafka.api.ApiUtils.readShortString;

package kafka.api;




public class ProducerRequestReader implements RequestReader {
    public static final RequestReader instance = new ProducerRequestReader();

    public final static short CurrentVersion = 0;


    @Override
    public RequestOrResponse readFrom(final ByteBuffer buffer) {
        final short versionId = buffer.getShort();
        final int correlationId = buffer.getInt();
        final String clientId = readShortString(buffer);
        final short requiredAcks = buffer.getShort();
        final int ackTimeoutMs = buffer.getInt();
        //build the topic structure
        int topicCount = buffer.getInt();

        final Map<TopicAndPartition, ByteBufferMessageSet> partitionData =
                Utils.flatMaps(1, topicCount, new Function0<Map<TopicAndPartition, ByteBufferMessageSet>>() {

                    @Override
                    public Map<TopicAndPartition, ByteBufferMessageSet> apply() {
                        // process topic
                        final String topic = readShortString(buffer);
                        int partitionCount = buffer.getInt();

                        return Utils.map(1, partitionCount, new Function0<Tuple2<TopicAndPartition, ByteBufferMessageSet>>() {