2011-10-30 05:19:41 +00:00
|
|
|
#pragma once
|
|
|
|
|
2011-10-31 06:37:12 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2011-10-30 05:19:41 +00:00
|
|
|
#include <DB/IO/ReadBuffer.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/** Читает из конкатенации нескольких ReadBuffer-ов
|
|
|
|
*/
|
|
|
|
class ConcatReadBuffer : public ReadBuffer
|
|
|
|
{
|
2011-10-31 06:37:12 +00:00
|
|
|
public:
|
2016-05-28 10:35:44 +00:00
|
|
|
using ReadBuffers = std::vector<ReadBuffer *>;
|
2015-02-07 23:13:04 +00:00
|
|
|
|
2011-10-31 06:37:12 +00:00
|
|
|
protected:
|
2011-10-30 05:19:41 +00:00
|
|
|
ReadBuffers buffers;
|
|
|
|
ReadBuffers::iterator current;
|
2015-02-07 23:13:04 +00:00
|
|
|
|
2011-10-30 05:19:41 +00:00
|
|
|
bool nextImpl()
|
|
|
|
{
|
2011-10-31 06:37:12 +00:00
|
|
|
if (buffers.end() == current)
|
|
|
|
return false;
|
2015-02-07 23:13:04 +00:00
|
|
|
|
2011-10-31 06:37:12 +00:00
|
|
|
/// Первое чтение
|
2015-02-07 23:13:04 +00:00
|
|
|
if (working_buffer.size() == 0 && (*current)->hasPendingData())
|
2011-10-31 06:37:12 +00:00
|
|
|
{
|
2014-04-24 20:18:00 +00:00
|
|
|
working_buffer = Buffer((*current)->position(), (*current)->buffer().end());
|
2011-10-31 06:37:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-02-07 23:13:04 +00:00
|
|
|
|
2011-10-30 05:19:41 +00:00
|
|
|
if (!(*current)->next())
|
|
|
|
{
|
|
|
|
++current;
|
|
|
|
if (buffers.end() == current)
|
|
|
|
return false;
|
2012-03-05 04:29:16 +00:00
|
|
|
|
|
|
|
/// Пропускаем закончившиеся буферы; если буфер не закончился, но курсор на конце, то прочитаем следующую порцию данных.
|
|
|
|
while ((*current)->eof())
|
|
|
|
{
|
|
|
|
++current;
|
|
|
|
if (buffers.end() == current)
|
|
|
|
return false;
|
|
|
|
}
|
2011-10-30 05:19:41 +00:00
|
|
|
}
|
2015-02-07 23:13:04 +00:00
|
|
|
|
2014-04-24 20:18:00 +00:00
|
|
|
working_buffer = Buffer((*current)->position(), (*current)->buffer().end());
|
2011-10-30 05:19:41 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2014-04-08 07:58:53 +00:00
|
|
|
ConcatReadBuffer(const ReadBuffers & buffers_) : ReadBuffer(nullptr, 0), buffers(buffers_), current(buffers.begin()) {}
|
2011-10-30 05:19:41 +00:00
|
|
|
|
2014-04-08 07:58:53 +00:00
|
|
|
ConcatReadBuffer(ReadBuffer & buf1, ReadBuffer & buf2) : ReadBuffer(nullptr, 0)
|
2011-10-30 05:19:41 +00:00
|
|
|
{
|
2011-10-31 06:37:12 +00:00
|
|
|
buffers.push_back(&buf1);
|
|
|
|
buffers.push_back(&buf2);
|
2011-10-30 05:19:41 +00:00
|
|
|
current = buffers.begin();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|