| 6 |
| * Copyright Nikolai Kudashov, 2016. |
| 7 | */ |
| 8 |
| 9 | #include "ApiScheme.h" |
| 10 | #include "ByteArray.h" |
| 11 | #include "NativeByteBuffer.h" |
| 12 | #include "FileLog.h" |
| 13 |
| 14 | Bool *Bool::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 15 | Bool *result = nullptr; |
| 16 | switch (constructor) { |
| 17 | case 0x997275b5: |
| 18 | result = new TL_boolTrue(); |
| 19 | break; |
| 20 | case 0xbc799737: |
| 21 | result = new TL_boolFalse(); |
| 22 | break; |
| 23 | default: |
| 24 | error = true; |
| 25 | DEBUG_E("can't parse magic %x in Bool", constructor); |
| 26 | return nullptr; |
| 27 | } |
| 28 | result->readParams(stream, error); |
| 29 | return result; |
| 30 | } |
| 31 |
| 32 | void TL_boolTrue::serializeToStream(NativeByteBuffer *stream) { |
| 33 | stream->writeInt32(constructor); |
| 34 | } |
| 35 |
| 36 | void TL_boolFalse::serializeToStream(NativeByteBuffer *stream) { |
| 37 | stream->writeInt32(constructor); |
| 38 | } |
| 39 |
| 40 | TL_dcOption *TL_dcOption::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 41 | if (TL_dcOption::constructor != constructor) { |
| 42 | error = true; |
| 43 | DEBUG_E("can't parse magic %x in TL_dcOption", constructor); |
| 44 | return nullptr; |
| 45 | } |
| 46 | TL_dcOption *result = new TL_dcOption(); |
| 47 | result->readParams(stream, error); |
| 48 | return result; |
| 49 | } |
| 50 |
| 51 | void TL_dcOption::readParams(NativeByteBuffer *stream, bool &error) { |
| 52 | flags = stream->readInt32(&error); |
| 53 | id = stream->readInt32(&error); |
| 54 | ip_address = stream->readString(&error); |
| 55 | port = stream->readInt32(&error); |
| 56 | } |
| 57 |
| 58 | void TL_dcOption::serializeToStream(NativeByteBuffer *stream) { |
| 59 | stream->writeInt32(constructor); |
| 60 | stream->writeInt32(flags); |
| 61 | stream->writeInt32(id); |
| 62 | stream->writeString(ip_address); |
| 63 | stream->writeInt32(port); |
| 64 | } |
| 65 |
| 66 | TL_disabledFeature *TL_disabledFeature::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 67 | if (TL_disabledFeature::constructor != constructor) { |
| 68 | error = true; |
| 69 | DEBUG_E("can't parse magic %x in TL_disabledFeature", constructor); |
| 70 | return nullptr; |
| 71 | } |
| 72 | TL_disabledFeature *result = new TL_disabledFeature(); |
| 73 | result->readParams(stream, error); |
| 74 | return result; |
| 75 | } |
| 76 |
| 77 | void TL_disabledFeature::readParams(NativeByteBuffer *stream, bool &error) { |
| 78 | feature = stream->readString(&error); |
| 79 | description = stream->readString(&error); |
| 80 | } |
| 81 |
| 82 | void TL_disabledFeature::serializeToStream(NativeByteBuffer *stream) { |
| 83 | stream->writeInt32(constructor); |
| 84 | stream->writeString(feature); |
| 85 | stream->writeString(description); |
| 86 | } |
| 87 |
| 88 | TL_config *TL_config::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 89 | if (TL_config::constructor != constructor) { |
| 90 | error = true; |
| 91 | DEBUG_E("can't parse magic %x in TL_config", constructor); |
| 92 | return nullptr; |
| 93 | } |
| 94 | TL_config *result = new TL_config(); |
| 95 | result->readParams(stream, error); |
| 96 | return result; |
| 97 | } |
| 98 |
| 99 | void TL_config::readParams(NativeByteBuffer *stream, bool &error) { |
| 100 | flags = stream->readInt32(&error); |
| 101 | date = stream->readInt32(&error); |
| 102 | expires = stream->readInt32(&error); |
| 103 | test_mode = stream->readBool(&error); |
| 104 | this_dc = stream->readInt32(&error); |
| 105 | uint32_t magic = stream->readUint32(&error); |
| 106 | if (magic != 0x1cb5c415) { |
| 107 | error = true; |
| 108 | DEBUG_E("wrong Vector magic, got %x", magic); |
| 109 | return; |
| 110 | } |
| 111 | int32_t count = stream->readInt32(&error); |
| 112 | for (int32_t a = 0; a < count; a++) { |
| 113 | TL_dcOption *object = TL_dcOption::TLdeserialize(stream, stream->readUint32(&error), error); |
| 114 | if (object == nullptr) { |
| 115 | return; |
| 116 | } |
| 117 | dc_options.push_back(std::unique_ptr<TL_dcOption>(object)); |
| 118 | } |
| 119 | chat_size_max = stream->readInt32(&error); |
| 120 | megagroup_size_max = stream->readInt32(&error); |
| 121 | forwarded_count_max = stream->readInt32(&error); |
| 122 | online_update_period_ms = stream->readInt32(&error); |
| 123 | offline_blur_timeout_ms = stream->readInt32(&error); |
| 124 | offline_idle_timeout_ms = stream->readInt32(&error); |
| 125 | online_cloud_timeout_ms = stream->readInt32(&error); |
| 126 | notify_cloud_delay_ms = stream->readInt32(&error); |
| 127 | notify_default_delay_ms = stream->readInt32(&error); |
| 128 | chat_big_size = stream->readInt32(&error); |
| 129 | push_chat_period_ms = stream->readInt32(&error); |
| 130 | push_chat_limit = stream->readInt32(&error); |
| 131 | saved_gifs_limit = stream->readInt32(&error); |
| 132 | edit_time_limit = stream->readInt32(&error); |
| 133 | rating_e_decay = stream->readInt32(&error); |
| 134 | stickers_recent_limit = stream->readInt32(&error); |
| 135 | if ((flags & 1) != 0) { |
| 136 | tmp_sessions = stream->readInt32(&error); |
| 137 | } |
| 138 | pinned_dialogs_count_max = stream->readInt32(&error); |
| 139 | call_receive_timeout_ms = stream->readInt32(&error); |
| 140 | call_ring_timeout_ms = stream->readInt32(&error); |
| 141 | call_connect_timeout_ms = stream->readInt32(&error); |
| 142 | call_packet_timeout_ms = stream->readInt32(&error); |
| 143 | me_url_prefix = stream->readString(&error); |
| 144 | magic = stream->readUint32(&error); |
| 145 | if (magic != 0x1cb5c415) { |
| 146 | error = true; |
| 147 | DEBUG_E("wrong Vector magic, got %x", magic); |
| 148 | return; |
| 149 | } |
| 150 | count = stream->readInt32(&error); |
| 151 | for (int32_t a = 0; a < count; a++) { |
| 152 | TL_disabledFeature *object = TL_disabledFeature::TLdeserialize(stream, stream->readUint32(&error), error); |
| 153 | if (object == nullptr) { |
| 154 | return; |
| 155 | } |
| 156 | disabled_features.push_back(std::unique_ptr<TL_disabledFeature>(object)); |
| 157 | } |
| 158 | } |
| 159 |
| 160 | void TL_config::serializeToStream(NativeByteBuffer *stream) { |
| 161 | stream->writeInt32(constructor); |
| 162 | stream->writeInt32(flags); |
| 163 | stream->writeInt32(date); |
| 164 | stream->writeInt32(expires); |
| 165 | stream->writeBool(test_mode); |
| 166 | stream->writeInt32(this_dc); |
| 167 | stream->writeInt32(0x1cb5c415); |
| 168 | uint32_t count = (uint32_t) dc_options.size(); |
| 169 | stream->writeInt32(count); |
| 170 | for (uint32_t a = 0; a < count; a++) { |
| 171 | dc_options[a]->serializeToStream(stream); |
| 172 | } |
| 173 | stream->writeInt32(chat_size_max); |
| 174 | stream->writeInt32(megagroup_size_max); |
| 175 | stream->writeInt32(forwarded_count_max); |
| 176 | stream->writeInt32(online_update_period_ms); |
| 177 | stream->writeInt32(offline_blur_timeout_ms); |
| 178 | stream->writeInt32(offline_idle_timeout_ms); |
| 179 | stream->writeInt32(online_cloud_timeout_ms); |
| 180 | stream->writeInt32(notify_cloud_delay_ms); |
| 181 | stream->writeInt32(notify_default_delay_ms); |
| 182 | stream->writeInt32(chat_big_size); |
| 183 | stream->writeInt32(push_chat_period_ms); |
| 184 | stream->writeInt32(push_chat_limit); |
| 185 | stream->writeInt32(saved_gifs_limit); |
| 186 | stream->writeInt32(edit_time_limit); |
| 187 | stream->writeInt32(rating_e_decay); |
| 188 | stream->writeInt32(stickers_recent_limit); |
| 189 | if ((flags & 1) != 0) { |
| 190 | stream->writeInt32(tmp_sessions); |
| 191 | } |
| 192 | stream->writeInt32(pinned_dialogs_count_max); |
| 193 | stream->writeInt32(call_receive_timeout_ms); |
| 194 | stream->writeInt32(call_ring_timeout_ms); |
| 195 | stream->writeInt32(call_connect_timeout_ms); |
| 196 | stream->writeInt32(call_packet_timeout_ms); |
| 197 | stream->writeString(me_url_prefix); |
| 198 | stream->writeInt32(0x1cb5c415); |
| 199 | count = (uint32_t) disabled_features.size(); |
| 200 | stream->writeInt32(count); |
| 201 | for (uint32_t a = 0; a < count; a++) { |
| 202 | disabled_features[a]->serializeToStream(stream); |
| 203 | } |
| 204 | } |
| 205 |
| 206 | TLObject *TL_help_getConfig::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 207 | return TL_config::TLdeserialize(stream, constructor, error); |
| 208 | } |
| 209 |
| 210 | void TL_help_getConfig::serializeToStream(NativeByteBuffer *stream) { |
| 211 | stream->writeInt32(constructor); |
| 212 | } |
| 213 |
| 214 | bool TL_help_getConfig::isNeedLayer() { |
| 215 | return true; |
| 216 | } |
| 217 |
| 218 | bool TL_account_registerDevice::isNeedLayer() { |
| 219 | return true; |
| 220 | } |
| 221 |
| 222 | TLObject *TL_account_registerDevice::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 223 | return Bool::TLdeserialize(stream, constructor, error); |
| 224 | } |
| 225 |
| 226 | void TL_account_registerDevice::serializeToStream(NativeByteBuffer *stream) { |
| 227 | stream->writeInt32(constructor); |
| 228 | stream->writeInt32(token_type); |
| 229 | stream->writeString(token); |
| 230 | } |
| 231 |
| 232 | User *User::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 233 | User *result = nullptr; |
| 234 | switch (constructor) { |
| 235 | case 0x200250ba: |
| 236 | result = new TL_userEmpty(); |
| 237 | break; |
| 238 | case 0xd10d979a: |
| 239 | result = new TL_user(); |
| 240 | break; |
| 241 | default: |
| 242 | error = true; |
| 243 | DEBUG_E("can't parse magic %x in User", constructor); |
| 244 | return nullptr; |
| 245 | } |
| 246 | result->readParams(stream, error); |
| 247 | return result; |
| 248 | } |
| 249 |
| 250 | void TL_userEmpty::readParams(NativeByteBuffer *stream, bool &error) { |
| 251 | id = stream->readInt32(&error); |
| 252 | } |
| 253 |
| 254 | void TL_userEmpty::serializeToStream(NativeByteBuffer *stream) { |
| 255 | stream->writeInt32(constructor); |
| 256 | stream->writeInt32(id); |
| 257 | } |
| 258 |
| 259 | void TL_user::readParams(NativeByteBuffer *stream, bool &error) { |
| 260 | flags = stream->readInt32(&error); |
| 261 | id = stream->readInt32(&error); |
| 262 | if ((flags & 1) != 0) { |
| 263 | access_hash = stream->readInt64(&error); |
| 264 | } |
| 265 | if ((flags & 2) != 0) { |
| 266 | first_name = stream->readString(&error); |
| 267 | } |
| 268 | if ((flags & 4) != 0) { |
| 269 | last_name = stream->readString(&error); |
| 270 | } |
| 271 | if ((flags & 8) != 0) { |
| 272 | username = stream->readString(&error); |
| 273 | } |
| 274 | if ((flags & 16) != 0) { |
| 275 | phone = stream->readString(&error); |
| 276 | } |
| 277 | if ((flags & 32) != 0) { |
| 278 | photo = std::unique_ptr<UserProfilePhoto>(UserProfilePhoto::TLdeserialize(stream, stream->readUint32(&error), error)); |
| 279 | } |
| 280 | if ((flags & 64) != 0) { |
| 281 | status = std::unique_ptr<UserStatus>(UserStatus::TLdeserialize(stream, stream->readUint32(&error), error)); |
| 282 | } |
| 283 | if ((flags & 16384) != 0) { |
| 284 | bot_info_version = stream->readInt32(&error); |
| 285 | } |
| 286 | if ((flags & 262144) != 0) { |
| 287 | restriction_reason = stream->readString(&error); |
| 288 | } |
| 289 | if ((flags & 524288) != 0) { |
| 290 | bot_inline_placeholder = stream->readString(&error); |
| 291 | } |
| 292 | } |
| 293 |
| 294 | void TL_user::serializeToStream(NativeByteBuffer *stream) { |
| 295 | stream->writeInt32(constructor); |
| 296 | stream->writeInt32(flags); |
| 297 | stream->writeInt32(id); |
| 298 | if ((flags & 1) != 0) { |
| 299 | stream->writeInt64(access_hash); |
| 300 | } |
| 301 | if ((flags & 2) != 0) { |
| 302 | stream->writeString(first_name); |
| 303 | } |
| 304 | if ((flags & 4) != 0) { |
| 305 | stream->writeString(last_name); |
| 306 | } |
| 307 | if ((flags & 8) != 0) { |
| 308 | stream->writeString(username); |
| 309 | } |
| 310 | if ((flags & 16) != 0) { |
| 311 | stream->writeString(phone); |
| 312 | } |
| 313 | if ((flags & 32) != 0) { |
| 314 | photo->serializeToStream(stream); |
| 315 | } |
| 316 | if ((flags & 64) != 0) { |
| 317 | status->serializeToStream(stream); |
| 318 | } |
| 319 | if ((flags & 16384) != 0) { |
| 320 | stream->writeInt32(bot_info_version); |
| 321 | } |
| 322 | if ((flags & 262144) != 0) { |
| 323 | stream->writeString(restriction_reason); |
| 324 | } |
| 325 | if ((flags & 524288) != 0) { |
| 326 | stream->writeString(bot_inline_placeholder); |
| 327 | } |
| 328 | } |
| 329 |
| 330 | TL_auth_authorization *TL_auth_authorization::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 331 | if (TL_auth_authorization::constructor != constructor) { |
| 332 | error = true; |
| 333 | DEBUG_E("can't parse magic %x in TL_auth_authorization", constructor); |
| 334 | return nullptr; |
| 335 | } |
| 336 | TL_auth_authorization *result = new TL_auth_authorization(); |
| 337 | result->readParams(stream, error); |
| 338 | return result; |
| 339 | } |
| 340 |
| 341 | void TL_auth_authorization::readParams(NativeByteBuffer *stream, bool &error) { |
| 342 | flags = stream->readInt32(&error); |
| 343 | if ((flags & 1) != 0) { |
| 344 | tmp_sessions = stream->readInt32(&error); |
| 345 | } |
| 346 | user = std::unique_ptr<User>(User::TLdeserialize(stream, stream->readUint32(&error), error)); |
| 347 | } |
| 348 |
| 349 | TL_auth_exportedAuthorization *TL_auth_exportedAuthorization::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 350 | if (TL_auth_exportedAuthorization::constructor != constructor) { |
| 351 | error = true; |
| 352 | DEBUG_E("can't parse magic %x in TL_auth_exportedAuthorization", constructor); |
| 353 | return nullptr; |
| 354 | } |
| 355 | TL_auth_exportedAuthorization *result = new TL_auth_exportedAuthorization(); |
| 356 | result->readParams(stream, error); |
| 357 | return result; |
| 358 | } |
| 359 |
| 360 | void TL_auth_exportedAuthorization::readParams(NativeByteBuffer *stream, bool &error) { |
| 361 | id = stream->readInt32(&error); |
| 362 | bytes = std::unique_ptr<ByteArray>(stream->readByteArray(&error)); |
| 363 | } |
| 364 |
| 365 | bool TL_auth_exportAuthorization::isNeedLayer() { |
| 366 | return true; |
| 367 | } |
| 368 |
| 369 | TLObject *TL_auth_exportAuthorization::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 370 | return TL_auth_exportedAuthorization::TLdeserialize(stream, constructor, error); |
| 371 | } |
| 372 |
| 373 | void TL_auth_exportAuthorization::serializeToStream(NativeByteBuffer *stream) { |
| 374 | stream->writeInt32(constructor); |
| 375 | stream->writeInt32(dc_id); |
| 376 | } |
| 377 |
| 378 | bool TL_auth_importAuthorization::isNeedLayer() { |
| 379 | return true; |
| 380 | } |
| 381 |
| 382 | TLObject *TL_auth_importAuthorization::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 383 | return TL_auth_authorization::TLdeserialize(stream, constructor, error); |
| 384 | } |
| 385 |
| 386 | void TL_auth_importAuthorization::serializeToStream(NativeByteBuffer *stream) { |
| 387 | stream->writeInt32(constructor); |
| 388 | stream->writeInt32(id); |
| 389 | stream->writeByteArray(bytes.get()); |
| 390 | } |
| 391 |
| 392 | UserStatus *UserStatus::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 393 | UserStatus *result = nullptr; |
| 394 | switch (constructor) { |
| 395 | case 0x8c703f: |
| 396 | result = new TL_userStatusOffline(); |
| 397 | break; |
| 398 | case 0x7bf09fc: |
| 399 | result = new TL_userStatusLastWeek(); |
| 400 | break; |
| 401 | case 0x9d05049: |
| 402 | result = new TL_userStatusEmpty(); |
| 403 | break; |
| 404 | case 0x77ebc742: |
| 405 | result = new TL_userStatusLastMonth(); |
| 406 | break; |
| 407 | case 0xedb93949: |
| 408 | result = new TL_userStatusOnline(); |
| 409 | break; |
| 410 | case 0xe26f42f1: |
| 411 | result = new TL_userStatusRecently(); |
| 412 | break; |
| 413 | default: |
| 414 | error = true; |
| 415 | DEBUG_E("can't parse magic %x in UserStatus", constructor); |
| 416 | return nullptr; |
| 417 | } |
| 418 | result->readParams(stream, error); |
| 419 | return result; |
| 420 | } |
| 421 |
| 422 | void TL_userStatusOffline::readParams(NativeByteBuffer *stream, bool &error) { |
| 423 | expires = stream->readInt32(&error); |
| 424 | } |
| 425 |
| 426 | void TL_userStatusOffline::serializeToStream(NativeByteBuffer *stream) { |
| 427 | stream->writeInt32(constructor); |
| 428 | stream->writeInt32(expires); |
| 429 | } |
| 430 |
| 431 | void TL_userStatusLastWeek::serializeToStream(NativeByteBuffer *stream) { |
| 432 | stream->writeInt32(constructor); |
| 433 | } |
| 434 |
| 435 | void TL_userStatusEmpty::serializeToStream(NativeByteBuffer *stream) { |
| 436 | stream->writeInt32(constructor); |
| 437 | } |
| 438 |
| 439 | void TL_userStatusLastMonth::serializeToStream(NativeByteBuffer *stream) { |
| 440 | stream->writeInt32(constructor); |
| 441 | } |
| 442 |
| 443 | void TL_userStatusOnline::readParams(NativeByteBuffer *stream, bool &error) { |
| 444 | expires = stream->readInt32(&error); |
| 445 | } |
| 446 |
| 447 | void TL_userStatusOnline::serializeToStream(NativeByteBuffer *stream) { |
| 448 | stream->writeInt32(constructor); |
| 449 | stream->writeInt32(expires); |
| 450 | } |
| 451 |
| 452 | void TL_userStatusRecently::serializeToStream(NativeByteBuffer *stream) { |
| 453 | stream->writeInt32(constructor); |
| 454 | } |
| 455 |
| 456 | FileLocation *FileLocation::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 457 | FileLocation *result = nullptr; |
| 458 | switch (constructor) { |
| 459 | case 0x53d69076: |
| 460 | result = new TL_fileLocation(); |
| 461 | break; |
| 462 | case 0x7c596b46: |
| 463 | result = new TL_fileLocationUnavailable(); |
| 464 | break; |
| 465 | case 0x55555554: |
| 466 | result = new TL_fileEncryptedLocation(); |
| 467 | break; |
| 468 | default: |
| 469 | error = true; |
| 470 | DEBUG_E("can't parse magic %x in FileLocation", constructor); |
| 471 | return nullptr; |
| 472 | } |
| 473 | result->readParams(stream, error); |
| 474 | return result; |
| 475 | } |
| 476 |
| 477 | void TL_fileLocation::readParams(NativeByteBuffer *stream, bool &error) { |
| 478 | dc_id = stream->readInt32(&error); |
| 479 | volume_id = stream->readInt64(&error); |
| 480 | local_id = stream->readInt32(&error); |
| 481 | secret = stream->readInt64(&error); |
| 482 | } |
| 483 |
| 484 | void TL_fileLocation::serializeToStream(NativeByteBuffer *stream) { |
| 485 | stream->writeInt32(constructor); |
| 486 | stream->writeInt32(dc_id); |
| 487 | stream->writeInt64(volume_id); |
| 488 | stream->writeInt32(local_id); |
| 489 | stream->writeInt64(secret); |
| 490 | } |
| 491 |
| 492 | void TL_fileLocationUnavailable::readParams(NativeByteBuffer *stream, bool &error) { |
| 493 | volume_id = stream->readInt64(&error); |
| 494 | local_id = stream->readInt32(&error); |
| 495 | secret = stream->readInt64(&error); |
| 496 | } |
| 497 |
| 498 | void TL_fileLocationUnavailable::serializeToStream(NativeByteBuffer *stream) { |
| 499 | stream->writeInt32(constructor); |
| 500 | stream->writeInt64(volume_id); |
| 501 | stream->writeInt32(local_id); |
| 502 | stream->writeInt64(secret); |
| 503 | } |
| 504 |
| 505 | void TL_fileEncryptedLocation::readParams(NativeByteBuffer *stream, bool &error) { |
| 506 | dc_id = stream->readInt32(&error); |
| 507 | volume_id = stream->readInt64(&error); |
| 508 | local_id = stream->readInt32(&error); |
| 509 | secret = stream->readInt64(&error); |
| 510 | key = std::unique_ptr<ByteArray>(stream->readByteArray(&error)); |
| 511 | iv = std::unique_ptr<ByteArray>(stream->readByteArray(&error)); |
| 512 | } |
| 513 |
| 514 | void TL_fileEncryptedLocation::serializeToStream(NativeByteBuffer *stream) { |
| 515 | stream->writeInt32(constructor); |
| 516 | stream->writeInt32(dc_id); |
| 517 | stream->writeInt64(volume_id); |
| 518 | stream->writeInt32(local_id); |
| 519 | stream->writeInt64(secret); |
| 520 | stream->writeByteArray(key.get()); |
| 521 | stream->writeByteArray(iv.get()); |
| 522 | } |
| 523 |
| 524 | UserProfilePhoto *UserProfilePhoto::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 525 | UserProfilePhoto *result = nullptr; |
| 526 | switch (constructor) { |
| 527 | case 0x4f11bae1: |
| 528 | result = new TL_userProfilePhotoEmpty(); |
| 529 | break; |
| 530 | case 0xd559d8c8: |
| 531 | result = new TL_userProfilePhoto(); |
| 532 | break; |
| 533 | default: |
| 534 | error = true; |
| 535 | DEBUG_E("can't parse magic %x in UserProfilePhoto", constructor); |
| 536 | return nullptr; |
| 537 | } |
| 538 | result->readParams(stream, error); |
| 539 | return result; |
| 540 | } |
| 541 |
| 542 | void TL_userProfilePhotoEmpty::serializeToStream(NativeByteBuffer *stream) { |
| 543 | stream->writeInt32(constructor); |
| 544 | } |
| 545 |
| 546 | void TL_userProfilePhoto::readParams(NativeByteBuffer *stream, bool &error) { |
| 547 | photo_id = stream->readInt64(&error); |
| 548 | photo_small = std::unique_ptr<FileLocation>(FileLocation::TLdeserialize(stream, stream->readUint32(&error), error)); |
| 549 | photo_big = std::unique_ptr<FileLocation>(FileLocation::TLdeserialize(stream, stream->readUint32(&error), error)); |
| 550 | } |
| 551 |
| 552 | void TL_userProfilePhoto::serializeToStream(NativeByteBuffer *stream) { |
| 553 | stream->writeInt32(constructor); |
| 554 | stream->writeInt64(photo_id); |
| 555 | photo_small->serializeToStream(stream); |
| 556 | photo_big->serializeToStream(stream); |
| 557 | } |
| 558 |
| 559 | auth_SentCode *auth_SentCode::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 560 | auth_SentCode *result = nullptr; |
| 561 | switch (constructor) { |
| 562 | case 0xe325edcf: |
| 563 | result = new TL_auth_sentAppCode(); |
| 564 | break; |
| 565 | case 0xefed51d9: |
| 566 | result = new TL_auth_sentCode(); |
| 567 | break; |
| 568 | default: |
| 569 | error = true; |
| 570 | DEBUG_E("can't parse magic %x in auth_SentCode", constructor); |
| 571 | return nullptr; |
| 572 | } |
| 573 | result->readParams(stream, error); |
| 574 | return result; |
| 575 | } |
| 576 |
| 577 | void TL_auth_sentAppCode::readParams(NativeByteBuffer *stream, bool &error) { |
| 578 | phone_registered = stream->readBool(&error); |
| 579 | phone_code_hash = stream->readString(&error); |
| 580 | send_call_timeout = stream->readInt32(&error); |
| 581 | is_password = stream->readBool(&error); |
| 582 | } |
| 583 |
| 584 | void TL_auth_sentAppCode::serializeToStream(NativeByteBuffer *stream) { |
| 585 | stream->writeInt32(constructor); |
| 586 | stream->writeBool(phone_registered); |
| 587 | stream->writeString(phone_code_hash); |
| 588 | stream->writeInt32(send_call_timeout); |
| 589 | stream->writeBool(is_password); |
| 590 | } |
| 591 |
| 592 | void TL_auth_sentCode::readParams(NativeByteBuffer *stream, bool &error) { |
| 593 | phone_registered = stream->readBool(&error); |
| 594 | phone_code_hash = stream->readString(&error); |
| 595 | send_call_timeout = stream->readInt32(&error); |
| 596 | is_password = stream->readBool(&error); |
| 597 | } |
| 598 |
| 599 | void TL_auth_sentCode::serializeToStream(NativeByteBuffer *stream) { |
| 600 | stream->writeInt32(constructor); |
| 601 | stream->writeBool(phone_registered); |
| 602 | stream->writeString(phone_code_hash); |
| 603 | stream->writeInt32(send_call_timeout); |
| 604 | stream->writeBool(is_password); |
| 605 | } |
| 606 |
| 607 | TLObject *TL_auth_sendCode::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 608 | return auth_SentCode::TLdeserialize(stream, constructor, error); |
| 609 | } |
| 610 |
| 611 | void TL_auth_sendCode::serializeToStream(NativeByteBuffer *stream) { |
| 612 | stream->writeInt32(constructor); |
| 613 | stream->writeString(phone_number); |
| 614 | stream->writeInt32(sms_type); |
| 615 | stream->writeInt32(api_id); |
| 616 | stream->writeString(api_hash); |
| 617 | stream->writeString(lang_code); |
| 618 | } |
| 619 |
| 620 | void TL_updatesTooLong::serializeToStream(NativeByteBuffer *stream) { |
| 621 | stream->writeInt32(constructor); |
| 622 | } |
| 623 |
| 624 | TL_upload_file *TL_upload_file::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 625 | if (TL_upload_file::constructor != constructor) { |
| 626 | error = true; |
| 627 | FileLog::e("can't parse magic %x in TL_upload_file", constructor); |
| 628 | return nullptr; |
| 629 | } |
| 630 | TL_upload_file *result = new TL_upload_file(); |
| 631 | result->readParams(stream, error); |
| 632 | return result; |
| 633 | } |
| 634 |
| 635 | TL_upload_file::~TL_upload_file() { |
| 636 | if (bytes != nullptr) { |
| 637 | bytes->reuse(); |
| 638 | bytes = nullptr; |
| 639 | } |
| 640 | } |
| 641 |
| 642 | void TL_upload_file::readParams(NativeByteBuffer *stream, bool &error) { |
| 643 | type = std::unique_ptr<storage_FileType>(storage_FileType::TLdeserialize(stream, stream->readInt32(&error), error)); |
| 644 | mtime = stream->readInt32(&error); |
| 645 | bytes = stream->readByteBuffer(true, &error); |
| 646 | } |
| 647 |
| 648 | InputFileLocation *InputFileLocation::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 649 | InputFileLocation *result = nullptr; |
| 650 | switch (constructor) { |
| 651 | case 0x430f0724: |
| 652 | result = new TL_inputDocumentFileLocation(); |
| 653 | break; |
| 654 | case 0x14637196: |
| 655 | result = new TL_inputFileLocation(); |
| 656 | break; |
| 657 | case 0xf5235d55: |
| 658 | result = new TL_inputEncryptedFileLocation(); |
| 659 | break; |
| 660 | default: |
| 661 | error = true; |
| 662 | FileLog::e("can't parse magic %x in InputFileLocation", constructor); |
| 663 | return nullptr; |
| 664 | } |
| 665 | result->readParams(stream, error); |
| 666 | return result; |
| 667 | } |
| 668 |
| 669 | void TL_inputDocumentFileLocation::readParams(NativeByteBuffer *stream, bool &error) { |
| 670 | id = stream->readInt64(&error); |
| 671 | access_hash = stream->readInt64(&error); |
| 672 | version = stream->readInt32(&error); |
| 673 | } |
| 674 |
| 675 | void TL_inputDocumentFileLocation::serializeToStream(NativeByteBuffer *stream) { |
| 676 | stream->writeInt32(constructor); |
| 677 | stream->writeInt64(id); |
| 678 | stream->writeInt64(access_hash); |
| 679 | stream->writeInt32(version); |
| 680 | } |
| 681 |
| 682 | void TL_inputFileLocation::readParams(NativeByteBuffer *stream, bool &error) { |
| 683 | volume_id = stream->readInt64(&error); |
| 684 | local_id = stream->readInt32(&error); |
| 685 | secret = stream->readInt64(&error); |
| 686 | } |
| 687 |
| 688 | void TL_inputFileLocation::serializeToStream(NativeByteBuffer *stream) { |
| 689 | stream->writeInt32(constructor); |
| 690 | stream->writeInt64(volume_id); |
| 691 | stream->writeInt32(local_id); |
| 692 | stream->writeInt64(secret); |
| 693 | } |
| 694 |
| 695 | void TL_inputEncryptedFileLocation::readParams(NativeByteBuffer *stream, bool &error) { |
| 696 | id = stream->readInt64(&error); |
| 697 | access_hash = stream->readInt64(&error); |
| 698 | } |
| 699 |
| 700 | void TL_inputEncryptedFileLocation::serializeToStream(NativeByteBuffer *stream) { |
| 701 | stream->writeInt32(constructor); |
| 702 | stream->writeInt64(id); |
| 703 | stream->writeInt64(access_hash); |
| 704 | } |
| 705 |
| 706 | storage_FileType *storage_FileType::TLdeserialize(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 707 | storage_FileType *result = nullptr; |
| 708 | switch (constructor) { |
| 709 | case 0xaa963b05: |
| 710 | result = new TL_storage_fileUnknown(); |
| 711 | break; |
| 712 | case 0xb3cea0e4: |
| 713 | result = new TL_storage_fileMp4(); |
| 714 | break; |
| 715 | case 0x1081464c: |
| 716 | result = new TL_storage_fileWebp(); |
| 717 | break; |
| 718 | case 0xa4f63c0: |
| 719 | result = new TL_storage_filePng(); |
| 720 | break; |
| 721 | case 0xcae1aadf: |
| 722 | result = new TL_storage_fileGif(); |
| 723 | break; |
| 724 | case 0xae1e508d: |
| 725 | result = new TL_storage_filePdf(); |
| 726 | break; |
| 727 | case 0x528a0677: |
| 728 | result = new TL_storage_fileMp3(); |
| 729 | break; |
| 730 | case 0x7efe0e: |
| 731 | result = new TL_storage_fileJpeg(); |
| 732 | break; |
| 733 | case 0x4b09ebbc: |
| 734 | result = new TL_storage_fileMov(); |
| 735 | break; |
| 736 | case 0x40bc6f52: |
| 737 | result = new TL_storage_filePartial(); |
| 738 | break; |
| 739 | default: |
| 740 | error = true; |
| 741 | FileLog::e("can't parse magic %x in storage_FileType", constructor); |
| 742 | return nullptr; |
| 743 | } |
| 744 | result->readParams(stream, error); |
| 745 | return result; |
| 746 | } |
| 747 |
| 748 | void TL_storage_fileUnknown::serializeToStream(NativeByteBuffer *stream) { |
| 749 | stream->writeInt32(constructor); |
| 750 | } |
| 751 |
| 752 | void TL_storage_fileMp4::serializeToStream(NativeByteBuffer *stream) { |
| 753 | stream->writeInt32(constructor); |
| 754 | } |
| 755 |
| 756 | void TL_storage_fileWebp::serializeToStream(NativeByteBuffer *stream) { |
| 757 | stream->writeInt32(constructor); |
| 758 | } |
| 759 |
| 760 | void TL_storage_filePng::serializeToStream(NativeByteBuffer *stream) { |
| 761 | stream->writeInt32(constructor); |
| 762 | } |
| 763 |
| 764 | void TL_storage_fileGif::serializeToStream(NativeByteBuffer *stream) { |
| 765 | stream->writeInt32(constructor); |
| 766 | } |
| 767 |
| 768 | void TL_storage_filePdf::serializeToStream(NativeByteBuffer *stream) { |
| 769 | stream->writeInt32(constructor); |
| 770 | } |
| 771 |
| 772 | void TL_storage_fileMp3::serializeToStream(NativeByteBuffer *stream) { |
| 773 | stream->writeInt32(constructor); |
| 774 | } |
| 775 |
| 776 | void TL_storage_fileJpeg::serializeToStream(NativeByteBuffer *stream) { |
| 777 | stream->writeInt32(constructor); |
| 778 | } |
| 779 |
| 780 | void TL_storage_fileMov::serializeToStream(NativeByteBuffer *stream) { |
| 781 | stream->writeInt32(constructor); |
| 782 | } |
| 783 |
| 784 | void TL_storage_filePartial::serializeToStream(NativeByteBuffer *stream) { |
| 785 | stream->writeInt32(constructor); |
| 786 | } |
| 787 |
| 788 | TLObject *TL_upload_saveFilePart::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 789 | return Bool::TLdeserialize(stream, constructor, error); |
| 790 | } |
| 791 |
| 792 | void TL_upload_saveFilePart::serializeToStream(NativeByteBuffer *stream) { |
| 793 | stream->writeInt32(constructor); |
| 794 | stream->writeInt64(file_id); |
| 795 | stream->writeInt32(file_part); |
| 796 | stream->writeByteArray(bytes.get()); |
| 797 | } |
| 798 |
| 799 | bool TL_upload_saveFilePart::isNeedLayer() { |
| 800 | return true; |
| 801 | } |
| 802 |
| 803 | TLObject *TL_upload_getFile::deserializeResponse(NativeByteBuffer *stream, uint32_t constructor, bool &error) { |
| 804 | return TL_upload_file::TLdeserialize(stream, constructor, error); |
| 805 | } |
| 806 |
| 807 | void TL_upload_getFile::serializeToStream(NativeByteBuffer *stream) { |
| 808 | stream->writeInt32(constructor); |
| 809 | location->serializeToStream(stream); |
| 810 | stream->writeInt32(offset); |
| 811 | stream->writeInt32(limit); |
| 812 | } |
| 813 |
| 814 | bool TL_upload_getFile::isNeedLayer() { |
| 815 | return true; |
| 816 | } |
| 817 |