| 6 |
| * Copyright Nikolai Kudashov, 2015. |
| 7 | */ |
| 8 |
| 9 | #include <memory.h> |
| 10 | #include "MTProtoScheme.h" |
| 11 | #include "FileLog.h" |
| 12 | #include "ByteArray.h" |
| 13 | #include "NativeByteBuffer.h" |
| 14 | #include "BuffersStorage.h" |
| 15 | #include "ConnectionsManager.h" |
| 16 |
| 17 | TLObject *TLClassStore::TLdeserialize(NativeByteBuffer *stream, uint32_t bytes, uint32_t constructor, 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 TL_rpc_result::constructor: |
| 33 | object = new TL_rpc_result(); |
| 34 | ((TL_rpc_result *) object)->readParamsEx(stream, bytes, error); |
| 35 | return object; |
| 36 | case TL_bad_msg_notification::constructor: |
| 37 | object = new TL_bad_msg_notification(); |
| 38 | break; |
| 39 | case TL_bad_server_salt::constructor: |
| 40 | object = new TL_bad_server_salt(); |
| 41 | break; |
| 42 | case TL_msg_detailed_info::constructor: |
| 43 | object = new TL_msg_detailed_info(); |
| 44 | break; |
| 45 | case TL_msg_new_detailed_info::constructor: |
| 46 | object = new TL_msg_new_detailed_info(); |
| 47 | break; |
| 48 | case TL_gzip_packed::constructor: |
| 49 | object = new TL_gzip_packed(); |
| 50 | break; |
| 51 | case TL_error::constructor: |
| 52 | object = new TL_error(); |
| 53 | break; |
| 54 | case TL_rpc_error::constructor: |
| 55 | object = new TL_rpc_error(); |
| 56 | break; |
| 57 | case TL_rpc_req_error::constructor: |
| 58 | object = new TL_rpc_req_error(); |
| 59 | break; |
| 60 | case TL_future_salts::constructor: |
| 61 | object = new TL_future_salts(); |
| 62 | break; |
| 63 | case TL_destroy_session_ok::constructor: |
| 64 | object = new TL_destroy_session_ok(); |
| 65 | break; |
| 66 | case TL_destroy_session_none::constructor: |
| 67 | object = new TL_destroy_session_none(); |
| 68 | break; |
| 69 | case TL_updatesTooLong::constructor: |
| 70 | object = new TL_updatesTooLong(); |
| 71 | break; |
| 72 | default: |
| 73 | return nullptr; |
| 74 | } |
| 75 | object->readParams(stream, error); |
| 76 | return object; |
| 77 | } |
| 78 |
| 79 | TL_api_request::~TL_api_request() { |
| 80 | if (request != nullptr) { |
| 81 | request->reuse(); |
| 82 | request = nullptr; |
| 83 | } |
| 84 | } |
| 85 |
| 86 | bool TL_api_request::isNeedLayer() { |
| 87 | return true; |
| 88 | } |
| 89 |
| 90 | TLObject *TL_api_request::deserializeResponse(NativeByteBuffer *stream, uint32_t bytes, bool &error) { |
| 91 | TL_api_response *result = new TL_api_response(); |
| 92 | result->readParamsEx(stream, bytes, error); |
| 93 | return result; |
| 94 | } |
| 95 |
| 96 | void TL_api_request::serializeToStream(NativeByteBuffer *stream) { |
| 97 | request->rewind(); |
| 98 | stream->writeBytes(request); |
| 99 | } |
| 100 |
| 101 | void TL_api_response::readParamsEx(NativeByteBuffer *stream, uint32_t bytes, bool &error) { |
| 102 | response = std::unique_ptr<NativeByteBuffer>(new NativeByteBuffer(stream->bytes() + stream->position() - 4, bytes)); |
| 103 | stream->skip((uint32_t) (bytes - 4)); |
| 104 | } |
| 105 |
| 106 | TL_future_salt *TL_future_salt::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 107 | if (TL_future_salt::constructor != constructor) { |
| 108 | error = true; |
| 109 | DEBUG_E("can't parse magic %x in TL_future_salt", constructor); |
| 110 | return nullptr; |
| 111 | } |
| 112 | TL_future_salt *result = new TL_future_salt(); |
| 113 | result->readParams(stream, error); |
| 114 | return result; |
| 115 | } |
| 116 |
| 117 | void TL_future_salt::readParams(NativeByteBuffer *stream, bool &error) { |
| 118 | valid_since = stream->readInt32(&error); |
| 119 | valid_until = stream->readInt32(&error); |
| 120 | salt = stream->readInt64(&error); |
| 121 | } |
| 122 |
| 123 | TL_msgs_state_info *TL_msgs_state_info::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 124 | if (TL_msgs_state_info::constructor != constructor) { |
| 125 | error = true; |
| 126 | DEBUG_E("can't parse magic %x in TL_msgs_state_info", constructor); |
| 127 | return nullptr; |
| 128 | } |
| 129 | TL_msgs_state_info *result = new TL_msgs_state_info(); |
| 130 | result->readParams(stream, error); |
| 131 | return result; |
| 132 | } |
| 133 |
| 134 | void TL_msgs_state_info::readParams(NativeByteBuffer *stream, bool &error) { |
| 135 | req_msg_id = stream->readInt64(&error); |
| 136 | info = std::unique_ptr<ByteArray>(stream->readByteArray(&error)); |
| 137 | } |
| 138 |
| 139 | void TL_msgs_state_info::serializeToStream(NativeByteBuffer *stream) { |
| 140 | stream->writeInt32(constructor); |
| 141 | stream->writeInt64(req_msg_id); |
| 142 | stream->writeByteArray(info.get()); |
| 143 | } |
| 144 |
| 145 | Server_DH_Params *Server_DH_Params::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 146 | Server_DH_Params *result = nullptr; |
| 147 | switch (constructor) { |
| 148 | case 0x79cb045d: |
| 149 | result = new TL_server_DH_params_fail(); |
| 150 | break; |
| 151 | case 0xd0e8075c: |
| 152 | result = new TL_server_DH_params_ok(); |
| 153 | break; |
| 154 | default: |
| 155 | error = true; |
| 156 | DEBUG_E("can't parse magic %x in Server_DH_Params", constructor); |
| 157 | return nullptr; |
| 158 | } |
| 159 | result->readParams(stream, error); |
| 160 | return result; |
| 161 | } |
| 162 |
| 163 | void TL_server_DH_params_fail::readParams(NativeByteBuffer *stream, bool &error) { |
| 164 | nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error)); |
| 165 | server_nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error)); |
| 166 | new_nonce_hash = std::unique_ptr<ByteArray>(stream->readBytes(16, &error)); |
| 167 | } |
| 168 |
| 169 | void TL_server_DH_params_ok::readParams(NativeByteBuffer *stream, bool &error) { |
| 170 | nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error)); |
| 171 | server_nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error)); |
| 172 | encrypted_answer = std::unique_ptr<ByteArray>(stream->readByteArray(&error)); |
| 173 | } |
| 174 |
| 175 | TL_resPQ *TL_resPQ::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 176 | if (TL_resPQ::constructor != constructor) { |
| 177 | error = true; |
| 178 | DEBUG_E("can't parse magic %x in TL_resPQ", constructor); |
| 179 | return nullptr; |
| 180 | } |
| 181 | TL_resPQ *result = new TL_resPQ(); |
| 182 | result->readParams(stream, error); |
| 183 | return result; |
| 184 | } |
| 185 |
| 186 | void TL_resPQ::readParams(NativeByteBuffer *stream, bool &error) { |
| 187 | nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error)); |
| 188 | server_nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error)); |
| 189 | pq = std::unique_ptr<ByteArray>(stream->readByteArray(&error)); |
| 190 | uint32_t magic = stream->readUint32(&error); |
| 191 | if (magic != 0x1cb5c415) { |
| 192 | error = true; |
| 193 | DEBUG_E("wrong Vector magic, got %x", magic); |
| 194 | return; |
| 195 | } |
| 196 | uint32_t count = stream->readUint32(&error); |
| 197 | if (count * sizeof(int64_t) + stream->position() > stream->limit()) { |
| 198 | error = true; |
| 199 | return; |
| 200 | } |
| 201 | for (uint32_t a = 0; a < count; a++) { |
| 202 | server_public_key_fingerprints.push_back(stream->readInt64(&error)); |
| 203 | } |
| 204 | } |
| 205 |
| 206 | void TL_p_q_inner_data::serializeToStream(NativeByteBuffer *stream) { |
| 207 | stream->writeInt32(constructor); |
| 208 | stream->writeByteArray(pq.get()); |
| 209 | stream->writeByteArray(p.get()); |
| 210 | stream->writeByteArray(q.get()); |
| 211 | stream->writeBytes(nonce.get()); |
| 212 | stream->writeBytes(server_nonce.get()); |
| 213 | stream->writeBytes(new_nonce.get()); |
| 214 | } |
| 215 |
| 216 | TL_pong *TL_pong::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 217 | if (TL_pong::constructor != constructor) { |
| 218 | error = true; |
| 219 | DEBUG_E("can't parse magic %x in TL_pong", constructor); |
| 220 | return nullptr; |
| 221 | } |
| 222 | TL_pong *result = new TL_pong(); |
| 223 | result->readParams(stream, error); |
| 224 | return result; |
| 225 | } |
| 226 |
| 227 | void TL_pong::readParams(NativeByteBuffer *stream, bool &error) { |
| 228 | msg_id = stream->readInt64(&error); |
| 229 | ping_id = stream->readInt64(&error); |
| 230 | } |
| 231 |
| 232 | TL_future_salts *TL_future_salts::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 233 | if (TL_future_salts::constructor != constructor) { |
| 234 | error = true; |
| 235 | DEBUG_E("can't parse magic %x in TL_future_salts", constructor); |
| 236 | return nullptr; |
| 237 | } |
| 238 | TL_future_salts *result = new TL_future_salts(); |
| 239 | result->readParams(stream, error); |
| 240 | return result; |
| 241 | } |
| 242 |
| 243 | void TL_future_salts::readParams(NativeByteBuffer *stream, bool &error) { |
| 244 | req_msg_id = stream->readInt64(&error); |
| 245 | now = stream->readInt32(&error); |
| 246 | uint32_t count = stream->readUint32(&error); |
| 247 | for (uint32_t a = 0; a < count; a++) { |
| 248 | TL_future_salt *object = new TL_future_salt(); |
| 249 | object->readParams(stream, error); |
| 250 | if (error) { |
| 251 | return; |
| 252 | } |
| 253 | salts.push_back(std::unique_ptr<TL_future_salt>(object)); |
| 254 | } |
| 255 | } |
| 256 |
| 257 | RpcDropAnswer *RpcDropAnswer::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 258 | RpcDropAnswer *result = nullptr; |
| 259 | switch (constructor) { |
| 260 | case 0x5e2ad36e: |
| 261 | result = new TL_rpc_answer_unknown(); |
| 262 | break; |
| 263 | case 0xa43ad8b7: |
| 264 | result = new TL_rpc_answer_dropped(); |
| 265 | break; |
| 266 | case 0xcd78e586: |
| 267 | result = new TL_rpc_answer_dropped_running(); |
| 268 | break; |
| 269 | default: |
| 270 | error = true; |
| 271 | DEBUG_E("can't parse magic %x in RpcDropAnswer", constructor); |
| 272 | return nullptr; |
| 273 | } |
| 274 | result->readParams(stream, error); |
| 275 | return result; |
| 276 | } |
| 277 |
| 278 | void TL_rpc_answer_unknown::serializeToStream(NativeByteBuffer *stream) { |
| 279 | stream->writeInt32(constructor); |
| 280 | } |
| 281 |
| 282 | void TL_rpc_answer_dropped::readParams(NativeByteBuffer *stream, bool &error) { |
| 283 | msg_id = stream->readInt64(&error); |
| 284 | seq_no = stream->readInt32(&error); |
| 285 | bytes = stream->readInt32(&error); |
| 286 | } |
| 287 |
| 288 | void TL_rpc_answer_dropped_running::serializeToStream(NativeByteBuffer *stream) { |
| 289 | stream->writeInt32(constructor); |
| 290 | } |
| 291 |
| 292 | Set_client_DH_params_answer *Set_client_DH_params_answer::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 293 | Set_client_DH_params_answer *result = nullptr; |
| 294 | switch (constructor) { |
| 295 | case 0x46dc1fb9: |
| 296 | result = new TL_dh_gen_retry(); |
| 297 | break; |
| 298 | case 0xa69dae02: |
| 299 | result = new TL_dh_gen_fail(); |
| 300 | break; |
| 301 | case 0x3bcbf734: |
| 302 | result = new TL_dh_gen_ok(); |
| 303 | break; |
| 304 | default: |
| 305 | error = true; |
| 306 | DEBUG_E("can't parse magic %x in Set_client_DH_params_answer", constructor); |
| 307 | return nullptr; |
| 308 | } |
| 309 | result->readParams(stream, error); |
| 310 | return result; |
| 311 | } |
| 312 |
| 313 | void TL_dh_gen_retry::readParams(NativeByteBuffer *stream, bool &error) { |
| 314 | nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error)); |
| 315 | server_nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error)); |
| 316 | new_nonce_hash2 = std::unique_ptr<ByteArray>(stream->readBytes(16, &error)); |
| 317 | } |
| 318 |
| 319 | void TL_dh_gen_fail::readParams(NativeByteBuffer *stream, bool &error) { |
| 320 | nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error)); |
| 321 | server_nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error)); |
| 322 | new_nonce_hash3 = std::unique_ptr<ByteArray>(stream->readBytes(16, &error)); |
| 323 | } |
| 324 |
| 325 | void TL_dh_gen_ok::readParams(NativeByteBuffer *stream, bool &error) { |
| 326 | nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error)); |
| 327 | server_nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error)); |
| 328 | new_nonce_hash1 = std::unique_ptr<ByteArray>(stream->readBytes(16, &error)); |
| 329 | } |
| 330 |
| 331 | BadMsgNotification *BadMsgNotification::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 332 | BadMsgNotification *result = nullptr; |
| 333 | switch (constructor) { |
| 334 | case 0xa7eff811: |
| 335 | result = new TL_bad_msg_notification(); |
| 336 | break; |
| 337 | case 0xedab447b: |
| 338 | result = new TL_bad_server_salt(); |
| 339 | break; |
| 340 | default: |
| 341 | error = true; |
| 342 | DEBUG_E("can't parse magic %x in BadMsgNotification", constructor); |
| 343 | return nullptr; |
| 344 | } |
| 345 | result->readParams(stream, error); |
| 346 | return result; |
| 347 | } |
| 348 |
| 349 | void TL_bad_msg_notification::readParams(NativeByteBuffer *stream, bool &error) { |
| 350 | bad_msg_id = stream->readInt64(&error); |
| 351 | bad_msg_seqno = stream->readInt32(&error); |
| 352 | error_code = stream->readInt32(&error); |
| 353 | } |
| 354 |
| 355 | void TL_bad_server_salt::readParams(NativeByteBuffer *stream, bool &error) { |
| 356 | bad_msg_id = stream->readInt64(&error); |
| 357 | bad_msg_seqno = stream->readInt32(&error); |
| 358 | error_code = stream->readInt32(&error); |
| 359 | new_server_salt = stream->readInt64(&error); |
| 360 | } |
| 361 |
| 362 | TL_msgs_state_req *TL_msgs_state_req::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 363 | if (TL_msgs_state_req::constructor != constructor) { |
| 364 | error = true; |
| 365 | DEBUG_E("can't parse magic %x in TL_msgs_state_req", constructor); |
| 366 | return nullptr; |
| 367 | } |
| 368 | TL_msgs_state_req *result = new TL_msgs_state_req(); |
| 369 | result->readParams(stream, error); |
| 370 | return result; |
| 371 | } |
| 372 |
| 373 | void TL_msgs_state_req::readParams(NativeByteBuffer *stream, bool &error) { |
| 374 | uint32_t magic = stream->readUint32(&error); |
| 375 | if (magic != 0x1cb5c415) { |
| 376 | error = true; |
| 377 | DEBUG_E("wrong Vector magic, got %x", magic); |
| 378 | return; |
| 379 | } |
| 380 | uint32_t count = stream->readUint32(&error); |
| 381 | if (count * sizeof(int64_t) + stream->position() > stream->limit()) { |
| 382 | error = true; |
| 383 | return; |
| 384 | } |
| 385 | for (uint32_t a = 0; a < count; a++) { |
| 386 | msg_ids.push_back(stream->readInt64(&error)); |
| 387 | } |
| 388 | } |
| 389 |
| 390 | void TL_msgs_state_req::serializeToStream(NativeByteBuffer *stream) { |
| 391 | stream->writeInt32(constructor); |
| 392 | stream->writeInt32(0x1cb5c415); |
| 393 | uint32_t count = (uint32_t) msg_ids.size(); |
| 394 | stream->writeInt32(count); |
| 395 | for (uint32_t a = 0; a < count; a++) { |
| 396 | stream->writeInt64(msg_ids[a]); |
| 397 | } |
| 398 | } |
| 399 |
| 400 | MsgDetailedInfo *MsgDetailedInfo::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 401 | MsgDetailedInfo *result = nullptr; |
| 402 | switch (constructor) { |
| 403 | case 0x809db6df: |
| 404 | result = new TL_msg_new_detailed_info(); |
| 405 | break; |
| 406 | case 0x276d3ec6: |
| 407 | result = new TL_msg_detailed_info(); |
| 408 | break; |
| 409 | default: |
| 410 | error = true; |
| 411 | DEBUG_E("can't parse magic %x in MsgDetailedInfo", constructor); |
| 412 | return nullptr; |
| 413 | } |
| 414 | result->readParams(stream, error); |
| 415 | return result; |
| 416 | } |
| 417 |
| 418 | void TL_msg_new_detailed_info::readParams(NativeByteBuffer *stream, bool &error) { |
| 419 | answer_msg_id = stream->readInt64(&error); |
| 420 | bytes = stream->readInt32(&error); |
| 421 | status = stream->readInt32(&error); |
| 422 | } |
| 423 |
| 424 | void TL_msg_detailed_info::readParams(NativeByteBuffer *stream, bool &error) { |
| 425 | msg_id = stream->readInt64(&error); |
| 426 | answer_msg_id = stream->readInt64(&error); |
| 427 | bytes = stream->readInt32(&error); |
| 428 | status = stream->readInt32(&error); |
| 429 | } |
| 430 |
| 431 | TL_msg_copy *TL_msg_copy::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 432 | if (TL_msg_copy::constructor != constructor) { |
| 433 | error = true; |
| 434 | DEBUG_E("can't parse magic %x in TL_msg_copy", constructor); |
| 435 | return nullptr; |
| 436 | } |
| 437 | TL_msg_copy *result = new TL_msg_copy(); |
| 438 | result->readParams(stream, error); |
| 439 | return result; |
| 440 | } |
| 441 |
| 442 | void TL_msg_copy::readParams(NativeByteBuffer *stream, bool &error) { |
| 443 | orig_message = std::unique_ptr<TL_message>(TL_message::TLdeserialize(stream, stream->readUint32(&error), error)); |
| 444 | } |
| 445 |
| 446 | void TL_msg_copy::serializeToStream(NativeByteBuffer *stream) { |
| 447 | stream->writeInt32(constructor); |
| 448 | orig_message->serializeToStream(stream); |
| 449 | } |
| 450 |
| 451 | TL_msgs_all_info *TL_msgs_all_info::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 452 | if (TL_msgs_all_info::constructor != constructor) { |
| 453 | error = true; |
| 454 | DEBUG_E("can't parse magic %x in TL_msgs_all_info", constructor); |
| 455 | return nullptr; |
| 456 | } |
| 457 | TL_msgs_all_info *result = new TL_msgs_all_info(); |
| 458 | result->readParams(stream, error); |
| 459 | return result; |
| 460 | } |
| 461 |
| 462 | void TL_msgs_all_info::readParams(NativeByteBuffer *stream, bool &error) { |
| 463 | uint32_t magic = stream->readUint32(&error); |
| 464 | if (magic != 0x1cb5c415) { |
| 465 | error = true; |
| 466 | DEBUG_E("wrong Vector magic, got %x", magic); |
| 467 | return; |
| 468 | } |
| 469 | uint32_t count = stream->readUint32(&error); |
| 470 | if (count * sizeof(int64_t) + stream->position() > stream->limit()) { |
| 471 | error = true; |
| 472 | return; |
| 473 | } |
| 474 | for (uint32_t a = 0; a < count; a++) { |
| 475 | msg_ids.push_back(stream->readInt64(&error)); |
| 476 | } |
| 477 | info = std::unique_ptr<ByteArray>(stream->readByteArray(&error)); |
| 478 | } |
| 479 |
| 480 | void TL_rpc_result::readParamsEx(NativeByteBuffer *stream, uint32_t bytes, bool &error) { |
| 481 | req_msg_id = stream->readInt64(&error); |
| 482 | TLObject *object = ConnectionsManager::getInstance().TLdeserialize(ConnectionsManager::getInstance().getRequestWithMessageId(req_msg_id), bytes - 12, stream); |
| 483 | if (object != nullptr) { |
| 484 | result = std::unique_ptr<TLObject>(object); |
| 485 | } else { |
| 486 | error = true; |
| 487 | } |
| 488 | } |
| 489 |
| 490 | void TL_new_session_created::readParams(NativeByteBuffer *stream, bool &error) { |
| 491 | first_msg_id = stream->readInt64(&error); |
| 492 | unique_id = stream->readInt64(&error); |
| 493 | server_salt = stream->readInt64(&error); |
| 494 | } |
| 495 |
| 496 | DestroySessionRes *DestroySessionRes::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 497 | DestroySessionRes *result = nullptr; |
| 498 | switch (constructor) { |
| 499 | case 0xe22045fc: |
| 500 | result = new TL_destroy_session_ok(); |
| 501 | break; |
| 502 | case 0x62d350c9: |
| 503 | result = new TL_destroy_session_none(); |
| 504 | break; |
| 505 | default: |
| 506 | error = true; |
| 507 | DEBUG_E("can't parse magic %x in DestroySessionRes", constructor); |
| 508 | return nullptr; |
| 509 | } |
| 510 | result->readParams(stream, error); |
| 511 | return result; |
| 512 | } |
| 513 |
| 514 | void TL_destroy_session_ok::readParams(NativeByteBuffer *stream, bool &error) { |
| 515 | session_id = stream->readInt64(&error); |
| 516 | } |
| 517 |
| 518 | void TL_destroy_session_none::readParams(NativeByteBuffer *stream, bool &error) { |
| 519 | session_id = stream->readInt64(&error); |
| 520 | } |
| 521 |
| 522 | TL_msgs_ack *TL_msgs_ack::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 523 | if (TL_msgs_ack::constructor != constructor) { |
| 524 | error = true; |
| 525 | DEBUG_E("can't parse magic %x in TL_msgs_ack", constructor); |
| 526 | return nullptr; |
| 527 | } |
| 528 | TL_msgs_ack *result = new TL_msgs_ack(); |
| 529 | result->readParams(stream, error); |
| 530 | return result; |
| 531 | } |
| 532 |
| 533 | void TL_msgs_ack::readParams(NativeByteBuffer *stream, bool &error) { |
| 534 | uint32_t magic = stream->readUint32(&error); |
| 535 | if (magic != 0x1cb5c415) { |
| 536 | error = true; |
| 537 | DEBUG_E("wrong Vector magic, got %x", magic); |
| 538 | return; |
| 539 | } |
| 540 | uint32_t count = stream->readUint32(&error); |
| 541 | if (count * sizeof(int64_t) + stream->position() > stream->limit()) { |
| 542 | error = true; |
| 543 | return; |
| 544 | } |
| 545 | for (uint32_t a = 0; a < count; a++) { |
| 546 | msg_ids.push_back(stream->readInt64(&error)); |
| 547 | } |
| 548 | } |
| 549 |
| 550 | void TL_msgs_ack::serializeToStream(NativeByteBuffer *stream) { |
| 551 | stream->writeInt32(constructor); |
| 552 | stream->writeInt32(0x1cb5c415); |
| 553 | uint32_t count = (uint32_t) msg_ids.size(); |
| 554 | stream->writeInt32(count); |
| 555 | for (uint32_t a = 0; a < count; a++) { |
| 556 | stream->writeInt64(msg_ids[a]); |
| 557 | } |
| 558 | } |
| 559 |
| 560 | TL_msg_container *TL_msg_container::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 561 | if (TL_msg_container::constructor != constructor) { |
| 562 | error = true; |
| 563 | DEBUG_E("can't parse magic %x in TL_msg_container", constructor); |
| 564 | return nullptr; |
| 565 | } |
| 566 | TL_msg_container *result = new TL_msg_container(); |
| 567 | result->readParams(stream, error); |
| 568 | return result; |
| 569 | } |
| 570 |
| 571 | void TL_msg_container::readParams(NativeByteBuffer *stream, bool &error) { |
| 572 | uint32_t count = stream->readUint32(&error); |
| 573 | for (uint32_t a = 0; a < count; a++) { |
| 574 | TL_message *object = new TL_message(); |
| 575 | object->readParams(stream, error); |
| 576 | if (error) { |
| 577 | return; |
| 578 | } |
| 579 | messages.push_back(std::unique_ptr<TL_message>(object)); |
| 580 | } |
| 581 | } |
| 582 |
| 583 | void TL_msg_container::serializeToStream(NativeByteBuffer *stream) { |
| 584 | stream->writeInt32(constructor); |
| 585 | uint32_t count = (uint32_t) messages.size(); |
| 586 | stream->writeInt32(count); |
| 587 | for (uint32_t a = 0; a < count; a++) { |
| 588 | messages[a]->serializeToStream(stream); |
| 589 | } |
| 590 | } |
| 591 |
| 592 | TL_message *TL_message::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 593 | if (TL_message::constructor != constructor) { |
| 594 | error = true; |
| 595 | DEBUG_E("can't parse magic %x in TL_message", constructor); |
| 596 | return nullptr; |
| 597 | } |
| 598 | TL_message *result = new TL_message(); |
| 599 | result->readParams(stream, error); |
| 600 | return result; |
| 601 | } |
| 602 |
| 603 | void TL_message::readParams(NativeByteBuffer *stream, bool &error) { |
| 604 | msg_id = stream->readInt64(&error); |
| 605 | seqno = stream->readInt32(&error); |
| 606 | bytes = stream->readInt32(&error); |
| 607 | TLObject *object = ConnectionsManager::getInstance().TLdeserialize(nullptr, (uint32_t) bytes, stream); |
| 608 | if (object == nullptr) { |
| 609 | unparsedBody = std::unique_ptr<NativeByteBuffer>(new NativeByteBuffer(stream->bytes() + stream->position(), (uint32_t) bytes)); |
| 610 | stream->skip((uint32_t) bytes); |
| 611 | } else { |
| 612 | body = std::unique_ptr<TLObject>(object); |
| 613 | } |
| 614 | } |
| 615 |
| 616 | void TL_message::serializeToStream(NativeByteBuffer *stream) { |
| 617 | stream->writeInt64(msg_id); |
| 618 | stream->writeInt32(seqno); |
| 619 | stream->writeInt32(bytes); |
| 620 | if (outgoingBody != nullptr) { |
| 621 | outgoingBody->serializeToStream(stream); |
| 622 | } else { |
| 623 | body->serializeToStream(stream); |
| 624 | } |
| 625 | } |
| 626 |
| 627 | TL_msg_resend_req *TL_msg_resend_req::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 628 | if (TL_msg_resend_req::constructor != constructor) { |
| 629 | error = true; |
| 630 | DEBUG_E("can't parse magic %x in TL_msg_resend_req", constructor); |
| 631 | return nullptr; |
| 632 | } |
| 633 | TL_msg_resend_req *result = new TL_msg_resend_req(); |
| 634 | result->readParams(stream, error); |
| 635 | return result; |
| 636 | } |
| 637 |
| 638 | void TL_msg_resend_req::readParams(NativeByteBuffer *stream, bool &error) { |
| 639 | uint32_t magic = stream->readUint32(&error); |
| 640 | if (magic != 0x1cb5c415) { |
| 641 | error = true; |
| 642 | DEBUG_E("wrong Vector magic, got %x", magic); |
| 643 | return; |
| 644 | } |
| 645 | uint32_t count = stream->readUint32(&error); |
| 646 | if (count * sizeof(int64_t) + stream->position() > stream->limit()) { |
| 647 | error = true; |
| 648 | return; |
| 649 | } |
| 650 | for (uint32_t a = 0; a < count; a++) { |
| 651 | msg_ids.push_back(stream->readInt64(&error)); |
| 652 | } |
| 653 | } |
| 654 |
| 655 | void TL_msg_resend_req::serializeToStream(NativeByteBuffer *stream) { |
| 656 | stream->writeInt32(constructor); |
| 657 | stream->writeInt32(0x1cb5c415); |
| 658 | uint32_t count = (uint32_t) msg_ids.size(); |
| 659 | stream->writeInt32(count); |
| 660 | for (uint32_t a = 0; a < count; a++) { |
| 661 | stream->writeInt64(msg_ids[a]); |
| 662 | } |
| 663 | } |
| 664 |
| 665 | void TL_rpc_error::readParams(NativeByteBuffer *stream, bool &error) { |
| 666 | error_code = stream->readInt32(&error); |
| 667 | error_message = stream->readString(&error); |
| 668 | } |
| 669 |
| 670 | void TL_rpc_req_error::readParams(NativeByteBuffer *stream, bool &error) { |
| 671 | query_id = stream->readInt64(&error); |
| 672 | error_code = stream->readInt32(&error); |
| 673 | error_message = stream->readString(&error); |
| 674 | } |
| 675 |
| 676 | void TL_client_DH_inner_data::serializeToStream(NativeByteBuffer *stream) { |
| 677 | stream->writeInt32(constructor); |
| 678 | stream->writeBytes(nonce.get()); |
| 679 | stream->writeBytes(server_nonce.get()); |
| 680 | stream->writeInt64(retry_id); |
| 681 | stream->writeByteArray(g_b.get()); |
| 682 | } |
| 683 |
| 684 | TL_server_DH_inner_data *TL_server_DH_inner_data::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 685 | if (TL_server_DH_inner_data::constructor != constructor) { |
| 686 | error = true; |
| 687 | DEBUG_E("can't parse magic %x in TL_server_DH_inner_data", constructor); |
| 688 | return nullptr; |
| 689 | } |
| 690 | TL_server_DH_inner_data *result = new TL_server_DH_inner_data(); |
| 691 | result->readParams(stream, error); |
| 692 | return result; |
| 693 | } |
| 694 |
| 695 | void TL_server_DH_inner_data::readParams(NativeByteBuffer *stream, bool &error) { |
| 696 | nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error)); |
| 697 | server_nonce = std::unique_ptr<ByteArray>(stream->readBytes(16, &error)); |
| 698 | g = stream->readUint32(&error); |
| 699 | dh_prime = std::unique_ptr<ByteArray>(stream->readByteArray(&error)); |
| 700 | g_a = std::unique_ptr<ByteArray>(stream->readByteArray(&error)); |
| 701 | server_time = stream->readInt32(&error); |
| 702 | } |
| 703 |
| 704 | void TL_server_DH_inner_data::serializeToStream(NativeByteBuffer *stream) { |
| 705 | stream->writeInt32(constructor); |
| 706 | stream->writeBytes(nonce.get()); |
| 707 | stream->writeBytes(server_nonce.get()); |
| 708 | stream->writeInt32(g); |
| 709 | stream->writeByteArray(dh_prime.get()); |
| 710 | stream->writeByteArray(g_a.get()); |
| 711 | stream->writeInt32(server_time); |
| 712 | } |
| 713 |
| 714 | TLObject *TL_req_pq::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 715 | return TL_resPQ::TLdeserialize(stream, constructor, error); |
| 716 | } |
| 717 |
| 718 | void TL_req_pq::serializeToStream(NativeByteBuffer *stream) { |
| 719 | stream->writeInt32(constructor); |
| 720 | stream->writeBytes(nonce.get()); |
| 721 | } |
| 722 |
| 723 | TLObject *TL_req_DH_params::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 724 | return Server_DH_Params::TLdeserialize(stream, constructor, error); |
| 725 | } |
| 726 |
| 727 | void TL_req_DH_params::serializeToStream(NativeByteBuffer *stream) { |
| 728 | stream->writeInt32(constructor); |
| 729 | stream->writeBytes(nonce.get()); |
| 730 | stream->writeBytes(server_nonce.get()); |
| 731 | stream->writeByteArray(p.get()); |
| 732 | stream->writeByteArray(q.get()); |
| 733 | stream->writeInt64(public_key_fingerprint); |
| 734 | stream->writeByteArray(encrypted_data.get()); |
| 735 | } |
| 736 |
| 737 | TLObject *TL_set_client_DH_params::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 738 | return Set_client_DH_params_answer::TLdeserialize(stream, constructor, error); |
| 739 | } |
| 740 |
| 741 | void TL_set_client_DH_params::serializeToStream(NativeByteBuffer *stream) { |
| 742 | stream->writeInt32(constructor); |
| 743 | stream->writeBytes(nonce.get()); |
| 744 | stream->writeBytes(server_nonce.get()); |
| 745 | stream->writeByteArray(encrypted_data.get()); |
| 746 | } |
| 747 |
| 748 | TLObject *TL_rpc_drop_answer::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 749 | return RpcDropAnswer::TLdeserialize(stream, constructor, error); |
| 750 | } |
| 751 |
| 752 | void TL_rpc_drop_answer::serializeToStream(NativeByteBuffer *stream) { |
| 753 | stream->writeInt32(constructor); |
| 754 | stream->writeInt64(req_msg_id); |
| 755 | } |
| 756 |
| 757 | TLObject *TL_get_future_salts::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 758 | return TL_future_salts::TLdeserialize(stream, constructor, error); |
| 759 | } |
| 760 |
| 761 | void TL_get_future_salts::serializeToStream(NativeByteBuffer *stream) { |
| 762 | stream->writeInt32(constructor); |
| 763 | stream->writeInt32(num); |
| 764 | } |
| 765 |
| 766 | TLObject *TL_ping::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 767 | return TL_pong::TLdeserialize(stream, constructor, error); |
| 768 | } |
| 769 |
| 770 | void TL_ping::serializeToStream(NativeByteBuffer *stream) { |
| 771 | stream->writeInt32(constructor); |
| 772 | stream->writeInt64(ping_id); |
| 773 | } |
| 774 |
| 775 | TLObject *TL_ping_delay_disconnect::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 776 | return TL_pong::TLdeserialize(stream, constructor, error); |
| 777 | } |
| 778 |
| 779 | void TL_ping_delay_disconnect::serializeToStream(NativeByteBuffer *stream) { |
| 780 | stream->writeInt32(constructor); |
| 781 | stream->writeInt64(ping_id); |
| 782 | stream->writeInt32(disconnect_delay); |
| 783 | } |
| 784 |
| 785 | TLObject *TL_destroy_session::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 786 | return DestroySessionRes::TLdeserialize(stream, constructor, error); |
| 787 | } |
| 788 |
| 789 | void TL_destroy_session::serializeToStream(NativeByteBuffer *stream) { |
| 790 | stream->writeInt32(constructor); |
| 791 | stream->writeInt64(session_id); |
| 792 | } |
| 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 |
| 801 | void TL_gzip_packed::readParams(NativeByteBuffer *stream, bool &error) { |
| 802 | packed_data = std::unique_ptr<NativeByteBuffer>(stream->readByteBuffer(false, &error)); |
| 803 | } |
| 804 |
| 805 | void TL_gzip_packed::serializeToStream(NativeByteBuffer *stream) { |
| 806 | stream->writeInt32(constructor); |
| 807 | stream->writeByteArray(packed_data_to_send); |
| 808 | } |
| 809 |
| 810 | TL_error *TL_error::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 811 | if (TL_error::constructor != constructor) { |
| 812 | error = true; |
| 813 | DEBUG_E("can't parse magic %x in TL_error", constructor); |
| 814 | return nullptr; |
| 815 | } |
| 816 | TL_error *result = new TL_error(); |
| 817 | result->readParams(stream, error); |
| 818 | return result; |
| 819 | } |
| 820 |
| 821 | void TL_error::readParams(NativeByteBuffer *stream, bool &error) { |
| 822 | code = stream->readInt32(&error); |
| 823 | text = stream->readString(&error); |
| 824 | } |
| 825 |
| 826 | void TL_error::serializeToStream(NativeByteBuffer *stream) { |
| 827 | stream->writeInt32(constructor); |
| 828 | stream->writeInt32(code); |
| 829 | stream->writeString(text); |
| 830 | } |
| 831 |
| 832 | void TL_invokeAfterMsg::serializeToStream(NativeByteBuffer *stream) { |
| 833 | stream->writeInt32(constructor); |
| 834 | stream->writeInt64(msg_id); |
| 835 | if (outgoingQuery != nullptr) { |
| 836 | outgoingQuery->serializeToStream(stream); |
| 837 | } else { |
| 838 | query->serializeToStream(stream); |
| 839 | } |
| 840 | } |
| 841 |
| 842 | void invokeWithLayer::serializeToStream(NativeByteBuffer *stream) { |
| 843 | stream->writeInt32(constructor); |
| 844 | stream->writeInt32(layer); |
| 845 | query->serializeToStream(stream); |
| 846 | } |
| 847 |
| 848 | void initConnection::serializeToStream(NativeByteBuffer *stream) { |
| 849 | stream->writeInt32(constructor); |
| 850 | stream->writeInt32(api_id); |
| 851 | stream->writeString(device_model); |
| 852 | stream->writeString(system_version); |
| 853 | stream->writeString(app_version); |
| 854 | stream->writeString(lang_code); |
| 855 | query->serializeToStream(stream); |
| 856 | } |
| 857 |
| 858 | TL_dcOption *TL_dcOption::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 859 | if (TL_dcOption::constructor != constructor) { |
| 860 | error = true; |
| 861 | DEBUG_E("can't parse magic %x in TL_dcOption", constructor); |
| 862 | return nullptr; |
| 863 | } |
| 864 | TL_dcOption *result = new TL_dcOption(); |
| 865 | result->readParams(stream, error); |
| 866 | return result; |
| 867 | } |
| 868 |
| 869 | void TL_dcOption::readParams(NativeByteBuffer *stream, bool &error) { |
| 870 | flags = stream->readInt32(&error); |
| 871 | id = stream->readInt32(&error); |
| 872 | ip_address = stream->readString(&error); |
| 873 | port = stream->readInt32(&error); |
| 874 | } |
| 875 |
| 876 | void TL_dcOption::serializeToStream(NativeByteBuffer *stream) { |
| 877 | stream->writeInt32(constructor); |
| 878 | stream->writeInt32(flags); |
| 879 | stream->writeInt32(id); |
| 880 | stream->writeString(ip_address); |
| 881 | stream->writeInt32(port); |
| 882 | } |
| 883 |
| 884 | TL_disabledFeature *TL_disabledFeature::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 885 | if (TL_disabledFeature::constructor != constructor) { |
| 886 | error = true; |
| 887 | DEBUG_E("can't parse magic %x in TL_disabledFeature", constructor); |
| 888 | return nullptr; |
| 889 | } |
| 890 | TL_disabledFeature *result = new TL_disabledFeature(); |
| 891 | result->readParams(stream, error); |
| 892 | return result; |
| 893 | } |
| 894 |
| 895 | void TL_disabledFeature::readParams(NativeByteBuffer *stream, bool &error) { |
| 896 | feature = stream->readString(&error); |
| 897 | description = stream->readString(&error); |
| 898 | } |
| 899 |
| 900 | void TL_disabledFeature::serializeToStream(NativeByteBuffer *stream) { |
| 901 | stream->writeInt32(constructor); |
| 902 | stream->writeString(feature); |
| 903 | stream->writeString(description); |
| 904 | } |
| 905 |
| 906 | TL_config *TL_config::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 907 | if (TL_config::constructor != constructor) { |
| 908 | error = true; |
| 909 | DEBUG_E("can't parse magic %x in TL_config", constructor); |
| 910 | return nullptr; |
| 911 | } |
| 912 | TL_config *result = new TL_config(); |
| 913 | result->readParams(stream, error); |
| 914 | return result; |
| 915 | } |
| 916 |
| 917 | void TL_config::readParams(NativeByteBuffer *stream, bool &error) { |
| 918 | date = stream->readInt32(&error); |
| 919 | expires = stream->readInt32(&error); |
| 920 | test_mode = stream->readBool(&error); |
| 921 | this_dc = stream->readInt32(&error); |
| 922 | uint32_t magic = stream->readUint32(&error); |
| 923 | if (magic != 0x1cb5c415) { |
| 924 | error = true; |
| 925 | DEBUG_E("wrong Vector magic, got %x", magic); |
| 926 | return; |
| 927 | } |
| 928 | int32_t count = stream->readInt32(&error); |
| 929 | for (int32_t a = 0; a < count; a++) { |
| 930 | TL_dcOption *object = TL_dcOption::TLdeserialize(stream, stream->readUint32(&error), error); |
| 931 | if (object == nullptr) { |
| 932 | return; |
| 933 | } |
| 934 | dc_options.push_back(std::unique_ptr<TL_dcOption>(object)); |
| 935 | } |
| 936 | chat_size_max = stream->readInt32(&error); |
| 937 | megagroup_size_max = stream->readInt32(&error); |
| 938 | forwarded_count_max = stream->readInt32(&error); |
| 939 | online_update_period_ms = stream->readInt32(&error); |
| 940 | offline_blur_timeout_ms = stream->readInt32(&error); |
| 941 | offline_idle_timeout_ms = stream->readInt32(&error); |
| 942 | online_cloud_timeout_ms = stream->readInt32(&error); |
| 943 | notify_cloud_delay_ms = stream->readInt32(&error); |
| 944 | notify_default_delay_ms = stream->readInt32(&error); |
| 945 | chat_big_size = stream->readInt32(&error); |
| 946 | push_chat_period_ms = stream->readInt32(&error); |
| 947 | push_chat_limit = stream->readInt32(&error); |
| 948 | saved_gifs_limit = stream->readInt32(&error); |
| 949 | edit_time_limit = stream->readInt32(&error); |
| 950 | magic = stream->readUint32(&error); |
| 951 | if (magic != 0x1cb5c415) { |
| 952 | error = true; |
| 953 | DEBUG_E("wrong Vector magic, got %x", magic); |
| 954 | return; |
| 955 | } |
| 956 | count = stream->readInt32(&error); |
| 957 | for (int32_t a = 0; a < count; a++) { |
| 958 | TL_disabledFeature *object = TL_disabledFeature::TLdeserialize(stream, stream->readUint32(&error), error); |
| 959 | if (object == nullptr) { |
| 960 | return; |
| 961 | } |
| 962 | disabled_features.push_back(std::unique_ptr<TL_disabledFeature>(object)); |
| 963 | } |
| 964 | } |
| 965 |
| 966 | void TL_config::serializeToStream(NativeByteBuffer *stream) { |
| 967 | stream->writeInt32(constructor); |
| 968 | stream->writeInt32(date); |
| 969 | stream->writeInt32(expires); |
| 970 | stream->writeBool(test_mode); |
| 971 | stream->writeInt32(this_dc); |
| 972 | stream->writeInt32(0x1cb5c415); |
| 973 | uint32_t count = (uint32_t) dc_options.size(); |
| 974 | stream->writeInt32(count); |
| 975 | for (uint32_t a = 0; a < count; a++) { |
| 976 | dc_options[a]->serializeToStream(stream); |
| 977 | } |
| 978 | stream->writeInt32(chat_size_max); |
| 979 | stream->writeInt32(megagroup_size_max); |
| 980 | stream->writeInt32(forwarded_count_max); |
| 981 | stream->writeInt32(online_update_period_ms); |
| 982 | stream->writeInt32(offline_blur_timeout_ms); |
| 983 | stream->writeInt32(offline_idle_timeout_ms); |
| 984 | stream->writeInt32(online_cloud_timeout_ms); |
| 985 | stream->writeInt32(notify_cloud_delay_ms); |
| 986 | stream->writeInt32(notify_default_delay_ms); |
| 987 | stream->writeInt32(chat_big_size); |
| 988 | stream->writeInt32(push_chat_period_ms); |
| 989 | stream->writeInt32(push_chat_limit); |
| 990 | stream->writeInt32(saved_gifs_limit); |
| 991 | stream->writeInt32(edit_time_limit); |
| 992 | stream->writeInt32(0x1cb5c415); |
| 993 | count = (uint32_t) disabled_features.size(); |
| 994 | stream->writeInt32(count); |
| 995 | for (uint32_t a = 0; a < count; a++) { |
| 996 | disabled_features[a]->serializeToStream(stream); |
| 997 | } |
| 998 | } |
| 999 |
| 1000 | TLObject *TL_help_getConfig::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 1001 | return TL_config::TLdeserialize(stream, constructor, error); |
| 1002 | } |
| 1003 |
| 1004 | void TL_help_getConfig::serializeToStream(NativeByteBuffer *stream) { |
| 1005 | stream->writeInt32(constructor); |
| 1006 | } |
| 1007 |
| 1008 | bool TL_help_getConfig::isNeedLayer() { |
| 1009 | return true; |
| 1010 | } |
| 1011 |
| 1012 | Bool *Bool::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 1013 | Bool *result = nullptr; |
| 1014 | switch (constructor) { |
| 1015 | case 0x997275b5: |
| 1016 | result = new TL_boolTrue(); |
| 1017 | break; |
| 1018 | case 0xbc799737: |
| 1019 | result = new TL_boolFalse(); |
| 1020 | break; |
| 1021 | default: |
| 1022 | error = true; |
| 1023 | DEBUG_E("can't parse magic %x in Bool", constructor); |
| 1024 | return nullptr; |
| 1025 | } |
| 1026 | result->readParams(stream, error); |
| 1027 | return result; |
| 1028 | } |
| 1029 |
| 1030 | void TL_boolTrue::serializeToStream(NativeByteBuffer *stream) { |
| 1031 | stream->writeInt32(constructor); |
| 1032 | } |
| 1033 |
| 1034 | void TL_boolFalse::serializeToStream(NativeByteBuffer *stream) { |
| 1035 | stream->writeInt32(constructor); |
| 1036 | } |
| 1037 |
| 1038 | bool TL_account_registerDevice::isNeedLayer() { |
| 1039 | return true; |
| 1040 | } |
| 1041 |
| 1042 | TLObject *TL_account_registerDevice::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 1043 | return Bool::TLdeserialize(stream, constructor, error); |
| 1044 | } |
| 1045 |
| 1046 | void TL_account_registerDevice::serializeToStream(NativeByteBuffer *stream) { |
| 1047 | stream->writeInt32(constructor); |
| 1048 | stream->writeInt32(token_type); |
| 1049 | stream->writeString(token); |
| 1050 | stream->writeString(device_model); |
| 1051 | stream->writeString(system_version); |
| 1052 | stream->writeString(app_version); |
| 1053 | stream->writeBool(app_sandbox); |
| 1054 | stream->writeString(lang_code); |
| 1055 | } |
| 1056 |
| 1057 | User *User::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 1058 | User *result = nullptr; |
| 1059 | switch (constructor) { |
| 1060 | case 0x200250ba: |
| 1061 | result = new TL_userEmpty(); |
| 1062 | break; |
| 1063 | case 0xd10d979a: |
| 1064 | result = new TL_user(); |
| 1065 | break; |
| 1066 | default: |
| 1067 | error = true; |
| 1068 | DEBUG_E("can't parse magic %x in User", constructor); |
| 1069 | return nullptr; |
| 1070 | } |
| 1071 | result->readParams(stream, error); |
| 1072 | return result; |
| 1073 | } |
| 1074 |
| 1075 | void TL_userEmpty::readParams(NativeByteBuffer *stream, bool &error) { |
| 1076 | id = stream->readInt32(&error); |
| 1077 | } |
| 1078 |
| 1079 | void TL_userEmpty::serializeToStream(NativeByteBuffer *stream) { |
| 1080 | stream->writeInt32(constructor); |
| 1081 | stream->writeInt32(id); |
| 1082 | } |
| 1083 |
| 1084 | void TL_user::readParams(NativeByteBuffer *stream, bool &error) { |
| 1085 | flags = stream->readInt32(&error); |
| 1086 | id = stream->readInt32(&error); |
| 1087 | if ((flags & 1) != 0) { |
| 1088 | access_hash = stream->readInt64(&error); |
| 1089 | } |
| 1090 | if ((flags & 2) != 0) { |
| 1091 | first_name = stream->readString(&error); |
| 1092 | } |
| 1093 | if ((flags & 4) != 0) { |
| 1094 | last_name = stream->readString(&error); |
| 1095 | } |
| 1096 | if ((flags & 8) != 0) { |
| 1097 | username = stream->readString(&error); |
| 1098 | } |
| 1099 | if ((flags & 16) != 0) { |
| 1100 | phone = stream->readString(&error); |
| 1101 | } |
| 1102 | if ((flags & 32) != 0) { |
| 1103 | photo = std::unique_ptr<UserProfilePhoto>(UserProfilePhoto::TLdeserialize(stream, stream->readUint32(&error), error)); |
| 1104 | } |
| 1105 | if ((flags & 64) != 0) { |
| 1106 | status = std::unique_ptr<UserStatus>(UserStatus::TLdeserialize(stream, stream->readUint32(&error), error)); |
| 1107 | } |
| 1108 | if ((flags & 16384) != 0) { |
| 1109 | bot_info_version = stream->readInt32(&error); |
| 1110 | } |
| 1111 | if ((flags & 262144) != 0) { |
| 1112 | restriction_reason = stream->readString(&error); |
| 1113 | } |
| 1114 | if ((flags & 524288) != 0) { |
| 1115 | bot_inline_placeholder = stream->readString(&error); |
| 1116 | } |
| 1117 | } |
| 1118 |
| 1119 | void TL_user::serializeToStream(NativeByteBuffer *stream) { |
| 1120 | stream->writeInt32(constructor); |
| 1121 | stream->writeInt32(flags); |
| 1122 | stream->writeInt32(id); |
| 1123 | if ((flags & 1) != 0) { |
| 1124 | stream->writeInt64(access_hash); |
| 1125 | } |
| 1126 | if ((flags & 2) != 0) { |
| 1127 | stream->writeString(first_name); |
| 1128 | } |
| 1129 | if ((flags & 4) != 0) { |
| 1130 | stream->writeString(last_name); |
| 1131 | } |
| 1132 | if ((flags & 8) != 0) { |
| 1133 | stream->writeString(username); |
| 1134 | } |
| 1135 | if ((flags & 16) != 0) { |
| 1136 | stream->writeString(phone); |
| 1137 | } |
| 1138 | if ((flags & 32) != 0) { |
| 1139 | photo->serializeToStream(stream); |
| 1140 | } |
| 1141 | if ((flags & 64) != 0) { |
| 1142 | status->serializeToStream(stream); |
| 1143 | } |
| 1144 | if ((flags & 16384) != 0) { |
| 1145 | stream->writeInt32(bot_info_version); |
| 1146 | } |
| 1147 | if ((flags & 262144) != 0) { |
| 1148 | stream->writeString(restriction_reason); |
| 1149 | } |
| 1150 | if ((flags & 524288) != 0) { |
| 1151 | stream->writeString(bot_inline_placeholder); |
| 1152 | } |
| 1153 | } |
| 1154 |
| 1155 | TL_auth_authorization *TL_auth_authorization::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 1156 | if (TL_auth_authorization::constructor != constructor) { |
| 1157 | error = true; |
| 1158 | DEBUG_E("can't parse magic %x in TL_auth_authorization", constructor); |
| 1159 | return nullptr; |
| 1160 | } |
| 1161 | TL_auth_authorization *result = new TL_auth_authorization(); |
| 1162 | result->readParams(stream, error); |
| 1163 | return result; |
| 1164 | } |
| 1165 |
| 1166 | void TL_auth_authorization::readParams(NativeByteBuffer *stream, bool &error) { |
| 1167 | user = std::unique_ptr<User>(User::TLdeserialize(stream, stream->readUint32(&error), error)); |
| 1168 | } |
| 1169 |
| 1170 | TL_auth_exportedAuthorization *TL_auth_exportedAuthorization::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 1171 | if (TL_auth_exportedAuthorization::constructor != constructor) { |
| 1172 | error = true; |
| 1173 | DEBUG_E("can't parse magic %x in TL_auth_exportedAuthorization", constructor); |
| 1174 | return nullptr; |
| 1175 | } |
| 1176 | TL_auth_exportedAuthorization *result = new TL_auth_exportedAuthorization(); |
| 1177 | result->readParams(stream, error); |
| 1178 | return result; |
| 1179 | } |
| 1180 |
| 1181 | void TL_auth_exportedAuthorization::readParams(NativeByteBuffer *stream, bool &error) { |
| 1182 | id = stream->readInt32(&error); |
| 1183 | bytes = std::unique_ptr<ByteArray>(stream->readByteArray(&error)); |
| 1184 | } |
| 1185 |
| 1186 | bool TL_auth_exportAuthorization::isNeedLayer() { |
| 1187 | return true; |
| 1188 | } |
| 1189 |
| 1190 | TLObject *TL_auth_exportAuthorization::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 1191 | return TL_auth_exportedAuthorization::TLdeserialize(stream, constructor, error); |
| 1192 | } |
| 1193 |
| 1194 | void TL_auth_exportAuthorization::serializeToStream(NativeByteBuffer *stream) { |
| 1195 | stream->writeInt32(constructor); |
| 1196 | stream->writeInt32(dc_id); |
| 1197 | } |
| 1198 |
| 1199 | bool TL_auth_importAuthorization::isNeedLayer() { |
| 1200 | return true; |
| 1201 | } |
| 1202 |
| 1203 | TLObject *TL_auth_importAuthorization::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 1204 | return TL_auth_authorization::TLdeserialize(stream, constructor, error); |
| 1205 | } |
| 1206 |
| 1207 | void TL_auth_importAuthorization::serializeToStream(NativeByteBuffer *stream) { |
| 1208 | stream->writeInt32(constructor); |
| 1209 | stream->writeInt32(id); |
| 1210 | stream->writeByteArray(bytes.get()); |
| 1211 | } |
| 1212 |
| 1213 | UserStatus *UserStatus::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 1214 | UserStatus *result = nullptr; |
| 1215 | switch (constructor) { |
| 1216 | case 0x8c703f: |
| 1217 | result = new TL_userStatusOffline(); |
| 1218 | break; |
| 1219 | case 0x7bf09fc: |
| 1220 | result = new TL_userStatusLastWeek(); |
| 1221 | break; |
| 1222 | case 0x9d05049: |
| 1223 | result = new TL_userStatusEmpty(); |
| 1224 | break; |
| 1225 | case 0x77ebc742: |
| 1226 | result = new TL_userStatusLastMonth(); |
| 1227 | break; |
| 1228 | case 0xedb93949: |
| 1229 | result = new TL_userStatusOnline(); |
| 1230 | break; |
| 1231 | case 0xe26f42f1: |
| 1232 | result = new TL_userStatusRecently(); |
| 1233 | break; |
| 1234 | default: |
| 1235 | error = true; |
| 1236 | DEBUG_E("can't parse magic %x in UserStatus", constructor); |
| 1237 | return nullptr; |
| 1238 | } |
| 1239 | result->readParams(stream, error); |
| 1240 | return result; |
| 1241 | } |
| 1242 |
| 1243 | void TL_userStatusOffline::readParams(NativeByteBuffer *stream, bool &error) { |
| 1244 | expires = stream->readInt32(&error); |
| 1245 | } |
| 1246 |
| 1247 | void TL_userStatusOffline::serializeToStream(NativeByteBuffer *stream) { |
| 1248 | stream->writeInt32(constructor); |
| 1249 | stream->writeInt32(expires); |
| 1250 | } |
| 1251 |
| 1252 | void TL_userStatusLastWeek::serializeToStream(NativeByteBuffer *stream) { |
| 1253 | stream->writeInt32(constructor); |
| 1254 | } |
| 1255 |
| 1256 | void TL_userStatusEmpty::serializeToStream(NativeByteBuffer *stream) { |
| 1257 | stream->writeInt32(constructor); |
| 1258 | } |
| 1259 |
| 1260 | void TL_userStatusLastMonth::serializeToStream(NativeByteBuffer *stream) { |
| 1261 | stream->writeInt32(constructor); |
| 1262 | } |
| 1263 |
| 1264 | void TL_userStatusOnline::readParams(NativeByteBuffer *stream, bool &error) { |
| 1265 | expires = stream->readInt32(&error); |
| 1266 | } |
| 1267 |
| 1268 | void TL_userStatusOnline::serializeToStream(NativeByteBuffer *stream) { |
| 1269 | stream->writeInt32(constructor); |
| 1270 | stream->writeInt32(expires); |
| 1271 | } |
| 1272 |
| 1273 | void TL_userStatusRecently::serializeToStream(NativeByteBuffer *stream) { |
| 1274 | stream->writeInt32(constructor); |
| 1275 | } |
| 1276 |
| 1277 | FileLocation *FileLocation::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 1278 | FileLocation *result = nullptr; |
| 1279 | switch (constructor) { |
| 1280 | case 0x53d69076: |
| 1281 | result = new TL_fileLocation(); |
| 1282 | break; |
| 1283 | case 0x7c596b46: |
| 1284 | result = new TL_fileLocationUnavailable(); |
| 1285 | break; |
| 1286 | default: |
| 1287 | error = true; |
| 1288 | DEBUG_E("can't parse magic %x in FileLocation", constructor); |
| 1289 | return nullptr; |
| 1290 | } |
| 1291 | result->readParams(stream, error); |
| 1292 | return result; |
| 1293 | } |
| 1294 |
| 1295 | void TL_fileLocation::readParams(NativeByteBuffer *stream, bool &error) { |
| 1296 | dc_id = stream->readInt32(&error); |
| 1297 | volume_id = stream->readInt64(&error); |
| 1298 | local_id = stream->readInt32(&error); |
| 1299 | secret = stream->readInt64(&error); |
| 1300 | } |
| 1301 |
| 1302 | void TL_fileLocation::serializeToStream(NativeByteBuffer *stream) { |
| 1303 | stream->writeInt32(constructor); |
| 1304 | stream->writeInt32(dc_id); |
| 1305 | stream->writeInt64(volume_id); |
| 1306 | stream->writeInt32(local_id); |
| 1307 | stream->writeInt64(secret); |
| 1308 | } |
| 1309 |
| 1310 | void TL_fileLocationUnavailable::readParams(NativeByteBuffer *stream, bool &error) { |
| 1311 | volume_id = stream->readInt64(&error); |
| 1312 | local_id = stream->readInt32(&error); |
| 1313 | secret = stream->readInt64(&error); |
| 1314 | } |
| 1315 |
| 1316 | void TL_fileLocationUnavailable::serializeToStream(NativeByteBuffer *stream) { |
| 1317 | stream->writeInt32(constructor); |
| 1318 | stream->writeInt64(volume_id); |
| 1319 | stream->writeInt32(local_id); |
| 1320 | stream->writeInt64(secret); |
| 1321 | } |
| 1322 |
| 1323 | UserProfilePhoto *UserProfilePhoto::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 1324 | UserProfilePhoto *result = nullptr; |
| 1325 | switch (constructor) { |
| 1326 | case 0x4f11bae1: |
| 1327 | result = new TL_userProfilePhotoEmpty(); |
| 1328 | break; |
| 1329 | case 0xd559d8c8: |
| 1330 | result = new TL_userProfilePhoto(); |
| 1331 | break; |
| 1332 | default: |
| 1333 | error = true; |
| 1334 | DEBUG_E("can't parse magic %x in UserProfilePhoto", constructor); |
| 1335 | return nullptr; |
| 1336 | } |
| 1337 | result->readParams(stream, error); |
| 1338 | return result; |
| 1339 | } |
| 1340 |
| 1341 | void TL_userProfilePhotoEmpty::serializeToStream(NativeByteBuffer *stream) { |
| 1342 | stream->writeInt32(constructor); |
| 1343 | } |
| 1344 |
| 1345 | void TL_userProfilePhoto::readParams(NativeByteBuffer *stream, bool &error) { |
| 1346 | photo_id = stream->readInt64(&error); |
| 1347 | photo_small = std::unique_ptr<FileLocation>(FileLocation::TLdeserialize(stream, stream->readUint32(&error), error)); |
| 1348 | photo_big = std::unique_ptr<FileLocation>(FileLocation::TLdeserialize(stream, stream->readUint32(&error), error)); |
| 1349 | } |
| 1350 |
| 1351 | void TL_userProfilePhoto::serializeToStream(NativeByteBuffer *stream) { |
| 1352 | stream->writeInt32(constructor); |
| 1353 | stream->writeInt64(photo_id); |
| 1354 | photo_small->serializeToStream(stream); |
| 1355 | photo_big->serializeToStream(stream); |
| 1356 | } |
| 1357 |
| 1358 | auth_SentCode *auth_SentCode::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 1359 | auth_SentCode *result = nullptr; |
| 1360 | switch (constructor) { |
| 1361 | case 0xe325edcf: |
| 1362 | result = new TL_auth_sentAppCode(); |
| 1363 | break; |
| 1364 | case 0xefed51d9: |
| 1365 | result = new TL_auth_sentCode(); |
| 1366 | break; |
| 1367 | default: |
| 1368 | error = true; |
| 1369 | DEBUG_E("can't parse magic %x in auth_SentCode", constructor); |
| 1370 | return nullptr; |
| 1371 | } |
| 1372 | result->readParams(stream, error); |
| 1373 | return result; |
| 1374 | } |
| 1375 |
| 1376 | void TL_auth_sentAppCode::readParams(NativeByteBuffer *stream, bool &error) { |
| 1377 | phone_registered = stream->readBool(&error); |
| 1378 | phone_code_hash = stream->readString(&error); |
| 1379 | send_call_timeout = stream->readInt32(&error); |
| 1380 | is_password = stream->readBool(&error); |
| 1381 | } |
| 1382 |
| 1383 | void TL_auth_sentAppCode::serializeToStream(NativeByteBuffer *stream) { |
| 1384 | stream->writeInt32(constructor); |
| 1385 | stream->writeBool(phone_registered); |
| 1386 | stream->writeString(phone_code_hash); |
| 1387 | stream->writeInt32(send_call_timeout); |
| 1388 | stream->writeBool(is_password); |
| 1389 | } |
| 1390 |
| 1391 | void TL_auth_sentCode::readParams(NativeByteBuffer *stream, bool &error) { |
| 1392 | phone_registered = stream->readBool(&error); |
| 1393 | phone_code_hash = stream->readString(&error); |
| 1394 | send_call_timeout = stream->readInt32(&error); |
| 1395 | is_password = stream->readBool(&error); |
| 1396 | } |
| 1397 |
| 1398 | void TL_auth_sentCode::serializeToStream(NativeByteBuffer *stream) { |
| 1399 | stream->writeInt32(constructor); |
| 1400 | stream->writeBool(phone_registered); |
| 1401 | stream->writeString(phone_code_hash); |
| 1402 | stream->writeInt32(send_call_timeout); |
| 1403 | stream->writeBool(is_password); |
| 1404 | } |
| 1405 |
| 1406 | TLObject *TL_auth_sendCode::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 1407 | return auth_SentCode::TLdeserialize(stream, constructor, error); |
| 1408 | } |
| 1409 |
| 1410 | void TL_auth_sendCode::serializeToStream(NativeByteBuffer *stream) { |
| 1411 | stream->writeInt32(constructor); |
| 1412 | stream->writeString(phone_number); |
| 1413 | stream->writeInt32(sms_type); |
| 1414 | stream->writeInt32(api_id); |
| 1415 | stream->writeString(api_hash); |
| 1416 | stream->writeString(lang_code); |
| 1417 | } |
| 1418 |
| 1419 | void TL_updatesTooLong::serializeToStream(NativeByteBuffer *stream) { |
| 1420 | stream->writeInt32(constructor); |
| 1421 | } |
| 1422 |