2023-01-10 00:32:37 +00:00
|
|
|
#include <IO/ReadBuffer.h>
|
2024-01-27 21:13:08 +00:00
|
|
|
#include <IO/ReadBufferWrapperBase.h>
|
2023-01-10 00:32:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
template <typename CustomData>
|
2024-01-27 21:13:08 +00:00
|
|
|
class ReadBufferWrapper : public ReadBuffer, public ReadBufferWrapperBase
|
2023-01-10 00:32:37 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
ReadBufferWrapper(ReadBuffer & in_, CustomData && custom_data_)
|
|
|
|
: ReadBuffer(in_.buffer().begin(), in_.buffer().size(), in_.offset()), in(in_), custom_data(std::move(custom_data_))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-01-27 21:13:08 +00:00
|
|
|
const ReadBuffer & getWrappedReadBuffer() const override { return in; }
|
|
|
|
|
2023-01-10 00:32:37 +00:00
|
|
|
private:
|
|
|
|
ReadBuffer & in;
|
|
|
|
CustomData custom_data;
|
|
|
|
|
|
|
|
bool nextImpl() override
|
|
|
|
{
|
|
|
|
in.position() = position();
|
|
|
|
if (!in.next())
|
|
|
|
{
|
|
|
|
set(in.position(), 0);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
BufferBase::set(in.buffer().begin(), in.buffer().size(), in.offset());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<ReadBuffer> wrapReadBufferReference(ReadBuffer & ref)
|
|
|
|
{
|
|
|
|
return std::make_unique<ReadBufferWrapper<nullptr_t>>(ref, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<ReadBuffer> wrapReadBufferPointer(ReadBufferPtr ptr)
|
|
|
|
{
|
|
|
|
return std::make_unique<ReadBufferWrapper<ReadBufferPtr>>(*ptr, ReadBufferPtr{ptr});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|