Auto-generate files after cl/721951543
[google-protobuf.git] / objectivec / GPBDictionary.m
blobc7199fe80136d17f1b10d21050392dfca3a2902a
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc.  All rights reserved.
3 //
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file or at
6 // https://developers.google.com/open-source/licenses/bsd
8 #import "GPBDictionary.h"
9 #import "GPBDictionary_PackagePrivate.h"
11 #import "GPBCodedInputStream.h"
12 #import "GPBCodedInputStream_PackagePrivate.h"
13 #import "GPBCodedOutputStream.h"
14 #import "GPBCodedOutputStream_PackagePrivate.h"
15 #import "GPBDescriptor.h"
16 #import "GPBDescriptor_PackagePrivate.h"
17 #import "GPBMessage.h"
18 #import "GPBMessage_PackagePrivate.h"
19 #import "GPBUtilities.h"
20 #import "GPBUtilities_PackagePrivate.h"
22 // ------------------------------ NOTE ------------------------------
23 // At the moment, this is all using NSNumbers in NSDictionaries under
24 // the hood, but it is all hidden so we can come back and optimize
25 // with direct CFDictionary usage later.  The reason that wasn't
26 // done yet is needing to support 32bit iOS builds.  Otherwise
27 // it would be pretty simple to store all this data in CFDictionaries
28 // directly.
29 // ------------------------------------------------------------------
31 // Direct access is use for speed, to avoid even internally declaring things
32 // read/write, etc. The warning is enabled in the project to ensure code calling
33 // protos can turn on -Wdirect-ivar-access without issues.
34 #pragma clang diagnostic push
35 #pragma clang diagnostic ignored "-Wdirect-ivar-access"
37 enum {
38   kMapKeyFieldNumber = 1,
39   kMapValueFieldNumber = 2,
42 static BOOL DictDefault_IsValidValue(int32_t value) {
43   // Anything but the bad value marker is allowed.
44   return (value != kGPBUnrecognizedEnumeratorValue);
47 // Disable clang-format for the macros.
48 // clang-format off
50 //%PDDM-DEFINE SERIALIZE_SUPPORT_2_TYPE(VALUE_NAME, VALUE_TYPE, GPBDATATYPE_NAME1, GPBDATATYPE_NAME2)
51 //%static size_t ComputeDict##VALUE_NAME##FieldSize(VALUE_TYPE value, uint32_t fieldNum, GPBDataType dataType) {
52 //%  if (dataType == GPBDataType##GPBDATATYPE_NAME1) {
53 //%    return GPBCompute##GPBDATATYPE_NAME1##Size(fieldNum, value);
54 //%  } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) {
55 //%    return GPBCompute##GPBDATATYPE_NAME2##Size(fieldNum, value);
56 //%  } else {
57 //%    NSCAssert(NO, @"Unexpected type %d", dataType);
58 //%    return 0;
59 //%  }
60 //%}
61 //%
62 //%static void WriteDict##VALUE_NAME##Field(GPBCodedOutputStream *stream, VALUE_TYPE value, uint32_t fieldNum, GPBDataType dataType) {
63 //%  if (dataType == GPBDataType##GPBDATATYPE_NAME1) {
64 //%    [stream write##GPBDATATYPE_NAME1##:fieldNum value:value];
65 //%  } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) {
66 //%    [stream write##GPBDATATYPE_NAME2##:fieldNum value:value];
67 //%  } else {
68 //%    NSCAssert(NO, @"Unexpected type %d", dataType);
69 //%  }
70 //%}
71 //%
72 //%PDDM-DEFINE SERIALIZE_SUPPORT_3_TYPE(VALUE_NAME, VALUE_TYPE, GPBDATATYPE_NAME1, GPBDATATYPE_NAME2, GPBDATATYPE_NAME3)
73 //%static size_t ComputeDict##VALUE_NAME##FieldSize(VALUE_TYPE value, uint32_t fieldNum, GPBDataType dataType) {
74 //%  if (dataType == GPBDataType##GPBDATATYPE_NAME1) {
75 //%    return GPBCompute##GPBDATATYPE_NAME1##Size(fieldNum, value);
76 //%  } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) {
77 //%    return GPBCompute##GPBDATATYPE_NAME2##Size(fieldNum, value);
78 //%  } else if (dataType == GPBDataType##GPBDATATYPE_NAME3) {
79 //%    return GPBCompute##GPBDATATYPE_NAME3##Size(fieldNum, value);
80 //%  } else {
81 //%    NSCAssert(NO, @"Unexpected type %d", dataType);
82 //%    return 0;
83 //%  }
84 //%}
85 //%
86 //%static void WriteDict##VALUE_NAME##Field(GPBCodedOutputStream *stream, VALUE_TYPE value, uint32_t fieldNum, GPBDataType dataType) {
87 //%  if (dataType == GPBDataType##GPBDATATYPE_NAME1) {
88 //%    [stream write##GPBDATATYPE_NAME1##:fieldNum value:value];
89 //%  } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) {
90 //%    [stream write##GPBDATATYPE_NAME2##:fieldNum value:value];
91 //%  } else if (dataType == GPBDataType##GPBDATATYPE_NAME3) {
92 //%    [stream write##GPBDATATYPE_NAME3##:fieldNum value:value];
93 //%  } else {
94 //%    NSCAssert(NO, @"Unexpected type %d", dataType);
95 //%  }
96 //%}
97 //%
98 //%PDDM-DEFINE SIMPLE_SERIALIZE_SUPPORT(VALUE_NAME, VALUE_TYPE, VisP)
99 //%static size_t ComputeDict##VALUE_NAME##FieldSize(VALUE_TYPE VisP##value, uint32_t fieldNum, __unused GPBDataType dataType) {
100 //%  NSCAssert(dataType == GPBDataType##VALUE_NAME, @"bad type: %d", dataType);
101 //%  return GPBCompute##VALUE_NAME##Size(fieldNum, value);
102 //%}
104 //%static void WriteDict##VALUE_NAME##Field(GPBCodedOutputStream *stream, VALUE_TYPE VisP##value, uint32_t fieldNum, __unused GPBDataType dataType) {
105 //%  NSCAssert(dataType == GPBDataType##VALUE_NAME, @"bad type: %d", dataType);
106 //%  [stream write##VALUE_NAME##:fieldNum value:value];
107 //%}
109 //%PDDM-DEFINE SERIALIZE_SUPPORT_HELPERS()
110 //%SERIALIZE_SUPPORT_3_TYPE(Int32, int32_t, Int32, SInt32, SFixed32)
111 //%SERIALIZE_SUPPORT_2_TYPE(UInt32, uint32_t, UInt32, Fixed32)
112 //%SERIALIZE_SUPPORT_3_TYPE(Int64, int64_t, Int64, SInt64, SFixed64)
113 //%SERIALIZE_SUPPORT_2_TYPE(UInt64, uint64_t, UInt64, Fixed64)
114 //%SIMPLE_SERIALIZE_SUPPORT(Bool, BOOL, )
115 //%SIMPLE_SERIALIZE_SUPPORT(Enum, int32_t, )
116 //%SIMPLE_SERIALIZE_SUPPORT(Float, float, )
117 //%SIMPLE_SERIALIZE_SUPPORT(Double, double, )
118 //%SIMPLE_SERIALIZE_SUPPORT(String, NSString, *)
119 //%SERIALIZE_SUPPORT_3_TYPE(Object, id, Message, String, Bytes)
120 //%PDDM-EXPAND SERIALIZE_SUPPORT_HELPERS()
121 // This block of code is generated, do not edit it directly.
123 static size_t ComputeDictInt32FieldSize(int32_t value, uint32_t fieldNum, GPBDataType dataType) {
124   if (dataType == GPBDataTypeInt32) {
125     return GPBComputeInt32Size(fieldNum, value);
126   } else if (dataType == GPBDataTypeSInt32) {
127     return GPBComputeSInt32Size(fieldNum, value);
128   } else if (dataType == GPBDataTypeSFixed32) {
129     return GPBComputeSFixed32Size(fieldNum, value);
130   } else {
131     NSCAssert(NO, @"Unexpected type %d", dataType);
132     return 0;
133   }
136 static void WriteDictInt32Field(GPBCodedOutputStream *stream, int32_t value, uint32_t fieldNum, GPBDataType dataType) {
137   if (dataType == GPBDataTypeInt32) {
138     [stream writeInt32:fieldNum value:value];
139   } else if (dataType == GPBDataTypeSInt32) {
140     [stream writeSInt32:fieldNum value:value];
141   } else if (dataType == GPBDataTypeSFixed32) {
142     [stream writeSFixed32:fieldNum value:value];
143   } else {
144     NSCAssert(NO, @"Unexpected type %d", dataType);
145   }
148 static size_t ComputeDictUInt32FieldSize(uint32_t value, uint32_t fieldNum, GPBDataType dataType) {
149   if (dataType == GPBDataTypeUInt32) {
150     return GPBComputeUInt32Size(fieldNum, value);
151   } else if (dataType == GPBDataTypeFixed32) {
152     return GPBComputeFixed32Size(fieldNum, value);
153   } else {
154     NSCAssert(NO, @"Unexpected type %d", dataType);
155     return 0;
156   }
159 static void WriteDictUInt32Field(GPBCodedOutputStream *stream, uint32_t value, uint32_t fieldNum, GPBDataType dataType) {
160   if (dataType == GPBDataTypeUInt32) {
161     [stream writeUInt32:fieldNum value:value];
162   } else if (dataType == GPBDataTypeFixed32) {
163     [stream writeFixed32:fieldNum value:value];
164   } else {
165     NSCAssert(NO, @"Unexpected type %d", dataType);
166   }
169 static size_t ComputeDictInt64FieldSize(int64_t value, uint32_t fieldNum, GPBDataType dataType) {
170   if (dataType == GPBDataTypeInt64) {
171     return GPBComputeInt64Size(fieldNum, value);
172   } else if (dataType == GPBDataTypeSInt64) {
173     return GPBComputeSInt64Size(fieldNum, value);
174   } else if (dataType == GPBDataTypeSFixed64) {
175     return GPBComputeSFixed64Size(fieldNum, value);
176   } else {
177     NSCAssert(NO, @"Unexpected type %d", dataType);
178     return 0;
179   }
182 static void WriteDictInt64Field(GPBCodedOutputStream *stream, int64_t value, uint32_t fieldNum, GPBDataType dataType) {
183   if (dataType == GPBDataTypeInt64) {
184     [stream writeInt64:fieldNum value:value];
185   } else if (dataType == GPBDataTypeSInt64) {
186     [stream writeSInt64:fieldNum value:value];
187   } else if (dataType == GPBDataTypeSFixed64) {
188     [stream writeSFixed64:fieldNum value:value];
189   } else {
190     NSCAssert(NO, @"Unexpected type %d", dataType);
191   }
194 static size_t ComputeDictUInt64FieldSize(uint64_t value, uint32_t fieldNum, GPBDataType dataType) {
195   if (dataType == GPBDataTypeUInt64) {
196     return GPBComputeUInt64Size(fieldNum, value);
197   } else if (dataType == GPBDataTypeFixed64) {
198     return GPBComputeFixed64Size(fieldNum, value);
199   } else {
200     NSCAssert(NO, @"Unexpected type %d", dataType);
201     return 0;
202   }
205 static void WriteDictUInt64Field(GPBCodedOutputStream *stream, uint64_t value, uint32_t fieldNum, GPBDataType dataType) {
206   if (dataType == GPBDataTypeUInt64) {
207     [stream writeUInt64:fieldNum value:value];
208   } else if (dataType == GPBDataTypeFixed64) {
209     [stream writeFixed64:fieldNum value:value];
210   } else {
211     NSCAssert(NO, @"Unexpected type %d", dataType);
212   }
215 static size_t ComputeDictBoolFieldSize(BOOL value, uint32_t fieldNum, __unused GPBDataType dataType) {
216   NSCAssert(dataType == GPBDataTypeBool, @"bad type: %d", dataType);
217   return GPBComputeBoolSize(fieldNum, value);
220 static void WriteDictBoolField(GPBCodedOutputStream *stream, BOOL value, uint32_t fieldNum, __unused GPBDataType dataType) {
221   NSCAssert(dataType == GPBDataTypeBool, @"bad type: %d", dataType);
222   [stream writeBool:fieldNum value:value];
225 static size_t ComputeDictEnumFieldSize(int32_t value, uint32_t fieldNum, __unused GPBDataType dataType) {
226   NSCAssert(dataType == GPBDataTypeEnum, @"bad type: %d", dataType);
227   return GPBComputeEnumSize(fieldNum, value);
230 static void WriteDictEnumField(GPBCodedOutputStream *stream, int32_t value, uint32_t fieldNum, __unused GPBDataType dataType) {
231   NSCAssert(dataType == GPBDataTypeEnum, @"bad type: %d", dataType);
232   [stream writeEnum:fieldNum value:value];
235 static size_t ComputeDictFloatFieldSize(float value, uint32_t fieldNum, __unused GPBDataType dataType) {
236   NSCAssert(dataType == GPBDataTypeFloat, @"bad type: %d", dataType);
237   return GPBComputeFloatSize(fieldNum, value);
240 static void WriteDictFloatField(GPBCodedOutputStream *stream, float value, uint32_t fieldNum, __unused GPBDataType dataType) {
241   NSCAssert(dataType == GPBDataTypeFloat, @"bad type: %d", dataType);
242   [stream writeFloat:fieldNum value:value];
245 static size_t ComputeDictDoubleFieldSize(double value, uint32_t fieldNum, __unused GPBDataType dataType) {
246   NSCAssert(dataType == GPBDataTypeDouble, @"bad type: %d", dataType);
247   return GPBComputeDoubleSize(fieldNum, value);
250 static void WriteDictDoubleField(GPBCodedOutputStream *stream, double value, uint32_t fieldNum, __unused GPBDataType dataType) {
251   NSCAssert(dataType == GPBDataTypeDouble, @"bad type: %d", dataType);
252   [stream writeDouble:fieldNum value:value];
255 static size_t ComputeDictStringFieldSize(NSString *value, uint32_t fieldNum, __unused GPBDataType dataType) {
256   NSCAssert(dataType == GPBDataTypeString, @"bad type: %d", dataType);
257   return GPBComputeStringSize(fieldNum, value);
260 static void WriteDictStringField(GPBCodedOutputStream *stream, NSString *value, uint32_t fieldNum, __unused GPBDataType dataType) {
261   NSCAssert(dataType == GPBDataTypeString, @"bad type: %d", dataType);
262   [stream writeString:fieldNum value:value];
265 static size_t ComputeDictObjectFieldSize(id value, uint32_t fieldNum, GPBDataType dataType) {
266   if (dataType == GPBDataTypeMessage) {
267     return GPBComputeMessageSize(fieldNum, value);
268   } else if (dataType == GPBDataTypeString) {
269     return GPBComputeStringSize(fieldNum, value);
270   } else if (dataType == GPBDataTypeBytes) {
271     return GPBComputeBytesSize(fieldNum, value);
272   } else {
273     NSCAssert(NO, @"Unexpected type %d", dataType);
274     return 0;
275   }
278 static void WriteDictObjectField(GPBCodedOutputStream *stream, id value, uint32_t fieldNum, GPBDataType dataType) {
279   if (dataType == GPBDataTypeMessage) {
280     [stream writeMessage:fieldNum value:value];
281   } else if (dataType == GPBDataTypeString) {
282     [stream writeString:fieldNum value:value];
283   } else if (dataType == GPBDataTypeBytes) {
284     [stream writeBytes:fieldNum value:value];
285   } else {
286     NSCAssert(NO, @"Unexpected type %d", dataType);
287   }
290 //%PDDM-EXPAND-END SERIALIZE_SUPPORT_HELPERS()
292 // clang-format on
294 size_t GPBDictionaryComputeSizeInternalHelper(NSDictionary *dict, GPBFieldDescriptor *field) {
295   GPBDataType mapValueType = GPBGetFieldDataType(field);
296   size_t result = 0;
297   NSString *key;
298   NSEnumerator *keys = [dict keyEnumerator];
299   while ((key = [keys nextObject])) {
300     id obj = dict[key];
301     size_t msgSize = GPBComputeStringSize(kMapKeyFieldNumber, key);
302     msgSize += ComputeDictObjectFieldSize(obj, kMapValueFieldNumber, mapValueType);
303     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
304   }
305   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
306   result += tagSize * dict.count;
307   return result;
310 void GPBDictionaryWriteToStreamInternalHelper(GPBCodedOutputStream *outputStream,
311                                               NSDictionary *dict, GPBFieldDescriptor *field) {
312   NSCAssert(field.mapKeyDataType == GPBDataTypeString, @"Unexpected key type");
313   GPBDataType mapValueType = GPBGetFieldDataType(field);
314   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
315   NSString *key;
316   NSEnumerator *keys = [dict keyEnumerator];
317   while ((key = [keys nextObject])) {
318     id obj = dict[key];
319     // Write the tag.
320     [outputStream writeInt32NoTag:tag];
321     // Write the size of the message.
322     size_t msgSize = GPBComputeStringSize(kMapKeyFieldNumber, key);
323     msgSize += ComputeDictObjectFieldSize(obj, kMapValueFieldNumber, mapValueType);
325     // Write the size and fields.
326     [outputStream writeInt32NoTag:(int32_t)msgSize];
327     [outputStream writeString:kMapKeyFieldNumber value:key];
328     WriteDictObjectField(outputStream, obj, kMapValueFieldNumber, mapValueType);
329   }
332 BOOL GPBDictionaryIsInitializedInternalHelper(NSDictionary *dict,
333                                               __unused GPBFieldDescriptor *field) {
334   NSCAssert(field.mapKeyDataType == GPBDataTypeString, @"Unexpected key type");
335   NSCAssert(GPBGetFieldDataType(field) == GPBDataTypeMessage, @"Unexpected value type");
336   GPBMessage *msg;
337   NSEnumerator *objects = [dict objectEnumerator];
338   while ((msg = [objects nextObject])) {
339     if (!msg.initialized) {
340       return NO;
341     }
342   }
343   return YES;
346 // Note: if the type is an object, it the retain pass back to the caller.
347 static void ReadValue(GPBCodedInputStream *stream, GPBGenericValue *valueToFill, GPBDataType type,
348                       id<GPBExtensionRegistry> registry, GPBFieldDescriptor *field) {
349   switch (type) {
350     case GPBDataTypeBool:
351       valueToFill->valueBool = GPBCodedInputStreamReadBool(&stream->state_);
352       break;
353     case GPBDataTypeFixed32:
354       valueToFill->valueUInt32 = GPBCodedInputStreamReadFixed32(&stream->state_);
355       break;
356     case GPBDataTypeSFixed32:
357       valueToFill->valueInt32 = GPBCodedInputStreamReadSFixed32(&stream->state_);
358       break;
359     case GPBDataTypeFloat:
360       valueToFill->valueFloat = GPBCodedInputStreamReadFloat(&stream->state_);
361       break;
362     case GPBDataTypeFixed64:
363       valueToFill->valueUInt64 = GPBCodedInputStreamReadFixed64(&stream->state_);
364       break;
365     case GPBDataTypeSFixed64:
366       valueToFill->valueInt64 = GPBCodedInputStreamReadSFixed64(&stream->state_);
367       break;
368     case GPBDataTypeDouble:
369       valueToFill->valueDouble = GPBCodedInputStreamReadDouble(&stream->state_);
370       break;
371     case GPBDataTypeInt32:
372       valueToFill->valueInt32 = GPBCodedInputStreamReadInt32(&stream->state_);
373       break;
374     case GPBDataTypeInt64:
375       valueToFill->valueInt64 = GPBCodedInputStreamReadInt64(&stream->state_);
376       break;
377     case GPBDataTypeSInt32:
378       valueToFill->valueInt32 = GPBCodedInputStreamReadSInt32(&stream->state_);
379       break;
380     case GPBDataTypeSInt64:
381       valueToFill->valueInt64 = GPBCodedInputStreamReadSInt64(&stream->state_);
382       break;
383     case GPBDataTypeUInt32:
384       valueToFill->valueUInt32 = GPBCodedInputStreamReadUInt32(&stream->state_);
385       break;
386     case GPBDataTypeUInt64:
387       valueToFill->valueUInt64 = GPBCodedInputStreamReadUInt64(&stream->state_);
388       break;
389     case GPBDataTypeBytes:
390       [valueToFill->valueData release];
391       valueToFill->valueData = GPBCodedInputStreamReadRetainedBytes(&stream->state_);
392       break;
393     case GPBDataTypeString:
394       [valueToFill->valueString release];
395       valueToFill->valueString = GPBCodedInputStreamReadRetainedString(&stream->state_);
396       break;
397     case GPBDataTypeMessage: {
398       GPBMessage *message = [[field.msgClass alloc] init];
399       [stream readMessage:message extensionRegistry:registry];
400       [valueToFill->valueMessage release];
401       valueToFill->valueMessage = message;
402       break;
403     }
404     case GPBDataTypeGroup:
405       NSCAssert(NO, @"Can't happen");
406       break;
407     case GPBDataTypeEnum:
408       valueToFill->valueEnum = GPBCodedInputStreamReadEnum(&stream->state_);
409       break;
410   }
413 void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream,
414                             id<GPBExtensionRegistry> registry, GPBFieldDescriptor *field,
415                             GPBMessage *parentMessage) {
416   GPBDataType keyDataType = field.mapKeyDataType;
417   GPBDataType valueDataType = GPBGetFieldDataType(field);
419   GPBGenericValue key;
420   GPBGenericValue value;
421   // Zero them (but pick up any enum default for proto2).
422   key.valueString = value.valueString = nil;
423   if (valueDataType == GPBDataTypeEnum) {
424     value = field.defaultValue;
425   }
427   GPBCodedInputStreamState *state = &stream->state_;
428   uint32_t keyTag = GPBWireFormatMakeTag(kMapKeyFieldNumber, GPBWireFormatForType(keyDataType, NO));
429   uint32_t valueTag =
430       GPBWireFormatMakeTag(kMapValueFieldNumber, GPBWireFormatForType(valueDataType, NO));
432   BOOL hitError = NO;
433   while (YES) {
434     uint32_t tag = GPBCodedInputStreamReadTag(state);
435     if (tag == keyTag) {
436       ReadValue(stream, &key, keyDataType, registry, field);
437     } else if (tag == valueTag) {
438       ReadValue(stream, &value, valueDataType, registry, field);
439     } else if (tag == 0) {
440       // zero signals EOF / limit reached
441       break;
442     } else {  // Unknown
443       if (![stream skipField:tag]) {
444         hitError = YES;
445         break;
446       }
447     }
448   }
450   if (!hitError) {
451     // Handle the special defaults and/or missing key/value.
452     if ((keyDataType == GPBDataTypeString) && (key.valueString == nil)) {
453       key.valueString = [@"" retain];
454     }
455     if (GPBDataTypeIsObject(valueDataType) && value.valueString == nil) {
456 #pragma clang diagnostic push
457 #pragma clang diagnostic ignored "-Wswitch-enum"
458       switch (valueDataType) {
459         case GPBDataTypeString:
460           value.valueString = [@"" retain];
461           break;
462         case GPBDataTypeBytes:
463           value.valueData = [GPBEmptyNSData() retain];
464           break;
465 #if defined(__clang_analyzer__)
466         case GPBDataTypeGroup:
467           // Maps can't really have Groups as the value type, but this case is needed
468           // so the analyzer won't report the possibility of send nil in for the value
469           // in the NSMutableDictionary case below.
470 #endif
471         case GPBDataTypeMessage: {
472           value.valueMessage = [[field.msgClass alloc] init];
473           break;
474         }
475         default:
476           // Nothing
477           break;
478       }
479 #pragma clang diagnostic pop
480     }
482     if ((keyDataType == GPBDataTypeString) && GPBDataTypeIsObject(valueDataType)) {
483       // mapDictionary is an NSMutableDictionary
484       [(NSMutableDictionary *)mapDictionary setObject:value.valueString forKey:key.valueString];
485     } else {
486       if (valueDataType == GPBDataTypeEnum) {
487         if ([field.enumDescriptor isOpenOrValidValue:value.valueEnum]) {
488           [mapDictionary setGPBGenericValue:&value forGPBGenericValueKey:&key];
489         } else {
490           NSData *data = [mapDictionary serializedDataForUnknownValue:value.valueEnum
491                                                                forKey:&key
492                                                           keyDataType:keyDataType];
493           [parentMessage addUnknownMapEntry:GPBFieldNumber(field) value:data];
494         }
495       } else {
496         [mapDictionary setGPBGenericValue:&value forGPBGenericValueKey:&key];
497       }
498     }
499   }
501   if (GPBDataTypeIsObject(keyDataType)) {
502     [key.valueString release];
503   }
504   if (GPBDataTypeIsObject(valueDataType)) {
505     [value.valueString release];
506   }
510 // Macros for the common basic cases.
513 // Disable clang-format for the macros.
514 // clang-format off
516 //%PDDM-DEFINE DICTIONARY_IMPL_FOR_POD_KEY(KEY_NAME, KEY_TYPE)
517 //%DICTIONARY_POD_IMPL_FOR_KEY(KEY_NAME, KEY_TYPE, , POD)
518 //%DICTIONARY_POD_KEY_TO_OBJECT_IMPL(KEY_NAME, KEY_TYPE, Object, id)
520 //%PDDM-DEFINE DICTIONARY_POD_IMPL_FOR_KEY(KEY_NAME, KEY_TYPE, KisP, KHELPER)
521 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, UInt32, uint32_t, KHELPER)
522 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Int32, int32_t, KHELPER)
523 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, UInt64, uint64_t, KHELPER)
524 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Int64, int64_t, KHELPER)
525 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Bool, BOOL, KHELPER)
526 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Float, float, KHELPER)
527 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Double, double, KHELPER)
528 //%DICTIONARY_KEY_TO_ENUM_IMPL(KEY_NAME, KEY_TYPE, KisP, Enum, int32_t, KHELPER)
530 //%PDDM-DEFINE DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER)
531 //%DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, POD, VALUE_NAME, value)
533 //%PDDM-DEFINE DICTIONARY_POD_KEY_TO_OBJECT_IMPL(KEY_NAME, KEY_TYPE, VALUE_NAME, VALUE_TYPE)
534 //%DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, , VALUE_NAME, VALUE_TYPE, POD, OBJECT, Object, object)
536 //%PDDM-DEFINE DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR)
537 //%#pragma mark - KEY_NAME -> VALUE_NAME
539 //%@implementation GPB##KEY_NAME##VALUE_NAME##Dictionary {
540 //% @package
541 //%  NSMutableDictionary *_dictionary;
542 //%}
544 //%- (instancetype)init {
545 //%  return [self initWith##VNAME##s:NULL forKeys:NULL count:0];
546 //%}
548 //%- (instancetype)initWith##VNAME##s:(const VALUE_TYPE [])##VNAME_VAR##s
549 //%                ##VNAME$S##  forKeys:(const KEY_TYPE##KisP$S##KisP [])keys
550 //%                ##VNAME$S##    count:(NSUInteger)count {
551 //%  self = [super init];
552 //%  if (self) {
553 //%    _dictionary = [[NSMutableDictionary alloc] init];
554 //%    if (count && VNAME_VAR##s && keys) {
555 //%      for (NSUInteger i = 0; i < count; ++i) {
556 //%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])];
557 //%      }
558 //%    }
559 //%  }
560 //%  return self;
561 //%}
563 //%- (instancetype)initWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary {
564 //%  self = [self initWith##VNAME##s:NULL forKeys:NULL count:0];
565 //%  if (self) {
566 //%    if (dictionary) {
567 //%      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
568 //%    }
569 //%  }
570 //%  return self;
571 //%}
573 //%- (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
574 //%  return [self initWith##VNAME##s:NULL forKeys:NULL count:0];
575 //%}
577 //%DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, )
579 //%VALUE_FOR_KEY_##VHELPER(KEY_TYPE##KisP$S##KisP, VALUE_NAME, VALUE_TYPE, KHELPER)
581 //%DICTIONARY_MUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, )
583 //%@end
586 //%PDDM-DEFINE DICTIONARY_KEY_TO_ENUM_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER)
587 //%DICTIONARY_KEY_TO_ENUM_IMPL2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, POD)
588 //%PDDM-DEFINE DICTIONARY_KEY_TO_ENUM_IMPL2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER)
589 //%#pragma mark - KEY_NAME -> VALUE_NAME
591 //%@implementation GPB##KEY_NAME##VALUE_NAME##Dictionary {
592 //% @package
593 //%  NSMutableDictionary *_dictionary;
594 //%  GPBEnumValidationFunc _validationFunc;
595 //%}
597 //%@synthesize validationFunc = _validationFunc;
599 //%- (instancetype)init {
600 //%  return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
601 //%}
603 //%- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
604 //%  return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
605 //%}
607 //%- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
608 //%                                 rawValues:(const VALUE_TYPE [])rawValues
609 //%                                   forKeys:(const KEY_TYPE##KisP$S##KisP [])keys
610 //%                                     count:(NSUInteger)count {
611 //%  self = [super init];
612 //%  if (self) {
613 //%    _dictionary = [[NSMutableDictionary alloc] init];
614 //%    _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
615 //%    if (count && rawValues && keys) {
616 //%      for (NSUInteger i = 0; i < count; ++i) {
617 //%DICTIONARY_VALIDATE_KEY_##KHELPER(keys[i], ______)        [_dictionary setObject:WRAPPED##VHELPER(rawValues[i]) forKey:WRAPPED##KHELPER(keys[i])];
618 //%      }
619 //%    }
620 //%  }
621 //%  return self;
622 //%}
624 //%- (instancetype)initWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary {
625 //%  self = [self initWithValidationFunction:dictionary.validationFunc
626 //%                                rawValues:NULL
627 //%                                  forKeys:NULL
628 //%                                    count:0];
629 //%  if (self) {
630 //%    if (dictionary) {
631 //%      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
632 //%    }
633 //%  }
634 //%  return self;
635 //%}
637 //%- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
638 //%                                  capacity:(__unused NSUInteger)numItems {
639 //%  return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
640 //%}
642 //%DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, Value, value, Raw)
644 //%- (BOOL)getEnum:(VALUE_TYPE *)value forKey:(KEY_TYPE##KisP$S##KisP)key {
645 //%  NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)];
646 //%  if (wrapped && value) {
647 //%    VALUE_TYPE result = UNWRAP##VALUE_NAME(wrapped);
648 //%    if (!_validationFunc(result)) {
649 //%      result = kGPBUnrecognizedEnumeratorValue;
650 //%    }
651 //%    *value = result;
652 //%  }
653 //%  return (wrapped != NULL);
654 //%}
656 //%- (BOOL)getRawValue:(VALUE_TYPE *)rawValue forKey:(KEY_TYPE##KisP$S##KisP)key {
657 //%  NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)];
658 //%  if (wrapped && rawValue) {
659 //%    *rawValue = UNWRAP##VALUE_NAME(wrapped);
660 //%  }
661 //%  return (wrapped != NULL);
662 //%}
664 //%- (void)enumerateKeysAndEnumsUsingBlock:
665 //%    (void (NS_NOESCAPE ^)(KEY_TYPE KisP##key, VALUE_TYPE value, BOOL *stop))block {
666 //%  GPBEnumValidationFunc func = _validationFunc;
667 //%  BOOL stop = NO;
668 //%  NSEnumerator *keys = [_dictionary keyEnumerator];
669 //%  ENUM_TYPE##KHELPER(KEY_TYPE)##aKey;
670 //%  while ((aKey = [keys nextObject])) {
671 //%    ENUM_TYPE##VHELPER(VALUE_TYPE)##aValue = _dictionary[aKey];
672 //%      VALUE_TYPE unwrapped = UNWRAP##VALUE_NAME(aValue);
673 //%      if (!func(unwrapped)) {
674 //%        unwrapped = kGPBUnrecognizedEnumeratorValue;
675 //%      }
676 //%    block(UNWRAP##KEY_NAME(aKey), unwrapped, &stop);
677 //%    if (stop) {
678 //%      break;
679 //%    }
680 //%  }
681 //%}
683 //%DICTIONARY_MUTABLE_CORE2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, Value, Enum, value, Raw)
685 //%- (void)setEnum:(VALUE_TYPE)value forKey:(KEY_TYPE##KisP$S##KisP)key {
686 //%DICTIONARY_VALIDATE_KEY_##KHELPER(key, )  if (!_validationFunc(value)) {
687 //%    [NSException raise:NSInvalidArgumentException
688 //%                format:@"GPB##KEY_NAME##VALUE_NAME##Dictionary: Attempt to set an unknown enum value (%d)",
689 //%                       value];
690 //%  }
692 //%  [_dictionary setObject:WRAPPED##VHELPER(value) forKey:WRAPPED##KHELPER(key)];
693 //%  if (_autocreator) {
694 //%    GPBAutocreatedDictionaryModified(_autocreator, self);
695 //%  }
696 //%}
698 //%@end
701 //%PDDM-DEFINE DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, ACCESSOR_NAME)
702 //%- (void)dealloc {
703 //%  NSAssert(!_autocreator,
704 //%           @"%@: Autocreator must be cleared before release, autocreator: %@",
705 //%           [self class], _autocreator);
706 //%  [_dictionary release];
707 //%  [super dealloc];
708 //%}
710 //%- (instancetype)copyWithZone:(NSZone *)zone {
711 //%  return [[GPB##KEY_NAME##VALUE_NAME##Dictionary allocWithZone:zone] initWithDictionary:self];
712 //%}
714 //%- (BOOL)isEqual:(id)other {
715 //%  if (self == other) {
716 //%    return YES;
717 //%  }
718 //%  if (![other isKindOfClass:[GPB##KEY_NAME##VALUE_NAME##Dictionary class]]) {
719 //%    return NO;
720 //%  }
721 //%  GPB##KEY_NAME##VALUE_NAME##Dictionary *otherDictionary = other;
722 //%  return [_dictionary isEqual:otherDictionary->_dictionary];
723 //%}
725 //%- (NSUInteger)hash {
726 //%  return _dictionary.count;
727 //%}
729 //%- (NSString *)description {
730 //%  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
731 //%}
733 //%- (NSUInteger)count {
734 //%  return _dictionary.count;
735 //%}
737 //%- (void)enumerateKeysAnd##ACCESSOR_NAME##VNAME##sUsingBlock:
738 //%    (void (NS_NOESCAPE ^)(KEY_TYPE KisP##key, VALUE_TYPE VNAME_VAR, BOOL *stop))block {
739 //%  BOOL stop = NO;
740 //%  NSDictionary *internal = _dictionary;
741 //%  NSEnumerator *keys = [internal keyEnumerator];
742 //%  ENUM_TYPE##KHELPER(KEY_TYPE)##aKey;
743 //%  while ((aKey = [keys nextObject])) {
744 //%    ENUM_TYPE##VHELPER(VALUE_TYPE)##a##VNAME_VAR$u = internal[aKey];
745 //%    block(UNWRAP##KEY_NAME(aKey), UNWRAP##VALUE_NAME(a##VNAME_VAR$u), &stop);
746 //%    if (stop) {
747 //%      break;
748 //%    }
749 //%  }
750 //%}
752 //%EXTRA_METHODS_##VHELPER(KEY_NAME, VALUE_NAME)- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
753 //%  NSDictionary *internal = _dictionary;
754 //%  NSUInteger count = internal.count;
755 //%  if (count == 0) {
756 //%    return 0;
757 //%  }
759 //%  GPBDataType valueDataType = GPBGetFieldDataType(field);
760 //%  GPBDataType keyDataType = field.mapKeyDataType;
761 //%  size_t result = 0;
762 //%  NSEnumerator *keys = [internal keyEnumerator];
763 //%  ENUM_TYPE##KHELPER(KEY_TYPE)##aKey;
764 //%  while ((aKey = [keys nextObject])) {
765 //%    ENUM_TYPE##VHELPER(VALUE_TYPE)##a##VNAME_VAR$u = internal[aKey];
766 //%    size_t msgSize = ComputeDict##KEY_NAME##FieldSize(UNWRAP##KEY_NAME(aKey), kMapKeyFieldNumber, keyDataType);
767 //%    msgSize += ComputeDict##VALUE_NAME##FieldSize(UNWRAP##VALUE_NAME(a##VNAME_VAR$u), kMapValueFieldNumber, valueDataType);
768 //%    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
769 //%  }
770 //%  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
771 //%  result += tagSize * count;
772 //%  return result;
773 //%}
775 //%- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
776 //%                         asField:(GPBFieldDescriptor *)field {
777 //%  GPBDataType valueDataType = GPBGetFieldDataType(field);
778 //%  GPBDataType keyDataType = field.mapKeyDataType;
779 //%  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
780 //%  NSDictionary *internal = _dictionary;
781 //%  NSEnumerator *keys = [internal keyEnumerator];
782 //%  ENUM_TYPE##KHELPER(KEY_TYPE)##aKey;
783 //%  while ((aKey = [keys nextObject])) {
784 //%    ENUM_TYPE##VHELPER(VALUE_TYPE)##a##VNAME_VAR$u = internal[aKey];
785 //%    [outputStream writeInt32NoTag:tag];
786 //%    // Write the size of the message.
787 //%    KEY_TYPE KisP##unwrappedKey = UNWRAP##KEY_NAME(aKey);
788 //%    VALUE_TYPE unwrappedValue = UNWRAP##VALUE_NAME(a##VNAME_VAR$u);
789 //%    size_t msgSize = ComputeDict##KEY_NAME##FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
790 //%    msgSize += ComputeDict##VALUE_NAME##FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
791 //%    [outputStream writeInt32NoTag:(int32_t)msgSize];
792 //%    // Write the fields.
793 //%    WriteDict##KEY_NAME##Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
794 //%    WriteDict##VALUE_NAME##Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
795 //%  }
796 //%}
798 //%SERIAL_DATA_FOR_ENTRY_##VHELPER(KEY_NAME, VALUE_NAME)- (void)setGPBGenericValue:(GPBGenericValue *)value
799 //%     forGPBGenericValueKey:(GPBGenericValue *)key {
800 //%  [_dictionary setObject:WRAPPED##VHELPER(value->##GPBVALUE_##VHELPER(VALUE_NAME)##) forKey:WRAPPED##KHELPER(key->value##KEY_NAME)];
801 //%}
803 //%- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
804 //%  [self enumerateKeysAnd##ACCESSOR_NAME##VNAME##sUsingBlock:^(KEY_TYPE KisP##key, VALUE_TYPE VNAME_VAR, __unused BOOL *stop) {
805 //%      block(TEXT_FORMAT_OBJ##KEY_NAME(key), TEXT_FORMAT_OBJ##VALUE_NAME(VNAME_VAR));
806 //%  }];
807 //%}
808 //%PDDM-DEFINE DICTIONARY_MUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, ACCESSOR_NAME)
809 //%DICTIONARY_MUTABLE_CORE2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME, VNAME_VAR, ACCESSOR_NAME)
810 //%PDDM-DEFINE DICTIONARY_MUTABLE_CORE2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_REMOVE, VNAME_VAR, ACCESSOR_NAME)
811 //%- (void)add##ACCESSOR_NAME##EntriesFromDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)otherDictionary {
812 //%  if (otherDictionary) {
813 //%    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
814 //%    if (_autocreator) {
815 //%      GPBAutocreatedDictionaryModified(_autocreator, self);
816 //%    }
817 //%  }
818 //%}
820 //%- (void)set##ACCESSOR_NAME##VNAME##:(VALUE_TYPE)VNAME_VAR forKey:(KEY_TYPE##KisP$S##KisP)key {
821 //%DICTIONARY_VALIDATE_VALUE_##VHELPER(VNAME_VAR, )##DICTIONARY_VALIDATE_KEY_##KHELPER(key, )  [_dictionary setObject:WRAPPED##VHELPER(VNAME_VAR) forKey:WRAPPED##KHELPER(key)];
822 //%  if (_autocreator) {
823 //%    GPBAutocreatedDictionaryModified(_autocreator, self);
824 //%  }
825 //%}
827 //%- (void)remove##VNAME_REMOVE##ForKey:(KEY_TYPE##KisP$S##KisP)aKey {
828 //%  [_dictionary removeObjectForKey:WRAPPED##KHELPER(aKey)];
829 //%}
831 //%- (void)removeAll {
832 //%  [_dictionary removeAllObjects];
833 //%}
836 // Custom Generation for Bool keys
839 //%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_POD_IMPL(VALUE_NAME, VALUE_TYPE)
840 //%DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, POD, VALUE_NAME, value)
841 //%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_OBJECT_IMPL(VALUE_NAME, VALUE_TYPE)
842 //%DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, OBJECT, Object, object)
844 //%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, HELPER, VNAME, VNAME_VAR)
845 //%#pragma mark - Bool -> VALUE_NAME
847 //%@implementation GPBBool##VALUE_NAME##Dictionary {
848 //% @package
849 //%  VALUE_TYPE _values[2];
850 //%BOOL_DICT_HAS_STORAGE_##HELPER()}
852 //%- (instancetype)init {
853 //%  return [self initWith##VNAME##s:NULL forKeys:NULL count:0];
854 //%}
856 //%BOOL_DICT_INITS_##HELPER(VALUE_NAME, VALUE_TYPE)
858 //%- (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
859 //%  return [self initWith##VNAME##s:NULL forKeys:NULL count:0];
860 //%}
862 //%BOOL_DICT_DEALLOC##HELPER()
864 //%- (instancetype)copyWithZone:(NSZone *)zone {
865 //%  return [[GPBBool##VALUE_NAME##Dictionary allocWithZone:zone] initWithDictionary:self];
866 //%}
868 //%- (BOOL)isEqual:(id)other {
869 //%  if (self == other) {
870 //%    return YES;
871 //%  }
872 //%  if (![other isKindOfClass:[GPBBool##VALUE_NAME##Dictionary class]]) {
873 //%    return NO;
874 //%  }
875 //%  GPBBool##VALUE_NAME##Dictionary *otherDictionary = other;
876 //%  if ((BOOL_DICT_W_HAS##HELPER(0, ) != BOOL_DICT_W_HAS##HELPER(0, otherDictionary->)) ||
877 //%      (BOOL_DICT_W_HAS##HELPER(1, ) != BOOL_DICT_W_HAS##HELPER(1, otherDictionary->))) {
878 //%    return NO;
879 //%  }
880 //%  if ((BOOL_DICT_W_HAS##HELPER(0, ) && (NEQ_##HELPER(_values[0], otherDictionary->_values[0]))) ||
881 //%      (BOOL_DICT_W_HAS##HELPER(1, ) && (NEQ_##HELPER(_values[1], otherDictionary->_values[1])))) {
882 //%    return NO;
883 //%  }
884 //%  return YES;
885 //%}
887 //%- (NSUInteger)hash {
888 //%  return (BOOL_DICT_W_HAS##HELPER(0, ) ? 1 : 0) + (BOOL_DICT_W_HAS##HELPER(1, ) ? 1 : 0);
889 //%}
891 //%- (NSString *)description {
892 //%  NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
893 //%  if (BOOL_DICT_W_HAS##HELPER(0, )) {
894 //%    [result appendFormat:@"NO: STR_FORMAT_##HELPER(VALUE_NAME)", _values[0]];
895 //%  }
896 //%  if (BOOL_DICT_W_HAS##HELPER(1, )) {
897 //%    [result appendFormat:@"YES: STR_FORMAT_##HELPER(VALUE_NAME)", _values[1]];
898 //%  }
899 //%  [result appendString:@" }"];
900 //%  return result;
901 //%}
903 //%- (NSUInteger)count {
904 //%  return (BOOL_DICT_W_HAS##HELPER(0, ) ? 1 : 0) + (BOOL_DICT_W_HAS##HELPER(1, ) ? 1 : 0);
905 //%}
907 //%BOOL_VALUE_FOR_KEY_##HELPER(VALUE_NAME, VALUE_TYPE)
909 //%BOOL_SET_GPBVALUE_FOR_KEY_##HELPER(VALUE_NAME, VALUE_TYPE, VisP)
911 //%- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
912 //%  if (BOOL_DICT_HAS##HELPER(0, )) {
913 //%    block(@"false", TEXT_FORMAT_OBJ##VALUE_NAME(_values[0]));
914 //%  }
915 //%  if (BOOL_DICT_W_HAS##HELPER(1, )) {
916 //%    block(@"true", TEXT_FORMAT_OBJ##VALUE_NAME(_values[1]));
917 //%  }
918 //%}
920 //%- (void)enumerateKeysAnd##VNAME##sUsingBlock:
921 //%    (void (NS_NOESCAPE ^)(BOOL key, VALUE_TYPE VNAME_VAR, BOOL *stop))block {
922 //%  BOOL stop = NO;
923 //%  if (BOOL_DICT_HAS##HELPER(0, )) {
924 //%    block(NO, _values[0], &stop);
925 //%  }
926 //%  if (!stop && BOOL_DICT_W_HAS##HELPER(1, )) {
927 //%    block(YES, _values[1], &stop);
928 //%  }
929 //%}
931 //%BOOL_EXTRA_METHODS_##HELPER(Bool, VALUE_NAME)- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
932 //%  GPBDataType valueDataType = GPBGetFieldDataType(field);
933 //%  NSUInteger count = 0;
934 //%  size_t result = 0;
935 //%  for (int i = 0; i < 2; ++i) {
936 //%    if (BOOL_DICT_HAS##HELPER(i, )) {
937 //%      ++count;
938 //%      size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
939 //%      msgSize += ComputeDict##VALUE_NAME##FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
940 //%      result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
941 //%    }
942 //%  }
943 //%  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
944 //%  result += tagSize * count;
945 //%  return result;
946 //%}
948 //%- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
949 //%                         asField:(GPBFieldDescriptor *)field {
950 //%  GPBDataType valueDataType = GPBGetFieldDataType(field);
951 //%  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
952 //%  for (int i = 0; i < 2; ++i) {
953 //%    if (BOOL_DICT_HAS##HELPER(i, )) {
954 //%      // Write the tag.
955 //%      [outputStream writeInt32NoTag:tag];
956 //%      // Write the size of the message.
957 //%      size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
958 //%      msgSize += ComputeDict##VALUE_NAME##FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
959 //%      [outputStream writeInt32NoTag:(int32_t)msgSize];
960 //%      // Write the fields.
961 //%      WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
962 //%      WriteDict##VALUE_NAME##Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
963 //%    }
964 //%  }
965 //%}
967 //%BOOL_DICT_MUTATIONS_##HELPER(VALUE_NAME, VALUE_TYPE)
969 //%@end
974 // Helpers for PODs
977 //%PDDM-DEFINE VALUE_FOR_KEY_POD(KEY_TYPE, VALUE_NAME, VALUE_TYPE, KHELPER)
978 //%- (BOOL)get##VALUE_NAME##:(nullable VALUE_TYPE *)value forKey:(KEY_TYPE)key {
979 //%  NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)];
980 //%  if (wrapped && value) {
981 //%    *value = UNWRAP##VALUE_NAME(wrapped);
982 //%  }
983 //%  return (wrapped != NULL);
984 //%}
985 //%PDDM-DEFINE WRAPPEDPOD(VALUE)
986 //%@(VALUE)
987 //%PDDM-DEFINE UNWRAPUInt32(VALUE)
988 //%[VALUE unsignedIntValue]
989 //%PDDM-DEFINE UNWRAPInt32(VALUE)
990 //%[VALUE intValue]
991 //%PDDM-DEFINE UNWRAPUInt64(VALUE)
992 //%[VALUE unsignedLongLongValue]
993 //%PDDM-DEFINE UNWRAPInt64(VALUE)
994 //%[VALUE longLongValue]
995 //%PDDM-DEFINE UNWRAPBool(VALUE)
996 //%[VALUE boolValue]
997 //%PDDM-DEFINE UNWRAPFloat(VALUE)
998 //%[VALUE floatValue]
999 //%PDDM-DEFINE UNWRAPDouble(VALUE)
1000 //%[VALUE doubleValue]
1001 //%PDDM-DEFINE UNWRAPEnum(VALUE)
1002 //%[VALUE intValue]
1003 //%PDDM-DEFINE TEXT_FORMAT_OBJUInt32(VALUE)
1004 //%[NSString stringWithFormat:@"%u", VALUE]
1005 //%PDDM-DEFINE TEXT_FORMAT_OBJInt32(VALUE)
1006 //%[NSString stringWithFormat:@"%d", VALUE]
1007 //%PDDM-DEFINE TEXT_FORMAT_OBJUInt64(VALUE)
1008 //%[NSString stringWithFormat:@"%llu", VALUE]
1009 //%PDDM-DEFINE TEXT_FORMAT_OBJInt64(VALUE)
1010 //%[NSString stringWithFormat:@"%lld", VALUE]
1011 //%PDDM-DEFINE TEXT_FORMAT_OBJBool(VALUE)
1012 //%(VALUE ? @"true" : @"false")
1013 //%PDDM-DEFINE TEXT_FORMAT_OBJFloat(VALUE)
1014 //%[NSString stringWithFormat:@"%.*g", FLT_DIG, VALUE]
1015 //%PDDM-DEFINE TEXT_FORMAT_OBJDouble(VALUE)
1016 //%[NSString stringWithFormat:@"%.*lg", DBL_DIG, VALUE]
1017 //%PDDM-DEFINE TEXT_FORMAT_OBJEnum(VALUE)
1018 //%@(VALUE)
1019 //%PDDM-DEFINE ENUM_TYPEPOD(TYPE)
1020 //%NSNumber *
1021 //%PDDM-DEFINE NEQ_POD(VAL1, VAL2)
1022 //%VAL1 != VAL2
1023 //%PDDM-DEFINE EXTRA_METHODS_POD(KEY_NAME, VALUE_NAME)
1024 // Empty
1025 //%PDDM-DEFINE BOOL_EXTRA_METHODS_POD(KEY_NAME, VALUE_NAME)
1026 // Empty
1027 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD(KEY_NAME, VALUE_NAME)
1028 //%SERIAL_DATA_FOR_ENTRY_POD_##VALUE_NAME(KEY_NAME)
1029 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_UInt32(KEY_NAME)
1030 // Empty
1031 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Int32(KEY_NAME)
1032 // Empty
1033 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_UInt64(KEY_NAME)
1034 // Empty
1035 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Int64(KEY_NAME)
1036 // Empty
1037 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Bool(KEY_NAME)
1038 // Empty
1039 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Float(KEY_NAME)
1040 // Empty
1041 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Double(KEY_NAME)
1042 // Empty
1043 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Enum(KEY_NAME)
1044 //%- (NSData *)serializedDataForUnknownValue:(int32_t)value
1045 //%                                   forKey:(GPBGenericValue *)key
1046 //%                              keyDataType:(GPBDataType)keyDataType {
1047 //%  size_t msgSize = ComputeDict##KEY_NAME##FieldSize(key->value##KEY_NAME, kMapKeyFieldNumber, keyDataType);
1048 //%  msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
1049 //%  NSMutableData *data = [NSMutableData dataWithLength:msgSize];
1050 //%  GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
1051 //%  WriteDict##KEY_NAME##Field(outputStream, key->value##KEY_NAME, kMapKeyFieldNumber, keyDataType);
1052 //%  WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
1053 //%  [outputStream flush];
1054 //%  [outputStream release];
1055 //%  return data;
1056 //%}
1058 //%PDDM-DEFINE GPBVALUE_POD(VALUE_NAME)
1059 //%value##VALUE_NAME
1060 //%PDDM-DEFINE DICTIONARY_VALIDATE_VALUE_POD(VALUE_NAME, EXTRA_INDENT)
1061 // Empty
1062 //%PDDM-DEFINE DICTIONARY_VALIDATE_KEY_POD(KEY_NAME, EXTRA_INDENT)
1063 // Empty
1065 //%PDDM-DEFINE BOOL_DICT_HAS_STORAGE_POD()
1066 //%  BOOL _valueSet[2];
1068 //%PDDM-DEFINE BOOL_DICT_INITS_POD(VALUE_NAME, VALUE_TYPE)
1069 //%- (instancetype)initWith##VALUE_NAME##s:(const VALUE_TYPE [])values
1070 //%                 ##VALUE_NAME$S## forKeys:(const BOOL [])keys
1071 //%                 ##VALUE_NAME$S##   count:(NSUInteger)count {
1072 //%  self = [super init];
1073 //%  if (self) {
1074 //%    for (NSUInteger i = 0; i < count; ++i) {
1075 //%      int idx = keys[i] ? 1 : 0;
1076 //%      _values[idx] = values[i];
1077 //%      _valueSet[idx] = YES;
1078 //%    }
1079 //%  }
1080 //%  return self;
1081 //%}
1083 //%- (instancetype)initWithDictionary:(GPBBool##VALUE_NAME##Dictionary *)dictionary {
1084 //%  self = [self initWith##VALUE_NAME##s:NULL forKeys:NULL count:0];
1085 //%  if (self) {
1086 //%    if (dictionary) {
1087 //%      for (int i = 0; i < 2; ++i) {
1088 //%        if (dictionary->_valueSet[i]) {
1089 //%          _values[i] = dictionary->_values[i];
1090 //%          _valueSet[i] = YES;
1091 //%        }
1092 //%      }
1093 //%    }
1094 //%  }
1095 //%  return self;
1096 //%}
1097 //%PDDM-DEFINE BOOL_DICT_DEALLOCPOD()
1098 //%#if !defined(NS_BLOCK_ASSERTIONS)
1099 //%- (void)dealloc {
1100 //%  NSAssert(!_autocreator,
1101 //%           @"%@: Autocreator must be cleared before release, autocreator: %@",
1102 //%           [self class], _autocreator);
1103 //%  [super dealloc];
1104 //%}
1105 //%#endif  // !defined(NS_BLOCK_ASSERTIONS)
1106 //%PDDM-DEFINE BOOL_DICT_W_HASPOD(IDX, REF)
1107 //%BOOL_DICT_HASPOD(IDX, REF)
1108 //%PDDM-DEFINE BOOL_DICT_HASPOD(IDX, REF)
1109 //%REF##_valueSet[IDX]
1110 //%PDDM-DEFINE BOOL_VALUE_FOR_KEY_POD(VALUE_NAME, VALUE_TYPE)
1111 //%- (BOOL)get##VALUE_NAME##:(VALUE_TYPE *)value forKey:(BOOL)key {
1112 //%  int idx = (key ? 1 : 0);
1113 //%  if (_valueSet[idx]) {
1114 //%    if (value) {
1115 //%      *value = _values[idx];
1116 //%    }
1117 //%    return YES;
1118 //%  }
1119 //%  return NO;
1120 //%}
1121 //%PDDM-DEFINE BOOL_SET_GPBVALUE_FOR_KEY_POD(VALUE_NAME, VALUE_TYPE, VisP)
1122 //%- (void)setGPBGenericValue:(GPBGenericValue *)value
1123 //%     forGPBGenericValueKey:(GPBGenericValue *)key {
1124 //%  int idx = (key->valueBool ? 1 : 0);
1125 //%  _values[idx] = value->value##VALUE_NAME;
1126 //%  _valueSet[idx] = YES;
1127 //%}
1128 //%PDDM-DEFINE BOOL_DICT_MUTATIONS_POD(VALUE_NAME, VALUE_TYPE)
1129 //%- (void)addEntriesFromDictionary:(GPBBool##VALUE_NAME##Dictionary *)otherDictionary {
1130 //%  if (otherDictionary) {
1131 //%    for (int i = 0; i < 2; ++i) {
1132 //%      if (otherDictionary->_valueSet[i]) {
1133 //%        _valueSet[i] = YES;
1134 //%        _values[i] = otherDictionary->_values[i];
1135 //%      }
1136 //%    }
1137 //%    if (_autocreator) {
1138 //%      GPBAutocreatedDictionaryModified(_autocreator, self);
1139 //%    }
1140 //%  }
1141 //%}
1143 //%- (void)set##VALUE_NAME:(VALUE_TYPE)value forKey:(BOOL)key {
1144 //%  int idx = (key ? 1 : 0);
1145 //%  _values[idx] = value;
1146 //%  _valueSet[idx] = YES;
1147 //%  if (_autocreator) {
1148 //%    GPBAutocreatedDictionaryModified(_autocreator, self);
1149 //%  }
1150 //%}
1152 //%- (void)remove##VALUE_NAME##ForKey:(BOOL)aKey {
1153 //%  _valueSet[aKey ? 1 : 0] = NO;
1154 //%}
1156 //%- (void)removeAll {
1157 //%  _valueSet[0] = NO;
1158 //%  _valueSet[1] = NO;
1159 //%}
1160 //%PDDM-DEFINE STR_FORMAT_POD(VALUE_NAME)
1161 //%STR_FORMAT_##VALUE_NAME()
1162 //%PDDM-DEFINE STR_FORMAT_UInt32()
1163 //%%u
1164 //%PDDM-DEFINE STR_FORMAT_Int32()
1165 //%%d
1166 //%PDDM-DEFINE STR_FORMAT_UInt64()
1167 //%%llu
1168 //%PDDM-DEFINE STR_FORMAT_Int64()
1169 //%%lld
1170 //%PDDM-DEFINE STR_FORMAT_Bool()
1171 //%%d
1172 //%PDDM-DEFINE STR_FORMAT_Float()
1173 //%%f
1174 //%PDDM-DEFINE STR_FORMAT_Double()
1175 //%%lf
1178 // Helpers for Objects
1181 //%PDDM-DEFINE VALUE_FOR_KEY_OBJECT(KEY_TYPE, VALUE_NAME, VALUE_TYPE, KHELPER)
1182 //%- (VALUE_TYPE)objectForKey:(KEY_TYPE)key {
1183 //%  VALUE_TYPE result = [_dictionary objectForKey:WRAPPED##KHELPER(key)];
1184 //%  return result;
1185 //%}
1186 //%PDDM-DEFINE WRAPPEDOBJECT(VALUE)
1187 //%VALUE
1188 //%PDDM-DEFINE UNWRAPString(VALUE)
1189 //%VALUE
1190 //%PDDM-DEFINE UNWRAPObject(VALUE)
1191 //%VALUE
1192 //%PDDM-DEFINE TEXT_FORMAT_OBJString(VALUE)
1193 //%VALUE
1194 //%PDDM-DEFINE TEXT_FORMAT_OBJObject(VALUE)
1195 //%VALUE
1196 //%PDDM-DEFINE ENUM_TYPEOBJECT(TYPE)
1197 //%ENUM_TYPEOBJECT_##TYPE()
1198 //%PDDM-DEFINE ENUM_TYPEOBJECT_NSString()
1199 //%NSString *
1200 //%PDDM-DEFINE ENUM_TYPEOBJECT_id()
1201 //%id ##
1202 //%PDDM-DEFINE NEQ_OBJECT(VAL1, VAL2)
1203 //%![VAL1 isEqual:VAL2]
1204 //%PDDM-DEFINE EXTRA_METHODS_OBJECT(KEY_NAME, VALUE_NAME)
1205 //%- (BOOL)isInitialized {
1206 //%  for (GPBMessage *msg in [_dictionary objectEnumerator]) {
1207 //%    if (!msg.initialized) {
1208 //%      return NO;
1209 //%    }
1210 //%  }
1211 //%  return YES;
1212 //%}
1214 //%- (instancetype)deepCopyWithZone:(NSZone *)zone {
1215 //%  GPB##KEY_NAME##VALUE_NAME##Dictionary *newDict =
1216 //%      [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] init];
1217 //%  NSEnumerator *keys = [_dictionary keyEnumerator];
1218 //%  id aKey;
1219 //%  NSMutableDictionary *internalDict = newDict->_dictionary;
1220 //%  while ((aKey = [keys nextObject])) {
1221 //%    GPBMessage *msg = _dictionary[aKey];
1222 //%    GPBMessage *copiedMsg = [msg copyWithZone:zone];
1223 //%    [internalDict setObject:copiedMsg forKey:aKey];
1224 //%    [copiedMsg release];
1225 //%  }
1226 //%  return newDict;
1227 //%}
1230 //%PDDM-DEFINE BOOL_EXTRA_METHODS_OBJECT(KEY_NAME, VALUE_NAME)
1231 //%- (BOOL)isInitialized {
1232 //%  if (_values[0] && ![_values[0] isInitialized]) {
1233 //%    return NO;
1234 //%  }
1235 //%  if (_values[1] && ![_values[1] isInitialized]) {
1236 //%    return NO;
1237 //%  }
1238 //%  return YES;
1239 //%}
1241 //%- (instancetype)deepCopyWithZone:(NSZone *)zone {
1242 //%  GPB##KEY_NAME##VALUE_NAME##Dictionary *newDict =
1243 //%      [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] init];
1244 //%  for (int i = 0; i < 2; ++i) {
1245 //%    if (_values[i] != nil) {
1246 //%      newDict->_values[i] = [_values[i] copyWithZone:zone];
1247 //%    }
1248 //%  }
1249 //%  return newDict;
1250 //%}
1253 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_OBJECT(KEY_NAME, VALUE_NAME)
1254 // Empty
1255 //%PDDM-DEFINE GPBVALUE_OBJECT(VALUE_NAME)
1256 //%valueString
1257 //%PDDM-DEFINE DICTIONARY_VALIDATE_VALUE_OBJECT(VALUE_NAME, EXTRA_INDENT)
1258 //%##EXTRA_INDENT$S##  if (!##VALUE_NAME) {
1259 //%##EXTRA_INDENT$S##    [NSException raise:NSInvalidArgumentException
1260 //%##EXTRA_INDENT$S##                format:@"Attempting to add nil object to a Dictionary"];
1261 //%##EXTRA_INDENT$S##  }
1263 //%PDDM-DEFINE DICTIONARY_VALIDATE_KEY_OBJECT(KEY_NAME, EXTRA_INDENT)
1264 //%##EXTRA_INDENT$S##  if (!##KEY_NAME) {
1265 //%##EXTRA_INDENT$S##    [NSException raise:NSInvalidArgumentException
1266 //%##EXTRA_INDENT$S##                format:@"Attempting to add nil key to a Dictionary"];
1267 //%##EXTRA_INDENT$S##  }
1270 //%PDDM-DEFINE BOOL_DICT_HAS_STORAGE_OBJECT()
1271 // Empty
1272 //%PDDM-DEFINE BOOL_DICT_INITS_OBJECT(VALUE_NAME, VALUE_TYPE)
1273 //%- (instancetype)initWithObjects:(const VALUE_TYPE [])objects
1274 //%                        forKeys:(const BOOL [])keys
1275 //%                          count:(NSUInteger)count {
1276 //%  self = [super init];
1277 //%  if (self) {
1278 //%    for (NSUInteger i = 0; i < count; ++i) {
1279 //%      if (!objects[i]) {
1280 //%        [NSException raise:NSInvalidArgumentException
1281 //%                    format:@"Attempting to add nil object to a Dictionary"];
1282 //%      }
1283 //%      int idx = keys[i] ? 1 : 0;
1284 //%      [_values[idx] release];
1285 //%      _values[idx] = (VALUE_TYPE)[objects[i] retain];
1286 //%    }
1287 //%  }
1288 //%  return self;
1289 //%}
1291 //%- (instancetype)initWithDictionary:(GPBBool##VALUE_NAME##Dictionary *)dictionary {
1292 //%  self = [self initWithObjects:NULL forKeys:NULL count:0];
1293 //%  if (self) {
1294 //%    if (dictionary) {
1295 //%      _values[0] = [dictionary->_values[0] retain];
1296 //%      _values[1] = [dictionary->_values[1] retain];
1297 //%    }
1298 //%  }
1299 //%  return self;
1300 //%}
1301 //%PDDM-DEFINE BOOL_DICT_DEALLOCOBJECT()
1302 //%- (void)dealloc {
1303 //%  NSAssert(!_autocreator,
1304 //%           @"%@: Autocreator must be cleared before release, autocreator: %@",
1305 //%           [self class], _autocreator);
1306 //%  [_values[0] release];
1307 //%  [_values[1] release];
1308 //%  [super dealloc];
1309 //%}
1310 //%PDDM-DEFINE BOOL_DICT_W_HASOBJECT(IDX, REF)
1311 //%(BOOL_DICT_HASOBJECT(IDX, REF))
1312 //%PDDM-DEFINE BOOL_DICT_HASOBJECT(IDX, REF)
1313 //%REF##_values[IDX] != nil
1314 //%PDDM-DEFINE BOOL_VALUE_FOR_KEY_OBJECT(VALUE_NAME, VALUE_TYPE)
1315 //%- (VALUE_TYPE)objectForKey:(BOOL)key {
1316 //%  return _values[key ? 1 : 0];
1317 //%}
1318 //%PDDM-DEFINE BOOL_SET_GPBVALUE_FOR_KEY_OBJECT(VALUE_NAME, VALUE_TYPE, VisP)
1319 //%- (void)setGPBGenericValue:(GPBGenericValue *)value
1320 //%     forGPBGenericValueKey:(GPBGenericValue *)key {
1321 //%  int idx = (key->valueBool ? 1 : 0);
1322 //%  [_values[idx] release];
1323 //%  _values[idx] = [value->valueString retain];
1324 //%}
1326 //%PDDM-DEFINE BOOL_DICT_MUTATIONS_OBJECT(VALUE_NAME, VALUE_TYPE)
1327 //%- (void)addEntriesFromDictionary:(GPBBool##VALUE_NAME##Dictionary *)otherDictionary {
1328 //%  if (otherDictionary) {
1329 //%    for (int i = 0; i < 2; ++i) {
1330 //%      if (otherDictionary->_values[i] != nil) {
1331 //%        [_values[i] release];
1332 //%        _values[i] = [otherDictionary->_values[i] retain];
1333 //%      }
1334 //%    }
1335 //%    if (_autocreator) {
1336 //%      GPBAutocreatedDictionaryModified(_autocreator, self);
1337 //%    }
1338 //%  }
1339 //%}
1341 //%- (void)setObject:(VALUE_TYPE)object forKey:(BOOL)key {
1342 //%  if (!object) {
1343 //%    [NSException raise:NSInvalidArgumentException
1344 //%                format:@"Attempting to add nil object to a Dictionary"];
1345 //%  }
1346 //%  int idx = (key ? 1 : 0);
1347 //%  [_values[idx] release];
1348 //%  _values[idx] = [object retain];
1349 //%  if (_autocreator) {
1350 //%    GPBAutocreatedDictionaryModified(_autocreator, self);
1351 //%  }
1352 //%}
1354 //%- (void)removeObjectForKey:(BOOL)aKey {
1355 //%  int idx = (aKey ? 1 : 0);
1356 //%  [_values[idx] release];
1357 //%  _values[idx] = nil;
1358 //%}
1360 //%- (void)removeAll {
1361 //%  for (int i = 0; i < 2; ++i) {
1362 //%    [_values[i] release];
1363 //%    _values[i] = nil;
1364 //%  }
1365 //%}
1366 //%PDDM-DEFINE STR_FORMAT_OBJECT(VALUE_NAME)
1367 //%%@
1370 //%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(UInt32, uint32_t)
1371 // This block of code is generated, do not edit it directly.
1373 #pragma mark - UInt32 -> UInt32
1375 @implementation GPBUInt32UInt32Dictionary {
1376  @package
1377   NSMutableDictionary *_dictionary;
1380 - (instancetype)init {
1381   return [self initWithUInt32s:NULL forKeys:NULL count:0];
1384 - (instancetype)initWithUInt32s:(const uint32_t [])values
1385                         forKeys:(const uint32_t [])keys
1386                           count:(NSUInteger)count {
1387   self = [super init];
1388   if (self) {
1389     _dictionary = [[NSMutableDictionary alloc] init];
1390     if (count && values && keys) {
1391       for (NSUInteger i = 0; i < count; ++i) {
1392         [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
1393       }
1394     }
1395   }
1396   return self;
1399 - (instancetype)initWithDictionary:(GPBUInt32UInt32Dictionary *)dictionary {
1400   self = [self initWithUInt32s:NULL forKeys:NULL count:0];
1401   if (self) {
1402     if (dictionary) {
1403       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
1404     }
1405   }
1406   return self;
1409 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
1410   return [self initWithUInt32s:NULL forKeys:NULL count:0];
1413 - (void)dealloc {
1414   NSAssert(!_autocreator,
1415            @"%@: Autocreator must be cleared before release, autocreator: %@",
1416            [self class], _autocreator);
1417   [_dictionary release];
1418   [super dealloc];
1421 - (instancetype)copyWithZone:(NSZone *)zone {
1422   return [[GPBUInt32UInt32Dictionary allocWithZone:zone] initWithDictionary:self];
1425 - (BOOL)isEqual:(id)other {
1426   if (self == other) {
1427     return YES;
1428   }
1429   if (![other isKindOfClass:[GPBUInt32UInt32Dictionary class]]) {
1430     return NO;
1431   }
1432   GPBUInt32UInt32Dictionary *otherDictionary = other;
1433   return [_dictionary isEqual:otherDictionary->_dictionary];
1436 - (NSUInteger)hash {
1437   return _dictionary.count;
1440 - (NSString *)description {
1441   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
1444 - (NSUInteger)count {
1445   return _dictionary.count;
1448 - (void)enumerateKeysAndUInt32sUsingBlock:
1449     (void (NS_NOESCAPE ^)(uint32_t key, uint32_t value, BOOL *stop))block {
1450   BOOL stop = NO;
1451   NSDictionary *internal = _dictionary;
1452   NSEnumerator *keys = [internal keyEnumerator];
1453   NSNumber *aKey;
1454   while ((aKey = [keys nextObject])) {
1455     NSNumber *aValue = internal[aKey];
1456     block([aKey unsignedIntValue], [aValue unsignedIntValue], &stop);
1457     if (stop) {
1458       break;
1459     }
1460   }
1463 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
1464   NSDictionary *internal = _dictionary;
1465   NSUInteger count = internal.count;
1466   if (count == 0) {
1467     return 0;
1468   }
1470   GPBDataType valueDataType = GPBGetFieldDataType(field);
1471   GPBDataType keyDataType = field.mapKeyDataType;
1472   size_t result = 0;
1473   NSEnumerator *keys = [internal keyEnumerator];
1474   NSNumber *aKey;
1475   while ((aKey = [keys nextObject])) {
1476     NSNumber *aValue = internal[aKey];
1477     size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
1478     msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
1479     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
1480   }
1481   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
1482   result += tagSize * count;
1483   return result;
1486 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
1487                          asField:(GPBFieldDescriptor *)field {
1488   GPBDataType valueDataType = GPBGetFieldDataType(field);
1489   GPBDataType keyDataType = field.mapKeyDataType;
1490   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
1491   NSDictionary *internal = _dictionary;
1492   NSEnumerator *keys = [internal keyEnumerator];
1493   NSNumber *aKey;
1494   while ((aKey = [keys nextObject])) {
1495     NSNumber *aValue = internal[aKey];
1496     [outputStream writeInt32NoTag:tag];
1497     // Write the size of the message.
1498     uint32_t unwrappedKey = [aKey unsignedIntValue];
1499     uint32_t unwrappedValue = [aValue unsignedIntValue];
1500     size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
1501     msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
1502     [outputStream writeInt32NoTag:(int32_t)msgSize];
1503     // Write the fields.
1504     WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
1505     WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
1506   }
1509 - (void)setGPBGenericValue:(GPBGenericValue *)value
1510      forGPBGenericValueKey:(GPBGenericValue *)key {
1511   [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueUInt32)];
1514 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
1515   [self enumerateKeysAndUInt32sUsingBlock:^(uint32_t key, uint32_t value, __unused BOOL *stop) {
1516       block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%u", value]);
1517   }];
1520 - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(uint32_t)key {
1521   NSNumber *wrapped = [_dictionary objectForKey:@(key)];
1522   if (wrapped && value) {
1523     *value = [wrapped unsignedIntValue];
1524   }
1525   return (wrapped != NULL);
1528 - (void)addEntriesFromDictionary:(GPBUInt32UInt32Dictionary *)otherDictionary {
1529   if (otherDictionary) {
1530     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
1531     if (_autocreator) {
1532       GPBAutocreatedDictionaryModified(_autocreator, self);
1533     }
1534   }
1537 - (void)setUInt32:(uint32_t)value forKey:(uint32_t)key {
1538   [_dictionary setObject:@(value) forKey:@(key)];
1539   if (_autocreator) {
1540     GPBAutocreatedDictionaryModified(_autocreator, self);
1541   }
1544 - (void)removeUInt32ForKey:(uint32_t)aKey {
1545   [_dictionary removeObjectForKey:@(aKey)];
1548 - (void)removeAll {
1549   [_dictionary removeAllObjects];
1552 @end
1554 #pragma mark - UInt32 -> Int32
1556 @implementation GPBUInt32Int32Dictionary {
1557  @package
1558   NSMutableDictionary *_dictionary;
1561 - (instancetype)init {
1562   return [self initWithInt32s:NULL forKeys:NULL count:0];
1565 - (instancetype)initWithInt32s:(const int32_t [])values
1566                        forKeys:(const uint32_t [])keys
1567                          count:(NSUInteger)count {
1568   self = [super init];
1569   if (self) {
1570     _dictionary = [[NSMutableDictionary alloc] init];
1571     if (count && values && keys) {
1572       for (NSUInteger i = 0; i < count; ++i) {
1573         [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
1574       }
1575     }
1576   }
1577   return self;
1580 - (instancetype)initWithDictionary:(GPBUInt32Int32Dictionary *)dictionary {
1581   self = [self initWithInt32s:NULL forKeys:NULL count:0];
1582   if (self) {
1583     if (dictionary) {
1584       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
1585     }
1586   }
1587   return self;
1590 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
1591   return [self initWithInt32s:NULL forKeys:NULL count:0];
1594 - (void)dealloc {
1595   NSAssert(!_autocreator,
1596            @"%@: Autocreator must be cleared before release, autocreator: %@",
1597            [self class], _autocreator);
1598   [_dictionary release];
1599   [super dealloc];
1602 - (instancetype)copyWithZone:(NSZone *)zone {
1603   return [[GPBUInt32Int32Dictionary allocWithZone:zone] initWithDictionary:self];
1606 - (BOOL)isEqual:(id)other {
1607   if (self == other) {
1608     return YES;
1609   }
1610   if (![other isKindOfClass:[GPBUInt32Int32Dictionary class]]) {
1611     return NO;
1612   }
1613   GPBUInt32Int32Dictionary *otherDictionary = other;
1614   return [_dictionary isEqual:otherDictionary->_dictionary];
1617 - (NSUInteger)hash {
1618   return _dictionary.count;
1621 - (NSString *)description {
1622   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
1625 - (NSUInteger)count {
1626   return _dictionary.count;
1629 - (void)enumerateKeysAndInt32sUsingBlock:
1630     (void (NS_NOESCAPE ^)(uint32_t key, int32_t value, BOOL *stop))block {
1631   BOOL stop = NO;
1632   NSDictionary *internal = _dictionary;
1633   NSEnumerator *keys = [internal keyEnumerator];
1634   NSNumber *aKey;
1635   while ((aKey = [keys nextObject])) {
1636     NSNumber *aValue = internal[aKey];
1637     block([aKey unsignedIntValue], [aValue intValue], &stop);
1638     if (stop) {
1639       break;
1640     }
1641   }
1644 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
1645   NSDictionary *internal = _dictionary;
1646   NSUInteger count = internal.count;
1647   if (count == 0) {
1648     return 0;
1649   }
1651   GPBDataType valueDataType = GPBGetFieldDataType(field);
1652   GPBDataType keyDataType = field.mapKeyDataType;
1653   size_t result = 0;
1654   NSEnumerator *keys = [internal keyEnumerator];
1655   NSNumber *aKey;
1656   while ((aKey = [keys nextObject])) {
1657     NSNumber *aValue = internal[aKey];
1658     size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
1659     msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
1660     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
1661   }
1662   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
1663   result += tagSize * count;
1664   return result;
1667 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
1668                          asField:(GPBFieldDescriptor *)field {
1669   GPBDataType valueDataType = GPBGetFieldDataType(field);
1670   GPBDataType keyDataType = field.mapKeyDataType;
1671   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
1672   NSDictionary *internal = _dictionary;
1673   NSEnumerator *keys = [internal keyEnumerator];
1674   NSNumber *aKey;
1675   while ((aKey = [keys nextObject])) {
1676     NSNumber *aValue = internal[aKey];
1677     [outputStream writeInt32NoTag:tag];
1678     // Write the size of the message.
1679     uint32_t unwrappedKey = [aKey unsignedIntValue];
1680     int32_t unwrappedValue = [aValue intValue];
1681     size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
1682     msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
1683     [outputStream writeInt32NoTag:(int32_t)msgSize];
1684     // Write the fields.
1685     WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
1686     WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
1687   }
1690 - (void)setGPBGenericValue:(GPBGenericValue *)value
1691      forGPBGenericValueKey:(GPBGenericValue *)key {
1692   [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueUInt32)];
1695 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
1696   [self enumerateKeysAndInt32sUsingBlock:^(uint32_t key, int32_t value, __unused BOOL *stop) {
1697       block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%d", value]);
1698   }];
1701 - (BOOL)getInt32:(nullable int32_t *)value forKey:(uint32_t)key {
1702   NSNumber *wrapped = [_dictionary objectForKey:@(key)];
1703   if (wrapped && value) {
1704     *value = [wrapped intValue];
1705   }
1706   return (wrapped != NULL);
1709 - (void)addEntriesFromDictionary:(GPBUInt32Int32Dictionary *)otherDictionary {
1710   if (otherDictionary) {
1711     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
1712     if (_autocreator) {
1713       GPBAutocreatedDictionaryModified(_autocreator, self);
1714     }
1715   }
1718 - (void)setInt32:(int32_t)value forKey:(uint32_t)key {
1719   [_dictionary setObject:@(value) forKey:@(key)];
1720   if (_autocreator) {
1721     GPBAutocreatedDictionaryModified(_autocreator, self);
1722   }
1725 - (void)removeInt32ForKey:(uint32_t)aKey {
1726   [_dictionary removeObjectForKey:@(aKey)];
1729 - (void)removeAll {
1730   [_dictionary removeAllObjects];
1733 @end
1735 #pragma mark - UInt32 -> UInt64
1737 @implementation GPBUInt32UInt64Dictionary {
1738  @package
1739   NSMutableDictionary *_dictionary;
1742 - (instancetype)init {
1743   return [self initWithUInt64s:NULL forKeys:NULL count:0];
1746 - (instancetype)initWithUInt64s:(const uint64_t [])values
1747                         forKeys:(const uint32_t [])keys
1748                           count:(NSUInteger)count {
1749   self = [super init];
1750   if (self) {
1751     _dictionary = [[NSMutableDictionary alloc] init];
1752     if (count && values && keys) {
1753       for (NSUInteger i = 0; i < count; ++i) {
1754         [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
1755       }
1756     }
1757   }
1758   return self;
1761 - (instancetype)initWithDictionary:(GPBUInt32UInt64Dictionary *)dictionary {
1762   self = [self initWithUInt64s:NULL forKeys:NULL count:0];
1763   if (self) {
1764     if (dictionary) {
1765       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
1766     }
1767   }
1768   return self;
1771 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
1772   return [self initWithUInt64s:NULL forKeys:NULL count:0];
1775 - (void)dealloc {
1776   NSAssert(!_autocreator,
1777            @"%@: Autocreator must be cleared before release, autocreator: %@",
1778            [self class], _autocreator);
1779   [_dictionary release];
1780   [super dealloc];
1783 - (instancetype)copyWithZone:(NSZone *)zone {
1784   return [[GPBUInt32UInt64Dictionary allocWithZone:zone] initWithDictionary:self];
1787 - (BOOL)isEqual:(id)other {
1788   if (self == other) {
1789     return YES;
1790   }
1791   if (![other isKindOfClass:[GPBUInt32UInt64Dictionary class]]) {
1792     return NO;
1793   }
1794   GPBUInt32UInt64Dictionary *otherDictionary = other;
1795   return [_dictionary isEqual:otherDictionary->_dictionary];
1798 - (NSUInteger)hash {
1799   return _dictionary.count;
1802 - (NSString *)description {
1803   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
1806 - (NSUInteger)count {
1807   return _dictionary.count;
1810 - (void)enumerateKeysAndUInt64sUsingBlock:
1811     (void (NS_NOESCAPE ^)(uint32_t key, uint64_t value, BOOL *stop))block {
1812   BOOL stop = NO;
1813   NSDictionary *internal = _dictionary;
1814   NSEnumerator *keys = [internal keyEnumerator];
1815   NSNumber *aKey;
1816   while ((aKey = [keys nextObject])) {
1817     NSNumber *aValue = internal[aKey];
1818     block([aKey unsignedIntValue], [aValue unsignedLongLongValue], &stop);
1819     if (stop) {
1820       break;
1821     }
1822   }
1825 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
1826   NSDictionary *internal = _dictionary;
1827   NSUInteger count = internal.count;
1828   if (count == 0) {
1829     return 0;
1830   }
1832   GPBDataType valueDataType = GPBGetFieldDataType(field);
1833   GPBDataType keyDataType = field.mapKeyDataType;
1834   size_t result = 0;
1835   NSEnumerator *keys = [internal keyEnumerator];
1836   NSNumber *aKey;
1837   while ((aKey = [keys nextObject])) {
1838     NSNumber *aValue = internal[aKey];
1839     size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
1840     msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
1841     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
1842   }
1843   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
1844   result += tagSize * count;
1845   return result;
1848 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
1849                          asField:(GPBFieldDescriptor *)field {
1850   GPBDataType valueDataType = GPBGetFieldDataType(field);
1851   GPBDataType keyDataType = field.mapKeyDataType;
1852   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
1853   NSDictionary *internal = _dictionary;
1854   NSEnumerator *keys = [internal keyEnumerator];
1855   NSNumber *aKey;
1856   while ((aKey = [keys nextObject])) {
1857     NSNumber *aValue = internal[aKey];
1858     [outputStream writeInt32NoTag:tag];
1859     // Write the size of the message.
1860     uint32_t unwrappedKey = [aKey unsignedIntValue];
1861     uint64_t unwrappedValue = [aValue unsignedLongLongValue];
1862     size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
1863     msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
1864     [outputStream writeInt32NoTag:(int32_t)msgSize];
1865     // Write the fields.
1866     WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
1867     WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
1868   }
1871 - (void)setGPBGenericValue:(GPBGenericValue *)value
1872      forGPBGenericValueKey:(GPBGenericValue *)key {
1873   [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueUInt32)];
1876 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
1877   [self enumerateKeysAndUInt64sUsingBlock:^(uint32_t key, uint64_t value, __unused BOOL *stop) {
1878       block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%llu", value]);
1879   }];
1882 - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(uint32_t)key {
1883   NSNumber *wrapped = [_dictionary objectForKey:@(key)];
1884   if (wrapped && value) {
1885     *value = [wrapped unsignedLongLongValue];
1886   }
1887   return (wrapped != NULL);
1890 - (void)addEntriesFromDictionary:(GPBUInt32UInt64Dictionary *)otherDictionary {
1891   if (otherDictionary) {
1892     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
1893     if (_autocreator) {
1894       GPBAutocreatedDictionaryModified(_autocreator, self);
1895     }
1896   }
1899 - (void)setUInt64:(uint64_t)value forKey:(uint32_t)key {
1900   [_dictionary setObject:@(value) forKey:@(key)];
1901   if (_autocreator) {
1902     GPBAutocreatedDictionaryModified(_autocreator, self);
1903   }
1906 - (void)removeUInt64ForKey:(uint32_t)aKey {
1907   [_dictionary removeObjectForKey:@(aKey)];
1910 - (void)removeAll {
1911   [_dictionary removeAllObjects];
1914 @end
1916 #pragma mark - UInt32 -> Int64
1918 @implementation GPBUInt32Int64Dictionary {
1919  @package
1920   NSMutableDictionary *_dictionary;
1923 - (instancetype)init {
1924   return [self initWithInt64s:NULL forKeys:NULL count:0];
1927 - (instancetype)initWithInt64s:(const int64_t [])values
1928                        forKeys:(const uint32_t [])keys
1929                          count:(NSUInteger)count {
1930   self = [super init];
1931   if (self) {
1932     _dictionary = [[NSMutableDictionary alloc] init];
1933     if (count && values && keys) {
1934       for (NSUInteger i = 0; i < count; ++i) {
1935         [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
1936       }
1937     }
1938   }
1939   return self;
1942 - (instancetype)initWithDictionary:(GPBUInt32Int64Dictionary *)dictionary {
1943   self = [self initWithInt64s:NULL forKeys:NULL count:0];
1944   if (self) {
1945     if (dictionary) {
1946       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
1947     }
1948   }
1949   return self;
1952 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
1953   return [self initWithInt64s:NULL forKeys:NULL count:0];
1956 - (void)dealloc {
1957   NSAssert(!_autocreator,
1958            @"%@: Autocreator must be cleared before release, autocreator: %@",
1959            [self class], _autocreator);
1960   [_dictionary release];
1961   [super dealloc];
1964 - (instancetype)copyWithZone:(NSZone *)zone {
1965   return [[GPBUInt32Int64Dictionary allocWithZone:zone] initWithDictionary:self];
1968 - (BOOL)isEqual:(id)other {
1969   if (self == other) {
1970     return YES;
1971   }
1972   if (![other isKindOfClass:[GPBUInt32Int64Dictionary class]]) {
1973     return NO;
1974   }
1975   GPBUInt32Int64Dictionary *otherDictionary = other;
1976   return [_dictionary isEqual:otherDictionary->_dictionary];
1979 - (NSUInteger)hash {
1980   return _dictionary.count;
1983 - (NSString *)description {
1984   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
1987 - (NSUInteger)count {
1988   return _dictionary.count;
1991 - (void)enumerateKeysAndInt64sUsingBlock:
1992     (void (NS_NOESCAPE ^)(uint32_t key, int64_t value, BOOL *stop))block {
1993   BOOL stop = NO;
1994   NSDictionary *internal = _dictionary;
1995   NSEnumerator *keys = [internal keyEnumerator];
1996   NSNumber *aKey;
1997   while ((aKey = [keys nextObject])) {
1998     NSNumber *aValue = internal[aKey];
1999     block([aKey unsignedIntValue], [aValue longLongValue], &stop);
2000     if (stop) {
2001       break;
2002     }
2003   }
2006 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
2007   NSDictionary *internal = _dictionary;
2008   NSUInteger count = internal.count;
2009   if (count == 0) {
2010     return 0;
2011   }
2013   GPBDataType valueDataType = GPBGetFieldDataType(field);
2014   GPBDataType keyDataType = field.mapKeyDataType;
2015   size_t result = 0;
2016   NSEnumerator *keys = [internal keyEnumerator];
2017   NSNumber *aKey;
2018   while ((aKey = [keys nextObject])) {
2019     NSNumber *aValue = internal[aKey];
2020     size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
2021     msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
2022     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
2023   }
2024   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
2025   result += tagSize * count;
2026   return result;
2029 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
2030                          asField:(GPBFieldDescriptor *)field {
2031   GPBDataType valueDataType = GPBGetFieldDataType(field);
2032   GPBDataType keyDataType = field.mapKeyDataType;
2033   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
2034   NSDictionary *internal = _dictionary;
2035   NSEnumerator *keys = [internal keyEnumerator];
2036   NSNumber *aKey;
2037   while ((aKey = [keys nextObject])) {
2038     NSNumber *aValue = internal[aKey];
2039     [outputStream writeInt32NoTag:tag];
2040     // Write the size of the message.
2041     uint32_t unwrappedKey = [aKey unsignedIntValue];
2042     int64_t unwrappedValue = [aValue longLongValue];
2043     size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
2044     msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
2045     [outputStream writeInt32NoTag:(int32_t)msgSize];
2046     // Write the fields.
2047     WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
2048     WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
2049   }
2052 - (void)setGPBGenericValue:(GPBGenericValue *)value
2053      forGPBGenericValueKey:(GPBGenericValue *)key {
2054   [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueUInt32)];
2057 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
2058   [self enumerateKeysAndInt64sUsingBlock:^(uint32_t key, int64_t value, __unused BOOL *stop) {
2059       block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%lld", value]);
2060   }];
2063 - (BOOL)getInt64:(nullable int64_t *)value forKey:(uint32_t)key {
2064   NSNumber *wrapped = [_dictionary objectForKey:@(key)];
2065   if (wrapped && value) {
2066     *value = [wrapped longLongValue];
2067   }
2068   return (wrapped != NULL);
2071 - (void)addEntriesFromDictionary:(GPBUInt32Int64Dictionary *)otherDictionary {
2072   if (otherDictionary) {
2073     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
2074     if (_autocreator) {
2075       GPBAutocreatedDictionaryModified(_autocreator, self);
2076     }
2077   }
2080 - (void)setInt64:(int64_t)value forKey:(uint32_t)key {
2081   [_dictionary setObject:@(value) forKey:@(key)];
2082   if (_autocreator) {
2083     GPBAutocreatedDictionaryModified(_autocreator, self);
2084   }
2087 - (void)removeInt64ForKey:(uint32_t)aKey {
2088   [_dictionary removeObjectForKey:@(aKey)];
2091 - (void)removeAll {
2092   [_dictionary removeAllObjects];
2095 @end
2097 #pragma mark - UInt32 -> Bool
2099 @implementation GPBUInt32BoolDictionary {
2100  @package
2101   NSMutableDictionary *_dictionary;
2104 - (instancetype)init {
2105   return [self initWithBools:NULL forKeys:NULL count:0];
2108 - (instancetype)initWithBools:(const BOOL [])values
2109                       forKeys:(const uint32_t [])keys
2110                         count:(NSUInteger)count {
2111   self = [super init];
2112   if (self) {
2113     _dictionary = [[NSMutableDictionary alloc] init];
2114     if (count && values && keys) {
2115       for (NSUInteger i = 0; i < count; ++i) {
2116         [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
2117       }
2118     }
2119   }
2120   return self;
2123 - (instancetype)initWithDictionary:(GPBUInt32BoolDictionary *)dictionary {
2124   self = [self initWithBools:NULL forKeys:NULL count:0];
2125   if (self) {
2126     if (dictionary) {
2127       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
2128     }
2129   }
2130   return self;
2133 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
2134   return [self initWithBools:NULL forKeys:NULL count:0];
2137 - (void)dealloc {
2138   NSAssert(!_autocreator,
2139            @"%@: Autocreator must be cleared before release, autocreator: %@",
2140            [self class], _autocreator);
2141   [_dictionary release];
2142   [super dealloc];
2145 - (instancetype)copyWithZone:(NSZone *)zone {
2146   return [[GPBUInt32BoolDictionary allocWithZone:zone] initWithDictionary:self];
2149 - (BOOL)isEqual:(id)other {
2150   if (self == other) {
2151     return YES;
2152   }
2153   if (![other isKindOfClass:[GPBUInt32BoolDictionary class]]) {
2154     return NO;
2155   }
2156   GPBUInt32BoolDictionary *otherDictionary = other;
2157   return [_dictionary isEqual:otherDictionary->_dictionary];
2160 - (NSUInteger)hash {
2161   return _dictionary.count;
2164 - (NSString *)description {
2165   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
2168 - (NSUInteger)count {
2169   return _dictionary.count;
2172 - (void)enumerateKeysAndBoolsUsingBlock:
2173     (void (NS_NOESCAPE ^)(uint32_t key, BOOL value, BOOL *stop))block {
2174   BOOL stop = NO;
2175   NSDictionary *internal = _dictionary;
2176   NSEnumerator *keys = [internal keyEnumerator];
2177   NSNumber *aKey;
2178   while ((aKey = [keys nextObject])) {
2179     NSNumber *aValue = internal[aKey];
2180     block([aKey unsignedIntValue], [aValue boolValue], &stop);
2181     if (stop) {
2182       break;
2183     }
2184   }
2187 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
2188   NSDictionary *internal = _dictionary;
2189   NSUInteger count = internal.count;
2190   if (count == 0) {
2191     return 0;
2192   }
2194   GPBDataType valueDataType = GPBGetFieldDataType(field);
2195   GPBDataType keyDataType = field.mapKeyDataType;
2196   size_t result = 0;
2197   NSEnumerator *keys = [internal keyEnumerator];
2198   NSNumber *aKey;
2199   while ((aKey = [keys nextObject])) {
2200     NSNumber *aValue = internal[aKey];
2201     size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
2202     msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
2203     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
2204   }
2205   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
2206   result += tagSize * count;
2207   return result;
2210 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
2211                          asField:(GPBFieldDescriptor *)field {
2212   GPBDataType valueDataType = GPBGetFieldDataType(field);
2213   GPBDataType keyDataType = field.mapKeyDataType;
2214   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
2215   NSDictionary *internal = _dictionary;
2216   NSEnumerator *keys = [internal keyEnumerator];
2217   NSNumber *aKey;
2218   while ((aKey = [keys nextObject])) {
2219     NSNumber *aValue = internal[aKey];
2220     [outputStream writeInt32NoTag:tag];
2221     // Write the size of the message.
2222     uint32_t unwrappedKey = [aKey unsignedIntValue];
2223     BOOL unwrappedValue = [aValue boolValue];
2224     size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
2225     msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
2226     [outputStream writeInt32NoTag:(int32_t)msgSize];
2227     // Write the fields.
2228     WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
2229     WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
2230   }
2233 - (void)setGPBGenericValue:(GPBGenericValue *)value
2234      forGPBGenericValueKey:(GPBGenericValue *)key {
2235   [_dictionary setObject:@(value->valueBool) forKey:@(key->valueUInt32)];
2238 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
2239   [self enumerateKeysAndBoolsUsingBlock:^(uint32_t key, BOOL value, __unused BOOL *stop) {
2240       block([NSString stringWithFormat:@"%u", key], (value ? @"true" : @"false"));
2241   }];
2244 - (BOOL)getBool:(nullable BOOL *)value forKey:(uint32_t)key {
2245   NSNumber *wrapped = [_dictionary objectForKey:@(key)];
2246   if (wrapped && value) {
2247     *value = [wrapped boolValue];
2248   }
2249   return (wrapped != NULL);
2252 - (void)addEntriesFromDictionary:(GPBUInt32BoolDictionary *)otherDictionary {
2253   if (otherDictionary) {
2254     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
2255     if (_autocreator) {
2256       GPBAutocreatedDictionaryModified(_autocreator, self);
2257     }
2258   }
2261 - (void)setBool:(BOOL)value forKey:(uint32_t)key {
2262   [_dictionary setObject:@(value) forKey:@(key)];
2263   if (_autocreator) {
2264     GPBAutocreatedDictionaryModified(_autocreator, self);
2265   }
2268 - (void)removeBoolForKey:(uint32_t)aKey {
2269   [_dictionary removeObjectForKey:@(aKey)];
2272 - (void)removeAll {
2273   [_dictionary removeAllObjects];
2276 @end
2278 #pragma mark - UInt32 -> Float
2280 @implementation GPBUInt32FloatDictionary {
2281  @package
2282   NSMutableDictionary *_dictionary;
2285 - (instancetype)init {
2286   return [self initWithFloats:NULL forKeys:NULL count:0];
2289 - (instancetype)initWithFloats:(const float [])values
2290                        forKeys:(const uint32_t [])keys
2291                          count:(NSUInteger)count {
2292   self = [super init];
2293   if (self) {
2294     _dictionary = [[NSMutableDictionary alloc] init];
2295     if (count && values && keys) {
2296       for (NSUInteger i = 0; i < count; ++i) {
2297         [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
2298       }
2299     }
2300   }
2301   return self;
2304 - (instancetype)initWithDictionary:(GPBUInt32FloatDictionary *)dictionary {
2305   self = [self initWithFloats:NULL forKeys:NULL count:0];
2306   if (self) {
2307     if (dictionary) {
2308       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
2309     }
2310   }
2311   return self;
2314 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
2315   return [self initWithFloats:NULL forKeys:NULL count:0];
2318 - (void)dealloc {
2319   NSAssert(!_autocreator,
2320            @"%@: Autocreator must be cleared before release, autocreator: %@",
2321            [self class], _autocreator);
2322   [_dictionary release];
2323   [super dealloc];
2326 - (instancetype)copyWithZone:(NSZone *)zone {
2327   return [[GPBUInt32FloatDictionary allocWithZone:zone] initWithDictionary:self];
2330 - (BOOL)isEqual:(id)other {
2331   if (self == other) {
2332     return YES;
2333   }
2334   if (![other isKindOfClass:[GPBUInt32FloatDictionary class]]) {
2335     return NO;
2336   }
2337   GPBUInt32FloatDictionary *otherDictionary = other;
2338   return [_dictionary isEqual:otherDictionary->_dictionary];
2341 - (NSUInteger)hash {
2342   return _dictionary.count;
2345 - (NSString *)description {
2346   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
2349 - (NSUInteger)count {
2350   return _dictionary.count;
2353 - (void)enumerateKeysAndFloatsUsingBlock:
2354     (void (NS_NOESCAPE ^)(uint32_t key, float value, BOOL *stop))block {
2355   BOOL stop = NO;
2356   NSDictionary *internal = _dictionary;
2357   NSEnumerator *keys = [internal keyEnumerator];
2358   NSNumber *aKey;
2359   while ((aKey = [keys nextObject])) {
2360     NSNumber *aValue = internal[aKey];
2361     block([aKey unsignedIntValue], [aValue floatValue], &stop);
2362     if (stop) {
2363       break;
2364     }
2365   }
2368 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
2369   NSDictionary *internal = _dictionary;
2370   NSUInteger count = internal.count;
2371   if (count == 0) {
2372     return 0;
2373   }
2375   GPBDataType valueDataType = GPBGetFieldDataType(field);
2376   GPBDataType keyDataType = field.mapKeyDataType;
2377   size_t result = 0;
2378   NSEnumerator *keys = [internal keyEnumerator];
2379   NSNumber *aKey;
2380   while ((aKey = [keys nextObject])) {
2381     NSNumber *aValue = internal[aKey];
2382     size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
2383     msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
2384     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
2385   }
2386   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
2387   result += tagSize * count;
2388   return result;
2391 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
2392                          asField:(GPBFieldDescriptor *)field {
2393   GPBDataType valueDataType = GPBGetFieldDataType(field);
2394   GPBDataType keyDataType = field.mapKeyDataType;
2395   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
2396   NSDictionary *internal = _dictionary;
2397   NSEnumerator *keys = [internal keyEnumerator];
2398   NSNumber *aKey;
2399   while ((aKey = [keys nextObject])) {
2400     NSNumber *aValue = internal[aKey];
2401     [outputStream writeInt32NoTag:tag];
2402     // Write the size of the message.
2403     uint32_t unwrappedKey = [aKey unsignedIntValue];
2404     float unwrappedValue = [aValue floatValue];
2405     size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
2406     msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
2407     [outputStream writeInt32NoTag:(int32_t)msgSize];
2408     // Write the fields.
2409     WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
2410     WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
2411   }
2414 - (void)setGPBGenericValue:(GPBGenericValue *)value
2415      forGPBGenericValueKey:(GPBGenericValue *)key {
2416   [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueUInt32)];
2419 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
2420   [self enumerateKeysAndFloatsUsingBlock:^(uint32_t key, float value, __unused BOOL *stop) {
2421       block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
2422   }];
2425 - (BOOL)getFloat:(nullable float *)value forKey:(uint32_t)key {
2426   NSNumber *wrapped = [_dictionary objectForKey:@(key)];
2427   if (wrapped && value) {
2428     *value = [wrapped floatValue];
2429   }
2430   return (wrapped != NULL);
2433 - (void)addEntriesFromDictionary:(GPBUInt32FloatDictionary *)otherDictionary {
2434   if (otherDictionary) {
2435     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
2436     if (_autocreator) {
2437       GPBAutocreatedDictionaryModified(_autocreator, self);
2438     }
2439   }
2442 - (void)setFloat:(float)value forKey:(uint32_t)key {
2443   [_dictionary setObject:@(value) forKey:@(key)];
2444   if (_autocreator) {
2445     GPBAutocreatedDictionaryModified(_autocreator, self);
2446   }
2449 - (void)removeFloatForKey:(uint32_t)aKey {
2450   [_dictionary removeObjectForKey:@(aKey)];
2453 - (void)removeAll {
2454   [_dictionary removeAllObjects];
2457 @end
2459 #pragma mark - UInt32 -> Double
2461 @implementation GPBUInt32DoubleDictionary {
2462  @package
2463   NSMutableDictionary *_dictionary;
2466 - (instancetype)init {
2467   return [self initWithDoubles:NULL forKeys:NULL count:0];
2470 - (instancetype)initWithDoubles:(const double [])values
2471                         forKeys:(const uint32_t [])keys
2472                           count:(NSUInteger)count {
2473   self = [super init];
2474   if (self) {
2475     _dictionary = [[NSMutableDictionary alloc] init];
2476     if (count && values && keys) {
2477       for (NSUInteger i = 0; i < count; ++i) {
2478         [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
2479       }
2480     }
2481   }
2482   return self;
2485 - (instancetype)initWithDictionary:(GPBUInt32DoubleDictionary *)dictionary {
2486   self = [self initWithDoubles:NULL forKeys:NULL count:0];
2487   if (self) {
2488     if (dictionary) {
2489       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
2490     }
2491   }
2492   return self;
2495 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
2496   return [self initWithDoubles:NULL forKeys:NULL count:0];
2499 - (void)dealloc {
2500   NSAssert(!_autocreator,
2501            @"%@: Autocreator must be cleared before release, autocreator: %@",
2502            [self class], _autocreator);
2503   [_dictionary release];
2504   [super dealloc];
2507 - (instancetype)copyWithZone:(NSZone *)zone {
2508   return [[GPBUInt32DoubleDictionary allocWithZone:zone] initWithDictionary:self];
2511 - (BOOL)isEqual:(id)other {
2512   if (self == other) {
2513     return YES;
2514   }
2515   if (![other isKindOfClass:[GPBUInt32DoubleDictionary class]]) {
2516     return NO;
2517   }
2518   GPBUInt32DoubleDictionary *otherDictionary = other;
2519   return [_dictionary isEqual:otherDictionary->_dictionary];
2522 - (NSUInteger)hash {
2523   return _dictionary.count;
2526 - (NSString *)description {
2527   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
2530 - (NSUInteger)count {
2531   return _dictionary.count;
2534 - (void)enumerateKeysAndDoublesUsingBlock:
2535     (void (NS_NOESCAPE ^)(uint32_t key, double value, BOOL *stop))block {
2536   BOOL stop = NO;
2537   NSDictionary *internal = _dictionary;
2538   NSEnumerator *keys = [internal keyEnumerator];
2539   NSNumber *aKey;
2540   while ((aKey = [keys nextObject])) {
2541     NSNumber *aValue = internal[aKey];
2542     block([aKey unsignedIntValue], [aValue doubleValue], &stop);
2543     if (stop) {
2544       break;
2545     }
2546   }
2549 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
2550   NSDictionary *internal = _dictionary;
2551   NSUInteger count = internal.count;
2552   if (count == 0) {
2553     return 0;
2554   }
2556   GPBDataType valueDataType = GPBGetFieldDataType(field);
2557   GPBDataType keyDataType = field.mapKeyDataType;
2558   size_t result = 0;
2559   NSEnumerator *keys = [internal keyEnumerator];
2560   NSNumber *aKey;
2561   while ((aKey = [keys nextObject])) {
2562     NSNumber *aValue = internal[aKey];
2563     size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
2564     msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
2565     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
2566   }
2567   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
2568   result += tagSize * count;
2569   return result;
2572 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
2573                          asField:(GPBFieldDescriptor *)field {
2574   GPBDataType valueDataType = GPBGetFieldDataType(field);
2575   GPBDataType keyDataType = field.mapKeyDataType;
2576   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
2577   NSDictionary *internal = _dictionary;
2578   NSEnumerator *keys = [internal keyEnumerator];
2579   NSNumber *aKey;
2580   while ((aKey = [keys nextObject])) {
2581     NSNumber *aValue = internal[aKey];
2582     [outputStream writeInt32NoTag:tag];
2583     // Write the size of the message.
2584     uint32_t unwrappedKey = [aKey unsignedIntValue];
2585     double unwrappedValue = [aValue doubleValue];
2586     size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
2587     msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
2588     [outputStream writeInt32NoTag:(int32_t)msgSize];
2589     // Write the fields.
2590     WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
2591     WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
2592   }
2595 - (void)setGPBGenericValue:(GPBGenericValue *)value
2596      forGPBGenericValueKey:(GPBGenericValue *)key {
2597   [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueUInt32)];
2600 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
2601   [self enumerateKeysAndDoublesUsingBlock:^(uint32_t key, double value, __unused BOOL *stop) {
2602       block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
2603   }];
2606 - (BOOL)getDouble:(nullable double *)value forKey:(uint32_t)key {
2607   NSNumber *wrapped = [_dictionary objectForKey:@(key)];
2608   if (wrapped && value) {
2609     *value = [wrapped doubleValue];
2610   }
2611   return (wrapped != NULL);
2614 - (void)addEntriesFromDictionary:(GPBUInt32DoubleDictionary *)otherDictionary {
2615   if (otherDictionary) {
2616     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
2617     if (_autocreator) {
2618       GPBAutocreatedDictionaryModified(_autocreator, self);
2619     }
2620   }
2623 - (void)setDouble:(double)value forKey:(uint32_t)key {
2624   [_dictionary setObject:@(value) forKey:@(key)];
2625   if (_autocreator) {
2626     GPBAutocreatedDictionaryModified(_autocreator, self);
2627   }
2630 - (void)removeDoubleForKey:(uint32_t)aKey {
2631   [_dictionary removeObjectForKey:@(aKey)];
2634 - (void)removeAll {
2635   [_dictionary removeAllObjects];
2638 @end
2640 #pragma mark - UInt32 -> Enum
2642 @implementation GPBUInt32EnumDictionary {
2643  @package
2644   NSMutableDictionary *_dictionary;
2645   GPBEnumValidationFunc _validationFunc;
2648 @synthesize validationFunc = _validationFunc;
2650 - (instancetype)init {
2651   return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
2654 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
2655   return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
2658 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
2659                                  rawValues:(const int32_t [])rawValues
2660                                    forKeys:(const uint32_t [])keys
2661                                      count:(NSUInteger)count {
2662   self = [super init];
2663   if (self) {
2664     _dictionary = [[NSMutableDictionary alloc] init];
2665     _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
2666     if (count && rawValues && keys) {
2667       for (NSUInteger i = 0; i < count; ++i) {
2668         [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])];
2669       }
2670     }
2671   }
2672   return self;
2675 - (instancetype)initWithDictionary:(GPBUInt32EnumDictionary *)dictionary {
2676   self = [self initWithValidationFunction:dictionary.validationFunc
2677                                 rawValues:NULL
2678                                   forKeys:NULL
2679                                     count:0];
2680   if (self) {
2681     if (dictionary) {
2682       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
2683     }
2684   }
2685   return self;
2688 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
2689                                   capacity:(__unused NSUInteger)numItems {
2690   return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
2693 - (void)dealloc {
2694   NSAssert(!_autocreator,
2695            @"%@: Autocreator must be cleared before release, autocreator: %@",
2696            [self class], _autocreator);
2697   [_dictionary release];
2698   [super dealloc];
2701 - (instancetype)copyWithZone:(NSZone *)zone {
2702   return [[GPBUInt32EnumDictionary allocWithZone:zone] initWithDictionary:self];
2705 - (BOOL)isEqual:(id)other {
2706   if (self == other) {
2707     return YES;
2708   }
2709   if (![other isKindOfClass:[GPBUInt32EnumDictionary class]]) {
2710     return NO;
2711   }
2712   GPBUInt32EnumDictionary *otherDictionary = other;
2713   return [_dictionary isEqual:otherDictionary->_dictionary];
2716 - (NSUInteger)hash {
2717   return _dictionary.count;
2720 - (NSString *)description {
2721   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
2724 - (NSUInteger)count {
2725   return _dictionary.count;
2728 - (void)enumerateKeysAndRawValuesUsingBlock:
2729     (void (NS_NOESCAPE ^)(uint32_t key, int32_t value, BOOL *stop))block {
2730   BOOL stop = NO;
2731   NSDictionary *internal = _dictionary;
2732   NSEnumerator *keys = [internal keyEnumerator];
2733   NSNumber *aKey;
2734   while ((aKey = [keys nextObject])) {
2735     NSNumber *aValue = internal[aKey];
2736     block([aKey unsignedIntValue], [aValue intValue], &stop);
2737     if (stop) {
2738       break;
2739     }
2740   }
2743 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
2744   NSDictionary *internal = _dictionary;
2745   NSUInteger count = internal.count;
2746   if (count == 0) {
2747     return 0;
2748   }
2750   GPBDataType valueDataType = GPBGetFieldDataType(field);
2751   GPBDataType keyDataType = field.mapKeyDataType;
2752   size_t result = 0;
2753   NSEnumerator *keys = [internal keyEnumerator];
2754   NSNumber *aKey;
2755   while ((aKey = [keys nextObject])) {
2756     NSNumber *aValue = internal[aKey];
2757     size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
2758     msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
2759     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
2760   }
2761   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
2762   result += tagSize * count;
2763   return result;
2766 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
2767                          asField:(GPBFieldDescriptor *)field {
2768   GPBDataType valueDataType = GPBGetFieldDataType(field);
2769   GPBDataType keyDataType = field.mapKeyDataType;
2770   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
2771   NSDictionary *internal = _dictionary;
2772   NSEnumerator *keys = [internal keyEnumerator];
2773   NSNumber *aKey;
2774   while ((aKey = [keys nextObject])) {
2775     NSNumber *aValue = internal[aKey];
2776     [outputStream writeInt32NoTag:tag];
2777     // Write the size of the message.
2778     uint32_t unwrappedKey = [aKey unsignedIntValue];
2779     int32_t unwrappedValue = [aValue intValue];
2780     size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
2781     msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
2782     [outputStream writeInt32NoTag:(int32_t)msgSize];
2783     // Write the fields.
2784     WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
2785     WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
2786   }
2789 - (NSData *)serializedDataForUnknownValue:(int32_t)value
2790                                    forKey:(GPBGenericValue *)key
2791                               keyDataType:(GPBDataType)keyDataType {
2792   size_t msgSize = ComputeDictUInt32FieldSize(key->valueUInt32, kMapKeyFieldNumber, keyDataType);
2793   msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
2794   NSMutableData *data = [NSMutableData dataWithLength:msgSize];
2795   GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
2796   WriteDictUInt32Field(outputStream, key->valueUInt32, kMapKeyFieldNumber, keyDataType);
2797   WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
2798   [outputStream flush];
2799   [outputStream release];
2800   return data;
2802 - (void)setGPBGenericValue:(GPBGenericValue *)value
2803      forGPBGenericValueKey:(GPBGenericValue *)key {
2804   [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueUInt32)];
2807 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
2808   [self enumerateKeysAndRawValuesUsingBlock:^(uint32_t key, int32_t value, __unused BOOL *stop) {
2809       block([NSString stringWithFormat:@"%u", key], @(value));
2810   }];
2813 - (BOOL)getEnum:(int32_t *)value forKey:(uint32_t)key {
2814   NSNumber *wrapped = [_dictionary objectForKey:@(key)];
2815   if (wrapped && value) {
2816     int32_t result = [wrapped intValue];
2817     if (!_validationFunc(result)) {
2818       result = kGPBUnrecognizedEnumeratorValue;
2819     }
2820     *value = result;
2821   }
2822   return (wrapped != NULL);
2825 - (BOOL)getRawValue:(int32_t *)rawValue forKey:(uint32_t)key {
2826   NSNumber *wrapped = [_dictionary objectForKey:@(key)];
2827   if (wrapped && rawValue) {
2828     *rawValue = [wrapped intValue];
2829   }
2830   return (wrapped != NULL);
2833 - (void)enumerateKeysAndEnumsUsingBlock:
2834     (void (NS_NOESCAPE ^)(uint32_t key, int32_t value, BOOL *stop))block {
2835   GPBEnumValidationFunc func = _validationFunc;
2836   BOOL stop = NO;
2837   NSEnumerator *keys = [_dictionary keyEnumerator];
2838   NSNumber *aKey;
2839   while ((aKey = [keys nextObject])) {
2840     NSNumber *aValue = _dictionary[aKey];
2841       int32_t unwrapped = [aValue intValue];
2842       if (!func(unwrapped)) {
2843         unwrapped = kGPBUnrecognizedEnumeratorValue;
2844       }
2845     block([aKey unsignedIntValue], unwrapped, &stop);
2846     if (stop) {
2847       break;
2848     }
2849   }
2852 - (void)addRawEntriesFromDictionary:(GPBUInt32EnumDictionary *)otherDictionary {
2853   if (otherDictionary) {
2854     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
2855     if (_autocreator) {
2856       GPBAutocreatedDictionaryModified(_autocreator, self);
2857     }
2858   }
2861 - (void)setRawValue:(int32_t)value forKey:(uint32_t)key {
2862   [_dictionary setObject:@(value) forKey:@(key)];
2863   if (_autocreator) {
2864     GPBAutocreatedDictionaryModified(_autocreator, self);
2865   }
2868 - (void)removeEnumForKey:(uint32_t)aKey {
2869   [_dictionary removeObjectForKey:@(aKey)];
2872 - (void)removeAll {
2873   [_dictionary removeAllObjects];
2876 - (void)setEnum:(int32_t)value forKey:(uint32_t)key {
2877   if (!_validationFunc(value)) {
2878     [NSException raise:NSInvalidArgumentException
2879                 format:@"GPBUInt32EnumDictionary: Attempt to set an unknown enum value (%d)",
2880                        value];
2881   }
2883   [_dictionary setObject:@(value) forKey:@(key)];
2884   if (_autocreator) {
2885     GPBAutocreatedDictionaryModified(_autocreator, self);
2886   }
2889 @end
2891 #pragma mark - UInt32 -> Object
2893 @implementation GPBUInt32ObjectDictionary {
2894  @package
2895   NSMutableDictionary *_dictionary;
2898 - (instancetype)init {
2899   return [self initWithObjects:NULL forKeys:NULL count:0];
2902 - (instancetype)initWithObjects:(const id [])objects
2903                         forKeys:(const uint32_t [])keys
2904                           count:(NSUInteger)count {
2905   self = [super init];
2906   if (self) {
2907     _dictionary = [[NSMutableDictionary alloc] init];
2908     if (count && objects && keys) {
2909       for (NSUInteger i = 0; i < count; ++i) {
2910         if (!objects[i]) {
2911           [NSException raise:NSInvalidArgumentException
2912                       format:@"Attempting to add nil object to a Dictionary"];
2913         }
2914         [_dictionary setObject:objects[i] forKey:@(keys[i])];
2915       }
2916     }
2917   }
2918   return self;
2921 - (instancetype)initWithDictionary:(GPBUInt32ObjectDictionary *)dictionary {
2922   self = [self initWithObjects:NULL forKeys:NULL count:0];
2923   if (self) {
2924     if (dictionary) {
2925       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
2926     }
2927   }
2928   return self;
2931 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
2932   return [self initWithObjects:NULL forKeys:NULL count:0];
2935 - (void)dealloc {
2936   NSAssert(!_autocreator,
2937            @"%@: Autocreator must be cleared before release, autocreator: %@",
2938            [self class], _autocreator);
2939   [_dictionary release];
2940   [super dealloc];
2943 - (instancetype)copyWithZone:(NSZone *)zone {
2944   return [[GPBUInt32ObjectDictionary allocWithZone:zone] initWithDictionary:self];
2947 - (BOOL)isEqual:(id)other {
2948   if (self == other) {
2949     return YES;
2950   }
2951   if (![other isKindOfClass:[GPBUInt32ObjectDictionary class]]) {
2952     return NO;
2953   }
2954   GPBUInt32ObjectDictionary *otherDictionary = other;
2955   return [_dictionary isEqual:otherDictionary->_dictionary];
2958 - (NSUInteger)hash {
2959   return _dictionary.count;
2962 - (NSString *)description {
2963   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
2966 - (NSUInteger)count {
2967   return _dictionary.count;
2970 - (void)enumerateKeysAndObjectsUsingBlock:
2971     (void (NS_NOESCAPE ^)(uint32_t key, id object, BOOL *stop))block {
2972   BOOL stop = NO;
2973   NSDictionary *internal = _dictionary;
2974   NSEnumerator *keys = [internal keyEnumerator];
2975   NSNumber *aKey;
2976   while ((aKey = [keys nextObject])) {
2977     id aObject = internal[aKey];
2978     block([aKey unsignedIntValue], aObject, &stop);
2979     if (stop) {
2980       break;
2981     }
2982   }
2985 - (BOOL)isInitialized {
2986   for (GPBMessage *msg in [_dictionary objectEnumerator]) {
2987     if (!msg.initialized) {
2988       return NO;
2989     }
2990   }
2991   return YES;
2994 - (instancetype)deepCopyWithZone:(NSZone *)zone {
2995   GPBUInt32ObjectDictionary *newDict =
2996       [[GPBUInt32ObjectDictionary alloc] init];
2997   NSEnumerator *keys = [_dictionary keyEnumerator];
2998   id aKey;
2999   NSMutableDictionary *internalDict = newDict->_dictionary;
3000   while ((aKey = [keys nextObject])) {
3001     GPBMessage *msg = _dictionary[aKey];
3002     GPBMessage *copiedMsg = [msg copyWithZone:zone];
3003     [internalDict setObject:copiedMsg forKey:aKey];
3004     [copiedMsg release];
3005   }
3006   return newDict;
3009 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
3010   NSDictionary *internal = _dictionary;
3011   NSUInteger count = internal.count;
3012   if (count == 0) {
3013     return 0;
3014   }
3016   GPBDataType valueDataType = GPBGetFieldDataType(field);
3017   GPBDataType keyDataType = field.mapKeyDataType;
3018   size_t result = 0;
3019   NSEnumerator *keys = [internal keyEnumerator];
3020   NSNumber *aKey;
3021   while ((aKey = [keys nextObject])) {
3022     id aObject = internal[aKey];
3023     size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
3024     msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
3025     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
3026   }
3027   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
3028   result += tagSize * count;
3029   return result;
3032 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
3033                          asField:(GPBFieldDescriptor *)field {
3034   GPBDataType valueDataType = GPBGetFieldDataType(field);
3035   GPBDataType keyDataType = field.mapKeyDataType;
3036   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
3037   NSDictionary *internal = _dictionary;
3038   NSEnumerator *keys = [internal keyEnumerator];
3039   NSNumber *aKey;
3040   while ((aKey = [keys nextObject])) {
3041     id aObject = internal[aKey];
3042     [outputStream writeInt32NoTag:tag];
3043     // Write the size of the message.
3044     uint32_t unwrappedKey = [aKey unsignedIntValue];
3045     id unwrappedValue = aObject;
3046     size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
3047     msgSize += ComputeDictObjectFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
3048     [outputStream writeInt32NoTag:(int32_t)msgSize];
3049     // Write the fields.
3050     WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
3051     WriteDictObjectField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
3052   }
3055 - (void)setGPBGenericValue:(GPBGenericValue *)value
3056      forGPBGenericValueKey:(GPBGenericValue *)key {
3057   [_dictionary setObject:value->valueString forKey:@(key->valueUInt32)];
3060 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
3061   [self enumerateKeysAndObjectsUsingBlock:^(uint32_t key, id object, __unused BOOL *stop) {
3062       block([NSString stringWithFormat:@"%u", key], object);
3063   }];
3066 - (id)objectForKey:(uint32_t)key {
3067   id result = [_dictionary objectForKey:@(key)];
3068   return result;
3071 - (void)addEntriesFromDictionary:(GPBUInt32ObjectDictionary *)otherDictionary {
3072   if (otherDictionary) {
3073     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
3074     if (_autocreator) {
3075       GPBAutocreatedDictionaryModified(_autocreator, self);
3076     }
3077   }
3080 - (void)setObject:(id)object forKey:(uint32_t)key {
3081   if (!object) {
3082     [NSException raise:NSInvalidArgumentException
3083                 format:@"Attempting to add nil object to a Dictionary"];
3084   }
3085   [_dictionary setObject:object forKey:@(key)];
3086   if (_autocreator) {
3087     GPBAutocreatedDictionaryModified(_autocreator, self);
3088   }
3091 - (void)removeObjectForKey:(uint32_t)aKey {
3092   [_dictionary removeObjectForKey:@(aKey)];
3095 - (void)removeAll {
3096   [_dictionary removeAllObjects];
3099 @end
3101 //%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(Int32, int32_t)
3102 // This block of code is generated, do not edit it directly.
3104 #pragma mark - Int32 -> UInt32
3106 @implementation GPBInt32UInt32Dictionary {
3107  @package
3108   NSMutableDictionary *_dictionary;
3111 - (instancetype)init {
3112   return [self initWithUInt32s:NULL forKeys:NULL count:0];
3115 - (instancetype)initWithUInt32s:(const uint32_t [])values
3116                         forKeys:(const int32_t [])keys
3117                           count:(NSUInteger)count {
3118   self = [super init];
3119   if (self) {
3120     _dictionary = [[NSMutableDictionary alloc] init];
3121     if (count && values && keys) {
3122       for (NSUInteger i = 0; i < count; ++i) {
3123         [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
3124       }
3125     }
3126   }
3127   return self;
3130 - (instancetype)initWithDictionary:(GPBInt32UInt32Dictionary *)dictionary {
3131   self = [self initWithUInt32s:NULL forKeys:NULL count:0];
3132   if (self) {
3133     if (dictionary) {
3134       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
3135     }
3136   }
3137   return self;
3140 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
3141   return [self initWithUInt32s:NULL forKeys:NULL count:0];
3144 - (void)dealloc {
3145   NSAssert(!_autocreator,
3146            @"%@: Autocreator must be cleared before release, autocreator: %@",
3147            [self class], _autocreator);
3148   [_dictionary release];
3149   [super dealloc];
3152 - (instancetype)copyWithZone:(NSZone *)zone {
3153   return [[GPBInt32UInt32Dictionary allocWithZone:zone] initWithDictionary:self];
3156 - (BOOL)isEqual:(id)other {
3157   if (self == other) {
3158     return YES;
3159   }
3160   if (![other isKindOfClass:[GPBInt32UInt32Dictionary class]]) {
3161     return NO;
3162   }
3163   GPBInt32UInt32Dictionary *otherDictionary = other;
3164   return [_dictionary isEqual:otherDictionary->_dictionary];
3167 - (NSUInteger)hash {
3168   return _dictionary.count;
3171 - (NSString *)description {
3172   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
3175 - (NSUInteger)count {
3176   return _dictionary.count;
3179 - (void)enumerateKeysAndUInt32sUsingBlock:
3180     (void (NS_NOESCAPE ^)(int32_t key, uint32_t value, BOOL *stop))block {
3181   BOOL stop = NO;
3182   NSDictionary *internal = _dictionary;
3183   NSEnumerator *keys = [internal keyEnumerator];
3184   NSNumber *aKey;
3185   while ((aKey = [keys nextObject])) {
3186     NSNumber *aValue = internal[aKey];
3187     block([aKey intValue], [aValue unsignedIntValue], &stop);
3188     if (stop) {
3189       break;
3190     }
3191   }
3194 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
3195   NSDictionary *internal = _dictionary;
3196   NSUInteger count = internal.count;
3197   if (count == 0) {
3198     return 0;
3199   }
3201   GPBDataType valueDataType = GPBGetFieldDataType(field);
3202   GPBDataType keyDataType = field.mapKeyDataType;
3203   size_t result = 0;
3204   NSEnumerator *keys = [internal keyEnumerator];
3205   NSNumber *aKey;
3206   while ((aKey = [keys nextObject])) {
3207     NSNumber *aValue = internal[aKey];
3208     size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
3209     msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
3210     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
3211   }
3212   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
3213   result += tagSize * count;
3214   return result;
3217 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
3218                          asField:(GPBFieldDescriptor *)field {
3219   GPBDataType valueDataType = GPBGetFieldDataType(field);
3220   GPBDataType keyDataType = field.mapKeyDataType;
3221   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
3222   NSDictionary *internal = _dictionary;
3223   NSEnumerator *keys = [internal keyEnumerator];
3224   NSNumber *aKey;
3225   while ((aKey = [keys nextObject])) {
3226     NSNumber *aValue = internal[aKey];
3227     [outputStream writeInt32NoTag:tag];
3228     // Write the size of the message.
3229     int32_t unwrappedKey = [aKey intValue];
3230     uint32_t unwrappedValue = [aValue unsignedIntValue];
3231     size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
3232     msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
3233     [outputStream writeInt32NoTag:(int32_t)msgSize];
3234     // Write the fields.
3235     WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
3236     WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
3237   }
3240 - (void)setGPBGenericValue:(GPBGenericValue *)value
3241      forGPBGenericValueKey:(GPBGenericValue *)key {
3242   [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueInt32)];
3245 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
3246   [self enumerateKeysAndUInt32sUsingBlock:^(int32_t key, uint32_t value, __unused BOOL *stop) {
3247       block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%u", value]);
3248   }];
3251 - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(int32_t)key {
3252   NSNumber *wrapped = [_dictionary objectForKey:@(key)];
3253   if (wrapped && value) {
3254     *value = [wrapped unsignedIntValue];
3255   }
3256   return (wrapped != NULL);
3259 - (void)addEntriesFromDictionary:(GPBInt32UInt32Dictionary *)otherDictionary {
3260   if (otherDictionary) {
3261     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
3262     if (_autocreator) {
3263       GPBAutocreatedDictionaryModified(_autocreator, self);
3264     }
3265   }
3268 - (void)setUInt32:(uint32_t)value forKey:(int32_t)key {
3269   [_dictionary setObject:@(value) forKey:@(key)];
3270   if (_autocreator) {
3271     GPBAutocreatedDictionaryModified(_autocreator, self);
3272   }
3275 - (void)removeUInt32ForKey:(int32_t)aKey {
3276   [_dictionary removeObjectForKey:@(aKey)];
3279 - (void)removeAll {
3280   [_dictionary removeAllObjects];
3283 @end
3285 #pragma mark - Int32 -> Int32
3287 @implementation GPBInt32Int32Dictionary {
3288  @package
3289   NSMutableDictionary *_dictionary;
3292 - (instancetype)init {
3293   return [self initWithInt32s:NULL forKeys:NULL count:0];
3296 - (instancetype)initWithInt32s:(const int32_t [])values
3297                        forKeys:(const int32_t [])keys
3298                          count:(NSUInteger)count {
3299   self = [super init];
3300   if (self) {
3301     _dictionary = [[NSMutableDictionary alloc] init];
3302     if (count && values && keys) {
3303       for (NSUInteger i = 0; i < count; ++i) {
3304         [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
3305       }
3306     }
3307   }
3308   return self;
3311 - (instancetype)initWithDictionary:(GPBInt32Int32Dictionary *)dictionary {
3312   self = [self initWithInt32s:NULL forKeys:NULL count:0];
3313   if (self) {
3314     if (dictionary) {
3315       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
3316     }
3317   }
3318   return self;
3321 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
3322   return [self initWithInt32s:NULL forKeys:NULL count:0];
3325 - (void)dealloc {
3326   NSAssert(!_autocreator,
3327            @"%@: Autocreator must be cleared before release, autocreator: %@",
3328            [self class], _autocreator);
3329   [_dictionary release];
3330   [super dealloc];
3333 - (instancetype)copyWithZone:(NSZone *)zone {
3334   return [[GPBInt32Int32Dictionary allocWithZone:zone] initWithDictionary:self];
3337 - (BOOL)isEqual:(id)other {
3338   if (self == other) {
3339     return YES;
3340   }
3341   if (![other isKindOfClass:[GPBInt32Int32Dictionary class]]) {
3342     return NO;
3343   }
3344   GPBInt32Int32Dictionary *otherDictionary = other;
3345   return [_dictionary isEqual:otherDictionary->_dictionary];
3348 - (NSUInteger)hash {
3349   return _dictionary.count;
3352 - (NSString *)description {
3353   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
3356 - (NSUInteger)count {
3357   return _dictionary.count;
3360 - (void)enumerateKeysAndInt32sUsingBlock:
3361     (void (NS_NOESCAPE ^)(int32_t key, int32_t value, BOOL *stop))block {
3362   BOOL stop = NO;
3363   NSDictionary *internal = _dictionary;
3364   NSEnumerator *keys = [internal keyEnumerator];
3365   NSNumber *aKey;
3366   while ((aKey = [keys nextObject])) {
3367     NSNumber *aValue = internal[aKey];
3368     block([aKey intValue], [aValue intValue], &stop);
3369     if (stop) {
3370       break;
3371     }
3372   }
3375 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
3376   NSDictionary *internal = _dictionary;
3377   NSUInteger count = internal.count;
3378   if (count == 0) {
3379     return 0;
3380   }
3382   GPBDataType valueDataType = GPBGetFieldDataType(field);
3383   GPBDataType keyDataType = field.mapKeyDataType;
3384   size_t result = 0;
3385   NSEnumerator *keys = [internal keyEnumerator];
3386   NSNumber *aKey;
3387   while ((aKey = [keys nextObject])) {
3388     NSNumber *aValue = internal[aKey];
3389     size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
3390     msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
3391     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
3392   }
3393   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
3394   result += tagSize * count;
3395   return result;
3398 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
3399                          asField:(GPBFieldDescriptor *)field {
3400   GPBDataType valueDataType = GPBGetFieldDataType(field);
3401   GPBDataType keyDataType = field.mapKeyDataType;
3402   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
3403   NSDictionary *internal = _dictionary;
3404   NSEnumerator *keys = [internal keyEnumerator];
3405   NSNumber *aKey;
3406   while ((aKey = [keys nextObject])) {
3407     NSNumber *aValue = internal[aKey];
3408     [outputStream writeInt32NoTag:tag];
3409     // Write the size of the message.
3410     int32_t unwrappedKey = [aKey intValue];
3411     int32_t unwrappedValue = [aValue intValue];
3412     size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
3413     msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
3414     [outputStream writeInt32NoTag:(int32_t)msgSize];
3415     // Write the fields.
3416     WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
3417     WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
3418   }
3421 - (void)setGPBGenericValue:(GPBGenericValue *)value
3422      forGPBGenericValueKey:(GPBGenericValue *)key {
3423   [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueInt32)];
3426 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
3427   [self enumerateKeysAndInt32sUsingBlock:^(int32_t key, int32_t value, __unused BOOL *stop) {
3428       block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%d", value]);
3429   }];
3432 - (BOOL)getInt32:(nullable int32_t *)value forKey:(int32_t)key {
3433   NSNumber *wrapped = [_dictionary objectForKey:@(key)];
3434   if (wrapped && value) {
3435     *value = [wrapped intValue];
3436   }
3437   return (wrapped != NULL);
3440 - (void)addEntriesFromDictionary:(GPBInt32Int32Dictionary *)otherDictionary {
3441   if (otherDictionary) {
3442     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
3443     if (_autocreator) {
3444       GPBAutocreatedDictionaryModified(_autocreator, self);
3445     }
3446   }
3449 - (void)setInt32:(int32_t)value forKey:(int32_t)key {
3450   [_dictionary setObject:@(value) forKey:@(key)];
3451   if (_autocreator) {
3452     GPBAutocreatedDictionaryModified(_autocreator, self);
3453   }
3456 - (void)removeInt32ForKey:(int32_t)aKey {
3457   [_dictionary removeObjectForKey:@(aKey)];
3460 - (void)removeAll {
3461   [_dictionary removeAllObjects];
3464 @end
3466 #pragma mark - Int32 -> UInt64
3468 @implementation GPBInt32UInt64Dictionary {
3469  @package
3470   NSMutableDictionary *_dictionary;
3473 - (instancetype)init {
3474   return [self initWithUInt64s:NULL forKeys:NULL count:0];
3477 - (instancetype)initWithUInt64s:(const uint64_t [])values
3478                         forKeys:(const int32_t [])keys
3479                           count:(NSUInteger)count {
3480   self = [super init];
3481   if (self) {
3482     _dictionary = [[NSMutableDictionary alloc] init];
3483     if (count && values && keys) {
3484       for (NSUInteger i = 0; i < count; ++i) {
3485         [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
3486       }
3487     }
3488   }
3489   return self;
3492 - (instancetype)initWithDictionary:(GPBInt32UInt64Dictionary *)dictionary {
3493   self = [self initWithUInt64s:NULL forKeys:NULL count:0];
3494   if (self) {
3495     if (dictionary) {
3496       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
3497     }
3498   }
3499   return self;
3502 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
3503   return [self initWithUInt64s:NULL forKeys:NULL count:0];
3506 - (void)dealloc {
3507   NSAssert(!_autocreator,
3508            @"%@: Autocreator must be cleared before release, autocreator: %@",
3509            [self class], _autocreator);
3510   [_dictionary release];
3511   [super dealloc];
3514 - (instancetype)copyWithZone:(NSZone *)zone {
3515   return [[GPBInt32UInt64Dictionary allocWithZone:zone] initWithDictionary:self];
3518 - (BOOL)isEqual:(id)other {
3519   if (self == other) {
3520     return YES;
3521   }
3522   if (![other isKindOfClass:[GPBInt32UInt64Dictionary class]]) {
3523     return NO;
3524   }
3525   GPBInt32UInt64Dictionary *otherDictionary = other;
3526   return [_dictionary isEqual:otherDictionary->_dictionary];
3529 - (NSUInteger)hash {
3530   return _dictionary.count;
3533 - (NSString *)description {
3534   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
3537 - (NSUInteger)count {
3538   return _dictionary.count;
3541 - (void)enumerateKeysAndUInt64sUsingBlock:
3542     (void (NS_NOESCAPE ^)(int32_t key, uint64_t value, BOOL *stop))block {
3543   BOOL stop = NO;
3544   NSDictionary *internal = _dictionary;
3545   NSEnumerator *keys = [internal keyEnumerator];
3546   NSNumber *aKey;
3547   while ((aKey = [keys nextObject])) {
3548     NSNumber *aValue = internal[aKey];
3549     block([aKey intValue], [aValue unsignedLongLongValue], &stop);
3550     if (stop) {
3551       break;
3552     }
3553   }
3556 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
3557   NSDictionary *internal = _dictionary;
3558   NSUInteger count = internal.count;
3559   if (count == 0) {
3560     return 0;
3561   }
3563   GPBDataType valueDataType = GPBGetFieldDataType(field);
3564   GPBDataType keyDataType = field.mapKeyDataType;
3565   size_t result = 0;
3566   NSEnumerator *keys = [internal keyEnumerator];
3567   NSNumber *aKey;
3568   while ((aKey = [keys nextObject])) {
3569     NSNumber *aValue = internal[aKey];
3570     size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
3571     msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
3572     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
3573   }
3574   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
3575   result += tagSize * count;
3576   return result;
3579 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
3580                          asField:(GPBFieldDescriptor *)field {
3581   GPBDataType valueDataType = GPBGetFieldDataType(field);
3582   GPBDataType keyDataType = field.mapKeyDataType;
3583   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
3584   NSDictionary *internal = _dictionary;
3585   NSEnumerator *keys = [internal keyEnumerator];
3586   NSNumber *aKey;
3587   while ((aKey = [keys nextObject])) {
3588     NSNumber *aValue = internal[aKey];
3589     [outputStream writeInt32NoTag:tag];
3590     // Write the size of the message.
3591     int32_t unwrappedKey = [aKey intValue];
3592     uint64_t unwrappedValue = [aValue unsignedLongLongValue];
3593     size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
3594     msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
3595     [outputStream writeInt32NoTag:(int32_t)msgSize];
3596     // Write the fields.
3597     WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
3598     WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
3599   }
3602 - (void)setGPBGenericValue:(GPBGenericValue *)value
3603      forGPBGenericValueKey:(GPBGenericValue *)key {
3604   [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueInt32)];
3607 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
3608   [self enumerateKeysAndUInt64sUsingBlock:^(int32_t key, uint64_t value, __unused BOOL *stop) {
3609       block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%llu", value]);
3610   }];
3613 - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(int32_t)key {
3614   NSNumber *wrapped = [_dictionary objectForKey:@(key)];
3615   if (wrapped && value) {
3616     *value = [wrapped unsignedLongLongValue];
3617   }
3618   return (wrapped != NULL);
3621 - (void)addEntriesFromDictionary:(GPBInt32UInt64Dictionary *)otherDictionary {
3622   if (otherDictionary) {
3623     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
3624     if (_autocreator) {
3625       GPBAutocreatedDictionaryModified(_autocreator, self);
3626     }
3627   }
3630 - (void)setUInt64:(uint64_t)value forKey:(int32_t)key {
3631   [_dictionary setObject:@(value) forKey:@(key)];
3632   if (_autocreator) {
3633     GPBAutocreatedDictionaryModified(_autocreator, self);
3634   }
3637 - (void)removeUInt64ForKey:(int32_t)aKey {
3638   [_dictionary removeObjectForKey:@(aKey)];
3641 - (void)removeAll {
3642   [_dictionary removeAllObjects];
3645 @end
3647 #pragma mark - Int32 -> Int64
3649 @implementation GPBInt32Int64Dictionary {
3650  @package
3651   NSMutableDictionary *_dictionary;
3654 - (instancetype)init {
3655   return [self initWithInt64s:NULL forKeys:NULL count:0];
3658 - (instancetype)initWithInt64s:(const int64_t [])values
3659                        forKeys:(const int32_t [])keys
3660                          count:(NSUInteger)count {
3661   self = [super init];
3662   if (self) {
3663     _dictionary = [[NSMutableDictionary alloc] init];
3664     if (count && values && keys) {
3665       for (NSUInteger i = 0; i < count; ++i) {
3666         [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
3667       }
3668     }
3669   }
3670   return self;
3673 - (instancetype)initWithDictionary:(GPBInt32Int64Dictionary *)dictionary {
3674   self = [self initWithInt64s:NULL forKeys:NULL count:0];
3675   if (self) {
3676     if (dictionary) {
3677       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
3678     }
3679   }
3680   return self;
3683 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
3684   return [self initWithInt64s:NULL forKeys:NULL count:0];
3687 - (void)dealloc {
3688   NSAssert(!_autocreator,
3689            @"%@: Autocreator must be cleared before release, autocreator: %@",
3690            [self class], _autocreator);
3691   [_dictionary release];
3692   [super dealloc];
3695 - (instancetype)copyWithZone:(NSZone *)zone {
3696   return [[GPBInt32Int64Dictionary allocWithZone:zone] initWithDictionary:self];
3699 - (BOOL)isEqual:(id)other {
3700   if (self == other) {
3701     return YES;
3702   }
3703   if (![other isKindOfClass:[GPBInt32Int64Dictionary class]]) {
3704     return NO;
3705   }
3706   GPBInt32Int64Dictionary *otherDictionary = other;
3707   return [_dictionary isEqual:otherDictionary->_dictionary];
3710 - (NSUInteger)hash {
3711   return _dictionary.count;
3714 - (NSString *)description {
3715   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
3718 - (NSUInteger)count {
3719   return _dictionary.count;
3722 - (void)enumerateKeysAndInt64sUsingBlock:
3723     (void (NS_NOESCAPE ^)(int32_t key, int64_t value, BOOL *stop))block {
3724   BOOL stop = NO;
3725   NSDictionary *internal = _dictionary;
3726   NSEnumerator *keys = [internal keyEnumerator];
3727   NSNumber *aKey;
3728   while ((aKey = [keys nextObject])) {
3729     NSNumber *aValue = internal[aKey];
3730     block([aKey intValue], [aValue longLongValue], &stop);
3731     if (stop) {
3732       break;
3733     }
3734   }
3737 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
3738   NSDictionary *internal = _dictionary;
3739   NSUInteger count = internal.count;
3740   if (count == 0) {
3741     return 0;
3742   }
3744   GPBDataType valueDataType = GPBGetFieldDataType(field);
3745   GPBDataType keyDataType = field.mapKeyDataType;
3746   size_t result = 0;
3747   NSEnumerator *keys = [internal keyEnumerator];
3748   NSNumber *aKey;
3749   while ((aKey = [keys nextObject])) {
3750     NSNumber *aValue = internal[aKey];
3751     size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
3752     msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
3753     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
3754   }
3755   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
3756   result += tagSize * count;
3757   return result;
3760 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
3761                          asField:(GPBFieldDescriptor *)field {
3762   GPBDataType valueDataType = GPBGetFieldDataType(field);
3763   GPBDataType keyDataType = field.mapKeyDataType;
3764   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
3765   NSDictionary *internal = _dictionary;
3766   NSEnumerator *keys = [internal keyEnumerator];
3767   NSNumber *aKey;
3768   while ((aKey = [keys nextObject])) {
3769     NSNumber *aValue = internal[aKey];
3770     [outputStream writeInt32NoTag:tag];
3771     // Write the size of the message.
3772     int32_t unwrappedKey = [aKey intValue];
3773     int64_t unwrappedValue = [aValue longLongValue];
3774     size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
3775     msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
3776     [outputStream writeInt32NoTag:(int32_t)msgSize];
3777     // Write the fields.
3778     WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
3779     WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
3780   }
3783 - (void)setGPBGenericValue:(GPBGenericValue *)value
3784      forGPBGenericValueKey:(GPBGenericValue *)key {
3785   [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueInt32)];
3788 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
3789   [self enumerateKeysAndInt64sUsingBlock:^(int32_t key, int64_t value, __unused BOOL *stop) {
3790       block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%lld", value]);
3791   }];
3794 - (BOOL)getInt64:(nullable int64_t *)value forKey:(int32_t)key {
3795   NSNumber *wrapped = [_dictionary objectForKey:@(key)];
3796   if (wrapped && value) {
3797     *value = [wrapped longLongValue];
3798   }
3799   return (wrapped != NULL);
3802 - (void)addEntriesFromDictionary:(GPBInt32Int64Dictionary *)otherDictionary {
3803   if (otherDictionary) {
3804     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
3805     if (_autocreator) {
3806       GPBAutocreatedDictionaryModified(_autocreator, self);
3807     }
3808   }
3811 - (void)setInt64:(int64_t)value forKey:(int32_t)key {
3812   [_dictionary setObject:@(value) forKey:@(key)];
3813   if (_autocreator) {
3814     GPBAutocreatedDictionaryModified(_autocreator, self);
3815   }
3818 - (void)removeInt64ForKey:(int32_t)aKey {
3819   [_dictionary removeObjectForKey:@(aKey)];
3822 - (void)removeAll {
3823   [_dictionary removeAllObjects];
3826 @end
3828 #pragma mark - Int32 -> Bool
3830 @implementation GPBInt32BoolDictionary {
3831  @package
3832   NSMutableDictionary *_dictionary;
3835 - (instancetype)init {
3836   return [self initWithBools:NULL forKeys:NULL count:0];
3839 - (instancetype)initWithBools:(const BOOL [])values
3840                       forKeys:(const int32_t [])keys
3841                         count:(NSUInteger)count {
3842   self = [super init];
3843   if (self) {
3844     _dictionary = [[NSMutableDictionary alloc] init];
3845     if (count && values && keys) {
3846       for (NSUInteger i = 0; i < count; ++i) {
3847         [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
3848       }
3849     }
3850   }
3851   return self;
3854 - (instancetype)initWithDictionary:(GPBInt32BoolDictionary *)dictionary {
3855   self = [self initWithBools:NULL forKeys:NULL count:0];
3856   if (self) {
3857     if (dictionary) {
3858       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
3859     }
3860   }
3861   return self;
3864 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
3865   return [self initWithBools:NULL forKeys:NULL count:0];
3868 - (void)dealloc {
3869   NSAssert(!_autocreator,
3870            @"%@: Autocreator must be cleared before release, autocreator: %@",
3871            [self class], _autocreator);
3872   [_dictionary release];
3873   [super dealloc];
3876 - (instancetype)copyWithZone:(NSZone *)zone {
3877   return [[GPBInt32BoolDictionary allocWithZone:zone] initWithDictionary:self];
3880 - (BOOL)isEqual:(id)other {
3881   if (self == other) {
3882     return YES;
3883   }
3884   if (![other isKindOfClass:[GPBInt32BoolDictionary class]]) {
3885     return NO;
3886   }
3887   GPBInt32BoolDictionary *otherDictionary = other;
3888   return [_dictionary isEqual:otherDictionary->_dictionary];
3891 - (NSUInteger)hash {
3892   return _dictionary.count;
3895 - (NSString *)description {
3896   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
3899 - (NSUInteger)count {
3900   return _dictionary.count;
3903 - (void)enumerateKeysAndBoolsUsingBlock:
3904     (void (NS_NOESCAPE ^)(int32_t key, BOOL value, BOOL *stop))block {
3905   BOOL stop = NO;
3906   NSDictionary *internal = _dictionary;
3907   NSEnumerator *keys = [internal keyEnumerator];
3908   NSNumber *aKey;
3909   while ((aKey = [keys nextObject])) {
3910     NSNumber *aValue = internal[aKey];
3911     block([aKey intValue], [aValue boolValue], &stop);
3912     if (stop) {
3913       break;
3914     }
3915   }
3918 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
3919   NSDictionary *internal = _dictionary;
3920   NSUInteger count = internal.count;
3921   if (count == 0) {
3922     return 0;
3923   }
3925   GPBDataType valueDataType = GPBGetFieldDataType(field);
3926   GPBDataType keyDataType = field.mapKeyDataType;
3927   size_t result = 0;
3928   NSEnumerator *keys = [internal keyEnumerator];
3929   NSNumber *aKey;
3930   while ((aKey = [keys nextObject])) {
3931     NSNumber *aValue = internal[aKey];
3932     size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
3933     msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
3934     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
3935   }
3936   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
3937   result += tagSize * count;
3938   return result;
3941 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
3942                          asField:(GPBFieldDescriptor *)field {
3943   GPBDataType valueDataType = GPBGetFieldDataType(field);
3944   GPBDataType keyDataType = field.mapKeyDataType;
3945   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
3946   NSDictionary *internal = _dictionary;
3947   NSEnumerator *keys = [internal keyEnumerator];
3948   NSNumber *aKey;
3949   while ((aKey = [keys nextObject])) {
3950     NSNumber *aValue = internal[aKey];
3951     [outputStream writeInt32NoTag:tag];
3952     // Write the size of the message.
3953     int32_t unwrappedKey = [aKey intValue];
3954     BOOL unwrappedValue = [aValue boolValue];
3955     size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
3956     msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
3957     [outputStream writeInt32NoTag:(int32_t)msgSize];
3958     // Write the fields.
3959     WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
3960     WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
3961   }
3964 - (void)setGPBGenericValue:(GPBGenericValue *)value
3965      forGPBGenericValueKey:(GPBGenericValue *)key {
3966   [_dictionary setObject:@(value->valueBool) forKey:@(key->valueInt32)];
3969 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
3970   [self enumerateKeysAndBoolsUsingBlock:^(int32_t key, BOOL value, __unused BOOL *stop) {
3971       block([NSString stringWithFormat:@"%d", key], (value ? @"true" : @"false"));
3972   }];
3975 - (BOOL)getBool:(nullable BOOL *)value forKey:(int32_t)key {
3976   NSNumber *wrapped = [_dictionary objectForKey:@(key)];
3977   if (wrapped && value) {
3978     *value = [wrapped boolValue];
3979   }
3980   return (wrapped != NULL);
3983 - (void)addEntriesFromDictionary:(GPBInt32BoolDictionary *)otherDictionary {
3984   if (otherDictionary) {
3985     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
3986     if (_autocreator) {
3987       GPBAutocreatedDictionaryModified(_autocreator, self);
3988     }
3989   }
3992 - (void)setBool:(BOOL)value forKey:(int32_t)key {
3993   [_dictionary setObject:@(value) forKey:@(key)];
3994   if (_autocreator) {
3995     GPBAutocreatedDictionaryModified(_autocreator, self);
3996   }
3999 - (void)removeBoolForKey:(int32_t)aKey {
4000   [_dictionary removeObjectForKey:@(aKey)];
4003 - (void)removeAll {
4004   [_dictionary removeAllObjects];
4007 @end
4009 #pragma mark - Int32 -> Float
4011 @implementation GPBInt32FloatDictionary {
4012  @package
4013   NSMutableDictionary *_dictionary;
4016 - (instancetype)init {
4017   return [self initWithFloats:NULL forKeys:NULL count:0];
4020 - (instancetype)initWithFloats:(const float [])values
4021                        forKeys:(const int32_t [])keys
4022                          count:(NSUInteger)count {
4023   self = [super init];
4024   if (self) {
4025     _dictionary = [[NSMutableDictionary alloc] init];
4026     if (count && values && keys) {
4027       for (NSUInteger i = 0; i < count; ++i) {
4028         [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
4029       }
4030     }
4031   }
4032   return self;
4035 - (instancetype)initWithDictionary:(GPBInt32FloatDictionary *)dictionary {
4036   self = [self initWithFloats:NULL forKeys:NULL count:0];
4037   if (self) {
4038     if (dictionary) {
4039       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
4040     }
4041   }
4042   return self;
4045 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
4046   return [self initWithFloats:NULL forKeys:NULL count:0];
4049 - (void)dealloc {
4050   NSAssert(!_autocreator,
4051            @"%@: Autocreator must be cleared before release, autocreator: %@",
4052            [self class], _autocreator);
4053   [_dictionary release];
4054   [super dealloc];
4057 - (instancetype)copyWithZone:(NSZone *)zone {
4058   return [[GPBInt32FloatDictionary allocWithZone:zone] initWithDictionary:self];
4061 - (BOOL)isEqual:(id)other {
4062   if (self == other) {
4063     return YES;
4064   }
4065   if (![other isKindOfClass:[GPBInt32FloatDictionary class]]) {
4066     return NO;
4067   }
4068   GPBInt32FloatDictionary *otherDictionary = other;
4069   return [_dictionary isEqual:otherDictionary->_dictionary];
4072 - (NSUInteger)hash {
4073   return _dictionary.count;
4076 - (NSString *)description {
4077   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
4080 - (NSUInteger)count {
4081   return _dictionary.count;
4084 - (void)enumerateKeysAndFloatsUsingBlock:
4085     (void (NS_NOESCAPE ^)(int32_t key, float value, BOOL *stop))block {
4086   BOOL stop = NO;
4087   NSDictionary *internal = _dictionary;
4088   NSEnumerator *keys = [internal keyEnumerator];
4089   NSNumber *aKey;
4090   while ((aKey = [keys nextObject])) {
4091     NSNumber *aValue = internal[aKey];
4092     block([aKey intValue], [aValue floatValue], &stop);
4093     if (stop) {
4094       break;
4095     }
4096   }
4099 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
4100   NSDictionary *internal = _dictionary;
4101   NSUInteger count = internal.count;
4102   if (count == 0) {
4103     return 0;
4104   }
4106   GPBDataType valueDataType = GPBGetFieldDataType(field);
4107   GPBDataType keyDataType = field.mapKeyDataType;
4108   size_t result = 0;
4109   NSEnumerator *keys = [internal keyEnumerator];
4110   NSNumber *aKey;
4111   while ((aKey = [keys nextObject])) {
4112     NSNumber *aValue = internal[aKey];
4113     size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
4114     msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
4115     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
4116   }
4117   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
4118   result += tagSize * count;
4119   return result;
4122 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
4123                          asField:(GPBFieldDescriptor *)field {
4124   GPBDataType valueDataType = GPBGetFieldDataType(field);
4125   GPBDataType keyDataType = field.mapKeyDataType;
4126   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
4127   NSDictionary *internal = _dictionary;
4128   NSEnumerator *keys = [internal keyEnumerator];
4129   NSNumber *aKey;
4130   while ((aKey = [keys nextObject])) {
4131     NSNumber *aValue = internal[aKey];
4132     [outputStream writeInt32NoTag:tag];
4133     // Write the size of the message.
4134     int32_t unwrappedKey = [aKey intValue];
4135     float unwrappedValue = [aValue floatValue];
4136     size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
4137     msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
4138     [outputStream writeInt32NoTag:(int32_t)msgSize];
4139     // Write the fields.
4140     WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
4141     WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
4142   }
4145 - (void)setGPBGenericValue:(GPBGenericValue *)value
4146      forGPBGenericValueKey:(GPBGenericValue *)key {
4147   [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueInt32)];
4150 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
4151   [self enumerateKeysAndFloatsUsingBlock:^(int32_t key, float value, __unused BOOL *stop) {
4152       block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
4153   }];
4156 - (BOOL)getFloat:(nullable float *)value forKey:(int32_t)key {
4157   NSNumber *wrapped = [_dictionary objectForKey:@(key)];
4158   if (wrapped && value) {
4159     *value = [wrapped floatValue];
4160   }
4161   return (wrapped != NULL);
4164 - (void)addEntriesFromDictionary:(GPBInt32FloatDictionary *)otherDictionary {
4165   if (otherDictionary) {
4166     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
4167     if (_autocreator) {
4168       GPBAutocreatedDictionaryModified(_autocreator, self);
4169     }
4170   }
4173 - (void)setFloat:(float)value forKey:(int32_t)key {
4174   [_dictionary setObject:@(value) forKey:@(key)];
4175   if (_autocreator) {
4176     GPBAutocreatedDictionaryModified(_autocreator, self);
4177   }
4180 - (void)removeFloatForKey:(int32_t)aKey {
4181   [_dictionary removeObjectForKey:@(aKey)];
4184 - (void)removeAll {
4185   [_dictionary removeAllObjects];
4188 @end
4190 #pragma mark - Int32 -> Double
4192 @implementation GPBInt32DoubleDictionary {
4193  @package
4194   NSMutableDictionary *_dictionary;
4197 - (instancetype)init {
4198   return [self initWithDoubles:NULL forKeys:NULL count:0];
4201 - (instancetype)initWithDoubles:(const double [])values
4202                         forKeys:(const int32_t [])keys
4203                           count:(NSUInteger)count {
4204   self = [super init];
4205   if (self) {
4206     _dictionary = [[NSMutableDictionary alloc] init];
4207     if (count && values && keys) {
4208       for (NSUInteger i = 0; i < count; ++i) {
4209         [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
4210       }
4211     }
4212   }
4213   return self;
4216 - (instancetype)initWithDictionary:(GPBInt32DoubleDictionary *)dictionary {
4217   self = [self initWithDoubles:NULL forKeys:NULL count:0];
4218   if (self) {
4219     if (dictionary) {
4220       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
4221     }
4222   }
4223   return self;
4226 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
4227   return [self initWithDoubles:NULL forKeys:NULL count:0];
4230 - (void)dealloc {
4231   NSAssert(!_autocreator,
4232            @"%@: Autocreator must be cleared before release, autocreator: %@",
4233            [self class], _autocreator);
4234   [_dictionary release];
4235   [super dealloc];
4238 - (instancetype)copyWithZone:(NSZone *)zone {
4239   return [[GPBInt32DoubleDictionary allocWithZone:zone] initWithDictionary:self];
4242 - (BOOL)isEqual:(id)other {
4243   if (self == other) {
4244     return YES;
4245   }
4246   if (![other isKindOfClass:[GPBInt32DoubleDictionary class]]) {
4247     return NO;
4248   }
4249   GPBInt32DoubleDictionary *otherDictionary = other;
4250   return [_dictionary isEqual:otherDictionary->_dictionary];
4253 - (NSUInteger)hash {
4254   return _dictionary.count;
4257 - (NSString *)description {
4258   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
4261 - (NSUInteger)count {
4262   return _dictionary.count;
4265 - (void)enumerateKeysAndDoublesUsingBlock:
4266     (void (NS_NOESCAPE ^)(int32_t key, double value, BOOL *stop))block {
4267   BOOL stop = NO;
4268   NSDictionary *internal = _dictionary;
4269   NSEnumerator *keys = [internal keyEnumerator];
4270   NSNumber *aKey;
4271   while ((aKey = [keys nextObject])) {
4272     NSNumber *aValue = internal[aKey];
4273     block([aKey intValue], [aValue doubleValue], &stop);
4274     if (stop) {
4275       break;
4276     }
4277   }
4280 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
4281   NSDictionary *internal = _dictionary;
4282   NSUInteger count = internal.count;
4283   if (count == 0) {
4284     return 0;
4285   }
4287   GPBDataType valueDataType = GPBGetFieldDataType(field);
4288   GPBDataType keyDataType = field.mapKeyDataType;
4289   size_t result = 0;
4290   NSEnumerator *keys = [internal keyEnumerator];
4291   NSNumber *aKey;
4292   while ((aKey = [keys nextObject])) {
4293     NSNumber *aValue = internal[aKey];
4294     size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
4295     msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
4296     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
4297   }
4298   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
4299   result += tagSize * count;
4300   return result;
4303 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
4304                          asField:(GPBFieldDescriptor *)field {
4305   GPBDataType valueDataType = GPBGetFieldDataType(field);
4306   GPBDataType keyDataType = field.mapKeyDataType;
4307   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
4308   NSDictionary *internal = _dictionary;
4309   NSEnumerator *keys = [internal keyEnumerator];
4310   NSNumber *aKey;
4311   while ((aKey = [keys nextObject])) {
4312     NSNumber *aValue = internal[aKey];
4313     [outputStream writeInt32NoTag:tag];
4314     // Write the size of the message.
4315     int32_t unwrappedKey = [aKey intValue];
4316     double unwrappedValue = [aValue doubleValue];
4317     size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
4318     msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
4319     [outputStream writeInt32NoTag:(int32_t)msgSize];
4320     // Write the fields.
4321     WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
4322     WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
4323   }
4326 - (void)setGPBGenericValue:(GPBGenericValue *)value
4327      forGPBGenericValueKey:(GPBGenericValue *)key {
4328   [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueInt32)];
4331 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
4332   [self enumerateKeysAndDoublesUsingBlock:^(int32_t key, double value, __unused BOOL *stop) {
4333       block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
4334   }];
4337 - (BOOL)getDouble:(nullable double *)value forKey:(int32_t)key {
4338   NSNumber *wrapped = [_dictionary objectForKey:@(key)];
4339   if (wrapped && value) {
4340     *value = [wrapped doubleValue];
4341   }
4342   return (wrapped != NULL);
4345 - (void)addEntriesFromDictionary:(GPBInt32DoubleDictionary *)otherDictionary {
4346   if (otherDictionary) {
4347     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
4348     if (_autocreator) {
4349       GPBAutocreatedDictionaryModified(_autocreator, self);
4350     }
4351   }
4354 - (void)setDouble:(double)value forKey:(int32_t)key {
4355   [_dictionary setObject:@(value) forKey:@(key)];
4356   if (_autocreator) {
4357     GPBAutocreatedDictionaryModified(_autocreator, self);
4358   }
4361 - (void)removeDoubleForKey:(int32_t)aKey {
4362   [_dictionary removeObjectForKey:@(aKey)];
4365 - (void)removeAll {
4366   [_dictionary removeAllObjects];
4369 @end
4371 #pragma mark - Int32 -> Enum
4373 @implementation GPBInt32EnumDictionary {
4374  @package
4375   NSMutableDictionary *_dictionary;
4376   GPBEnumValidationFunc _validationFunc;
4379 @synthesize validationFunc = _validationFunc;
4381 - (instancetype)init {
4382   return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
4385 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
4386   return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
4389 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
4390                                  rawValues:(const int32_t [])rawValues
4391                                    forKeys:(const int32_t [])keys
4392                                      count:(NSUInteger)count {
4393   self = [super init];
4394   if (self) {
4395     _dictionary = [[NSMutableDictionary alloc] init];
4396     _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
4397     if (count && rawValues && keys) {
4398       for (NSUInteger i = 0; i < count; ++i) {
4399         [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])];
4400       }
4401     }
4402   }
4403   return self;
4406 - (instancetype)initWithDictionary:(GPBInt32EnumDictionary *)dictionary {
4407   self = [self initWithValidationFunction:dictionary.validationFunc
4408                                 rawValues:NULL
4409                                   forKeys:NULL
4410                                     count:0];
4411   if (self) {
4412     if (dictionary) {
4413       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
4414     }
4415   }
4416   return self;
4419 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
4420                                   capacity:(__unused NSUInteger)numItems {
4421   return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
4424 - (void)dealloc {
4425   NSAssert(!_autocreator,
4426            @"%@: Autocreator must be cleared before release, autocreator: %@",
4427            [self class], _autocreator);
4428   [_dictionary release];
4429   [super dealloc];
4432 - (instancetype)copyWithZone:(NSZone *)zone {
4433   return [[GPBInt32EnumDictionary allocWithZone:zone] initWithDictionary:self];
4436 - (BOOL)isEqual:(id)other {
4437   if (self == other) {
4438     return YES;
4439   }
4440   if (![other isKindOfClass:[GPBInt32EnumDictionary class]]) {
4441     return NO;
4442   }
4443   GPBInt32EnumDictionary *otherDictionary = other;
4444   return [_dictionary isEqual:otherDictionary->_dictionary];
4447 - (NSUInteger)hash {
4448   return _dictionary.count;
4451 - (NSString *)description {
4452   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
4455 - (NSUInteger)count {
4456   return _dictionary.count;
4459 - (void)enumerateKeysAndRawValuesUsingBlock:
4460     (void (NS_NOESCAPE ^)(int32_t key, int32_t value, BOOL *stop))block {
4461   BOOL stop = NO;
4462   NSDictionary *internal = _dictionary;
4463   NSEnumerator *keys = [internal keyEnumerator];
4464   NSNumber *aKey;
4465   while ((aKey = [keys nextObject])) {
4466     NSNumber *aValue = internal[aKey];
4467     block([aKey intValue], [aValue intValue], &stop);
4468     if (stop) {
4469       break;
4470     }
4471   }
4474 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
4475   NSDictionary *internal = _dictionary;
4476   NSUInteger count = internal.count;
4477   if (count == 0) {
4478     return 0;
4479   }
4481   GPBDataType valueDataType = GPBGetFieldDataType(field);
4482   GPBDataType keyDataType = field.mapKeyDataType;
4483   size_t result = 0;
4484   NSEnumerator *keys = [internal keyEnumerator];
4485   NSNumber *aKey;
4486   while ((aKey = [keys nextObject])) {
4487     NSNumber *aValue = internal[aKey];
4488     size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
4489     msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
4490     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
4491   }
4492   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
4493   result += tagSize * count;
4494   return result;
4497 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
4498                          asField:(GPBFieldDescriptor *)field {
4499   GPBDataType valueDataType = GPBGetFieldDataType(field);
4500   GPBDataType keyDataType = field.mapKeyDataType;
4501   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
4502   NSDictionary *internal = _dictionary;
4503   NSEnumerator *keys = [internal keyEnumerator];
4504   NSNumber *aKey;
4505   while ((aKey = [keys nextObject])) {
4506     NSNumber *aValue = internal[aKey];
4507     [outputStream writeInt32NoTag:tag];
4508     // Write the size of the message.
4509     int32_t unwrappedKey = [aKey intValue];
4510     int32_t unwrappedValue = [aValue intValue];
4511     size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
4512     msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
4513     [outputStream writeInt32NoTag:(int32_t)msgSize];
4514     // Write the fields.
4515     WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
4516     WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
4517   }
4520 - (NSData *)serializedDataForUnknownValue:(int32_t)value
4521                                    forKey:(GPBGenericValue *)key
4522                               keyDataType:(GPBDataType)keyDataType {
4523   size_t msgSize = ComputeDictInt32FieldSize(key->valueInt32, kMapKeyFieldNumber, keyDataType);
4524   msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
4525   NSMutableData *data = [NSMutableData dataWithLength:msgSize];
4526   GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
4527   WriteDictInt32Field(outputStream, key->valueInt32, kMapKeyFieldNumber, keyDataType);
4528   WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
4529   [outputStream flush];
4530   [outputStream release];
4531   return data;
4533 - (void)setGPBGenericValue:(GPBGenericValue *)value
4534      forGPBGenericValueKey:(GPBGenericValue *)key {
4535   [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueInt32)];
4538 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
4539   [self enumerateKeysAndRawValuesUsingBlock:^(int32_t key, int32_t value, __unused BOOL *stop) {
4540       block([NSString stringWithFormat:@"%d", key], @(value));
4541   }];
4544 - (BOOL)getEnum:(int32_t *)value forKey:(int32_t)key {
4545   NSNumber *wrapped = [_dictionary objectForKey:@(key)];
4546   if (wrapped && value) {
4547     int32_t result = [wrapped intValue];
4548     if (!_validationFunc(result)) {
4549       result = kGPBUnrecognizedEnumeratorValue;
4550     }
4551     *value = result;
4552   }
4553   return (wrapped != NULL);
4556 - (BOOL)getRawValue:(int32_t *)rawValue forKey:(int32_t)key {
4557   NSNumber *wrapped = [_dictionary objectForKey:@(key)];
4558   if (wrapped && rawValue) {
4559     *rawValue = [wrapped intValue];
4560   }
4561   return (wrapped != NULL);
4564 - (void)enumerateKeysAndEnumsUsingBlock:
4565     (void (NS_NOESCAPE ^)(int32_t key, int32_t value, BOOL *stop))block {
4566   GPBEnumValidationFunc func = _validationFunc;
4567   BOOL stop = NO;
4568   NSEnumerator *keys = [_dictionary keyEnumerator];
4569   NSNumber *aKey;
4570   while ((aKey = [keys nextObject])) {
4571     NSNumber *aValue = _dictionary[aKey];
4572       int32_t unwrapped = [aValue intValue];
4573       if (!func(unwrapped)) {
4574         unwrapped = kGPBUnrecognizedEnumeratorValue;
4575       }
4576     block([aKey intValue], unwrapped, &stop);
4577     if (stop) {
4578       break;
4579     }
4580   }
4583 - (void)addRawEntriesFromDictionary:(GPBInt32EnumDictionary *)otherDictionary {
4584   if (otherDictionary) {
4585     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
4586     if (_autocreator) {
4587       GPBAutocreatedDictionaryModified(_autocreator, self);
4588     }
4589   }
4592 - (void)setRawValue:(int32_t)value forKey:(int32_t)key {
4593   [_dictionary setObject:@(value) forKey:@(key)];
4594   if (_autocreator) {
4595     GPBAutocreatedDictionaryModified(_autocreator, self);
4596   }
4599 - (void)removeEnumForKey:(int32_t)aKey {
4600   [_dictionary removeObjectForKey:@(aKey)];
4603 - (void)removeAll {
4604   [_dictionary removeAllObjects];
4607 - (void)setEnum:(int32_t)value forKey:(int32_t)key {
4608   if (!_validationFunc(value)) {
4609     [NSException raise:NSInvalidArgumentException
4610                 format:@"GPBInt32EnumDictionary: Attempt to set an unknown enum value (%d)",
4611                        value];
4612   }
4614   [_dictionary setObject:@(value) forKey:@(key)];
4615   if (_autocreator) {
4616     GPBAutocreatedDictionaryModified(_autocreator, self);
4617   }
4620 @end
4622 #pragma mark - Int32 -> Object
4624 @implementation GPBInt32ObjectDictionary {
4625  @package
4626   NSMutableDictionary *_dictionary;
4629 - (instancetype)init {
4630   return [self initWithObjects:NULL forKeys:NULL count:0];
4633 - (instancetype)initWithObjects:(const id [])objects
4634                         forKeys:(const int32_t [])keys
4635                           count:(NSUInteger)count {
4636   self = [super init];
4637   if (self) {
4638     _dictionary = [[NSMutableDictionary alloc] init];
4639     if (count && objects && keys) {
4640       for (NSUInteger i = 0; i < count; ++i) {
4641         if (!objects[i]) {
4642           [NSException raise:NSInvalidArgumentException
4643                       format:@"Attempting to add nil object to a Dictionary"];
4644         }
4645         [_dictionary setObject:objects[i] forKey:@(keys[i])];
4646       }
4647     }
4648   }
4649   return self;
4652 - (instancetype)initWithDictionary:(GPBInt32ObjectDictionary *)dictionary {
4653   self = [self initWithObjects:NULL forKeys:NULL count:0];
4654   if (self) {
4655     if (dictionary) {
4656       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
4657     }
4658   }
4659   return self;
4662 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
4663   return [self initWithObjects:NULL forKeys:NULL count:0];
4666 - (void)dealloc {
4667   NSAssert(!_autocreator,
4668            @"%@: Autocreator must be cleared before release, autocreator: %@",
4669            [self class], _autocreator);
4670   [_dictionary release];
4671   [super dealloc];
4674 - (instancetype)copyWithZone:(NSZone *)zone {
4675   return [[GPBInt32ObjectDictionary allocWithZone:zone] initWithDictionary:self];
4678 - (BOOL)isEqual:(id)other {
4679   if (self == other) {
4680     return YES;
4681   }
4682   if (![other isKindOfClass:[GPBInt32ObjectDictionary class]]) {
4683     return NO;
4684   }
4685   GPBInt32ObjectDictionary *otherDictionary = other;
4686   return [_dictionary isEqual:otherDictionary->_dictionary];
4689 - (NSUInteger)hash {
4690   return _dictionary.count;
4693 - (NSString *)description {
4694   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
4697 - (NSUInteger)count {
4698   return _dictionary.count;
4701 - (void)enumerateKeysAndObjectsUsingBlock:
4702     (void (NS_NOESCAPE ^)(int32_t key, id object, BOOL *stop))block {
4703   BOOL stop = NO;
4704   NSDictionary *internal = _dictionary;
4705   NSEnumerator *keys = [internal keyEnumerator];
4706   NSNumber *aKey;
4707   while ((aKey = [keys nextObject])) {
4708     id aObject = internal[aKey];
4709     block([aKey intValue], aObject, &stop);
4710     if (stop) {
4711       break;
4712     }
4713   }
4716 - (BOOL)isInitialized {
4717   for (GPBMessage *msg in [_dictionary objectEnumerator]) {
4718     if (!msg.initialized) {
4719       return NO;
4720     }
4721   }
4722   return YES;
4725 - (instancetype)deepCopyWithZone:(NSZone *)zone {
4726   GPBInt32ObjectDictionary *newDict =
4727       [[GPBInt32ObjectDictionary alloc] init];
4728   NSEnumerator *keys = [_dictionary keyEnumerator];
4729   id aKey;
4730   NSMutableDictionary *internalDict = newDict->_dictionary;
4731   while ((aKey = [keys nextObject])) {
4732     GPBMessage *msg = _dictionary[aKey];
4733     GPBMessage *copiedMsg = [msg copyWithZone:zone];
4734     [internalDict setObject:copiedMsg forKey:aKey];
4735     [copiedMsg release];
4736   }
4737   return newDict;
4740 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
4741   NSDictionary *internal = _dictionary;
4742   NSUInteger count = internal.count;
4743   if (count == 0) {
4744     return 0;
4745   }
4747   GPBDataType valueDataType = GPBGetFieldDataType(field);
4748   GPBDataType keyDataType = field.mapKeyDataType;
4749   size_t result = 0;
4750   NSEnumerator *keys = [internal keyEnumerator];
4751   NSNumber *aKey;
4752   while ((aKey = [keys nextObject])) {
4753     id aObject = internal[aKey];
4754     size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
4755     msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
4756     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
4757   }
4758   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
4759   result += tagSize * count;
4760   return result;
4763 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
4764                          asField:(GPBFieldDescriptor *)field {
4765   GPBDataType valueDataType = GPBGetFieldDataType(field);
4766   GPBDataType keyDataType = field.mapKeyDataType;
4767   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
4768   NSDictionary *internal = _dictionary;
4769   NSEnumerator *keys = [internal keyEnumerator];
4770   NSNumber *aKey;
4771   while ((aKey = [keys nextObject])) {
4772     id aObject = internal[aKey];
4773     [outputStream writeInt32NoTag:tag];
4774     // Write the size of the message.
4775     int32_t unwrappedKey = [aKey intValue];
4776     id unwrappedValue = aObject;
4777     size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
4778     msgSize += ComputeDictObjectFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
4779     [outputStream writeInt32NoTag:(int32_t)msgSize];
4780     // Write the fields.
4781     WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
4782     WriteDictObjectField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
4783   }
4786 - (void)setGPBGenericValue:(GPBGenericValue *)value
4787      forGPBGenericValueKey:(GPBGenericValue *)key {
4788   [_dictionary setObject:value->valueString forKey:@(key->valueInt32)];
4791 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
4792   [self enumerateKeysAndObjectsUsingBlock:^(int32_t key, id object, __unused BOOL *stop) {
4793       block([NSString stringWithFormat:@"%d", key], object);
4794   }];
4797 - (id)objectForKey:(int32_t)key {
4798   id result = [_dictionary objectForKey:@(key)];
4799   return result;
4802 - (void)addEntriesFromDictionary:(GPBInt32ObjectDictionary *)otherDictionary {
4803   if (otherDictionary) {
4804     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
4805     if (_autocreator) {
4806       GPBAutocreatedDictionaryModified(_autocreator, self);
4807     }
4808   }
4811 - (void)setObject:(id)object forKey:(int32_t)key {
4812   if (!object) {
4813     [NSException raise:NSInvalidArgumentException
4814                 format:@"Attempting to add nil object to a Dictionary"];
4815   }
4816   [_dictionary setObject:object forKey:@(key)];
4817   if (_autocreator) {
4818     GPBAutocreatedDictionaryModified(_autocreator, self);
4819   }
4822 - (void)removeObjectForKey:(int32_t)aKey {
4823   [_dictionary removeObjectForKey:@(aKey)];
4826 - (void)removeAll {
4827   [_dictionary removeAllObjects];
4830 @end
4832 //%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(UInt64, uint64_t)
4833 // This block of code is generated, do not edit it directly.
4835 #pragma mark - UInt64 -> UInt32
4837 @implementation GPBUInt64UInt32Dictionary {
4838  @package
4839   NSMutableDictionary *_dictionary;
4842 - (instancetype)init {
4843   return [self initWithUInt32s:NULL forKeys:NULL count:0];
4846 - (instancetype)initWithUInt32s:(const uint32_t [])values
4847                         forKeys:(const uint64_t [])keys
4848                           count:(NSUInteger)count {
4849   self = [super init];
4850   if (self) {
4851     _dictionary = [[NSMutableDictionary alloc] init];
4852     if (count && values && keys) {
4853       for (NSUInteger i = 0; i < count; ++i) {
4854         [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
4855       }
4856     }
4857   }
4858   return self;
4861 - (instancetype)initWithDictionary:(GPBUInt64UInt32Dictionary *)dictionary {
4862   self = [self initWithUInt32s:NULL forKeys:NULL count:0];
4863   if (self) {
4864     if (dictionary) {
4865       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
4866     }
4867   }
4868   return self;
4871 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
4872   return [self initWithUInt32s:NULL forKeys:NULL count:0];
4875 - (void)dealloc {
4876   NSAssert(!_autocreator,
4877            @"%@: Autocreator must be cleared before release, autocreator: %@",
4878            [self class], _autocreator);
4879   [_dictionary release];
4880   [super dealloc];
4883 - (instancetype)copyWithZone:(NSZone *)zone {
4884   return [[GPBUInt64UInt32Dictionary allocWithZone:zone] initWithDictionary:self];
4887 - (BOOL)isEqual:(id)other {
4888   if (self == other) {
4889     return YES;
4890   }
4891   if (![other isKindOfClass:[GPBUInt64UInt32Dictionary class]]) {
4892     return NO;
4893   }
4894   GPBUInt64UInt32Dictionary *otherDictionary = other;
4895   return [_dictionary isEqual:otherDictionary->_dictionary];
4898 - (NSUInteger)hash {
4899   return _dictionary.count;
4902 - (NSString *)description {
4903   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
4906 - (NSUInteger)count {
4907   return _dictionary.count;
4910 - (void)enumerateKeysAndUInt32sUsingBlock:
4911     (void (NS_NOESCAPE ^)(uint64_t key, uint32_t value, BOOL *stop))block {
4912   BOOL stop = NO;
4913   NSDictionary *internal = _dictionary;
4914   NSEnumerator *keys = [internal keyEnumerator];
4915   NSNumber *aKey;
4916   while ((aKey = [keys nextObject])) {
4917     NSNumber *aValue = internal[aKey];
4918     block([aKey unsignedLongLongValue], [aValue unsignedIntValue], &stop);
4919     if (stop) {
4920       break;
4921     }
4922   }
4925 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
4926   NSDictionary *internal = _dictionary;
4927   NSUInteger count = internal.count;
4928   if (count == 0) {
4929     return 0;
4930   }
4932   GPBDataType valueDataType = GPBGetFieldDataType(field);
4933   GPBDataType keyDataType = field.mapKeyDataType;
4934   size_t result = 0;
4935   NSEnumerator *keys = [internal keyEnumerator];
4936   NSNumber *aKey;
4937   while ((aKey = [keys nextObject])) {
4938     NSNumber *aValue = internal[aKey];
4939     size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
4940     msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
4941     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
4942   }
4943   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
4944   result += tagSize * count;
4945   return result;
4948 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
4949                          asField:(GPBFieldDescriptor *)field {
4950   GPBDataType valueDataType = GPBGetFieldDataType(field);
4951   GPBDataType keyDataType = field.mapKeyDataType;
4952   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
4953   NSDictionary *internal = _dictionary;
4954   NSEnumerator *keys = [internal keyEnumerator];
4955   NSNumber *aKey;
4956   while ((aKey = [keys nextObject])) {
4957     NSNumber *aValue = internal[aKey];
4958     [outputStream writeInt32NoTag:tag];
4959     // Write the size of the message.
4960     uint64_t unwrappedKey = [aKey unsignedLongLongValue];
4961     uint32_t unwrappedValue = [aValue unsignedIntValue];
4962     size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
4963     msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
4964     [outputStream writeInt32NoTag:(int32_t)msgSize];
4965     // Write the fields.
4966     WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
4967     WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
4968   }
4971 - (void)setGPBGenericValue:(GPBGenericValue *)value
4972      forGPBGenericValueKey:(GPBGenericValue *)key {
4973   [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueUInt64)];
4976 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
4977   [self enumerateKeysAndUInt32sUsingBlock:^(uint64_t key, uint32_t value, __unused BOOL *stop) {
4978       block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%u", value]);
4979   }];
4982 - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(uint64_t)key {
4983   NSNumber *wrapped = [_dictionary objectForKey:@(key)];
4984   if (wrapped && value) {
4985     *value = [wrapped unsignedIntValue];
4986   }
4987   return (wrapped != NULL);
4990 - (void)addEntriesFromDictionary:(GPBUInt64UInt32Dictionary *)otherDictionary {
4991   if (otherDictionary) {
4992     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
4993     if (_autocreator) {
4994       GPBAutocreatedDictionaryModified(_autocreator, self);
4995     }
4996   }
4999 - (void)setUInt32:(uint32_t)value forKey:(uint64_t)key {
5000   [_dictionary setObject:@(value) forKey:@(key)];
5001   if (_autocreator) {
5002     GPBAutocreatedDictionaryModified(_autocreator, self);
5003   }
5006 - (void)removeUInt32ForKey:(uint64_t)aKey {
5007   [_dictionary removeObjectForKey:@(aKey)];
5010 - (void)removeAll {
5011   [_dictionary removeAllObjects];
5014 @end
5016 #pragma mark - UInt64 -> Int32
5018 @implementation GPBUInt64Int32Dictionary {
5019  @package
5020   NSMutableDictionary *_dictionary;
5023 - (instancetype)init {
5024   return [self initWithInt32s:NULL forKeys:NULL count:0];
5027 - (instancetype)initWithInt32s:(const int32_t [])values
5028                        forKeys:(const uint64_t [])keys
5029                          count:(NSUInteger)count {
5030   self = [super init];
5031   if (self) {
5032     _dictionary = [[NSMutableDictionary alloc] init];
5033     if (count && values && keys) {
5034       for (NSUInteger i = 0; i < count; ++i) {
5035         [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
5036       }
5037     }
5038   }
5039   return self;
5042 - (instancetype)initWithDictionary:(GPBUInt64Int32Dictionary *)dictionary {
5043   self = [self initWithInt32s:NULL forKeys:NULL count:0];
5044   if (self) {
5045     if (dictionary) {
5046       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
5047     }
5048   }
5049   return self;
5052 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
5053   return [self initWithInt32s:NULL forKeys:NULL count:0];
5056 - (void)dealloc {
5057   NSAssert(!_autocreator,
5058            @"%@: Autocreator must be cleared before release, autocreator: %@",
5059            [self class], _autocreator);
5060   [_dictionary release];
5061   [super dealloc];
5064 - (instancetype)copyWithZone:(NSZone *)zone {
5065   return [[GPBUInt64Int32Dictionary allocWithZone:zone] initWithDictionary:self];
5068 - (BOOL)isEqual:(id)other {
5069   if (self == other) {
5070     return YES;
5071   }
5072   if (![other isKindOfClass:[GPBUInt64Int32Dictionary class]]) {
5073     return NO;
5074   }
5075   GPBUInt64Int32Dictionary *otherDictionary = other;
5076   return [_dictionary isEqual:otherDictionary->_dictionary];
5079 - (NSUInteger)hash {
5080   return _dictionary.count;
5083 - (NSString *)description {
5084   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
5087 - (NSUInteger)count {
5088   return _dictionary.count;
5091 - (void)enumerateKeysAndInt32sUsingBlock:
5092     (void (NS_NOESCAPE ^)(uint64_t key, int32_t value, BOOL *stop))block {
5093   BOOL stop = NO;
5094   NSDictionary *internal = _dictionary;
5095   NSEnumerator *keys = [internal keyEnumerator];
5096   NSNumber *aKey;
5097   while ((aKey = [keys nextObject])) {
5098     NSNumber *aValue = internal[aKey];
5099     block([aKey unsignedLongLongValue], [aValue intValue], &stop);
5100     if (stop) {
5101       break;
5102     }
5103   }
5106 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
5107   NSDictionary *internal = _dictionary;
5108   NSUInteger count = internal.count;
5109   if (count == 0) {
5110     return 0;
5111   }
5113   GPBDataType valueDataType = GPBGetFieldDataType(field);
5114   GPBDataType keyDataType = field.mapKeyDataType;
5115   size_t result = 0;
5116   NSEnumerator *keys = [internal keyEnumerator];
5117   NSNumber *aKey;
5118   while ((aKey = [keys nextObject])) {
5119     NSNumber *aValue = internal[aKey];
5120     size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
5121     msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
5122     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
5123   }
5124   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
5125   result += tagSize * count;
5126   return result;
5129 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
5130                          asField:(GPBFieldDescriptor *)field {
5131   GPBDataType valueDataType = GPBGetFieldDataType(field);
5132   GPBDataType keyDataType = field.mapKeyDataType;
5133   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
5134   NSDictionary *internal = _dictionary;
5135   NSEnumerator *keys = [internal keyEnumerator];
5136   NSNumber *aKey;
5137   while ((aKey = [keys nextObject])) {
5138     NSNumber *aValue = internal[aKey];
5139     [outputStream writeInt32NoTag:tag];
5140     // Write the size of the message.
5141     uint64_t unwrappedKey = [aKey unsignedLongLongValue];
5142     int32_t unwrappedValue = [aValue intValue];
5143     size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
5144     msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
5145     [outputStream writeInt32NoTag:(int32_t)msgSize];
5146     // Write the fields.
5147     WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
5148     WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
5149   }
5152 - (void)setGPBGenericValue:(GPBGenericValue *)value
5153      forGPBGenericValueKey:(GPBGenericValue *)key {
5154   [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueUInt64)];
5157 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
5158   [self enumerateKeysAndInt32sUsingBlock:^(uint64_t key, int32_t value, __unused BOOL *stop) {
5159       block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%d", value]);
5160   }];
5163 - (BOOL)getInt32:(nullable int32_t *)value forKey:(uint64_t)key {
5164   NSNumber *wrapped = [_dictionary objectForKey:@(key)];
5165   if (wrapped && value) {
5166     *value = [wrapped intValue];
5167   }
5168   return (wrapped != NULL);
5171 - (void)addEntriesFromDictionary:(GPBUInt64Int32Dictionary *)otherDictionary {
5172   if (otherDictionary) {
5173     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
5174     if (_autocreator) {
5175       GPBAutocreatedDictionaryModified(_autocreator, self);
5176     }
5177   }
5180 - (void)setInt32:(int32_t)value forKey:(uint64_t)key {
5181   [_dictionary setObject:@(value) forKey:@(key)];
5182   if (_autocreator) {
5183     GPBAutocreatedDictionaryModified(_autocreator, self);
5184   }
5187 - (void)removeInt32ForKey:(uint64_t)aKey {
5188   [_dictionary removeObjectForKey:@(aKey)];
5191 - (void)removeAll {
5192   [_dictionary removeAllObjects];
5195 @end
5197 #pragma mark - UInt64 -> UInt64
5199 @implementation GPBUInt64UInt64Dictionary {
5200  @package
5201   NSMutableDictionary *_dictionary;
5204 - (instancetype)init {
5205   return [self initWithUInt64s:NULL forKeys:NULL count:0];
5208 - (instancetype)initWithUInt64s:(const uint64_t [])values
5209                         forKeys:(const uint64_t [])keys
5210                           count:(NSUInteger)count {
5211   self = [super init];
5212   if (self) {
5213     _dictionary = [[NSMutableDictionary alloc] init];
5214     if (count && values && keys) {
5215       for (NSUInteger i = 0; i < count; ++i) {
5216         [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
5217       }
5218     }
5219   }
5220   return self;
5223 - (instancetype)initWithDictionary:(GPBUInt64UInt64Dictionary *)dictionary {
5224   self = [self initWithUInt64s:NULL forKeys:NULL count:0];
5225   if (self) {
5226     if (dictionary) {
5227       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
5228     }
5229   }
5230   return self;
5233 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
5234   return [self initWithUInt64s:NULL forKeys:NULL count:0];
5237 - (void)dealloc {
5238   NSAssert(!_autocreator,
5239            @"%@: Autocreator must be cleared before release, autocreator: %@",
5240            [self class], _autocreator);
5241   [_dictionary release];
5242   [super dealloc];
5245 - (instancetype)copyWithZone:(NSZone *)zone {
5246   return [[GPBUInt64UInt64Dictionary allocWithZone:zone] initWithDictionary:self];
5249 - (BOOL)isEqual:(id)other {
5250   if (self == other) {
5251     return YES;
5252   }
5253   if (![other isKindOfClass:[GPBUInt64UInt64Dictionary class]]) {
5254     return NO;
5255   }
5256   GPBUInt64UInt64Dictionary *otherDictionary = other;
5257   return [_dictionary isEqual:otherDictionary->_dictionary];
5260 - (NSUInteger)hash {
5261   return _dictionary.count;
5264 - (NSString *)description {
5265   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
5268 - (NSUInteger)count {
5269   return _dictionary.count;
5272 - (void)enumerateKeysAndUInt64sUsingBlock:
5273     (void (NS_NOESCAPE ^)(uint64_t key, uint64_t value, BOOL *stop))block {
5274   BOOL stop = NO;
5275   NSDictionary *internal = _dictionary;
5276   NSEnumerator *keys = [internal keyEnumerator];
5277   NSNumber *aKey;
5278   while ((aKey = [keys nextObject])) {
5279     NSNumber *aValue = internal[aKey];
5280     block([aKey unsignedLongLongValue], [aValue unsignedLongLongValue], &stop);
5281     if (stop) {
5282       break;
5283     }
5284   }
5287 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
5288   NSDictionary *internal = _dictionary;
5289   NSUInteger count = internal.count;
5290   if (count == 0) {
5291     return 0;
5292   }
5294   GPBDataType valueDataType = GPBGetFieldDataType(field);
5295   GPBDataType keyDataType = field.mapKeyDataType;
5296   size_t result = 0;
5297   NSEnumerator *keys = [internal keyEnumerator];
5298   NSNumber *aKey;
5299   while ((aKey = [keys nextObject])) {
5300     NSNumber *aValue = internal[aKey];
5301     size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
5302     msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
5303     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
5304   }
5305   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
5306   result += tagSize * count;
5307   return result;
5310 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
5311                          asField:(GPBFieldDescriptor *)field {
5312   GPBDataType valueDataType = GPBGetFieldDataType(field);
5313   GPBDataType keyDataType = field.mapKeyDataType;
5314   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
5315   NSDictionary *internal = _dictionary;
5316   NSEnumerator *keys = [internal keyEnumerator];
5317   NSNumber *aKey;
5318   while ((aKey = [keys nextObject])) {
5319     NSNumber *aValue = internal[aKey];
5320     [outputStream writeInt32NoTag:tag];
5321     // Write the size of the message.
5322     uint64_t unwrappedKey = [aKey unsignedLongLongValue];
5323     uint64_t unwrappedValue = [aValue unsignedLongLongValue];
5324     size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
5325     msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
5326     [outputStream writeInt32NoTag:(int32_t)msgSize];
5327     // Write the fields.
5328     WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
5329     WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
5330   }
5333 - (void)setGPBGenericValue:(GPBGenericValue *)value
5334      forGPBGenericValueKey:(GPBGenericValue *)key {
5335   [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueUInt64)];
5338 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
5339   [self enumerateKeysAndUInt64sUsingBlock:^(uint64_t key, uint64_t value, __unused BOOL *stop) {
5340       block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%llu", value]);
5341   }];
5344 - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(uint64_t)key {
5345   NSNumber *wrapped = [_dictionary objectForKey:@(key)];
5346   if (wrapped && value) {
5347     *value = [wrapped unsignedLongLongValue];
5348   }
5349   return (wrapped != NULL);
5352 - (void)addEntriesFromDictionary:(GPBUInt64UInt64Dictionary *)otherDictionary {
5353   if (otherDictionary) {
5354     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
5355     if (_autocreator) {
5356       GPBAutocreatedDictionaryModified(_autocreator, self);
5357     }
5358   }
5361 - (void)setUInt64:(uint64_t)value forKey:(uint64_t)key {
5362   [_dictionary setObject:@(value) forKey:@(key)];
5363   if (_autocreator) {
5364     GPBAutocreatedDictionaryModified(_autocreator, self);
5365   }
5368 - (void)removeUInt64ForKey:(uint64_t)aKey {
5369   [_dictionary removeObjectForKey:@(aKey)];
5372 - (void)removeAll {
5373   [_dictionary removeAllObjects];
5376 @end
5378 #pragma mark - UInt64 -> Int64
5380 @implementation GPBUInt64Int64Dictionary {
5381  @package
5382   NSMutableDictionary *_dictionary;
5385 - (instancetype)init {
5386   return [self initWithInt64s:NULL forKeys:NULL count:0];
5389 - (instancetype)initWithInt64s:(const int64_t [])values
5390                        forKeys:(const uint64_t [])keys
5391                          count:(NSUInteger)count {
5392   self = [super init];
5393   if (self) {
5394     _dictionary = [[NSMutableDictionary alloc] init];
5395     if (count && values && keys) {
5396       for (NSUInteger i = 0; i < count; ++i) {
5397         [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
5398       }
5399     }
5400   }
5401   return self;
5404 - (instancetype)initWithDictionary:(GPBUInt64Int64Dictionary *)dictionary {
5405   self = [self initWithInt64s:NULL forKeys:NULL count:0];
5406   if (self) {
5407     if (dictionary) {
5408       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
5409     }
5410   }
5411   return self;
5414 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
5415   return [self initWithInt64s:NULL forKeys:NULL count:0];
5418 - (void)dealloc {
5419   NSAssert(!_autocreator,
5420            @"%@: Autocreator must be cleared before release, autocreator: %@",
5421            [self class], _autocreator);
5422   [_dictionary release];
5423   [super dealloc];
5426 - (instancetype)copyWithZone:(NSZone *)zone {
5427   return [[GPBUInt64Int64Dictionary allocWithZone:zone] initWithDictionary:self];
5430 - (BOOL)isEqual:(id)other {
5431   if (self == other) {
5432     return YES;
5433   }
5434   if (![other isKindOfClass:[GPBUInt64Int64Dictionary class]]) {
5435     return NO;
5436   }
5437   GPBUInt64Int64Dictionary *otherDictionary = other;
5438   return [_dictionary isEqual:otherDictionary->_dictionary];
5441 - (NSUInteger)hash {
5442   return _dictionary.count;
5445 - (NSString *)description {
5446   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
5449 - (NSUInteger)count {
5450   return _dictionary.count;
5453 - (void)enumerateKeysAndInt64sUsingBlock:
5454     (void (NS_NOESCAPE ^)(uint64_t key, int64_t value, BOOL *stop))block {
5455   BOOL stop = NO;
5456   NSDictionary *internal = _dictionary;
5457   NSEnumerator *keys = [internal keyEnumerator];
5458   NSNumber *aKey;
5459   while ((aKey = [keys nextObject])) {
5460     NSNumber *aValue = internal[aKey];
5461     block([aKey unsignedLongLongValue], [aValue longLongValue], &stop);
5462     if (stop) {
5463       break;
5464     }
5465   }
5468 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
5469   NSDictionary *internal = _dictionary;
5470   NSUInteger count = internal.count;
5471   if (count == 0) {
5472     return 0;
5473   }
5475   GPBDataType valueDataType = GPBGetFieldDataType(field);
5476   GPBDataType keyDataType = field.mapKeyDataType;
5477   size_t result = 0;
5478   NSEnumerator *keys = [internal keyEnumerator];
5479   NSNumber *aKey;
5480   while ((aKey = [keys nextObject])) {
5481     NSNumber *aValue = internal[aKey];
5482     size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
5483     msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
5484     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
5485   }
5486   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
5487   result += tagSize * count;
5488   return result;
5491 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
5492                          asField:(GPBFieldDescriptor *)field {
5493   GPBDataType valueDataType = GPBGetFieldDataType(field);
5494   GPBDataType keyDataType = field.mapKeyDataType;
5495   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
5496   NSDictionary *internal = _dictionary;
5497   NSEnumerator *keys = [internal keyEnumerator];
5498   NSNumber *aKey;
5499   while ((aKey = [keys nextObject])) {
5500     NSNumber *aValue = internal[aKey];
5501     [outputStream writeInt32NoTag:tag];
5502     // Write the size of the message.
5503     uint64_t unwrappedKey = [aKey unsignedLongLongValue];
5504     int64_t unwrappedValue = [aValue longLongValue];
5505     size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
5506     msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
5507     [outputStream writeInt32NoTag:(int32_t)msgSize];
5508     // Write the fields.
5509     WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
5510     WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
5511   }
5514 - (void)setGPBGenericValue:(GPBGenericValue *)value
5515      forGPBGenericValueKey:(GPBGenericValue *)key {
5516   [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueUInt64)];
5519 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
5520   [self enumerateKeysAndInt64sUsingBlock:^(uint64_t key, int64_t value, __unused BOOL *stop) {
5521       block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%lld", value]);
5522   }];
5525 - (BOOL)getInt64:(nullable int64_t *)value forKey:(uint64_t)key {
5526   NSNumber *wrapped = [_dictionary objectForKey:@(key)];
5527   if (wrapped && value) {
5528     *value = [wrapped longLongValue];
5529   }
5530   return (wrapped != NULL);
5533 - (void)addEntriesFromDictionary:(GPBUInt64Int64Dictionary *)otherDictionary {
5534   if (otherDictionary) {
5535     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
5536     if (_autocreator) {
5537       GPBAutocreatedDictionaryModified(_autocreator, self);
5538     }
5539   }
5542 - (void)setInt64:(int64_t)value forKey:(uint64_t)key {
5543   [_dictionary setObject:@(value) forKey:@(key)];
5544   if (_autocreator) {
5545     GPBAutocreatedDictionaryModified(_autocreator, self);
5546   }
5549 - (void)removeInt64ForKey:(uint64_t)aKey {
5550   [_dictionary removeObjectForKey:@(aKey)];
5553 - (void)removeAll {
5554   [_dictionary removeAllObjects];
5557 @end
5559 #pragma mark - UInt64 -> Bool
5561 @implementation GPBUInt64BoolDictionary {
5562  @package
5563   NSMutableDictionary *_dictionary;
5566 - (instancetype)init {
5567   return [self initWithBools:NULL forKeys:NULL count:0];
5570 - (instancetype)initWithBools:(const BOOL [])values
5571                       forKeys:(const uint64_t [])keys
5572                         count:(NSUInteger)count {
5573   self = [super init];
5574   if (self) {
5575     _dictionary = [[NSMutableDictionary alloc] init];
5576     if (count && values && keys) {
5577       for (NSUInteger i = 0; i < count; ++i) {
5578         [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
5579       }
5580     }
5581   }
5582   return self;
5585 - (instancetype)initWithDictionary:(GPBUInt64BoolDictionary *)dictionary {
5586   self = [self initWithBools:NULL forKeys:NULL count:0];
5587   if (self) {
5588     if (dictionary) {
5589       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
5590     }
5591   }
5592   return self;
5595 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
5596   return [self initWithBools:NULL forKeys:NULL count:0];
5599 - (void)dealloc {
5600   NSAssert(!_autocreator,
5601            @"%@: Autocreator must be cleared before release, autocreator: %@",
5602            [self class], _autocreator);
5603   [_dictionary release];
5604   [super dealloc];
5607 - (instancetype)copyWithZone:(NSZone *)zone {
5608   return [[GPBUInt64BoolDictionary allocWithZone:zone] initWithDictionary:self];
5611 - (BOOL)isEqual:(id)other {
5612   if (self == other) {
5613     return YES;
5614   }
5615   if (![other isKindOfClass:[GPBUInt64BoolDictionary class]]) {
5616     return NO;
5617   }
5618   GPBUInt64BoolDictionary *otherDictionary = other;
5619   return [_dictionary isEqual:otherDictionary->_dictionary];
5622 - (NSUInteger)hash {
5623   return _dictionary.count;
5626 - (NSString *)description {
5627   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
5630 - (NSUInteger)count {
5631   return _dictionary.count;
5634 - (void)enumerateKeysAndBoolsUsingBlock:
5635     (void (NS_NOESCAPE ^)(uint64_t key, BOOL value, BOOL *stop))block {
5636   BOOL stop = NO;
5637   NSDictionary *internal = _dictionary;
5638   NSEnumerator *keys = [internal keyEnumerator];
5639   NSNumber *aKey;
5640   while ((aKey = [keys nextObject])) {
5641     NSNumber *aValue = internal[aKey];
5642     block([aKey unsignedLongLongValue], [aValue boolValue], &stop);
5643     if (stop) {
5644       break;
5645     }
5646   }
5649 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
5650   NSDictionary *internal = _dictionary;
5651   NSUInteger count = internal.count;
5652   if (count == 0) {
5653     return 0;
5654   }
5656   GPBDataType valueDataType = GPBGetFieldDataType(field);
5657   GPBDataType keyDataType = field.mapKeyDataType;
5658   size_t result = 0;
5659   NSEnumerator *keys = [internal keyEnumerator];
5660   NSNumber *aKey;
5661   while ((aKey = [keys nextObject])) {
5662     NSNumber *aValue = internal[aKey];
5663     size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
5664     msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
5665     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
5666   }
5667   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
5668   result += tagSize * count;
5669   return result;
5672 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
5673                          asField:(GPBFieldDescriptor *)field {
5674   GPBDataType valueDataType = GPBGetFieldDataType(field);
5675   GPBDataType keyDataType = field.mapKeyDataType;
5676   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
5677   NSDictionary *internal = _dictionary;
5678   NSEnumerator *keys = [internal keyEnumerator];
5679   NSNumber *aKey;
5680   while ((aKey = [keys nextObject])) {
5681     NSNumber *aValue = internal[aKey];
5682     [outputStream writeInt32NoTag:tag];
5683     // Write the size of the message.
5684     uint64_t unwrappedKey = [aKey unsignedLongLongValue];
5685     BOOL unwrappedValue = [aValue boolValue];
5686     size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
5687     msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
5688     [outputStream writeInt32NoTag:(int32_t)msgSize];
5689     // Write the fields.
5690     WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
5691     WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
5692   }
5695 - (void)setGPBGenericValue:(GPBGenericValue *)value
5696      forGPBGenericValueKey:(GPBGenericValue *)key {
5697   [_dictionary setObject:@(value->valueBool) forKey:@(key->valueUInt64)];
5700 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
5701   [self enumerateKeysAndBoolsUsingBlock:^(uint64_t key, BOOL value, __unused BOOL *stop) {
5702       block([NSString stringWithFormat:@"%llu", key], (value ? @"true" : @"false"));
5703   }];
5706 - (BOOL)getBool:(nullable BOOL *)value forKey:(uint64_t)key {
5707   NSNumber *wrapped = [_dictionary objectForKey:@(key)];
5708   if (wrapped && value) {
5709     *value = [wrapped boolValue];
5710   }
5711   return (wrapped != NULL);
5714 - (void)addEntriesFromDictionary:(GPBUInt64BoolDictionary *)otherDictionary {
5715   if (otherDictionary) {
5716     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
5717     if (_autocreator) {
5718       GPBAutocreatedDictionaryModified(_autocreator, self);
5719     }
5720   }
5723 - (void)setBool:(BOOL)value forKey:(uint64_t)key {
5724   [_dictionary setObject:@(value) forKey:@(key)];
5725   if (_autocreator) {
5726     GPBAutocreatedDictionaryModified(_autocreator, self);
5727   }
5730 - (void)removeBoolForKey:(uint64_t)aKey {
5731   [_dictionary removeObjectForKey:@(aKey)];
5734 - (void)removeAll {
5735   [_dictionary removeAllObjects];
5738 @end
5740 #pragma mark - UInt64 -> Float
5742 @implementation GPBUInt64FloatDictionary {
5743  @package
5744   NSMutableDictionary *_dictionary;
5747 - (instancetype)init {
5748   return [self initWithFloats:NULL forKeys:NULL count:0];
5751 - (instancetype)initWithFloats:(const float [])values
5752                        forKeys:(const uint64_t [])keys
5753                          count:(NSUInteger)count {
5754   self = [super init];
5755   if (self) {
5756     _dictionary = [[NSMutableDictionary alloc] init];
5757     if (count && values && keys) {
5758       for (NSUInteger i = 0; i < count; ++i) {
5759         [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
5760       }
5761     }
5762   }
5763   return self;
5766 - (instancetype)initWithDictionary:(GPBUInt64FloatDictionary *)dictionary {
5767   self = [self initWithFloats:NULL forKeys:NULL count:0];
5768   if (self) {
5769     if (dictionary) {
5770       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
5771     }
5772   }
5773   return self;
5776 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
5777   return [self initWithFloats:NULL forKeys:NULL count:0];
5780 - (void)dealloc {
5781   NSAssert(!_autocreator,
5782            @"%@: Autocreator must be cleared before release, autocreator: %@",
5783            [self class], _autocreator);
5784   [_dictionary release];
5785   [super dealloc];
5788 - (instancetype)copyWithZone:(NSZone *)zone {
5789   return [[GPBUInt64FloatDictionary allocWithZone:zone] initWithDictionary:self];
5792 - (BOOL)isEqual:(id)other {
5793   if (self == other) {
5794     return YES;
5795   }
5796   if (![other isKindOfClass:[GPBUInt64FloatDictionary class]]) {
5797     return NO;
5798   }
5799   GPBUInt64FloatDictionary *otherDictionary = other;
5800   return [_dictionary isEqual:otherDictionary->_dictionary];
5803 - (NSUInteger)hash {
5804   return _dictionary.count;
5807 - (NSString *)description {
5808   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
5811 - (NSUInteger)count {
5812   return _dictionary.count;
5815 - (void)enumerateKeysAndFloatsUsingBlock:
5816     (void (NS_NOESCAPE ^)(uint64_t key, float value, BOOL *stop))block {
5817   BOOL stop = NO;
5818   NSDictionary *internal = _dictionary;
5819   NSEnumerator *keys = [internal keyEnumerator];
5820   NSNumber *aKey;
5821   while ((aKey = [keys nextObject])) {
5822     NSNumber *aValue = internal[aKey];
5823     block([aKey unsignedLongLongValue], [aValue floatValue], &stop);
5824     if (stop) {
5825       break;
5826     }
5827   }
5830 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
5831   NSDictionary *internal = _dictionary;
5832   NSUInteger count = internal.count;
5833   if (count == 0) {
5834     return 0;
5835   }
5837   GPBDataType valueDataType = GPBGetFieldDataType(field);
5838   GPBDataType keyDataType = field.mapKeyDataType;
5839   size_t result = 0;
5840   NSEnumerator *keys = [internal keyEnumerator];
5841   NSNumber *aKey;
5842   while ((aKey = [keys nextObject])) {
5843     NSNumber *aValue = internal[aKey];
5844     size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
5845     msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
5846     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
5847   }
5848   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
5849   result += tagSize * count;
5850   return result;
5853 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
5854                          asField:(GPBFieldDescriptor *)field {
5855   GPBDataType valueDataType = GPBGetFieldDataType(field);
5856   GPBDataType keyDataType = field.mapKeyDataType;
5857   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
5858   NSDictionary *internal = _dictionary;
5859   NSEnumerator *keys = [internal keyEnumerator];
5860   NSNumber *aKey;
5861   while ((aKey = [keys nextObject])) {
5862     NSNumber *aValue = internal[aKey];
5863     [outputStream writeInt32NoTag:tag];
5864     // Write the size of the message.
5865     uint64_t unwrappedKey = [aKey unsignedLongLongValue];
5866     float unwrappedValue = [aValue floatValue];
5867     size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
5868     msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
5869     [outputStream writeInt32NoTag:(int32_t)msgSize];
5870     // Write the fields.
5871     WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
5872     WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
5873   }
5876 - (void)setGPBGenericValue:(GPBGenericValue *)value
5877      forGPBGenericValueKey:(GPBGenericValue *)key {
5878   [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueUInt64)];
5881 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
5882   [self enumerateKeysAndFloatsUsingBlock:^(uint64_t key, float value, __unused BOOL *stop) {
5883       block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
5884   }];
5887 - (BOOL)getFloat:(nullable float *)value forKey:(uint64_t)key {
5888   NSNumber *wrapped = [_dictionary objectForKey:@(key)];
5889   if (wrapped && value) {
5890     *value = [wrapped floatValue];
5891   }
5892   return (wrapped != NULL);
5895 - (void)addEntriesFromDictionary:(GPBUInt64FloatDictionary *)otherDictionary {
5896   if (otherDictionary) {
5897     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
5898     if (_autocreator) {
5899       GPBAutocreatedDictionaryModified(_autocreator, self);
5900     }
5901   }
5904 - (void)setFloat:(float)value forKey:(uint64_t)key {
5905   [_dictionary setObject:@(value) forKey:@(key)];
5906   if (_autocreator) {
5907     GPBAutocreatedDictionaryModified(_autocreator, self);
5908   }
5911 - (void)removeFloatForKey:(uint64_t)aKey {
5912   [_dictionary removeObjectForKey:@(aKey)];
5915 - (void)removeAll {
5916   [_dictionary removeAllObjects];
5919 @end
5921 #pragma mark - UInt64 -> Double
5923 @implementation GPBUInt64DoubleDictionary {
5924  @package
5925   NSMutableDictionary *_dictionary;
5928 - (instancetype)init {
5929   return [self initWithDoubles:NULL forKeys:NULL count:0];
5932 - (instancetype)initWithDoubles:(const double [])values
5933                         forKeys:(const uint64_t [])keys
5934                           count:(NSUInteger)count {
5935   self = [super init];
5936   if (self) {
5937     _dictionary = [[NSMutableDictionary alloc] init];
5938     if (count && values && keys) {
5939       for (NSUInteger i = 0; i < count; ++i) {
5940         [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
5941       }
5942     }
5943   }
5944   return self;
5947 - (instancetype)initWithDictionary:(GPBUInt64DoubleDictionary *)dictionary {
5948   self = [self initWithDoubles:NULL forKeys:NULL count:0];
5949   if (self) {
5950     if (dictionary) {
5951       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
5952     }
5953   }
5954   return self;
5957 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
5958   return [self initWithDoubles:NULL forKeys:NULL count:0];
5961 - (void)dealloc {
5962   NSAssert(!_autocreator,
5963            @"%@: Autocreator must be cleared before release, autocreator: %@",
5964            [self class], _autocreator);
5965   [_dictionary release];
5966   [super dealloc];
5969 - (instancetype)copyWithZone:(NSZone *)zone {
5970   return [[GPBUInt64DoubleDictionary allocWithZone:zone] initWithDictionary:self];
5973 - (BOOL)isEqual:(id)other {
5974   if (self == other) {
5975     return YES;
5976   }
5977   if (![other isKindOfClass:[GPBUInt64DoubleDictionary class]]) {
5978     return NO;
5979   }
5980   GPBUInt64DoubleDictionary *otherDictionary = other;
5981   return [_dictionary isEqual:otherDictionary->_dictionary];
5984 - (NSUInteger)hash {
5985   return _dictionary.count;
5988 - (NSString *)description {
5989   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
5992 - (NSUInteger)count {
5993   return _dictionary.count;
5996 - (void)enumerateKeysAndDoublesUsingBlock:
5997     (void (NS_NOESCAPE ^)(uint64_t key, double value, BOOL *stop))block {
5998   BOOL stop = NO;
5999   NSDictionary *internal = _dictionary;
6000   NSEnumerator *keys = [internal keyEnumerator];
6001   NSNumber *aKey;
6002   while ((aKey = [keys nextObject])) {
6003     NSNumber *aValue = internal[aKey];
6004     block([aKey unsignedLongLongValue], [aValue doubleValue], &stop);
6005     if (stop) {
6006       break;
6007     }
6008   }
6011 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
6012   NSDictionary *internal = _dictionary;
6013   NSUInteger count = internal.count;
6014   if (count == 0) {
6015     return 0;
6016   }
6018   GPBDataType valueDataType = GPBGetFieldDataType(field);
6019   GPBDataType keyDataType = field.mapKeyDataType;
6020   size_t result = 0;
6021   NSEnumerator *keys = [internal keyEnumerator];
6022   NSNumber *aKey;
6023   while ((aKey = [keys nextObject])) {
6024     NSNumber *aValue = internal[aKey];
6025     size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
6026     msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
6027     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
6028   }
6029   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
6030   result += tagSize * count;
6031   return result;
6034 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
6035                          asField:(GPBFieldDescriptor *)field {
6036   GPBDataType valueDataType = GPBGetFieldDataType(field);
6037   GPBDataType keyDataType = field.mapKeyDataType;
6038   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
6039   NSDictionary *internal = _dictionary;
6040   NSEnumerator *keys = [internal keyEnumerator];
6041   NSNumber *aKey;
6042   while ((aKey = [keys nextObject])) {
6043     NSNumber *aValue = internal[aKey];
6044     [outputStream writeInt32NoTag:tag];
6045     // Write the size of the message.
6046     uint64_t unwrappedKey = [aKey unsignedLongLongValue];
6047     double unwrappedValue = [aValue doubleValue];
6048     size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
6049     msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
6050     [outputStream writeInt32NoTag:(int32_t)msgSize];
6051     // Write the fields.
6052     WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
6053     WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
6054   }
6057 - (void)setGPBGenericValue:(GPBGenericValue *)value
6058      forGPBGenericValueKey:(GPBGenericValue *)key {
6059   [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueUInt64)];
6062 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
6063   [self enumerateKeysAndDoublesUsingBlock:^(uint64_t key, double value, __unused BOOL *stop) {
6064       block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
6065   }];
6068 - (BOOL)getDouble:(nullable double *)value forKey:(uint64_t)key {
6069   NSNumber *wrapped = [_dictionary objectForKey:@(key)];
6070   if (wrapped && value) {
6071     *value = [wrapped doubleValue];
6072   }
6073   return (wrapped != NULL);
6076 - (void)addEntriesFromDictionary:(GPBUInt64DoubleDictionary *)otherDictionary {
6077   if (otherDictionary) {
6078     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
6079     if (_autocreator) {
6080       GPBAutocreatedDictionaryModified(_autocreator, self);
6081     }
6082   }
6085 - (void)setDouble:(double)value forKey:(uint64_t)key {
6086   [_dictionary setObject:@(value) forKey:@(key)];
6087   if (_autocreator) {
6088     GPBAutocreatedDictionaryModified(_autocreator, self);
6089   }
6092 - (void)removeDoubleForKey:(uint64_t)aKey {
6093   [_dictionary removeObjectForKey:@(aKey)];
6096 - (void)removeAll {
6097   [_dictionary removeAllObjects];
6100 @end
6102 #pragma mark - UInt64 -> Enum
6104 @implementation GPBUInt64EnumDictionary {
6105  @package
6106   NSMutableDictionary *_dictionary;
6107   GPBEnumValidationFunc _validationFunc;
6110 @synthesize validationFunc = _validationFunc;
6112 - (instancetype)init {
6113   return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
6116 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
6117   return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
6120 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
6121                                  rawValues:(const int32_t [])rawValues
6122                                    forKeys:(const uint64_t [])keys
6123                                      count:(NSUInteger)count {
6124   self = [super init];
6125   if (self) {
6126     _dictionary = [[NSMutableDictionary alloc] init];
6127     _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
6128     if (count && rawValues && keys) {
6129       for (NSUInteger i = 0; i < count; ++i) {
6130         [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])];
6131       }
6132     }
6133   }
6134   return self;
6137 - (instancetype)initWithDictionary:(GPBUInt64EnumDictionary *)dictionary {
6138   self = [self initWithValidationFunction:dictionary.validationFunc
6139                                 rawValues:NULL
6140                                   forKeys:NULL
6141                                     count:0];
6142   if (self) {
6143     if (dictionary) {
6144       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
6145     }
6146   }
6147   return self;
6150 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
6151                                   capacity:(__unused NSUInteger)numItems {
6152   return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
6155 - (void)dealloc {
6156   NSAssert(!_autocreator,
6157            @"%@: Autocreator must be cleared before release, autocreator: %@",
6158            [self class], _autocreator);
6159   [_dictionary release];
6160   [super dealloc];
6163 - (instancetype)copyWithZone:(NSZone *)zone {
6164   return [[GPBUInt64EnumDictionary allocWithZone:zone] initWithDictionary:self];
6167 - (BOOL)isEqual:(id)other {
6168   if (self == other) {
6169     return YES;
6170   }
6171   if (![other isKindOfClass:[GPBUInt64EnumDictionary class]]) {
6172     return NO;
6173   }
6174   GPBUInt64EnumDictionary *otherDictionary = other;
6175   return [_dictionary isEqual:otherDictionary->_dictionary];
6178 - (NSUInteger)hash {
6179   return _dictionary.count;
6182 - (NSString *)description {
6183   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
6186 - (NSUInteger)count {
6187   return _dictionary.count;
6190 - (void)enumerateKeysAndRawValuesUsingBlock:
6191     (void (NS_NOESCAPE ^)(uint64_t key, int32_t value, BOOL *stop))block {
6192   BOOL stop = NO;
6193   NSDictionary *internal = _dictionary;
6194   NSEnumerator *keys = [internal keyEnumerator];
6195   NSNumber *aKey;
6196   while ((aKey = [keys nextObject])) {
6197     NSNumber *aValue = internal[aKey];
6198     block([aKey unsignedLongLongValue], [aValue intValue], &stop);
6199     if (stop) {
6200       break;
6201     }
6202   }
6205 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
6206   NSDictionary *internal = _dictionary;
6207   NSUInteger count = internal.count;
6208   if (count == 0) {
6209     return 0;
6210   }
6212   GPBDataType valueDataType = GPBGetFieldDataType(field);
6213   GPBDataType keyDataType = field.mapKeyDataType;
6214   size_t result = 0;
6215   NSEnumerator *keys = [internal keyEnumerator];
6216   NSNumber *aKey;
6217   while ((aKey = [keys nextObject])) {
6218     NSNumber *aValue = internal[aKey];
6219     size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
6220     msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
6221     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
6222   }
6223   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
6224   result += tagSize * count;
6225   return result;
6228 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
6229                          asField:(GPBFieldDescriptor *)field {
6230   GPBDataType valueDataType = GPBGetFieldDataType(field);
6231   GPBDataType keyDataType = field.mapKeyDataType;
6232   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
6233   NSDictionary *internal = _dictionary;
6234   NSEnumerator *keys = [internal keyEnumerator];
6235   NSNumber *aKey;
6236   while ((aKey = [keys nextObject])) {
6237     NSNumber *aValue = internal[aKey];
6238     [outputStream writeInt32NoTag:tag];
6239     // Write the size of the message.
6240     uint64_t unwrappedKey = [aKey unsignedLongLongValue];
6241     int32_t unwrappedValue = [aValue intValue];
6242     size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
6243     msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
6244     [outputStream writeInt32NoTag:(int32_t)msgSize];
6245     // Write the fields.
6246     WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
6247     WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
6248   }
6251 - (NSData *)serializedDataForUnknownValue:(int32_t)value
6252                                    forKey:(GPBGenericValue *)key
6253                               keyDataType:(GPBDataType)keyDataType {
6254   size_t msgSize = ComputeDictUInt64FieldSize(key->valueUInt64, kMapKeyFieldNumber, keyDataType);
6255   msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
6256   NSMutableData *data = [NSMutableData dataWithLength:msgSize];
6257   GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
6258   WriteDictUInt64Field(outputStream, key->valueUInt64, kMapKeyFieldNumber, keyDataType);
6259   WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
6260   [outputStream flush];
6261   [outputStream release];
6262   return data;
6264 - (void)setGPBGenericValue:(GPBGenericValue *)value
6265      forGPBGenericValueKey:(GPBGenericValue *)key {
6266   [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueUInt64)];
6269 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
6270   [self enumerateKeysAndRawValuesUsingBlock:^(uint64_t key, int32_t value, __unused BOOL *stop) {
6271       block([NSString stringWithFormat:@"%llu", key], @(value));
6272   }];
6275 - (BOOL)getEnum:(int32_t *)value forKey:(uint64_t)key {
6276   NSNumber *wrapped = [_dictionary objectForKey:@(key)];
6277   if (wrapped && value) {
6278     int32_t result = [wrapped intValue];
6279     if (!_validationFunc(result)) {
6280       result = kGPBUnrecognizedEnumeratorValue;
6281     }
6282     *value = result;
6283   }
6284   return (wrapped != NULL);
6287 - (BOOL)getRawValue:(int32_t *)rawValue forKey:(uint64_t)key {
6288   NSNumber *wrapped = [_dictionary objectForKey:@(key)];
6289   if (wrapped && rawValue) {
6290     *rawValue = [wrapped intValue];
6291   }
6292   return (wrapped != NULL);
6295 - (void)enumerateKeysAndEnumsUsingBlock:
6296     (void (NS_NOESCAPE ^)(uint64_t key, int32_t value, BOOL *stop))block {
6297   GPBEnumValidationFunc func = _validationFunc;
6298   BOOL stop = NO;
6299   NSEnumerator *keys = [_dictionary keyEnumerator];
6300   NSNumber *aKey;
6301   while ((aKey = [keys nextObject])) {
6302     NSNumber *aValue = _dictionary[aKey];
6303       int32_t unwrapped = [aValue intValue];
6304       if (!func(unwrapped)) {
6305         unwrapped = kGPBUnrecognizedEnumeratorValue;
6306       }
6307     block([aKey unsignedLongLongValue], unwrapped, &stop);
6308     if (stop) {
6309       break;
6310     }
6311   }
6314 - (void)addRawEntriesFromDictionary:(GPBUInt64EnumDictionary *)otherDictionary {
6315   if (otherDictionary) {
6316     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
6317     if (_autocreator) {
6318       GPBAutocreatedDictionaryModified(_autocreator, self);
6319     }
6320   }
6323 - (void)setRawValue:(int32_t)value forKey:(uint64_t)key {
6324   [_dictionary setObject:@(value) forKey:@(key)];
6325   if (_autocreator) {
6326     GPBAutocreatedDictionaryModified(_autocreator, self);
6327   }
6330 - (void)removeEnumForKey:(uint64_t)aKey {
6331   [_dictionary removeObjectForKey:@(aKey)];
6334 - (void)removeAll {
6335   [_dictionary removeAllObjects];
6338 - (void)setEnum:(int32_t)value forKey:(uint64_t)key {
6339   if (!_validationFunc(value)) {
6340     [NSException raise:NSInvalidArgumentException
6341                 format:@"GPBUInt64EnumDictionary: Attempt to set an unknown enum value (%d)",
6342                        value];
6343   }
6345   [_dictionary setObject:@(value) forKey:@(key)];
6346   if (_autocreator) {
6347     GPBAutocreatedDictionaryModified(_autocreator, self);
6348   }
6351 @end
6353 #pragma mark - UInt64 -> Object
6355 @implementation GPBUInt64ObjectDictionary {
6356  @package
6357   NSMutableDictionary *_dictionary;
6360 - (instancetype)init {
6361   return [self initWithObjects:NULL forKeys:NULL count:0];
6364 - (instancetype)initWithObjects:(const id [])objects
6365                         forKeys:(const uint64_t [])keys
6366                           count:(NSUInteger)count {
6367   self = [super init];
6368   if (self) {
6369     _dictionary = [[NSMutableDictionary alloc] init];
6370     if (count && objects && keys) {
6371       for (NSUInteger i = 0; i < count; ++i) {
6372         if (!objects[i]) {
6373           [NSException raise:NSInvalidArgumentException
6374                       format:@"Attempting to add nil object to a Dictionary"];
6375         }
6376         [_dictionary setObject:objects[i] forKey:@(keys[i])];
6377       }
6378     }
6379   }
6380   return self;
6383 - (instancetype)initWithDictionary:(GPBUInt64ObjectDictionary *)dictionary {
6384   self = [self initWithObjects:NULL forKeys:NULL count:0];
6385   if (self) {
6386     if (dictionary) {
6387       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
6388     }
6389   }
6390   return self;
6393 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
6394   return [self initWithObjects:NULL forKeys:NULL count:0];
6397 - (void)dealloc {
6398   NSAssert(!_autocreator,
6399            @"%@: Autocreator must be cleared before release, autocreator: %@",
6400            [self class], _autocreator);
6401   [_dictionary release];
6402   [super dealloc];
6405 - (instancetype)copyWithZone:(NSZone *)zone {
6406   return [[GPBUInt64ObjectDictionary allocWithZone:zone] initWithDictionary:self];
6409 - (BOOL)isEqual:(id)other {
6410   if (self == other) {
6411     return YES;
6412   }
6413   if (![other isKindOfClass:[GPBUInt64ObjectDictionary class]]) {
6414     return NO;
6415   }
6416   GPBUInt64ObjectDictionary *otherDictionary = other;
6417   return [_dictionary isEqual:otherDictionary->_dictionary];
6420 - (NSUInteger)hash {
6421   return _dictionary.count;
6424 - (NSString *)description {
6425   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
6428 - (NSUInteger)count {
6429   return _dictionary.count;
6432 - (void)enumerateKeysAndObjectsUsingBlock:
6433     (void (NS_NOESCAPE ^)(uint64_t key, id object, BOOL *stop))block {
6434   BOOL stop = NO;
6435   NSDictionary *internal = _dictionary;
6436   NSEnumerator *keys = [internal keyEnumerator];
6437   NSNumber *aKey;
6438   while ((aKey = [keys nextObject])) {
6439     id aObject = internal[aKey];
6440     block([aKey unsignedLongLongValue], aObject, &stop);
6441     if (stop) {
6442       break;
6443     }
6444   }
6447 - (BOOL)isInitialized {
6448   for (GPBMessage *msg in [_dictionary objectEnumerator]) {
6449     if (!msg.initialized) {
6450       return NO;
6451     }
6452   }
6453   return YES;
6456 - (instancetype)deepCopyWithZone:(NSZone *)zone {
6457   GPBUInt64ObjectDictionary *newDict =
6458       [[GPBUInt64ObjectDictionary alloc] init];
6459   NSEnumerator *keys = [_dictionary keyEnumerator];
6460   id aKey;
6461   NSMutableDictionary *internalDict = newDict->_dictionary;
6462   while ((aKey = [keys nextObject])) {
6463     GPBMessage *msg = _dictionary[aKey];
6464     GPBMessage *copiedMsg = [msg copyWithZone:zone];
6465     [internalDict setObject:copiedMsg forKey:aKey];
6466     [copiedMsg release];
6467   }
6468   return newDict;
6471 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
6472   NSDictionary *internal = _dictionary;
6473   NSUInteger count = internal.count;
6474   if (count == 0) {
6475     return 0;
6476   }
6478   GPBDataType valueDataType = GPBGetFieldDataType(field);
6479   GPBDataType keyDataType = field.mapKeyDataType;
6480   size_t result = 0;
6481   NSEnumerator *keys = [internal keyEnumerator];
6482   NSNumber *aKey;
6483   while ((aKey = [keys nextObject])) {
6484     id aObject = internal[aKey];
6485     size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
6486     msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
6487     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
6488   }
6489   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
6490   result += tagSize * count;
6491   return result;
6494 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
6495                          asField:(GPBFieldDescriptor *)field {
6496   GPBDataType valueDataType = GPBGetFieldDataType(field);
6497   GPBDataType keyDataType = field.mapKeyDataType;
6498   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
6499   NSDictionary *internal = _dictionary;
6500   NSEnumerator *keys = [internal keyEnumerator];
6501   NSNumber *aKey;
6502   while ((aKey = [keys nextObject])) {
6503     id aObject = internal[aKey];
6504     [outputStream writeInt32NoTag:tag];
6505     // Write the size of the message.
6506     uint64_t unwrappedKey = [aKey unsignedLongLongValue];
6507     id unwrappedValue = aObject;
6508     size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
6509     msgSize += ComputeDictObjectFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
6510     [outputStream writeInt32NoTag:(int32_t)msgSize];
6511     // Write the fields.
6512     WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
6513     WriteDictObjectField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
6514   }
6517 - (void)setGPBGenericValue:(GPBGenericValue *)value
6518      forGPBGenericValueKey:(GPBGenericValue *)key {
6519   [_dictionary setObject:value->valueString forKey:@(key->valueUInt64)];
6522 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
6523   [self enumerateKeysAndObjectsUsingBlock:^(uint64_t key, id object, __unused BOOL *stop) {
6524       block([NSString stringWithFormat:@"%llu", key], object);
6525   }];
6528 - (id)objectForKey:(uint64_t)key {
6529   id result = [_dictionary objectForKey:@(key)];
6530   return result;
6533 - (void)addEntriesFromDictionary:(GPBUInt64ObjectDictionary *)otherDictionary {
6534   if (otherDictionary) {
6535     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
6536     if (_autocreator) {
6537       GPBAutocreatedDictionaryModified(_autocreator, self);
6538     }
6539   }
6542 - (void)setObject:(id)object forKey:(uint64_t)key {
6543   if (!object) {
6544     [NSException raise:NSInvalidArgumentException
6545                 format:@"Attempting to add nil object to a Dictionary"];
6546   }
6547   [_dictionary setObject:object forKey:@(key)];
6548   if (_autocreator) {
6549     GPBAutocreatedDictionaryModified(_autocreator, self);
6550   }
6553 - (void)removeObjectForKey:(uint64_t)aKey {
6554   [_dictionary removeObjectForKey:@(aKey)];
6557 - (void)removeAll {
6558   [_dictionary removeAllObjects];
6561 @end
6563 //%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(Int64, int64_t)
6564 // This block of code is generated, do not edit it directly.
6566 #pragma mark - Int64 -> UInt32
6568 @implementation GPBInt64UInt32Dictionary {
6569  @package
6570   NSMutableDictionary *_dictionary;
6573 - (instancetype)init {
6574   return [self initWithUInt32s:NULL forKeys:NULL count:0];
6577 - (instancetype)initWithUInt32s:(const uint32_t [])values
6578                         forKeys:(const int64_t [])keys
6579                           count:(NSUInteger)count {
6580   self = [super init];
6581   if (self) {
6582     _dictionary = [[NSMutableDictionary alloc] init];
6583     if (count && values && keys) {
6584       for (NSUInteger i = 0; i < count; ++i) {
6585         [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
6586       }
6587     }
6588   }
6589   return self;
6592 - (instancetype)initWithDictionary:(GPBInt64UInt32Dictionary *)dictionary {
6593   self = [self initWithUInt32s:NULL forKeys:NULL count:0];
6594   if (self) {
6595     if (dictionary) {
6596       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
6597     }
6598   }
6599   return self;
6602 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
6603   return [self initWithUInt32s:NULL forKeys:NULL count:0];
6606 - (void)dealloc {
6607   NSAssert(!_autocreator,
6608            @"%@: Autocreator must be cleared before release, autocreator: %@",
6609            [self class], _autocreator);
6610   [_dictionary release];
6611   [super dealloc];
6614 - (instancetype)copyWithZone:(NSZone *)zone {
6615   return [[GPBInt64UInt32Dictionary allocWithZone:zone] initWithDictionary:self];
6618 - (BOOL)isEqual:(id)other {
6619   if (self == other) {
6620     return YES;
6621   }
6622   if (![other isKindOfClass:[GPBInt64UInt32Dictionary class]]) {
6623     return NO;
6624   }
6625   GPBInt64UInt32Dictionary *otherDictionary = other;
6626   return [_dictionary isEqual:otherDictionary->_dictionary];
6629 - (NSUInteger)hash {
6630   return _dictionary.count;
6633 - (NSString *)description {
6634   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
6637 - (NSUInteger)count {
6638   return _dictionary.count;
6641 - (void)enumerateKeysAndUInt32sUsingBlock:
6642     (void (NS_NOESCAPE ^)(int64_t key, uint32_t value, BOOL *stop))block {
6643   BOOL stop = NO;
6644   NSDictionary *internal = _dictionary;
6645   NSEnumerator *keys = [internal keyEnumerator];
6646   NSNumber *aKey;
6647   while ((aKey = [keys nextObject])) {
6648     NSNumber *aValue = internal[aKey];
6649     block([aKey longLongValue], [aValue unsignedIntValue], &stop);
6650     if (stop) {
6651       break;
6652     }
6653   }
6656 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
6657   NSDictionary *internal = _dictionary;
6658   NSUInteger count = internal.count;
6659   if (count == 0) {
6660     return 0;
6661   }
6663   GPBDataType valueDataType = GPBGetFieldDataType(field);
6664   GPBDataType keyDataType = field.mapKeyDataType;
6665   size_t result = 0;
6666   NSEnumerator *keys = [internal keyEnumerator];
6667   NSNumber *aKey;
6668   while ((aKey = [keys nextObject])) {
6669     NSNumber *aValue = internal[aKey];
6670     size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
6671     msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
6672     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
6673   }
6674   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
6675   result += tagSize * count;
6676   return result;
6679 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
6680                          asField:(GPBFieldDescriptor *)field {
6681   GPBDataType valueDataType = GPBGetFieldDataType(field);
6682   GPBDataType keyDataType = field.mapKeyDataType;
6683   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
6684   NSDictionary *internal = _dictionary;
6685   NSEnumerator *keys = [internal keyEnumerator];
6686   NSNumber *aKey;
6687   while ((aKey = [keys nextObject])) {
6688     NSNumber *aValue = internal[aKey];
6689     [outputStream writeInt32NoTag:tag];
6690     // Write the size of the message.
6691     int64_t unwrappedKey = [aKey longLongValue];
6692     uint32_t unwrappedValue = [aValue unsignedIntValue];
6693     size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
6694     msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
6695     [outputStream writeInt32NoTag:(int32_t)msgSize];
6696     // Write the fields.
6697     WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
6698     WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
6699   }
6702 - (void)setGPBGenericValue:(GPBGenericValue *)value
6703      forGPBGenericValueKey:(GPBGenericValue *)key {
6704   [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueInt64)];
6707 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
6708   [self enumerateKeysAndUInt32sUsingBlock:^(int64_t key, uint32_t value, __unused BOOL *stop) {
6709       block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%u", value]);
6710   }];
6713 - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(int64_t)key {
6714   NSNumber *wrapped = [_dictionary objectForKey:@(key)];
6715   if (wrapped && value) {
6716     *value = [wrapped unsignedIntValue];
6717   }
6718   return (wrapped != NULL);
6721 - (void)addEntriesFromDictionary:(GPBInt64UInt32Dictionary *)otherDictionary {
6722   if (otherDictionary) {
6723     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
6724     if (_autocreator) {
6725       GPBAutocreatedDictionaryModified(_autocreator, self);
6726     }
6727   }
6730 - (void)setUInt32:(uint32_t)value forKey:(int64_t)key {
6731   [_dictionary setObject:@(value) forKey:@(key)];
6732   if (_autocreator) {
6733     GPBAutocreatedDictionaryModified(_autocreator, self);
6734   }
6737 - (void)removeUInt32ForKey:(int64_t)aKey {
6738   [_dictionary removeObjectForKey:@(aKey)];
6741 - (void)removeAll {
6742   [_dictionary removeAllObjects];
6745 @end
6747 #pragma mark - Int64 -> Int32
6749 @implementation GPBInt64Int32Dictionary {
6750  @package
6751   NSMutableDictionary *_dictionary;
6754 - (instancetype)init {
6755   return [self initWithInt32s:NULL forKeys:NULL count:0];
6758 - (instancetype)initWithInt32s:(const int32_t [])values
6759                        forKeys:(const int64_t [])keys
6760                          count:(NSUInteger)count {
6761   self = [super init];
6762   if (self) {
6763     _dictionary = [[NSMutableDictionary alloc] init];
6764     if (count && values && keys) {
6765       for (NSUInteger i = 0; i < count; ++i) {
6766         [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
6767       }
6768     }
6769   }
6770   return self;
6773 - (instancetype)initWithDictionary:(GPBInt64Int32Dictionary *)dictionary {
6774   self = [self initWithInt32s:NULL forKeys:NULL count:0];
6775   if (self) {
6776     if (dictionary) {
6777       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
6778     }
6779   }
6780   return self;
6783 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
6784   return [self initWithInt32s:NULL forKeys:NULL count:0];
6787 - (void)dealloc {
6788   NSAssert(!_autocreator,
6789            @"%@: Autocreator must be cleared before release, autocreator: %@",
6790            [self class], _autocreator);
6791   [_dictionary release];
6792   [super dealloc];
6795 - (instancetype)copyWithZone:(NSZone *)zone {
6796   return [[GPBInt64Int32Dictionary allocWithZone:zone] initWithDictionary:self];
6799 - (BOOL)isEqual:(id)other {
6800   if (self == other) {
6801     return YES;
6802   }
6803   if (![other isKindOfClass:[GPBInt64Int32Dictionary class]]) {
6804     return NO;
6805   }
6806   GPBInt64Int32Dictionary *otherDictionary = other;
6807   return [_dictionary isEqual:otherDictionary->_dictionary];
6810 - (NSUInteger)hash {
6811   return _dictionary.count;
6814 - (NSString *)description {
6815   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
6818 - (NSUInteger)count {
6819   return _dictionary.count;
6822 - (void)enumerateKeysAndInt32sUsingBlock:
6823     (void (NS_NOESCAPE ^)(int64_t key, int32_t value, BOOL *stop))block {
6824   BOOL stop = NO;
6825   NSDictionary *internal = _dictionary;
6826   NSEnumerator *keys = [internal keyEnumerator];
6827   NSNumber *aKey;
6828   while ((aKey = [keys nextObject])) {
6829     NSNumber *aValue = internal[aKey];
6830     block([aKey longLongValue], [aValue intValue], &stop);
6831     if (stop) {
6832       break;
6833     }
6834   }
6837 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
6838   NSDictionary *internal = _dictionary;
6839   NSUInteger count = internal.count;
6840   if (count == 0) {
6841     return 0;
6842   }
6844   GPBDataType valueDataType = GPBGetFieldDataType(field);
6845   GPBDataType keyDataType = field.mapKeyDataType;
6846   size_t result = 0;
6847   NSEnumerator *keys = [internal keyEnumerator];
6848   NSNumber *aKey;
6849   while ((aKey = [keys nextObject])) {
6850     NSNumber *aValue = internal[aKey];
6851     size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
6852     msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
6853     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
6854   }
6855   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
6856   result += tagSize * count;
6857   return result;
6860 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
6861                          asField:(GPBFieldDescriptor *)field {
6862   GPBDataType valueDataType = GPBGetFieldDataType(field);
6863   GPBDataType keyDataType = field.mapKeyDataType;
6864   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
6865   NSDictionary *internal = _dictionary;
6866   NSEnumerator *keys = [internal keyEnumerator];
6867   NSNumber *aKey;
6868   while ((aKey = [keys nextObject])) {
6869     NSNumber *aValue = internal[aKey];
6870     [outputStream writeInt32NoTag:tag];
6871     // Write the size of the message.
6872     int64_t unwrappedKey = [aKey longLongValue];
6873     int32_t unwrappedValue = [aValue intValue];
6874     size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
6875     msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
6876     [outputStream writeInt32NoTag:(int32_t)msgSize];
6877     // Write the fields.
6878     WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
6879     WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
6880   }
6883 - (void)setGPBGenericValue:(GPBGenericValue *)value
6884      forGPBGenericValueKey:(GPBGenericValue *)key {
6885   [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueInt64)];
6888 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
6889   [self enumerateKeysAndInt32sUsingBlock:^(int64_t key, int32_t value, __unused BOOL *stop) {
6890       block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%d", value]);
6891   }];
6894 - (BOOL)getInt32:(nullable int32_t *)value forKey:(int64_t)key {
6895   NSNumber *wrapped = [_dictionary objectForKey:@(key)];
6896   if (wrapped && value) {
6897     *value = [wrapped intValue];
6898   }
6899   return (wrapped != NULL);
6902 - (void)addEntriesFromDictionary:(GPBInt64Int32Dictionary *)otherDictionary {
6903   if (otherDictionary) {
6904     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
6905     if (_autocreator) {
6906       GPBAutocreatedDictionaryModified(_autocreator, self);
6907     }
6908   }
6911 - (void)setInt32:(int32_t)value forKey:(int64_t)key {
6912   [_dictionary setObject:@(value) forKey:@(key)];
6913   if (_autocreator) {
6914     GPBAutocreatedDictionaryModified(_autocreator, self);
6915   }
6918 - (void)removeInt32ForKey:(int64_t)aKey {
6919   [_dictionary removeObjectForKey:@(aKey)];
6922 - (void)removeAll {
6923   [_dictionary removeAllObjects];
6926 @end
6928 #pragma mark - Int64 -> UInt64
6930 @implementation GPBInt64UInt64Dictionary {
6931  @package
6932   NSMutableDictionary *_dictionary;
6935 - (instancetype)init {
6936   return [self initWithUInt64s:NULL forKeys:NULL count:0];
6939 - (instancetype)initWithUInt64s:(const uint64_t [])values
6940                         forKeys:(const int64_t [])keys
6941                           count:(NSUInteger)count {
6942   self = [super init];
6943   if (self) {
6944     _dictionary = [[NSMutableDictionary alloc] init];
6945     if (count && values && keys) {
6946       for (NSUInteger i = 0; i < count; ++i) {
6947         [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
6948       }
6949     }
6950   }
6951   return self;
6954 - (instancetype)initWithDictionary:(GPBInt64UInt64Dictionary *)dictionary {
6955   self = [self initWithUInt64s:NULL forKeys:NULL count:0];
6956   if (self) {
6957     if (dictionary) {
6958       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
6959     }
6960   }
6961   return self;
6964 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
6965   return [self initWithUInt64s:NULL forKeys:NULL count:0];
6968 - (void)dealloc {
6969   NSAssert(!_autocreator,
6970            @"%@: Autocreator must be cleared before release, autocreator: %@",
6971            [self class], _autocreator);
6972   [_dictionary release];
6973   [super dealloc];
6976 - (instancetype)copyWithZone:(NSZone *)zone {
6977   return [[GPBInt64UInt64Dictionary allocWithZone:zone] initWithDictionary:self];
6980 - (BOOL)isEqual:(id)other {
6981   if (self == other) {
6982     return YES;
6983   }
6984   if (![other isKindOfClass:[GPBInt64UInt64Dictionary class]]) {
6985     return NO;
6986   }
6987   GPBInt64UInt64Dictionary *otherDictionary = other;
6988   return [_dictionary isEqual:otherDictionary->_dictionary];
6991 - (NSUInteger)hash {
6992   return _dictionary.count;
6995 - (NSString *)description {
6996   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
6999 - (NSUInteger)count {
7000   return _dictionary.count;
7003 - (void)enumerateKeysAndUInt64sUsingBlock:
7004     (void (NS_NOESCAPE ^)(int64_t key, uint64_t value, BOOL *stop))block {
7005   BOOL stop = NO;
7006   NSDictionary *internal = _dictionary;
7007   NSEnumerator *keys = [internal keyEnumerator];
7008   NSNumber *aKey;
7009   while ((aKey = [keys nextObject])) {
7010     NSNumber *aValue = internal[aKey];
7011     block([aKey longLongValue], [aValue unsignedLongLongValue], &stop);
7012     if (stop) {
7013       break;
7014     }
7015   }
7018 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
7019   NSDictionary *internal = _dictionary;
7020   NSUInteger count = internal.count;
7021   if (count == 0) {
7022     return 0;
7023   }
7025   GPBDataType valueDataType = GPBGetFieldDataType(field);
7026   GPBDataType keyDataType = field.mapKeyDataType;
7027   size_t result = 0;
7028   NSEnumerator *keys = [internal keyEnumerator];
7029   NSNumber *aKey;
7030   while ((aKey = [keys nextObject])) {
7031     NSNumber *aValue = internal[aKey];
7032     size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
7033     msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
7034     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
7035   }
7036   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
7037   result += tagSize * count;
7038   return result;
7041 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
7042                          asField:(GPBFieldDescriptor *)field {
7043   GPBDataType valueDataType = GPBGetFieldDataType(field);
7044   GPBDataType keyDataType = field.mapKeyDataType;
7045   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
7046   NSDictionary *internal = _dictionary;
7047   NSEnumerator *keys = [internal keyEnumerator];
7048   NSNumber *aKey;
7049   while ((aKey = [keys nextObject])) {
7050     NSNumber *aValue = internal[aKey];
7051     [outputStream writeInt32NoTag:tag];
7052     // Write the size of the message.
7053     int64_t unwrappedKey = [aKey longLongValue];
7054     uint64_t unwrappedValue = [aValue unsignedLongLongValue];
7055     size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
7056     msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
7057     [outputStream writeInt32NoTag:(int32_t)msgSize];
7058     // Write the fields.
7059     WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
7060     WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
7061   }
7064 - (void)setGPBGenericValue:(GPBGenericValue *)value
7065      forGPBGenericValueKey:(GPBGenericValue *)key {
7066   [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueInt64)];
7069 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
7070   [self enumerateKeysAndUInt64sUsingBlock:^(int64_t key, uint64_t value, __unused BOOL *stop) {
7071       block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%llu", value]);
7072   }];
7075 - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(int64_t)key {
7076   NSNumber *wrapped = [_dictionary objectForKey:@(key)];
7077   if (wrapped && value) {
7078     *value = [wrapped unsignedLongLongValue];
7079   }
7080   return (wrapped != NULL);
7083 - (void)addEntriesFromDictionary:(GPBInt64UInt64Dictionary *)otherDictionary {
7084   if (otherDictionary) {
7085     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
7086     if (_autocreator) {
7087       GPBAutocreatedDictionaryModified(_autocreator, self);
7088     }
7089   }
7092 - (void)setUInt64:(uint64_t)value forKey:(int64_t)key {
7093   [_dictionary setObject:@(value) forKey:@(key)];
7094   if (_autocreator) {
7095     GPBAutocreatedDictionaryModified(_autocreator, self);
7096   }
7099 - (void)removeUInt64ForKey:(int64_t)aKey {
7100   [_dictionary removeObjectForKey:@(aKey)];
7103 - (void)removeAll {
7104   [_dictionary removeAllObjects];
7107 @end
7109 #pragma mark - Int64 -> Int64
7111 @implementation GPBInt64Int64Dictionary {
7112  @package
7113   NSMutableDictionary *_dictionary;
7116 - (instancetype)init {
7117   return [self initWithInt64s:NULL forKeys:NULL count:0];
7120 - (instancetype)initWithInt64s:(const int64_t [])values
7121                        forKeys:(const int64_t [])keys
7122                          count:(NSUInteger)count {
7123   self = [super init];
7124   if (self) {
7125     _dictionary = [[NSMutableDictionary alloc] init];
7126     if (count && values && keys) {
7127       for (NSUInteger i = 0; i < count; ++i) {
7128         [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
7129       }
7130     }
7131   }
7132   return self;
7135 - (instancetype)initWithDictionary:(GPBInt64Int64Dictionary *)dictionary {
7136   self = [self initWithInt64s:NULL forKeys:NULL count:0];
7137   if (self) {
7138     if (dictionary) {
7139       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
7140     }
7141   }
7142   return self;
7145 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
7146   return [self initWithInt64s:NULL forKeys:NULL count:0];
7149 - (void)dealloc {
7150   NSAssert(!_autocreator,
7151            @"%@: Autocreator must be cleared before release, autocreator: %@",
7152            [self class], _autocreator);
7153   [_dictionary release];
7154   [super dealloc];
7157 - (instancetype)copyWithZone:(NSZone *)zone {
7158   return [[GPBInt64Int64Dictionary allocWithZone:zone] initWithDictionary:self];
7161 - (BOOL)isEqual:(id)other {
7162   if (self == other) {
7163     return YES;
7164   }
7165   if (![other isKindOfClass:[GPBInt64Int64Dictionary class]]) {
7166     return NO;
7167   }
7168   GPBInt64Int64Dictionary *otherDictionary = other;
7169   return [_dictionary isEqual:otherDictionary->_dictionary];
7172 - (NSUInteger)hash {
7173   return _dictionary.count;
7176 - (NSString *)description {
7177   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
7180 - (NSUInteger)count {
7181   return _dictionary.count;
7184 - (void)enumerateKeysAndInt64sUsingBlock:
7185     (void (NS_NOESCAPE ^)(int64_t key, int64_t value, BOOL *stop))block {
7186   BOOL stop = NO;
7187   NSDictionary *internal = _dictionary;
7188   NSEnumerator *keys = [internal keyEnumerator];
7189   NSNumber *aKey;
7190   while ((aKey = [keys nextObject])) {
7191     NSNumber *aValue = internal[aKey];
7192     block([aKey longLongValue], [aValue longLongValue], &stop);
7193     if (stop) {
7194       break;
7195     }
7196   }
7199 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
7200   NSDictionary *internal = _dictionary;
7201   NSUInteger count = internal.count;
7202   if (count == 0) {
7203     return 0;
7204   }
7206   GPBDataType valueDataType = GPBGetFieldDataType(field);
7207   GPBDataType keyDataType = field.mapKeyDataType;
7208   size_t result = 0;
7209   NSEnumerator *keys = [internal keyEnumerator];
7210   NSNumber *aKey;
7211   while ((aKey = [keys nextObject])) {
7212     NSNumber *aValue = internal[aKey];
7213     size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
7214     msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
7215     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
7216   }
7217   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
7218   result += tagSize * count;
7219   return result;
7222 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
7223                          asField:(GPBFieldDescriptor *)field {
7224   GPBDataType valueDataType = GPBGetFieldDataType(field);
7225   GPBDataType keyDataType = field.mapKeyDataType;
7226   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
7227   NSDictionary *internal = _dictionary;
7228   NSEnumerator *keys = [internal keyEnumerator];
7229   NSNumber *aKey;
7230   while ((aKey = [keys nextObject])) {
7231     NSNumber *aValue = internal[aKey];
7232     [outputStream writeInt32NoTag:tag];
7233     // Write the size of the message.
7234     int64_t unwrappedKey = [aKey longLongValue];
7235     int64_t unwrappedValue = [aValue longLongValue];
7236     size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
7237     msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
7238     [outputStream writeInt32NoTag:(int32_t)msgSize];
7239     // Write the fields.
7240     WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
7241     WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
7242   }
7245 - (void)setGPBGenericValue:(GPBGenericValue *)value
7246      forGPBGenericValueKey:(GPBGenericValue *)key {
7247   [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueInt64)];
7250 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
7251   [self enumerateKeysAndInt64sUsingBlock:^(int64_t key, int64_t value, __unused BOOL *stop) {
7252       block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%lld", value]);
7253   }];
7256 - (BOOL)getInt64:(nullable int64_t *)value forKey:(int64_t)key {
7257   NSNumber *wrapped = [_dictionary objectForKey:@(key)];
7258   if (wrapped && value) {
7259     *value = [wrapped longLongValue];
7260   }
7261   return (wrapped != NULL);
7264 - (void)addEntriesFromDictionary:(GPBInt64Int64Dictionary *)otherDictionary {
7265   if (otherDictionary) {
7266     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
7267     if (_autocreator) {
7268       GPBAutocreatedDictionaryModified(_autocreator, self);
7269     }
7270   }
7273 - (void)setInt64:(int64_t)value forKey:(int64_t)key {
7274   [_dictionary setObject:@(value) forKey:@(key)];
7275   if (_autocreator) {
7276     GPBAutocreatedDictionaryModified(_autocreator, self);
7277   }
7280 - (void)removeInt64ForKey:(int64_t)aKey {
7281   [_dictionary removeObjectForKey:@(aKey)];
7284 - (void)removeAll {
7285   [_dictionary removeAllObjects];
7288 @end
7290 #pragma mark - Int64 -> Bool
7292 @implementation GPBInt64BoolDictionary {
7293  @package
7294   NSMutableDictionary *_dictionary;
7297 - (instancetype)init {
7298   return [self initWithBools:NULL forKeys:NULL count:0];
7301 - (instancetype)initWithBools:(const BOOL [])values
7302                       forKeys:(const int64_t [])keys
7303                         count:(NSUInteger)count {
7304   self = [super init];
7305   if (self) {
7306     _dictionary = [[NSMutableDictionary alloc] init];
7307     if (count && values && keys) {
7308       for (NSUInteger i = 0; i < count; ++i) {
7309         [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
7310       }
7311     }
7312   }
7313   return self;
7316 - (instancetype)initWithDictionary:(GPBInt64BoolDictionary *)dictionary {
7317   self = [self initWithBools:NULL forKeys:NULL count:0];
7318   if (self) {
7319     if (dictionary) {
7320       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
7321     }
7322   }
7323   return self;
7326 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
7327   return [self initWithBools:NULL forKeys:NULL count:0];
7330 - (void)dealloc {
7331   NSAssert(!_autocreator,
7332            @"%@: Autocreator must be cleared before release, autocreator: %@",
7333            [self class], _autocreator);
7334   [_dictionary release];
7335   [super dealloc];
7338 - (instancetype)copyWithZone:(NSZone *)zone {
7339   return [[GPBInt64BoolDictionary allocWithZone:zone] initWithDictionary:self];
7342 - (BOOL)isEqual:(id)other {
7343   if (self == other) {
7344     return YES;
7345   }
7346   if (![other isKindOfClass:[GPBInt64BoolDictionary class]]) {
7347     return NO;
7348   }
7349   GPBInt64BoolDictionary *otherDictionary = other;
7350   return [_dictionary isEqual:otherDictionary->_dictionary];
7353 - (NSUInteger)hash {
7354   return _dictionary.count;
7357 - (NSString *)description {
7358   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
7361 - (NSUInteger)count {
7362   return _dictionary.count;
7365 - (void)enumerateKeysAndBoolsUsingBlock:
7366     (void (NS_NOESCAPE ^)(int64_t key, BOOL value, BOOL *stop))block {
7367   BOOL stop = NO;
7368   NSDictionary *internal = _dictionary;
7369   NSEnumerator *keys = [internal keyEnumerator];
7370   NSNumber *aKey;
7371   while ((aKey = [keys nextObject])) {
7372     NSNumber *aValue = internal[aKey];
7373     block([aKey longLongValue], [aValue boolValue], &stop);
7374     if (stop) {
7375       break;
7376     }
7377   }
7380 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
7381   NSDictionary *internal = _dictionary;
7382   NSUInteger count = internal.count;
7383   if (count == 0) {
7384     return 0;
7385   }
7387   GPBDataType valueDataType = GPBGetFieldDataType(field);
7388   GPBDataType keyDataType = field.mapKeyDataType;
7389   size_t result = 0;
7390   NSEnumerator *keys = [internal keyEnumerator];
7391   NSNumber *aKey;
7392   while ((aKey = [keys nextObject])) {
7393     NSNumber *aValue = internal[aKey];
7394     size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
7395     msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
7396     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
7397   }
7398   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
7399   result += tagSize * count;
7400   return result;
7403 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
7404                          asField:(GPBFieldDescriptor *)field {
7405   GPBDataType valueDataType = GPBGetFieldDataType(field);
7406   GPBDataType keyDataType = field.mapKeyDataType;
7407   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
7408   NSDictionary *internal = _dictionary;
7409   NSEnumerator *keys = [internal keyEnumerator];
7410   NSNumber *aKey;
7411   while ((aKey = [keys nextObject])) {
7412     NSNumber *aValue = internal[aKey];
7413     [outputStream writeInt32NoTag:tag];
7414     // Write the size of the message.
7415     int64_t unwrappedKey = [aKey longLongValue];
7416     BOOL unwrappedValue = [aValue boolValue];
7417     size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
7418     msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
7419     [outputStream writeInt32NoTag:(int32_t)msgSize];
7420     // Write the fields.
7421     WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
7422     WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
7423   }
7426 - (void)setGPBGenericValue:(GPBGenericValue *)value
7427      forGPBGenericValueKey:(GPBGenericValue *)key {
7428   [_dictionary setObject:@(value->valueBool) forKey:@(key->valueInt64)];
7431 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
7432   [self enumerateKeysAndBoolsUsingBlock:^(int64_t key, BOOL value, __unused BOOL *stop) {
7433       block([NSString stringWithFormat:@"%lld", key], (value ? @"true" : @"false"));
7434   }];
7437 - (BOOL)getBool:(nullable BOOL *)value forKey:(int64_t)key {
7438   NSNumber *wrapped = [_dictionary objectForKey:@(key)];
7439   if (wrapped && value) {
7440     *value = [wrapped boolValue];
7441   }
7442   return (wrapped != NULL);
7445 - (void)addEntriesFromDictionary:(GPBInt64BoolDictionary *)otherDictionary {
7446   if (otherDictionary) {
7447     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
7448     if (_autocreator) {
7449       GPBAutocreatedDictionaryModified(_autocreator, self);
7450     }
7451   }
7454 - (void)setBool:(BOOL)value forKey:(int64_t)key {
7455   [_dictionary setObject:@(value) forKey:@(key)];
7456   if (_autocreator) {
7457     GPBAutocreatedDictionaryModified(_autocreator, self);
7458   }
7461 - (void)removeBoolForKey:(int64_t)aKey {
7462   [_dictionary removeObjectForKey:@(aKey)];
7465 - (void)removeAll {
7466   [_dictionary removeAllObjects];
7469 @end
7471 #pragma mark - Int64 -> Float
7473 @implementation GPBInt64FloatDictionary {
7474  @package
7475   NSMutableDictionary *_dictionary;
7478 - (instancetype)init {
7479   return [self initWithFloats:NULL forKeys:NULL count:0];
7482 - (instancetype)initWithFloats:(const float [])values
7483                        forKeys:(const int64_t [])keys
7484                          count:(NSUInteger)count {
7485   self = [super init];
7486   if (self) {
7487     _dictionary = [[NSMutableDictionary alloc] init];
7488     if (count && values && keys) {
7489       for (NSUInteger i = 0; i < count; ++i) {
7490         [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
7491       }
7492     }
7493   }
7494   return self;
7497 - (instancetype)initWithDictionary:(GPBInt64FloatDictionary *)dictionary {
7498   self = [self initWithFloats:NULL forKeys:NULL count:0];
7499   if (self) {
7500     if (dictionary) {
7501       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
7502     }
7503   }
7504   return self;
7507 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
7508   return [self initWithFloats:NULL forKeys:NULL count:0];
7511 - (void)dealloc {
7512   NSAssert(!_autocreator,
7513            @"%@: Autocreator must be cleared before release, autocreator: %@",
7514            [self class], _autocreator);
7515   [_dictionary release];
7516   [super dealloc];
7519 - (instancetype)copyWithZone:(NSZone *)zone {
7520   return [[GPBInt64FloatDictionary allocWithZone:zone] initWithDictionary:self];
7523 - (BOOL)isEqual:(id)other {
7524   if (self == other) {
7525     return YES;
7526   }
7527   if (![other isKindOfClass:[GPBInt64FloatDictionary class]]) {
7528     return NO;
7529   }
7530   GPBInt64FloatDictionary *otherDictionary = other;
7531   return [_dictionary isEqual:otherDictionary->_dictionary];
7534 - (NSUInteger)hash {
7535   return _dictionary.count;
7538 - (NSString *)description {
7539   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
7542 - (NSUInteger)count {
7543   return _dictionary.count;
7546 - (void)enumerateKeysAndFloatsUsingBlock:
7547     (void (NS_NOESCAPE ^)(int64_t key, float value, BOOL *stop))block {
7548   BOOL stop = NO;
7549   NSDictionary *internal = _dictionary;
7550   NSEnumerator *keys = [internal keyEnumerator];
7551   NSNumber *aKey;
7552   while ((aKey = [keys nextObject])) {
7553     NSNumber *aValue = internal[aKey];
7554     block([aKey longLongValue], [aValue floatValue], &stop);
7555     if (stop) {
7556       break;
7557     }
7558   }
7561 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
7562   NSDictionary *internal = _dictionary;
7563   NSUInteger count = internal.count;
7564   if (count == 0) {
7565     return 0;
7566   }
7568   GPBDataType valueDataType = GPBGetFieldDataType(field);
7569   GPBDataType keyDataType = field.mapKeyDataType;
7570   size_t result = 0;
7571   NSEnumerator *keys = [internal keyEnumerator];
7572   NSNumber *aKey;
7573   while ((aKey = [keys nextObject])) {
7574     NSNumber *aValue = internal[aKey];
7575     size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
7576     msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
7577     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
7578   }
7579   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
7580   result += tagSize * count;
7581   return result;
7584 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
7585                          asField:(GPBFieldDescriptor *)field {
7586   GPBDataType valueDataType = GPBGetFieldDataType(field);
7587   GPBDataType keyDataType = field.mapKeyDataType;
7588   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
7589   NSDictionary *internal = _dictionary;
7590   NSEnumerator *keys = [internal keyEnumerator];
7591   NSNumber *aKey;
7592   while ((aKey = [keys nextObject])) {
7593     NSNumber *aValue = internal[aKey];
7594     [outputStream writeInt32NoTag:tag];
7595     // Write the size of the message.
7596     int64_t unwrappedKey = [aKey longLongValue];
7597     float unwrappedValue = [aValue floatValue];
7598     size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
7599     msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
7600     [outputStream writeInt32NoTag:(int32_t)msgSize];
7601     // Write the fields.
7602     WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
7603     WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
7604   }
7607 - (void)setGPBGenericValue:(GPBGenericValue *)value
7608      forGPBGenericValueKey:(GPBGenericValue *)key {
7609   [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueInt64)];
7612 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
7613   [self enumerateKeysAndFloatsUsingBlock:^(int64_t key, float value, __unused BOOL *stop) {
7614       block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
7615   }];
7618 - (BOOL)getFloat:(nullable float *)value forKey:(int64_t)key {
7619   NSNumber *wrapped = [_dictionary objectForKey:@(key)];
7620   if (wrapped && value) {
7621     *value = [wrapped floatValue];
7622   }
7623   return (wrapped != NULL);
7626 - (void)addEntriesFromDictionary:(GPBInt64FloatDictionary *)otherDictionary {
7627   if (otherDictionary) {
7628     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
7629     if (_autocreator) {
7630       GPBAutocreatedDictionaryModified(_autocreator, self);
7631     }
7632   }
7635 - (void)setFloat:(float)value forKey:(int64_t)key {
7636   [_dictionary setObject:@(value) forKey:@(key)];
7637   if (_autocreator) {
7638     GPBAutocreatedDictionaryModified(_autocreator, self);
7639   }
7642 - (void)removeFloatForKey:(int64_t)aKey {
7643   [_dictionary removeObjectForKey:@(aKey)];
7646 - (void)removeAll {
7647   [_dictionary removeAllObjects];
7650 @end
7652 #pragma mark - Int64 -> Double
7654 @implementation GPBInt64DoubleDictionary {
7655  @package
7656   NSMutableDictionary *_dictionary;
7659 - (instancetype)init {
7660   return [self initWithDoubles:NULL forKeys:NULL count:0];
7663 - (instancetype)initWithDoubles:(const double [])values
7664                         forKeys:(const int64_t [])keys
7665                           count:(NSUInteger)count {
7666   self = [super init];
7667   if (self) {
7668     _dictionary = [[NSMutableDictionary alloc] init];
7669     if (count && values && keys) {
7670       for (NSUInteger i = 0; i < count; ++i) {
7671         [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
7672       }
7673     }
7674   }
7675   return self;
7678 - (instancetype)initWithDictionary:(GPBInt64DoubleDictionary *)dictionary {
7679   self = [self initWithDoubles:NULL forKeys:NULL count:0];
7680   if (self) {
7681     if (dictionary) {
7682       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
7683     }
7684   }
7685   return self;
7688 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
7689   return [self initWithDoubles:NULL forKeys:NULL count:0];
7692 - (void)dealloc {
7693   NSAssert(!_autocreator,
7694            @"%@: Autocreator must be cleared before release, autocreator: %@",
7695            [self class], _autocreator);
7696   [_dictionary release];
7697   [super dealloc];
7700 - (instancetype)copyWithZone:(NSZone *)zone {
7701   return [[GPBInt64DoubleDictionary allocWithZone:zone] initWithDictionary:self];
7704 - (BOOL)isEqual:(id)other {
7705   if (self == other) {
7706     return YES;
7707   }
7708   if (![other isKindOfClass:[GPBInt64DoubleDictionary class]]) {
7709     return NO;
7710   }
7711   GPBInt64DoubleDictionary *otherDictionary = other;
7712   return [_dictionary isEqual:otherDictionary->_dictionary];
7715 - (NSUInteger)hash {
7716   return _dictionary.count;
7719 - (NSString *)description {
7720   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
7723 - (NSUInteger)count {
7724   return _dictionary.count;
7727 - (void)enumerateKeysAndDoublesUsingBlock:
7728     (void (NS_NOESCAPE ^)(int64_t key, double value, BOOL *stop))block {
7729   BOOL stop = NO;
7730   NSDictionary *internal = _dictionary;
7731   NSEnumerator *keys = [internal keyEnumerator];
7732   NSNumber *aKey;
7733   while ((aKey = [keys nextObject])) {
7734     NSNumber *aValue = internal[aKey];
7735     block([aKey longLongValue], [aValue doubleValue], &stop);
7736     if (stop) {
7737       break;
7738     }
7739   }
7742 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
7743   NSDictionary *internal = _dictionary;
7744   NSUInteger count = internal.count;
7745   if (count == 0) {
7746     return 0;
7747   }
7749   GPBDataType valueDataType = GPBGetFieldDataType(field);
7750   GPBDataType keyDataType = field.mapKeyDataType;
7751   size_t result = 0;
7752   NSEnumerator *keys = [internal keyEnumerator];
7753   NSNumber *aKey;
7754   while ((aKey = [keys nextObject])) {
7755     NSNumber *aValue = internal[aKey];
7756     size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
7757     msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
7758     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
7759   }
7760   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
7761   result += tagSize * count;
7762   return result;
7765 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
7766                          asField:(GPBFieldDescriptor *)field {
7767   GPBDataType valueDataType = GPBGetFieldDataType(field);
7768   GPBDataType keyDataType = field.mapKeyDataType;
7769   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
7770   NSDictionary *internal = _dictionary;
7771   NSEnumerator *keys = [internal keyEnumerator];
7772   NSNumber *aKey;
7773   while ((aKey = [keys nextObject])) {
7774     NSNumber *aValue = internal[aKey];
7775     [outputStream writeInt32NoTag:tag];
7776     // Write the size of the message.
7777     int64_t unwrappedKey = [aKey longLongValue];
7778     double unwrappedValue = [aValue doubleValue];
7779     size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
7780     msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
7781     [outputStream writeInt32NoTag:(int32_t)msgSize];
7782     // Write the fields.
7783     WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
7784     WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
7785   }
7788 - (void)setGPBGenericValue:(GPBGenericValue *)value
7789      forGPBGenericValueKey:(GPBGenericValue *)key {
7790   [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueInt64)];
7793 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
7794   [self enumerateKeysAndDoublesUsingBlock:^(int64_t key, double value, __unused BOOL *stop) {
7795       block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
7796   }];
7799 - (BOOL)getDouble:(nullable double *)value forKey:(int64_t)key {
7800   NSNumber *wrapped = [_dictionary objectForKey:@(key)];
7801   if (wrapped && value) {
7802     *value = [wrapped doubleValue];
7803   }
7804   return (wrapped != NULL);
7807 - (void)addEntriesFromDictionary:(GPBInt64DoubleDictionary *)otherDictionary {
7808   if (otherDictionary) {
7809     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
7810     if (_autocreator) {
7811       GPBAutocreatedDictionaryModified(_autocreator, self);
7812     }
7813   }
7816 - (void)setDouble:(double)value forKey:(int64_t)key {
7817   [_dictionary setObject:@(value) forKey:@(key)];
7818   if (_autocreator) {
7819     GPBAutocreatedDictionaryModified(_autocreator, self);
7820   }
7823 - (void)removeDoubleForKey:(int64_t)aKey {
7824   [_dictionary removeObjectForKey:@(aKey)];
7827 - (void)removeAll {
7828   [_dictionary removeAllObjects];
7831 @end
7833 #pragma mark - Int64 -> Enum
7835 @implementation GPBInt64EnumDictionary {
7836  @package
7837   NSMutableDictionary *_dictionary;
7838   GPBEnumValidationFunc _validationFunc;
7841 @synthesize validationFunc = _validationFunc;
7843 - (instancetype)init {
7844   return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
7847 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
7848   return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
7851 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
7852                                  rawValues:(const int32_t [])rawValues
7853                                    forKeys:(const int64_t [])keys
7854                                      count:(NSUInteger)count {
7855   self = [super init];
7856   if (self) {
7857     _dictionary = [[NSMutableDictionary alloc] init];
7858     _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
7859     if (count && rawValues && keys) {
7860       for (NSUInteger i = 0; i < count; ++i) {
7861         [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])];
7862       }
7863     }
7864   }
7865   return self;
7868 - (instancetype)initWithDictionary:(GPBInt64EnumDictionary *)dictionary {
7869   self = [self initWithValidationFunction:dictionary.validationFunc
7870                                 rawValues:NULL
7871                                   forKeys:NULL
7872                                     count:0];
7873   if (self) {
7874     if (dictionary) {
7875       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
7876     }
7877   }
7878   return self;
7881 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
7882                                   capacity:(__unused NSUInteger)numItems {
7883   return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
7886 - (void)dealloc {
7887   NSAssert(!_autocreator,
7888            @"%@: Autocreator must be cleared before release, autocreator: %@",
7889            [self class], _autocreator);
7890   [_dictionary release];
7891   [super dealloc];
7894 - (instancetype)copyWithZone:(NSZone *)zone {
7895   return [[GPBInt64EnumDictionary allocWithZone:zone] initWithDictionary:self];
7898 - (BOOL)isEqual:(id)other {
7899   if (self == other) {
7900     return YES;
7901   }
7902   if (![other isKindOfClass:[GPBInt64EnumDictionary class]]) {
7903     return NO;
7904   }
7905   GPBInt64EnumDictionary *otherDictionary = other;
7906   return [_dictionary isEqual:otherDictionary->_dictionary];
7909 - (NSUInteger)hash {
7910   return _dictionary.count;
7913 - (NSString *)description {
7914   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
7917 - (NSUInteger)count {
7918   return _dictionary.count;
7921 - (void)enumerateKeysAndRawValuesUsingBlock:
7922     (void (NS_NOESCAPE ^)(int64_t key, int32_t value, BOOL *stop))block {
7923   BOOL stop = NO;
7924   NSDictionary *internal = _dictionary;
7925   NSEnumerator *keys = [internal keyEnumerator];
7926   NSNumber *aKey;
7927   while ((aKey = [keys nextObject])) {
7928     NSNumber *aValue = internal[aKey];
7929     block([aKey longLongValue], [aValue intValue], &stop);
7930     if (stop) {
7931       break;
7932     }
7933   }
7936 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
7937   NSDictionary *internal = _dictionary;
7938   NSUInteger count = internal.count;
7939   if (count == 0) {
7940     return 0;
7941   }
7943   GPBDataType valueDataType = GPBGetFieldDataType(field);
7944   GPBDataType keyDataType = field.mapKeyDataType;
7945   size_t result = 0;
7946   NSEnumerator *keys = [internal keyEnumerator];
7947   NSNumber *aKey;
7948   while ((aKey = [keys nextObject])) {
7949     NSNumber *aValue = internal[aKey];
7950     size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
7951     msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
7952     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
7953   }
7954   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
7955   result += tagSize * count;
7956   return result;
7959 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
7960                          asField:(GPBFieldDescriptor *)field {
7961   GPBDataType valueDataType = GPBGetFieldDataType(field);
7962   GPBDataType keyDataType = field.mapKeyDataType;
7963   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
7964   NSDictionary *internal = _dictionary;
7965   NSEnumerator *keys = [internal keyEnumerator];
7966   NSNumber *aKey;
7967   while ((aKey = [keys nextObject])) {
7968     NSNumber *aValue = internal[aKey];
7969     [outputStream writeInt32NoTag:tag];
7970     // Write the size of the message.
7971     int64_t unwrappedKey = [aKey longLongValue];
7972     int32_t unwrappedValue = [aValue intValue];
7973     size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
7974     msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
7975     [outputStream writeInt32NoTag:(int32_t)msgSize];
7976     // Write the fields.
7977     WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
7978     WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
7979   }
7982 - (NSData *)serializedDataForUnknownValue:(int32_t)value
7983                                    forKey:(GPBGenericValue *)key
7984                               keyDataType:(GPBDataType)keyDataType {
7985   size_t msgSize = ComputeDictInt64FieldSize(key->valueInt64, kMapKeyFieldNumber, keyDataType);
7986   msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
7987   NSMutableData *data = [NSMutableData dataWithLength:msgSize];
7988   GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
7989   WriteDictInt64Field(outputStream, key->valueInt64, kMapKeyFieldNumber, keyDataType);
7990   WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
7991   [outputStream flush];
7992   [outputStream release];
7993   return data;
7995 - (void)setGPBGenericValue:(GPBGenericValue *)value
7996      forGPBGenericValueKey:(GPBGenericValue *)key {
7997   [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueInt64)];
8000 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
8001   [self enumerateKeysAndRawValuesUsingBlock:^(int64_t key, int32_t value, __unused BOOL *stop) {
8002       block([NSString stringWithFormat:@"%lld", key], @(value));
8003   }];
8006 - (BOOL)getEnum:(int32_t *)value forKey:(int64_t)key {
8007   NSNumber *wrapped = [_dictionary objectForKey:@(key)];
8008   if (wrapped && value) {
8009     int32_t result = [wrapped intValue];
8010     if (!_validationFunc(result)) {
8011       result = kGPBUnrecognizedEnumeratorValue;
8012     }
8013     *value = result;
8014   }
8015   return (wrapped != NULL);
8018 - (BOOL)getRawValue:(int32_t *)rawValue forKey:(int64_t)key {
8019   NSNumber *wrapped = [_dictionary objectForKey:@(key)];
8020   if (wrapped && rawValue) {
8021     *rawValue = [wrapped intValue];
8022   }
8023   return (wrapped != NULL);
8026 - (void)enumerateKeysAndEnumsUsingBlock:
8027     (void (NS_NOESCAPE ^)(int64_t key, int32_t value, BOOL *stop))block {
8028   GPBEnumValidationFunc func = _validationFunc;
8029   BOOL stop = NO;
8030   NSEnumerator *keys = [_dictionary keyEnumerator];
8031   NSNumber *aKey;
8032   while ((aKey = [keys nextObject])) {
8033     NSNumber *aValue = _dictionary[aKey];
8034       int32_t unwrapped = [aValue intValue];
8035       if (!func(unwrapped)) {
8036         unwrapped = kGPBUnrecognizedEnumeratorValue;
8037       }
8038     block([aKey longLongValue], unwrapped, &stop);
8039     if (stop) {
8040       break;
8041     }
8042   }
8045 - (void)addRawEntriesFromDictionary:(GPBInt64EnumDictionary *)otherDictionary {
8046   if (otherDictionary) {
8047     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
8048     if (_autocreator) {
8049       GPBAutocreatedDictionaryModified(_autocreator, self);
8050     }
8051   }
8054 - (void)setRawValue:(int32_t)value forKey:(int64_t)key {
8055   [_dictionary setObject:@(value) forKey:@(key)];
8056   if (_autocreator) {
8057     GPBAutocreatedDictionaryModified(_autocreator, self);
8058   }
8061 - (void)removeEnumForKey:(int64_t)aKey {
8062   [_dictionary removeObjectForKey:@(aKey)];
8065 - (void)removeAll {
8066   [_dictionary removeAllObjects];
8069 - (void)setEnum:(int32_t)value forKey:(int64_t)key {
8070   if (!_validationFunc(value)) {
8071     [NSException raise:NSInvalidArgumentException
8072                 format:@"GPBInt64EnumDictionary: Attempt to set an unknown enum value (%d)",
8073                        value];
8074   }
8076   [_dictionary setObject:@(value) forKey:@(key)];
8077   if (_autocreator) {
8078     GPBAutocreatedDictionaryModified(_autocreator, self);
8079   }
8082 @end
8084 #pragma mark - Int64 -> Object
8086 @implementation GPBInt64ObjectDictionary {
8087  @package
8088   NSMutableDictionary *_dictionary;
8091 - (instancetype)init {
8092   return [self initWithObjects:NULL forKeys:NULL count:0];
8095 - (instancetype)initWithObjects:(const id [])objects
8096                         forKeys:(const int64_t [])keys
8097                           count:(NSUInteger)count {
8098   self = [super init];
8099   if (self) {
8100     _dictionary = [[NSMutableDictionary alloc] init];
8101     if (count && objects && keys) {
8102       for (NSUInteger i = 0; i < count; ++i) {
8103         if (!objects[i]) {
8104           [NSException raise:NSInvalidArgumentException
8105                       format:@"Attempting to add nil object to a Dictionary"];
8106         }
8107         [_dictionary setObject:objects[i] forKey:@(keys[i])];
8108       }
8109     }
8110   }
8111   return self;
8114 - (instancetype)initWithDictionary:(GPBInt64ObjectDictionary *)dictionary {
8115   self = [self initWithObjects:NULL forKeys:NULL count:0];
8116   if (self) {
8117     if (dictionary) {
8118       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
8119     }
8120   }
8121   return self;
8124 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
8125   return [self initWithObjects:NULL forKeys:NULL count:0];
8128 - (void)dealloc {
8129   NSAssert(!_autocreator,
8130            @"%@: Autocreator must be cleared before release, autocreator: %@",
8131            [self class], _autocreator);
8132   [_dictionary release];
8133   [super dealloc];
8136 - (instancetype)copyWithZone:(NSZone *)zone {
8137   return [[GPBInt64ObjectDictionary allocWithZone:zone] initWithDictionary:self];
8140 - (BOOL)isEqual:(id)other {
8141   if (self == other) {
8142     return YES;
8143   }
8144   if (![other isKindOfClass:[GPBInt64ObjectDictionary class]]) {
8145     return NO;
8146   }
8147   GPBInt64ObjectDictionary *otherDictionary = other;
8148   return [_dictionary isEqual:otherDictionary->_dictionary];
8151 - (NSUInteger)hash {
8152   return _dictionary.count;
8155 - (NSString *)description {
8156   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
8159 - (NSUInteger)count {
8160   return _dictionary.count;
8163 - (void)enumerateKeysAndObjectsUsingBlock:
8164     (void (NS_NOESCAPE ^)(int64_t key, id object, BOOL *stop))block {
8165   BOOL stop = NO;
8166   NSDictionary *internal = _dictionary;
8167   NSEnumerator *keys = [internal keyEnumerator];
8168   NSNumber *aKey;
8169   while ((aKey = [keys nextObject])) {
8170     id aObject = internal[aKey];
8171     block([aKey longLongValue], aObject, &stop);
8172     if (stop) {
8173       break;
8174     }
8175   }
8178 - (BOOL)isInitialized {
8179   for (GPBMessage *msg in [_dictionary objectEnumerator]) {
8180     if (!msg.initialized) {
8181       return NO;
8182     }
8183   }
8184   return YES;
8187 - (instancetype)deepCopyWithZone:(NSZone *)zone {
8188   GPBInt64ObjectDictionary *newDict =
8189       [[GPBInt64ObjectDictionary alloc] init];
8190   NSEnumerator *keys = [_dictionary keyEnumerator];
8191   id aKey;
8192   NSMutableDictionary *internalDict = newDict->_dictionary;
8193   while ((aKey = [keys nextObject])) {
8194     GPBMessage *msg = _dictionary[aKey];
8195     GPBMessage *copiedMsg = [msg copyWithZone:zone];
8196     [internalDict setObject:copiedMsg forKey:aKey];
8197     [copiedMsg release];
8198   }
8199   return newDict;
8202 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
8203   NSDictionary *internal = _dictionary;
8204   NSUInteger count = internal.count;
8205   if (count == 0) {
8206     return 0;
8207   }
8209   GPBDataType valueDataType = GPBGetFieldDataType(field);
8210   GPBDataType keyDataType = field.mapKeyDataType;
8211   size_t result = 0;
8212   NSEnumerator *keys = [internal keyEnumerator];
8213   NSNumber *aKey;
8214   while ((aKey = [keys nextObject])) {
8215     id aObject = internal[aKey];
8216     size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
8217     msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
8218     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
8219   }
8220   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
8221   result += tagSize * count;
8222   return result;
8225 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
8226                          asField:(GPBFieldDescriptor *)field {
8227   GPBDataType valueDataType = GPBGetFieldDataType(field);
8228   GPBDataType keyDataType = field.mapKeyDataType;
8229   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
8230   NSDictionary *internal = _dictionary;
8231   NSEnumerator *keys = [internal keyEnumerator];
8232   NSNumber *aKey;
8233   while ((aKey = [keys nextObject])) {
8234     id aObject = internal[aKey];
8235     [outputStream writeInt32NoTag:tag];
8236     // Write the size of the message.
8237     int64_t unwrappedKey = [aKey longLongValue];
8238     id unwrappedValue = aObject;
8239     size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
8240     msgSize += ComputeDictObjectFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
8241     [outputStream writeInt32NoTag:(int32_t)msgSize];
8242     // Write the fields.
8243     WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
8244     WriteDictObjectField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
8245   }
8248 - (void)setGPBGenericValue:(GPBGenericValue *)value
8249      forGPBGenericValueKey:(GPBGenericValue *)key {
8250   [_dictionary setObject:value->valueString forKey:@(key->valueInt64)];
8253 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
8254   [self enumerateKeysAndObjectsUsingBlock:^(int64_t key, id object, __unused BOOL *stop) {
8255       block([NSString stringWithFormat:@"%lld", key], object);
8256   }];
8259 - (id)objectForKey:(int64_t)key {
8260   id result = [_dictionary objectForKey:@(key)];
8261   return result;
8264 - (void)addEntriesFromDictionary:(GPBInt64ObjectDictionary *)otherDictionary {
8265   if (otherDictionary) {
8266     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
8267     if (_autocreator) {
8268       GPBAutocreatedDictionaryModified(_autocreator, self);
8269     }
8270   }
8273 - (void)setObject:(id)object forKey:(int64_t)key {
8274   if (!object) {
8275     [NSException raise:NSInvalidArgumentException
8276                 format:@"Attempting to add nil object to a Dictionary"];
8277   }
8278   [_dictionary setObject:object forKey:@(key)];
8279   if (_autocreator) {
8280     GPBAutocreatedDictionaryModified(_autocreator, self);
8281   }
8284 - (void)removeObjectForKey:(int64_t)aKey {
8285   [_dictionary removeObjectForKey:@(aKey)];
8288 - (void)removeAll {
8289   [_dictionary removeAllObjects];
8292 @end
8294 //%PDDM-EXPAND DICTIONARY_POD_IMPL_FOR_KEY(String, NSString, *, OBJECT)
8295 // This block of code is generated, do not edit it directly.
8297 #pragma mark - String -> UInt32
8299 @implementation GPBStringUInt32Dictionary {
8300  @package
8301   NSMutableDictionary *_dictionary;
8304 - (instancetype)init {
8305   return [self initWithUInt32s:NULL forKeys:NULL count:0];
8308 - (instancetype)initWithUInt32s:(const uint32_t [])values
8309                         forKeys:(const NSString * [])keys
8310                           count:(NSUInteger)count {
8311   self = [super init];
8312   if (self) {
8313     _dictionary = [[NSMutableDictionary alloc] init];
8314     if (count && values && keys) {
8315       for (NSUInteger i = 0; i < count; ++i) {
8316         if (!keys[i]) {
8317           [NSException raise:NSInvalidArgumentException
8318                       format:@"Attempting to add nil key to a Dictionary"];
8319         }
8320         [_dictionary setObject:@(values[i]) forKey:keys[i]];
8321       }
8322     }
8323   }
8324   return self;
8327 - (instancetype)initWithDictionary:(GPBStringUInt32Dictionary *)dictionary {
8328   self = [self initWithUInt32s:NULL forKeys:NULL count:0];
8329   if (self) {
8330     if (dictionary) {
8331       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
8332     }
8333   }
8334   return self;
8337 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
8338   return [self initWithUInt32s:NULL forKeys:NULL count:0];
8341 - (void)dealloc {
8342   NSAssert(!_autocreator,
8343            @"%@: Autocreator must be cleared before release, autocreator: %@",
8344            [self class], _autocreator);
8345   [_dictionary release];
8346   [super dealloc];
8349 - (instancetype)copyWithZone:(NSZone *)zone {
8350   return [[GPBStringUInt32Dictionary allocWithZone:zone] initWithDictionary:self];
8353 - (BOOL)isEqual:(id)other {
8354   if (self == other) {
8355     return YES;
8356   }
8357   if (![other isKindOfClass:[GPBStringUInt32Dictionary class]]) {
8358     return NO;
8359   }
8360   GPBStringUInt32Dictionary *otherDictionary = other;
8361   return [_dictionary isEqual:otherDictionary->_dictionary];
8364 - (NSUInteger)hash {
8365   return _dictionary.count;
8368 - (NSString *)description {
8369   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
8372 - (NSUInteger)count {
8373   return _dictionary.count;
8376 - (void)enumerateKeysAndUInt32sUsingBlock:
8377     (void (NS_NOESCAPE ^)(NSString *key, uint32_t value, BOOL *stop))block {
8378   BOOL stop = NO;
8379   NSDictionary *internal = _dictionary;
8380   NSEnumerator *keys = [internal keyEnumerator];
8381   NSString *aKey;
8382   while ((aKey = [keys nextObject])) {
8383     NSNumber *aValue = internal[aKey];
8384     block(aKey, [aValue unsignedIntValue], &stop);
8385     if (stop) {
8386       break;
8387     }
8388   }
8391 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
8392   NSDictionary *internal = _dictionary;
8393   NSUInteger count = internal.count;
8394   if (count == 0) {
8395     return 0;
8396   }
8398   GPBDataType valueDataType = GPBGetFieldDataType(field);
8399   GPBDataType keyDataType = field.mapKeyDataType;
8400   size_t result = 0;
8401   NSEnumerator *keys = [internal keyEnumerator];
8402   NSString *aKey;
8403   while ((aKey = [keys nextObject])) {
8404     NSNumber *aValue = internal[aKey];
8405     size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
8406     msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
8407     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
8408   }
8409   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
8410   result += tagSize * count;
8411   return result;
8414 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
8415                          asField:(GPBFieldDescriptor *)field {
8416   GPBDataType valueDataType = GPBGetFieldDataType(field);
8417   GPBDataType keyDataType = field.mapKeyDataType;
8418   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
8419   NSDictionary *internal = _dictionary;
8420   NSEnumerator *keys = [internal keyEnumerator];
8421   NSString *aKey;
8422   while ((aKey = [keys nextObject])) {
8423     NSNumber *aValue = internal[aKey];
8424     [outputStream writeInt32NoTag:tag];
8425     // Write the size of the message.
8426     NSString *unwrappedKey = aKey;
8427     uint32_t unwrappedValue = [aValue unsignedIntValue];
8428     size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
8429     msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
8430     [outputStream writeInt32NoTag:(int32_t)msgSize];
8431     // Write the fields.
8432     WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
8433     WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
8434   }
8437 - (void)setGPBGenericValue:(GPBGenericValue *)value
8438      forGPBGenericValueKey:(GPBGenericValue *)key {
8439   [_dictionary setObject:@(value->valueUInt32) forKey:key->valueString];
8442 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
8443   [self enumerateKeysAndUInt32sUsingBlock:^(NSString *key, uint32_t value, __unused BOOL *stop) {
8444       block(key, [NSString stringWithFormat:@"%u", value]);
8445   }];
8448 - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(NSString *)key {
8449   NSNumber *wrapped = [_dictionary objectForKey:key];
8450   if (wrapped && value) {
8451     *value = [wrapped unsignedIntValue];
8452   }
8453   return (wrapped != NULL);
8456 - (void)addEntriesFromDictionary:(GPBStringUInt32Dictionary *)otherDictionary {
8457   if (otherDictionary) {
8458     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
8459     if (_autocreator) {
8460       GPBAutocreatedDictionaryModified(_autocreator, self);
8461     }
8462   }
8465 - (void)setUInt32:(uint32_t)value forKey:(NSString *)key {
8466   if (!key) {
8467     [NSException raise:NSInvalidArgumentException
8468                 format:@"Attempting to add nil key to a Dictionary"];
8469   }
8470   [_dictionary setObject:@(value) forKey:key];
8471   if (_autocreator) {
8472     GPBAutocreatedDictionaryModified(_autocreator, self);
8473   }
8476 - (void)removeUInt32ForKey:(NSString *)aKey {
8477   [_dictionary removeObjectForKey:aKey];
8480 - (void)removeAll {
8481   [_dictionary removeAllObjects];
8484 @end
8486 #pragma mark - String -> Int32
8488 @implementation GPBStringInt32Dictionary {
8489  @package
8490   NSMutableDictionary *_dictionary;
8493 - (instancetype)init {
8494   return [self initWithInt32s:NULL forKeys:NULL count:0];
8497 - (instancetype)initWithInt32s:(const int32_t [])values
8498                        forKeys:(const NSString * [])keys
8499                          count:(NSUInteger)count {
8500   self = [super init];
8501   if (self) {
8502     _dictionary = [[NSMutableDictionary alloc] init];
8503     if (count && values && keys) {
8504       for (NSUInteger i = 0; i < count; ++i) {
8505         if (!keys[i]) {
8506           [NSException raise:NSInvalidArgumentException
8507                       format:@"Attempting to add nil key to a Dictionary"];
8508         }
8509         [_dictionary setObject:@(values[i]) forKey:keys[i]];
8510       }
8511     }
8512   }
8513   return self;
8516 - (instancetype)initWithDictionary:(GPBStringInt32Dictionary *)dictionary {
8517   self = [self initWithInt32s:NULL forKeys:NULL count:0];
8518   if (self) {
8519     if (dictionary) {
8520       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
8521     }
8522   }
8523   return self;
8526 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
8527   return [self initWithInt32s:NULL forKeys:NULL count:0];
8530 - (void)dealloc {
8531   NSAssert(!_autocreator,
8532            @"%@: Autocreator must be cleared before release, autocreator: %@",
8533            [self class], _autocreator);
8534   [_dictionary release];
8535   [super dealloc];
8538 - (instancetype)copyWithZone:(NSZone *)zone {
8539   return [[GPBStringInt32Dictionary allocWithZone:zone] initWithDictionary:self];
8542 - (BOOL)isEqual:(id)other {
8543   if (self == other) {
8544     return YES;
8545   }
8546   if (![other isKindOfClass:[GPBStringInt32Dictionary class]]) {
8547     return NO;
8548   }
8549   GPBStringInt32Dictionary *otherDictionary = other;
8550   return [_dictionary isEqual:otherDictionary->_dictionary];
8553 - (NSUInteger)hash {
8554   return _dictionary.count;
8557 - (NSString *)description {
8558   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
8561 - (NSUInteger)count {
8562   return _dictionary.count;
8565 - (void)enumerateKeysAndInt32sUsingBlock:
8566     (void (NS_NOESCAPE ^)(NSString *key, int32_t value, BOOL *stop))block {
8567   BOOL stop = NO;
8568   NSDictionary *internal = _dictionary;
8569   NSEnumerator *keys = [internal keyEnumerator];
8570   NSString *aKey;
8571   while ((aKey = [keys nextObject])) {
8572     NSNumber *aValue = internal[aKey];
8573     block(aKey, [aValue intValue], &stop);
8574     if (stop) {
8575       break;
8576     }
8577   }
8580 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
8581   NSDictionary *internal = _dictionary;
8582   NSUInteger count = internal.count;
8583   if (count == 0) {
8584     return 0;
8585   }
8587   GPBDataType valueDataType = GPBGetFieldDataType(field);
8588   GPBDataType keyDataType = field.mapKeyDataType;
8589   size_t result = 0;
8590   NSEnumerator *keys = [internal keyEnumerator];
8591   NSString *aKey;
8592   while ((aKey = [keys nextObject])) {
8593     NSNumber *aValue = internal[aKey];
8594     size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
8595     msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
8596     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
8597   }
8598   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
8599   result += tagSize * count;
8600   return result;
8603 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
8604                          asField:(GPBFieldDescriptor *)field {
8605   GPBDataType valueDataType = GPBGetFieldDataType(field);
8606   GPBDataType keyDataType = field.mapKeyDataType;
8607   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
8608   NSDictionary *internal = _dictionary;
8609   NSEnumerator *keys = [internal keyEnumerator];
8610   NSString *aKey;
8611   while ((aKey = [keys nextObject])) {
8612     NSNumber *aValue = internal[aKey];
8613     [outputStream writeInt32NoTag:tag];
8614     // Write the size of the message.
8615     NSString *unwrappedKey = aKey;
8616     int32_t unwrappedValue = [aValue intValue];
8617     size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
8618     msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
8619     [outputStream writeInt32NoTag:(int32_t)msgSize];
8620     // Write the fields.
8621     WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
8622     WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
8623   }
8626 - (void)setGPBGenericValue:(GPBGenericValue *)value
8627      forGPBGenericValueKey:(GPBGenericValue *)key {
8628   [_dictionary setObject:@(value->valueInt32) forKey:key->valueString];
8631 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
8632   [self enumerateKeysAndInt32sUsingBlock:^(NSString *key, int32_t value, __unused BOOL *stop) {
8633       block(key, [NSString stringWithFormat:@"%d", value]);
8634   }];
8637 - (BOOL)getInt32:(nullable int32_t *)value forKey:(NSString *)key {
8638   NSNumber *wrapped = [_dictionary objectForKey:key];
8639   if (wrapped && value) {
8640     *value = [wrapped intValue];
8641   }
8642   return (wrapped != NULL);
8645 - (void)addEntriesFromDictionary:(GPBStringInt32Dictionary *)otherDictionary {
8646   if (otherDictionary) {
8647     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
8648     if (_autocreator) {
8649       GPBAutocreatedDictionaryModified(_autocreator, self);
8650     }
8651   }
8654 - (void)setInt32:(int32_t)value forKey:(NSString *)key {
8655   if (!key) {
8656     [NSException raise:NSInvalidArgumentException
8657                 format:@"Attempting to add nil key to a Dictionary"];
8658   }
8659   [_dictionary setObject:@(value) forKey:key];
8660   if (_autocreator) {
8661     GPBAutocreatedDictionaryModified(_autocreator, self);
8662   }
8665 - (void)removeInt32ForKey:(NSString *)aKey {
8666   [_dictionary removeObjectForKey:aKey];
8669 - (void)removeAll {
8670   [_dictionary removeAllObjects];
8673 @end
8675 #pragma mark - String -> UInt64
8677 @implementation GPBStringUInt64Dictionary {
8678  @package
8679   NSMutableDictionary *_dictionary;
8682 - (instancetype)init {
8683   return [self initWithUInt64s:NULL forKeys:NULL count:0];
8686 - (instancetype)initWithUInt64s:(const uint64_t [])values
8687                         forKeys:(const NSString * [])keys
8688                           count:(NSUInteger)count {
8689   self = [super init];
8690   if (self) {
8691     _dictionary = [[NSMutableDictionary alloc] init];
8692     if (count && values && keys) {
8693       for (NSUInteger i = 0; i < count; ++i) {
8694         if (!keys[i]) {
8695           [NSException raise:NSInvalidArgumentException
8696                       format:@"Attempting to add nil key to a Dictionary"];
8697         }
8698         [_dictionary setObject:@(values[i]) forKey:keys[i]];
8699       }
8700     }
8701   }
8702   return self;
8705 - (instancetype)initWithDictionary:(GPBStringUInt64Dictionary *)dictionary {
8706   self = [self initWithUInt64s:NULL forKeys:NULL count:0];
8707   if (self) {
8708     if (dictionary) {
8709       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
8710     }
8711   }
8712   return self;
8715 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
8716   return [self initWithUInt64s:NULL forKeys:NULL count:0];
8719 - (void)dealloc {
8720   NSAssert(!_autocreator,
8721            @"%@: Autocreator must be cleared before release, autocreator: %@",
8722            [self class], _autocreator);
8723   [_dictionary release];
8724   [super dealloc];
8727 - (instancetype)copyWithZone:(NSZone *)zone {
8728   return [[GPBStringUInt64Dictionary allocWithZone:zone] initWithDictionary:self];
8731 - (BOOL)isEqual:(id)other {
8732   if (self == other) {
8733     return YES;
8734   }
8735   if (![other isKindOfClass:[GPBStringUInt64Dictionary class]]) {
8736     return NO;
8737   }
8738   GPBStringUInt64Dictionary *otherDictionary = other;
8739   return [_dictionary isEqual:otherDictionary->_dictionary];
8742 - (NSUInteger)hash {
8743   return _dictionary.count;
8746 - (NSString *)description {
8747   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
8750 - (NSUInteger)count {
8751   return _dictionary.count;
8754 - (void)enumerateKeysAndUInt64sUsingBlock:
8755     (void (NS_NOESCAPE ^)(NSString *key, uint64_t value, BOOL *stop))block {
8756   BOOL stop = NO;
8757   NSDictionary *internal = _dictionary;
8758   NSEnumerator *keys = [internal keyEnumerator];
8759   NSString *aKey;
8760   while ((aKey = [keys nextObject])) {
8761     NSNumber *aValue = internal[aKey];
8762     block(aKey, [aValue unsignedLongLongValue], &stop);
8763     if (stop) {
8764       break;
8765     }
8766   }
8769 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
8770   NSDictionary *internal = _dictionary;
8771   NSUInteger count = internal.count;
8772   if (count == 0) {
8773     return 0;
8774   }
8776   GPBDataType valueDataType = GPBGetFieldDataType(field);
8777   GPBDataType keyDataType = field.mapKeyDataType;
8778   size_t result = 0;
8779   NSEnumerator *keys = [internal keyEnumerator];
8780   NSString *aKey;
8781   while ((aKey = [keys nextObject])) {
8782     NSNumber *aValue = internal[aKey];
8783     size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
8784     msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
8785     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
8786   }
8787   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
8788   result += tagSize * count;
8789   return result;
8792 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
8793                          asField:(GPBFieldDescriptor *)field {
8794   GPBDataType valueDataType = GPBGetFieldDataType(field);
8795   GPBDataType keyDataType = field.mapKeyDataType;
8796   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
8797   NSDictionary *internal = _dictionary;
8798   NSEnumerator *keys = [internal keyEnumerator];
8799   NSString *aKey;
8800   while ((aKey = [keys nextObject])) {
8801     NSNumber *aValue = internal[aKey];
8802     [outputStream writeInt32NoTag:tag];
8803     // Write the size of the message.
8804     NSString *unwrappedKey = aKey;
8805     uint64_t unwrappedValue = [aValue unsignedLongLongValue];
8806     size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
8807     msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
8808     [outputStream writeInt32NoTag:(int32_t)msgSize];
8809     // Write the fields.
8810     WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
8811     WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
8812   }
8815 - (void)setGPBGenericValue:(GPBGenericValue *)value
8816      forGPBGenericValueKey:(GPBGenericValue *)key {
8817   [_dictionary setObject:@(value->valueUInt64) forKey:key->valueString];
8820 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
8821   [self enumerateKeysAndUInt64sUsingBlock:^(NSString *key, uint64_t value, __unused BOOL *stop) {
8822       block(key, [NSString stringWithFormat:@"%llu", value]);
8823   }];
8826 - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(NSString *)key {
8827   NSNumber *wrapped = [_dictionary objectForKey:key];
8828   if (wrapped && value) {
8829     *value = [wrapped unsignedLongLongValue];
8830   }
8831   return (wrapped != NULL);
8834 - (void)addEntriesFromDictionary:(GPBStringUInt64Dictionary *)otherDictionary {
8835   if (otherDictionary) {
8836     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
8837     if (_autocreator) {
8838       GPBAutocreatedDictionaryModified(_autocreator, self);
8839     }
8840   }
8843 - (void)setUInt64:(uint64_t)value forKey:(NSString *)key {
8844   if (!key) {
8845     [NSException raise:NSInvalidArgumentException
8846                 format:@"Attempting to add nil key to a Dictionary"];
8847   }
8848   [_dictionary setObject:@(value) forKey:key];
8849   if (_autocreator) {
8850     GPBAutocreatedDictionaryModified(_autocreator, self);
8851   }
8854 - (void)removeUInt64ForKey:(NSString *)aKey {
8855   [_dictionary removeObjectForKey:aKey];
8858 - (void)removeAll {
8859   [_dictionary removeAllObjects];
8862 @end
8864 #pragma mark - String -> Int64
8866 @implementation GPBStringInt64Dictionary {
8867  @package
8868   NSMutableDictionary *_dictionary;
8871 - (instancetype)init {
8872   return [self initWithInt64s:NULL forKeys:NULL count:0];
8875 - (instancetype)initWithInt64s:(const int64_t [])values
8876                        forKeys:(const NSString * [])keys
8877                          count:(NSUInteger)count {
8878   self = [super init];
8879   if (self) {
8880     _dictionary = [[NSMutableDictionary alloc] init];
8881     if (count && values && keys) {
8882       for (NSUInteger i = 0; i < count; ++i) {
8883         if (!keys[i]) {
8884           [NSException raise:NSInvalidArgumentException
8885                       format:@"Attempting to add nil key to a Dictionary"];
8886         }
8887         [_dictionary setObject:@(values[i]) forKey:keys[i]];
8888       }
8889     }
8890   }
8891   return self;
8894 - (instancetype)initWithDictionary:(GPBStringInt64Dictionary *)dictionary {
8895   self = [self initWithInt64s:NULL forKeys:NULL count:0];
8896   if (self) {
8897     if (dictionary) {
8898       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
8899     }
8900   }
8901   return self;
8904 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
8905   return [self initWithInt64s:NULL forKeys:NULL count:0];
8908 - (void)dealloc {
8909   NSAssert(!_autocreator,
8910            @"%@: Autocreator must be cleared before release, autocreator: %@",
8911            [self class], _autocreator);
8912   [_dictionary release];
8913   [super dealloc];
8916 - (instancetype)copyWithZone:(NSZone *)zone {
8917   return [[GPBStringInt64Dictionary allocWithZone:zone] initWithDictionary:self];
8920 - (BOOL)isEqual:(id)other {
8921   if (self == other) {
8922     return YES;
8923   }
8924   if (![other isKindOfClass:[GPBStringInt64Dictionary class]]) {
8925     return NO;
8926   }
8927   GPBStringInt64Dictionary *otherDictionary = other;
8928   return [_dictionary isEqual:otherDictionary->_dictionary];
8931 - (NSUInteger)hash {
8932   return _dictionary.count;
8935 - (NSString *)description {
8936   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
8939 - (NSUInteger)count {
8940   return _dictionary.count;
8943 - (void)enumerateKeysAndInt64sUsingBlock:
8944     (void (NS_NOESCAPE ^)(NSString *key, int64_t value, BOOL *stop))block {
8945   BOOL stop = NO;
8946   NSDictionary *internal = _dictionary;
8947   NSEnumerator *keys = [internal keyEnumerator];
8948   NSString *aKey;
8949   while ((aKey = [keys nextObject])) {
8950     NSNumber *aValue = internal[aKey];
8951     block(aKey, [aValue longLongValue], &stop);
8952     if (stop) {
8953       break;
8954     }
8955   }
8958 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
8959   NSDictionary *internal = _dictionary;
8960   NSUInteger count = internal.count;
8961   if (count == 0) {
8962     return 0;
8963   }
8965   GPBDataType valueDataType = GPBGetFieldDataType(field);
8966   GPBDataType keyDataType = field.mapKeyDataType;
8967   size_t result = 0;
8968   NSEnumerator *keys = [internal keyEnumerator];
8969   NSString *aKey;
8970   while ((aKey = [keys nextObject])) {
8971     NSNumber *aValue = internal[aKey];
8972     size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
8973     msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
8974     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
8975   }
8976   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
8977   result += tagSize * count;
8978   return result;
8981 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
8982                          asField:(GPBFieldDescriptor *)field {
8983   GPBDataType valueDataType = GPBGetFieldDataType(field);
8984   GPBDataType keyDataType = field.mapKeyDataType;
8985   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
8986   NSDictionary *internal = _dictionary;
8987   NSEnumerator *keys = [internal keyEnumerator];
8988   NSString *aKey;
8989   while ((aKey = [keys nextObject])) {
8990     NSNumber *aValue = internal[aKey];
8991     [outputStream writeInt32NoTag:tag];
8992     // Write the size of the message.
8993     NSString *unwrappedKey = aKey;
8994     int64_t unwrappedValue = [aValue longLongValue];
8995     size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
8996     msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
8997     [outputStream writeInt32NoTag:(int32_t)msgSize];
8998     // Write the fields.
8999     WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
9000     WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
9001   }
9004 - (void)setGPBGenericValue:(GPBGenericValue *)value
9005      forGPBGenericValueKey:(GPBGenericValue *)key {
9006   [_dictionary setObject:@(value->valueInt64) forKey:key->valueString];
9009 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
9010   [self enumerateKeysAndInt64sUsingBlock:^(NSString *key, int64_t value, __unused BOOL *stop) {
9011       block(key, [NSString stringWithFormat:@"%lld", value]);
9012   }];
9015 - (BOOL)getInt64:(nullable int64_t *)value forKey:(NSString *)key {
9016   NSNumber *wrapped = [_dictionary objectForKey:key];
9017   if (wrapped && value) {
9018     *value = [wrapped longLongValue];
9019   }
9020   return (wrapped != NULL);
9023 - (void)addEntriesFromDictionary:(GPBStringInt64Dictionary *)otherDictionary {
9024   if (otherDictionary) {
9025     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
9026     if (_autocreator) {
9027       GPBAutocreatedDictionaryModified(_autocreator, self);
9028     }
9029   }
9032 - (void)setInt64:(int64_t)value forKey:(NSString *)key {
9033   if (!key) {
9034     [NSException raise:NSInvalidArgumentException
9035                 format:@"Attempting to add nil key to a Dictionary"];
9036   }
9037   [_dictionary setObject:@(value) forKey:key];
9038   if (_autocreator) {
9039     GPBAutocreatedDictionaryModified(_autocreator, self);
9040   }
9043 - (void)removeInt64ForKey:(NSString *)aKey {
9044   [_dictionary removeObjectForKey:aKey];
9047 - (void)removeAll {
9048   [_dictionary removeAllObjects];
9051 @end
9053 #pragma mark - String -> Bool
9055 @implementation GPBStringBoolDictionary {
9056  @package
9057   NSMutableDictionary *_dictionary;
9060 - (instancetype)init {
9061   return [self initWithBools:NULL forKeys:NULL count:0];
9064 - (instancetype)initWithBools:(const BOOL [])values
9065                       forKeys:(const NSString * [])keys
9066                         count:(NSUInteger)count {
9067   self = [super init];
9068   if (self) {
9069     _dictionary = [[NSMutableDictionary alloc] init];
9070     if (count && values && keys) {
9071       for (NSUInteger i = 0; i < count; ++i) {
9072         if (!keys[i]) {
9073           [NSException raise:NSInvalidArgumentException
9074                       format:@"Attempting to add nil key to a Dictionary"];
9075         }
9076         [_dictionary setObject:@(values[i]) forKey:keys[i]];
9077       }
9078     }
9079   }
9080   return self;
9083 - (instancetype)initWithDictionary:(GPBStringBoolDictionary *)dictionary {
9084   self = [self initWithBools:NULL forKeys:NULL count:0];
9085   if (self) {
9086     if (dictionary) {
9087       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
9088     }
9089   }
9090   return self;
9093 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
9094   return [self initWithBools:NULL forKeys:NULL count:0];
9097 - (void)dealloc {
9098   NSAssert(!_autocreator,
9099            @"%@: Autocreator must be cleared before release, autocreator: %@",
9100            [self class], _autocreator);
9101   [_dictionary release];
9102   [super dealloc];
9105 - (instancetype)copyWithZone:(NSZone *)zone {
9106   return [[GPBStringBoolDictionary allocWithZone:zone] initWithDictionary:self];
9109 - (BOOL)isEqual:(id)other {
9110   if (self == other) {
9111     return YES;
9112   }
9113   if (![other isKindOfClass:[GPBStringBoolDictionary class]]) {
9114     return NO;
9115   }
9116   GPBStringBoolDictionary *otherDictionary = other;
9117   return [_dictionary isEqual:otherDictionary->_dictionary];
9120 - (NSUInteger)hash {
9121   return _dictionary.count;
9124 - (NSString *)description {
9125   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
9128 - (NSUInteger)count {
9129   return _dictionary.count;
9132 - (void)enumerateKeysAndBoolsUsingBlock:
9133     (void (NS_NOESCAPE ^)(NSString *key, BOOL value, BOOL *stop))block {
9134   BOOL stop = NO;
9135   NSDictionary *internal = _dictionary;
9136   NSEnumerator *keys = [internal keyEnumerator];
9137   NSString *aKey;
9138   while ((aKey = [keys nextObject])) {
9139     NSNumber *aValue = internal[aKey];
9140     block(aKey, [aValue boolValue], &stop);
9141     if (stop) {
9142       break;
9143     }
9144   }
9147 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
9148   NSDictionary *internal = _dictionary;
9149   NSUInteger count = internal.count;
9150   if (count == 0) {
9151     return 0;
9152   }
9154   GPBDataType valueDataType = GPBGetFieldDataType(field);
9155   GPBDataType keyDataType = field.mapKeyDataType;
9156   size_t result = 0;
9157   NSEnumerator *keys = [internal keyEnumerator];
9158   NSString *aKey;
9159   while ((aKey = [keys nextObject])) {
9160     NSNumber *aValue = internal[aKey];
9161     size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
9162     msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
9163     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
9164   }
9165   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
9166   result += tagSize * count;
9167   return result;
9170 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
9171                          asField:(GPBFieldDescriptor *)field {
9172   GPBDataType valueDataType = GPBGetFieldDataType(field);
9173   GPBDataType keyDataType = field.mapKeyDataType;
9174   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
9175   NSDictionary *internal = _dictionary;
9176   NSEnumerator *keys = [internal keyEnumerator];
9177   NSString *aKey;
9178   while ((aKey = [keys nextObject])) {
9179     NSNumber *aValue = internal[aKey];
9180     [outputStream writeInt32NoTag:tag];
9181     // Write the size of the message.
9182     NSString *unwrappedKey = aKey;
9183     BOOL unwrappedValue = [aValue boolValue];
9184     size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
9185     msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
9186     [outputStream writeInt32NoTag:(int32_t)msgSize];
9187     // Write the fields.
9188     WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
9189     WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
9190   }
9193 - (void)setGPBGenericValue:(GPBGenericValue *)value
9194      forGPBGenericValueKey:(GPBGenericValue *)key {
9195   [_dictionary setObject:@(value->valueBool) forKey:key->valueString];
9198 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
9199   [self enumerateKeysAndBoolsUsingBlock:^(NSString *key, BOOL value, __unused BOOL *stop) {
9200       block(key, (value ? @"true" : @"false"));
9201   }];
9204 - (BOOL)getBool:(nullable BOOL *)value forKey:(NSString *)key {
9205   NSNumber *wrapped = [_dictionary objectForKey:key];
9206   if (wrapped && value) {
9207     *value = [wrapped boolValue];
9208   }
9209   return (wrapped != NULL);
9212 - (void)addEntriesFromDictionary:(GPBStringBoolDictionary *)otherDictionary {
9213   if (otherDictionary) {
9214     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
9215     if (_autocreator) {
9216       GPBAutocreatedDictionaryModified(_autocreator, self);
9217     }
9218   }
9221 - (void)setBool:(BOOL)value forKey:(NSString *)key {
9222   if (!key) {
9223     [NSException raise:NSInvalidArgumentException
9224                 format:@"Attempting to add nil key to a Dictionary"];
9225   }
9226   [_dictionary setObject:@(value) forKey:key];
9227   if (_autocreator) {
9228     GPBAutocreatedDictionaryModified(_autocreator, self);
9229   }
9232 - (void)removeBoolForKey:(NSString *)aKey {
9233   [_dictionary removeObjectForKey:aKey];
9236 - (void)removeAll {
9237   [_dictionary removeAllObjects];
9240 @end
9242 #pragma mark - String -> Float
9244 @implementation GPBStringFloatDictionary {
9245  @package
9246   NSMutableDictionary *_dictionary;
9249 - (instancetype)init {
9250   return [self initWithFloats:NULL forKeys:NULL count:0];
9253 - (instancetype)initWithFloats:(const float [])values
9254                        forKeys:(const NSString * [])keys
9255                          count:(NSUInteger)count {
9256   self = [super init];
9257   if (self) {
9258     _dictionary = [[NSMutableDictionary alloc] init];
9259     if (count && values && keys) {
9260       for (NSUInteger i = 0; i < count; ++i) {
9261         if (!keys[i]) {
9262           [NSException raise:NSInvalidArgumentException
9263                       format:@"Attempting to add nil key to a Dictionary"];
9264         }
9265         [_dictionary setObject:@(values[i]) forKey:keys[i]];
9266       }
9267     }
9268   }
9269   return self;
9272 - (instancetype)initWithDictionary:(GPBStringFloatDictionary *)dictionary {
9273   self = [self initWithFloats:NULL forKeys:NULL count:0];
9274   if (self) {
9275     if (dictionary) {
9276       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
9277     }
9278   }
9279   return self;
9282 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
9283   return [self initWithFloats:NULL forKeys:NULL count:0];
9286 - (void)dealloc {
9287   NSAssert(!_autocreator,
9288            @"%@: Autocreator must be cleared before release, autocreator: %@",
9289            [self class], _autocreator);
9290   [_dictionary release];
9291   [super dealloc];
9294 - (instancetype)copyWithZone:(NSZone *)zone {
9295   return [[GPBStringFloatDictionary allocWithZone:zone] initWithDictionary:self];
9298 - (BOOL)isEqual:(id)other {
9299   if (self == other) {
9300     return YES;
9301   }
9302   if (![other isKindOfClass:[GPBStringFloatDictionary class]]) {
9303     return NO;
9304   }
9305   GPBStringFloatDictionary *otherDictionary = other;
9306   return [_dictionary isEqual:otherDictionary->_dictionary];
9309 - (NSUInteger)hash {
9310   return _dictionary.count;
9313 - (NSString *)description {
9314   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
9317 - (NSUInteger)count {
9318   return _dictionary.count;
9321 - (void)enumerateKeysAndFloatsUsingBlock:
9322     (void (NS_NOESCAPE ^)(NSString *key, float value, BOOL *stop))block {
9323   BOOL stop = NO;
9324   NSDictionary *internal = _dictionary;
9325   NSEnumerator *keys = [internal keyEnumerator];
9326   NSString *aKey;
9327   while ((aKey = [keys nextObject])) {
9328     NSNumber *aValue = internal[aKey];
9329     block(aKey, [aValue floatValue], &stop);
9330     if (stop) {
9331       break;
9332     }
9333   }
9336 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
9337   NSDictionary *internal = _dictionary;
9338   NSUInteger count = internal.count;
9339   if (count == 0) {
9340     return 0;
9341   }
9343   GPBDataType valueDataType = GPBGetFieldDataType(field);
9344   GPBDataType keyDataType = field.mapKeyDataType;
9345   size_t result = 0;
9346   NSEnumerator *keys = [internal keyEnumerator];
9347   NSString *aKey;
9348   while ((aKey = [keys nextObject])) {
9349     NSNumber *aValue = internal[aKey];
9350     size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
9351     msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
9352     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
9353   }
9354   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
9355   result += tagSize * count;
9356   return result;
9359 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
9360                          asField:(GPBFieldDescriptor *)field {
9361   GPBDataType valueDataType = GPBGetFieldDataType(field);
9362   GPBDataType keyDataType = field.mapKeyDataType;
9363   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
9364   NSDictionary *internal = _dictionary;
9365   NSEnumerator *keys = [internal keyEnumerator];
9366   NSString *aKey;
9367   while ((aKey = [keys nextObject])) {
9368     NSNumber *aValue = internal[aKey];
9369     [outputStream writeInt32NoTag:tag];
9370     // Write the size of the message.
9371     NSString *unwrappedKey = aKey;
9372     float unwrappedValue = [aValue floatValue];
9373     size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
9374     msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
9375     [outputStream writeInt32NoTag:(int32_t)msgSize];
9376     // Write the fields.
9377     WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
9378     WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
9379   }
9382 - (void)setGPBGenericValue:(GPBGenericValue *)value
9383      forGPBGenericValueKey:(GPBGenericValue *)key {
9384   [_dictionary setObject:@(value->valueFloat) forKey:key->valueString];
9387 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
9388   [self enumerateKeysAndFloatsUsingBlock:^(NSString *key, float value, __unused BOOL *stop) {
9389       block(key, [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
9390   }];
9393 - (BOOL)getFloat:(nullable float *)value forKey:(NSString *)key {
9394   NSNumber *wrapped = [_dictionary objectForKey:key];
9395   if (wrapped && value) {
9396     *value = [wrapped floatValue];
9397   }
9398   return (wrapped != NULL);
9401 - (void)addEntriesFromDictionary:(GPBStringFloatDictionary *)otherDictionary {
9402   if (otherDictionary) {
9403     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
9404     if (_autocreator) {
9405       GPBAutocreatedDictionaryModified(_autocreator, self);
9406     }
9407   }
9410 - (void)setFloat:(float)value forKey:(NSString *)key {
9411   if (!key) {
9412     [NSException raise:NSInvalidArgumentException
9413                 format:@"Attempting to add nil key to a Dictionary"];
9414   }
9415   [_dictionary setObject:@(value) forKey:key];
9416   if (_autocreator) {
9417     GPBAutocreatedDictionaryModified(_autocreator, self);
9418   }
9421 - (void)removeFloatForKey:(NSString *)aKey {
9422   [_dictionary removeObjectForKey:aKey];
9425 - (void)removeAll {
9426   [_dictionary removeAllObjects];
9429 @end
9431 #pragma mark - String -> Double
9433 @implementation GPBStringDoubleDictionary {
9434  @package
9435   NSMutableDictionary *_dictionary;
9438 - (instancetype)init {
9439   return [self initWithDoubles:NULL forKeys:NULL count:0];
9442 - (instancetype)initWithDoubles:(const double [])values
9443                         forKeys:(const NSString * [])keys
9444                           count:(NSUInteger)count {
9445   self = [super init];
9446   if (self) {
9447     _dictionary = [[NSMutableDictionary alloc] init];
9448     if (count && values && keys) {
9449       for (NSUInteger i = 0; i < count; ++i) {
9450         if (!keys[i]) {
9451           [NSException raise:NSInvalidArgumentException
9452                       format:@"Attempting to add nil key to a Dictionary"];
9453         }
9454         [_dictionary setObject:@(values[i]) forKey:keys[i]];
9455       }
9456     }
9457   }
9458   return self;
9461 - (instancetype)initWithDictionary:(GPBStringDoubleDictionary *)dictionary {
9462   self = [self initWithDoubles:NULL forKeys:NULL count:0];
9463   if (self) {
9464     if (dictionary) {
9465       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
9466     }
9467   }
9468   return self;
9471 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
9472   return [self initWithDoubles:NULL forKeys:NULL count:0];
9475 - (void)dealloc {
9476   NSAssert(!_autocreator,
9477            @"%@: Autocreator must be cleared before release, autocreator: %@",
9478            [self class], _autocreator);
9479   [_dictionary release];
9480   [super dealloc];
9483 - (instancetype)copyWithZone:(NSZone *)zone {
9484   return [[GPBStringDoubleDictionary allocWithZone:zone] initWithDictionary:self];
9487 - (BOOL)isEqual:(id)other {
9488   if (self == other) {
9489     return YES;
9490   }
9491   if (![other isKindOfClass:[GPBStringDoubleDictionary class]]) {
9492     return NO;
9493   }
9494   GPBStringDoubleDictionary *otherDictionary = other;
9495   return [_dictionary isEqual:otherDictionary->_dictionary];
9498 - (NSUInteger)hash {
9499   return _dictionary.count;
9502 - (NSString *)description {
9503   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
9506 - (NSUInteger)count {
9507   return _dictionary.count;
9510 - (void)enumerateKeysAndDoublesUsingBlock:
9511     (void (NS_NOESCAPE ^)(NSString *key, double value, BOOL *stop))block {
9512   BOOL stop = NO;
9513   NSDictionary *internal = _dictionary;
9514   NSEnumerator *keys = [internal keyEnumerator];
9515   NSString *aKey;
9516   while ((aKey = [keys nextObject])) {
9517     NSNumber *aValue = internal[aKey];
9518     block(aKey, [aValue doubleValue], &stop);
9519     if (stop) {
9520       break;
9521     }
9522   }
9525 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
9526   NSDictionary *internal = _dictionary;
9527   NSUInteger count = internal.count;
9528   if (count == 0) {
9529     return 0;
9530   }
9532   GPBDataType valueDataType = GPBGetFieldDataType(field);
9533   GPBDataType keyDataType = field.mapKeyDataType;
9534   size_t result = 0;
9535   NSEnumerator *keys = [internal keyEnumerator];
9536   NSString *aKey;
9537   while ((aKey = [keys nextObject])) {
9538     NSNumber *aValue = internal[aKey];
9539     size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
9540     msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
9541     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
9542   }
9543   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
9544   result += tagSize * count;
9545   return result;
9548 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
9549                          asField:(GPBFieldDescriptor *)field {
9550   GPBDataType valueDataType = GPBGetFieldDataType(field);
9551   GPBDataType keyDataType = field.mapKeyDataType;
9552   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
9553   NSDictionary *internal = _dictionary;
9554   NSEnumerator *keys = [internal keyEnumerator];
9555   NSString *aKey;
9556   while ((aKey = [keys nextObject])) {
9557     NSNumber *aValue = internal[aKey];
9558     [outputStream writeInt32NoTag:tag];
9559     // Write the size of the message.
9560     NSString *unwrappedKey = aKey;
9561     double unwrappedValue = [aValue doubleValue];
9562     size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
9563     msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
9564     [outputStream writeInt32NoTag:(int32_t)msgSize];
9565     // Write the fields.
9566     WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
9567     WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
9568   }
9571 - (void)setGPBGenericValue:(GPBGenericValue *)value
9572      forGPBGenericValueKey:(GPBGenericValue *)key {
9573   [_dictionary setObject:@(value->valueDouble) forKey:key->valueString];
9576 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
9577   [self enumerateKeysAndDoublesUsingBlock:^(NSString *key, double value, __unused BOOL *stop) {
9578       block(key, [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
9579   }];
9582 - (BOOL)getDouble:(nullable double *)value forKey:(NSString *)key {
9583   NSNumber *wrapped = [_dictionary objectForKey:key];
9584   if (wrapped && value) {
9585     *value = [wrapped doubleValue];
9586   }
9587   return (wrapped != NULL);
9590 - (void)addEntriesFromDictionary:(GPBStringDoubleDictionary *)otherDictionary {
9591   if (otherDictionary) {
9592     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
9593     if (_autocreator) {
9594       GPBAutocreatedDictionaryModified(_autocreator, self);
9595     }
9596   }
9599 - (void)setDouble:(double)value forKey:(NSString *)key {
9600   if (!key) {
9601     [NSException raise:NSInvalidArgumentException
9602                 format:@"Attempting to add nil key to a Dictionary"];
9603   }
9604   [_dictionary setObject:@(value) forKey:key];
9605   if (_autocreator) {
9606     GPBAutocreatedDictionaryModified(_autocreator, self);
9607   }
9610 - (void)removeDoubleForKey:(NSString *)aKey {
9611   [_dictionary removeObjectForKey:aKey];
9614 - (void)removeAll {
9615   [_dictionary removeAllObjects];
9618 @end
9620 #pragma mark - String -> Enum
9622 @implementation GPBStringEnumDictionary {
9623  @package
9624   NSMutableDictionary *_dictionary;
9625   GPBEnumValidationFunc _validationFunc;
9628 @synthesize validationFunc = _validationFunc;
9630 - (instancetype)init {
9631   return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
9634 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
9635   return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
9638 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
9639                                  rawValues:(const int32_t [])rawValues
9640                                    forKeys:(const NSString * [])keys
9641                                      count:(NSUInteger)count {
9642   self = [super init];
9643   if (self) {
9644     _dictionary = [[NSMutableDictionary alloc] init];
9645     _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
9646     if (count && rawValues && keys) {
9647       for (NSUInteger i = 0; i < count; ++i) {
9648         if (!keys[i]) {
9649           [NSException raise:NSInvalidArgumentException
9650                       format:@"Attempting to add nil key to a Dictionary"];
9651         }
9652         [_dictionary setObject:@(rawValues[i]) forKey:keys[i]];
9653       }
9654     }
9655   }
9656   return self;
9659 - (instancetype)initWithDictionary:(GPBStringEnumDictionary *)dictionary {
9660   self = [self initWithValidationFunction:dictionary.validationFunc
9661                                 rawValues:NULL
9662                                   forKeys:NULL
9663                                     count:0];
9664   if (self) {
9665     if (dictionary) {
9666       [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
9667     }
9668   }
9669   return self;
9672 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
9673                                   capacity:(__unused NSUInteger)numItems {
9674   return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
9677 - (void)dealloc {
9678   NSAssert(!_autocreator,
9679            @"%@: Autocreator must be cleared before release, autocreator: %@",
9680            [self class], _autocreator);
9681   [_dictionary release];
9682   [super dealloc];
9685 - (instancetype)copyWithZone:(NSZone *)zone {
9686   return [[GPBStringEnumDictionary allocWithZone:zone] initWithDictionary:self];
9689 - (BOOL)isEqual:(id)other {
9690   if (self == other) {
9691     return YES;
9692   }
9693   if (![other isKindOfClass:[GPBStringEnumDictionary class]]) {
9694     return NO;
9695   }
9696   GPBStringEnumDictionary *otherDictionary = other;
9697   return [_dictionary isEqual:otherDictionary->_dictionary];
9700 - (NSUInteger)hash {
9701   return _dictionary.count;
9704 - (NSString *)description {
9705   return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
9708 - (NSUInteger)count {
9709   return _dictionary.count;
9712 - (void)enumerateKeysAndRawValuesUsingBlock:
9713     (void (NS_NOESCAPE ^)(NSString *key, int32_t value, BOOL *stop))block {
9714   BOOL stop = NO;
9715   NSDictionary *internal = _dictionary;
9716   NSEnumerator *keys = [internal keyEnumerator];
9717   NSString *aKey;
9718   while ((aKey = [keys nextObject])) {
9719     NSNumber *aValue = internal[aKey];
9720     block(aKey, [aValue intValue], &stop);
9721     if (stop) {
9722       break;
9723     }
9724   }
9727 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
9728   NSDictionary *internal = _dictionary;
9729   NSUInteger count = internal.count;
9730   if (count == 0) {
9731     return 0;
9732   }
9734   GPBDataType valueDataType = GPBGetFieldDataType(field);
9735   GPBDataType keyDataType = field.mapKeyDataType;
9736   size_t result = 0;
9737   NSEnumerator *keys = [internal keyEnumerator];
9738   NSString *aKey;
9739   while ((aKey = [keys nextObject])) {
9740     NSNumber *aValue = internal[aKey];
9741     size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
9742     msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
9743     result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
9744   }
9745   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
9746   result += tagSize * count;
9747   return result;
9750 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
9751                          asField:(GPBFieldDescriptor *)field {
9752   GPBDataType valueDataType = GPBGetFieldDataType(field);
9753   GPBDataType keyDataType = field.mapKeyDataType;
9754   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
9755   NSDictionary *internal = _dictionary;
9756   NSEnumerator *keys = [internal keyEnumerator];
9757   NSString *aKey;
9758   while ((aKey = [keys nextObject])) {
9759     NSNumber *aValue = internal[aKey];
9760     [outputStream writeInt32NoTag:tag];
9761     // Write the size of the message.
9762     NSString *unwrappedKey = aKey;
9763     int32_t unwrappedValue = [aValue intValue];
9764     size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
9765     msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
9766     [outputStream writeInt32NoTag:(int32_t)msgSize];
9767     // Write the fields.
9768     WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
9769     WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
9770   }
9773 - (NSData *)serializedDataForUnknownValue:(int32_t)value
9774                                    forKey:(GPBGenericValue *)key
9775                               keyDataType:(GPBDataType)keyDataType {
9776   size_t msgSize = ComputeDictStringFieldSize(key->valueString, kMapKeyFieldNumber, keyDataType);
9777   msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
9778   NSMutableData *data = [NSMutableData dataWithLength:msgSize];
9779   GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
9780   WriteDictStringField(outputStream, key->valueString, kMapKeyFieldNumber, keyDataType);
9781   WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
9782   [outputStream flush];
9783   [outputStream release];
9784   return data;
9786 - (void)setGPBGenericValue:(GPBGenericValue *)value
9787      forGPBGenericValueKey:(GPBGenericValue *)key {
9788   [_dictionary setObject:@(value->valueEnum) forKey:key->valueString];
9791 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
9792   [self enumerateKeysAndRawValuesUsingBlock:^(NSString *key, int32_t value, __unused BOOL *stop) {
9793       block(key, @(value));
9794   }];
9797 - (BOOL)getEnum:(int32_t *)value forKey:(NSString *)key {
9798   NSNumber *wrapped = [_dictionary objectForKey:key];
9799   if (wrapped && value) {
9800     int32_t result = [wrapped intValue];
9801     if (!_validationFunc(result)) {
9802       result = kGPBUnrecognizedEnumeratorValue;
9803     }
9804     *value = result;
9805   }
9806   return (wrapped != NULL);
9809 - (BOOL)getRawValue:(int32_t *)rawValue forKey:(NSString *)key {
9810   NSNumber *wrapped = [_dictionary objectForKey:key];
9811   if (wrapped && rawValue) {
9812     *rawValue = [wrapped intValue];
9813   }
9814   return (wrapped != NULL);
9817 - (void)enumerateKeysAndEnumsUsingBlock:
9818     (void (NS_NOESCAPE ^)(NSString *key, int32_t value, BOOL *stop))block {
9819   GPBEnumValidationFunc func = _validationFunc;
9820   BOOL stop = NO;
9821   NSEnumerator *keys = [_dictionary keyEnumerator];
9822   NSString *aKey;
9823   while ((aKey = [keys nextObject])) {
9824     NSNumber *aValue = _dictionary[aKey];
9825       int32_t unwrapped = [aValue intValue];
9826       if (!func(unwrapped)) {
9827         unwrapped = kGPBUnrecognizedEnumeratorValue;
9828       }
9829     block(aKey, unwrapped, &stop);
9830     if (stop) {
9831       break;
9832     }
9833   }
9836 - (void)addRawEntriesFromDictionary:(GPBStringEnumDictionary *)otherDictionary {
9837   if (otherDictionary) {
9838     [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
9839     if (_autocreator) {
9840       GPBAutocreatedDictionaryModified(_autocreator, self);
9841     }
9842   }
9845 - (void)setRawValue:(int32_t)value forKey:(NSString *)key {
9846   if (!key) {
9847     [NSException raise:NSInvalidArgumentException
9848                 format:@"Attempting to add nil key to a Dictionary"];
9849   }
9850   [_dictionary setObject:@(value) forKey:key];
9851   if (_autocreator) {
9852     GPBAutocreatedDictionaryModified(_autocreator, self);
9853   }
9856 - (void)removeEnumForKey:(NSString *)aKey {
9857   [_dictionary removeObjectForKey:aKey];
9860 - (void)removeAll {
9861   [_dictionary removeAllObjects];
9864 - (void)setEnum:(int32_t)value forKey:(NSString *)key {
9865   if (!key) {
9866     [NSException raise:NSInvalidArgumentException
9867                 format:@"Attempting to add nil key to a Dictionary"];
9868   }
9869   if (!_validationFunc(value)) {
9870     [NSException raise:NSInvalidArgumentException
9871                 format:@"GPBStringEnumDictionary: Attempt to set an unknown enum value (%d)",
9872                        value];
9873   }
9875   [_dictionary setObject:@(value) forKey:key];
9876   if (_autocreator) {
9877     GPBAutocreatedDictionaryModified(_autocreator, self);
9878   }
9881 @end
9883 //%PDDM-EXPAND-END (5 expansions)
9886 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(UInt32, uint32_t)
9887 // This block of code is generated, do not edit it directly.
9889 #pragma mark - Bool -> UInt32
9891 @implementation GPBBoolUInt32Dictionary {
9892  @package
9893   uint32_t _values[2];
9894   BOOL _valueSet[2];
9897 - (instancetype)init {
9898   return [self initWithUInt32s:NULL forKeys:NULL count:0];
9901 - (instancetype)initWithUInt32s:(const uint32_t [])values
9902                         forKeys:(const BOOL [])keys
9903                           count:(NSUInteger)count {
9904   self = [super init];
9905   if (self) {
9906     for (NSUInteger i = 0; i < count; ++i) {
9907       int idx = keys[i] ? 1 : 0;
9908       _values[idx] = values[i];
9909       _valueSet[idx] = YES;
9910     }
9911   }
9912   return self;
9915 - (instancetype)initWithDictionary:(GPBBoolUInt32Dictionary *)dictionary {
9916   self = [self initWithUInt32s:NULL forKeys:NULL count:0];
9917   if (self) {
9918     if (dictionary) {
9919       for (int i = 0; i < 2; ++i) {
9920         if (dictionary->_valueSet[i]) {
9921           _values[i] = dictionary->_values[i];
9922           _valueSet[i] = YES;
9923         }
9924       }
9925     }
9926   }
9927   return self;
9930 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
9931   return [self initWithUInt32s:NULL forKeys:NULL count:0];
9934 #if !defined(NS_BLOCK_ASSERTIONS)
9935 - (void)dealloc {
9936   NSAssert(!_autocreator,
9937            @"%@: Autocreator must be cleared before release, autocreator: %@",
9938            [self class], _autocreator);
9939   [super dealloc];
9941 #endif  // !defined(NS_BLOCK_ASSERTIONS)
9943 - (instancetype)copyWithZone:(NSZone *)zone {
9944   return [[GPBBoolUInt32Dictionary allocWithZone:zone] initWithDictionary:self];
9947 - (BOOL)isEqual:(id)other {
9948   if (self == other) {
9949     return YES;
9950   }
9951   if (![other isKindOfClass:[GPBBoolUInt32Dictionary class]]) {
9952     return NO;
9953   }
9954   GPBBoolUInt32Dictionary *otherDictionary = other;
9955   if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
9956       (_valueSet[1] != otherDictionary->_valueSet[1])) {
9957     return NO;
9958   }
9959   if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
9960       (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
9961     return NO;
9962   }
9963   return YES;
9966 - (NSUInteger)hash {
9967   return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
9970 - (NSString *)description {
9971   NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
9972   if (_valueSet[0]) {
9973     [result appendFormat:@"NO: %u", _values[0]];
9974   }
9975   if (_valueSet[1]) {
9976     [result appendFormat:@"YES: %u", _values[1]];
9977   }
9978   [result appendString:@" }"];
9979   return result;
9982 - (NSUInteger)count {
9983   return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
9986 - (BOOL)getUInt32:(uint32_t *)value forKey:(BOOL)key {
9987   int idx = (key ? 1 : 0);
9988   if (_valueSet[idx]) {
9989     if (value) {
9990       *value = _values[idx];
9991     }
9992     return YES;
9993   }
9994   return NO;
9997 - (void)setGPBGenericValue:(GPBGenericValue *)value
9998      forGPBGenericValueKey:(GPBGenericValue *)key {
9999   int idx = (key->valueBool ? 1 : 0);
10000   _values[idx] = value->valueUInt32;
10001   _valueSet[idx] = YES;
10004 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
10005   if (_valueSet[0]) {
10006     block(@"false", [NSString stringWithFormat:@"%u", _values[0]]);
10007   }
10008   if (_valueSet[1]) {
10009     block(@"true", [NSString stringWithFormat:@"%u", _values[1]]);
10010   }
10013 - (void)enumerateKeysAndUInt32sUsingBlock:
10014     (void (NS_NOESCAPE ^)(BOOL key, uint32_t value, BOOL *stop))block {
10015   BOOL stop = NO;
10016   if (_valueSet[0]) {
10017     block(NO, _values[0], &stop);
10018   }
10019   if (!stop && _valueSet[1]) {
10020     block(YES, _values[1], &stop);
10021   }
10024 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
10025   GPBDataType valueDataType = GPBGetFieldDataType(field);
10026   NSUInteger count = 0;
10027   size_t result = 0;
10028   for (int i = 0; i < 2; ++i) {
10029     if (_valueSet[i]) {
10030       ++count;
10031       size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10032       msgSize += ComputeDictUInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
10033       result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
10034     }
10035   }
10036   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
10037   result += tagSize * count;
10038   return result;
10041 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
10042                          asField:(GPBFieldDescriptor *)field {
10043   GPBDataType valueDataType = GPBGetFieldDataType(field);
10044   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
10045   for (int i = 0; i < 2; ++i) {
10046     if (_valueSet[i]) {
10047       // Write the tag.
10048       [outputStream writeInt32NoTag:tag];
10049       // Write the size of the message.
10050       size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10051       msgSize += ComputeDictUInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
10052       [outputStream writeInt32NoTag:(int32_t)msgSize];
10053       // Write the fields.
10054       WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10055       WriteDictUInt32Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
10056     }
10057   }
10060 - (void)addEntriesFromDictionary:(GPBBoolUInt32Dictionary *)otherDictionary {
10061   if (otherDictionary) {
10062     for (int i = 0; i < 2; ++i) {
10063       if (otherDictionary->_valueSet[i]) {
10064         _valueSet[i] = YES;
10065         _values[i] = otherDictionary->_values[i];
10066       }
10067     }
10068     if (_autocreator) {
10069       GPBAutocreatedDictionaryModified(_autocreator, self);
10070     }
10071   }
10074 - (void)setUInt32:(uint32_t)value forKey:(BOOL)key {
10075   int idx = (key ? 1 : 0);
10076   _values[idx] = value;
10077   _valueSet[idx] = YES;
10078   if (_autocreator) {
10079     GPBAutocreatedDictionaryModified(_autocreator, self);
10080   }
10083 - (void)removeUInt32ForKey:(BOOL)aKey {
10084   _valueSet[aKey ? 1 : 0] = NO;
10087 - (void)removeAll {
10088   _valueSet[0] = NO;
10089   _valueSet[1] = NO;
10092 @end
10094 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Int32, int32_t)
10095 // This block of code is generated, do not edit it directly.
10097 #pragma mark - Bool -> Int32
10099 @implementation GPBBoolInt32Dictionary {
10100  @package
10101   int32_t _values[2];
10102   BOOL _valueSet[2];
10105 - (instancetype)init {
10106   return [self initWithInt32s:NULL forKeys:NULL count:0];
10109 - (instancetype)initWithInt32s:(const int32_t [])values
10110                        forKeys:(const BOOL [])keys
10111                          count:(NSUInteger)count {
10112   self = [super init];
10113   if (self) {
10114     for (NSUInteger i = 0; i < count; ++i) {
10115       int idx = keys[i] ? 1 : 0;
10116       _values[idx] = values[i];
10117       _valueSet[idx] = YES;
10118     }
10119   }
10120   return self;
10123 - (instancetype)initWithDictionary:(GPBBoolInt32Dictionary *)dictionary {
10124   self = [self initWithInt32s:NULL forKeys:NULL count:0];
10125   if (self) {
10126     if (dictionary) {
10127       for (int i = 0; i < 2; ++i) {
10128         if (dictionary->_valueSet[i]) {
10129           _values[i] = dictionary->_values[i];
10130           _valueSet[i] = YES;
10131         }
10132       }
10133     }
10134   }
10135   return self;
10138 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
10139   return [self initWithInt32s:NULL forKeys:NULL count:0];
10142 #if !defined(NS_BLOCK_ASSERTIONS)
10143 - (void)dealloc {
10144   NSAssert(!_autocreator,
10145            @"%@: Autocreator must be cleared before release, autocreator: %@",
10146            [self class], _autocreator);
10147   [super dealloc];
10149 #endif  // !defined(NS_BLOCK_ASSERTIONS)
10151 - (instancetype)copyWithZone:(NSZone *)zone {
10152   return [[GPBBoolInt32Dictionary allocWithZone:zone] initWithDictionary:self];
10155 - (BOOL)isEqual:(id)other {
10156   if (self == other) {
10157     return YES;
10158   }
10159   if (![other isKindOfClass:[GPBBoolInt32Dictionary class]]) {
10160     return NO;
10161   }
10162   GPBBoolInt32Dictionary *otherDictionary = other;
10163   if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
10164       (_valueSet[1] != otherDictionary->_valueSet[1])) {
10165     return NO;
10166   }
10167   if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
10168       (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
10169     return NO;
10170   }
10171   return YES;
10174 - (NSUInteger)hash {
10175   return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
10178 - (NSString *)description {
10179   NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
10180   if (_valueSet[0]) {
10181     [result appendFormat:@"NO: %d", _values[0]];
10182   }
10183   if (_valueSet[1]) {
10184     [result appendFormat:@"YES: %d", _values[1]];
10185   }
10186   [result appendString:@" }"];
10187   return result;
10190 - (NSUInteger)count {
10191   return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
10194 - (BOOL)getInt32:(int32_t *)value forKey:(BOOL)key {
10195   int idx = (key ? 1 : 0);
10196   if (_valueSet[idx]) {
10197     if (value) {
10198       *value = _values[idx];
10199     }
10200     return YES;
10201   }
10202   return NO;
10205 - (void)setGPBGenericValue:(GPBGenericValue *)value
10206      forGPBGenericValueKey:(GPBGenericValue *)key {
10207   int idx = (key->valueBool ? 1 : 0);
10208   _values[idx] = value->valueInt32;
10209   _valueSet[idx] = YES;
10212 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
10213   if (_valueSet[0]) {
10214     block(@"false", [NSString stringWithFormat:@"%d", _values[0]]);
10215   }
10216   if (_valueSet[1]) {
10217     block(@"true", [NSString stringWithFormat:@"%d", _values[1]]);
10218   }
10221 - (void)enumerateKeysAndInt32sUsingBlock:
10222     (void (NS_NOESCAPE ^)(BOOL key, int32_t value, BOOL *stop))block {
10223   BOOL stop = NO;
10224   if (_valueSet[0]) {
10225     block(NO, _values[0], &stop);
10226   }
10227   if (!stop && _valueSet[1]) {
10228     block(YES, _values[1], &stop);
10229   }
10232 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
10233   GPBDataType valueDataType = GPBGetFieldDataType(field);
10234   NSUInteger count = 0;
10235   size_t result = 0;
10236   for (int i = 0; i < 2; ++i) {
10237     if (_valueSet[i]) {
10238       ++count;
10239       size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10240       msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
10241       result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
10242     }
10243   }
10244   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
10245   result += tagSize * count;
10246   return result;
10249 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
10250                          asField:(GPBFieldDescriptor *)field {
10251   GPBDataType valueDataType = GPBGetFieldDataType(field);
10252   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
10253   for (int i = 0; i < 2; ++i) {
10254     if (_valueSet[i]) {
10255       // Write the tag.
10256       [outputStream writeInt32NoTag:tag];
10257       // Write the size of the message.
10258       size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10259       msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
10260       [outputStream writeInt32NoTag:(int32_t)msgSize];
10261       // Write the fields.
10262       WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10263       WriteDictInt32Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
10264     }
10265   }
10268 - (void)addEntriesFromDictionary:(GPBBoolInt32Dictionary *)otherDictionary {
10269   if (otherDictionary) {
10270     for (int i = 0; i < 2; ++i) {
10271       if (otherDictionary->_valueSet[i]) {
10272         _valueSet[i] = YES;
10273         _values[i] = otherDictionary->_values[i];
10274       }
10275     }
10276     if (_autocreator) {
10277       GPBAutocreatedDictionaryModified(_autocreator, self);
10278     }
10279   }
10282 - (void)setInt32:(int32_t)value forKey:(BOOL)key {
10283   int idx = (key ? 1 : 0);
10284   _values[idx] = value;
10285   _valueSet[idx] = YES;
10286   if (_autocreator) {
10287     GPBAutocreatedDictionaryModified(_autocreator, self);
10288   }
10291 - (void)removeInt32ForKey:(BOOL)aKey {
10292   _valueSet[aKey ? 1 : 0] = NO;
10295 - (void)removeAll {
10296   _valueSet[0] = NO;
10297   _valueSet[1] = NO;
10300 @end
10302 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(UInt64, uint64_t)
10303 // This block of code is generated, do not edit it directly.
10305 #pragma mark - Bool -> UInt64
10307 @implementation GPBBoolUInt64Dictionary {
10308  @package
10309   uint64_t _values[2];
10310   BOOL _valueSet[2];
10313 - (instancetype)init {
10314   return [self initWithUInt64s:NULL forKeys:NULL count:0];
10317 - (instancetype)initWithUInt64s:(const uint64_t [])values
10318                         forKeys:(const BOOL [])keys
10319                           count:(NSUInteger)count {
10320   self = [super init];
10321   if (self) {
10322     for (NSUInteger i = 0; i < count; ++i) {
10323       int idx = keys[i] ? 1 : 0;
10324       _values[idx] = values[i];
10325       _valueSet[idx] = YES;
10326     }
10327   }
10328   return self;
10331 - (instancetype)initWithDictionary:(GPBBoolUInt64Dictionary *)dictionary {
10332   self = [self initWithUInt64s:NULL forKeys:NULL count:0];
10333   if (self) {
10334     if (dictionary) {
10335       for (int i = 0; i < 2; ++i) {
10336         if (dictionary->_valueSet[i]) {
10337           _values[i] = dictionary->_values[i];
10338           _valueSet[i] = YES;
10339         }
10340       }
10341     }
10342   }
10343   return self;
10346 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
10347   return [self initWithUInt64s:NULL forKeys:NULL count:0];
10350 #if !defined(NS_BLOCK_ASSERTIONS)
10351 - (void)dealloc {
10352   NSAssert(!_autocreator,
10353            @"%@: Autocreator must be cleared before release, autocreator: %@",
10354            [self class], _autocreator);
10355   [super dealloc];
10357 #endif  // !defined(NS_BLOCK_ASSERTIONS)
10359 - (instancetype)copyWithZone:(NSZone *)zone {
10360   return [[GPBBoolUInt64Dictionary allocWithZone:zone] initWithDictionary:self];
10363 - (BOOL)isEqual:(id)other {
10364   if (self == other) {
10365     return YES;
10366   }
10367   if (![other isKindOfClass:[GPBBoolUInt64Dictionary class]]) {
10368     return NO;
10369   }
10370   GPBBoolUInt64Dictionary *otherDictionary = other;
10371   if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
10372       (_valueSet[1] != otherDictionary->_valueSet[1])) {
10373     return NO;
10374   }
10375   if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
10376       (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
10377     return NO;
10378   }
10379   return YES;
10382 - (NSUInteger)hash {
10383   return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
10386 - (NSString *)description {
10387   NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
10388   if (_valueSet[0]) {
10389     [result appendFormat:@"NO: %llu", _values[0]];
10390   }
10391   if (_valueSet[1]) {
10392     [result appendFormat:@"YES: %llu", _values[1]];
10393   }
10394   [result appendString:@" }"];
10395   return result;
10398 - (NSUInteger)count {
10399   return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
10402 - (BOOL)getUInt64:(uint64_t *)value forKey:(BOOL)key {
10403   int idx = (key ? 1 : 0);
10404   if (_valueSet[idx]) {
10405     if (value) {
10406       *value = _values[idx];
10407     }
10408     return YES;
10409   }
10410   return NO;
10413 - (void)setGPBGenericValue:(GPBGenericValue *)value
10414      forGPBGenericValueKey:(GPBGenericValue *)key {
10415   int idx = (key->valueBool ? 1 : 0);
10416   _values[idx] = value->valueUInt64;
10417   _valueSet[idx] = YES;
10420 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
10421   if (_valueSet[0]) {
10422     block(@"false", [NSString stringWithFormat:@"%llu", _values[0]]);
10423   }
10424   if (_valueSet[1]) {
10425     block(@"true", [NSString stringWithFormat:@"%llu", _values[1]]);
10426   }
10429 - (void)enumerateKeysAndUInt64sUsingBlock:
10430     (void (NS_NOESCAPE ^)(BOOL key, uint64_t value, BOOL *stop))block {
10431   BOOL stop = NO;
10432   if (_valueSet[0]) {
10433     block(NO, _values[0], &stop);
10434   }
10435   if (!stop && _valueSet[1]) {
10436     block(YES, _values[1], &stop);
10437   }
10440 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
10441   GPBDataType valueDataType = GPBGetFieldDataType(field);
10442   NSUInteger count = 0;
10443   size_t result = 0;
10444   for (int i = 0; i < 2; ++i) {
10445     if (_valueSet[i]) {
10446       ++count;
10447       size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10448       msgSize += ComputeDictUInt64FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
10449       result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
10450     }
10451   }
10452   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
10453   result += tagSize * count;
10454   return result;
10457 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
10458                          asField:(GPBFieldDescriptor *)field {
10459   GPBDataType valueDataType = GPBGetFieldDataType(field);
10460   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
10461   for (int i = 0; i < 2; ++i) {
10462     if (_valueSet[i]) {
10463       // Write the tag.
10464       [outputStream writeInt32NoTag:tag];
10465       // Write the size of the message.
10466       size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10467       msgSize += ComputeDictUInt64FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
10468       [outputStream writeInt32NoTag:(int32_t)msgSize];
10469       // Write the fields.
10470       WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10471       WriteDictUInt64Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
10472     }
10473   }
10476 - (void)addEntriesFromDictionary:(GPBBoolUInt64Dictionary *)otherDictionary {
10477   if (otherDictionary) {
10478     for (int i = 0; i < 2; ++i) {
10479       if (otherDictionary->_valueSet[i]) {
10480         _valueSet[i] = YES;
10481         _values[i] = otherDictionary->_values[i];
10482       }
10483     }
10484     if (_autocreator) {
10485       GPBAutocreatedDictionaryModified(_autocreator, self);
10486     }
10487   }
10490 - (void)setUInt64:(uint64_t)value forKey:(BOOL)key {
10491   int idx = (key ? 1 : 0);
10492   _values[idx] = value;
10493   _valueSet[idx] = YES;
10494   if (_autocreator) {
10495     GPBAutocreatedDictionaryModified(_autocreator, self);
10496   }
10499 - (void)removeUInt64ForKey:(BOOL)aKey {
10500   _valueSet[aKey ? 1 : 0] = NO;
10503 - (void)removeAll {
10504   _valueSet[0] = NO;
10505   _valueSet[1] = NO;
10508 @end
10510 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Int64, int64_t)
10511 // This block of code is generated, do not edit it directly.
10513 #pragma mark - Bool -> Int64
10515 @implementation GPBBoolInt64Dictionary {
10516  @package
10517   int64_t _values[2];
10518   BOOL _valueSet[2];
10521 - (instancetype)init {
10522   return [self initWithInt64s:NULL forKeys:NULL count:0];
10525 - (instancetype)initWithInt64s:(const int64_t [])values
10526                        forKeys:(const BOOL [])keys
10527                          count:(NSUInteger)count {
10528   self = [super init];
10529   if (self) {
10530     for (NSUInteger i = 0; i < count; ++i) {
10531       int idx = keys[i] ? 1 : 0;
10532       _values[idx] = values[i];
10533       _valueSet[idx] = YES;
10534     }
10535   }
10536   return self;
10539 - (instancetype)initWithDictionary:(GPBBoolInt64Dictionary *)dictionary {
10540   self = [self initWithInt64s:NULL forKeys:NULL count:0];
10541   if (self) {
10542     if (dictionary) {
10543       for (int i = 0; i < 2; ++i) {
10544         if (dictionary->_valueSet[i]) {
10545           _values[i] = dictionary->_values[i];
10546           _valueSet[i] = YES;
10547         }
10548       }
10549     }
10550   }
10551   return self;
10554 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
10555   return [self initWithInt64s:NULL forKeys:NULL count:0];
10558 #if !defined(NS_BLOCK_ASSERTIONS)
10559 - (void)dealloc {
10560   NSAssert(!_autocreator,
10561            @"%@: Autocreator must be cleared before release, autocreator: %@",
10562            [self class], _autocreator);
10563   [super dealloc];
10565 #endif  // !defined(NS_BLOCK_ASSERTIONS)
10567 - (instancetype)copyWithZone:(NSZone *)zone {
10568   return [[GPBBoolInt64Dictionary allocWithZone:zone] initWithDictionary:self];
10571 - (BOOL)isEqual:(id)other {
10572   if (self == other) {
10573     return YES;
10574   }
10575   if (![other isKindOfClass:[GPBBoolInt64Dictionary class]]) {
10576     return NO;
10577   }
10578   GPBBoolInt64Dictionary *otherDictionary = other;
10579   if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
10580       (_valueSet[1] != otherDictionary->_valueSet[1])) {
10581     return NO;
10582   }
10583   if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
10584       (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
10585     return NO;
10586   }
10587   return YES;
10590 - (NSUInteger)hash {
10591   return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
10594 - (NSString *)description {
10595   NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
10596   if (_valueSet[0]) {
10597     [result appendFormat:@"NO: %lld", _values[0]];
10598   }
10599   if (_valueSet[1]) {
10600     [result appendFormat:@"YES: %lld", _values[1]];
10601   }
10602   [result appendString:@" }"];
10603   return result;
10606 - (NSUInteger)count {
10607   return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
10610 - (BOOL)getInt64:(int64_t *)value forKey:(BOOL)key {
10611   int idx = (key ? 1 : 0);
10612   if (_valueSet[idx]) {
10613     if (value) {
10614       *value = _values[idx];
10615     }
10616     return YES;
10617   }
10618   return NO;
10621 - (void)setGPBGenericValue:(GPBGenericValue *)value
10622      forGPBGenericValueKey:(GPBGenericValue *)key {
10623   int idx = (key->valueBool ? 1 : 0);
10624   _values[idx] = value->valueInt64;
10625   _valueSet[idx] = YES;
10628 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
10629   if (_valueSet[0]) {
10630     block(@"false", [NSString stringWithFormat:@"%lld", _values[0]]);
10631   }
10632   if (_valueSet[1]) {
10633     block(@"true", [NSString stringWithFormat:@"%lld", _values[1]]);
10634   }
10637 - (void)enumerateKeysAndInt64sUsingBlock:
10638     (void (NS_NOESCAPE ^)(BOOL key, int64_t value, BOOL *stop))block {
10639   BOOL stop = NO;
10640   if (_valueSet[0]) {
10641     block(NO, _values[0], &stop);
10642   }
10643   if (!stop && _valueSet[1]) {
10644     block(YES, _values[1], &stop);
10645   }
10648 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
10649   GPBDataType valueDataType = GPBGetFieldDataType(field);
10650   NSUInteger count = 0;
10651   size_t result = 0;
10652   for (int i = 0; i < 2; ++i) {
10653     if (_valueSet[i]) {
10654       ++count;
10655       size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10656       msgSize += ComputeDictInt64FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
10657       result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
10658     }
10659   }
10660   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
10661   result += tagSize * count;
10662   return result;
10665 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
10666                          asField:(GPBFieldDescriptor *)field {
10667   GPBDataType valueDataType = GPBGetFieldDataType(field);
10668   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
10669   for (int i = 0; i < 2; ++i) {
10670     if (_valueSet[i]) {
10671       // Write the tag.
10672       [outputStream writeInt32NoTag:tag];
10673       // Write the size of the message.
10674       size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10675       msgSize += ComputeDictInt64FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
10676       [outputStream writeInt32NoTag:(int32_t)msgSize];
10677       // Write the fields.
10678       WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10679       WriteDictInt64Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
10680     }
10681   }
10684 - (void)addEntriesFromDictionary:(GPBBoolInt64Dictionary *)otherDictionary {
10685   if (otherDictionary) {
10686     for (int i = 0; i < 2; ++i) {
10687       if (otherDictionary->_valueSet[i]) {
10688         _valueSet[i] = YES;
10689         _values[i] = otherDictionary->_values[i];
10690       }
10691     }
10692     if (_autocreator) {
10693       GPBAutocreatedDictionaryModified(_autocreator, self);
10694     }
10695   }
10698 - (void)setInt64:(int64_t)value forKey:(BOOL)key {
10699   int idx = (key ? 1 : 0);
10700   _values[idx] = value;
10701   _valueSet[idx] = YES;
10702   if (_autocreator) {
10703     GPBAutocreatedDictionaryModified(_autocreator, self);
10704   }
10707 - (void)removeInt64ForKey:(BOOL)aKey {
10708   _valueSet[aKey ? 1 : 0] = NO;
10711 - (void)removeAll {
10712   _valueSet[0] = NO;
10713   _valueSet[1] = NO;
10716 @end
10718 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Bool, BOOL)
10719 // This block of code is generated, do not edit it directly.
10721 #pragma mark - Bool -> Bool
10723 @implementation GPBBoolBoolDictionary {
10724  @package
10725   BOOL _values[2];
10726   BOOL _valueSet[2];
10729 - (instancetype)init {
10730   return [self initWithBools:NULL forKeys:NULL count:0];
10733 - (instancetype)initWithBools:(const BOOL [])values
10734                       forKeys:(const BOOL [])keys
10735                         count:(NSUInteger)count {
10736   self = [super init];
10737   if (self) {
10738     for (NSUInteger i = 0; i < count; ++i) {
10739       int idx = keys[i] ? 1 : 0;
10740       _values[idx] = values[i];
10741       _valueSet[idx] = YES;
10742     }
10743   }
10744   return self;
10747 - (instancetype)initWithDictionary:(GPBBoolBoolDictionary *)dictionary {
10748   self = [self initWithBools:NULL forKeys:NULL count:0];
10749   if (self) {
10750     if (dictionary) {
10751       for (int i = 0; i < 2; ++i) {
10752         if (dictionary->_valueSet[i]) {
10753           _values[i] = dictionary->_values[i];
10754           _valueSet[i] = YES;
10755         }
10756       }
10757     }
10758   }
10759   return self;
10762 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
10763   return [self initWithBools:NULL forKeys:NULL count:0];
10766 #if !defined(NS_BLOCK_ASSERTIONS)
10767 - (void)dealloc {
10768   NSAssert(!_autocreator,
10769            @"%@: Autocreator must be cleared before release, autocreator: %@",
10770            [self class], _autocreator);
10771   [super dealloc];
10773 #endif  // !defined(NS_BLOCK_ASSERTIONS)
10775 - (instancetype)copyWithZone:(NSZone *)zone {
10776   return [[GPBBoolBoolDictionary allocWithZone:zone] initWithDictionary:self];
10779 - (BOOL)isEqual:(id)other {
10780   if (self == other) {
10781     return YES;
10782   }
10783   if (![other isKindOfClass:[GPBBoolBoolDictionary class]]) {
10784     return NO;
10785   }
10786   GPBBoolBoolDictionary *otherDictionary = other;
10787   if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
10788       (_valueSet[1] != otherDictionary->_valueSet[1])) {
10789     return NO;
10790   }
10791   if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
10792       (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
10793     return NO;
10794   }
10795   return YES;
10798 - (NSUInteger)hash {
10799   return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
10802 - (NSString *)description {
10803   NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
10804   if (_valueSet[0]) {
10805     [result appendFormat:@"NO: %d", _values[0]];
10806   }
10807   if (_valueSet[1]) {
10808     [result appendFormat:@"YES: %d", _values[1]];
10809   }
10810   [result appendString:@" }"];
10811   return result;
10814 - (NSUInteger)count {
10815   return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
10818 - (BOOL)getBool:(BOOL *)value forKey:(BOOL)key {
10819   int idx = (key ? 1 : 0);
10820   if (_valueSet[idx]) {
10821     if (value) {
10822       *value = _values[idx];
10823     }
10824     return YES;
10825   }
10826   return NO;
10829 - (void)setGPBGenericValue:(GPBGenericValue *)value
10830      forGPBGenericValueKey:(GPBGenericValue *)key {
10831   int idx = (key->valueBool ? 1 : 0);
10832   _values[idx] = value->valueBool;
10833   _valueSet[idx] = YES;
10836 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
10837   if (_valueSet[0]) {
10838     block(@"false", (_values[0] ? @"true" : @"false"));
10839   }
10840   if (_valueSet[1]) {
10841     block(@"true", (_values[1] ? @"true" : @"false"));
10842   }
10845 - (void)enumerateKeysAndBoolsUsingBlock:
10846     (void (NS_NOESCAPE ^)(BOOL key, BOOL value, BOOL *stop))block {
10847   BOOL stop = NO;
10848   if (_valueSet[0]) {
10849     block(NO, _values[0], &stop);
10850   }
10851   if (!stop && _valueSet[1]) {
10852     block(YES, _values[1], &stop);
10853   }
10856 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
10857   GPBDataType valueDataType = GPBGetFieldDataType(field);
10858   NSUInteger count = 0;
10859   size_t result = 0;
10860   for (int i = 0; i < 2; ++i) {
10861     if (_valueSet[i]) {
10862       ++count;
10863       size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10864       msgSize += ComputeDictBoolFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
10865       result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
10866     }
10867   }
10868   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
10869   result += tagSize * count;
10870   return result;
10873 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
10874                          asField:(GPBFieldDescriptor *)field {
10875   GPBDataType valueDataType = GPBGetFieldDataType(field);
10876   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
10877   for (int i = 0; i < 2; ++i) {
10878     if (_valueSet[i]) {
10879       // Write the tag.
10880       [outputStream writeInt32NoTag:tag];
10881       // Write the size of the message.
10882       size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10883       msgSize += ComputeDictBoolFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
10884       [outputStream writeInt32NoTag:(int32_t)msgSize];
10885       // Write the fields.
10886       WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10887       WriteDictBoolField(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
10888     }
10889   }
10892 - (void)addEntriesFromDictionary:(GPBBoolBoolDictionary *)otherDictionary {
10893   if (otherDictionary) {
10894     for (int i = 0; i < 2; ++i) {
10895       if (otherDictionary->_valueSet[i]) {
10896         _valueSet[i] = YES;
10897         _values[i] = otherDictionary->_values[i];
10898       }
10899     }
10900     if (_autocreator) {
10901       GPBAutocreatedDictionaryModified(_autocreator, self);
10902     }
10903   }
10906 - (void)setBool:(BOOL)value forKey:(BOOL)key {
10907   int idx = (key ? 1 : 0);
10908   _values[idx] = value;
10909   _valueSet[idx] = YES;
10910   if (_autocreator) {
10911     GPBAutocreatedDictionaryModified(_autocreator, self);
10912   }
10915 - (void)removeBoolForKey:(BOOL)aKey {
10916   _valueSet[aKey ? 1 : 0] = NO;
10919 - (void)removeAll {
10920   _valueSet[0] = NO;
10921   _valueSet[1] = NO;
10924 @end
10926 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Float, float)
10927 // This block of code is generated, do not edit it directly.
10929 #pragma mark - Bool -> Float
10931 @implementation GPBBoolFloatDictionary {
10932  @package
10933   float _values[2];
10934   BOOL _valueSet[2];
10937 - (instancetype)init {
10938   return [self initWithFloats:NULL forKeys:NULL count:0];
10941 - (instancetype)initWithFloats:(const float [])values
10942                        forKeys:(const BOOL [])keys
10943                          count:(NSUInteger)count {
10944   self = [super init];
10945   if (self) {
10946     for (NSUInteger i = 0; i < count; ++i) {
10947       int idx = keys[i] ? 1 : 0;
10948       _values[idx] = values[i];
10949       _valueSet[idx] = YES;
10950     }
10951   }
10952   return self;
10955 - (instancetype)initWithDictionary:(GPBBoolFloatDictionary *)dictionary {
10956   self = [self initWithFloats:NULL forKeys:NULL count:0];
10957   if (self) {
10958     if (dictionary) {
10959       for (int i = 0; i < 2; ++i) {
10960         if (dictionary->_valueSet[i]) {
10961           _values[i] = dictionary->_values[i];
10962           _valueSet[i] = YES;
10963         }
10964       }
10965     }
10966   }
10967   return self;
10970 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
10971   return [self initWithFloats:NULL forKeys:NULL count:0];
10974 #if !defined(NS_BLOCK_ASSERTIONS)
10975 - (void)dealloc {
10976   NSAssert(!_autocreator,
10977            @"%@: Autocreator must be cleared before release, autocreator: %@",
10978            [self class], _autocreator);
10979   [super dealloc];
10981 #endif  // !defined(NS_BLOCK_ASSERTIONS)
10983 - (instancetype)copyWithZone:(NSZone *)zone {
10984   return [[GPBBoolFloatDictionary allocWithZone:zone] initWithDictionary:self];
10987 - (BOOL)isEqual:(id)other {
10988   if (self == other) {
10989     return YES;
10990   }
10991   if (![other isKindOfClass:[GPBBoolFloatDictionary class]]) {
10992     return NO;
10993   }
10994   GPBBoolFloatDictionary *otherDictionary = other;
10995   if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
10996       (_valueSet[1] != otherDictionary->_valueSet[1])) {
10997     return NO;
10998   }
10999   if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
11000       (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
11001     return NO;
11002   }
11003   return YES;
11006 - (NSUInteger)hash {
11007   return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
11010 - (NSString *)description {
11011   NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
11012   if (_valueSet[0]) {
11013     [result appendFormat:@"NO: %f", _values[0]];
11014   }
11015   if (_valueSet[1]) {
11016     [result appendFormat:@"YES: %f", _values[1]];
11017   }
11018   [result appendString:@" }"];
11019   return result;
11022 - (NSUInteger)count {
11023   return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
11026 - (BOOL)getFloat:(float *)value forKey:(BOOL)key {
11027   int idx = (key ? 1 : 0);
11028   if (_valueSet[idx]) {
11029     if (value) {
11030       *value = _values[idx];
11031     }
11032     return YES;
11033   }
11034   return NO;
11037 - (void)setGPBGenericValue:(GPBGenericValue *)value
11038      forGPBGenericValueKey:(GPBGenericValue *)key {
11039   int idx = (key->valueBool ? 1 : 0);
11040   _values[idx] = value->valueFloat;
11041   _valueSet[idx] = YES;
11044 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
11045   if (_valueSet[0]) {
11046     block(@"false", [NSString stringWithFormat:@"%.*g", FLT_DIG, _values[0]]);
11047   }
11048   if (_valueSet[1]) {
11049     block(@"true", [NSString stringWithFormat:@"%.*g", FLT_DIG, _values[1]]);
11050   }
11053 - (void)enumerateKeysAndFloatsUsingBlock:
11054     (void (NS_NOESCAPE ^)(BOOL key, float value, BOOL *stop))block {
11055   BOOL stop = NO;
11056   if (_valueSet[0]) {
11057     block(NO, _values[0], &stop);
11058   }
11059   if (!stop && _valueSet[1]) {
11060     block(YES, _values[1], &stop);
11061   }
11064 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
11065   GPBDataType valueDataType = GPBGetFieldDataType(field);
11066   NSUInteger count = 0;
11067   size_t result = 0;
11068   for (int i = 0; i < 2; ++i) {
11069     if (_valueSet[i]) {
11070       ++count;
11071       size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11072       msgSize += ComputeDictFloatFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
11073       result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
11074     }
11075   }
11076   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
11077   result += tagSize * count;
11078   return result;
11081 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
11082                          asField:(GPBFieldDescriptor *)field {
11083   GPBDataType valueDataType = GPBGetFieldDataType(field);
11084   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
11085   for (int i = 0; i < 2; ++i) {
11086     if (_valueSet[i]) {
11087       // Write the tag.
11088       [outputStream writeInt32NoTag:tag];
11089       // Write the size of the message.
11090       size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11091       msgSize += ComputeDictFloatFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
11092       [outputStream writeInt32NoTag:(int32_t)msgSize];
11093       // Write the fields.
11094       WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11095       WriteDictFloatField(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
11096     }
11097   }
11100 - (void)addEntriesFromDictionary:(GPBBoolFloatDictionary *)otherDictionary {
11101   if (otherDictionary) {
11102     for (int i = 0; i < 2; ++i) {
11103       if (otherDictionary->_valueSet[i]) {
11104         _valueSet[i] = YES;
11105         _values[i] = otherDictionary->_values[i];
11106       }
11107     }
11108     if (_autocreator) {
11109       GPBAutocreatedDictionaryModified(_autocreator, self);
11110     }
11111   }
11114 - (void)setFloat:(float)value forKey:(BOOL)key {
11115   int idx = (key ? 1 : 0);
11116   _values[idx] = value;
11117   _valueSet[idx] = YES;
11118   if (_autocreator) {
11119     GPBAutocreatedDictionaryModified(_autocreator, self);
11120   }
11123 - (void)removeFloatForKey:(BOOL)aKey {
11124   _valueSet[aKey ? 1 : 0] = NO;
11127 - (void)removeAll {
11128   _valueSet[0] = NO;
11129   _valueSet[1] = NO;
11132 @end
11134 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Double, double)
11135 // This block of code is generated, do not edit it directly.
11137 #pragma mark - Bool -> Double
11139 @implementation GPBBoolDoubleDictionary {
11140  @package
11141   double _values[2];
11142   BOOL _valueSet[2];
11145 - (instancetype)init {
11146   return [self initWithDoubles:NULL forKeys:NULL count:0];
11149 - (instancetype)initWithDoubles:(const double [])values
11150                         forKeys:(const BOOL [])keys
11151                           count:(NSUInteger)count {
11152   self = [super init];
11153   if (self) {
11154     for (NSUInteger i = 0; i < count; ++i) {
11155       int idx = keys[i] ? 1 : 0;
11156       _values[idx] = values[i];
11157       _valueSet[idx] = YES;
11158     }
11159   }
11160   return self;
11163 - (instancetype)initWithDictionary:(GPBBoolDoubleDictionary *)dictionary {
11164   self = [self initWithDoubles:NULL forKeys:NULL count:0];
11165   if (self) {
11166     if (dictionary) {
11167       for (int i = 0; i < 2; ++i) {
11168         if (dictionary->_valueSet[i]) {
11169           _values[i] = dictionary->_values[i];
11170           _valueSet[i] = YES;
11171         }
11172       }
11173     }
11174   }
11175   return self;
11178 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
11179   return [self initWithDoubles:NULL forKeys:NULL count:0];
11182 #if !defined(NS_BLOCK_ASSERTIONS)
11183 - (void)dealloc {
11184   NSAssert(!_autocreator,
11185            @"%@: Autocreator must be cleared before release, autocreator: %@",
11186            [self class], _autocreator);
11187   [super dealloc];
11189 #endif  // !defined(NS_BLOCK_ASSERTIONS)
11191 - (instancetype)copyWithZone:(NSZone *)zone {
11192   return [[GPBBoolDoubleDictionary allocWithZone:zone] initWithDictionary:self];
11195 - (BOOL)isEqual:(id)other {
11196   if (self == other) {
11197     return YES;
11198   }
11199   if (![other isKindOfClass:[GPBBoolDoubleDictionary class]]) {
11200     return NO;
11201   }
11202   GPBBoolDoubleDictionary *otherDictionary = other;
11203   if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
11204       (_valueSet[1] != otherDictionary->_valueSet[1])) {
11205     return NO;
11206   }
11207   if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
11208       (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
11209     return NO;
11210   }
11211   return YES;
11214 - (NSUInteger)hash {
11215   return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
11218 - (NSString *)description {
11219   NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
11220   if (_valueSet[0]) {
11221     [result appendFormat:@"NO: %lf", _values[0]];
11222   }
11223   if (_valueSet[1]) {
11224     [result appendFormat:@"YES: %lf", _values[1]];
11225   }
11226   [result appendString:@" }"];
11227   return result;
11230 - (NSUInteger)count {
11231   return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
11234 - (BOOL)getDouble:(double *)value forKey:(BOOL)key {
11235   int idx = (key ? 1 : 0);
11236   if (_valueSet[idx]) {
11237     if (value) {
11238       *value = _values[idx];
11239     }
11240     return YES;
11241   }
11242   return NO;
11245 - (void)setGPBGenericValue:(GPBGenericValue *)value
11246      forGPBGenericValueKey:(GPBGenericValue *)key {
11247   int idx = (key->valueBool ? 1 : 0);
11248   _values[idx] = value->valueDouble;
11249   _valueSet[idx] = YES;
11252 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
11253   if (_valueSet[0]) {
11254     block(@"false", [NSString stringWithFormat:@"%.*lg", DBL_DIG, _values[0]]);
11255   }
11256   if (_valueSet[1]) {
11257     block(@"true", [NSString stringWithFormat:@"%.*lg", DBL_DIG, _values[1]]);
11258   }
11261 - (void)enumerateKeysAndDoublesUsingBlock:
11262     (void (NS_NOESCAPE ^)(BOOL key, double value, BOOL *stop))block {
11263   BOOL stop = NO;
11264   if (_valueSet[0]) {
11265     block(NO, _values[0], &stop);
11266   }
11267   if (!stop && _valueSet[1]) {
11268     block(YES, _values[1], &stop);
11269   }
11272 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
11273   GPBDataType valueDataType = GPBGetFieldDataType(field);
11274   NSUInteger count = 0;
11275   size_t result = 0;
11276   for (int i = 0; i < 2; ++i) {
11277     if (_valueSet[i]) {
11278       ++count;
11279       size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11280       msgSize += ComputeDictDoubleFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
11281       result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
11282     }
11283   }
11284   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
11285   result += tagSize * count;
11286   return result;
11289 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
11290                          asField:(GPBFieldDescriptor *)field {
11291   GPBDataType valueDataType = GPBGetFieldDataType(field);
11292   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
11293   for (int i = 0; i < 2; ++i) {
11294     if (_valueSet[i]) {
11295       // Write the tag.
11296       [outputStream writeInt32NoTag:tag];
11297       // Write the size of the message.
11298       size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11299       msgSize += ComputeDictDoubleFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
11300       [outputStream writeInt32NoTag:(int32_t)msgSize];
11301       // Write the fields.
11302       WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11303       WriteDictDoubleField(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
11304     }
11305   }
11308 - (void)addEntriesFromDictionary:(GPBBoolDoubleDictionary *)otherDictionary {
11309   if (otherDictionary) {
11310     for (int i = 0; i < 2; ++i) {
11311       if (otherDictionary->_valueSet[i]) {
11312         _valueSet[i] = YES;
11313         _values[i] = otherDictionary->_values[i];
11314       }
11315     }
11316     if (_autocreator) {
11317       GPBAutocreatedDictionaryModified(_autocreator, self);
11318     }
11319   }
11322 - (void)setDouble:(double)value forKey:(BOOL)key {
11323   int idx = (key ? 1 : 0);
11324   _values[idx] = value;
11325   _valueSet[idx] = YES;
11326   if (_autocreator) {
11327     GPBAutocreatedDictionaryModified(_autocreator, self);
11328   }
11331 - (void)removeDoubleForKey:(BOOL)aKey {
11332   _valueSet[aKey ? 1 : 0] = NO;
11335 - (void)removeAll {
11336   _valueSet[0] = NO;
11337   _valueSet[1] = NO;
11340 @end
11342 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_OBJECT_IMPL(Object, id)
11343 // This block of code is generated, do not edit it directly.
11345 #pragma mark - Bool -> Object
11347 @implementation GPBBoolObjectDictionary {
11348  @package
11349   id _values[2];
11352 - (instancetype)init {
11353   return [self initWithObjects:NULL forKeys:NULL count:0];
11356 - (instancetype)initWithObjects:(const id [])objects
11357                         forKeys:(const BOOL [])keys
11358                           count:(NSUInteger)count {
11359   self = [super init];
11360   if (self) {
11361     for (NSUInteger i = 0; i < count; ++i) {
11362       if (!objects[i]) {
11363         [NSException raise:NSInvalidArgumentException
11364                     format:@"Attempting to add nil object to a Dictionary"];
11365       }
11366       int idx = keys[i] ? 1 : 0;
11367       [_values[idx] release];
11368       _values[idx] = (id)[objects[i] retain];
11369     }
11370   }
11371   return self;
11374 - (instancetype)initWithDictionary:(GPBBoolObjectDictionary *)dictionary {
11375   self = [self initWithObjects:NULL forKeys:NULL count:0];
11376   if (self) {
11377     if (dictionary) {
11378       _values[0] = [dictionary->_values[0] retain];
11379       _values[1] = [dictionary->_values[1] retain];
11380     }
11381   }
11382   return self;
11385 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
11386   return [self initWithObjects:NULL forKeys:NULL count:0];
11389 - (void)dealloc {
11390   NSAssert(!_autocreator,
11391            @"%@: Autocreator must be cleared before release, autocreator: %@",
11392            [self class], _autocreator);
11393   [_values[0] release];
11394   [_values[1] release];
11395   [super dealloc];
11398 - (instancetype)copyWithZone:(NSZone *)zone {
11399   return [[GPBBoolObjectDictionary allocWithZone:zone] initWithDictionary:self];
11402 - (BOOL)isEqual:(id)other {
11403   if (self == other) {
11404     return YES;
11405   }
11406   if (![other isKindOfClass:[GPBBoolObjectDictionary class]]) {
11407     return NO;
11408   }
11409   GPBBoolObjectDictionary *otherDictionary = other;
11410   if (((_values[0] != nil) != (otherDictionary->_values[0] != nil)) ||
11411       ((_values[1] != nil) != (otherDictionary->_values[1] != nil))) {
11412     return NO;
11413   }
11414   if (((_values[0] != nil) && (![_values[0] isEqual:otherDictionary->_values[0]])) ||
11415       ((_values[1] != nil) && (![_values[1] isEqual:otherDictionary->_values[1]]))) {
11416     return NO;
11417   }
11418   return YES;
11421 - (NSUInteger)hash {
11422   return ((_values[0] != nil) ? 1 : 0) + ((_values[1] != nil) ? 1 : 0);
11425 - (NSString *)description {
11426   NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
11427   if ((_values[0] != nil)) {
11428     [result appendFormat:@"NO: %@", _values[0]];
11429   }
11430   if ((_values[1] != nil)) {
11431     [result appendFormat:@"YES: %@", _values[1]];
11432   }
11433   [result appendString:@" }"];
11434   return result;
11437 - (NSUInteger)count {
11438   return ((_values[0] != nil) ? 1 : 0) + ((_values[1] != nil) ? 1 : 0);
11441 - (id)objectForKey:(BOOL)key {
11442   return _values[key ? 1 : 0];
11445 - (void)setGPBGenericValue:(GPBGenericValue *)value
11446      forGPBGenericValueKey:(GPBGenericValue *)key {
11447   int idx = (key->valueBool ? 1 : 0);
11448   [_values[idx] release];
11449   _values[idx] = [value->valueString retain];
11452 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
11453   if (_values[0] != nil) {
11454     block(@"false", _values[0]);
11455   }
11456   if ((_values[1] != nil)) {
11457     block(@"true", _values[1]);
11458   }
11461 - (void)enumerateKeysAndObjectsUsingBlock:
11462     (void (NS_NOESCAPE ^)(BOOL key, id object, BOOL *stop))block {
11463   BOOL stop = NO;
11464   if (_values[0] != nil) {
11465     block(NO, _values[0], &stop);
11466   }
11467   if (!stop && (_values[1] != nil)) {
11468     block(YES, _values[1], &stop);
11469   }
11472 - (BOOL)isInitialized {
11473   if (_values[0] && ![_values[0] isInitialized]) {
11474     return NO;
11475   }
11476   if (_values[1] && ![_values[1] isInitialized]) {
11477     return NO;
11478   }
11479   return YES;
11482 - (instancetype)deepCopyWithZone:(NSZone *)zone {
11483   GPBBoolObjectDictionary *newDict =
11484       [[GPBBoolObjectDictionary alloc] init];
11485   for (int i = 0; i < 2; ++i) {
11486     if (_values[i] != nil) {
11487       newDict->_values[i] = [_values[i] copyWithZone:zone];
11488     }
11489   }
11490   return newDict;
11493 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
11494   GPBDataType valueDataType = GPBGetFieldDataType(field);
11495   NSUInteger count = 0;
11496   size_t result = 0;
11497   for (int i = 0; i < 2; ++i) {
11498     if (_values[i] != nil) {
11499       ++count;
11500       size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11501       msgSize += ComputeDictObjectFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
11502       result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
11503     }
11504   }
11505   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
11506   result += tagSize * count;
11507   return result;
11510 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
11511                          asField:(GPBFieldDescriptor *)field {
11512   GPBDataType valueDataType = GPBGetFieldDataType(field);
11513   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
11514   for (int i = 0; i < 2; ++i) {
11515     if (_values[i] != nil) {
11516       // Write the tag.
11517       [outputStream writeInt32NoTag:tag];
11518       // Write the size of the message.
11519       size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11520       msgSize += ComputeDictObjectFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
11521       [outputStream writeInt32NoTag:(int32_t)msgSize];
11522       // Write the fields.
11523       WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11524       WriteDictObjectField(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
11525     }
11526   }
11529 - (void)addEntriesFromDictionary:(GPBBoolObjectDictionary *)otherDictionary {
11530   if (otherDictionary) {
11531     for (int i = 0; i < 2; ++i) {
11532       if (otherDictionary->_values[i] != nil) {
11533         [_values[i] release];
11534         _values[i] = [otherDictionary->_values[i] retain];
11535       }
11536     }
11537     if (_autocreator) {
11538       GPBAutocreatedDictionaryModified(_autocreator, self);
11539     }
11540   }
11543 - (void)setObject:(id)object forKey:(BOOL)key {
11544   if (!object) {
11545     [NSException raise:NSInvalidArgumentException
11546                 format:@"Attempting to add nil object to a Dictionary"];
11547   }
11548   int idx = (key ? 1 : 0);
11549   [_values[idx] release];
11550   _values[idx] = [object retain];
11551   if (_autocreator) {
11552     GPBAutocreatedDictionaryModified(_autocreator, self);
11553   }
11556 - (void)removeObjectForKey:(BOOL)aKey {
11557   int idx = (aKey ? 1 : 0);
11558   [_values[idx] release];
11559   _values[idx] = nil;
11562 - (void)removeAll {
11563   for (int i = 0; i < 2; ++i) {
11564     [_values[i] release];
11565     _values[i] = nil;
11566   }
11569 @end
11571 //%PDDM-EXPAND-END (8 expansions)
11573 // clang-format on
11575 #pragma mark - Bool -> Enum
11577 @implementation GPBBoolEnumDictionary {
11578  @package
11579   GPBEnumValidationFunc _validationFunc;
11580   int32_t _values[2];
11581   BOOL _valueSet[2];
11584 @synthesize validationFunc = _validationFunc;
11586 - (instancetype)init {
11587   return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
11590 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
11591   return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
11594 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
11595                                  rawValues:(const int32_t[])rawValues
11596                                    forKeys:(const BOOL[])keys
11597                                      count:(NSUInteger)count {
11598   self = [super init];
11599   if (self) {
11600     _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
11601     for (NSUInteger i = 0; i < count; ++i) {
11602       int idx = keys[i] ? 1 : 0;
11603       _values[idx] = rawValues[i];
11604       _valueSet[idx] = YES;
11605     }
11606   }
11607   return self;
11610 - (instancetype)initWithDictionary:(GPBBoolEnumDictionary *)dictionary {
11611   self = [self initWithValidationFunction:dictionary.validationFunc
11612                                 rawValues:NULL
11613                                   forKeys:NULL
11614                                     count:0];
11615   if (self) {
11616     if (dictionary) {
11617       for (int i = 0; i < 2; ++i) {
11618         if (dictionary->_valueSet[i]) {
11619           _values[i] = dictionary->_values[i];
11620           _valueSet[i] = YES;
11621         }
11622       }
11623     }
11624   }
11625   return self;
11628 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
11629                                   capacity:(__unused NSUInteger)numItems {
11630   return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
11633 #if !defined(NS_BLOCK_ASSERTIONS)
11634 - (void)dealloc {
11635   NSAssert(!_autocreator, @"%@: Autocreator must be cleared before release, autocreator: %@",
11636            [self class], _autocreator);
11637   [super dealloc];
11639 #endif  // !defined(NS_BLOCK_ASSERTIONS)
11641 - (instancetype)copyWithZone:(NSZone *)zone {
11642   return [[GPBBoolEnumDictionary allocWithZone:zone] initWithDictionary:self];
11645 - (BOOL)isEqual:(id)other {
11646   if (self == other) {
11647     return YES;
11648   }
11649   if (![other isKindOfClass:[GPBBoolEnumDictionary class]]) {
11650     return NO;
11651   }
11652   GPBBoolEnumDictionary *otherDictionary = other;
11653   if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
11654       (_valueSet[1] != otherDictionary->_valueSet[1])) {
11655     return NO;
11656   }
11657   if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
11658       (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
11659     return NO;
11660   }
11661   return YES;
11664 - (NSUInteger)hash {
11665   return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
11668 - (NSString *)description {
11669   NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
11670   if (_valueSet[0]) {
11671     [result appendFormat:@"NO: %d", _values[0]];
11672   }
11673   if (_valueSet[1]) {
11674     [result appendFormat:@"YES: %d", _values[1]];
11675   }
11676   [result appendString:@" }"];
11677   return result;
11680 - (NSUInteger)count {
11681   return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
11684 - (BOOL)getEnum:(int32_t *)value forKey:(BOOL)key {
11685   int idx = (key ? 1 : 0);
11686   if (_valueSet[idx]) {
11687     if (value) {
11688       int32_t result = _values[idx];
11689       if (!_validationFunc(result)) {
11690         result = kGPBUnrecognizedEnumeratorValue;
11691       }
11692       *value = result;
11693     }
11694     return YES;
11695   }
11696   return NO;
11699 - (BOOL)getRawValue:(int32_t *)rawValue forKey:(BOOL)key {
11700   int idx = (key ? 1 : 0);
11701   if (_valueSet[idx]) {
11702     if (rawValue) {
11703       *rawValue = _values[idx];
11704     }
11705     return YES;
11706   }
11707   return NO;
11710 - (void)enumerateKeysAndRawValuesUsingBlock:(void(NS_NOESCAPE ^)(BOOL key, int32_t value,
11711                                                                  BOOL *stop))block {
11712   BOOL stop = NO;
11713   if (_valueSet[0]) {
11714     block(NO, _values[0], &stop);
11715   }
11716   if (!stop && _valueSet[1]) {
11717     block(YES, _values[1], &stop);
11718   }
11721 - (void)enumerateKeysAndEnumsUsingBlock:(void(NS_NOESCAPE ^)(BOOL key, int32_t rawValue,
11722                                                              BOOL *stop))block {
11723   BOOL stop = NO;
11724   GPBEnumValidationFunc func = _validationFunc;
11725   int32_t validatedValue;
11726   if (_valueSet[0]) {
11727     validatedValue = _values[0];
11728     if (!func(validatedValue)) {
11729       validatedValue = kGPBUnrecognizedEnumeratorValue;
11730     }
11731     block(NO, validatedValue, &stop);
11732   }
11733   if (!stop && _valueSet[1]) {
11734     validatedValue = _values[1];
11735     if (!func(validatedValue)) {
11736       validatedValue = kGPBUnrecognizedEnumeratorValue;
11737     }
11738     block(YES, validatedValue, &stop);
11739   }
11742 // clang-format off
11744 //%PDDM-EXPAND SERIAL_DATA_FOR_ENTRY_POD_Enum(Bool)
11745 // This block of code is generated, do not edit it directly.
11747 - (NSData *)serializedDataForUnknownValue:(int32_t)value
11748                                    forKey:(GPBGenericValue *)key
11749                               keyDataType:(GPBDataType)keyDataType {
11750   size_t msgSize = ComputeDictBoolFieldSize(key->valueBool, kMapKeyFieldNumber, keyDataType);
11751   msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
11752   NSMutableData *data = [NSMutableData dataWithLength:msgSize];
11753   GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
11754   WriteDictBoolField(outputStream, key->valueBool, kMapKeyFieldNumber, keyDataType);
11755   WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
11756   [outputStream flush];
11757   [outputStream release];
11758   return data;
11761 //%PDDM-EXPAND-END SERIAL_DATA_FOR_ENTRY_POD_Enum(Bool)
11763 // clang-format on
11765 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
11766   GPBDataType valueDataType = GPBGetFieldDataType(field);
11767   NSUInteger count = 0;
11768   size_t result = 0;
11769   for (int i = 0; i < 2; ++i) {
11770     if (_valueSet[i]) {
11771       ++count;
11772       size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11773       msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
11774       result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
11775     }
11776   }
11777   size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
11778   result += tagSize * count;
11779   return result;
11782 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
11783                          asField:(GPBFieldDescriptor *)field {
11784   GPBDataType valueDataType = GPBGetFieldDataType(field);
11785   uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
11786   for (int i = 0; i < 2; ++i) {
11787     if (_valueSet[i]) {
11788       // Write the tag.
11789       [outputStream writeInt32NoTag:tag];
11790       // Write the size of the message.
11791       size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11792       msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
11793       [outputStream writeInt32NoTag:(int32_t)msgSize];
11794       // Write the fields.
11795       WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11796       WriteDictInt32Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
11797     }
11798   }
11801 - (void)enumerateForTextFormat:(void(NS_NOESCAPE ^)(id keyObj, id valueObj))block {
11802   if (_valueSet[0]) {
11803     block(@"false", @(_values[0]));
11804   }
11805   if (_valueSet[1]) {
11806     block(@"true", @(_values[1]));
11807   }
11810 - (void)setGPBGenericValue:(GPBGenericValue *)value forGPBGenericValueKey:(GPBGenericValue *)key {
11811   int idx = (key->valueBool ? 1 : 0);
11812   _values[idx] = value->valueInt32;
11813   _valueSet[idx] = YES;
11816 - (void)addRawEntriesFromDictionary:(GPBBoolEnumDictionary *)otherDictionary {
11817   if (otherDictionary) {
11818     for (int i = 0; i < 2; ++i) {
11819       if (otherDictionary->_valueSet[i]) {
11820         _valueSet[i] = YES;
11821         _values[i] = otherDictionary->_values[i];
11822       }
11823     }
11824     if (_autocreator) {
11825       GPBAutocreatedDictionaryModified(_autocreator, self);
11826     }
11827   }
11830 - (void)setEnum:(int32_t)value forKey:(BOOL)key {
11831   if (!_validationFunc(value)) {
11832     [NSException raise:NSInvalidArgumentException
11833                 format:@"GPBBoolEnumDictionary: Attempt to set an unknown enum value (%d)", value];
11834   }
11835   int idx = (key ? 1 : 0);
11836   _values[idx] = value;
11837   _valueSet[idx] = YES;
11838   if (_autocreator) {
11839     GPBAutocreatedDictionaryModified(_autocreator, self);
11840   }
11843 - (void)setRawValue:(int32_t)rawValue forKey:(BOOL)key {
11844   int idx = (key ? 1 : 0);
11845   _values[idx] = rawValue;
11846   _valueSet[idx] = YES;
11847   if (_autocreator) {
11848     GPBAutocreatedDictionaryModified(_autocreator, self);
11849   }
11852 - (void)removeEnumForKey:(BOOL)aKey {
11853   _valueSet[aKey ? 1 : 0] = NO;
11856 - (void)removeAll {
11857   _valueSet[0] = NO;
11858   _valueSet[1] = NO;
11861 @end
11863 #pragma mark - NSDictionary Subclass
11865 @implementation GPBAutocreatedDictionary {
11866   NSMutableDictionary *_dictionary;
11869 - (void)dealloc {
11870   NSAssert(!_autocreator, @"%@: Autocreator must be cleared before release, autocreator: %@",
11871            [self class], _autocreator);
11872   [_dictionary release];
11873   [super dealloc];
11876 #pragma mark Required NSDictionary overrides
11878 - (instancetype)initWithObjects:(const id[])objects
11879                         forKeys:(const id<NSCopying>[])keys
11880                           count:(NSUInteger)count {
11881   self = [super init];
11882   if (self) {
11883     _dictionary = [[NSMutableDictionary alloc] initWithObjects:objects forKeys:keys count:count];
11884   }
11885   return self;
11888 - (NSUInteger)count {
11889   return [_dictionary count];
11892 - (id)objectForKey:(id)aKey {
11893   return [_dictionary objectForKey:aKey];
11896 - (NSEnumerator *)keyEnumerator {
11897   if (_dictionary == nil) {
11898     _dictionary = [[NSMutableDictionary alloc] init];
11899   }
11900   return [_dictionary keyEnumerator];
11903 #pragma mark Required NSMutableDictionary overrides
11905 // Only need to call GPBAutocreatedDictionaryModified() when adding things
11906 // since we only autocreate empty dictionaries.
11908 - (void)setObject:(id)anObject forKey:(id<NSCopying>)aKey {
11909   if (_dictionary == nil) {
11910     _dictionary = [[NSMutableDictionary alloc] init];
11911   }
11912   [_dictionary setObject:anObject forKey:aKey];
11913   if (_autocreator) {
11914     GPBAutocreatedDictionaryModified(_autocreator, self);
11915   }
11918 - (void)removeObjectForKey:(id)aKey {
11919   [_dictionary removeObjectForKey:aKey];
11922 #pragma mark Extra things hooked
11924 - (id)copyWithZone:(NSZone *)zone {
11925   if (_dictionary == nil) {
11926     return [[NSMutableDictionary allocWithZone:zone] init];
11927   }
11928   return [_dictionary copyWithZone:zone];
11931 - (id)mutableCopyWithZone:(NSZone *)zone {
11932   if (_dictionary == nil) {
11933     return [[NSMutableDictionary allocWithZone:zone] init];
11934   }
11935   return [_dictionary mutableCopyWithZone:zone];
11938 // Not really needed, but subscripting is likely common enough it doesn't hurt
11939 // to ensure it goes directly to the real NSMutableDictionary.
11940 - (id)objectForKeyedSubscript:(id)key {
11941   return [_dictionary objectForKeyedSubscript:key];
11944 // Not really needed, but subscripting is likely common enough it doesn't hurt
11945 // to ensure it goes directly to the real NSMutableDictionary.
11946 - (void)setObject:(id)obj forKeyedSubscript:(id<NSCopying>)key {
11947   if (_dictionary == nil) {
11948     _dictionary = [[NSMutableDictionary alloc] init];
11949   }
11950   [_dictionary setObject:obj forKeyedSubscript:key];
11951   if (_autocreator) {
11952     GPBAutocreatedDictionaryModified(_autocreator, self);
11953   }
11956 - (void)enumerateKeysAndObjectsUsingBlock:(void(NS_NOESCAPE ^)(id key, id obj, BOOL *stop))block {
11957   [_dictionary enumerateKeysAndObjectsUsingBlock:block];
11960 - (void)enumerateKeysAndObjectsWithOptions:(NSEnumerationOptions)opts
11961                                 usingBlock:(void(NS_NOESCAPE ^)(id key, id obj, BOOL *stop))block {
11962   [_dictionary enumerateKeysAndObjectsWithOptions:opts usingBlock:block];
11965 @end
11967 #pragma clang diagnostic pop