11#import " ARTAnnotation.h"
22#import " ARTJsonEncoder.h"
33#import " ARTJsonLikeEncoder.h"
4- #import " ARTBaseMessage +Private.h"
4+ #import " ARTAnnotation +Private.h"
55#import " ARTNSArray+ARTFunctional.h"
66#import " ARTInternalLog.h"
77
88@implementation ARTAnnotation
99
10- - (instancetype )initWithType : (NSString *)type data : (id )data {
10+ - (instancetype )initWithId : (NSString *)annotationId
11+ action : (ARTAnnotationAction)action
12+ clientId : (NSString *)clientId
13+ name : (NSString *)name
14+ count : (NSNumber *)count
15+ data : (id )data
16+ encoding : (NSString *)encoding
17+ timestamp : (NSDate *)timestamp
18+ serial : (NSString *)serial
19+ messageSerial : (NSString *)messageSerial
20+ type : (NSString *)type
21+ extras : (id <ARTJsonCompatible>)extras {
1122 if (self = [self init ]) {
12- self. type = [type copy ] ;
13- if (data) {
14- self. data = data ;
15- self. encoding = @" " ;
16- }
17- }
18- return self ;
19- }
20-
21- - ( instancetype ) initWithType : ( NSString *) type data : ( id ) data clientId : ( NSString *) clientId {
22- if (self = [ self initWithType: type data: data]) {
23- self. clientId = clientId ;
23+ _id = annotationId ;
24+ _action = action;
25+ _clientId = clientId ;
26+ _name = name ;
27+ _count = count;
28+ _data = data;
29+ _encoding = encoding ;
30+ _timestamp = timestamp;
31+ _serial = serial;
32+ _messageSerial = messageSerial;
33+ _type = type;
34+ _extras = extras ;
2435 }
2536 return self;
2637}
@@ -29,44 +40,61 @@ - (NSString *)description {
2940 NSMutableString *description = [[super description ] mutableCopy ];
3041 [description deleteCharactersInRange: NSMakeRange (description.length - (description.length>2 ? 2: 0 ), 2 )];
3142 [description appendFormat: @" ,\n " ];
43+ [description appendFormat: @" id: %@ ,\n " , self .id ];
3244 [description appendFormat: @" action: %@ \n " , ARTAnnotationActionToStr (self .action)];
45+ [description appendFormat: @" clientId: %@ ,\n " , self .clientId];
46+ [description appendFormat: @" name: %@ \n " , self .name];
47+ [description appendFormat: @" count: %@ \n " , self .count];
48+ [description appendFormat: @" data: %@ \n " , self .data];
49+ [description appendFormat: @" encoding: %@ ,\n " , self .encoding];
50+ [description appendFormat: @" timestamp: %@ ,\n " , self .timestamp];
3351 [description appendFormat: @" serial: %@ \n " , self .serial];
3452 [description appendFormat: @" messageSerial: %@ \n " , self .messageSerial];
3553 [description appendFormat: @" type: %@ \n " , self .type];
36- [description appendFormat: @" name: %@ \n " , self .name];
37- [description appendFormat: @" count: %@ \n " , self .count];
54+ [description appendFormat: @" extras: %@ \n " , self .extras];
3855 [description appendFormat: @" }" ];
3956 return description;
4057}
4158
4259- (id )copyWithZone : (NSZone *)zone {
43- ARTAnnotation *annotation = [super copyWithZone: zone];
44- annotation.action = self.action ;
45- annotation.serial = self.serial ;
46- annotation.messageSerial = self.messageSerial ;
47- annotation.type = self.type ;
48- annotation.name = self.name ;
49- annotation.count = self.count ;
60+ ARTAnnotation *annotation = [[self .class allocWithZone: zone] init ];
61+ annotation->_id = self.id ;
62+ annotation->_clientId = self.clientId ;
63+ annotation->_timestamp = self.timestamp ;
64+ annotation->_data = [self .data copy ];
65+ annotation->_extras = self.extras ;
66+ annotation->_encoding = self.encoding ;
67+ annotation->_action = self.action ;
68+ annotation->_serial = self.serial ;
69+ annotation->_messageSerial = self.messageSerial ;
70+ annotation->_type = self.type ;
71+ annotation->_name = self.name ;
72+ annotation->_count = self.count ;
5073 return annotation;
5174}
5275
53- - (NSInteger )messageSize {
54- // spec is not clear here, issue - https://github.com/ably/specification/issues/336
55- return [super messageSize ];
56- }
57-
58- @end
59-
60- @implementation ARTAnnotation (Decoding)
61-
62- + (instancetype )fromEncoded : (NSDictionary *)jsonObject channelOptions : (ARTChannelOptions *)options error : (NSError **)error {
63- // TODO: implement
64- return nil ;
76+ - (id )decodeWithEncoder : (ARTDataEncoder*)encoder error : (NSError **)error {
77+ ARTDataEncoderOutput *decoded = [encoder decode: self .data encoding: self .encoding];
78+ if (decoded.errorInfo && error) {
79+ *error = [NSError errorWithDomain: ARTAblyErrorDomain code: decoded.errorInfo.code userInfo: @{NSLocalizedDescriptionKey : @" decoding failed" ,
80+ NSLocalizedFailureReasonErrorKey : decoded.errorInfo .message }];
81+ }
82+ id ret = [self copy ];
83+ ((ARTAnnotation *)ret)->_data = decoded.data ;
84+ ((ARTAnnotation *)ret)->_encoding = decoded.encoding ;
85+ return ret;
6586}
6687
67- + (NSArray <ARTMessage *> *)fromEncodedArray : (NSArray <NSDictionary *> *)jsonArray channelOptions : (ARTChannelOptions *)options error : (NSError **)error {
68- // TODO: implement
69- return nil ;
88+ - (id )encodeWithEncoder : (ARTDataEncoder*)encoder error : (NSError **)error {
89+ ARTDataEncoderOutput *encoded = [encoder encode: self .data];
90+ if (encoded.errorInfo && error) {
91+ *error = [NSError errorWithDomain: ARTAblyErrorDomain code: 0 userInfo: @{NSLocalizedDescriptionKey : @" encoding failed" ,
92+ NSLocalizedFailureReasonErrorKey : encoded.errorInfo .message }];
93+ }
94+ id ret = [self copy ];
95+ ((ARTAnnotation *)ret)->_data = encoded.data ;
96+ ((ARTAnnotation *)ret)->_encoding = [NSString artAddEncoding: encoded.encoding toString: self .encoding];
97+ return ret;
7098}
7199
72100@end
@@ -83,15 +111,7 @@ + (instancetype)fromEncoded:(NSDictionary *)jsonObject channelOptions:(ARTChanne
83111
84112#pragma mark - ARTEvent
85113
86- @implementation ARTEvent (AnnotationAction)
87-
88- - (instancetype )initWithAnnotationAction : (ARTAnnotationAction)value {
89- return [self initWithString: [NSString stringWithFormat: @" ARTAnnotation%@ " , ARTAnnotationActionToStr (value)]];
90- }
91-
92- + (instancetype )newWithAnnotationAction : (ARTAnnotationAction)value {
93- return [[self alloc ] initWithAnnotationAction: value];
94- }
114+ @implementation ARTEvent (AnnotationType)
95115
96116- (instancetype )initWithAnnotationType : (NSString *)type {
97117 return [self initWithString: [NSString stringWithFormat: @" ARTAnnotation:%@ " , type]];
0 commit comments