@@ -26,9 +26,12 @@ namespace cloud {
2626namespace storage_internal {
2727GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
2828
29- GrpcObjectReadSource::GrpcObjectReadSource (TimerSource timer_source,
30- std::unique_ptr<StreamingRpc> stream)
31- : timer_source_(std::move(timer_source)), stream_(std::move(stream)) {}
29+ GrpcObjectReadSource::GrpcObjectReadSource (
30+ TimerSource timer_source, std::unique_ptr<StreamingRpc> stream,
31+ std::shared_ptr<storage::internal::HashFunction> hash_function)
32+ : timer_source_(std::move(timer_source)),
33+ stream_ (std::move(stream)),
34+ hash_function_(std::move(hash_function)) {}
3235
3336StatusOr<storage::internal::HttpResponse> GrpcObjectReadSource::Close () {
3437 if (stream_) stream_ = nullptr ;
@@ -74,18 +77,30 @@ StatusOr<storage::internal::ReadSourceResult> GrpcObjectReadSource::Read(
7477 if (!status_.ok ()) return status_;
7578 return result;
7679 }
77- HandleResponse (result, buf, n, std::move (response));
80+ auto handle_status = HandleResponse (result, buf, n, std::move (response));
81+ if (!handle_status.ok ()) return handle_status;
7882 }
7983
8084 return result;
8185}
8286
83- void GrpcObjectReadSource::HandleResponse (
87+ Status GrpcObjectReadSource::HandleResponse (
8488 storage::internal::ReadSourceResult& result, char * buf, std::size_t n,
8589 google::storage::v2::ReadObjectResponse response) {
90+ if (!offset_ && response.has_content_range ()) {
91+ offset_ = response.content_range ().start ();
92+ }
8693 // The google.storage.v1.Storage documentation says this field can be
8794 // empty.
8895 if (response.has_checksummed_data ()) {
96+ auto const & data = response.checksummed_data ();
97+ auto status = hash_function_->Update (offset_.value_or (0 ),
98+ GetContent (data),
99+ data.crc32c ());
100+ if (!status.ok ()) return status;
101+
102+ offset_ = offset_.value_or (0 ) + GetContent (data).size ();
103+
89104 auto const offset = result.bytes_received ;
90105 result.bytes_received += buffer_.HandleResponse (
91106 buf + offset, n - offset,
@@ -115,6 +130,7 @@ void GrpcObjectReadSource::HandleResponse(
115130 result.storage_class .value_or (metadata.storage_class ());
116131 result.size = result.size .value_or (metadata.size ());
117132 }
133+ return {};
118134}
119135
120136GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
0 commit comments