Skip to content

Commit d052137

Browse files
committed
Always split td_api_json.
1 parent ec94a24 commit d052137

File tree

5 files changed

+63
-21
lines changed

5 files changed

+63
-21
lines changed

SplitSource.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,7 @@ function ($matches) use ($needed_std_headers) {
512512
'td/telegram/StickersManager' => 10,
513513
'td/telegram/StoryManager' => 10,
514514
'td/telegram/UpdatesManager' => 10,
515-
'td/telegram/UserManager' => 10,
516-
'td/generate/auto/td/telegram/td_api_json' => 10);
515+
'td/telegram/UserManager' => 10);
517516

518517
foreach ($files as $file => $chunks) {
519518
split_file($file, $chunks, $undo);

td/generate/CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,16 @@ set(TL_TD_API_AUTO_SOURCE
6464
)
6565

6666
set(TL_TD_JSON_AUTO_SOURCE
67-
${TD_AUTO_INCLUDE_DIR}/telegram/td_api_json.cpp
67+
${TD_AUTO_INCLUDE_DIR}/telegram/td_api_json_0.cpp
68+
${TD_AUTO_INCLUDE_DIR}/telegram/td_api_json_1.cpp
69+
${TD_AUTO_INCLUDE_DIR}/telegram/td_api_json_2.cpp
70+
${TD_AUTO_INCLUDE_DIR}/telegram/td_api_json_3.cpp
71+
${TD_AUTO_INCLUDE_DIR}/telegram/td_api_json_4.cpp
72+
${TD_AUTO_INCLUDE_DIR}/telegram/td_api_json_5.cpp
73+
${TD_AUTO_INCLUDE_DIR}/telegram/td_api_json_6.cpp
74+
${TD_AUTO_INCLUDE_DIR}/telegram/td_api_json_7.cpp
75+
${TD_AUTO_INCLUDE_DIR}/telegram/td_api_json_8.cpp
76+
${TD_AUTO_INCLUDE_DIR}/telegram/td_api_json_9.cpp
6877
${TD_AUTO_INCLUDE_DIR}/telegram/td_api_json.h
6978
PARENT_SCOPE
7079
)

td/generate/generate_json.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111

1212
int main() {
1313
td::gen_json_converter(td::tl::read_tl_config_from_file("tlo/td_api.tlo"), "td/telegram/td_api_json",
14-
td::tl::TL_writer::Server);
14+
td::tl::TL_writer::Server, 10);
1515
}

td/generate/tl_json_converter.cpp

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "td/utils/buffer.h"
1212
#include "td/utils/common.h"
1313
#include "td/utils/filesystem.h"
14+
#include "td/utils/misc.h"
1415
#include "td/utils/Slice.h"
1516
#include "td/utils/SliceBuilder.h"
1617
#include "td/utils/StringBuilder.h"
@@ -26,6 +27,14 @@ static bool need_bytes(const tl::simple::Type *type) {
2627
(type->type == tl::simple::Type::Vector && need_bytes(type->vector_value_type));
2728
}
2829

