def tlv_find_tags(tlv_data, tags, num_results=None):
    """Find (and return) all instances of tags in the given tlv structure (as
    returned by unpack).  If num_results is specified then at most that many
    results will be returned."""

    results = []

    def find_recursive(tlv_data):
        for d in tlv_data:
            t, l, v = d[:3]
            if t in tags:
                results.append(d)
            else:
                if isinstance(v, list):
                    find_recursive(v)

            if num_results is not None and len(results) >= num_results:
                return

    find_recursive(tlv_data)

    return results