mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 23:52:03 +00:00
Moved code to cpp [#CLICKHOUSE-2].
This commit is contained in:
parent
94a15df626
commit
09d83eecd0
35
dbms/src/IO/LimitReadBuffer.cpp
Normal file
35
dbms/src/IO/LimitReadBuffer.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
#include <IO/LimitReadBuffer.h>
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
bool LimitReadBuffer::nextImpl()
|
||||
{
|
||||
/// Let underlying buffer calculate read bytes in `next()` call.
|
||||
in.position() = position();
|
||||
|
||||
if (bytes >= limit || !in.next())
|
||||
return false;
|
||||
|
||||
working_buffer = in.buffer();
|
||||
|
||||
if (limit - bytes < working_buffer.size())
|
||||
working_buffer.resize(limit - bytes);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
LimitReadBuffer::LimitReadBuffer(ReadBuffer & in_, size_t limit_)
|
||||
: ReadBuffer(nullptr, 0), in(in_), limit(limit_) {}
|
||||
|
||||
|
||||
LimitReadBuffer::~LimitReadBuffer()
|
||||
{
|
||||
/// Update underlying buffer's position in case when limit wasn't reached.
|
||||
if (working_buffer.size() != 0)
|
||||
in.position() = position();
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <IO/ReadBuffer.h>
|
||||
|
||||
|
||||
@ -14,31 +15,11 @@ private:
|
||||
ReadBuffer & in;
|
||||
size_t limit;
|
||||
|
||||
bool nextImpl() override
|
||||
{
|
||||
/// Let underlying buffer calculate read bytes in `next()` call.
|
||||
in.position() = position();
|
||||
|
||||
if (bytes >= limit || !in.next())
|
||||
return false;
|
||||
|
||||
working_buffer = in.buffer();
|
||||
|
||||
if (limit - count() < working_buffer.size())
|
||||
working_buffer.resize(limit - count());
|
||||
|
||||
return true;
|
||||
}
|
||||
bool nextImpl() override;
|
||||
|
||||
public:
|
||||
LimitReadBuffer(ReadBuffer & in_, size_t limit_) : ReadBuffer(nullptr, 0), in(in_), limit(limit_) {}
|
||||
|
||||
~LimitReadBuffer() override
|
||||
{
|
||||
/// Update underlying buffer's position in case when limit wasn't reached.
|
||||
if (working_buffer.size() != 0)
|
||||
in.position() = position();
|
||||
}
|
||||
LimitReadBuffer(ReadBuffer & in_, size_t limit_);
|
||||
~LimitReadBuffer() override;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user