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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2026
//
// 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/telegram/KeyboardButtonStyle.hpp"
#include "td/telegram/ReplyMarkup.h"
#include "td/telegram/RequestedDialogType.hpp"
#include "td/telegram/Version.h"
#include "td/utils/tl_helpers.h"
namespace td {
template <class StorerT>
void store(const KeyboardButton &button, StorerT &storer) {
bool has_url = !button.url.empty();
bool has_requested_dialog_type = button.requested_dialog_type != nullptr;
bool has_style = !button.style.is_default();
BEGIN_STORE_FLAGS();
STORE_FLAG(has_url);
STORE_FLAG(has_requested_dialog_type);
STORE_FLAG(has_style);
END_STORE_FLAGS();
store(button.type, storer);
store(button.text, storer);
if (has_url) {
store(button.url, storer);
}
if (has_requested_dialog_type) {
store(button.requested_dialog_type, storer);
}
if (has_style) {
store(button.style, storer);
}
}
template <class ParserT>
void parse(KeyboardButton &button, ParserT &parser) {
bool has_url;
bool has_requested_dialog_type;
bool has_style;
if (parser.version() >= static_cast<int32>(Version::AddKeyboardButtonFlags)) {
BEGIN_PARSE_FLAGS();
PARSE_FLAG(has_url);
PARSE_FLAG(has_requested_dialog_type);
PARSE_FLAG(has_style);
END_PARSE_FLAGS();
} else {
has_url = false;
has_requested_dialog_type = false;
has_style = false;
}
parse(button.type, parser);
parse(button.text, parser);
if (has_url) {
parse(button.url, parser);
}
if (has_requested_dialog_type) {
parse(button.requested_dialog_type, parser);
}
if (has_style) {
parse(button.style, parser);
}
}
template <class StorerT>
void store(const InlineKeyboardButton &button, StorerT &storer) {
bool has_id = button.id != 0;
bool has_user_id = button.user_id.is_valid();
bool has_forward_text = !button.forward_text.empty();
bool has_data = !button.data.empty();
bool has_style = !button.style.is_default();
BEGIN_STORE_FLAGS();
STORE_FLAG(has_id);
STORE_FLAG(has_user_id);
STORE_FLAG(has_forward_text);
STORE_FLAG(has_data);
STORE_FLAG(has_style);
END_STORE_FLAGS();
store(button.type, storer);
if (has_id) {
store(button.id, storer);
}
if (has_user_id) {
store(button.user_id, storer);
}
store(button.text, storer);
if (has_forward_text) {
store(button.forward_text, storer);
}
if (has_data) {
store(button.data, storer);
}
if (has_style) {
store(button.style, storer);
}
}
template <class ParserT>
void parse(InlineKeyboardButton &button, ParserT &parser) {
if (parser.version() >= static_cast<int32>(Version::AddKeyboardButtonFlags)) {
bool has_id;
bool has_user_id;
bool has_forward_text;
bool has_data;
bool has_style;
BEGIN_PARSE_FLAGS();
PARSE_FLAG(has_id);
PARSE_FLAG(has_user_id);
PARSE_FLAG(has_forward_text);
PARSE_FLAG(has_data);
PARSE_FLAG(has_style);
END_PARSE_FLAGS();
parse(button.type, parser);
if (has_id) {
parse(button.id, parser);
}
if (has_user_id) {
parse(button.user_id, parser);
}
parse(button.text, parser);
if (has_forward_text) {
parse(button.forward_text, parser);
}
if (has_data) {
parse(button.data, parser);
}
if (has_style) {
parse(button.style, parser);
}
} else {
parse(button.type, parser);
if (button.type == InlineKeyboardButton::Type::UrlAuth) {
if (parser.version() >= static_cast<int32>(Version::Support64BitIds)) {
parse(button.id, parser);
} else {
int32 old_id;
parse(old_id, parser);
button.id = old_id;
}
}
parse(button.text, parser);
parse(button.data, parser);
}
}
template <class StorerT>
void store(const ReplyMarkup &reply_markup, StorerT &storer) {
bool has_keyboard = !reply_markup.keyboard.empty();
bool has_inline_keyboard = !reply_markup.inline_keyboard.empty();
bool has_placeholder = !reply_markup.placeholder.empty();
BEGIN_STORE_FLAGS();
STORE_FLAG(reply_markup.is_personal);
STORE_FLAG(reply_markup.need_resize_keyboard);
STORE_FLAG(reply_markup.is_one_time_keyboard);
STORE_FLAG(has_keyboard);
STORE_FLAG(has_inline_keyboard);
STORE_FLAG(has_placeholder);
STORE_FLAG(reply_markup.is_persistent);
END_STORE_FLAGS();
store(reply_markup.type, storer);
if (has_keyboard) {
store(reply_markup.keyboard, storer);
}
if (has_inline_keyboard) {
store(reply_markup.inline_keyboard, storer);
}
if (has_placeholder) {
store(reply_markup.placeholder, storer);
}
}
template <class ParserT>
void parse(ReplyMarkup &reply_markup, ParserT &parser) {
bool has_keyboard;
bool has_inline_keyboard;
bool has_placeholder;
BEGIN_PARSE_FLAGS();
PARSE_FLAG(reply_markup.is_personal);
PARSE_FLAG(reply_markup.need_resize_keyboard);
PARSE_FLAG(reply_markup.is_one_time_keyboard);
PARSE_FLAG(has_keyboard);
PARSE_FLAG(has_inline_keyboard);
PARSE_FLAG(has_placeholder);
PARSE_FLAG(reply_markup.is_persistent);
END_PARSE_FLAGS();
parse(reply_markup.type, parser);
if (has_keyboard) {
parse(reply_markup.keyboard, parser);
}
if (has_inline_keyboard) {
parse(reply_markup.inline_keyboard, parser);
}
if (has_placeholder) {
parse(reply_markup.placeholder, parser);
}
}
} // namespace td
|