forked from mpartel/postgres-protobuf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
descriptor_db.hpp
48 lines (34 loc) · 1.25 KB
/
descriptor_db.hpp
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
#ifndef POSTGRES_PROTOBUF_DESCRIPTOR_DB_HPP_
#define POSTGRES_PROTOBUF_DESCRIPTOR_DB_HPP_
#include <memory>
#include <unordered_map>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor_database.h>
#include <google/protobuf/util/type_resolver.h>
namespace postgres_protobuf {
namespace descriptor_db {
namespace pb = ::google::protobuf;
struct DescDb;
struct DescSet;
// NOTE: This currently lives outside of Postgres's memory management,
// because the protobuf library doesn't support alternative allocators.
struct DescDb {
// TODO: load DescSets lazily
const std::unordered_map<std::string, std::unique_ptr<DescSet>> desc_sets;
static const std::shared_ptr<DescDb>& GetOrCreateCached();
static void ClearCache();
private:
DescDb(std::unordered_map<std::string, std::unique_ptr<DescSet>> desc_sets);
static std::shared_ptr<DescDb> cached_;
static uint64_t GetTableXmin();
static void ClearCacheCallback(void*);
};
struct DescSet {
std::unique_ptr<pb::SimpleDescriptorDatabase> desc_db;
std::unique_ptr<pb::DescriptorPool> pool;
std::unique_ptr<pb::util::TypeResolver> type_resolver;
DescSet();
};
} // namespace descriptor_db
} // namespace postgres_protobuf
#endif // POSTGRES_PROTOBUF_DESCRIPTOR_DB_HPP_