44
55#include " runtime-light/stdlib/rpc/rpc-tl-error.h"
66
7+ #include < optional>
78#include < tuple>
89
910#include " common/tl/constants/common.h"
@@ -26,11 +27,14 @@ bool fetch_and_skip_n(int32_t n, tl::fetcher& fetcher) noexcept {
2627
2728} // namespace
2829
29- bool TlRpcError::try_fetch () noexcept {
30+ std::optional< bool > TlRpcError::try_fetch () noexcept {
3031 const auto backup_pos{tl_parse_save_pos ()};
3132 auto op{TRY_CALL (decltype (f$fetch_int ()), bool , f$fetch_int ())};
3233 if (op == TL_REQ_RESULT_HEADER) {
33- fetch_and_skip_header ();
34+ if (!fetch_and_skip_header ()) [[unlikely]] {
35+ tl_parse_restore_pos (backup_pos);
36+ return std::nullopt ;
37+ }
3438 op = TRY_CALL (decltype (f$fetch_int ()), bool , f$fetch_int ());
3539 }
3640 if (op != TL_RPC_REQ_ERROR) {
@@ -44,59 +48,6 @@ bool TlRpcError::try_fetch() noexcept {
4448 return true ;
4549}
4650
47- void TlRpcError::fetch_and_skip_header () const noexcept {
48- auto & fetcher{RpcServerInstanceState::get ().tl_fetcher };
49- tl::i32 flags{};
50- if (!flags.fetch (fetcher)) [[unlikely]] {
51- THROW_EXCEPTION (kphp::rpc::exception::not_enough_data_to_fetch::make ());
52- return ;
53- }
54-
55- if (flags.value & vk::tl::common::rpc_req_result_extra_flags::binlog_pos && !tl::i64 {}.fetch (fetcher)) [[unlikely]] {
56- THROW_EXCEPTION (kphp::rpc::exception::not_enough_data_to_fetch::make ());
57- return ;
58- }
59- if (flags.value & vk::tl::common::rpc_req_result_extra_flags::binlog_time && !tl::i64 {}.fetch (fetcher)) [[unlikely]] {
60- THROW_EXCEPTION (kphp::rpc::exception::not_enough_data_to_fetch::make ());
61- return ;
62- }
63- if (flags.value & vk::tl::common::rpc_req_result_extra_flags::engine_pid && !fetch_and_skip_n<tl::i32 >(3 , fetcher)) [[unlikely]] {
64- THROW_EXCEPTION (kphp::rpc::exception::not_enough_data_to_fetch::make ());
65- return ;
66- }
67- if (flags.value & vk::tl::common::rpc_req_result_extra_flags::request_size && !tl::i32 {}.fetch (fetcher)) [[unlikely]] {
68- THROW_EXCEPTION (kphp::rpc::exception::not_enough_data_to_fetch::make ());
69- return ;
70- }
71- if (flags.value & vk::tl::common::rpc_req_result_extra_flags::response_size && !tl::i32 {}.fetch (fetcher)) [[unlikely]] {
72- THROW_EXCEPTION (kphp::rpc::exception::not_enough_data_to_fetch::make ());
73- return ;
74- }
75- if (flags.value & vk::tl::common::rpc_req_result_extra_flags::failed_subqueries && !tl::i32 {}.fetch (fetcher)) [[unlikely]] {
76- THROW_EXCEPTION (kphp::rpc::exception::not_enough_data_to_fetch::make ());
77- return ;
78- }
79- if (flags.value & vk::tl::common::rpc_req_result_extra_flags::compression_version && !tl::i32 {}.fetch (fetcher)) [[unlikely]] {
80- THROW_EXCEPTION (kphp::rpc::exception::not_enough_data_to_fetch::make ());
81- return ;
82- }
83- if (flags.value & vk::tl::common::rpc_req_result_extra_flags::stats) {
84- tl::i32 size{};
85- if (!size.fetch (fetcher)) [[unlikely]] {
86- THROW_EXCEPTION (kphp::rpc::exception::not_enough_data_to_fetch::make ());
87- return ;
88- }
89- if (!fetch_and_skip_n<tl::string>(size.value * 2 , fetcher)) [[unlikely]] {
90- THROW_EXCEPTION (kphp::rpc::exception::cant_fetch_string::make ());
91- return ;
92- }
93- }
94- if (flags.value & vk::tl::common::rpc_req_result_extra_flags::epoch_number && !tl::i64 {}.fetch (fetcher)) [[unlikely]] {
95- THROW_EXCEPTION (kphp::rpc::exception::not_enough_data_to_fetch::make ());
96- return ;
97- }
98- if (flags.value & vk::tl::common::rpc_req_result_extra_flags::view_number && !tl::i64 {}.fetch (fetcher)) [[unlikely]] {
99- THROW_EXCEPTION (kphp::rpc::exception::not_enough_data_to_fetch::make ());
100- return ;
101- }
51+ bool TlRpcError::fetch_and_skip_header () const noexcept {
52+ return tl::rpcReqResultExtra{}.fetch (RpcServerInstanceState::get ().tl_fetcher );
10253}
0 commit comments