2012-02-27 06:28:20 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-10-02 07:13:14 +00:00
|
|
|
#include <base/types.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <IO/ReadBuffer.h>
|
2012-02-27 06:28:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-08-14 04:26:52 +00:00
|
|
|
/** Allows to read from another ReadBuffer no more than the specified number of bytes.
|
2018-11-30 15:36:41 +00:00
|
|
|
* Note that the nested ReadBuffer may read slightly more data internally to fill its buffer.
|
2012-02-27 06:28:20 +00:00
|
|
|
*/
|
2017-08-14 04:30:37 +00:00
|
|
|
class LimitReadBuffer : public ReadBuffer
|
|
|
|
{
|
2021-02-19 12:51:26 +00:00
|
|
|
public:
|
2023-02-22 16:54:35 +00:00
|
|
|
LimitReadBuffer(ReadBuffer & in_, UInt64 limit_, bool throw_exception_,
|
|
|
|
std::optional<size_t> exact_limit_, std::string exception_message_ = {});
|
|
|
|
LimitReadBuffer(std::unique_ptr<ReadBuffer> in_, UInt64 limit_, bool throw_exception_, std::optional<size_t> exact_limit_,
|
2023-02-22 01:34:03 +00:00
|
|
|
std::string exception_message_ = {});
|
2021-02-19 12:51:26 +00:00
|
|
|
~LimitReadBuffer() override;
|
|
|
|
|
2017-08-14 04:30:37 +00:00
|
|
|
private:
|
2021-02-19 12:51:26 +00:00
|
|
|
ReadBuffer * in;
|
|
|
|
bool owns_in;
|
|
|
|
|
2019-02-10 15:17:45 +00:00
|
|
|
UInt64 limit;
|
2018-08-20 02:23:35 +00:00
|
|
|
bool throw_exception;
|
2023-02-22 16:54:35 +00:00
|
|
|
std::optional<size_t> exact_limit;
|
2018-08-20 02:23:35 +00:00
|
|
|
std::string exception_message;
|
2017-08-14 03:38:32 +00:00
|
|
|
|
2023-02-22 16:54:35 +00:00
|
|
|
LimitReadBuffer(ReadBuffer * in_, bool owns, UInt64 limit_, bool throw_exception_, std::optional<size_t> exact_limit_, std::string exception_message_);
|
2017-08-14 03:38:32 +00:00
|
|
|
|
2021-02-19 12:51:26 +00:00
|
|
|
bool nextImpl() override;
|
2017-08-14 04:30:37 +00:00
|
|
|
};
|
2012-02-27 06:28:20 +00:00
|
|
|
|
|
|
|
}
|