GDTCORDataFuture.m 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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/GDTCORDataFuture.h>
  17. @implementation GDTCORDataFuture
  18. - (instancetype)initWithFileURL:(NSURL *)fileURL {
  19. self = [super init];
  20. if (self) {
  21. _fileURL = fileURL;
  22. }
  23. return self;
  24. }
  25. - (BOOL)isEqual:(id)object {
  26. return [self hash] == [object hash];
  27. }
  28. - (NSUInteger)hash {
  29. // In reality, only one of these should be populated.
  30. return [_fileURL hash] ^ [_originalData hash];
  31. }
  32. #pragma mark - NSSecureCoding
  33. /** Coding key for _fileURL ivar. */
  34. static NSString *kGDTCORDataFutureFileURLKey = @"GDTCORDataFutureFileURLKey";
  35. /** Coding key for _data ivar. */
  36. static NSString *kGDTCORDataFutureDataKey = @"GDTCORDataFutureDataKey";
  37. + (BOOL)supportsSecureCoding {
  38. return YES;
  39. }
  40. - (void)encodeWithCoder:(nonnull NSCoder *)aCoder {
  41. [aCoder encodeObject:_fileURL forKey:kGDTCORDataFutureFileURLKey];
  42. [aCoder encodeObject:_originalData forKey:kGDTCORDataFutureDataKey];
  43. }
  44. - (nullable instancetype)initWithCoder:(nonnull NSCoder *)aDecoder {
  45. self = [self init];
  46. if (self) {
  47. _fileURL = [aDecoder decodeObjectOfClass:[NSURL class] forKey:kGDTCORDataFutureFileURLKey];
  48. _originalData = [aDecoder decodeObjectOfClass:[NSData class] forKey:kGDTCORDataFutureDataKey];
  49. }
  50. return self;
  51. }
  52. @end