mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-13 11:04:10 +00:00
34 lines
628 B
C
34 lines
628 B
C
|
#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:
|
||
|
LimitReadBuffer(ReadBuffer & in_, size_t limit_) : ReadBuffer(NULL, 0), in(in_), limit(limit_) {}
|
||
|
};
|
||
|
|
||
|
}
|