From 240c0923685bfb83ab8391697f9dcb213ca8404e Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 24 Dec 2019 03:55:36 +0300 Subject: [PATCH] Remove tl_json dependency on td_api. GitOrigin-RevId: 2453a8ac022cf86b799d24045d98e3e69b4a3d9e --- td/generate/tl_json_converter.cpp | 28 +++++++++++++++++++++++++++- td/telegram/cli.cpp | 13 ++++++------- td/tl/tl_json.h | 24 ++---------------------- 3 files changed, 35 insertions(+), 30 deletions(-) diff --git a/td/generate/tl_json_converter.cpp b/td/generate/tl_json_converter.cpp index 9c4d5bc7c..421337e12 100644 --- a/td/generate/tl_json_converter.cpp +++ b/td/generate/tl_json_converter.cpp @@ -218,10 +218,36 @@ void gen_json_converter_file(const tl::simple::Schema &schema, const std::string sb << "#include \"td/utils/common.h\"\n"; sb << "#include \"td/utils/Slice.h\"\n\n"; + sb << "#include \n"; sb << "#include \n\n"; } sb << "namespace td {\n"; - sb << "namespace td_api{\n\n"; + sb << "namespace td_api {\n"; + if (is_header) { + sb << "\nvoid to_json(JsonValueScope &jv, const Object &object);\n"; + sb << "\nvoid to_json(JsonValueScope &jv, const Function &object);\n\n"; + } else { + sb << R"ABCD( +template +auto lazy_to_json(JsonValueScope &jv, const T &t) -> decltype(td_api::to_json(jv, t)) { + return td_api::to_json(jv, t); +} + +template +void lazy_to_json(std::reference_wrapper, const T &t) { + UNREACHABLE(); +} + +void to_json(JsonValueScope &jv, const Object &object) { + downcast_call(const_cast(object), [&jv](const auto &object) { lazy_to_json(jv, object); }); +} + +void to_json(JsonValueScope &jv, const Function &object) { + downcast_call(const_cast(object), [&jv](const auto &object) { lazy_to_json(jv, object); }); +} + +)ABCD"; + } gen_tl_constructor_from_string(sb, schema, is_header, mode); gen_from_json(sb, schema, is_header, mode); gen_to_json(sb, schema, is_header, mode); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 89a8ac70c..6dd0c573b 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -4,20 +4,19 @@ // 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) // -#include "td/telegram/ClientActor.h" -#include "td/telegram/Log.h" - -#include "td/telegram/td_api_json.h" - #include "td/actor/actor.h" -#include "td/tl/tl_json.h" // should be included after td_api_json? - #include "memprof/memprof.h" #include "td/net/HttpQuery.h" #include "td/net/HttpReader.h" +#include "td/tl/tl_json.h" + +#include "td/telegram/ClientActor.h" +#include "td/telegram/Log.h" +#include "td/telegram/td_api_json.h" + #include "td/utils/base64.h" #include "td/utils/buffer.h" #include "td/utils/common.h" diff --git a/td/tl/tl_json.h b/td/tl/tl_json.h index 66d69037d..b5143559a 100644 --- a/td/tl/tl_json.h +++ b/td/tl/tl_json.h @@ -6,6 +6,8 @@ // #pragma once +#include "td/tl/TlObject.h" + #include "td/utils/base64.h" #include "td/utils/common.h" #include "td/utils/format.h" @@ -15,10 +17,6 @@ #include "td/utils/Status.h" #include "td/utils/tl_storers.h" -#include "td/telegram/td_api.h" -#include "td/telegram/td_api.hpp" - -#include #include namespace td { @@ -42,24 +40,6 @@ inline void to_json(JsonValueScope &jv, const JsonVectorInt64 &vec) { } } -template -auto lazy_to_json(JsonValueScope &jv, const T &t) -> decltype(td_api::to_json(jv, t)) { - return td_api::to_json(jv, t); -} - -template -void lazy_to_json(std::reference_wrapper, const T &t) { - UNREACHABLE(); -} - -inline void to_json(JsonValueScope &jv, const td_api::Object &object) { - td_api::downcast_call(const_cast(object), [&jv](const auto &object) { lazy_to_json(jv, object); }); -} -inline void to_json(JsonValueScope &jv, const td_api::Function &object) { - td_api::downcast_call(const_cast(object), - [&jv](const auto &object) { lazy_to_json(jv, object); }); -} - template void to_json(JsonValueScope &jv, const tl_object_ptr &value) { if (value) {