public static ByteBuffer serialize(
        Message header,
        short headerVersion,
        Message apiMessage,
        short apiVersion
    ) {
        ObjectSerializationCache cache = new ObjectSerializationCache();

        int headerSize = header.size(cache, headerVersion);
        int messageSize = apiMessage.size(cache, apiVersion);
        ByteBufferAccessor writable = new ByteBufferAccessor(ByteBuffer.allocate(headerSize + messageSize));

        header.write(writable, cache, headerVersion);
        apiMessage.write(writable, cache, apiVersion);

        writable.flip();
        return writable.buffer();
    }
find a flag from all records of a produce request.
@param request produce request
@param predicate used to predicate the record
@return true if there is any matched flag in the produce request. Otherwise, false
clients/src/main/java/org/apache/kafka/common/requests/RequestUtils.java