aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Formats/CapnProtoSchema.h
blob: b446b12688798fbadce905c3a5e4fbaf66140354 (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
#pragma once

#include "clickhouse_config.h"
#if USE_CAPNP

#include <Formats/FormatSchemaInfo.h>
#include <Formats/FormatSettings.h>
#include <Core/Block.h>
#error #include <capnp/schema-parser.h>
#error #include <capnp/dynamic.h>

namespace DB
{
// Wrapper for classes that could throw in destructor
// https://github.com/capnproto/capnproto/issues/553
template <typename T>
struct DestructorCatcher
{
    T impl;
    template <typename ... Arg>
    explicit DestructorCatcher(Arg && ... args) : impl(kj::fwd<Arg>(args)...) {}
    ~DestructorCatcher() noexcept try { } catch (...) { return; }
};

class CapnProtoSchemaParser : public DestructorCatcher<capnp::SchemaParser>
{
public:
    CapnProtoSchemaParser() = default;

    capnp::StructSchema getMessageSchema(const FormatSchemaInfo & schema_info);
};

bool checkIfStructContainsUnnamedUnion(const capnp::StructSchema & struct_schema);
bool checkIfStructIsNamedUnion(const capnp::StructSchema & struct_schema);

/// Get full name of type for better exception messages.
String getCapnProtoFullTypeName(const capnp::Type & type);

NamesAndTypesList capnProtoSchemaToCHSchema(const capnp::StructSchema & schema, bool skip_unsupported_fields);

}

#endif