#pragma once #include #include #include namespace { template constexpr size_t max_int_width = 20; template <> inline constexpr size_t max_int_width = 3; /// 255 template <> inline constexpr size_t max_int_width = 4; /// -128 template <> inline constexpr size_t max_int_width = 5; /// 65535 template <> inline constexpr size_t max_int_width = 6; /// -32768 template <> inline constexpr size_t max_int_width = 10; /// 4294967295 template <> inline constexpr size_t max_int_width = 11; /// -2147483648 template <> inline constexpr size_t max_int_width = 20; /// 18446744073709551615 template <> inline constexpr size_t max_int_width = 20; /// -9223372036854775808 template <> inline constexpr size_t max_int_width = 39; /// 340282366920938463463374607431768211455 template <> inline constexpr size_t max_int_width = 40; /// -170141183460469231731687303715884105728 template <> inline constexpr size_t max_int_width = 78; /// 115792089237316195423570985008687907853269984665640564039457584007913129639935 template <> inline constexpr size_t max_int_width = 78; /// -57896044618658097711785492504343953926634992332820282019728792003956564819968 } namespace DB { namespace detail { template void NO_INLINE writeUIntTextFallback(T x, WriteBuffer & buf) { char tmp[max_int_width]; int len = itoa(x, tmp) - tmp; buf.write(tmp, len); } } template void writeIntText(T x, WriteBuffer & buf) { if (likely(reinterpret_cast(buf.position()) + max_int_width < reinterpret_cast(buf.buffer().end()))) buf.position() = itoa(x, buf.position()); else detail::writeUIntTextFallback(x, buf); } }