forked from TelegramMessenger/Telegram-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApi.m
More file actions
1979 lines (1633 loc) · 74.9 KB
/
Copy pathApi.m
File metadata and controls
1979 lines (1633 loc) · 74.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#import "Api.h"
#import <objc/runtime.h>
static const char *Api1__Serializer_Key = "Api1__Serializer";
@interface Api1__Number : NSNumber
{
NSNumber *_value;
}
@end
@implementation Api1__Number
- (instancetype)initWithNumber:(NSNumber *)number
{
self = [super init];
if (self != nil)
{
_value = number;
}
return self;
}
- (char)charValue
{
return [_value charValue];
}
- (unsigned char)unsignedCharValue
{
return [_value unsignedCharValue];
}
- (short)shortValue
{
return [_value shortValue];
}
- (unsigned short)unsignedShortValue
{
return [_value unsignedShortValue];
}
- (int)intValue
{
return [_value intValue];
}
- (unsigned int)unsignedIntValue
{
return [_value unsignedIntValue];
}
- (long)longValue
{
return [_value longValue];
}
- (unsigned long)unsignedLongValue
{
return [_value unsignedLongValue];
}
- (long long)longLongValue
{
return [_value longLongValue];
}
- (unsigned long long)unsignedLongLongValue
{
return [_value unsignedLongLongValue];
}
- (float)floatValue
{
return [_value floatValue];
}
- (double)doubleValue
{
return [_value doubleValue];
}
- (BOOL)boolValue
{
return [_value boolValue];
}
- (NSInteger)integerValue
{
return [_value integerValue];
}
- (NSUInteger)unsignedIntegerValue
{
return [_value unsignedIntegerValue];
}
- (NSString *)stringValue
{
return [_value stringValue];
}
- (NSComparisonResult)compare:(NSNumber *)otherNumber
{
return [_value compare:otherNumber];
}
- (BOOL)isEqualToNumber:(NSNumber *)number
{
return [_value isEqualToNumber:number];
}
- (NSString *)descriptionWithLocale:(id)locale
{
return [_value descriptionWithLocale:locale];
}
- (void)getValue:(void *)value
{
[_value getValue:value];
}
- (const char *)objCType
{
return [_value objCType];
}
- (NSUInteger)hash
{
return [_value hash];
}
- (instancetype)copyWithZone:(NSZone *)__unused zone
{
return self;
}
@end
@interface Api1__Serializer : NSObject
@property (nonatomic) int32_t constructorSignature;
@property (nonatomic, copy) bool (^serializeBlock)(id object, NSMutableData *);
@end
@implementation Api1__Serializer
- (instancetype)initWithConstructorSignature:(int32_t)constructorSignature serializeBlock:(bool (^)(id, NSMutableData *))serializeBlock
{
self = [super init];
if (self != nil)
{
self.constructorSignature = constructorSignature;
self.serializeBlock = serializeBlock;
}
return self;
}
+ (id)addSerializerToObject:(id)object withConstructorSignature:(int32_t)constructorSignature serializeBlock:(bool (^)(id, NSMutableData *))serializeBlock
{
if (object != nil)
objc_setAssociatedObject(object, Api1__Serializer_Key, [[Api1__Serializer alloc] initWithConstructorSignature:constructorSignature serializeBlock:serializeBlock], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
return object;
}
+ (id)addSerializerToObject:(id)object serializer:(Api1__Serializer *)serializer
{
if (object != nil)
objc_setAssociatedObject(object, Api1__Serializer_Key, serializer, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
return object;
}
@end
@interface Api1__UnboxedTypeMetaInfo : NSObject
@property (nonatomic, readonly) int32_t constructorSignature;
@end
@implementation Api1__UnboxedTypeMetaInfo
- (instancetype)initWithConstructorSignature:(int32_t)constructorSignature
{
self = [super init];
if (self != nil)
{
_constructorSignature = constructorSignature;
}
return self;
}
@end
@interface Api1__PreferNSDataTypeMetaInfo : NSObject
@end
@implementation Api1__PreferNSDataTypeMetaInfo
+ (instancetype)preferNSDataTypeMetaInfo
{
static Api1__PreferNSDataTypeMetaInfo *instance = nil;
static dispatch_once_t t;
dispatch_once(&t, ^
{
instance = [[Api1__PreferNSDataTypeMetaInfo alloc] init];
});
return instance;
}
@end
@interface Api1__BoxedTypeMetaInfo : NSObject
@end
@implementation Api1__BoxedTypeMetaInfo
+ (instancetype)boxedTypeMetaInfo
{
static Api1__BoxedTypeMetaInfo *instance = nil;
static dispatch_once_t t;
dispatch_once(&t, ^
{
instance = [[Api1__BoxedTypeMetaInfo alloc] init];
});
return instance;
}
@end
@implementation Api1__Environment
+ (id (^)(NSData *data, NSUInteger *offset, id metaInfo))parserByConstructorSignature:(int32_t)constructorSignature
{
static NSMutableDictionary *parsers = nil;
static dispatch_once_t t;
dispatch_once(&t, ^
{
parsers = [[NSMutableDictionary alloc] init];
parsers[@((int32_t)0xA8509BDA)] = [^id (NSData *data, NSUInteger *offset, __unused id metaInfo)
{
if (*offset + 4 > data.length)
return nil;
int32_t value = 0;
[data getBytes:(void *)&value range:NSMakeRange(*offset, 4)];
*offset += 4;
return @(value);
} copy];
parsers[@((int32_t)0x22076CBA)] = [^id (NSData *data, NSUInteger *offset, __unused id metaInfo)
{
if (*offset + 8 > data.length)
return nil;
int64_t value = 0;
[data getBytes:(void *)&value range:NSMakeRange(*offset, 8)];
*offset += 8;
return @(value);
} copy];
parsers[@((int32_t)0x2210C154)] = [^id (NSData *data, NSUInteger *offset, __unused id metaInfo)
{
if (*offset + 8 > data.length)
return nil;
double value = 0;
[data getBytes:(void *)&value range:NSMakeRange(*offset, 8)];
*offset += 8;
return @(value);
} copy];
parsers[@((int32_t)0xB5286E24)] = [^id (NSData *data, NSUInteger *offset, __unused id metaInfo)
{
if (*offset + 1 > data.length)
return nil;
uint8_t tmp = 0;
[data getBytes:(void *)&tmp range:NSMakeRange(*offset, 1)];
*offset += 1;
int paddingBytes = 0;
int32_t length = tmp;
if (length == 254)
{
length = 0;
if (*offset + 3 > data.length)
return nil;
[data getBytes:((uint8_t *)&length) + 1 range:NSMakeRange(*offset, 3)];
*offset += 3;
length >>= 8;
paddingBytes = (((length % 4) == 0 ? length : (length + 4 - (length % 4)))) - length;
}
else
paddingBytes = ((((length + 1) % 4) == 0 ? (length + 1) : ((length + 1) + 4 - ((length + 1) % 4)))) - (length + 1);
bool isData = [metaInfo isKindOfClass:[Api1__PreferNSDataTypeMetaInfo class]];
id object = nil;
if (length > 0)
{
if (*offset + length > data.length)
return nil;
if (isData)
object = [[NSData alloc] initWithBytes:((uint8_t *)data.bytes) + *offset length:length];
else
object = [[NSString alloc] initWithBytes:((uint8_t *)data.bytes) + *offset length:length encoding:NSUTF8StringEncoding];
*offset += length;
}
*offset += paddingBytes;
return object == nil ? (isData ? [NSData data] : @"") : object;
} copy];
parsers[@((int32_t)0x1cb5c415)] = [^id (NSData *data, NSUInteger *offset, id metaInfo)
{
if (*offset + 4 > data.length)
return nil;
int32_t count = 0;
[data getBytes:(void *)&count range:NSMakeRange(*offset, 4)];
*offset += 4;
if (count < 0)
return nil;
bool isBoxed = false;
int32_t unboxedConstructorSignature = 0;
if ([metaInfo isKindOfClass:[Api1__BoxedTypeMetaInfo class]])
isBoxed = true;
else if ([metaInfo isKindOfClass:[Api1__UnboxedTypeMetaInfo class]])
unboxedConstructorSignature = ((Api1__UnboxedTypeMetaInfo *)metaInfo).constructorSignature;
else
return nil;
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:(NSUInteger)count];
for (int32_t i = 0; i < count; i++)
{
int32_t itemConstructorSignature = 0;
if (isBoxed)
{
if (*offset + 4 > data.length)
return nil;
[data getBytes:(void *)&itemConstructorSignature range:NSMakeRange(*offset, 4)];
*offset += 4;
}
else
itemConstructorSignature = unboxedConstructorSignature;
id item = [Api1__Environment parseObject:data offset:offset implicitSignature:itemConstructorSignature metaInfo:nil];
if (item == nil)
return nil;
[array addObject:item];
}
return array;
} copy];
parsers[@((int32_t)0x2331b22d)] = [^id (NSData *_data, NSUInteger* _offset, __unused id metaInfo)
{
NSNumber * pid = nil;
if ((pid = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0x22076cba metaInfo:nil]) == nil)
return nil;
return [Api1_Photo photoEmptyWithPid:pid];
} copy];
parsers[@((int32_t)0xd07504a5)] = [^id (NSData *_data, NSUInteger* _offset, __unused id metaInfo)
{
NSNumber * flags = nil;
if ((flags = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xa8509bda metaInfo:nil]) == nil)
return nil;
NSNumber * pid = nil;
if ((pid = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0x22076cba metaInfo:nil]) == nil)
return nil;
NSNumber * accessHash = nil;
if ((accessHash = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0x22076cba metaInfo:nil]) == nil)
return nil;
NSData * fileReference = nil;
if ((fileReference = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xb5286e24 metaInfo:[Api1__PreferNSDataTypeMetaInfo preferNSDataTypeMetaInfo]]) == nil)
return nil;
NSNumber * date = nil;
if ((date = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xa8509bda metaInfo:nil]) == nil)
return nil;
NSArray * sizes = nil;
int32_t sizes_signature = 0; [_data getBytes:(void *)&sizes_signature range:NSMakeRange(*_offset, 4)]; *_offset += 4;
if ((sizes = [Api1__Environment parseObject:_data offset:_offset implicitSignature:sizes_signature metaInfo:[Api1__BoxedTypeMetaInfo boxedTypeMetaInfo]]) == nil)
return nil;
NSNumber * dcId = nil;
if ((dcId = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xa8509bda metaInfo:nil]) == nil)
return nil;
return [Api1_Photo photoWithFlags:flags pid:pid accessHash:accessHash fileReference:fileReference date:date sizes:sizes dcId:dcId];
} copy];
parsers[@((int32_t)0xe17e23c)] = [^id (NSData *_data, NSUInteger* _offset, __unused id metaInfo)
{
NSString * type = nil;
if ((type = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xb5286e24 metaInfo:nil]) == nil)
return nil;
return [Api1_PhotoSize photoSizeEmptyWithType:type];
} copy];
parsers[@((int32_t)0x77bfb61b)] = [^id (NSData *_data, NSUInteger* _offset, __unused id metaInfo)
{
NSString * type = nil;
if ((type = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xb5286e24 metaInfo:nil]) == nil)
return nil;
Api1_FileLocation * location = nil;
int32_t location_signature = 0; [_data getBytes:(void *)&location_signature range:NSMakeRange(*_offset, 4)]; *_offset += 4;
if ((location = [Api1__Environment parseObject:_data offset:_offset implicitSignature:location_signature metaInfo:nil]) == nil)
return nil;
NSNumber * w = nil;
if ((w = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xa8509bda metaInfo:nil]) == nil)
return nil;
NSNumber * h = nil;
if ((h = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xa8509bda metaInfo:nil]) == nil)
return nil;
NSNumber * size = nil;
if ((size = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xa8509bda metaInfo:nil]) == nil)
return nil;
return [Api1_PhotoSize photoSizeWithType:type location:location w:w h:h size:size];
} copy];
parsers[@((int32_t)0xe9a734fa)] = [^id (NSData *_data, NSUInteger* _offset, __unused id metaInfo)
{
NSString * type = nil;
if ((type = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xb5286e24 metaInfo:nil]) == nil)
return nil;
Api1_FileLocation * location = nil;
int32_t location_signature = 0; [_data getBytes:(void *)&location_signature range:NSMakeRange(*_offset, 4)]; *_offset += 4;
if ((location = [Api1__Environment parseObject:_data offset:_offset implicitSignature:location_signature metaInfo:nil]) == nil)
return nil;
NSNumber * w = nil;
if ((w = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xa8509bda metaInfo:nil]) == nil)
return nil;
NSNumber * h = nil;
if ((h = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xa8509bda metaInfo:nil]) == nil)
return nil;
NSData * bytes = nil;
if ((bytes = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xb5286e24 metaInfo:[Api1__PreferNSDataTypeMetaInfo preferNSDataTypeMetaInfo]]) == nil)
return nil;
return [Api1_PhotoSize photoCachedSizeWithType:type location:location w:w h:h bytes:bytes];
} copy];
parsers[@((int32_t)0xe0b0bc2e)] = [^id (NSData *_data, NSUInteger* _offset, __unused id metaInfo)
{
NSString * type = nil;
if ((type = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xb5286e24 metaInfo:nil]) == nil)
return nil;
NSData * bytes = nil;
if ((bytes = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xb5286e24 metaInfo:[Api1__PreferNSDataTypeMetaInfo preferNSDataTypeMetaInfo]]) == nil)
return nil;
return [Api1_PhotoSize photoStrippedSizeWithType:type bytes:bytes];
} copy];
parsers[@((int32_t)0xbc7fc6cd)] = [^id (NSData *_data, NSUInteger* _offset, __unused id metaInfo)
{
NSNumber * volumeId = nil;
if ((volumeId = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0x22076cba metaInfo:nil]) == nil)
return nil;
NSNumber * localId = nil;
if ((localId = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xa8509bda metaInfo:nil]) == nil)
return nil;
return [Api1_FileLocation fileLocationToBeDeprecatedWithVolumeId:volumeId localId:localId];
} copy];
parsers[@((int32_t)0x6c37c15c)] = [^id (NSData *_data, NSUInteger* _offset, __unused id metaInfo)
{
NSNumber * w = nil;
if ((w = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xa8509bda metaInfo:nil]) == nil)
return nil;
NSNumber * h = nil;
if ((h = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xa8509bda metaInfo:nil]) == nil)
return nil;
return [Api1_DocumentAttribute documentAttributeImageSizeWithW:w h:h];
} copy];
parsers[@((int32_t)0x11b58939)] = [^id (__unused NSData *_data, __unused NSUInteger* _offset, __unused id metaInfo)
{
return [Api1_DocumentAttribute documentAttributeAnimated];
} copy];
parsers[@((int32_t)0x6319d612)] = [^id (NSData *_data, NSUInteger* _offset, __unused id metaInfo)
{
NSNumber * flags = nil;
if ((flags = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xa8509bda metaInfo:nil]) == nil)
return nil;
NSString * alt = nil;
if ((alt = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xb5286e24 metaInfo:nil]) == nil)
return nil;
Api1_InputStickerSet * stickerset = nil;
int32_t stickerset_signature = 0; [_data getBytes:(void *)&stickerset_signature range:NSMakeRange(*_offset, 4)]; *_offset += 4;
if ((stickerset = [Api1__Environment parseObject:_data offset:_offset implicitSignature:stickerset_signature metaInfo:nil]) == nil)
return nil;
Api1_MaskCoords * maskCoords = nil;
if (flags != nil && ([flags intValue] & (1 << 0))) {
int32_t maskCoords_signature = 0; [_data getBytes:(void *)&maskCoords_signature range:NSMakeRange(*_offset, 4)]; *_offset += 4;
if ((maskCoords = [Api1__Environment parseObject:_data offset:_offset implicitSignature:maskCoords_signature metaInfo:nil]) == nil)
return nil;
}
return [Api1_DocumentAttribute documentAttributeStickerWithFlags:flags alt:alt stickerset:stickerset maskCoords:maskCoords];
} copy];
parsers[@((int32_t)0xef02ce6)] = [^id (NSData *_data, NSUInteger* _offset, __unused id metaInfo)
{
NSNumber * flags = nil;
if ((flags = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xa8509bda metaInfo:nil]) == nil)
return nil;
NSNumber * duration = nil;
if ((duration = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xa8509bda metaInfo:nil]) == nil)
return nil;
NSNumber * w = nil;
if ((w = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xa8509bda metaInfo:nil]) == nil)
return nil;
NSNumber * h = nil;
if ((h = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xa8509bda metaInfo:nil]) == nil)
return nil;
return [Api1_DocumentAttribute documentAttributeVideoWithFlags:flags duration:duration w:w h:h];
} copy];
parsers[@((int32_t)0x9852f9c6)] = [^id (NSData *_data, NSUInteger* _offset, __unused id metaInfo)
{
NSNumber * flags = nil;
if ((flags = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xa8509bda metaInfo:nil]) == nil)
return nil;
NSNumber * duration = nil;
if ((duration = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xa8509bda metaInfo:nil]) == nil)
return nil;
NSString * title = nil;
if (flags != nil && ([flags intValue] & (1 << 0))) {
if ((title = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xb5286e24 metaInfo:nil]) == nil)
return nil;
}
NSString * performer = nil;
if (flags != nil && ([flags intValue] & (1 << 1))) {
if ((performer = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xb5286e24 metaInfo:nil]) == nil)
return nil;
}
NSData * waveform = nil;
if (flags != nil && ([flags intValue] & (1 << 2))) {
if ((waveform = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xb5286e24 metaInfo:[Api1__PreferNSDataTypeMetaInfo preferNSDataTypeMetaInfo]]) == nil)
return nil;
}
return [Api1_DocumentAttribute documentAttributeAudioWithFlags:flags duration:duration title:title performer:performer waveform:waveform];
} copy];
parsers[@((int32_t)0x15590068)] = [^id (NSData *_data, NSUInteger* _offset, __unused id metaInfo)
{
NSString * fileName = nil;
if ((fileName = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xb5286e24 metaInfo:nil]) == nil)
return nil;
return [Api1_DocumentAttribute documentAttributeFilenameWithFileName:fileName];
} copy];
parsers[@((int32_t)0x9801d2f7)] = [^id (__unused NSData *_data, __unused NSUInteger* _offset, __unused id metaInfo)
{
return [Api1_DocumentAttribute documentAttributeHasStickers];
} copy];
parsers[@((int32_t)0xffb62b95)] = [^id (__unused NSData *_data, __unused NSUInteger* _offset, __unused id metaInfo)
{
return [Api1_InputStickerSet inputStickerSetEmpty];
} copy];
parsers[@((int32_t)0x9de7a269)] = [^id (NSData *_data, NSUInteger* _offset, __unused id metaInfo)
{
NSNumber * pid = nil;
if ((pid = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0x22076cba metaInfo:nil]) == nil)
return nil;
NSNumber * accessHash = nil;
if ((accessHash = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0x22076cba metaInfo:nil]) == nil)
return nil;
return [Api1_InputStickerSet inputStickerSetIDWithPid:pid accessHash:accessHash];
} copy];
parsers[@((int32_t)0x861cc8a0)] = [^id (NSData *_data, NSUInteger* _offset, __unused id metaInfo)
{
NSString * shortName = nil;
if ((shortName = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xb5286e24 metaInfo:nil]) == nil)
return nil;
return [Api1_InputStickerSet inputStickerSetShortNameWithShortName:shortName];
} copy];
parsers[@((int32_t)0x40181ffe)] = [^id (NSData *_data, NSUInteger* _offset, __unused id metaInfo)
{
NSNumber * pid = nil;
if ((pid = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0x22076cba metaInfo:nil]) == nil)
return nil;
NSNumber * accessHash = nil;
if ((accessHash = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0x22076cba metaInfo:nil]) == nil)
return nil;
NSData * fileReference = nil;
if ((fileReference = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xb5286e24 metaInfo:[Api1__PreferNSDataTypeMetaInfo preferNSDataTypeMetaInfo]]) == nil)
return nil;
NSString * thumbSize = nil;
if ((thumbSize = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xb5286e24 metaInfo:nil]) == nil)
return nil;
return [Api1_InputFileLocation inputPhotoFileLocationWithPid:pid accessHash:accessHash fileReference:fileReference thumbSize:thumbSize];
} copy];
parsers[@((int32_t)0xbad07584)] = [^id (NSData *_data, NSUInteger* _offset, __unused id metaInfo)
{
NSNumber * pid = nil;
if ((pid = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0x22076cba metaInfo:nil]) == nil)
return nil;
NSNumber * accessHash = nil;
if ((accessHash = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0x22076cba metaInfo:nil]) == nil)
return nil;
NSData * fileReference = nil;
if ((fileReference = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xb5286e24 metaInfo:[Api1__PreferNSDataTypeMetaInfo preferNSDataTypeMetaInfo]]) == nil)
return nil;
NSString * thumbSize = nil;
if ((thumbSize = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xb5286e24 metaInfo:nil]) == nil)
return nil;
return [Api1_InputFileLocation inputDocumentFileLocationWithPid:pid accessHash:accessHash fileReference:fileReference thumbSize:thumbSize];
} copy];
parsers[@((int32_t)0xaed6dbb2)] = [^id (NSData *_data, NSUInteger* _offset, __unused id metaInfo)
{
NSNumber * n = nil;
if ((n = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xa8509bda metaInfo:nil]) == nil)
return nil;
NSNumber * x = nil;
if ((x = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0x2210c154 metaInfo:nil]) == nil)
return nil;
NSNumber * y = nil;
if ((y = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0x2210c154 metaInfo:nil]) == nil)
return nil;
NSNumber * zoom = nil;
if ((zoom = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0x2210c154 metaInfo:nil]) == nil)
return nil;
return [Api1_MaskCoords maskCoordsWithN:n x:x y:y zoom:zoom];
} copy];
parsers[@((int32_t)0x9ba29cc1)] = [^id (NSData *_data, NSUInteger* _offset, __unused id metaInfo)
{
NSNumber * flags = nil;
if ((flags = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xa8509bda metaInfo:nil]) == nil)
return nil;
NSNumber * pid = nil;
if ((pid = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0x22076cba metaInfo:nil]) == nil)
return nil;
NSNumber * accessHash = nil;
if ((accessHash = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0x22076cba metaInfo:nil]) == nil)
return nil;
NSData * fileReference = nil;
if ((fileReference = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xb5286e24 metaInfo:[Api1__PreferNSDataTypeMetaInfo preferNSDataTypeMetaInfo]]) == nil)
return nil;
NSNumber * date = nil;
if ((date = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xa8509bda metaInfo:nil]) == nil)
return nil;
NSString * mimeType = nil;
if ((mimeType = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xb5286e24 metaInfo:nil]) == nil)
return nil;
NSNumber * size = nil;
if ((size = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xa8509bda metaInfo:nil]) == nil)
return nil;
NSArray * thumbs = nil;
if (flags != nil && ([flags intValue] & (1 << 0))) {
int32_t thumbs_signature = 0; [_data getBytes:(void *)&thumbs_signature range:NSMakeRange(*_offset, 4)]; *_offset += 4;
if ((thumbs = [Api1__Environment parseObject:_data offset:_offset implicitSignature:thumbs_signature metaInfo:[Api1__BoxedTypeMetaInfo boxedTypeMetaInfo]]) == nil)
return nil;
}
NSNumber * dcId = nil;
if ((dcId = [Api1__Environment parseObject:_data offset:_offset implicitSignature:(int32_t)0xa8509bda metaInfo:nil]) == nil)
return nil;
NSArray * attributes = nil;
int32_t attributes_signature = 0; [_data getBytes:(void *)&attributes_signature range:NSMakeRange(*_offset, 4)]; *_offset += 4;
if ((attributes = [Api1__Environment parseObject:_data offset:_offset implicitSignature:attributes_signature metaInfo:[Api1__BoxedTypeMetaInfo boxedTypeMetaInfo]]) == nil)
return nil;
return [Api1_Document documentWithFlags:flags pid:pid accessHash:accessHash fileReference:fileReference date:date mimeType:mimeType size:size thumbs:thumbs dcId:dcId attributes:attributes];
} copy];
});
return parsers[@(constructorSignature)];
}
+ (NSData *)serializeObject:(id)object
{
NSMutableData *data = [[NSMutableData alloc] init];
if ([self serializeObject:object data:data addSignature:true])
return data;
return nil;
}
+ (bool)serializeObject:(id)object data:(NSMutableData *)data addSignature:(bool)addSignature
{
Api1__Serializer *serializer = objc_getAssociatedObject(object, Api1__Serializer_Key);
if (serializer == nil)
return false;
if (addSignature)
{
int32_t value = serializer.constructorSignature;
[data appendBytes:(void *)&value length:4];
}
return serializer.serializeBlock(object, data);
}
+ (id)parseObject:(NSData *)data
{
if (data.length < 4)
return nil;
int32_t constructorSignature = 0;
[data getBytes:(void *)&constructorSignature length:4];
NSUInteger offset = 4;
return [self parseObject:data offset:&offset implicitSignature:constructorSignature metaInfo:nil];
}
+ (id)parseObject:(NSData *)data offset:(NSUInteger *)offset implicitSignature:(int32_t)implicitSignature metaInfo:(id)metaInfo
{
id (^parser)(NSData *data, NSUInteger *offset, id metaInfo) = [self parserByConstructorSignature:implicitSignature];
if (parser)
return parser(data, offset, metaInfo);
return nil;
}
@end
@interface Api1_BuiltinSerializer_Int : Api1__Serializer
@end
@implementation Api1_BuiltinSerializer_Int
- (instancetype)init
{
return [super initWithConstructorSignature:(int32_t)0xA8509BDA serializeBlock:^bool (NSNumber *object, NSMutableData *data)
{
int32_t value = (int32_t)[object intValue];
[data appendBytes:(void *)&value length:4];
return true;
}];
}
@end
@interface Api1_BuiltinSerializer_Long : Api1__Serializer
@end
@implementation Api1_BuiltinSerializer_Long
- (instancetype)init
{
return [super initWithConstructorSignature:(int32_t)0x22076CBA serializeBlock:^bool (NSNumber *object, NSMutableData *data)
{
int64_t value = (int64_t)[object longLongValue];
[data appendBytes:(void *)&value length:8];
return true;
}];
}
@end
@interface Api1_BuiltinSerializer_Double : Api1__Serializer
@end
@implementation Api1_BuiltinSerializer_Double
- (instancetype)init
{
return [super initWithConstructorSignature:(int32_t)0x2210C154 serializeBlock:^bool (NSNumber *object, NSMutableData *data)
{
double value = (double)[object doubleValue];
[data appendBytes:(void *)&value length:8];
return true;
}];
}
@end
@interface Api1_BuiltinSerializer_String : Api1__Serializer
@end
@implementation Api1_BuiltinSerializer_String
- (instancetype)init
{
return [super initWithConstructorSignature:(int32_t)0xB5286E24 serializeBlock:^bool (NSString *object, NSMutableData *data)
{
NSData *value = [object dataUsingEncoding:NSUTF8StringEncoding];
int32_t length = value.length;
int32_t padding = 0;
if (length >= 254)
{
uint8_t tmp = 254;
[data appendBytes:&tmp length:1];
[data appendBytes:(void *)&length length:3];
padding = (((length % 4) == 0 ? length : (length + 4 - (length % 4)))) - length;
}
else
{
[data appendBytes:(void *)&length length:1];
padding = ((((length + 1) % 4) == 0 ? (length + 1) : ((length + 1) + 4 - ((length + 1) % 4)))) - (length + 1);
}
[data appendData:value];
for (int i = 0; i < padding; i++)
{
uint8_t tmp = 0;
[data appendBytes:(void *)&tmp length:1];
}
return true;
}];
}
@end
@interface Api1_BuiltinSerializer_Bytes : Api1__Serializer
@end
@implementation Api1_BuiltinSerializer_Bytes
- (instancetype)init
{
return [super initWithConstructorSignature:(int32_t)0xB5286E24 serializeBlock:^bool (NSData *object, NSMutableData *data)
{
NSData *value = object;
int32_t length = (int32_t)value.length;
int32_t padding = 0;
if (length >= 254)
{
uint8_t tmp = 254;
[data appendBytes:&tmp length:1];
[data appendBytes:(void *)&length length:3];
padding = (((length % 4) == 0 ? length : (length + 4 - (length % 4)))) - length;
}
else
{
[data appendBytes:(void *)&length length:1];
padding = ((((length + 1) % 4) == 0 ? (length + 1) : ((length + 1) + 4 - ((length + 1) % 4)))) - (length + 1);
}
[data appendData:value];
for (int i = 0; i < padding; i++)
{
uint8_t tmp = 0;
[data appendBytes:(void *)&tmp length:1];
}
return true;
}];
}
@end
@interface Api1_BuiltinSerializer_Int128 : Api1__Serializer
@end
@implementation Api1_BuiltinSerializer_Int128
- (instancetype)init
{
return [super initWithConstructorSignature:(int32_t)0x4BB5362B serializeBlock:^bool (NSData *object, NSMutableData *data)
{
if (object.length != 16)
return false;
[data appendData:object];
return true;
}];
}
@end
@interface Api1_BuiltinSerializer_Int256 : Api1__Serializer
@end
@implementation Api1_BuiltinSerializer_Int256
- (instancetype)init
{
return [super initWithConstructorSignature:(int32_t)0x0929C32F serializeBlock:^bool (NSData *object, NSMutableData *data)
{
if (object.length != 32)
return false;
[data appendData:object];
return true;
}];
}
@end
@implementation Api1_FunctionContext
- (instancetype)initWithPayload:(NSData *)payload responseParser:(id (^)(NSData *))responseParser metadata:(id)metadata
{
self = [super init];
if (self != nil)
{
_payload = payload;
_responseParser = [responseParser copy];
_metadata = metadata;
}
return self;
}
@end
@interface Api1_Photo ()
@property (nonatomic, strong) NSNumber * pid;
@end
@interface Api1_Photo_photoEmpty ()
@end
@interface Api1_Photo_photo ()
@property (nonatomic, strong) NSNumber * flags;
@property (nonatomic, strong) NSNumber * accessHash;
@property (nonatomic, strong) NSData * fileReference;
@property (nonatomic, strong) NSNumber * date;
@property (nonatomic, strong) NSArray * sizes;
@property (nonatomic, strong) NSNumber * dcId;
@end
@implementation Api1_Photo
+ (Api1_Photo_photoEmpty *)photoEmptyWithPid:(NSNumber *)pid
{
Api1_Photo_photoEmpty *_object = [[Api1_Photo_photoEmpty alloc] init];
_object.pid = [Api1__Serializer addSerializerToObject:[[Api1__Number alloc] initWithNumber:pid] serializer:[[Api1_BuiltinSerializer_Long alloc] init]];
return _object;
}
+ (Api1_Photo_photo *)photoWithFlags:(NSNumber *)flags pid:(NSNumber *)pid accessHash:(NSNumber *)accessHash fileReference:(NSData *)fileReference date:(NSNumber *)date sizes:(NSArray *)sizes dcId:(NSNumber *)dcId
{
Api1_Photo_photo *_object = [[Api1_Photo_photo alloc] init];
_object.flags = [Api1__Serializer addSerializerToObject:[[Api1__Number alloc] initWithNumber:flags] serializer:[[Api1_BuiltinSerializer_Int alloc] init]];
_object.pid = [Api1__Serializer addSerializerToObject:[[Api1__Number alloc] initWithNumber:pid] serializer:[[Api1_BuiltinSerializer_Long alloc] init]];
_object.accessHash = [Api1__Serializer addSerializerToObject:[[Api1__Number alloc] initWithNumber:accessHash] serializer:[[Api1_BuiltinSerializer_Long alloc] init]];
_object.fileReference = [Api1__Serializer addSerializerToObject:[fileReference copy] serializer:[[Api1_BuiltinSerializer_Bytes alloc] init]];
_object.date = [Api1__Serializer addSerializerToObject:[[Api1__Number alloc] initWithNumber:date] serializer:[[Api1_BuiltinSerializer_Int alloc] init]];
_object.sizes =
({
NSMutableArray *sizes_copy = [[NSMutableArray alloc] initWithCapacity:sizes.count];
for (id sizes_item in sizes)
{
[sizes_copy addObject:sizes_item];
}
id sizes_result = [Api1__Serializer addSerializerToObject:sizes_copy serializer:[[Api1__Serializer alloc] initWithConstructorSignature:(int32_t)0x1cb5c415 serializeBlock:^bool (NSArray *object, NSMutableData *data)
{
int32_t count = (int32_t)object.count;
[data appendBytes:(void *)&count length:4];
for (id item in object)
{
if (![Api1__Environment serializeObject:item data:data addSignature:true])
return false;
}
return true;
}]]; sizes_result;});
_object.dcId = [Api1__Serializer addSerializerToObject:[[Api1__Number alloc] initWithNumber:dcId] serializer:[[Api1_BuiltinSerializer_Int alloc] init]];
return _object;
}
@end
@implementation Api1_Photo_photoEmpty
- (instancetype)init
{
self = [super init];
if (self != nil)
{
[Api1__Serializer addSerializerToObject:self withConstructorSignature:0x2331b22d serializeBlock:^bool (Api1_Photo_photoEmpty *object, NSMutableData *data)
{
if (![Api1__Environment serializeObject:object.pid data:data addSignature:false])
return false;
return true;
}];
}
return self;
}
- (NSString *)description
{
return [[NSString alloc] initWithFormat:@"(photoEmpty id:%@)", self.pid];
}
@end
@implementation Api1_Photo_photo
- (instancetype)init
{
self = [super init];
if (self != nil)
{
[Api1__Serializer addSerializerToObject:self withConstructorSignature:0xd07504a5 serializeBlock:^bool (Api1_Photo_photo *object, NSMutableData *data)
{
if (![Api1__Environment serializeObject:object.flags data:data addSignature:false])
return false;
if (![Api1__Environment serializeObject:object.pid data:data addSignature:false])
return false;
if (![Api1__Environment serializeObject:object.accessHash data:data addSignature:false])
return false;
if (![Api1__Environment serializeObject:object.fileReference data:data addSignature:false])
return false;
if (![Api1__Environment serializeObject:object.date data:data addSignature:false])
return false;
if (![Api1__Environment serializeObject:object.sizes data:data addSignature:true])
return false;
if (![Api1__Environment serializeObject:object.dcId data:data addSignature:false])
return false;
return true;
}];
}
return self;
}
- (NSString *)description
{