提交 f0b4fcee 编写于 作者: A Alexey Milovidov

Minor modifications

上级 85f2e86e
#pragma once
#include <byteswap.h>
#include <cmath>
#include <cstring>
#include <limits>
......@@ -746,6 +747,23 @@ inline void readBinary(Decimal128 & x, ReadBuffer & buf) { readPODBinary(x, buf)
inline void readBinary(LocalDate & x, ReadBuffer & buf) { readPODBinary(x, buf); }
template <typename T>
inline std::enable_if_t<is_arithmetic_v<T> && (sizeof(T) <= 8), void>
readBinaryBigEndian(T & x, ReadBuffer & buf) /// Assuming little endian architecture.
{
readPODBinary(x, buf);
if constexpr (sizeof(x) == 1)
return;
else if constexpr (sizeof(x) == 2)
x = bswap_16(x);
else if constexpr (sizeof(x) == 4)
x = bswap_32(x);
else if constexpr (sizeof(x) == 8)
x = bswap_64(x);
}
/// Generic methods to read value in text tab-separated format.
template <typename T>
inline std::enable_if_t<is_integral_v<T>, void>
......
......@@ -553,16 +553,16 @@ private:
static uint32_t readConfluentSchemaId(ReadBuffer & in)
{
Poco::Buffer<char> buf(5);
in.readStrict(buf.begin(), buf.capacity());
Poco::MemoryBinaryReader binary_reader(buf, Poco::BinaryReader::BIG_ENDIAN_BYTE_ORDER);
uint8_t magic;
uint32_t schema_id;
binary_reader >> magic >> schema_id;
readBinaryBigEndian(magic, in);
readBinaryBigEndian(schema_id, in);
if (magic != 0x00)
{
throw Exception("Invalid magic byte", ErrorCodes::INCORRECT_DATA);
throw Exception("Invalid magic byte before AvroConfluent schema identifier."
" Must be zero byte, found " + std::to_string(int(magic)) + " instead", ErrorCodes::INCORRECT_DATA);
}
return schema_id;
......@@ -577,7 +577,6 @@ AvroConfluentRowInputFormat::AvroConfluentRowInputFormat(
, decoder(avro::binaryDecoder())
{
(void)format_settings_;
decoder->init(*input_stream);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册