Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 <memory>
Expand Down
2 changes: 2 additions & 0 deletions generator/internal/connection_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <memory>
Expand Down
1 change: 1 addition & 0 deletions google/cloud/aiplatform/v1/prediction_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <memory>
Expand Down
1 change: 1 addition & 0 deletions google/cloud/aiplatform/v1/tensorboard_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <memory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <memory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <memory>
#include <utility>
Expand Down
1 change: 1 addition & 0 deletions google/cloud/bigquery/v2/minimal/benchmarks/benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <memory>

namespace google {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <memory>

namespace google {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <memory>

namespace google {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <memory>

namespace google {
Expand Down
1 change: 1 addition & 0 deletions google/cloud/bigtable/row_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <iterator>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <gmock/gmock.h>

Expand Down
1 change: 1 addition & 0 deletions google/cloud/ces/v1/session_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <memory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <memory>
Expand Down
1 change: 1 addition & 0 deletions google/cloud/dialogflow_cx/sessions_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <memory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <memory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <memory>
Expand Down
1 change: 1 addition & 0 deletions google/cloud/google_cloud_cpp_common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions google/cloud/google_cloud_cpp_common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
82 changes: 82 additions & 0 deletions google/cloud/internal/make_stream_range.h
Original file line number Diff line number Diff line change
@@ -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 <functional>
#include <utility>
#include <variant>

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<int>::result_type {
* if (++counter <= 10) return counter;
* return Status{}; // OK
* };
* @endcode
*/
template <typename T>
using StreamReader = std::function<std::variant<Status, T>()>;

/**
* Factory to construct a `StreamRange<T>` with the given `StreamReader<T>`.
*
* Callers should explicitly specify the `T` parameter when calling this
* function template so that lambdas will implicitly convert to the underlying
* `StreamReader<T>` (i.e., std::function). For example:
*
* @code
* StreamReader<int> empty = MakeStreamReader<int>([] { return Status{}; });
* @endcode
*/
template <typename T>
StreamRange<T> MakeStreamRange(ImmutableOptions options,
StreamReaderExplicit<T> reader) {
return StreamRange<T>{std::move(options), std::move(reader)};
}

// TODO(#12359) - remove overload when `*Stub` consumes Options.
template <typename T>
StreamRange<T> MakeStreamRange(StreamReader<T> reader) {
auto wrapper = [r = std::move(reader)](Options const&) { return r(); };
return MakeStreamRange<T>(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
1 change: 1 addition & 0 deletions google/cloud/internal/pagination_range.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions google/cloud/internal/resumable_streaming_read_rpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <chrono>
Expand Down
1 change: 1 addition & 0 deletions google/cloud/internal/traced_stream_range.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <opentelemetry/nostd/shared_ptr.h>
Expand Down
1 change: 1 addition & 0 deletions google/cloud/mocks/mock_stream_range.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <vector>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <memory>
#include <utility>
Expand Down
1 change: 1 addition & 0 deletions google/cloud/spanner/connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
51 changes: 1 addition & 50 deletions google/cloud/stream_range.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>::result_type {
* if (++counter <= 10) return counter;
* return Status{}; // OK
* };
* @endcode
*/
template <typename T>
using StreamReader = std::function<std::variant<Status, T>()>;

template <typename T>
using StreamReaderExplicit =
std::function<std::variant<Status, T>(Options const&)>;

// Defined below.
// Defined in make_stream_range.h.
template <typename T>
StreamRange<T> MakeStreamRange(ImmutableOptions, StreamReaderExplicit<T>);

Expand Down Expand Up @@ -252,34 +231,6 @@ class StreamRange {
bool is_end_ = true;
};

namespace internal {

/**
* Factory to construct a `StreamRange<T>` with the given `StreamReader<T>`.
*
* Callers should explicitly specify the `T` parameter when calling this
* function template so that lambdas will implicitly convert to the underlying
* `StreamReader<T>` (i.e., std::function). For example:
*
* @code
* StreamReader<int> empty = MakeStreamReader<int>([] { return Status{}; });
* @endcode
*/
template <typename T>
StreamRange<T> MakeStreamRange(ImmutableOptions options,
StreamReaderExplicit<T> reader) {
return StreamRange<T>{std::move(options), std::move(reader)};
}

// TODO(#12359) - remove overload when `*Stub` consumes Options.
template <typename T>
StreamRange<T> MakeStreamRange(StreamReader<T> reader) {
auto wrapper = [r = std::move(reader)](Options const&) { return r(); };
return MakeStreamRange<T>(SaveCurrentOptions(), std::move(wrapper));
}

} // namespace internal

GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
} // namespace cloud
} // namespace google
Expand Down
1 change: 1 addition & 0 deletions google/cloud/stream_range_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading