Google Cloud Pub/Sub C++ Client  1.33.0
A C++ Client Library for Google Cloud Pub/Sub
schema_stub.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 // http://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_INTERNAL_SCHEMA_STUB_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_PUBSUB_INTERNAL_SCHEMA_STUB_H
17 
18 #include "google/cloud/pubsub/connection_options.h"
19 #include "google/cloud/pubsub/version.h"
20 #include "google/cloud/status_or.h"
21 #include <google/pubsub/v1/schema.pb.h>
22 
23 namespace google {
24 namespace cloud {
25 namespace pubsub_internal {
27 
28 /**
29  * Define the interface for the gRPC wrapper.
30  *
31  * We wrap the gRPC-generated `SchemaStub` to:
32  * - Return a `StatusOr<T>` instead of using a `grpc::Status` and an "output
33  * parameter" for the response.
34  * - To be able to mock the stubs.
35  * - To be able to decompose some functionality (logging, adding metadata
36  * information) into layers.
37  */
38 class SchemaStub {
39  public:
40  virtual ~SchemaStub() = default;
41 
42  /// Creates a schema.
43  virtual StatusOr<google::pubsub::v1::Schema> CreateSchema(
44  grpc::ClientContext& context,
45  google::pubsub::v1::CreateSchemaRequest const& request) = 0;
46 
47  /// Gets a schema.
48  virtual StatusOr<google::pubsub::v1::Schema> GetSchema(
49  grpc::ClientContext& context,
50  google::pubsub::v1::GetSchemaRequest const& request) = 0;
51 
52  /// Lists schemas in a project.
53  virtual StatusOr<google::pubsub::v1::ListSchemasResponse> ListSchemas(
54  grpc::ClientContext& context,
55  google::pubsub::v1::ListSchemasRequest const& request) = 0;
56 
57  /// Deletes a schema.
58  virtual Status DeleteSchema(
59  grpc::ClientContext& context,
60  google::pubsub::v1::DeleteSchemaRequest const& request) = 0;
61 
62  /// Validates a schema.
63  virtual StatusOr<google::pubsub::v1::ValidateSchemaResponse> ValidateSchema(
64  grpc::ClientContext& context,
65  google::pubsub::v1::ValidateSchemaRequest const& request) = 0;
66 
67  /// Validates a message against a schema.
68  virtual StatusOr<google::pubsub::v1::ValidateMessageResponse> ValidateMessage(
69  grpc::ClientContext& context,
70  google::pubsub::v1::ValidateMessageRequest const& request) = 0;
71 };
72 
73 /**
74  * Creates a SchemaStub with a pre-configured channel.
75  */
76 std::shared_ptr<SchemaStub> CreateDefaultSchemaStub(
77  std::shared_ptr<grpc::Channel> channel);
78 
80 } // namespace pubsub_internal
81 } // namespace cloud
82 } // namespace google
83 
84 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_PUBSUB_INTERNAL_SCHEMA_STUB_H