2011-11-28 19:27:51 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <DB/IO/BufferWithOwnMemory.h>
|
|
|
|
|
#include <DB/IO/WriteBuffer.h>
|
|
|
|
|
|
|
|
|
|
|
2011-11-29 18:53:44 +00:00
|
|
|
|
/// Так как HexWriteBuffer часто создаётся во внутреннем цикле, сделаем у него размер буфера маленьким.
|
2011-11-29 17:23:30 +00:00
|
|
|
|
#define DBMS_HEX_WRITE_BUFFER_SIZE 32
|
|
|
|
|
|
|
|
|
|
|
2011-11-28 19:27:51 +00:00
|
|
|
|
namespace DB
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/** Всё что в него пишут, переводит в HEX (большими буквами) и пишет в другой WriteBuffer.
|
|
|
|
|
*/
|
2011-11-29 17:23:30 +00:00
|
|
|
|
class HexWriteBuffer : public WriteBuffer
|
2011-11-28 19:27:51 +00:00
|
|
|
|
{
|
|
|
|
|
protected:
|
2011-11-29 17:23:30 +00:00
|
|
|
|
char buf[DBMS_HEX_WRITE_BUFFER_SIZE];
|
|
|
|
|
|
2011-11-28 19:27:51 +00:00
|
|
|
|
WriteBuffer & out;
|
|
|
|
|
|
|
|
|
|
void nextImpl()
|
|
|
|
|
{
|
|
|
|
|
if (!offset())
|
|
|
|
|
return;
|
|
|
|
|
|
2011-11-29 17:23:30 +00:00
|
|
|
|
for (Position p = working_buffer.begin(); p != pos; ++p)
|
2011-11-28 19:27:51 +00:00
|
|
|
|
{
|
2011-11-29 17:23:30 +00:00
|
|
|
|
out.write("0123456789ABCDEF"[static_cast<unsigned char>(*p) >> 4]);
|
|
|
|
|
out.write("0123456789ABCDEF"[static_cast<unsigned char>(*p) & 0xF]);
|
2011-11-28 19:27:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
2011-11-29 17:23:30 +00:00
|
|
|
|
HexWriteBuffer(WriteBuffer & out_) : WriteBuffer(buf, sizeof(buf)), out(out_) {}
|
2011-11-28 19:27:51 +00:00
|
|
|
|
|
2012-02-02 23:14:08 +00:00
|
|
|
|
~HexWriteBuffer()
|
2011-11-28 19:27:51 +00:00
|
|
|
|
{
|
2013-11-18 17:17:45 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
2012-02-02 23:14:08 +00:00
|
|
|
|
nextImpl();
|
2013-11-18 17:17:45 +00:00
|
|
|
|
}
|
|
|
|
|
catch (...)
|
|
|
|
|
{
|
2013-11-18 19:18:03 +00:00
|
|
|
|
tryLogCurrentException(__PRETTY_FUNCTION__);
|
2013-11-18 17:17:45 +00:00
|
|
|
|
}
|
2011-11-28 19:27:51 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|