#include #include #if USE_PROTOBUF #include "ProtobufRowOutputStream.h" #include #include #include #include #include namespace DB { ProtobufRowOutputStream::ProtobufRowOutputStream(WriteBuffer & out, const Block & header, const FormatSchemaInfo & info) : data_types(header.getDataTypes()), writer(out, ProtobufSchemas::instance().getMessageTypeForFormatSchema(info), header.getNames()) { } void ProtobufRowOutputStream::write(const Block & block, size_t row_num) { writer.startMessage(); size_t column_index; while (writer.writeField(column_index)) data_types[column_index]->serializeProtobuf(*block.getByPosition(column_index).column, row_num, writer); writer.endMessage(); } void registerOutputFormatProtobuf(FormatFactory & factory) { factory.registerOutputFormat( "Protobuf", [](WriteBuffer & buf, const Block & header, const Context & context, const FormatSettings &) { return std::make_shared( std::make_shared(buf, header, FormatSchemaInfo(context, "proto")), header); }); } } #else namespace DB { class FormatFactory; void registerOutputFormatProtobuf(FormatFactory &) {} } #endif