public static Builder forMagic(byte magic, ProduceRequestData data) {
        // Message format upgrades correspond with a bump in the produce request version. Older
        // message format versions are generally not supported by the produce request versions
        // following the bump.

        final short minVersion;
        final short maxVersion;
        if (magic < RecordBatch.MAGIC_VALUE_V2) {
            minVersion = 2;
            maxVersion = 2;
        } else {
            minVersion = 3;
            maxVersion = ApiKeys.PRODUCE.latestVersion();
        }
        return new Builder(minVersion, maxVersion, data);
    }
@Test
    public void testBuildWithOldMessageFormat() {
        ByteBuffer buffer = ByteBuffer.allocate(256);
        MemoryRecordsBuilder builder = MemoryRecords.builder(buffer, RecordBatch.MAGIC_VALUE_V1, Compression.NONE,
                TimestampType.CREATE_TIME, 0L);
        builder.append(10L, null, "a".getBytes());
        ProduceRequest.Builder requestBuilder = ProduceRequest.forMagic(RecordBatch.MAGIC_VALUE_V1,
            new ProduceRequestData()
                .setTopicData(new ProduceRequestData.TopicProduceDataCollection(Collections.singletonList(
                    new ProduceRequestData.TopicProduceData().setName("test").setPartitionData(Collections.singletonList(
                        new ProduceRequestData.PartitionProduceData().setIndex(9).setRecords(builder.build()))))
                    .iterator()))
                .setAcks((short) 1)
                .setTimeoutMs(5000));
        assertEquals(2, requestBuilder.oldestAllowedVersion());
        assertEquals(2, requestBuilder.latestAllowedVersion());
    }