2017-04-01 09:19:00 +00:00
|
|
|
#include <Core/Types.h>
|
|
|
|
#include <Common/Exception.h>
|
|
|
|
#include <IO/ReadBuffer.h>
|
|
|
|
#include <IO/WriteBuffer.h>
|
|
|
|
#include <IO/VarInt.h>
|
|
|
|
#include <IO/ReadHelpers.h>
|
|
|
|
#include <IO/WriteHelpers.h>
|
|
|
|
#include <Core/BlockInfo.h>
|
2016-06-07 08:23:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
extern const int UNKNOWN_BLOCK_INFO_FIELD;
|
2016-06-07 08:23:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-26 01:20:25 +00:00
|
|
|
/// Write values in binary form. NOTE: You could use protobuf, but it would be overkill for this case.
|
2016-06-07 08:23:15 +00:00
|
|
|
void BlockInfo::write(WriteBuffer & out) const
|
|
|
|
{
|
2017-03-25 20:12:56 +00:00
|
|
|
/// Set of pairs `FIELD_NUM`, value in binary form. Then 0.
|
2016-06-07 08:23:15 +00:00
|
|
|
#define WRITE_FIELD(TYPE, NAME, DEFAULT, FIELD_NUM) \
|
2017-04-01 07:20:54 +00:00
|
|
|
writeVarUInt(FIELD_NUM, out); \
|
|
|
|
writeBinary(NAME, out);
|
2016-06-07 08:23:15 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
APPLY_FOR_BLOCK_INFO_FIELDS(WRITE_FIELD);
|
2016-06-07 08:23:15 +00:00
|
|
|
|
|
|
|
#undef WRITE_FIELD
|
2017-04-01 07:20:54 +00:00
|
|
|
writeVarUInt(0, out);
|
2016-06-07 08:23:15 +00:00
|
|
|
}
|
|
|
|
|
2017-03-26 01:20:25 +00:00
|
|
|
/// Read values in binary form.
|
2016-06-07 08:23:15 +00:00
|
|
|
void BlockInfo::read(ReadBuffer & in)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
UInt64 field_num = 0;
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
readVarUInt(field_num, in);
|
|
|
|
if (field_num == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch (field_num)
|
|
|
|
{
|
|
|
|
#define READ_FIELD(TYPE, NAME, DEFAULT, FIELD_NUM) \
|
|
|
|
case FIELD_NUM: \
|
|
|
|
readBinary(NAME, in); \
|
|
|
|
break;
|
|
|
|
|
|
|
|
APPLY_FOR_BLOCK_INFO_FIELDS(READ_FIELD);
|
|
|
|
|
|
|
|
#undef READ_FIELD
|
|
|
|
default:
|
|
|
|
throw Exception("Unknown BlockInfo field number: " + toString(field_num), ErrorCodes::UNKNOWN_BLOCK_INFO_FIELD);
|
|
|
|
}
|
|
|
|
}
|
2016-06-07 08:23:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|