ClickHouse/src/IO/BoundedReadBuffer.h

38 lines
959 B
C++
Raw Normal View History

2022-05-25 20:45:31 +00:00
#pragma once
2022-05-25 18:28:46 +00:00
#include <IO/ReadBufferFromFileDecorator.h>
namespace DB
{
class BoundedReadBuffer : public ReadBufferFromFileDecorator
{
public:
explicit BoundedReadBuffer(std::unique_ptr<SeekableReadBuffer> impl_);
bool supportsRightBoundedReads() const override { return true; }
void setReadUntilPosition(size_t position) override;
void setReadUntilEnd() override;
bool nextImpl() override;
off_t seek(off_t off, int whence) override;
2022-05-27 13:10:52 +00:00
Range getRemainingReadRange() const override;
2022-05-30 18:35:31 +00:00
size_t getFileOffsetOfBufferEnd() const override { return file_offset_of_buffer_end; }
/// file_offset_of_buffer_end can differ from impl's file_offset_of_buffer_end
2022-05-30 19:32:49 +00:00
/// because of resizing of the tail. => Need to also override getPosition() as
2022-05-30 18:35:31 +00:00
/// it uses file_offset_of_buffer_end.
off_t getPosition() override;
2022-05-25 18:28:46 +00:00
private:
std::optional<size_t> read_until_position;
size_t file_offset_of_buffer_end = 0;
};
}