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