Add TlStorerTotString.store_vector_begin.

This commit is contained in:
levlam 2021-11-01 19:45:55 +03:00
parent f743c782bf
commit 6e8a88be35
2 changed files with 13 additions and 11 deletions

View File

@ -284,7 +284,7 @@ std::string TD_TL_writer_cpp::gen_var_type_fetch(const tl::arg &a) const {
}
std::string TD_TL_writer_cpp::get_pretty_field_name(std::string field_name) const {
if (!field_name.empty() && field_name.back() == ']') {
if (!field_name.empty() && field_name[0] == '_') {
return "";
}
auto equals_pos = field_name.find('=');
@ -306,16 +306,10 @@ std::string TD_TL_writer_cpp::get_pretty_class_name(std::string class_name) cons
std::string TD_TL_writer_cpp::gen_vector_store(const std::string &field_name, const tl::tl_tree_type *t,
const std::vector<tl::var_description> &vars, int storer_type) const {
std::string num = field_name.back() == ']' ? "2" : "";
return "{ const array<" + gen_type_name(t) + "> &v" + num + " = " + field_name +
"; const std::uint32_t multiplicity" + num + " = static_cast<std::uint32_t>(v" + num +
".size()); const auto vector_name" + num + " = \"" + get_pretty_class_name("vector") +
"[\" + td::to_string(multiplicity" + num + ")+ \"]\"; s.store_class_begin(\"" +
get_pretty_field_name(field_name) + "\", vector_name" + num +
".c_str()); "
"for (std::uint32_t i" +
num + " = 0; i" + num + " < multiplicity" + num + "; i" + num + "++) { " +
gen_type_store("v" + num + "[i" + num + "]", t, vars, storer_type) + " } s.store_class_end(); }";
std::string num = !field_name.empty() && field_name[0] == '_' ? "2" : "";
return "{ s.store_vector_begin(\"" + get_pretty_field_name(field_name) + "\", " + field_name +
".size()); for (const auto &_value" + num + " : " + field_name + ") { " +
gen_type_store("_value" + num, t, vars, storer_type) + " } s.store_class_end(); }";
}
std::string TD_TL_writer_cpp::gen_store_class_name(const tl::tl_tree_type *tree_type) const {

View File

@ -149,6 +149,14 @@ class TlStorerToString {
store_field_end();
}
void store_vector_begin(const char *field_name, size_t vector_size) {
store_field_begin(field_name);
result += "vector[";
result += (PSLICE() << vector_size).c_str();
result += "] {\n";
shift += 2;
}
void store_class_begin(const char *field_name, const char *class_name) {
store_field_begin(field_name);
result += class_name;