MTProtoScheme.cpp 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178
  1. /*
  2. * This is the source code of tgnet library v. 1.1
  3. * It is licensed under GNU GPL v. 2 or later.
  4. * You should have received a copy of the license in this archive (see LICENSE).
  5. *
  6. * Copyright Nikolai Kudashov, 2015-2018.
  7. */
  8. #include <memory.h>
  9. #include <arpa/inet.h>
  10. #include "MTProtoScheme.h"
  11. #include "ApiScheme.h"
  12. #include "FileLog.h"
  13. #include "ByteArray.h"
  14. #include "NativeByteBuffer.h"
  15. #include "BuffersStorage.h"
  16. #include "ConnectionsManager.h"
  17. TLObject *TLClassStore::TLdeserialize(NativeByteBuffer *stream, uint32_t bytes, uint32_t constructor, int32_t instanceNum, bool &error) {
  18. TLObject *object = nullptr;
  19. switch (constructor) {
  20. case TL_msgs_ack::constructor:
  21. object = new TL_msgs_ack();
  22. break;
  23. case TL_msg_container::constructor:
  24. object = new TL_msg_container();
  25. break;
  26. case TL_pong::constructor:
  27. object = new TL_pong();
  28. break;
  29. case TL_new_session_created::constructor:
  30. object = new TL_new_session_created();
  31. break;
  32. case MsgsStateInfo::constructor:
  33. object = new MsgsStateInfo();
  34. break;
  35. case TL_rpc_result::constructor:
  36. object = new TL_rpc_result();
  37. ((TL_rpc_result *) object)->readParamsEx(stream, bytes, instanceNum, error);
  38. return object;
  39. case TL_bad_msg_notification::constructor:
  40. object = new TL_bad_msg_notification();
  41. break;
  42. case TL_bad_server_salt::constructor:
  43. object = new TL_bad_server_salt();
  44. break;
  45. case TL_msg_detailed_info::constructor:
  46. object = new TL_msg_detailed_info();
  47. break;
  48. case TL_msg_new_detailed_info::constructor:
  49. object = new TL_msg_new_detailed_info();
  50. break;
  51. case TL_gzip_packed::constructor:
  52. object = new TL_gzip_packed();
  53. break;
  54. case TL_error::constructor:
  55. object = new TL_error();
  56. break;
  57. case TL_rpc_error::constructor:
  58. object = new TL_rpc_error();
  59. break;
  60. case TL_rpc_req_error::constructor:
  61. object = new TL_rpc_req_error();
  62. break;
  63. case TL_future_salts::constructor:
  64. object = new TL_future_salts();
  65. break;
  66. case TL_destroy_session_ok::constructor:
  67. object = new TL_destroy_session_ok();
  68. break;
  69. case TL_destroy_session_none::constructor:
  70. object = new TL_destroy_session_none();
  71. break;
  72. case TL_updatesTooLong::constructor:
  73. object = new TL_updatesTooLong();
  74. break;
  75. default:
  76. return nullptr;
  77. }
  78. object->readParams(stream, instanceNum, error);
  79. return object;
  80. }
  81. TL_api_request::~TL_api_request() {
  82. if (request != nullptr) {
  83. request->reuse();
  84. request = nullptr;
  85. }
  86. }
  87. bool TL_api_request::isNeedLayer() {
  88. return true;
  89. }
  90. TLObject *TL_api_request::deserializeResponse(NativeByteBuffer *stream, uint32_t bytes, int32_t instanceNum, bool &error) {
  91. TL_api_response *result = new TL_api_response();
  92. result->readParamsEx(stream, bytes, error);
  93. return result;
  94. }
  95. void TL_api_request::serializeToStream(NativeByteBuffer *stream) {
  96. request->rewind();
  97. stream->writeBytes(request);
  98. }
  99. void TL_api_response::readParamsEx(NativeByteBuffer *stream, uint32_t bytes, bool &error) {
  100. response = std::unique_ptr<NativeByteBuffer>(new NativeByteBuffer(stream->bytes() + stream->position() - 4, bytes));
  101. stream->skip((uint32_t) (bytes - 4));
  102. }
  103. TL_future_salt *TL_future_salt::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
  104. if (TL_future_salt::constructor != constructor) {
  105. error = true;
  106. if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in TL_future_salt", constructor);
  107. return nullptr;
  108. }
  109. TL_future_salt *result = new TL_future_salt();
  110. result->readParams(stream, instanceNum, error);
  111. return result;
  112. }
  113. void TL_future_salt::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  114. valid_since = stream->readInt32(&error);
  115. valid_until = stream->readInt32(&error);
  116. salt = stream->readInt64(&error);
  117. }
  118. TL_msgs_state_info *TL_msgs_state_info::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
  119. if (TL_msgs_state_info::constructor != constructor) {
  120. error = true;
  121. if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in TL_msgs_state_info", constructor);
  122. return nullptr;
  123. }
  124. TL_msgs_state_info *result = new TL_msgs_state_info();
  125. result->readParams(stream, instanceNum, error);
  126. return result;
  127. }
  128. void TL_msgs_state_info::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  129. req_msg_id = stream->readInt64(&error);
  130. info = std::unique_ptr<ByteArray>(stream->readByteArray(&error));
  131. }
  132. void TL_msgs_state_info::serializeToStream(NativeByteBuffer *stream) {
  133. stream->writeInt32(constructor);
  134. stream->writeInt64(req_msg_id);
  135. stream->writeByteArray(info.get());
  136. }
  137. Server_DH_Params *Server_DH_Params::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
  138. Server_DH_Params *result = nullptr;
  139. switch (constructor) {
  140. case 0x79cb045d:
  141. result = new TL_server_DH_params_fail();
  142. break;
  143. case 0xd0e8075c:
  144. result = new TL_server_DH_params_ok();
  145. break;
  146. default:
  147. error = true;
  148. if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in Server_DH_Params", constructor);
  149. return nullptr;
  150. }
  151. result->readParams(stream, instanceNum, error);
  152. return result;
  153. }
  154. void TL_server_DH_params_fail::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  155. nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error));
  156. server_nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error));
  157. new_nonce_hash = std::unique_ptr<ByteArray>(stream->readBytes(16, &error));
  158. }
  159. void TL_server_DH_params_ok::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  160. nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error));
  161. server_nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error));
  162. encrypted_answer = std::unique_ptr<ByteArray>(stream->readByteArray(&error));
  163. }
  164. TL_resPQ *TL_resPQ::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
  165. if (TL_resPQ::constructor != constructor) {
  166. error = true;
  167. if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in TL_resPQ", constructor);
  168. return nullptr;
  169. }
  170. TL_resPQ *result = new TL_resPQ();
  171. result->readParams(stream, instanceNum, error);
  172. return result;
  173. }
  174. void TL_resPQ::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  175. nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error));
  176. server_nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error));
  177. pq = std::unique_ptr<ByteArray>(stream->readByteArray(&error));
  178. uint32_t magic = stream->readUint32(&error);
  179. if (magic != 0x1cb5c415) {
  180. error = true;
  181. if (LOGS_ENABLED) DEBUG_FATAL("wrong Vector magic, got %x", magic);
  182. return;
  183. }
  184. uint32_t count = stream->readUint32(&error);
  185. if (count * sizeof(int64_t) + stream->position() > stream->limit()) {
  186. error = true;
  187. return;
  188. }
  189. for (uint32_t a = 0; a < count; a++) {
  190. server_public_key_fingerprints.push_back(stream->readInt64(&error));
  191. }
  192. }
  193. void TL_p_q_inner_data::serializeToStream(NativeByteBuffer *stream) {
  194. stream->writeInt32(constructor);
  195. stream->writeByteArray(pq.get());
  196. stream->writeByteArray(p.get());
  197. stream->writeByteArray(q.get());
  198. stream->writeBytes(nonce.get());
  199. stream->writeBytes(server_nonce.get());
  200. stream->writeBytes(new_nonce.get());
  201. }
  202. void TL_p_q_inner_data_dc::serializeToStream(NativeByteBuffer *stream) {
  203. stream->writeInt32(constructor);
  204. stream->writeByteArray(pq.get());
  205. stream->writeByteArray(p.get());
  206. stream->writeByteArray(q.get());
  207. stream->writeBytes(nonce.get());
  208. stream->writeBytes(server_nonce.get());
  209. stream->writeBytes(new_nonce.get());
  210. stream->writeInt32(dc);
  211. }
  212. void TL_p_q_inner_data_temp::serializeToStream(NativeByteBuffer *stream) {
  213. stream->writeInt32(constructor);
  214. stream->writeByteArray(pq.get());
  215. stream->writeByteArray(p.get());
  216. stream->writeByteArray(q.get());
  217. stream->writeBytes(nonce.get());
  218. stream->writeBytes(server_nonce.get());
  219. stream->writeBytes(new_nonce.get());
  220. stream->writeInt32(expires_in);
  221. }
  222. void TL_p_q_inner_data_temp_dc::serializeToStream(NativeByteBuffer *stream) {
  223. stream->writeInt32(constructor);
  224. stream->writeByteArray(pq.get());
  225. stream->writeByteArray(p.get());
  226. stream->writeByteArray(q.get());
  227. stream->writeBytes(nonce.get());
  228. stream->writeBytes(server_nonce.get());
  229. stream->writeBytes(new_nonce.get());
  230. stream->writeInt32(dc);
  231. stream->writeInt32(expires_in);
  232. }
  233. void TL_bind_auth_key_inner::serializeToStream(NativeByteBuffer *stream) {
  234. stream->writeInt32(constructor);
  235. stream->writeInt64(nonce);
  236. stream->writeInt64(temp_auth_key_id);
  237. stream->writeInt64(perm_auth_key_id);
  238. stream->writeInt64(temp_session_id);
  239. stream->writeInt32(expires_at);
  240. }
  241. TL_auth_bindTempAuthKey::~TL_auth_bindTempAuthKey() {
  242. if (encrypted_message != nullptr) {
  243. encrypted_message->reuse();
  244. encrypted_message = nullptr;
  245. }
  246. }
  247. TLObject *TL_auth_bindTempAuthKey::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
  248. return Bool::TLdeserialize(stream, constructor, instanceNum, error);
  249. }
  250. void TL_auth_bindTempAuthKey::serializeToStream(NativeByteBuffer *stream) {
  251. stream->writeInt32(constructor);
  252. stream->writeInt64(perm_auth_key_id);
  253. stream->writeInt64(nonce);
  254. stream->writeInt32(expires_at);
  255. stream->writeByteArray(encrypted_message);
  256. }
  257. TLObject *TL_auth_dropTempAuthKeys::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
  258. return Bool::TLdeserialize(stream, constructor, instanceNum, error);
  259. }
  260. void TL_auth_dropTempAuthKeys::serializeToStream(NativeByteBuffer *stream) {
  261. stream->writeInt32(constructor);
  262. stream->writeInt32(0x1cb5c415);
  263. uint32_t count = (uint32_t) except_auth_keys.size();
  264. stream->writeInt32(count);
  265. for (int a = 0; a < count; a++) {
  266. stream->writeInt64(except_auth_keys[a]);
  267. }
  268. }
  269. TL_pong *TL_pong::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
  270. if (TL_pong::constructor != constructor) {
  271. error = true;
  272. if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in TL_pong", constructor);
  273. return nullptr;
  274. }
  275. TL_pong *result = new TL_pong();
  276. result->readParams(stream, instanceNum, error);
  277. return result;
  278. }
  279. void TL_pong::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  280. msg_id = stream->readInt64(&error);
  281. ping_id = stream->readInt64(&error);
  282. }
  283. TL_future_salts *TL_future_salts::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
  284. if (TL_future_salts::constructor != constructor) {
  285. error = true;
  286. if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in TL_future_salts", constructor);
  287. return nullptr;
  288. }
  289. TL_future_salts *result = new TL_future_salts();
  290. result->readParams(stream, instanceNum, error);
  291. return result;
  292. }
  293. void TL_future_salts::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  294. req_msg_id = stream->readInt64(&error);
  295. now = stream->readInt32(&error);
  296. uint32_t count = stream->readUint32(&error);
  297. for (uint32_t a = 0; a < count; a++) {
  298. TL_future_salt *object = new TL_future_salt();
  299. object->readParams(stream, instanceNum, error);
  300. if (error) {
  301. return;
  302. }
  303. salts.push_back(std::unique_ptr<TL_future_salt>(object));
  304. }
  305. }
  306. RpcDropAnswer *RpcDropAnswer::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
  307. RpcDropAnswer *result = nullptr;
  308. switch (constructor) {
  309. case 0x5e2ad36e:
  310. result = new TL_rpc_answer_unknown();
  311. break;
  312. case 0xa43ad8b7:
  313. result = new TL_rpc_answer_dropped();
  314. break;
  315. case 0xcd78e586:
  316. result = new TL_rpc_answer_dropped_running();
  317. break;
  318. default:
  319. error = true;
  320. if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in RpcDropAnswer", constructor);
  321. return nullptr;
  322. }
  323. result->readParams(stream, instanceNum, error);
  324. return result;
  325. }
  326. void TL_rpc_answer_unknown::serializeToStream(NativeByteBuffer *stream) {
  327. stream->writeInt32(constructor);
  328. }
  329. void TL_rpc_answer_dropped::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  330. msg_id = stream->readInt64(&error);
  331. seq_no = stream->readInt32(&error);
  332. bytes = stream->readInt32(&error);
  333. }
  334. void TL_rpc_answer_dropped_running::serializeToStream(NativeByteBuffer *stream) {
  335. stream->writeInt32(constructor);
  336. }
  337. Set_client_DH_params_answer *Set_client_DH_params_answer::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
  338. Set_client_DH_params_answer *result = nullptr;
  339. switch (constructor) {
  340. case 0x46dc1fb9:
  341. result = new TL_dh_gen_retry();
  342. break;
  343. case 0xa69dae02:
  344. result = new TL_dh_gen_fail();
  345. break;
  346. case 0x3bcbf734:
  347. result = new TL_dh_gen_ok();
  348. break;
  349. default:
  350. error = true;
  351. if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in Set_client_DH_params_answer", constructor);
  352. return nullptr;
  353. }
  354. result->readParams(stream, instanceNum, error);
  355. return result;
  356. }
  357. void TL_dh_gen_retry::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  358. nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error));
  359. server_nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error));
  360. new_nonce_hash2 = std::unique_ptr<ByteArray>(stream->readBytes(16, &error));
  361. }
  362. void TL_dh_gen_fail::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  363. nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error));
  364. server_nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error));
  365. new_nonce_hash3 = std::unique_ptr<ByteArray>(stream->readBytes(16, &error));
  366. }
  367. void TL_dh_gen_ok::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  368. nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error));
  369. server_nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error));
  370. new_nonce_hash1 = std::unique_ptr<ByteArray>(stream->readBytes(16, &error));
  371. }
  372. BadMsgNotification *BadMsgNotification::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
  373. BadMsgNotification *result = nullptr;
  374. switch (constructor) {
  375. case 0xa7eff811:
  376. result = new TL_bad_msg_notification();
  377. break;
  378. case 0xedab447b:
  379. result = new TL_bad_server_salt();
  380. break;
  381. default:
  382. error = true;
  383. if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in BadMsgNotification", constructor);
  384. return nullptr;
  385. }
  386. result->readParams(stream, instanceNum, error);
  387. return result;
  388. }
  389. void TL_bad_msg_notification::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  390. bad_msg_id = stream->readInt64(&error);
  391. bad_msg_seqno = stream->readInt32(&error);
  392. error_code = stream->readInt32(&error);
  393. }
  394. void TL_bad_server_salt::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  395. bad_msg_id = stream->readInt64(&error);
  396. bad_msg_seqno = stream->readInt32(&error);
  397. error_code = stream->readInt32(&error);
  398. new_server_salt = stream->readInt64(&error);
  399. }
  400. TL_msgs_state_req *TL_msgs_state_req::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
  401. if (TL_msgs_state_req::constructor != constructor) {
  402. error = true;
  403. if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in TL_msgs_state_req", constructor);
  404. return nullptr;
  405. }
  406. TL_msgs_state_req *result = new TL_msgs_state_req();
  407. result->readParams(stream, instanceNum, error);
  408. return result;
  409. }
  410. void TL_msgs_state_req::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  411. uint32_t magic = stream->readUint32(&error);
  412. if (magic != 0x1cb5c415) {
  413. error = true;
  414. if (LOGS_ENABLED) DEBUG_FATAL("wrong Vector magic, got %x", magic);
  415. return;
  416. }
  417. uint32_t count = stream->readUint32(&error);
  418. if (count * sizeof(int64_t) + stream->position() > stream->limit()) {
  419. error = true;
  420. return;
  421. }
  422. for (uint32_t a = 0; a < count; a++) {
  423. msg_ids.push_back(stream->readInt64(&error));
  424. }
  425. }
  426. void TL_msgs_state_req::serializeToStream(NativeByteBuffer *stream) {
  427. stream->writeInt32(constructor);
  428. stream->writeInt32(0x1cb5c415);
  429. uint32_t count = (uint32_t) msg_ids.size();
  430. stream->writeInt32(count);
  431. for (uint32_t a = 0; a < count; a++) {
  432. stream->writeInt64(msg_ids[a]);
  433. }
  434. }
  435. MsgDetailedInfo *MsgDetailedInfo::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
  436. MsgDetailedInfo *result = nullptr;
  437. switch (constructor) {
  438. case 0x809db6df:
  439. result = new TL_msg_new_detailed_info();
  440. break;
  441. case 0x276d3ec6:
  442. result = new TL_msg_detailed_info();
  443. break;
  444. default:
  445. error = true;
  446. if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in MsgDetailedInfo", constructor);
  447. return nullptr;
  448. }
  449. result->readParams(stream, instanceNum, error);
  450. return result;
  451. }
  452. void TL_msg_new_detailed_info::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  453. answer_msg_id = stream->readInt64(&error);
  454. bytes = stream->readInt32(&error);
  455. status = stream->readInt32(&error);
  456. }
  457. void TL_msg_detailed_info::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  458. msg_id = stream->readInt64(&error);
  459. answer_msg_id = stream->readInt64(&error);
  460. bytes = stream->readInt32(&error);
  461. status = stream->readInt32(&error);
  462. }
  463. TL_msg_copy *TL_msg_copy::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
  464. if (TL_msg_copy::constructor != constructor) {
  465. error = true;
  466. if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in TL_msg_copy", constructor);
  467. return nullptr;
  468. }
  469. TL_msg_copy *result = new TL_msg_copy();
  470. result->readParams(stream, instanceNum, error);
  471. return result;
  472. }
  473. void TL_msg_copy::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  474. orig_message = std::unique_ptr<TL_message>(TL_message::TLdeserialize(stream, stream->readUint32(&error), instanceNum, error));
  475. }
  476. void TL_msg_copy::serializeToStream(NativeByteBuffer *stream) {
  477. stream->writeInt32(constructor);
  478. orig_message->serializeToStream(stream);
  479. }
  480. TL_msgs_all_info *TL_msgs_all_info::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
  481. if (TL_msgs_all_info::constructor != constructor) {
  482. error = true;
  483. if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in TL_msgs_all_info", constructor);
  484. return nullptr;
  485. }
  486. TL_msgs_all_info *result = new TL_msgs_all_info();
  487. result->readParams(stream, instanceNum, error);
  488. return result;
  489. }
  490. void TL_msgs_all_info::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  491. uint32_t magic = stream->readUint32(&error);
  492. if (magic != 0x1cb5c415) {
  493. error = true;
  494. if (LOGS_ENABLED) DEBUG_FATAL("wrong Vector magic, got %x", magic);
  495. return;
  496. }
  497. uint32_t count = stream->readUint32(&error);
  498. if (count * sizeof(int64_t) + stream->position() > stream->limit()) {
  499. error = true;
  500. return;
  501. }
  502. for (uint32_t a = 0; a < count; a++) {
  503. msg_ids.push_back(stream->readInt64(&error));
  504. }
  505. info = std::unique_ptr<ByteArray>(stream->readByteArray(&error));
  506. }
  507. void TL_rpc_result::readParamsEx(NativeByteBuffer *stream, uint32_t bytes, int32_t instanceNum, bool &error) {
  508. req_msg_id = stream->readInt64(&error);
  509. ConnectionsManager &connectionsManager = ConnectionsManager::getInstance(instanceNum);
  510. TLObject *object = connectionsManager.TLdeserialize(connectionsManager.getRequestWithMessageId(req_msg_id), bytes - 12, stream);
  511. if (object != nullptr) {
  512. result = std::unique_ptr<TLObject>(object);
  513. } else {
  514. error = true;
  515. }
  516. }
  517. void TL_new_session_created::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  518. first_msg_id = stream->readInt64(&error);
  519. unique_id = stream->readInt64(&error);
  520. server_salt = stream->readInt64(&error);
  521. }
  522. DestroySessionRes *DestroySessionRes::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
  523. DestroySessionRes *result = nullptr;
  524. switch (constructor) {
  525. case 0xe22045fc:
  526. result = new TL_destroy_session_ok();
  527. break;
  528. case 0x62d350c9:
  529. result = new TL_destroy_session_none();
  530. break;
  531. default:
  532. error = true;
  533. if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in DestroySessionRes", constructor);
  534. return nullptr;
  535. }
  536. result->readParams(stream, instanceNum, error);
  537. return result;
  538. }
  539. void TL_destroy_session_ok::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  540. session_id = stream->readInt64(&error);
  541. }
  542. void TL_destroy_session_none::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  543. session_id = stream->readInt64(&error);
  544. }
  545. TL_msgs_ack *TL_msgs_ack::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
  546. if (TL_msgs_ack::constructor != constructor) {
  547. error = true;
  548. if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in TL_msgs_ack", constructor);
  549. return nullptr;
  550. }
  551. TL_msgs_ack *result = new TL_msgs_ack();
  552. result->readParams(stream, instanceNum, error);
  553. return result;
  554. }
  555. void TL_msgs_ack::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  556. uint32_t magic = stream->readUint32(&error);
  557. if (magic != 0x1cb5c415) {
  558. error = true;
  559. if (LOGS_ENABLED) DEBUG_FATAL("wrong Vector magic, got %x", magic);
  560. return;
  561. }
  562. uint32_t count = stream->readUint32(&error);
  563. if (count * sizeof(int64_t) + stream->position() > stream->limit()) {
  564. error = true;
  565. return;
  566. }
  567. for (uint32_t a = 0; a < count; a++) {
  568. msg_ids.push_back(stream->readInt64(&error));
  569. }
  570. }
  571. void TL_msgs_ack::serializeToStream(NativeByteBuffer *stream) {
  572. stream->writeInt32(constructor);
  573. stream->writeInt32(0x1cb5c415);
  574. uint32_t count = (uint32_t) msg_ids.size();
  575. stream->writeInt32(count);
  576. for (uint32_t a = 0; a < count; a++) {
  577. stream->writeInt64(msg_ids[a]);
  578. }
  579. }
  580. TL_msg_container *TL_msg_container::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
  581. if (TL_msg_container::constructor != constructor) {
  582. error = true;
  583. if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in TL_msg_container", constructor);
  584. return nullptr;
  585. }
  586. TL_msg_container *result = new TL_msg_container();
  587. result->readParams(stream, instanceNum, error);
  588. return result;
  589. }
  590. void TL_msg_container::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  591. uint32_t count = stream->readUint32(&error);
  592. for (uint32_t a = 0; a < count; a++) {
  593. TL_message *object = new TL_message();
  594. object->readParams(stream, instanceNum, error);
  595. if (error) {
  596. return;
  597. }
  598. messages.push_back(std::unique_ptr<TL_message>(object));
  599. }
  600. }
  601. void TL_msg_container::serializeToStream(NativeByteBuffer *stream) {
  602. stream->writeInt32(constructor);
  603. uint32_t count = (uint32_t) messages.size();
  604. stream->writeInt32(count);
  605. for (uint32_t a = 0; a < count; a++) {
  606. messages[a]->serializeToStream(stream);
  607. }
  608. }
  609. TL_message *TL_message::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
  610. if (TL_message::constructor != constructor) {
  611. error = true;
  612. if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in TL_message", constructor);
  613. return nullptr;
  614. }
  615. TL_message *result = new TL_message();
  616. result->readParams(stream, instanceNum, error);
  617. return result;
  618. }
  619. void TL_message::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  620. msg_id = stream->readInt64(&error);
  621. seqno = stream->readInt32(&error);
  622. bytes = stream->readInt32(&error);
  623. TLObject *object = ConnectionsManager::getInstance(instanceNum).TLdeserialize(nullptr, (uint32_t) bytes, stream);
  624. if (object == nullptr) {
  625. unparsedBody = std::unique_ptr<NativeByteBuffer>(new NativeByteBuffer(stream->bytes() + stream->position(), (uint32_t) bytes));
  626. stream->skip((uint32_t) bytes);
  627. } else {
  628. body = std::unique_ptr<TLObject>(object);
  629. }
  630. }
  631. void TL_message::serializeToStream(NativeByteBuffer *stream) {
  632. stream->writeInt64(msg_id);
  633. stream->writeInt32(seqno);
  634. stream->writeInt32(bytes);
  635. if (outgoingBody != nullptr) {
  636. outgoingBody->serializeToStream(stream);
  637. } else {
  638. body->serializeToStream(stream);
  639. }
  640. }
  641. TL_msg_resend_req *TL_msg_resend_req::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
  642. if (TL_msg_resend_req::constructor != constructor) {
  643. error = true;
  644. if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in TL_msg_resend_req", constructor);
  645. return nullptr;
  646. }
  647. TL_msg_resend_req *result = new TL_msg_resend_req();
  648. result->readParams(stream, instanceNum, error);
  649. return result;
  650. }
  651. void TL_msg_resend_req::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  652. uint32_t magic = stream->readUint32(&error);
  653. if (magic != 0x1cb5c415) {
  654. error = true;
  655. if (LOGS_ENABLED) DEBUG_FATAL("wrong Vector magic, got %x", magic);
  656. return;
  657. }
  658. uint32_t count = stream->readUint32(&error);
  659. if (count * sizeof(int64_t) + stream->position() > stream->limit()) {
  660. error = true;
  661. return;
  662. }
  663. for (uint32_t a = 0; a < count; a++) {
  664. msg_ids.push_back(stream->readInt64(&error));
  665. }
  666. }
  667. void TL_msg_resend_req::serializeToStream(NativeByteBuffer *stream) {
  668. stream->writeInt32(constructor);
  669. stream->writeInt32(0x1cb5c415);
  670. uint32_t count = (uint32_t) msg_ids.size();
  671. stream->writeInt32(count);
  672. for (uint32_t a = 0; a < count; a++) {
  673. stream->writeInt64(msg_ids[a]);
  674. }
  675. }
  676. void MsgsStateInfo::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  677. req_msg_id = stream->readInt64(&error);
  678. info = stream->readString(&error);
  679. }
  680. void TL_rpc_error::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  681. error_code = stream->readInt32(&error);
  682. error_message = stream->readString(&error);
  683. }
  684. void TL_rpc_req_error::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  685. query_id = stream->readInt64(&error);
  686. error_code = stream->readInt32(&error);
  687. error_message = stream->readString(&error);
  688. }
  689. void TL_client_DH_inner_data::serializeToStream(NativeByteBuffer *stream) {
  690. stream->writeInt32(constructor);
  691. stream->writeBytes(nonce.get());
  692. stream->writeBytes(server_nonce.get());
  693. stream->writeInt64(retry_id);
  694. stream->writeByteArray(g_b.get());
  695. }
  696. TL_server_DH_inner_data *TL_server_DH_inner_data::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
  697. if (TL_server_DH_inner_data::constructor != constructor) {
  698. error = true;
  699. if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in TL_server_DH_inner_data", constructor);
  700. return nullptr;
  701. }
  702. TL_server_DH_inner_data *result = new TL_server_DH_inner_data();
  703. result->readParams(stream, instanceNum, error);
  704. return result;
  705. }
  706. void TL_server_DH_inner_data::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  707. nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error));
  708. server_nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error));
  709. g = stream->readUint32(&error);
  710. dh_prime = std::unique_ptr<ByteArray>(stream->readByteArray(&error));
  711. g_a = std::unique_ptr<ByteArray>(stream->readByteArray(&error));
  712. server_time = stream->readInt32(&error);
  713. }
  714. void TL_server_DH_inner_data::serializeToStream(NativeByteBuffer *stream) {
  715. stream->writeInt32(constructor);
  716. stream->writeBytes(nonce.get());
  717. stream->writeBytes(server_nonce.get());
  718. stream->writeInt32(g);
  719. stream->writeByteArray(dh_prime.get());
  720. stream->writeByteArray(g_a.get());
  721. stream->writeInt32(server_time);
  722. }
  723. TLObject *TL_req_pq::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
  724. return TL_resPQ::TLdeserialize(stream, constructor, instanceNum, error);
  725. }
  726. void TL_req_pq::serializeToStream(NativeByteBuffer *stream) {
  727. stream->writeInt32(constructor);
  728. stream->writeBytes(nonce.get());
  729. }
  730. TLObject *TL_req_pq_multi::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
  731. return TL_resPQ::TLdeserialize(stream, constructor, instanceNum, error);
  732. }
  733. void TL_req_pq_multi::serializeToStream(NativeByteBuffer *stream) {
  734. stream->writeInt32(constructor);
  735. stream->writeBytes(nonce.get());
  736. }
  737. TLObject *TL_req_DH_params::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
  738. return Server_DH_Params::TLdeserialize(stream, constructor, instanceNum, error);
  739. }
  740. void TL_req_DH_params::serializeToStream(NativeByteBuffer *stream) {
  741. stream->writeInt32(constructor);
  742. stream->writeBytes(nonce.get());
  743. stream->writeBytes(server_nonce.get());
  744. stream->writeByteArray(p.get());
  745. stream->writeByteArray(q.get());
  746. stream->writeInt64(public_key_fingerprint);
  747. stream->writeByteArray(encrypted_data.get());
  748. }
  749. TLObject *TL_set_client_DH_params::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
  750. return Set_client_DH_params_answer::TLdeserialize(stream, constructor, instanceNum, error);
  751. }
  752. void TL_set_client_DH_params::serializeToStream(NativeByteBuffer *stream) {
  753. stream->writeInt32(constructor);
  754. stream->writeBytes(nonce.get());
  755. stream->writeBytes(server_nonce.get());
  756. stream->writeByteArray(encrypted_data.get());
  757. }
  758. TLObject *TL_rpc_drop_answer::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
  759. return RpcDropAnswer::TLdeserialize(stream, constructor, instanceNum, error);
  760. }
  761. void TL_rpc_drop_answer::serializeToStream(NativeByteBuffer *stream) {
  762. stream->writeInt32(constructor);
  763. stream->writeInt64(req_msg_id);
  764. }
  765. TLObject *TL_get_future_salts::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
  766. return TL_future_salts::TLdeserialize(stream, constructor, instanceNum, error);
  767. }
  768. void TL_get_future_salts::serializeToStream(NativeByteBuffer *stream) {
  769. stream->writeInt32(constructor);
  770. stream->writeInt32(num);
  771. }
  772. TLObject *TL_ping::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
  773. return TL_pong::TLdeserialize(stream, constructor, instanceNum, error);
  774. }
  775. void TL_ping::serializeToStream(NativeByteBuffer *stream) {
  776. stream->writeInt32(constructor);
  777. stream->writeInt64(ping_id);
  778. }
  779. TLObject *TL_ping_delay_disconnect::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
  780. return TL_pong::TLdeserialize(stream, constructor, instanceNum, error);
  781. }
  782. void TL_ping_delay_disconnect::serializeToStream(NativeByteBuffer *stream) {
  783. stream->writeInt32(constructor);
  784. stream->writeInt64(ping_id);
  785. stream->writeInt32(disconnect_delay);
  786. }
  787. TLObject *TL_destroy_session::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
  788. return DestroySessionRes::TLdeserialize(stream, constructor, instanceNum, error);
  789. }
  790. void TL_destroy_session::serializeToStream(NativeByteBuffer *stream) {
  791. stream->writeInt32(constructor);
  792. stream->writeInt64(session_id);
  793. }
  794. TL_gzip_packed::~TL_gzip_packed() {
  795. if (packed_data_to_send != nullptr) {
  796. packed_data_to_send->reuse();
  797. packed_data_to_send = nullptr;
  798. }
  799. }
  800. void TL_gzip_packed::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  801. packed_data = std::unique_ptr<NativeByteBuffer>(stream->readByteBuffer(false, &error));
  802. }
  803. void TL_gzip_packed::serializeToStream(NativeByteBuffer *stream) {
  804. stream->writeInt32(constructor);
  805. stream->writeByteArray(packed_data_to_send);
  806. }
  807. TL_error *TL_error::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
  808. if (TL_error::constructor != constructor) {
  809. error = true;
  810. if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in TL_error", constructor);
  811. return nullptr;
  812. }
  813. TL_error *result = new TL_error();
  814. result->readParams(stream, instanceNum, error);
  815. return result;
  816. }
  817. void TL_error::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  818. code = stream->readInt32(&error);
  819. text = stream->readString(&error);
  820. }
  821. void TL_error::serializeToStream(NativeByteBuffer *stream) {
  822. stream->writeInt32(constructor);
  823. stream->writeInt32(code);
  824. stream->writeString(text);
  825. }
  826. void TL_invokeAfterMsg::serializeToStream(NativeByteBuffer *stream) {
  827. stream->writeInt32(constructor);
  828. stream->writeInt64(msg_id);
  829. if (outgoingQuery != nullptr) {
  830. outgoingQuery->serializeToStream(stream);
  831. } else {
  832. query->serializeToStream(stream);
  833. }
  834. }
  835. void invokeWithLayer::serializeToStream(NativeByteBuffer *stream) {
  836. stream->writeInt32(constructor);
  837. stream->writeInt32(layer);
  838. query->serializeToStream(stream);
  839. }
  840. void TL_inputClientProxy::serializeToStream(NativeByteBuffer *stream) {
  841. stream->writeInt32(constructor);
  842. stream->writeString(address);
  843. stream->writeInt32(port);
  844. }
  845. JSONValue *JSONValue::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
  846. JSONValue *result = nullptr;
  847. switch (constructor) {
  848. case 0xc7345e6a:
  849. result = new TL_jsonBool();
  850. break;
  851. case 0x3f6d7b68:
  852. result = new TL_jsonNull();
  853. break;
  854. case 0xb71e767a:
  855. result = new TL_jsonString();
  856. break;
  857. case 0xf7444763:
  858. result = new TL_jsonArray();
  859. break;
  860. case 0x99c1d49d:
  861. result = new TL_jsonObject();
  862. break;
  863. case 0x2be0dfa4:
  864. result = new TL_jsonNumber();
  865. break;
  866. default:
  867. error = true;
  868. if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in JSONValue", constructor);
  869. return nullptr;
  870. }
  871. result->readParams(stream, instanceNum, error);
  872. return result;
  873. }
  874. TL_jsonObjectValue *TL_jsonObjectValue::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
  875. if (TL_jsonObjectValue::constructor != constructor) {
  876. error = true;
  877. if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in TL_jsonObjectValue", constructor);
  878. return nullptr;
  879. }
  880. TL_jsonObjectValue *result = new TL_jsonObjectValue();
  881. result->readParams(stream, instanceNum, error);
  882. return result;
  883. }
  884. void TL_jsonObjectValue::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  885. key = stream->readString(&error);
  886. value = std::unique_ptr<JSONValue>(JSONValue::TLdeserialize(stream, stream->readUint32(&error), instanceNum, error));
  887. }
  888. void TL_jsonObjectValue::serializeToStream(NativeByteBuffer *stream) {
  889. stream->writeInt32(constructor);
  890. stream->writeString(key);
  891. value->serializeToStream(stream);
  892. }
  893. void TL_jsonBool::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  894. value = stream->readBool(&error);
  895. }
  896. void TL_jsonBool::serializeToStream(NativeByteBuffer *stream) {
  897. stream->writeInt32(constructor);
  898. stream->writeBool(value);
  899. }
  900. void TL_jsonNull::serializeToStream(NativeByteBuffer *stream) {
  901. stream->writeInt32(constructor);
  902. }
  903. void TL_jsonString::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  904. value = stream->readString(&error);
  905. }
  906. void TL_jsonString::serializeToStream(NativeByteBuffer *stream) {
  907. stream->writeInt32(constructor);
  908. stream->writeString(value);
  909. }
  910. void TL_jsonArray::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  911. int magic = stream->readInt32(&error);
  912. if (magic != 0x1cb5c415) {
  913. error = true;
  914. if (LOGS_ENABLED) DEBUG_FATAL("wrong Vector magic, got %x", magic);
  915. return;
  916. }
  917. int count = stream->readInt32(&error);
  918. for (int a = 0; a < count; a++) {
  919. JSONValue *object = JSONValue::TLdeserialize(stream, stream->readUint32(&error), instanceNum, error);
  920. if (object == nullptr) {
  921. return;
  922. }
  923. value.push_back(std::unique_ptr<JSONValue>(object));
  924. }
  925. }
  926. void TL_jsonArray::serializeToStream(NativeByteBuffer *stream) {
  927. stream->writeInt32(constructor);
  928. stream->writeInt32(0x1cb5c415);
  929. uint32_t count = (uint32_t) value.size();
  930. stream->writeInt32(count);
  931. for (int a = 0; a < count; a++) {
  932. value[a]->serializeToStream(stream);
  933. }
  934. }
  935. void TL_jsonObject::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  936. int magic = stream->readInt32(&error);
  937. if (magic != 0x1cb5c415) {
  938. error = true;
  939. if (LOGS_ENABLED) DEBUG_FATAL("wrong Vector magic, got %x", magic);
  940. return;
  941. }
  942. int count = stream->readInt32(&error);
  943. for (int a = 0; a < count; a++) {
  944. TL_jsonObjectValue *object = TL_jsonObjectValue::TLdeserialize(stream, stream->readUint32(&error), instanceNum, error);
  945. if (object == nullptr) {
  946. return;
  947. }
  948. value.push_back(std::unique_ptr<TL_jsonObjectValue>(object));
  949. }
  950. }
  951. void TL_jsonObject::serializeToStream(NativeByteBuffer *stream) {
  952. stream->writeInt32(constructor);
  953. stream->writeInt32(0x1cb5c415);
  954. uint32_t count = (uint32_t) value.size();
  955. stream->writeInt32(count);
  956. for (int a = 0; a < count; a++) {
  957. value[a]->serializeToStream(stream);
  958. }
  959. }
  960. void TL_jsonNumber::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  961. value = stream->readDouble(&error);
  962. }
  963. void TL_jsonNumber::serializeToStream(NativeByteBuffer *stream) {
  964. stream->writeInt32(constructor);
  965. stream->writeDouble(value);
  966. }
  967. void initConnection::serializeToStream(NativeByteBuffer *stream) {
  968. stream->writeInt32(constructor);
  969. stream->writeInt32(flags);
  970. stream->writeInt32(api_id);
  971. stream->writeString(device_model);
  972. stream->writeString(system_version);
  973. stream->writeString(app_version);
  974. stream->writeString(system_lang_code);
  975. stream->writeString(lang_pack);
  976. stream->writeString(lang_code);
  977. if ((flags & 1) != 0) {
  978. proxy->serializeToStream(stream);
  979. }
  980. if ((flags & 2) != 0) {
  981. params->serializeToStream(stream);
  982. }
  983. query->serializeToStream(stream);
  984. }
  985. IpPort *IpPort::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
  986. IpPort *result = nullptr;
  987. switch (constructor) {
  988. case 0xd433ad73:
  989. result = new TL_ipPort();
  990. break;
  991. case 0x37982646:
  992. result = new TL_ipPortSecret();
  993. break;
  994. default:
  995. error = true;
  996. if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in IpPort", constructor);
  997. return nullptr;
  998. }
  999. result->readParams(stream, instanceNum, error);
  1000. return result;
  1001. }
  1002. void TL_ipPort::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  1003. struct in_addr ip_addr;
  1004. ip_addr.s_addr = htonl(stream->readUint32(&error));
  1005. ipv4 = inet_ntoa(ip_addr);
  1006. port = stream->readUint32(&error);
  1007. }
  1008. void TL_ipPortSecret::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  1009. struct in_addr ip_addr;
  1010. ip_addr.s_addr = htonl(stream->readUint32(&error));
  1011. ipv4 = inet_ntoa(ip_addr);
  1012. port = stream->readUint32(&error);
  1013. secret = std::unique_ptr<ByteArray>(stream->readByteArray(&error));
  1014. }
  1015. void TL_accessPointRule::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  1016. phone_prefix_rules = stream->readString(&error);
  1017. dc_id = stream->readUint32(&error);
  1018. uint32_t count = stream->readUint32(&error);
  1019. for (uint32_t a = 0; a < count; a++) {
  1020. IpPort *object = IpPort::TLdeserialize(stream, stream->readUint32(&error), instanceNum, error);
  1021. if (object == nullptr) {
  1022. return;
  1023. }
  1024. ips.push_back(std::unique_ptr<IpPort>(object));
  1025. }
  1026. }
  1027. TL_help_configSimple *TL_help_configSimple::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, int32_t instanceNum, bool &error) {
  1028. if (TL_help_configSimple::constructor != constructor) {
  1029. error = true;
  1030. if (LOGS_ENABLED) DEBUG_FATAL("can't parse magic %x in TL_help_configSimple", constructor);
  1031. return nullptr;
  1032. }
  1033. TL_help_configSimple *result = new TL_help_configSimple();
  1034. result->readParams(stream, instanceNum, error);
  1035. return result;
  1036. }
  1037. void TL_help_configSimple::readParams(NativeByteBuffer *stream, int32_t instanceNum, bool &error) {
  1038. date = stream->readInt32(&error);
  1039. expires = stream->readInt32(&error);
  1040. uint32_t count = stream->readUint32(&error);
  1041. for (uint32_t a = 0; a < count; a++) {
  1042. TL_accessPointRule *object = new TL_accessPointRule();
  1043. object->readParams(stream, stream->readUint32(&error), error);
  1044. if (error) {
  1045. return;
  1046. }
  1047. rules.push_back(std::unique_ptr<TL_accessPointRule>(object));
  1048. }
  1049. }