forked from protocolbuffers/protobuf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GPBDictionary.m
12150 lines (10741 loc) · 376 KB
/
GPBDictionary.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#import "GPBDictionary_PackagePrivate.h"
#import "GPBCodedInputStream_PackagePrivate.h"
#import "GPBCodedOutputStream_PackagePrivate.h"
#import "GPBDescriptor_PackagePrivate.h"
#import "GPBMessage_PackagePrivate.h"
#import "GPBUtilities_PackagePrivate.h"
// ------------------------------ NOTE ------------------------------
// At the moment, this is all using NSNumbers in NSDictionaries under
// the hood, but it is all hidden so we can come back and optimize
// with direct CFDictionary usage later. The reason that wasn't
// done yet is needing to support 32bit iOS builds. Otherwise
// it would be pretty simple to store all this data in CFDictionaries
// directly.
// ------------------------------------------------------------------
// Direct access is use for speed, to avoid even internally declaring things
// read/write, etc. The warning is enabled in the project to ensure code calling
// protos can turn on -Wdirect-ivar-access without issues.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdirect-ivar-access"
// Used to include code only visible to specific versions of the static
// analyzer. Useful for wrapping code that only exists to silence the analyzer.
// Determine the values you want to use for BEGIN_APPLE_BUILD_VERSION,
// END_APPLE_BUILD_VERSION using:
// xcrun clang -dM -E -x c /dev/null | grep __apple_build_version__
// Example usage:
// #if GPB_STATIC_ANALYZER_ONLY(5621, 5623) ... #endif
#define GPB_STATIC_ANALYZER_ONLY(BEGIN_APPLE_BUILD_VERSION, END_APPLE_BUILD_VERSION) \
(defined(__clang_analyzer__) && \
(__apple_build_version__ >= BEGIN_APPLE_BUILD_VERSION && \
__apple_build_version__ <= END_APPLE_BUILD_VERSION))
enum {
kMapKeyFieldNumber = 1,
kMapValueFieldNumber = 2,
};
static BOOL DictDefault_IsValidValue(int32_t value) {
// Anything but the bad value marker is allowed.
return (value != kGPBUnrecognizedEnumeratorValue);
}
//%PDDM-DEFINE SERIALIZE_SUPPORT_2_TYPE(VALUE_NAME, VALUE_TYPE, GPBDATATYPE_NAME1, GPBDATATYPE_NAME2)
//%static size_t ComputeDict##VALUE_NAME##FieldSize(VALUE_TYPE value, uint32_t fieldNum, GPBDataType dataType) {
//% if (dataType == GPBDataType##GPBDATATYPE_NAME1) {
//% return GPBCompute##GPBDATATYPE_NAME1##Size(fieldNum, value);
//% } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) {
//% return GPBCompute##GPBDATATYPE_NAME2##Size(fieldNum, value);
//% } else {
//% NSCAssert(NO, @"Unexpected type %d", dataType);
//% return 0;
//% }
//%}
//%
//%static void WriteDict##VALUE_NAME##Field(GPBCodedOutputStream *stream, VALUE_TYPE value, uint32_t fieldNum, GPBDataType dataType) {
//% if (dataType == GPBDataType##GPBDATATYPE_NAME1) {
//% [stream write##GPBDATATYPE_NAME1##:fieldNum value:value];
//% } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) {
//% [stream write##GPBDATATYPE_NAME2##:fieldNum value:value];
//% } else {
//% NSCAssert(NO, @"Unexpected type %d", dataType);
//% }
//%}
//%
//%PDDM-DEFINE SERIALIZE_SUPPORT_3_TYPE(VALUE_NAME, VALUE_TYPE, GPBDATATYPE_NAME1, GPBDATATYPE_NAME2, GPBDATATYPE_NAME3)
//%static size_t ComputeDict##VALUE_NAME##FieldSize(VALUE_TYPE value, uint32_t fieldNum, GPBDataType dataType) {
//% if (dataType == GPBDataType##GPBDATATYPE_NAME1) {
//% return GPBCompute##GPBDATATYPE_NAME1##Size(fieldNum, value);
//% } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) {
//% return GPBCompute##GPBDATATYPE_NAME2##Size(fieldNum, value);
//% } else if (dataType == GPBDataType##GPBDATATYPE_NAME3) {
//% return GPBCompute##GPBDATATYPE_NAME3##Size(fieldNum, value);
//% } else {
//% NSCAssert(NO, @"Unexpected type %d", dataType);
//% return 0;
//% }
//%}
//%
//%static void WriteDict##VALUE_NAME##Field(GPBCodedOutputStream *stream, VALUE_TYPE value, uint32_t fieldNum, GPBDataType dataType) {
//% if (dataType == GPBDataType##GPBDATATYPE_NAME1) {
//% [stream write##GPBDATATYPE_NAME1##:fieldNum value:value];
//% } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) {
//% [stream write##GPBDATATYPE_NAME2##:fieldNum value:value];
//% } else if (dataType == GPBDataType##GPBDATATYPE_NAME3) {
//% [stream write##GPBDATATYPE_NAME3##:fieldNum value:value];
//% } else {
//% NSCAssert(NO, @"Unexpected type %d", dataType);
//% }
//%}
//%
//%PDDM-DEFINE SIMPLE_SERIALIZE_SUPPORT(VALUE_NAME, VALUE_TYPE, VisP)
//%static size_t ComputeDict##VALUE_NAME##FieldSize(VALUE_TYPE VisP##value, uint32_t fieldNum, GPBDataType dataType) {
//% NSCAssert(dataType == GPBDataType##VALUE_NAME, @"bad type: %d", dataType);
//% #pragma unused(dataType) // For when asserts are off in release.
//% return GPBCompute##VALUE_NAME##Size(fieldNum, value);
//%}
//%
//%static void WriteDict##VALUE_NAME##Field(GPBCodedOutputStream *stream, VALUE_TYPE VisP##value, uint32_t fieldNum, GPBDataType dataType) {
//% NSCAssert(dataType == GPBDataType##VALUE_NAME, @"bad type: %d", dataType);
//% #pragma unused(dataType) // For when asserts are off in release.
//% [stream write##VALUE_NAME##:fieldNum value:value];
//%}
//%
//%PDDM-DEFINE SERIALIZE_SUPPORT_HELPERS()
//%SERIALIZE_SUPPORT_3_TYPE(Int32, int32_t, Int32, SInt32, SFixed32)
//%SERIALIZE_SUPPORT_2_TYPE(UInt32, uint32_t, UInt32, Fixed32)
//%SERIALIZE_SUPPORT_3_TYPE(Int64, int64_t, Int64, SInt64, SFixed64)
//%SERIALIZE_SUPPORT_2_TYPE(UInt64, uint64_t, UInt64, Fixed64)
//%SIMPLE_SERIALIZE_SUPPORT(Bool, BOOL, )
//%SIMPLE_SERIALIZE_SUPPORT(Enum, int32_t, )
//%SIMPLE_SERIALIZE_SUPPORT(Float, float, )
//%SIMPLE_SERIALIZE_SUPPORT(Double, double, )
//%SIMPLE_SERIALIZE_SUPPORT(String, NSString, *)
//%SERIALIZE_SUPPORT_3_TYPE(Object, id, Message, String, Bytes)
//%PDDM-EXPAND SERIALIZE_SUPPORT_HELPERS()
// This block of code is generated, do not edit it directly.
// clang-format off
static size_t ComputeDictInt32FieldSize(int32_t value, uint32_t fieldNum, GPBDataType dataType) {
if (dataType == GPBDataTypeInt32) {
return GPBComputeInt32Size(fieldNum, value);
} else if (dataType == GPBDataTypeSInt32) {
return GPBComputeSInt32Size(fieldNum, value);
} else if (dataType == GPBDataTypeSFixed32) {
return GPBComputeSFixed32Size(fieldNum, value);
} else {
NSCAssert(NO, @"Unexpected type %d", dataType);
return 0;
}
}
static void WriteDictInt32Field(GPBCodedOutputStream *stream, int32_t value, uint32_t fieldNum, GPBDataType dataType) {
if (dataType == GPBDataTypeInt32) {
[stream writeInt32:fieldNum value:value];
} else if (dataType == GPBDataTypeSInt32) {
[stream writeSInt32:fieldNum value:value];
} else if (dataType == GPBDataTypeSFixed32) {
[stream writeSFixed32:fieldNum value:value];
} else {
NSCAssert(NO, @"Unexpected type %d", dataType);
}
}
static size_t ComputeDictUInt32FieldSize(uint32_t value, uint32_t fieldNum, GPBDataType dataType) {
if (dataType == GPBDataTypeUInt32) {
return GPBComputeUInt32Size(fieldNum, value);
} else if (dataType == GPBDataTypeFixed32) {
return GPBComputeFixed32Size(fieldNum, value);
} else {
NSCAssert(NO, @"Unexpected type %d", dataType);
return 0;
}
}
static void WriteDictUInt32Field(GPBCodedOutputStream *stream, uint32_t value, uint32_t fieldNum, GPBDataType dataType) {
if (dataType == GPBDataTypeUInt32) {
[stream writeUInt32:fieldNum value:value];
} else if (dataType == GPBDataTypeFixed32) {
[stream writeFixed32:fieldNum value:value];
} else {
NSCAssert(NO, @"Unexpected type %d", dataType);
}
}
static size_t ComputeDictInt64FieldSize(int64_t value, uint32_t fieldNum, GPBDataType dataType) {
if (dataType == GPBDataTypeInt64) {
return GPBComputeInt64Size(fieldNum, value);
} else if (dataType == GPBDataTypeSInt64) {
return GPBComputeSInt64Size(fieldNum, value);
} else if (dataType == GPBDataTypeSFixed64) {
return GPBComputeSFixed64Size(fieldNum, value);
} else {
NSCAssert(NO, @"Unexpected type %d", dataType);
return 0;
}
}
static void WriteDictInt64Field(GPBCodedOutputStream *stream, int64_t value, uint32_t fieldNum, GPBDataType dataType) {
if (dataType == GPBDataTypeInt64) {
[stream writeInt64:fieldNum value:value];
} else if (dataType == GPBDataTypeSInt64) {
[stream writeSInt64:fieldNum value:value];
} else if (dataType == GPBDataTypeSFixed64) {
[stream writeSFixed64:fieldNum value:value];
} else {
NSCAssert(NO, @"Unexpected type %d", dataType);
}
}
static size_t ComputeDictUInt64FieldSize(uint64_t value, uint32_t fieldNum, GPBDataType dataType) {
if (dataType == GPBDataTypeUInt64) {
return GPBComputeUInt64Size(fieldNum, value);
} else if (dataType == GPBDataTypeFixed64) {
return GPBComputeFixed64Size(fieldNum, value);
} else {
NSCAssert(NO, @"Unexpected type %d", dataType);
return 0;
}
}
static void WriteDictUInt64Field(GPBCodedOutputStream *stream, uint64_t value, uint32_t fieldNum, GPBDataType dataType) {
if (dataType == GPBDataTypeUInt64) {
[stream writeUInt64:fieldNum value:value];
} else if (dataType == GPBDataTypeFixed64) {
[stream writeFixed64:fieldNum value:value];
} else {
NSCAssert(NO, @"Unexpected type %d", dataType);
}
}
static size_t ComputeDictBoolFieldSize(BOOL value, uint32_t fieldNum, GPBDataType dataType) {
NSCAssert(dataType == GPBDataTypeBool, @"bad type: %d", dataType);
#pragma unused(dataType) // For when asserts are off in release.
return GPBComputeBoolSize(fieldNum, value);
}
static void WriteDictBoolField(GPBCodedOutputStream *stream, BOOL value, uint32_t fieldNum, GPBDataType dataType) {
NSCAssert(dataType == GPBDataTypeBool, @"bad type: %d", dataType);
#pragma unused(dataType) // For when asserts are off in release.
[stream writeBool:fieldNum value:value];
}
static size_t ComputeDictEnumFieldSize(int32_t value, uint32_t fieldNum, GPBDataType dataType) {
NSCAssert(dataType == GPBDataTypeEnum, @"bad type: %d", dataType);
#pragma unused(dataType) // For when asserts are off in release.
return GPBComputeEnumSize(fieldNum, value);
}
static void WriteDictEnumField(GPBCodedOutputStream *stream, int32_t value, uint32_t fieldNum, GPBDataType dataType) {
NSCAssert(dataType == GPBDataTypeEnum, @"bad type: %d", dataType);
#pragma unused(dataType) // For when asserts are off in release.
[stream writeEnum:fieldNum value:value];
}
static size_t ComputeDictFloatFieldSize(float value, uint32_t fieldNum, GPBDataType dataType) {
NSCAssert(dataType == GPBDataTypeFloat, @"bad type: %d", dataType);
#pragma unused(dataType) // For when asserts are off in release.
return GPBComputeFloatSize(fieldNum, value);
}
static void WriteDictFloatField(GPBCodedOutputStream *stream, float value, uint32_t fieldNum, GPBDataType dataType) {
NSCAssert(dataType == GPBDataTypeFloat, @"bad type: %d", dataType);
#pragma unused(dataType) // For when asserts are off in release.
[stream writeFloat:fieldNum value:value];
}
static size_t ComputeDictDoubleFieldSize(double value, uint32_t fieldNum, GPBDataType dataType) {
NSCAssert(dataType == GPBDataTypeDouble, @"bad type: %d", dataType);
#pragma unused(dataType) // For when asserts are off in release.
return GPBComputeDoubleSize(fieldNum, value);
}
static void WriteDictDoubleField(GPBCodedOutputStream *stream, double value, uint32_t fieldNum, GPBDataType dataType) {
NSCAssert(dataType == GPBDataTypeDouble, @"bad type: %d", dataType);
#pragma unused(dataType) // For when asserts are off in release.
[stream writeDouble:fieldNum value:value];
}
static size_t ComputeDictStringFieldSize(NSString *value, uint32_t fieldNum, GPBDataType dataType) {
NSCAssert(dataType == GPBDataTypeString, @"bad type: %d", dataType);
#pragma unused(dataType) // For when asserts are off in release.
return GPBComputeStringSize(fieldNum, value);
}
static void WriteDictStringField(GPBCodedOutputStream *stream, NSString *value, uint32_t fieldNum, GPBDataType dataType) {
NSCAssert(dataType == GPBDataTypeString, @"bad type: %d", dataType);
#pragma unused(dataType) // For when asserts are off in release.
[stream writeString:fieldNum value:value];
}
static size_t ComputeDictObjectFieldSize(id value, uint32_t fieldNum, GPBDataType dataType) {
if (dataType == GPBDataTypeMessage) {
return GPBComputeMessageSize(fieldNum, value);
} else if (dataType == GPBDataTypeString) {
return GPBComputeStringSize(fieldNum, value);
} else if (dataType == GPBDataTypeBytes) {
return GPBComputeBytesSize(fieldNum, value);
} else {
NSCAssert(NO, @"Unexpected type %d", dataType);
return 0;
}
}
static void WriteDictObjectField(GPBCodedOutputStream *stream, id value, uint32_t fieldNum, GPBDataType dataType) {
if (dataType == GPBDataTypeMessage) {
[stream writeMessage:fieldNum value:value];
} else if (dataType == GPBDataTypeString) {
[stream writeString:fieldNum value:value];
} else if (dataType == GPBDataTypeBytes) {
[stream writeBytes:fieldNum value:value];
} else {
NSCAssert(NO, @"Unexpected type %d", dataType);
}
}
// clang-format on
//%PDDM-EXPAND-END SERIALIZE_SUPPORT_HELPERS()
size_t GPBDictionaryComputeSizeInternalHelper(NSDictionary *dict, GPBFieldDescriptor *field) {
GPBDataType mapValueType = GPBGetFieldDataType(field);
size_t result = 0;
NSString *key;
NSEnumerator *keys = [dict keyEnumerator];
while ((key = [keys nextObject])) {
id obj = dict[key];
size_t msgSize = GPBComputeStringSize(kMapKeyFieldNumber, key);
msgSize += ComputeDictObjectFieldSize(obj, kMapValueFieldNumber, mapValueType);
result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
}
size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
result += tagSize * dict.count;
return result;
}
void GPBDictionaryWriteToStreamInternalHelper(GPBCodedOutputStream *outputStream,
NSDictionary *dict,
GPBFieldDescriptor *field) {
NSCAssert(field.mapKeyDataType == GPBDataTypeString, @"Unexpected key type");
GPBDataType mapValueType = GPBGetFieldDataType(field);
uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
NSString *key;
NSEnumerator *keys = [dict keyEnumerator];
while ((key = [keys nextObject])) {
id obj = dict[key];
// Write the tag.
[outputStream writeInt32NoTag:tag];
// Write the size of the message.
size_t msgSize = GPBComputeStringSize(kMapKeyFieldNumber, key);
msgSize += ComputeDictObjectFieldSize(obj, kMapValueFieldNumber, mapValueType);
// Write the size and fields.
[outputStream writeInt32NoTag:(int32_t)msgSize];
[outputStream writeString:kMapKeyFieldNumber value:key];
WriteDictObjectField(outputStream, obj, kMapValueFieldNumber, mapValueType);
}
}
BOOL GPBDictionaryIsInitializedInternalHelper(NSDictionary *dict, GPBFieldDescriptor *field) {
NSCAssert(field.mapKeyDataType == GPBDataTypeString, @"Unexpected key type");
NSCAssert(GPBGetFieldDataType(field) == GPBDataTypeMessage, @"Unexpected value type");
#pragma unused(field) // For when asserts are off in release.
GPBMessage *msg;
NSEnumerator *objects = [dict objectEnumerator];
while ((msg = [objects nextObject])) {
if (!msg.initialized) {
return NO;
}
}
return YES;
}
// Note: if the type is an object, it the retain pass back to the caller.
static void ReadValue(GPBCodedInputStream *stream,
GPBGenericValue *valueToFill,
GPBDataType type,
GPBExtensionRegistry *registry,
GPBFieldDescriptor *field) {
switch (type) {
case GPBDataTypeBool:
valueToFill->valueBool = GPBCodedInputStreamReadBool(&stream->state_);
break;
case GPBDataTypeFixed32:
valueToFill->valueUInt32 = GPBCodedInputStreamReadFixed32(&stream->state_);
break;
case GPBDataTypeSFixed32:
valueToFill->valueInt32 = GPBCodedInputStreamReadSFixed32(&stream->state_);
break;
case GPBDataTypeFloat:
valueToFill->valueFloat = GPBCodedInputStreamReadFloat(&stream->state_);
break;
case GPBDataTypeFixed64:
valueToFill->valueUInt64 = GPBCodedInputStreamReadFixed64(&stream->state_);
break;
case GPBDataTypeSFixed64:
valueToFill->valueInt64 = GPBCodedInputStreamReadSFixed64(&stream->state_);
break;
case GPBDataTypeDouble:
valueToFill->valueDouble = GPBCodedInputStreamReadDouble(&stream->state_);
break;
case GPBDataTypeInt32:
valueToFill->valueInt32 = GPBCodedInputStreamReadInt32(&stream->state_);
break;
case GPBDataTypeInt64:
valueToFill->valueInt64 = GPBCodedInputStreamReadInt64(&stream->state_);
break;
case GPBDataTypeSInt32:
valueToFill->valueInt32 = GPBCodedInputStreamReadSInt32(&stream->state_);
break;
case GPBDataTypeSInt64:
valueToFill->valueInt64 = GPBCodedInputStreamReadSInt64(&stream->state_);
break;
case GPBDataTypeUInt32:
valueToFill->valueUInt32 = GPBCodedInputStreamReadUInt32(&stream->state_);
break;
case GPBDataTypeUInt64:
valueToFill->valueUInt64 = GPBCodedInputStreamReadUInt64(&stream->state_);
break;
case GPBDataTypeBytes:
[valueToFill->valueData release];
valueToFill->valueData = GPBCodedInputStreamReadRetainedBytes(&stream->state_);
break;
case GPBDataTypeString:
[valueToFill->valueString release];
valueToFill->valueString = GPBCodedInputStreamReadRetainedString(&stream->state_);
break;
case GPBDataTypeMessage: {
GPBMessage *message = [[field.msgClass alloc] init];
[stream readMessage:message extensionRegistry:registry];
[valueToFill->valueMessage release];
valueToFill->valueMessage = message;
break;
}
case GPBDataTypeGroup:
NSCAssert(NO, @"Can't happen");
break;
case GPBDataTypeEnum:
valueToFill->valueEnum = GPBCodedInputStreamReadEnum(&stream->state_);
break;
}
}
void GPBDictionaryReadEntry(id mapDictionary,
GPBCodedInputStream *stream,
GPBExtensionRegistry *registry,
GPBFieldDescriptor *field,
GPBMessage *parentMessage) {
GPBDataType keyDataType = field.mapKeyDataType;
GPBDataType valueDataType = GPBGetFieldDataType(field);
GPBGenericValue key;
GPBGenericValue value;
// Zero them (but pick up any enum default for proto2).
key.valueString = value.valueString = nil;
if (valueDataType == GPBDataTypeEnum) {
value = field.defaultValue;
}
GPBCodedInputStreamState *state = &stream->state_;
uint32_t keyTag =
GPBWireFormatMakeTag(kMapKeyFieldNumber, GPBWireFormatForType(keyDataType, NO));
uint32_t valueTag =
GPBWireFormatMakeTag(kMapValueFieldNumber, GPBWireFormatForType(valueDataType, NO));
BOOL hitError = NO;
while (YES) {
uint32_t tag = GPBCodedInputStreamReadTag(state);
if (tag == keyTag) {
ReadValue(stream, &key, keyDataType, registry, field);
} else if (tag == valueTag) {
ReadValue(stream, &value, valueDataType, registry, field);
} else if (tag == 0) {
// zero signals EOF / limit reached
break;
} else { // Unknown
if (![stream skipField:tag]){
hitError = YES;
break;
}
}
}
if (!hitError) {
// Handle the special defaults and/or missing key/value.
if ((keyDataType == GPBDataTypeString) && (key.valueString == nil)) {
key.valueString = [@"" retain];
}
if (GPBDataTypeIsObject(valueDataType) && value.valueString == nil) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wswitch-enum"
switch (valueDataType) {
case GPBDataTypeString:
value.valueString = [@"" retain];
break;
case GPBDataTypeBytes:
value.valueData = [GPBEmptyNSData() retain];
break;
#if defined(__clang_analyzer__)
case GPBDataTypeGroup:
// Maps can't really have Groups as the value type, but this case is needed
// so the analyzer won't report the possibility of send nil in for the value
// in the NSMutableDictionary case below.
#endif
case GPBDataTypeMessage: {
value.valueMessage = [[field.msgClass alloc] init];
break;
}
default:
// Nothing
break;
}
#pragma clang diagnostic pop
}
if ((keyDataType == GPBDataTypeString) && GPBDataTypeIsObject(valueDataType)) {
#if GPB_STATIC_ANALYZER_ONLY(6020053, 7000181)
// Limited to Xcode 6.4 - 7.2, are known to fail here. The upper end can
// be raised as needed for new Xcodes.
//
// This is only needed on a "shallow" analyze; on a "deep" analyze, the
// existing code path gets this correct. In shallow, the analyzer decides
// GPBDataTypeIsObject(valueDataType) is both false and true on a single
// path through this function, allowing nil to be used for the
// setObject:forKey:.
if (value.valueString == nil) {
value.valueString = [@"" retain];
}
#endif
// mapDictionary is an NSMutableDictionary
[(NSMutableDictionary *)mapDictionary setObject:value.valueString
forKey:key.valueString];
} else {
if (valueDataType == GPBDataTypeEnum) {
if (GPBHasPreservingUnknownEnumSemantics([parentMessage descriptor].file.syntax) ||
[field isValidEnumValue:value.valueEnum]) {
[mapDictionary setGPBGenericValue:&value forGPBGenericValueKey:&key];
} else {
NSData *data = [mapDictionary serializedDataForUnknownValue:value.valueEnum
forKey:&key
keyDataType:keyDataType];
[parentMessage addUnknownMapEntry:GPBFieldNumber(field) value:data];
}
} else {
[mapDictionary setGPBGenericValue:&value forGPBGenericValueKey:&key];
}
}
}
if (GPBDataTypeIsObject(keyDataType)) {
[key.valueString release];
}
if (GPBDataTypeIsObject(valueDataType)) {
[value.valueString release];
}
}
//
// Macros for the common basic cases.
//
//%PDDM-DEFINE DICTIONARY_IMPL_FOR_POD_KEY(KEY_NAME, KEY_TYPE)
//%DICTIONARY_POD_IMPL_FOR_KEY(KEY_NAME, KEY_TYPE, , POD)
//%DICTIONARY_POD_KEY_TO_OBJECT_IMPL(KEY_NAME, KEY_TYPE, Object, id)
//%PDDM-DEFINE DICTIONARY_POD_IMPL_FOR_KEY(KEY_NAME, KEY_TYPE, KisP, KHELPER)
//%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, UInt32, uint32_t, KHELPER)
//%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Int32, int32_t, KHELPER)
//%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, UInt64, uint64_t, KHELPER)
//%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Int64, int64_t, KHELPER)
//%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Bool, BOOL, KHELPER)
//%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Float, float, KHELPER)
//%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Double, double, KHELPER)
//%DICTIONARY_KEY_TO_ENUM_IMPL(KEY_NAME, KEY_TYPE, KisP, Enum, int32_t, KHELPER)
//%PDDM-DEFINE DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER)
//%DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, POD, VALUE_NAME, value)
//%PDDM-DEFINE DICTIONARY_POD_KEY_TO_OBJECT_IMPL(KEY_NAME, KEY_TYPE, VALUE_NAME, VALUE_TYPE)
//%DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, , VALUE_NAME, VALUE_TYPE, POD, OBJECT, Object, object)
//%PDDM-DEFINE DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR)
//%#pragma mark - KEY_NAME -> VALUE_NAME
//%
//%@implementation GPB##KEY_NAME##VALUE_NAME##Dictionary {
//% @package
//% NSMutableDictionary *_dictionary;
//%}
//%
//%- (instancetype)init {
//% return [self initWith##VNAME##s:NULL forKeys:NULL count:0];
//%}
//%
//%- (instancetype)initWith##VNAME##s:(const VALUE_TYPE [])##VNAME_VAR##s
//% ##VNAME$S## forKeys:(const KEY_TYPE##KisP$S##KisP [])keys
//% ##VNAME$S## count:(NSUInteger)count {
//% self = [super init];
//% if (self) {
//% _dictionary = [[NSMutableDictionary alloc] init];
//% if (count && VNAME_VAR##s && keys) {
//% for (NSUInteger i = 0; i < count; ++i) {
//%DICTIONARY_VALIDATE_VALUE_##VHELPER(VNAME_VAR##s[i], ______)##DICTIONARY_VALIDATE_KEY_##KHELPER(keys[i], ______) [_dictionary setObject:WRAPPED##VHELPER(VNAME_VAR##s[i]) forKey:WRAPPED##KHELPER(keys[i])];
//% }
//% }
//% }
//% return self;
//%}
//%
//%- (instancetype)initWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary {
//% self = [self initWith##VNAME##s:NULL forKeys:NULL count:0];
//% if (self) {
//% if (dictionary) {
//% [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
//% }
//% }
//% return self;
//%}
//%
//%- (instancetype)initWithCapacity:(NSUInteger)numItems {
//% #pragma unused(numItems)
//% return [self initWith##VNAME##s:NULL forKeys:NULL count:0];
//%}
//%
//%DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, )
//%
//%VALUE_FOR_KEY_##VHELPER(KEY_TYPE##KisP$S##KisP, VALUE_NAME, VALUE_TYPE, KHELPER)
//%
//%DICTIONARY_MUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, )
//%
//%@end
//%
//%PDDM-DEFINE DICTIONARY_KEY_TO_ENUM_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER)
//%DICTIONARY_KEY_TO_ENUM_IMPL2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, POD)
//%PDDM-DEFINE DICTIONARY_KEY_TO_ENUM_IMPL2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER)
//%#pragma mark - KEY_NAME -> VALUE_NAME
//%
//%@implementation GPB##KEY_NAME##VALUE_NAME##Dictionary {
//% @package
//% NSMutableDictionary *_dictionary;
//% GPBEnumValidationFunc _validationFunc;
//%}
//%
//%@synthesize validationFunc = _validationFunc;
//%
//%- (instancetype)init {
//% return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
//%}
//%
//%- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
//% return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
//%}
//%
//%- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
//% rawValues:(const VALUE_TYPE [])rawValues
//% forKeys:(const KEY_TYPE##KisP$S##KisP [])keys
//% count:(NSUInteger)count {
//% self = [super init];
//% if (self) {
//% _dictionary = [[NSMutableDictionary alloc] init];
//% _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
//% if (count && rawValues && keys) {
//% for (NSUInteger i = 0; i < count; ++i) {
//%DICTIONARY_VALIDATE_KEY_##KHELPER(keys[i], ______) [_dictionary setObject:WRAPPED##VHELPER(rawValues[i]) forKey:WRAPPED##KHELPER(keys[i])];
//% }
//% }
//% }
//% return self;
//%}
//%
//%- (instancetype)initWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary {
//% self = [self initWithValidationFunction:dictionary.validationFunc
//% rawValues:NULL
//% forKeys:NULL
//% count:0];
//% if (self) {
//% if (dictionary) {
//% [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
//% }
//% }
//% return self;
//%}
//%
//%- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
//% capacity:(NSUInteger)numItems {
//% #pragma unused(numItems)
//% return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
//%}
//%
//%DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, Value, value, Raw)
//%
//%- (BOOL)getEnum:(VALUE_TYPE *)value forKey:(KEY_TYPE##KisP$S##KisP)key {
//% NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)];
//% if (wrapped && value) {
//% VALUE_TYPE result = UNWRAP##VALUE_NAME(wrapped);
//% if (!_validationFunc(result)) {
//% result = kGPBUnrecognizedEnumeratorValue;
//% }
//% *value = result;
//% }
//% return (wrapped != NULL);
//%}
//%
//%- (BOOL)getRawValue:(VALUE_TYPE *)rawValue forKey:(KEY_TYPE##KisP$S##KisP)key {
//% NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)];
//% if (wrapped && rawValue) {
//% *rawValue = UNWRAP##VALUE_NAME(wrapped);
//% }
//% return (wrapped != NULL);
//%}
//%
//%- (void)enumerateKeysAndEnumsUsingBlock:
//% (void (NS_NOESCAPE ^)(KEY_TYPE KisP##key, VALUE_TYPE value, BOOL *stop))block {
//% GPBEnumValidationFunc func = _validationFunc;
//% BOOL stop = NO;
//% NSEnumerator *keys = [_dictionary keyEnumerator];
//% ENUM_TYPE##KHELPER(KEY_TYPE)##aKey;
//% while ((aKey = [keys nextObject])) {
//% ENUM_TYPE##VHELPER(VALUE_TYPE)##aValue = _dictionary[aKey];
//% VALUE_TYPE unwrapped = UNWRAP##VALUE_NAME(aValue);
//% if (!func(unwrapped)) {
//% unwrapped = kGPBUnrecognizedEnumeratorValue;
//% }
//% block(UNWRAP##KEY_NAME(aKey), unwrapped, &stop);
//% if (stop) {
//% break;
//% }
//% }
//%}
//%
//%DICTIONARY_MUTABLE_CORE2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, Value, Enum, value, Raw)
//%
//%- (void)setEnum:(VALUE_TYPE)value forKey:(KEY_TYPE##KisP$S##KisP)key {
//%DICTIONARY_VALIDATE_KEY_##KHELPER(key, ) if (!_validationFunc(value)) {
//% [NSException raise:NSInvalidArgumentException
//% format:@"GPB##KEY_NAME##VALUE_NAME##Dictionary: Attempt to set an unknown enum value (%d)",
//% value];
//% }
//%
//% [_dictionary setObject:WRAPPED##VHELPER(value) forKey:WRAPPED##KHELPER(key)];
//% if (_autocreator) {
//% GPBAutocreatedDictionaryModified(_autocreator, self);
//% }
//%}
//%
//%@end
//%
//%PDDM-DEFINE DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, ACCESSOR_NAME)
//%- (void)dealloc {
//% NSAssert(!_autocreator,
//% @"%@: Autocreator must be cleared before release, autocreator: %@",
//% [self class], _autocreator);
//% [_dictionary release];
//% [super dealloc];
//%}
//%
//%- (instancetype)copyWithZone:(NSZone *)zone {
//% return [[GPB##KEY_NAME##VALUE_NAME##Dictionary allocWithZone:zone] initWithDictionary:self];
//%}
//%
//%- (BOOL)isEqual:(id)other {
//% if (self == other) {
//% return YES;
//% }
//% if (![other isKindOfClass:[GPB##KEY_NAME##VALUE_NAME##Dictionary class]]) {
//% return NO;
//% }
//% GPB##KEY_NAME##VALUE_NAME##Dictionary *otherDictionary = other;
//% return [_dictionary isEqual:otherDictionary->_dictionary];
//%}
//%
//%- (NSUInteger)hash {
//% return _dictionary.count;
//%}
//%
//%- (NSString *)description {
//% return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
//%}
//%
//%- (NSUInteger)count {
//% return _dictionary.count;
//%}
//%
//%- (void)enumerateKeysAnd##ACCESSOR_NAME##VNAME##sUsingBlock:
//% (void (NS_NOESCAPE ^)(KEY_TYPE KisP##key, VALUE_TYPE VNAME_VAR, BOOL *stop))block {
//% BOOL stop = NO;
//% NSDictionary *internal = _dictionary;
//% NSEnumerator *keys = [internal keyEnumerator];
//% ENUM_TYPE##KHELPER(KEY_TYPE)##aKey;
//% while ((aKey = [keys nextObject])) {
//% ENUM_TYPE##VHELPER(VALUE_TYPE)##a##VNAME_VAR$u = internal[aKey];
//% block(UNWRAP##KEY_NAME(aKey), UNWRAP##VALUE_NAME(a##VNAME_VAR$u), &stop);
//% if (stop) {
//% break;
//% }
//% }
//%}
//%
//%EXTRA_METHODS_##VHELPER(KEY_NAME, VALUE_NAME)- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
//% NSDictionary *internal = _dictionary;
//% NSUInteger count = internal.count;
//% if (count == 0) {
//% return 0;
//% }
//%
//% GPBDataType valueDataType = GPBGetFieldDataType(field);
//% GPBDataType keyDataType = field.mapKeyDataType;
//% size_t result = 0;
//% NSEnumerator *keys = [internal keyEnumerator];
//% ENUM_TYPE##KHELPER(KEY_TYPE)##aKey;
//% while ((aKey = [keys nextObject])) {
//% ENUM_TYPE##VHELPER(VALUE_TYPE)##a##VNAME_VAR$u = internal[aKey];
//% size_t msgSize = ComputeDict##KEY_NAME##FieldSize(UNWRAP##KEY_NAME(aKey), kMapKeyFieldNumber, keyDataType);
//% msgSize += ComputeDict##VALUE_NAME##FieldSize(UNWRAP##VALUE_NAME(a##VNAME_VAR$u), kMapValueFieldNumber, valueDataType);
//% result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
//% }
//% size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
//% result += tagSize * count;
//% return result;
//%}
//%
//%- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
//% asField:(GPBFieldDescriptor *)field {
//% GPBDataType valueDataType = GPBGetFieldDataType(field);
//% GPBDataType keyDataType = field.mapKeyDataType;
//% uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
//% NSDictionary *internal = _dictionary;
//% NSEnumerator *keys = [internal keyEnumerator];
//% ENUM_TYPE##KHELPER(KEY_TYPE)##aKey;
//% while ((aKey = [keys nextObject])) {
//% ENUM_TYPE##VHELPER(VALUE_TYPE)##a##VNAME_VAR$u = internal[aKey];
//% [outputStream writeInt32NoTag:tag];
//% // Write the size of the message.
//% KEY_TYPE KisP##unwrappedKey = UNWRAP##KEY_NAME(aKey);
//% VALUE_TYPE unwrappedValue = UNWRAP##VALUE_NAME(a##VNAME_VAR$u);
//% size_t msgSize = ComputeDict##KEY_NAME##FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
//% msgSize += ComputeDict##VALUE_NAME##FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
//% [outputStream writeInt32NoTag:(int32_t)msgSize];
//% // Write the fields.
//% WriteDict##KEY_NAME##Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
//% WriteDict##VALUE_NAME##Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
//% }
//%}
//%
//%SERIAL_DATA_FOR_ENTRY_##VHELPER(KEY_NAME, VALUE_NAME)- (void)setGPBGenericValue:(GPBGenericValue *)value
//% forGPBGenericValueKey:(GPBGenericValue *)key {
//% [_dictionary setObject:WRAPPED##VHELPER(value->##GPBVALUE_##VHELPER(VALUE_NAME)##) forKey:WRAPPED##KHELPER(key->value##KEY_NAME)];
//%}
//%
//%- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
//% [self enumerateKeysAnd##ACCESSOR_NAME##VNAME##sUsingBlock:^(KEY_TYPE KisP##key, VALUE_TYPE VNAME_VAR, BOOL *stop) {
//% #pragma unused(stop)
//% block(TEXT_FORMAT_OBJ##KEY_NAME(key), TEXT_FORMAT_OBJ##VALUE_NAME(VNAME_VAR));
//% }];
//%}
//%PDDM-DEFINE DICTIONARY_MUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, ACCESSOR_NAME)
//%DICTIONARY_MUTABLE_CORE2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME, VNAME_VAR, ACCESSOR_NAME)
//%PDDM-DEFINE DICTIONARY_MUTABLE_CORE2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_REMOVE, VNAME_VAR, ACCESSOR_NAME)
//%- (void)add##ACCESSOR_NAME##EntriesFromDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)otherDictionary {
//% if (otherDictionary) {
//% [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
//% if (_autocreator) {
//% GPBAutocreatedDictionaryModified(_autocreator, self);
//% }
//% }
//%}
//%
//%- (void)set##ACCESSOR_NAME##VNAME##:(VALUE_TYPE)VNAME_VAR forKey:(KEY_TYPE##KisP$S##KisP)key {
//%DICTIONARY_VALIDATE_VALUE_##VHELPER(VNAME_VAR, )##DICTIONARY_VALIDATE_KEY_##KHELPER(key, ) [_dictionary setObject:WRAPPED##VHELPER(VNAME_VAR) forKey:WRAPPED##KHELPER(key)];
//% if (_autocreator) {
//% GPBAutocreatedDictionaryModified(_autocreator, self);
//% }
//%}
//%
//%- (void)remove##VNAME_REMOVE##ForKey:(KEY_TYPE##KisP$S##KisP)aKey {
//% [_dictionary removeObjectForKey:WRAPPED##KHELPER(aKey)];
//%}
//%
//%- (void)removeAll {
//% [_dictionary removeAllObjects];
//%}
//
// Custom Generation for Bool keys
//
//%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_POD_IMPL(VALUE_NAME, VALUE_TYPE)
//%DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, POD, VALUE_NAME, value)
//%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_OBJECT_IMPL(VALUE_NAME, VALUE_TYPE)
//%DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, OBJECT, Object, object)
//%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, HELPER, VNAME, VNAME_VAR)
//%#pragma mark - Bool -> VALUE_NAME
//%
//%@implementation GPBBool##VALUE_NAME##Dictionary {
//% @package
//% VALUE_TYPE _values[2];
//%BOOL_DICT_HAS_STORAGE_##HELPER()}
//%
//%- (instancetype)init {
//% return [self initWith##VNAME##s:NULL forKeys:NULL count:0];
//%}
//%
//%BOOL_DICT_INITS_##HELPER(VALUE_NAME, VALUE_TYPE)
//%
//%- (instancetype)initWithCapacity:(NSUInteger)numItems {
//% #pragma unused(numItems)
//% return [self initWith##VNAME##s:NULL forKeys:NULL count:0];
//%}
//%
//%BOOL_DICT_DEALLOC##HELPER()
//%
//%- (instancetype)copyWithZone:(NSZone *)zone {
//% return [[GPBBool##VALUE_NAME##Dictionary allocWithZone:zone] initWithDictionary:self];
//%}
//%
//%- (BOOL)isEqual:(id)other {
//% if (self == other) {
//% return YES;
//% }
//% if (![other isKindOfClass:[GPBBool##VALUE_NAME##Dictionary class]]) {
//% return NO;
//% }
//% GPBBool##VALUE_NAME##Dictionary *otherDictionary = other;
//% if ((BOOL_DICT_W_HAS##HELPER(0, ) != BOOL_DICT_W_HAS##HELPER(0, otherDictionary->)) ||
//% (BOOL_DICT_W_HAS##HELPER(1, ) != BOOL_DICT_W_HAS##HELPER(1, otherDictionary->))) {
//% return NO;
//% }
//% if ((BOOL_DICT_W_HAS##HELPER(0, ) && (NEQ_##HELPER(_values[0], otherDictionary->_values[0]))) ||
//% (BOOL_DICT_W_HAS##HELPER(1, ) && (NEQ_##HELPER(_values[1], otherDictionary->_values[1])))) {
//% return NO;
//% }
//% return YES;
//%}
//%
//%- (NSUInteger)hash {
//% return (BOOL_DICT_W_HAS##HELPER(0, ) ? 1 : 0) + (BOOL_DICT_W_HAS##HELPER(1, ) ? 1 : 0);
//%}
//%
//%- (NSString *)description {
//% NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
//% if (BOOL_DICT_W_HAS##HELPER(0, )) {
//% [result appendFormat:@"NO: STR_FORMAT_##HELPER(VALUE_NAME)", _values[0]];
//% }
//% if (BOOL_DICT_W_HAS##HELPER(1, )) {
//% [result appendFormat:@"YES: STR_FORMAT_##HELPER(VALUE_NAME)", _values[1]];
//% }
//% [result appendString:@" }"];
//% return result;
//%}
//%
//%- (NSUInteger)count {
//% return (BOOL_DICT_W_HAS##HELPER(0, ) ? 1 : 0) + (BOOL_DICT_W_HAS##HELPER(1, ) ? 1 : 0);
//%}
//%
//%BOOL_VALUE_FOR_KEY_##HELPER(VALUE_NAME, VALUE_TYPE)
//%
//%BOOL_SET_GPBVALUE_FOR_KEY_##HELPER(VALUE_NAME, VALUE_TYPE, VisP)
//%
//%- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
//% if (BOOL_DICT_HAS##HELPER(0, )) {
//% block(@"false", TEXT_FORMAT_OBJ##VALUE_NAME(_values[0]));
//% }
//% if (BOOL_DICT_W_HAS##HELPER(1, )) {
//% block(@"true", TEXT_FORMAT_OBJ##VALUE_NAME(_values[1]));
//% }
//%}
//%
//%- (void)enumerateKeysAnd##VNAME##sUsingBlock:
//% (void (NS_NOESCAPE ^)(BOOL key, VALUE_TYPE VNAME_VAR, BOOL *stop))block {
//% BOOL stop = NO;
//% if (BOOL_DICT_HAS##HELPER(0, )) {
//% block(NO, _values[0], &stop);
//% }
//% if (!stop && BOOL_DICT_W_HAS##HELPER(1, )) {
//% block(YES, _values[1], &stop);
//% }
//%}
//%
//%BOOL_EXTRA_METHODS_##HELPER(Bool, VALUE_NAME)- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
//% GPBDataType valueDataType = GPBGetFieldDataType(field);
//% NSUInteger count = 0;
//% size_t result = 0;
//% for (int i = 0; i < 2; ++i) {
//% if (BOOL_DICT_HAS##HELPER(i, )) {
//% ++count;
//% size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
//% msgSize += ComputeDict##VALUE_NAME##FieldSize(_values[i], kMapValueFieldNumber, valueDataType);