-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-43408: [C++] IO: Make Advance to virtual and naive implement it #43409
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -434,6 +434,32 @@ class BufferedInputStream::Impl : public BufferedBase { | |
return std::shared_ptr<Buffer>(std::move(buffer)); | ||
} | ||
|
||
Status Advance(int64_t nbytes) { | ||
if (nbytes < 0) { | ||
return Status::Invalid("Bytes to advance must be non-negative. Received:", nbytes); | ||
} | ||
if (nbytes == 0) { | ||
return Status::OK(); | ||
} | ||
|
||
if (nbytes < bytes_buffered_) { | ||
ConsumeBuffer(nbytes); | ||
return Status::OK(); | ||
} | ||
|
||
// Invalidate buffered data, as with a Seek or large Read | ||
int64_t remain_skip_bytes = nbytes - bytes_buffered_; | ||
RewindBuffer(); | ||
// TODO(mwish): Considering using raw_->Advance if available, | ||
// currently we don't have a way to know if the underlying stream supports fast | ||
// skipping. So we just read and discard the data. | ||
Comment on lines
+453
to
+455
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe some code like:
Would help, a |
||
auto result = Read(remain_skip_bytes); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not simply call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If underlying don't have |
||
if (!result.ok()) { | ||
return result.status(); | ||
} | ||
return Status::OK(); | ||
} | ||
|
||
// For providing access to the raw file handles | ||
std::shared_ptr<InputStream> raw() const { return raw_; } | ||
|
||
|
@@ -498,6 +524,8 @@ Result<std::shared_ptr<Buffer>> BufferedInputStream::DoRead(int64_t nbytes) { | |
return impl_->Read(nbytes); | ||
} | ||
|
||
Status BufferedInputStream::DoAdvance(int64_t nbytes) { return impl_->Advance(nbytes); } | ||
|
||
Result<std::shared_ptr<const KeyValueMetadata>> BufferedInputStream::ReadMetadata() { | ||
return impl_->raw()->ReadMetadata(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.