def _query_response_to_snapshot(response_pb, collection, expected_prefix):
    """Parse a query response protobuf to a document snapshot.

    Args:
        response_pb (google.cloud.proto.firestore.v1beta1.\
            firestore_pb2.RunQueryResponse): A
        collection (~.firestore_v1beta1.collection.CollectionReference): A
            reference to the collection that initiated the query.
        expected_prefix (str): The expected prefix for fully-qualified
            document names returned in the query results. This can be computed
            directly from ``collection`` via :meth:`_parent_info`.

    Returns:
        Optional[~.firestore.document.DocumentSnapshot]: A
        snapshot of the data returned in the query. If ``response_pb.document``
        is not set, the snapshot will be :data:`None`.
    """
    if not response_pb.HasField("document"):
        return None

    document_id = _helpers.get_doc_id(response_pb.document, expected_prefix)
    reference = collection.document(document_id)
    data = _helpers.decode_dict(response_pb.document.fields, collection._client)
    snapshot = document.DocumentSnapshot(
        reference,
        data,
        exists=True,
        read_time=response_pb.read_time,
        create_time=response_pb.document.create_time,
        update_time=response_pb.document.update_time,
    )
    return snapshot
Parse a query response protobuf to a document snapshot.

    Args:
        response_pb (google.cloud.proto.firestore.v1beta1.\
            firestore_pb2.RunQueryResponse): A
        collection (~.firestore_v1beta1.collection.CollectionReference): A
            reference to the collection that initiated the query.
        expected_prefix (str): The expected prefix for fully-qualified
            document names returned in the query results. This can be computed
            directly from ``collection`` via :meth:`_parent_info`.

    Returns:
        Optional[~.firestore.document.DocumentSnapshot]: A
        snapshot of the data returned in the query. If ``response_pb.document``
        is not set, the snapshot will be :data:`None`.