30+
static bool is_suitable(int file_number, int file_count, int &counter) {
31+
if (file_count <= 1) {
32+
return true;
33+
}
34+
counter++;
35+
return counter % (file_count - 1) == file_number - 1;
36+
}
37+
2938
template <class T>
3039
void gen_to_json_constructor(StringBuilder &sb, const T *constructor, bool is_header) {
3140
sb << "void to_json(JsonValueScope &jv, "
@@ -71,11 +80,15 @@ void gen_to_json_constructor(StringBuilder &sb, const T *constructor, bool is_he
7180
sb << "}\n\n";
7281
}
7382

74-
void gen_to_json(StringBuilder &sb, const tl::simple::Schema &schema, bool is_header, Mode mode) {
83+
void gen_to_json(StringBuilder &sb, const tl::simple::Schema &schema, bool is_header, Mode mode, int file_number,
84+
int file_count, int &counter) {
7585
for (auto *custom_type : schema.custom_types) {
7686
if (!((custom_type->is_query_ && mode != Mode::Server) || (custom_type->is_result_ && mode != Mode::Client))) {
7787
continue;
7888
}
89+
if (!is_suitable(file_number, file_count, counter)) {
90+
continue;
91+
}
7992
if (custom_type->constructors.size() > 1) {
8093
auto type_name = tl::simple::gen_cpp_name(custom_type->name);
8194
sb << "void to_json(JsonValueScope &jv, const td_api::" << type_name << " &object)";
@@ -97,7 +110,9 @@ void gen_to_json(StringBuilder &sb, const tl::simple::Schema &schema, bool is_he
97110
return;
98111
}
99112
for (auto *function : schema.functions) {
100-
gen_to_json_constructor(sb, function, is_header);
113+
if (is_suitable(file_number, file_count, counter)) {
114+
gen_to_json_constructor(sb, function, is_header);
115+
}
101116
}
102117
}
103118

@@ -118,20 +133,25 @@ void gen_from_json_constructor(StringBuilder &sb, const T *constructor, bool is_
118133
}
119134
}
120135

121-
void gen_from_json(StringBuilder &sb, const tl::simple::Schema &schema, bool is_header, Mode mode) {
136+
void gen_from_json(StringBuilder &sb, const tl::simple::Schema &schema, bool is_header, Mode mode, int file_number,
137+
int file_count, int &counter) {
122138
for (auto *custom_type : schema.custom_types) {
123139
if (!((custom_type->is_query_ && mode != Mode::Client) || (custom_type->is_result_ && mode != Mode::Server))) {
124140
continue;
125141
}
126142
for (auto *constructor : custom_type->constructors) {
127-
gen_from_json_constructor(sb, constructor, is_header);
143+
if (is_suitable(file_number, file_count, counter)) {
144+
gen_from_json_constructor(sb, constructor, is_header);
145+
}
128146
}
129147
}
130148
if (mode == Mode::Client) {
131149
return;
132150
}
133151
for (auto *function : schema.functions) {
134-
gen_from_json_constructor(sb, function, is_header);
152+
if (is_suitable(file_number, file_count, counter)) {
153+
gen_from_json_constructor(sb, function, is_header);
154+
}
135155
}
136156
}
137157

@@ -163,7 +183,8 @@ void gen_tl_constructor_from_string(StringBuilder &sb, Slice name, const Vec &ve
163183
sb << "}\n\n";
164184
}
165185

166-
void gen_tl_constructor_from_string(StringBuilder &sb, const tl::simple::Schema &schema, bool is_header, Mode mode) {
186+
void gen_tl_constructor_from_string(StringBuilder &sb, const tl::simple::Schema &schema, bool is_header, Mode mode,
187+
int file_number, int file_count, int &counter) {
167188
Vec vec_for_nullary;
168189
for (auto *custom_type : schema.custom_types) {
169190
if (!((custom_type->is_query_ && mode != Mode::Client) || (custom_type->is_result_ && mode != Mode::Server))) {
@@ -176,9 +197,14 @@ void gen_tl_constructor_from_string(StringBuilder &sb, const tl::simple::Schema
176197
}
177198

178199
if (vec.size() > 1) {
179-
gen_tl_constructor_from_string(sb, tl::simple::gen_cpp_name(custom_type->name), vec, is_header);
200+
if (is_suitable(file_number, file_count, counter)) {
201+
gen_tl_constructor_from_string(sb, tl::simple::gen_cpp_name(custom_type->name), vec, is_header);
202+
}
180203
}
181204
}
205+
if (file_number != 1 % file_count) {
206+
return;
207+
}
182208
gen_tl_constructor_from_string(sb, "Object", vec_for_nullary, is_header);
183209

184210
if (mode == Mode::Client) {
@@ -192,8 +218,12 @@ void gen_tl_constructor_from_string(StringBuilder &sb, const tl::simple::Schema
192218
}
193219

194220
void gen_json_converter_file(const tl::simple::Schema &schema, const std::string &file_name_base, bool is_header,
195-
Mode mode) {
196-
auto file_name = is_header ? file_name_base + ".h" : file_name_base + ".cpp";
221+
Mode mode, int file_number, int file_count) {
222+
string file_name_suffix;
223+
if (file_count > 1) {
224+
file_name_suffix = "_" + td::to_string(file_number);
225+
}
226+
auto file_name = is_header ? file_name_base + file_name_suffix + ".h" : file_name_base + file_name_suffix + ".cpp";
197227
auto old_file_content = [&] {
198228
auto r_content = read_file(file_name);
199229
if (r_content.is_error()) {
@@ -234,7 +264,7 @@ void gen_json_converter_file(const tl::simple::Schema &schema, const std::string
234264
sb << "\nStatus from_json(td_api::object_ptr<Function> &to, td::JsonValue from);\n";
235265
sb << "\nvoid to_json(JsonValueScope &jv, const Object &object);\n";
236266
sb << "\nvoid to_json(JsonValueScope &jv, const Function &object);\n\n";
237-
} else {
267+
} else if (file_number == 0) {
238268
sb << R"ABCD(
239269
void to_json(JsonValueScope &jv, const td_api::object_ptr<Object> &value) {
240270
td::to_json(jv, value);
@@ -264,9 +294,10 @@ void to_json(JsonValueScope &jv, const Function &object) {
264294
265295
)ABCD";
266296
}
267-
gen_tl_constructor_from_string(sb, schema, is_header, mode);
268-
gen_from_json(sb, schema, is_header, mode);
269-
gen_to_json(sb, schema, is_header, mode);
297+
int counter = 0;
298+
gen_tl_constructor_from_string(sb, schema, is_header, mode, file_number, file_count, counter);
299+
gen_from_json(sb, schema, is_header, mode, file_number, file_count, counter);
300+
gen_to_json(sb, schema, is_header, mode, file_number, file_count, counter);
270301
sb << "} // namespace td_api\n";
271302
sb << "} // namespace td\n";
272303

@@ -288,10 +319,12 @@ void to_json(JsonValueScope &jv, const Function &object) {
288319
}
289320
}
290321

291-
void gen_json_converter(const tl::tl_config &config, const std::string &file_name, Mode mode) {
322+
void gen_json_converter(const tl::tl_config &config, const std::string &file_name, Mode mode, int source_file_count) {
292323
tl::simple::Schema schema(config);
293-
gen_json_converter_file(schema, file_name, true, mode);
294-
gen_json_converter_file(schema, file_name, false, mode);
324+
gen_json_converter_file(schema, file_name, true, mode, 0, 1);
325+
for (int i = 0; i < source_file_count; i++) {
326+
gen_json_converter_file(schema, file_name, false, mode, i, source_file_count);
327+
}
295328
}
296329

297330
} // namespace td

td/generate/tl_json_converter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace td {
1515

16-
void gen_json_converter(const tl::tl_config &config, const std::string &file_name, tl::TL_writer::Mode mode);
16+
void gen_json_converter(const tl::tl_config &config, const std::string &file_name, tl::TL_writer::Mode mode,
17+
int source_file_count);
1718

1819
} // namespace td

0 commit comments

Comments
 (0)