Google Cloud Pub/Sub C++ Client 2.13.0
A C++ Client Library for Google Cloud Pub/Sub
Loading...
Searching...
No Matches
snapshot_builder.h
1// Copyright 2020 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_PUBSUB_SNAPSHOT_BUILDER_H
16#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_PUBSUB_SNAPSHOT_BUILDER_H
17
18#include "google/cloud/pubsub/snapshot.h"
19#include "google/cloud/pubsub/subscription.h"
20#include "google/cloud/pubsub/version.h"
21#include "google/cloud/internal/time_utils.h"
22#include <google/protobuf/util/field_mask_util.h>
23#include <google/pubsub/v1/pubsub.pb.h>
24#include <set>
25#include <string>
26
27namespace google {
28namespace cloud {
29namespace pubsub {
30GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
31
32/**
33 * Build a request to create a Cloud Pub/Sub snapshot.
34 *
35 * Makes it easier to create the protobuf messages consumed by
36 * `SubscriptionAdminClient`. The main advantages are:
37 *
38 * - Use a fluent API to set multiple values when constructing complex objects.
39 * - Automatically compute the set of paths for update requests.
40 */
41class SnapshotBuilder {
42 public:
43 SnapshotBuilder() = default;
44
45 /// Build a protocol buffer message to create snapshots with server-assigned
46 /// ids.
47 google::pubsub::v1::CreateSnapshotRequest BuildCreateRequest(
48 Subscription const& subscription) &&;
49
50 /// Build a protocol buffer message to create snapshots with
51 /// application-assigned ids.
52 google::pubsub::v1::CreateSnapshotRequest BuildCreateRequest(
53 Subscription const& subscription, Snapshot const& snapshot) &&;
54
55 /// Build a protocol buffer message to update an existing snapshot.
56 google::pubsub::v1::UpdateSnapshotRequest BuildUpdateRequest(
57 Snapshot const& snapshot) &&;
58
59 /// @name Setters for each protocol buffer field.
60 ///@{
61 SnapshotBuilder& add_label(std::string const& key,
62 std::string const& value) & {
63 using value_type =
64 google::protobuf::Map<std::string, std::string>::value_type;
65 proto_.mutable_labels()->insert(value_type(key, value));
66 paths_.insert("labels");
67 return *this;
68 }
69 SnapshotBuilder&& add_label(std::string const& key,
70 std::string const& value) && {
71 return std::move(add_label(key, value));
72 }
73
75 proto_.clear_labels();
76 paths_.insert("labels");
77 return *this;
78 }
79 SnapshotBuilder&& clear_labels() && { return std::move(clear_labels()); }
80 ///@}
81
82 private:
83 google::pubsub::v1::Snapshot proto_;
84 std::set<std::string> paths_;
85};
86
87GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
88} // namespace pubsub
89} // namespace cloud
90} // namespace google
91
92#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_PUBSUB_SNAPSHOT_BUILDER_H
Build a request to create a Cloud Pub/Sub snapshot.
Definition: snapshot_builder.h:41
google::pubsub::v1::UpdateSnapshotRequest BuildUpdateRequest(Snapshot const &snapshot) &&
Build a protocol buffer message to update an existing snapshot.
SnapshotBuilder && add_label(std::string const &key, std::string const &value) &&
Definition: snapshot_builder.h:69
google::pubsub::v1::CreateSnapshotRequest BuildCreateRequest(Subscription const &subscription, Snapshot const &snapshot) &&
Build a protocol buffer message to create snapshots with application-assigned ids.
SnapshotBuilder && clear_labels() &&
Definition: snapshot_builder.h:79
google::pubsub::v1::CreateSnapshotRequest BuildCreateRequest(Subscription const &subscription) &&
Build a protocol buffer message to create snapshots with server-assigned ids.
SnapshotBuilder & clear_labels() &
Definition: snapshot_builder.h:74
SnapshotBuilder & add_label(std::string const &key, std::string const &value) &
Definition: snapshot_builder.h:61
Objects of this class identify a Cloud Pub/Sub snapshot.
Definition: snapshot.h:37
Objects of this class identify a Cloud Pub/Sub subscription.
Definition: subscription.h:37
Contains all the Cloud Pub/Sub C++ client types and functions.
Definition: ack_handler.h:25
The namespace Google Cloud Platform C++ client libraries.