ClickMapBLOB: using DB::IO [#CONV-2807].

This commit is contained in:
Alexey Milovidov 2011-11-28 19:27:51 +00:00
parent 44fdb6c7d1
commit b0cfa59a40

View File

@ -0,0 +1,38 @@
#pragma once
#include <DB/IO/BufferWithOwnMemory.h>
#include <DB/IO/WriteBuffer.h>
namespace DB
{
/** Всё что в него пишут, переводит в HEX (большими буквами) и пишет в другой WriteBuffer.
*/
class HexWriteBuffer : public BufferWithOwnMemory<WriteBuffer>
{
protected:
WriteBuffer & out;
void nextImpl()
{
if (!offset())
return;
for (Position pos = working_buffer.begin(); pos != working_buffer.end(); ++pos)
{
out.write("0123456789ABCDEF"[static_cast<unsigned char>(*pos) >> 4]);
out.write("0123456789ABCDEF"[static_cast<unsigned char>(*pos) & 0xF]);
}
}
public:
HexWriteBuffer(WriteBuffer & out_) : out(out_) {}
virtual ~HexWriteBuffer()
{
nextImpl();
}
};
}