2011-10-30 05:19:41 +00:00
|
|
|
#pragma once
|
|
|
|
|
2011-10-31 06:37:12 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <IO/ReadBuffer.h>
|
2011-10-30 05:19:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-05-28 14:29:40 +00:00
|
|
|
/** Reads from the concatenation of multiple ReadBuffers
|
2011-10-30 05:19:41 +00:00
|
|
|
*/
|
|
|
|
class ConcatReadBuffer : public ReadBuffer
|
|
|
|
{
|
2011-10-31 06:37:12 +00:00
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
using ReadBuffers = std::vector<ReadBuffer *>;
|
2015-02-07 23:13:04 +00:00
|
|
|
|
2011-10-31 06:37:12 +00:00
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
ReadBuffers buffers;
|
|
|
|
ReadBuffers::iterator current;
|
2015-02-07 23:13:04 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
bool nextImpl() override
|
|
|
|
{
|
|
|
|
if (buffers.end() == current)
|
|
|
|
return false;
|
2015-02-07 23:13:04 +00:00
|
|
|
|
2017-05-28 14:29:40 +00:00
|
|
|
/// First reading
|
2021-02-03 12:31:45 +00:00
|
|
|
if (working_buffer.empty())
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2021-02-03 12:31:45 +00:00
|
|
|
if ((*current)->hasPendingData())
|
|
|
|
{
|
|
|
|
working_buffer = Buffer((*current)->position(), (*current)->buffer().end());
|
|
|
|
return true;
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2021-02-03 12:31:45 +00:00
|
|
|
else
|
|
|
|
(*current)->position() = position();
|
2015-02-07 23:13:04 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (!(*current)->next())
|
|
|
|
{
|
|
|
|
++current;
|
|
|
|
if (buffers.end() == current)
|
|
|
|
return false;
|
2012-03-05 04:29:16 +00:00
|
|
|
|
2017-05-28 14:29:40 +00:00
|
|
|
/// We skip the filled up buffers; if the buffer is not filled in, but the cursor is at the end, then read the next piece of data.
|
2017-04-01 07:20:54 +00:00
|
|
|
while ((*current)->eof())
|
|
|
|
{
|
|
|
|
++current;
|
|
|
|
if (buffers.end() == current)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2015-02-07 23:13:04 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
working_buffer = Buffer((*current)->position(), (*current)->buffer().end());
|
|
|
|
return true;
|
|
|
|
}
|
2011-10-30 05:19:41 +00:00
|
|
|
|
|
|
|
public:
|
2021-02-03 12:31:45 +00:00
|
|
|
explicit ConcatReadBuffer(const ReadBuffers & buffers_) : ReadBuffer(nullptr, 0), buffers(buffers_), current(buffers.begin())
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2021-02-03 12:31:45 +00:00
|
|
|
assert(!buffers.empty());
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2021-02-03 12:31:45 +00:00
|
|
|
|
|
|
|
ConcatReadBuffer(ReadBuffer & buf1, ReadBuffer & buf2) : ConcatReadBuffer({&buf1, &buf2}) {}
|
2011-10-30 05:19:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|