| OLD | NEW |
| 1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
| 2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
| 3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
| 4 // | 4 // |
| 5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
| 6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
| 7 // met: | 7 // met: |
| 8 // | 8 // |
| 9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
| 10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 #import "GPBCodedInputStream_PackagePrivate.h" | 37 #import "GPBCodedInputStream_PackagePrivate.h" |
| 38 #import "GPBCodedOutputStream_PackagePrivate.h" | 38 #import "GPBCodedOutputStream_PackagePrivate.h" |
| 39 #import "GPBDescriptor_PackagePrivate.h" | 39 #import "GPBDescriptor_PackagePrivate.h" |
| 40 #import "GPBDictionary_PackagePrivate.h" | 40 #import "GPBDictionary_PackagePrivate.h" |
| 41 #import "GPBExtensionInternals.h" | 41 #import "GPBExtensionInternals.h" |
| 42 #import "GPBExtensionRegistry.h" | 42 #import "GPBExtensionRegistry.h" |
| 43 #import "GPBRootObject_PackagePrivate.h" | 43 #import "GPBRootObject_PackagePrivate.h" |
| 44 #import "GPBUnknownFieldSet_PackagePrivate.h" | 44 #import "GPBUnknownFieldSet_PackagePrivate.h" |
| 45 #import "GPBUtilities_PackagePrivate.h" | 45 #import "GPBUtilities_PackagePrivate.h" |
| 46 | 46 |
| 47 // Direct access is use for speed, to avoid even internally declaring things |
| 48 // read/write, etc. The warning is enabled in the project to ensure code calling |
| 49 // protos can turn on -Wdirect-ivar-access without issues. |
| 50 #pragma clang diagnostic push |
| 51 #pragma clang diagnostic ignored "-Wdirect-ivar-access" |
| 52 |
| 47 NSString *const GPBMessageErrorDomain = | 53 NSString *const GPBMessageErrorDomain = |
| 48 GPBNSStringifySymbol(GPBMessageErrorDomain); | 54 GPBNSStringifySymbol(GPBMessageErrorDomain); |
| 49 | 55 |
| 50 #ifdef DEBUG | 56 NSString *const GPBErrorReasonKey = @"Reason"; |
| 51 NSString *const GPBExceptionMessageKey = | |
| 52 GPBNSStringifySymbol(GPBExceptionMessage); | |
| 53 #endif // DEBUG | |
| 54 | 57 |
| 55 static NSString *const kGPBDataCoderKey = @"GPBData"; | 58 static NSString *const kGPBDataCoderKey = @"GPBData"; |
| 56 | 59 |
| 57 // | 60 // |
| 58 // PLEASE REMEMBER: | 61 // PLEASE REMEMBER: |
| 59 // | 62 // |
| 60 // This is the base class for *all* messages generated, so any selector defined, | 63 // This is the base class for *all* messages generated, so any selector defined, |
| 61 // *public* or *private* could end up colliding with a proto message field. So | 64 // *public* or *private* could end up colliding with a proto message field. So |
| 62 // avoid using selectors that could match a property, use C functions to hide | 65 // avoid using selectors that could match a property, use C functions to hide |
| 63 // them, etc. | 66 // them, etc. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 88 GPBMessage *autocreator) | 91 GPBMessage *autocreator) |
| 89 __attribute__((ns_returns_retained)); | 92 __attribute__((ns_returns_retained)); |
| 90 static id GetOrCreateMapIvarWithField(GPBMessage *self, | 93 static id GetOrCreateMapIvarWithField(GPBMessage *self, |
| 91 GPBFieldDescriptor *field, | 94 GPBFieldDescriptor *field, |
| 92 GPBFileSyntax syntax); | 95 GPBFileSyntax syntax); |
| 93 static id GetMapIvarWithField(GPBMessage *self, GPBFieldDescriptor *field); | 96 static id GetMapIvarWithField(GPBMessage *self, GPBFieldDescriptor *field); |
| 94 static NSMutableDictionary *CloneExtensionMap(NSDictionary *extensionMap, | 97 static NSMutableDictionary *CloneExtensionMap(NSDictionary *extensionMap, |
| 95 NSZone *zone) | 98 NSZone *zone) |
| 96 __attribute__((ns_returns_retained)); | 99 __attribute__((ns_returns_retained)); |
| 97 | 100 |
| 101 #ifdef DEBUG |
| 98 static NSError *MessageError(NSInteger code, NSDictionary *userInfo) { | 102 static NSError *MessageError(NSInteger code, NSDictionary *userInfo) { |
| 99 return [NSError errorWithDomain:GPBMessageErrorDomain | 103 return [NSError errorWithDomain:GPBMessageErrorDomain |
| 100 code:code | 104 code:code |
| 101 userInfo:userInfo]; | 105 userInfo:userInfo]; |
| 102 } | 106 } |
| 107 #endif |
| 103 | 108 |
| 104 static NSError *MessageErrorWithReason(NSInteger code, NSString *reason) { | 109 static NSError *ErrorFromException(NSException *exception) { |
| 105 NSDictionary *userInfo = nil; | 110 NSError *error = nil; |
| 106 if ([reason length]) { | 111 |
| 107 userInfo = @{ @"Reason" : reason }; | 112 if ([exception.name isEqual:GPBCodedInputStreamException]) { |
| 113 NSDictionary *exceptionInfo = exception.userInfo; |
| 114 error = exceptionInfo[GPBCodedInputStreamUnderlyingErrorKey]; |
| 108 } | 115 } |
| 109 return MessageError(code, userInfo); | 116 |
| 117 if (!error) { |
| 118 NSString *reason = exception.reason; |
| 119 NSDictionary *userInfo = nil; |
| 120 if ([reason length]) { |
| 121 userInfo = @{ GPBErrorReasonKey : reason }; |
| 122 } |
| 123 |
| 124 error = [NSError errorWithDomain:GPBMessageErrorDomain |
| 125 code:GPBMessageErrorCodeOther |
| 126 userInfo:userInfo]; |
| 127 } |
| 128 return error; |
| 110 } | 129 } |
| 111 | 130 |
| 112 | |
| 113 static void CheckExtension(GPBMessage *self, | 131 static void CheckExtension(GPBMessage *self, |
| 114 GPBExtensionDescriptor *extension) { | 132 GPBExtensionDescriptor *extension) { |
| 115 if ([self class] != extension.containingMessageClass) { | 133 if ([self class] != extension.containingMessageClass) { |
| 116 [NSException | 134 [NSException |
| 117 raise:NSInvalidArgumentException | 135 raise:NSInvalidArgumentException |
| 118 format:@"Extension %@ used on wrong class (%@ instead of %@)", | 136 format:@"Extension %@ used on wrong class (%@ instead of %@)", |
| 119 extension.singletonName, | 137 extension.singletonName, |
| 120 [self class], extension.containingMessageClass]; | 138 [self class], extension.containingMessageClass]; |
| 121 } | 139 } |
| 122 } | 140 } |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 } | 705 } |
| 688 } | 706 } |
| 689 NSCAssert(NO, @"Unknown autocreated %@ for %@.", [dictionary class], self); | 707 NSCAssert(NO, @"Unknown autocreated %@ for %@.", [dictionary class], self); |
| 690 } | 708 } |
| 691 | 709 |
| 692 void GPBClearMessageAutocreator(GPBMessage *self) { | 710 void GPBClearMessageAutocreator(GPBMessage *self) { |
| 693 if ((self == nil) || !self->autocreator_) { | 711 if ((self == nil) || !self->autocreator_) { |
| 694 return; | 712 return; |
| 695 } | 713 } |
| 696 | 714 |
| 697 #if DEBUG && !defined(NS_BLOCK_ASSERTIONS) | 715 #if defined(DEBUG) && DEBUG && !defined(NS_BLOCK_ASSERTIONS) |
| 698 // Either the autocreator must have its "has" flag set to YES, or it must be | 716 // Either the autocreator must have its "has" flag set to YES, or it must be |
| 699 // NO and not equal to ourselves. | 717 // NO and not equal to ourselves. |
| 700 BOOL autocreatorHas = | 718 BOOL autocreatorHas = |
| 701 (self->autocreatorField_ | 719 (self->autocreatorField_ |
| 702 ? GPBGetHasIvarField(self->autocreator_, self->autocreatorField_) | 720 ? GPBGetHasIvarField(self->autocreator_, self->autocreatorField_) |
| 703 : [self->autocreator_ hasExtension:self->autocreatorExtension_]); | 721 : [self->autocreator_ hasExtension:self->autocreatorExtension_]); |
| 704 GPBMessage *autocreatorFieldValue = | 722 GPBMessage *autocreatorFieldValue = |
| 705 (self->autocreatorField_ | 723 (self->autocreatorField_ |
| 706 ? GPBGetObjectIvarWithFieldNoAutocreate(self->autocreator_, | 724 ? GPBGetObjectIvarWithFieldNoAutocreate(self->autocreator_, |
| 707 self->autocreatorField_) | 725 self->autocreatorField_) |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 @try { | 827 @try { |
| 810 [self mergeFromData:data extensionRegistry:extensionRegistry]; | 828 [self mergeFromData:data extensionRegistry:extensionRegistry]; |
| 811 if (errorPtr) { | 829 if (errorPtr) { |
| 812 *errorPtr = nil; | 830 *errorPtr = nil; |
| 813 } | 831 } |
| 814 } | 832 } |
| 815 @catch (NSException *exception) { | 833 @catch (NSException *exception) { |
| 816 [self release]; | 834 [self release]; |
| 817 self = nil; | 835 self = nil; |
| 818 if (errorPtr) { | 836 if (errorPtr) { |
| 819 *errorPtr = MessageErrorWithReason(GPBMessageErrorCodeMalformedData, | 837 *errorPtr = ErrorFromException(exception); |
| 820 exception.reason); | |
| 821 } | 838 } |
| 822 } | 839 } |
| 823 #ifdef DEBUG | 840 #ifdef DEBUG |
| 824 if (self && !self.initialized) { | 841 if (self && !self.initialized) { |
| 825 [self release]; | 842 [self release]; |
| 826 self = nil; | 843 self = nil; |
| 827 if (errorPtr) { | 844 if (errorPtr) { |
| 828 *errorPtr = MessageError(GPBMessageErrorCodeMissingRequiredField, nil); | 845 *errorPtr = MessageError(GPBMessageErrorCodeMissingRequiredField, nil); |
| 829 } | 846 } |
| 830 } | 847 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 841 @try { | 858 @try { |
| 842 [self mergeFromCodedInputStream:input extensionRegistry:extensionRegistry]
; | 859 [self mergeFromCodedInputStream:input extensionRegistry:extensionRegistry]
; |
| 843 if (errorPtr) { | 860 if (errorPtr) { |
| 844 *errorPtr = nil; | 861 *errorPtr = nil; |
| 845 } | 862 } |
| 846 } | 863 } |
| 847 @catch (NSException *exception) { | 864 @catch (NSException *exception) { |
| 848 [self release]; | 865 [self release]; |
| 849 self = nil; | 866 self = nil; |
| 850 if (errorPtr) { | 867 if (errorPtr) { |
| 851 *errorPtr = MessageErrorWithReason(GPBMessageErrorCodeMalformedData, | 868 *errorPtr = ErrorFromException(exception); |
| 852 exception.reason); | |
| 853 } | 869 } |
| 854 } | 870 } |
| 855 #ifdef DEBUG | 871 #ifdef DEBUG |
| 856 if (self && !self.initialized) { | 872 if (self && !self.initialized) { |
| 857 [self release]; | 873 [self release]; |
| 858 self = nil; | 874 self = nil; |
| 859 if (errorPtr) { | 875 if (errorPtr) { |
| 860 *errorPtr = MessageError(GPBMessageErrorCodeMissingRequiredField, nil); | 876 *errorPtr = MessageError(GPBMessageErrorCodeMissingRequiredField, nil); |
| 861 } | 877 } |
| 862 } | 878 } |
| (...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1729 dispatch_semaphore_signal(readOnlySemaphore_); | 1745 dispatch_semaphore_signal(readOnlySemaphore_); |
| 1730 return value; | 1746 return value; |
| 1731 } | 1747 } |
| 1732 | 1748 |
| 1733 - (id)getExistingExtension:(GPBExtensionDescriptor *)extension { | 1749 - (id)getExistingExtension:(GPBExtensionDescriptor *)extension { |
| 1734 // This is an internal method so we don't need to call CheckExtension(). | 1750 // This is an internal method so we don't need to call CheckExtension(). |
| 1735 return [extensionMap_ objectForKey:extension]; | 1751 return [extensionMap_ objectForKey:extension]; |
| 1736 } | 1752 } |
| 1737 | 1753 |
| 1738 - (BOOL)hasExtension:(GPBExtensionDescriptor *)extension { | 1754 - (BOOL)hasExtension:(GPBExtensionDescriptor *)extension { |
| 1739 #if DEBUG | 1755 #if defined(DEBUG) && DEBUG |
| 1740 CheckExtension(self, extension); | 1756 CheckExtension(self, extension); |
| 1741 #endif // DEBUG | 1757 #endif // DEBUG |
| 1742 return nil != [extensionMap_ objectForKey:extension]; | 1758 return nil != [extensionMap_ objectForKey:extension]; |
| 1743 } | 1759 } |
| 1744 | 1760 |
| 1745 - (NSArray *)extensionsCurrentlySet { | 1761 - (NSArray *)extensionsCurrentlySet { |
| 1746 return [extensionMap_ allKeys]; | 1762 return [extensionMap_ allKeys]; |
| 1747 } | 1763 } |
| 1748 | 1764 |
| 1749 - (void)writeExtensionsToCodedOutputStream:(GPBCodedOutputStream *)output | 1765 - (void)writeExtensionsToCodedOutputStream:(GPBCodedOutputStream *)output |
| 1750 range:(GPBExtensionRange)range { | 1766 range:(GPBExtensionRange)range { |
| 1751 NSArray *sortedExtensions = [[extensionMap_ allKeys] | 1767 NSArray *sortedExtensions = [[extensionMap_ allKeys] |
| 1752 sortedArrayUsingSelector:@selector(compareByFieldNumber:)]; | 1768 sortedArrayUsingSelector:@selector(compareByFieldNumber:)]; |
| 1753 uint32_t start = range.start; | 1769 uint32_t start = range.start; |
| 1754 uint32_t end = range.end; | 1770 uint32_t end = range.end; |
| 1755 for (GPBExtensionDescriptor *extension in sortedExtensions) { | 1771 for (GPBExtensionDescriptor *extension in sortedExtensions) { |
| 1756 uint32_t fieldNumber = extension.fieldNumber; | 1772 uint32_t fieldNumber = extension.fieldNumber; |
| 1757 if (fieldNumber >= start && fieldNumber < end) { | 1773 if (fieldNumber >= start && fieldNumber < end) { |
| 1758 id value = [extensionMap_ objectForKey:extension]; | 1774 id value = [extensionMap_ objectForKey:extension]; |
| 1759 GPBWriteExtensionValueToOutputStream(extension, value, output); | 1775 GPBWriteExtensionValueToOutputStream(extension, value, output); |
| 1760 } | 1776 } |
| 1761 } | 1777 } |
| 1762 } | 1778 } |
| 1763 | 1779 |
| 1764 - (NSArray *)sortedExtensionsInUse { | |
| 1765 return [[extensionMap_ allKeys] | |
| 1766 sortedArrayUsingSelector:@selector(compareByFieldNumber:)]; | |
| 1767 } | |
| 1768 | |
| 1769 - (void)setExtension:(GPBExtensionDescriptor *)extension value:(id)value { | 1780 - (void)setExtension:(GPBExtensionDescriptor *)extension value:(id)value { |
| 1770 if (!value) { | 1781 if (!value) { |
| 1771 [self clearExtension:extension]; | 1782 [self clearExtension:extension]; |
| 1772 return; | 1783 return; |
| 1773 } | 1784 } |
| 1774 | 1785 |
| 1775 CheckExtension(self, extension); | 1786 CheckExtension(self, extension); |
| 1776 | 1787 |
| 1777 if (extension.repeated) { | 1788 if (extension.repeated) { |
| 1778 [NSException raise:NSInvalidArgumentException | 1789 [NSException raise:NSInvalidArgumentException |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1915 @try { | 1926 @try { |
| 1916 [message mergeDelimitedFromCodedInputStream:input | 1927 [message mergeDelimitedFromCodedInputStream:input |
| 1917 extensionRegistry:extensionRegistry]; | 1928 extensionRegistry:extensionRegistry]; |
| 1918 if (errorPtr) { | 1929 if (errorPtr) { |
| 1919 *errorPtr = nil; | 1930 *errorPtr = nil; |
| 1920 } | 1931 } |
| 1921 } | 1932 } |
| 1922 @catch (NSException *exception) { | 1933 @catch (NSException *exception) { |
| 1923 message = nil; | 1934 message = nil; |
| 1924 if (errorPtr) { | 1935 if (errorPtr) { |
| 1925 *errorPtr = MessageErrorWithReason(GPBMessageErrorCodeMalformedData, | 1936 *errorPtr = ErrorFromException(exception); |
| 1926 exception.reason); | |
| 1927 } | 1937 } |
| 1928 } | 1938 } |
| 1929 #ifdef DEBUG | 1939 #ifdef DEBUG |
| 1930 if (message && !message.initialized) { | 1940 if (message && !message.initialized) { |
| 1931 message = nil; | 1941 message = nil; |
| 1932 if (errorPtr) { | 1942 if (errorPtr) { |
| 1933 *errorPtr = MessageError(GPBMessageErrorCodeMissingRequiredField, nil); | 1943 *errorPtr = MessageError(GPBMessageErrorCodeMissingRequiredField, nil); |
| 1934 } | 1944 } |
| 1935 } | 1945 } |
| 1936 #endif | 1946 #endif |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2257 GPBDescriptor *descriptor = [self descriptor]; | 2267 GPBDescriptor *descriptor = [self descriptor]; |
| 2258 GPBFileSyntax syntax = descriptor.file.syntax; | 2268 GPBFileSyntax syntax = descriptor.file.syntax; |
| 2259 GPBCodedInputStreamState *state = &input->state_; | 2269 GPBCodedInputStreamState *state = &input->state_; |
| 2260 uint32_t tag = 0; | 2270 uint32_t tag = 0; |
| 2261 NSUInteger startingIndex = 0; | 2271 NSUInteger startingIndex = 0; |
| 2262 NSArray *fields = descriptor->fields_; | 2272 NSArray *fields = descriptor->fields_; |
| 2263 NSUInteger numFields = fields.count; | 2273 NSUInteger numFields = fields.count; |
| 2264 while (YES) { | 2274 while (YES) { |
| 2265 BOOL merged = NO; | 2275 BOOL merged = NO; |
| 2266 tag = GPBCodedInputStreamReadTag(state); | 2276 tag = GPBCodedInputStreamReadTag(state); |
| 2277 if (tag == 0) { |
| 2278 break; // Reached end. |
| 2279 } |
| 2267 for (NSUInteger i = 0; i < numFields; ++i) { | 2280 for (NSUInteger i = 0; i < numFields; ++i) { |
| 2268 if (startingIndex >= numFields) startingIndex = 0; | 2281 if (startingIndex >= numFields) startingIndex = 0; |
| 2269 GPBFieldDescriptor *fieldDescriptor = fields[startingIndex]; | 2282 GPBFieldDescriptor *fieldDescriptor = fields[startingIndex]; |
| 2270 if (GPBFieldTag(fieldDescriptor) == tag) { | 2283 if (GPBFieldTag(fieldDescriptor) == tag) { |
| 2271 GPBFieldType fieldType = fieldDescriptor.fieldType; | 2284 GPBFieldType fieldType = fieldDescriptor.fieldType; |
| 2272 if (fieldType == GPBFieldTypeSingle) { | 2285 if (fieldType == GPBFieldTypeSingle) { |
| 2273 MergeSingleFieldFromCodedInputStream(self, fieldDescriptor, syntax, | 2286 MergeSingleFieldFromCodedInputStream(self, fieldDescriptor, syntax, |
| 2274 input, extensionRegistry); | 2287 input, extensionRegistry); |
| 2275 // Well formed protos will only have a single field once, advance | 2288 // Well formed protos will only have a single field once, advance |
| 2276 // the starting index to the next field. | 2289 // the starting index to the next field. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2295 field:fieldDescriptor | 2308 field:fieldDescriptor |
| 2296 parentMessage:self]; | 2309 parentMessage:self]; |
| 2297 } | 2310 } |
| 2298 merged = YES; | 2311 merged = YES; |
| 2299 break; | 2312 break; |
| 2300 } else { | 2313 } else { |
| 2301 startingIndex += 1; | 2314 startingIndex += 1; |
| 2302 } | 2315 } |
| 2303 } // for(i < numFields) | 2316 } // for(i < numFields) |
| 2304 | 2317 |
| 2305 if (!merged) { | 2318 if (!merged && (tag != 0)) { |
| 2306 // Primitive, repeated types can be packed on unpacked on the wire, and | 2319 // Primitive, repeated types can be packed on unpacked on the wire, and |
| 2307 // are parsed either way. The above loop covered tag in the preferred | 2320 // are parsed either way. The above loop covered tag in the preferred |
| 2308 // for, so this need to check the alternate form. | 2321 // for, so this need to check the alternate form. |
| 2309 for (NSUInteger i = 0; i < numFields; ++i) { | 2322 for (NSUInteger i = 0; i < numFields; ++i) { |
| 2310 if (startingIndex >= numFields) startingIndex = 0; | 2323 if (startingIndex >= numFields) startingIndex = 0; |
| 2311 GPBFieldDescriptor *fieldDescriptor = fields[startingIndex]; | 2324 GPBFieldDescriptor *fieldDescriptor = fields[startingIndex]; |
| 2312 if ((fieldDescriptor.fieldType == GPBFieldTypeRepeated) && | 2325 if ((fieldDescriptor.fieldType == GPBFieldTypeRepeated) && |
| 2313 !GPBFieldDataTypeIsObject(fieldDescriptor) && | 2326 !GPBFieldDataTypeIsObject(fieldDescriptor) && |
| 2314 (GPBFieldAlternateTag(fieldDescriptor) == tag)) { | 2327 (GPBFieldAlternateTag(fieldDescriptor) == tag)) { |
| 2315 BOOL alternateIsPacked = !fieldDescriptor.isPackable; | 2328 BOOL alternateIsPacked = !fieldDescriptor.isPackable; |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2550 [autocreatedExtensionMap_ removeObjectForKey:extension]; | 2563 [autocreatedExtensionMap_ removeObjectForKey:extension]; |
| 2551 GPBClearMessageAutocreator(autocreatedValue); | 2564 GPBClearMessageAutocreator(autocreatedValue); |
| 2552 [autocreatedValue release]; | 2565 [autocreatedValue release]; |
| 2553 } | 2566 } |
| 2554 } | 2567 } |
| 2555 } | 2568 } |
| 2556 } | 2569 } |
| 2557 | 2570 |
| 2558 #pragma mark - isEqual: & hash Support | 2571 #pragma mark - isEqual: & hash Support |
| 2559 | 2572 |
| 2560 - (BOOL)isEqual:(GPBMessage *)other { | 2573 - (BOOL)isEqual:(id)other { |
| 2561 if (other == self) { | 2574 if (other == self) { |
| 2562 return YES; | 2575 return YES; |
| 2563 } | 2576 } |
| 2564 if (![other isKindOfClass:[self class]] && | 2577 if (![other isKindOfClass:[self class]] && |
| 2565 ![self isKindOfClass:[other class]]) { | 2578 ![self isKindOfClass:[other class]]) { |
| 2566 return NO; | 2579 return NO; |
| 2567 } | 2580 } |
| 2568 | 2581 |
| 2582 GPBMessage *otherMsg = other; |
| 2569 GPBDescriptor *descriptor = [[self class] descriptor]; | 2583 GPBDescriptor *descriptor = [[self class] descriptor]; |
| 2570 uint8_t *selfStorage = (uint8_t *)messageStorage_; | 2584 uint8_t *selfStorage = (uint8_t *)messageStorage_; |
| 2571 uint8_t *otherStorage = (uint8_t *)other->messageStorage_; | 2585 uint8_t *otherStorage = (uint8_t *)otherMsg->messageStorage_; |
| 2572 | 2586 |
| 2573 for (GPBFieldDescriptor *field in descriptor->fields_) { | 2587 for (GPBFieldDescriptor *field in descriptor->fields_) { |
| 2574 if (GPBFieldIsMapOrArray(field)) { | 2588 if (GPBFieldIsMapOrArray(field)) { |
| 2575 // In the case of a list or map, there is no _hasIvar to worry about. | 2589 // In the case of a list or map, there is no _hasIvar to worry about. |
| 2576 // NOTE: These are NSArray/GPB*Array or NSDictionary/GPB*Dictionary, but | 2590 // NOTE: These are NSArray/GPB*Array or NSDictionary/GPB*Dictionary, but |
| 2577 // the type doesn't really matter as the objects all support -count and | 2591 // the type doesn't really matter as the objects all support -count and |
| 2578 // -isEqual:. | 2592 // -isEqual:. |
| 2579 NSArray *resultMapOrArray = | 2593 NSArray *resultMapOrArray = |
| 2580 GPBGetObjectIvarWithFieldNoAutocreate(self, field); | 2594 GPBGetObjectIvarWithFieldNoAutocreate(self, field); |
| 2581 NSArray *otherMapOrArray = | 2595 NSArray *otherMapOrArray = |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2614 } | 2628 } |
| 2615 break; | 2629 break; |
| 2616 } | 2630 } |
| 2617 case GPBDataTypeSFixed32: | 2631 case GPBDataTypeSFixed32: |
| 2618 case GPBDataTypeInt32: | 2632 case GPBDataTypeInt32: |
| 2619 case GPBDataTypeSInt32: | 2633 case GPBDataTypeSInt32: |
| 2620 case GPBDataTypeEnum: | 2634 case GPBDataTypeEnum: |
| 2621 case GPBDataTypeFixed32: | 2635 case GPBDataTypeFixed32: |
| 2622 case GPBDataTypeUInt32: | 2636 case GPBDataTypeUInt32: |
| 2623 case GPBDataTypeFloat: { | 2637 case GPBDataTypeFloat: { |
| 2624 _GPBCompileAssert(sizeof(float) == sizeof(uint32_t), float_not_32_bits
); | 2638 GPBInternalCompileAssert(sizeof(float) == sizeof(uint32_t), float_not_
32_bits); |
| 2625 // These are all 32bit, signed/unsigned doesn't matter for equality. | 2639 // These are all 32bit, signed/unsigned doesn't matter for equality. |
| 2626 uint32_t *selfValPtr = (uint32_t *)&selfStorage[fieldOffset]; | 2640 uint32_t *selfValPtr = (uint32_t *)&selfStorage[fieldOffset]; |
| 2627 uint32_t *otherValPtr = (uint32_t *)&otherStorage[fieldOffset]; | 2641 uint32_t *otherValPtr = (uint32_t *)&otherStorage[fieldOffset]; |
| 2628 if (*selfValPtr != *otherValPtr) { | 2642 if (*selfValPtr != *otherValPtr) { |
| 2629 return NO; | 2643 return NO; |
| 2630 } | 2644 } |
| 2631 break; | 2645 break; |
| 2632 } | 2646 } |
| 2633 case GPBDataTypeSFixed64: | 2647 case GPBDataTypeSFixed64: |
| 2634 case GPBDataTypeInt64: | 2648 case GPBDataTypeInt64: |
| 2635 case GPBDataTypeSInt64: | 2649 case GPBDataTypeSInt64: |
| 2636 case GPBDataTypeFixed64: | 2650 case GPBDataTypeFixed64: |
| 2637 case GPBDataTypeUInt64: | 2651 case GPBDataTypeUInt64: |
| 2638 case GPBDataTypeDouble: { | 2652 case GPBDataTypeDouble: { |
| 2639 _GPBCompileAssert(sizeof(double) == sizeof(uint64_t), double_not_64_bi
ts); | 2653 GPBInternalCompileAssert(sizeof(double) == sizeof(uint64_t), double_no
t_64_bits); |
| 2640 // These are all 64bit, signed/unsigned doesn't matter for equality. | 2654 // These are all 64bit, signed/unsigned doesn't matter for equality. |
| 2641 uint64_t *selfValPtr = (uint64_t *)&selfStorage[fieldOffset]; | 2655 uint64_t *selfValPtr = (uint64_t *)&selfStorage[fieldOffset]; |
| 2642 uint64_t *otherValPtr = (uint64_t *)&otherStorage[fieldOffset]; | 2656 uint64_t *otherValPtr = (uint64_t *)&otherStorage[fieldOffset]; |
| 2643 if (*selfValPtr != *otherValPtr) { | 2657 if (*selfValPtr != *otherValPtr) { |
| 2644 return NO; | 2658 return NO; |
| 2645 } | 2659 } |
| 2646 break; | 2660 break; |
| 2647 } | 2661 } |
| 2648 case GPBDataTypeBytes: | 2662 case GPBDataTypeBytes: |
| 2649 case GPBDataTypeString: | 2663 case GPBDataTypeString: |
| 2650 case GPBDataTypeMessage: | 2664 case GPBDataTypeMessage: |
| 2651 case GPBDataTypeGroup: { | 2665 case GPBDataTypeGroup: { |
| 2652 // Type doesn't matter here, they all implement -isEqual:. | 2666 // Type doesn't matter here, they all implement -isEqual:. |
| 2653 id *selfValPtr = (id *)&selfStorage[fieldOffset]; | 2667 id *selfValPtr = (id *)&selfStorage[fieldOffset]; |
| 2654 id *otherValPtr = (id *)&otherStorage[fieldOffset]; | 2668 id *otherValPtr = (id *)&otherStorage[fieldOffset]; |
| 2655 if (![*selfValPtr isEqual:*otherValPtr]) { | 2669 if (![*selfValPtr isEqual:*otherValPtr]) { |
| 2656 return NO; | 2670 return NO; |
| 2657 } | 2671 } |
| 2658 break; | 2672 break; |
| 2659 } | 2673 } |
| 2660 } // switch() | 2674 } // switch() |
| 2661 } // if(mapOrArray)...else | 2675 } // if(mapOrArray)...else |
| 2662 } // for(fields) | 2676 } // for(fields) |
| 2663 | 2677 |
| 2664 // nil and empty are equal | 2678 // nil and empty are equal |
| 2665 if (extensionMap_.count != 0 || other->extensionMap_.count != 0) { | 2679 if (extensionMap_.count != 0 || otherMsg->extensionMap_.count != 0) { |
| 2666 if (![extensionMap_ isEqual:other->extensionMap_]) { | 2680 if (![extensionMap_ isEqual:otherMsg->extensionMap_]) { |
| 2667 return NO; | 2681 return NO; |
| 2668 } | 2682 } |
| 2669 } | 2683 } |
| 2670 | 2684 |
| 2671 // nil and empty are equal | 2685 // nil and empty are equal |
| 2672 GPBUnknownFieldSet *otherUnknowns = other->unknownFields_; | 2686 GPBUnknownFieldSet *otherUnknowns = otherMsg->unknownFields_; |
| 2673 if ([unknownFields_ countOfFields] != 0 || | 2687 if ([unknownFields_ countOfFields] != 0 || |
| 2674 [otherUnknowns countOfFields] != 0) { | 2688 [otherUnknowns countOfFields] != 0) { |
| 2675 if (![unknownFields_ isEqual:otherUnknowns]) { | 2689 if (![unknownFields_ isEqual:otherUnknowns]) { |
| 2676 return NO; | 2690 return NO; |
| 2677 } | 2691 } |
| 2678 } | 2692 } |
| 2679 | 2693 |
| 2680 return YES; | 2694 return YES; |
| 2681 } | 2695 } |
| 2682 | 2696 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2726 result = prime * result + value; | 2740 result = prime * result + value; |
| 2727 break; | 2741 break; |
| 2728 } | 2742 } |
| 2729 case GPBDataTypeSFixed32: | 2743 case GPBDataTypeSFixed32: |
| 2730 case GPBDataTypeInt32: | 2744 case GPBDataTypeInt32: |
| 2731 case GPBDataTypeSInt32: | 2745 case GPBDataTypeSInt32: |
| 2732 case GPBDataTypeEnum: | 2746 case GPBDataTypeEnum: |
| 2733 case GPBDataTypeFixed32: | 2747 case GPBDataTypeFixed32: |
| 2734 case GPBDataTypeUInt32: | 2748 case GPBDataTypeUInt32: |
| 2735 case GPBDataTypeFloat: { | 2749 case GPBDataTypeFloat: { |
| 2736 _GPBCompileAssert(sizeof(float) == sizeof(uint32_t), float_not_32_bits
); | 2750 GPBInternalCompileAssert(sizeof(float) == sizeof(uint32_t), float_not_
32_bits); |
| 2737 // These are all 32bit, just mix it in. | 2751 // These are all 32bit, just mix it in. |
| 2738 uint32_t *valPtr = (uint32_t *)&storage[fieldOffset]; | 2752 uint32_t *valPtr = (uint32_t *)&storage[fieldOffset]; |
| 2739 result = prime * result + *valPtr; | 2753 result = prime * result + *valPtr; |
| 2740 break; | 2754 break; |
| 2741 } | 2755 } |
| 2742 case GPBDataTypeSFixed64: | 2756 case GPBDataTypeSFixed64: |
| 2743 case GPBDataTypeInt64: | 2757 case GPBDataTypeInt64: |
| 2744 case GPBDataTypeSInt64: | 2758 case GPBDataTypeSInt64: |
| 2745 case GPBDataTypeFixed64: | 2759 case GPBDataTypeFixed64: |
| 2746 case GPBDataTypeUInt64: | 2760 case GPBDataTypeUInt64: |
| 2747 case GPBDataTypeDouble: { | 2761 case GPBDataTypeDouble: { |
| 2748 _GPBCompileAssert(sizeof(double) == sizeof(uint64_t), double_not_64_bi
ts); | 2762 GPBInternalCompileAssert(sizeof(double) == sizeof(uint64_t), double_no
t_64_bits); |
| 2749 // These are all 64bit, just mix what fits into an NSUInteger in. | 2763 // These are all 64bit, just mix what fits into an NSUInteger in. |
| 2750 uint64_t *valPtr = (uint64_t *)&storage[fieldOffset]; | 2764 uint64_t *valPtr = (uint64_t *)&storage[fieldOffset]; |
| 2751 result = prime * result + (NSUInteger)(*valPtr); | 2765 result = prime * result + (NSUInteger)(*valPtr); |
| 2752 break; | 2766 break; |
| 2753 } | 2767 } |
| 2754 case GPBDataTypeBytes: | 2768 case GPBDataTypeBytes: |
| 2755 case GPBDataTypeString: { | 2769 case GPBDataTypeString: { |
| 2756 // Type doesn't matter here, they both implement -hash:. | 2770 // Type doesn't matter here, they both implement -hash:. |
| 2757 id *valPtr = (id *)&storage[fieldOffset]; | 2771 id *valPtr = (id *)&storage[fieldOffset]; |
| 2758 result = prime * result + [*valPtr hash]; | 2772 result = prime * result + [*valPtr hash]; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 2785 | 2799 |
| 2786 #pragma mark - Description Support | 2800 #pragma mark - Description Support |
| 2787 | 2801 |
| 2788 - (NSString *)description { | 2802 - (NSString *)description { |
| 2789 NSString *textFormat = GPBTextFormatForMessage(self, @" "); | 2803 NSString *textFormat = GPBTextFormatForMessage(self, @" "); |
| 2790 NSString *description = [NSString | 2804 NSString *description = [NSString |
| 2791 stringWithFormat:@"<%@ %p>: {\n%@}", [self class], self, textFormat]; | 2805 stringWithFormat:@"<%@ %p>: {\n%@}", [self class], self, textFormat]; |
| 2792 return description; | 2806 return description; |
| 2793 } | 2807 } |
| 2794 | 2808 |
| 2795 #if DEBUG | 2809 #if defined(DEBUG) && DEBUG |
| 2796 | 2810 |
| 2797 // Xcode 5.1 added support for custom quick look info. | 2811 // Xcode 5.1 added support for custom quick look info. |
| 2798 // https://developer.apple.com/library/ios/documentation/IDEs/Conceptual/CustomC
lassDisplay_in_QuickLook/CH01-quick_look_for_custom_objects/CH01-quick_look_for_
custom_objects.html#//apple_ref/doc/uid/TP40014001-CH2-SW1 | 2812 // https://developer.apple.com/library/ios/documentation/IDEs/Conceptual/CustomC
lassDisplay_in_QuickLook/CH01-quick_look_for_custom_objects/CH01-quick_look_for_
custom_objects.html#//apple_ref/doc/uid/TP40014001-CH2-SW1 |
| 2799 - (id)debugQuickLookObject { | 2813 - (id)debugQuickLookObject { |
| 2800 return GPBTextFormatForMessage(self, nil); | 2814 return GPBTextFormatForMessage(self, nil); |
| 2801 } | 2815 } |
| 2802 | 2816 |
| 2803 #endif // DEBUG | 2817 #endif // DEBUG |
| 2804 | 2818 |
| 2805 #pragma mark - SerializedSize | 2819 #pragma mark - SerializedSize |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3175 } | 3189 } |
| 3176 | 3190 |
| 3177 #pragma mark - KVC Support | 3191 #pragma mark - KVC Support |
| 3178 | 3192 |
| 3179 + (BOOL)accessInstanceVariablesDirectly { | 3193 + (BOOL)accessInstanceVariablesDirectly { |
| 3180 // Make sure KVC doesn't use instance variables. | 3194 // Make sure KVC doesn't use instance variables. |
| 3181 return NO; | 3195 return NO; |
| 3182 } | 3196 } |
| 3183 | 3197 |
| 3184 @end | 3198 @end |
| 3199 |
| 3200 #pragma mark - Messages from GPBUtilities.h but defined here for access to helpe
rs. |
| 3201 |
| 3202 // Only exists for public api, no core code should use this. |
| 3203 id GPBGetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field) { |
| 3204 #if defined(DEBUG) && DEBUG |
| 3205 if (field.fieldType != GPBFieldTypeRepeated) { |
| 3206 [NSException raise:NSInvalidArgumentException |
| 3207 format:@"%@.%@ is not a repeated field.", |
| 3208 [self class], field.name]; |
| 3209 } |
| 3210 #endif |
| 3211 GPBDescriptor *descriptor = [[self class] descriptor]; |
| 3212 GPBFileSyntax syntax = descriptor.file.syntax; |
| 3213 return GetOrCreateArrayIvarWithField(self, field, syntax); |
| 3214 } |
| 3215 |
| 3216 // Only exists for public api, no core code should use this. |
| 3217 id GPBGetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field) { |
| 3218 #if defined(DEBUG) && DEBUG |
| 3219 if (field.fieldType != GPBFieldTypeMap) { |
| 3220 [NSException raise:NSInvalidArgumentException |
| 3221 format:@"%@.%@ is not a map<> field.", |
| 3222 [self class], field.name]; |
| 3223 } |
| 3224 #endif |
| 3225 GPBDescriptor *descriptor = [[self class] descriptor]; |
| 3226 GPBFileSyntax syntax = descriptor.file.syntax; |
| 3227 return GetOrCreateMapIvarWithField(self, field, syntax); |
| 3228 } |
| 3229 |
| 3230 #pragma clang diagnostic pop |
| OLD | NEW |