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;
|
|
|
|
|
|
|
|
bool nextImpl()
|
|
|
|
{
|
|
|
|
if (count() >= limit || !in.next())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
working_buffer = in.buffer();
|
|
|
|
if (limit - count() < working_buffer.size())
|
|
|
|
working_buffer.resize(limit - count());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2014-04-08 07:58:53 +00:00
|
|
|
LimitReadBuffer(ReadBuffer & in_, size_t limit_) : ReadBuffer(nullptr, 0), in(in_), limit(limit_) {}
|
2012-02-27 06:28:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|