def METHOD_NAME(items):
    """Serialize a list of TabHistoryItems to a data stream.
    Args:
        items: An iterable of TabHistoryItems.
    Return:
        A (stream, data, user_data) tuple.
            stream: The reset QDataStream.
            data: The QByteArray with the raw data.
            cur_user_data: The user data for the current item or None.
    Warning:
        If 'data' goes out of scope, reading from 'stream' will result in a
        segfault!
    """
    data = QByteArray()
    stream = QDataStream(data, QIODevice.OpenModeFlag.ReadWrite)
    cur_user_data = None
    current_idx = None
    for i, item in enumerate(items):
        if item.active:
            if current_idx is not None:
                raise ValueError("Multiple active items ({} and {}) "
                                 "found!".format(current_idx, i))
            current_idx = i
            cur_user_data = item.user_data
    if items:
        if current_idx is None:
            raise ValueError("No active item found!")
    else:
        current_idx = -1
    ### src/core/web_contents_adapter.cpp serializeNavigationHistory
    #                                          sample data:
    # kHistoryStreamVersion
    stream.writeInt(HISTORY_STREAM_VERSION)  # \x00\x00\x00\x03
    # count
    stream.writeInt(len(items))              # \x00\x00\x00\x01
    # currentIndex
    stream.writeInt(current_idx)             # \x00\x00\x00\x00
    for item in items:
        _serialize_item(item, stream)
    dev = stream.device()
    assert dev is not None
    dev.reset()
    qtutils.check_qdatastream(stream)
    return stream, data, cur_user_data