1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
15 // * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #import "GPBDictionary_PackagePrivate.h"
33 #import "GPBCodedInputStream_PackagePrivate.h"
34 #import "GPBCodedOutputStream_PackagePrivate.h"
35 #import "GPBDescriptor_PackagePrivate.h"
36 #import "GPBMessage_PackagePrivate.h"
37 #import "GPBUtilities_PackagePrivate.h"
39 // ------------------------------ NOTE ------------------------------
40 // At the moment, this is all using NSNumbers in NSDictionaries under
41 // the hood, but it is all hidden so we can come back and optimize
42 // with direct CFDictionary usage later. The reason that wasn't
43 // done yet is needing to support 32bit iOS builds. Otherwise
44 // it would be pretty simple to store all this data in CFDictionaries
46 // ------------------------------------------------------------------
48 // Direct access is use for speed, to avoid even internally declaring things
49 // read/write, etc. The warning is enabled in the project to ensure code calling
50 // protos can turn on -Wdirect-ivar-access without issues.
51 #pragma clang diagnostic push
52 #pragma clang diagnostic ignored "-Wdirect-ivar-access"
54 // Used to include code only visible to specific versions of the static
55 // analyzer. Useful for wrapping code that only exists to silence the analyzer.
56 // Determine the values you want to use for BEGIN_APPLE_BUILD_VERSION,
57 // END_APPLE_BUILD_VERSION using:
58 // xcrun clang -dM -E -x c /dev/null | grep __apple_build_version__
60 // #if GPB_STATIC_ANALYZER_ONLY(5621, 5623) ... #endif
61 #define GPB_STATIC_ANALYZER_ONLY(BEGIN_APPLE_BUILD_VERSION, END_APPLE_BUILD_VERSION) \
62 (defined(__clang_analyzer__) && \
63 (__apple_build_version__ >= BEGIN_APPLE_BUILD_VERSION && \
64 __apple_build_version__ <= END_APPLE_BUILD_VERSION))
67 kMapKeyFieldNumber = 1,
68 kMapValueFieldNumber = 2,
71 static BOOL DictDefault_IsValidValue(int32_t value) {
72 // Anything but the bad value marker is allowed.
73 return (value != kGPBUnrecognizedEnumeratorValue);
76 //%PDDM-DEFINE SERIALIZE_SUPPORT_2_TYPE(VALUE_NAME, VALUE_TYPE, GPBDATATYPE_NAME1, GPBDATATYPE_NAME2)
77 //%static size_t ComputeDict##VALUE_NAME##FieldSize(VALUE_TYPE value, uint32_t fieldNum, GPBDataType dataType) {
78 //% if (dataType == GPBDataType##GPBDATATYPE_NAME1) {
79 //% return GPBCompute##GPBDATATYPE_NAME1##Size(fieldNum, value);
80 //% } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) {
81 //% return GPBCompute##GPBDATATYPE_NAME2##Size(fieldNum, value);
83 //% NSCAssert(NO, @"Unexpected type %d", dataType);
88 //%static void WriteDict##VALUE_NAME##Field(GPBCodedOutputStream *stream, VALUE_TYPE value, uint32_t fieldNum, GPBDataType dataType) {
89 //% if (dataType == GPBDataType##GPBDATATYPE_NAME1) {
90 //% [stream write##GPBDATATYPE_NAME1##:fieldNum value:value];
91 //% } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) {
92 //% [stream write##GPBDATATYPE_NAME2##:fieldNum value:value];
94 //% NSCAssert(NO, @"Unexpected type %d", dataType);
98 //%PDDM-DEFINE SERIALIZE_SUPPORT_3_TYPE(VALUE_NAME, VALUE_TYPE, GPBDATATYPE_NAME1, GPBDATATYPE_NAME2, GPBDATATYPE_NAME3)
99 //%static size_t ComputeDict##VALUE_NAME##FieldSize(VALUE_TYPE value, uint32_t fieldNum, GPBDataType dataType) {
100 //% if (dataType == GPBDataType##GPBDATATYPE_NAME1) {
101 //% return GPBCompute##GPBDATATYPE_NAME1##Size(fieldNum, value);
102 //% } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) {
103 //% return GPBCompute##GPBDATATYPE_NAME2##Size(fieldNum, value);
104 //% } else if (dataType == GPBDataType##GPBDATATYPE_NAME3) {
105 //% return GPBCompute##GPBDATATYPE_NAME3##Size(fieldNum, value);
107 //% NSCAssert(NO, @"Unexpected type %d", dataType);
112 //%static void WriteDict##VALUE_NAME##Field(GPBCodedOutputStream *stream, VALUE_TYPE value, uint32_t fieldNum, GPBDataType dataType) {
113 //% if (dataType == GPBDataType##GPBDATATYPE_NAME1) {
114 //% [stream write##GPBDATATYPE_NAME1##:fieldNum value:value];
115 //% } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) {
116 //% [stream write##GPBDATATYPE_NAME2##:fieldNum value:value];
117 //% } else if (dataType == GPBDataType##GPBDATATYPE_NAME3) {
118 //% [stream write##GPBDATATYPE_NAME3##:fieldNum value:value];
120 //% NSCAssert(NO, @"Unexpected type %d", dataType);
124 //%PDDM-DEFINE SIMPLE_SERIALIZE_SUPPORT(VALUE_NAME, VALUE_TYPE, VisP)
125 //%static size_t ComputeDict##VALUE_NAME##FieldSize(VALUE_TYPE VisP##value, uint32_t fieldNum, GPBDataType dataType) {
126 //% NSCAssert(dataType == GPBDataType##VALUE_NAME, @"bad type: %d", dataType);
127 //% #pragma unused(dataType) // For when asserts are off in release.
128 //% return GPBCompute##VALUE_NAME##Size(fieldNum, value);
131 //%static void WriteDict##VALUE_NAME##Field(GPBCodedOutputStream *stream, VALUE_TYPE VisP##value, uint32_t fieldNum, GPBDataType dataType) {
132 //% NSCAssert(dataType == GPBDataType##VALUE_NAME, @"bad type: %d", dataType);
133 //% #pragma unused(dataType) // For when asserts are off in release.
134 //% [stream write##VALUE_NAME##:fieldNum value:value];
137 //%PDDM-DEFINE SERIALIZE_SUPPORT_HELPERS()
138 //%SERIALIZE_SUPPORT_3_TYPE(Int32, int32_t, Int32, SInt32, SFixed32)
139 //%SERIALIZE_SUPPORT_2_TYPE(UInt32, uint32_t, UInt32, Fixed32)
140 //%SERIALIZE_SUPPORT_3_TYPE(Int64, int64_t, Int64, SInt64, SFixed64)
141 //%SERIALIZE_SUPPORT_2_TYPE(UInt64, uint64_t, UInt64, Fixed64)
142 //%SIMPLE_SERIALIZE_SUPPORT(Bool, BOOL, )
143 //%SIMPLE_SERIALIZE_SUPPORT(Enum, int32_t, )
144 //%SIMPLE_SERIALIZE_SUPPORT(Float, float, )
145 //%SIMPLE_SERIALIZE_SUPPORT(Double, double, )
146 //%SIMPLE_SERIALIZE_SUPPORT(String, NSString, *)
147 //%SERIALIZE_SUPPORT_3_TYPE(Object, id, Message, String, Bytes)
148 //%PDDM-EXPAND SERIALIZE_SUPPORT_HELPERS()
149 // This block of code is generated, do not edit it directly.
151 static size_t ComputeDictInt32FieldSize(int32_t value, uint32_t fieldNum, GPBDataType dataType) {
152 if (dataType == GPBDataTypeInt32) {
153 return GPBComputeInt32Size(fieldNum, value);
154 } else if (dataType == GPBDataTypeSInt32) {
155 return GPBComputeSInt32Size(fieldNum, value);
156 } else if (dataType == GPBDataTypeSFixed32) {
157 return GPBComputeSFixed32Size(fieldNum, value);
159 NSCAssert(NO, @"Unexpected type %d", dataType);
164 static void WriteDictInt32Field(GPBCodedOutputStream *stream, int32_t value, uint32_t fieldNum, GPBDataType dataType) {
165 if (dataType == GPBDataTypeInt32) {
166 [stream writeInt32:fieldNum value:value];
167 } else if (dataType == GPBDataTypeSInt32) {
168 [stream writeSInt32:fieldNum value:value];
169 } else if (dataType == GPBDataTypeSFixed32) {
170 [stream writeSFixed32:fieldNum value:value];
172 NSCAssert(NO, @"Unexpected type %d", dataType);
176 static size_t ComputeDictUInt32FieldSize(uint32_t value, uint32_t fieldNum, GPBDataType dataType) {
177 if (dataType == GPBDataTypeUInt32) {
178 return GPBComputeUInt32Size(fieldNum, value);
179 } else if (dataType == GPBDataTypeFixed32) {
180 return GPBComputeFixed32Size(fieldNum, value);
182 NSCAssert(NO, @"Unexpected type %d", dataType);
187 static void WriteDictUInt32Field(GPBCodedOutputStream *stream, uint32_t value, uint32_t fieldNum, GPBDataType dataType) {
188 if (dataType == GPBDataTypeUInt32) {
189 [stream writeUInt32:fieldNum value:value];
190 } else if (dataType == GPBDataTypeFixed32) {
191 [stream writeFixed32:fieldNum value:value];
193 NSCAssert(NO, @"Unexpected type %d", dataType);
197 static size_t ComputeDictInt64FieldSize(int64_t value, uint32_t fieldNum, GPBDataType dataType) {
198 if (dataType == GPBDataTypeInt64) {
199 return GPBComputeInt64Size(fieldNum, value);
200 } else if (dataType == GPBDataTypeSInt64) {
201 return GPBComputeSInt64Size(fieldNum, value);
202 } else if (dataType == GPBDataTypeSFixed64) {
203 return GPBComputeSFixed64Size(fieldNum, value);
205 NSCAssert(NO, @"Unexpected type %d", dataType);
210 static void WriteDictInt64Field(GPBCodedOutputStream *stream, int64_t value, uint32_t fieldNum, GPBDataType dataType) {
211 if (dataType == GPBDataTypeInt64) {
212 [stream writeInt64:fieldNum value:value];
213 } else if (dataType == GPBDataTypeSInt64) {
214 [stream writeSInt64:fieldNum value:value];
215 } else if (dataType == GPBDataTypeSFixed64) {
216 [stream writeSFixed64:fieldNum value:value];
218 NSCAssert(NO, @"Unexpected type %d", dataType);
222 static size_t ComputeDictUInt64FieldSize(uint64_t value, uint32_t fieldNum, GPBDataType dataType) {
223 if (dataType == GPBDataTypeUInt64) {
224 return GPBComputeUInt64Size(fieldNum, value);
225 } else if (dataType == GPBDataTypeFixed64) {
226 return GPBComputeFixed64Size(fieldNum, value);
228 NSCAssert(NO, @"Unexpected type %d", dataType);
233 static void WriteDictUInt64Field(GPBCodedOutputStream *stream, uint64_t value, uint32_t fieldNum, GPBDataType dataType) {
234 if (dataType == GPBDataTypeUInt64) {
235 [stream writeUInt64:fieldNum value:value];
236 } else if (dataType == GPBDataTypeFixed64) {
237 [stream writeFixed64:fieldNum value:value];
239 NSCAssert(NO, @"Unexpected type %d", dataType);
243 static size_t ComputeDictBoolFieldSize(BOOL value, uint32_t fieldNum, GPBDataType dataType) {
244 NSCAssert(dataType == GPBDataTypeBool, @"bad type: %d", dataType);
245 #pragma unused(dataType) // For when asserts are off in release.
246 return GPBComputeBoolSize(fieldNum, value);
249 static void WriteDictBoolField(GPBCodedOutputStream *stream, BOOL value, uint32_t fieldNum, GPBDataType dataType) {
250 NSCAssert(dataType == GPBDataTypeBool, @"bad type: %d", dataType);
251 #pragma unused(dataType) // For when asserts are off in release.
252 [stream writeBool:fieldNum value:value];
255 static size_t ComputeDictEnumFieldSize(int32_t value, uint32_t fieldNum, GPBDataType dataType) {
256 NSCAssert(dataType == GPBDataTypeEnum, @"bad type: %d", dataType);
257 #pragma unused(dataType) // For when asserts are off in release.
258 return GPBComputeEnumSize(fieldNum, value);
261 static void WriteDictEnumField(GPBCodedOutputStream *stream, int32_t value, uint32_t fieldNum, GPBDataType dataType) {
262 NSCAssert(dataType == GPBDataTypeEnum, @"bad type: %d", dataType);
263 #pragma unused(dataType) // For when asserts are off in release.
264 [stream writeEnum:fieldNum value:value];
267 static size_t ComputeDictFloatFieldSize(float value, uint32_t fieldNum, GPBDataType dataType) {
268 NSCAssert(dataType == GPBDataTypeFloat, @"bad type: %d", dataType);
269 #pragma unused(dataType) // For when asserts are off in release.
270 return GPBComputeFloatSize(fieldNum, value);
273 static void WriteDictFloatField(GPBCodedOutputStream *stream, float value, uint32_t fieldNum, GPBDataType dataType) {
274 NSCAssert(dataType == GPBDataTypeFloat, @"bad type: %d", dataType);
275 #pragma unused(dataType) // For when asserts are off in release.
276 [stream writeFloat:fieldNum value:value];
279 static size_t ComputeDictDoubleFieldSize(double value, uint32_t fieldNum, GPBDataType dataType) {
280 NSCAssert(dataType == GPBDataTypeDouble, @"bad type: %d", dataType);
281 #pragma unused(dataType) // For when asserts are off in release.
282 return GPBComputeDoubleSize(fieldNum, value);
285 static void WriteDictDoubleField(GPBCodedOutputStream *stream, double value, uint32_t fieldNum, GPBDataType dataType) {
286 NSCAssert(dataType == GPBDataTypeDouble, @"bad type: %d", dataType);
287 #pragma unused(dataType) // For when asserts are off in release.
288 [stream writeDouble:fieldNum value:value];
291 static size_t ComputeDictStringFieldSize(NSString *value, uint32_t fieldNum, GPBDataType dataType) {
292 NSCAssert(dataType == GPBDataTypeString, @"bad type: %d", dataType);
293 #pragma unused(dataType) // For when asserts are off in release.
294 return GPBComputeStringSize(fieldNum, value);
297 static void WriteDictStringField(GPBCodedOutputStream *stream, NSString *value, uint32_t fieldNum, GPBDataType dataType) {
298 NSCAssert(dataType == GPBDataTypeString, @"bad type: %d", dataType);
299 #pragma unused(dataType) // For when asserts are off in release.
300 [stream writeString:fieldNum value:value];
303 static size_t ComputeDictObjectFieldSize(id value, uint32_t fieldNum, GPBDataType dataType) {
304 if (dataType == GPBDataTypeMessage) {
305 return GPBComputeMessageSize(fieldNum, value);
306 } else if (dataType == GPBDataTypeString) {
307 return GPBComputeStringSize(fieldNum, value);
308 } else if (dataType == GPBDataTypeBytes) {
309 return GPBComputeBytesSize(fieldNum, value);
311 NSCAssert(NO, @"Unexpected type %d", dataType);
316 static void WriteDictObjectField(GPBCodedOutputStream *stream, id value, uint32_t fieldNum, GPBDataType dataType) {
317 if (dataType == GPBDataTypeMessage) {
318 [stream writeMessage:fieldNum value:value];
319 } else if (dataType == GPBDataTypeString) {
320 [stream writeString:fieldNum value:value];
321 } else if (dataType == GPBDataTypeBytes) {
322 [stream writeBytes:fieldNum value:value];
324 NSCAssert(NO, @"Unexpected type %d", dataType);
328 //%PDDM-EXPAND-END SERIALIZE_SUPPORT_HELPERS()
330 size_t GPBDictionaryComputeSizeInternalHelper(NSDictionary *dict, GPBFieldDescriptor *field) {
331 GPBDataType mapValueType = GPBGetFieldDataType(field);
334 NSEnumerator *keys = [dict keyEnumerator];
335 while ((key = [keys nextObject])) {
337 size_t msgSize = GPBComputeStringSize(kMapKeyFieldNumber, key);
338 msgSize += ComputeDictObjectFieldSize(obj, kMapValueFieldNumber, mapValueType);
339 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
341 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
342 result += tagSize * dict.count;
346 void GPBDictionaryWriteToStreamInternalHelper(GPBCodedOutputStream *outputStream,
348 GPBFieldDescriptor *field) {
349 NSCAssert(field.mapKeyDataType == GPBDataTypeString, @"Unexpected key type");
350 GPBDataType mapValueType = GPBGetFieldDataType(field);
351 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
353 NSEnumerator *keys = [dict keyEnumerator];
354 while ((key = [keys nextObject])) {
357 [outputStream writeInt32NoTag:tag];
358 // Write the size of the message.
359 size_t msgSize = GPBComputeStringSize(kMapKeyFieldNumber, key);
360 msgSize += ComputeDictObjectFieldSize(obj, kMapValueFieldNumber, mapValueType);
362 // Write the size and fields.
363 [outputStream writeInt32NoTag:(int32_t)msgSize];
364 [outputStream writeString:kMapKeyFieldNumber value:key];
365 WriteDictObjectField(outputStream, obj, kMapValueFieldNumber, mapValueType);
369 BOOL GPBDictionaryIsInitializedInternalHelper(NSDictionary *dict, GPBFieldDescriptor *field) {
370 NSCAssert(field.mapKeyDataType == GPBDataTypeString, @"Unexpected key type");
371 NSCAssert(GPBGetFieldDataType(field) == GPBDataTypeMessage, @"Unexpected value type");
372 #pragma unused(field) // For when asserts are off in release.
374 NSEnumerator *objects = [dict objectEnumerator];
375 while ((msg = [objects nextObject])) {
376 if (!msg.initialized) {
383 // Note: if the type is an object, it the retain pass back to the caller.
384 static void ReadValue(GPBCodedInputStream *stream,
385 GPBGenericValue *valueToFill,
387 GPBExtensionRegistry *registry,
388 GPBFieldDescriptor *field) {
390 case GPBDataTypeBool:
391 valueToFill->valueBool = GPBCodedInputStreamReadBool(&stream->state_);
393 case GPBDataTypeFixed32:
394 valueToFill->valueUInt32 = GPBCodedInputStreamReadFixed32(&stream->state_);
396 case GPBDataTypeSFixed32:
397 valueToFill->valueInt32 = GPBCodedInputStreamReadSFixed32(&stream->state_);
399 case GPBDataTypeFloat:
400 valueToFill->valueFloat = GPBCodedInputStreamReadFloat(&stream->state_);
402 case GPBDataTypeFixed64:
403 valueToFill->valueUInt64 = GPBCodedInputStreamReadFixed64(&stream->state_);
405 case GPBDataTypeSFixed64:
406 valueToFill->valueInt64 = GPBCodedInputStreamReadSFixed64(&stream->state_);
408 case GPBDataTypeDouble:
409 valueToFill->valueDouble = GPBCodedInputStreamReadDouble(&stream->state_);
411 case GPBDataTypeInt32:
412 valueToFill->valueInt32 = GPBCodedInputStreamReadInt32(&stream->state_);
414 case GPBDataTypeInt64:
415 valueToFill->valueInt64 = GPBCodedInputStreamReadInt64(&stream->state_);
417 case GPBDataTypeSInt32:
418 valueToFill->valueInt32 = GPBCodedInputStreamReadSInt32(&stream->state_);
420 case GPBDataTypeSInt64:
421 valueToFill->valueInt64 = GPBCodedInputStreamReadSInt64(&stream->state_);
423 case GPBDataTypeUInt32:
424 valueToFill->valueUInt32 = GPBCodedInputStreamReadUInt32(&stream->state_);
426 case GPBDataTypeUInt64:
427 valueToFill->valueUInt64 = GPBCodedInputStreamReadUInt64(&stream->state_);
429 case GPBDataTypeBytes:
430 [valueToFill->valueData release];
431 valueToFill->valueData = GPBCodedInputStreamReadRetainedBytes(&stream->state_);
433 case GPBDataTypeString:
434 [valueToFill->valueString release];
435 valueToFill->valueString = GPBCodedInputStreamReadRetainedString(&stream->state_);
437 case GPBDataTypeMessage: {
438 GPBMessage *message = [[field.msgClass alloc] init];
439 [stream readMessage:message extensionRegistry:registry];
440 [valueToFill->valueMessage release];
441 valueToFill->valueMessage = message;
444 case GPBDataTypeGroup:
445 NSCAssert(NO, @"Can't happen");
447 case GPBDataTypeEnum:
448 valueToFill->valueEnum = GPBCodedInputStreamReadEnum(&stream->state_);
453 void GPBDictionaryReadEntry(id mapDictionary,
454 GPBCodedInputStream *stream,
455 GPBExtensionRegistry *registry,
456 GPBFieldDescriptor *field,
457 GPBMessage *parentMessage) {
458 GPBDataType keyDataType = field.mapKeyDataType;
459 GPBDataType valueDataType = GPBGetFieldDataType(field);
462 GPBGenericValue value;
463 // Zero them (but pick up any enum default for proto2).
464 key.valueString = value.valueString = nil;
465 if (valueDataType == GPBDataTypeEnum) {
466 value = field.defaultValue;
469 GPBCodedInputStreamState *state = &stream->state_;
471 GPBWireFormatMakeTag(kMapKeyFieldNumber, GPBWireFormatForType(keyDataType, NO));
473 GPBWireFormatMakeTag(kMapValueFieldNumber, GPBWireFormatForType(valueDataType, NO));
477 uint32_t tag = GPBCodedInputStreamReadTag(state);
479 ReadValue(stream, &key, keyDataType, registry, field);
480 } else if (tag == valueTag) {
481 ReadValue(stream, &value, valueDataType, registry, field);
482 } else if (tag == 0) {
483 // zero signals EOF / limit reached
486 if (![stream skipField:tag]){
494 // Handle the special defaults and/or missing key/value.
495 if ((keyDataType == GPBDataTypeString) && (key.valueString == nil)) {
496 key.valueString = [@"" retain];
498 if (GPBDataTypeIsObject(valueDataType) && value.valueString == nil) {
499 #pragma clang diagnostic push
500 #pragma clang diagnostic ignored "-Wswitch-enum"
501 switch (valueDataType) {
502 case GPBDataTypeString:
503 value.valueString = [@"" retain];
505 case GPBDataTypeBytes:
506 value.valueData = [GPBEmptyNSData() retain];
508 #if defined(__clang_analyzer__)
509 case GPBDataTypeGroup:
510 // Maps can't really have Groups as the value type, but this case is needed
511 // so the analyzer won't report the posibility of send nil in for the value
512 // in the NSMutableDictionary case below.
514 case GPBDataTypeMessage: {
515 value.valueMessage = [[field.msgClass alloc] init];
522 #pragma clang diagnostic pop
525 if ((keyDataType == GPBDataTypeString) && GPBDataTypeIsObject(valueDataType)) {
526 #if GPB_STATIC_ANALYZER_ONLY(6020053, 7000181)
527 // Limited to Xcode 6.4 - 7.2, are known to fail here. The upper end can
528 // be raised as needed for new Xcodes.
530 // This is only needed on a "shallow" analyze; on a "deep" analyze, the
531 // existing code path gets this correct. In shallow, the analyzer decides
532 // GPBDataTypeIsObject(valueDataType) is both false and true on a single
533 // path through this function, allowing nil to be used for the
534 // setObject:forKey:.
535 if (value.valueString == nil) {
536 value.valueString = [@"" retain];
539 // mapDictionary is an NSMutableDictionary
540 [(NSMutableDictionary *)mapDictionary setObject:value.valueString
541 forKey:key.valueString];
543 if (valueDataType == GPBDataTypeEnum) {
544 if (GPBHasPreservingUnknownEnumSemantics([parentMessage descriptor].file.syntax) ||
545 [field isValidEnumValue:value.valueEnum]) {
546 [mapDictionary setGPBGenericValue:&value forGPBGenericValueKey:&key];
548 NSData *data = [mapDictionary serializedDataForUnknownValue:value.valueEnum
550 keyDataType:keyDataType];
551 [parentMessage addUnknownMapEntry:GPBFieldNumber(field) value:data];
554 [mapDictionary setGPBGenericValue:&value forGPBGenericValueKey:&key];
559 if (GPBDataTypeIsObject(keyDataType)) {
560 [key.valueString release];
562 if (GPBDataTypeIsObject(valueDataType)) {
563 [value.valueString release];
568 // Macros for the common basic cases.
571 //%PDDM-DEFINE DICTIONARY_IMPL_FOR_POD_KEY(KEY_NAME, KEY_TYPE)
572 //%DICTIONARY_POD_IMPL_FOR_KEY(KEY_NAME, KEY_TYPE, , POD)
573 //%DICTIONARY_POD_KEY_TO_OBJECT_IMPL(KEY_NAME, KEY_TYPE, Object, id)
575 //%PDDM-DEFINE DICTIONARY_POD_IMPL_FOR_KEY(KEY_NAME, KEY_TYPE, KisP, KHELPER)
576 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, UInt32, uint32_t, KHELPER)
577 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Int32, int32_t, KHELPER)
578 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, UInt64, uint64_t, KHELPER)
579 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Int64, int64_t, KHELPER)
580 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Bool, BOOL, KHELPER)
581 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Float, float, KHELPER)
582 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Double, double, KHELPER)
583 //%DICTIONARY_KEY_TO_ENUM_IMPL(KEY_NAME, KEY_TYPE, KisP, Enum, int32_t, KHELPER)
585 //%PDDM-DEFINE DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER)
586 //%DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, POD, VALUE_NAME, value)
588 //%PDDM-DEFINE DICTIONARY_POD_KEY_TO_OBJECT_IMPL(KEY_NAME, KEY_TYPE, VALUE_NAME, VALUE_TYPE)
589 //%DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, , VALUE_NAME, VALUE_TYPE, POD, OBJECT, Object, object)
591 //%PDDM-DEFINE DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR)
592 //%#pragma mark - KEY_NAME -> VALUE_NAME
594 //%@implementation GPB##KEY_NAME##VALUE_NAME##Dictionary {
596 //% NSMutableDictionary *_dictionary;
599 //%- (instancetype)init {
600 //% return [self initWith##VNAME##s:NULL forKeys:NULL count:0];
603 //%- (instancetype)initWith##VNAME##s:(const VALUE_TYPE [])##VNAME_VAR##s
604 //% ##VNAME$S## forKeys:(const KEY_TYPE##KisP$S##KisP [])keys
605 //% ##VNAME$S## count:(NSUInteger)count {
606 //% self = [super init];
608 //% _dictionary = [[NSMutableDictionary alloc] init];
609 //% if (count && VNAME_VAR##s && keys) {
610 //% for (NSUInteger i = 0; i < count; ++i) {
611 //%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])];
618 //%- (instancetype)initWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary {
619 //% self = [self initWith##VNAME##s:NULL forKeys:NULL count:0];
621 //% if (dictionary) {
622 //% [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
628 //%- (instancetype)initWithCapacity:(NSUInteger)numItems {
629 //% #pragma unused(numItems)
630 //% return [self initWith##VNAME##s:NULL forKeys:NULL count:0];
633 //%DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, )
635 //%VALUE_FOR_KEY_##VHELPER(KEY_TYPE##KisP$S##KisP, VALUE_NAME, VALUE_TYPE, KHELPER)
637 //%DICTIONARY_MUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, )
642 //%PDDM-DEFINE DICTIONARY_KEY_TO_ENUM_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER)
643 //%DICTIONARY_KEY_TO_ENUM_IMPL2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, POD)
644 //%PDDM-DEFINE DICTIONARY_KEY_TO_ENUM_IMPL2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER)
645 //%#pragma mark - KEY_NAME -> VALUE_NAME
647 //%@implementation GPB##KEY_NAME##VALUE_NAME##Dictionary {
649 //% NSMutableDictionary *_dictionary;
650 //% GPBEnumValidationFunc _validationFunc;
653 //%@synthesize validationFunc = _validationFunc;
655 //%- (instancetype)init {
656 //% return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
659 //%- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
660 //% return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
663 //%- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
664 //% rawValues:(const VALUE_TYPE [])rawValues
665 //% forKeys:(const KEY_TYPE##KisP$S##KisP [])keys
666 //% count:(NSUInteger)count {
667 //% self = [super init];
669 //% _dictionary = [[NSMutableDictionary alloc] init];
670 //% _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
671 //% if (count && rawValues && keys) {
672 //% for (NSUInteger i = 0; i < count; ++i) {
673 //%DICTIONARY_VALIDATE_KEY_##KHELPER(keys[i], ______) [_dictionary setObject:WRAPPED##VHELPER(rawValues[i]) forKey:WRAPPED##KHELPER(keys[i])];
680 //%- (instancetype)initWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary {
681 //% self = [self initWithValidationFunction:dictionary.validationFunc
686 //% if (dictionary) {
687 //% [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
693 //%- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
694 //% capacity:(NSUInteger)numItems {
695 //% #pragma unused(numItems)
696 //% return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
699 //%DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, Value, value, Raw)
701 //%- (BOOL)getEnum:(VALUE_TYPE *)value forKey:(KEY_TYPE##KisP$S##KisP)key {
702 //% NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)];
703 //% if (wrapped && value) {
704 //% VALUE_TYPE result = UNWRAP##VALUE_NAME(wrapped);
705 //% if (!_validationFunc(result)) {
706 //% result = kGPBUnrecognizedEnumeratorValue;
710 //% return (wrapped != NULL);
713 //%- (BOOL)getRawValue:(VALUE_TYPE *)rawValue forKey:(KEY_TYPE##KisP$S##KisP)key {
714 //% NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)];
715 //% if (wrapped && rawValue) {
716 //% *rawValue = UNWRAP##VALUE_NAME(wrapped);
718 //% return (wrapped != NULL);
721 //%- (void)enumerateKeysAndEnumsUsingBlock:
722 //% (void (^)(KEY_TYPE KisP##key, VALUE_TYPE value, BOOL *stop))block {
723 //% GPBEnumValidationFunc func = _validationFunc;
725 //% NSEnumerator *keys = [_dictionary keyEnumerator];
726 //% ENUM_TYPE##KHELPER(KEY_TYPE)##aKey;
727 //% while ((aKey = [keys nextObject])) {
728 //% ENUM_TYPE##VHELPER(VALUE_TYPE)##aValue = _dictionary[aKey];
729 //% VALUE_TYPE unwrapped = UNWRAP##VALUE_NAME(aValue);
730 //% if (!func(unwrapped)) {
731 //% unwrapped = kGPBUnrecognizedEnumeratorValue;
733 //% block(UNWRAP##KEY_NAME(aKey), unwrapped, &stop);
740 //%DICTIONARY_MUTABLE_CORE2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, Value, Enum, value, Raw)
742 //%- (void)setEnum:(VALUE_TYPE)value forKey:(KEY_TYPE##KisP$S##KisP)key {
743 //%DICTIONARY_VALIDATE_KEY_##KHELPER(key, ) if (!_validationFunc(value)) {
744 //% [NSException raise:NSInvalidArgumentException
745 //% format:@"GPB##KEY_NAME##VALUE_NAME##Dictionary: Attempt to set an unknown enum value (%d)",
749 //% [_dictionary setObject:WRAPPED##VHELPER(value) forKey:WRAPPED##KHELPER(key)];
750 //% if (_autocreator) {
751 //% GPBAutocreatedDictionaryModified(_autocreator, self);
758 //%PDDM-DEFINE DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, ACCESSOR_NAME)
760 //% NSAssert(!_autocreator,
761 //% @"%@: Autocreator must be cleared before release, autocreator: %@",
762 //% [self class], _autocreator);
763 //% [_dictionary release];
767 //%- (instancetype)copyWithZone:(NSZone *)zone {
768 //% return [[GPB##KEY_NAME##VALUE_NAME##Dictionary allocWithZone:zone] initWithDictionary:self];
771 //%- (BOOL)isEqual:(id)other {
772 //% if (self == other) {
775 //% if (![other isKindOfClass:[GPB##KEY_NAME##VALUE_NAME##Dictionary class]]) {
778 //% GPB##KEY_NAME##VALUE_NAME##Dictionary *otherDictionary = other;
779 //% return [_dictionary isEqual:otherDictionary->_dictionary];
782 //%- (NSUInteger)hash {
783 //% return _dictionary.count;
786 //%- (NSString *)description {
787 //% return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
790 //%- (NSUInteger)count {
791 //% return _dictionary.count;
794 //%- (void)enumerateKeysAnd##ACCESSOR_NAME##VNAME##sUsingBlock:
795 //% (void (^)(KEY_TYPE KisP##key, VALUE_TYPE VNAME_VAR, BOOL *stop))block {
797 //% NSDictionary *internal = _dictionary;
798 //% NSEnumerator *keys = [internal keyEnumerator];
799 //% ENUM_TYPE##KHELPER(KEY_TYPE)##aKey;
800 //% while ((aKey = [keys nextObject])) {
801 //% ENUM_TYPE##VHELPER(VALUE_TYPE)##a##VNAME_VAR$u = internal[aKey];
802 //% block(UNWRAP##KEY_NAME(aKey), UNWRAP##VALUE_NAME(a##VNAME_VAR$u), &stop);
809 //%EXTRA_METHODS_##VHELPER(KEY_NAME, VALUE_NAME)- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
810 //% NSDictionary *internal = _dictionary;
811 //% NSUInteger count = internal.count;
812 //% if (count == 0) {
816 //% GPBDataType valueDataType = GPBGetFieldDataType(field);
817 //% GPBDataType keyDataType = field.mapKeyDataType;
818 //% size_t result = 0;
819 //% NSEnumerator *keys = [internal keyEnumerator];
820 //% ENUM_TYPE##KHELPER(KEY_TYPE)##aKey;
821 //% while ((aKey = [keys nextObject])) {
822 //% ENUM_TYPE##VHELPER(VALUE_TYPE)##a##VNAME_VAR$u = internal[aKey];
823 //% size_t msgSize = ComputeDict##KEY_NAME##FieldSize(UNWRAP##KEY_NAME(aKey), kMapKeyFieldNumber, keyDataType);
824 //% msgSize += ComputeDict##VALUE_NAME##FieldSize(UNWRAP##VALUE_NAME(a##VNAME_VAR$u), kMapValueFieldNumber, valueDataType);
825 //% result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
827 //% size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
828 //% result += tagSize * count;
832 //%- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
833 //% asField:(GPBFieldDescriptor *)field {
834 //% GPBDataType valueDataType = GPBGetFieldDataType(field);
835 //% GPBDataType keyDataType = field.mapKeyDataType;
836 //% uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
837 //% NSDictionary *internal = _dictionary;
838 //% NSEnumerator *keys = [internal keyEnumerator];
839 //% ENUM_TYPE##KHELPER(KEY_TYPE)##aKey;
840 //% while ((aKey = [keys nextObject])) {
841 //% ENUM_TYPE##VHELPER(VALUE_TYPE)##a##VNAME_VAR$u = internal[aKey];
842 //% [outputStream writeInt32NoTag:tag];
843 //% // Write the size of the message.
844 //% KEY_TYPE KisP##unwrappedKey = UNWRAP##KEY_NAME(aKey);
845 //% VALUE_TYPE unwrappedValue = UNWRAP##VALUE_NAME(a##VNAME_VAR$u);
846 //% size_t msgSize = ComputeDict##KEY_NAME##FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
847 //% msgSize += ComputeDict##VALUE_NAME##FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
848 //% [outputStream writeInt32NoTag:(int32_t)msgSize];
849 //% // Write the fields.
850 //% WriteDict##KEY_NAME##Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
851 //% WriteDict##VALUE_NAME##Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
855 //%SERIAL_DATA_FOR_ENTRY_##VHELPER(KEY_NAME, VALUE_NAME)- (void)setGPBGenericValue:(GPBGenericValue *)value
856 //% forGPBGenericValueKey:(GPBGenericValue *)key {
857 //% [_dictionary setObject:WRAPPED##VHELPER(value->##GPBVALUE_##VHELPER(VALUE_NAME)##) forKey:WRAPPED##KHELPER(key->value##KEY_NAME)];
860 //%- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
861 //% [self enumerateKeysAnd##ACCESSOR_NAME##VNAME##sUsingBlock:^(KEY_TYPE KisP##key, VALUE_TYPE VNAME_VAR, BOOL *stop) {
862 //% #pragma unused(stop)
863 //% block(TEXT_FORMAT_OBJ##KEY_NAME(key), TEXT_FORMAT_OBJ##VALUE_NAME(VNAME_VAR));
866 //%PDDM-DEFINE DICTIONARY_MUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, ACCESSOR_NAME)
867 //%DICTIONARY_MUTABLE_CORE2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME, VNAME_VAR, ACCESSOR_NAME)
868 //%PDDM-DEFINE DICTIONARY_MUTABLE_CORE2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_REMOVE, VNAME_VAR, ACCESSOR_NAME)
869 //%- (void)add##ACCESSOR_NAME##EntriesFromDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)otherDictionary {
870 //% if (otherDictionary) {
871 //% [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
872 //% if (_autocreator) {
873 //% GPBAutocreatedDictionaryModified(_autocreator, self);
878 //%- (void)set##ACCESSOR_NAME##VNAME##:(VALUE_TYPE)VNAME_VAR forKey:(KEY_TYPE##KisP$S##KisP)key {
879 //%DICTIONARY_VALIDATE_VALUE_##VHELPER(VNAME_VAR, )##DICTIONARY_VALIDATE_KEY_##KHELPER(key, ) [_dictionary setObject:WRAPPED##VHELPER(VNAME_VAR) forKey:WRAPPED##KHELPER(key)];
880 //% if (_autocreator) {
881 //% GPBAutocreatedDictionaryModified(_autocreator, self);
885 //%- (void)remove##VNAME_REMOVE##ForKey:(KEY_TYPE##KisP$S##KisP)aKey {
886 //% [_dictionary removeObjectForKey:WRAPPED##KHELPER(aKey)];
889 //%- (void)removeAll {
890 //% [_dictionary removeAllObjects];
894 // Custom Generation for Bool keys
897 //%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_POD_IMPL(VALUE_NAME, VALUE_TYPE)
898 //%DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, POD, VALUE_NAME, value)
899 //%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_OBJECT_IMPL(VALUE_NAME, VALUE_TYPE)
900 //%DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, OBJECT, Object, object)
902 //%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, HELPER, VNAME, VNAME_VAR)
903 //%#pragma mark - Bool -> VALUE_NAME
905 //%@implementation GPBBool##VALUE_NAME##Dictionary {
907 //% VALUE_TYPE _values[2];
908 //%BOOL_DICT_HAS_STORAGE_##HELPER()}
910 //%- (instancetype)init {
911 //% return [self initWith##VNAME##s:NULL forKeys:NULL count:0];
914 //%BOOL_DICT_INITS_##HELPER(VALUE_NAME, VALUE_TYPE)
916 //%- (instancetype)initWithCapacity:(NSUInteger)numItems {
917 //% #pragma unused(numItems)
918 //% return [self initWith##VNAME##s:NULL forKeys:NULL count:0];
921 //%BOOL_DICT_DEALLOC##HELPER()
923 //%- (instancetype)copyWithZone:(NSZone *)zone {
924 //% return [[GPBBool##VALUE_NAME##Dictionary allocWithZone:zone] initWithDictionary:self];
927 //%- (BOOL)isEqual:(id)other {
928 //% if (self == other) {
931 //% if (![other isKindOfClass:[GPBBool##VALUE_NAME##Dictionary class]]) {
934 //% GPBBool##VALUE_NAME##Dictionary *otherDictionary = other;
935 //% if ((BOOL_DICT_W_HAS##HELPER(0, ) != BOOL_DICT_W_HAS##HELPER(0, otherDictionary->)) ||
936 //% (BOOL_DICT_W_HAS##HELPER(1, ) != BOOL_DICT_W_HAS##HELPER(1, otherDictionary->))) {
939 //% if ((BOOL_DICT_W_HAS##HELPER(0, ) && (NEQ_##HELPER(_values[0], otherDictionary->_values[0]))) ||
940 //% (BOOL_DICT_W_HAS##HELPER(1, ) && (NEQ_##HELPER(_values[1], otherDictionary->_values[1])))) {
946 //%- (NSUInteger)hash {
947 //% return (BOOL_DICT_W_HAS##HELPER(0, ) ? 1 : 0) + (BOOL_DICT_W_HAS##HELPER(1, ) ? 1 : 0);
950 //%- (NSString *)description {
951 //% NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
952 //% if (BOOL_DICT_W_HAS##HELPER(0, )) {
953 //% [result appendFormat:@"NO: STR_FORMAT_##HELPER(VALUE_NAME)", _values[0]];
955 //% if (BOOL_DICT_W_HAS##HELPER(1, )) {
956 //% [result appendFormat:@"YES: STR_FORMAT_##HELPER(VALUE_NAME)", _values[1]];
958 //% [result appendString:@" }"];
962 //%- (NSUInteger)count {
963 //% return (BOOL_DICT_W_HAS##HELPER(0, ) ? 1 : 0) + (BOOL_DICT_W_HAS##HELPER(1, ) ? 1 : 0);
966 //%BOOL_VALUE_FOR_KEY_##HELPER(VALUE_NAME, VALUE_TYPE)
968 //%BOOL_SET_GPBVALUE_FOR_KEY_##HELPER(VALUE_NAME, VALUE_TYPE, VisP)
970 //%- (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
971 //% if (BOOL_DICT_HAS##HELPER(0, )) {
972 //% block(@"false", TEXT_FORMAT_OBJ##VALUE_NAME(_values[0]));
974 //% if (BOOL_DICT_W_HAS##HELPER(1, )) {
975 //% block(@"true", TEXT_FORMAT_OBJ##VALUE_NAME(_values[1]));
979 //%- (void)enumerateKeysAnd##VNAME##sUsingBlock:
980 //% (void (^)(BOOL key, VALUE_TYPE VNAME_VAR, BOOL *stop))block {
982 //% if (BOOL_DICT_HAS##HELPER(0, )) {
983 //% block(NO, _values[0], &stop);
985 //% if (!stop && BOOL_DICT_W_HAS##HELPER(1, )) {
986 //% block(YES, _values[1], &stop);
990 //%BOOL_EXTRA_METHODS_##HELPER(Bool, VALUE_NAME)- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
991 //% GPBDataType valueDataType = GPBGetFieldDataType(field);
992 //% NSUInteger count = 0;
993 //% size_t result = 0;
994 //% for (int i = 0; i < 2; ++i) {
995 //% if (BOOL_DICT_HAS##HELPER(i, )) {
997 //% size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
998 //% msgSize += ComputeDict##VALUE_NAME##FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
999 //% result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
1002 //% size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
1003 //% result += tagSize * count;
1007 //%- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
1008 //% asField:(GPBFieldDescriptor *)field {
1009 //% GPBDataType valueDataType = GPBGetFieldDataType(field);
1010 //% uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
1011 //% for (int i = 0; i < 2; ++i) {
1012 //% if (BOOL_DICT_HAS##HELPER(i, )) {
1013 //% // Write the tag.
1014 //% [outputStream writeInt32NoTag:tag];
1015 //% // Write the size of the message.
1016 //% size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
1017 //% msgSize += ComputeDict##VALUE_NAME##FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
1018 //% [outputStream writeInt32NoTag:(int32_t)msgSize];
1019 //% // Write the fields.
1020 //% WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
1021 //% WriteDict##VALUE_NAME##Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
1026 //%BOOL_DICT_MUTATIONS_##HELPER(VALUE_NAME, VALUE_TYPE)
1036 //%PDDM-DEFINE VALUE_FOR_KEY_POD(KEY_TYPE, VALUE_NAME, VALUE_TYPE, KHELPER)
1037 //%- (BOOL)get##VALUE_NAME##:(nullable VALUE_TYPE *)value forKey:(KEY_TYPE)key {
1038 //% NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)];
1039 //% if (wrapped && value) {
1040 //% *value = UNWRAP##VALUE_NAME(wrapped);
1042 //% return (wrapped != NULL);
1044 //%PDDM-DEFINE WRAPPEDPOD(VALUE)
1046 //%PDDM-DEFINE UNWRAPUInt32(VALUE)
1047 //%[VALUE unsignedIntValue]
1048 //%PDDM-DEFINE UNWRAPInt32(VALUE)
1050 //%PDDM-DEFINE UNWRAPUInt64(VALUE)
1051 //%[VALUE unsignedLongLongValue]
1052 //%PDDM-DEFINE UNWRAPInt64(VALUE)
1053 //%[VALUE longLongValue]
1054 //%PDDM-DEFINE UNWRAPBool(VALUE)
1055 //%[VALUE boolValue]
1056 //%PDDM-DEFINE UNWRAPFloat(VALUE)
1057 //%[VALUE floatValue]
1058 //%PDDM-DEFINE UNWRAPDouble(VALUE)
1059 //%[VALUE doubleValue]
1060 //%PDDM-DEFINE UNWRAPEnum(VALUE)
1062 //%PDDM-DEFINE TEXT_FORMAT_OBJUInt32(VALUE)
1063 //%[NSString stringWithFormat:@"%u", VALUE]
1064 //%PDDM-DEFINE TEXT_FORMAT_OBJInt32(VALUE)
1065 //%[NSString stringWithFormat:@"%d", VALUE]
1066 //%PDDM-DEFINE TEXT_FORMAT_OBJUInt64(VALUE)
1067 //%[NSString stringWithFormat:@"%llu", VALUE]
1068 //%PDDM-DEFINE TEXT_FORMAT_OBJInt64(VALUE)
1069 //%[NSString stringWithFormat:@"%lld", VALUE]
1070 //%PDDM-DEFINE TEXT_FORMAT_OBJBool(VALUE)
1071 //%(VALUE ? @"true" : @"false")
1072 //%PDDM-DEFINE TEXT_FORMAT_OBJFloat(VALUE)
1073 //%[NSString stringWithFormat:@"%.*g", FLT_DIG, VALUE]
1074 //%PDDM-DEFINE TEXT_FORMAT_OBJDouble(VALUE)
1075 //%[NSString stringWithFormat:@"%.*lg", DBL_DIG, VALUE]
1076 //%PDDM-DEFINE TEXT_FORMAT_OBJEnum(VALUE)
1078 //%PDDM-DEFINE ENUM_TYPEPOD(TYPE)
1080 //%PDDM-DEFINE NEQ_POD(VAL1, VAL2)
1082 //%PDDM-DEFINE EXTRA_METHODS_POD(KEY_NAME, VALUE_NAME)
1084 //%PDDM-DEFINE BOOL_EXTRA_METHODS_POD(KEY_NAME, VALUE_NAME)
1086 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD(KEY_NAME, VALUE_NAME)
1087 //%SERIAL_DATA_FOR_ENTRY_POD_##VALUE_NAME(KEY_NAME)
1088 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_UInt32(KEY_NAME)
1090 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Int32(KEY_NAME)
1092 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_UInt64(KEY_NAME)
1094 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Int64(KEY_NAME)
1096 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Bool(KEY_NAME)
1098 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Float(KEY_NAME)
1100 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Double(KEY_NAME)
1102 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Enum(KEY_NAME)
1103 //%- (NSData *)serializedDataForUnknownValue:(int32_t)value
1104 //% forKey:(GPBGenericValue *)key
1105 //% keyDataType:(GPBDataType)keyDataType {
1106 //% size_t msgSize = ComputeDict##KEY_NAME##FieldSize(key->value##KEY_NAME, kMapKeyFieldNumber, keyDataType);
1107 //% msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
1108 //% NSMutableData *data = [NSMutableData dataWithLength:msgSize];
1109 //% GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
1110 //% WriteDict##KEY_NAME##Field(outputStream, key->value##KEY_NAME, kMapKeyFieldNumber, keyDataType);
1111 //% WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
1112 //% [outputStream release];
1116 //%PDDM-DEFINE GPBVALUE_POD(VALUE_NAME)
1117 //%value##VALUE_NAME
1118 //%PDDM-DEFINE DICTIONARY_VALIDATE_VALUE_POD(VALUE_NAME, EXTRA_INDENT)
1120 //%PDDM-DEFINE DICTIONARY_VALIDATE_KEY_POD(KEY_NAME, EXTRA_INDENT)
1123 //%PDDM-DEFINE BOOL_DICT_HAS_STORAGE_POD()
1124 //% BOOL _valueSet[2];
1126 //%PDDM-DEFINE BOOL_DICT_INITS_POD(VALUE_NAME, VALUE_TYPE)
1127 //%- (instancetype)initWith##VALUE_NAME##s:(const VALUE_TYPE [])values
1128 //% ##VALUE_NAME$S## forKeys:(const BOOL [])keys
1129 //% ##VALUE_NAME$S## count:(NSUInteger)count {
1130 //% self = [super init];
1132 //% for (NSUInteger i = 0; i < count; ++i) {
1133 //% int idx = keys[i] ? 1 : 0;
1134 //% _values[idx] = values[i];
1135 //% _valueSet[idx] = YES;
1141 //%- (instancetype)initWithDictionary:(GPBBool##VALUE_NAME##Dictionary *)dictionary {
1142 //% self = [self initWith##VALUE_NAME##s:NULL forKeys:NULL count:0];
1144 //% if (dictionary) {
1145 //% for (int i = 0; i < 2; ++i) {
1146 //% if (dictionary->_valueSet[i]) {
1147 //% _values[i] = dictionary->_values[i];
1148 //% _valueSet[i] = YES;
1155 //%PDDM-DEFINE BOOL_DICT_DEALLOCPOD()
1156 //%#if !defined(NS_BLOCK_ASSERTIONS)
1157 //%- (void)dealloc {
1158 //% NSAssert(!_autocreator,
1159 //% @"%@: Autocreator must be cleared before release, autocreator: %@",
1160 //% [self class], _autocreator);
1161 //% [super dealloc];
1163 //%#endif // !defined(NS_BLOCK_ASSERTIONS)
1164 //%PDDM-DEFINE BOOL_DICT_W_HASPOD(IDX, REF)
1165 //%BOOL_DICT_HASPOD(IDX, REF)
1166 //%PDDM-DEFINE BOOL_DICT_HASPOD(IDX, REF)
1167 //%REF##_valueSet[IDX]
1168 //%PDDM-DEFINE BOOL_VALUE_FOR_KEY_POD(VALUE_NAME, VALUE_TYPE)
1169 //%- (BOOL)get##VALUE_NAME##:(VALUE_TYPE *)value forKey:(BOOL)key {
1170 //% int idx = (key ? 1 : 0);
1171 //% if (_valueSet[idx]) {
1173 //% *value = _values[idx];
1179 //%PDDM-DEFINE BOOL_SET_GPBVALUE_FOR_KEY_POD(VALUE_NAME, VALUE_TYPE, VisP)
1180 //%- (void)setGPBGenericValue:(GPBGenericValue *)value
1181 //% forGPBGenericValueKey:(GPBGenericValue *)key {
1182 //% int idx = (key->valueBool ? 1 : 0);
1183 //% _values[idx] = value->value##VALUE_NAME;
1184 //% _valueSet[idx] = YES;
1186 //%PDDM-DEFINE BOOL_DICT_MUTATIONS_POD(VALUE_NAME, VALUE_TYPE)
1187 //%- (void)addEntriesFromDictionary:(GPBBool##VALUE_NAME##Dictionary *)otherDictionary {
1188 //% if (otherDictionary) {
1189 //% for (int i = 0; i < 2; ++i) {
1190 //% if (otherDictionary->_valueSet[i]) {
1191 //% _valueSet[i] = YES;
1192 //% _values[i] = otherDictionary->_values[i];
1195 //% if (_autocreator) {
1196 //% GPBAutocreatedDictionaryModified(_autocreator, self);
1201 //%- (void)set##VALUE_NAME:(VALUE_TYPE)value forKey:(BOOL)key {
1202 //% int idx = (key ? 1 : 0);
1203 //% _values[idx] = value;
1204 //% _valueSet[idx] = YES;
1205 //% if (_autocreator) {
1206 //% GPBAutocreatedDictionaryModified(_autocreator, self);
1210 //%- (void)remove##VALUE_NAME##ForKey:(BOOL)aKey {
1211 //% _valueSet[aKey ? 1 : 0] = NO;
1214 //%- (void)removeAll {
1215 //% _valueSet[0] = NO;
1216 //% _valueSet[1] = NO;
1218 //%PDDM-DEFINE STR_FORMAT_POD(VALUE_NAME)
1219 //%STR_FORMAT_##VALUE_NAME()
1220 //%PDDM-DEFINE STR_FORMAT_UInt32()
1222 //%PDDM-DEFINE STR_FORMAT_Int32()
1224 //%PDDM-DEFINE STR_FORMAT_UInt64()
1226 //%PDDM-DEFINE STR_FORMAT_Int64()
1228 //%PDDM-DEFINE STR_FORMAT_Bool()
1230 //%PDDM-DEFINE STR_FORMAT_Float()
1232 //%PDDM-DEFINE STR_FORMAT_Double()
1236 // Helpers for Objects
1239 //%PDDM-DEFINE VALUE_FOR_KEY_OBJECT(KEY_TYPE, VALUE_NAME, VALUE_TYPE, KHELPER)
1240 //%- (VALUE_TYPE)objectForKey:(KEY_TYPE)key {
1241 //% VALUE_TYPE result = [_dictionary objectForKey:WRAPPED##KHELPER(key)];
1244 //%PDDM-DEFINE WRAPPEDOBJECT(VALUE)
1246 //%PDDM-DEFINE UNWRAPString(VALUE)
1248 //%PDDM-DEFINE UNWRAPObject(VALUE)
1250 //%PDDM-DEFINE TEXT_FORMAT_OBJString(VALUE)
1252 //%PDDM-DEFINE TEXT_FORMAT_OBJObject(VALUE)
1254 //%PDDM-DEFINE ENUM_TYPEOBJECT(TYPE)
1255 //%ENUM_TYPEOBJECT_##TYPE()
1256 //%PDDM-DEFINE ENUM_TYPEOBJECT_NSString()
1258 //%PDDM-DEFINE ENUM_TYPEOBJECT_id()
1260 //%PDDM-DEFINE NEQ_OBJECT(VAL1, VAL2)
1261 //%![VAL1 isEqual:VAL2]
1262 //%PDDM-DEFINE EXTRA_METHODS_OBJECT(KEY_NAME, VALUE_NAME)
1263 //%- (BOOL)isInitialized {
1264 //% for (GPBMessage *msg in [_dictionary objectEnumerator]) {
1265 //% if (!msg.initialized) {
1272 //%- (instancetype)deepCopyWithZone:(NSZone *)zone {
1273 //% GPB##KEY_NAME##VALUE_NAME##Dictionary *newDict =
1274 //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] init];
1275 //% NSEnumerator *keys = [_dictionary keyEnumerator];
1277 //% NSMutableDictionary *internalDict = newDict->_dictionary;
1278 //% while ((aKey = [keys nextObject])) {
1279 //% GPBMessage *msg = _dictionary[aKey];
1280 //% GPBMessage *copiedMsg = [msg copyWithZone:zone];
1281 //% [internalDict setObject:copiedMsg forKey:aKey];
1282 //% [copiedMsg release];
1288 //%PDDM-DEFINE BOOL_EXTRA_METHODS_OBJECT(KEY_NAME, VALUE_NAME)
1289 //%- (BOOL)isInitialized {
1290 //% if (_values[0] && ![_values[0] isInitialized]) {
1293 //% if (_values[1] && ![_values[1] isInitialized]) {
1299 //%- (instancetype)deepCopyWithZone:(NSZone *)zone {
1300 //% GPB##KEY_NAME##VALUE_NAME##Dictionary *newDict =
1301 //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] init];
1302 //% for (int i = 0; i < 2; ++i) {
1303 //% if (_values[i] != nil) {
1304 //% newDict->_values[i] = [_values[i] copyWithZone:zone];
1311 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_OBJECT(KEY_NAME, VALUE_NAME)
1313 //%PDDM-DEFINE GPBVALUE_OBJECT(VALUE_NAME)
1315 //%PDDM-DEFINE DICTIONARY_VALIDATE_VALUE_OBJECT(VALUE_NAME, EXTRA_INDENT)
1316 //%##EXTRA_INDENT$S## if (!##VALUE_NAME) {
1317 //%##EXTRA_INDENT$S## [NSException raise:NSInvalidArgumentException
1318 //%##EXTRA_INDENT$S## format:@"Attempting to add nil object to a Dictionary"];
1319 //%##EXTRA_INDENT$S## }
1321 //%PDDM-DEFINE DICTIONARY_VALIDATE_KEY_OBJECT(KEY_NAME, EXTRA_INDENT)
1322 //%##EXTRA_INDENT$S## if (!##KEY_NAME) {
1323 //%##EXTRA_INDENT$S## [NSException raise:NSInvalidArgumentException
1324 //%##EXTRA_INDENT$S## format:@"Attempting to add nil key to a Dictionary"];
1325 //%##EXTRA_INDENT$S## }
1328 //%PDDM-DEFINE BOOL_DICT_HAS_STORAGE_OBJECT()
1330 //%PDDM-DEFINE BOOL_DICT_INITS_OBJECT(VALUE_NAME, VALUE_TYPE)
1331 //%- (instancetype)initWithObjects:(const VALUE_TYPE [])objects
1332 //% forKeys:(const BOOL [])keys
1333 //% count:(NSUInteger)count {
1334 //% self = [super init];
1336 //% for (NSUInteger i = 0; i < count; ++i) {
1337 //% if (!objects[i]) {
1338 //% [NSException raise:NSInvalidArgumentException
1339 //% format:@"Attempting to add nil object to a Dictionary"];
1341 //% int idx = keys[i] ? 1 : 0;
1342 //% [_values[idx] release];
1343 //% _values[idx] = (VALUE_TYPE)[objects[i] retain];
1349 //%- (instancetype)initWithDictionary:(GPBBool##VALUE_NAME##Dictionary *)dictionary {
1350 //% self = [self initWithObjects:NULL forKeys:NULL count:0];
1352 //% if (dictionary) {
1353 //% _values[0] = [dictionary->_values[0] retain];
1354 //% _values[1] = [dictionary->_values[1] retain];
1359 //%PDDM-DEFINE BOOL_DICT_DEALLOCOBJECT()
1360 //%- (void)dealloc {
1361 //% NSAssert(!_autocreator,
1362 //% @"%@: Autocreator must be cleared before release, autocreator: %@",
1363 //% [self class], _autocreator);
1364 //% [_values[0] release];
1365 //% [_values[1] release];
1366 //% [super dealloc];
1368 //%PDDM-DEFINE BOOL_DICT_W_HASOBJECT(IDX, REF)
1369 //%(BOOL_DICT_HASOBJECT(IDX, REF))
1370 //%PDDM-DEFINE BOOL_DICT_HASOBJECT(IDX, REF)
1371 //%REF##_values[IDX] != nil
1372 //%PDDM-DEFINE BOOL_VALUE_FOR_KEY_OBJECT(VALUE_NAME, VALUE_TYPE)
1373 //%- (VALUE_TYPE)objectForKey:(BOOL)key {
1374 //% return _values[key ? 1 : 0];
1376 //%PDDM-DEFINE BOOL_SET_GPBVALUE_FOR_KEY_OBJECT(VALUE_NAME, VALUE_TYPE, VisP)
1377 //%- (void)setGPBGenericValue:(GPBGenericValue *)value
1378 //% forGPBGenericValueKey:(GPBGenericValue *)key {
1379 //% int idx = (key->valueBool ? 1 : 0);
1380 //% [_values[idx] release];
1381 //% _values[idx] = [value->valueString retain];
1384 //%PDDM-DEFINE BOOL_DICT_MUTATIONS_OBJECT(VALUE_NAME, VALUE_TYPE)
1385 //%- (void)addEntriesFromDictionary:(GPBBool##VALUE_NAME##Dictionary *)otherDictionary {
1386 //% if (otherDictionary) {
1387 //% for (int i = 0; i < 2; ++i) {
1388 //% if (otherDictionary->_values[i] != nil) {
1389 //% [_values[i] release];
1390 //% _values[i] = [otherDictionary->_values[i] retain];
1393 //% if (_autocreator) {
1394 //% GPBAutocreatedDictionaryModified(_autocreator, self);
1399 //%- (void)setObject:(VALUE_TYPE)object forKey:(BOOL)key {
1401 //% [NSException raise:NSInvalidArgumentException
1402 //% format:@"Attempting to add nil object to a Dictionary"];
1404 //% int idx = (key ? 1 : 0);
1405 //% [_values[idx] release];
1406 //% _values[idx] = [object retain];
1407 //% if (_autocreator) {
1408 //% GPBAutocreatedDictionaryModified(_autocreator, self);
1412 //%- (void)removeObjectForKey:(BOOL)aKey {
1413 //% int idx = (aKey ? 1 : 0);
1414 //% [_values[idx] release];
1415 //% _values[idx] = nil;
1418 //%- (void)removeAll {
1419 //% for (int i = 0; i < 2; ++i) {
1420 //% [_values[i] release];
1421 //% _values[i] = nil;
1424 //%PDDM-DEFINE STR_FORMAT_OBJECT(VALUE_NAME)
1428 //%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(UInt32, uint32_t)
1429 // This block of code is generated, do not edit it directly.
1431 #pragma mark - UInt32 -> UInt32
1433 @implementation GPBUInt32UInt32Dictionary {
1435 NSMutableDictionary *_dictionary;
1438 - (instancetype)init {
1439 return [self initWithUInt32s:NULL forKeys:NULL count:0];
1442 - (instancetype)initWithUInt32s:(const uint32_t [])values
1443 forKeys:(const uint32_t [])keys
1444 count:(NSUInteger)count {
1445 self = [super init];
1447 _dictionary = [[NSMutableDictionary alloc] init];
1448 if (count && values && keys) {
1449 for (NSUInteger i = 0; i < count; ++i) {
1450 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
1457 - (instancetype)initWithDictionary:(GPBUInt32UInt32Dictionary *)dictionary {
1458 self = [self initWithUInt32s:NULL forKeys:NULL count:0];
1461 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
1467 - (instancetype)initWithCapacity:(NSUInteger)numItems {
1468 #pragma unused(numItems)
1469 return [self initWithUInt32s:NULL forKeys:NULL count:0];
1473 NSAssert(!_autocreator,
1474 @"%@: Autocreator must be cleared before release, autocreator: %@",
1475 [self class], _autocreator);
1476 [_dictionary release];
1480 - (instancetype)copyWithZone:(NSZone *)zone {
1481 return [[GPBUInt32UInt32Dictionary allocWithZone:zone] initWithDictionary:self];
1484 - (BOOL)isEqual:(id)other {
1485 if (self == other) {
1488 if (![other isKindOfClass:[GPBUInt32UInt32Dictionary class]]) {
1491 GPBUInt32UInt32Dictionary *otherDictionary = other;
1492 return [_dictionary isEqual:otherDictionary->_dictionary];
1495 - (NSUInteger)hash {
1496 return _dictionary.count;
1499 - (NSString *)description {
1500 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
1503 - (NSUInteger)count {
1504 return _dictionary.count;
1507 - (void)enumerateKeysAndUInt32sUsingBlock:
1508 (void (^)(uint32_t key, uint32_t value, BOOL *stop))block {
1510 NSDictionary *internal = _dictionary;
1511 NSEnumerator *keys = [internal keyEnumerator];
1513 while ((aKey = [keys nextObject])) {
1514 NSNumber *aValue = internal[aKey];
1515 block([aKey unsignedIntValue], [aValue unsignedIntValue], &stop);
1522 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
1523 NSDictionary *internal = _dictionary;
1524 NSUInteger count = internal.count;
1529 GPBDataType valueDataType = GPBGetFieldDataType(field);
1530 GPBDataType keyDataType = field.mapKeyDataType;
1532 NSEnumerator *keys = [internal keyEnumerator];
1534 while ((aKey = [keys nextObject])) {
1535 NSNumber *aValue = internal[aKey];
1536 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
1537 msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
1538 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
1540 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
1541 result += tagSize * count;
1545 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
1546 asField:(GPBFieldDescriptor *)field {
1547 GPBDataType valueDataType = GPBGetFieldDataType(field);
1548 GPBDataType keyDataType = field.mapKeyDataType;
1549 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
1550 NSDictionary *internal = _dictionary;
1551 NSEnumerator *keys = [internal keyEnumerator];
1553 while ((aKey = [keys nextObject])) {
1554 NSNumber *aValue = internal[aKey];
1555 [outputStream writeInt32NoTag:tag];
1556 // Write the size of the message.
1557 uint32_t unwrappedKey = [aKey unsignedIntValue];
1558 uint32_t unwrappedValue = [aValue unsignedIntValue];
1559 size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
1560 msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
1561 [outputStream writeInt32NoTag:(int32_t)msgSize];
1562 // Write the fields.
1563 WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
1564 WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
1568 - (void)setGPBGenericValue:(GPBGenericValue *)value
1569 forGPBGenericValueKey:(GPBGenericValue *)key {
1570 [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueUInt32)];
1573 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
1574 [self enumerateKeysAndUInt32sUsingBlock:^(uint32_t key, uint32_t value, BOOL *stop) {
1575 #pragma unused(stop)
1576 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%u", value]);
1580 - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(uint32_t)key {
1581 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
1582 if (wrapped && value) {
1583 *value = [wrapped unsignedIntValue];
1585 return (wrapped != NULL);
1588 - (void)addEntriesFromDictionary:(GPBUInt32UInt32Dictionary *)otherDictionary {
1589 if (otherDictionary) {
1590 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
1592 GPBAutocreatedDictionaryModified(_autocreator, self);
1597 - (void)setUInt32:(uint32_t)value forKey:(uint32_t)key {
1598 [_dictionary setObject:@(value) forKey:@(key)];
1600 GPBAutocreatedDictionaryModified(_autocreator, self);
1604 - (void)removeUInt32ForKey:(uint32_t)aKey {
1605 [_dictionary removeObjectForKey:@(aKey)];
1609 [_dictionary removeAllObjects];
1614 #pragma mark - UInt32 -> Int32
1616 @implementation GPBUInt32Int32Dictionary {
1618 NSMutableDictionary *_dictionary;
1621 - (instancetype)init {
1622 return [self initWithInt32s:NULL forKeys:NULL count:0];
1625 - (instancetype)initWithInt32s:(const int32_t [])values
1626 forKeys:(const uint32_t [])keys
1627 count:(NSUInteger)count {
1628 self = [super init];
1630 _dictionary = [[NSMutableDictionary alloc] init];
1631 if (count && values && keys) {
1632 for (NSUInteger i = 0; i < count; ++i) {
1633 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
1640 - (instancetype)initWithDictionary:(GPBUInt32Int32Dictionary *)dictionary {
1641 self = [self initWithInt32s:NULL forKeys:NULL count:0];
1644 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
1650 - (instancetype)initWithCapacity:(NSUInteger)numItems {
1651 #pragma unused(numItems)
1652 return [self initWithInt32s:NULL forKeys:NULL count:0];
1656 NSAssert(!_autocreator,
1657 @"%@: Autocreator must be cleared before release, autocreator: %@",
1658 [self class], _autocreator);
1659 [_dictionary release];
1663 - (instancetype)copyWithZone:(NSZone *)zone {
1664 return [[GPBUInt32Int32Dictionary allocWithZone:zone] initWithDictionary:self];
1667 - (BOOL)isEqual:(id)other {
1668 if (self == other) {
1671 if (![other isKindOfClass:[GPBUInt32Int32Dictionary class]]) {
1674 GPBUInt32Int32Dictionary *otherDictionary = other;
1675 return [_dictionary isEqual:otherDictionary->_dictionary];
1678 - (NSUInteger)hash {
1679 return _dictionary.count;
1682 - (NSString *)description {
1683 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
1686 - (NSUInteger)count {
1687 return _dictionary.count;
1690 - (void)enumerateKeysAndInt32sUsingBlock:
1691 (void (^)(uint32_t key, int32_t value, BOOL *stop))block {
1693 NSDictionary *internal = _dictionary;
1694 NSEnumerator *keys = [internal keyEnumerator];
1696 while ((aKey = [keys nextObject])) {
1697 NSNumber *aValue = internal[aKey];
1698 block([aKey unsignedIntValue], [aValue intValue], &stop);
1705 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
1706 NSDictionary *internal = _dictionary;
1707 NSUInteger count = internal.count;
1712 GPBDataType valueDataType = GPBGetFieldDataType(field);
1713 GPBDataType keyDataType = field.mapKeyDataType;
1715 NSEnumerator *keys = [internal keyEnumerator];
1717 while ((aKey = [keys nextObject])) {
1718 NSNumber *aValue = internal[aKey];
1719 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
1720 msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
1721 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
1723 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
1724 result += tagSize * count;
1728 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
1729 asField:(GPBFieldDescriptor *)field {
1730 GPBDataType valueDataType = GPBGetFieldDataType(field);
1731 GPBDataType keyDataType = field.mapKeyDataType;
1732 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
1733 NSDictionary *internal = _dictionary;
1734 NSEnumerator *keys = [internal keyEnumerator];
1736 while ((aKey = [keys nextObject])) {
1737 NSNumber *aValue = internal[aKey];
1738 [outputStream writeInt32NoTag:tag];
1739 // Write the size of the message.
1740 uint32_t unwrappedKey = [aKey unsignedIntValue];
1741 int32_t unwrappedValue = [aValue intValue];
1742 size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
1743 msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
1744 [outputStream writeInt32NoTag:(int32_t)msgSize];
1745 // Write the fields.
1746 WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
1747 WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
1751 - (void)setGPBGenericValue:(GPBGenericValue *)value
1752 forGPBGenericValueKey:(GPBGenericValue *)key {
1753 [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueUInt32)];
1756 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
1757 [self enumerateKeysAndInt32sUsingBlock:^(uint32_t key, int32_t value, BOOL *stop) {
1758 #pragma unused(stop)
1759 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%d", value]);
1763 - (BOOL)getInt32:(nullable int32_t *)value forKey:(uint32_t)key {
1764 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
1765 if (wrapped && value) {
1766 *value = [wrapped intValue];
1768 return (wrapped != NULL);
1771 - (void)addEntriesFromDictionary:(GPBUInt32Int32Dictionary *)otherDictionary {
1772 if (otherDictionary) {
1773 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
1775 GPBAutocreatedDictionaryModified(_autocreator, self);
1780 - (void)setInt32:(int32_t)value forKey:(uint32_t)key {
1781 [_dictionary setObject:@(value) forKey:@(key)];
1783 GPBAutocreatedDictionaryModified(_autocreator, self);
1787 - (void)removeInt32ForKey:(uint32_t)aKey {
1788 [_dictionary removeObjectForKey:@(aKey)];
1792 [_dictionary removeAllObjects];
1797 #pragma mark - UInt32 -> UInt64
1799 @implementation GPBUInt32UInt64Dictionary {
1801 NSMutableDictionary *_dictionary;
1804 - (instancetype)init {
1805 return [self initWithUInt64s:NULL forKeys:NULL count:0];
1808 - (instancetype)initWithUInt64s:(const uint64_t [])values
1809 forKeys:(const uint32_t [])keys
1810 count:(NSUInteger)count {
1811 self = [super init];
1813 _dictionary = [[NSMutableDictionary alloc] init];
1814 if (count && values && keys) {
1815 for (NSUInteger i = 0; i < count; ++i) {
1816 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
1823 - (instancetype)initWithDictionary:(GPBUInt32UInt64Dictionary *)dictionary {
1824 self = [self initWithUInt64s:NULL forKeys:NULL count:0];
1827 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
1833 - (instancetype)initWithCapacity:(NSUInteger)numItems {
1834 #pragma unused(numItems)
1835 return [self initWithUInt64s:NULL forKeys:NULL count:0];
1839 NSAssert(!_autocreator,
1840 @"%@: Autocreator must be cleared before release, autocreator: %@",
1841 [self class], _autocreator);
1842 [_dictionary release];
1846 - (instancetype)copyWithZone:(NSZone *)zone {
1847 return [[GPBUInt32UInt64Dictionary allocWithZone:zone] initWithDictionary:self];
1850 - (BOOL)isEqual:(id)other {
1851 if (self == other) {
1854 if (![other isKindOfClass:[GPBUInt32UInt64Dictionary class]]) {
1857 GPBUInt32UInt64Dictionary *otherDictionary = other;
1858 return [_dictionary isEqual:otherDictionary->_dictionary];
1861 - (NSUInteger)hash {
1862 return _dictionary.count;
1865 - (NSString *)description {
1866 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
1869 - (NSUInteger)count {
1870 return _dictionary.count;
1873 - (void)enumerateKeysAndUInt64sUsingBlock:
1874 (void (^)(uint32_t key, uint64_t value, BOOL *stop))block {
1876 NSDictionary *internal = _dictionary;
1877 NSEnumerator *keys = [internal keyEnumerator];
1879 while ((aKey = [keys nextObject])) {
1880 NSNumber *aValue = internal[aKey];
1881 block([aKey unsignedIntValue], [aValue unsignedLongLongValue], &stop);
1888 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
1889 NSDictionary *internal = _dictionary;
1890 NSUInteger count = internal.count;
1895 GPBDataType valueDataType = GPBGetFieldDataType(field);
1896 GPBDataType keyDataType = field.mapKeyDataType;
1898 NSEnumerator *keys = [internal keyEnumerator];
1900 while ((aKey = [keys nextObject])) {
1901 NSNumber *aValue = internal[aKey];
1902 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
1903 msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
1904 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
1906 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
1907 result += tagSize * count;
1911 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
1912 asField:(GPBFieldDescriptor *)field {
1913 GPBDataType valueDataType = GPBGetFieldDataType(field);
1914 GPBDataType keyDataType = field.mapKeyDataType;
1915 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
1916 NSDictionary *internal = _dictionary;
1917 NSEnumerator *keys = [internal keyEnumerator];
1919 while ((aKey = [keys nextObject])) {
1920 NSNumber *aValue = internal[aKey];
1921 [outputStream writeInt32NoTag:tag];
1922 // Write the size of the message.
1923 uint32_t unwrappedKey = [aKey unsignedIntValue];
1924 uint64_t unwrappedValue = [aValue unsignedLongLongValue];
1925 size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
1926 msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
1927 [outputStream writeInt32NoTag:(int32_t)msgSize];
1928 // Write the fields.
1929 WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
1930 WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
1934 - (void)setGPBGenericValue:(GPBGenericValue *)value
1935 forGPBGenericValueKey:(GPBGenericValue *)key {
1936 [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueUInt32)];
1939 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
1940 [self enumerateKeysAndUInt64sUsingBlock:^(uint32_t key, uint64_t value, BOOL *stop) {
1941 #pragma unused(stop)
1942 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%llu", value]);
1946 - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(uint32_t)key {
1947 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
1948 if (wrapped && value) {
1949 *value = [wrapped unsignedLongLongValue];
1951 return (wrapped != NULL);
1954 - (void)addEntriesFromDictionary:(GPBUInt32UInt64Dictionary *)otherDictionary {
1955 if (otherDictionary) {
1956 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
1958 GPBAutocreatedDictionaryModified(_autocreator, self);
1963 - (void)setUInt64:(uint64_t)value forKey:(uint32_t)key {
1964 [_dictionary setObject:@(value) forKey:@(key)];
1966 GPBAutocreatedDictionaryModified(_autocreator, self);
1970 - (void)removeUInt64ForKey:(uint32_t)aKey {
1971 [_dictionary removeObjectForKey:@(aKey)];
1975 [_dictionary removeAllObjects];
1980 #pragma mark - UInt32 -> Int64
1982 @implementation GPBUInt32Int64Dictionary {
1984 NSMutableDictionary *_dictionary;
1987 - (instancetype)init {
1988 return [self initWithInt64s:NULL forKeys:NULL count:0];
1991 - (instancetype)initWithInt64s:(const int64_t [])values
1992 forKeys:(const uint32_t [])keys
1993 count:(NSUInteger)count {
1994 self = [super init];
1996 _dictionary = [[NSMutableDictionary alloc] init];
1997 if (count && values && keys) {
1998 for (NSUInteger i = 0; i < count; ++i) {
1999 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
2006 - (instancetype)initWithDictionary:(GPBUInt32Int64Dictionary *)dictionary {
2007 self = [self initWithInt64s:NULL forKeys:NULL count:0];
2010 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
2016 - (instancetype)initWithCapacity:(NSUInteger)numItems {
2017 #pragma unused(numItems)
2018 return [self initWithInt64s:NULL forKeys:NULL count:0];
2022 NSAssert(!_autocreator,
2023 @"%@: Autocreator must be cleared before release, autocreator: %@",
2024 [self class], _autocreator);
2025 [_dictionary release];
2029 - (instancetype)copyWithZone:(NSZone *)zone {
2030 return [[GPBUInt32Int64Dictionary allocWithZone:zone] initWithDictionary:self];
2033 - (BOOL)isEqual:(id)other {
2034 if (self == other) {
2037 if (![other isKindOfClass:[GPBUInt32Int64Dictionary class]]) {
2040 GPBUInt32Int64Dictionary *otherDictionary = other;
2041 return [_dictionary isEqual:otherDictionary->_dictionary];
2044 - (NSUInteger)hash {
2045 return _dictionary.count;
2048 - (NSString *)description {
2049 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
2052 - (NSUInteger)count {
2053 return _dictionary.count;
2056 - (void)enumerateKeysAndInt64sUsingBlock:
2057 (void (^)(uint32_t key, int64_t value, BOOL *stop))block {
2059 NSDictionary *internal = _dictionary;
2060 NSEnumerator *keys = [internal keyEnumerator];
2062 while ((aKey = [keys nextObject])) {
2063 NSNumber *aValue = internal[aKey];
2064 block([aKey unsignedIntValue], [aValue longLongValue], &stop);
2071 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
2072 NSDictionary *internal = _dictionary;
2073 NSUInteger count = internal.count;
2078 GPBDataType valueDataType = GPBGetFieldDataType(field);
2079 GPBDataType keyDataType = field.mapKeyDataType;
2081 NSEnumerator *keys = [internal keyEnumerator];
2083 while ((aKey = [keys nextObject])) {
2084 NSNumber *aValue = internal[aKey];
2085 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
2086 msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
2087 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
2089 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
2090 result += tagSize * count;
2094 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
2095 asField:(GPBFieldDescriptor *)field {
2096 GPBDataType valueDataType = GPBGetFieldDataType(field);
2097 GPBDataType keyDataType = field.mapKeyDataType;
2098 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
2099 NSDictionary *internal = _dictionary;
2100 NSEnumerator *keys = [internal keyEnumerator];
2102 while ((aKey = [keys nextObject])) {
2103 NSNumber *aValue = internal[aKey];
2104 [outputStream writeInt32NoTag:tag];
2105 // Write the size of the message.
2106 uint32_t unwrappedKey = [aKey unsignedIntValue];
2107 int64_t unwrappedValue = [aValue longLongValue];
2108 size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
2109 msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
2110 [outputStream writeInt32NoTag:(int32_t)msgSize];
2111 // Write the fields.
2112 WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
2113 WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
2117 - (void)setGPBGenericValue:(GPBGenericValue *)value
2118 forGPBGenericValueKey:(GPBGenericValue *)key {
2119 [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueUInt32)];
2122 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
2123 [self enumerateKeysAndInt64sUsingBlock:^(uint32_t key, int64_t value, BOOL *stop) {
2124 #pragma unused(stop)
2125 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%lld", value]);
2129 - (BOOL)getInt64:(nullable int64_t *)value forKey:(uint32_t)key {
2130 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
2131 if (wrapped && value) {
2132 *value = [wrapped longLongValue];
2134 return (wrapped != NULL);
2137 - (void)addEntriesFromDictionary:(GPBUInt32Int64Dictionary *)otherDictionary {
2138 if (otherDictionary) {
2139 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
2141 GPBAutocreatedDictionaryModified(_autocreator, self);
2146 - (void)setInt64:(int64_t)value forKey:(uint32_t)key {
2147 [_dictionary setObject:@(value) forKey:@(key)];
2149 GPBAutocreatedDictionaryModified(_autocreator, self);
2153 - (void)removeInt64ForKey:(uint32_t)aKey {
2154 [_dictionary removeObjectForKey:@(aKey)];
2158 [_dictionary removeAllObjects];
2163 #pragma mark - UInt32 -> Bool
2165 @implementation GPBUInt32BoolDictionary {
2167 NSMutableDictionary *_dictionary;
2170 - (instancetype)init {
2171 return [self initWithBools:NULL forKeys:NULL count:0];
2174 - (instancetype)initWithBools:(const BOOL [])values
2175 forKeys:(const uint32_t [])keys
2176 count:(NSUInteger)count {
2177 self = [super init];
2179 _dictionary = [[NSMutableDictionary alloc] init];
2180 if (count && values && keys) {
2181 for (NSUInteger i = 0; i < count; ++i) {
2182 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
2189 - (instancetype)initWithDictionary:(GPBUInt32BoolDictionary *)dictionary {
2190 self = [self initWithBools:NULL forKeys:NULL count:0];
2193 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
2199 - (instancetype)initWithCapacity:(NSUInteger)numItems {
2200 #pragma unused(numItems)
2201 return [self initWithBools:NULL forKeys:NULL count:0];
2205 NSAssert(!_autocreator,
2206 @"%@: Autocreator must be cleared before release, autocreator: %@",
2207 [self class], _autocreator);
2208 [_dictionary release];
2212 - (instancetype)copyWithZone:(NSZone *)zone {
2213 return [[GPBUInt32BoolDictionary allocWithZone:zone] initWithDictionary:self];
2216 - (BOOL)isEqual:(id)other {
2217 if (self == other) {
2220 if (![other isKindOfClass:[GPBUInt32BoolDictionary class]]) {
2223 GPBUInt32BoolDictionary *otherDictionary = other;
2224 return [_dictionary isEqual:otherDictionary->_dictionary];
2227 - (NSUInteger)hash {
2228 return _dictionary.count;
2231 - (NSString *)description {
2232 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
2235 - (NSUInteger)count {
2236 return _dictionary.count;
2239 - (void)enumerateKeysAndBoolsUsingBlock:
2240 (void (^)(uint32_t key, BOOL value, BOOL *stop))block {
2242 NSDictionary *internal = _dictionary;
2243 NSEnumerator *keys = [internal keyEnumerator];
2245 while ((aKey = [keys nextObject])) {
2246 NSNumber *aValue = internal[aKey];
2247 block([aKey unsignedIntValue], [aValue boolValue], &stop);
2254 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
2255 NSDictionary *internal = _dictionary;
2256 NSUInteger count = internal.count;
2261 GPBDataType valueDataType = GPBGetFieldDataType(field);
2262 GPBDataType keyDataType = field.mapKeyDataType;
2264 NSEnumerator *keys = [internal keyEnumerator];
2266 while ((aKey = [keys nextObject])) {
2267 NSNumber *aValue = internal[aKey];
2268 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
2269 msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
2270 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
2272 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
2273 result += tagSize * count;
2277 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
2278 asField:(GPBFieldDescriptor *)field {
2279 GPBDataType valueDataType = GPBGetFieldDataType(field);
2280 GPBDataType keyDataType = field.mapKeyDataType;
2281 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
2282 NSDictionary *internal = _dictionary;
2283 NSEnumerator *keys = [internal keyEnumerator];
2285 while ((aKey = [keys nextObject])) {
2286 NSNumber *aValue = internal[aKey];
2287 [outputStream writeInt32NoTag:tag];
2288 // Write the size of the message.
2289 uint32_t unwrappedKey = [aKey unsignedIntValue];
2290 BOOL unwrappedValue = [aValue boolValue];
2291 size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
2292 msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
2293 [outputStream writeInt32NoTag:(int32_t)msgSize];
2294 // Write the fields.
2295 WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
2296 WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
2300 - (void)setGPBGenericValue:(GPBGenericValue *)value
2301 forGPBGenericValueKey:(GPBGenericValue *)key {
2302 [_dictionary setObject:@(value->valueBool) forKey:@(key->valueUInt32)];
2305 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
2306 [self enumerateKeysAndBoolsUsingBlock:^(uint32_t key, BOOL value, BOOL *stop) {
2307 #pragma unused(stop)
2308 block([NSString stringWithFormat:@"%u", key], (value ? @"true" : @"false"));
2312 - (BOOL)getBool:(nullable BOOL *)value forKey:(uint32_t)key {
2313 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
2314 if (wrapped && value) {
2315 *value = [wrapped boolValue];
2317 return (wrapped != NULL);
2320 - (void)addEntriesFromDictionary:(GPBUInt32BoolDictionary *)otherDictionary {
2321 if (otherDictionary) {
2322 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
2324 GPBAutocreatedDictionaryModified(_autocreator, self);
2329 - (void)setBool:(BOOL)value forKey:(uint32_t)key {
2330 [_dictionary setObject:@(value) forKey:@(key)];
2332 GPBAutocreatedDictionaryModified(_autocreator, self);
2336 - (void)removeBoolForKey:(uint32_t)aKey {
2337 [_dictionary removeObjectForKey:@(aKey)];
2341 [_dictionary removeAllObjects];
2346 #pragma mark - UInt32 -> Float
2348 @implementation GPBUInt32FloatDictionary {
2350 NSMutableDictionary *_dictionary;
2353 - (instancetype)init {
2354 return [self initWithFloats:NULL forKeys:NULL count:0];
2357 - (instancetype)initWithFloats:(const float [])values
2358 forKeys:(const uint32_t [])keys
2359 count:(NSUInteger)count {
2360 self = [super init];
2362 _dictionary = [[NSMutableDictionary alloc] init];
2363 if (count && values && keys) {
2364 for (NSUInteger i = 0; i < count; ++i) {
2365 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
2372 - (instancetype)initWithDictionary:(GPBUInt32FloatDictionary *)dictionary {
2373 self = [self initWithFloats:NULL forKeys:NULL count:0];
2376 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
2382 - (instancetype)initWithCapacity:(NSUInteger)numItems {
2383 #pragma unused(numItems)
2384 return [self initWithFloats:NULL forKeys:NULL count:0];
2388 NSAssert(!_autocreator,
2389 @"%@: Autocreator must be cleared before release, autocreator: %@",
2390 [self class], _autocreator);
2391 [_dictionary release];
2395 - (instancetype)copyWithZone:(NSZone *)zone {
2396 return [[GPBUInt32FloatDictionary allocWithZone:zone] initWithDictionary:self];
2399 - (BOOL)isEqual:(id)other {
2400 if (self == other) {
2403 if (![other isKindOfClass:[GPBUInt32FloatDictionary class]]) {
2406 GPBUInt32FloatDictionary *otherDictionary = other;
2407 return [_dictionary isEqual:otherDictionary->_dictionary];
2410 - (NSUInteger)hash {
2411 return _dictionary.count;
2414 - (NSString *)description {
2415 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
2418 - (NSUInteger)count {
2419 return _dictionary.count;
2422 - (void)enumerateKeysAndFloatsUsingBlock:
2423 (void (^)(uint32_t key, float value, BOOL *stop))block {
2425 NSDictionary *internal = _dictionary;
2426 NSEnumerator *keys = [internal keyEnumerator];
2428 while ((aKey = [keys nextObject])) {
2429 NSNumber *aValue = internal[aKey];
2430 block([aKey unsignedIntValue], [aValue floatValue], &stop);
2437 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
2438 NSDictionary *internal = _dictionary;
2439 NSUInteger count = internal.count;
2444 GPBDataType valueDataType = GPBGetFieldDataType(field);
2445 GPBDataType keyDataType = field.mapKeyDataType;
2447 NSEnumerator *keys = [internal keyEnumerator];
2449 while ((aKey = [keys nextObject])) {
2450 NSNumber *aValue = internal[aKey];
2451 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
2452 msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
2453 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
2455 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
2456 result += tagSize * count;
2460 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
2461 asField:(GPBFieldDescriptor *)field {
2462 GPBDataType valueDataType = GPBGetFieldDataType(field);
2463 GPBDataType keyDataType = field.mapKeyDataType;
2464 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
2465 NSDictionary *internal = _dictionary;
2466 NSEnumerator *keys = [internal keyEnumerator];
2468 while ((aKey = [keys nextObject])) {
2469 NSNumber *aValue = internal[aKey];
2470 [outputStream writeInt32NoTag:tag];
2471 // Write the size of the message.
2472 uint32_t unwrappedKey = [aKey unsignedIntValue];
2473 float unwrappedValue = [aValue floatValue];
2474 size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
2475 msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
2476 [outputStream writeInt32NoTag:(int32_t)msgSize];
2477 // Write the fields.
2478 WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
2479 WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
2483 - (void)setGPBGenericValue:(GPBGenericValue *)value
2484 forGPBGenericValueKey:(GPBGenericValue *)key {
2485 [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueUInt32)];
2488 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
2489 [self enumerateKeysAndFloatsUsingBlock:^(uint32_t key, float value, BOOL *stop) {
2490 #pragma unused(stop)
2491 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
2495 - (BOOL)getFloat:(nullable float *)value forKey:(uint32_t)key {
2496 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
2497 if (wrapped && value) {
2498 *value = [wrapped floatValue];
2500 return (wrapped != NULL);
2503 - (void)addEntriesFromDictionary:(GPBUInt32FloatDictionary *)otherDictionary {
2504 if (otherDictionary) {
2505 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
2507 GPBAutocreatedDictionaryModified(_autocreator, self);
2512 - (void)setFloat:(float)value forKey:(uint32_t)key {
2513 [_dictionary setObject:@(value) forKey:@(key)];
2515 GPBAutocreatedDictionaryModified(_autocreator, self);
2519 - (void)removeFloatForKey:(uint32_t)aKey {
2520 [_dictionary removeObjectForKey:@(aKey)];
2524 [_dictionary removeAllObjects];
2529 #pragma mark - UInt32 -> Double
2531 @implementation GPBUInt32DoubleDictionary {
2533 NSMutableDictionary *_dictionary;
2536 - (instancetype)init {
2537 return [self initWithDoubles:NULL forKeys:NULL count:0];
2540 - (instancetype)initWithDoubles:(const double [])values
2541 forKeys:(const uint32_t [])keys
2542 count:(NSUInteger)count {
2543 self = [super init];
2545 _dictionary = [[NSMutableDictionary alloc] init];
2546 if (count && values && keys) {
2547 for (NSUInteger i = 0; i < count; ++i) {
2548 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
2555 - (instancetype)initWithDictionary:(GPBUInt32DoubleDictionary *)dictionary {
2556 self = [self initWithDoubles:NULL forKeys:NULL count:0];
2559 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
2565 - (instancetype)initWithCapacity:(NSUInteger)numItems {
2566 #pragma unused(numItems)
2567 return [self initWithDoubles:NULL forKeys:NULL count:0];
2571 NSAssert(!_autocreator,
2572 @"%@: Autocreator must be cleared before release, autocreator: %@",
2573 [self class], _autocreator);
2574 [_dictionary release];
2578 - (instancetype)copyWithZone:(NSZone *)zone {
2579 return [[GPBUInt32DoubleDictionary allocWithZone:zone] initWithDictionary:self];
2582 - (BOOL)isEqual:(id)other {
2583 if (self == other) {
2586 if (![other isKindOfClass:[GPBUInt32DoubleDictionary class]]) {
2589 GPBUInt32DoubleDictionary *otherDictionary = other;
2590 return [_dictionary isEqual:otherDictionary->_dictionary];
2593 - (NSUInteger)hash {
2594 return _dictionary.count;
2597 - (NSString *)description {
2598 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
2601 - (NSUInteger)count {
2602 return _dictionary.count;
2605 - (void)enumerateKeysAndDoublesUsingBlock:
2606 (void (^)(uint32_t key, double value, BOOL *stop))block {
2608 NSDictionary *internal = _dictionary;
2609 NSEnumerator *keys = [internal keyEnumerator];
2611 while ((aKey = [keys nextObject])) {
2612 NSNumber *aValue = internal[aKey];
2613 block([aKey unsignedIntValue], [aValue doubleValue], &stop);
2620 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
2621 NSDictionary *internal = _dictionary;
2622 NSUInteger count = internal.count;
2627 GPBDataType valueDataType = GPBGetFieldDataType(field);
2628 GPBDataType keyDataType = field.mapKeyDataType;
2630 NSEnumerator *keys = [internal keyEnumerator];
2632 while ((aKey = [keys nextObject])) {
2633 NSNumber *aValue = internal[aKey];
2634 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
2635 msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
2636 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
2638 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
2639 result += tagSize * count;
2643 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
2644 asField:(GPBFieldDescriptor *)field {
2645 GPBDataType valueDataType = GPBGetFieldDataType(field);
2646 GPBDataType keyDataType = field.mapKeyDataType;
2647 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
2648 NSDictionary *internal = _dictionary;
2649 NSEnumerator *keys = [internal keyEnumerator];
2651 while ((aKey = [keys nextObject])) {
2652 NSNumber *aValue = internal[aKey];
2653 [outputStream writeInt32NoTag:tag];
2654 // Write the size of the message.
2655 uint32_t unwrappedKey = [aKey unsignedIntValue];
2656 double unwrappedValue = [aValue doubleValue];
2657 size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
2658 msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
2659 [outputStream writeInt32NoTag:(int32_t)msgSize];
2660 // Write the fields.
2661 WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
2662 WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
2666 - (void)setGPBGenericValue:(GPBGenericValue *)value
2667 forGPBGenericValueKey:(GPBGenericValue *)key {
2668 [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueUInt32)];
2671 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
2672 [self enumerateKeysAndDoublesUsingBlock:^(uint32_t key, double value, BOOL *stop) {
2673 #pragma unused(stop)
2674 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
2678 - (BOOL)getDouble:(nullable double *)value forKey:(uint32_t)key {
2679 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
2680 if (wrapped && value) {
2681 *value = [wrapped doubleValue];
2683 return (wrapped != NULL);
2686 - (void)addEntriesFromDictionary:(GPBUInt32DoubleDictionary *)otherDictionary {
2687 if (otherDictionary) {
2688 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
2690 GPBAutocreatedDictionaryModified(_autocreator, self);
2695 - (void)setDouble:(double)value forKey:(uint32_t)key {
2696 [_dictionary setObject:@(value) forKey:@(key)];
2698 GPBAutocreatedDictionaryModified(_autocreator, self);
2702 - (void)removeDoubleForKey:(uint32_t)aKey {
2703 [_dictionary removeObjectForKey:@(aKey)];
2707 [_dictionary removeAllObjects];
2712 #pragma mark - UInt32 -> Enum
2714 @implementation GPBUInt32EnumDictionary {
2716 NSMutableDictionary *_dictionary;
2717 GPBEnumValidationFunc _validationFunc;
2720 @synthesize validationFunc = _validationFunc;
2722 - (instancetype)init {
2723 return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
2726 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
2727 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
2730 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
2731 rawValues:(const int32_t [])rawValues
2732 forKeys:(const uint32_t [])keys
2733 count:(NSUInteger)count {
2734 self = [super init];
2736 _dictionary = [[NSMutableDictionary alloc] init];
2737 _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
2738 if (count && rawValues && keys) {
2739 for (NSUInteger i = 0; i < count; ++i) {
2740 [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])];
2747 - (instancetype)initWithDictionary:(GPBUInt32EnumDictionary *)dictionary {
2748 self = [self initWithValidationFunction:dictionary.validationFunc
2754 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
2760 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
2761 capacity:(NSUInteger)numItems {
2762 #pragma unused(numItems)
2763 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
2767 NSAssert(!_autocreator,
2768 @"%@: Autocreator must be cleared before release, autocreator: %@",
2769 [self class], _autocreator);
2770 [_dictionary release];
2774 - (instancetype)copyWithZone:(NSZone *)zone {
2775 return [[GPBUInt32EnumDictionary allocWithZone:zone] initWithDictionary:self];
2778 - (BOOL)isEqual:(id)other {
2779 if (self == other) {
2782 if (![other isKindOfClass:[GPBUInt32EnumDictionary class]]) {
2785 GPBUInt32EnumDictionary *otherDictionary = other;
2786 return [_dictionary isEqual:otherDictionary->_dictionary];
2789 - (NSUInteger)hash {
2790 return _dictionary.count;
2793 - (NSString *)description {
2794 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
2797 - (NSUInteger)count {
2798 return _dictionary.count;
2801 - (void)enumerateKeysAndRawValuesUsingBlock:
2802 (void (^)(uint32_t key, int32_t value, BOOL *stop))block {
2804 NSDictionary *internal = _dictionary;
2805 NSEnumerator *keys = [internal keyEnumerator];
2807 while ((aKey = [keys nextObject])) {
2808 NSNumber *aValue = internal[aKey];
2809 block([aKey unsignedIntValue], [aValue intValue], &stop);
2816 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
2817 NSDictionary *internal = _dictionary;
2818 NSUInteger count = internal.count;
2823 GPBDataType valueDataType = GPBGetFieldDataType(field);
2824 GPBDataType keyDataType = field.mapKeyDataType;
2826 NSEnumerator *keys = [internal keyEnumerator];
2828 while ((aKey = [keys nextObject])) {
2829 NSNumber *aValue = internal[aKey];
2830 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
2831 msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
2832 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
2834 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
2835 result += tagSize * count;
2839 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
2840 asField:(GPBFieldDescriptor *)field {
2841 GPBDataType valueDataType = GPBGetFieldDataType(field);
2842 GPBDataType keyDataType = field.mapKeyDataType;
2843 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
2844 NSDictionary *internal = _dictionary;
2845 NSEnumerator *keys = [internal keyEnumerator];
2847 while ((aKey = [keys nextObject])) {
2848 NSNumber *aValue = internal[aKey];
2849 [outputStream writeInt32NoTag:tag];
2850 // Write the size of the message.
2851 uint32_t unwrappedKey = [aKey unsignedIntValue];
2852 int32_t unwrappedValue = [aValue intValue];
2853 size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
2854 msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
2855 [outputStream writeInt32NoTag:(int32_t)msgSize];
2856 // Write the fields.
2857 WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
2858 WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
2862 - (NSData *)serializedDataForUnknownValue:(int32_t)value
2863 forKey:(GPBGenericValue *)key
2864 keyDataType:(GPBDataType)keyDataType {
2865 size_t msgSize = ComputeDictUInt32FieldSize(key->valueUInt32, kMapKeyFieldNumber, keyDataType);
2866 msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
2867 NSMutableData *data = [NSMutableData dataWithLength:msgSize];
2868 GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
2869 WriteDictUInt32Field(outputStream, key->valueUInt32, kMapKeyFieldNumber, keyDataType);
2870 WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
2871 [outputStream release];
2874 - (void)setGPBGenericValue:(GPBGenericValue *)value
2875 forGPBGenericValueKey:(GPBGenericValue *)key {
2876 [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueUInt32)];
2879 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
2880 [self enumerateKeysAndRawValuesUsingBlock:^(uint32_t key, int32_t value, BOOL *stop) {
2881 #pragma unused(stop)
2882 block([NSString stringWithFormat:@"%u", key], @(value));
2886 - (BOOL)getEnum:(int32_t *)value forKey:(uint32_t)key {
2887 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
2888 if (wrapped && value) {
2889 int32_t result = [wrapped intValue];
2890 if (!_validationFunc(result)) {
2891 result = kGPBUnrecognizedEnumeratorValue;
2895 return (wrapped != NULL);
2898 - (BOOL)getRawValue:(int32_t *)rawValue forKey:(uint32_t)key {
2899 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
2900 if (wrapped && rawValue) {
2901 *rawValue = [wrapped intValue];
2903 return (wrapped != NULL);
2906 - (void)enumerateKeysAndEnumsUsingBlock:
2907 (void (^)(uint32_t key, int32_t value, BOOL *stop))block {
2908 GPBEnumValidationFunc func = _validationFunc;
2910 NSEnumerator *keys = [_dictionary keyEnumerator];
2912 while ((aKey = [keys nextObject])) {
2913 NSNumber *aValue = _dictionary[aKey];
2914 int32_t unwrapped = [aValue intValue];
2915 if (!func(unwrapped)) {
2916 unwrapped = kGPBUnrecognizedEnumeratorValue;
2918 block([aKey unsignedIntValue], unwrapped, &stop);
2925 - (void)addRawEntriesFromDictionary:(GPBUInt32EnumDictionary *)otherDictionary {
2926 if (otherDictionary) {
2927 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
2929 GPBAutocreatedDictionaryModified(_autocreator, self);
2934 - (void)setRawValue:(int32_t)value forKey:(uint32_t)key {
2935 [_dictionary setObject:@(value) forKey:@(key)];
2937 GPBAutocreatedDictionaryModified(_autocreator, self);
2941 - (void)removeEnumForKey:(uint32_t)aKey {
2942 [_dictionary removeObjectForKey:@(aKey)];
2946 [_dictionary removeAllObjects];
2949 - (void)setEnum:(int32_t)value forKey:(uint32_t)key {
2950 if (!_validationFunc(value)) {
2951 [NSException raise:NSInvalidArgumentException
2952 format:@"GPBUInt32EnumDictionary: Attempt to set an unknown enum value (%d)",
2956 [_dictionary setObject:@(value) forKey:@(key)];
2958 GPBAutocreatedDictionaryModified(_autocreator, self);
2964 #pragma mark - UInt32 -> Object
2966 @implementation GPBUInt32ObjectDictionary {
2968 NSMutableDictionary *_dictionary;
2971 - (instancetype)init {
2972 return [self initWithObjects:NULL forKeys:NULL count:0];
2975 - (instancetype)initWithObjects:(const id [])objects
2976 forKeys:(const uint32_t [])keys
2977 count:(NSUInteger)count {
2978 self = [super init];
2980 _dictionary = [[NSMutableDictionary alloc] init];
2981 if (count && objects && keys) {
2982 for (NSUInteger i = 0; i < count; ++i) {
2984 [NSException raise:NSInvalidArgumentException
2985 format:@"Attempting to add nil object to a Dictionary"];
2987 [_dictionary setObject:objects[i] forKey:@(keys[i])];
2994 - (instancetype)initWithDictionary:(GPBUInt32ObjectDictionary *)dictionary {
2995 self = [self initWithObjects:NULL forKeys:NULL count:0];
2998 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
3004 - (instancetype)initWithCapacity:(NSUInteger)numItems {
3005 #pragma unused(numItems)
3006 return [self initWithObjects:NULL forKeys:NULL count:0];
3010 NSAssert(!_autocreator,
3011 @"%@: Autocreator must be cleared before release, autocreator: %@",
3012 [self class], _autocreator);
3013 [_dictionary release];
3017 - (instancetype)copyWithZone:(NSZone *)zone {
3018 return [[GPBUInt32ObjectDictionary allocWithZone:zone] initWithDictionary:self];
3021 - (BOOL)isEqual:(id)other {
3022 if (self == other) {
3025 if (![other isKindOfClass:[GPBUInt32ObjectDictionary class]]) {
3028 GPBUInt32ObjectDictionary *otherDictionary = other;
3029 return [_dictionary isEqual:otherDictionary->_dictionary];
3032 - (NSUInteger)hash {
3033 return _dictionary.count;
3036 - (NSString *)description {
3037 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
3040 - (NSUInteger)count {
3041 return _dictionary.count;
3044 - (void)enumerateKeysAndObjectsUsingBlock:
3045 (void (^)(uint32_t key, id object, BOOL *stop))block {
3047 NSDictionary *internal = _dictionary;
3048 NSEnumerator *keys = [internal keyEnumerator];
3050 while ((aKey = [keys nextObject])) {
3051 id aObject = internal[aKey];
3052 block([aKey unsignedIntValue], aObject, &stop);
3059 - (BOOL)isInitialized {
3060 for (GPBMessage *msg in [_dictionary objectEnumerator]) {
3061 if (!msg.initialized) {
3068 - (instancetype)deepCopyWithZone:(NSZone *)zone {
3069 GPBUInt32ObjectDictionary *newDict =
3070 [[GPBUInt32ObjectDictionary alloc] init];
3071 NSEnumerator *keys = [_dictionary keyEnumerator];
3073 NSMutableDictionary *internalDict = newDict->_dictionary;
3074 while ((aKey = [keys nextObject])) {
3075 GPBMessage *msg = _dictionary[aKey];
3076 GPBMessage *copiedMsg = [msg copyWithZone:zone];
3077 [internalDict setObject:copiedMsg forKey:aKey];
3078 [copiedMsg release];
3083 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
3084 NSDictionary *internal = _dictionary;
3085 NSUInteger count = internal.count;
3090 GPBDataType valueDataType = GPBGetFieldDataType(field);
3091 GPBDataType keyDataType = field.mapKeyDataType;
3093 NSEnumerator *keys = [internal keyEnumerator];
3095 while ((aKey = [keys nextObject])) {
3096 id aObject = internal[aKey];
3097 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
3098 msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
3099 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
3101 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
3102 result += tagSize * count;
3106 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
3107 asField:(GPBFieldDescriptor *)field {
3108 GPBDataType valueDataType = GPBGetFieldDataType(field);
3109 GPBDataType keyDataType = field.mapKeyDataType;
3110 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
3111 NSDictionary *internal = _dictionary;
3112 NSEnumerator *keys = [internal keyEnumerator];
3114 while ((aKey = [keys nextObject])) {
3115 id aObject = internal[aKey];
3116 [outputStream writeInt32NoTag:tag];
3117 // Write the size of the message.
3118 uint32_t unwrappedKey = [aKey unsignedIntValue];
3119 id unwrappedValue = aObject;
3120 size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
3121 msgSize += ComputeDictObjectFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
3122 [outputStream writeInt32NoTag:(int32_t)msgSize];
3123 // Write the fields.
3124 WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
3125 WriteDictObjectField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
3129 - (void)setGPBGenericValue:(GPBGenericValue *)value
3130 forGPBGenericValueKey:(GPBGenericValue *)key {
3131 [_dictionary setObject:value->valueString forKey:@(key->valueUInt32)];
3134 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
3135 [self enumerateKeysAndObjectsUsingBlock:^(uint32_t key, id object, BOOL *stop) {
3136 #pragma unused(stop)
3137 block([NSString stringWithFormat:@"%u", key], object);
3141 - (id)objectForKey:(uint32_t)key {
3142 id result = [_dictionary objectForKey:@(key)];
3146 - (void)addEntriesFromDictionary:(GPBUInt32ObjectDictionary *)otherDictionary {
3147 if (otherDictionary) {
3148 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
3150 GPBAutocreatedDictionaryModified(_autocreator, self);
3155 - (void)setObject:(id)object forKey:(uint32_t)key {
3157 [NSException raise:NSInvalidArgumentException
3158 format:@"Attempting to add nil object to a Dictionary"];
3160 [_dictionary setObject:object forKey:@(key)];
3162 GPBAutocreatedDictionaryModified(_autocreator, self);
3166 - (void)removeObjectForKey:(uint32_t)aKey {
3167 [_dictionary removeObjectForKey:@(aKey)];
3171 [_dictionary removeAllObjects];
3176 //%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(Int32, int32_t)
3177 // This block of code is generated, do not edit it directly.
3179 #pragma mark - Int32 -> UInt32
3181 @implementation GPBInt32UInt32Dictionary {
3183 NSMutableDictionary *_dictionary;
3186 - (instancetype)init {
3187 return [self initWithUInt32s:NULL forKeys:NULL count:0];
3190 - (instancetype)initWithUInt32s:(const uint32_t [])values
3191 forKeys:(const int32_t [])keys
3192 count:(NSUInteger)count {
3193 self = [super init];
3195 _dictionary = [[NSMutableDictionary alloc] init];
3196 if (count && values && keys) {
3197 for (NSUInteger i = 0; i < count; ++i) {
3198 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
3205 - (instancetype)initWithDictionary:(GPBInt32UInt32Dictionary *)dictionary {
3206 self = [self initWithUInt32s:NULL forKeys:NULL count:0];
3209 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
3215 - (instancetype)initWithCapacity:(NSUInteger)numItems {
3216 #pragma unused(numItems)
3217 return [self initWithUInt32s:NULL forKeys:NULL count:0];
3221 NSAssert(!_autocreator,
3222 @"%@: Autocreator must be cleared before release, autocreator: %@",
3223 [self class], _autocreator);
3224 [_dictionary release];
3228 - (instancetype)copyWithZone:(NSZone *)zone {
3229 return [[GPBInt32UInt32Dictionary allocWithZone:zone] initWithDictionary:self];
3232 - (BOOL)isEqual:(id)other {
3233 if (self == other) {
3236 if (![other isKindOfClass:[GPBInt32UInt32Dictionary class]]) {
3239 GPBInt32UInt32Dictionary *otherDictionary = other;
3240 return [_dictionary isEqual:otherDictionary->_dictionary];
3243 - (NSUInteger)hash {
3244 return _dictionary.count;
3247 - (NSString *)description {
3248 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
3251 - (NSUInteger)count {
3252 return _dictionary.count;
3255 - (void)enumerateKeysAndUInt32sUsingBlock:
3256 (void (^)(int32_t key, uint32_t value, BOOL *stop))block {
3258 NSDictionary *internal = _dictionary;
3259 NSEnumerator *keys = [internal keyEnumerator];
3261 while ((aKey = [keys nextObject])) {
3262 NSNumber *aValue = internal[aKey];
3263 block([aKey intValue], [aValue unsignedIntValue], &stop);
3270 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
3271 NSDictionary *internal = _dictionary;
3272 NSUInteger count = internal.count;
3277 GPBDataType valueDataType = GPBGetFieldDataType(field);
3278 GPBDataType keyDataType = field.mapKeyDataType;
3280 NSEnumerator *keys = [internal keyEnumerator];
3282 while ((aKey = [keys nextObject])) {
3283 NSNumber *aValue = internal[aKey];
3284 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
3285 msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
3286 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
3288 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
3289 result += tagSize * count;
3293 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
3294 asField:(GPBFieldDescriptor *)field {
3295 GPBDataType valueDataType = GPBGetFieldDataType(field);
3296 GPBDataType keyDataType = field.mapKeyDataType;
3297 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
3298 NSDictionary *internal = _dictionary;
3299 NSEnumerator *keys = [internal keyEnumerator];
3301 while ((aKey = [keys nextObject])) {
3302 NSNumber *aValue = internal[aKey];
3303 [outputStream writeInt32NoTag:tag];
3304 // Write the size of the message.
3305 int32_t unwrappedKey = [aKey intValue];
3306 uint32_t unwrappedValue = [aValue unsignedIntValue];
3307 size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
3308 msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
3309 [outputStream writeInt32NoTag:(int32_t)msgSize];
3310 // Write the fields.
3311 WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
3312 WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
3316 - (void)setGPBGenericValue:(GPBGenericValue *)value
3317 forGPBGenericValueKey:(GPBGenericValue *)key {
3318 [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueInt32)];
3321 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
3322 [self enumerateKeysAndUInt32sUsingBlock:^(int32_t key, uint32_t value, BOOL *stop) {
3323 #pragma unused(stop)
3324 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%u", value]);
3328 - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(int32_t)key {
3329 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
3330 if (wrapped && value) {
3331 *value = [wrapped unsignedIntValue];
3333 return (wrapped != NULL);
3336 - (void)addEntriesFromDictionary:(GPBInt32UInt32Dictionary *)otherDictionary {
3337 if (otherDictionary) {
3338 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
3340 GPBAutocreatedDictionaryModified(_autocreator, self);
3345 - (void)setUInt32:(uint32_t)value forKey:(int32_t)key {
3346 [_dictionary setObject:@(value) forKey:@(key)];
3348 GPBAutocreatedDictionaryModified(_autocreator, self);
3352 - (void)removeUInt32ForKey:(int32_t)aKey {
3353 [_dictionary removeObjectForKey:@(aKey)];
3357 [_dictionary removeAllObjects];
3362 #pragma mark - Int32 -> Int32
3364 @implementation GPBInt32Int32Dictionary {
3366 NSMutableDictionary *_dictionary;
3369 - (instancetype)init {
3370 return [self initWithInt32s:NULL forKeys:NULL count:0];
3373 - (instancetype)initWithInt32s:(const int32_t [])values
3374 forKeys:(const int32_t [])keys
3375 count:(NSUInteger)count {
3376 self = [super init];
3378 _dictionary = [[NSMutableDictionary alloc] init];
3379 if (count && values && keys) {
3380 for (NSUInteger i = 0; i < count; ++i) {
3381 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
3388 - (instancetype)initWithDictionary:(GPBInt32Int32Dictionary *)dictionary {
3389 self = [self initWithInt32s:NULL forKeys:NULL count:0];
3392 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
3398 - (instancetype)initWithCapacity:(NSUInteger)numItems {
3399 #pragma unused(numItems)
3400 return [self initWithInt32s:NULL forKeys:NULL count:0];
3404 NSAssert(!_autocreator,
3405 @"%@: Autocreator must be cleared before release, autocreator: %@",
3406 [self class], _autocreator);
3407 [_dictionary release];
3411 - (instancetype)copyWithZone:(NSZone *)zone {
3412 return [[GPBInt32Int32Dictionary allocWithZone:zone] initWithDictionary:self];
3415 - (BOOL)isEqual:(id)other {
3416 if (self == other) {
3419 if (![other isKindOfClass:[GPBInt32Int32Dictionary class]]) {
3422 GPBInt32Int32Dictionary *otherDictionary = other;
3423 return [_dictionary isEqual:otherDictionary->_dictionary];
3426 - (NSUInteger)hash {
3427 return _dictionary.count;
3430 - (NSString *)description {
3431 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
3434 - (NSUInteger)count {
3435 return _dictionary.count;
3438 - (void)enumerateKeysAndInt32sUsingBlock:
3439 (void (^)(int32_t key, int32_t value, BOOL *stop))block {
3441 NSDictionary *internal = _dictionary;
3442 NSEnumerator *keys = [internal keyEnumerator];
3444 while ((aKey = [keys nextObject])) {
3445 NSNumber *aValue = internal[aKey];
3446 block([aKey intValue], [aValue intValue], &stop);
3453 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
3454 NSDictionary *internal = _dictionary;
3455 NSUInteger count = internal.count;
3460 GPBDataType valueDataType = GPBGetFieldDataType(field);
3461 GPBDataType keyDataType = field.mapKeyDataType;
3463 NSEnumerator *keys = [internal keyEnumerator];
3465 while ((aKey = [keys nextObject])) {
3466 NSNumber *aValue = internal[aKey];
3467 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
3468 msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
3469 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
3471 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
3472 result += tagSize * count;
3476 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
3477 asField:(GPBFieldDescriptor *)field {
3478 GPBDataType valueDataType = GPBGetFieldDataType(field);
3479 GPBDataType keyDataType = field.mapKeyDataType;
3480 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
3481 NSDictionary *internal = _dictionary;
3482 NSEnumerator *keys = [internal keyEnumerator];
3484 while ((aKey = [keys nextObject])) {
3485 NSNumber *aValue = internal[aKey];
3486 [outputStream writeInt32NoTag:tag];
3487 // Write the size of the message.
3488 int32_t unwrappedKey = [aKey intValue];
3489 int32_t unwrappedValue = [aValue intValue];
3490 size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
3491 msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
3492 [outputStream writeInt32NoTag:(int32_t)msgSize];
3493 // Write the fields.
3494 WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
3495 WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
3499 - (void)setGPBGenericValue:(GPBGenericValue *)value
3500 forGPBGenericValueKey:(GPBGenericValue *)key {
3501 [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueInt32)];
3504 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
3505 [self enumerateKeysAndInt32sUsingBlock:^(int32_t key, int32_t value, BOOL *stop) {
3506 #pragma unused(stop)
3507 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%d", value]);
3511 - (BOOL)getInt32:(nullable int32_t *)value forKey:(int32_t)key {
3512 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
3513 if (wrapped && value) {
3514 *value = [wrapped intValue];
3516 return (wrapped != NULL);
3519 - (void)addEntriesFromDictionary:(GPBInt32Int32Dictionary *)otherDictionary {
3520 if (otherDictionary) {
3521 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
3523 GPBAutocreatedDictionaryModified(_autocreator, self);
3528 - (void)setInt32:(int32_t)value forKey:(int32_t)key {
3529 [_dictionary setObject:@(value) forKey:@(key)];
3531 GPBAutocreatedDictionaryModified(_autocreator, self);
3535 - (void)removeInt32ForKey:(int32_t)aKey {
3536 [_dictionary removeObjectForKey:@(aKey)];
3540 [_dictionary removeAllObjects];
3545 #pragma mark - Int32 -> UInt64
3547 @implementation GPBInt32UInt64Dictionary {
3549 NSMutableDictionary *_dictionary;
3552 - (instancetype)init {
3553 return [self initWithUInt64s:NULL forKeys:NULL count:0];
3556 - (instancetype)initWithUInt64s:(const uint64_t [])values
3557 forKeys:(const int32_t [])keys
3558 count:(NSUInteger)count {
3559 self = [super init];
3561 _dictionary = [[NSMutableDictionary alloc] init];
3562 if (count && values && keys) {
3563 for (NSUInteger i = 0; i < count; ++i) {
3564 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
3571 - (instancetype)initWithDictionary:(GPBInt32UInt64Dictionary *)dictionary {
3572 self = [self initWithUInt64s:NULL forKeys:NULL count:0];
3575 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
3581 - (instancetype)initWithCapacity:(NSUInteger)numItems {
3582 #pragma unused(numItems)
3583 return [self initWithUInt64s:NULL forKeys:NULL count:0];
3587 NSAssert(!_autocreator,
3588 @"%@: Autocreator must be cleared before release, autocreator: %@",
3589 [self class], _autocreator);
3590 [_dictionary release];
3594 - (instancetype)copyWithZone:(NSZone *)zone {
3595 return [[GPBInt32UInt64Dictionary allocWithZone:zone] initWithDictionary:self];
3598 - (BOOL)isEqual:(id)other {
3599 if (self == other) {
3602 if (![other isKindOfClass:[GPBInt32UInt64Dictionary class]]) {
3605 GPBInt32UInt64Dictionary *otherDictionary = other;
3606 return [_dictionary isEqual:otherDictionary->_dictionary];
3609 - (NSUInteger)hash {
3610 return _dictionary.count;
3613 - (NSString *)description {
3614 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
3617 - (NSUInteger)count {
3618 return _dictionary.count;
3621 - (void)enumerateKeysAndUInt64sUsingBlock:
3622 (void (^)(int32_t key, uint64_t value, BOOL *stop))block {
3624 NSDictionary *internal = _dictionary;
3625 NSEnumerator *keys = [internal keyEnumerator];
3627 while ((aKey = [keys nextObject])) {
3628 NSNumber *aValue = internal[aKey];
3629 block([aKey intValue], [aValue unsignedLongLongValue], &stop);
3636 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
3637 NSDictionary *internal = _dictionary;
3638 NSUInteger count = internal.count;
3643 GPBDataType valueDataType = GPBGetFieldDataType(field);
3644 GPBDataType keyDataType = field.mapKeyDataType;
3646 NSEnumerator *keys = [internal keyEnumerator];
3648 while ((aKey = [keys nextObject])) {
3649 NSNumber *aValue = internal[aKey];
3650 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
3651 msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
3652 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
3654 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
3655 result += tagSize * count;
3659 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
3660 asField:(GPBFieldDescriptor *)field {
3661 GPBDataType valueDataType = GPBGetFieldDataType(field);
3662 GPBDataType keyDataType = field.mapKeyDataType;
3663 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
3664 NSDictionary *internal = _dictionary;
3665 NSEnumerator *keys = [internal keyEnumerator];
3667 while ((aKey = [keys nextObject])) {
3668 NSNumber *aValue = internal[aKey];
3669 [outputStream writeInt32NoTag:tag];
3670 // Write the size of the message.
3671 int32_t unwrappedKey = [aKey intValue];
3672 uint64_t unwrappedValue = [aValue unsignedLongLongValue];
3673 size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
3674 msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
3675 [outputStream writeInt32NoTag:(int32_t)msgSize];
3676 // Write the fields.
3677 WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
3678 WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
3682 - (void)setGPBGenericValue:(GPBGenericValue *)value
3683 forGPBGenericValueKey:(GPBGenericValue *)key {
3684 [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueInt32)];
3687 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
3688 [self enumerateKeysAndUInt64sUsingBlock:^(int32_t key, uint64_t value, BOOL *stop) {
3689 #pragma unused(stop)
3690 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%llu", value]);
3694 - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(int32_t)key {
3695 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
3696 if (wrapped && value) {
3697 *value = [wrapped unsignedLongLongValue];
3699 return (wrapped != NULL);
3702 - (void)addEntriesFromDictionary:(GPBInt32UInt64Dictionary *)otherDictionary {
3703 if (otherDictionary) {
3704 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
3706 GPBAutocreatedDictionaryModified(_autocreator, self);
3711 - (void)setUInt64:(uint64_t)value forKey:(int32_t)key {
3712 [_dictionary setObject:@(value) forKey:@(key)];
3714 GPBAutocreatedDictionaryModified(_autocreator, self);
3718 - (void)removeUInt64ForKey:(int32_t)aKey {
3719 [_dictionary removeObjectForKey:@(aKey)];
3723 [_dictionary removeAllObjects];
3728 #pragma mark - Int32 -> Int64
3730 @implementation GPBInt32Int64Dictionary {
3732 NSMutableDictionary *_dictionary;
3735 - (instancetype)init {
3736 return [self initWithInt64s:NULL forKeys:NULL count:0];
3739 - (instancetype)initWithInt64s:(const int64_t [])values
3740 forKeys:(const int32_t [])keys
3741 count:(NSUInteger)count {
3742 self = [super init];
3744 _dictionary = [[NSMutableDictionary alloc] init];
3745 if (count && values && keys) {
3746 for (NSUInteger i = 0; i < count; ++i) {
3747 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
3754 - (instancetype)initWithDictionary:(GPBInt32Int64Dictionary *)dictionary {
3755 self = [self initWithInt64s:NULL forKeys:NULL count:0];
3758 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
3764 - (instancetype)initWithCapacity:(NSUInteger)numItems {
3765 #pragma unused(numItems)
3766 return [self initWithInt64s:NULL forKeys:NULL count:0];
3770 NSAssert(!_autocreator,
3771 @"%@: Autocreator must be cleared before release, autocreator: %@",
3772 [self class], _autocreator);
3773 [_dictionary release];
3777 - (instancetype)copyWithZone:(NSZone *)zone {
3778 return [[GPBInt32Int64Dictionary allocWithZone:zone] initWithDictionary:self];
3781 - (BOOL)isEqual:(id)other {
3782 if (self == other) {
3785 if (![other isKindOfClass:[GPBInt32Int64Dictionary class]]) {
3788 GPBInt32Int64Dictionary *otherDictionary = other;
3789 return [_dictionary isEqual:otherDictionary->_dictionary];
3792 - (NSUInteger)hash {
3793 return _dictionary.count;
3796 - (NSString *)description {
3797 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
3800 - (NSUInteger)count {
3801 return _dictionary.count;
3804 - (void)enumerateKeysAndInt64sUsingBlock:
3805 (void (^)(int32_t key, int64_t value, BOOL *stop))block {
3807 NSDictionary *internal = _dictionary;
3808 NSEnumerator *keys = [internal keyEnumerator];
3810 while ((aKey = [keys nextObject])) {
3811 NSNumber *aValue = internal[aKey];
3812 block([aKey intValue], [aValue longLongValue], &stop);
3819 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
3820 NSDictionary *internal = _dictionary;
3821 NSUInteger count = internal.count;
3826 GPBDataType valueDataType = GPBGetFieldDataType(field);
3827 GPBDataType keyDataType = field.mapKeyDataType;
3829 NSEnumerator *keys = [internal keyEnumerator];
3831 while ((aKey = [keys nextObject])) {
3832 NSNumber *aValue = internal[aKey];
3833 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
3834 msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
3835 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
3837 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
3838 result += tagSize * count;
3842 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
3843 asField:(GPBFieldDescriptor *)field {
3844 GPBDataType valueDataType = GPBGetFieldDataType(field);
3845 GPBDataType keyDataType = field.mapKeyDataType;
3846 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
3847 NSDictionary *internal = _dictionary;
3848 NSEnumerator *keys = [internal keyEnumerator];
3850 while ((aKey = [keys nextObject])) {
3851 NSNumber *aValue = internal[aKey];
3852 [outputStream writeInt32NoTag:tag];
3853 // Write the size of the message.
3854 int32_t unwrappedKey = [aKey intValue];
3855 int64_t unwrappedValue = [aValue longLongValue];
3856 size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
3857 msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
3858 [outputStream writeInt32NoTag:(int32_t)msgSize];
3859 // Write the fields.
3860 WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
3861 WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
3865 - (void)setGPBGenericValue:(GPBGenericValue *)value
3866 forGPBGenericValueKey:(GPBGenericValue *)key {
3867 [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueInt32)];
3870 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
3871 [self enumerateKeysAndInt64sUsingBlock:^(int32_t key, int64_t value, BOOL *stop) {
3872 #pragma unused(stop)
3873 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%lld", value]);
3877 - (BOOL)getInt64:(nullable int64_t *)value forKey:(int32_t)key {
3878 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
3879 if (wrapped && value) {
3880 *value = [wrapped longLongValue];
3882 return (wrapped != NULL);
3885 - (void)addEntriesFromDictionary:(GPBInt32Int64Dictionary *)otherDictionary {
3886 if (otherDictionary) {
3887 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
3889 GPBAutocreatedDictionaryModified(_autocreator, self);
3894 - (void)setInt64:(int64_t)value forKey:(int32_t)key {
3895 [_dictionary setObject:@(value) forKey:@(key)];
3897 GPBAutocreatedDictionaryModified(_autocreator, self);
3901 - (void)removeInt64ForKey:(int32_t)aKey {
3902 [_dictionary removeObjectForKey:@(aKey)];
3906 [_dictionary removeAllObjects];
3911 #pragma mark - Int32 -> Bool
3913 @implementation GPBInt32BoolDictionary {
3915 NSMutableDictionary *_dictionary;
3918 - (instancetype)init {
3919 return [self initWithBools:NULL forKeys:NULL count:0];
3922 - (instancetype)initWithBools:(const BOOL [])values
3923 forKeys:(const int32_t [])keys
3924 count:(NSUInteger)count {
3925 self = [super init];
3927 _dictionary = [[NSMutableDictionary alloc] init];
3928 if (count && values && keys) {
3929 for (NSUInteger i = 0; i < count; ++i) {
3930 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
3937 - (instancetype)initWithDictionary:(GPBInt32BoolDictionary *)dictionary {
3938 self = [self initWithBools:NULL forKeys:NULL count:0];
3941 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
3947 - (instancetype)initWithCapacity:(NSUInteger)numItems {
3948 #pragma unused(numItems)
3949 return [self initWithBools:NULL forKeys:NULL count:0];
3953 NSAssert(!_autocreator,
3954 @"%@: Autocreator must be cleared before release, autocreator: %@",
3955 [self class], _autocreator);
3956 [_dictionary release];
3960 - (instancetype)copyWithZone:(NSZone *)zone {
3961 return [[GPBInt32BoolDictionary allocWithZone:zone] initWithDictionary:self];
3964 - (BOOL)isEqual:(id)other {
3965 if (self == other) {
3968 if (![other isKindOfClass:[GPBInt32BoolDictionary class]]) {
3971 GPBInt32BoolDictionary *otherDictionary = other;
3972 return [_dictionary isEqual:otherDictionary->_dictionary];
3975 - (NSUInteger)hash {
3976 return _dictionary.count;
3979 - (NSString *)description {
3980 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
3983 - (NSUInteger)count {
3984 return _dictionary.count;
3987 - (void)enumerateKeysAndBoolsUsingBlock:
3988 (void (^)(int32_t key, BOOL value, BOOL *stop))block {
3990 NSDictionary *internal = _dictionary;
3991 NSEnumerator *keys = [internal keyEnumerator];
3993 while ((aKey = [keys nextObject])) {
3994 NSNumber *aValue = internal[aKey];
3995 block([aKey intValue], [aValue boolValue], &stop);
4002 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
4003 NSDictionary *internal = _dictionary;
4004 NSUInteger count = internal.count;
4009 GPBDataType valueDataType = GPBGetFieldDataType(field);
4010 GPBDataType keyDataType = field.mapKeyDataType;
4012 NSEnumerator *keys = [internal keyEnumerator];
4014 while ((aKey = [keys nextObject])) {
4015 NSNumber *aValue = internal[aKey];
4016 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
4017 msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
4018 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
4020 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
4021 result += tagSize * count;
4025 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
4026 asField:(GPBFieldDescriptor *)field {
4027 GPBDataType valueDataType = GPBGetFieldDataType(field);
4028 GPBDataType keyDataType = field.mapKeyDataType;
4029 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
4030 NSDictionary *internal = _dictionary;
4031 NSEnumerator *keys = [internal keyEnumerator];
4033 while ((aKey = [keys nextObject])) {
4034 NSNumber *aValue = internal[aKey];
4035 [outputStream writeInt32NoTag:tag];
4036 // Write the size of the message.
4037 int32_t unwrappedKey = [aKey intValue];
4038 BOOL unwrappedValue = [aValue boolValue];
4039 size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
4040 msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
4041 [outputStream writeInt32NoTag:(int32_t)msgSize];
4042 // Write the fields.
4043 WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
4044 WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
4048 - (void)setGPBGenericValue:(GPBGenericValue *)value
4049 forGPBGenericValueKey:(GPBGenericValue *)key {
4050 [_dictionary setObject:@(value->valueBool) forKey:@(key->valueInt32)];
4053 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
4054 [self enumerateKeysAndBoolsUsingBlock:^(int32_t key, BOOL value, BOOL *stop) {
4055 #pragma unused(stop)
4056 block([NSString stringWithFormat:@"%d", key], (value ? @"true" : @"false"));
4060 - (BOOL)getBool:(nullable BOOL *)value forKey:(int32_t)key {
4061 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
4062 if (wrapped && value) {
4063 *value = [wrapped boolValue];
4065 return (wrapped != NULL);
4068 - (void)addEntriesFromDictionary:(GPBInt32BoolDictionary *)otherDictionary {
4069 if (otherDictionary) {
4070 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
4072 GPBAutocreatedDictionaryModified(_autocreator, self);
4077 - (void)setBool:(BOOL)value forKey:(int32_t)key {
4078 [_dictionary setObject:@(value) forKey:@(key)];
4080 GPBAutocreatedDictionaryModified(_autocreator, self);
4084 - (void)removeBoolForKey:(int32_t)aKey {
4085 [_dictionary removeObjectForKey:@(aKey)];
4089 [_dictionary removeAllObjects];
4094 #pragma mark - Int32 -> Float
4096 @implementation GPBInt32FloatDictionary {
4098 NSMutableDictionary *_dictionary;
4101 - (instancetype)init {
4102 return [self initWithFloats:NULL forKeys:NULL count:0];
4105 - (instancetype)initWithFloats:(const float [])values
4106 forKeys:(const int32_t [])keys
4107 count:(NSUInteger)count {
4108 self = [super init];
4110 _dictionary = [[NSMutableDictionary alloc] init];
4111 if (count && values && keys) {
4112 for (NSUInteger i = 0; i < count; ++i) {
4113 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
4120 - (instancetype)initWithDictionary:(GPBInt32FloatDictionary *)dictionary {
4121 self = [self initWithFloats:NULL forKeys:NULL count:0];
4124 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
4130 - (instancetype)initWithCapacity:(NSUInteger)numItems {
4131 #pragma unused(numItems)
4132 return [self initWithFloats:NULL forKeys:NULL count:0];
4136 NSAssert(!_autocreator,
4137 @"%@: Autocreator must be cleared before release, autocreator: %@",
4138 [self class], _autocreator);
4139 [_dictionary release];
4143 - (instancetype)copyWithZone:(NSZone *)zone {
4144 return [[GPBInt32FloatDictionary allocWithZone:zone] initWithDictionary:self];
4147 - (BOOL)isEqual:(id)other {
4148 if (self == other) {
4151 if (![other isKindOfClass:[GPBInt32FloatDictionary class]]) {
4154 GPBInt32FloatDictionary *otherDictionary = other;
4155 return [_dictionary isEqual:otherDictionary->_dictionary];
4158 - (NSUInteger)hash {
4159 return _dictionary.count;
4162 - (NSString *)description {
4163 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
4166 - (NSUInteger)count {
4167 return _dictionary.count;
4170 - (void)enumerateKeysAndFloatsUsingBlock:
4171 (void (^)(int32_t key, float value, BOOL *stop))block {
4173 NSDictionary *internal = _dictionary;
4174 NSEnumerator *keys = [internal keyEnumerator];
4176 while ((aKey = [keys nextObject])) {
4177 NSNumber *aValue = internal[aKey];
4178 block([aKey intValue], [aValue floatValue], &stop);
4185 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
4186 NSDictionary *internal = _dictionary;
4187 NSUInteger count = internal.count;
4192 GPBDataType valueDataType = GPBGetFieldDataType(field);
4193 GPBDataType keyDataType = field.mapKeyDataType;
4195 NSEnumerator *keys = [internal keyEnumerator];
4197 while ((aKey = [keys nextObject])) {
4198 NSNumber *aValue = internal[aKey];
4199 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
4200 msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
4201 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
4203 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
4204 result += tagSize * count;
4208 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
4209 asField:(GPBFieldDescriptor *)field {
4210 GPBDataType valueDataType = GPBGetFieldDataType(field);
4211 GPBDataType keyDataType = field.mapKeyDataType;
4212 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
4213 NSDictionary *internal = _dictionary;
4214 NSEnumerator *keys = [internal keyEnumerator];
4216 while ((aKey = [keys nextObject])) {
4217 NSNumber *aValue = internal[aKey];
4218 [outputStream writeInt32NoTag:tag];
4219 // Write the size of the message.
4220 int32_t unwrappedKey = [aKey intValue];
4221 float unwrappedValue = [aValue floatValue];
4222 size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
4223 msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
4224 [outputStream writeInt32NoTag:(int32_t)msgSize];
4225 // Write the fields.
4226 WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
4227 WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
4231 - (void)setGPBGenericValue:(GPBGenericValue *)value
4232 forGPBGenericValueKey:(GPBGenericValue *)key {
4233 [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueInt32)];
4236 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
4237 [self enumerateKeysAndFloatsUsingBlock:^(int32_t key, float value, BOOL *stop) {
4238 #pragma unused(stop)
4239 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
4243 - (BOOL)getFloat:(nullable float *)value forKey:(int32_t)key {
4244 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
4245 if (wrapped && value) {
4246 *value = [wrapped floatValue];
4248 return (wrapped != NULL);
4251 - (void)addEntriesFromDictionary:(GPBInt32FloatDictionary *)otherDictionary {
4252 if (otherDictionary) {
4253 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
4255 GPBAutocreatedDictionaryModified(_autocreator, self);
4260 - (void)setFloat:(float)value forKey:(int32_t)key {
4261 [_dictionary setObject:@(value) forKey:@(key)];
4263 GPBAutocreatedDictionaryModified(_autocreator, self);
4267 - (void)removeFloatForKey:(int32_t)aKey {
4268 [_dictionary removeObjectForKey:@(aKey)];
4272 [_dictionary removeAllObjects];
4277 #pragma mark - Int32 -> Double
4279 @implementation GPBInt32DoubleDictionary {
4281 NSMutableDictionary *_dictionary;
4284 - (instancetype)init {
4285 return [self initWithDoubles:NULL forKeys:NULL count:0];
4288 - (instancetype)initWithDoubles:(const double [])values
4289 forKeys:(const int32_t [])keys
4290 count:(NSUInteger)count {
4291 self = [super init];
4293 _dictionary = [[NSMutableDictionary alloc] init];
4294 if (count && values && keys) {
4295 for (NSUInteger i = 0; i < count; ++i) {
4296 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
4303 - (instancetype)initWithDictionary:(GPBInt32DoubleDictionary *)dictionary {
4304 self = [self initWithDoubles:NULL forKeys:NULL count:0];
4307 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
4313 - (instancetype)initWithCapacity:(NSUInteger)numItems {
4314 #pragma unused(numItems)
4315 return [self initWithDoubles:NULL forKeys:NULL count:0];
4319 NSAssert(!_autocreator,
4320 @"%@: Autocreator must be cleared before release, autocreator: %@",
4321 [self class], _autocreator);
4322 [_dictionary release];
4326 - (instancetype)copyWithZone:(NSZone *)zone {
4327 return [[GPBInt32DoubleDictionary allocWithZone:zone] initWithDictionary:self];
4330 - (BOOL)isEqual:(id)other {
4331 if (self == other) {
4334 if (![other isKindOfClass:[GPBInt32DoubleDictionary class]]) {
4337 GPBInt32DoubleDictionary *otherDictionary = other;
4338 return [_dictionary isEqual:otherDictionary->_dictionary];
4341 - (NSUInteger)hash {
4342 return _dictionary.count;
4345 - (NSString *)description {
4346 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
4349 - (NSUInteger)count {
4350 return _dictionary.count;
4353 - (void)enumerateKeysAndDoublesUsingBlock:
4354 (void (^)(int32_t key, double value, BOOL *stop))block {
4356 NSDictionary *internal = _dictionary;
4357 NSEnumerator *keys = [internal keyEnumerator];
4359 while ((aKey = [keys nextObject])) {
4360 NSNumber *aValue = internal[aKey];
4361 block([aKey intValue], [aValue doubleValue], &stop);
4368 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
4369 NSDictionary *internal = _dictionary;
4370 NSUInteger count = internal.count;
4375 GPBDataType valueDataType = GPBGetFieldDataType(field);
4376 GPBDataType keyDataType = field.mapKeyDataType;
4378 NSEnumerator *keys = [internal keyEnumerator];
4380 while ((aKey = [keys nextObject])) {
4381 NSNumber *aValue = internal[aKey];
4382 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
4383 msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
4384 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
4386 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
4387 result += tagSize * count;
4391 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
4392 asField:(GPBFieldDescriptor *)field {
4393 GPBDataType valueDataType = GPBGetFieldDataType(field);
4394 GPBDataType keyDataType = field.mapKeyDataType;
4395 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
4396 NSDictionary *internal = _dictionary;
4397 NSEnumerator *keys = [internal keyEnumerator];
4399 while ((aKey = [keys nextObject])) {
4400 NSNumber *aValue = internal[aKey];
4401 [outputStream writeInt32NoTag:tag];
4402 // Write the size of the message.
4403 int32_t unwrappedKey = [aKey intValue];
4404 double unwrappedValue = [aValue doubleValue];
4405 size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
4406 msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
4407 [outputStream writeInt32NoTag:(int32_t)msgSize];
4408 // Write the fields.
4409 WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
4410 WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
4414 - (void)setGPBGenericValue:(GPBGenericValue *)value
4415 forGPBGenericValueKey:(GPBGenericValue *)key {
4416 [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueInt32)];
4419 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
4420 [self enumerateKeysAndDoublesUsingBlock:^(int32_t key, double value, BOOL *stop) {
4421 #pragma unused(stop)
4422 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
4426 - (BOOL)getDouble:(nullable double *)value forKey:(int32_t)key {
4427 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
4428 if (wrapped && value) {
4429 *value = [wrapped doubleValue];
4431 return (wrapped != NULL);
4434 - (void)addEntriesFromDictionary:(GPBInt32DoubleDictionary *)otherDictionary {
4435 if (otherDictionary) {
4436 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
4438 GPBAutocreatedDictionaryModified(_autocreator, self);
4443 - (void)setDouble:(double)value forKey:(int32_t)key {
4444 [_dictionary setObject:@(value) forKey:@(key)];
4446 GPBAutocreatedDictionaryModified(_autocreator, self);
4450 - (void)removeDoubleForKey:(int32_t)aKey {
4451 [_dictionary removeObjectForKey:@(aKey)];
4455 [_dictionary removeAllObjects];
4460 #pragma mark - Int32 -> Enum
4462 @implementation GPBInt32EnumDictionary {
4464 NSMutableDictionary *_dictionary;
4465 GPBEnumValidationFunc _validationFunc;
4468 @synthesize validationFunc = _validationFunc;
4470 - (instancetype)init {
4471 return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
4474 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
4475 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
4478 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
4479 rawValues:(const int32_t [])rawValues
4480 forKeys:(const int32_t [])keys
4481 count:(NSUInteger)count {
4482 self = [super init];
4484 _dictionary = [[NSMutableDictionary alloc] init];
4485 _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
4486 if (count && rawValues && keys) {
4487 for (NSUInteger i = 0; i < count; ++i) {
4488 [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])];
4495 - (instancetype)initWithDictionary:(GPBInt32EnumDictionary *)dictionary {
4496 self = [self initWithValidationFunction:dictionary.validationFunc
4502 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
4508 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
4509 capacity:(NSUInteger)numItems {
4510 #pragma unused(numItems)
4511 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
4515 NSAssert(!_autocreator,
4516 @"%@: Autocreator must be cleared before release, autocreator: %@",
4517 [self class], _autocreator);
4518 [_dictionary release];
4522 - (instancetype)copyWithZone:(NSZone *)zone {
4523 return [[GPBInt32EnumDictionary allocWithZone:zone] initWithDictionary:self];
4526 - (BOOL)isEqual:(id)other {
4527 if (self == other) {
4530 if (![other isKindOfClass:[GPBInt32EnumDictionary class]]) {
4533 GPBInt32EnumDictionary *otherDictionary = other;
4534 return [_dictionary isEqual:otherDictionary->_dictionary];
4537 - (NSUInteger)hash {
4538 return _dictionary.count;
4541 - (NSString *)description {
4542 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
4545 - (NSUInteger)count {
4546 return _dictionary.count;
4549 - (void)enumerateKeysAndRawValuesUsingBlock:
4550 (void (^)(int32_t key, int32_t value, BOOL *stop))block {
4552 NSDictionary *internal = _dictionary;
4553 NSEnumerator *keys = [internal keyEnumerator];
4555 while ((aKey = [keys nextObject])) {
4556 NSNumber *aValue = internal[aKey];
4557 block([aKey intValue], [aValue intValue], &stop);
4564 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
4565 NSDictionary *internal = _dictionary;
4566 NSUInteger count = internal.count;
4571 GPBDataType valueDataType = GPBGetFieldDataType(field);
4572 GPBDataType keyDataType = field.mapKeyDataType;
4574 NSEnumerator *keys = [internal keyEnumerator];
4576 while ((aKey = [keys nextObject])) {
4577 NSNumber *aValue = internal[aKey];
4578 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
4579 msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
4580 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
4582 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
4583 result += tagSize * count;
4587 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
4588 asField:(GPBFieldDescriptor *)field {
4589 GPBDataType valueDataType = GPBGetFieldDataType(field);
4590 GPBDataType keyDataType = field.mapKeyDataType;
4591 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
4592 NSDictionary *internal = _dictionary;
4593 NSEnumerator *keys = [internal keyEnumerator];
4595 while ((aKey = [keys nextObject])) {
4596 NSNumber *aValue = internal[aKey];
4597 [outputStream writeInt32NoTag:tag];
4598 // Write the size of the message.
4599 int32_t unwrappedKey = [aKey intValue];
4600 int32_t unwrappedValue = [aValue intValue];
4601 size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
4602 msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
4603 [outputStream writeInt32NoTag:(int32_t)msgSize];
4604 // Write the fields.
4605 WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
4606 WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
4610 - (NSData *)serializedDataForUnknownValue:(int32_t)value
4611 forKey:(GPBGenericValue *)key
4612 keyDataType:(GPBDataType)keyDataType {
4613 size_t msgSize = ComputeDictInt32FieldSize(key->valueInt32, kMapKeyFieldNumber, keyDataType);
4614 msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
4615 NSMutableData *data = [NSMutableData dataWithLength:msgSize];
4616 GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
4617 WriteDictInt32Field(outputStream, key->valueInt32, kMapKeyFieldNumber, keyDataType);
4618 WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
4619 [outputStream release];
4622 - (void)setGPBGenericValue:(GPBGenericValue *)value
4623 forGPBGenericValueKey:(GPBGenericValue *)key {
4624 [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueInt32)];
4627 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
4628 [self enumerateKeysAndRawValuesUsingBlock:^(int32_t key, int32_t value, BOOL *stop) {
4629 #pragma unused(stop)
4630 block([NSString stringWithFormat:@"%d", key], @(value));
4634 - (BOOL)getEnum:(int32_t *)value forKey:(int32_t)key {
4635 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
4636 if (wrapped && value) {
4637 int32_t result = [wrapped intValue];
4638 if (!_validationFunc(result)) {
4639 result = kGPBUnrecognizedEnumeratorValue;
4643 return (wrapped != NULL);
4646 - (BOOL)getRawValue:(int32_t *)rawValue forKey:(int32_t)key {
4647 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
4648 if (wrapped && rawValue) {
4649 *rawValue = [wrapped intValue];
4651 return (wrapped != NULL);
4654 - (void)enumerateKeysAndEnumsUsingBlock:
4655 (void (^)(int32_t key, int32_t value, BOOL *stop))block {
4656 GPBEnumValidationFunc func = _validationFunc;
4658 NSEnumerator *keys = [_dictionary keyEnumerator];
4660 while ((aKey = [keys nextObject])) {
4661 NSNumber *aValue = _dictionary[aKey];
4662 int32_t unwrapped = [aValue intValue];
4663 if (!func(unwrapped)) {
4664 unwrapped = kGPBUnrecognizedEnumeratorValue;
4666 block([aKey intValue], unwrapped, &stop);
4673 - (void)addRawEntriesFromDictionary:(GPBInt32EnumDictionary *)otherDictionary {
4674 if (otherDictionary) {
4675 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
4677 GPBAutocreatedDictionaryModified(_autocreator, self);
4682 - (void)setRawValue:(int32_t)value forKey:(int32_t)key {
4683 [_dictionary setObject:@(value) forKey:@(key)];
4685 GPBAutocreatedDictionaryModified(_autocreator, self);
4689 - (void)removeEnumForKey:(int32_t)aKey {
4690 [_dictionary removeObjectForKey:@(aKey)];
4694 [_dictionary removeAllObjects];
4697 - (void)setEnum:(int32_t)value forKey:(int32_t)key {
4698 if (!_validationFunc(value)) {
4699 [NSException raise:NSInvalidArgumentException
4700 format:@"GPBInt32EnumDictionary: Attempt to set an unknown enum value (%d)",
4704 [_dictionary setObject:@(value) forKey:@(key)];
4706 GPBAutocreatedDictionaryModified(_autocreator, self);
4712 #pragma mark - Int32 -> Object
4714 @implementation GPBInt32ObjectDictionary {
4716 NSMutableDictionary *_dictionary;
4719 - (instancetype)init {
4720 return [self initWithObjects:NULL forKeys:NULL count:0];
4723 - (instancetype)initWithObjects:(const id [])objects
4724 forKeys:(const int32_t [])keys
4725 count:(NSUInteger)count {
4726 self = [super init];
4728 _dictionary = [[NSMutableDictionary alloc] init];
4729 if (count && objects && keys) {
4730 for (NSUInteger i = 0; i < count; ++i) {
4732 [NSException raise:NSInvalidArgumentException
4733 format:@"Attempting to add nil object to a Dictionary"];
4735 [_dictionary setObject:objects[i] forKey:@(keys[i])];
4742 - (instancetype)initWithDictionary:(GPBInt32ObjectDictionary *)dictionary {
4743 self = [self initWithObjects:NULL forKeys:NULL count:0];
4746 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
4752 - (instancetype)initWithCapacity:(NSUInteger)numItems {
4753 #pragma unused(numItems)
4754 return [self initWithObjects:NULL forKeys:NULL count:0];
4758 NSAssert(!_autocreator,
4759 @"%@: Autocreator must be cleared before release, autocreator: %@",
4760 [self class], _autocreator);
4761 [_dictionary release];
4765 - (instancetype)copyWithZone:(NSZone *)zone {
4766 return [[GPBInt32ObjectDictionary allocWithZone:zone] initWithDictionary:self];
4769 - (BOOL)isEqual:(id)other {
4770 if (self == other) {
4773 if (![other isKindOfClass:[GPBInt32ObjectDictionary class]]) {
4776 GPBInt32ObjectDictionary *otherDictionary = other;
4777 return [_dictionary isEqual:otherDictionary->_dictionary];
4780 - (NSUInteger)hash {
4781 return _dictionary.count;
4784 - (NSString *)description {
4785 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
4788 - (NSUInteger)count {
4789 return _dictionary.count;
4792 - (void)enumerateKeysAndObjectsUsingBlock:
4793 (void (^)(int32_t key, id object, BOOL *stop))block {
4795 NSDictionary *internal = _dictionary;
4796 NSEnumerator *keys = [internal keyEnumerator];
4798 while ((aKey = [keys nextObject])) {
4799 id aObject = internal[aKey];
4800 block([aKey intValue], aObject, &stop);
4807 - (BOOL)isInitialized {
4808 for (GPBMessage *msg in [_dictionary objectEnumerator]) {
4809 if (!msg.initialized) {
4816 - (instancetype)deepCopyWithZone:(NSZone *)zone {
4817 GPBInt32ObjectDictionary *newDict =
4818 [[GPBInt32ObjectDictionary alloc] init];
4819 NSEnumerator *keys = [_dictionary keyEnumerator];
4821 NSMutableDictionary *internalDict = newDict->_dictionary;
4822 while ((aKey = [keys nextObject])) {
4823 GPBMessage *msg = _dictionary[aKey];
4824 GPBMessage *copiedMsg = [msg copyWithZone:zone];
4825 [internalDict setObject:copiedMsg forKey:aKey];
4826 [copiedMsg release];
4831 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
4832 NSDictionary *internal = _dictionary;
4833 NSUInteger count = internal.count;
4838 GPBDataType valueDataType = GPBGetFieldDataType(field);
4839 GPBDataType keyDataType = field.mapKeyDataType;
4841 NSEnumerator *keys = [internal keyEnumerator];
4843 while ((aKey = [keys nextObject])) {
4844 id aObject = internal[aKey];
4845 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
4846 msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
4847 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
4849 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
4850 result += tagSize * count;
4854 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
4855 asField:(GPBFieldDescriptor *)field {
4856 GPBDataType valueDataType = GPBGetFieldDataType(field);
4857 GPBDataType keyDataType = field.mapKeyDataType;
4858 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
4859 NSDictionary *internal = _dictionary;
4860 NSEnumerator *keys = [internal keyEnumerator];
4862 while ((aKey = [keys nextObject])) {
4863 id aObject = internal[aKey];
4864 [outputStream writeInt32NoTag:tag];
4865 // Write the size of the message.
4866 int32_t unwrappedKey = [aKey intValue];
4867 id unwrappedValue = aObject;
4868 size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
4869 msgSize += ComputeDictObjectFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
4870 [outputStream writeInt32NoTag:(int32_t)msgSize];
4871 // Write the fields.
4872 WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
4873 WriteDictObjectField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
4877 - (void)setGPBGenericValue:(GPBGenericValue *)value
4878 forGPBGenericValueKey:(GPBGenericValue *)key {
4879 [_dictionary setObject:value->valueString forKey:@(key->valueInt32)];
4882 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
4883 [self enumerateKeysAndObjectsUsingBlock:^(int32_t key, id object, BOOL *stop) {
4884 #pragma unused(stop)
4885 block([NSString stringWithFormat:@"%d", key], object);
4889 - (id)objectForKey:(int32_t)key {
4890 id result = [_dictionary objectForKey:@(key)];
4894 - (void)addEntriesFromDictionary:(GPBInt32ObjectDictionary *)otherDictionary {
4895 if (otherDictionary) {
4896 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
4898 GPBAutocreatedDictionaryModified(_autocreator, self);
4903 - (void)setObject:(id)object forKey:(int32_t)key {
4905 [NSException raise:NSInvalidArgumentException
4906 format:@"Attempting to add nil object to a Dictionary"];
4908 [_dictionary setObject:object forKey:@(key)];
4910 GPBAutocreatedDictionaryModified(_autocreator, self);
4914 - (void)removeObjectForKey:(int32_t)aKey {
4915 [_dictionary removeObjectForKey:@(aKey)];
4919 [_dictionary removeAllObjects];
4924 //%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(UInt64, uint64_t)
4925 // This block of code is generated, do not edit it directly.
4927 #pragma mark - UInt64 -> UInt32
4929 @implementation GPBUInt64UInt32Dictionary {
4931 NSMutableDictionary *_dictionary;
4934 - (instancetype)init {
4935 return [self initWithUInt32s:NULL forKeys:NULL count:0];
4938 - (instancetype)initWithUInt32s:(const uint32_t [])values
4939 forKeys:(const uint64_t [])keys
4940 count:(NSUInteger)count {
4941 self = [super init];
4943 _dictionary = [[NSMutableDictionary alloc] init];
4944 if (count && values && keys) {
4945 for (NSUInteger i = 0; i < count; ++i) {
4946 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
4953 - (instancetype)initWithDictionary:(GPBUInt64UInt32Dictionary *)dictionary {
4954 self = [self initWithUInt32s:NULL forKeys:NULL count:0];
4957 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
4963 - (instancetype)initWithCapacity:(NSUInteger)numItems {
4964 #pragma unused(numItems)
4965 return [self initWithUInt32s:NULL forKeys:NULL count:0];
4969 NSAssert(!_autocreator,
4970 @"%@: Autocreator must be cleared before release, autocreator: %@",
4971 [self class], _autocreator);
4972 [_dictionary release];
4976 - (instancetype)copyWithZone:(NSZone *)zone {
4977 return [[GPBUInt64UInt32Dictionary allocWithZone:zone] initWithDictionary:self];
4980 - (BOOL)isEqual:(id)other {
4981 if (self == other) {
4984 if (![other isKindOfClass:[GPBUInt64UInt32Dictionary class]]) {
4987 GPBUInt64UInt32Dictionary *otherDictionary = other;
4988 return [_dictionary isEqual:otherDictionary->_dictionary];
4991 - (NSUInteger)hash {
4992 return _dictionary.count;
4995 - (NSString *)description {
4996 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
4999 - (NSUInteger)count {
5000 return _dictionary.count;
5003 - (void)enumerateKeysAndUInt32sUsingBlock:
5004 (void (^)(uint64_t key, uint32_t value, BOOL *stop))block {
5006 NSDictionary *internal = _dictionary;
5007 NSEnumerator *keys = [internal keyEnumerator];
5009 while ((aKey = [keys nextObject])) {
5010 NSNumber *aValue = internal[aKey];
5011 block([aKey unsignedLongLongValue], [aValue unsignedIntValue], &stop);
5018 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
5019 NSDictionary *internal = _dictionary;
5020 NSUInteger count = internal.count;
5025 GPBDataType valueDataType = GPBGetFieldDataType(field);
5026 GPBDataType keyDataType = field.mapKeyDataType;
5028 NSEnumerator *keys = [internal keyEnumerator];
5030 while ((aKey = [keys nextObject])) {
5031 NSNumber *aValue = internal[aKey];
5032 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
5033 msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
5034 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
5036 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
5037 result += tagSize * count;
5041 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
5042 asField:(GPBFieldDescriptor *)field {
5043 GPBDataType valueDataType = GPBGetFieldDataType(field);
5044 GPBDataType keyDataType = field.mapKeyDataType;
5045 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
5046 NSDictionary *internal = _dictionary;
5047 NSEnumerator *keys = [internal keyEnumerator];
5049 while ((aKey = [keys nextObject])) {
5050 NSNumber *aValue = internal[aKey];
5051 [outputStream writeInt32NoTag:tag];
5052 // Write the size of the message.
5053 uint64_t unwrappedKey = [aKey unsignedLongLongValue];
5054 uint32_t unwrappedValue = [aValue unsignedIntValue];
5055 size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
5056 msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
5057 [outputStream writeInt32NoTag:(int32_t)msgSize];
5058 // Write the fields.
5059 WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
5060 WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
5064 - (void)setGPBGenericValue:(GPBGenericValue *)value
5065 forGPBGenericValueKey:(GPBGenericValue *)key {
5066 [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueUInt64)];
5069 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
5070 [self enumerateKeysAndUInt32sUsingBlock:^(uint64_t key, uint32_t value, BOOL *stop) {
5071 #pragma unused(stop)
5072 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%u", value]);
5076 - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(uint64_t)key {
5077 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
5078 if (wrapped && value) {
5079 *value = [wrapped unsignedIntValue];
5081 return (wrapped != NULL);
5084 - (void)addEntriesFromDictionary:(GPBUInt64UInt32Dictionary *)otherDictionary {
5085 if (otherDictionary) {
5086 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
5088 GPBAutocreatedDictionaryModified(_autocreator, self);
5093 - (void)setUInt32:(uint32_t)value forKey:(uint64_t)key {
5094 [_dictionary setObject:@(value) forKey:@(key)];
5096 GPBAutocreatedDictionaryModified(_autocreator, self);
5100 - (void)removeUInt32ForKey:(uint64_t)aKey {
5101 [_dictionary removeObjectForKey:@(aKey)];
5105 [_dictionary removeAllObjects];
5110 #pragma mark - UInt64 -> Int32
5112 @implementation GPBUInt64Int32Dictionary {
5114 NSMutableDictionary *_dictionary;
5117 - (instancetype)init {
5118 return [self initWithInt32s:NULL forKeys:NULL count:0];
5121 - (instancetype)initWithInt32s:(const int32_t [])values
5122 forKeys:(const uint64_t [])keys
5123 count:(NSUInteger)count {
5124 self = [super init];
5126 _dictionary = [[NSMutableDictionary alloc] init];
5127 if (count && values && keys) {
5128 for (NSUInteger i = 0; i < count; ++i) {
5129 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
5136 - (instancetype)initWithDictionary:(GPBUInt64Int32Dictionary *)dictionary {
5137 self = [self initWithInt32s:NULL forKeys:NULL count:0];
5140 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
5146 - (instancetype)initWithCapacity:(NSUInteger)numItems {
5147 #pragma unused(numItems)
5148 return [self initWithInt32s:NULL forKeys:NULL count:0];
5152 NSAssert(!_autocreator,
5153 @"%@: Autocreator must be cleared before release, autocreator: %@",
5154 [self class], _autocreator);
5155 [_dictionary release];
5159 - (instancetype)copyWithZone:(NSZone *)zone {
5160 return [[GPBUInt64Int32Dictionary allocWithZone:zone] initWithDictionary:self];
5163 - (BOOL)isEqual:(id)other {
5164 if (self == other) {
5167 if (![other isKindOfClass:[GPBUInt64Int32Dictionary class]]) {
5170 GPBUInt64Int32Dictionary *otherDictionary = other;
5171 return [_dictionary isEqual:otherDictionary->_dictionary];
5174 - (NSUInteger)hash {
5175 return _dictionary.count;
5178 - (NSString *)description {
5179 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
5182 - (NSUInteger)count {
5183 return _dictionary.count;
5186 - (void)enumerateKeysAndInt32sUsingBlock:
5187 (void (^)(uint64_t key, int32_t value, BOOL *stop))block {
5189 NSDictionary *internal = _dictionary;
5190 NSEnumerator *keys = [internal keyEnumerator];
5192 while ((aKey = [keys nextObject])) {
5193 NSNumber *aValue = internal[aKey];
5194 block([aKey unsignedLongLongValue], [aValue intValue], &stop);
5201 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
5202 NSDictionary *internal = _dictionary;
5203 NSUInteger count = internal.count;
5208 GPBDataType valueDataType = GPBGetFieldDataType(field);
5209 GPBDataType keyDataType = field.mapKeyDataType;
5211 NSEnumerator *keys = [internal keyEnumerator];
5213 while ((aKey = [keys nextObject])) {
5214 NSNumber *aValue = internal[aKey];
5215 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
5216 msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
5217 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
5219 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
5220 result += tagSize * count;
5224 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
5225 asField:(GPBFieldDescriptor *)field {
5226 GPBDataType valueDataType = GPBGetFieldDataType(field);
5227 GPBDataType keyDataType = field.mapKeyDataType;
5228 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
5229 NSDictionary *internal = _dictionary;
5230 NSEnumerator *keys = [internal keyEnumerator];
5232 while ((aKey = [keys nextObject])) {
5233 NSNumber *aValue = internal[aKey];
5234 [outputStream writeInt32NoTag:tag];
5235 // Write the size of the message.
5236 uint64_t unwrappedKey = [aKey unsignedLongLongValue];
5237 int32_t unwrappedValue = [aValue intValue];
5238 size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
5239 msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
5240 [outputStream writeInt32NoTag:(int32_t)msgSize];
5241 // Write the fields.
5242 WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
5243 WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
5247 - (void)setGPBGenericValue:(GPBGenericValue *)value
5248 forGPBGenericValueKey:(GPBGenericValue *)key {
5249 [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueUInt64)];
5252 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
5253 [self enumerateKeysAndInt32sUsingBlock:^(uint64_t key, int32_t value, BOOL *stop) {
5254 #pragma unused(stop)
5255 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%d", value]);
5259 - (BOOL)getInt32:(nullable int32_t *)value forKey:(uint64_t)key {
5260 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
5261 if (wrapped && value) {
5262 *value = [wrapped intValue];
5264 return (wrapped != NULL);
5267 - (void)addEntriesFromDictionary:(GPBUInt64Int32Dictionary *)otherDictionary {
5268 if (otherDictionary) {
5269 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
5271 GPBAutocreatedDictionaryModified(_autocreator, self);
5276 - (void)setInt32:(int32_t)value forKey:(uint64_t)key {
5277 [_dictionary setObject:@(value) forKey:@(key)];
5279 GPBAutocreatedDictionaryModified(_autocreator, self);
5283 - (void)removeInt32ForKey:(uint64_t)aKey {
5284 [_dictionary removeObjectForKey:@(aKey)];
5288 [_dictionary removeAllObjects];
5293 #pragma mark - UInt64 -> UInt64
5295 @implementation GPBUInt64UInt64Dictionary {
5297 NSMutableDictionary *_dictionary;
5300 - (instancetype)init {
5301 return [self initWithUInt64s:NULL forKeys:NULL count:0];
5304 - (instancetype)initWithUInt64s:(const uint64_t [])values
5305 forKeys:(const uint64_t [])keys
5306 count:(NSUInteger)count {
5307 self = [super init];
5309 _dictionary = [[NSMutableDictionary alloc] init];
5310 if (count && values && keys) {
5311 for (NSUInteger i = 0; i < count; ++i) {
5312 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
5319 - (instancetype)initWithDictionary:(GPBUInt64UInt64Dictionary *)dictionary {
5320 self = [self initWithUInt64s:NULL forKeys:NULL count:0];
5323 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
5329 - (instancetype)initWithCapacity:(NSUInteger)numItems {
5330 #pragma unused(numItems)
5331 return [self initWithUInt64s:NULL forKeys:NULL count:0];
5335 NSAssert(!_autocreator,
5336 @"%@: Autocreator must be cleared before release, autocreator: %@",
5337 [self class], _autocreator);
5338 [_dictionary release];
5342 - (instancetype)copyWithZone:(NSZone *)zone {
5343 return [[GPBUInt64UInt64Dictionary allocWithZone:zone] initWithDictionary:self];
5346 - (BOOL)isEqual:(id)other {
5347 if (self == other) {
5350 if (![other isKindOfClass:[GPBUInt64UInt64Dictionary class]]) {
5353 GPBUInt64UInt64Dictionary *otherDictionary = other;
5354 return [_dictionary isEqual:otherDictionary->_dictionary];
5357 - (NSUInteger)hash {
5358 return _dictionary.count;
5361 - (NSString *)description {
5362 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
5365 - (NSUInteger)count {
5366 return _dictionary.count;
5369 - (void)enumerateKeysAndUInt64sUsingBlock:
5370 (void (^)(uint64_t key, uint64_t value, BOOL *stop))block {
5372 NSDictionary *internal = _dictionary;
5373 NSEnumerator *keys = [internal keyEnumerator];
5375 while ((aKey = [keys nextObject])) {
5376 NSNumber *aValue = internal[aKey];
5377 block([aKey unsignedLongLongValue], [aValue unsignedLongLongValue], &stop);
5384 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
5385 NSDictionary *internal = _dictionary;
5386 NSUInteger count = internal.count;
5391 GPBDataType valueDataType = GPBGetFieldDataType(field);
5392 GPBDataType keyDataType = field.mapKeyDataType;
5394 NSEnumerator *keys = [internal keyEnumerator];
5396 while ((aKey = [keys nextObject])) {
5397 NSNumber *aValue = internal[aKey];
5398 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
5399 msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
5400 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
5402 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
5403 result += tagSize * count;
5407 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
5408 asField:(GPBFieldDescriptor *)field {
5409 GPBDataType valueDataType = GPBGetFieldDataType(field);
5410 GPBDataType keyDataType = field.mapKeyDataType;
5411 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
5412 NSDictionary *internal = _dictionary;
5413 NSEnumerator *keys = [internal keyEnumerator];
5415 while ((aKey = [keys nextObject])) {
5416 NSNumber *aValue = internal[aKey];
5417 [outputStream writeInt32NoTag:tag];
5418 // Write the size of the message.
5419 uint64_t unwrappedKey = [aKey unsignedLongLongValue];
5420 uint64_t unwrappedValue = [aValue unsignedLongLongValue];
5421 size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
5422 msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
5423 [outputStream writeInt32NoTag:(int32_t)msgSize];
5424 // Write the fields.
5425 WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
5426 WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
5430 - (void)setGPBGenericValue:(GPBGenericValue *)value
5431 forGPBGenericValueKey:(GPBGenericValue *)key {
5432 [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueUInt64)];
5435 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
5436 [self enumerateKeysAndUInt64sUsingBlock:^(uint64_t key, uint64_t value, BOOL *stop) {
5437 #pragma unused(stop)
5438 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%llu", value]);
5442 - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(uint64_t)key {
5443 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
5444 if (wrapped && value) {
5445 *value = [wrapped unsignedLongLongValue];
5447 return (wrapped != NULL);
5450 - (void)addEntriesFromDictionary:(GPBUInt64UInt64Dictionary *)otherDictionary {
5451 if (otherDictionary) {
5452 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
5454 GPBAutocreatedDictionaryModified(_autocreator, self);
5459 - (void)setUInt64:(uint64_t)value forKey:(uint64_t)key {
5460 [_dictionary setObject:@(value) forKey:@(key)];
5462 GPBAutocreatedDictionaryModified(_autocreator, self);
5466 - (void)removeUInt64ForKey:(uint64_t)aKey {
5467 [_dictionary removeObjectForKey:@(aKey)];
5471 [_dictionary removeAllObjects];
5476 #pragma mark - UInt64 -> Int64
5478 @implementation GPBUInt64Int64Dictionary {
5480 NSMutableDictionary *_dictionary;
5483 - (instancetype)init {
5484 return [self initWithInt64s:NULL forKeys:NULL count:0];
5487 - (instancetype)initWithInt64s:(const int64_t [])values
5488 forKeys:(const uint64_t [])keys
5489 count:(NSUInteger)count {
5490 self = [super init];
5492 _dictionary = [[NSMutableDictionary alloc] init];
5493 if (count && values && keys) {
5494 for (NSUInteger i = 0; i < count; ++i) {
5495 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
5502 - (instancetype)initWithDictionary:(GPBUInt64Int64Dictionary *)dictionary {
5503 self = [self initWithInt64s:NULL forKeys:NULL count:0];
5506 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
5512 - (instancetype)initWithCapacity:(NSUInteger)numItems {
5513 #pragma unused(numItems)
5514 return [self initWithInt64s:NULL forKeys:NULL count:0];
5518 NSAssert(!_autocreator,
5519 @"%@: Autocreator must be cleared before release, autocreator: %@",
5520 [self class], _autocreator);
5521 [_dictionary release];
5525 - (instancetype)copyWithZone:(NSZone *)zone {
5526 return [[GPBUInt64Int64Dictionary allocWithZone:zone] initWithDictionary:self];
5529 - (BOOL)isEqual:(id)other {
5530 if (self == other) {
5533 if (![other isKindOfClass:[GPBUInt64Int64Dictionary class]]) {
5536 GPBUInt64Int64Dictionary *otherDictionary = other;
5537 return [_dictionary isEqual:otherDictionary->_dictionary];
5540 - (NSUInteger)hash {
5541 return _dictionary.count;
5544 - (NSString *)description {
5545 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
5548 - (NSUInteger)count {
5549 return _dictionary.count;
5552 - (void)enumerateKeysAndInt64sUsingBlock:
5553 (void (^)(uint64_t key, int64_t value, BOOL *stop))block {
5555 NSDictionary *internal = _dictionary;
5556 NSEnumerator *keys = [internal keyEnumerator];
5558 while ((aKey = [keys nextObject])) {
5559 NSNumber *aValue = internal[aKey];
5560 block([aKey unsignedLongLongValue], [aValue longLongValue], &stop);
5567 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
5568 NSDictionary *internal = _dictionary;
5569 NSUInteger count = internal.count;
5574 GPBDataType valueDataType = GPBGetFieldDataType(field);
5575 GPBDataType keyDataType = field.mapKeyDataType;
5577 NSEnumerator *keys = [internal keyEnumerator];
5579 while ((aKey = [keys nextObject])) {
5580 NSNumber *aValue = internal[aKey];
5581 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
5582 msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
5583 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
5585 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
5586 result += tagSize * count;
5590 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
5591 asField:(GPBFieldDescriptor *)field {
5592 GPBDataType valueDataType = GPBGetFieldDataType(field);
5593 GPBDataType keyDataType = field.mapKeyDataType;
5594 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
5595 NSDictionary *internal = _dictionary;
5596 NSEnumerator *keys = [internal keyEnumerator];
5598 while ((aKey = [keys nextObject])) {
5599 NSNumber *aValue = internal[aKey];
5600 [outputStream writeInt32NoTag:tag];
5601 // Write the size of the message.
5602 uint64_t unwrappedKey = [aKey unsignedLongLongValue];
5603 int64_t unwrappedValue = [aValue longLongValue];
5604 size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
5605 msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
5606 [outputStream writeInt32NoTag:(int32_t)msgSize];
5607 // Write the fields.
5608 WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
5609 WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
5613 - (void)setGPBGenericValue:(GPBGenericValue *)value
5614 forGPBGenericValueKey:(GPBGenericValue *)key {
5615 [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueUInt64)];
5618 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
5619 [self enumerateKeysAndInt64sUsingBlock:^(uint64_t key, int64_t value, BOOL *stop) {
5620 #pragma unused(stop)
5621 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%lld", value]);
5625 - (BOOL)getInt64:(nullable int64_t *)value forKey:(uint64_t)key {
5626 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
5627 if (wrapped && value) {
5628 *value = [wrapped longLongValue];
5630 return (wrapped != NULL);
5633 - (void)addEntriesFromDictionary:(GPBUInt64Int64Dictionary *)otherDictionary {
5634 if (otherDictionary) {
5635 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
5637 GPBAutocreatedDictionaryModified(_autocreator, self);
5642 - (void)setInt64:(int64_t)value forKey:(uint64_t)key {
5643 [_dictionary setObject:@(value) forKey:@(key)];
5645 GPBAutocreatedDictionaryModified(_autocreator, self);
5649 - (void)removeInt64ForKey:(uint64_t)aKey {
5650 [_dictionary removeObjectForKey:@(aKey)];
5654 [_dictionary removeAllObjects];
5659 #pragma mark - UInt64 -> Bool
5661 @implementation GPBUInt64BoolDictionary {
5663 NSMutableDictionary *_dictionary;
5666 - (instancetype)init {
5667 return [self initWithBools:NULL forKeys:NULL count:0];
5670 - (instancetype)initWithBools:(const BOOL [])values
5671 forKeys:(const uint64_t [])keys
5672 count:(NSUInteger)count {
5673 self = [super init];
5675 _dictionary = [[NSMutableDictionary alloc] init];
5676 if (count && values && keys) {
5677 for (NSUInteger i = 0; i < count; ++i) {
5678 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
5685 - (instancetype)initWithDictionary:(GPBUInt64BoolDictionary *)dictionary {
5686 self = [self initWithBools:NULL forKeys:NULL count:0];
5689 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
5695 - (instancetype)initWithCapacity:(NSUInteger)numItems {
5696 #pragma unused(numItems)
5697 return [self initWithBools:NULL forKeys:NULL count:0];
5701 NSAssert(!_autocreator,
5702 @"%@: Autocreator must be cleared before release, autocreator: %@",
5703 [self class], _autocreator);
5704 [_dictionary release];
5708 - (instancetype)copyWithZone:(NSZone *)zone {
5709 return [[GPBUInt64BoolDictionary allocWithZone:zone] initWithDictionary:self];
5712 - (BOOL)isEqual:(id)other {
5713 if (self == other) {
5716 if (![other isKindOfClass:[GPBUInt64BoolDictionary class]]) {
5719 GPBUInt64BoolDictionary *otherDictionary = other;
5720 return [_dictionary isEqual:otherDictionary->_dictionary];
5723 - (NSUInteger)hash {
5724 return _dictionary.count;
5727 - (NSString *)description {
5728 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
5731 - (NSUInteger)count {
5732 return _dictionary.count;
5735 - (void)enumerateKeysAndBoolsUsingBlock:
5736 (void (^)(uint64_t key, BOOL value, BOOL *stop))block {
5738 NSDictionary *internal = _dictionary;
5739 NSEnumerator *keys = [internal keyEnumerator];
5741 while ((aKey = [keys nextObject])) {
5742 NSNumber *aValue = internal[aKey];
5743 block([aKey unsignedLongLongValue], [aValue boolValue], &stop);
5750 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
5751 NSDictionary *internal = _dictionary;
5752 NSUInteger count = internal.count;
5757 GPBDataType valueDataType = GPBGetFieldDataType(field);
5758 GPBDataType keyDataType = field.mapKeyDataType;
5760 NSEnumerator *keys = [internal keyEnumerator];
5762 while ((aKey = [keys nextObject])) {
5763 NSNumber *aValue = internal[aKey];
5764 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
5765 msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
5766 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
5768 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
5769 result += tagSize * count;
5773 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
5774 asField:(GPBFieldDescriptor *)field {
5775 GPBDataType valueDataType = GPBGetFieldDataType(field);
5776 GPBDataType keyDataType = field.mapKeyDataType;
5777 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
5778 NSDictionary *internal = _dictionary;
5779 NSEnumerator *keys = [internal keyEnumerator];
5781 while ((aKey = [keys nextObject])) {
5782 NSNumber *aValue = internal[aKey];
5783 [outputStream writeInt32NoTag:tag];
5784 // Write the size of the message.
5785 uint64_t unwrappedKey = [aKey unsignedLongLongValue];
5786 BOOL unwrappedValue = [aValue boolValue];
5787 size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
5788 msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
5789 [outputStream writeInt32NoTag:(int32_t)msgSize];
5790 // Write the fields.
5791 WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
5792 WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
5796 - (void)setGPBGenericValue:(GPBGenericValue *)value
5797 forGPBGenericValueKey:(GPBGenericValue *)key {
5798 [_dictionary setObject:@(value->valueBool) forKey:@(key->valueUInt64)];
5801 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
5802 [self enumerateKeysAndBoolsUsingBlock:^(uint64_t key, BOOL value, BOOL *stop) {
5803 #pragma unused(stop)
5804 block([NSString stringWithFormat:@"%llu", key], (value ? @"true" : @"false"));
5808 - (BOOL)getBool:(nullable BOOL *)value forKey:(uint64_t)key {
5809 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
5810 if (wrapped && value) {
5811 *value = [wrapped boolValue];
5813 return (wrapped != NULL);
5816 - (void)addEntriesFromDictionary:(GPBUInt64BoolDictionary *)otherDictionary {
5817 if (otherDictionary) {
5818 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
5820 GPBAutocreatedDictionaryModified(_autocreator, self);
5825 - (void)setBool:(BOOL)value forKey:(uint64_t)key {
5826 [_dictionary setObject:@(value) forKey:@(key)];
5828 GPBAutocreatedDictionaryModified(_autocreator, self);
5832 - (void)removeBoolForKey:(uint64_t)aKey {
5833 [_dictionary removeObjectForKey:@(aKey)];
5837 [_dictionary removeAllObjects];
5842 #pragma mark - UInt64 -> Float
5844 @implementation GPBUInt64FloatDictionary {
5846 NSMutableDictionary *_dictionary;
5849 - (instancetype)init {
5850 return [self initWithFloats:NULL forKeys:NULL count:0];
5853 - (instancetype)initWithFloats:(const float [])values
5854 forKeys:(const uint64_t [])keys
5855 count:(NSUInteger)count {
5856 self = [super init];
5858 _dictionary = [[NSMutableDictionary alloc] init];
5859 if (count && values && keys) {
5860 for (NSUInteger i = 0; i < count; ++i) {
5861 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
5868 - (instancetype)initWithDictionary:(GPBUInt64FloatDictionary *)dictionary {
5869 self = [self initWithFloats:NULL forKeys:NULL count:0];
5872 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
5878 - (instancetype)initWithCapacity:(NSUInteger)numItems {
5879 #pragma unused(numItems)
5880 return [self initWithFloats:NULL forKeys:NULL count:0];
5884 NSAssert(!_autocreator,
5885 @"%@: Autocreator must be cleared before release, autocreator: %@",
5886 [self class], _autocreator);
5887 [_dictionary release];
5891 - (instancetype)copyWithZone:(NSZone *)zone {
5892 return [[GPBUInt64FloatDictionary allocWithZone:zone] initWithDictionary:self];
5895 - (BOOL)isEqual:(id)other {
5896 if (self == other) {
5899 if (![other isKindOfClass:[GPBUInt64FloatDictionary class]]) {
5902 GPBUInt64FloatDictionary *otherDictionary = other;
5903 return [_dictionary isEqual:otherDictionary->_dictionary];
5906 - (NSUInteger)hash {
5907 return _dictionary.count;
5910 - (NSString *)description {
5911 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
5914 - (NSUInteger)count {
5915 return _dictionary.count;
5918 - (void)enumerateKeysAndFloatsUsingBlock:
5919 (void (^)(uint64_t key, float value, BOOL *stop))block {
5921 NSDictionary *internal = _dictionary;
5922 NSEnumerator *keys = [internal keyEnumerator];
5924 while ((aKey = [keys nextObject])) {
5925 NSNumber *aValue = internal[aKey];
5926 block([aKey unsignedLongLongValue], [aValue floatValue], &stop);
5933 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
5934 NSDictionary *internal = _dictionary;
5935 NSUInteger count = internal.count;
5940 GPBDataType valueDataType = GPBGetFieldDataType(field);
5941 GPBDataType keyDataType = field.mapKeyDataType;
5943 NSEnumerator *keys = [internal keyEnumerator];
5945 while ((aKey = [keys nextObject])) {
5946 NSNumber *aValue = internal[aKey];
5947 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
5948 msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
5949 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
5951 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
5952 result += tagSize * count;
5956 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
5957 asField:(GPBFieldDescriptor *)field {
5958 GPBDataType valueDataType = GPBGetFieldDataType(field);
5959 GPBDataType keyDataType = field.mapKeyDataType;
5960 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
5961 NSDictionary *internal = _dictionary;
5962 NSEnumerator *keys = [internal keyEnumerator];
5964 while ((aKey = [keys nextObject])) {
5965 NSNumber *aValue = internal[aKey];
5966 [outputStream writeInt32NoTag:tag];
5967 // Write the size of the message.
5968 uint64_t unwrappedKey = [aKey unsignedLongLongValue];
5969 float unwrappedValue = [aValue floatValue];
5970 size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
5971 msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
5972 [outputStream writeInt32NoTag:(int32_t)msgSize];
5973 // Write the fields.
5974 WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
5975 WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
5979 - (void)setGPBGenericValue:(GPBGenericValue *)value
5980 forGPBGenericValueKey:(GPBGenericValue *)key {
5981 [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueUInt64)];
5984 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
5985 [self enumerateKeysAndFloatsUsingBlock:^(uint64_t key, float value, BOOL *stop) {
5986 #pragma unused(stop)
5987 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
5991 - (BOOL)getFloat:(nullable float *)value forKey:(uint64_t)key {
5992 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
5993 if (wrapped && value) {
5994 *value = [wrapped floatValue];
5996 return (wrapped != NULL);
5999 - (void)addEntriesFromDictionary:(GPBUInt64FloatDictionary *)otherDictionary {
6000 if (otherDictionary) {
6001 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
6003 GPBAutocreatedDictionaryModified(_autocreator, self);
6008 - (void)setFloat:(float)value forKey:(uint64_t)key {
6009 [_dictionary setObject:@(value) forKey:@(key)];
6011 GPBAutocreatedDictionaryModified(_autocreator, self);
6015 - (void)removeFloatForKey:(uint64_t)aKey {
6016 [_dictionary removeObjectForKey:@(aKey)];
6020 [_dictionary removeAllObjects];
6025 #pragma mark - UInt64 -> Double
6027 @implementation GPBUInt64DoubleDictionary {
6029 NSMutableDictionary *_dictionary;
6032 - (instancetype)init {
6033 return [self initWithDoubles:NULL forKeys:NULL count:0];
6036 - (instancetype)initWithDoubles:(const double [])values
6037 forKeys:(const uint64_t [])keys
6038 count:(NSUInteger)count {
6039 self = [super init];
6041 _dictionary = [[NSMutableDictionary alloc] init];
6042 if (count && values && keys) {
6043 for (NSUInteger i = 0; i < count; ++i) {
6044 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
6051 - (instancetype)initWithDictionary:(GPBUInt64DoubleDictionary *)dictionary {
6052 self = [self initWithDoubles:NULL forKeys:NULL count:0];
6055 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
6061 - (instancetype)initWithCapacity:(NSUInteger)numItems {
6062 #pragma unused(numItems)
6063 return [self initWithDoubles:NULL forKeys:NULL count:0];
6067 NSAssert(!_autocreator,
6068 @"%@: Autocreator must be cleared before release, autocreator: %@",
6069 [self class], _autocreator);
6070 [_dictionary release];
6074 - (instancetype)copyWithZone:(NSZone *)zone {
6075 return [[GPBUInt64DoubleDictionary allocWithZone:zone] initWithDictionary:self];
6078 - (BOOL)isEqual:(id)other {
6079 if (self == other) {
6082 if (![other isKindOfClass:[GPBUInt64DoubleDictionary class]]) {
6085 GPBUInt64DoubleDictionary *otherDictionary = other;
6086 return [_dictionary isEqual:otherDictionary->_dictionary];
6089 - (NSUInteger)hash {
6090 return _dictionary.count;
6093 - (NSString *)description {
6094 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
6097 - (NSUInteger)count {
6098 return _dictionary.count;
6101 - (void)enumerateKeysAndDoublesUsingBlock:
6102 (void (^)(uint64_t key, double value, BOOL *stop))block {
6104 NSDictionary *internal = _dictionary;
6105 NSEnumerator *keys = [internal keyEnumerator];
6107 while ((aKey = [keys nextObject])) {
6108 NSNumber *aValue = internal[aKey];
6109 block([aKey unsignedLongLongValue], [aValue doubleValue], &stop);
6116 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
6117 NSDictionary *internal = _dictionary;
6118 NSUInteger count = internal.count;
6123 GPBDataType valueDataType = GPBGetFieldDataType(field);
6124 GPBDataType keyDataType = field.mapKeyDataType;
6126 NSEnumerator *keys = [internal keyEnumerator];
6128 while ((aKey = [keys nextObject])) {
6129 NSNumber *aValue = internal[aKey];
6130 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
6131 msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
6132 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
6134 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
6135 result += tagSize * count;
6139 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
6140 asField:(GPBFieldDescriptor *)field {
6141 GPBDataType valueDataType = GPBGetFieldDataType(field);
6142 GPBDataType keyDataType = field.mapKeyDataType;
6143 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
6144 NSDictionary *internal = _dictionary;
6145 NSEnumerator *keys = [internal keyEnumerator];
6147 while ((aKey = [keys nextObject])) {
6148 NSNumber *aValue = internal[aKey];
6149 [outputStream writeInt32NoTag:tag];
6150 // Write the size of the message.
6151 uint64_t unwrappedKey = [aKey unsignedLongLongValue];
6152 double unwrappedValue = [aValue doubleValue];
6153 size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
6154 msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
6155 [outputStream writeInt32NoTag:(int32_t)msgSize];
6156 // Write the fields.
6157 WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
6158 WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
6162 - (void)setGPBGenericValue:(GPBGenericValue *)value
6163 forGPBGenericValueKey:(GPBGenericValue *)key {
6164 [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueUInt64)];
6167 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
6168 [self enumerateKeysAndDoublesUsingBlock:^(uint64_t key, double value, BOOL *stop) {
6169 #pragma unused(stop)
6170 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
6174 - (BOOL)getDouble:(nullable double *)value forKey:(uint64_t)key {
6175 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
6176 if (wrapped && value) {
6177 *value = [wrapped doubleValue];
6179 return (wrapped != NULL);
6182 - (void)addEntriesFromDictionary:(GPBUInt64DoubleDictionary *)otherDictionary {
6183 if (otherDictionary) {
6184 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
6186 GPBAutocreatedDictionaryModified(_autocreator, self);
6191 - (void)setDouble:(double)value forKey:(uint64_t)key {
6192 [_dictionary setObject:@(value) forKey:@(key)];
6194 GPBAutocreatedDictionaryModified(_autocreator, self);
6198 - (void)removeDoubleForKey:(uint64_t)aKey {
6199 [_dictionary removeObjectForKey:@(aKey)];
6203 [_dictionary removeAllObjects];
6208 #pragma mark - UInt64 -> Enum
6210 @implementation GPBUInt64EnumDictionary {
6212 NSMutableDictionary *_dictionary;
6213 GPBEnumValidationFunc _validationFunc;
6216 @synthesize validationFunc = _validationFunc;
6218 - (instancetype)init {
6219 return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
6222 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
6223 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
6226 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
6227 rawValues:(const int32_t [])rawValues
6228 forKeys:(const uint64_t [])keys
6229 count:(NSUInteger)count {
6230 self = [super init];
6232 _dictionary = [[NSMutableDictionary alloc] init];
6233 _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
6234 if (count && rawValues && keys) {
6235 for (NSUInteger i = 0; i < count; ++i) {
6236 [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])];
6243 - (instancetype)initWithDictionary:(GPBUInt64EnumDictionary *)dictionary {
6244 self = [self initWithValidationFunction:dictionary.validationFunc
6250 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
6256 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
6257 capacity:(NSUInteger)numItems {
6258 #pragma unused(numItems)
6259 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
6263 NSAssert(!_autocreator,
6264 @"%@: Autocreator must be cleared before release, autocreator: %@",
6265 [self class], _autocreator);
6266 [_dictionary release];
6270 - (instancetype)copyWithZone:(NSZone *)zone {
6271 return [[GPBUInt64EnumDictionary allocWithZone:zone] initWithDictionary:self];
6274 - (BOOL)isEqual:(id)other {
6275 if (self == other) {
6278 if (![other isKindOfClass:[GPBUInt64EnumDictionary class]]) {
6281 GPBUInt64EnumDictionary *otherDictionary = other;
6282 return [_dictionary isEqual:otherDictionary->_dictionary];
6285 - (NSUInteger)hash {
6286 return _dictionary.count;
6289 - (NSString *)description {
6290 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
6293 - (NSUInteger)count {
6294 return _dictionary.count;
6297 - (void)enumerateKeysAndRawValuesUsingBlock:
6298 (void (^)(uint64_t key, int32_t value, BOOL *stop))block {
6300 NSDictionary *internal = _dictionary;
6301 NSEnumerator *keys = [internal keyEnumerator];
6303 while ((aKey = [keys nextObject])) {
6304 NSNumber *aValue = internal[aKey];
6305 block([aKey unsignedLongLongValue], [aValue intValue], &stop);
6312 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
6313 NSDictionary *internal = _dictionary;
6314 NSUInteger count = internal.count;
6319 GPBDataType valueDataType = GPBGetFieldDataType(field);
6320 GPBDataType keyDataType = field.mapKeyDataType;
6322 NSEnumerator *keys = [internal keyEnumerator];
6324 while ((aKey = [keys nextObject])) {
6325 NSNumber *aValue = internal[aKey];
6326 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
6327 msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
6328 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
6330 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
6331 result += tagSize * count;
6335 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
6336 asField:(GPBFieldDescriptor *)field {
6337 GPBDataType valueDataType = GPBGetFieldDataType(field);
6338 GPBDataType keyDataType = field.mapKeyDataType;
6339 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
6340 NSDictionary *internal = _dictionary;
6341 NSEnumerator *keys = [internal keyEnumerator];
6343 while ((aKey = [keys nextObject])) {
6344 NSNumber *aValue = internal[aKey];
6345 [outputStream writeInt32NoTag:tag];
6346 // Write the size of the message.
6347 uint64_t unwrappedKey = [aKey unsignedLongLongValue];
6348 int32_t unwrappedValue = [aValue intValue];
6349 size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
6350 msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
6351 [outputStream writeInt32NoTag:(int32_t)msgSize];
6352 // Write the fields.
6353 WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
6354 WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
6358 - (NSData *)serializedDataForUnknownValue:(int32_t)value
6359 forKey:(GPBGenericValue *)key
6360 keyDataType:(GPBDataType)keyDataType {
6361 size_t msgSize = ComputeDictUInt64FieldSize(key->valueUInt64, kMapKeyFieldNumber, keyDataType);
6362 msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
6363 NSMutableData *data = [NSMutableData dataWithLength:msgSize];
6364 GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
6365 WriteDictUInt64Field(outputStream, key->valueUInt64, kMapKeyFieldNumber, keyDataType);
6366 WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
6367 [outputStream release];
6370 - (void)setGPBGenericValue:(GPBGenericValue *)value
6371 forGPBGenericValueKey:(GPBGenericValue *)key {
6372 [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueUInt64)];
6375 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
6376 [self enumerateKeysAndRawValuesUsingBlock:^(uint64_t key, int32_t value, BOOL *stop) {
6377 #pragma unused(stop)
6378 block([NSString stringWithFormat:@"%llu", key], @(value));
6382 - (BOOL)getEnum:(int32_t *)value forKey:(uint64_t)key {
6383 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
6384 if (wrapped && value) {
6385 int32_t result = [wrapped intValue];
6386 if (!_validationFunc(result)) {
6387 result = kGPBUnrecognizedEnumeratorValue;
6391 return (wrapped != NULL);
6394 - (BOOL)getRawValue:(int32_t *)rawValue forKey:(uint64_t)key {
6395 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
6396 if (wrapped && rawValue) {
6397 *rawValue = [wrapped intValue];
6399 return (wrapped != NULL);
6402 - (void)enumerateKeysAndEnumsUsingBlock:
6403 (void (^)(uint64_t key, int32_t value, BOOL *stop))block {
6404 GPBEnumValidationFunc func = _validationFunc;
6406 NSEnumerator *keys = [_dictionary keyEnumerator];
6408 while ((aKey = [keys nextObject])) {
6409 NSNumber *aValue = _dictionary[aKey];
6410 int32_t unwrapped = [aValue intValue];
6411 if (!func(unwrapped)) {
6412 unwrapped = kGPBUnrecognizedEnumeratorValue;
6414 block([aKey unsignedLongLongValue], unwrapped, &stop);
6421 - (void)addRawEntriesFromDictionary:(GPBUInt64EnumDictionary *)otherDictionary {
6422 if (otherDictionary) {
6423 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
6425 GPBAutocreatedDictionaryModified(_autocreator, self);
6430 - (void)setRawValue:(int32_t)value forKey:(uint64_t)key {
6431 [_dictionary setObject:@(value) forKey:@(key)];
6433 GPBAutocreatedDictionaryModified(_autocreator, self);
6437 - (void)removeEnumForKey:(uint64_t)aKey {
6438 [_dictionary removeObjectForKey:@(aKey)];
6442 [_dictionary removeAllObjects];
6445 - (void)setEnum:(int32_t)value forKey:(uint64_t)key {
6446 if (!_validationFunc(value)) {
6447 [NSException raise:NSInvalidArgumentException
6448 format:@"GPBUInt64EnumDictionary: Attempt to set an unknown enum value (%d)",
6452 [_dictionary setObject:@(value) forKey:@(key)];
6454 GPBAutocreatedDictionaryModified(_autocreator, self);
6460 #pragma mark - UInt64 -> Object
6462 @implementation GPBUInt64ObjectDictionary {
6464 NSMutableDictionary *_dictionary;
6467 - (instancetype)init {
6468 return [self initWithObjects:NULL forKeys:NULL count:0];
6471 - (instancetype)initWithObjects:(const id [])objects
6472 forKeys:(const uint64_t [])keys
6473 count:(NSUInteger)count {
6474 self = [super init];
6476 _dictionary = [[NSMutableDictionary alloc] init];
6477 if (count && objects && keys) {
6478 for (NSUInteger i = 0; i < count; ++i) {
6480 [NSException raise:NSInvalidArgumentException
6481 format:@"Attempting to add nil object to a Dictionary"];
6483 [_dictionary setObject:objects[i] forKey:@(keys[i])];
6490 - (instancetype)initWithDictionary:(GPBUInt64ObjectDictionary *)dictionary {
6491 self = [self initWithObjects:NULL forKeys:NULL count:0];
6494 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
6500 - (instancetype)initWithCapacity:(NSUInteger)numItems {
6501 #pragma unused(numItems)
6502 return [self initWithObjects:NULL forKeys:NULL count:0];
6506 NSAssert(!_autocreator,
6507 @"%@: Autocreator must be cleared before release, autocreator: %@",
6508 [self class], _autocreator);
6509 [_dictionary release];
6513 - (instancetype)copyWithZone:(NSZone *)zone {
6514 return [[GPBUInt64ObjectDictionary allocWithZone:zone] initWithDictionary:self];
6517 - (BOOL)isEqual:(id)other {
6518 if (self == other) {
6521 if (![other isKindOfClass:[GPBUInt64ObjectDictionary class]]) {
6524 GPBUInt64ObjectDictionary *otherDictionary = other;
6525 return [_dictionary isEqual:otherDictionary->_dictionary];
6528 - (NSUInteger)hash {
6529 return _dictionary.count;
6532 - (NSString *)description {
6533 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
6536 - (NSUInteger)count {
6537 return _dictionary.count;
6540 - (void)enumerateKeysAndObjectsUsingBlock:
6541 (void (^)(uint64_t key, id object, BOOL *stop))block {
6543 NSDictionary *internal = _dictionary;
6544 NSEnumerator *keys = [internal keyEnumerator];
6546 while ((aKey = [keys nextObject])) {
6547 id aObject = internal[aKey];
6548 block([aKey unsignedLongLongValue], aObject, &stop);
6555 - (BOOL)isInitialized {
6556 for (GPBMessage *msg in [_dictionary objectEnumerator]) {
6557 if (!msg.initialized) {
6564 - (instancetype)deepCopyWithZone:(NSZone *)zone {
6565 GPBUInt64ObjectDictionary *newDict =
6566 [[GPBUInt64ObjectDictionary alloc] init];
6567 NSEnumerator *keys = [_dictionary keyEnumerator];
6569 NSMutableDictionary *internalDict = newDict->_dictionary;
6570 while ((aKey = [keys nextObject])) {
6571 GPBMessage *msg = _dictionary[aKey];
6572 GPBMessage *copiedMsg = [msg copyWithZone:zone];
6573 [internalDict setObject:copiedMsg forKey:aKey];
6574 [copiedMsg release];
6579 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
6580 NSDictionary *internal = _dictionary;
6581 NSUInteger count = internal.count;
6586 GPBDataType valueDataType = GPBGetFieldDataType(field);
6587 GPBDataType keyDataType = field.mapKeyDataType;
6589 NSEnumerator *keys = [internal keyEnumerator];
6591 while ((aKey = [keys nextObject])) {
6592 id aObject = internal[aKey];
6593 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
6594 msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
6595 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
6597 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
6598 result += tagSize * count;
6602 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
6603 asField:(GPBFieldDescriptor *)field {
6604 GPBDataType valueDataType = GPBGetFieldDataType(field);
6605 GPBDataType keyDataType = field.mapKeyDataType;
6606 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
6607 NSDictionary *internal = _dictionary;
6608 NSEnumerator *keys = [internal keyEnumerator];
6610 while ((aKey = [keys nextObject])) {
6611 id aObject = internal[aKey];
6612 [outputStream writeInt32NoTag:tag];
6613 // Write the size of the message.
6614 uint64_t unwrappedKey = [aKey unsignedLongLongValue];
6615 id unwrappedValue = aObject;
6616 size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
6617 msgSize += ComputeDictObjectFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
6618 [outputStream writeInt32NoTag:(int32_t)msgSize];
6619 // Write the fields.
6620 WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
6621 WriteDictObjectField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
6625 - (void)setGPBGenericValue:(GPBGenericValue *)value
6626 forGPBGenericValueKey:(GPBGenericValue *)key {
6627 [_dictionary setObject:value->valueString forKey:@(key->valueUInt64)];
6630 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
6631 [self enumerateKeysAndObjectsUsingBlock:^(uint64_t key, id object, BOOL *stop) {
6632 #pragma unused(stop)
6633 block([NSString stringWithFormat:@"%llu", key], object);
6637 - (id)objectForKey:(uint64_t)key {
6638 id result = [_dictionary objectForKey:@(key)];
6642 - (void)addEntriesFromDictionary:(GPBUInt64ObjectDictionary *)otherDictionary {
6643 if (otherDictionary) {
6644 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
6646 GPBAutocreatedDictionaryModified(_autocreator, self);
6651 - (void)setObject:(id)object forKey:(uint64_t)key {
6653 [NSException raise:NSInvalidArgumentException
6654 format:@"Attempting to add nil object to a Dictionary"];
6656 [_dictionary setObject:object forKey:@(key)];
6658 GPBAutocreatedDictionaryModified(_autocreator, self);
6662 - (void)removeObjectForKey:(uint64_t)aKey {
6663 [_dictionary removeObjectForKey:@(aKey)];
6667 [_dictionary removeAllObjects];
6672 //%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(Int64, int64_t)
6673 // This block of code is generated, do not edit it directly.
6675 #pragma mark - Int64 -> UInt32
6677 @implementation GPBInt64UInt32Dictionary {
6679 NSMutableDictionary *_dictionary;
6682 - (instancetype)init {
6683 return [self initWithUInt32s:NULL forKeys:NULL count:0];
6686 - (instancetype)initWithUInt32s:(const uint32_t [])values
6687 forKeys:(const int64_t [])keys
6688 count:(NSUInteger)count {
6689 self = [super init];
6691 _dictionary = [[NSMutableDictionary alloc] init];
6692 if (count && values && keys) {
6693 for (NSUInteger i = 0; i < count; ++i) {
6694 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
6701 - (instancetype)initWithDictionary:(GPBInt64UInt32Dictionary *)dictionary {
6702 self = [self initWithUInt32s:NULL forKeys:NULL count:0];
6705 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
6711 - (instancetype)initWithCapacity:(NSUInteger)numItems {
6712 #pragma unused(numItems)
6713 return [self initWithUInt32s:NULL forKeys:NULL count:0];
6717 NSAssert(!_autocreator,
6718 @"%@: Autocreator must be cleared before release, autocreator: %@",
6719 [self class], _autocreator);
6720 [_dictionary release];
6724 - (instancetype)copyWithZone:(NSZone *)zone {
6725 return [[GPBInt64UInt32Dictionary allocWithZone:zone] initWithDictionary:self];
6728 - (BOOL)isEqual:(id)other {
6729 if (self == other) {
6732 if (![other isKindOfClass:[GPBInt64UInt32Dictionary class]]) {
6735 GPBInt64UInt32Dictionary *otherDictionary = other;
6736 return [_dictionary isEqual:otherDictionary->_dictionary];
6739 - (NSUInteger)hash {
6740 return _dictionary.count;
6743 - (NSString *)description {
6744 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
6747 - (NSUInteger)count {
6748 return _dictionary.count;
6751 - (void)enumerateKeysAndUInt32sUsingBlock:
6752 (void (^)(int64_t key, uint32_t value, BOOL *stop))block {
6754 NSDictionary *internal = _dictionary;
6755 NSEnumerator *keys = [internal keyEnumerator];
6757 while ((aKey = [keys nextObject])) {
6758 NSNumber *aValue = internal[aKey];
6759 block([aKey longLongValue], [aValue unsignedIntValue], &stop);
6766 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
6767 NSDictionary *internal = _dictionary;
6768 NSUInteger count = internal.count;
6773 GPBDataType valueDataType = GPBGetFieldDataType(field);
6774 GPBDataType keyDataType = field.mapKeyDataType;
6776 NSEnumerator *keys = [internal keyEnumerator];
6778 while ((aKey = [keys nextObject])) {
6779 NSNumber *aValue = internal[aKey];
6780 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
6781 msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
6782 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
6784 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
6785 result += tagSize * count;
6789 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
6790 asField:(GPBFieldDescriptor *)field {
6791 GPBDataType valueDataType = GPBGetFieldDataType(field);
6792 GPBDataType keyDataType = field.mapKeyDataType;
6793 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
6794 NSDictionary *internal = _dictionary;
6795 NSEnumerator *keys = [internal keyEnumerator];
6797 while ((aKey = [keys nextObject])) {
6798 NSNumber *aValue = internal[aKey];
6799 [outputStream writeInt32NoTag:tag];
6800 // Write the size of the message.
6801 int64_t unwrappedKey = [aKey longLongValue];
6802 uint32_t unwrappedValue = [aValue unsignedIntValue];
6803 size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
6804 msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
6805 [outputStream writeInt32NoTag:(int32_t)msgSize];
6806 // Write the fields.
6807 WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
6808 WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
6812 - (void)setGPBGenericValue:(GPBGenericValue *)value
6813 forGPBGenericValueKey:(GPBGenericValue *)key {
6814 [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueInt64)];
6817 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
6818 [self enumerateKeysAndUInt32sUsingBlock:^(int64_t key, uint32_t value, BOOL *stop) {
6819 #pragma unused(stop)
6820 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%u", value]);
6824 - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(int64_t)key {
6825 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
6826 if (wrapped && value) {
6827 *value = [wrapped unsignedIntValue];
6829 return (wrapped != NULL);
6832 - (void)addEntriesFromDictionary:(GPBInt64UInt32Dictionary *)otherDictionary {
6833 if (otherDictionary) {
6834 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
6836 GPBAutocreatedDictionaryModified(_autocreator, self);
6841 - (void)setUInt32:(uint32_t)value forKey:(int64_t)key {
6842 [_dictionary setObject:@(value) forKey:@(key)];
6844 GPBAutocreatedDictionaryModified(_autocreator, self);
6848 - (void)removeUInt32ForKey:(int64_t)aKey {
6849 [_dictionary removeObjectForKey:@(aKey)];
6853 [_dictionary removeAllObjects];
6858 #pragma mark - Int64 -> Int32
6860 @implementation GPBInt64Int32Dictionary {
6862 NSMutableDictionary *_dictionary;
6865 - (instancetype)init {
6866 return [self initWithInt32s:NULL forKeys:NULL count:0];
6869 - (instancetype)initWithInt32s:(const int32_t [])values
6870 forKeys:(const int64_t [])keys
6871 count:(NSUInteger)count {
6872 self = [super init];
6874 _dictionary = [[NSMutableDictionary alloc] init];
6875 if (count && values && keys) {
6876 for (NSUInteger i = 0; i < count; ++i) {
6877 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
6884 - (instancetype)initWithDictionary:(GPBInt64Int32Dictionary *)dictionary {
6885 self = [self initWithInt32s:NULL forKeys:NULL count:0];
6888 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
6894 - (instancetype)initWithCapacity:(NSUInteger)numItems {
6895 #pragma unused(numItems)
6896 return [self initWithInt32s:NULL forKeys:NULL count:0];
6900 NSAssert(!_autocreator,
6901 @"%@: Autocreator must be cleared before release, autocreator: %@",
6902 [self class], _autocreator);
6903 [_dictionary release];
6907 - (instancetype)copyWithZone:(NSZone *)zone {
6908 return [[GPBInt64Int32Dictionary allocWithZone:zone] initWithDictionary:self];
6911 - (BOOL)isEqual:(id)other {
6912 if (self == other) {
6915 if (![other isKindOfClass:[GPBInt64Int32Dictionary class]]) {
6918 GPBInt64Int32Dictionary *otherDictionary = other;
6919 return [_dictionary isEqual:otherDictionary->_dictionary];
6922 - (NSUInteger)hash {
6923 return _dictionary.count;
6926 - (NSString *)description {
6927 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
6930 - (NSUInteger)count {
6931 return _dictionary.count;
6934 - (void)enumerateKeysAndInt32sUsingBlock:
6935 (void (^)(int64_t key, int32_t value, BOOL *stop))block {
6937 NSDictionary *internal = _dictionary;
6938 NSEnumerator *keys = [internal keyEnumerator];
6940 while ((aKey = [keys nextObject])) {
6941 NSNumber *aValue = internal[aKey];
6942 block([aKey longLongValue], [aValue intValue], &stop);
6949 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
6950 NSDictionary *internal = _dictionary;
6951 NSUInteger count = internal.count;
6956 GPBDataType valueDataType = GPBGetFieldDataType(field);
6957 GPBDataType keyDataType = field.mapKeyDataType;
6959 NSEnumerator *keys = [internal keyEnumerator];
6961 while ((aKey = [keys nextObject])) {
6962 NSNumber *aValue = internal[aKey];
6963 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
6964 msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
6965 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
6967 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
6968 result += tagSize * count;
6972 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
6973 asField:(GPBFieldDescriptor *)field {
6974 GPBDataType valueDataType = GPBGetFieldDataType(field);
6975 GPBDataType keyDataType = field.mapKeyDataType;
6976 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
6977 NSDictionary *internal = _dictionary;
6978 NSEnumerator *keys = [internal keyEnumerator];
6980 while ((aKey = [keys nextObject])) {
6981 NSNumber *aValue = internal[aKey];
6982 [outputStream writeInt32NoTag:tag];
6983 // Write the size of the message.
6984 int64_t unwrappedKey = [aKey longLongValue];
6985 int32_t unwrappedValue = [aValue intValue];
6986 size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
6987 msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
6988 [outputStream writeInt32NoTag:(int32_t)msgSize];
6989 // Write the fields.
6990 WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
6991 WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
6995 - (void)setGPBGenericValue:(GPBGenericValue *)value
6996 forGPBGenericValueKey:(GPBGenericValue *)key {
6997 [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueInt64)];
7000 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
7001 [self enumerateKeysAndInt32sUsingBlock:^(int64_t key, int32_t value, BOOL *stop) {
7002 #pragma unused(stop)
7003 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%d", value]);
7007 - (BOOL)getInt32:(nullable int32_t *)value forKey:(int64_t)key {
7008 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
7009 if (wrapped && value) {
7010 *value = [wrapped intValue];
7012 return (wrapped != NULL);
7015 - (void)addEntriesFromDictionary:(GPBInt64Int32Dictionary *)otherDictionary {
7016 if (otherDictionary) {
7017 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
7019 GPBAutocreatedDictionaryModified(_autocreator, self);
7024 - (void)setInt32:(int32_t)value forKey:(int64_t)key {
7025 [_dictionary setObject:@(value) forKey:@(key)];
7027 GPBAutocreatedDictionaryModified(_autocreator, self);
7031 - (void)removeInt32ForKey:(int64_t)aKey {
7032 [_dictionary removeObjectForKey:@(aKey)];
7036 [_dictionary removeAllObjects];
7041 #pragma mark - Int64 -> UInt64
7043 @implementation GPBInt64UInt64Dictionary {
7045 NSMutableDictionary *_dictionary;
7048 - (instancetype)init {
7049 return [self initWithUInt64s:NULL forKeys:NULL count:0];
7052 - (instancetype)initWithUInt64s:(const uint64_t [])values
7053 forKeys:(const int64_t [])keys
7054 count:(NSUInteger)count {
7055 self = [super init];
7057 _dictionary = [[NSMutableDictionary alloc] init];
7058 if (count && values && keys) {
7059 for (NSUInteger i = 0; i < count; ++i) {
7060 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
7067 - (instancetype)initWithDictionary:(GPBInt64UInt64Dictionary *)dictionary {
7068 self = [self initWithUInt64s:NULL forKeys:NULL count:0];
7071 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
7077 - (instancetype)initWithCapacity:(NSUInteger)numItems {
7078 #pragma unused(numItems)
7079 return [self initWithUInt64s:NULL forKeys:NULL count:0];
7083 NSAssert(!_autocreator,
7084 @"%@: Autocreator must be cleared before release, autocreator: %@",
7085 [self class], _autocreator);
7086 [_dictionary release];
7090 - (instancetype)copyWithZone:(NSZone *)zone {
7091 return [[GPBInt64UInt64Dictionary allocWithZone:zone] initWithDictionary:self];
7094 - (BOOL)isEqual:(id)other {
7095 if (self == other) {
7098 if (![other isKindOfClass:[GPBInt64UInt64Dictionary class]]) {
7101 GPBInt64UInt64Dictionary *otherDictionary = other;
7102 return [_dictionary isEqual:otherDictionary->_dictionary];
7105 - (NSUInteger)hash {
7106 return _dictionary.count;
7109 - (NSString *)description {
7110 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
7113 - (NSUInteger)count {
7114 return _dictionary.count;
7117 - (void)enumerateKeysAndUInt64sUsingBlock:
7118 (void (^)(int64_t key, uint64_t value, BOOL *stop))block {
7120 NSDictionary *internal = _dictionary;
7121 NSEnumerator *keys = [internal keyEnumerator];
7123 while ((aKey = [keys nextObject])) {
7124 NSNumber *aValue = internal[aKey];
7125 block([aKey longLongValue], [aValue unsignedLongLongValue], &stop);
7132 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
7133 NSDictionary *internal = _dictionary;
7134 NSUInteger count = internal.count;
7139 GPBDataType valueDataType = GPBGetFieldDataType(field);
7140 GPBDataType keyDataType = field.mapKeyDataType;
7142 NSEnumerator *keys = [internal keyEnumerator];
7144 while ((aKey = [keys nextObject])) {
7145 NSNumber *aValue = internal[aKey];
7146 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
7147 msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
7148 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
7150 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
7151 result += tagSize * count;
7155 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
7156 asField:(GPBFieldDescriptor *)field {
7157 GPBDataType valueDataType = GPBGetFieldDataType(field);
7158 GPBDataType keyDataType = field.mapKeyDataType;
7159 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
7160 NSDictionary *internal = _dictionary;
7161 NSEnumerator *keys = [internal keyEnumerator];
7163 while ((aKey = [keys nextObject])) {
7164 NSNumber *aValue = internal[aKey];
7165 [outputStream writeInt32NoTag:tag];
7166 // Write the size of the message.
7167 int64_t unwrappedKey = [aKey longLongValue];
7168 uint64_t unwrappedValue = [aValue unsignedLongLongValue];
7169 size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
7170 msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
7171 [outputStream writeInt32NoTag:(int32_t)msgSize];
7172 // Write the fields.
7173 WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
7174 WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
7178 - (void)setGPBGenericValue:(GPBGenericValue *)value
7179 forGPBGenericValueKey:(GPBGenericValue *)key {
7180 [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueInt64)];
7183 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
7184 [self enumerateKeysAndUInt64sUsingBlock:^(int64_t key, uint64_t value, BOOL *stop) {
7185 #pragma unused(stop)
7186 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%llu", value]);
7190 - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(int64_t)key {
7191 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
7192 if (wrapped && value) {
7193 *value = [wrapped unsignedLongLongValue];
7195 return (wrapped != NULL);
7198 - (void)addEntriesFromDictionary:(GPBInt64UInt64Dictionary *)otherDictionary {
7199 if (otherDictionary) {
7200 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
7202 GPBAutocreatedDictionaryModified(_autocreator, self);
7207 - (void)setUInt64:(uint64_t)value forKey:(int64_t)key {
7208 [_dictionary setObject:@(value) forKey:@(key)];
7210 GPBAutocreatedDictionaryModified(_autocreator, self);
7214 - (void)removeUInt64ForKey:(int64_t)aKey {
7215 [_dictionary removeObjectForKey:@(aKey)];
7219 [_dictionary removeAllObjects];
7224 #pragma mark - Int64 -> Int64
7226 @implementation GPBInt64Int64Dictionary {
7228 NSMutableDictionary *_dictionary;
7231 - (instancetype)init {
7232 return [self initWithInt64s:NULL forKeys:NULL count:0];
7235 - (instancetype)initWithInt64s:(const int64_t [])values
7236 forKeys:(const int64_t [])keys
7237 count:(NSUInteger)count {
7238 self = [super init];
7240 _dictionary = [[NSMutableDictionary alloc] init];
7241 if (count && values && keys) {
7242 for (NSUInteger i = 0; i < count; ++i) {
7243 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
7250 - (instancetype)initWithDictionary:(GPBInt64Int64Dictionary *)dictionary {
7251 self = [self initWithInt64s:NULL forKeys:NULL count:0];
7254 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
7260 - (instancetype)initWithCapacity:(NSUInteger)numItems {
7261 #pragma unused(numItems)
7262 return [self initWithInt64s:NULL forKeys:NULL count:0];
7266 NSAssert(!_autocreator,
7267 @"%@: Autocreator must be cleared before release, autocreator: %@",
7268 [self class], _autocreator);
7269 [_dictionary release];
7273 - (instancetype)copyWithZone:(NSZone *)zone {
7274 return [[GPBInt64Int64Dictionary allocWithZone:zone] initWithDictionary:self];
7277 - (BOOL)isEqual:(id)other {
7278 if (self == other) {
7281 if (![other isKindOfClass:[GPBInt64Int64Dictionary class]]) {
7284 GPBInt64Int64Dictionary *otherDictionary = other;
7285 return [_dictionary isEqual:otherDictionary->_dictionary];
7288 - (NSUInteger)hash {
7289 return _dictionary.count;
7292 - (NSString *)description {
7293 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
7296 - (NSUInteger)count {
7297 return _dictionary.count;
7300 - (void)enumerateKeysAndInt64sUsingBlock:
7301 (void (^)(int64_t key, int64_t value, BOOL *stop))block {
7303 NSDictionary *internal = _dictionary;
7304 NSEnumerator *keys = [internal keyEnumerator];
7306 while ((aKey = [keys nextObject])) {
7307 NSNumber *aValue = internal[aKey];
7308 block([aKey longLongValue], [aValue longLongValue], &stop);
7315 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
7316 NSDictionary *internal = _dictionary;
7317 NSUInteger count = internal.count;
7322 GPBDataType valueDataType = GPBGetFieldDataType(field);
7323 GPBDataType keyDataType = field.mapKeyDataType;
7325 NSEnumerator *keys = [internal keyEnumerator];
7327 while ((aKey = [keys nextObject])) {
7328 NSNumber *aValue = internal[aKey];
7329 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
7330 msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
7331 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
7333 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
7334 result += tagSize * count;
7338 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
7339 asField:(GPBFieldDescriptor *)field {
7340 GPBDataType valueDataType = GPBGetFieldDataType(field);
7341 GPBDataType keyDataType = field.mapKeyDataType;
7342 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
7343 NSDictionary *internal = _dictionary;
7344 NSEnumerator *keys = [internal keyEnumerator];
7346 while ((aKey = [keys nextObject])) {
7347 NSNumber *aValue = internal[aKey];
7348 [outputStream writeInt32NoTag:tag];
7349 // Write the size of the message.
7350 int64_t unwrappedKey = [aKey longLongValue];
7351 int64_t unwrappedValue = [aValue longLongValue];
7352 size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
7353 msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
7354 [outputStream writeInt32NoTag:(int32_t)msgSize];
7355 // Write the fields.
7356 WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
7357 WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
7361 - (void)setGPBGenericValue:(GPBGenericValue *)value
7362 forGPBGenericValueKey:(GPBGenericValue *)key {
7363 [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueInt64)];
7366 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
7367 [self enumerateKeysAndInt64sUsingBlock:^(int64_t key, int64_t value, BOOL *stop) {
7368 #pragma unused(stop)
7369 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%lld", value]);
7373 - (BOOL)getInt64:(nullable int64_t *)value forKey:(int64_t)key {
7374 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
7375 if (wrapped && value) {
7376 *value = [wrapped longLongValue];
7378 return (wrapped != NULL);
7381 - (void)addEntriesFromDictionary:(GPBInt64Int64Dictionary *)otherDictionary {
7382 if (otherDictionary) {
7383 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
7385 GPBAutocreatedDictionaryModified(_autocreator, self);
7390 - (void)setInt64:(int64_t)value forKey:(int64_t)key {
7391 [_dictionary setObject:@(value) forKey:@(key)];
7393 GPBAutocreatedDictionaryModified(_autocreator, self);
7397 - (void)removeInt64ForKey:(int64_t)aKey {
7398 [_dictionary removeObjectForKey:@(aKey)];
7402 [_dictionary removeAllObjects];
7407 #pragma mark - Int64 -> Bool
7409 @implementation GPBInt64BoolDictionary {
7411 NSMutableDictionary *_dictionary;
7414 - (instancetype)init {
7415 return [self initWithBools:NULL forKeys:NULL count:0];
7418 - (instancetype)initWithBools:(const BOOL [])values
7419 forKeys:(const int64_t [])keys
7420 count:(NSUInteger)count {
7421 self = [super init];
7423 _dictionary = [[NSMutableDictionary alloc] init];
7424 if (count && values && keys) {
7425 for (NSUInteger i = 0; i < count; ++i) {
7426 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
7433 - (instancetype)initWithDictionary:(GPBInt64BoolDictionary *)dictionary {
7434 self = [self initWithBools:NULL forKeys:NULL count:0];
7437 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
7443 - (instancetype)initWithCapacity:(NSUInteger)numItems {
7444 #pragma unused(numItems)
7445 return [self initWithBools:NULL forKeys:NULL count:0];
7449 NSAssert(!_autocreator,
7450 @"%@: Autocreator must be cleared before release, autocreator: %@",
7451 [self class], _autocreator);
7452 [_dictionary release];
7456 - (instancetype)copyWithZone:(NSZone *)zone {
7457 return [[GPBInt64BoolDictionary allocWithZone:zone] initWithDictionary:self];
7460 - (BOOL)isEqual:(id)other {
7461 if (self == other) {
7464 if (![other isKindOfClass:[GPBInt64BoolDictionary class]]) {
7467 GPBInt64BoolDictionary *otherDictionary = other;
7468 return [_dictionary isEqual:otherDictionary->_dictionary];
7471 - (NSUInteger)hash {
7472 return _dictionary.count;
7475 - (NSString *)description {
7476 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
7479 - (NSUInteger)count {
7480 return _dictionary.count;
7483 - (void)enumerateKeysAndBoolsUsingBlock:
7484 (void (^)(int64_t key, BOOL value, BOOL *stop))block {
7486 NSDictionary *internal = _dictionary;
7487 NSEnumerator *keys = [internal keyEnumerator];
7489 while ((aKey = [keys nextObject])) {
7490 NSNumber *aValue = internal[aKey];
7491 block([aKey longLongValue], [aValue boolValue], &stop);
7498 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
7499 NSDictionary *internal = _dictionary;
7500 NSUInteger count = internal.count;
7505 GPBDataType valueDataType = GPBGetFieldDataType(field);
7506 GPBDataType keyDataType = field.mapKeyDataType;
7508 NSEnumerator *keys = [internal keyEnumerator];
7510 while ((aKey = [keys nextObject])) {
7511 NSNumber *aValue = internal[aKey];
7512 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
7513 msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
7514 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
7516 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
7517 result += tagSize * count;
7521 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
7522 asField:(GPBFieldDescriptor *)field {
7523 GPBDataType valueDataType = GPBGetFieldDataType(field);
7524 GPBDataType keyDataType = field.mapKeyDataType;
7525 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
7526 NSDictionary *internal = _dictionary;
7527 NSEnumerator *keys = [internal keyEnumerator];
7529 while ((aKey = [keys nextObject])) {
7530 NSNumber *aValue = internal[aKey];
7531 [outputStream writeInt32NoTag:tag];
7532 // Write the size of the message.
7533 int64_t unwrappedKey = [aKey longLongValue];
7534 BOOL unwrappedValue = [aValue boolValue];
7535 size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
7536 msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
7537 [outputStream writeInt32NoTag:(int32_t)msgSize];
7538 // Write the fields.
7539 WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
7540 WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
7544 - (void)setGPBGenericValue:(GPBGenericValue *)value
7545 forGPBGenericValueKey:(GPBGenericValue *)key {
7546 [_dictionary setObject:@(value->valueBool) forKey:@(key->valueInt64)];
7549 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
7550 [self enumerateKeysAndBoolsUsingBlock:^(int64_t key, BOOL value, BOOL *stop) {
7551 #pragma unused(stop)
7552 block([NSString stringWithFormat:@"%lld", key], (value ? @"true" : @"false"));
7556 - (BOOL)getBool:(nullable BOOL *)value forKey:(int64_t)key {
7557 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
7558 if (wrapped && value) {
7559 *value = [wrapped boolValue];
7561 return (wrapped != NULL);
7564 - (void)addEntriesFromDictionary:(GPBInt64BoolDictionary *)otherDictionary {
7565 if (otherDictionary) {
7566 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
7568 GPBAutocreatedDictionaryModified(_autocreator, self);
7573 - (void)setBool:(BOOL)value forKey:(int64_t)key {
7574 [_dictionary setObject:@(value) forKey:@(key)];
7576 GPBAutocreatedDictionaryModified(_autocreator, self);
7580 - (void)removeBoolForKey:(int64_t)aKey {
7581 [_dictionary removeObjectForKey:@(aKey)];
7585 [_dictionary removeAllObjects];
7590 #pragma mark - Int64 -> Float
7592 @implementation GPBInt64FloatDictionary {
7594 NSMutableDictionary *_dictionary;
7597 - (instancetype)init {
7598 return [self initWithFloats:NULL forKeys:NULL count:0];
7601 - (instancetype)initWithFloats:(const float [])values
7602 forKeys:(const int64_t [])keys
7603 count:(NSUInteger)count {
7604 self = [super init];
7606 _dictionary = [[NSMutableDictionary alloc] init];
7607 if (count && values && keys) {
7608 for (NSUInteger i = 0; i < count; ++i) {
7609 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
7616 - (instancetype)initWithDictionary:(GPBInt64FloatDictionary *)dictionary {
7617 self = [self initWithFloats:NULL forKeys:NULL count:0];
7620 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
7626 - (instancetype)initWithCapacity:(NSUInteger)numItems {
7627 #pragma unused(numItems)
7628 return [self initWithFloats:NULL forKeys:NULL count:0];
7632 NSAssert(!_autocreator,
7633 @"%@: Autocreator must be cleared before release, autocreator: %@",
7634 [self class], _autocreator);
7635 [_dictionary release];
7639 - (instancetype)copyWithZone:(NSZone *)zone {
7640 return [[GPBInt64FloatDictionary allocWithZone:zone] initWithDictionary:self];
7643 - (BOOL)isEqual:(id)other {
7644 if (self == other) {
7647 if (![other isKindOfClass:[GPBInt64FloatDictionary class]]) {
7650 GPBInt64FloatDictionary *otherDictionary = other;
7651 return [_dictionary isEqual:otherDictionary->_dictionary];
7654 - (NSUInteger)hash {
7655 return _dictionary.count;
7658 - (NSString *)description {
7659 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
7662 - (NSUInteger)count {
7663 return _dictionary.count;
7666 - (void)enumerateKeysAndFloatsUsingBlock:
7667 (void (^)(int64_t key, float value, BOOL *stop))block {
7669 NSDictionary *internal = _dictionary;
7670 NSEnumerator *keys = [internal keyEnumerator];
7672 while ((aKey = [keys nextObject])) {
7673 NSNumber *aValue = internal[aKey];
7674 block([aKey longLongValue], [aValue floatValue], &stop);
7681 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
7682 NSDictionary *internal = _dictionary;
7683 NSUInteger count = internal.count;
7688 GPBDataType valueDataType = GPBGetFieldDataType(field);
7689 GPBDataType keyDataType = field.mapKeyDataType;
7691 NSEnumerator *keys = [internal keyEnumerator];
7693 while ((aKey = [keys nextObject])) {
7694 NSNumber *aValue = internal[aKey];
7695 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
7696 msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
7697 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
7699 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
7700 result += tagSize * count;
7704 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
7705 asField:(GPBFieldDescriptor *)field {
7706 GPBDataType valueDataType = GPBGetFieldDataType(field);
7707 GPBDataType keyDataType = field.mapKeyDataType;
7708 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
7709 NSDictionary *internal = _dictionary;
7710 NSEnumerator *keys = [internal keyEnumerator];
7712 while ((aKey = [keys nextObject])) {
7713 NSNumber *aValue = internal[aKey];
7714 [outputStream writeInt32NoTag:tag];
7715 // Write the size of the message.
7716 int64_t unwrappedKey = [aKey longLongValue];
7717 float unwrappedValue = [aValue floatValue];
7718 size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
7719 msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
7720 [outputStream writeInt32NoTag:(int32_t)msgSize];
7721 // Write the fields.
7722 WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
7723 WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
7727 - (void)setGPBGenericValue:(GPBGenericValue *)value
7728 forGPBGenericValueKey:(GPBGenericValue *)key {
7729 [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueInt64)];
7732 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
7733 [self enumerateKeysAndFloatsUsingBlock:^(int64_t key, float value, BOOL *stop) {
7734 #pragma unused(stop)
7735 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
7739 - (BOOL)getFloat:(nullable float *)value forKey:(int64_t)key {
7740 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
7741 if (wrapped && value) {
7742 *value = [wrapped floatValue];
7744 return (wrapped != NULL);
7747 - (void)addEntriesFromDictionary:(GPBInt64FloatDictionary *)otherDictionary {
7748 if (otherDictionary) {
7749 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
7751 GPBAutocreatedDictionaryModified(_autocreator, self);
7756 - (void)setFloat:(float)value forKey:(int64_t)key {
7757 [_dictionary setObject:@(value) forKey:@(key)];
7759 GPBAutocreatedDictionaryModified(_autocreator, self);
7763 - (void)removeFloatForKey:(int64_t)aKey {
7764 [_dictionary removeObjectForKey:@(aKey)];
7768 [_dictionary removeAllObjects];
7773 #pragma mark - Int64 -> Double
7775 @implementation GPBInt64DoubleDictionary {
7777 NSMutableDictionary *_dictionary;
7780 - (instancetype)init {
7781 return [self initWithDoubles:NULL forKeys:NULL count:0];
7784 - (instancetype)initWithDoubles:(const double [])values
7785 forKeys:(const int64_t [])keys
7786 count:(NSUInteger)count {
7787 self = [super init];
7789 _dictionary = [[NSMutableDictionary alloc] init];
7790 if (count && values && keys) {
7791 for (NSUInteger i = 0; i < count; ++i) {
7792 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
7799 - (instancetype)initWithDictionary:(GPBInt64DoubleDictionary *)dictionary {
7800 self = [self initWithDoubles:NULL forKeys:NULL count:0];
7803 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
7809 - (instancetype)initWithCapacity:(NSUInteger)numItems {
7810 #pragma unused(numItems)
7811 return [self initWithDoubles:NULL forKeys:NULL count:0];
7815 NSAssert(!_autocreator,
7816 @"%@: Autocreator must be cleared before release, autocreator: %@",
7817 [self class], _autocreator);
7818 [_dictionary release];
7822 - (instancetype)copyWithZone:(NSZone *)zone {
7823 return [[GPBInt64DoubleDictionary allocWithZone:zone] initWithDictionary:self];
7826 - (BOOL)isEqual:(id)other {
7827 if (self == other) {
7830 if (![other isKindOfClass:[GPBInt64DoubleDictionary class]]) {
7833 GPBInt64DoubleDictionary *otherDictionary = other;
7834 return [_dictionary isEqual:otherDictionary->_dictionary];
7837 - (NSUInteger)hash {
7838 return _dictionary.count;
7841 - (NSString *)description {
7842 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
7845 - (NSUInteger)count {
7846 return _dictionary.count;
7849 - (void)enumerateKeysAndDoublesUsingBlock:
7850 (void (^)(int64_t key, double value, BOOL *stop))block {
7852 NSDictionary *internal = _dictionary;
7853 NSEnumerator *keys = [internal keyEnumerator];
7855 while ((aKey = [keys nextObject])) {
7856 NSNumber *aValue = internal[aKey];
7857 block([aKey longLongValue], [aValue doubleValue], &stop);
7864 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
7865 NSDictionary *internal = _dictionary;
7866 NSUInteger count = internal.count;
7871 GPBDataType valueDataType = GPBGetFieldDataType(field);
7872 GPBDataType keyDataType = field.mapKeyDataType;
7874 NSEnumerator *keys = [internal keyEnumerator];
7876 while ((aKey = [keys nextObject])) {
7877 NSNumber *aValue = internal[aKey];
7878 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
7879 msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
7880 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
7882 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
7883 result += tagSize * count;
7887 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
7888 asField:(GPBFieldDescriptor *)field {
7889 GPBDataType valueDataType = GPBGetFieldDataType(field);
7890 GPBDataType keyDataType = field.mapKeyDataType;
7891 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
7892 NSDictionary *internal = _dictionary;
7893 NSEnumerator *keys = [internal keyEnumerator];
7895 while ((aKey = [keys nextObject])) {
7896 NSNumber *aValue = internal[aKey];
7897 [outputStream writeInt32NoTag:tag];
7898 // Write the size of the message.
7899 int64_t unwrappedKey = [aKey longLongValue];
7900 double unwrappedValue = [aValue doubleValue];
7901 size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
7902 msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
7903 [outputStream writeInt32NoTag:(int32_t)msgSize];
7904 // Write the fields.
7905 WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
7906 WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
7910 - (void)setGPBGenericValue:(GPBGenericValue *)value
7911 forGPBGenericValueKey:(GPBGenericValue *)key {
7912 [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueInt64)];
7915 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
7916 [self enumerateKeysAndDoublesUsingBlock:^(int64_t key, double value, BOOL *stop) {
7917 #pragma unused(stop)
7918 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
7922 - (BOOL)getDouble:(nullable double *)value forKey:(int64_t)key {
7923 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
7924 if (wrapped && value) {
7925 *value = [wrapped doubleValue];
7927 return (wrapped != NULL);
7930 - (void)addEntriesFromDictionary:(GPBInt64DoubleDictionary *)otherDictionary {
7931 if (otherDictionary) {
7932 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
7934 GPBAutocreatedDictionaryModified(_autocreator, self);
7939 - (void)setDouble:(double)value forKey:(int64_t)key {
7940 [_dictionary setObject:@(value) forKey:@(key)];
7942 GPBAutocreatedDictionaryModified(_autocreator, self);
7946 - (void)removeDoubleForKey:(int64_t)aKey {
7947 [_dictionary removeObjectForKey:@(aKey)];
7951 [_dictionary removeAllObjects];
7956 #pragma mark - Int64 -> Enum
7958 @implementation GPBInt64EnumDictionary {
7960 NSMutableDictionary *_dictionary;
7961 GPBEnumValidationFunc _validationFunc;
7964 @synthesize validationFunc = _validationFunc;
7966 - (instancetype)init {
7967 return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
7970 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
7971 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
7974 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
7975 rawValues:(const int32_t [])rawValues
7976 forKeys:(const int64_t [])keys
7977 count:(NSUInteger)count {
7978 self = [super init];
7980 _dictionary = [[NSMutableDictionary alloc] init];
7981 _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
7982 if (count && rawValues && keys) {
7983 for (NSUInteger i = 0; i < count; ++i) {
7984 [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])];
7991 - (instancetype)initWithDictionary:(GPBInt64EnumDictionary *)dictionary {
7992 self = [self initWithValidationFunction:dictionary.validationFunc
7998 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
8004 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
8005 capacity:(NSUInteger)numItems {
8006 #pragma unused(numItems)
8007 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
8011 NSAssert(!_autocreator,
8012 @"%@: Autocreator must be cleared before release, autocreator: %@",
8013 [self class], _autocreator);
8014 [_dictionary release];
8018 - (instancetype)copyWithZone:(NSZone *)zone {
8019 return [[GPBInt64EnumDictionary allocWithZone:zone] initWithDictionary:self];
8022 - (BOOL)isEqual:(id)other {
8023 if (self == other) {
8026 if (![other isKindOfClass:[GPBInt64EnumDictionary class]]) {
8029 GPBInt64EnumDictionary *otherDictionary = other;
8030 return [_dictionary isEqual:otherDictionary->_dictionary];
8033 - (NSUInteger)hash {
8034 return _dictionary.count;
8037 - (NSString *)description {
8038 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
8041 - (NSUInteger)count {
8042 return _dictionary.count;
8045 - (void)enumerateKeysAndRawValuesUsingBlock:
8046 (void (^)(int64_t key, int32_t value, BOOL *stop))block {
8048 NSDictionary *internal = _dictionary;
8049 NSEnumerator *keys = [internal keyEnumerator];
8051 while ((aKey = [keys nextObject])) {
8052 NSNumber *aValue = internal[aKey];
8053 block([aKey longLongValue], [aValue intValue], &stop);
8060 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
8061 NSDictionary *internal = _dictionary;
8062 NSUInteger count = internal.count;
8067 GPBDataType valueDataType = GPBGetFieldDataType(field);
8068 GPBDataType keyDataType = field.mapKeyDataType;
8070 NSEnumerator *keys = [internal keyEnumerator];
8072 while ((aKey = [keys nextObject])) {
8073 NSNumber *aValue = internal[aKey];
8074 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
8075 msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
8076 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
8078 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
8079 result += tagSize * count;
8083 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
8084 asField:(GPBFieldDescriptor *)field {
8085 GPBDataType valueDataType = GPBGetFieldDataType(field);
8086 GPBDataType keyDataType = field.mapKeyDataType;
8087 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
8088 NSDictionary *internal = _dictionary;
8089 NSEnumerator *keys = [internal keyEnumerator];
8091 while ((aKey = [keys nextObject])) {
8092 NSNumber *aValue = internal[aKey];
8093 [outputStream writeInt32NoTag:tag];
8094 // Write the size of the message.
8095 int64_t unwrappedKey = [aKey longLongValue];
8096 int32_t unwrappedValue = [aValue intValue];
8097 size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
8098 msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
8099 [outputStream writeInt32NoTag:(int32_t)msgSize];
8100 // Write the fields.
8101 WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
8102 WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
8106 - (NSData *)serializedDataForUnknownValue:(int32_t)value
8107 forKey:(GPBGenericValue *)key
8108 keyDataType:(GPBDataType)keyDataType {
8109 size_t msgSize = ComputeDictInt64FieldSize(key->valueInt64, kMapKeyFieldNumber, keyDataType);
8110 msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
8111 NSMutableData *data = [NSMutableData dataWithLength:msgSize];
8112 GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
8113 WriteDictInt64Field(outputStream, key->valueInt64, kMapKeyFieldNumber, keyDataType);
8114 WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
8115 [outputStream release];
8118 - (void)setGPBGenericValue:(GPBGenericValue *)value
8119 forGPBGenericValueKey:(GPBGenericValue *)key {
8120 [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueInt64)];
8123 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
8124 [self enumerateKeysAndRawValuesUsingBlock:^(int64_t key, int32_t value, BOOL *stop) {
8125 #pragma unused(stop)
8126 block([NSString stringWithFormat:@"%lld", key], @(value));
8130 - (BOOL)getEnum:(int32_t *)value forKey:(int64_t)key {
8131 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
8132 if (wrapped && value) {
8133 int32_t result = [wrapped intValue];
8134 if (!_validationFunc(result)) {
8135 result = kGPBUnrecognizedEnumeratorValue;
8139 return (wrapped != NULL);
8142 - (BOOL)getRawValue:(int32_t *)rawValue forKey:(int64_t)key {
8143 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
8144 if (wrapped && rawValue) {
8145 *rawValue = [wrapped intValue];
8147 return (wrapped != NULL);
8150 - (void)enumerateKeysAndEnumsUsingBlock:
8151 (void (^)(int64_t key, int32_t value, BOOL *stop))block {
8152 GPBEnumValidationFunc func = _validationFunc;
8154 NSEnumerator *keys = [_dictionary keyEnumerator];
8156 while ((aKey = [keys nextObject])) {
8157 NSNumber *aValue = _dictionary[aKey];
8158 int32_t unwrapped = [aValue intValue];
8159 if (!func(unwrapped)) {
8160 unwrapped = kGPBUnrecognizedEnumeratorValue;
8162 block([aKey longLongValue], unwrapped, &stop);
8169 - (void)addRawEntriesFromDictionary:(GPBInt64EnumDictionary *)otherDictionary {
8170 if (otherDictionary) {
8171 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
8173 GPBAutocreatedDictionaryModified(_autocreator, self);
8178 - (void)setRawValue:(int32_t)value forKey:(int64_t)key {
8179 [_dictionary setObject:@(value) forKey:@(key)];
8181 GPBAutocreatedDictionaryModified(_autocreator, self);
8185 - (void)removeEnumForKey:(int64_t)aKey {
8186 [_dictionary removeObjectForKey:@(aKey)];
8190 [_dictionary removeAllObjects];
8193 - (void)setEnum:(int32_t)value forKey:(int64_t)key {
8194 if (!_validationFunc(value)) {
8195 [NSException raise:NSInvalidArgumentException
8196 format:@"GPBInt64EnumDictionary: Attempt to set an unknown enum value (%d)",
8200 [_dictionary setObject:@(value) forKey:@(key)];
8202 GPBAutocreatedDictionaryModified(_autocreator, self);
8208 #pragma mark - Int64 -> Object
8210 @implementation GPBInt64ObjectDictionary {
8212 NSMutableDictionary *_dictionary;
8215 - (instancetype)init {
8216 return [self initWithObjects:NULL forKeys:NULL count:0];
8219 - (instancetype)initWithObjects:(const id [])objects
8220 forKeys:(const int64_t [])keys
8221 count:(NSUInteger)count {
8222 self = [super init];
8224 _dictionary = [[NSMutableDictionary alloc] init];
8225 if (count && objects && keys) {
8226 for (NSUInteger i = 0; i < count; ++i) {
8228 [NSException raise:NSInvalidArgumentException
8229 format:@"Attempting to add nil object to a Dictionary"];
8231 [_dictionary setObject:objects[i] forKey:@(keys[i])];
8238 - (instancetype)initWithDictionary:(GPBInt64ObjectDictionary *)dictionary {
8239 self = [self initWithObjects:NULL forKeys:NULL count:0];
8242 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
8248 - (instancetype)initWithCapacity:(NSUInteger)numItems {
8249 #pragma unused(numItems)
8250 return [self initWithObjects:NULL forKeys:NULL count:0];
8254 NSAssert(!_autocreator,
8255 @"%@: Autocreator must be cleared before release, autocreator: %@",
8256 [self class], _autocreator);
8257 [_dictionary release];
8261 - (instancetype)copyWithZone:(NSZone *)zone {
8262 return [[GPBInt64ObjectDictionary allocWithZone:zone] initWithDictionary:self];
8265 - (BOOL)isEqual:(id)other {
8266 if (self == other) {
8269 if (![other isKindOfClass:[GPBInt64ObjectDictionary class]]) {
8272 GPBInt64ObjectDictionary *otherDictionary = other;
8273 return [_dictionary isEqual:otherDictionary->_dictionary];
8276 - (NSUInteger)hash {
8277 return _dictionary.count;
8280 - (NSString *)description {
8281 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
8284 - (NSUInteger)count {
8285 return _dictionary.count;
8288 - (void)enumerateKeysAndObjectsUsingBlock:
8289 (void (^)(int64_t key, id object, BOOL *stop))block {
8291 NSDictionary *internal = _dictionary;
8292 NSEnumerator *keys = [internal keyEnumerator];
8294 while ((aKey = [keys nextObject])) {
8295 id aObject = internal[aKey];
8296 block([aKey longLongValue], aObject, &stop);
8303 - (BOOL)isInitialized {
8304 for (GPBMessage *msg in [_dictionary objectEnumerator]) {
8305 if (!msg.initialized) {
8312 - (instancetype)deepCopyWithZone:(NSZone *)zone {
8313 GPBInt64ObjectDictionary *newDict =
8314 [[GPBInt64ObjectDictionary alloc] init];
8315 NSEnumerator *keys = [_dictionary keyEnumerator];
8317 NSMutableDictionary *internalDict = newDict->_dictionary;
8318 while ((aKey = [keys nextObject])) {
8319 GPBMessage *msg = _dictionary[aKey];
8320 GPBMessage *copiedMsg = [msg copyWithZone:zone];
8321 [internalDict setObject:copiedMsg forKey:aKey];
8322 [copiedMsg release];
8327 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
8328 NSDictionary *internal = _dictionary;
8329 NSUInteger count = internal.count;
8334 GPBDataType valueDataType = GPBGetFieldDataType(field);
8335 GPBDataType keyDataType = field.mapKeyDataType;
8337 NSEnumerator *keys = [internal keyEnumerator];
8339 while ((aKey = [keys nextObject])) {
8340 id aObject = internal[aKey];
8341 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
8342 msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
8343 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
8345 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
8346 result += tagSize * count;
8350 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
8351 asField:(GPBFieldDescriptor *)field {
8352 GPBDataType valueDataType = GPBGetFieldDataType(field);
8353 GPBDataType keyDataType = field.mapKeyDataType;
8354 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
8355 NSDictionary *internal = _dictionary;
8356 NSEnumerator *keys = [internal keyEnumerator];
8358 while ((aKey = [keys nextObject])) {
8359 id aObject = internal[aKey];
8360 [outputStream writeInt32NoTag:tag];
8361 // Write the size of the message.
8362 int64_t unwrappedKey = [aKey longLongValue];
8363 id unwrappedValue = aObject;
8364 size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
8365 msgSize += ComputeDictObjectFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
8366 [outputStream writeInt32NoTag:(int32_t)msgSize];
8367 // Write the fields.
8368 WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
8369 WriteDictObjectField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
8373 - (void)setGPBGenericValue:(GPBGenericValue *)value
8374 forGPBGenericValueKey:(GPBGenericValue *)key {
8375 [_dictionary setObject:value->valueString forKey:@(key->valueInt64)];
8378 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
8379 [self enumerateKeysAndObjectsUsingBlock:^(int64_t key, id object, BOOL *stop) {
8380 #pragma unused(stop)
8381 block([NSString stringWithFormat:@"%lld", key], object);
8385 - (id)objectForKey:(int64_t)key {
8386 id result = [_dictionary objectForKey:@(key)];
8390 - (void)addEntriesFromDictionary:(GPBInt64ObjectDictionary *)otherDictionary {
8391 if (otherDictionary) {
8392 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
8394 GPBAutocreatedDictionaryModified(_autocreator, self);
8399 - (void)setObject:(id)object forKey:(int64_t)key {
8401 [NSException raise:NSInvalidArgumentException
8402 format:@"Attempting to add nil object to a Dictionary"];
8404 [_dictionary setObject:object forKey:@(key)];
8406 GPBAutocreatedDictionaryModified(_autocreator, self);
8410 - (void)removeObjectForKey:(int64_t)aKey {
8411 [_dictionary removeObjectForKey:@(aKey)];
8415 [_dictionary removeAllObjects];
8420 //%PDDM-EXPAND DICTIONARY_POD_IMPL_FOR_KEY(String, NSString, *, OBJECT)
8421 // This block of code is generated, do not edit it directly.
8423 #pragma mark - String -> UInt32
8425 @implementation GPBStringUInt32Dictionary {
8427 NSMutableDictionary *_dictionary;
8430 - (instancetype)init {
8431 return [self initWithUInt32s:NULL forKeys:NULL count:0];
8434 - (instancetype)initWithUInt32s:(const uint32_t [])values
8435 forKeys:(const NSString * [])keys
8436 count:(NSUInteger)count {
8437 self = [super init];
8439 _dictionary = [[NSMutableDictionary alloc] init];
8440 if (count && values && keys) {
8441 for (NSUInteger i = 0; i < count; ++i) {
8443 [NSException raise:NSInvalidArgumentException
8444 format:@"Attempting to add nil key to a Dictionary"];
8446 [_dictionary setObject:@(values[i]) forKey:keys[i]];
8453 - (instancetype)initWithDictionary:(GPBStringUInt32Dictionary *)dictionary {
8454 self = [self initWithUInt32s:NULL forKeys:NULL count:0];
8457 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
8463 - (instancetype)initWithCapacity:(NSUInteger)numItems {
8464 #pragma unused(numItems)
8465 return [self initWithUInt32s:NULL forKeys:NULL count:0];
8469 NSAssert(!_autocreator,
8470 @"%@: Autocreator must be cleared before release, autocreator: %@",
8471 [self class], _autocreator);
8472 [_dictionary release];
8476 - (instancetype)copyWithZone:(NSZone *)zone {
8477 return [[GPBStringUInt32Dictionary allocWithZone:zone] initWithDictionary:self];
8480 - (BOOL)isEqual:(id)other {
8481 if (self == other) {
8484 if (![other isKindOfClass:[GPBStringUInt32Dictionary class]]) {
8487 GPBStringUInt32Dictionary *otherDictionary = other;
8488 return [_dictionary isEqual:otherDictionary->_dictionary];
8491 - (NSUInteger)hash {
8492 return _dictionary.count;
8495 - (NSString *)description {
8496 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
8499 - (NSUInteger)count {
8500 return _dictionary.count;
8503 - (void)enumerateKeysAndUInt32sUsingBlock:
8504 (void (^)(NSString *key, uint32_t value, BOOL *stop))block {
8506 NSDictionary *internal = _dictionary;
8507 NSEnumerator *keys = [internal keyEnumerator];
8509 while ((aKey = [keys nextObject])) {
8510 NSNumber *aValue = internal[aKey];
8511 block(aKey, [aValue unsignedIntValue], &stop);
8518 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
8519 NSDictionary *internal = _dictionary;
8520 NSUInteger count = internal.count;
8525 GPBDataType valueDataType = GPBGetFieldDataType(field);
8526 GPBDataType keyDataType = field.mapKeyDataType;
8528 NSEnumerator *keys = [internal keyEnumerator];
8530 while ((aKey = [keys nextObject])) {
8531 NSNumber *aValue = internal[aKey];
8532 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
8533 msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
8534 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
8536 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
8537 result += tagSize * count;
8541 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
8542 asField:(GPBFieldDescriptor *)field {
8543 GPBDataType valueDataType = GPBGetFieldDataType(field);
8544 GPBDataType keyDataType = field.mapKeyDataType;
8545 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
8546 NSDictionary *internal = _dictionary;
8547 NSEnumerator *keys = [internal keyEnumerator];
8549 while ((aKey = [keys nextObject])) {
8550 NSNumber *aValue = internal[aKey];
8551 [outputStream writeInt32NoTag:tag];
8552 // Write the size of the message.
8553 NSString *unwrappedKey = aKey;
8554 uint32_t unwrappedValue = [aValue unsignedIntValue];
8555 size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
8556 msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
8557 [outputStream writeInt32NoTag:(int32_t)msgSize];
8558 // Write the fields.
8559 WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
8560 WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
8564 - (void)setGPBGenericValue:(GPBGenericValue *)value
8565 forGPBGenericValueKey:(GPBGenericValue *)key {
8566 [_dictionary setObject:@(value->valueUInt32) forKey:key->valueString];
8569 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
8570 [self enumerateKeysAndUInt32sUsingBlock:^(NSString *key, uint32_t value, BOOL *stop) {
8571 #pragma unused(stop)
8572 block(key, [NSString stringWithFormat:@"%u", value]);
8576 - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(NSString *)key {
8577 NSNumber *wrapped = [_dictionary objectForKey:key];
8578 if (wrapped && value) {
8579 *value = [wrapped unsignedIntValue];
8581 return (wrapped != NULL);
8584 - (void)addEntriesFromDictionary:(GPBStringUInt32Dictionary *)otherDictionary {
8585 if (otherDictionary) {
8586 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
8588 GPBAutocreatedDictionaryModified(_autocreator, self);
8593 - (void)setUInt32:(uint32_t)value forKey:(NSString *)key {
8595 [NSException raise:NSInvalidArgumentException
8596 format:@"Attempting to add nil key to a Dictionary"];
8598 [_dictionary setObject:@(value) forKey:key];
8600 GPBAutocreatedDictionaryModified(_autocreator, self);
8604 - (void)removeUInt32ForKey:(NSString *)aKey {
8605 [_dictionary removeObjectForKey:aKey];
8609 [_dictionary removeAllObjects];
8614 #pragma mark - String -> Int32
8616 @implementation GPBStringInt32Dictionary {
8618 NSMutableDictionary *_dictionary;
8621 - (instancetype)init {
8622 return [self initWithInt32s:NULL forKeys:NULL count:0];
8625 - (instancetype)initWithInt32s:(const int32_t [])values
8626 forKeys:(const NSString * [])keys
8627 count:(NSUInteger)count {
8628 self = [super init];
8630 _dictionary = [[NSMutableDictionary alloc] init];
8631 if (count && values && keys) {
8632 for (NSUInteger i = 0; i < count; ++i) {
8634 [NSException raise:NSInvalidArgumentException
8635 format:@"Attempting to add nil key to a Dictionary"];
8637 [_dictionary setObject:@(values[i]) forKey:keys[i]];
8644 - (instancetype)initWithDictionary:(GPBStringInt32Dictionary *)dictionary {
8645 self = [self initWithInt32s:NULL forKeys:NULL count:0];
8648 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
8654 - (instancetype)initWithCapacity:(NSUInteger)numItems {
8655 #pragma unused(numItems)
8656 return [self initWithInt32s:NULL forKeys:NULL count:0];
8660 NSAssert(!_autocreator,
8661 @"%@: Autocreator must be cleared before release, autocreator: %@",
8662 [self class], _autocreator);
8663 [_dictionary release];
8667 - (instancetype)copyWithZone:(NSZone *)zone {
8668 return [[GPBStringInt32Dictionary allocWithZone:zone] initWithDictionary:self];
8671 - (BOOL)isEqual:(id)other {
8672 if (self == other) {
8675 if (![other isKindOfClass:[GPBStringInt32Dictionary class]]) {
8678 GPBStringInt32Dictionary *otherDictionary = other;
8679 return [_dictionary isEqual:otherDictionary->_dictionary];
8682 - (NSUInteger)hash {
8683 return _dictionary.count;
8686 - (NSString *)description {
8687 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
8690 - (NSUInteger)count {
8691 return _dictionary.count;
8694 - (void)enumerateKeysAndInt32sUsingBlock:
8695 (void (^)(NSString *key, int32_t value, BOOL *stop))block {
8697 NSDictionary *internal = _dictionary;
8698 NSEnumerator *keys = [internal keyEnumerator];
8700 while ((aKey = [keys nextObject])) {
8701 NSNumber *aValue = internal[aKey];
8702 block(aKey, [aValue intValue], &stop);
8709 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
8710 NSDictionary *internal = _dictionary;
8711 NSUInteger count = internal.count;
8716 GPBDataType valueDataType = GPBGetFieldDataType(field);
8717 GPBDataType keyDataType = field.mapKeyDataType;
8719 NSEnumerator *keys = [internal keyEnumerator];
8721 while ((aKey = [keys nextObject])) {
8722 NSNumber *aValue = internal[aKey];
8723 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
8724 msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
8725 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
8727 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
8728 result += tagSize * count;
8732 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
8733 asField:(GPBFieldDescriptor *)field {
8734 GPBDataType valueDataType = GPBGetFieldDataType(field);
8735 GPBDataType keyDataType = field.mapKeyDataType;
8736 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
8737 NSDictionary *internal = _dictionary;
8738 NSEnumerator *keys = [internal keyEnumerator];
8740 while ((aKey = [keys nextObject])) {
8741 NSNumber *aValue = internal[aKey];
8742 [outputStream writeInt32NoTag:tag];
8743 // Write the size of the message.
8744 NSString *unwrappedKey = aKey;
8745 int32_t unwrappedValue = [aValue intValue];
8746 size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
8747 msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
8748 [outputStream writeInt32NoTag:(int32_t)msgSize];
8749 // Write the fields.
8750 WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
8751 WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
8755 - (void)setGPBGenericValue:(GPBGenericValue *)value
8756 forGPBGenericValueKey:(GPBGenericValue *)key {
8757 [_dictionary setObject:@(value->valueInt32) forKey:key->valueString];
8760 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
8761 [self enumerateKeysAndInt32sUsingBlock:^(NSString *key, int32_t value, BOOL *stop) {
8762 #pragma unused(stop)
8763 block(key, [NSString stringWithFormat:@"%d", value]);
8767 - (BOOL)getInt32:(nullable int32_t *)value forKey:(NSString *)key {
8768 NSNumber *wrapped = [_dictionary objectForKey:key];
8769 if (wrapped && value) {
8770 *value = [wrapped intValue];
8772 return (wrapped != NULL);
8775 - (void)addEntriesFromDictionary:(GPBStringInt32Dictionary *)otherDictionary {
8776 if (otherDictionary) {
8777 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
8779 GPBAutocreatedDictionaryModified(_autocreator, self);
8784 - (void)setInt32:(int32_t)value forKey:(NSString *)key {
8786 [NSException raise:NSInvalidArgumentException
8787 format:@"Attempting to add nil key to a Dictionary"];
8789 [_dictionary setObject:@(value) forKey:key];
8791 GPBAutocreatedDictionaryModified(_autocreator, self);
8795 - (void)removeInt32ForKey:(NSString *)aKey {
8796 [_dictionary removeObjectForKey:aKey];
8800 [_dictionary removeAllObjects];
8805 #pragma mark - String -> UInt64
8807 @implementation GPBStringUInt64Dictionary {
8809 NSMutableDictionary *_dictionary;
8812 - (instancetype)init {
8813 return [self initWithUInt64s:NULL forKeys:NULL count:0];
8816 - (instancetype)initWithUInt64s:(const uint64_t [])values
8817 forKeys:(const NSString * [])keys
8818 count:(NSUInteger)count {
8819 self = [super init];
8821 _dictionary = [[NSMutableDictionary alloc] init];
8822 if (count && values && keys) {
8823 for (NSUInteger i = 0; i < count; ++i) {
8825 [NSException raise:NSInvalidArgumentException
8826 format:@"Attempting to add nil key to a Dictionary"];
8828 [_dictionary setObject:@(values[i]) forKey:keys[i]];
8835 - (instancetype)initWithDictionary:(GPBStringUInt64Dictionary *)dictionary {
8836 self = [self initWithUInt64s:NULL forKeys:NULL count:0];
8839 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
8845 - (instancetype)initWithCapacity:(NSUInteger)numItems {
8846 #pragma unused(numItems)
8847 return [self initWithUInt64s:NULL forKeys:NULL count:0];
8851 NSAssert(!_autocreator,
8852 @"%@: Autocreator must be cleared before release, autocreator: %@",
8853 [self class], _autocreator);
8854 [_dictionary release];
8858 - (instancetype)copyWithZone:(NSZone *)zone {
8859 return [[GPBStringUInt64Dictionary allocWithZone:zone] initWithDictionary:self];
8862 - (BOOL)isEqual:(id)other {
8863 if (self == other) {
8866 if (![other isKindOfClass:[GPBStringUInt64Dictionary class]]) {
8869 GPBStringUInt64Dictionary *otherDictionary = other;
8870 return [_dictionary isEqual:otherDictionary->_dictionary];
8873 - (NSUInteger)hash {
8874 return _dictionary.count;
8877 - (NSString *)description {
8878 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
8881 - (NSUInteger)count {
8882 return _dictionary.count;
8885 - (void)enumerateKeysAndUInt64sUsingBlock:
8886 (void (^)(NSString *key, uint64_t value, BOOL *stop))block {
8888 NSDictionary *internal = _dictionary;
8889 NSEnumerator *keys = [internal keyEnumerator];
8891 while ((aKey = [keys nextObject])) {
8892 NSNumber *aValue = internal[aKey];
8893 block(aKey, [aValue unsignedLongLongValue], &stop);
8900 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
8901 NSDictionary *internal = _dictionary;
8902 NSUInteger count = internal.count;
8907 GPBDataType valueDataType = GPBGetFieldDataType(field);
8908 GPBDataType keyDataType = field.mapKeyDataType;
8910 NSEnumerator *keys = [internal keyEnumerator];
8912 while ((aKey = [keys nextObject])) {
8913 NSNumber *aValue = internal[aKey];
8914 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
8915 msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
8916 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
8918 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
8919 result += tagSize * count;
8923 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
8924 asField:(GPBFieldDescriptor *)field {
8925 GPBDataType valueDataType = GPBGetFieldDataType(field);
8926 GPBDataType keyDataType = field.mapKeyDataType;
8927 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
8928 NSDictionary *internal = _dictionary;
8929 NSEnumerator *keys = [internal keyEnumerator];
8931 while ((aKey = [keys nextObject])) {
8932 NSNumber *aValue = internal[aKey];
8933 [outputStream writeInt32NoTag:tag];
8934 // Write the size of the message.
8935 NSString *unwrappedKey = aKey;
8936 uint64_t unwrappedValue = [aValue unsignedLongLongValue];
8937 size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
8938 msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
8939 [outputStream writeInt32NoTag:(int32_t)msgSize];
8940 // Write the fields.
8941 WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
8942 WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
8946 - (void)setGPBGenericValue:(GPBGenericValue *)value
8947 forGPBGenericValueKey:(GPBGenericValue *)key {
8948 [_dictionary setObject:@(value->valueUInt64) forKey:key->valueString];
8951 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
8952 [self enumerateKeysAndUInt64sUsingBlock:^(NSString *key, uint64_t value, BOOL *stop) {
8953 #pragma unused(stop)
8954 block(key, [NSString stringWithFormat:@"%llu", value]);
8958 - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(NSString *)key {
8959 NSNumber *wrapped = [_dictionary objectForKey:key];
8960 if (wrapped && value) {
8961 *value = [wrapped unsignedLongLongValue];
8963 return (wrapped != NULL);
8966 - (void)addEntriesFromDictionary:(GPBStringUInt64Dictionary *)otherDictionary {
8967 if (otherDictionary) {
8968 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
8970 GPBAutocreatedDictionaryModified(_autocreator, self);
8975 - (void)setUInt64:(uint64_t)value forKey:(NSString *)key {
8977 [NSException raise:NSInvalidArgumentException
8978 format:@"Attempting to add nil key to a Dictionary"];
8980 [_dictionary setObject:@(value) forKey:key];
8982 GPBAutocreatedDictionaryModified(_autocreator, self);
8986 - (void)removeUInt64ForKey:(NSString *)aKey {
8987 [_dictionary removeObjectForKey:aKey];
8991 [_dictionary removeAllObjects];
8996 #pragma mark - String -> Int64
8998 @implementation GPBStringInt64Dictionary {
9000 NSMutableDictionary *_dictionary;
9003 - (instancetype)init {
9004 return [self initWithInt64s:NULL forKeys:NULL count:0];
9007 - (instancetype)initWithInt64s:(const int64_t [])values
9008 forKeys:(const NSString * [])keys
9009 count:(NSUInteger)count {
9010 self = [super init];
9012 _dictionary = [[NSMutableDictionary alloc] init];
9013 if (count && values && keys) {
9014 for (NSUInteger i = 0; i < count; ++i) {
9016 [NSException raise:NSInvalidArgumentException
9017 format:@"Attempting to add nil key to a Dictionary"];
9019 [_dictionary setObject:@(values[i]) forKey:keys[i]];
9026 - (instancetype)initWithDictionary:(GPBStringInt64Dictionary *)dictionary {
9027 self = [self initWithInt64s:NULL forKeys:NULL count:0];
9030 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
9036 - (instancetype)initWithCapacity:(NSUInteger)numItems {
9037 #pragma unused(numItems)
9038 return [self initWithInt64s:NULL forKeys:NULL count:0];
9042 NSAssert(!_autocreator,
9043 @"%@: Autocreator must be cleared before release, autocreator: %@",
9044 [self class], _autocreator);
9045 [_dictionary release];
9049 - (instancetype)copyWithZone:(NSZone *)zone {
9050 return [[GPBStringInt64Dictionary allocWithZone:zone] initWithDictionary:self];
9053 - (BOOL)isEqual:(id)other {
9054 if (self == other) {
9057 if (![other isKindOfClass:[GPBStringInt64Dictionary class]]) {
9060 GPBStringInt64Dictionary *otherDictionary = other;
9061 return [_dictionary isEqual:otherDictionary->_dictionary];
9064 - (NSUInteger)hash {
9065 return _dictionary.count;
9068 - (NSString *)description {
9069 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
9072 - (NSUInteger)count {
9073 return _dictionary.count;
9076 - (void)enumerateKeysAndInt64sUsingBlock:
9077 (void (^)(NSString *key, int64_t value, BOOL *stop))block {
9079 NSDictionary *internal = _dictionary;
9080 NSEnumerator *keys = [internal keyEnumerator];
9082 while ((aKey = [keys nextObject])) {
9083 NSNumber *aValue = internal[aKey];
9084 block(aKey, [aValue longLongValue], &stop);
9091 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
9092 NSDictionary *internal = _dictionary;
9093 NSUInteger count = internal.count;
9098 GPBDataType valueDataType = GPBGetFieldDataType(field);
9099 GPBDataType keyDataType = field.mapKeyDataType;
9101 NSEnumerator *keys = [internal keyEnumerator];
9103 while ((aKey = [keys nextObject])) {
9104 NSNumber *aValue = internal[aKey];
9105 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
9106 msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
9107 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
9109 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
9110 result += tagSize * count;
9114 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
9115 asField:(GPBFieldDescriptor *)field {
9116 GPBDataType valueDataType = GPBGetFieldDataType(field);
9117 GPBDataType keyDataType = field.mapKeyDataType;
9118 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
9119 NSDictionary *internal = _dictionary;
9120 NSEnumerator *keys = [internal keyEnumerator];
9122 while ((aKey = [keys nextObject])) {
9123 NSNumber *aValue = internal[aKey];
9124 [outputStream writeInt32NoTag:tag];
9125 // Write the size of the message.
9126 NSString *unwrappedKey = aKey;
9127 int64_t unwrappedValue = [aValue longLongValue];
9128 size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
9129 msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
9130 [outputStream writeInt32NoTag:(int32_t)msgSize];
9131 // Write the fields.
9132 WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
9133 WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
9137 - (void)setGPBGenericValue:(GPBGenericValue *)value
9138 forGPBGenericValueKey:(GPBGenericValue *)key {
9139 [_dictionary setObject:@(value->valueInt64) forKey:key->valueString];
9142 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
9143 [self enumerateKeysAndInt64sUsingBlock:^(NSString *key, int64_t value, BOOL *stop) {
9144 #pragma unused(stop)
9145 block(key, [NSString stringWithFormat:@"%lld", value]);
9149 - (BOOL)getInt64:(nullable int64_t *)value forKey:(NSString *)key {
9150 NSNumber *wrapped = [_dictionary objectForKey:key];
9151 if (wrapped && value) {
9152 *value = [wrapped longLongValue];
9154 return (wrapped != NULL);
9157 - (void)addEntriesFromDictionary:(GPBStringInt64Dictionary *)otherDictionary {
9158 if (otherDictionary) {
9159 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
9161 GPBAutocreatedDictionaryModified(_autocreator, self);
9166 - (void)setInt64:(int64_t)value forKey:(NSString *)key {
9168 [NSException raise:NSInvalidArgumentException
9169 format:@"Attempting to add nil key to a Dictionary"];
9171 [_dictionary setObject:@(value) forKey:key];
9173 GPBAutocreatedDictionaryModified(_autocreator, self);
9177 - (void)removeInt64ForKey:(NSString *)aKey {
9178 [_dictionary removeObjectForKey:aKey];
9182 [_dictionary removeAllObjects];
9187 #pragma mark - String -> Bool
9189 @implementation GPBStringBoolDictionary {
9191 NSMutableDictionary *_dictionary;
9194 - (instancetype)init {
9195 return [self initWithBools:NULL forKeys:NULL count:0];
9198 - (instancetype)initWithBools:(const BOOL [])values
9199 forKeys:(const NSString * [])keys
9200 count:(NSUInteger)count {
9201 self = [super init];
9203 _dictionary = [[NSMutableDictionary alloc] init];
9204 if (count && values && keys) {
9205 for (NSUInteger i = 0; i < count; ++i) {
9207 [NSException raise:NSInvalidArgumentException
9208 format:@"Attempting to add nil key to a Dictionary"];
9210 [_dictionary setObject:@(values[i]) forKey:keys[i]];
9217 - (instancetype)initWithDictionary:(GPBStringBoolDictionary *)dictionary {
9218 self = [self initWithBools:NULL forKeys:NULL count:0];
9221 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
9227 - (instancetype)initWithCapacity:(NSUInteger)numItems {
9228 #pragma unused(numItems)
9229 return [self initWithBools:NULL forKeys:NULL count:0];
9233 NSAssert(!_autocreator,
9234 @"%@: Autocreator must be cleared before release, autocreator: %@",
9235 [self class], _autocreator);
9236 [_dictionary release];
9240 - (instancetype)copyWithZone:(NSZone *)zone {
9241 return [[GPBStringBoolDictionary allocWithZone:zone] initWithDictionary:self];
9244 - (BOOL)isEqual:(id)other {
9245 if (self == other) {
9248 if (![other isKindOfClass:[GPBStringBoolDictionary class]]) {
9251 GPBStringBoolDictionary *otherDictionary = other;
9252 return [_dictionary isEqual:otherDictionary->_dictionary];
9255 - (NSUInteger)hash {
9256 return _dictionary.count;
9259 - (NSString *)description {
9260 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
9263 - (NSUInteger)count {
9264 return _dictionary.count;
9267 - (void)enumerateKeysAndBoolsUsingBlock:
9268 (void (^)(NSString *key, BOOL value, BOOL *stop))block {
9270 NSDictionary *internal = _dictionary;
9271 NSEnumerator *keys = [internal keyEnumerator];
9273 while ((aKey = [keys nextObject])) {
9274 NSNumber *aValue = internal[aKey];
9275 block(aKey, [aValue boolValue], &stop);
9282 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
9283 NSDictionary *internal = _dictionary;
9284 NSUInteger count = internal.count;
9289 GPBDataType valueDataType = GPBGetFieldDataType(field);
9290 GPBDataType keyDataType = field.mapKeyDataType;
9292 NSEnumerator *keys = [internal keyEnumerator];
9294 while ((aKey = [keys nextObject])) {
9295 NSNumber *aValue = internal[aKey];
9296 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
9297 msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
9298 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
9300 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
9301 result += tagSize * count;
9305 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
9306 asField:(GPBFieldDescriptor *)field {
9307 GPBDataType valueDataType = GPBGetFieldDataType(field);
9308 GPBDataType keyDataType = field.mapKeyDataType;
9309 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
9310 NSDictionary *internal = _dictionary;
9311 NSEnumerator *keys = [internal keyEnumerator];
9313 while ((aKey = [keys nextObject])) {
9314 NSNumber *aValue = internal[aKey];
9315 [outputStream writeInt32NoTag:tag];
9316 // Write the size of the message.
9317 NSString *unwrappedKey = aKey;
9318 BOOL unwrappedValue = [aValue boolValue];
9319 size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
9320 msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
9321 [outputStream writeInt32NoTag:(int32_t)msgSize];
9322 // Write the fields.
9323 WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
9324 WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
9328 - (void)setGPBGenericValue:(GPBGenericValue *)value
9329 forGPBGenericValueKey:(GPBGenericValue *)key {
9330 [_dictionary setObject:@(value->valueBool) forKey:key->valueString];
9333 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
9334 [self enumerateKeysAndBoolsUsingBlock:^(NSString *key, BOOL value, BOOL *stop) {
9335 #pragma unused(stop)
9336 block(key, (value ? @"true" : @"false"));
9340 - (BOOL)getBool:(nullable BOOL *)value forKey:(NSString *)key {
9341 NSNumber *wrapped = [_dictionary objectForKey:key];
9342 if (wrapped && value) {
9343 *value = [wrapped boolValue];
9345 return (wrapped != NULL);
9348 - (void)addEntriesFromDictionary:(GPBStringBoolDictionary *)otherDictionary {
9349 if (otherDictionary) {
9350 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
9352 GPBAutocreatedDictionaryModified(_autocreator, self);
9357 - (void)setBool:(BOOL)value forKey:(NSString *)key {
9359 [NSException raise:NSInvalidArgumentException
9360 format:@"Attempting to add nil key to a Dictionary"];
9362 [_dictionary setObject:@(value) forKey:key];
9364 GPBAutocreatedDictionaryModified(_autocreator, self);
9368 - (void)removeBoolForKey:(NSString *)aKey {
9369 [_dictionary removeObjectForKey:aKey];
9373 [_dictionary removeAllObjects];
9378 #pragma mark - String -> Float
9380 @implementation GPBStringFloatDictionary {
9382 NSMutableDictionary *_dictionary;
9385 - (instancetype)init {
9386 return [self initWithFloats:NULL forKeys:NULL count:0];
9389 - (instancetype)initWithFloats:(const float [])values
9390 forKeys:(const NSString * [])keys
9391 count:(NSUInteger)count {
9392 self = [super init];
9394 _dictionary = [[NSMutableDictionary alloc] init];
9395 if (count && values && keys) {
9396 for (NSUInteger i = 0; i < count; ++i) {
9398 [NSException raise:NSInvalidArgumentException
9399 format:@"Attempting to add nil key to a Dictionary"];
9401 [_dictionary setObject:@(values[i]) forKey:keys[i]];
9408 - (instancetype)initWithDictionary:(GPBStringFloatDictionary *)dictionary {
9409 self = [self initWithFloats:NULL forKeys:NULL count:0];
9412 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
9418 - (instancetype)initWithCapacity:(NSUInteger)numItems {
9419 #pragma unused(numItems)
9420 return [self initWithFloats:NULL forKeys:NULL count:0];
9424 NSAssert(!_autocreator,
9425 @"%@: Autocreator must be cleared before release, autocreator: %@",
9426 [self class], _autocreator);
9427 [_dictionary release];
9431 - (instancetype)copyWithZone:(NSZone *)zone {
9432 return [[GPBStringFloatDictionary allocWithZone:zone] initWithDictionary:self];
9435 - (BOOL)isEqual:(id)other {
9436 if (self == other) {
9439 if (![other isKindOfClass:[GPBStringFloatDictionary class]]) {
9442 GPBStringFloatDictionary *otherDictionary = other;
9443 return [_dictionary isEqual:otherDictionary->_dictionary];
9446 - (NSUInteger)hash {
9447 return _dictionary.count;
9450 - (NSString *)description {
9451 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
9454 - (NSUInteger)count {
9455 return _dictionary.count;
9458 - (void)enumerateKeysAndFloatsUsingBlock:
9459 (void (^)(NSString *key, float value, BOOL *stop))block {
9461 NSDictionary *internal = _dictionary;
9462 NSEnumerator *keys = [internal keyEnumerator];
9464 while ((aKey = [keys nextObject])) {
9465 NSNumber *aValue = internal[aKey];
9466 block(aKey, [aValue floatValue], &stop);
9473 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
9474 NSDictionary *internal = _dictionary;
9475 NSUInteger count = internal.count;
9480 GPBDataType valueDataType = GPBGetFieldDataType(field);
9481 GPBDataType keyDataType = field.mapKeyDataType;
9483 NSEnumerator *keys = [internal keyEnumerator];
9485 while ((aKey = [keys nextObject])) {
9486 NSNumber *aValue = internal[aKey];
9487 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
9488 msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
9489 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
9491 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
9492 result += tagSize * count;
9496 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
9497 asField:(GPBFieldDescriptor *)field {
9498 GPBDataType valueDataType = GPBGetFieldDataType(field);
9499 GPBDataType keyDataType = field.mapKeyDataType;
9500 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
9501 NSDictionary *internal = _dictionary;
9502 NSEnumerator *keys = [internal keyEnumerator];
9504 while ((aKey = [keys nextObject])) {
9505 NSNumber *aValue = internal[aKey];
9506 [outputStream writeInt32NoTag:tag];
9507 // Write the size of the message.
9508 NSString *unwrappedKey = aKey;
9509 float unwrappedValue = [aValue floatValue];
9510 size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
9511 msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
9512 [outputStream writeInt32NoTag:(int32_t)msgSize];
9513 // Write the fields.
9514 WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
9515 WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
9519 - (void)setGPBGenericValue:(GPBGenericValue *)value
9520 forGPBGenericValueKey:(GPBGenericValue *)key {
9521 [_dictionary setObject:@(value->valueFloat) forKey:key->valueString];
9524 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
9525 [self enumerateKeysAndFloatsUsingBlock:^(NSString *key, float value, BOOL *stop) {
9526 #pragma unused(stop)
9527 block(key, [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
9531 - (BOOL)getFloat:(nullable float *)value forKey:(NSString *)key {
9532 NSNumber *wrapped = [_dictionary objectForKey:key];
9533 if (wrapped && value) {
9534 *value = [wrapped floatValue];
9536 return (wrapped != NULL);
9539 - (void)addEntriesFromDictionary:(GPBStringFloatDictionary *)otherDictionary {
9540 if (otherDictionary) {
9541 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
9543 GPBAutocreatedDictionaryModified(_autocreator, self);
9548 - (void)setFloat:(float)value forKey:(NSString *)key {
9550 [NSException raise:NSInvalidArgumentException
9551 format:@"Attempting to add nil key to a Dictionary"];
9553 [_dictionary setObject:@(value) forKey:key];
9555 GPBAutocreatedDictionaryModified(_autocreator, self);
9559 - (void)removeFloatForKey:(NSString *)aKey {
9560 [_dictionary removeObjectForKey:aKey];
9564 [_dictionary removeAllObjects];
9569 #pragma mark - String -> Double
9571 @implementation GPBStringDoubleDictionary {
9573 NSMutableDictionary *_dictionary;
9576 - (instancetype)init {
9577 return [self initWithDoubles:NULL forKeys:NULL count:0];
9580 - (instancetype)initWithDoubles:(const double [])values
9581 forKeys:(const NSString * [])keys
9582 count:(NSUInteger)count {
9583 self = [super init];
9585 _dictionary = [[NSMutableDictionary alloc] init];
9586 if (count && values && keys) {
9587 for (NSUInteger i = 0; i < count; ++i) {
9589 [NSException raise:NSInvalidArgumentException
9590 format:@"Attempting to add nil key to a Dictionary"];
9592 [_dictionary setObject:@(values[i]) forKey:keys[i]];
9599 - (instancetype)initWithDictionary:(GPBStringDoubleDictionary *)dictionary {
9600 self = [self initWithDoubles:NULL forKeys:NULL count:0];
9603 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
9609 - (instancetype)initWithCapacity:(NSUInteger)numItems {
9610 #pragma unused(numItems)
9611 return [self initWithDoubles:NULL forKeys:NULL count:0];
9615 NSAssert(!_autocreator,
9616 @"%@: Autocreator must be cleared before release, autocreator: %@",
9617 [self class], _autocreator);
9618 [_dictionary release];
9622 - (instancetype)copyWithZone:(NSZone *)zone {
9623 return [[GPBStringDoubleDictionary allocWithZone:zone] initWithDictionary:self];
9626 - (BOOL)isEqual:(id)other {
9627 if (self == other) {
9630 if (![other isKindOfClass:[GPBStringDoubleDictionary class]]) {
9633 GPBStringDoubleDictionary *otherDictionary = other;
9634 return [_dictionary isEqual:otherDictionary->_dictionary];
9637 - (NSUInteger)hash {
9638 return _dictionary.count;
9641 - (NSString *)description {
9642 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
9645 - (NSUInteger)count {
9646 return _dictionary.count;
9649 - (void)enumerateKeysAndDoublesUsingBlock:
9650 (void (^)(NSString *key, double value, BOOL *stop))block {
9652 NSDictionary *internal = _dictionary;
9653 NSEnumerator *keys = [internal keyEnumerator];
9655 while ((aKey = [keys nextObject])) {
9656 NSNumber *aValue = internal[aKey];
9657 block(aKey, [aValue doubleValue], &stop);
9664 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
9665 NSDictionary *internal = _dictionary;
9666 NSUInteger count = internal.count;
9671 GPBDataType valueDataType = GPBGetFieldDataType(field);
9672 GPBDataType keyDataType = field.mapKeyDataType;
9674 NSEnumerator *keys = [internal keyEnumerator];
9676 while ((aKey = [keys nextObject])) {
9677 NSNumber *aValue = internal[aKey];
9678 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
9679 msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
9680 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
9682 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
9683 result += tagSize * count;
9687 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
9688 asField:(GPBFieldDescriptor *)field {
9689 GPBDataType valueDataType = GPBGetFieldDataType(field);
9690 GPBDataType keyDataType = field.mapKeyDataType;
9691 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
9692 NSDictionary *internal = _dictionary;
9693 NSEnumerator *keys = [internal keyEnumerator];
9695 while ((aKey = [keys nextObject])) {
9696 NSNumber *aValue = internal[aKey];
9697 [outputStream writeInt32NoTag:tag];
9698 // Write the size of the message.
9699 NSString *unwrappedKey = aKey;
9700 double unwrappedValue = [aValue doubleValue];
9701 size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
9702 msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
9703 [outputStream writeInt32NoTag:(int32_t)msgSize];
9704 // Write the fields.
9705 WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
9706 WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
9710 - (void)setGPBGenericValue:(GPBGenericValue *)value
9711 forGPBGenericValueKey:(GPBGenericValue *)key {
9712 [_dictionary setObject:@(value->valueDouble) forKey:key->valueString];
9715 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
9716 [self enumerateKeysAndDoublesUsingBlock:^(NSString *key, double value, BOOL *stop) {
9717 #pragma unused(stop)
9718 block(key, [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
9722 - (BOOL)getDouble:(nullable double *)value forKey:(NSString *)key {
9723 NSNumber *wrapped = [_dictionary objectForKey:key];
9724 if (wrapped && value) {
9725 *value = [wrapped doubleValue];
9727 return (wrapped != NULL);
9730 - (void)addEntriesFromDictionary:(GPBStringDoubleDictionary *)otherDictionary {
9731 if (otherDictionary) {
9732 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
9734 GPBAutocreatedDictionaryModified(_autocreator, self);
9739 - (void)setDouble:(double)value forKey:(NSString *)key {
9741 [NSException raise:NSInvalidArgumentException
9742 format:@"Attempting to add nil key to a Dictionary"];
9744 [_dictionary setObject:@(value) forKey:key];
9746 GPBAutocreatedDictionaryModified(_autocreator, self);
9750 - (void)removeDoubleForKey:(NSString *)aKey {
9751 [_dictionary removeObjectForKey:aKey];
9755 [_dictionary removeAllObjects];
9760 #pragma mark - String -> Enum
9762 @implementation GPBStringEnumDictionary {
9764 NSMutableDictionary *_dictionary;
9765 GPBEnumValidationFunc _validationFunc;
9768 @synthesize validationFunc = _validationFunc;
9770 - (instancetype)init {
9771 return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
9774 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
9775 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
9778 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
9779 rawValues:(const int32_t [])rawValues
9780 forKeys:(const NSString * [])keys
9781 count:(NSUInteger)count {
9782 self = [super init];
9784 _dictionary = [[NSMutableDictionary alloc] init];
9785 _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
9786 if (count && rawValues && keys) {
9787 for (NSUInteger i = 0; i < count; ++i) {
9789 [NSException raise:NSInvalidArgumentException
9790 format:@"Attempting to add nil key to a Dictionary"];
9792 [_dictionary setObject:@(rawValues[i]) forKey:keys[i]];
9799 - (instancetype)initWithDictionary:(GPBStringEnumDictionary *)dictionary {
9800 self = [self initWithValidationFunction:dictionary.validationFunc
9806 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
9812 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
9813 capacity:(NSUInteger)numItems {
9814 #pragma unused(numItems)
9815 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
9819 NSAssert(!_autocreator,
9820 @"%@: Autocreator must be cleared before release, autocreator: %@",
9821 [self class], _autocreator);
9822 [_dictionary release];
9826 - (instancetype)copyWithZone:(NSZone *)zone {
9827 return [[GPBStringEnumDictionary allocWithZone:zone] initWithDictionary:self];
9830 - (BOOL)isEqual:(id)other {
9831 if (self == other) {
9834 if (![other isKindOfClass:[GPBStringEnumDictionary class]]) {
9837 GPBStringEnumDictionary *otherDictionary = other;
9838 return [_dictionary isEqual:otherDictionary->_dictionary];
9841 - (NSUInteger)hash {
9842 return _dictionary.count;
9845 - (NSString *)description {
9846 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
9849 - (NSUInteger)count {
9850 return _dictionary.count;
9853 - (void)enumerateKeysAndRawValuesUsingBlock:
9854 (void (^)(NSString *key, int32_t value, BOOL *stop))block {
9856 NSDictionary *internal = _dictionary;
9857 NSEnumerator *keys = [internal keyEnumerator];
9859 while ((aKey = [keys nextObject])) {
9860 NSNumber *aValue = internal[aKey];
9861 block(aKey, [aValue intValue], &stop);
9868 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
9869 NSDictionary *internal = _dictionary;
9870 NSUInteger count = internal.count;
9875 GPBDataType valueDataType = GPBGetFieldDataType(field);
9876 GPBDataType keyDataType = field.mapKeyDataType;
9878 NSEnumerator *keys = [internal keyEnumerator];
9880 while ((aKey = [keys nextObject])) {
9881 NSNumber *aValue = internal[aKey];
9882 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
9883 msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
9884 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
9886 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
9887 result += tagSize * count;
9891 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
9892 asField:(GPBFieldDescriptor *)field {
9893 GPBDataType valueDataType = GPBGetFieldDataType(field);
9894 GPBDataType keyDataType = field.mapKeyDataType;
9895 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
9896 NSDictionary *internal = _dictionary;
9897 NSEnumerator *keys = [internal keyEnumerator];
9899 while ((aKey = [keys nextObject])) {
9900 NSNumber *aValue = internal[aKey];
9901 [outputStream writeInt32NoTag:tag];
9902 // Write the size of the message.
9903 NSString *unwrappedKey = aKey;
9904 int32_t unwrappedValue = [aValue intValue];
9905 size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
9906 msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
9907 [outputStream writeInt32NoTag:(int32_t)msgSize];
9908 // Write the fields.
9909 WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
9910 WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
9914 - (NSData *)serializedDataForUnknownValue:(int32_t)value
9915 forKey:(GPBGenericValue *)key
9916 keyDataType:(GPBDataType)keyDataType {
9917 size_t msgSize = ComputeDictStringFieldSize(key->valueString, kMapKeyFieldNumber, keyDataType);
9918 msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
9919 NSMutableData *data = [NSMutableData dataWithLength:msgSize];
9920 GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
9921 WriteDictStringField(outputStream, key->valueString, kMapKeyFieldNumber, keyDataType);
9922 WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
9923 [outputStream release];
9926 - (void)setGPBGenericValue:(GPBGenericValue *)value
9927 forGPBGenericValueKey:(GPBGenericValue *)key {
9928 [_dictionary setObject:@(value->valueEnum) forKey:key->valueString];
9931 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
9932 [self enumerateKeysAndRawValuesUsingBlock:^(NSString *key, int32_t value, BOOL *stop) {
9933 #pragma unused(stop)
9934 block(key, @(value));
9938 - (BOOL)getEnum:(int32_t *)value forKey:(NSString *)key {
9939 NSNumber *wrapped = [_dictionary objectForKey:key];
9940 if (wrapped && value) {
9941 int32_t result = [wrapped intValue];
9942 if (!_validationFunc(result)) {
9943 result = kGPBUnrecognizedEnumeratorValue;
9947 return (wrapped != NULL);
9950 - (BOOL)getRawValue:(int32_t *)rawValue forKey:(NSString *)key {
9951 NSNumber *wrapped = [_dictionary objectForKey:key];
9952 if (wrapped && rawValue) {
9953 *rawValue = [wrapped intValue];
9955 return (wrapped != NULL);
9958 - (void)enumerateKeysAndEnumsUsingBlock:
9959 (void (^)(NSString *key, int32_t value, BOOL *stop))block {
9960 GPBEnumValidationFunc func = _validationFunc;
9962 NSEnumerator *keys = [_dictionary keyEnumerator];
9964 while ((aKey = [keys nextObject])) {
9965 NSNumber *aValue = _dictionary[aKey];
9966 int32_t unwrapped = [aValue intValue];
9967 if (!func(unwrapped)) {
9968 unwrapped = kGPBUnrecognizedEnumeratorValue;
9970 block(aKey, unwrapped, &stop);
9977 - (void)addRawEntriesFromDictionary:(GPBStringEnumDictionary *)otherDictionary {
9978 if (otherDictionary) {
9979 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
9981 GPBAutocreatedDictionaryModified(_autocreator, self);
9986 - (void)setRawValue:(int32_t)value forKey:(NSString *)key {
9988 [NSException raise:NSInvalidArgumentException
9989 format:@"Attempting to add nil key to a Dictionary"];
9991 [_dictionary setObject:@(value) forKey:key];
9993 GPBAutocreatedDictionaryModified(_autocreator, self);
9997 - (void)removeEnumForKey:(NSString *)aKey {
9998 [_dictionary removeObjectForKey:aKey];
10001 - (void)removeAll {
10002 [_dictionary removeAllObjects];
10005 - (void)setEnum:(int32_t)value forKey:(NSString *)key {
10007 [NSException raise:NSInvalidArgumentException
10008 format:@"Attempting to add nil key to a Dictionary"];
10010 if (!_validationFunc(value)) {
10011 [NSException raise:NSInvalidArgumentException
10012 format:@"GPBStringEnumDictionary: Attempt to set an unknown enum value (%d)",
10016 [_dictionary setObject:@(value) forKey:key];
10017 if (_autocreator) {
10018 GPBAutocreatedDictionaryModified(_autocreator, self);
10024 //%PDDM-EXPAND-END (5 expansions)
10027 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(UInt32, uint32_t)
10028 // This block of code is generated, do not edit it directly.
10030 #pragma mark - Bool -> UInt32
10032 @implementation GPBBoolUInt32Dictionary {
10034 uint32_t _values[2];
10038 - (instancetype)init {
10039 return [self initWithUInt32s:NULL forKeys:NULL count:0];
10042 - (instancetype)initWithUInt32s:(const uint32_t [])values
10043 forKeys:(const BOOL [])keys
10044 count:(NSUInteger)count {
10045 self = [super init];
10047 for (NSUInteger i = 0; i < count; ++i) {
10048 int idx = keys[i] ? 1 : 0;
10049 _values[idx] = values[i];
10050 _valueSet[idx] = YES;
10056 - (instancetype)initWithDictionary:(GPBBoolUInt32Dictionary *)dictionary {
10057 self = [self initWithUInt32s:NULL forKeys:NULL count:0];
10060 for (int i = 0; i < 2; ++i) {
10061 if (dictionary->_valueSet[i]) {
10062 _values[i] = dictionary->_values[i];
10063 _valueSet[i] = YES;
10071 - (instancetype)initWithCapacity:(NSUInteger)numItems {
10072 #pragma unused(numItems)
10073 return [self initWithUInt32s:NULL forKeys:NULL count:0];
10076 #if !defined(NS_BLOCK_ASSERTIONS)
10078 NSAssert(!_autocreator,
10079 @"%@: Autocreator must be cleared before release, autocreator: %@",
10080 [self class], _autocreator);
10083 #endif // !defined(NS_BLOCK_ASSERTIONS)
10085 - (instancetype)copyWithZone:(NSZone *)zone {
10086 return [[GPBBoolUInt32Dictionary allocWithZone:zone] initWithDictionary:self];
10089 - (BOOL)isEqual:(id)other {
10090 if (self == other) {
10093 if (![other isKindOfClass:[GPBBoolUInt32Dictionary class]]) {
10096 GPBBoolUInt32Dictionary *otherDictionary = other;
10097 if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
10098 (_valueSet[1] != otherDictionary->_valueSet[1])) {
10101 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
10102 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
10108 - (NSUInteger)hash {
10109 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
10112 - (NSString *)description {
10113 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
10114 if (_valueSet[0]) {
10115 [result appendFormat:@"NO: %u", _values[0]];
10117 if (_valueSet[1]) {
10118 [result appendFormat:@"YES: %u", _values[1]];
10120 [result appendString:@" }"];
10124 - (NSUInteger)count {
10125 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
10128 - (BOOL)getUInt32:(uint32_t *)value forKey:(BOOL)key {
10129 int idx = (key ? 1 : 0);
10130 if (_valueSet[idx]) {
10132 *value = _values[idx];
10139 - (void)setGPBGenericValue:(GPBGenericValue *)value
10140 forGPBGenericValueKey:(GPBGenericValue *)key {
10141 int idx = (key->valueBool ? 1 : 0);
10142 _values[idx] = value->valueUInt32;
10143 _valueSet[idx] = YES;
10146 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
10147 if (_valueSet[0]) {
10148 block(@"false", [NSString stringWithFormat:@"%u", _values[0]]);
10150 if (_valueSet[1]) {
10151 block(@"true", [NSString stringWithFormat:@"%u", _values[1]]);
10155 - (void)enumerateKeysAndUInt32sUsingBlock:
10156 (void (^)(BOOL key, uint32_t value, BOOL *stop))block {
10158 if (_valueSet[0]) {
10159 block(NO, _values[0], &stop);
10161 if (!stop && _valueSet[1]) {
10162 block(YES, _values[1], &stop);
10166 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
10167 GPBDataType valueDataType = GPBGetFieldDataType(field);
10168 NSUInteger count = 0;
10170 for (int i = 0; i < 2; ++i) {
10171 if (_valueSet[i]) {
10173 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10174 msgSize += ComputeDictUInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
10175 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
10178 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
10179 result += tagSize * count;
10183 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
10184 asField:(GPBFieldDescriptor *)field {
10185 GPBDataType valueDataType = GPBGetFieldDataType(field);
10186 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
10187 for (int i = 0; i < 2; ++i) {
10188 if (_valueSet[i]) {
10190 [outputStream writeInt32NoTag:tag];
10191 // Write the size of the message.
10192 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10193 msgSize += ComputeDictUInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
10194 [outputStream writeInt32NoTag:(int32_t)msgSize];
10195 // Write the fields.
10196 WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10197 WriteDictUInt32Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
10202 - (void)addEntriesFromDictionary:(GPBBoolUInt32Dictionary *)otherDictionary {
10203 if (otherDictionary) {
10204 for (int i = 0; i < 2; ++i) {
10205 if (otherDictionary->_valueSet[i]) {
10206 _valueSet[i] = YES;
10207 _values[i] = otherDictionary->_values[i];
10210 if (_autocreator) {
10211 GPBAutocreatedDictionaryModified(_autocreator, self);
10216 - (void)setUInt32:(uint32_t)value forKey:(BOOL)key {
10217 int idx = (key ? 1 : 0);
10218 _values[idx] = value;
10219 _valueSet[idx] = YES;
10220 if (_autocreator) {
10221 GPBAutocreatedDictionaryModified(_autocreator, self);
10225 - (void)removeUInt32ForKey:(BOOL)aKey {
10226 _valueSet[aKey ? 1 : 0] = NO;
10229 - (void)removeAll {
10236 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Int32, int32_t)
10237 // This block of code is generated, do not edit it directly.
10239 #pragma mark - Bool -> Int32
10241 @implementation GPBBoolInt32Dictionary {
10243 int32_t _values[2];
10247 - (instancetype)init {
10248 return [self initWithInt32s:NULL forKeys:NULL count:0];
10251 - (instancetype)initWithInt32s:(const int32_t [])values
10252 forKeys:(const BOOL [])keys
10253 count:(NSUInteger)count {
10254 self = [super init];
10256 for (NSUInteger i = 0; i < count; ++i) {
10257 int idx = keys[i] ? 1 : 0;
10258 _values[idx] = values[i];
10259 _valueSet[idx] = YES;
10265 - (instancetype)initWithDictionary:(GPBBoolInt32Dictionary *)dictionary {
10266 self = [self initWithInt32s:NULL forKeys:NULL count:0];
10269 for (int i = 0; i < 2; ++i) {
10270 if (dictionary->_valueSet[i]) {
10271 _values[i] = dictionary->_values[i];
10272 _valueSet[i] = YES;
10280 - (instancetype)initWithCapacity:(NSUInteger)numItems {
10281 #pragma unused(numItems)
10282 return [self initWithInt32s:NULL forKeys:NULL count:0];
10285 #if !defined(NS_BLOCK_ASSERTIONS)
10287 NSAssert(!_autocreator,
10288 @"%@: Autocreator must be cleared before release, autocreator: %@",
10289 [self class], _autocreator);
10292 #endif // !defined(NS_BLOCK_ASSERTIONS)
10294 - (instancetype)copyWithZone:(NSZone *)zone {
10295 return [[GPBBoolInt32Dictionary allocWithZone:zone] initWithDictionary:self];
10298 - (BOOL)isEqual:(id)other {
10299 if (self == other) {
10302 if (![other isKindOfClass:[GPBBoolInt32Dictionary class]]) {
10305 GPBBoolInt32Dictionary *otherDictionary = other;
10306 if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
10307 (_valueSet[1] != otherDictionary->_valueSet[1])) {
10310 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
10311 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
10317 - (NSUInteger)hash {
10318 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
10321 - (NSString *)description {
10322 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
10323 if (_valueSet[0]) {
10324 [result appendFormat:@"NO: %d", _values[0]];
10326 if (_valueSet[1]) {
10327 [result appendFormat:@"YES: %d", _values[1]];
10329 [result appendString:@" }"];
10333 - (NSUInteger)count {
10334 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
10337 - (BOOL)getInt32:(int32_t *)value forKey:(BOOL)key {
10338 int idx = (key ? 1 : 0);
10339 if (_valueSet[idx]) {
10341 *value = _values[idx];
10348 - (void)setGPBGenericValue:(GPBGenericValue *)value
10349 forGPBGenericValueKey:(GPBGenericValue *)key {
10350 int idx = (key->valueBool ? 1 : 0);
10351 _values[idx] = value->valueInt32;
10352 _valueSet[idx] = YES;
10355 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
10356 if (_valueSet[0]) {
10357 block(@"false", [NSString stringWithFormat:@"%d", _values[0]]);
10359 if (_valueSet[1]) {
10360 block(@"true", [NSString stringWithFormat:@"%d", _values[1]]);
10364 - (void)enumerateKeysAndInt32sUsingBlock:
10365 (void (^)(BOOL key, int32_t value, BOOL *stop))block {
10367 if (_valueSet[0]) {
10368 block(NO, _values[0], &stop);
10370 if (!stop && _valueSet[1]) {
10371 block(YES, _values[1], &stop);
10375 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
10376 GPBDataType valueDataType = GPBGetFieldDataType(field);
10377 NSUInteger count = 0;
10379 for (int i = 0; i < 2; ++i) {
10380 if (_valueSet[i]) {
10382 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10383 msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
10384 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
10387 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
10388 result += tagSize * count;
10392 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
10393 asField:(GPBFieldDescriptor *)field {
10394 GPBDataType valueDataType = GPBGetFieldDataType(field);
10395 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
10396 for (int i = 0; i < 2; ++i) {
10397 if (_valueSet[i]) {
10399 [outputStream writeInt32NoTag:tag];
10400 // Write the size of the message.
10401 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10402 msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
10403 [outputStream writeInt32NoTag:(int32_t)msgSize];
10404 // Write the fields.
10405 WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10406 WriteDictInt32Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
10411 - (void)addEntriesFromDictionary:(GPBBoolInt32Dictionary *)otherDictionary {
10412 if (otherDictionary) {
10413 for (int i = 0; i < 2; ++i) {
10414 if (otherDictionary->_valueSet[i]) {
10415 _valueSet[i] = YES;
10416 _values[i] = otherDictionary->_values[i];
10419 if (_autocreator) {
10420 GPBAutocreatedDictionaryModified(_autocreator, self);
10425 - (void)setInt32:(int32_t)value forKey:(BOOL)key {
10426 int idx = (key ? 1 : 0);
10427 _values[idx] = value;
10428 _valueSet[idx] = YES;
10429 if (_autocreator) {
10430 GPBAutocreatedDictionaryModified(_autocreator, self);
10434 - (void)removeInt32ForKey:(BOOL)aKey {
10435 _valueSet[aKey ? 1 : 0] = NO;
10438 - (void)removeAll {
10445 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(UInt64, uint64_t)
10446 // This block of code is generated, do not edit it directly.
10448 #pragma mark - Bool -> UInt64
10450 @implementation GPBBoolUInt64Dictionary {
10452 uint64_t _values[2];
10456 - (instancetype)init {
10457 return [self initWithUInt64s:NULL forKeys:NULL count:0];
10460 - (instancetype)initWithUInt64s:(const uint64_t [])values
10461 forKeys:(const BOOL [])keys
10462 count:(NSUInteger)count {
10463 self = [super init];
10465 for (NSUInteger i = 0; i < count; ++i) {
10466 int idx = keys[i] ? 1 : 0;
10467 _values[idx] = values[i];
10468 _valueSet[idx] = YES;
10474 - (instancetype)initWithDictionary:(GPBBoolUInt64Dictionary *)dictionary {
10475 self = [self initWithUInt64s:NULL forKeys:NULL count:0];
10478 for (int i = 0; i < 2; ++i) {
10479 if (dictionary->_valueSet[i]) {
10480 _values[i] = dictionary->_values[i];
10481 _valueSet[i] = YES;
10489 - (instancetype)initWithCapacity:(NSUInteger)numItems {
10490 #pragma unused(numItems)
10491 return [self initWithUInt64s:NULL forKeys:NULL count:0];
10494 #if !defined(NS_BLOCK_ASSERTIONS)
10496 NSAssert(!_autocreator,
10497 @"%@: Autocreator must be cleared before release, autocreator: %@",
10498 [self class], _autocreator);
10501 #endif // !defined(NS_BLOCK_ASSERTIONS)
10503 - (instancetype)copyWithZone:(NSZone *)zone {
10504 return [[GPBBoolUInt64Dictionary allocWithZone:zone] initWithDictionary:self];
10507 - (BOOL)isEqual:(id)other {
10508 if (self == other) {
10511 if (![other isKindOfClass:[GPBBoolUInt64Dictionary class]]) {
10514 GPBBoolUInt64Dictionary *otherDictionary = other;
10515 if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
10516 (_valueSet[1] != otherDictionary->_valueSet[1])) {
10519 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
10520 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
10526 - (NSUInteger)hash {
10527 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
10530 - (NSString *)description {
10531 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
10532 if (_valueSet[0]) {
10533 [result appendFormat:@"NO: %llu", _values[0]];
10535 if (_valueSet[1]) {
10536 [result appendFormat:@"YES: %llu", _values[1]];
10538 [result appendString:@" }"];
10542 - (NSUInteger)count {
10543 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
10546 - (BOOL)getUInt64:(uint64_t *)value forKey:(BOOL)key {
10547 int idx = (key ? 1 : 0);
10548 if (_valueSet[idx]) {
10550 *value = _values[idx];
10557 - (void)setGPBGenericValue:(GPBGenericValue *)value
10558 forGPBGenericValueKey:(GPBGenericValue *)key {
10559 int idx = (key->valueBool ? 1 : 0);
10560 _values[idx] = value->valueUInt64;
10561 _valueSet[idx] = YES;
10564 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
10565 if (_valueSet[0]) {
10566 block(@"false", [NSString stringWithFormat:@"%llu", _values[0]]);
10568 if (_valueSet[1]) {
10569 block(@"true", [NSString stringWithFormat:@"%llu", _values[1]]);
10573 - (void)enumerateKeysAndUInt64sUsingBlock:
10574 (void (^)(BOOL key, uint64_t value, BOOL *stop))block {
10576 if (_valueSet[0]) {
10577 block(NO, _values[0], &stop);
10579 if (!stop && _valueSet[1]) {
10580 block(YES, _values[1], &stop);
10584 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
10585 GPBDataType valueDataType = GPBGetFieldDataType(field);
10586 NSUInteger count = 0;
10588 for (int i = 0; i < 2; ++i) {
10589 if (_valueSet[i]) {
10591 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10592 msgSize += ComputeDictUInt64FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
10593 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
10596 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
10597 result += tagSize * count;
10601 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
10602 asField:(GPBFieldDescriptor *)field {
10603 GPBDataType valueDataType = GPBGetFieldDataType(field);
10604 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
10605 for (int i = 0; i < 2; ++i) {
10606 if (_valueSet[i]) {
10608 [outputStream writeInt32NoTag:tag];
10609 // Write the size of the message.
10610 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10611 msgSize += ComputeDictUInt64FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
10612 [outputStream writeInt32NoTag:(int32_t)msgSize];
10613 // Write the fields.
10614 WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10615 WriteDictUInt64Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
10620 - (void)addEntriesFromDictionary:(GPBBoolUInt64Dictionary *)otherDictionary {
10621 if (otherDictionary) {
10622 for (int i = 0; i < 2; ++i) {
10623 if (otherDictionary->_valueSet[i]) {
10624 _valueSet[i] = YES;
10625 _values[i] = otherDictionary->_values[i];
10628 if (_autocreator) {
10629 GPBAutocreatedDictionaryModified(_autocreator, self);
10634 - (void)setUInt64:(uint64_t)value forKey:(BOOL)key {
10635 int idx = (key ? 1 : 0);
10636 _values[idx] = value;
10637 _valueSet[idx] = YES;
10638 if (_autocreator) {
10639 GPBAutocreatedDictionaryModified(_autocreator, self);
10643 - (void)removeUInt64ForKey:(BOOL)aKey {
10644 _valueSet[aKey ? 1 : 0] = NO;
10647 - (void)removeAll {
10654 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Int64, int64_t)
10655 // This block of code is generated, do not edit it directly.
10657 #pragma mark - Bool -> Int64
10659 @implementation GPBBoolInt64Dictionary {
10661 int64_t _values[2];
10665 - (instancetype)init {
10666 return [self initWithInt64s:NULL forKeys:NULL count:0];
10669 - (instancetype)initWithInt64s:(const int64_t [])values
10670 forKeys:(const BOOL [])keys
10671 count:(NSUInteger)count {
10672 self = [super init];
10674 for (NSUInteger i = 0; i < count; ++i) {
10675 int idx = keys[i] ? 1 : 0;
10676 _values[idx] = values[i];
10677 _valueSet[idx] = YES;
10683 - (instancetype)initWithDictionary:(GPBBoolInt64Dictionary *)dictionary {
10684 self = [self initWithInt64s:NULL forKeys:NULL count:0];
10687 for (int i = 0; i < 2; ++i) {
10688 if (dictionary->_valueSet[i]) {
10689 _values[i] = dictionary->_values[i];
10690 _valueSet[i] = YES;
10698 - (instancetype)initWithCapacity:(NSUInteger)numItems {
10699 #pragma unused(numItems)
10700 return [self initWithInt64s:NULL forKeys:NULL count:0];
10703 #if !defined(NS_BLOCK_ASSERTIONS)
10705 NSAssert(!_autocreator,
10706 @"%@: Autocreator must be cleared before release, autocreator: %@",
10707 [self class], _autocreator);
10710 #endif // !defined(NS_BLOCK_ASSERTIONS)
10712 - (instancetype)copyWithZone:(NSZone *)zone {
10713 return [[GPBBoolInt64Dictionary allocWithZone:zone] initWithDictionary:self];
10716 - (BOOL)isEqual:(id)other {
10717 if (self == other) {
10720 if (![other isKindOfClass:[GPBBoolInt64Dictionary class]]) {
10723 GPBBoolInt64Dictionary *otherDictionary = other;
10724 if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
10725 (_valueSet[1] != otherDictionary->_valueSet[1])) {
10728 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
10729 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
10735 - (NSUInteger)hash {
10736 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
10739 - (NSString *)description {
10740 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
10741 if (_valueSet[0]) {
10742 [result appendFormat:@"NO: %lld", _values[0]];
10744 if (_valueSet[1]) {
10745 [result appendFormat:@"YES: %lld", _values[1]];
10747 [result appendString:@" }"];
10751 - (NSUInteger)count {
10752 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
10755 - (BOOL)getInt64:(int64_t *)value forKey:(BOOL)key {
10756 int idx = (key ? 1 : 0);
10757 if (_valueSet[idx]) {
10759 *value = _values[idx];
10766 - (void)setGPBGenericValue:(GPBGenericValue *)value
10767 forGPBGenericValueKey:(GPBGenericValue *)key {
10768 int idx = (key->valueBool ? 1 : 0);
10769 _values[idx] = value->valueInt64;
10770 _valueSet[idx] = YES;
10773 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
10774 if (_valueSet[0]) {
10775 block(@"false", [NSString stringWithFormat:@"%lld", _values[0]]);
10777 if (_valueSet[1]) {
10778 block(@"true", [NSString stringWithFormat:@"%lld", _values[1]]);
10782 - (void)enumerateKeysAndInt64sUsingBlock:
10783 (void (^)(BOOL key, int64_t value, BOOL *stop))block {
10785 if (_valueSet[0]) {
10786 block(NO, _values[0], &stop);
10788 if (!stop && _valueSet[1]) {
10789 block(YES, _values[1], &stop);
10793 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
10794 GPBDataType valueDataType = GPBGetFieldDataType(field);
10795 NSUInteger count = 0;
10797 for (int i = 0; i < 2; ++i) {
10798 if (_valueSet[i]) {
10800 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10801 msgSize += ComputeDictInt64FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
10802 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
10805 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
10806 result += tagSize * count;
10810 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
10811 asField:(GPBFieldDescriptor *)field {
10812 GPBDataType valueDataType = GPBGetFieldDataType(field);
10813 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
10814 for (int i = 0; i < 2; ++i) {
10815 if (_valueSet[i]) {
10817 [outputStream writeInt32NoTag:tag];
10818 // Write the size of the message.
10819 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10820 msgSize += ComputeDictInt64FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
10821 [outputStream writeInt32NoTag:(int32_t)msgSize];
10822 // Write the fields.
10823 WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10824 WriteDictInt64Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
10829 - (void)addEntriesFromDictionary:(GPBBoolInt64Dictionary *)otherDictionary {
10830 if (otherDictionary) {
10831 for (int i = 0; i < 2; ++i) {
10832 if (otherDictionary->_valueSet[i]) {
10833 _valueSet[i] = YES;
10834 _values[i] = otherDictionary->_values[i];
10837 if (_autocreator) {
10838 GPBAutocreatedDictionaryModified(_autocreator, self);
10843 - (void)setInt64:(int64_t)value forKey:(BOOL)key {
10844 int idx = (key ? 1 : 0);
10845 _values[idx] = value;
10846 _valueSet[idx] = YES;
10847 if (_autocreator) {
10848 GPBAutocreatedDictionaryModified(_autocreator, self);
10852 - (void)removeInt64ForKey:(BOOL)aKey {
10853 _valueSet[aKey ? 1 : 0] = NO;
10856 - (void)removeAll {
10863 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Bool, BOOL)
10864 // This block of code is generated, do not edit it directly.
10866 #pragma mark - Bool -> Bool
10868 @implementation GPBBoolBoolDictionary {
10874 - (instancetype)init {
10875 return [self initWithBools:NULL forKeys:NULL count:0];
10878 - (instancetype)initWithBools:(const BOOL [])values
10879 forKeys:(const BOOL [])keys
10880 count:(NSUInteger)count {
10881 self = [super init];
10883 for (NSUInteger i = 0; i < count; ++i) {
10884 int idx = keys[i] ? 1 : 0;
10885 _values[idx] = values[i];
10886 _valueSet[idx] = YES;
10892 - (instancetype)initWithDictionary:(GPBBoolBoolDictionary *)dictionary {
10893 self = [self initWithBools:NULL forKeys:NULL count:0];
10896 for (int i = 0; i < 2; ++i) {
10897 if (dictionary->_valueSet[i]) {
10898 _values[i] = dictionary->_values[i];
10899 _valueSet[i] = YES;
10907 - (instancetype)initWithCapacity:(NSUInteger)numItems {
10908 #pragma unused(numItems)
10909 return [self initWithBools:NULL forKeys:NULL count:0];
10912 #if !defined(NS_BLOCK_ASSERTIONS)
10914 NSAssert(!_autocreator,
10915 @"%@: Autocreator must be cleared before release, autocreator: %@",
10916 [self class], _autocreator);
10919 #endif // !defined(NS_BLOCK_ASSERTIONS)
10921 - (instancetype)copyWithZone:(NSZone *)zone {
10922 return [[GPBBoolBoolDictionary allocWithZone:zone] initWithDictionary:self];
10925 - (BOOL)isEqual:(id)other {
10926 if (self == other) {
10929 if (![other isKindOfClass:[GPBBoolBoolDictionary class]]) {
10932 GPBBoolBoolDictionary *otherDictionary = other;
10933 if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
10934 (_valueSet[1] != otherDictionary->_valueSet[1])) {
10937 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
10938 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
10944 - (NSUInteger)hash {
10945 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
10948 - (NSString *)description {
10949 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
10950 if (_valueSet[0]) {
10951 [result appendFormat:@"NO: %d", _values[0]];
10953 if (_valueSet[1]) {
10954 [result appendFormat:@"YES: %d", _values[1]];
10956 [result appendString:@" }"];
10960 - (NSUInteger)count {
10961 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
10964 - (BOOL)getBool:(BOOL *)value forKey:(BOOL)key {
10965 int idx = (key ? 1 : 0);
10966 if (_valueSet[idx]) {
10968 *value = _values[idx];
10975 - (void)setGPBGenericValue:(GPBGenericValue *)value
10976 forGPBGenericValueKey:(GPBGenericValue *)key {
10977 int idx = (key->valueBool ? 1 : 0);
10978 _values[idx] = value->valueBool;
10979 _valueSet[idx] = YES;
10982 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
10983 if (_valueSet[0]) {
10984 block(@"false", (_values[0] ? @"true" : @"false"));
10986 if (_valueSet[1]) {
10987 block(@"true", (_values[1] ? @"true" : @"false"));
10991 - (void)enumerateKeysAndBoolsUsingBlock:
10992 (void (^)(BOOL key, BOOL value, BOOL *stop))block {
10994 if (_valueSet[0]) {
10995 block(NO, _values[0], &stop);
10997 if (!stop && _valueSet[1]) {
10998 block(YES, _values[1], &stop);
11002 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
11003 GPBDataType valueDataType = GPBGetFieldDataType(field);
11004 NSUInteger count = 0;
11006 for (int i = 0; i < 2; ++i) {
11007 if (_valueSet[i]) {
11009 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11010 msgSize += ComputeDictBoolFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
11011 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
11014 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
11015 result += tagSize * count;
11019 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
11020 asField:(GPBFieldDescriptor *)field {
11021 GPBDataType valueDataType = GPBGetFieldDataType(field);
11022 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
11023 for (int i = 0; i < 2; ++i) {
11024 if (_valueSet[i]) {
11026 [outputStream writeInt32NoTag:tag];
11027 // Write the size of the message.
11028 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11029 msgSize += ComputeDictBoolFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
11030 [outputStream writeInt32NoTag:(int32_t)msgSize];
11031 // Write the fields.
11032 WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11033 WriteDictBoolField(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
11038 - (void)addEntriesFromDictionary:(GPBBoolBoolDictionary *)otherDictionary {
11039 if (otherDictionary) {
11040 for (int i = 0; i < 2; ++i) {
11041 if (otherDictionary->_valueSet[i]) {
11042 _valueSet[i] = YES;
11043 _values[i] = otherDictionary->_values[i];
11046 if (_autocreator) {
11047 GPBAutocreatedDictionaryModified(_autocreator, self);
11052 - (void)setBool:(BOOL)value forKey:(BOOL)key {
11053 int idx = (key ? 1 : 0);
11054 _values[idx] = value;
11055 _valueSet[idx] = YES;
11056 if (_autocreator) {
11057 GPBAutocreatedDictionaryModified(_autocreator, self);
11061 - (void)removeBoolForKey:(BOOL)aKey {
11062 _valueSet[aKey ? 1 : 0] = NO;
11065 - (void)removeAll {
11072 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Float, float)
11073 // This block of code is generated, do not edit it directly.
11075 #pragma mark - Bool -> Float
11077 @implementation GPBBoolFloatDictionary {
11083 - (instancetype)init {
11084 return [self initWithFloats:NULL forKeys:NULL count:0];
11087 - (instancetype)initWithFloats:(const float [])values
11088 forKeys:(const BOOL [])keys
11089 count:(NSUInteger)count {
11090 self = [super init];
11092 for (NSUInteger i = 0; i < count; ++i) {
11093 int idx = keys[i] ? 1 : 0;
11094 _values[idx] = values[i];
11095 _valueSet[idx] = YES;
11101 - (instancetype)initWithDictionary:(GPBBoolFloatDictionary *)dictionary {
11102 self = [self initWithFloats:NULL forKeys:NULL count:0];
11105 for (int i = 0; i < 2; ++i) {
11106 if (dictionary->_valueSet[i]) {
11107 _values[i] = dictionary->_values[i];
11108 _valueSet[i] = YES;
11116 - (instancetype)initWithCapacity:(NSUInteger)numItems {
11117 #pragma unused(numItems)
11118 return [self initWithFloats:NULL forKeys:NULL count:0];
11121 #if !defined(NS_BLOCK_ASSERTIONS)
11123 NSAssert(!_autocreator,
11124 @"%@: Autocreator must be cleared before release, autocreator: %@",
11125 [self class], _autocreator);
11128 #endif // !defined(NS_BLOCK_ASSERTIONS)
11130 - (instancetype)copyWithZone:(NSZone *)zone {
11131 return [[GPBBoolFloatDictionary allocWithZone:zone] initWithDictionary:self];
11134 - (BOOL)isEqual:(id)other {
11135 if (self == other) {
11138 if (![other isKindOfClass:[GPBBoolFloatDictionary class]]) {
11141 GPBBoolFloatDictionary *otherDictionary = other;
11142 if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
11143 (_valueSet[1] != otherDictionary->_valueSet[1])) {
11146 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
11147 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
11153 - (NSUInteger)hash {
11154 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
11157 - (NSString *)description {
11158 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
11159 if (_valueSet[0]) {
11160 [result appendFormat:@"NO: %f", _values[0]];
11162 if (_valueSet[1]) {
11163 [result appendFormat:@"YES: %f", _values[1]];
11165 [result appendString:@" }"];
11169 - (NSUInteger)count {
11170 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
11173 - (BOOL)getFloat:(float *)value forKey:(BOOL)key {
11174 int idx = (key ? 1 : 0);
11175 if (_valueSet[idx]) {
11177 *value = _values[idx];
11184 - (void)setGPBGenericValue:(GPBGenericValue *)value
11185 forGPBGenericValueKey:(GPBGenericValue *)key {
11186 int idx = (key->valueBool ? 1 : 0);
11187 _values[idx] = value->valueFloat;
11188 _valueSet[idx] = YES;
11191 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
11192 if (_valueSet[0]) {
11193 block(@"false", [NSString stringWithFormat:@"%.*g", FLT_DIG, _values[0]]);
11195 if (_valueSet[1]) {
11196 block(@"true", [NSString stringWithFormat:@"%.*g", FLT_DIG, _values[1]]);
11200 - (void)enumerateKeysAndFloatsUsingBlock:
11201 (void (^)(BOOL key, float value, BOOL *stop))block {
11203 if (_valueSet[0]) {
11204 block(NO, _values[0], &stop);
11206 if (!stop && _valueSet[1]) {
11207 block(YES, _values[1], &stop);
11211 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
11212 GPBDataType valueDataType = GPBGetFieldDataType(field);
11213 NSUInteger count = 0;
11215 for (int i = 0; i < 2; ++i) {
11216 if (_valueSet[i]) {
11218 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11219 msgSize += ComputeDictFloatFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
11220 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
11223 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
11224 result += tagSize * count;
11228 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
11229 asField:(GPBFieldDescriptor *)field {
11230 GPBDataType valueDataType = GPBGetFieldDataType(field);
11231 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
11232 for (int i = 0; i < 2; ++i) {
11233 if (_valueSet[i]) {
11235 [outputStream writeInt32NoTag:tag];
11236 // Write the size of the message.
11237 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11238 msgSize += ComputeDictFloatFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
11239 [outputStream writeInt32NoTag:(int32_t)msgSize];
11240 // Write the fields.
11241 WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11242 WriteDictFloatField(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
11247 - (void)addEntriesFromDictionary:(GPBBoolFloatDictionary *)otherDictionary {
11248 if (otherDictionary) {
11249 for (int i = 0; i < 2; ++i) {
11250 if (otherDictionary->_valueSet[i]) {
11251 _valueSet[i] = YES;
11252 _values[i] = otherDictionary->_values[i];
11255 if (_autocreator) {
11256 GPBAutocreatedDictionaryModified(_autocreator, self);
11261 - (void)setFloat:(float)value forKey:(BOOL)key {
11262 int idx = (key ? 1 : 0);
11263 _values[idx] = value;
11264 _valueSet[idx] = YES;
11265 if (_autocreator) {
11266 GPBAutocreatedDictionaryModified(_autocreator, self);
11270 - (void)removeFloatForKey:(BOOL)aKey {
11271 _valueSet[aKey ? 1 : 0] = NO;
11274 - (void)removeAll {
11281 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Double, double)
11282 // This block of code is generated, do not edit it directly.
11284 #pragma mark - Bool -> Double
11286 @implementation GPBBoolDoubleDictionary {
11292 - (instancetype)init {
11293 return [self initWithDoubles:NULL forKeys:NULL count:0];
11296 - (instancetype)initWithDoubles:(const double [])values
11297 forKeys:(const BOOL [])keys
11298 count:(NSUInteger)count {
11299 self = [super init];
11301 for (NSUInteger i = 0; i < count; ++i) {
11302 int idx = keys[i] ? 1 : 0;
11303 _values[idx] = values[i];
11304 _valueSet[idx] = YES;
11310 - (instancetype)initWithDictionary:(GPBBoolDoubleDictionary *)dictionary {
11311 self = [self initWithDoubles:NULL forKeys:NULL count:0];
11314 for (int i = 0; i < 2; ++i) {
11315 if (dictionary->_valueSet[i]) {
11316 _values[i] = dictionary->_values[i];
11317 _valueSet[i] = YES;
11325 - (instancetype)initWithCapacity:(NSUInteger)numItems {
11326 #pragma unused(numItems)
11327 return [self initWithDoubles:NULL forKeys:NULL count:0];
11330 #if !defined(NS_BLOCK_ASSERTIONS)
11332 NSAssert(!_autocreator,
11333 @"%@: Autocreator must be cleared before release, autocreator: %@",
11334 [self class], _autocreator);
11337 #endif // !defined(NS_BLOCK_ASSERTIONS)
11339 - (instancetype)copyWithZone:(NSZone *)zone {
11340 return [[GPBBoolDoubleDictionary allocWithZone:zone] initWithDictionary:self];
11343 - (BOOL)isEqual:(id)other {
11344 if (self == other) {
11347 if (![other isKindOfClass:[GPBBoolDoubleDictionary class]]) {
11350 GPBBoolDoubleDictionary *otherDictionary = other;
11351 if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
11352 (_valueSet[1] != otherDictionary->_valueSet[1])) {
11355 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
11356 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
11362 - (NSUInteger)hash {
11363 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
11366 - (NSString *)description {
11367 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
11368 if (_valueSet[0]) {
11369 [result appendFormat:@"NO: %lf", _values[0]];
11371 if (_valueSet[1]) {
11372 [result appendFormat:@"YES: %lf", _values[1]];
11374 [result appendString:@" }"];
11378 - (NSUInteger)count {
11379 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
11382 - (BOOL)getDouble:(double *)value forKey:(BOOL)key {
11383 int idx = (key ? 1 : 0);
11384 if (_valueSet[idx]) {
11386 *value = _values[idx];
11393 - (void)setGPBGenericValue:(GPBGenericValue *)value
11394 forGPBGenericValueKey:(GPBGenericValue *)key {
11395 int idx = (key->valueBool ? 1 : 0);
11396 _values[idx] = value->valueDouble;
11397 _valueSet[idx] = YES;
11400 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
11401 if (_valueSet[0]) {
11402 block(@"false", [NSString stringWithFormat:@"%.*lg", DBL_DIG, _values[0]]);
11404 if (_valueSet[1]) {
11405 block(@"true", [NSString stringWithFormat:@"%.*lg", DBL_DIG, _values[1]]);
11409 - (void)enumerateKeysAndDoublesUsingBlock:
11410 (void (^)(BOOL key, double value, BOOL *stop))block {
11412 if (_valueSet[0]) {
11413 block(NO, _values[0], &stop);
11415 if (!stop && _valueSet[1]) {
11416 block(YES, _values[1], &stop);
11420 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
11421 GPBDataType valueDataType = GPBGetFieldDataType(field);
11422 NSUInteger count = 0;
11424 for (int i = 0; i < 2; ++i) {
11425 if (_valueSet[i]) {
11427 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11428 msgSize += ComputeDictDoubleFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
11429 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
11432 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
11433 result += tagSize * count;
11437 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
11438 asField:(GPBFieldDescriptor *)field {
11439 GPBDataType valueDataType = GPBGetFieldDataType(field);
11440 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
11441 for (int i = 0; i < 2; ++i) {
11442 if (_valueSet[i]) {
11444 [outputStream writeInt32NoTag:tag];
11445 // Write the size of the message.
11446 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11447 msgSize += ComputeDictDoubleFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
11448 [outputStream writeInt32NoTag:(int32_t)msgSize];
11449 // Write the fields.
11450 WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11451 WriteDictDoubleField(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
11456 - (void)addEntriesFromDictionary:(GPBBoolDoubleDictionary *)otherDictionary {
11457 if (otherDictionary) {
11458 for (int i = 0; i < 2; ++i) {
11459 if (otherDictionary->_valueSet[i]) {
11460 _valueSet[i] = YES;
11461 _values[i] = otherDictionary->_values[i];
11464 if (_autocreator) {
11465 GPBAutocreatedDictionaryModified(_autocreator, self);
11470 - (void)setDouble:(double)value forKey:(BOOL)key {
11471 int idx = (key ? 1 : 0);
11472 _values[idx] = value;
11473 _valueSet[idx] = YES;
11474 if (_autocreator) {
11475 GPBAutocreatedDictionaryModified(_autocreator, self);
11479 - (void)removeDoubleForKey:(BOOL)aKey {
11480 _valueSet[aKey ? 1 : 0] = NO;
11483 - (void)removeAll {
11490 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_OBJECT_IMPL(Object, id)
11491 // This block of code is generated, do not edit it directly.
11493 #pragma mark - Bool -> Object
11495 @implementation GPBBoolObjectDictionary {
11500 - (instancetype)init {
11501 return [self initWithObjects:NULL forKeys:NULL count:0];
11504 - (instancetype)initWithObjects:(const id [])objects
11505 forKeys:(const BOOL [])keys
11506 count:(NSUInteger)count {
11507 self = [super init];
11509 for (NSUInteger i = 0; i < count; ++i) {
11511 [NSException raise:NSInvalidArgumentException
11512 format:@"Attempting to add nil object to a Dictionary"];
11514 int idx = keys[i] ? 1 : 0;
11515 [_values[idx] release];
11516 _values[idx] = (id)[objects[i] retain];
11522 - (instancetype)initWithDictionary:(GPBBoolObjectDictionary *)dictionary {
11523 self = [self initWithObjects:NULL forKeys:NULL count:0];
11526 _values[0] = [dictionary->_values[0] retain];
11527 _values[1] = [dictionary->_values[1] retain];
11533 - (instancetype)initWithCapacity:(NSUInteger)numItems {
11534 #pragma unused(numItems)
11535 return [self initWithObjects:NULL forKeys:NULL count:0];
11539 NSAssert(!_autocreator,
11540 @"%@: Autocreator must be cleared before release, autocreator: %@",
11541 [self class], _autocreator);
11542 [_values[0] release];
11543 [_values[1] release];
11547 - (instancetype)copyWithZone:(NSZone *)zone {
11548 return [[GPBBoolObjectDictionary allocWithZone:zone] initWithDictionary:self];
11551 - (BOOL)isEqual:(id)other {
11552 if (self == other) {
11555 if (![other isKindOfClass:[GPBBoolObjectDictionary class]]) {
11558 GPBBoolObjectDictionary *otherDictionary = other;
11559 if (((_values[0] != nil) != (otherDictionary->_values[0] != nil)) ||
11560 ((_values[1] != nil) != (otherDictionary->_values[1] != nil))) {
11563 if (((_values[0] != nil) && (![_values[0] isEqual:otherDictionary->_values[0]])) ||
11564 ((_values[1] != nil) && (![_values[1] isEqual:otherDictionary->_values[1]]))) {
11570 - (NSUInteger)hash {
11571 return ((_values[0] != nil) ? 1 : 0) + ((_values[1] != nil) ? 1 : 0);
11574 - (NSString *)description {
11575 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
11576 if ((_values[0] != nil)) {
11577 [result appendFormat:@"NO: %@", _values[0]];
11579 if ((_values[1] != nil)) {
11580 [result appendFormat:@"YES: %@", _values[1]];
11582 [result appendString:@" }"];
11586 - (NSUInteger)count {
11587 return ((_values[0] != nil) ? 1 : 0) + ((_values[1] != nil) ? 1 : 0);
11590 - (id)objectForKey:(BOOL)key {
11591 return _values[key ? 1 : 0];
11594 - (void)setGPBGenericValue:(GPBGenericValue *)value
11595 forGPBGenericValueKey:(GPBGenericValue *)key {
11596 int idx = (key->valueBool ? 1 : 0);
11597 [_values[idx] release];
11598 _values[idx] = [value->valueString retain];
11601 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
11602 if (_values[0] != nil) {
11603 block(@"false", _values[0]);
11605 if ((_values[1] != nil)) {
11606 block(@"true", _values[1]);
11610 - (void)enumerateKeysAndObjectsUsingBlock:
11611 (void (^)(BOOL key, id object, BOOL *stop))block {
11613 if (_values[0] != nil) {
11614 block(NO, _values[0], &stop);
11616 if (!stop && (_values[1] != nil)) {
11617 block(YES, _values[1], &stop);
11621 - (BOOL)isInitialized {
11622 if (_values[0] && ![_values[0] isInitialized]) {
11625 if (_values[1] && ![_values[1] isInitialized]) {
11631 - (instancetype)deepCopyWithZone:(NSZone *)zone {
11632 GPBBoolObjectDictionary *newDict =
11633 [[GPBBoolObjectDictionary alloc] init];
11634 for (int i = 0; i < 2; ++i) {
11635 if (_values[i] != nil) {
11636 newDict->_values[i] = [_values[i] copyWithZone:zone];
11642 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
11643 GPBDataType valueDataType = GPBGetFieldDataType(field);
11644 NSUInteger count = 0;
11646 for (int i = 0; i < 2; ++i) {
11647 if (_values[i] != nil) {
11649 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11650 msgSize += ComputeDictObjectFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
11651 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
11654 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
11655 result += tagSize * count;
11659 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
11660 asField:(GPBFieldDescriptor *)field {
11661 GPBDataType valueDataType = GPBGetFieldDataType(field);
11662 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
11663 for (int i = 0; i < 2; ++i) {
11664 if (_values[i] != nil) {
11666 [outputStream writeInt32NoTag:tag];
11667 // Write the size of the message.
11668 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11669 msgSize += ComputeDictObjectFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
11670 [outputStream writeInt32NoTag:(int32_t)msgSize];
11671 // Write the fields.
11672 WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11673 WriteDictObjectField(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
11678 - (void)addEntriesFromDictionary:(GPBBoolObjectDictionary *)otherDictionary {
11679 if (otherDictionary) {
11680 for (int i = 0; i < 2; ++i) {
11681 if (otherDictionary->_values[i] != nil) {
11682 [_values[i] release];
11683 _values[i] = [otherDictionary->_values[i] retain];
11686 if (_autocreator) {
11687 GPBAutocreatedDictionaryModified(_autocreator, self);
11692 - (void)setObject:(id)object forKey:(BOOL)key {
11694 [NSException raise:NSInvalidArgumentException
11695 format:@"Attempting to add nil object to a Dictionary"];
11697 int idx = (key ? 1 : 0);
11698 [_values[idx] release];
11699 _values[idx] = [object retain];
11700 if (_autocreator) {
11701 GPBAutocreatedDictionaryModified(_autocreator, self);
11705 - (void)removeObjectForKey:(BOOL)aKey {
11706 int idx = (aKey ? 1 : 0);
11707 [_values[idx] release];
11708 _values[idx] = nil;
11711 - (void)removeAll {
11712 for (int i = 0; i < 2; ++i) {
11713 [_values[i] release];
11720 //%PDDM-EXPAND-END (8 expansions)
11722 #pragma mark - Bool -> Enum
11724 @implementation GPBBoolEnumDictionary {
11726 GPBEnumValidationFunc _validationFunc;
11727 int32_t _values[2];
11731 @synthesize validationFunc = _validationFunc;
11733 - (instancetype)init {
11734 return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
11737 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
11738 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
11741 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
11742 rawValues:(const int32_t [])rawValues
11743 forKeys:(const BOOL [])keys
11744 count:(NSUInteger)count {
11745 self = [super init];
11747 _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
11748 for (NSUInteger i = 0; i < count; ++i) {
11749 int idx = keys[i] ? 1 : 0;
11750 _values[idx] = rawValues[i];
11751 _valueSet[idx] = YES;
11757 - (instancetype)initWithDictionary:(GPBBoolEnumDictionary *)dictionary {
11758 self = [self initWithValidationFunction:dictionary.validationFunc
11764 for (int i = 0; i < 2; ++i) {
11765 if (dictionary->_valueSet[i]) {
11766 _values[i] = dictionary->_values[i];
11767 _valueSet[i] = YES;
11775 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
11776 capacity:(NSUInteger)numItems {
11777 #pragma unused(numItems)
11778 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
11781 #if !defined(NS_BLOCK_ASSERTIONS)
11783 NSAssert(!_autocreator,
11784 @"%@: Autocreator must be cleared before release, autocreator: %@",
11785 [self class], _autocreator);
11788 #endif // !defined(NS_BLOCK_ASSERTIONS)
11790 - (instancetype)copyWithZone:(NSZone *)zone {
11791 return [[GPBBoolEnumDictionary allocWithZone:zone] initWithDictionary:self];
11794 - (BOOL)isEqual:(id)other {
11795 if (self == other) {
11798 if (![other isKindOfClass:[GPBBoolEnumDictionary class]]) {
11801 GPBBoolEnumDictionary *otherDictionary = other;
11802 if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
11803 (_valueSet[1] != otherDictionary->_valueSet[1])) {
11806 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
11807 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
11813 - (NSUInteger)hash {
11814 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
11817 - (NSString *)description {
11818 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
11819 if (_valueSet[0]) {
11820 [result appendFormat:@"NO: %d", _values[0]];
11822 if (_valueSet[1]) {
11823 [result appendFormat:@"YES: %d", _values[1]];
11825 [result appendString:@" }"];
11829 - (NSUInteger)count {
11830 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
11833 - (BOOL)getEnum:(int32_t*)value forKey:(BOOL)key {
11834 int idx = (key ? 1 : 0);
11835 if (_valueSet[idx]) {
11837 int32_t result = _values[idx];
11838 if (!_validationFunc(result)) {
11839 result = kGPBUnrecognizedEnumeratorValue;
11848 - (BOOL)getRawValue:(int32_t*)rawValue forKey:(BOOL)key {
11849 int idx = (key ? 1 : 0);
11850 if (_valueSet[idx]) {
11852 *rawValue = _values[idx];
11859 - (void)enumerateKeysAndRawValuesUsingBlock:
11860 (void (^)(BOOL key, int32_t value, BOOL *stop))block {
11862 if (_valueSet[0]) {
11863 block(NO, _values[0], &stop);
11865 if (!stop && _valueSet[1]) {
11866 block(YES, _values[1], &stop);
11870 - (void)enumerateKeysAndEnumsUsingBlock:
11871 (void (^)(BOOL key, int32_t rawValue, BOOL *stop))block {
11873 GPBEnumValidationFunc func = _validationFunc;
11874 int32_t validatedValue;
11875 if (_valueSet[0]) {
11876 validatedValue = _values[0];
11877 if (!func(validatedValue)) {
11878 validatedValue = kGPBUnrecognizedEnumeratorValue;
11880 block(NO, validatedValue, &stop);
11882 if (!stop && _valueSet[1]) {
11883 validatedValue = _values[1];
11884 if (!func(validatedValue)) {
11885 validatedValue = kGPBUnrecognizedEnumeratorValue;
11887 block(YES, validatedValue, &stop);
11891 //%PDDM-EXPAND SERIAL_DATA_FOR_ENTRY_POD_Enum(Bool)
11892 // This block of code is generated, do not edit it directly.
11894 - (NSData *)serializedDataForUnknownValue:(int32_t)value
11895 forKey:(GPBGenericValue *)key
11896 keyDataType:(GPBDataType)keyDataType {
11897 size_t msgSize = ComputeDictBoolFieldSize(key->valueBool, kMapKeyFieldNumber, keyDataType);
11898 msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
11899 NSMutableData *data = [NSMutableData dataWithLength:msgSize];
11900 GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
11901 WriteDictBoolField(outputStream, key->valueBool, kMapKeyFieldNumber, keyDataType);
11902 WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
11903 [outputStream release];
11907 //%PDDM-EXPAND-END SERIAL_DATA_FOR_ENTRY_POD_Enum(Bool)
11909 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
11910 GPBDataType valueDataType = GPBGetFieldDataType(field);
11911 NSUInteger count = 0;
11913 for (int i = 0; i < 2; ++i) {
11914 if (_valueSet[i]) {
11916 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11917 msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
11918 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
11921 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
11922 result += tagSize * count;
11926 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
11927 asField:(GPBFieldDescriptor *)field {
11928 GPBDataType valueDataType = GPBGetFieldDataType(field);
11929 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
11930 for (int i = 0; i < 2; ++i) {
11931 if (_valueSet[i]) {
11933 [outputStream writeInt32NoTag:tag];
11934 // Write the size of the message.
11935 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11936 msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
11937 [outputStream writeInt32NoTag:(int32_t)msgSize];
11938 // Write the fields.
11939 WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11940 WriteDictInt32Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
11945 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block {
11946 if (_valueSet[0]) {
11947 block(@"false", @(_values[0]));
11949 if (_valueSet[1]) {
11950 block(@"true", @(_values[1]));
11954 - (void)setGPBGenericValue:(GPBGenericValue *)value
11955 forGPBGenericValueKey:(GPBGenericValue *)key {
11956 int idx = (key->valueBool ? 1 : 0);
11957 _values[idx] = value->valueInt32;
11958 _valueSet[idx] = YES;
11961 - (void)addRawEntriesFromDictionary:(GPBBoolEnumDictionary *)otherDictionary {
11962 if (otherDictionary) {
11963 for (int i = 0; i < 2; ++i) {
11964 if (otherDictionary->_valueSet[i]) {
11965 _valueSet[i] = YES;
11966 _values[i] = otherDictionary->_values[i];
11969 if (_autocreator) {
11970 GPBAutocreatedDictionaryModified(_autocreator, self);
11975 - (void)setEnum:(int32_t)value forKey:(BOOL)key {
11976 if (!_validationFunc(value)) {
11977 [NSException raise:NSInvalidArgumentException
11978 format:@"GPBBoolEnumDictionary: Attempt to set an unknown enum value (%d)",
11981 int idx = (key ? 1 : 0);
11982 _values[idx] = value;
11983 _valueSet[idx] = YES;
11984 if (_autocreator) {
11985 GPBAutocreatedDictionaryModified(_autocreator, self);
11989 - (void)setRawValue:(int32_t)rawValue forKey:(BOOL)key {
11990 int idx = (key ? 1 : 0);
11991 _values[idx] = rawValue;
11992 _valueSet[idx] = YES;
11993 if (_autocreator) {
11994 GPBAutocreatedDictionaryModified(_autocreator, self);
11998 - (void)removeEnumForKey:(BOOL)aKey {
11999 _valueSet[aKey ? 1 : 0] = NO;
12002 - (void)removeAll {
12009 #pragma mark - NSDictionary Subclass
12011 @implementation GPBAutocreatedDictionary {
12012 NSMutableDictionary *_dictionary;
12016 NSAssert(!_autocreator,
12017 @"%@: Autocreator must be cleared before release, autocreator: %@",
12018 [self class], _autocreator);
12019 [_dictionary release];
12023 #pragma mark Required NSDictionary overrides
12025 - (instancetype)initWithObjects:(const id [])objects
12026 forKeys:(const id<NSCopying> [])keys
12027 count:(NSUInteger)count {
12028 self = [super init];
12030 _dictionary = [[NSMutableDictionary alloc] initWithObjects:objects
12037 - (NSUInteger)count {
12038 return [_dictionary count];
12041 - (id)objectForKey:(id)aKey {
12042 return [_dictionary objectForKey:aKey];
12045 - (NSEnumerator *)keyEnumerator {
12046 if (_dictionary == nil) {
12047 _dictionary = [[NSMutableDictionary alloc] init];
12049 return [_dictionary keyEnumerator];
12052 #pragma mark Required NSMutableDictionary overrides
12054 // Only need to call GPBAutocreatedDictionaryModified() when adding things
12055 // since we only autocreate empty dictionaries.
12057 - (void)setObject:(id)anObject forKey:(id<NSCopying>)aKey {
12058 if (_dictionary == nil) {
12059 _dictionary = [[NSMutableDictionary alloc] init];
12061 [_dictionary setObject:anObject forKey:aKey];
12062 if (_autocreator) {
12063 GPBAutocreatedDictionaryModified(_autocreator, self);
12067 - (void)removeObjectForKey:(id)aKey {
12068 [_dictionary removeObjectForKey:aKey];
12071 #pragma mark Extra things hooked
12073 - (id)copyWithZone:(NSZone *)zone {
12074 if (_dictionary == nil) {
12075 return [[NSMutableDictionary allocWithZone:zone] init];
12077 return [_dictionary copyWithZone:zone];
12080 - (id)mutableCopyWithZone:(NSZone *)zone {
12081 if (_dictionary == nil) {
12082 return [[NSMutableDictionary allocWithZone:zone] init];
12084 return [_dictionary mutableCopyWithZone:zone];
12087 // Not really needed, but subscripting is likely common enough it doesn't hurt
12088 // to ensure it goes directly to the real NSMutableDictionary.
12089 - (id)objectForKeyedSubscript:(id)key {
12090 return [_dictionary objectForKeyedSubscript:key];
12093 // Not really needed, but subscripting is likely common enough it doesn't hurt
12094 // to ensure it goes directly to the real NSMutableDictionary.
12095 - (void)setObject:(id)obj forKeyedSubscript:(id<NSCopying>)key {
12096 if (_dictionary == nil) {
12097 _dictionary = [[NSMutableDictionary alloc] init];
12099 [_dictionary setObject:obj forKeyedSubscript:key];
12100 if (_autocreator) {
12101 GPBAutocreatedDictionaryModified(_autocreator, self);
12105 - (void)enumerateKeysAndObjectsUsingBlock:(void (NS_NOESCAPE ^)(id key,
12107 BOOL *stop))block {
12108 [_dictionary enumerateKeysAndObjectsUsingBlock:block];
12111 - (void)enumerateKeysAndObjectsWithOptions:(NSEnumerationOptions)opts
12112 usingBlock:(void (NS_NOESCAPE ^)(id key,
12114 BOOL *stop))block {
12115 [_dictionary enumerateKeysAndObjectsWithOptions:opts usingBlock:block];
12120 #pragma clang diagnostic pop