2014-06-06 09:14:51 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <city.h>
|
|
|
|
|
#include <DB/IO/ReadBuffer.h>
|
|
|
|
|
#include <DB/IO/HashingWriteBuffer.h>
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
|
{
|
|
|
|
|
/*
|
2014-07-23 06:55:59 +00:00
|
|
|
|
* Считает хэш от прочитанных данных. При чтении данные читаются из вложенного ReadBuffer.
|
2014-06-06 09:14:51 +00:00
|
|
|
|
* Мелкие кусочки копируются в собственную память.
|
|
|
|
|
*/
|
2014-06-06 14:50:29 +00:00
|
|
|
|
class HashingReadBuffer : public IHashingBuffer<ReadBuffer>
|
2014-06-06 09:14:51 +00:00
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
HashingReadBuffer(ReadBuffer & in_, size_t block_size = DBMS_DEFAULT_HASHING_BLOCK_SIZE) :
|
2014-06-06 14:50:29 +00:00
|
|
|
|
in(in_)
|
2014-06-06 09:14:51 +00:00
|
|
|
|
{
|
|
|
|
|
working_buffer = in.buffer();
|
2014-06-06 13:50:09 +00:00
|
|
|
|
pos = in.position();
|
2014-06-06 09:14:51 +00:00
|
|
|
|
|
2014-06-06 13:50:09 +00:00
|
|
|
|
/// считаем хэш от уже прочитанных данных
|
|
|
|
|
if (working_buffer.size())
|
|
|
|
|
{
|
|
|
|
|
calculateHash(pos, working_buffer.end() - pos);
|
|
|
|
|
}
|
2014-06-06 09:14:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
2014-06-06 13:50:09 +00:00
|
|
|
|
bool nextImpl() override
|
|
|
|
|
{
|
|
|
|
|
in.position() = pos;
|
2014-06-06 09:14:51 +00:00
|
|
|
|
bool res = in.next();
|
|
|
|
|
working_buffer = in.buffer();
|
2014-06-06 13:50:09 +00:00
|
|
|
|
pos = in.position();
|
|
|
|
|
|
|
|
|
|
calculateHash(working_buffer.begin(), working_buffer.size());
|
|
|
|
|
|
2014-06-06 09:14:51 +00:00
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
ReadBuffer & in;
|
|
|
|
|
};
|
|
|
|
|
}
|