LookinConnectionResponseAttachment.m 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #ifdef SHOULD_COMPILE_LOOKIN_SERVER
  2. //
  3. // LookinConnectionResponse.m
  4. // Lookin
  5. //
  6. // Created by Li Kai on 2019/1/15.
  7. // https://lookin.work
  8. //
  9. #import "LookinConnectionResponseAttachment.h"
  10. #import "LookinDefines.h"
  11. @interface LookinConnectionResponseAttachment ()
  12. @end
  13. @implementation LookinConnectionResponseAttachment
  14. - (void)encodeWithCoder:(NSCoder *)aCoder {
  15. [super encodeWithCoder:aCoder];
  16. [aCoder encodeInt:self.lookinServerVersion forKey:@"lookinServerVersion"];
  17. [aCoder encodeObject:self.error forKey:@"error"];
  18. [aCoder encodeObject:@(self.dataTotalCount) forKey:@"dataTotalCount"];
  19. [aCoder encodeObject:@(self.currentDataCount) forKey:@"currentDataCount"];
  20. [aCoder encodeBool:self.lookinServerIsExprimental forKey:@"lookinServerIsExprimental"];
  21. [aCoder encodeBool:self.appIsInBackground forKey:@"appIsInBackground"];
  22. }
  23. - (instancetype)init {
  24. if (self = [super init]) {
  25. self.lookinServerVersion = LOOKIN_SERVER_VERSION;
  26. self.dataTotalCount = 0;
  27. self.lookinServerIsExprimental = LOOKIN_SERVER_IS_EXPERIMENTAL;
  28. }
  29. return self;
  30. }
  31. - (instancetype)initWithCoder:(NSCoder *)aDecoder {
  32. if (self = [super initWithCoder:aDecoder]) {
  33. self.lookinServerVersion = [aDecoder decodeIntForKey:@"lookinServerVersion"];
  34. self.lookinServerIsExprimental = [aDecoder decodeBoolForKey:@"lookinServerIsExprimental"];
  35. self.error = [aDecoder decodeObjectForKey:@"error"];
  36. self.dataTotalCount = [[aDecoder decodeObjectForKey:@"dataTotalCount"] unsignedIntegerValue];
  37. self.currentDataCount = [[aDecoder decodeObjectForKey:@"currentDataCount"] unsignedIntegerValue];
  38. self.appIsInBackground = [aDecoder decodeBoolForKey:@"appIsInBackground"];
  39. }
  40. return self;
  41. }
  42. + (BOOL)supportsSecureCoding {
  43. return YES;
  44. }
  45. + (instancetype)attachmentWithError:(NSError *)error {
  46. LookinConnectionResponseAttachment *attachment = [LookinConnectionResponseAttachment new];
  47. attachment.error = error;
  48. return attachment;
  49. }
  50. @end
  51. #endif /* SHOULD_COMPILE_LOOKIN_SERVER */