| 1 | #pragma once |
|---|---|
| 2 | |
| 3 | #include <IO/ReadBuffer.h> |
| 4 | #include <IO/HashingWriteBuffer.h> |
| 5 | |
| 6 | namespace DB |
| 7 | { |
| 8 | /* |
| 9 | * Calculates the hash from the read data. When reading, the data is read from the nested ReadBuffer. |
| 10 | * Small pieces are copied into its own memory. |
| 11 | */ |
| 12 | class HashingReadBuffer : public IHashingBuffer<ReadBuffer> |
| 13 | { |
| 14 | public: |
| 15 | HashingReadBuffer(ReadBuffer & in_, size_t block_size_ = DBMS_DEFAULT_HASHING_BLOCK_SIZE) : |
| 16 | IHashingBuffer<ReadBuffer>(block_size_), in(in_) |
| 17 | { |
| 18 | working_buffer = in.buffer(); |
| 19 | pos = in.position(); |
| 20 | |
| 21 | /// calculate hash from the data already read |
| 22 | if (working_buffer.size()) |
| 23 | { |
| 24 | calculateHash(pos, working_buffer.end() - pos); |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | private: |
| 29 | bool nextImpl() override |
| 30 | { |
| 31 | in.position() = pos; |
| 32 | bool res = in.next(); |
| 33 | working_buffer = in.buffer(); |
| 34 | pos = in.position(); |
| 35 | |
| 36 | calculateHash(working_buffer.begin(), working_buffer.size()); |
| 37 | |
| 38 | return res; |
| 39 | } |
| 40 | |
| 41 | private: |
| 42 | ReadBuffer & in; |
| 43 | }; |
| 44 | } |
| 45 |