mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-19 06:01:57 +00:00
67 lines
1.6 KiB
C++
67 lines
1.6 KiB
C++
#include <IO/WriteHelpers.h>
|
|
#include <inttypes.h>
|
|
#include <Common/hex.h>
|
|
|
|
|
|
namespace DB
|
|
{
|
|
|
|
template <typename IteratorSrc, typename IteratorDst>
|
|
void formatHex(IteratorSrc src, IteratorDst dst, const size_t num_bytes)
|
|
{
|
|
size_t src_pos = 0;
|
|
size_t dst_pos = 0;
|
|
for (; src_pos < num_bytes; ++src_pos)
|
|
{
|
|
writeHexByteLowercase(src[src_pos], &dst[dst_pos]);
|
|
dst_pos += 2;
|
|
}
|
|
}
|
|
|
|
void formatUUID(const UInt8 * src16, UInt8 * dst36)
|
|
{
|
|
formatHex(&src16[0], &dst36[0], 4);
|
|
dst36[8] = '-';
|
|
formatHex(&src16[4], &dst36[9], 2);
|
|
dst36[13] = '-';
|
|
formatHex(&src16[6], &dst36[14], 2);
|
|
dst36[18] = '-';
|
|
formatHex(&src16[8], &dst36[19], 2);
|
|
dst36[23] = '-';
|
|
formatHex(&src16[10], &dst36[24], 6);
|
|
}
|
|
|
|
/** Function used when byte ordering is important when parsing uuid
|
|
* ex: When we create an UUID type
|
|
*/
|
|
void formatUUID(std::reverse_iterator<const UInt8 *> src16, UInt8 * dst36)
|
|
{
|
|
formatHex(src16 + 8, &dst36[0], 4);
|
|
dst36[8] = '-';
|
|
formatHex(src16 + 12, &dst36[9], 2);
|
|
dst36[13] = '-';
|
|
formatHex(src16 + 14, &dst36[14], 2);
|
|
dst36[18] = '-';
|
|
formatHex(src16, &dst36[19], 2);
|
|
dst36[23] = '-';
|
|
formatHex(src16 + 2, &dst36[24], 6);
|
|
}
|
|
|
|
|
|
|
|
void writeException(const Exception & e, WriteBuffer & buf)
|
|
{
|
|
writeBinary(e.code(), buf);
|
|
writeBinary(String(e.name()), buf);
|
|
writeBinary(e.displayText(), buf);
|
|
writeBinary(e.getStackTrace().toString(), buf);
|
|
|
|
bool has_nested = e.nested() != nullptr;
|
|
writeBinary(has_nested, buf);
|
|
|
|
if (has_nested)
|
|
writeException(Exception(*e.nested()), buf);
|
|
}
|
|
|
|
}
|