diff --git a/generator/integration_tests/golden/v1/golden_kitchen_sink_connection.cc b/generator/integration_tests/golden/v1/golden_kitchen_sink_connection.cc index 9b8b075d20a28..46700ee5ca262 100644 --- a/generator/integration_tests/golden/v1/golden_kitchen_sink_connection.cc +++ b/generator/integration_tests/golden/v1/golden_kitchen_sink_connection.cc @@ -26,6 +26,7 @@ #include "google/cloud/common_options.h" #include "google/cloud/credentials.h" #include "google/cloud/grpc_options.h" +#include "google/cloud/internal/make_stream_range.h" #include "google/cloud/internal/pagination_range.h" #include "google/cloud/internal/unified_grpc_credentials.h" #include diff --git a/generator/internal/connection_generator.cc b/generator/internal/connection_generator.cc index c9736bf2413bf..20fb191b61bdd 100644 --- a/generator/internal/connection_generator.cc +++ b/generator/internal/connection_generator.cc @@ -358,6 +358,8 @@ Status ConnectionGenerator::GenerateCc() { "google/cloud/background_threads.h", "google/cloud/common_options.h", "google/cloud/credentials.h", "google/cloud/grpc_options.h", "google/cloud/internal/unified_grpc_credentials.h", + HasStreamingReadMethod() ? "google/cloud/internal/make_stream_range.h" + : "", HasPaginatedMethod() ? "google/cloud/internal/pagination_range.h" : ""}); CcSystemIncludes({"memory", "utility"}); diff --git a/google/cloud/aiplatform/v1/featurestore_online_serving_connection.cc b/google/cloud/aiplatform/v1/featurestore_online_serving_connection.cc index f886234d25c3c..468c94bc9e705 100644 --- a/google/cloud/aiplatform/v1/featurestore_online_serving_connection.cc +++ b/google/cloud/aiplatform/v1/featurestore_online_serving_connection.cc @@ -26,6 +26,7 @@ #include "google/cloud/common_options.h" #include "google/cloud/credentials.h" #include "google/cloud/grpc_options.h" +#include "google/cloud/internal/make_stream_range.h" #include "google/cloud/internal/pagination_range.h" #include "google/cloud/internal/unified_grpc_credentials.h" #include diff --git a/google/cloud/aiplatform/v1/prediction_connection.cc b/google/cloud/aiplatform/v1/prediction_connection.cc index 1a8782a66e2d6..e283cbb3537e1 100644 --- a/google/cloud/aiplatform/v1/prediction_connection.cc +++ b/google/cloud/aiplatform/v1/prediction_connection.cc @@ -26,6 +26,7 @@ #include "google/cloud/common_options.h" #include "google/cloud/credentials.h" #include "google/cloud/grpc_options.h" +#include "google/cloud/internal/make_stream_range.h" #include "google/cloud/internal/pagination_range.h" #include "google/cloud/internal/unified_grpc_credentials.h" #include diff --git a/google/cloud/aiplatform/v1/tensorboard_connection.cc b/google/cloud/aiplatform/v1/tensorboard_connection.cc index c441c7be40733..4abeb5b347d9a 100644 --- a/google/cloud/aiplatform/v1/tensorboard_connection.cc +++ b/google/cloud/aiplatform/v1/tensorboard_connection.cc @@ -26,6 +26,7 @@ #include "google/cloud/common_options.h" #include "google/cloud/credentials.h" #include "google/cloud/grpc_options.h" +#include "google/cloud/internal/make_stream_range.h" #include "google/cloud/internal/pagination_range.h" #include "google/cloud/internal/unified_grpc_credentials.h" #include diff --git a/google/cloud/biglake/hive/v1/hive_metastore_connection.cc b/google/cloud/biglake/hive/v1/hive_metastore_connection.cc index 685caf92f942e..37ac806f8de67 100644 --- a/google/cloud/biglake/hive/v1/hive_metastore_connection.cc +++ b/google/cloud/biglake/hive/v1/hive_metastore_connection.cc @@ -26,6 +26,7 @@ #include "google/cloud/common_options.h" #include "google/cloud/credentials.h" #include "google/cloud/grpc_options.h" +#include "google/cloud/internal/make_stream_range.h" #include "google/cloud/internal/pagination_range.h" #include "google/cloud/internal/unified_grpc_credentials.h" #include diff --git a/google/cloud/bigquery/storage/v1/bigquery_read_connection.cc b/google/cloud/bigquery/storage/v1/bigquery_read_connection.cc index e2b05e223efa2..4c4cdb4ab66f5 100644 --- a/google/cloud/bigquery/storage/v1/bigquery_read_connection.cc +++ b/google/cloud/bigquery/storage/v1/bigquery_read_connection.cc @@ -26,6 +26,7 @@ #include "google/cloud/common_options.h" #include "google/cloud/credentials.h" #include "google/cloud/grpc_options.h" +#include "google/cloud/internal/make_stream_range.h" #include "google/cloud/internal/unified_grpc_credentials.h" #include #include diff --git a/google/cloud/bigquery/v2/minimal/benchmarks/benchmark.cc b/google/cloud/bigquery/v2/minimal/benchmarks/benchmark.cc index 7c62b20e95cf2..5934841bbab04 100644 --- a/google/cloud/bigquery/v2/minimal/benchmarks/benchmark.cc +++ b/google/cloud/bigquery/v2/minimal/benchmarks/benchmark.cc @@ -17,6 +17,7 @@ #include "google/cloud/common_options.h" #include "google/cloud/internal/getenv.h" #include "google/cloud/internal/make_status.h" +#include "google/cloud/internal/make_stream_range.h" #include "google/cloud/internal/random.h" #include "google/cloud/options.h" #include "google/cloud/stream_range.h" diff --git a/google/cloud/bigquery/v2/minimal/internal/dataset_connection.cc b/google/cloud/bigquery/v2/minimal/internal/dataset_connection.cc index 328152fa23d96..0867272f7eeba 100644 --- a/google/cloud/bigquery/v2/minimal/internal/dataset_connection.cc +++ b/google/cloud/bigquery/v2/minimal/internal/dataset_connection.cc @@ -17,6 +17,7 @@ #include "google/cloud/bigquery/v2/minimal/internal/dataset_rest_stub_factory.h" #include "google/cloud/common_options.h" #include "google/cloud/credentials.h" +#include "google/cloud/internal/make_stream_range.h" #include namespace google { diff --git a/google/cloud/bigquery/v2/minimal/internal/job_connection.cc b/google/cloud/bigquery/v2/minimal/internal/job_connection.cc index da4f1bb9be640..0d59181399c64 100644 --- a/google/cloud/bigquery/v2/minimal/internal/job_connection.cc +++ b/google/cloud/bigquery/v2/minimal/internal/job_connection.cc @@ -17,6 +17,7 @@ #include "google/cloud/bigquery/v2/minimal/internal/job_rest_stub_factory.h" #include "google/cloud/common_options.h" #include "google/cloud/credentials.h" +#include "google/cloud/internal/make_stream_range.h" #include namespace google { diff --git a/google/cloud/bigquery/v2/minimal/internal/project_connection.cc b/google/cloud/bigquery/v2/minimal/internal/project_connection.cc index ac36ab9723071..7b9ddbf2ebfc3 100644 --- a/google/cloud/bigquery/v2/minimal/internal/project_connection.cc +++ b/google/cloud/bigquery/v2/minimal/internal/project_connection.cc @@ -18,6 +18,7 @@ #include "google/cloud/bigquery/v2/minimal/internal/project_rest_stub_factory.h" #include "google/cloud/common_options.h" #include "google/cloud/credentials.h" +#include "google/cloud/internal/make_stream_range.h" #include namespace google { diff --git a/google/cloud/bigquery/v2/minimal/internal/table_connection.cc b/google/cloud/bigquery/v2/minimal/internal/table_connection.cc index 82de28bf1744c..4d0b43460c46b 100644 --- a/google/cloud/bigquery/v2/minimal/internal/table_connection.cc +++ b/google/cloud/bigquery/v2/minimal/internal/table_connection.cc @@ -17,6 +17,7 @@ #include "google/cloud/bigquery/v2/minimal/internal/table_rest_stub_factory.h" #include "google/cloud/common_options.h" #include "google/cloud/credentials.h" +#include "google/cloud/internal/make_stream_range.h" #include namespace google { diff --git a/google/cloud/bigtable/row_reader.cc b/google/cloud/bigtable/row_reader.cc index aeb5960655140..7238620f0398a 100644 --- a/google/cloud/bigtable/row_reader.cc +++ b/google/cloud/bigtable/row_reader.cc @@ -15,6 +15,7 @@ #include "google/cloud/bigtable/row_reader.h" #include "google/cloud/bigtable/table.h" #include "google/cloud/grpc_error_delegate.h" +#include "google/cloud/internal/make_stream_range.h" #include "google/cloud/internal/throw_delegate.h" #include "google/cloud/log.h" #include diff --git a/google/cloud/bigtable/testing/cleanup_stale_resources_test.cc b/google/cloud/bigtable/testing/cleanup_stale_resources_test.cc index 17617972d501a..474899732cc4c 100644 --- a/google/cloud/bigtable/testing/cleanup_stale_resources_test.cc +++ b/google/cloud/bigtable/testing/cleanup_stale_resources_test.cc @@ -17,6 +17,7 @@ #include "google/cloud/bigtable/admin/mocks/mock_bigtable_table_admin_connection.h" #include "google/cloud/bigtable/resource_names.h" #include "google/cloud/bigtable/testing/random_names.h" +#include "google/cloud/internal/make_stream_range.h" #include "google/cloud/project.h" #include diff --git a/google/cloud/ces/v1/session_connection.cc b/google/cloud/ces/v1/session_connection.cc index 5d3412f0b68a9..484fabdad0c85 100644 --- a/google/cloud/ces/v1/session_connection.cc +++ b/google/cloud/ces/v1/session_connection.cc @@ -26,6 +26,7 @@ #include "google/cloud/common_options.h" #include "google/cloud/credentials.h" #include "google/cloud/grpc_options.h" +#include "google/cloud/internal/make_stream_range.h" #include "google/cloud/internal/pagination_range.h" #include "google/cloud/internal/unified_grpc_credentials.h" #include diff --git a/google/cloud/datacatalog/lineage/v1/lineage_connection.cc b/google/cloud/datacatalog/lineage/v1/lineage_connection.cc index 9efd11c831ebf..ffebbc80cf866 100644 --- a/google/cloud/datacatalog/lineage/v1/lineage_connection.cc +++ b/google/cloud/datacatalog/lineage/v1/lineage_connection.cc @@ -26,6 +26,7 @@ #include "google/cloud/common_options.h" #include "google/cloud/credentials.h" #include "google/cloud/grpc_options.h" +#include "google/cloud/internal/make_stream_range.h" #include "google/cloud/internal/pagination_range.h" #include "google/cloud/internal/unified_grpc_credentials.h" #include diff --git a/google/cloud/dialogflow_cx/sessions_connection.cc b/google/cloud/dialogflow_cx/sessions_connection.cc index 97cf1842b7903..0722a08a8334d 100644 --- a/google/cloud/dialogflow_cx/sessions_connection.cc +++ b/google/cloud/dialogflow_cx/sessions_connection.cc @@ -26,6 +26,7 @@ #include "google/cloud/common_options.h" #include "google/cloud/credentials.h" #include "google/cloud/grpc_options.h" +#include "google/cloud/internal/make_stream_range.h" #include "google/cloud/internal/pagination_range.h" #include "google/cloud/internal/unified_grpc_credentials.h" #include diff --git a/google/cloud/discoveryengine/v1/conversational_search_connection.cc b/google/cloud/discoveryengine/v1/conversational_search_connection.cc index 385734d91e1e0..c5be577d477fc 100644 --- a/google/cloud/discoveryengine/v1/conversational_search_connection.cc +++ b/google/cloud/discoveryengine/v1/conversational_search_connection.cc @@ -26,6 +26,7 @@ #include "google/cloud/common_options.h" #include "google/cloud/credentials.h" #include "google/cloud/grpc_options.h" +#include "google/cloud/internal/make_stream_range.h" #include "google/cloud/internal/pagination_range.h" #include "google/cloud/internal/unified_grpc_credentials.h" #include diff --git a/google/cloud/geminidataanalytics/v1/data_chat_connection.cc b/google/cloud/geminidataanalytics/v1/data_chat_connection.cc index a99aeb1e20885..dbb37e7e4bd99 100644 --- a/google/cloud/geminidataanalytics/v1/data_chat_connection.cc +++ b/google/cloud/geminidataanalytics/v1/data_chat_connection.cc @@ -26,6 +26,7 @@ #include "google/cloud/common_options.h" #include "google/cloud/credentials.h" #include "google/cloud/grpc_options.h" +#include "google/cloud/internal/make_stream_range.h" #include "google/cloud/internal/pagination_range.h" #include "google/cloud/internal/unified_grpc_credentials.h" #include diff --git a/google/cloud/google_cloud_cpp_common.bzl b/google/cloud/google_cloud_cpp_common.bzl index e8b0354ef6f47..f3a4f2483f516 100644 --- a/google/cloud/google_cloud_cpp_common.bzl +++ b/google/cloud/google_cloud_cpp_common.bzl @@ -63,6 +63,7 @@ google_cloud_cpp_common_hdrs = [ "internal/ios_flags_saver.h", "internal/log_impl.h", "internal/make_status.h", + "internal/make_stream_range.h", "internal/noexcept_action.h", "internal/non_constructible.h", "internal/opentelemetry.h", diff --git a/google/cloud/google_cloud_cpp_common.cmake b/google/cloud/google_cloud_cpp_common.cmake index f66b24a63d02a..ffc139c7f17ba 100644 --- a/google/cloud/google_cloud_cpp_common.cmake +++ b/google/cloud/google_cloud_cpp_common.cmake @@ -98,6 +98,7 @@ add_library( internal/log_impl.h internal/make_status.cc internal/make_status.h + internal/make_stream_range.h internal/noexcept_action.cc internal/noexcept_action.h internal/non_constructible.h diff --git a/google/cloud/internal/make_stream_range.h b/google/cloud/internal/make_stream_range.h new file mode 100644 index 0000000000000..f798ea23b2f41 --- /dev/null +++ b/google/cloud/internal/make_stream_range.h @@ -0,0 +1,82 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_INTERNAL_MAKE_STREAM_RANGE_H +#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_INTERNAL_MAKE_STREAM_RANGE_H + +#include "google/cloud/internal/call_context.h" +#include "google/cloud/options.h" +#include "google/cloud/status.h" +#include "google/cloud/stream_range.h" +#include "google/cloud/version.h" +#include +#include +#include + +namespace google { +namespace cloud { +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN +namespace internal { + +/** + * A function that repeatedly returns `T`s, and ends with a `Status`. + * + * This function should return instances of `T` from its underlying stream + * until there are no more. The end-of-stream is indicated by returning a + * `Status` indicating either success or an error. This function will not be + * invoked any more after it returns any `Status`. + * + * @par Example: returning the integers from 1-10. + * + * @code + * int counter = 0; + * auto reader = [&counter](Options const&) -> StreamReader::result_type { + * if (++counter <= 10) return counter; + * return Status{}; // OK + * }; + * @endcode + */ +template +using StreamReader = std::function()>; + +/** + * Factory to construct a `StreamRange` with the given `StreamReader`. + * + * Callers should explicitly specify the `T` parameter when calling this + * function template so that lambdas will implicitly convert to the underlying + * `StreamReader` (i.e., std::function). For example: + * + * @code + * StreamReader empty = MakeStreamReader([] { return Status{}; }); + * @endcode + */ +template +StreamRange MakeStreamRange(ImmutableOptions options, + StreamReaderExplicit reader) { + return StreamRange{std::move(options), std::move(reader)}; +} + +// TODO(#12359) - remove overload when `*Stub` consumes Options. +template +StreamRange MakeStreamRange(StreamReader reader) { + auto wrapper = [r = std::move(reader)](Options const&) { return r(); }; + return MakeStreamRange(SaveCurrentOptions(), std::move(wrapper)); +} + +} // namespace internal +GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END +} // namespace cloud +} // namespace google + +#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_INTERNAL_MAKE_STREAM_RANGE_H diff --git a/google/cloud/internal/pagination_range.h b/google/cloud/internal/pagination_range.h index d0a85fa619ed7..55231bd21c5cd 100644 --- a/google/cloud/internal/pagination_range.h +++ b/google/cloud/internal/pagination_range.h @@ -16,6 +16,7 @@ #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_INTERNAL_PAGINATION_RANGE_H #include "google/cloud/internal/invoke_result.h" +#include "google/cloud/internal/make_stream_range.h" #include "google/cloud/internal/type_traits.h" #include "google/cloud/status_or.h" #include "google/cloud/stream_range.h" diff --git a/google/cloud/internal/resumable_streaming_read_rpc.h b/google/cloud/internal/resumable_streaming_read_rpc.h index 560999f30aa93..6d65e96541119 100644 --- a/google/cloud/internal/resumable_streaming_read_rpc.h +++ b/google/cloud/internal/resumable_streaming_read_rpc.h @@ -15,6 +15,7 @@ #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_INTERNAL_RESUMABLE_STREAMING_READ_RPC_H #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_INTERNAL_RESUMABLE_STREAMING_READ_RPC_H +#include "google/cloud/internal/make_stream_range.h" #include "google/cloud/internal/streaming_read_rpc.h" #include "google/cloud/version.h" #include diff --git a/google/cloud/internal/traced_stream_range.h b/google/cloud/internal/traced_stream_range.h index 6eff998cab890..1c067e7bf347f 100644 --- a/google/cloud/internal/traced_stream_range.h +++ b/google/cloud/internal/traced_stream_range.h @@ -15,6 +15,7 @@ #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_INTERNAL_TRACED_STREAM_RANGE_H #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_INTERNAL_TRACED_STREAM_RANGE_H +#include "google/cloud/internal/make_stream_range.h" #include "google/cloud/internal/opentelemetry.h" #include "google/cloud/stream_range.h" #include diff --git a/google/cloud/mocks/mock_stream_range.h b/google/cloud/mocks/mock_stream_range.h index fc75a15b8de61..2b56479856cc7 100644 --- a/google/cloud/mocks/mock_stream_range.h +++ b/google/cloud/mocks/mock_stream_range.h @@ -15,6 +15,7 @@ #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_MOCKS_MOCK_STREAM_RANGE_H #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_MOCKS_MOCK_STREAM_RANGE_H +#include "google/cloud/internal/make_stream_range.h" #include "google/cloud/status.h" #include "google/cloud/stream_range.h" #include diff --git a/google/cloud/osconfig/agentendpoint/v1/agent_endpoint_connection.cc b/google/cloud/osconfig/agentendpoint/v1/agent_endpoint_connection.cc index 152cc5ba5d6de..3ebb43ebc7f14 100644 --- a/google/cloud/osconfig/agentendpoint/v1/agent_endpoint_connection.cc +++ b/google/cloud/osconfig/agentendpoint/v1/agent_endpoint_connection.cc @@ -26,6 +26,7 @@ #include "google/cloud/common_options.h" #include "google/cloud/credentials.h" #include "google/cloud/grpc_options.h" +#include "google/cloud/internal/make_stream_range.h" #include "google/cloud/internal/unified_grpc_credentials.h" #include #include diff --git a/google/cloud/spanner/connection.cc b/google/cloud/spanner/connection.cc index 7b8319a94ea30..d4e67fdbb2346 100644 --- a/google/cloud/spanner/connection.cc +++ b/google/cloud/spanner/connection.cc @@ -15,6 +15,7 @@ #include "google/cloud/spanner/connection.h" #include "google/cloud/spanner/query_partition.h" #include "google/cloud/spanner/read_partition.h" +#include "google/cloud/internal/make_stream_range.h" namespace google { namespace cloud { diff --git a/google/cloud/stream_range.h b/google/cloud/stream_range.h index 3d372054c3d53..895dec1840a04 100644 --- a/google/cloud/stream_range.h +++ b/google/cloud/stream_range.h @@ -35,32 +35,11 @@ class StreamRange; namespace internal { -/** - * A function that repeatedly returns `T`s, and ends with a `Status`. - * - * This function should return instances of `T` from its underlying stream - * until there are no more. The end-of-stream is indicated by returning a - * `Status` indicating either success or an error. This function will not be - * invoked any more after it returns any `Status`. - * - * @par Example: returning the integers from 1-10. - * - * @code - * int counter = 0; - * auto reader = [&counter](Options const&) -> StreamReader::result_type { - * if (++counter <= 10) return counter; - * return Status{}; // OK - * }; - * @endcode - */ -template -using StreamReader = std::function()>; - template using StreamReaderExplicit = std::function(Options const&)>; -// Defined below. +// Defined in make_stream_range.h. template StreamRange MakeStreamRange(ImmutableOptions, StreamReaderExplicit); @@ -252,34 +231,6 @@ class StreamRange { bool is_end_ = true; }; -namespace internal { - -/** - * Factory to construct a `StreamRange` with the given `StreamReader`. - * - * Callers should explicitly specify the `T` parameter when calling this - * function template so that lambdas will implicitly convert to the underlying - * `StreamReader` (i.e., std::function). For example: - * - * @code - * StreamReader empty = MakeStreamReader([] { return Status{}; }); - * @endcode - */ -template -StreamRange MakeStreamRange(ImmutableOptions options, - StreamReaderExplicit reader) { - return StreamRange{std::move(options), std::move(reader)}; -} - -// TODO(#12359) - remove overload when `*Stub` consumes Options. -template -StreamRange MakeStreamRange(StreamReader reader) { - auto wrapper = [r = std::move(reader)](Options const&) { return r(); }; - return MakeStreamRange(SaveCurrentOptions(), std::move(wrapper)); -} - -} // namespace internal - GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END } // namespace cloud } // namespace google diff --git a/google/cloud/stream_range_test.cc b/google/cloud/stream_range_test.cc index a4305136bd811..12504a5ad730e 100644 --- a/google/cloud/stream_range_test.cc +++ b/google/cloud/stream_range_test.cc @@ -13,6 +13,7 @@ // limitations under the License. #include "google/cloud/stream_range.h" +#include "google/cloud/internal/make_stream_range.h" #include "google/cloud/internal/opentelemetry.h" #include "google/cloud/options.h" #include "google/cloud/testing_util/opentelemetry_matchers.h"