1 | #pragma once |
2 | #include <memory> |
3 | #include <IO/ReadBuffer.h> |
4 | |
5 | namespace DB |
6 | { |
7 | |
8 | struct IReadableWriteBuffer |
9 | { |
10 | /// At the first time returns getReadBufferImpl(). Next calls return nullptr. |
11 | inline std::shared_ptr<ReadBuffer> tryGetReadBuffer() |
12 | { |
13 | if (!can_reread) |
14 | return nullptr; |
15 | |
16 | can_reread = false; |
17 | return getReadBufferImpl(); |
18 | } |
19 | |
20 | virtual ~IReadableWriteBuffer() {} |
21 | |
22 | protected: |
23 | |
24 | /// Creates read buffer from current write buffer. |
25 | /// Returned buffer points to the first byte of original buffer. |
26 | /// Original stream becomes invalid. |
27 | virtual std::shared_ptr<ReadBuffer> getReadBufferImpl() = 0; |
28 | |
29 | bool can_reread = true; |
30 | }; |
31 | |
32 | } |
33 | |