Skip to content

Commit

Permalink
Fix offset handling too
Browse files Browse the repository at this point in the history
  • Loading branch information
coryan committed Jul 25, 2024
1 parent 636f45e commit 830d1e4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
17 changes: 8 additions & 9 deletions google/cloud/storage/internal/async/reader_connection_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ future<AsyncReaderConnectionImpl::ReadResponse>
AsyncReaderConnectionImpl::OnRead(absl::optional<ProtoPayload> r) {
if (!r) return DoFinish();
auto response = *std::move(r);
auto hash =
hash_function_->Update(offset_, GetContent(response.checksummed_data()),
response.checksummed_data().crc32c());
if (!offset_ && response.has_content_range()) {
offset_ = response.content_range().start();
}
auto hash = hash_function_->Update(offset_.value_or(0),
GetContent(response.checksummed_data()),
response.checksummed_data().crc32c());
if (!hash.ok()) return HandleHashError(std::move(hash));
auto result = ReadPayloadImpl::Make(
StealMutableContent(*response.mutable_checksummed_data()));
Expand All @@ -61,12 +64,8 @@ AsyncReaderConnectionImpl::OnRead(absl::optional<ProtoPayload> r) {
if (response.has_metadata()) {
result.set_metadata(std::move(*response.mutable_metadata()));
}
if (response.has_content_range()) {
result.set_offset(response.content_range().start());
} else {
result.set_offset(offset_);
}
offset_ = result.offset() + result.size();
result.set_offset(offset_.value_or(0));
offset_ = offset_.value_or(0) + result.size();
return make_ready_future(ReadResponse(std::move(result)));
}

Expand Down
3 changes: 2 additions & 1 deletion google/cloud/storage/internal/async/reader_connection_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "google/cloud/internal/async_streaming_read_rpc.h"
#include "google/cloud/options.h"
#include "google/cloud/version.h"
#include "absl/types/optional.h"
#include <google/storage/v2/storage.pb.h>
#include <cstdint>
#include <memory>
Expand Down Expand Up @@ -59,7 +60,7 @@ class AsyncReaderConnectionImpl
std::shared_ptr<storage::internal::HashFunction> hash_;
std::unique_ptr<StreamingRpc> impl_;
std::shared_ptr<storage::internal::HashFunction> hash_function_;
std::int64_t offset_ = 0;
absl::optional<std::int64_t> offset_;
};

GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
Expand Down

0 comments on commit 830d1e4

Please sign in to comment.