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

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

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