-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtl_object_store.h
86 lines (73 loc) · 1.88 KB
/
tl_object_store.h
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//
// Copyright Aliaksei Levin ([email protected]), Arseny Smirnov ([email protected]) 2014-2023
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#pragma once
#include "td/tl/TlObject.h"
#include "td/utils/misc.h"
#include <cstdint>
#include <string>
#include <vector>
namespace td {
template <class Func, std::int32_t constructor_id>
class TlStoreBoxed {
public:
template <class T, class StorerT>
static void store(const T &x, StorerT &storer) {
storer.store_binary(constructor_id);
Func::store(x, storer);
}
};
template <class Func>
class TlStoreBoxedUnknown {
public:
template <class T, class StorerT>
static void store(const T &x, StorerT &storer) {
storer.store_binary(x->get_id());
Func::store(x, storer);
}
};
class TlStoreBool {
public:
template <class StorerT>
static void store(const bool &x, StorerT &storer) {
constexpr std::int32_t ID_BOOL_FALSE = 0xbc799737;
constexpr std::int32_t ID_BOOL_TRUE = 0x997275b5;
storer.store_binary(x ? ID_BOOL_TRUE : ID_BOOL_FALSE);
}
};
class TlStoreBinary {
public:
template <class T, class StorerT>
static void store(const T &x, StorerT &storer) {
storer.store_binary(x);
}
};
class TlStoreString {
public:
template <class T, class StorerT>
static void store(const T &x, StorerT &storer) {
storer.store_string(x);
}
};
template <class Func>
class TlStoreVector {
public:
template <class T, class StorerT>
static void store(const T &vec, StorerT &storer) {
storer.store_binary(narrow_cast<int32>(vec.size()));
for (auto &val : vec) {
Func::store(val, storer);
}
}
};
class TlStoreObject {
public:
template <class T, class StorerT>
static void store(const tl_object_ptr<T> &obj, StorerT &storer) {
return obj->store(storer);
}
};
} // namespace td