2017-02-22 15:29:43 +00:00
|
|
|
#pragma once
|
|
|
|
#include <memory>
|
|
|
|
#include <DB/IO/ReadBuffer.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
struct IReadableWriteBuffer
|
|
|
|
{
|
2017-02-28 14:15:13 +00:00
|
|
|
/// At the first time returns getReadBufferImpl(). Next calls return nullptr.
|
|
|
|
inline std::shared_ptr<ReadBuffer> tryGetReadBuffer()
|
|
|
|
{
|
|
|
|
if (!can_reread)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
can_reread = false;
|
|
|
|
return getReadBufferImpl();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~IReadableWriteBuffer() {}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2017-02-22 15:29:43 +00:00
|
|
|
/// Creates read buffer from current write buffer.
|
|
|
|
/// Returned buffer points to the first byte of original buffer.
|
|
|
|
/// Original stream becomes invalid.
|
2017-02-28 14:15:13 +00:00
|
|
|
virtual std::shared_ptr<ReadBuffer> getReadBufferImpl() = 0;
|
2017-02-22 15:29:43 +00:00
|
|
|
|
2017-02-28 14:15:13 +00:00
|
|
|
bool can_reread = true;
|
2017-02-22 15:29:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|