mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-05 15:21:43 +00:00
34 lines
634 B
C++
34 lines
634 B
C++
#pragma once
|
|
|
|
#include <DB/IO/ReadBuffer.h>
|
|
|
|
|
|
namespace DB
|
|
{
|
|
|
|
/** Позволяет считать из другого ReadBuffer не более указанного количества байт.
|
|
*/
|
|
class LimitReadBuffer : public ReadBuffer
|
|
{
|
|
private:
|
|
ReadBuffer & in;
|
|
size_t limit;
|
|
|
|
bool nextImpl() override
|
|
{
|
|
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:
|
|
LimitReadBuffer(ReadBuffer & in_, size_t limit_) : ReadBuffer(nullptr, 0), in(in_), limit(limit_) {}
|
|
};
|
|
|
|
}
|