2021-01-11 01:50:30 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-10-27 23:10:39 +00:00
|
|
|
#include "config_formats.h"
|
2021-01-11 01:50:30 +00:00
|
|
|
|
|
|
|
#if USE_PROTOBUF
|
|
|
|
# include <Columns/IColumn.h>
|
2021-12-15 11:30:57 +00:00
|
|
|
#include <Core/NamesAndTypes.h>
|
2021-01-11 01:50:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace google::protobuf { class Descriptor; }
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
class ProtobufReader;
|
|
|
|
class ProtobufWriter;
|
|
|
|
class IDataType;
|
|
|
|
using DataTypePtr = std::shared_ptr<const IDataType>;
|
|
|
|
using DataTypes = std::vector<DataTypePtr>;
|
2021-12-01 18:19:47 +00:00
|
|
|
class WriteBuffer;
|
2021-01-11 01:50:30 +00:00
|
|
|
|
|
|
|
/// Utility class, does all the work for serialization in the Protobuf format.
|
|
|
|
class ProtobufSerializer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~ProtobufSerializer() = default;
|
|
|
|
|
|
|
|
virtual void setColumns(const ColumnPtr * columns, size_t num_columns) = 0;
|
|
|
|
virtual void writeRow(size_t row_num) = 0;
|
|
|
|
|
|
|
|
virtual void setColumns(const MutableColumnPtr * columns, size_t num_columns) = 0;
|
|
|
|
virtual void readRow(size_t row_num) = 0;
|
|
|
|
virtual void insertDefaults(size_t row_num) = 0;
|
|
|
|
|
2021-12-01 18:19:47 +00:00
|
|
|
virtual void describeTree(WriteBuffer & out, size_t indent) const = 0;
|
|
|
|
|
2021-01-11 01:50:30 +00:00
|
|
|
static std::unique_ptr<ProtobufSerializer> create(
|
|
|
|
const Strings & column_names,
|
|
|
|
const DataTypes & data_types,
|
|
|
|
std::vector<size_t> & missing_column_indices,
|
|
|
|
const google::protobuf::Descriptor & message_descriptor,
|
|
|
|
bool with_length_delimiter,
|
|
|
|
ProtobufReader & reader);
|
|
|
|
|
|
|
|
static std::unique_ptr<ProtobufSerializer> create(
|
|
|
|
const Strings & column_names,
|
|
|
|
const DataTypes & data_types,
|
|
|
|
const google::protobuf::Descriptor & message_descriptor,
|
|
|
|
bool with_length_delimiter,
|
|
|
|
ProtobufWriter & writer);
|
|
|
|
};
|
|
|
|
|
2021-12-15 11:30:57 +00:00
|
|
|
NamesAndTypesList protobufSchemaToCHSchema(const google::protobuf::Descriptor * message_descriptor);
|
|
|
|
|
2021-01-11 01:50:30 +00:00
|
|
|
}
|
|
|
|
#endif
|