GDTCORStoredEvent.m 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright 2019 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <GoogleDataTransport/GDTCORStoredEvent.h>
  17. #import <GoogleDataTransport/GDTCORClock.h>
  18. #import "GDTCORLibrary/Private/GDTCORStorage_Private.h"
  19. @implementation GDTCORStoredEvent
  20. - (instancetype)initWithEvent:(GDTCOREvent *)event
  21. dataFuture:(nonnull GDTCORDataFuture *)dataFuture {
  22. self = [super init];
  23. if (self) {
  24. _dataFuture = dataFuture;
  25. _mappingID = event.mappingID;
  26. _target = @(event.target);
  27. _qosTier = event.qosTier;
  28. _clockSnapshot = event.clockSnapshot;
  29. _customPrioritizationParams = event.customPrioritizationParams;
  30. }
  31. return self;
  32. }
  33. #pragma mark - NSSecureCoding
  34. /** Coding key for the dataFuture ivar. */
  35. static NSString *kDataFutureKey = @"GDTCORStoredEventDataFutureKey";
  36. /** Coding key for mappingID ivar. */
  37. static NSString *kMappingIDKey = @"GDTCORStoredEventMappingIDKey";
  38. /** Coding key for target ivar. */
  39. static NSString *kTargetKey = @"GDTCORStoredEventTargetKey";
  40. /** Coding key for qosTier ivar. */
  41. static NSString *kQosTierKey = @"GDTCORStoredEventQosTierKey";
  42. /** Coding key for clockSnapshot ivar. */
  43. static NSString *kClockSnapshotKey = @"GDTCORStoredEventClockSnapshotKey";
  44. /** Coding key for customPrioritizationParams ivar. */
  45. static NSString *kCustomPrioritizationParamsKey = @"GDTCORStoredEventcustomPrioritizationParamsKey";
  46. + (BOOL)supportsSecureCoding {
  47. return YES;
  48. }
  49. - (void)encodeWithCoder:(nonnull NSCoder *)aCoder {
  50. [aCoder encodeObject:_dataFuture forKey:kDataFutureKey];
  51. [aCoder encodeObject:_mappingID forKey:kMappingIDKey];
  52. [aCoder encodeObject:_target forKey:kTargetKey];
  53. [aCoder encodeObject:@(_qosTier) forKey:kQosTierKey];
  54. [aCoder encodeObject:_clockSnapshot forKey:kClockSnapshotKey];
  55. [aCoder encodeObject:_customPrioritizationParams forKey:kCustomPrioritizationParamsKey];
  56. }
  57. - (nullable instancetype)initWithCoder:(nonnull NSCoder *)aDecoder {
  58. self = [self init];
  59. if (self) {
  60. _dataFuture = [aDecoder decodeObjectOfClass:[GDTCORDataFuture class] forKey:kDataFutureKey];
  61. _mappingID = [aDecoder decodeObjectOfClass:[NSString class] forKey:kMappingIDKey];
  62. _target = [aDecoder decodeObjectOfClass:[NSNumber class] forKey:kTargetKey];
  63. NSNumber *qosTier = [aDecoder decodeObjectOfClass:[NSNumber class] forKey:kQosTierKey];
  64. _qosTier = [qosTier intValue];
  65. _clockSnapshot = [aDecoder decodeObjectOfClass:[GDTCORClock class] forKey:kClockSnapshotKey];
  66. _customPrioritizationParams = [aDecoder decodeObjectOfClass:[NSDictionary class]
  67. forKey:kCustomPrioritizationParamsKey];
  68. }
  69. return self;
  70. }
  71. - (BOOL)isEqual:(GDTCORStoredEvent *)other {
  72. return [self hash] == [other hash];
  73. }
  74. - (NSUInteger)hash {
  75. return [_dataFuture hash] ^ [_mappingID hash] ^ [_target hash] ^ [_clockSnapshot hash] ^ _qosTier;
  76. }
  77. @end