|
21 | 21 | #include "generator/internal/predicate_utils.h" |
22 | 22 | #include "generator/internal/printer.h" |
23 | 23 | #include "absl/strings/str_cat.h" |
| 24 | +#include "absl/strings/str_replace.h" |
24 | 25 | #include "google/api/client.pb.h" |
25 | 26 | #include <google/protobuf/descriptor.h> |
26 | 27 |
|
27 | 28 | namespace google { |
28 | 29 | namespace cloud { |
29 | 30 | namespace generator_internal { |
| 31 | +namespace { |
| 32 | +std::string FormatBespokeMethodComments(std::string const& method_name) { |
| 33 | + if (method_name == "WaitForConsistency") { |
| 34 | + return R"""( |
| 35 | + // clang-format off |
| 36 | + /// |
| 37 | + /// Polls a table until it is consistent or the RetryPolicy is exhausted based |
| 38 | + /// on a consistency token, that is, if replication has caught up based on the |
| 39 | + /// provided conditions specified in the token and the check request. |
| 40 | + /// |
| 41 | + /// @param request Unary RPCs, such as the one wrapped by this |
| 42 | + /// function, receive a single `request` proto message which includes all |
| 43 | + /// the inputs for the RPC. In this case, the proto message is a |
| 44 | + /// [google.bigtable.admin.v2.CheckConsistencyRequest]. |
| 45 | + /// Proto messages are converted to C++ classes by Protobuf, using the |
| 46 | + /// [Protobuf mapping rules]. |
| 47 | + /// @param opts Optional. Override the class-level options, such as retry and |
| 48 | + /// backoff policies. |
| 49 | + /// @return the result of the RPC. The response message type |
| 50 | + /// ([google.bigtable.admin.v2.CheckConsistencyResponse]) |
| 51 | + /// is mapped to a C++ class using the [Protobuf mapping rules]. |
| 52 | + /// If the request fails, the [`StatusOr`] contains the error details. |
| 53 | + /// |
| 54 | + /// [Protobuf mapping rules]: https://protobuf.dev/reference/cpp/cpp-generated/ |
| 55 | + /// [input iterator requirements]: https://en.cppreference.com/w/cpp/named_req/InputIterator |
| 56 | + /// [`std::string`]: https://en.cppreference.com/w/cpp/string/basic_string |
| 57 | + /// [`future`]: @ref google::cloud::future |
| 58 | + /// [`StatusOr`]: @ref google::cloud::StatusOr |
| 59 | + /// [`Status`]: @ref google::cloud::Status |
| 60 | + /// [google.bigtable.admin.v2.CheckConsistencyRequest]: @googleapis_reference_link{google/bigtable/admin/v2/bigtable_table_admin.proto#L909} |
| 61 | + /// [google.bigtable.admin.v2.CheckConsistencyResponse]: @googleapis_reference_link{google/bigtable/admin/v2/bigtable_table_admin.proto#L948} |
| 62 | + /// |
| 63 | + // clang-format on |
| 64 | +)"""; |
| 65 | + } |
| 66 | + return ""; |
| 67 | +} |
| 68 | +} // namespace |
30 | 69 |
|
31 | 70 | ClientGenerator::ClientGenerator( |
32 | 71 | google::protobuf::ServiceDescriptor const* service_descriptor, |
@@ -380,6 +419,13 @@ R"""( std::unique_ptr<::google::cloud::AsyncStreamingReadWriteRpc< |
380 | 419 | __FILE__, __LINE__); |
381 | 420 | } |
382 | 421 |
|
| 422 | + for (auto const& method : bespoke_methods()) { |
| 423 | + HeaderPrint("\n"); |
| 424 | + HeaderPrint(FormatBespokeMethodComments(method.name())); |
| 425 | + HeaderPrint(absl::StrCat(method.return_type(), " ", method.name(), |
| 426 | + method.parameters(), ";")); |
| 427 | + } |
| 428 | + |
383 | 429 | HeaderPrint( // clang-format off |
384 | 430 | "\n" |
385 | 431 | " private:\n" |
@@ -716,6 +762,19 @@ std::unique_ptr<::google::cloud::AsyncStreamingReadWriteRpc< |
716 | 762 | __FILE__, __LINE__); |
717 | 763 | } |
718 | 764 |
|
| 765 | + for (auto const& method : bespoke_methods()) { |
| 766 | + CcPrint("\n"); |
| 767 | + CcPrint(absl::StrCat( |
| 768 | + method.return_type(), R"""( $client_class_name$::)""", method.name(), |
| 769 | + absl::StrReplaceAll(method.parameters(), {{" = {}", ""}}), |
| 770 | + absl::StrFormat(R"""( { |
| 771 | + internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_)); |
| 772 | + return connection_->%s(request); |
| 773 | +} |
| 774 | +)""", |
| 775 | + method.name()))); |
| 776 | + } |
| 777 | + |
719 | 778 | CcCloseNamespaces(); |
720 | 779 | return {}; |
721 | 780 | } |
|
0 commit comments