aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Formats/ProtobufSerializer.h
blob: 008e08416d30f08aa12fe95e1330affd0b8ed59c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#pragma once

#include "clickhouse_config.h"

#if USE_PROTOBUF
#   include <Columns/IColumn.h>
#include <Core/NamesAndTypes.h>


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>;
class WriteBuffer;

/// 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 finalizeWrite() {}
    virtual void reset() {}

    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;

    virtual void describeTree(WriteBuffer & out, size_t indent) const = 0;

    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,
        bool with_envelope,
        bool flatten_google_wrappers,
        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,
        bool with_envelope,
        bool defaults_for_nullable_google_wrappers,
        ProtobufWriter & writer);
};

NamesAndTypesList protobufSchemaToCHSchema(const google::protobuf::Descriptor * message_descriptor, bool skip_unsupported_fields);

}
#endif