Google Cloud Storage C++ Client  1.24.0
A C++ Client Library for Google Cloud Storage
object_rewriter.h
Go to the documentation of this file.
1 // Copyright 2018 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_STORAGE_OBJECT_REWRITER_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_OBJECT_REWRITER_H
17 
18 #include "google/cloud/storage/internal/raw_client.h"
20 #include "google/cloud/internal/invoke_result.h"
21 
22 namespace google {
23 namespace cloud {
24 namespace storage {
25 inline namespace STORAGE_CLIENT_NS {
35  std::uint64_t total_bytes_rewritten;
36  std::uint64_t object_size;
37  bool done;
38 };
39 
49  public:
50  ObjectRewriter(std::shared_ptr<internal::RawClient> client,
51  internal::RewriteObjectRequest request);
52 
60  StatusOr<RewriteProgress> Iterate();
61 
63  StatusOr<RewriteProgress> CurrentProgress() const {
64  if (!last_error_.ok()) {
65  return last_error_;
66  }
67  return progress_;
68  }
69 
80  StatusOr<ObjectMetadata> Result() {
81  return ResultWithProgressCallback([](StatusOr<RewriteProgress> const&) {});
82  }
83 
99  template <
100  typename Functor,
101  typename std::enable_if<google::cloud::internal::is_invocable<
102  Functor, StatusOr<RewriteProgress>>::value,
103  int>::type = 0>
104  StatusOr<ObjectMetadata> ResultWithProgressCallback(Functor cb) {
105  while (!progress_.done) {
106  cb(Iterate());
107  }
108  if (!last_error_.ok()) {
109  return last_error_;
110  }
111  return result_;
112  }
113 
128  std::string const& token() const { return request_.rewrite_token(); }
129 
130  private:
131  std::shared_ptr<internal::RawClient> client_;
132  internal::RewriteObjectRequest request_;
133  RewriteProgress progress_;
134  ObjectMetadata result_;
135  Status last_error_;
136 };
137 } // namespace STORAGE_CLIENT_NS
138 } // namespace storage
139 } // namespace cloud
140 } // namespace google
141 
142 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_OBJECT_REWRITER_H
google::cloud::storage::v1::ObjectMetadata
Represents the metadata for a Google Cloud Storage Object.
Definition: object_metadata.h:88
google::cloud::storage::v1::RewriteProgress
Represents the status of a rewrite operation.
Definition: object_rewriter.h:34
google::cloud::storage::v1::RewriteProgress::object_size
std::uint64_t object_size
Definition: object_rewriter.h:36
google::cloud::storage::v1::ObjectRewriter::CurrentProgress
StatusOr< RewriteProgress > CurrentProgress() const
The current progress on the rewrite operation.
Definition: object_rewriter.h:63
google::cloud::storage::v1::ObjectRewriter
Complete long running object rewrite operations.
Definition: object_rewriter.h:48
google::cloud::storage::v1::RewriteProgress::done
bool done
Definition: object_rewriter.h:37
version.h
google::cloud::storage::v1::ObjectRewriter::ResultWithProgressCallback
StatusOr< ObjectMetadata > ResultWithProgressCallback(Functor cb)
Iterate until the operation completes using a callback to report progress.
Definition: object_rewriter.h:104
google::cloud::storage::v1::ObjectRewriter::token
std::string const & token() const
The current rewrite token.
Definition: object_rewriter.h:128
google::cloud::storage::v1::RewriteProgress::total_bytes_rewritten
std::uint64_t total_bytes_rewritten
Definition: object_rewriter.h:35
google::cloud::storage::v1::ObjectRewriter::Result
StatusOr< ObjectMetadata > Result()
Iterate until the operation completes using a callback to report progress.
Definition: object_rewriter.h:80
STORAGE_CLIENT_NS
#define STORAGE_CLIENT_NS
Definition: version.h:22
google