Google Cloud Pub/Sub C++ Client  2.1.0
A C++ Client Library for Google Cloud Pub/Sub
schema.h
Go to the documentation of this file.
1 // Copyright 2021 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_SCHEMA_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_PUBSUB_SCHEMA_H
17 
18 #include "google/cloud/pubsub/version.h"
19 #include <grpcpp/grpcpp.h>
20 #include <iosfwd>
21 #include <string>
22 
23 namespace google {
24 namespace cloud {
25 namespace pubsub {
27 
28 /**
29  * Objects of this class identify a Cloud Pub/Sub schema.
30  *
31  * @note
32  * This class makes no effort to validate the ids provided. The application
33  * should verify that any ids passed to this application conform to the
34  * Cloud Pub/Sub [resource name][name-link] restrictions.
35  *
36  * [name-link]: https://cloud.google.com/pubsub/docs/admin#resource_names
37  */
38 class Schema {
39  public:
40  Schema(std::string project_id, std::string schema_id)
41  : project_id_(std::move(project_id)), schema_id_(std::move(schema_id)) {}
42 
43  /// @name Copy and move
44  //@{
45  Schema(Schema const&) = default;
46  Schema& operator=(Schema const&) = default;
47  Schema(Schema&&) = default;
48  Schema& operator=(Schema&&) = default;
49  //@}
50 
51  /// Returns the Project ID
52  std::string const& project_id() const { return project_id_; }
53 
54  /// Returns the Schema ID
55  std::string const& schema_id() const { return schema_id_; }
56 
57  /**
58  * Returns the fully qualified schema name as a string of the form:
59  * "projects/<project-id>/schemas/<schema-id>"
60  */
61  std::string FullName() const;
62 
63  //@{
64  /// @name Equality operators
65  friend bool operator==(Schema const& a, Schema const& b);
66  friend bool operator!=(Schema const& a, Schema const& b) { return !(a == b); }
67  //@}
68 
69  /// Output the `FullName()` format.
70  friend std::ostream& operator<<(std::ostream& os, Schema const& rhs);
71 
72  private:
73  std::string project_id_;
74  std::string schema_id_;
75 };
76 
78 } // namespace pubsub
79 } // namespace cloud
80 } // namespace google
81 
82 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_PUBSUB_SCHEMA_H