// // Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019 // // 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/tl/TlObject.h" #include "td/utils/UInt.h" #include #include #include namespace td { template class TlFetchBoxed { public: template static auto parse(ParserT &p) -> decltype(Func::parse(p)) { if (p.fetch_int() != constructor_id) { p.set_error("Wrong constructor found"); return decltype(Func::parse(p))(); } return Func::parse(p); } }; class TlFetchTrue { public: template static bool parse(ParserT &p) { return true; } }; class TlFetchBool { public: template static bool parse(ParserT &p) { constexpr std::int32_t ID_BOOL_FALSE = 0xbc799737; constexpr std::int32_t ID_BOOL_TRUE = 0x997275b5; std::int32_t c = p.fetch_int(); if (c == ID_BOOL_TRUE) { return true; } if (c != ID_BOOL_FALSE) { p.set_error("Bool expected"); } return false; } }; class TlFetchInt { public: template static std::int32_t parse(ParserT &p) { return p.fetch_int(); } }; class TlFetchLong { public: template static std::int64_t parse(ParserT &p) { return p.fetch_long(); } }; class TlFetchDouble { public: template static double parse(ParserT &p) { return p.fetch_double(); } }; class TlFetchInt128 { public: template static UInt128 parse(ParserT &p) { return p.template fetch_binary(); } }; class TlFetchInt256 { public: template static UInt256 parse(ParserT &p) { return p.template fetch_binary(); } }; template class TlFetchString { public: template static T parse(ParserT &p) { return p.template fetch_string(); } }; template class TlFetchBytes { public: template static T parse(ParserT &p) { return p.template fetch_string(); } }; template class TlFetchVector { public: template static auto parse(ParserT &p) -> std::vector { const std::uint32_t multiplicity = p.fetch_int(); std::vector v; if (p.get_left_len() < multiplicity) { p.set_error("Wrong vector length"); } else { v.reserve(multiplicity); for (std::uint32_t i = 0; i < multiplicity; i++) { v.push_back(Func::parse(p)); } } return v; } }; template class TlFetchObject { public: template static tl_object_ptr parse(ParserT &p) { return T::fetch(p); } }; } // namespace td