Avoid double null check for stored to JSON objects.
GitOrigin-RevId: 73fe0eab42d933491a39a83e6bc4fa93dabadc39
This commit is contained in:
parent
b1314b38be
commit
70926d1882
@ -33,14 +33,13 @@ void gen_to_json_constructor(StringBuilder &sb, const T *constructor, bool is_he
|
|||||||
sb << " auto jo = jv.enter_object();\n";
|
sb << " auto jo = jv.enter_object();\n";
|
||||||
sb << " jo(\"@type\", \"" << tl::simple::gen_cpp_name(constructor->name) << "\");\n";
|
sb << " jo(\"@type\", \"" << tl::simple::gen_cpp_name(constructor->name) << "\");\n";
|
||||||
for (auto &arg : constructor->args) {
|
for (auto &arg : constructor->args) {
|
||||||
auto field = tl::simple::gen_cpp_field_name(arg.name);
|
auto field_name = tl::simple::gen_cpp_field_name(arg.name);
|
||||||
// TODO: or as null
|
|
||||||
bool is_custom = arg.type->type == tl::simple::Type::Custom;
|
bool is_custom = arg.type->type == tl::simple::Type::Custom;
|
||||||
|
|
||||||
|
auto object = PSTRING() << "object." << field_name;
|
||||||
if (is_custom) {
|
if (is_custom) {
|
||||||
sb << " if (object." << field << ") {\n ";
|
sb << " if (" << object << ") {\n ";
|
||||||
}
|
}
|
||||||
auto object = PSTRING() << "object." << tl::simple::gen_cpp_field_name(arg.name);
|
|
||||||
if (arg.type->type == tl::simple::Type::Bytes) {
|
if (arg.type->type == tl::simple::Type::Bytes) {
|
||||||
object = PSTRING() << "base64_encode(" << object << ")";
|
object = PSTRING() << "base64_encode(" << object << ")";
|
||||||
} else if (arg.type->type == tl::simple::Type::Bool) {
|
} else if (arg.type->type == tl::simple::Type::Bool) {
|
||||||
@ -51,8 +50,9 @@ void gen_to_json_constructor(StringBuilder &sb, const T *constructor, bool is_he
|
|||||||
arg.type->vector_value_type->type == tl::simple::Type::Int64) {
|
arg.type->vector_value_type->type == tl::simple::Type::Int64) {
|
||||||
object = PSTRING() << "JsonVectorInt64{" << object << "}";
|
object = PSTRING() << "JsonVectorInt64{" << object << "}";
|
||||||
}
|
}
|
||||||
if (arg.type->type == tl::simple::Type::Int64 || arg.type->type == tl::simple::Type::Vector ||
|
if (is_custom) {
|
||||||
arg.type->type == tl::simple::Type::Custom) {
|
sb << " jo(\"" << arg.name << "\", ToJson(*" << object << "));\n";
|
||||||
|
} else if (arg.type->type == tl::simple::Type::Int64 || arg.type->type == tl::simple::Type::Vector) {
|
||||||
sb << " jo(\"" << arg.name << "\", ToJson(" << object << "));\n";
|
sb << " jo(\"" << arg.name << "\", ToJson(" << object << "));\n";
|
||||||
} else {
|
} else {
|
||||||
sb << " jo(\"" << arg.name << "\", " << object << ");\n";
|
sb << " jo(\"" << arg.name << "\", " << object << ");\n";
|
||||||
|
Loading…
Reference in New Issue
Block a user