2012-02-27 06:28:20 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <DB/IO/ReadBuffer.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/** Позволяет считать из другого ReadBuffer не более указанного количества байт.
|
|
|
|
*/
|
|
|
|
class LimitReadBuffer : public ReadBuffer
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
ReadBuffer & in;
|
|
|
|
size_t limit;
|
2016-08-19 01:54:23 +00:00
|
|
|
|
|
|
|
bool nextImpl() override
|
2012-02-27 06:28:20 +00:00
|
|
|
{
|
|
|
|
if (count() >= limit || !in.next())
|
|
|
|
return false;
|
2016-08-19 01:54:23 +00:00
|
|
|
|
2012-02-27 06:28:20 +00:00
|
|
|
working_buffer = in.buffer();
|
|
|
|
if (limit - count() < working_buffer.size())
|
|
|
|
working_buffer.resize(limit - count());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2017-03-09 04:26:17 +00:00
|
|
|
LimitReadBuffer(ReadBuffer & in_, size_t limit_) : ReadBuffer(nullptr, 0), in(in_), limit(limit_) {}
|
2012-02-27 06:28:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|