ClickHouse/dbms/src/IO/HashingWriteBuffer.cpp

36 lines
1.0 KiB
C++
Raw Normal View History

#include <DB/IO/HashingWriteBuffer.h>
2014-06-05 16:59:30 +00:00
#include <iomanip>
2014-06-06 09:17:26 +00:00
/// UInt64 это 39 символов в 10 системе счисления
static const size_t UINT64_DECIMAL_SIZE = 39;
std::string uint128ToString(uint128 data)
{
std::stringstream ss;
ss << std::setw(UINT64_DECIMAL_SIZE) << std::setfill('0') << data.first << std::setw(UINT64_DECIMAL_SIZE) << std::setfill('0') << data.second;
return ss.str();
}
std::ostream & operator<<(std::ostream & os, const uint128 & data)
{
2014-06-06 09:17:26 +00:00
os << uint128ToString(data);
return os;
}
std::istream & operator>>(std::istream & is, uint128 & data)
{
2014-06-06 09:17:26 +00:00
std::vector<char> buffer(UINT64_DECIMAL_SIZE);
is.read(buffer.data(), UINT64_DECIMAL_SIZE);
data.first = DB::parse<UInt64>(buffer.data(), UINT64_DECIMAL_SIZE);
if (!is)
throw DB::Exception(std::string("Fail to parse uint128 from ") + buffer.data());
2014-06-06 09:17:26 +00:00
is.read(buffer.data(), UINT64_DECIMAL_SIZE);
data.first = DB::parse<UInt64>(buffer.data(), UINT64_DECIMAL_SIZE);
if (!is)
throw DB::Exception(std::string("Fail to parse uint128 from ") + buffer.data());
return is;
}