Files
firebase-ios-sdk/GoogleDataTransport/GDTCORLibrary/GDTCORStoredEvent.m
T

95 lines
3.3 KiB
Objective-C
Raw Normal View History

2019-04-12 19:27:00 -07:00
/*
* Copyright 2019 Google
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
2019-09-09 15:21:29 -07:00
#import <GoogleDataTransport/GDTCORStoredEvent.h>
2019-04-12 19:27:00 -07:00
2019-09-09 15:21:29 -07:00
#import <GoogleDataTransport/GDTCORClock.h>
2019-04-12 19:27:00 -07:00
2019-09-09 15:21:29 -07:00
#import "GDTCORLibrary/Private/GDTCORStorage_Private.h"
2019-09-09 15:21:29 -07:00
@implementation GDTCORStoredEvent
2019-04-12 19:27:00 -07:00
2019-09-09 15:21:29 -07:00
- (instancetype)initWithEvent:(GDTCOREvent *)event
dataFuture:(nonnull GDTCORDataFuture *)dataFuture {
2019-04-12 19:27:00 -07:00
self = [super init];
if (self) {
_dataFuture = dataFuture;
2019-04-12 19:27:00 -07:00
_mappingID = event.mappingID;
_target = @(event.target);
_qosTier = event.qosTier;
_clockSnapshot = event.clockSnapshot;
_customPrioritizationParams = event.customPrioritizationParams;
}
return self;
}
#pragma mark - NSSecureCoding
/** Coding key for the dataFuture ivar. */
2019-09-09 15:21:29 -07:00
static NSString *kDataFutureKey = @"GDTCORStoredEventDataFutureKey";
2019-04-12 19:27:00 -07:00
/** Coding key for mappingID ivar. */
2019-09-09 15:21:29 -07:00
static NSString *kMappingIDKey = @"GDTCORStoredEventMappingIDKey";
2019-04-12 19:27:00 -07:00
/** Coding key for target ivar. */
2019-09-09 15:21:29 -07:00
static NSString *kTargetKey = @"GDTCORStoredEventTargetKey";
2019-04-12 19:27:00 -07:00
/** Coding key for qosTier ivar. */
2019-09-09 15:21:29 -07:00
static NSString *kQosTierKey = @"GDTCORStoredEventQosTierKey";
2019-04-12 19:27:00 -07:00
/** Coding key for clockSnapshot ivar. */
2019-09-09 15:21:29 -07:00
static NSString *kClockSnapshotKey = @"GDTCORStoredEventClockSnapshotKey";
2019-04-12 19:27:00 -07:00
/** Coding key for customPrioritizationParams ivar. */
2019-09-09 15:21:29 -07:00
static NSString *kCustomPrioritizationParamsKey = @"GDTCORStoredEventcustomPrioritizationParamsKey";
2019-04-12 19:27:00 -07:00
+ (BOOL)supportsSecureCoding {
return YES;
}
- (void)encodeWithCoder:(nonnull NSCoder *)aCoder {
[aCoder encodeObject:_dataFuture forKey:kDataFutureKey];
2019-04-12 19:27:00 -07:00
[aCoder encodeObject:_mappingID forKey:kMappingIDKey];
[aCoder encodeObject:_target forKey:kTargetKey];
[aCoder encodeObject:@(_qosTier) forKey:kQosTierKey];
[aCoder encodeObject:_clockSnapshot forKey:kClockSnapshotKey];
[aCoder encodeObject:_customPrioritizationParams forKey:kCustomPrioritizationParamsKey];
}
- (nullable instancetype)initWithCoder:(nonnull NSCoder *)aDecoder {
self = [self init];
if (self) {
2019-09-09 15:21:29 -07:00
_dataFuture = [aDecoder decodeObjectOfClass:[GDTCORDataFuture class] forKey:kDataFutureKey];
2019-04-12 19:27:00 -07:00
_mappingID = [aDecoder decodeObjectOfClass:[NSString class] forKey:kMappingIDKey];
_target = [aDecoder decodeObjectOfClass:[NSNumber class] forKey:kTargetKey];
NSNumber *qosTier = [aDecoder decodeObjectOfClass:[NSNumber class] forKey:kQosTierKey];
_qosTier = [qosTier intValue];
2019-09-09 15:21:29 -07:00
_clockSnapshot = [aDecoder decodeObjectOfClass:[GDTCORClock class] forKey:kClockSnapshotKey];
2019-04-12 19:27:00 -07:00
_customPrioritizationParams = [aDecoder decodeObjectOfClass:[NSDictionary class]
forKey:kCustomPrioritizationParamsKey];
}
return self;
}
2019-09-09 15:21:29 -07:00
- (BOOL)isEqual:(GDTCORStoredEvent *)other {
2019-04-12 19:27:00 -07:00
return [self hash] == [other hash];
}
- (NSUInteger)hash {
return [_dataFuture hash] ^ [_mappingID hash] ^ [_target hash] ^ [_clockSnapshot hash] ^ _qosTier;
2019-04-12 19:27:00 -07:00
}
@end