public static byte requiredMagicForVersion(short produceRequestVersion) {
        if (produceRequestVersion < ApiKeys.PRODUCE.oldestVersion() || produceRequestVersion > ApiKeys.PRODUCE.latestVersion())
            throw new IllegalArgumentException("Magic value to use for produce request version " +
                    produceRequestVersion + " is not known");

        switch (produceRequestVersion) {
            case 0:
            case 1:
                return RecordBatch.MAGIC_VALUE_V0;

            case 2:
                return RecordBatch.MAGIC_VALUE_V1;

            default:
                return RecordBatch.MAGIC_VALUE_V2;
        }
    }
@return data or IllegalStateException if the data is removed (to prevent unnecessary memory retention).
clients/src/main/java/org/apache/kafka/common/requests/ProduceRequest.java