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