diff --git a/dbms/include/DB/DataTypes/IDataTypeNumberFixed.h b/dbms/include/DB/DataTypes/IDataTypeNumberFixed.h index 6691fbe1adc..c4890c7cf46 100644 --- a/dbms/include/DB/DataTypes/IDataTypeNumberFixed.h +++ b/dbms/include/DB/DataTypes/IDataTypeNumberFixed.h @@ -28,13 +28,13 @@ public: { /// ColumnType::value_type - более узкий тип. Например, UInt8, когда тип Field - UInt64 typename ColumnType::value_type x = boost::get(field); - ostr.write(reinterpret_cast(&x), sizeof(x)); + writeIntBinary(x, ostr); } void deserializeBinary(Field & field, ReadBuffer & istr) const { typename ColumnType::value_type x; - istr.readStrict(reinterpret_cast(&x), sizeof(x)); + readIntBinary(x, istr); field = typename NearestFieldType::Type(x); } diff --git a/dbms/include/DB/IO/ReadHelpers.h b/dbms/include/DB/IO/ReadHelpers.h index 54c697c83a2..4d6e80b8538 100644 --- a/dbms/include/DB/IO/ReadHelpers.h +++ b/dbms/include/DB/IO/ReadHelpers.h @@ -46,6 +46,14 @@ static inline void throwReadAfterEOF() } +/// Чтение числа в native формате +template +inline void readIntBinary(T & x, ReadBuffer & buf) +{ + buf.readStrict(reinterpret_cast(&x), sizeof(x)); +} + + inline void readChar(char & x, ReadBuffer & buf) { if (!buf.eof()) diff --git a/dbms/include/DB/IO/WriteHelpers.h b/dbms/include/DB/IO/WriteHelpers.h index f9064b60bda..6d049b04d66 100644 --- a/dbms/include/DB/IO/WriteHelpers.h +++ b/dbms/include/DB/IO/WriteHelpers.h @@ -32,6 +32,14 @@ inline void writeChar(char x, WriteBuffer & buf) } +/// Запись числа в native формате +template +inline void writeIntBinary(T & x, WriteBuffer & buf) +{ + buf.write(reinterpret_cast(&x), sizeof(x)); +} + + template void writeIntText(T x, WriteBuffer & buf) {