Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(842)

Side by Side Diff: third_party/protobuf/objectivec/GPBUtilities.m

Issue 2600753002: Reverts third_party/protobuf: Update to HEAD (f52e188fe4) (Closed)
Patch Set: Created 3 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 21 matching lines...) Expand all
32 32
33 #import <objc/runtime.h> 33 #import <objc/runtime.h>
34 34
35 #import "GPBArray_PackagePrivate.h" 35 #import "GPBArray_PackagePrivate.h"
36 #import "GPBDescriptor_PackagePrivate.h" 36 #import "GPBDescriptor_PackagePrivate.h"
37 #import "GPBDictionary_PackagePrivate.h" 37 #import "GPBDictionary_PackagePrivate.h"
38 #import "GPBMessage_PackagePrivate.h" 38 #import "GPBMessage_PackagePrivate.h"
39 #import "GPBUnknownField.h" 39 #import "GPBUnknownField.h"
40 #import "GPBUnknownFieldSet.h" 40 #import "GPBUnknownFieldSet.h"
41 41
42 // Direct access is use for speed, to avoid even internally declaring things
43 // read/write, etc. The warning is enabled in the project to ensure code calling
44 // protos can turn on -Wdirect-ivar-access without issues.
45 #pragma clang diagnostic push
46 #pragma clang diagnostic ignored "-Wdirect-ivar-access"
47
48 static void AppendTextFormatForMessage(GPBMessage *message, 42 static void AppendTextFormatForMessage(GPBMessage *message,
49 NSMutableString *toStr, 43 NSMutableString *toStr,
50 NSString *lineIndent); 44 NSString *lineIndent);
51 45
52 NSData *GPBEmptyNSData(void) { 46 NSData *GPBEmptyNSData(void) {
53 static dispatch_once_t onceToken; 47 static dispatch_once_t onceToken;
54 static NSData *defaultNSData = nil; 48 static NSData *defaultNSData = nil;
55 dispatch_once(&onceToken, ^{ 49 dispatch_once(&onceToken, ^{
56 defaultNSData = [[NSData alloc] init]; 50 defaultNSData = [[NSData alloc] init];
57 }); 51 });
58 return defaultNSData; 52 return defaultNSData;
59 } 53 }
60 54
61 // -- About Version Checks --
62 // There's actually 3 places these checks all come into play:
63 // 1. When the generated source is compile into .o files, the header check
64 // happens. This is checking the protoc used matches the library being used
65 // when making the .o.
66 // 2. Every place a generated proto header is included in a developer's code,
67 // the header check comes into play again. But this time it is checking that
68 // the current library headers being used still support/match the ones for
69 // the generated code.
70 // 3. At runtime the final check here (GPBCheckRuntimeVersionsInternal), is
71 // called from the generated code passing in values captured when the
72 // generated code's .o was made. This checks that at runtime the generated
73 // code and runtime library match.
74
75 void GPBCheckRuntimeVersionSupport(int32_t objcRuntimeVersion) {
76 // NOTE: This is passing the value captured in the compiled code to check
77 // against the values captured when the runtime support was compiled. This
78 // ensures the library code isn't in a different framework/library that
79 // was generated with a non matching version.
80 if (GOOGLE_PROTOBUF_OBJC_VERSION < objcRuntimeVersion) {
81 // Library is too old for headers.
82 [NSException raise:NSInternalInconsistencyException
83 format:@"Linked to ProtocolBuffer runtime version %d,"
84 @" but code compiled needing atleast %d!",
85 GOOGLE_PROTOBUF_OBJC_VERSION, objcRuntimeVersion];
86 }
87 if (objcRuntimeVersion < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION) {
88 // Headers are too old for library.
89 [NSException raise:NSInternalInconsistencyException
90 format:@"Proto generation source compiled against runtime"
91 @" version %d, but this version of the runtime only"
92 @" supports back to %d!",
93 objcRuntimeVersion,
94 GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION];
95 }
96 }
97
98 // This api is no longer used for version checks. 30001 is the last version
99 // using this old versioning model. When that support is removed, this function
100 // can be removed (along with the declaration in GPBUtilities_PackagePrivate.h).
101 void GPBCheckRuntimeVersionInternal(int32_t version) { 55 void GPBCheckRuntimeVersionInternal(int32_t version) {
102 GPBInternalCompileAssert(GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION == 30001, 56 if (version != GOOGLE_PROTOBUF_OBJC_GEN_VERSION) {
103 time_to_remove_this_old_version_shim);
104 if (version != GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION) {
105 [NSException raise:NSInternalInconsistencyException 57 [NSException raise:NSInternalInconsistencyException
106 format:@"Linked to ProtocolBuffer runtime version %d," 58 format:@"Linked to ProtocolBuffer runtime version %d,"
107 @" but code compiled with version %d!", 59 @" but code compiled with version %d!",
108 GOOGLE_PROTOBUF_OBJC_GEN_VERSION, version]; 60 GOOGLE_PROTOBUF_OBJC_GEN_VERSION, version];
109 } 61 }
110 } 62 }
111 63
112 BOOL GPBMessageHasFieldNumberSet(GPBMessage *self, uint32_t fieldNumber) { 64 BOOL GPBMessageHasFieldNumberSet(GPBMessage *self, uint32_t fieldNumber) {
113 GPBDescriptor *descriptor = [self descriptor]; 65 GPBDescriptor *descriptor = [self descriptor];
114 GPBFieldDescriptor *field = [descriptor fieldWithNumber:fieldNumber]; 66 GPBFieldDescriptor *field = [descriptor fieldWithNumber:fieldNumber];
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 //% NSCAssert(self->messageStorage_ != NULL, 205 //% NSCAssert(self->messageStorage_ != NULL,
254 //% @"%@: All messages should have storage (from init)", 206 //% @"%@: All messages should have storage (from init)",
255 //% [self class]); 207 //% [self class]);
256 //%#if defined(__clang_analyzer__) 208 //%#if defined(__clang_analyzer__)
257 //% if (self->messageStorage_ == NULL) return; 209 //% if (self->messageStorage_ == NULL) return;
258 //%#endif 210 //%#endif
259 //% uint8_t *storage = (uint8_t *)self->messageStorage_; 211 //% uint8_t *storage = (uint8_t *)self->messageStorage_;
260 //% TYPE *typePtr = (TYPE *)&storage[field->description_->offset]; 212 //% TYPE *typePtr = (TYPE *)&storage[field->description_->offset];
261 //% *typePtr = value; 213 //% *typePtr = value;
262 //% // proto2: any value counts as having been set; proto3, it 214 //% // proto2: any value counts as having been set; proto3, it
263 //% // has to be a non zero value or be in a oneof. 215 //% // has to be a non zero value.
264 //% BOOL hasValue = ((syntax == GPBFileSyntaxProto2) 216 //% BOOL hasValue =
265 //% || (value != (TYPE)0) 217 //% (syntax == GPBFileSyntaxProto2) || (value != (TYPE)0);
266 //% || (field->containingOneof_ != NULL));
267 //% GPBSetHasIvarField(self, field, hasValue); 218 //% GPBSetHasIvarField(self, field, hasValue);
268 //% GPBBecomeVisibleToAutocreator(self); 219 //% GPBBecomeVisibleToAutocreator(self);
269 //%} 220 //%}
270 //% 221 //%
271 //%PDDM-DEFINE IVAR_ALIAS_DEFN_OBJECT(NAME, TYPE) 222 //%PDDM-DEFINE IVAR_ALIAS_DEFN_OBJECT(NAME, TYPE)
272 //%// Only exists for public api, no core code should use this. 223 //%// Only exists for public api, no core code should use this.
273 //%TYPE *GPBGetMessage##NAME##Field(GPBMessage *self, 224 //%TYPE *GPBGetMessage##NAME##Field(GPBMessage *self,
274 //% TYPE$S NAME$S GPBFieldDescriptor *field) { 225 //% TYPE$S NAME$S GPBFieldDescriptor *field) {
275 //% return (TYPE *)GPBGetObjectIvarWithField(self, field); 226 //% return (TYPE *)GPBGetObjectIvarWithField(self, field);
276 //%} 227 //%}
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 GPBMessageFieldDescription *fieldDesc = field->description_; 324 GPBMessageFieldDescription *fieldDesc = field->description_;
374 GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number); 325 GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
375 } 326 }
376 // Clear "has" if they are being set to nil. 327 // Clear "has" if they are being set to nil.
377 BOOL setHasValue = (value != nil); 328 BOOL setHasValue = (value != nil);
378 // Under proto3, Bytes & String fields get cleared by resetting them to 329 // Under proto3, Bytes & String fields get cleared by resetting them to
379 // their default (empty) values, so if they are set to something of length 330 // their default (empty) values, so if they are set to something of length
380 // zero, they are being cleared. 331 // zero, they are being cleared.
381 if ((syntax == GPBFileSyntaxProto3) && !fieldIsMessage && 332 if ((syntax == GPBFileSyntaxProto3) && !fieldIsMessage &&
382 ([value length] == 0)) { 333 ([value length] == 0)) {
383 // Except, if the field was in a oneof, then it still gets recorded as 334 setHasValue = NO;
384 // having been set so the state of the oneof can be serialized back out. 335 value = nil;
385 if (!oneof) {
386 setHasValue = NO;
387 }
388 if (setHasValue) {
389 NSCAssert(value != nil, @"Should never be setting has for nil");
390 } else {
391 // The value passed in was retained, it must be released since we
392 // aren't saving anything in the field.
393 [value release];
394 value = nil;
395 }
396 } 336 }
397 GPBSetHasIvarField(self, field, setHasValue); 337 GPBSetHasIvarField(self, field, setHasValue);
398 } 338 }
399 uint8_t *storage = (uint8_t *)self->messageStorage_; 339 uint8_t *storage = (uint8_t *)self->messageStorage_;
400 id *typePtr = (id *)&storage[field->description_->offset]; 340 id *typePtr = (id *)&storage[field->description_->offset];
401 341
402 id oldValue = *typePtr; 342 id oldValue = *typePtr;
403 343
404 *typePtr = value; 344 *typePtr = value;
405 345
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number); 511 GPBMaybeClearOneof(self, oneof, fieldDesc->hasIndex, fieldDesc->number);
572 } 512 }
573 513
574 // Bools are stored in the has bits to avoid needing explicit space in the 514 // Bools are stored in the has bits to avoid needing explicit space in the
575 // storage structure. 515 // storage structure.
576 // (the field number passed to the HasIvar helper doesn't really matter since 516 // (the field number passed to the HasIvar helper doesn't really matter since
577 // the offset is never negative) 517 // the offset is never negative)
578 GPBSetHasIvar(self, (int32_t)(fieldDesc->offset), fieldDesc->number, value); 518 GPBSetHasIvar(self, (int32_t)(fieldDesc->offset), fieldDesc->number, value);
579 519
580 // proto2: any value counts as having been set; proto3, it 520 // proto2: any value counts as having been set; proto3, it
581 // has to be a non zero value or be in a oneof. 521 // has to be a non zero value.
582 BOOL hasValue = ((syntax == GPBFileSyntaxProto2) 522 BOOL hasValue =
583 || (value != (BOOL)0) 523 (syntax == GPBFileSyntaxProto2) || (value != (BOOL)0);
584 || (field->containingOneof_ != NULL));
585 GPBSetHasIvarField(self, field, hasValue); 524 GPBSetHasIvarField(self, field, hasValue);
586 GPBBecomeVisibleToAutocreator(self); 525 GPBBecomeVisibleToAutocreator(self);
587 } 526 }
588 527
589 //%PDDM-EXPAND IVAR_POD_ACCESSORS_DEFN(Int32, int32_t) 528 //%PDDM-EXPAND IVAR_POD_ACCESSORS_DEFN(Int32, int32_t)
590 // This block of code is generated, do not edit it directly. 529 // This block of code is generated, do not edit it directly.
591 530
592 int32_t GPBGetMessageInt32Field(GPBMessage *self, 531 int32_t GPBGetMessageInt32Field(GPBMessage *self,
593 GPBFieldDescriptor *field) { 532 GPBFieldDescriptor *field) {
594 if (GPBGetHasIvarField(self, field)) { 533 if (GPBGetHasIvarField(self, field)) {
(...skipping 26 matching lines...) Expand all
621 NSCAssert(self->messageStorage_ != NULL, 560 NSCAssert(self->messageStorage_ != NULL,
622 @"%@: All messages should have storage (from init)", 561 @"%@: All messages should have storage (from init)",
623 [self class]); 562 [self class]);
624 #if defined(__clang_analyzer__) 563 #if defined(__clang_analyzer__)
625 if (self->messageStorage_ == NULL) return; 564 if (self->messageStorage_ == NULL) return;
626 #endif 565 #endif
627 uint8_t *storage = (uint8_t *)self->messageStorage_; 566 uint8_t *storage = (uint8_t *)self->messageStorage_;
628 int32_t *typePtr = (int32_t *)&storage[field->description_->offset]; 567 int32_t *typePtr = (int32_t *)&storage[field->description_->offset];
629 *typePtr = value; 568 *typePtr = value;
630 // proto2: any value counts as having been set; proto3, it 569 // proto2: any value counts as having been set; proto3, it
631 // has to be a non zero value or be in a oneof. 570 // has to be a non zero value.
632 BOOL hasValue = ((syntax == GPBFileSyntaxProto2) 571 BOOL hasValue =
633 || (value != (int32_t)0) 572 (syntax == GPBFileSyntaxProto2) || (value != (int32_t)0);
634 || (field->containingOneof_ != NULL));
635 GPBSetHasIvarField(self, field, hasValue); 573 GPBSetHasIvarField(self, field, hasValue);
636 GPBBecomeVisibleToAutocreator(self); 574 GPBBecomeVisibleToAutocreator(self);
637 } 575 }
638 576
639 //%PDDM-EXPAND IVAR_POD_ACCESSORS_DEFN(UInt32, uint32_t) 577 //%PDDM-EXPAND IVAR_POD_ACCESSORS_DEFN(UInt32, uint32_t)
640 // This block of code is generated, do not edit it directly. 578 // This block of code is generated, do not edit it directly.
641 579
642 uint32_t GPBGetMessageUInt32Field(GPBMessage *self, 580 uint32_t GPBGetMessageUInt32Field(GPBMessage *self,
643 GPBFieldDescriptor *field) { 581 GPBFieldDescriptor *field) {
644 if (GPBGetHasIvarField(self, field)) { 582 if (GPBGetHasIvarField(self, field)) {
(...skipping 26 matching lines...) Expand all
671 NSCAssert(self->messageStorage_ != NULL, 609 NSCAssert(self->messageStorage_ != NULL,
672 @"%@: All messages should have storage (from init)", 610 @"%@: All messages should have storage (from init)",
673 [self class]); 611 [self class]);
674 #if defined(__clang_analyzer__) 612 #if defined(__clang_analyzer__)
675 if (self->messageStorage_ == NULL) return; 613 if (self->messageStorage_ == NULL) return;
676 #endif 614 #endif
677 uint8_t *storage = (uint8_t *)self->messageStorage_; 615 uint8_t *storage = (uint8_t *)self->messageStorage_;
678 uint32_t *typePtr = (uint32_t *)&storage[field->description_->offset]; 616 uint32_t *typePtr = (uint32_t *)&storage[field->description_->offset];
679 *typePtr = value; 617 *typePtr = value;
680 // proto2: any value counts as having been set; proto3, it 618 // proto2: any value counts as having been set; proto3, it
681 // has to be a non zero value or be in a oneof. 619 // has to be a non zero value.
682 BOOL hasValue = ((syntax == GPBFileSyntaxProto2) 620 BOOL hasValue =
683 || (value != (uint32_t)0) 621 (syntax == GPBFileSyntaxProto2) || (value != (uint32_t)0);
684 || (field->containingOneof_ != NULL));
685 GPBSetHasIvarField(self, field, hasValue); 622 GPBSetHasIvarField(self, field, hasValue);
686 GPBBecomeVisibleToAutocreator(self); 623 GPBBecomeVisibleToAutocreator(self);
687 } 624 }
688 625
689 //%PDDM-EXPAND IVAR_POD_ACCESSORS_DEFN(Int64, int64_t) 626 //%PDDM-EXPAND IVAR_POD_ACCESSORS_DEFN(Int64, int64_t)
690 // This block of code is generated, do not edit it directly. 627 // This block of code is generated, do not edit it directly.
691 628
692 int64_t GPBGetMessageInt64Field(GPBMessage *self, 629 int64_t GPBGetMessageInt64Field(GPBMessage *self,
693 GPBFieldDescriptor *field) { 630 GPBFieldDescriptor *field) {
694 if (GPBGetHasIvarField(self, field)) { 631 if (GPBGetHasIvarField(self, field)) {
(...skipping 26 matching lines...) Expand all
721 NSCAssert(self->messageStorage_ != NULL, 658 NSCAssert(self->messageStorage_ != NULL,
722 @"%@: All messages should have storage (from init)", 659 @"%@: All messages should have storage (from init)",
723 [self class]); 660 [self class]);
724 #if defined(__clang_analyzer__) 661 #if defined(__clang_analyzer__)
725 if (self->messageStorage_ == NULL) return; 662 if (self->messageStorage_ == NULL) return;
726 #endif 663 #endif
727 uint8_t *storage = (uint8_t *)self->messageStorage_; 664 uint8_t *storage = (uint8_t *)self->messageStorage_;
728 int64_t *typePtr = (int64_t *)&storage[field->description_->offset]; 665 int64_t *typePtr = (int64_t *)&storage[field->description_->offset];
729 *typePtr = value; 666 *typePtr = value;
730 // proto2: any value counts as having been set; proto3, it 667 // proto2: any value counts as having been set; proto3, it
731 // has to be a non zero value or be in a oneof. 668 // has to be a non zero value.
732 BOOL hasValue = ((syntax == GPBFileSyntaxProto2) 669 BOOL hasValue =
733 || (value != (int64_t)0) 670 (syntax == GPBFileSyntaxProto2) || (value != (int64_t)0);
734 || (field->containingOneof_ != NULL));
735 GPBSetHasIvarField(self, field, hasValue); 671 GPBSetHasIvarField(self, field, hasValue);
736 GPBBecomeVisibleToAutocreator(self); 672 GPBBecomeVisibleToAutocreator(self);
737 } 673 }
738 674
739 //%PDDM-EXPAND IVAR_POD_ACCESSORS_DEFN(UInt64, uint64_t) 675 //%PDDM-EXPAND IVAR_POD_ACCESSORS_DEFN(UInt64, uint64_t)
740 // This block of code is generated, do not edit it directly. 676 // This block of code is generated, do not edit it directly.
741 677
742 uint64_t GPBGetMessageUInt64Field(GPBMessage *self, 678 uint64_t GPBGetMessageUInt64Field(GPBMessage *self,
743 GPBFieldDescriptor *field) { 679 GPBFieldDescriptor *field) {
744 if (GPBGetHasIvarField(self, field)) { 680 if (GPBGetHasIvarField(self, field)) {
(...skipping 26 matching lines...) Expand all
771 NSCAssert(self->messageStorage_ != NULL, 707 NSCAssert(self->messageStorage_ != NULL,
772 @"%@: All messages should have storage (from init)", 708 @"%@: All messages should have storage (from init)",
773 [self class]); 709 [self class]);
774 #if defined(__clang_analyzer__) 710 #if defined(__clang_analyzer__)
775 if (self->messageStorage_ == NULL) return; 711 if (self->messageStorage_ == NULL) return;
776 #endif 712 #endif
777 uint8_t *storage = (uint8_t *)self->messageStorage_; 713 uint8_t *storage = (uint8_t *)self->messageStorage_;
778 uint64_t *typePtr = (uint64_t *)&storage[field->description_->offset]; 714 uint64_t *typePtr = (uint64_t *)&storage[field->description_->offset];
779 *typePtr = value; 715 *typePtr = value;
780 // proto2: any value counts as having been set; proto3, it 716 // proto2: any value counts as having been set; proto3, it
781 // has to be a non zero value or be in a oneof. 717 // has to be a non zero value.
782 BOOL hasValue = ((syntax == GPBFileSyntaxProto2) 718 BOOL hasValue =
783 || (value != (uint64_t)0) 719 (syntax == GPBFileSyntaxProto2) || (value != (uint64_t)0);
784 || (field->containingOneof_ != NULL));
785 GPBSetHasIvarField(self, field, hasValue); 720 GPBSetHasIvarField(self, field, hasValue);
786 GPBBecomeVisibleToAutocreator(self); 721 GPBBecomeVisibleToAutocreator(self);
787 } 722 }
788 723
789 //%PDDM-EXPAND IVAR_POD_ACCESSORS_DEFN(Float, float) 724 //%PDDM-EXPAND IVAR_POD_ACCESSORS_DEFN(Float, float)
790 // This block of code is generated, do not edit it directly. 725 // This block of code is generated, do not edit it directly.
791 726
792 float GPBGetMessageFloatField(GPBMessage *self, 727 float GPBGetMessageFloatField(GPBMessage *self,
793 GPBFieldDescriptor *field) { 728 GPBFieldDescriptor *field) {
794 if (GPBGetHasIvarField(self, field)) { 729 if (GPBGetHasIvarField(self, field)) {
(...skipping 26 matching lines...) Expand all
821 NSCAssert(self->messageStorage_ != NULL, 756 NSCAssert(self->messageStorage_ != NULL,
822 @"%@: All messages should have storage (from init)", 757 @"%@: All messages should have storage (from init)",
823 [self class]); 758 [self class]);
824 #if defined(__clang_analyzer__) 759 #if defined(__clang_analyzer__)
825 if (self->messageStorage_ == NULL) return; 760 if (self->messageStorage_ == NULL) return;
826 #endif 761 #endif
827 uint8_t *storage = (uint8_t *)self->messageStorage_; 762 uint8_t *storage = (uint8_t *)self->messageStorage_;
828 float *typePtr = (float *)&storage[field->description_->offset]; 763 float *typePtr = (float *)&storage[field->description_->offset];
829 *typePtr = value; 764 *typePtr = value;
830 // proto2: any value counts as having been set; proto3, it 765 // proto2: any value counts as having been set; proto3, it
831 // has to be a non zero value or be in a oneof. 766 // has to be a non zero value.
832 BOOL hasValue = ((syntax == GPBFileSyntaxProto2) 767 BOOL hasValue =
833 || (value != (float)0) 768 (syntax == GPBFileSyntaxProto2) || (value != (float)0);
834 || (field->containingOneof_ != NULL));
835 GPBSetHasIvarField(self, field, hasValue); 769 GPBSetHasIvarField(self, field, hasValue);
836 GPBBecomeVisibleToAutocreator(self); 770 GPBBecomeVisibleToAutocreator(self);
837 } 771 }
838 772
839 //%PDDM-EXPAND IVAR_POD_ACCESSORS_DEFN(Double, double) 773 //%PDDM-EXPAND IVAR_POD_ACCESSORS_DEFN(Double, double)
840 // This block of code is generated, do not edit it directly. 774 // This block of code is generated, do not edit it directly.
841 775
842 double GPBGetMessageDoubleField(GPBMessage *self, 776 double GPBGetMessageDoubleField(GPBMessage *self,
843 GPBFieldDescriptor *field) { 777 GPBFieldDescriptor *field) {
844 if (GPBGetHasIvarField(self, field)) { 778 if (GPBGetHasIvarField(self, field)) {
(...skipping 26 matching lines...) Expand all
871 NSCAssert(self->messageStorage_ != NULL, 805 NSCAssert(self->messageStorage_ != NULL,
872 @"%@: All messages should have storage (from init)", 806 @"%@: All messages should have storage (from init)",
873 [self class]); 807 [self class]);
874 #if defined(__clang_analyzer__) 808 #if defined(__clang_analyzer__)
875 if (self->messageStorage_ == NULL) return; 809 if (self->messageStorage_ == NULL) return;
876 #endif 810 #endif
877 uint8_t *storage = (uint8_t *)self->messageStorage_; 811 uint8_t *storage = (uint8_t *)self->messageStorage_;
878 double *typePtr = (double *)&storage[field->description_->offset]; 812 double *typePtr = (double *)&storage[field->description_->offset];
879 *typePtr = value; 813 *typePtr = value;
880 // proto2: any value counts as having been set; proto3, it 814 // proto2: any value counts as having been set; proto3, it
881 // has to be a non zero value or be in a oneof. 815 // has to be a non zero value.
882 BOOL hasValue = ((syntax == GPBFileSyntaxProto2) 816 BOOL hasValue =
883 || (value != (double)0) 817 (syntax == GPBFileSyntaxProto2) || (value != (double)0);
884 || (field->containingOneof_ != NULL));
885 GPBSetHasIvarField(self, field, hasValue); 818 GPBSetHasIvarField(self, field, hasValue);
886 GPBBecomeVisibleToAutocreator(self); 819 GPBBecomeVisibleToAutocreator(self);
887 } 820 }
888 821
889 //%PDDM-EXPAND-END (6 expansions) 822 //%PDDM-EXPAND-END (6 expansions)
890 823
891 // Aliases are function calls that are virtually the same. 824 // Aliases are function calls that are virtually the same.
892 825
893 //%PDDM-EXPAND IVAR_ALIAS_DEFN_OBJECT(String, NSString) 826 //%PDDM-EXPAND IVAR_ALIAS_DEFN_OBJECT(String, NSString)
894 // This block of code is generated, do not edit it directly. 827 // This block of code is generated, do not edit it directly.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 882
950 // Only exists for public api, no core code should use this. 883 // Only exists for public api, no core code should use this.
951 void GPBSetMessageGroupField(GPBMessage *self, 884 void GPBSetMessageGroupField(GPBMessage *self,
952 GPBFieldDescriptor *field, 885 GPBFieldDescriptor *field,
953 GPBMessage *value) { 886 GPBMessage *value) {
954 GPBSetObjectIvarWithField(self, field, (id)value); 887 GPBSetObjectIvarWithField(self, field, (id)value);
955 } 888 }
956 889
957 //%PDDM-EXPAND-END (4 expansions) 890 //%PDDM-EXPAND-END (4 expansions)
958 891
959 // GPBGetMessageRepeatedField is defined in GPBMessage.m 892 // Only exists for public api, no core code should use this.
893 id GPBGetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field) {
894 #if DEBUG
895 if (field.fieldType != GPBFieldTypeRepeated) {
896 [NSException raise:NSInvalidArgumentException
897 format:@"%@.%@ is not a repeated field.",
898 [self class], field.name];
899 }
900 #endif
901 return GPBGetObjectIvarWithField(self, field);
902 }
960 903
961 // Only exists for public api, no core code should use this. 904 // Only exists for public api, no core code should use this.
962 void GPBSetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field, id array) { 905 void GPBSetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field, id array) {
963 #if defined(DEBUG) && DEBUG 906 #if DEBUG
964 if (field.fieldType != GPBFieldTypeRepeated) { 907 if (field.fieldType != GPBFieldTypeRepeated) {
965 [NSException raise:NSInvalidArgumentException 908 [NSException raise:NSInvalidArgumentException
966 format:@"%@.%@ is not a repeated field.", 909 format:@"%@.%@ is not a repeated field.",
967 [self class], field.name]; 910 [self class], field.name];
968 } 911 }
969 Class expectedClass = Nil; 912 Class expectedClass = Nil;
970 switch (GPBGetFieldDataType(field)) { 913 switch (GPBGetFieldDataType(field)) {
971 case GPBDataTypeBool: 914 case GPBDataTypeBool:
972 expectedClass = [GPBBoolArray class]; 915 expectedClass = [GPBBoolArray class];
973 break; 916 break;
(...skipping 18 matching lines...) Expand all
992 case GPBDataTypeFloat: 935 case GPBDataTypeFloat:
993 expectedClass = [GPBFloatArray class]; 936 expectedClass = [GPBFloatArray class];
994 break; 937 break;
995 case GPBDataTypeDouble: 938 case GPBDataTypeDouble:
996 expectedClass = [GPBDoubleArray class]; 939 expectedClass = [GPBDoubleArray class];
997 break; 940 break;
998 case GPBDataTypeBytes: 941 case GPBDataTypeBytes:
999 case GPBDataTypeString: 942 case GPBDataTypeString:
1000 case GPBDataTypeMessage: 943 case GPBDataTypeMessage:
1001 case GPBDataTypeGroup: 944 case GPBDataTypeGroup:
1002 expectedClass = [NSMutableArray class]; 945 expectedClass = [NSMutableDictionary class];
1003 break; 946 break;
1004 case GPBDataTypeEnum: 947 case GPBDataTypeEnum:
1005 expectedClass = [GPBEnumArray class]; 948 expectedClass = [GPBBoolArray class];
1006 break; 949 break;
1007 } 950 }
1008 if (array && ![array isKindOfClass:expectedClass]) { 951 if (array && ![array isKindOfClass:expectedClass]) {
1009 [NSException raise:NSInvalidArgumentException 952 [NSException raise:NSInvalidArgumentException
1010 format:@"%@.%@: Expected %@ object, got %@.", 953 format:@"%@.%@: Expected %@ object, got %@.",
1011 [self class], field.name, expectedClass, [array class]]; 954 [self class], field.name, expectedClass, [array class]];
1012 } 955 }
1013 #endif 956 #endif
1014 GPBSetObjectIvarWithField(self, field, array); 957 GPBSetObjectIvarWithField(self, field, array);
1015 } 958 }
1016 959
1017 #if defined(DEBUG) && DEBUG 960 #if DEBUG
1018 static NSString *TypeToStr(GPBDataType dataType) { 961 static NSString *TypeToStr(GPBDataType dataType) {
1019 switch (dataType) { 962 switch (dataType) {
1020 case GPBDataTypeBool: 963 case GPBDataTypeBool:
1021 return @"Bool"; 964 return @"Bool";
1022 case GPBDataTypeSFixed32: 965 case GPBDataTypeSFixed32:
1023 case GPBDataTypeInt32: 966 case GPBDataTypeInt32:
1024 case GPBDataTypeSInt32: 967 case GPBDataTypeSInt32:
1025 return @"Int32"; 968 return @"Int32";
1026 case GPBDataTypeFixed32: 969 case GPBDataTypeFixed32:
1027 case GPBDataTypeUInt32: 970 case GPBDataTypeUInt32:
(...skipping 13 matching lines...) Expand all
1041 case GPBDataTypeString: 984 case GPBDataTypeString:
1042 case GPBDataTypeMessage: 985 case GPBDataTypeMessage:
1043 case GPBDataTypeGroup: 986 case GPBDataTypeGroup:
1044 return @"Object"; 987 return @"Object";
1045 case GPBDataTypeEnum: 988 case GPBDataTypeEnum:
1046 return @"Bool"; 989 return @"Bool";
1047 } 990 }
1048 } 991 }
1049 #endif 992 #endif
1050 993
1051 // GPBGetMessageMapField is defined in GPBMessage.m 994 // Only exists for public api, no core code should use this.
995 id GPBGetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field) {
996 #if DEBUG
997 if (field.fieldType != GPBFieldTypeMap) {
998 [NSException raise:NSInvalidArgumentException
999 format:@"%@.%@ is not a map<> field.",
1000 [self class], field.name];
1001 }
1002 #endif
1003 return GPBGetObjectIvarWithField(self, field);
1004 }
1052 1005
1053 // Only exists for public api, no core code should use this. 1006 // Only exists for public api, no core code should use this.
1054 void GPBSetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field, 1007 void GPBSetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field,
1055 id dictionary) { 1008 id dictionary) {
1056 #if defined(DEBUG) && DEBUG 1009 #if DEBUG
1057 if (field.fieldType != GPBFieldTypeMap) { 1010 if (field.fieldType != GPBFieldTypeMap) {
1058 [NSException raise:NSInvalidArgumentException 1011 [NSException raise:NSInvalidArgumentException
1059 format:@"%@.%@ is not a map<> field.", 1012 format:@"%@.%@ is not a map<> field.",
1060 [self class], field.name]; 1013 [self class], field.name];
1061 } 1014 }
1062 if (dictionary) { 1015 if (dictionary) {
1063 GPBDataType keyDataType = field.mapKeyDataType; 1016 GPBDataType keyDataType = field.mapKeyDataType;
1064 GPBDataType valueDataType = GPBGetFieldDataType(field); 1017 GPBDataType valueDataType = GPBGetFieldDataType(field);
1065 NSString *keyStr = TypeToStr(keyDataType); 1018 NSString *keyStr = TypeToStr(keyDataType);
1066 NSString *valueStr = TypeToStr(valueDataType); 1019 NSString *valueStr = TypeToStr(valueDataType);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1106 for (NSUInteger i = 0; i < len; ++i) { 1059 for (NSUInteger i = 0; i < len; ++i) {
1107 unichar aChar = [toPrint characterAtIndex:i]; 1060 unichar aChar = [toPrint characterAtIndex:i];
1108 switch (aChar) { 1061 switch (aChar) {
1109 case '\n': [destStr appendString:@"\\n"]; break; 1062 case '\n': [destStr appendString:@"\\n"]; break;
1110 case '\r': [destStr appendString:@"\\r"]; break; 1063 case '\r': [destStr appendString:@"\\r"]; break;
1111 case '\t': [destStr appendString:@"\\t"]; break; 1064 case '\t': [destStr appendString:@"\\t"]; break;
1112 case '\"': [destStr appendString:@"\\\""]; break; 1065 case '\"': [destStr appendString:@"\\\""]; break;
1113 case '\'': [destStr appendString:@"\\\'"]; break; 1066 case '\'': [destStr appendString:@"\\\'"]; break;
1114 case '\\': [destStr appendString:@"\\\\"]; break; 1067 case '\\': [destStr appendString:@"\\\\"]; break;
1115 default: 1068 default:
1116 // This differs slightly from the C++ code in that the C++ doesn't 1069 [destStr appendFormat:@"%C", aChar];
1117 // generate UTF8; it looks at the string in UTF8, but escapes every
1118 // byte > 0x7E.
1119 if (aChar < 0x20) {
1120 [destStr appendFormat:@"\\%d%d%d",
1121 (aChar / 64), ((aChar % 64) / 8), (aChar % 8)];
1122 } else {
1123 [destStr appendFormat:@"%C", aChar];
1124 }
1125 break; 1070 break;
1126 } 1071 }
1127 } 1072 }
1128 [destStr appendString:@"\""]; 1073 [destStr appendString:@"\""];
1129 } 1074 }
1130 1075
1131 static void AppendBufferAsString(NSData *buffer, NSMutableString *destStr) { 1076 static void AppendBufferAsString(NSData *buffer, NSMutableString *destStr) {
1132 const char *src = (const char *)[buffer bytes]; 1077 const char *src = (const char *)[buffer bytes];
1133 size_t srcLen = [buffer length]; 1078 size_t srcLen = [buffer length];
1134 [destStr appendString:@"\""]; 1079 [destStr appendString:@"\""];
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 [dict enumerateKeysAndObjectsUsingBlock:^(NSString *key, id value, BOOL *sto p) { 1126 [dict enumerateKeysAndObjectsUsingBlock:^(NSString *key, id value, BOOL *sto p) {
1182 #pragma unused(stop) 1127 #pragma unused(stop)
1183 [toStr appendString:(isFirst ? msgStartFirst : msgStart)]; 1128 [toStr appendString:(isFirst ? msgStartFirst : msgStart)];
1184 isFirst = NO; 1129 isFirst = NO;
1185 1130
1186 [toStr appendString:keyLine]; 1131 [toStr appendString:keyLine];
1187 AppendStringEscaped(key, toStr); 1132 AppendStringEscaped(key, toStr);
1188 [toStr appendString:@"\n"]; 1133 [toStr appendString:@"\n"];
1189 1134
1190 [toStr appendString:valueLine]; 1135 [toStr appendString:valueLine];
1191 #pragma clang diagnostic push
1192 #pragma clang diagnostic ignored "-Wswitch-enum"
1193 switch (valueDataType) { 1136 switch (valueDataType) {
1194 case GPBDataTypeString: 1137 case GPBDataTypeString:
1195 AppendStringEscaped(value, toStr); 1138 AppendStringEscaped(value, toStr);
1196 break; 1139 break;
1197 1140
1198 case GPBDataTypeBytes: 1141 case GPBDataTypeBytes:
1199 AppendBufferAsString(value, toStr); 1142 AppendBufferAsString(value, toStr);
1200 break; 1143 break;
1201 1144
1202 case GPBDataTypeMessage: 1145 case GPBDataTypeMessage:
1203 [toStr appendString:@"{\n"]; 1146 [toStr appendString:@"{\n"];
1204 NSString *subIndent = [lineIndent stringByAppendingString:@" "]; 1147 NSString *subIndent = [lineIndent stringByAppendingString:@" "];
1205 AppendTextFormatForMessage(value, toStr, subIndent); 1148 AppendTextFormatForMessage(value, toStr, subIndent);
1206 [toStr appendFormat:@"%@ }", lineIndent]; 1149 [toStr appendFormat:@"%@ }", lineIndent];
1207 break; 1150 break;
1208 1151
1209 default: 1152 default:
1210 NSCAssert(NO, @"Can't happen"); 1153 NSCAssert(NO, @"Can't happen");
1211 break; 1154 break;
1212 } 1155 }
1213 #pragma clang diagnostic pop
1214 [toStr appendString:@"\n"]; 1156 [toStr appendString:@"\n"];
1215 1157
1216 [toStr appendString:msgEnd]; 1158 [toStr appendString:msgEnd];
1217 }]; 1159 }];
1218 } else { 1160 } else {
1219 // map is one of the GPB*Dictionary classes, type doesn't matter. 1161 // map is one of the GPB*Dictionary classes, type doesn't matter.
1220 GPBInt32Int32Dictionary *dict = map; 1162 GPBInt32Int32Dictionary *dict = map;
1221 [dict enumerateForTextFormat:^(id keyObj, id valueObj) { 1163 [dict enumerateForTextFormat:^(id keyObj, id valueObj) {
1222 [toStr appendString:(isFirst ? msgStartFirst : msgStart)]; 1164 [toStr appendString:(isFirst ? msgStartFirst : msgStart)];
1223 isFirst = NO; 1165 isFirst = NO;
1224 1166
1225 // Key always is a NSString. 1167 // Key always is a NSString.
1226 if (keyDataType == GPBDataTypeString) { 1168 if (keyDataType == GPBDataTypeString) {
1227 [toStr appendString:keyLine]; 1169 [toStr appendString:keyLine];
1228 AppendStringEscaped(keyObj, toStr); 1170 AppendStringEscaped(keyObj, toStr);
1229 [toStr appendString:@"\n"]; 1171 [toStr appendString:@"\n"];
1230 } else { 1172 } else {
1231 [toStr appendFormat:@"%@%@\n", keyLine, keyObj]; 1173 [toStr appendFormat:@"%@%@\n", keyLine, keyObj];
1232 } 1174 }
1233 1175
1234 [toStr appendString:valueLine]; 1176 [toStr appendString:valueLine];
1235 #pragma clang diagnostic push
1236 #pragma clang diagnostic ignored "-Wswitch-enum"
1237 switch (valueDataType) { 1177 switch (valueDataType) {
1238 case GPBDataTypeString: 1178 case GPBDataTypeString:
1239 AppendStringEscaped(valueObj, toStr); 1179 AppendStringEscaped(valueObj, toStr);
1240 break; 1180 break;
1241 1181
1242 case GPBDataTypeBytes: 1182 case GPBDataTypeBytes:
1243 AppendBufferAsString(valueObj, toStr); 1183 AppendBufferAsString(valueObj, toStr);
1244 break; 1184 break;
1245 1185
1246 case GPBDataTypeMessage: 1186 case GPBDataTypeMessage:
(...skipping 17 matching lines...) Expand all
1264 } 1204 }
1265 break; 1205 break;
1266 } 1206 }
1267 1207
1268 default: 1208 default:
1269 NSCAssert(valueDataType != GPBDataTypeGroup, @"Can't happen"); 1209 NSCAssert(valueDataType != GPBDataTypeGroup, @"Can't happen");
1270 // Everything else is a NSString. 1210 // Everything else is a NSString.
1271 [toStr appendString:valueObj]; 1211 [toStr appendString:valueObj];
1272 break; 1212 break;
1273 } 1213 }
1274 #pragma clang diagnostic pop
1275 [toStr appendString:@"\n"]; 1214 [toStr appendString:@"\n"];
1276 1215
1277 [toStr appendString:msgEnd]; 1216 [toStr appendString:msgEnd];
1278 }]; 1217 }];
1279 } 1218 }
1280 } 1219 }
1281 1220
1282 static void AppendTextFormatForMessageField(GPBMessage *message, 1221 static void AppendTextFormatForMessageField(GPBMessage *message,
1283 GPBFieldDescriptor *field, 1222 GPBFieldDescriptor *field,
1284 NSMutableString *toStr, 1223 NSMutableString *toStr,
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
1534 } 1473 }
1535 1474
1536 static void AppendTextFormatForMessage(GPBMessage *message, 1475 static void AppendTextFormatForMessage(GPBMessage *message,
1537 NSMutableString *toStr, 1476 NSMutableString *toStr,
1538 NSString *lineIndent) { 1477 NSString *lineIndent) {
1539 GPBDescriptor *descriptor = [message descriptor]; 1478 GPBDescriptor *descriptor = [message descriptor];
1540 NSArray *fieldsArray = descriptor->fields_; 1479 NSArray *fieldsArray = descriptor->fields_;
1541 NSUInteger fieldCount = fieldsArray.count; 1480 NSUInteger fieldCount = fieldsArray.count;
1542 const GPBExtensionRange *extensionRanges = descriptor.extensionRanges; 1481 const GPBExtensionRange *extensionRanges = descriptor.extensionRanges;
1543 NSUInteger extensionRangesCount = descriptor.extensionRangesCount; 1482 NSUInteger extensionRangesCount = descriptor.extensionRangesCount;
1544 NSArray *activeExtensions = [[message extensionsCurrentlySet] 1483 NSArray *activeExtensions = [message sortedExtensionsInUse];
1545 sortedArrayUsingSelector:@selector(compareByFieldNumber:)];
1546 for (NSUInteger i = 0, j = 0; i < fieldCount || j < extensionRangesCount;) { 1484 for (NSUInteger i = 0, j = 0; i < fieldCount || j < extensionRangesCount;) {
1547 if (i == fieldCount) { 1485 if (i == fieldCount) {
1548 AppendTextFormatForMessageExtensionRange( 1486 AppendTextFormatForMessageExtensionRange(
1549 message, activeExtensions, extensionRanges[j++], toStr, lineIndent); 1487 message, activeExtensions, extensionRanges[j++], toStr, lineIndent);
1550 } else if (j == extensionRangesCount || 1488 } else if (j == extensionRangesCount ||
1551 GPBFieldNumber(fieldsArray[i]) < extensionRanges[j].start) { 1489 GPBFieldNumber(fieldsArray[i]) < extensionRanges[j].start) {
1552 AppendTextFormatForMessageField(message, fieldsArray[i++], toStr, 1490 AppendTextFormatForMessageField(message, fieldsArray[i++], toStr,
1553 lineIndent); 1491 lineIndent);
1554 } else { 1492 } else {
1555 AppendTextFormatForMessageExtensionRange( 1493 AppendTextFormatForMessageExtensionRange(
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
1761 } else { 1699 } else {
1762 [result appendFormat:@"%C", c]; 1700 [result appendFormat:@"%C", c];
1763 } 1701 }
1764 } 1702 }
1765 i += segmentLen; 1703 i += segmentLen;
1766 } 1704 }
1767 1705
1768 return result; 1706 return result;
1769 } 1707 }
1770 1708
1771 #pragma clang diagnostic pop
1772
1773 #pragma mark - GPBMessageSignatureProtocol 1709 #pragma mark - GPBMessageSignatureProtocol
1774 1710
1775 // A series of selectors that are used solely to get @encoding values 1711 // A series of selectors that are used solely to get @encoding values
1776 // for them by the dynamic protobuf runtime code. An object using the protocol 1712 // for them by the dynamic protobuf runtime code. An object using the protocol
1777 // needs to be declared for the protocol to be valid at runtime. 1713 // needs to be declared for the protocol to be valid at runtime.
1778 @interface GPBMessageSignatureProtocol : NSObject<GPBMessageSignatureProtocol> 1714 @interface GPBMessageSignatureProtocol : NSObject<GPBMessageSignatureProtocol>
1779 @end 1715 @end
1780 @implementation GPBMessageSignatureProtocol 1716 @implementation GPBMessageSignatureProtocol
1781 @end 1717 @end
OLDNEW
« no previous file with comments | « third_party/protobuf/objectivec/GPBUtilities.h ('k') | third_party/protobuf/objectivec/GPBUtilities_PackagePrivate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698