1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file or at
6 // https://developers.google.com/open-source/licenses/bsd
8 #import "GPBDictionary.h"
9 #import "GPBDictionary_PackagePrivate.h"
11 #import "GPBCodedInputStream.h"
12 #import "GPBCodedInputStream_PackagePrivate.h"
13 #import "GPBCodedOutputStream.h"
14 #import "GPBCodedOutputStream_PackagePrivate.h"
15 #import "GPBDescriptor.h"
16 #import "GPBDescriptor_PackagePrivate.h"
17 #import "GPBMessage.h"
18 #import "GPBMessage_PackagePrivate.h"
19 #import "GPBUtilities.h"
20 #import "GPBUtilities_PackagePrivate.h"
22 // ------------------------------ NOTE ------------------------------
23 // At the moment, this is all using NSNumbers in NSDictionaries under
24 // the hood, but it is all hidden so we can come back and optimize
25 // with direct CFDictionary usage later. The reason that wasn't
26 // done yet is needing to support 32bit iOS builds. Otherwise
27 // it would be pretty simple to store all this data in CFDictionaries
29 // ------------------------------------------------------------------
31 // Direct access is use for speed, to avoid even internally declaring things
32 // read/write, etc. The warning is enabled in the project to ensure code calling
33 // protos can turn on -Wdirect-ivar-access without issues.
34 #pragma clang diagnostic push
35 #pragma clang diagnostic ignored "-Wdirect-ivar-access"
38 kMapKeyFieldNumber = 1,
39 kMapValueFieldNumber = 2,
42 static BOOL DictDefault_IsValidValue(int32_t value) {
43 // Anything but the bad value marker is allowed.
44 return (value != kGPBUnrecognizedEnumeratorValue);
47 // Disable clang-format for the macros.
50 //%PDDM-DEFINE SERIALIZE_SUPPORT_2_TYPE(VALUE_NAME, VALUE_TYPE, GPBDATATYPE_NAME1, GPBDATATYPE_NAME2)
51 //%static size_t ComputeDict##VALUE_NAME##FieldSize(VALUE_TYPE value, uint32_t fieldNum, GPBDataType dataType) {
52 //% if (dataType == GPBDataType##GPBDATATYPE_NAME1) {
53 //% return GPBCompute##GPBDATATYPE_NAME1##Size(fieldNum, value);
54 //% } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) {
55 //% return GPBCompute##GPBDATATYPE_NAME2##Size(fieldNum, value);
57 //% NSCAssert(NO, @"Unexpected type %d", dataType);
62 //%static void WriteDict##VALUE_NAME##Field(GPBCodedOutputStream *stream, VALUE_TYPE value, uint32_t fieldNum, GPBDataType dataType) {
63 //% if (dataType == GPBDataType##GPBDATATYPE_NAME1) {
64 //% [stream write##GPBDATATYPE_NAME1##:fieldNum value:value];
65 //% } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) {
66 //% [stream write##GPBDATATYPE_NAME2##:fieldNum value:value];
68 //% NSCAssert(NO, @"Unexpected type %d", dataType);
72 //%PDDM-DEFINE SERIALIZE_SUPPORT_3_TYPE(VALUE_NAME, VALUE_TYPE, GPBDATATYPE_NAME1, GPBDATATYPE_NAME2, GPBDATATYPE_NAME3)
73 //%static size_t ComputeDict##VALUE_NAME##FieldSize(VALUE_TYPE value, uint32_t fieldNum, GPBDataType dataType) {
74 //% if (dataType == GPBDataType##GPBDATATYPE_NAME1) {
75 //% return GPBCompute##GPBDATATYPE_NAME1##Size(fieldNum, value);
76 //% } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) {
77 //% return GPBCompute##GPBDATATYPE_NAME2##Size(fieldNum, value);
78 //% } else if (dataType == GPBDataType##GPBDATATYPE_NAME3) {
79 //% return GPBCompute##GPBDATATYPE_NAME3##Size(fieldNum, value);
81 //% NSCAssert(NO, @"Unexpected type %d", dataType);
86 //%static void WriteDict##VALUE_NAME##Field(GPBCodedOutputStream *stream, VALUE_TYPE value, uint32_t fieldNum, GPBDataType dataType) {
87 //% if (dataType == GPBDataType##GPBDATATYPE_NAME1) {
88 //% [stream write##GPBDATATYPE_NAME1##:fieldNum value:value];
89 //% } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) {
90 //% [stream write##GPBDATATYPE_NAME2##:fieldNum value:value];
91 //% } else if (dataType == GPBDataType##GPBDATATYPE_NAME3) {
92 //% [stream write##GPBDATATYPE_NAME3##:fieldNum value:value];
94 //% NSCAssert(NO, @"Unexpected type %d", dataType);
98 //%PDDM-DEFINE SIMPLE_SERIALIZE_SUPPORT(VALUE_NAME, VALUE_TYPE, VisP)
99 //%static size_t ComputeDict##VALUE_NAME##FieldSize(VALUE_TYPE VisP##value, uint32_t fieldNum, __unused GPBDataType dataType) {
100 //% NSCAssert(dataType == GPBDataType##VALUE_NAME, @"bad type: %d", dataType);
101 //% return GPBCompute##VALUE_NAME##Size(fieldNum, value);
104 //%static void WriteDict##VALUE_NAME##Field(GPBCodedOutputStream *stream, VALUE_TYPE VisP##value, uint32_t fieldNum, __unused GPBDataType dataType) {
105 //% NSCAssert(dataType == GPBDataType##VALUE_NAME, @"bad type: %d", dataType);
106 //% [stream write##VALUE_NAME##:fieldNum value:value];
109 //%PDDM-DEFINE SERIALIZE_SUPPORT_HELPERS()
110 //%SERIALIZE_SUPPORT_3_TYPE(Int32, int32_t, Int32, SInt32, SFixed32)
111 //%SERIALIZE_SUPPORT_2_TYPE(UInt32, uint32_t, UInt32, Fixed32)
112 //%SERIALIZE_SUPPORT_3_TYPE(Int64, int64_t, Int64, SInt64, SFixed64)
113 //%SERIALIZE_SUPPORT_2_TYPE(UInt64, uint64_t, UInt64, Fixed64)
114 //%SIMPLE_SERIALIZE_SUPPORT(Bool, BOOL, )
115 //%SIMPLE_SERIALIZE_SUPPORT(Enum, int32_t, )
116 //%SIMPLE_SERIALIZE_SUPPORT(Float, float, )
117 //%SIMPLE_SERIALIZE_SUPPORT(Double, double, )
118 //%SIMPLE_SERIALIZE_SUPPORT(String, NSString, *)
119 //%SERIALIZE_SUPPORT_3_TYPE(Object, id, Message, String, Bytes)
120 //%PDDM-EXPAND SERIALIZE_SUPPORT_HELPERS()
121 // This block of code is generated, do not edit it directly.
123 static size_t ComputeDictInt32FieldSize(int32_t value, uint32_t fieldNum, GPBDataType dataType) {
124 if (dataType == GPBDataTypeInt32) {
125 return GPBComputeInt32Size(fieldNum, value);
126 } else if (dataType == GPBDataTypeSInt32) {
127 return GPBComputeSInt32Size(fieldNum, value);
128 } else if (dataType == GPBDataTypeSFixed32) {
129 return GPBComputeSFixed32Size(fieldNum, value);
131 NSCAssert(NO, @"Unexpected type %d", dataType);
136 static void WriteDictInt32Field(GPBCodedOutputStream *stream, int32_t value, uint32_t fieldNum, GPBDataType dataType) {
137 if (dataType == GPBDataTypeInt32) {
138 [stream writeInt32:fieldNum value:value];
139 } else if (dataType == GPBDataTypeSInt32) {
140 [stream writeSInt32:fieldNum value:value];
141 } else if (dataType == GPBDataTypeSFixed32) {
142 [stream writeSFixed32:fieldNum value:value];
144 NSCAssert(NO, @"Unexpected type %d", dataType);
148 static size_t ComputeDictUInt32FieldSize(uint32_t value, uint32_t fieldNum, GPBDataType dataType) {
149 if (dataType == GPBDataTypeUInt32) {
150 return GPBComputeUInt32Size(fieldNum, value);
151 } else if (dataType == GPBDataTypeFixed32) {
152 return GPBComputeFixed32Size(fieldNum, value);
154 NSCAssert(NO, @"Unexpected type %d", dataType);
159 static void WriteDictUInt32Field(GPBCodedOutputStream *stream, uint32_t value, uint32_t fieldNum, GPBDataType dataType) {
160 if (dataType == GPBDataTypeUInt32) {
161 [stream writeUInt32:fieldNum value:value];
162 } else if (dataType == GPBDataTypeFixed32) {
163 [stream writeFixed32:fieldNum value:value];
165 NSCAssert(NO, @"Unexpected type %d", dataType);
169 static size_t ComputeDictInt64FieldSize(int64_t value, uint32_t fieldNum, GPBDataType dataType) {
170 if (dataType == GPBDataTypeInt64) {
171 return GPBComputeInt64Size(fieldNum, value);
172 } else if (dataType == GPBDataTypeSInt64) {
173 return GPBComputeSInt64Size(fieldNum, value);
174 } else if (dataType == GPBDataTypeSFixed64) {
175 return GPBComputeSFixed64Size(fieldNum, value);
177 NSCAssert(NO, @"Unexpected type %d", dataType);
182 static void WriteDictInt64Field(GPBCodedOutputStream *stream, int64_t value, uint32_t fieldNum, GPBDataType dataType) {
183 if (dataType == GPBDataTypeInt64) {
184 [stream writeInt64:fieldNum value:value];
185 } else if (dataType == GPBDataTypeSInt64) {
186 [stream writeSInt64:fieldNum value:value];
187 } else if (dataType == GPBDataTypeSFixed64) {
188 [stream writeSFixed64:fieldNum value:value];
190 NSCAssert(NO, @"Unexpected type %d", dataType);
194 static size_t ComputeDictUInt64FieldSize(uint64_t value, uint32_t fieldNum, GPBDataType dataType) {
195 if (dataType == GPBDataTypeUInt64) {
196 return GPBComputeUInt64Size(fieldNum, value);
197 } else if (dataType == GPBDataTypeFixed64) {
198 return GPBComputeFixed64Size(fieldNum, value);
200 NSCAssert(NO, @"Unexpected type %d", dataType);
205 static void WriteDictUInt64Field(GPBCodedOutputStream *stream, uint64_t value, uint32_t fieldNum, GPBDataType dataType) {
206 if (dataType == GPBDataTypeUInt64) {
207 [stream writeUInt64:fieldNum value:value];
208 } else if (dataType == GPBDataTypeFixed64) {
209 [stream writeFixed64:fieldNum value:value];
211 NSCAssert(NO, @"Unexpected type %d", dataType);
215 static size_t ComputeDictBoolFieldSize(BOOL value, uint32_t fieldNum, __unused GPBDataType dataType) {
216 NSCAssert(dataType == GPBDataTypeBool, @"bad type: %d", dataType);
217 return GPBComputeBoolSize(fieldNum, value);
220 static void WriteDictBoolField(GPBCodedOutputStream *stream, BOOL value, uint32_t fieldNum, __unused GPBDataType dataType) {
221 NSCAssert(dataType == GPBDataTypeBool, @"bad type: %d", dataType);
222 [stream writeBool:fieldNum value:value];
225 static size_t ComputeDictEnumFieldSize(int32_t value, uint32_t fieldNum, __unused GPBDataType dataType) {
226 NSCAssert(dataType == GPBDataTypeEnum, @"bad type: %d", dataType);
227 return GPBComputeEnumSize(fieldNum, value);
230 static void WriteDictEnumField(GPBCodedOutputStream *stream, int32_t value, uint32_t fieldNum, __unused GPBDataType dataType) {
231 NSCAssert(dataType == GPBDataTypeEnum, @"bad type: %d", dataType);
232 [stream writeEnum:fieldNum value:value];
235 static size_t ComputeDictFloatFieldSize(float value, uint32_t fieldNum, __unused GPBDataType dataType) {
236 NSCAssert(dataType == GPBDataTypeFloat, @"bad type: %d", dataType);
237 return GPBComputeFloatSize(fieldNum, value);
240 static void WriteDictFloatField(GPBCodedOutputStream *stream, float value, uint32_t fieldNum, __unused GPBDataType dataType) {
241 NSCAssert(dataType == GPBDataTypeFloat, @"bad type: %d", dataType);
242 [stream writeFloat:fieldNum value:value];
245 static size_t ComputeDictDoubleFieldSize(double value, uint32_t fieldNum, __unused GPBDataType dataType) {
246 NSCAssert(dataType == GPBDataTypeDouble, @"bad type: %d", dataType);
247 return GPBComputeDoubleSize(fieldNum, value);
250 static void WriteDictDoubleField(GPBCodedOutputStream *stream, double value, uint32_t fieldNum, __unused GPBDataType dataType) {
251 NSCAssert(dataType == GPBDataTypeDouble, @"bad type: %d", dataType);
252 [stream writeDouble:fieldNum value:value];
255 static size_t ComputeDictStringFieldSize(NSString *value, uint32_t fieldNum, __unused GPBDataType dataType) {
256 NSCAssert(dataType == GPBDataTypeString, @"bad type: %d", dataType);
257 return GPBComputeStringSize(fieldNum, value);
260 static void WriteDictStringField(GPBCodedOutputStream *stream, NSString *value, uint32_t fieldNum, __unused GPBDataType dataType) {
261 NSCAssert(dataType == GPBDataTypeString, @"bad type: %d", dataType);
262 [stream writeString:fieldNum value:value];
265 static size_t ComputeDictObjectFieldSize(id value, uint32_t fieldNum, GPBDataType dataType) {
266 if (dataType == GPBDataTypeMessage) {
267 return GPBComputeMessageSize(fieldNum, value);
268 } else if (dataType == GPBDataTypeString) {
269 return GPBComputeStringSize(fieldNum, value);
270 } else if (dataType == GPBDataTypeBytes) {
271 return GPBComputeBytesSize(fieldNum, value);
273 NSCAssert(NO, @"Unexpected type %d", dataType);
278 static void WriteDictObjectField(GPBCodedOutputStream *stream, id value, uint32_t fieldNum, GPBDataType dataType) {
279 if (dataType == GPBDataTypeMessage) {
280 [stream writeMessage:fieldNum value:value];
281 } else if (dataType == GPBDataTypeString) {
282 [stream writeString:fieldNum value:value];
283 } else if (dataType == GPBDataTypeBytes) {
284 [stream writeBytes:fieldNum value:value];
286 NSCAssert(NO, @"Unexpected type %d", dataType);
290 //%PDDM-EXPAND-END SERIALIZE_SUPPORT_HELPERS()
294 size_t GPBDictionaryComputeSizeInternalHelper(NSDictionary *dict, GPBFieldDescriptor *field) {
295 GPBDataType mapValueType = GPBGetFieldDataType(field);
298 NSEnumerator *keys = [dict keyEnumerator];
299 while ((key = [keys nextObject])) {
301 size_t msgSize = GPBComputeStringSize(kMapKeyFieldNumber, key);
302 msgSize += ComputeDictObjectFieldSize(obj, kMapValueFieldNumber, mapValueType);
303 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
305 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
306 result += tagSize * dict.count;
310 void GPBDictionaryWriteToStreamInternalHelper(GPBCodedOutputStream *outputStream,
311 NSDictionary *dict, GPBFieldDescriptor *field) {
312 NSCAssert(field.mapKeyDataType == GPBDataTypeString, @"Unexpected key type");
313 GPBDataType mapValueType = GPBGetFieldDataType(field);
314 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
316 NSEnumerator *keys = [dict keyEnumerator];
317 while ((key = [keys nextObject])) {
320 [outputStream writeInt32NoTag:tag];
321 // Write the size of the message.
322 size_t msgSize = GPBComputeStringSize(kMapKeyFieldNumber, key);
323 msgSize += ComputeDictObjectFieldSize(obj, kMapValueFieldNumber, mapValueType);
325 // Write the size and fields.
326 [outputStream writeInt32NoTag:(int32_t)msgSize];
327 [outputStream writeString:kMapKeyFieldNumber value:key];
328 WriteDictObjectField(outputStream, obj, kMapValueFieldNumber, mapValueType);
332 BOOL GPBDictionaryIsInitializedInternalHelper(NSDictionary *dict,
333 __unused GPBFieldDescriptor *field) {
334 NSCAssert(field.mapKeyDataType == GPBDataTypeString, @"Unexpected key type");
335 NSCAssert(GPBGetFieldDataType(field) == GPBDataTypeMessage, @"Unexpected value type");
337 NSEnumerator *objects = [dict objectEnumerator];
338 while ((msg = [objects nextObject])) {
339 if (!msg.initialized) {
346 // Note: if the type is an object, it the retain pass back to the caller.
347 static void ReadValue(GPBCodedInputStream *stream, GPBGenericValue *valueToFill, GPBDataType type,
348 id<GPBExtensionRegistry> registry, GPBFieldDescriptor *field) {
350 case GPBDataTypeBool:
351 valueToFill->valueBool = GPBCodedInputStreamReadBool(&stream->state_);
353 case GPBDataTypeFixed32:
354 valueToFill->valueUInt32 = GPBCodedInputStreamReadFixed32(&stream->state_);
356 case GPBDataTypeSFixed32:
357 valueToFill->valueInt32 = GPBCodedInputStreamReadSFixed32(&stream->state_);
359 case GPBDataTypeFloat:
360 valueToFill->valueFloat = GPBCodedInputStreamReadFloat(&stream->state_);
362 case GPBDataTypeFixed64:
363 valueToFill->valueUInt64 = GPBCodedInputStreamReadFixed64(&stream->state_);
365 case GPBDataTypeSFixed64:
366 valueToFill->valueInt64 = GPBCodedInputStreamReadSFixed64(&stream->state_);
368 case GPBDataTypeDouble:
369 valueToFill->valueDouble = GPBCodedInputStreamReadDouble(&stream->state_);
371 case GPBDataTypeInt32:
372 valueToFill->valueInt32 = GPBCodedInputStreamReadInt32(&stream->state_);
374 case GPBDataTypeInt64:
375 valueToFill->valueInt64 = GPBCodedInputStreamReadInt64(&stream->state_);
377 case GPBDataTypeSInt32:
378 valueToFill->valueInt32 = GPBCodedInputStreamReadSInt32(&stream->state_);
380 case GPBDataTypeSInt64:
381 valueToFill->valueInt64 = GPBCodedInputStreamReadSInt64(&stream->state_);
383 case GPBDataTypeUInt32:
384 valueToFill->valueUInt32 = GPBCodedInputStreamReadUInt32(&stream->state_);
386 case GPBDataTypeUInt64:
387 valueToFill->valueUInt64 = GPBCodedInputStreamReadUInt64(&stream->state_);
389 case GPBDataTypeBytes:
390 [valueToFill->valueData release];
391 valueToFill->valueData = GPBCodedInputStreamReadRetainedBytes(&stream->state_);
393 case GPBDataTypeString:
394 [valueToFill->valueString release];
395 valueToFill->valueString = GPBCodedInputStreamReadRetainedString(&stream->state_);
397 case GPBDataTypeMessage: {
398 GPBMessage *message = [[field.msgClass alloc] init];
399 [stream readMessage:message extensionRegistry:registry];
400 [valueToFill->valueMessage release];
401 valueToFill->valueMessage = message;
404 case GPBDataTypeGroup:
405 NSCAssert(NO, @"Can't happen");
407 case GPBDataTypeEnum:
408 valueToFill->valueEnum = GPBCodedInputStreamReadEnum(&stream->state_);
413 void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream,
414 id<GPBExtensionRegistry> registry, GPBFieldDescriptor *field,
415 GPBMessage *parentMessage) {
416 GPBDataType keyDataType = field.mapKeyDataType;
417 GPBDataType valueDataType = GPBGetFieldDataType(field);
420 GPBGenericValue value;
421 // Zero them (but pick up any enum default for proto2).
422 key.valueString = value.valueString = nil;
423 if (valueDataType == GPBDataTypeEnum) {
424 value = field.defaultValue;
427 GPBCodedInputStreamState *state = &stream->state_;
428 uint32_t keyTag = GPBWireFormatMakeTag(kMapKeyFieldNumber, GPBWireFormatForType(keyDataType, NO));
430 GPBWireFormatMakeTag(kMapValueFieldNumber, GPBWireFormatForType(valueDataType, NO));
434 uint32_t tag = GPBCodedInputStreamReadTag(state);
436 ReadValue(stream, &key, keyDataType, registry, field);
437 } else if (tag == valueTag) {
438 ReadValue(stream, &value, valueDataType, registry, field);
439 } else if (tag == 0) {
440 // zero signals EOF / limit reached
443 if (![stream skipField:tag]) {
451 // Handle the special defaults and/or missing key/value.
452 if ((keyDataType == GPBDataTypeString) && (key.valueString == nil)) {
453 key.valueString = [@"" retain];
455 if (GPBDataTypeIsObject(valueDataType) && value.valueString == nil) {
456 #pragma clang diagnostic push
457 #pragma clang diagnostic ignored "-Wswitch-enum"
458 switch (valueDataType) {
459 case GPBDataTypeString:
460 value.valueString = [@"" retain];
462 case GPBDataTypeBytes:
463 value.valueData = [GPBEmptyNSData() retain];
465 #if defined(__clang_analyzer__)
466 case GPBDataTypeGroup:
467 // Maps can't really have Groups as the value type, but this case is needed
468 // so the analyzer won't report the possibility of send nil in for the value
469 // in the NSMutableDictionary case below.
471 case GPBDataTypeMessage: {
472 value.valueMessage = [[field.msgClass alloc] init];
479 #pragma clang diagnostic pop
482 if ((keyDataType == GPBDataTypeString) && GPBDataTypeIsObject(valueDataType)) {
483 // mapDictionary is an NSMutableDictionary
484 [(NSMutableDictionary *)mapDictionary setObject:value.valueString forKey:key.valueString];
486 if (valueDataType == GPBDataTypeEnum) {
487 if ([field.enumDescriptor isOpenOrValidValue:value.valueEnum]) {
488 [mapDictionary setGPBGenericValue:&value forGPBGenericValueKey:&key];
490 NSData *data = [mapDictionary serializedDataForUnknownValue:value.valueEnum
492 keyDataType:keyDataType];
493 [parentMessage addUnknownMapEntry:GPBFieldNumber(field) value:data];
496 [mapDictionary setGPBGenericValue:&value forGPBGenericValueKey:&key];
501 if (GPBDataTypeIsObject(keyDataType)) {
502 [key.valueString release];
504 if (GPBDataTypeIsObject(valueDataType)) {
505 [value.valueString release];
510 // Macros for the common basic cases.
513 // Disable clang-format for the macros.
516 //%PDDM-DEFINE DICTIONARY_IMPL_FOR_POD_KEY(KEY_NAME, KEY_TYPE)
517 //%DICTIONARY_POD_IMPL_FOR_KEY(KEY_NAME, KEY_TYPE, , POD)
518 //%DICTIONARY_POD_KEY_TO_OBJECT_IMPL(KEY_NAME, KEY_TYPE, Object, id)
520 //%PDDM-DEFINE DICTIONARY_POD_IMPL_FOR_KEY(KEY_NAME, KEY_TYPE, KisP, KHELPER)
521 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, UInt32, uint32_t, KHELPER)
522 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Int32, int32_t, KHELPER)
523 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, UInt64, uint64_t, KHELPER)
524 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Int64, int64_t, KHELPER)
525 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Bool, BOOL, KHELPER)
526 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Float, float, KHELPER)
527 //%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Double, double, KHELPER)
528 //%DICTIONARY_KEY_TO_ENUM_IMPL(KEY_NAME, KEY_TYPE, KisP, Enum, int32_t, KHELPER)
530 //%PDDM-DEFINE DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER)
531 //%DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, POD, VALUE_NAME, value)
533 //%PDDM-DEFINE DICTIONARY_POD_KEY_TO_OBJECT_IMPL(KEY_NAME, KEY_TYPE, VALUE_NAME, VALUE_TYPE)
534 //%DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, , VALUE_NAME, VALUE_TYPE, POD, OBJECT, Object, object)
536 //%PDDM-DEFINE DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR)
537 //%#pragma mark - KEY_NAME -> VALUE_NAME
539 //%@implementation GPB##KEY_NAME##VALUE_NAME##Dictionary {
541 //% NSMutableDictionary *_dictionary;
544 //%- (instancetype)init {
545 //% return [self initWith##VNAME##s:NULL forKeys:NULL count:0];
548 //%- (instancetype)initWith##VNAME##s:(const VALUE_TYPE [])##VNAME_VAR##s
549 //% ##VNAME$S## forKeys:(const KEY_TYPE##KisP$S##KisP [])keys
550 //% ##VNAME$S## count:(NSUInteger)count {
551 //% self = [super init];
553 //% _dictionary = [[NSMutableDictionary alloc] init];
554 //% if (count && VNAME_VAR##s && keys) {
555 //% for (NSUInteger i = 0; i < count; ++i) {
556 //%DICTIONARY_VALIDATE_VALUE_##VHELPER(VNAME_VAR##s[i], ______)##DICTIONARY_VALIDATE_KEY_##KHELPER(keys[i], ______) [_dictionary setObject:WRAPPED##VHELPER(VNAME_VAR##s[i]) forKey:WRAPPED##KHELPER(keys[i])];
563 //%- (instancetype)initWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary {
564 //% self = [self initWith##VNAME##s:NULL forKeys:NULL count:0];
566 //% if (dictionary) {
567 //% [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
573 //%- (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
574 //% return [self initWith##VNAME##s:NULL forKeys:NULL count:0];
577 //%DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, )
579 //%VALUE_FOR_KEY_##VHELPER(KEY_TYPE##KisP$S##KisP, VALUE_NAME, VALUE_TYPE, KHELPER)
581 //%DICTIONARY_MUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, )
586 //%PDDM-DEFINE DICTIONARY_KEY_TO_ENUM_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER)
587 //%DICTIONARY_KEY_TO_ENUM_IMPL2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, POD)
588 //%PDDM-DEFINE DICTIONARY_KEY_TO_ENUM_IMPL2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER)
589 //%#pragma mark - KEY_NAME -> VALUE_NAME
591 //%@implementation GPB##KEY_NAME##VALUE_NAME##Dictionary {
593 //% NSMutableDictionary *_dictionary;
594 //% GPBEnumValidationFunc _validationFunc;
597 //%@synthesize validationFunc = _validationFunc;
599 //%- (instancetype)init {
600 //% return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
603 //%- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
604 //% return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
607 //%- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
608 //% rawValues:(const VALUE_TYPE [])rawValues
609 //% forKeys:(const KEY_TYPE##KisP$S##KisP [])keys
610 //% count:(NSUInteger)count {
611 //% self = [super init];
613 //% _dictionary = [[NSMutableDictionary alloc] init];
614 //% _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
615 //% if (count && rawValues && keys) {
616 //% for (NSUInteger i = 0; i < count; ++i) {
617 //%DICTIONARY_VALIDATE_KEY_##KHELPER(keys[i], ______) [_dictionary setObject:WRAPPED##VHELPER(rawValues[i]) forKey:WRAPPED##KHELPER(keys[i])];
624 //%- (instancetype)initWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary {
625 //% self = [self initWithValidationFunction:dictionary.validationFunc
630 //% if (dictionary) {
631 //% [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
637 //%- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
638 //% capacity:(__unused NSUInteger)numItems {
639 //% return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
642 //%DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, Value, value, Raw)
644 //%- (BOOL)getEnum:(VALUE_TYPE *)value forKey:(KEY_TYPE##KisP$S##KisP)key {
645 //% NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)];
646 //% if (wrapped && value) {
647 //% VALUE_TYPE result = UNWRAP##VALUE_NAME(wrapped);
648 //% if (!_validationFunc(result)) {
649 //% result = kGPBUnrecognizedEnumeratorValue;
653 //% return (wrapped != NULL);
656 //%- (BOOL)getRawValue:(VALUE_TYPE *)rawValue forKey:(KEY_TYPE##KisP$S##KisP)key {
657 //% NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)];
658 //% if (wrapped && rawValue) {
659 //% *rawValue = UNWRAP##VALUE_NAME(wrapped);
661 //% return (wrapped != NULL);
664 //%- (void)enumerateKeysAndEnumsUsingBlock:
665 //% (void (NS_NOESCAPE ^)(KEY_TYPE KisP##key, VALUE_TYPE value, BOOL *stop))block {
666 //% GPBEnumValidationFunc func = _validationFunc;
668 //% NSEnumerator *keys = [_dictionary keyEnumerator];
669 //% ENUM_TYPE##KHELPER(KEY_TYPE)##aKey;
670 //% while ((aKey = [keys nextObject])) {
671 //% ENUM_TYPE##VHELPER(VALUE_TYPE)##aValue = _dictionary[aKey];
672 //% VALUE_TYPE unwrapped = UNWRAP##VALUE_NAME(aValue);
673 //% if (!func(unwrapped)) {
674 //% unwrapped = kGPBUnrecognizedEnumeratorValue;
676 //% block(UNWRAP##KEY_NAME(aKey), unwrapped, &stop);
683 //%DICTIONARY_MUTABLE_CORE2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, Value, Enum, value, Raw)
685 //%- (void)setEnum:(VALUE_TYPE)value forKey:(KEY_TYPE##KisP$S##KisP)key {
686 //%DICTIONARY_VALIDATE_KEY_##KHELPER(key, ) if (!_validationFunc(value)) {
687 //% [NSException raise:NSInvalidArgumentException
688 //% format:@"GPB##KEY_NAME##VALUE_NAME##Dictionary: Attempt to set an unknown enum value (%d)",
692 //% [_dictionary setObject:WRAPPED##VHELPER(value) forKey:WRAPPED##KHELPER(key)];
693 //% if (_autocreator) {
694 //% GPBAutocreatedDictionaryModified(_autocreator, self);
701 //%PDDM-DEFINE DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, ACCESSOR_NAME)
703 //% NSAssert(!_autocreator,
704 //% @"%@: Autocreator must be cleared before release, autocreator: %@",
705 //% [self class], _autocreator);
706 //% [_dictionary release];
710 //%- (instancetype)copyWithZone:(NSZone *)zone {
711 //% return [[GPB##KEY_NAME##VALUE_NAME##Dictionary allocWithZone:zone] initWithDictionary:self];
714 //%- (BOOL)isEqual:(id)other {
715 //% if (self == other) {
718 //% if (![other isKindOfClass:[GPB##KEY_NAME##VALUE_NAME##Dictionary class]]) {
721 //% GPB##KEY_NAME##VALUE_NAME##Dictionary *otherDictionary = other;
722 //% return [_dictionary isEqual:otherDictionary->_dictionary];
725 //%- (NSUInteger)hash {
726 //% return _dictionary.count;
729 //%- (NSString *)description {
730 //% return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
733 //%- (NSUInteger)count {
734 //% return _dictionary.count;
737 //%- (void)enumerateKeysAnd##ACCESSOR_NAME##VNAME##sUsingBlock:
738 //% (void (NS_NOESCAPE ^)(KEY_TYPE KisP##key, VALUE_TYPE VNAME_VAR, BOOL *stop))block {
740 //% NSDictionary *internal = _dictionary;
741 //% NSEnumerator *keys = [internal keyEnumerator];
742 //% ENUM_TYPE##KHELPER(KEY_TYPE)##aKey;
743 //% while ((aKey = [keys nextObject])) {
744 //% ENUM_TYPE##VHELPER(VALUE_TYPE)##a##VNAME_VAR$u = internal[aKey];
745 //% block(UNWRAP##KEY_NAME(aKey), UNWRAP##VALUE_NAME(a##VNAME_VAR$u), &stop);
752 //%EXTRA_METHODS_##VHELPER(KEY_NAME, VALUE_NAME)- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
753 //% NSDictionary *internal = _dictionary;
754 //% NSUInteger count = internal.count;
755 //% if (count == 0) {
759 //% GPBDataType valueDataType = GPBGetFieldDataType(field);
760 //% GPBDataType keyDataType = field.mapKeyDataType;
761 //% size_t result = 0;
762 //% NSEnumerator *keys = [internal keyEnumerator];
763 //% ENUM_TYPE##KHELPER(KEY_TYPE)##aKey;
764 //% while ((aKey = [keys nextObject])) {
765 //% ENUM_TYPE##VHELPER(VALUE_TYPE)##a##VNAME_VAR$u = internal[aKey];
766 //% size_t msgSize = ComputeDict##KEY_NAME##FieldSize(UNWRAP##KEY_NAME(aKey), kMapKeyFieldNumber, keyDataType);
767 //% msgSize += ComputeDict##VALUE_NAME##FieldSize(UNWRAP##VALUE_NAME(a##VNAME_VAR$u), kMapValueFieldNumber, valueDataType);
768 //% result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
770 //% size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
771 //% result += tagSize * count;
775 //%- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
776 //% asField:(GPBFieldDescriptor *)field {
777 //% GPBDataType valueDataType = GPBGetFieldDataType(field);
778 //% GPBDataType keyDataType = field.mapKeyDataType;
779 //% uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
780 //% NSDictionary *internal = _dictionary;
781 //% NSEnumerator *keys = [internal keyEnumerator];
782 //% ENUM_TYPE##KHELPER(KEY_TYPE)##aKey;
783 //% while ((aKey = [keys nextObject])) {
784 //% ENUM_TYPE##VHELPER(VALUE_TYPE)##a##VNAME_VAR$u = internal[aKey];
785 //% [outputStream writeInt32NoTag:tag];
786 //% // Write the size of the message.
787 //% KEY_TYPE KisP##unwrappedKey = UNWRAP##KEY_NAME(aKey);
788 //% VALUE_TYPE unwrappedValue = UNWRAP##VALUE_NAME(a##VNAME_VAR$u);
789 //% size_t msgSize = ComputeDict##KEY_NAME##FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
790 //% msgSize += ComputeDict##VALUE_NAME##FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
791 //% [outputStream writeInt32NoTag:(int32_t)msgSize];
792 //% // Write the fields.
793 //% WriteDict##KEY_NAME##Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
794 //% WriteDict##VALUE_NAME##Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
798 //%SERIAL_DATA_FOR_ENTRY_##VHELPER(KEY_NAME, VALUE_NAME)- (void)setGPBGenericValue:(GPBGenericValue *)value
799 //% forGPBGenericValueKey:(GPBGenericValue *)key {
800 //% [_dictionary setObject:WRAPPED##VHELPER(value->##GPBVALUE_##VHELPER(VALUE_NAME)##) forKey:WRAPPED##KHELPER(key->value##KEY_NAME)];
803 //%- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
804 //% [self enumerateKeysAnd##ACCESSOR_NAME##VNAME##sUsingBlock:^(KEY_TYPE KisP##key, VALUE_TYPE VNAME_VAR, __unused BOOL *stop) {
805 //% block(TEXT_FORMAT_OBJ##KEY_NAME(key), TEXT_FORMAT_OBJ##VALUE_NAME(VNAME_VAR));
808 //%PDDM-DEFINE DICTIONARY_MUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, ACCESSOR_NAME)
809 //%DICTIONARY_MUTABLE_CORE2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME, VNAME_VAR, ACCESSOR_NAME)
810 //%PDDM-DEFINE DICTIONARY_MUTABLE_CORE2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_REMOVE, VNAME_VAR, ACCESSOR_NAME)
811 //%- (void)add##ACCESSOR_NAME##EntriesFromDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)otherDictionary {
812 //% if (otherDictionary) {
813 //% [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
814 //% if (_autocreator) {
815 //% GPBAutocreatedDictionaryModified(_autocreator, self);
820 //%- (void)set##ACCESSOR_NAME##VNAME##:(VALUE_TYPE)VNAME_VAR forKey:(KEY_TYPE##KisP$S##KisP)key {
821 //%DICTIONARY_VALIDATE_VALUE_##VHELPER(VNAME_VAR, )##DICTIONARY_VALIDATE_KEY_##KHELPER(key, ) [_dictionary setObject:WRAPPED##VHELPER(VNAME_VAR) forKey:WRAPPED##KHELPER(key)];
822 //% if (_autocreator) {
823 //% GPBAutocreatedDictionaryModified(_autocreator, self);
827 //%- (void)remove##VNAME_REMOVE##ForKey:(KEY_TYPE##KisP$S##KisP)aKey {
828 //% [_dictionary removeObjectForKey:WRAPPED##KHELPER(aKey)];
831 //%- (void)removeAll {
832 //% [_dictionary removeAllObjects];
836 // Custom Generation for Bool keys
839 //%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_POD_IMPL(VALUE_NAME, VALUE_TYPE)
840 //%DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, POD, VALUE_NAME, value)
841 //%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_OBJECT_IMPL(VALUE_NAME, VALUE_TYPE)
842 //%DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, OBJECT, Object, object)
844 //%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, HELPER, VNAME, VNAME_VAR)
845 //%#pragma mark - Bool -> VALUE_NAME
847 //%@implementation GPBBool##VALUE_NAME##Dictionary {
849 //% VALUE_TYPE _values[2];
850 //%BOOL_DICT_HAS_STORAGE_##HELPER()}
852 //%- (instancetype)init {
853 //% return [self initWith##VNAME##s:NULL forKeys:NULL count:0];
856 //%BOOL_DICT_INITS_##HELPER(VALUE_NAME, VALUE_TYPE)
858 //%- (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
859 //% return [self initWith##VNAME##s:NULL forKeys:NULL count:0];
862 //%BOOL_DICT_DEALLOC##HELPER()
864 //%- (instancetype)copyWithZone:(NSZone *)zone {
865 //% return [[GPBBool##VALUE_NAME##Dictionary allocWithZone:zone] initWithDictionary:self];
868 //%- (BOOL)isEqual:(id)other {
869 //% if (self == other) {
872 //% if (![other isKindOfClass:[GPBBool##VALUE_NAME##Dictionary class]]) {
875 //% GPBBool##VALUE_NAME##Dictionary *otherDictionary = other;
876 //% if ((BOOL_DICT_W_HAS##HELPER(0, ) != BOOL_DICT_W_HAS##HELPER(0, otherDictionary->)) ||
877 //% (BOOL_DICT_W_HAS##HELPER(1, ) != BOOL_DICT_W_HAS##HELPER(1, otherDictionary->))) {
880 //% if ((BOOL_DICT_W_HAS##HELPER(0, ) && (NEQ_##HELPER(_values[0], otherDictionary->_values[0]))) ||
881 //% (BOOL_DICT_W_HAS##HELPER(1, ) && (NEQ_##HELPER(_values[1], otherDictionary->_values[1])))) {
887 //%- (NSUInteger)hash {
888 //% return (BOOL_DICT_W_HAS##HELPER(0, ) ? 1 : 0) + (BOOL_DICT_W_HAS##HELPER(1, ) ? 1 : 0);
891 //%- (NSString *)description {
892 //% NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
893 //% if (BOOL_DICT_W_HAS##HELPER(0, )) {
894 //% [result appendFormat:@"NO: STR_FORMAT_##HELPER(VALUE_NAME)", _values[0]];
896 //% if (BOOL_DICT_W_HAS##HELPER(1, )) {
897 //% [result appendFormat:@"YES: STR_FORMAT_##HELPER(VALUE_NAME)", _values[1]];
899 //% [result appendString:@" }"];
903 //%- (NSUInteger)count {
904 //% return (BOOL_DICT_W_HAS##HELPER(0, ) ? 1 : 0) + (BOOL_DICT_W_HAS##HELPER(1, ) ? 1 : 0);
907 //%BOOL_VALUE_FOR_KEY_##HELPER(VALUE_NAME, VALUE_TYPE)
909 //%BOOL_SET_GPBVALUE_FOR_KEY_##HELPER(VALUE_NAME, VALUE_TYPE, VisP)
911 //%- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
912 //% if (BOOL_DICT_HAS##HELPER(0, )) {
913 //% block(@"false", TEXT_FORMAT_OBJ##VALUE_NAME(_values[0]));
915 //% if (BOOL_DICT_W_HAS##HELPER(1, )) {
916 //% block(@"true", TEXT_FORMAT_OBJ##VALUE_NAME(_values[1]));
920 //%- (void)enumerateKeysAnd##VNAME##sUsingBlock:
921 //% (void (NS_NOESCAPE ^)(BOOL key, VALUE_TYPE VNAME_VAR, BOOL *stop))block {
923 //% if (BOOL_DICT_HAS##HELPER(0, )) {
924 //% block(NO, _values[0], &stop);
926 //% if (!stop && BOOL_DICT_W_HAS##HELPER(1, )) {
927 //% block(YES, _values[1], &stop);
931 //%BOOL_EXTRA_METHODS_##HELPER(Bool, VALUE_NAME)- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
932 //% GPBDataType valueDataType = GPBGetFieldDataType(field);
933 //% NSUInteger count = 0;
934 //% size_t result = 0;
935 //% for (int i = 0; i < 2; ++i) {
936 //% if (BOOL_DICT_HAS##HELPER(i, )) {
938 //% size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
939 //% msgSize += ComputeDict##VALUE_NAME##FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
940 //% result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
943 //% size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
944 //% result += tagSize * count;
948 //%- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
949 //% asField:(GPBFieldDescriptor *)field {
950 //% GPBDataType valueDataType = GPBGetFieldDataType(field);
951 //% uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
952 //% for (int i = 0; i < 2; ++i) {
953 //% if (BOOL_DICT_HAS##HELPER(i, )) {
954 //% // Write the tag.
955 //% [outputStream writeInt32NoTag:tag];
956 //% // Write the size of the message.
957 //% size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
958 //% msgSize += ComputeDict##VALUE_NAME##FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
959 //% [outputStream writeInt32NoTag:(int32_t)msgSize];
960 //% // Write the fields.
961 //% WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
962 //% WriteDict##VALUE_NAME##Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
967 //%BOOL_DICT_MUTATIONS_##HELPER(VALUE_NAME, VALUE_TYPE)
977 //%PDDM-DEFINE VALUE_FOR_KEY_POD(KEY_TYPE, VALUE_NAME, VALUE_TYPE, KHELPER)
978 //%- (BOOL)get##VALUE_NAME##:(nullable VALUE_TYPE *)value forKey:(KEY_TYPE)key {
979 //% NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)];
980 //% if (wrapped && value) {
981 //% *value = UNWRAP##VALUE_NAME(wrapped);
983 //% return (wrapped != NULL);
985 //%PDDM-DEFINE WRAPPEDPOD(VALUE)
987 //%PDDM-DEFINE UNWRAPUInt32(VALUE)
988 //%[VALUE unsignedIntValue]
989 //%PDDM-DEFINE UNWRAPInt32(VALUE)
991 //%PDDM-DEFINE UNWRAPUInt64(VALUE)
992 //%[VALUE unsignedLongLongValue]
993 //%PDDM-DEFINE UNWRAPInt64(VALUE)
994 //%[VALUE longLongValue]
995 //%PDDM-DEFINE UNWRAPBool(VALUE)
997 //%PDDM-DEFINE UNWRAPFloat(VALUE)
998 //%[VALUE floatValue]
999 //%PDDM-DEFINE UNWRAPDouble(VALUE)
1000 //%[VALUE doubleValue]
1001 //%PDDM-DEFINE UNWRAPEnum(VALUE)
1003 //%PDDM-DEFINE TEXT_FORMAT_OBJUInt32(VALUE)
1004 //%[NSString stringWithFormat:@"%u", VALUE]
1005 //%PDDM-DEFINE TEXT_FORMAT_OBJInt32(VALUE)
1006 //%[NSString stringWithFormat:@"%d", VALUE]
1007 //%PDDM-DEFINE TEXT_FORMAT_OBJUInt64(VALUE)
1008 //%[NSString stringWithFormat:@"%llu", VALUE]
1009 //%PDDM-DEFINE TEXT_FORMAT_OBJInt64(VALUE)
1010 //%[NSString stringWithFormat:@"%lld", VALUE]
1011 //%PDDM-DEFINE TEXT_FORMAT_OBJBool(VALUE)
1012 //%(VALUE ? @"true" : @"false")
1013 //%PDDM-DEFINE TEXT_FORMAT_OBJFloat(VALUE)
1014 //%[NSString stringWithFormat:@"%.*g", FLT_DIG, VALUE]
1015 //%PDDM-DEFINE TEXT_FORMAT_OBJDouble(VALUE)
1016 //%[NSString stringWithFormat:@"%.*lg", DBL_DIG, VALUE]
1017 //%PDDM-DEFINE TEXT_FORMAT_OBJEnum(VALUE)
1019 //%PDDM-DEFINE ENUM_TYPEPOD(TYPE)
1021 //%PDDM-DEFINE NEQ_POD(VAL1, VAL2)
1023 //%PDDM-DEFINE EXTRA_METHODS_POD(KEY_NAME, VALUE_NAME)
1025 //%PDDM-DEFINE BOOL_EXTRA_METHODS_POD(KEY_NAME, VALUE_NAME)
1027 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD(KEY_NAME, VALUE_NAME)
1028 //%SERIAL_DATA_FOR_ENTRY_POD_##VALUE_NAME(KEY_NAME)
1029 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_UInt32(KEY_NAME)
1031 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Int32(KEY_NAME)
1033 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_UInt64(KEY_NAME)
1035 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Int64(KEY_NAME)
1037 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Bool(KEY_NAME)
1039 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Float(KEY_NAME)
1041 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Double(KEY_NAME)
1043 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Enum(KEY_NAME)
1044 //%- (NSData *)serializedDataForUnknownValue:(int32_t)value
1045 //% forKey:(GPBGenericValue *)key
1046 //% keyDataType:(GPBDataType)keyDataType {
1047 //% size_t msgSize = ComputeDict##KEY_NAME##FieldSize(key->value##KEY_NAME, kMapKeyFieldNumber, keyDataType);
1048 //% msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
1049 //% NSMutableData *data = [NSMutableData dataWithLength:msgSize];
1050 //% GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
1051 //% WriteDict##KEY_NAME##Field(outputStream, key->value##KEY_NAME, kMapKeyFieldNumber, keyDataType);
1052 //% WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
1053 //% [outputStream flush];
1054 //% [outputStream release];
1058 //%PDDM-DEFINE GPBVALUE_POD(VALUE_NAME)
1059 //%value##VALUE_NAME
1060 //%PDDM-DEFINE DICTIONARY_VALIDATE_VALUE_POD(VALUE_NAME, EXTRA_INDENT)
1062 //%PDDM-DEFINE DICTIONARY_VALIDATE_KEY_POD(KEY_NAME, EXTRA_INDENT)
1065 //%PDDM-DEFINE BOOL_DICT_HAS_STORAGE_POD()
1066 //% BOOL _valueSet[2];
1068 //%PDDM-DEFINE BOOL_DICT_INITS_POD(VALUE_NAME, VALUE_TYPE)
1069 //%- (instancetype)initWith##VALUE_NAME##s:(const VALUE_TYPE [])values
1070 //% ##VALUE_NAME$S## forKeys:(const BOOL [])keys
1071 //% ##VALUE_NAME$S## count:(NSUInteger)count {
1072 //% self = [super init];
1074 //% for (NSUInteger i = 0; i < count; ++i) {
1075 //% int idx = keys[i] ? 1 : 0;
1076 //% _values[idx] = values[i];
1077 //% _valueSet[idx] = YES;
1083 //%- (instancetype)initWithDictionary:(GPBBool##VALUE_NAME##Dictionary *)dictionary {
1084 //% self = [self initWith##VALUE_NAME##s:NULL forKeys:NULL count:0];
1086 //% if (dictionary) {
1087 //% for (int i = 0; i < 2; ++i) {
1088 //% if (dictionary->_valueSet[i]) {
1089 //% _values[i] = dictionary->_values[i];
1090 //% _valueSet[i] = YES;
1097 //%PDDM-DEFINE BOOL_DICT_DEALLOCPOD()
1098 //%#if !defined(NS_BLOCK_ASSERTIONS)
1099 //%- (void)dealloc {
1100 //% NSAssert(!_autocreator,
1101 //% @"%@: Autocreator must be cleared before release, autocreator: %@",
1102 //% [self class], _autocreator);
1103 //% [super dealloc];
1105 //%#endif // !defined(NS_BLOCK_ASSERTIONS)
1106 //%PDDM-DEFINE BOOL_DICT_W_HASPOD(IDX, REF)
1107 //%BOOL_DICT_HASPOD(IDX, REF)
1108 //%PDDM-DEFINE BOOL_DICT_HASPOD(IDX, REF)
1109 //%REF##_valueSet[IDX]
1110 //%PDDM-DEFINE BOOL_VALUE_FOR_KEY_POD(VALUE_NAME, VALUE_TYPE)
1111 //%- (BOOL)get##VALUE_NAME##:(VALUE_TYPE *)value forKey:(BOOL)key {
1112 //% int idx = (key ? 1 : 0);
1113 //% if (_valueSet[idx]) {
1115 //% *value = _values[idx];
1121 //%PDDM-DEFINE BOOL_SET_GPBVALUE_FOR_KEY_POD(VALUE_NAME, VALUE_TYPE, VisP)
1122 //%- (void)setGPBGenericValue:(GPBGenericValue *)value
1123 //% forGPBGenericValueKey:(GPBGenericValue *)key {
1124 //% int idx = (key->valueBool ? 1 : 0);
1125 //% _values[idx] = value->value##VALUE_NAME;
1126 //% _valueSet[idx] = YES;
1128 //%PDDM-DEFINE BOOL_DICT_MUTATIONS_POD(VALUE_NAME, VALUE_TYPE)
1129 //%- (void)addEntriesFromDictionary:(GPBBool##VALUE_NAME##Dictionary *)otherDictionary {
1130 //% if (otherDictionary) {
1131 //% for (int i = 0; i < 2; ++i) {
1132 //% if (otherDictionary->_valueSet[i]) {
1133 //% _valueSet[i] = YES;
1134 //% _values[i] = otherDictionary->_values[i];
1137 //% if (_autocreator) {
1138 //% GPBAutocreatedDictionaryModified(_autocreator, self);
1143 //%- (void)set##VALUE_NAME:(VALUE_TYPE)value forKey:(BOOL)key {
1144 //% int idx = (key ? 1 : 0);
1145 //% _values[idx] = value;
1146 //% _valueSet[idx] = YES;
1147 //% if (_autocreator) {
1148 //% GPBAutocreatedDictionaryModified(_autocreator, self);
1152 //%- (void)remove##VALUE_NAME##ForKey:(BOOL)aKey {
1153 //% _valueSet[aKey ? 1 : 0] = NO;
1156 //%- (void)removeAll {
1157 //% _valueSet[0] = NO;
1158 //% _valueSet[1] = NO;
1160 //%PDDM-DEFINE STR_FORMAT_POD(VALUE_NAME)
1161 //%STR_FORMAT_##VALUE_NAME()
1162 //%PDDM-DEFINE STR_FORMAT_UInt32()
1164 //%PDDM-DEFINE STR_FORMAT_Int32()
1166 //%PDDM-DEFINE STR_FORMAT_UInt64()
1168 //%PDDM-DEFINE STR_FORMAT_Int64()
1170 //%PDDM-DEFINE STR_FORMAT_Bool()
1172 //%PDDM-DEFINE STR_FORMAT_Float()
1174 //%PDDM-DEFINE STR_FORMAT_Double()
1178 // Helpers for Objects
1181 //%PDDM-DEFINE VALUE_FOR_KEY_OBJECT(KEY_TYPE, VALUE_NAME, VALUE_TYPE, KHELPER)
1182 //%- (VALUE_TYPE)objectForKey:(KEY_TYPE)key {
1183 //% VALUE_TYPE result = [_dictionary objectForKey:WRAPPED##KHELPER(key)];
1186 //%PDDM-DEFINE WRAPPEDOBJECT(VALUE)
1188 //%PDDM-DEFINE UNWRAPString(VALUE)
1190 //%PDDM-DEFINE UNWRAPObject(VALUE)
1192 //%PDDM-DEFINE TEXT_FORMAT_OBJString(VALUE)
1194 //%PDDM-DEFINE TEXT_FORMAT_OBJObject(VALUE)
1196 //%PDDM-DEFINE ENUM_TYPEOBJECT(TYPE)
1197 //%ENUM_TYPEOBJECT_##TYPE()
1198 //%PDDM-DEFINE ENUM_TYPEOBJECT_NSString()
1200 //%PDDM-DEFINE ENUM_TYPEOBJECT_id()
1202 //%PDDM-DEFINE NEQ_OBJECT(VAL1, VAL2)
1203 //%![VAL1 isEqual:VAL2]
1204 //%PDDM-DEFINE EXTRA_METHODS_OBJECT(KEY_NAME, VALUE_NAME)
1205 //%- (BOOL)isInitialized {
1206 //% for (GPBMessage *msg in [_dictionary objectEnumerator]) {
1207 //% if (!msg.initialized) {
1214 //%- (instancetype)deepCopyWithZone:(NSZone *)zone {
1215 //% GPB##KEY_NAME##VALUE_NAME##Dictionary *newDict =
1216 //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] init];
1217 //% NSEnumerator *keys = [_dictionary keyEnumerator];
1219 //% NSMutableDictionary *internalDict = newDict->_dictionary;
1220 //% while ((aKey = [keys nextObject])) {
1221 //% GPBMessage *msg = _dictionary[aKey];
1222 //% GPBMessage *copiedMsg = [msg copyWithZone:zone];
1223 //% [internalDict setObject:copiedMsg forKey:aKey];
1224 //% [copiedMsg release];
1230 //%PDDM-DEFINE BOOL_EXTRA_METHODS_OBJECT(KEY_NAME, VALUE_NAME)
1231 //%- (BOOL)isInitialized {
1232 //% if (_values[0] && ![_values[0] isInitialized]) {
1235 //% if (_values[1] && ![_values[1] isInitialized]) {
1241 //%- (instancetype)deepCopyWithZone:(NSZone *)zone {
1242 //% GPB##KEY_NAME##VALUE_NAME##Dictionary *newDict =
1243 //% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] init];
1244 //% for (int i = 0; i < 2; ++i) {
1245 //% if (_values[i] != nil) {
1246 //% newDict->_values[i] = [_values[i] copyWithZone:zone];
1253 //%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_OBJECT(KEY_NAME, VALUE_NAME)
1255 //%PDDM-DEFINE GPBVALUE_OBJECT(VALUE_NAME)
1257 //%PDDM-DEFINE DICTIONARY_VALIDATE_VALUE_OBJECT(VALUE_NAME, EXTRA_INDENT)
1258 //%##EXTRA_INDENT$S## if (!##VALUE_NAME) {
1259 //%##EXTRA_INDENT$S## [NSException raise:NSInvalidArgumentException
1260 //%##EXTRA_INDENT$S## format:@"Attempting to add nil object to a Dictionary"];
1261 //%##EXTRA_INDENT$S## }
1263 //%PDDM-DEFINE DICTIONARY_VALIDATE_KEY_OBJECT(KEY_NAME, EXTRA_INDENT)
1264 //%##EXTRA_INDENT$S## if (!##KEY_NAME) {
1265 //%##EXTRA_INDENT$S## [NSException raise:NSInvalidArgumentException
1266 //%##EXTRA_INDENT$S## format:@"Attempting to add nil key to a Dictionary"];
1267 //%##EXTRA_INDENT$S## }
1270 //%PDDM-DEFINE BOOL_DICT_HAS_STORAGE_OBJECT()
1272 //%PDDM-DEFINE BOOL_DICT_INITS_OBJECT(VALUE_NAME, VALUE_TYPE)
1273 //%- (instancetype)initWithObjects:(const VALUE_TYPE [])objects
1274 //% forKeys:(const BOOL [])keys
1275 //% count:(NSUInteger)count {
1276 //% self = [super init];
1278 //% for (NSUInteger i = 0; i < count; ++i) {
1279 //% if (!objects[i]) {
1280 //% [NSException raise:NSInvalidArgumentException
1281 //% format:@"Attempting to add nil object to a Dictionary"];
1283 //% int idx = keys[i] ? 1 : 0;
1284 //% [_values[idx] release];
1285 //% _values[idx] = (VALUE_TYPE)[objects[i] retain];
1291 //%- (instancetype)initWithDictionary:(GPBBool##VALUE_NAME##Dictionary *)dictionary {
1292 //% self = [self initWithObjects:NULL forKeys:NULL count:0];
1294 //% if (dictionary) {
1295 //% _values[0] = [dictionary->_values[0] retain];
1296 //% _values[1] = [dictionary->_values[1] retain];
1301 //%PDDM-DEFINE BOOL_DICT_DEALLOCOBJECT()
1302 //%- (void)dealloc {
1303 //% NSAssert(!_autocreator,
1304 //% @"%@: Autocreator must be cleared before release, autocreator: %@",
1305 //% [self class], _autocreator);
1306 //% [_values[0] release];
1307 //% [_values[1] release];
1308 //% [super dealloc];
1310 //%PDDM-DEFINE BOOL_DICT_W_HASOBJECT(IDX, REF)
1311 //%(BOOL_DICT_HASOBJECT(IDX, REF))
1312 //%PDDM-DEFINE BOOL_DICT_HASOBJECT(IDX, REF)
1313 //%REF##_values[IDX] != nil
1314 //%PDDM-DEFINE BOOL_VALUE_FOR_KEY_OBJECT(VALUE_NAME, VALUE_TYPE)
1315 //%- (VALUE_TYPE)objectForKey:(BOOL)key {
1316 //% return _values[key ? 1 : 0];
1318 //%PDDM-DEFINE BOOL_SET_GPBVALUE_FOR_KEY_OBJECT(VALUE_NAME, VALUE_TYPE, VisP)
1319 //%- (void)setGPBGenericValue:(GPBGenericValue *)value
1320 //% forGPBGenericValueKey:(GPBGenericValue *)key {
1321 //% int idx = (key->valueBool ? 1 : 0);
1322 //% [_values[idx] release];
1323 //% _values[idx] = [value->valueString retain];
1326 //%PDDM-DEFINE BOOL_DICT_MUTATIONS_OBJECT(VALUE_NAME, VALUE_TYPE)
1327 //%- (void)addEntriesFromDictionary:(GPBBool##VALUE_NAME##Dictionary *)otherDictionary {
1328 //% if (otherDictionary) {
1329 //% for (int i = 0; i < 2; ++i) {
1330 //% if (otherDictionary->_values[i] != nil) {
1331 //% [_values[i] release];
1332 //% _values[i] = [otherDictionary->_values[i] retain];
1335 //% if (_autocreator) {
1336 //% GPBAutocreatedDictionaryModified(_autocreator, self);
1341 //%- (void)setObject:(VALUE_TYPE)object forKey:(BOOL)key {
1343 //% [NSException raise:NSInvalidArgumentException
1344 //% format:@"Attempting to add nil object to a Dictionary"];
1346 //% int idx = (key ? 1 : 0);
1347 //% [_values[idx] release];
1348 //% _values[idx] = [object retain];
1349 //% if (_autocreator) {
1350 //% GPBAutocreatedDictionaryModified(_autocreator, self);
1354 //%- (void)removeObjectForKey:(BOOL)aKey {
1355 //% int idx = (aKey ? 1 : 0);
1356 //% [_values[idx] release];
1357 //% _values[idx] = nil;
1360 //%- (void)removeAll {
1361 //% for (int i = 0; i < 2; ++i) {
1362 //% [_values[i] release];
1363 //% _values[i] = nil;
1366 //%PDDM-DEFINE STR_FORMAT_OBJECT(VALUE_NAME)
1370 //%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(UInt32, uint32_t)
1371 // This block of code is generated, do not edit it directly.
1373 #pragma mark - UInt32 -> UInt32
1375 @implementation GPBUInt32UInt32Dictionary {
1377 NSMutableDictionary *_dictionary;
1380 - (instancetype)init {
1381 return [self initWithUInt32s:NULL forKeys:NULL count:0];
1384 - (instancetype)initWithUInt32s:(const uint32_t [])values
1385 forKeys:(const uint32_t [])keys
1386 count:(NSUInteger)count {
1387 self = [super init];
1389 _dictionary = [[NSMutableDictionary alloc] init];
1390 if (count && values && keys) {
1391 for (NSUInteger i = 0; i < count; ++i) {
1392 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
1399 - (instancetype)initWithDictionary:(GPBUInt32UInt32Dictionary *)dictionary {
1400 self = [self initWithUInt32s:NULL forKeys:NULL count:0];
1403 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
1409 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
1410 return [self initWithUInt32s:NULL forKeys:NULL count:0];
1414 NSAssert(!_autocreator,
1415 @"%@: Autocreator must be cleared before release, autocreator: %@",
1416 [self class], _autocreator);
1417 [_dictionary release];
1421 - (instancetype)copyWithZone:(NSZone *)zone {
1422 return [[GPBUInt32UInt32Dictionary allocWithZone:zone] initWithDictionary:self];
1425 - (BOOL)isEqual:(id)other {
1426 if (self == other) {
1429 if (![other isKindOfClass:[GPBUInt32UInt32Dictionary class]]) {
1432 GPBUInt32UInt32Dictionary *otherDictionary = other;
1433 return [_dictionary isEqual:otherDictionary->_dictionary];
1436 - (NSUInteger)hash {
1437 return _dictionary.count;
1440 - (NSString *)description {
1441 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
1444 - (NSUInteger)count {
1445 return _dictionary.count;
1448 - (void)enumerateKeysAndUInt32sUsingBlock:
1449 (void (NS_NOESCAPE ^)(uint32_t key, uint32_t value, BOOL *stop))block {
1451 NSDictionary *internal = _dictionary;
1452 NSEnumerator *keys = [internal keyEnumerator];
1454 while ((aKey = [keys nextObject])) {
1455 NSNumber *aValue = internal[aKey];
1456 block([aKey unsignedIntValue], [aValue unsignedIntValue], &stop);
1463 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
1464 NSDictionary *internal = _dictionary;
1465 NSUInteger count = internal.count;
1470 GPBDataType valueDataType = GPBGetFieldDataType(field);
1471 GPBDataType keyDataType = field.mapKeyDataType;
1473 NSEnumerator *keys = [internal keyEnumerator];
1475 while ((aKey = [keys nextObject])) {
1476 NSNumber *aValue = internal[aKey];
1477 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
1478 msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
1479 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
1481 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
1482 result += tagSize * count;
1486 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
1487 asField:(GPBFieldDescriptor *)field {
1488 GPBDataType valueDataType = GPBGetFieldDataType(field);
1489 GPBDataType keyDataType = field.mapKeyDataType;
1490 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
1491 NSDictionary *internal = _dictionary;
1492 NSEnumerator *keys = [internal keyEnumerator];
1494 while ((aKey = [keys nextObject])) {
1495 NSNumber *aValue = internal[aKey];
1496 [outputStream writeInt32NoTag:tag];
1497 // Write the size of the message.
1498 uint32_t unwrappedKey = [aKey unsignedIntValue];
1499 uint32_t unwrappedValue = [aValue unsignedIntValue];
1500 size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
1501 msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
1502 [outputStream writeInt32NoTag:(int32_t)msgSize];
1503 // Write the fields.
1504 WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
1505 WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
1509 - (void)setGPBGenericValue:(GPBGenericValue *)value
1510 forGPBGenericValueKey:(GPBGenericValue *)key {
1511 [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueUInt32)];
1514 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
1515 [self enumerateKeysAndUInt32sUsingBlock:^(uint32_t key, uint32_t value, __unused BOOL *stop) {
1516 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%u", value]);
1520 - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(uint32_t)key {
1521 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
1522 if (wrapped && value) {
1523 *value = [wrapped unsignedIntValue];
1525 return (wrapped != NULL);
1528 - (void)addEntriesFromDictionary:(GPBUInt32UInt32Dictionary *)otherDictionary {
1529 if (otherDictionary) {
1530 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
1532 GPBAutocreatedDictionaryModified(_autocreator, self);
1537 - (void)setUInt32:(uint32_t)value forKey:(uint32_t)key {
1538 [_dictionary setObject:@(value) forKey:@(key)];
1540 GPBAutocreatedDictionaryModified(_autocreator, self);
1544 - (void)removeUInt32ForKey:(uint32_t)aKey {
1545 [_dictionary removeObjectForKey:@(aKey)];
1549 [_dictionary removeAllObjects];
1554 #pragma mark - UInt32 -> Int32
1556 @implementation GPBUInt32Int32Dictionary {
1558 NSMutableDictionary *_dictionary;
1561 - (instancetype)init {
1562 return [self initWithInt32s:NULL forKeys:NULL count:0];
1565 - (instancetype)initWithInt32s:(const int32_t [])values
1566 forKeys:(const uint32_t [])keys
1567 count:(NSUInteger)count {
1568 self = [super init];
1570 _dictionary = [[NSMutableDictionary alloc] init];
1571 if (count && values && keys) {
1572 for (NSUInteger i = 0; i < count; ++i) {
1573 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
1580 - (instancetype)initWithDictionary:(GPBUInt32Int32Dictionary *)dictionary {
1581 self = [self initWithInt32s:NULL forKeys:NULL count:0];
1584 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
1590 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
1591 return [self initWithInt32s:NULL forKeys:NULL count:0];
1595 NSAssert(!_autocreator,
1596 @"%@: Autocreator must be cleared before release, autocreator: %@",
1597 [self class], _autocreator);
1598 [_dictionary release];
1602 - (instancetype)copyWithZone:(NSZone *)zone {
1603 return [[GPBUInt32Int32Dictionary allocWithZone:zone] initWithDictionary:self];
1606 - (BOOL)isEqual:(id)other {
1607 if (self == other) {
1610 if (![other isKindOfClass:[GPBUInt32Int32Dictionary class]]) {
1613 GPBUInt32Int32Dictionary *otherDictionary = other;
1614 return [_dictionary isEqual:otherDictionary->_dictionary];
1617 - (NSUInteger)hash {
1618 return _dictionary.count;
1621 - (NSString *)description {
1622 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
1625 - (NSUInteger)count {
1626 return _dictionary.count;
1629 - (void)enumerateKeysAndInt32sUsingBlock:
1630 (void (NS_NOESCAPE ^)(uint32_t key, int32_t value, BOOL *stop))block {
1632 NSDictionary *internal = _dictionary;
1633 NSEnumerator *keys = [internal keyEnumerator];
1635 while ((aKey = [keys nextObject])) {
1636 NSNumber *aValue = internal[aKey];
1637 block([aKey unsignedIntValue], [aValue intValue], &stop);
1644 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
1645 NSDictionary *internal = _dictionary;
1646 NSUInteger count = internal.count;
1651 GPBDataType valueDataType = GPBGetFieldDataType(field);
1652 GPBDataType keyDataType = field.mapKeyDataType;
1654 NSEnumerator *keys = [internal keyEnumerator];
1656 while ((aKey = [keys nextObject])) {
1657 NSNumber *aValue = internal[aKey];
1658 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
1659 msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
1660 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
1662 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
1663 result += tagSize * count;
1667 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
1668 asField:(GPBFieldDescriptor *)field {
1669 GPBDataType valueDataType = GPBGetFieldDataType(field);
1670 GPBDataType keyDataType = field.mapKeyDataType;
1671 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
1672 NSDictionary *internal = _dictionary;
1673 NSEnumerator *keys = [internal keyEnumerator];
1675 while ((aKey = [keys nextObject])) {
1676 NSNumber *aValue = internal[aKey];
1677 [outputStream writeInt32NoTag:tag];
1678 // Write the size of the message.
1679 uint32_t unwrappedKey = [aKey unsignedIntValue];
1680 int32_t unwrappedValue = [aValue intValue];
1681 size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
1682 msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
1683 [outputStream writeInt32NoTag:(int32_t)msgSize];
1684 // Write the fields.
1685 WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
1686 WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
1690 - (void)setGPBGenericValue:(GPBGenericValue *)value
1691 forGPBGenericValueKey:(GPBGenericValue *)key {
1692 [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueUInt32)];
1695 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
1696 [self enumerateKeysAndInt32sUsingBlock:^(uint32_t key, int32_t value, __unused BOOL *stop) {
1697 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%d", value]);
1701 - (BOOL)getInt32:(nullable int32_t *)value forKey:(uint32_t)key {
1702 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
1703 if (wrapped && value) {
1704 *value = [wrapped intValue];
1706 return (wrapped != NULL);
1709 - (void)addEntriesFromDictionary:(GPBUInt32Int32Dictionary *)otherDictionary {
1710 if (otherDictionary) {
1711 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
1713 GPBAutocreatedDictionaryModified(_autocreator, self);
1718 - (void)setInt32:(int32_t)value forKey:(uint32_t)key {
1719 [_dictionary setObject:@(value) forKey:@(key)];
1721 GPBAutocreatedDictionaryModified(_autocreator, self);
1725 - (void)removeInt32ForKey:(uint32_t)aKey {
1726 [_dictionary removeObjectForKey:@(aKey)];
1730 [_dictionary removeAllObjects];
1735 #pragma mark - UInt32 -> UInt64
1737 @implementation GPBUInt32UInt64Dictionary {
1739 NSMutableDictionary *_dictionary;
1742 - (instancetype)init {
1743 return [self initWithUInt64s:NULL forKeys:NULL count:0];
1746 - (instancetype)initWithUInt64s:(const uint64_t [])values
1747 forKeys:(const uint32_t [])keys
1748 count:(NSUInteger)count {
1749 self = [super init];
1751 _dictionary = [[NSMutableDictionary alloc] init];
1752 if (count && values && keys) {
1753 for (NSUInteger i = 0; i < count; ++i) {
1754 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
1761 - (instancetype)initWithDictionary:(GPBUInt32UInt64Dictionary *)dictionary {
1762 self = [self initWithUInt64s:NULL forKeys:NULL count:0];
1765 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
1771 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
1772 return [self initWithUInt64s:NULL forKeys:NULL count:0];
1776 NSAssert(!_autocreator,
1777 @"%@: Autocreator must be cleared before release, autocreator: %@",
1778 [self class], _autocreator);
1779 [_dictionary release];
1783 - (instancetype)copyWithZone:(NSZone *)zone {
1784 return [[GPBUInt32UInt64Dictionary allocWithZone:zone] initWithDictionary:self];
1787 - (BOOL)isEqual:(id)other {
1788 if (self == other) {
1791 if (![other isKindOfClass:[GPBUInt32UInt64Dictionary class]]) {
1794 GPBUInt32UInt64Dictionary *otherDictionary = other;
1795 return [_dictionary isEqual:otherDictionary->_dictionary];
1798 - (NSUInteger)hash {
1799 return _dictionary.count;
1802 - (NSString *)description {
1803 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
1806 - (NSUInteger)count {
1807 return _dictionary.count;
1810 - (void)enumerateKeysAndUInt64sUsingBlock:
1811 (void (NS_NOESCAPE ^)(uint32_t key, uint64_t value, BOOL *stop))block {
1813 NSDictionary *internal = _dictionary;
1814 NSEnumerator *keys = [internal keyEnumerator];
1816 while ((aKey = [keys nextObject])) {
1817 NSNumber *aValue = internal[aKey];
1818 block([aKey unsignedIntValue], [aValue unsignedLongLongValue], &stop);
1825 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
1826 NSDictionary *internal = _dictionary;
1827 NSUInteger count = internal.count;
1832 GPBDataType valueDataType = GPBGetFieldDataType(field);
1833 GPBDataType keyDataType = field.mapKeyDataType;
1835 NSEnumerator *keys = [internal keyEnumerator];
1837 while ((aKey = [keys nextObject])) {
1838 NSNumber *aValue = internal[aKey];
1839 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
1840 msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
1841 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
1843 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
1844 result += tagSize * count;
1848 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
1849 asField:(GPBFieldDescriptor *)field {
1850 GPBDataType valueDataType = GPBGetFieldDataType(field);
1851 GPBDataType keyDataType = field.mapKeyDataType;
1852 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
1853 NSDictionary *internal = _dictionary;
1854 NSEnumerator *keys = [internal keyEnumerator];
1856 while ((aKey = [keys nextObject])) {
1857 NSNumber *aValue = internal[aKey];
1858 [outputStream writeInt32NoTag:tag];
1859 // Write the size of the message.
1860 uint32_t unwrappedKey = [aKey unsignedIntValue];
1861 uint64_t unwrappedValue = [aValue unsignedLongLongValue];
1862 size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
1863 msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
1864 [outputStream writeInt32NoTag:(int32_t)msgSize];
1865 // Write the fields.
1866 WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
1867 WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
1871 - (void)setGPBGenericValue:(GPBGenericValue *)value
1872 forGPBGenericValueKey:(GPBGenericValue *)key {
1873 [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueUInt32)];
1876 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
1877 [self enumerateKeysAndUInt64sUsingBlock:^(uint32_t key, uint64_t value, __unused BOOL *stop) {
1878 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%llu", value]);
1882 - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(uint32_t)key {
1883 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
1884 if (wrapped && value) {
1885 *value = [wrapped unsignedLongLongValue];
1887 return (wrapped != NULL);
1890 - (void)addEntriesFromDictionary:(GPBUInt32UInt64Dictionary *)otherDictionary {
1891 if (otherDictionary) {
1892 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
1894 GPBAutocreatedDictionaryModified(_autocreator, self);
1899 - (void)setUInt64:(uint64_t)value forKey:(uint32_t)key {
1900 [_dictionary setObject:@(value) forKey:@(key)];
1902 GPBAutocreatedDictionaryModified(_autocreator, self);
1906 - (void)removeUInt64ForKey:(uint32_t)aKey {
1907 [_dictionary removeObjectForKey:@(aKey)];
1911 [_dictionary removeAllObjects];
1916 #pragma mark - UInt32 -> Int64
1918 @implementation GPBUInt32Int64Dictionary {
1920 NSMutableDictionary *_dictionary;
1923 - (instancetype)init {
1924 return [self initWithInt64s:NULL forKeys:NULL count:0];
1927 - (instancetype)initWithInt64s:(const int64_t [])values
1928 forKeys:(const uint32_t [])keys
1929 count:(NSUInteger)count {
1930 self = [super init];
1932 _dictionary = [[NSMutableDictionary alloc] init];
1933 if (count && values && keys) {
1934 for (NSUInteger i = 0; i < count; ++i) {
1935 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
1942 - (instancetype)initWithDictionary:(GPBUInt32Int64Dictionary *)dictionary {
1943 self = [self initWithInt64s:NULL forKeys:NULL count:0];
1946 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
1952 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
1953 return [self initWithInt64s:NULL forKeys:NULL count:0];
1957 NSAssert(!_autocreator,
1958 @"%@: Autocreator must be cleared before release, autocreator: %@",
1959 [self class], _autocreator);
1960 [_dictionary release];
1964 - (instancetype)copyWithZone:(NSZone *)zone {
1965 return [[GPBUInt32Int64Dictionary allocWithZone:zone] initWithDictionary:self];
1968 - (BOOL)isEqual:(id)other {
1969 if (self == other) {
1972 if (![other isKindOfClass:[GPBUInt32Int64Dictionary class]]) {
1975 GPBUInt32Int64Dictionary *otherDictionary = other;
1976 return [_dictionary isEqual:otherDictionary->_dictionary];
1979 - (NSUInteger)hash {
1980 return _dictionary.count;
1983 - (NSString *)description {
1984 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
1987 - (NSUInteger)count {
1988 return _dictionary.count;
1991 - (void)enumerateKeysAndInt64sUsingBlock:
1992 (void (NS_NOESCAPE ^)(uint32_t key, int64_t value, BOOL *stop))block {
1994 NSDictionary *internal = _dictionary;
1995 NSEnumerator *keys = [internal keyEnumerator];
1997 while ((aKey = [keys nextObject])) {
1998 NSNumber *aValue = internal[aKey];
1999 block([aKey unsignedIntValue], [aValue longLongValue], &stop);
2006 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
2007 NSDictionary *internal = _dictionary;
2008 NSUInteger count = internal.count;
2013 GPBDataType valueDataType = GPBGetFieldDataType(field);
2014 GPBDataType keyDataType = field.mapKeyDataType;
2016 NSEnumerator *keys = [internal keyEnumerator];
2018 while ((aKey = [keys nextObject])) {
2019 NSNumber *aValue = internal[aKey];
2020 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
2021 msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
2022 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
2024 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
2025 result += tagSize * count;
2029 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
2030 asField:(GPBFieldDescriptor *)field {
2031 GPBDataType valueDataType = GPBGetFieldDataType(field);
2032 GPBDataType keyDataType = field.mapKeyDataType;
2033 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
2034 NSDictionary *internal = _dictionary;
2035 NSEnumerator *keys = [internal keyEnumerator];
2037 while ((aKey = [keys nextObject])) {
2038 NSNumber *aValue = internal[aKey];
2039 [outputStream writeInt32NoTag:tag];
2040 // Write the size of the message.
2041 uint32_t unwrappedKey = [aKey unsignedIntValue];
2042 int64_t unwrappedValue = [aValue longLongValue];
2043 size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
2044 msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
2045 [outputStream writeInt32NoTag:(int32_t)msgSize];
2046 // Write the fields.
2047 WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
2048 WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
2052 - (void)setGPBGenericValue:(GPBGenericValue *)value
2053 forGPBGenericValueKey:(GPBGenericValue *)key {
2054 [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueUInt32)];
2057 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
2058 [self enumerateKeysAndInt64sUsingBlock:^(uint32_t key, int64_t value, __unused BOOL *stop) {
2059 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%lld", value]);
2063 - (BOOL)getInt64:(nullable int64_t *)value forKey:(uint32_t)key {
2064 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
2065 if (wrapped && value) {
2066 *value = [wrapped longLongValue];
2068 return (wrapped != NULL);
2071 - (void)addEntriesFromDictionary:(GPBUInt32Int64Dictionary *)otherDictionary {
2072 if (otherDictionary) {
2073 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
2075 GPBAutocreatedDictionaryModified(_autocreator, self);
2080 - (void)setInt64:(int64_t)value forKey:(uint32_t)key {
2081 [_dictionary setObject:@(value) forKey:@(key)];
2083 GPBAutocreatedDictionaryModified(_autocreator, self);
2087 - (void)removeInt64ForKey:(uint32_t)aKey {
2088 [_dictionary removeObjectForKey:@(aKey)];
2092 [_dictionary removeAllObjects];
2097 #pragma mark - UInt32 -> Bool
2099 @implementation GPBUInt32BoolDictionary {
2101 NSMutableDictionary *_dictionary;
2104 - (instancetype)init {
2105 return [self initWithBools:NULL forKeys:NULL count:0];
2108 - (instancetype)initWithBools:(const BOOL [])values
2109 forKeys:(const uint32_t [])keys
2110 count:(NSUInteger)count {
2111 self = [super init];
2113 _dictionary = [[NSMutableDictionary alloc] init];
2114 if (count && values && keys) {
2115 for (NSUInteger i = 0; i < count; ++i) {
2116 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
2123 - (instancetype)initWithDictionary:(GPBUInt32BoolDictionary *)dictionary {
2124 self = [self initWithBools:NULL forKeys:NULL count:0];
2127 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
2133 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
2134 return [self initWithBools:NULL forKeys:NULL count:0];
2138 NSAssert(!_autocreator,
2139 @"%@: Autocreator must be cleared before release, autocreator: %@",
2140 [self class], _autocreator);
2141 [_dictionary release];
2145 - (instancetype)copyWithZone:(NSZone *)zone {
2146 return [[GPBUInt32BoolDictionary allocWithZone:zone] initWithDictionary:self];
2149 - (BOOL)isEqual:(id)other {
2150 if (self == other) {
2153 if (![other isKindOfClass:[GPBUInt32BoolDictionary class]]) {
2156 GPBUInt32BoolDictionary *otherDictionary = other;
2157 return [_dictionary isEqual:otherDictionary->_dictionary];
2160 - (NSUInteger)hash {
2161 return _dictionary.count;
2164 - (NSString *)description {
2165 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
2168 - (NSUInteger)count {
2169 return _dictionary.count;
2172 - (void)enumerateKeysAndBoolsUsingBlock:
2173 (void (NS_NOESCAPE ^)(uint32_t key, BOOL value, BOOL *stop))block {
2175 NSDictionary *internal = _dictionary;
2176 NSEnumerator *keys = [internal keyEnumerator];
2178 while ((aKey = [keys nextObject])) {
2179 NSNumber *aValue = internal[aKey];
2180 block([aKey unsignedIntValue], [aValue boolValue], &stop);
2187 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
2188 NSDictionary *internal = _dictionary;
2189 NSUInteger count = internal.count;
2194 GPBDataType valueDataType = GPBGetFieldDataType(field);
2195 GPBDataType keyDataType = field.mapKeyDataType;
2197 NSEnumerator *keys = [internal keyEnumerator];
2199 while ((aKey = [keys nextObject])) {
2200 NSNumber *aValue = internal[aKey];
2201 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
2202 msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
2203 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
2205 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
2206 result += tagSize * count;
2210 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
2211 asField:(GPBFieldDescriptor *)field {
2212 GPBDataType valueDataType = GPBGetFieldDataType(field);
2213 GPBDataType keyDataType = field.mapKeyDataType;
2214 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
2215 NSDictionary *internal = _dictionary;
2216 NSEnumerator *keys = [internal keyEnumerator];
2218 while ((aKey = [keys nextObject])) {
2219 NSNumber *aValue = internal[aKey];
2220 [outputStream writeInt32NoTag:tag];
2221 // Write the size of the message.
2222 uint32_t unwrappedKey = [aKey unsignedIntValue];
2223 BOOL unwrappedValue = [aValue boolValue];
2224 size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
2225 msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
2226 [outputStream writeInt32NoTag:(int32_t)msgSize];
2227 // Write the fields.
2228 WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
2229 WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
2233 - (void)setGPBGenericValue:(GPBGenericValue *)value
2234 forGPBGenericValueKey:(GPBGenericValue *)key {
2235 [_dictionary setObject:@(value->valueBool) forKey:@(key->valueUInt32)];
2238 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
2239 [self enumerateKeysAndBoolsUsingBlock:^(uint32_t key, BOOL value, __unused BOOL *stop) {
2240 block([NSString stringWithFormat:@"%u", key], (value ? @"true" : @"false"));
2244 - (BOOL)getBool:(nullable BOOL *)value forKey:(uint32_t)key {
2245 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
2246 if (wrapped && value) {
2247 *value = [wrapped boolValue];
2249 return (wrapped != NULL);
2252 - (void)addEntriesFromDictionary:(GPBUInt32BoolDictionary *)otherDictionary {
2253 if (otherDictionary) {
2254 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
2256 GPBAutocreatedDictionaryModified(_autocreator, self);
2261 - (void)setBool:(BOOL)value forKey:(uint32_t)key {
2262 [_dictionary setObject:@(value) forKey:@(key)];
2264 GPBAutocreatedDictionaryModified(_autocreator, self);
2268 - (void)removeBoolForKey:(uint32_t)aKey {
2269 [_dictionary removeObjectForKey:@(aKey)];
2273 [_dictionary removeAllObjects];
2278 #pragma mark - UInt32 -> Float
2280 @implementation GPBUInt32FloatDictionary {
2282 NSMutableDictionary *_dictionary;
2285 - (instancetype)init {
2286 return [self initWithFloats:NULL forKeys:NULL count:0];
2289 - (instancetype)initWithFloats:(const float [])values
2290 forKeys:(const uint32_t [])keys
2291 count:(NSUInteger)count {
2292 self = [super init];
2294 _dictionary = [[NSMutableDictionary alloc] init];
2295 if (count && values && keys) {
2296 for (NSUInteger i = 0; i < count; ++i) {
2297 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
2304 - (instancetype)initWithDictionary:(GPBUInt32FloatDictionary *)dictionary {
2305 self = [self initWithFloats:NULL forKeys:NULL count:0];
2308 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
2314 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
2315 return [self initWithFloats:NULL forKeys:NULL count:0];
2319 NSAssert(!_autocreator,
2320 @"%@: Autocreator must be cleared before release, autocreator: %@",
2321 [self class], _autocreator);
2322 [_dictionary release];
2326 - (instancetype)copyWithZone:(NSZone *)zone {
2327 return [[GPBUInt32FloatDictionary allocWithZone:zone] initWithDictionary:self];
2330 - (BOOL)isEqual:(id)other {
2331 if (self == other) {
2334 if (![other isKindOfClass:[GPBUInt32FloatDictionary class]]) {
2337 GPBUInt32FloatDictionary *otherDictionary = other;
2338 return [_dictionary isEqual:otherDictionary->_dictionary];
2341 - (NSUInteger)hash {
2342 return _dictionary.count;
2345 - (NSString *)description {
2346 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
2349 - (NSUInteger)count {
2350 return _dictionary.count;
2353 - (void)enumerateKeysAndFloatsUsingBlock:
2354 (void (NS_NOESCAPE ^)(uint32_t key, float value, BOOL *stop))block {
2356 NSDictionary *internal = _dictionary;
2357 NSEnumerator *keys = [internal keyEnumerator];
2359 while ((aKey = [keys nextObject])) {
2360 NSNumber *aValue = internal[aKey];
2361 block([aKey unsignedIntValue], [aValue floatValue], &stop);
2368 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
2369 NSDictionary *internal = _dictionary;
2370 NSUInteger count = internal.count;
2375 GPBDataType valueDataType = GPBGetFieldDataType(field);
2376 GPBDataType keyDataType = field.mapKeyDataType;
2378 NSEnumerator *keys = [internal keyEnumerator];
2380 while ((aKey = [keys nextObject])) {
2381 NSNumber *aValue = internal[aKey];
2382 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
2383 msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
2384 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
2386 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
2387 result += tagSize * count;
2391 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
2392 asField:(GPBFieldDescriptor *)field {
2393 GPBDataType valueDataType = GPBGetFieldDataType(field);
2394 GPBDataType keyDataType = field.mapKeyDataType;
2395 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
2396 NSDictionary *internal = _dictionary;
2397 NSEnumerator *keys = [internal keyEnumerator];
2399 while ((aKey = [keys nextObject])) {
2400 NSNumber *aValue = internal[aKey];
2401 [outputStream writeInt32NoTag:tag];
2402 // Write the size of the message.
2403 uint32_t unwrappedKey = [aKey unsignedIntValue];
2404 float unwrappedValue = [aValue floatValue];
2405 size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
2406 msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
2407 [outputStream writeInt32NoTag:(int32_t)msgSize];
2408 // Write the fields.
2409 WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
2410 WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
2414 - (void)setGPBGenericValue:(GPBGenericValue *)value
2415 forGPBGenericValueKey:(GPBGenericValue *)key {
2416 [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueUInt32)];
2419 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
2420 [self enumerateKeysAndFloatsUsingBlock:^(uint32_t key, float value, __unused BOOL *stop) {
2421 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
2425 - (BOOL)getFloat:(nullable float *)value forKey:(uint32_t)key {
2426 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
2427 if (wrapped && value) {
2428 *value = [wrapped floatValue];
2430 return (wrapped != NULL);
2433 - (void)addEntriesFromDictionary:(GPBUInt32FloatDictionary *)otherDictionary {
2434 if (otherDictionary) {
2435 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
2437 GPBAutocreatedDictionaryModified(_autocreator, self);
2442 - (void)setFloat:(float)value forKey:(uint32_t)key {
2443 [_dictionary setObject:@(value) forKey:@(key)];
2445 GPBAutocreatedDictionaryModified(_autocreator, self);
2449 - (void)removeFloatForKey:(uint32_t)aKey {
2450 [_dictionary removeObjectForKey:@(aKey)];
2454 [_dictionary removeAllObjects];
2459 #pragma mark - UInt32 -> Double
2461 @implementation GPBUInt32DoubleDictionary {
2463 NSMutableDictionary *_dictionary;
2466 - (instancetype)init {
2467 return [self initWithDoubles:NULL forKeys:NULL count:0];
2470 - (instancetype)initWithDoubles:(const double [])values
2471 forKeys:(const uint32_t [])keys
2472 count:(NSUInteger)count {
2473 self = [super init];
2475 _dictionary = [[NSMutableDictionary alloc] init];
2476 if (count && values && keys) {
2477 for (NSUInteger i = 0; i < count; ++i) {
2478 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
2485 - (instancetype)initWithDictionary:(GPBUInt32DoubleDictionary *)dictionary {
2486 self = [self initWithDoubles:NULL forKeys:NULL count:0];
2489 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
2495 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
2496 return [self initWithDoubles:NULL forKeys:NULL count:0];
2500 NSAssert(!_autocreator,
2501 @"%@: Autocreator must be cleared before release, autocreator: %@",
2502 [self class], _autocreator);
2503 [_dictionary release];
2507 - (instancetype)copyWithZone:(NSZone *)zone {
2508 return [[GPBUInt32DoubleDictionary allocWithZone:zone] initWithDictionary:self];
2511 - (BOOL)isEqual:(id)other {
2512 if (self == other) {
2515 if (![other isKindOfClass:[GPBUInt32DoubleDictionary class]]) {
2518 GPBUInt32DoubleDictionary *otherDictionary = other;
2519 return [_dictionary isEqual:otherDictionary->_dictionary];
2522 - (NSUInteger)hash {
2523 return _dictionary.count;
2526 - (NSString *)description {
2527 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
2530 - (NSUInteger)count {
2531 return _dictionary.count;
2534 - (void)enumerateKeysAndDoublesUsingBlock:
2535 (void (NS_NOESCAPE ^)(uint32_t key, double value, BOOL *stop))block {
2537 NSDictionary *internal = _dictionary;
2538 NSEnumerator *keys = [internal keyEnumerator];
2540 while ((aKey = [keys nextObject])) {
2541 NSNumber *aValue = internal[aKey];
2542 block([aKey unsignedIntValue], [aValue doubleValue], &stop);
2549 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
2550 NSDictionary *internal = _dictionary;
2551 NSUInteger count = internal.count;
2556 GPBDataType valueDataType = GPBGetFieldDataType(field);
2557 GPBDataType keyDataType = field.mapKeyDataType;
2559 NSEnumerator *keys = [internal keyEnumerator];
2561 while ((aKey = [keys nextObject])) {
2562 NSNumber *aValue = internal[aKey];
2563 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
2564 msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
2565 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
2567 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
2568 result += tagSize * count;
2572 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
2573 asField:(GPBFieldDescriptor *)field {
2574 GPBDataType valueDataType = GPBGetFieldDataType(field);
2575 GPBDataType keyDataType = field.mapKeyDataType;
2576 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
2577 NSDictionary *internal = _dictionary;
2578 NSEnumerator *keys = [internal keyEnumerator];
2580 while ((aKey = [keys nextObject])) {
2581 NSNumber *aValue = internal[aKey];
2582 [outputStream writeInt32NoTag:tag];
2583 // Write the size of the message.
2584 uint32_t unwrappedKey = [aKey unsignedIntValue];
2585 double unwrappedValue = [aValue doubleValue];
2586 size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
2587 msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
2588 [outputStream writeInt32NoTag:(int32_t)msgSize];
2589 // Write the fields.
2590 WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
2591 WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
2595 - (void)setGPBGenericValue:(GPBGenericValue *)value
2596 forGPBGenericValueKey:(GPBGenericValue *)key {
2597 [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueUInt32)];
2600 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
2601 [self enumerateKeysAndDoublesUsingBlock:^(uint32_t key, double value, __unused BOOL *stop) {
2602 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
2606 - (BOOL)getDouble:(nullable double *)value forKey:(uint32_t)key {
2607 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
2608 if (wrapped && value) {
2609 *value = [wrapped doubleValue];
2611 return (wrapped != NULL);
2614 - (void)addEntriesFromDictionary:(GPBUInt32DoubleDictionary *)otherDictionary {
2615 if (otherDictionary) {
2616 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
2618 GPBAutocreatedDictionaryModified(_autocreator, self);
2623 - (void)setDouble:(double)value forKey:(uint32_t)key {
2624 [_dictionary setObject:@(value) forKey:@(key)];
2626 GPBAutocreatedDictionaryModified(_autocreator, self);
2630 - (void)removeDoubleForKey:(uint32_t)aKey {
2631 [_dictionary removeObjectForKey:@(aKey)];
2635 [_dictionary removeAllObjects];
2640 #pragma mark - UInt32 -> Enum
2642 @implementation GPBUInt32EnumDictionary {
2644 NSMutableDictionary *_dictionary;
2645 GPBEnumValidationFunc _validationFunc;
2648 @synthesize validationFunc = _validationFunc;
2650 - (instancetype)init {
2651 return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
2654 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
2655 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
2658 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
2659 rawValues:(const int32_t [])rawValues
2660 forKeys:(const uint32_t [])keys
2661 count:(NSUInteger)count {
2662 self = [super init];
2664 _dictionary = [[NSMutableDictionary alloc] init];
2665 _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
2666 if (count && rawValues && keys) {
2667 for (NSUInteger i = 0; i < count; ++i) {
2668 [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])];
2675 - (instancetype)initWithDictionary:(GPBUInt32EnumDictionary *)dictionary {
2676 self = [self initWithValidationFunction:dictionary.validationFunc
2682 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
2688 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
2689 capacity:(__unused NSUInteger)numItems {
2690 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
2694 NSAssert(!_autocreator,
2695 @"%@: Autocreator must be cleared before release, autocreator: %@",
2696 [self class], _autocreator);
2697 [_dictionary release];
2701 - (instancetype)copyWithZone:(NSZone *)zone {
2702 return [[GPBUInt32EnumDictionary allocWithZone:zone] initWithDictionary:self];
2705 - (BOOL)isEqual:(id)other {
2706 if (self == other) {
2709 if (![other isKindOfClass:[GPBUInt32EnumDictionary class]]) {
2712 GPBUInt32EnumDictionary *otherDictionary = other;
2713 return [_dictionary isEqual:otherDictionary->_dictionary];
2716 - (NSUInteger)hash {
2717 return _dictionary.count;
2720 - (NSString *)description {
2721 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
2724 - (NSUInteger)count {
2725 return _dictionary.count;
2728 - (void)enumerateKeysAndRawValuesUsingBlock:
2729 (void (NS_NOESCAPE ^)(uint32_t key, int32_t value, BOOL *stop))block {
2731 NSDictionary *internal = _dictionary;
2732 NSEnumerator *keys = [internal keyEnumerator];
2734 while ((aKey = [keys nextObject])) {
2735 NSNumber *aValue = internal[aKey];
2736 block([aKey unsignedIntValue], [aValue intValue], &stop);
2743 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
2744 NSDictionary *internal = _dictionary;
2745 NSUInteger count = internal.count;
2750 GPBDataType valueDataType = GPBGetFieldDataType(field);
2751 GPBDataType keyDataType = field.mapKeyDataType;
2753 NSEnumerator *keys = [internal keyEnumerator];
2755 while ((aKey = [keys nextObject])) {
2756 NSNumber *aValue = internal[aKey];
2757 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
2758 msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
2759 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
2761 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
2762 result += tagSize * count;
2766 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
2767 asField:(GPBFieldDescriptor *)field {
2768 GPBDataType valueDataType = GPBGetFieldDataType(field);
2769 GPBDataType keyDataType = field.mapKeyDataType;
2770 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
2771 NSDictionary *internal = _dictionary;
2772 NSEnumerator *keys = [internal keyEnumerator];
2774 while ((aKey = [keys nextObject])) {
2775 NSNumber *aValue = internal[aKey];
2776 [outputStream writeInt32NoTag:tag];
2777 // Write the size of the message.
2778 uint32_t unwrappedKey = [aKey unsignedIntValue];
2779 int32_t unwrappedValue = [aValue intValue];
2780 size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
2781 msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
2782 [outputStream writeInt32NoTag:(int32_t)msgSize];
2783 // Write the fields.
2784 WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
2785 WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
2789 - (NSData *)serializedDataForUnknownValue:(int32_t)value
2790 forKey:(GPBGenericValue *)key
2791 keyDataType:(GPBDataType)keyDataType {
2792 size_t msgSize = ComputeDictUInt32FieldSize(key->valueUInt32, kMapKeyFieldNumber, keyDataType);
2793 msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
2794 NSMutableData *data = [NSMutableData dataWithLength:msgSize];
2795 GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
2796 WriteDictUInt32Field(outputStream, key->valueUInt32, kMapKeyFieldNumber, keyDataType);
2797 WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
2798 [outputStream flush];
2799 [outputStream release];
2802 - (void)setGPBGenericValue:(GPBGenericValue *)value
2803 forGPBGenericValueKey:(GPBGenericValue *)key {
2804 [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueUInt32)];
2807 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
2808 [self enumerateKeysAndRawValuesUsingBlock:^(uint32_t key, int32_t value, __unused BOOL *stop) {
2809 block([NSString stringWithFormat:@"%u", key], @(value));
2813 - (BOOL)getEnum:(int32_t *)value forKey:(uint32_t)key {
2814 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
2815 if (wrapped && value) {
2816 int32_t result = [wrapped intValue];
2817 if (!_validationFunc(result)) {
2818 result = kGPBUnrecognizedEnumeratorValue;
2822 return (wrapped != NULL);
2825 - (BOOL)getRawValue:(int32_t *)rawValue forKey:(uint32_t)key {
2826 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
2827 if (wrapped && rawValue) {
2828 *rawValue = [wrapped intValue];
2830 return (wrapped != NULL);
2833 - (void)enumerateKeysAndEnumsUsingBlock:
2834 (void (NS_NOESCAPE ^)(uint32_t key, int32_t value, BOOL *stop))block {
2835 GPBEnumValidationFunc func = _validationFunc;
2837 NSEnumerator *keys = [_dictionary keyEnumerator];
2839 while ((aKey = [keys nextObject])) {
2840 NSNumber *aValue = _dictionary[aKey];
2841 int32_t unwrapped = [aValue intValue];
2842 if (!func(unwrapped)) {
2843 unwrapped = kGPBUnrecognizedEnumeratorValue;
2845 block([aKey unsignedIntValue], unwrapped, &stop);
2852 - (void)addRawEntriesFromDictionary:(GPBUInt32EnumDictionary *)otherDictionary {
2853 if (otherDictionary) {
2854 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
2856 GPBAutocreatedDictionaryModified(_autocreator, self);
2861 - (void)setRawValue:(int32_t)value forKey:(uint32_t)key {
2862 [_dictionary setObject:@(value) forKey:@(key)];
2864 GPBAutocreatedDictionaryModified(_autocreator, self);
2868 - (void)removeEnumForKey:(uint32_t)aKey {
2869 [_dictionary removeObjectForKey:@(aKey)];
2873 [_dictionary removeAllObjects];
2876 - (void)setEnum:(int32_t)value forKey:(uint32_t)key {
2877 if (!_validationFunc(value)) {
2878 [NSException raise:NSInvalidArgumentException
2879 format:@"GPBUInt32EnumDictionary: Attempt to set an unknown enum value (%d)",
2883 [_dictionary setObject:@(value) forKey:@(key)];
2885 GPBAutocreatedDictionaryModified(_autocreator, self);
2891 #pragma mark - UInt32 -> Object
2893 @implementation GPBUInt32ObjectDictionary {
2895 NSMutableDictionary *_dictionary;
2898 - (instancetype)init {
2899 return [self initWithObjects:NULL forKeys:NULL count:0];
2902 - (instancetype)initWithObjects:(const id [])objects
2903 forKeys:(const uint32_t [])keys
2904 count:(NSUInteger)count {
2905 self = [super init];
2907 _dictionary = [[NSMutableDictionary alloc] init];
2908 if (count && objects && keys) {
2909 for (NSUInteger i = 0; i < count; ++i) {
2911 [NSException raise:NSInvalidArgumentException
2912 format:@"Attempting to add nil object to a Dictionary"];
2914 [_dictionary setObject:objects[i] forKey:@(keys[i])];
2921 - (instancetype)initWithDictionary:(GPBUInt32ObjectDictionary *)dictionary {
2922 self = [self initWithObjects:NULL forKeys:NULL count:0];
2925 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
2931 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
2932 return [self initWithObjects:NULL forKeys:NULL count:0];
2936 NSAssert(!_autocreator,
2937 @"%@: Autocreator must be cleared before release, autocreator: %@",
2938 [self class], _autocreator);
2939 [_dictionary release];
2943 - (instancetype)copyWithZone:(NSZone *)zone {
2944 return [[GPBUInt32ObjectDictionary allocWithZone:zone] initWithDictionary:self];
2947 - (BOOL)isEqual:(id)other {
2948 if (self == other) {
2951 if (![other isKindOfClass:[GPBUInt32ObjectDictionary class]]) {
2954 GPBUInt32ObjectDictionary *otherDictionary = other;
2955 return [_dictionary isEqual:otherDictionary->_dictionary];
2958 - (NSUInteger)hash {
2959 return _dictionary.count;
2962 - (NSString *)description {
2963 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
2966 - (NSUInteger)count {
2967 return _dictionary.count;
2970 - (void)enumerateKeysAndObjectsUsingBlock:
2971 (void (NS_NOESCAPE ^)(uint32_t key, id object, BOOL *stop))block {
2973 NSDictionary *internal = _dictionary;
2974 NSEnumerator *keys = [internal keyEnumerator];
2976 while ((aKey = [keys nextObject])) {
2977 id aObject = internal[aKey];
2978 block([aKey unsignedIntValue], aObject, &stop);
2985 - (BOOL)isInitialized {
2986 for (GPBMessage *msg in [_dictionary objectEnumerator]) {
2987 if (!msg.initialized) {
2994 - (instancetype)deepCopyWithZone:(NSZone *)zone {
2995 GPBUInt32ObjectDictionary *newDict =
2996 [[GPBUInt32ObjectDictionary alloc] init];
2997 NSEnumerator *keys = [_dictionary keyEnumerator];
2999 NSMutableDictionary *internalDict = newDict->_dictionary;
3000 while ((aKey = [keys nextObject])) {
3001 GPBMessage *msg = _dictionary[aKey];
3002 GPBMessage *copiedMsg = [msg copyWithZone:zone];
3003 [internalDict setObject:copiedMsg forKey:aKey];
3004 [copiedMsg release];
3009 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
3010 NSDictionary *internal = _dictionary;
3011 NSUInteger count = internal.count;
3016 GPBDataType valueDataType = GPBGetFieldDataType(field);
3017 GPBDataType keyDataType = field.mapKeyDataType;
3019 NSEnumerator *keys = [internal keyEnumerator];
3021 while ((aKey = [keys nextObject])) {
3022 id aObject = internal[aKey];
3023 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
3024 msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
3025 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
3027 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
3028 result += tagSize * count;
3032 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
3033 asField:(GPBFieldDescriptor *)field {
3034 GPBDataType valueDataType = GPBGetFieldDataType(field);
3035 GPBDataType keyDataType = field.mapKeyDataType;
3036 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
3037 NSDictionary *internal = _dictionary;
3038 NSEnumerator *keys = [internal keyEnumerator];
3040 while ((aKey = [keys nextObject])) {
3041 id aObject = internal[aKey];
3042 [outputStream writeInt32NoTag:tag];
3043 // Write the size of the message.
3044 uint32_t unwrappedKey = [aKey unsignedIntValue];
3045 id unwrappedValue = aObject;
3046 size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
3047 msgSize += ComputeDictObjectFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
3048 [outputStream writeInt32NoTag:(int32_t)msgSize];
3049 // Write the fields.
3050 WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
3051 WriteDictObjectField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
3055 - (void)setGPBGenericValue:(GPBGenericValue *)value
3056 forGPBGenericValueKey:(GPBGenericValue *)key {
3057 [_dictionary setObject:value->valueString forKey:@(key->valueUInt32)];
3060 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
3061 [self enumerateKeysAndObjectsUsingBlock:^(uint32_t key, id object, __unused BOOL *stop) {
3062 block([NSString stringWithFormat:@"%u", key], object);
3066 - (id)objectForKey:(uint32_t)key {
3067 id result = [_dictionary objectForKey:@(key)];
3071 - (void)addEntriesFromDictionary:(GPBUInt32ObjectDictionary *)otherDictionary {
3072 if (otherDictionary) {
3073 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
3075 GPBAutocreatedDictionaryModified(_autocreator, self);
3080 - (void)setObject:(id)object forKey:(uint32_t)key {
3082 [NSException raise:NSInvalidArgumentException
3083 format:@"Attempting to add nil object to a Dictionary"];
3085 [_dictionary setObject:object forKey:@(key)];
3087 GPBAutocreatedDictionaryModified(_autocreator, self);
3091 - (void)removeObjectForKey:(uint32_t)aKey {
3092 [_dictionary removeObjectForKey:@(aKey)];
3096 [_dictionary removeAllObjects];
3101 //%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(Int32, int32_t)
3102 // This block of code is generated, do not edit it directly.
3104 #pragma mark - Int32 -> UInt32
3106 @implementation GPBInt32UInt32Dictionary {
3108 NSMutableDictionary *_dictionary;
3111 - (instancetype)init {
3112 return [self initWithUInt32s:NULL forKeys:NULL count:0];
3115 - (instancetype)initWithUInt32s:(const uint32_t [])values
3116 forKeys:(const int32_t [])keys
3117 count:(NSUInteger)count {
3118 self = [super init];
3120 _dictionary = [[NSMutableDictionary alloc] init];
3121 if (count && values && keys) {
3122 for (NSUInteger i = 0; i < count; ++i) {
3123 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
3130 - (instancetype)initWithDictionary:(GPBInt32UInt32Dictionary *)dictionary {
3131 self = [self initWithUInt32s:NULL forKeys:NULL count:0];
3134 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
3140 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
3141 return [self initWithUInt32s:NULL forKeys:NULL count:0];
3145 NSAssert(!_autocreator,
3146 @"%@: Autocreator must be cleared before release, autocreator: %@",
3147 [self class], _autocreator);
3148 [_dictionary release];
3152 - (instancetype)copyWithZone:(NSZone *)zone {
3153 return [[GPBInt32UInt32Dictionary allocWithZone:zone] initWithDictionary:self];
3156 - (BOOL)isEqual:(id)other {
3157 if (self == other) {
3160 if (![other isKindOfClass:[GPBInt32UInt32Dictionary class]]) {
3163 GPBInt32UInt32Dictionary *otherDictionary = other;
3164 return [_dictionary isEqual:otherDictionary->_dictionary];
3167 - (NSUInteger)hash {
3168 return _dictionary.count;
3171 - (NSString *)description {
3172 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
3175 - (NSUInteger)count {
3176 return _dictionary.count;
3179 - (void)enumerateKeysAndUInt32sUsingBlock:
3180 (void (NS_NOESCAPE ^)(int32_t key, uint32_t value, BOOL *stop))block {
3182 NSDictionary *internal = _dictionary;
3183 NSEnumerator *keys = [internal keyEnumerator];
3185 while ((aKey = [keys nextObject])) {
3186 NSNumber *aValue = internal[aKey];
3187 block([aKey intValue], [aValue unsignedIntValue], &stop);
3194 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
3195 NSDictionary *internal = _dictionary;
3196 NSUInteger count = internal.count;
3201 GPBDataType valueDataType = GPBGetFieldDataType(field);
3202 GPBDataType keyDataType = field.mapKeyDataType;
3204 NSEnumerator *keys = [internal keyEnumerator];
3206 while ((aKey = [keys nextObject])) {
3207 NSNumber *aValue = internal[aKey];
3208 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
3209 msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
3210 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
3212 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
3213 result += tagSize * count;
3217 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
3218 asField:(GPBFieldDescriptor *)field {
3219 GPBDataType valueDataType = GPBGetFieldDataType(field);
3220 GPBDataType keyDataType = field.mapKeyDataType;
3221 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
3222 NSDictionary *internal = _dictionary;
3223 NSEnumerator *keys = [internal keyEnumerator];
3225 while ((aKey = [keys nextObject])) {
3226 NSNumber *aValue = internal[aKey];
3227 [outputStream writeInt32NoTag:tag];
3228 // Write the size of the message.
3229 int32_t unwrappedKey = [aKey intValue];
3230 uint32_t unwrappedValue = [aValue unsignedIntValue];
3231 size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
3232 msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
3233 [outputStream writeInt32NoTag:(int32_t)msgSize];
3234 // Write the fields.
3235 WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
3236 WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
3240 - (void)setGPBGenericValue:(GPBGenericValue *)value
3241 forGPBGenericValueKey:(GPBGenericValue *)key {
3242 [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueInt32)];
3245 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
3246 [self enumerateKeysAndUInt32sUsingBlock:^(int32_t key, uint32_t value, __unused BOOL *stop) {
3247 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%u", value]);
3251 - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(int32_t)key {
3252 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
3253 if (wrapped && value) {
3254 *value = [wrapped unsignedIntValue];
3256 return (wrapped != NULL);
3259 - (void)addEntriesFromDictionary:(GPBInt32UInt32Dictionary *)otherDictionary {
3260 if (otherDictionary) {
3261 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
3263 GPBAutocreatedDictionaryModified(_autocreator, self);
3268 - (void)setUInt32:(uint32_t)value forKey:(int32_t)key {
3269 [_dictionary setObject:@(value) forKey:@(key)];
3271 GPBAutocreatedDictionaryModified(_autocreator, self);
3275 - (void)removeUInt32ForKey:(int32_t)aKey {
3276 [_dictionary removeObjectForKey:@(aKey)];
3280 [_dictionary removeAllObjects];
3285 #pragma mark - Int32 -> Int32
3287 @implementation GPBInt32Int32Dictionary {
3289 NSMutableDictionary *_dictionary;
3292 - (instancetype)init {
3293 return [self initWithInt32s:NULL forKeys:NULL count:0];
3296 - (instancetype)initWithInt32s:(const int32_t [])values
3297 forKeys:(const int32_t [])keys
3298 count:(NSUInteger)count {
3299 self = [super init];
3301 _dictionary = [[NSMutableDictionary alloc] init];
3302 if (count && values && keys) {
3303 for (NSUInteger i = 0; i < count; ++i) {
3304 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
3311 - (instancetype)initWithDictionary:(GPBInt32Int32Dictionary *)dictionary {
3312 self = [self initWithInt32s:NULL forKeys:NULL count:0];
3315 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
3321 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
3322 return [self initWithInt32s:NULL forKeys:NULL count:0];
3326 NSAssert(!_autocreator,
3327 @"%@: Autocreator must be cleared before release, autocreator: %@",
3328 [self class], _autocreator);
3329 [_dictionary release];
3333 - (instancetype)copyWithZone:(NSZone *)zone {
3334 return [[GPBInt32Int32Dictionary allocWithZone:zone] initWithDictionary:self];
3337 - (BOOL)isEqual:(id)other {
3338 if (self == other) {
3341 if (![other isKindOfClass:[GPBInt32Int32Dictionary class]]) {
3344 GPBInt32Int32Dictionary *otherDictionary = other;
3345 return [_dictionary isEqual:otherDictionary->_dictionary];
3348 - (NSUInteger)hash {
3349 return _dictionary.count;
3352 - (NSString *)description {
3353 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
3356 - (NSUInteger)count {
3357 return _dictionary.count;
3360 - (void)enumerateKeysAndInt32sUsingBlock:
3361 (void (NS_NOESCAPE ^)(int32_t key, int32_t value, BOOL *stop))block {
3363 NSDictionary *internal = _dictionary;
3364 NSEnumerator *keys = [internal keyEnumerator];
3366 while ((aKey = [keys nextObject])) {
3367 NSNumber *aValue = internal[aKey];
3368 block([aKey intValue], [aValue intValue], &stop);
3375 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
3376 NSDictionary *internal = _dictionary;
3377 NSUInteger count = internal.count;
3382 GPBDataType valueDataType = GPBGetFieldDataType(field);
3383 GPBDataType keyDataType = field.mapKeyDataType;
3385 NSEnumerator *keys = [internal keyEnumerator];
3387 while ((aKey = [keys nextObject])) {
3388 NSNumber *aValue = internal[aKey];
3389 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
3390 msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
3391 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
3393 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
3394 result += tagSize * count;
3398 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
3399 asField:(GPBFieldDescriptor *)field {
3400 GPBDataType valueDataType = GPBGetFieldDataType(field);
3401 GPBDataType keyDataType = field.mapKeyDataType;
3402 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
3403 NSDictionary *internal = _dictionary;
3404 NSEnumerator *keys = [internal keyEnumerator];
3406 while ((aKey = [keys nextObject])) {
3407 NSNumber *aValue = internal[aKey];
3408 [outputStream writeInt32NoTag:tag];
3409 // Write the size of the message.
3410 int32_t unwrappedKey = [aKey intValue];
3411 int32_t unwrappedValue = [aValue intValue];
3412 size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
3413 msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
3414 [outputStream writeInt32NoTag:(int32_t)msgSize];
3415 // Write the fields.
3416 WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
3417 WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
3421 - (void)setGPBGenericValue:(GPBGenericValue *)value
3422 forGPBGenericValueKey:(GPBGenericValue *)key {
3423 [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueInt32)];
3426 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
3427 [self enumerateKeysAndInt32sUsingBlock:^(int32_t key, int32_t value, __unused BOOL *stop) {
3428 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%d", value]);
3432 - (BOOL)getInt32:(nullable int32_t *)value forKey:(int32_t)key {
3433 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
3434 if (wrapped && value) {
3435 *value = [wrapped intValue];
3437 return (wrapped != NULL);
3440 - (void)addEntriesFromDictionary:(GPBInt32Int32Dictionary *)otherDictionary {
3441 if (otherDictionary) {
3442 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
3444 GPBAutocreatedDictionaryModified(_autocreator, self);
3449 - (void)setInt32:(int32_t)value forKey:(int32_t)key {
3450 [_dictionary setObject:@(value) forKey:@(key)];
3452 GPBAutocreatedDictionaryModified(_autocreator, self);
3456 - (void)removeInt32ForKey:(int32_t)aKey {
3457 [_dictionary removeObjectForKey:@(aKey)];
3461 [_dictionary removeAllObjects];
3466 #pragma mark - Int32 -> UInt64
3468 @implementation GPBInt32UInt64Dictionary {
3470 NSMutableDictionary *_dictionary;
3473 - (instancetype)init {
3474 return [self initWithUInt64s:NULL forKeys:NULL count:0];
3477 - (instancetype)initWithUInt64s:(const uint64_t [])values
3478 forKeys:(const int32_t [])keys
3479 count:(NSUInteger)count {
3480 self = [super init];
3482 _dictionary = [[NSMutableDictionary alloc] init];
3483 if (count && values && keys) {
3484 for (NSUInteger i = 0; i < count; ++i) {
3485 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
3492 - (instancetype)initWithDictionary:(GPBInt32UInt64Dictionary *)dictionary {
3493 self = [self initWithUInt64s:NULL forKeys:NULL count:0];
3496 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
3502 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
3503 return [self initWithUInt64s:NULL forKeys:NULL count:0];
3507 NSAssert(!_autocreator,
3508 @"%@: Autocreator must be cleared before release, autocreator: %@",
3509 [self class], _autocreator);
3510 [_dictionary release];
3514 - (instancetype)copyWithZone:(NSZone *)zone {
3515 return [[GPBInt32UInt64Dictionary allocWithZone:zone] initWithDictionary:self];
3518 - (BOOL)isEqual:(id)other {
3519 if (self == other) {
3522 if (![other isKindOfClass:[GPBInt32UInt64Dictionary class]]) {
3525 GPBInt32UInt64Dictionary *otherDictionary = other;
3526 return [_dictionary isEqual:otherDictionary->_dictionary];
3529 - (NSUInteger)hash {
3530 return _dictionary.count;
3533 - (NSString *)description {
3534 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
3537 - (NSUInteger)count {
3538 return _dictionary.count;
3541 - (void)enumerateKeysAndUInt64sUsingBlock:
3542 (void (NS_NOESCAPE ^)(int32_t key, uint64_t value, BOOL *stop))block {
3544 NSDictionary *internal = _dictionary;
3545 NSEnumerator *keys = [internal keyEnumerator];
3547 while ((aKey = [keys nextObject])) {
3548 NSNumber *aValue = internal[aKey];
3549 block([aKey intValue], [aValue unsignedLongLongValue], &stop);
3556 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
3557 NSDictionary *internal = _dictionary;
3558 NSUInteger count = internal.count;
3563 GPBDataType valueDataType = GPBGetFieldDataType(field);
3564 GPBDataType keyDataType = field.mapKeyDataType;
3566 NSEnumerator *keys = [internal keyEnumerator];
3568 while ((aKey = [keys nextObject])) {
3569 NSNumber *aValue = internal[aKey];
3570 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
3571 msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
3572 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
3574 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
3575 result += tagSize * count;
3579 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
3580 asField:(GPBFieldDescriptor *)field {
3581 GPBDataType valueDataType = GPBGetFieldDataType(field);
3582 GPBDataType keyDataType = field.mapKeyDataType;
3583 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
3584 NSDictionary *internal = _dictionary;
3585 NSEnumerator *keys = [internal keyEnumerator];
3587 while ((aKey = [keys nextObject])) {
3588 NSNumber *aValue = internal[aKey];
3589 [outputStream writeInt32NoTag:tag];
3590 // Write the size of the message.
3591 int32_t unwrappedKey = [aKey intValue];
3592 uint64_t unwrappedValue = [aValue unsignedLongLongValue];
3593 size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
3594 msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
3595 [outputStream writeInt32NoTag:(int32_t)msgSize];
3596 // Write the fields.
3597 WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
3598 WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
3602 - (void)setGPBGenericValue:(GPBGenericValue *)value
3603 forGPBGenericValueKey:(GPBGenericValue *)key {
3604 [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueInt32)];
3607 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
3608 [self enumerateKeysAndUInt64sUsingBlock:^(int32_t key, uint64_t value, __unused BOOL *stop) {
3609 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%llu", value]);
3613 - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(int32_t)key {
3614 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
3615 if (wrapped && value) {
3616 *value = [wrapped unsignedLongLongValue];
3618 return (wrapped != NULL);
3621 - (void)addEntriesFromDictionary:(GPBInt32UInt64Dictionary *)otherDictionary {
3622 if (otherDictionary) {
3623 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
3625 GPBAutocreatedDictionaryModified(_autocreator, self);
3630 - (void)setUInt64:(uint64_t)value forKey:(int32_t)key {
3631 [_dictionary setObject:@(value) forKey:@(key)];
3633 GPBAutocreatedDictionaryModified(_autocreator, self);
3637 - (void)removeUInt64ForKey:(int32_t)aKey {
3638 [_dictionary removeObjectForKey:@(aKey)];
3642 [_dictionary removeAllObjects];
3647 #pragma mark - Int32 -> Int64
3649 @implementation GPBInt32Int64Dictionary {
3651 NSMutableDictionary *_dictionary;
3654 - (instancetype)init {
3655 return [self initWithInt64s:NULL forKeys:NULL count:0];
3658 - (instancetype)initWithInt64s:(const int64_t [])values
3659 forKeys:(const int32_t [])keys
3660 count:(NSUInteger)count {
3661 self = [super init];
3663 _dictionary = [[NSMutableDictionary alloc] init];
3664 if (count && values && keys) {
3665 for (NSUInteger i = 0; i < count; ++i) {
3666 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
3673 - (instancetype)initWithDictionary:(GPBInt32Int64Dictionary *)dictionary {
3674 self = [self initWithInt64s:NULL forKeys:NULL count:0];
3677 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
3683 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
3684 return [self initWithInt64s:NULL forKeys:NULL count:0];
3688 NSAssert(!_autocreator,
3689 @"%@: Autocreator must be cleared before release, autocreator: %@",
3690 [self class], _autocreator);
3691 [_dictionary release];
3695 - (instancetype)copyWithZone:(NSZone *)zone {
3696 return [[GPBInt32Int64Dictionary allocWithZone:zone] initWithDictionary:self];
3699 - (BOOL)isEqual:(id)other {
3700 if (self == other) {
3703 if (![other isKindOfClass:[GPBInt32Int64Dictionary class]]) {
3706 GPBInt32Int64Dictionary *otherDictionary = other;
3707 return [_dictionary isEqual:otherDictionary->_dictionary];
3710 - (NSUInteger)hash {
3711 return _dictionary.count;
3714 - (NSString *)description {
3715 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
3718 - (NSUInteger)count {
3719 return _dictionary.count;
3722 - (void)enumerateKeysAndInt64sUsingBlock:
3723 (void (NS_NOESCAPE ^)(int32_t key, int64_t value, BOOL *stop))block {
3725 NSDictionary *internal = _dictionary;
3726 NSEnumerator *keys = [internal keyEnumerator];
3728 while ((aKey = [keys nextObject])) {
3729 NSNumber *aValue = internal[aKey];
3730 block([aKey intValue], [aValue longLongValue], &stop);
3737 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
3738 NSDictionary *internal = _dictionary;
3739 NSUInteger count = internal.count;
3744 GPBDataType valueDataType = GPBGetFieldDataType(field);
3745 GPBDataType keyDataType = field.mapKeyDataType;
3747 NSEnumerator *keys = [internal keyEnumerator];
3749 while ((aKey = [keys nextObject])) {
3750 NSNumber *aValue = internal[aKey];
3751 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
3752 msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
3753 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
3755 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
3756 result += tagSize * count;
3760 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
3761 asField:(GPBFieldDescriptor *)field {
3762 GPBDataType valueDataType = GPBGetFieldDataType(field);
3763 GPBDataType keyDataType = field.mapKeyDataType;
3764 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
3765 NSDictionary *internal = _dictionary;
3766 NSEnumerator *keys = [internal keyEnumerator];
3768 while ((aKey = [keys nextObject])) {
3769 NSNumber *aValue = internal[aKey];
3770 [outputStream writeInt32NoTag:tag];
3771 // Write the size of the message.
3772 int32_t unwrappedKey = [aKey intValue];
3773 int64_t unwrappedValue = [aValue longLongValue];
3774 size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
3775 msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
3776 [outputStream writeInt32NoTag:(int32_t)msgSize];
3777 // Write the fields.
3778 WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
3779 WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
3783 - (void)setGPBGenericValue:(GPBGenericValue *)value
3784 forGPBGenericValueKey:(GPBGenericValue *)key {
3785 [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueInt32)];
3788 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
3789 [self enumerateKeysAndInt64sUsingBlock:^(int32_t key, int64_t value, __unused BOOL *stop) {
3790 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%lld", value]);
3794 - (BOOL)getInt64:(nullable int64_t *)value forKey:(int32_t)key {
3795 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
3796 if (wrapped && value) {
3797 *value = [wrapped longLongValue];
3799 return (wrapped != NULL);
3802 - (void)addEntriesFromDictionary:(GPBInt32Int64Dictionary *)otherDictionary {
3803 if (otherDictionary) {
3804 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
3806 GPBAutocreatedDictionaryModified(_autocreator, self);
3811 - (void)setInt64:(int64_t)value forKey:(int32_t)key {
3812 [_dictionary setObject:@(value) forKey:@(key)];
3814 GPBAutocreatedDictionaryModified(_autocreator, self);
3818 - (void)removeInt64ForKey:(int32_t)aKey {
3819 [_dictionary removeObjectForKey:@(aKey)];
3823 [_dictionary removeAllObjects];
3828 #pragma mark - Int32 -> Bool
3830 @implementation GPBInt32BoolDictionary {
3832 NSMutableDictionary *_dictionary;
3835 - (instancetype)init {
3836 return [self initWithBools:NULL forKeys:NULL count:0];
3839 - (instancetype)initWithBools:(const BOOL [])values
3840 forKeys:(const int32_t [])keys
3841 count:(NSUInteger)count {
3842 self = [super init];
3844 _dictionary = [[NSMutableDictionary alloc] init];
3845 if (count && values && keys) {
3846 for (NSUInteger i = 0; i < count; ++i) {
3847 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
3854 - (instancetype)initWithDictionary:(GPBInt32BoolDictionary *)dictionary {
3855 self = [self initWithBools:NULL forKeys:NULL count:0];
3858 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
3864 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
3865 return [self initWithBools:NULL forKeys:NULL count:0];
3869 NSAssert(!_autocreator,
3870 @"%@: Autocreator must be cleared before release, autocreator: %@",
3871 [self class], _autocreator);
3872 [_dictionary release];
3876 - (instancetype)copyWithZone:(NSZone *)zone {
3877 return [[GPBInt32BoolDictionary allocWithZone:zone] initWithDictionary:self];
3880 - (BOOL)isEqual:(id)other {
3881 if (self == other) {
3884 if (![other isKindOfClass:[GPBInt32BoolDictionary class]]) {
3887 GPBInt32BoolDictionary *otherDictionary = other;
3888 return [_dictionary isEqual:otherDictionary->_dictionary];
3891 - (NSUInteger)hash {
3892 return _dictionary.count;
3895 - (NSString *)description {
3896 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
3899 - (NSUInteger)count {
3900 return _dictionary.count;
3903 - (void)enumerateKeysAndBoolsUsingBlock:
3904 (void (NS_NOESCAPE ^)(int32_t key, BOOL value, BOOL *stop))block {
3906 NSDictionary *internal = _dictionary;
3907 NSEnumerator *keys = [internal keyEnumerator];
3909 while ((aKey = [keys nextObject])) {
3910 NSNumber *aValue = internal[aKey];
3911 block([aKey intValue], [aValue boolValue], &stop);
3918 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
3919 NSDictionary *internal = _dictionary;
3920 NSUInteger count = internal.count;
3925 GPBDataType valueDataType = GPBGetFieldDataType(field);
3926 GPBDataType keyDataType = field.mapKeyDataType;
3928 NSEnumerator *keys = [internal keyEnumerator];
3930 while ((aKey = [keys nextObject])) {
3931 NSNumber *aValue = internal[aKey];
3932 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
3933 msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
3934 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
3936 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
3937 result += tagSize * count;
3941 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
3942 asField:(GPBFieldDescriptor *)field {
3943 GPBDataType valueDataType = GPBGetFieldDataType(field);
3944 GPBDataType keyDataType = field.mapKeyDataType;
3945 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
3946 NSDictionary *internal = _dictionary;
3947 NSEnumerator *keys = [internal keyEnumerator];
3949 while ((aKey = [keys nextObject])) {
3950 NSNumber *aValue = internal[aKey];
3951 [outputStream writeInt32NoTag:tag];
3952 // Write the size of the message.
3953 int32_t unwrappedKey = [aKey intValue];
3954 BOOL unwrappedValue = [aValue boolValue];
3955 size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
3956 msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
3957 [outputStream writeInt32NoTag:(int32_t)msgSize];
3958 // Write the fields.
3959 WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
3960 WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
3964 - (void)setGPBGenericValue:(GPBGenericValue *)value
3965 forGPBGenericValueKey:(GPBGenericValue *)key {
3966 [_dictionary setObject:@(value->valueBool) forKey:@(key->valueInt32)];
3969 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
3970 [self enumerateKeysAndBoolsUsingBlock:^(int32_t key, BOOL value, __unused BOOL *stop) {
3971 block([NSString stringWithFormat:@"%d", key], (value ? @"true" : @"false"));
3975 - (BOOL)getBool:(nullable BOOL *)value forKey:(int32_t)key {
3976 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
3977 if (wrapped && value) {
3978 *value = [wrapped boolValue];
3980 return (wrapped != NULL);
3983 - (void)addEntriesFromDictionary:(GPBInt32BoolDictionary *)otherDictionary {
3984 if (otherDictionary) {
3985 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
3987 GPBAutocreatedDictionaryModified(_autocreator, self);
3992 - (void)setBool:(BOOL)value forKey:(int32_t)key {
3993 [_dictionary setObject:@(value) forKey:@(key)];
3995 GPBAutocreatedDictionaryModified(_autocreator, self);
3999 - (void)removeBoolForKey:(int32_t)aKey {
4000 [_dictionary removeObjectForKey:@(aKey)];
4004 [_dictionary removeAllObjects];
4009 #pragma mark - Int32 -> Float
4011 @implementation GPBInt32FloatDictionary {
4013 NSMutableDictionary *_dictionary;
4016 - (instancetype)init {
4017 return [self initWithFloats:NULL forKeys:NULL count:0];
4020 - (instancetype)initWithFloats:(const float [])values
4021 forKeys:(const int32_t [])keys
4022 count:(NSUInteger)count {
4023 self = [super init];
4025 _dictionary = [[NSMutableDictionary alloc] init];
4026 if (count && values && keys) {
4027 for (NSUInteger i = 0; i < count; ++i) {
4028 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
4035 - (instancetype)initWithDictionary:(GPBInt32FloatDictionary *)dictionary {
4036 self = [self initWithFloats:NULL forKeys:NULL count:0];
4039 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
4045 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
4046 return [self initWithFloats:NULL forKeys:NULL count:0];
4050 NSAssert(!_autocreator,
4051 @"%@: Autocreator must be cleared before release, autocreator: %@",
4052 [self class], _autocreator);
4053 [_dictionary release];
4057 - (instancetype)copyWithZone:(NSZone *)zone {
4058 return [[GPBInt32FloatDictionary allocWithZone:zone] initWithDictionary:self];
4061 - (BOOL)isEqual:(id)other {
4062 if (self == other) {
4065 if (![other isKindOfClass:[GPBInt32FloatDictionary class]]) {
4068 GPBInt32FloatDictionary *otherDictionary = other;
4069 return [_dictionary isEqual:otherDictionary->_dictionary];
4072 - (NSUInteger)hash {
4073 return _dictionary.count;
4076 - (NSString *)description {
4077 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
4080 - (NSUInteger)count {
4081 return _dictionary.count;
4084 - (void)enumerateKeysAndFloatsUsingBlock:
4085 (void (NS_NOESCAPE ^)(int32_t key, float value, BOOL *stop))block {
4087 NSDictionary *internal = _dictionary;
4088 NSEnumerator *keys = [internal keyEnumerator];
4090 while ((aKey = [keys nextObject])) {
4091 NSNumber *aValue = internal[aKey];
4092 block([aKey intValue], [aValue floatValue], &stop);
4099 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
4100 NSDictionary *internal = _dictionary;
4101 NSUInteger count = internal.count;
4106 GPBDataType valueDataType = GPBGetFieldDataType(field);
4107 GPBDataType keyDataType = field.mapKeyDataType;
4109 NSEnumerator *keys = [internal keyEnumerator];
4111 while ((aKey = [keys nextObject])) {
4112 NSNumber *aValue = internal[aKey];
4113 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
4114 msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
4115 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
4117 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
4118 result += tagSize * count;
4122 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
4123 asField:(GPBFieldDescriptor *)field {
4124 GPBDataType valueDataType = GPBGetFieldDataType(field);
4125 GPBDataType keyDataType = field.mapKeyDataType;
4126 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
4127 NSDictionary *internal = _dictionary;
4128 NSEnumerator *keys = [internal keyEnumerator];
4130 while ((aKey = [keys nextObject])) {
4131 NSNumber *aValue = internal[aKey];
4132 [outputStream writeInt32NoTag:tag];
4133 // Write the size of the message.
4134 int32_t unwrappedKey = [aKey intValue];
4135 float unwrappedValue = [aValue floatValue];
4136 size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
4137 msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
4138 [outputStream writeInt32NoTag:(int32_t)msgSize];
4139 // Write the fields.
4140 WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
4141 WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
4145 - (void)setGPBGenericValue:(GPBGenericValue *)value
4146 forGPBGenericValueKey:(GPBGenericValue *)key {
4147 [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueInt32)];
4150 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
4151 [self enumerateKeysAndFloatsUsingBlock:^(int32_t key, float value, __unused BOOL *stop) {
4152 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
4156 - (BOOL)getFloat:(nullable float *)value forKey:(int32_t)key {
4157 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
4158 if (wrapped && value) {
4159 *value = [wrapped floatValue];
4161 return (wrapped != NULL);
4164 - (void)addEntriesFromDictionary:(GPBInt32FloatDictionary *)otherDictionary {
4165 if (otherDictionary) {
4166 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
4168 GPBAutocreatedDictionaryModified(_autocreator, self);
4173 - (void)setFloat:(float)value forKey:(int32_t)key {
4174 [_dictionary setObject:@(value) forKey:@(key)];
4176 GPBAutocreatedDictionaryModified(_autocreator, self);
4180 - (void)removeFloatForKey:(int32_t)aKey {
4181 [_dictionary removeObjectForKey:@(aKey)];
4185 [_dictionary removeAllObjects];
4190 #pragma mark - Int32 -> Double
4192 @implementation GPBInt32DoubleDictionary {
4194 NSMutableDictionary *_dictionary;
4197 - (instancetype)init {
4198 return [self initWithDoubles:NULL forKeys:NULL count:0];
4201 - (instancetype)initWithDoubles:(const double [])values
4202 forKeys:(const int32_t [])keys
4203 count:(NSUInteger)count {
4204 self = [super init];
4206 _dictionary = [[NSMutableDictionary alloc] init];
4207 if (count && values && keys) {
4208 for (NSUInteger i = 0; i < count; ++i) {
4209 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
4216 - (instancetype)initWithDictionary:(GPBInt32DoubleDictionary *)dictionary {
4217 self = [self initWithDoubles:NULL forKeys:NULL count:0];
4220 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
4226 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
4227 return [self initWithDoubles:NULL forKeys:NULL count:0];
4231 NSAssert(!_autocreator,
4232 @"%@: Autocreator must be cleared before release, autocreator: %@",
4233 [self class], _autocreator);
4234 [_dictionary release];
4238 - (instancetype)copyWithZone:(NSZone *)zone {
4239 return [[GPBInt32DoubleDictionary allocWithZone:zone] initWithDictionary:self];
4242 - (BOOL)isEqual:(id)other {
4243 if (self == other) {
4246 if (![other isKindOfClass:[GPBInt32DoubleDictionary class]]) {
4249 GPBInt32DoubleDictionary *otherDictionary = other;
4250 return [_dictionary isEqual:otherDictionary->_dictionary];
4253 - (NSUInteger)hash {
4254 return _dictionary.count;
4257 - (NSString *)description {
4258 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
4261 - (NSUInteger)count {
4262 return _dictionary.count;
4265 - (void)enumerateKeysAndDoublesUsingBlock:
4266 (void (NS_NOESCAPE ^)(int32_t key, double value, BOOL *stop))block {
4268 NSDictionary *internal = _dictionary;
4269 NSEnumerator *keys = [internal keyEnumerator];
4271 while ((aKey = [keys nextObject])) {
4272 NSNumber *aValue = internal[aKey];
4273 block([aKey intValue], [aValue doubleValue], &stop);
4280 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
4281 NSDictionary *internal = _dictionary;
4282 NSUInteger count = internal.count;
4287 GPBDataType valueDataType = GPBGetFieldDataType(field);
4288 GPBDataType keyDataType = field.mapKeyDataType;
4290 NSEnumerator *keys = [internal keyEnumerator];
4292 while ((aKey = [keys nextObject])) {
4293 NSNumber *aValue = internal[aKey];
4294 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
4295 msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
4296 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
4298 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
4299 result += tagSize * count;
4303 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
4304 asField:(GPBFieldDescriptor *)field {
4305 GPBDataType valueDataType = GPBGetFieldDataType(field);
4306 GPBDataType keyDataType = field.mapKeyDataType;
4307 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
4308 NSDictionary *internal = _dictionary;
4309 NSEnumerator *keys = [internal keyEnumerator];
4311 while ((aKey = [keys nextObject])) {
4312 NSNumber *aValue = internal[aKey];
4313 [outputStream writeInt32NoTag:tag];
4314 // Write the size of the message.
4315 int32_t unwrappedKey = [aKey intValue];
4316 double unwrappedValue = [aValue doubleValue];
4317 size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
4318 msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
4319 [outputStream writeInt32NoTag:(int32_t)msgSize];
4320 // Write the fields.
4321 WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
4322 WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
4326 - (void)setGPBGenericValue:(GPBGenericValue *)value
4327 forGPBGenericValueKey:(GPBGenericValue *)key {
4328 [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueInt32)];
4331 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
4332 [self enumerateKeysAndDoublesUsingBlock:^(int32_t key, double value, __unused BOOL *stop) {
4333 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
4337 - (BOOL)getDouble:(nullable double *)value forKey:(int32_t)key {
4338 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
4339 if (wrapped && value) {
4340 *value = [wrapped doubleValue];
4342 return (wrapped != NULL);
4345 - (void)addEntriesFromDictionary:(GPBInt32DoubleDictionary *)otherDictionary {
4346 if (otherDictionary) {
4347 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
4349 GPBAutocreatedDictionaryModified(_autocreator, self);
4354 - (void)setDouble:(double)value forKey:(int32_t)key {
4355 [_dictionary setObject:@(value) forKey:@(key)];
4357 GPBAutocreatedDictionaryModified(_autocreator, self);
4361 - (void)removeDoubleForKey:(int32_t)aKey {
4362 [_dictionary removeObjectForKey:@(aKey)];
4366 [_dictionary removeAllObjects];
4371 #pragma mark - Int32 -> Enum
4373 @implementation GPBInt32EnumDictionary {
4375 NSMutableDictionary *_dictionary;
4376 GPBEnumValidationFunc _validationFunc;
4379 @synthesize validationFunc = _validationFunc;
4381 - (instancetype)init {
4382 return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
4385 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
4386 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
4389 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
4390 rawValues:(const int32_t [])rawValues
4391 forKeys:(const int32_t [])keys
4392 count:(NSUInteger)count {
4393 self = [super init];
4395 _dictionary = [[NSMutableDictionary alloc] init];
4396 _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
4397 if (count && rawValues && keys) {
4398 for (NSUInteger i = 0; i < count; ++i) {
4399 [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])];
4406 - (instancetype)initWithDictionary:(GPBInt32EnumDictionary *)dictionary {
4407 self = [self initWithValidationFunction:dictionary.validationFunc
4413 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
4419 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
4420 capacity:(__unused NSUInteger)numItems {
4421 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
4425 NSAssert(!_autocreator,
4426 @"%@: Autocreator must be cleared before release, autocreator: %@",
4427 [self class], _autocreator);
4428 [_dictionary release];
4432 - (instancetype)copyWithZone:(NSZone *)zone {
4433 return [[GPBInt32EnumDictionary allocWithZone:zone] initWithDictionary:self];
4436 - (BOOL)isEqual:(id)other {
4437 if (self == other) {
4440 if (![other isKindOfClass:[GPBInt32EnumDictionary class]]) {
4443 GPBInt32EnumDictionary *otherDictionary = other;
4444 return [_dictionary isEqual:otherDictionary->_dictionary];
4447 - (NSUInteger)hash {
4448 return _dictionary.count;
4451 - (NSString *)description {
4452 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
4455 - (NSUInteger)count {
4456 return _dictionary.count;
4459 - (void)enumerateKeysAndRawValuesUsingBlock:
4460 (void (NS_NOESCAPE ^)(int32_t key, int32_t value, BOOL *stop))block {
4462 NSDictionary *internal = _dictionary;
4463 NSEnumerator *keys = [internal keyEnumerator];
4465 while ((aKey = [keys nextObject])) {
4466 NSNumber *aValue = internal[aKey];
4467 block([aKey intValue], [aValue intValue], &stop);
4474 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
4475 NSDictionary *internal = _dictionary;
4476 NSUInteger count = internal.count;
4481 GPBDataType valueDataType = GPBGetFieldDataType(field);
4482 GPBDataType keyDataType = field.mapKeyDataType;
4484 NSEnumerator *keys = [internal keyEnumerator];
4486 while ((aKey = [keys nextObject])) {
4487 NSNumber *aValue = internal[aKey];
4488 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
4489 msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
4490 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
4492 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
4493 result += tagSize * count;
4497 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
4498 asField:(GPBFieldDescriptor *)field {
4499 GPBDataType valueDataType = GPBGetFieldDataType(field);
4500 GPBDataType keyDataType = field.mapKeyDataType;
4501 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
4502 NSDictionary *internal = _dictionary;
4503 NSEnumerator *keys = [internal keyEnumerator];
4505 while ((aKey = [keys nextObject])) {
4506 NSNumber *aValue = internal[aKey];
4507 [outputStream writeInt32NoTag:tag];
4508 // Write the size of the message.
4509 int32_t unwrappedKey = [aKey intValue];
4510 int32_t unwrappedValue = [aValue intValue];
4511 size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
4512 msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
4513 [outputStream writeInt32NoTag:(int32_t)msgSize];
4514 // Write the fields.
4515 WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
4516 WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
4520 - (NSData *)serializedDataForUnknownValue:(int32_t)value
4521 forKey:(GPBGenericValue *)key
4522 keyDataType:(GPBDataType)keyDataType {
4523 size_t msgSize = ComputeDictInt32FieldSize(key->valueInt32, kMapKeyFieldNumber, keyDataType);
4524 msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
4525 NSMutableData *data = [NSMutableData dataWithLength:msgSize];
4526 GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
4527 WriteDictInt32Field(outputStream, key->valueInt32, kMapKeyFieldNumber, keyDataType);
4528 WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
4529 [outputStream flush];
4530 [outputStream release];
4533 - (void)setGPBGenericValue:(GPBGenericValue *)value
4534 forGPBGenericValueKey:(GPBGenericValue *)key {
4535 [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueInt32)];
4538 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
4539 [self enumerateKeysAndRawValuesUsingBlock:^(int32_t key, int32_t value, __unused BOOL *stop) {
4540 block([NSString stringWithFormat:@"%d", key], @(value));
4544 - (BOOL)getEnum:(int32_t *)value forKey:(int32_t)key {
4545 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
4546 if (wrapped && value) {
4547 int32_t result = [wrapped intValue];
4548 if (!_validationFunc(result)) {
4549 result = kGPBUnrecognizedEnumeratorValue;
4553 return (wrapped != NULL);
4556 - (BOOL)getRawValue:(int32_t *)rawValue forKey:(int32_t)key {
4557 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
4558 if (wrapped && rawValue) {
4559 *rawValue = [wrapped intValue];
4561 return (wrapped != NULL);
4564 - (void)enumerateKeysAndEnumsUsingBlock:
4565 (void (NS_NOESCAPE ^)(int32_t key, int32_t value, BOOL *stop))block {
4566 GPBEnumValidationFunc func = _validationFunc;
4568 NSEnumerator *keys = [_dictionary keyEnumerator];
4570 while ((aKey = [keys nextObject])) {
4571 NSNumber *aValue = _dictionary[aKey];
4572 int32_t unwrapped = [aValue intValue];
4573 if (!func(unwrapped)) {
4574 unwrapped = kGPBUnrecognizedEnumeratorValue;
4576 block([aKey intValue], unwrapped, &stop);
4583 - (void)addRawEntriesFromDictionary:(GPBInt32EnumDictionary *)otherDictionary {
4584 if (otherDictionary) {
4585 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
4587 GPBAutocreatedDictionaryModified(_autocreator, self);
4592 - (void)setRawValue:(int32_t)value forKey:(int32_t)key {
4593 [_dictionary setObject:@(value) forKey:@(key)];
4595 GPBAutocreatedDictionaryModified(_autocreator, self);
4599 - (void)removeEnumForKey:(int32_t)aKey {
4600 [_dictionary removeObjectForKey:@(aKey)];
4604 [_dictionary removeAllObjects];
4607 - (void)setEnum:(int32_t)value forKey:(int32_t)key {
4608 if (!_validationFunc(value)) {
4609 [NSException raise:NSInvalidArgumentException
4610 format:@"GPBInt32EnumDictionary: Attempt to set an unknown enum value (%d)",
4614 [_dictionary setObject:@(value) forKey:@(key)];
4616 GPBAutocreatedDictionaryModified(_autocreator, self);
4622 #pragma mark - Int32 -> Object
4624 @implementation GPBInt32ObjectDictionary {
4626 NSMutableDictionary *_dictionary;
4629 - (instancetype)init {
4630 return [self initWithObjects:NULL forKeys:NULL count:0];
4633 - (instancetype)initWithObjects:(const id [])objects
4634 forKeys:(const int32_t [])keys
4635 count:(NSUInteger)count {
4636 self = [super init];
4638 _dictionary = [[NSMutableDictionary alloc] init];
4639 if (count && objects && keys) {
4640 for (NSUInteger i = 0; i < count; ++i) {
4642 [NSException raise:NSInvalidArgumentException
4643 format:@"Attempting to add nil object to a Dictionary"];
4645 [_dictionary setObject:objects[i] forKey:@(keys[i])];
4652 - (instancetype)initWithDictionary:(GPBInt32ObjectDictionary *)dictionary {
4653 self = [self initWithObjects:NULL forKeys:NULL count:0];
4656 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
4662 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
4663 return [self initWithObjects:NULL forKeys:NULL count:0];
4667 NSAssert(!_autocreator,
4668 @"%@: Autocreator must be cleared before release, autocreator: %@",
4669 [self class], _autocreator);
4670 [_dictionary release];
4674 - (instancetype)copyWithZone:(NSZone *)zone {
4675 return [[GPBInt32ObjectDictionary allocWithZone:zone] initWithDictionary:self];
4678 - (BOOL)isEqual:(id)other {
4679 if (self == other) {
4682 if (![other isKindOfClass:[GPBInt32ObjectDictionary class]]) {
4685 GPBInt32ObjectDictionary *otherDictionary = other;
4686 return [_dictionary isEqual:otherDictionary->_dictionary];
4689 - (NSUInteger)hash {
4690 return _dictionary.count;
4693 - (NSString *)description {
4694 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
4697 - (NSUInteger)count {
4698 return _dictionary.count;
4701 - (void)enumerateKeysAndObjectsUsingBlock:
4702 (void (NS_NOESCAPE ^)(int32_t key, id object, BOOL *stop))block {
4704 NSDictionary *internal = _dictionary;
4705 NSEnumerator *keys = [internal keyEnumerator];
4707 while ((aKey = [keys nextObject])) {
4708 id aObject = internal[aKey];
4709 block([aKey intValue], aObject, &stop);
4716 - (BOOL)isInitialized {
4717 for (GPBMessage *msg in [_dictionary objectEnumerator]) {
4718 if (!msg.initialized) {
4725 - (instancetype)deepCopyWithZone:(NSZone *)zone {
4726 GPBInt32ObjectDictionary *newDict =
4727 [[GPBInt32ObjectDictionary alloc] init];
4728 NSEnumerator *keys = [_dictionary keyEnumerator];
4730 NSMutableDictionary *internalDict = newDict->_dictionary;
4731 while ((aKey = [keys nextObject])) {
4732 GPBMessage *msg = _dictionary[aKey];
4733 GPBMessage *copiedMsg = [msg copyWithZone:zone];
4734 [internalDict setObject:copiedMsg forKey:aKey];
4735 [copiedMsg release];
4740 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
4741 NSDictionary *internal = _dictionary;
4742 NSUInteger count = internal.count;
4747 GPBDataType valueDataType = GPBGetFieldDataType(field);
4748 GPBDataType keyDataType = field.mapKeyDataType;
4750 NSEnumerator *keys = [internal keyEnumerator];
4752 while ((aKey = [keys nextObject])) {
4753 id aObject = internal[aKey];
4754 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
4755 msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
4756 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
4758 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
4759 result += tagSize * count;
4763 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
4764 asField:(GPBFieldDescriptor *)field {
4765 GPBDataType valueDataType = GPBGetFieldDataType(field);
4766 GPBDataType keyDataType = field.mapKeyDataType;
4767 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
4768 NSDictionary *internal = _dictionary;
4769 NSEnumerator *keys = [internal keyEnumerator];
4771 while ((aKey = [keys nextObject])) {
4772 id aObject = internal[aKey];
4773 [outputStream writeInt32NoTag:tag];
4774 // Write the size of the message.
4775 int32_t unwrappedKey = [aKey intValue];
4776 id unwrappedValue = aObject;
4777 size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
4778 msgSize += ComputeDictObjectFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
4779 [outputStream writeInt32NoTag:(int32_t)msgSize];
4780 // Write the fields.
4781 WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
4782 WriteDictObjectField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
4786 - (void)setGPBGenericValue:(GPBGenericValue *)value
4787 forGPBGenericValueKey:(GPBGenericValue *)key {
4788 [_dictionary setObject:value->valueString forKey:@(key->valueInt32)];
4791 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
4792 [self enumerateKeysAndObjectsUsingBlock:^(int32_t key, id object, __unused BOOL *stop) {
4793 block([NSString stringWithFormat:@"%d", key], object);
4797 - (id)objectForKey:(int32_t)key {
4798 id result = [_dictionary objectForKey:@(key)];
4802 - (void)addEntriesFromDictionary:(GPBInt32ObjectDictionary *)otherDictionary {
4803 if (otherDictionary) {
4804 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
4806 GPBAutocreatedDictionaryModified(_autocreator, self);
4811 - (void)setObject:(id)object forKey:(int32_t)key {
4813 [NSException raise:NSInvalidArgumentException
4814 format:@"Attempting to add nil object to a Dictionary"];
4816 [_dictionary setObject:object forKey:@(key)];
4818 GPBAutocreatedDictionaryModified(_autocreator, self);
4822 - (void)removeObjectForKey:(int32_t)aKey {
4823 [_dictionary removeObjectForKey:@(aKey)];
4827 [_dictionary removeAllObjects];
4832 //%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(UInt64, uint64_t)
4833 // This block of code is generated, do not edit it directly.
4835 #pragma mark - UInt64 -> UInt32
4837 @implementation GPBUInt64UInt32Dictionary {
4839 NSMutableDictionary *_dictionary;
4842 - (instancetype)init {
4843 return [self initWithUInt32s:NULL forKeys:NULL count:0];
4846 - (instancetype)initWithUInt32s:(const uint32_t [])values
4847 forKeys:(const uint64_t [])keys
4848 count:(NSUInteger)count {
4849 self = [super init];
4851 _dictionary = [[NSMutableDictionary alloc] init];
4852 if (count && values && keys) {
4853 for (NSUInteger i = 0; i < count; ++i) {
4854 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
4861 - (instancetype)initWithDictionary:(GPBUInt64UInt32Dictionary *)dictionary {
4862 self = [self initWithUInt32s:NULL forKeys:NULL count:0];
4865 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
4871 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
4872 return [self initWithUInt32s:NULL forKeys:NULL count:0];
4876 NSAssert(!_autocreator,
4877 @"%@: Autocreator must be cleared before release, autocreator: %@",
4878 [self class], _autocreator);
4879 [_dictionary release];
4883 - (instancetype)copyWithZone:(NSZone *)zone {
4884 return [[GPBUInt64UInt32Dictionary allocWithZone:zone] initWithDictionary:self];
4887 - (BOOL)isEqual:(id)other {
4888 if (self == other) {
4891 if (![other isKindOfClass:[GPBUInt64UInt32Dictionary class]]) {
4894 GPBUInt64UInt32Dictionary *otherDictionary = other;
4895 return [_dictionary isEqual:otherDictionary->_dictionary];
4898 - (NSUInteger)hash {
4899 return _dictionary.count;
4902 - (NSString *)description {
4903 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
4906 - (NSUInteger)count {
4907 return _dictionary.count;
4910 - (void)enumerateKeysAndUInt32sUsingBlock:
4911 (void (NS_NOESCAPE ^)(uint64_t key, uint32_t value, BOOL *stop))block {
4913 NSDictionary *internal = _dictionary;
4914 NSEnumerator *keys = [internal keyEnumerator];
4916 while ((aKey = [keys nextObject])) {
4917 NSNumber *aValue = internal[aKey];
4918 block([aKey unsignedLongLongValue], [aValue unsignedIntValue], &stop);
4925 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
4926 NSDictionary *internal = _dictionary;
4927 NSUInteger count = internal.count;
4932 GPBDataType valueDataType = GPBGetFieldDataType(field);
4933 GPBDataType keyDataType = field.mapKeyDataType;
4935 NSEnumerator *keys = [internal keyEnumerator];
4937 while ((aKey = [keys nextObject])) {
4938 NSNumber *aValue = internal[aKey];
4939 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
4940 msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
4941 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
4943 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
4944 result += tagSize * count;
4948 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
4949 asField:(GPBFieldDescriptor *)field {
4950 GPBDataType valueDataType = GPBGetFieldDataType(field);
4951 GPBDataType keyDataType = field.mapKeyDataType;
4952 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
4953 NSDictionary *internal = _dictionary;
4954 NSEnumerator *keys = [internal keyEnumerator];
4956 while ((aKey = [keys nextObject])) {
4957 NSNumber *aValue = internal[aKey];
4958 [outputStream writeInt32NoTag:tag];
4959 // Write the size of the message.
4960 uint64_t unwrappedKey = [aKey unsignedLongLongValue];
4961 uint32_t unwrappedValue = [aValue unsignedIntValue];
4962 size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
4963 msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
4964 [outputStream writeInt32NoTag:(int32_t)msgSize];
4965 // Write the fields.
4966 WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
4967 WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
4971 - (void)setGPBGenericValue:(GPBGenericValue *)value
4972 forGPBGenericValueKey:(GPBGenericValue *)key {
4973 [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueUInt64)];
4976 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
4977 [self enumerateKeysAndUInt32sUsingBlock:^(uint64_t key, uint32_t value, __unused BOOL *stop) {
4978 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%u", value]);
4982 - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(uint64_t)key {
4983 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
4984 if (wrapped && value) {
4985 *value = [wrapped unsignedIntValue];
4987 return (wrapped != NULL);
4990 - (void)addEntriesFromDictionary:(GPBUInt64UInt32Dictionary *)otherDictionary {
4991 if (otherDictionary) {
4992 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
4994 GPBAutocreatedDictionaryModified(_autocreator, self);
4999 - (void)setUInt32:(uint32_t)value forKey:(uint64_t)key {
5000 [_dictionary setObject:@(value) forKey:@(key)];
5002 GPBAutocreatedDictionaryModified(_autocreator, self);
5006 - (void)removeUInt32ForKey:(uint64_t)aKey {
5007 [_dictionary removeObjectForKey:@(aKey)];
5011 [_dictionary removeAllObjects];
5016 #pragma mark - UInt64 -> Int32
5018 @implementation GPBUInt64Int32Dictionary {
5020 NSMutableDictionary *_dictionary;
5023 - (instancetype)init {
5024 return [self initWithInt32s:NULL forKeys:NULL count:0];
5027 - (instancetype)initWithInt32s:(const int32_t [])values
5028 forKeys:(const uint64_t [])keys
5029 count:(NSUInteger)count {
5030 self = [super init];
5032 _dictionary = [[NSMutableDictionary alloc] init];
5033 if (count && values && keys) {
5034 for (NSUInteger i = 0; i < count; ++i) {
5035 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
5042 - (instancetype)initWithDictionary:(GPBUInt64Int32Dictionary *)dictionary {
5043 self = [self initWithInt32s:NULL forKeys:NULL count:0];
5046 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
5052 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
5053 return [self initWithInt32s:NULL forKeys:NULL count:0];
5057 NSAssert(!_autocreator,
5058 @"%@: Autocreator must be cleared before release, autocreator: %@",
5059 [self class], _autocreator);
5060 [_dictionary release];
5064 - (instancetype)copyWithZone:(NSZone *)zone {
5065 return [[GPBUInt64Int32Dictionary allocWithZone:zone] initWithDictionary:self];
5068 - (BOOL)isEqual:(id)other {
5069 if (self == other) {
5072 if (![other isKindOfClass:[GPBUInt64Int32Dictionary class]]) {
5075 GPBUInt64Int32Dictionary *otherDictionary = other;
5076 return [_dictionary isEqual:otherDictionary->_dictionary];
5079 - (NSUInteger)hash {
5080 return _dictionary.count;
5083 - (NSString *)description {
5084 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
5087 - (NSUInteger)count {
5088 return _dictionary.count;
5091 - (void)enumerateKeysAndInt32sUsingBlock:
5092 (void (NS_NOESCAPE ^)(uint64_t key, int32_t value, BOOL *stop))block {
5094 NSDictionary *internal = _dictionary;
5095 NSEnumerator *keys = [internal keyEnumerator];
5097 while ((aKey = [keys nextObject])) {
5098 NSNumber *aValue = internal[aKey];
5099 block([aKey unsignedLongLongValue], [aValue intValue], &stop);
5106 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
5107 NSDictionary *internal = _dictionary;
5108 NSUInteger count = internal.count;
5113 GPBDataType valueDataType = GPBGetFieldDataType(field);
5114 GPBDataType keyDataType = field.mapKeyDataType;
5116 NSEnumerator *keys = [internal keyEnumerator];
5118 while ((aKey = [keys nextObject])) {
5119 NSNumber *aValue = internal[aKey];
5120 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
5121 msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
5122 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
5124 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
5125 result += tagSize * count;
5129 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
5130 asField:(GPBFieldDescriptor *)field {
5131 GPBDataType valueDataType = GPBGetFieldDataType(field);
5132 GPBDataType keyDataType = field.mapKeyDataType;
5133 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
5134 NSDictionary *internal = _dictionary;
5135 NSEnumerator *keys = [internal keyEnumerator];
5137 while ((aKey = [keys nextObject])) {
5138 NSNumber *aValue = internal[aKey];
5139 [outputStream writeInt32NoTag:tag];
5140 // Write the size of the message.
5141 uint64_t unwrappedKey = [aKey unsignedLongLongValue];
5142 int32_t unwrappedValue = [aValue intValue];
5143 size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
5144 msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
5145 [outputStream writeInt32NoTag:(int32_t)msgSize];
5146 // Write the fields.
5147 WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
5148 WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
5152 - (void)setGPBGenericValue:(GPBGenericValue *)value
5153 forGPBGenericValueKey:(GPBGenericValue *)key {
5154 [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueUInt64)];
5157 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
5158 [self enumerateKeysAndInt32sUsingBlock:^(uint64_t key, int32_t value, __unused BOOL *stop) {
5159 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%d", value]);
5163 - (BOOL)getInt32:(nullable int32_t *)value forKey:(uint64_t)key {
5164 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
5165 if (wrapped && value) {
5166 *value = [wrapped intValue];
5168 return (wrapped != NULL);
5171 - (void)addEntriesFromDictionary:(GPBUInt64Int32Dictionary *)otherDictionary {
5172 if (otherDictionary) {
5173 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
5175 GPBAutocreatedDictionaryModified(_autocreator, self);
5180 - (void)setInt32:(int32_t)value forKey:(uint64_t)key {
5181 [_dictionary setObject:@(value) forKey:@(key)];
5183 GPBAutocreatedDictionaryModified(_autocreator, self);
5187 - (void)removeInt32ForKey:(uint64_t)aKey {
5188 [_dictionary removeObjectForKey:@(aKey)];
5192 [_dictionary removeAllObjects];
5197 #pragma mark - UInt64 -> UInt64
5199 @implementation GPBUInt64UInt64Dictionary {
5201 NSMutableDictionary *_dictionary;
5204 - (instancetype)init {
5205 return [self initWithUInt64s:NULL forKeys:NULL count:0];
5208 - (instancetype)initWithUInt64s:(const uint64_t [])values
5209 forKeys:(const uint64_t [])keys
5210 count:(NSUInteger)count {
5211 self = [super init];
5213 _dictionary = [[NSMutableDictionary alloc] init];
5214 if (count && values && keys) {
5215 for (NSUInteger i = 0; i < count; ++i) {
5216 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
5223 - (instancetype)initWithDictionary:(GPBUInt64UInt64Dictionary *)dictionary {
5224 self = [self initWithUInt64s:NULL forKeys:NULL count:0];
5227 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
5233 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
5234 return [self initWithUInt64s:NULL forKeys:NULL count:0];
5238 NSAssert(!_autocreator,
5239 @"%@: Autocreator must be cleared before release, autocreator: %@",
5240 [self class], _autocreator);
5241 [_dictionary release];
5245 - (instancetype)copyWithZone:(NSZone *)zone {
5246 return [[GPBUInt64UInt64Dictionary allocWithZone:zone] initWithDictionary:self];
5249 - (BOOL)isEqual:(id)other {
5250 if (self == other) {
5253 if (![other isKindOfClass:[GPBUInt64UInt64Dictionary class]]) {
5256 GPBUInt64UInt64Dictionary *otherDictionary = other;
5257 return [_dictionary isEqual:otherDictionary->_dictionary];
5260 - (NSUInteger)hash {
5261 return _dictionary.count;
5264 - (NSString *)description {
5265 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
5268 - (NSUInteger)count {
5269 return _dictionary.count;
5272 - (void)enumerateKeysAndUInt64sUsingBlock:
5273 (void (NS_NOESCAPE ^)(uint64_t key, uint64_t value, BOOL *stop))block {
5275 NSDictionary *internal = _dictionary;
5276 NSEnumerator *keys = [internal keyEnumerator];
5278 while ((aKey = [keys nextObject])) {
5279 NSNumber *aValue = internal[aKey];
5280 block([aKey unsignedLongLongValue], [aValue unsignedLongLongValue], &stop);
5287 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
5288 NSDictionary *internal = _dictionary;
5289 NSUInteger count = internal.count;
5294 GPBDataType valueDataType = GPBGetFieldDataType(field);
5295 GPBDataType keyDataType = field.mapKeyDataType;
5297 NSEnumerator *keys = [internal keyEnumerator];
5299 while ((aKey = [keys nextObject])) {
5300 NSNumber *aValue = internal[aKey];
5301 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
5302 msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
5303 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
5305 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
5306 result += tagSize * count;
5310 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
5311 asField:(GPBFieldDescriptor *)field {
5312 GPBDataType valueDataType = GPBGetFieldDataType(field);
5313 GPBDataType keyDataType = field.mapKeyDataType;
5314 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
5315 NSDictionary *internal = _dictionary;
5316 NSEnumerator *keys = [internal keyEnumerator];
5318 while ((aKey = [keys nextObject])) {
5319 NSNumber *aValue = internal[aKey];
5320 [outputStream writeInt32NoTag:tag];
5321 // Write the size of the message.
5322 uint64_t unwrappedKey = [aKey unsignedLongLongValue];
5323 uint64_t unwrappedValue = [aValue unsignedLongLongValue];
5324 size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
5325 msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
5326 [outputStream writeInt32NoTag:(int32_t)msgSize];
5327 // Write the fields.
5328 WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
5329 WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
5333 - (void)setGPBGenericValue:(GPBGenericValue *)value
5334 forGPBGenericValueKey:(GPBGenericValue *)key {
5335 [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueUInt64)];
5338 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
5339 [self enumerateKeysAndUInt64sUsingBlock:^(uint64_t key, uint64_t value, __unused BOOL *stop) {
5340 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%llu", value]);
5344 - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(uint64_t)key {
5345 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
5346 if (wrapped && value) {
5347 *value = [wrapped unsignedLongLongValue];
5349 return (wrapped != NULL);
5352 - (void)addEntriesFromDictionary:(GPBUInt64UInt64Dictionary *)otherDictionary {
5353 if (otherDictionary) {
5354 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
5356 GPBAutocreatedDictionaryModified(_autocreator, self);
5361 - (void)setUInt64:(uint64_t)value forKey:(uint64_t)key {
5362 [_dictionary setObject:@(value) forKey:@(key)];
5364 GPBAutocreatedDictionaryModified(_autocreator, self);
5368 - (void)removeUInt64ForKey:(uint64_t)aKey {
5369 [_dictionary removeObjectForKey:@(aKey)];
5373 [_dictionary removeAllObjects];
5378 #pragma mark - UInt64 -> Int64
5380 @implementation GPBUInt64Int64Dictionary {
5382 NSMutableDictionary *_dictionary;
5385 - (instancetype)init {
5386 return [self initWithInt64s:NULL forKeys:NULL count:0];
5389 - (instancetype)initWithInt64s:(const int64_t [])values
5390 forKeys:(const uint64_t [])keys
5391 count:(NSUInteger)count {
5392 self = [super init];
5394 _dictionary = [[NSMutableDictionary alloc] init];
5395 if (count && values && keys) {
5396 for (NSUInteger i = 0; i < count; ++i) {
5397 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
5404 - (instancetype)initWithDictionary:(GPBUInt64Int64Dictionary *)dictionary {
5405 self = [self initWithInt64s:NULL forKeys:NULL count:0];
5408 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
5414 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
5415 return [self initWithInt64s:NULL forKeys:NULL count:0];
5419 NSAssert(!_autocreator,
5420 @"%@: Autocreator must be cleared before release, autocreator: %@",
5421 [self class], _autocreator);
5422 [_dictionary release];
5426 - (instancetype)copyWithZone:(NSZone *)zone {
5427 return [[GPBUInt64Int64Dictionary allocWithZone:zone] initWithDictionary:self];
5430 - (BOOL)isEqual:(id)other {
5431 if (self == other) {
5434 if (![other isKindOfClass:[GPBUInt64Int64Dictionary class]]) {
5437 GPBUInt64Int64Dictionary *otherDictionary = other;
5438 return [_dictionary isEqual:otherDictionary->_dictionary];
5441 - (NSUInteger)hash {
5442 return _dictionary.count;
5445 - (NSString *)description {
5446 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
5449 - (NSUInteger)count {
5450 return _dictionary.count;
5453 - (void)enumerateKeysAndInt64sUsingBlock:
5454 (void (NS_NOESCAPE ^)(uint64_t key, int64_t value, BOOL *stop))block {
5456 NSDictionary *internal = _dictionary;
5457 NSEnumerator *keys = [internal keyEnumerator];
5459 while ((aKey = [keys nextObject])) {
5460 NSNumber *aValue = internal[aKey];
5461 block([aKey unsignedLongLongValue], [aValue longLongValue], &stop);
5468 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
5469 NSDictionary *internal = _dictionary;
5470 NSUInteger count = internal.count;
5475 GPBDataType valueDataType = GPBGetFieldDataType(field);
5476 GPBDataType keyDataType = field.mapKeyDataType;
5478 NSEnumerator *keys = [internal keyEnumerator];
5480 while ((aKey = [keys nextObject])) {
5481 NSNumber *aValue = internal[aKey];
5482 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
5483 msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
5484 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
5486 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
5487 result += tagSize * count;
5491 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
5492 asField:(GPBFieldDescriptor *)field {
5493 GPBDataType valueDataType = GPBGetFieldDataType(field);
5494 GPBDataType keyDataType = field.mapKeyDataType;
5495 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
5496 NSDictionary *internal = _dictionary;
5497 NSEnumerator *keys = [internal keyEnumerator];
5499 while ((aKey = [keys nextObject])) {
5500 NSNumber *aValue = internal[aKey];
5501 [outputStream writeInt32NoTag:tag];
5502 // Write the size of the message.
5503 uint64_t unwrappedKey = [aKey unsignedLongLongValue];
5504 int64_t unwrappedValue = [aValue longLongValue];
5505 size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
5506 msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
5507 [outputStream writeInt32NoTag:(int32_t)msgSize];
5508 // Write the fields.
5509 WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
5510 WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
5514 - (void)setGPBGenericValue:(GPBGenericValue *)value
5515 forGPBGenericValueKey:(GPBGenericValue *)key {
5516 [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueUInt64)];
5519 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
5520 [self enumerateKeysAndInt64sUsingBlock:^(uint64_t key, int64_t value, __unused BOOL *stop) {
5521 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%lld", value]);
5525 - (BOOL)getInt64:(nullable int64_t *)value forKey:(uint64_t)key {
5526 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
5527 if (wrapped && value) {
5528 *value = [wrapped longLongValue];
5530 return (wrapped != NULL);
5533 - (void)addEntriesFromDictionary:(GPBUInt64Int64Dictionary *)otherDictionary {
5534 if (otherDictionary) {
5535 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
5537 GPBAutocreatedDictionaryModified(_autocreator, self);
5542 - (void)setInt64:(int64_t)value forKey:(uint64_t)key {
5543 [_dictionary setObject:@(value) forKey:@(key)];
5545 GPBAutocreatedDictionaryModified(_autocreator, self);
5549 - (void)removeInt64ForKey:(uint64_t)aKey {
5550 [_dictionary removeObjectForKey:@(aKey)];
5554 [_dictionary removeAllObjects];
5559 #pragma mark - UInt64 -> Bool
5561 @implementation GPBUInt64BoolDictionary {
5563 NSMutableDictionary *_dictionary;
5566 - (instancetype)init {
5567 return [self initWithBools:NULL forKeys:NULL count:0];
5570 - (instancetype)initWithBools:(const BOOL [])values
5571 forKeys:(const uint64_t [])keys
5572 count:(NSUInteger)count {
5573 self = [super init];
5575 _dictionary = [[NSMutableDictionary alloc] init];
5576 if (count && values && keys) {
5577 for (NSUInteger i = 0; i < count; ++i) {
5578 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
5585 - (instancetype)initWithDictionary:(GPBUInt64BoolDictionary *)dictionary {
5586 self = [self initWithBools:NULL forKeys:NULL count:0];
5589 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
5595 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
5596 return [self initWithBools:NULL forKeys:NULL count:0];
5600 NSAssert(!_autocreator,
5601 @"%@: Autocreator must be cleared before release, autocreator: %@",
5602 [self class], _autocreator);
5603 [_dictionary release];
5607 - (instancetype)copyWithZone:(NSZone *)zone {
5608 return [[GPBUInt64BoolDictionary allocWithZone:zone] initWithDictionary:self];
5611 - (BOOL)isEqual:(id)other {
5612 if (self == other) {
5615 if (![other isKindOfClass:[GPBUInt64BoolDictionary class]]) {
5618 GPBUInt64BoolDictionary *otherDictionary = other;
5619 return [_dictionary isEqual:otherDictionary->_dictionary];
5622 - (NSUInteger)hash {
5623 return _dictionary.count;
5626 - (NSString *)description {
5627 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
5630 - (NSUInteger)count {
5631 return _dictionary.count;
5634 - (void)enumerateKeysAndBoolsUsingBlock:
5635 (void (NS_NOESCAPE ^)(uint64_t key, BOOL value, BOOL *stop))block {
5637 NSDictionary *internal = _dictionary;
5638 NSEnumerator *keys = [internal keyEnumerator];
5640 while ((aKey = [keys nextObject])) {
5641 NSNumber *aValue = internal[aKey];
5642 block([aKey unsignedLongLongValue], [aValue boolValue], &stop);
5649 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
5650 NSDictionary *internal = _dictionary;
5651 NSUInteger count = internal.count;
5656 GPBDataType valueDataType = GPBGetFieldDataType(field);
5657 GPBDataType keyDataType = field.mapKeyDataType;
5659 NSEnumerator *keys = [internal keyEnumerator];
5661 while ((aKey = [keys nextObject])) {
5662 NSNumber *aValue = internal[aKey];
5663 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
5664 msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
5665 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
5667 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
5668 result += tagSize * count;
5672 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
5673 asField:(GPBFieldDescriptor *)field {
5674 GPBDataType valueDataType = GPBGetFieldDataType(field);
5675 GPBDataType keyDataType = field.mapKeyDataType;
5676 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
5677 NSDictionary *internal = _dictionary;
5678 NSEnumerator *keys = [internal keyEnumerator];
5680 while ((aKey = [keys nextObject])) {
5681 NSNumber *aValue = internal[aKey];
5682 [outputStream writeInt32NoTag:tag];
5683 // Write the size of the message.
5684 uint64_t unwrappedKey = [aKey unsignedLongLongValue];
5685 BOOL unwrappedValue = [aValue boolValue];
5686 size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
5687 msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
5688 [outputStream writeInt32NoTag:(int32_t)msgSize];
5689 // Write the fields.
5690 WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
5691 WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
5695 - (void)setGPBGenericValue:(GPBGenericValue *)value
5696 forGPBGenericValueKey:(GPBGenericValue *)key {
5697 [_dictionary setObject:@(value->valueBool) forKey:@(key->valueUInt64)];
5700 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
5701 [self enumerateKeysAndBoolsUsingBlock:^(uint64_t key, BOOL value, __unused BOOL *stop) {
5702 block([NSString stringWithFormat:@"%llu", key], (value ? @"true" : @"false"));
5706 - (BOOL)getBool:(nullable BOOL *)value forKey:(uint64_t)key {
5707 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
5708 if (wrapped && value) {
5709 *value = [wrapped boolValue];
5711 return (wrapped != NULL);
5714 - (void)addEntriesFromDictionary:(GPBUInt64BoolDictionary *)otherDictionary {
5715 if (otherDictionary) {
5716 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
5718 GPBAutocreatedDictionaryModified(_autocreator, self);
5723 - (void)setBool:(BOOL)value forKey:(uint64_t)key {
5724 [_dictionary setObject:@(value) forKey:@(key)];
5726 GPBAutocreatedDictionaryModified(_autocreator, self);
5730 - (void)removeBoolForKey:(uint64_t)aKey {
5731 [_dictionary removeObjectForKey:@(aKey)];
5735 [_dictionary removeAllObjects];
5740 #pragma mark - UInt64 -> Float
5742 @implementation GPBUInt64FloatDictionary {
5744 NSMutableDictionary *_dictionary;
5747 - (instancetype)init {
5748 return [self initWithFloats:NULL forKeys:NULL count:0];
5751 - (instancetype)initWithFloats:(const float [])values
5752 forKeys:(const uint64_t [])keys
5753 count:(NSUInteger)count {
5754 self = [super init];
5756 _dictionary = [[NSMutableDictionary alloc] init];
5757 if (count && values && keys) {
5758 for (NSUInteger i = 0; i < count; ++i) {
5759 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
5766 - (instancetype)initWithDictionary:(GPBUInt64FloatDictionary *)dictionary {
5767 self = [self initWithFloats:NULL forKeys:NULL count:0];
5770 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
5776 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
5777 return [self initWithFloats:NULL forKeys:NULL count:0];
5781 NSAssert(!_autocreator,
5782 @"%@: Autocreator must be cleared before release, autocreator: %@",
5783 [self class], _autocreator);
5784 [_dictionary release];
5788 - (instancetype)copyWithZone:(NSZone *)zone {
5789 return [[GPBUInt64FloatDictionary allocWithZone:zone] initWithDictionary:self];
5792 - (BOOL)isEqual:(id)other {
5793 if (self == other) {
5796 if (![other isKindOfClass:[GPBUInt64FloatDictionary class]]) {
5799 GPBUInt64FloatDictionary *otherDictionary = other;
5800 return [_dictionary isEqual:otherDictionary->_dictionary];
5803 - (NSUInteger)hash {
5804 return _dictionary.count;
5807 - (NSString *)description {
5808 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
5811 - (NSUInteger)count {
5812 return _dictionary.count;
5815 - (void)enumerateKeysAndFloatsUsingBlock:
5816 (void (NS_NOESCAPE ^)(uint64_t key, float value, BOOL *stop))block {
5818 NSDictionary *internal = _dictionary;
5819 NSEnumerator *keys = [internal keyEnumerator];
5821 while ((aKey = [keys nextObject])) {
5822 NSNumber *aValue = internal[aKey];
5823 block([aKey unsignedLongLongValue], [aValue floatValue], &stop);
5830 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
5831 NSDictionary *internal = _dictionary;
5832 NSUInteger count = internal.count;
5837 GPBDataType valueDataType = GPBGetFieldDataType(field);
5838 GPBDataType keyDataType = field.mapKeyDataType;
5840 NSEnumerator *keys = [internal keyEnumerator];
5842 while ((aKey = [keys nextObject])) {
5843 NSNumber *aValue = internal[aKey];
5844 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
5845 msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
5846 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
5848 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
5849 result += tagSize * count;
5853 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
5854 asField:(GPBFieldDescriptor *)field {
5855 GPBDataType valueDataType = GPBGetFieldDataType(field);
5856 GPBDataType keyDataType = field.mapKeyDataType;
5857 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
5858 NSDictionary *internal = _dictionary;
5859 NSEnumerator *keys = [internal keyEnumerator];
5861 while ((aKey = [keys nextObject])) {
5862 NSNumber *aValue = internal[aKey];
5863 [outputStream writeInt32NoTag:tag];
5864 // Write the size of the message.
5865 uint64_t unwrappedKey = [aKey unsignedLongLongValue];
5866 float unwrappedValue = [aValue floatValue];
5867 size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
5868 msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
5869 [outputStream writeInt32NoTag:(int32_t)msgSize];
5870 // Write the fields.
5871 WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
5872 WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
5876 - (void)setGPBGenericValue:(GPBGenericValue *)value
5877 forGPBGenericValueKey:(GPBGenericValue *)key {
5878 [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueUInt64)];
5881 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
5882 [self enumerateKeysAndFloatsUsingBlock:^(uint64_t key, float value, __unused BOOL *stop) {
5883 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
5887 - (BOOL)getFloat:(nullable float *)value forKey:(uint64_t)key {
5888 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
5889 if (wrapped && value) {
5890 *value = [wrapped floatValue];
5892 return (wrapped != NULL);
5895 - (void)addEntriesFromDictionary:(GPBUInt64FloatDictionary *)otherDictionary {
5896 if (otherDictionary) {
5897 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
5899 GPBAutocreatedDictionaryModified(_autocreator, self);
5904 - (void)setFloat:(float)value forKey:(uint64_t)key {
5905 [_dictionary setObject:@(value) forKey:@(key)];
5907 GPBAutocreatedDictionaryModified(_autocreator, self);
5911 - (void)removeFloatForKey:(uint64_t)aKey {
5912 [_dictionary removeObjectForKey:@(aKey)];
5916 [_dictionary removeAllObjects];
5921 #pragma mark - UInt64 -> Double
5923 @implementation GPBUInt64DoubleDictionary {
5925 NSMutableDictionary *_dictionary;
5928 - (instancetype)init {
5929 return [self initWithDoubles:NULL forKeys:NULL count:0];
5932 - (instancetype)initWithDoubles:(const double [])values
5933 forKeys:(const uint64_t [])keys
5934 count:(NSUInteger)count {
5935 self = [super init];
5937 _dictionary = [[NSMutableDictionary alloc] init];
5938 if (count && values && keys) {
5939 for (NSUInteger i = 0; i < count; ++i) {
5940 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
5947 - (instancetype)initWithDictionary:(GPBUInt64DoubleDictionary *)dictionary {
5948 self = [self initWithDoubles:NULL forKeys:NULL count:0];
5951 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
5957 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
5958 return [self initWithDoubles:NULL forKeys:NULL count:0];
5962 NSAssert(!_autocreator,
5963 @"%@: Autocreator must be cleared before release, autocreator: %@",
5964 [self class], _autocreator);
5965 [_dictionary release];
5969 - (instancetype)copyWithZone:(NSZone *)zone {
5970 return [[GPBUInt64DoubleDictionary allocWithZone:zone] initWithDictionary:self];
5973 - (BOOL)isEqual:(id)other {
5974 if (self == other) {
5977 if (![other isKindOfClass:[GPBUInt64DoubleDictionary class]]) {
5980 GPBUInt64DoubleDictionary *otherDictionary = other;
5981 return [_dictionary isEqual:otherDictionary->_dictionary];
5984 - (NSUInteger)hash {
5985 return _dictionary.count;
5988 - (NSString *)description {
5989 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
5992 - (NSUInteger)count {
5993 return _dictionary.count;
5996 - (void)enumerateKeysAndDoublesUsingBlock:
5997 (void (NS_NOESCAPE ^)(uint64_t key, double value, BOOL *stop))block {
5999 NSDictionary *internal = _dictionary;
6000 NSEnumerator *keys = [internal keyEnumerator];
6002 while ((aKey = [keys nextObject])) {
6003 NSNumber *aValue = internal[aKey];
6004 block([aKey unsignedLongLongValue], [aValue doubleValue], &stop);
6011 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
6012 NSDictionary *internal = _dictionary;
6013 NSUInteger count = internal.count;
6018 GPBDataType valueDataType = GPBGetFieldDataType(field);
6019 GPBDataType keyDataType = field.mapKeyDataType;
6021 NSEnumerator *keys = [internal keyEnumerator];
6023 while ((aKey = [keys nextObject])) {
6024 NSNumber *aValue = internal[aKey];
6025 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
6026 msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
6027 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
6029 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
6030 result += tagSize * count;
6034 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
6035 asField:(GPBFieldDescriptor *)field {
6036 GPBDataType valueDataType = GPBGetFieldDataType(field);
6037 GPBDataType keyDataType = field.mapKeyDataType;
6038 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
6039 NSDictionary *internal = _dictionary;
6040 NSEnumerator *keys = [internal keyEnumerator];
6042 while ((aKey = [keys nextObject])) {
6043 NSNumber *aValue = internal[aKey];
6044 [outputStream writeInt32NoTag:tag];
6045 // Write the size of the message.
6046 uint64_t unwrappedKey = [aKey unsignedLongLongValue];
6047 double unwrappedValue = [aValue doubleValue];
6048 size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
6049 msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
6050 [outputStream writeInt32NoTag:(int32_t)msgSize];
6051 // Write the fields.
6052 WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
6053 WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
6057 - (void)setGPBGenericValue:(GPBGenericValue *)value
6058 forGPBGenericValueKey:(GPBGenericValue *)key {
6059 [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueUInt64)];
6062 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
6063 [self enumerateKeysAndDoublesUsingBlock:^(uint64_t key, double value, __unused BOOL *stop) {
6064 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
6068 - (BOOL)getDouble:(nullable double *)value forKey:(uint64_t)key {
6069 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
6070 if (wrapped && value) {
6071 *value = [wrapped doubleValue];
6073 return (wrapped != NULL);
6076 - (void)addEntriesFromDictionary:(GPBUInt64DoubleDictionary *)otherDictionary {
6077 if (otherDictionary) {
6078 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
6080 GPBAutocreatedDictionaryModified(_autocreator, self);
6085 - (void)setDouble:(double)value forKey:(uint64_t)key {
6086 [_dictionary setObject:@(value) forKey:@(key)];
6088 GPBAutocreatedDictionaryModified(_autocreator, self);
6092 - (void)removeDoubleForKey:(uint64_t)aKey {
6093 [_dictionary removeObjectForKey:@(aKey)];
6097 [_dictionary removeAllObjects];
6102 #pragma mark - UInt64 -> Enum
6104 @implementation GPBUInt64EnumDictionary {
6106 NSMutableDictionary *_dictionary;
6107 GPBEnumValidationFunc _validationFunc;
6110 @synthesize validationFunc = _validationFunc;
6112 - (instancetype)init {
6113 return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
6116 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
6117 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
6120 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
6121 rawValues:(const int32_t [])rawValues
6122 forKeys:(const uint64_t [])keys
6123 count:(NSUInteger)count {
6124 self = [super init];
6126 _dictionary = [[NSMutableDictionary alloc] init];
6127 _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
6128 if (count && rawValues && keys) {
6129 for (NSUInteger i = 0; i < count; ++i) {
6130 [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])];
6137 - (instancetype)initWithDictionary:(GPBUInt64EnumDictionary *)dictionary {
6138 self = [self initWithValidationFunction:dictionary.validationFunc
6144 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
6150 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
6151 capacity:(__unused NSUInteger)numItems {
6152 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
6156 NSAssert(!_autocreator,
6157 @"%@: Autocreator must be cleared before release, autocreator: %@",
6158 [self class], _autocreator);
6159 [_dictionary release];
6163 - (instancetype)copyWithZone:(NSZone *)zone {
6164 return [[GPBUInt64EnumDictionary allocWithZone:zone] initWithDictionary:self];
6167 - (BOOL)isEqual:(id)other {
6168 if (self == other) {
6171 if (![other isKindOfClass:[GPBUInt64EnumDictionary class]]) {
6174 GPBUInt64EnumDictionary *otherDictionary = other;
6175 return [_dictionary isEqual:otherDictionary->_dictionary];
6178 - (NSUInteger)hash {
6179 return _dictionary.count;
6182 - (NSString *)description {
6183 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
6186 - (NSUInteger)count {
6187 return _dictionary.count;
6190 - (void)enumerateKeysAndRawValuesUsingBlock:
6191 (void (NS_NOESCAPE ^)(uint64_t key, int32_t value, BOOL *stop))block {
6193 NSDictionary *internal = _dictionary;
6194 NSEnumerator *keys = [internal keyEnumerator];
6196 while ((aKey = [keys nextObject])) {
6197 NSNumber *aValue = internal[aKey];
6198 block([aKey unsignedLongLongValue], [aValue intValue], &stop);
6205 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
6206 NSDictionary *internal = _dictionary;
6207 NSUInteger count = internal.count;
6212 GPBDataType valueDataType = GPBGetFieldDataType(field);
6213 GPBDataType keyDataType = field.mapKeyDataType;
6215 NSEnumerator *keys = [internal keyEnumerator];
6217 while ((aKey = [keys nextObject])) {
6218 NSNumber *aValue = internal[aKey];
6219 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
6220 msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
6221 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
6223 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
6224 result += tagSize * count;
6228 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
6229 asField:(GPBFieldDescriptor *)field {
6230 GPBDataType valueDataType = GPBGetFieldDataType(field);
6231 GPBDataType keyDataType = field.mapKeyDataType;
6232 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
6233 NSDictionary *internal = _dictionary;
6234 NSEnumerator *keys = [internal keyEnumerator];
6236 while ((aKey = [keys nextObject])) {
6237 NSNumber *aValue = internal[aKey];
6238 [outputStream writeInt32NoTag:tag];
6239 // Write the size of the message.
6240 uint64_t unwrappedKey = [aKey unsignedLongLongValue];
6241 int32_t unwrappedValue = [aValue intValue];
6242 size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
6243 msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
6244 [outputStream writeInt32NoTag:(int32_t)msgSize];
6245 // Write the fields.
6246 WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
6247 WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
6251 - (NSData *)serializedDataForUnknownValue:(int32_t)value
6252 forKey:(GPBGenericValue *)key
6253 keyDataType:(GPBDataType)keyDataType {
6254 size_t msgSize = ComputeDictUInt64FieldSize(key->valueUInt64, kMapKeyFieldNumber, keyDataType);
6255 msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
6256 NSMutableData *data = [NSMutableData dataWithLength:msgSize];
6257 GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
6258 WriteDictUInt64Field(outputStream, key->valueUInt64, kMapKeyFieldNumber, keyDataType);
6259 WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
6260 [outputStream flush];
6261 [outputStream release];
6264 - (void)setGPBGenericValue:(GPBGenericValue *)value
6265 forGPBGenericValueKey:(GPBGenericValue *)key {
6266 [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueUInt64)];
6269 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
6270 [self enumerateKeysAndRawValuesUsingBlock:^(uint64_t key, int32_t value, __unused BOOL *stop) {
6271 block([NSString stringWithFormat:@"%llu", key], @(value));
6275 - (BOOL)getEnum:(int32_t *)value forKey:(uint64_t)key {
6276 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
6277 if (wrapped && value) {
6278 int32_t result = [wrapped intValue];
6279 if (!_validationFunc(result)) {
6280 result = kGPBUnrecognizedEnumeratorValue;
6284 return (wrapped != NULL);
6287 - (BOOL)getRawValue:(int32_t *)rawValue forKey:(uint64_t)key {
6288 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
6289 if (wrapped && rawValue) {
6290 *rawValue = [wrapped intValue];
6292 return (wrapped != NULL);
6295 - (void)enumerateKeysAndEnumsUsingBlock:
6296 (void (NS_NOESCAPE ^)(uint64_t key, int32_t value, BOOL *stop))block {
6297 GPBEnumValidationFunc func = _validationFunc;
6299 NSEnumerator *keys = [_dictionary keyEnumerator];
6301 while ((aKey = [keys nextObject])) {
6302 NSNumber *aValue = _dictionary[aKey];
6303 int32_t unwrapped = [aValue intValue];
6304 if (!func(unwrapped)) {
6305 unwrapped = kGPBUnrecognizedEnumeratorValue;
6307 block([aKey unsignedLongLongValue], unwrapped, &stop);
6314 - (void)addRawEntriesFromDictionary:(GPBUInt64EnumDictionary *)otherDictionary {
6315 if (otherDictionary) {
6316 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
6318 GPBAutocreatedDictionaryModified(_autocreator, self);
6323 - (void)setRawValue:(int32_t)value forKey:(uint64_t)key {
6324 [_dictionary setObject:@(value) forKey:@(key)];
6326 GPBAutocreatedDictionaryModified(_autocreator, self);
6330 - (void)removeEnumForKey:(uint64_t)aKey {
6331 [_dictionary removeObjectForKey:@(aKey)];
6335 [_dictionary removeAllObjects];
6338 - (void)setEnum:(int32_t)value forKey:(uint64_t)key {
6339 if (!_validationFunc(value)) {
6340 [NSException raise:NSInvalidArgumentException
6341 format:@"GPBUInt64EnumDictionary: Attempt to set an unknown enum value (%d)",
6345 [_dictionary setObject:@(value) forKey:@(key)];
6347 GPBAutocreatedDictionaryModified(_autocreator, self);
6353 #pragma mark - UInt64 -> Object
6355 @implementation GPBUInt64ObjectDictionary {
6357 NSMutableDictionary *_dictionary;
6360 - (instancetype)init {
6361 return [self initWithObjects:NULL forKeys:NULL count:0];
6364 - (instancetype)initWithObjects:(const id [])objects
6365 forKeys:(const uint64_t [])keys
6366 count:(NSUInteger)count {
6367 self = [super init];
6369 _dictionary = [[NSMutableDictionary alloc] init];
6370 if (count && objects && keys) {
6371 for (NSUInteger i = 0; i < count; ++i) {
6373 [NSException raise:NSInvalidArgumentException
6374 format:@"Attempting to add nil object to a Dictionary"];
6376 [_dictionary setObject:objects[i] forKey:@(keys[i])];
6383 - (instancetype)initWithDictionary:(GPBUInt64ObjectDictionary *)dictionary {
6384 self = [self initWithObjects:NULL forKeys:NULL count:0];
6387 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
6393 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
6394 return [self initWithObjects:NULL forKeys:NULL count:0];
6398 NSAssert(!_autocreator,
6399 @"%@: Autocreator must be cleared before release, autocreator: %@",
6400 [self class], _autocreator);
6401 [_dictionary release];
6405 - (instancetype)copyWithZone:(NSZone *)zone {
6406 return [[GPBUInt64ObjectDictionary allocWithZone:zone] initWithDictionary:self];
6409 - (BOOL)isEqual:(id)other {
6410 if (self == other) {
6413 if (![other isKindOfClass:[GPBUInt64ObjectDictionary class]]) {
6416 GPBUInt64ObjectDictionary *otherDictionary = other;
6417 return [_dictionary isEqual:otherDictionary->_dictionary];
6420 - (NSUInteger)hash {
6421 return _dictionary.count;
6424 - (NSString *)description {
6425 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
6428 - (NSUInteger)count {
6429 return _dictionary.count;
6432 - (void)enumerateKeysAndObjectsUsingBlock:
6433 (void (NS_NOESCAPE ^)(uint64_t key, id object, BOOL *stop))block {
6435 NSDictionary *internal = _dictionary;
6436 NSEnumerator *keys = [internal keyEnumerator];
6438 while ((aKey = [keys nextObject])) {
6439 id aObject = internal[aKey];
6440 block([aKey unsignedLongLongValue], aObject, &stop);
6447 - (BOOL)isInitialized {
6448 for (GPBMessage *msg in [_dictionary objectEnumerator]) {
6449 if (!msg.initialized) {
6456 - (instancetype)deepCopyWithZone:(NSZone *)zone {
6457 GPBUInt64ObjectDictionary *newDict =
6458 [[GPBUInt64ObjectDictionary alloc] init];
6459 NSEnumerator *keys = [_dictionary keyEnumerator];
6461 NSMutableDictionary *internalDict = newDict->_dictionary;
6462 while ((aKey = [keys nextObject])) {
6463 GPBMessage *msg = _dictionary[aKey];
6464 GPBMessage *copiedMsg = [msg copyWithZone:zone];
6465 [internalDict setObject:copiedMsg forKey:aKey];
6466 [copiedMsg release];
6471 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
6472 NSDictionary *internal = _dictionary;
6473 NSUInteger count = internal.count;
6478 GPBDataType valueDataType = GPBGetFieldDataType(field);
6479 GPBDataType keyDataType = field.mapKeyDataType;
6481 NSEnumerator *keys = [internal keyEnumerator];
6483 while ((aKey = [keys nextObject])) {
6484 id aObject = internal[aKey];
6485 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
6486 msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
6487 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
6489 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
6490 result += tagSize * count;
6494 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
6495 asField:(GPBFieldDescriptor *)field {
6496 GPBDataType valueDataType = GPBGetFieldDataType(field);
6497 GPBDataType keyDataType = field.mapKeyDataType;
6498 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
6499 NSDictionary *internal = _dictionary;
6500 NSEnumerator *keys = [internal keyEnumerator];
6502 while ((aKey = [keys nextObject])) {
6503 id aObject = internal[aKey];
6504 [outputStream writeInt32NoTag:tag];
6505 // Write the size of the message.
6506 uint64_t unwrappedKey = [aKey unsignedLongLongValue];
6507 id unwrappedValue = aObject;
6508 size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
6509 msgSize += ComputeDictObjectFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
6510 [outputStream writeInt32NoTag:(int32_t)msgSize];
6511 // Write the fields.
6512 WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
6513 WriteDictObjectField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
6517 - (void)setGPBGenericValue:(GPBGenericValue *)value
6518 forGPBGenericValueKey:(GPBGenericValue *)key {
6519 [_dictionary setObject:value->valueString forKey:@(key->valueUInt64)];
6522 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
6523 [self enumerateKeysAndObjectsUsingBlock:^(uint64_t key, id object, __unused BOOL *stop) {
6524 block([NSString stringWithFormat:@"%llu", key], object);
6528 - (id)objectForKey:(uint64_t)key {
6529 id result = [_dictionary objectForKey:@(key)];
6533 - (void)addEntriesFromDictionary:(GPBUInt64ObjectDictionary *)otherDictionary {
6534 if (otherDictionary) {
6535 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
6537 GPBAutocreatedDictionaryModified(_autocreator, self);
6542 - (void)setObject:(id)object forKey:(uint64_t)key {
6544 [NSException raise:NSInvalidArgumentException
6545 format:@"Attempting to add nil object to a Dictionary"];
6547 [_dictionary setObject:object forKey:@(key)];
6549 GPBAutocreatedDictionaryModified(_autocreator, self);
6553 - (void)removeObjectForKey:(uint64_t)aKey {
6554 [_dictionary removeObjectForKey:@(aKey)];
6558 [_dictionary removeAllObjects];
6563 //%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(Int64, int64_t)
6564 // This block of code is generated, do not edit it directly.
6566 #pragma mark - Int64 -> UInt32
6568 @implementation GPBInt64UInt32Dictionary {
6570 NSMutableDictionary *_dictionary;
6573 - (instancetype)init {
6574 return [self initWithUInt32s:NULL forKeys:NULL count:0];
6577 - (instancetype)initWithUInt32s:(const uint32_t [])values
6578 forKeys:(const int64_t [])keys
6579 count:(NSUInteger)count {
6580 self = [super init];
6582 _dictionary = [[NSMutableDictionary alloc] init];
6583 if (count && values && keys) {
6584 for (NSUInteger i = 0; i < count; ++i) {
6585 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
6592 - (instancetype)initWithDictionary:(GPBInt64UInt32Dictionary *)dictionary {
6593 self = [self initWithUInt32s:NULL forKeys:NULL count:0];
6596 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
6602 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
6603 return [self initWithUInt32s:NULL forKeys:NULL count:0];
6607 NSAssert(!_autocreator,
6608 @"%@: Autocreator must be cleared before release, autocreator: %@",
6609 [self class], _autocreator);
6610 [_dictionary release];
6614 - (instancetype)copyWithZone:(NSZone *)zone {
6615 return [[GPBInt64UInt32Dictionary allocWithZone:zone] initWithDictionary:self];
6618 - (BOOL)isEqual:(id)other {
6619 if (self == other) {
6622 if (![other isKindOfClass:[GPBInt64UInt32Dictionary class]]) {
6625 GPBInt64UInt32Dictionary *otherDictionary = other;
6626 return [_dictionary isEqual:otherDictionary->_dictionary];
6629 - (NSUInteger)hash {
6630 return _dictionary.count;
6633 - (NSString *)description {
6634 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
6637 - (NSUInteger)count {
6638 return _dictionary.count;
6641 - (void)enumerateKeysAndUInt32sUsingBlock:
6642 (void (NS_NOESCAPE ^)(int64_t key, uint32_t value, BOOL *stop))block {
6644 NSDictionary *internal = _dictionary;
6645 NSEnumerator *keys = [internal keyEnumerator];
6647 while ((aKey = [keys nextObject])) {
6648 NSNumber *aValue = internal[aKey];
6649 block([aKey longLongValue], [aValue unsignedIntValue], &stop);
6656 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
6657 NSDictionary *internal = _dictionary;
6658 NSUInteger count = internal.count;
6663 GPBDataType valueDataType = GPBGetFieldDataType(field);
6664 GPBDataType keyDataType = field.mapKeyDataType;
6666 NSEnumerator *keys = [internal keyEnumerator];
6668 while ((aKey = [keys nextObject])) {
6669 NSNumber *aValue = internal[aKey];
6670 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
6671 msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
6672 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
6674 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
6675 result += tagSize * count;
6679 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
6680 asField:(GPBFieldDescriptor *)field {
6681 GPBDataType valueDataType = GPBGetFieldDataType(field);
6682 GPBDataType keyDataType = field.mapKeyDataType;
6683 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
6684 NSDictionary *internal = _dictionary;
6685 NSEnumerator *keys = [internal keyEnumerator];
6687 while ((aKey = [keys nextObject])) {
6688 NSNumber *aValue = internal[aKey];
6689 [outputStream writeInt32NoTag:tag];
6690 // Write the size of the message.
6691 int64_t unwrappedKey = [aKey longLongValue];
6692 uint32_t unwrappedValue = [aValue unsignedIntValue];
6693 size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
6694 msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
6695 [outputStream writeInt32NoTag:(int32_t)msgSize];
6696 // Write the fields.
6697 WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
6698 WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
6702 - (void)setGPBGenericValue:(GPBGenericValue *)value
6703 forGPBGenericValueKey:(GPBGenericValue *)key {
6704 [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueInt64)];
6707 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
6708 [self enumerateKeysAndUInt32sUsingBlock:^(int64_t key, uint32_t value, __unused BOOL *stop) {
6709 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%u", value]);
6713 - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(int64_t)key {
6714 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
6715 if (wrapped && value) {
6716 *value = [wrapped unsignedIntValue];
6718 return (wrapped != NULL);
6721 - (void)addEntriesFromDictionary:(GPBInt64UInt32Dictionary *)otherDictionary {
6722 if (otherDictionary) {
6723 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
6725 GPBAutocreatedDictionaryModified(_autocreator, self);
6730 - (void)setUInt32:(uint32_t)value forKey:(int64_t)key {
6731 [_dictionary setObject:@(value) forKey:@(key)];
6733 GPBAutocreatedDictionaryModified(_autocreator, self);
6737 - (void)removeUInt32ForKey:(int64_t)aKey {
6738 [_dictionary removeObjectForKey:@(aKey)];
6742 [_dictionary removeAllObjects];
6747 #pragma mark - Int64 -> Int32
6749 @implementation GPBInt64Int32Dictionary {
6751 NSMutableDictionary *_dictionary;
6754 - (instancetype)init {
6755 return [self initWithInt32s:NULL forKeys:NULL count:0];
6758 - (instancetype)initWithInt32s:(const int32_t [])values
6759 forKeys:(const int64_t [])keys
6760 count:(NSUInteger)count {
6761 self = [super init];
6763 _dictionary = [[NSMutableDictionary alloc] init];
6764 if (count && values && keys) {
6765 for (NSUInteger i = 0; i < count; ++i) {
6766 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
6773 - (instancetype)initWithDictionary:(GPBInt64Int32Dictionary *)dictionary {
6774 self = [self initWithInt32s:NULL forKeys:NULL count:0];
6777 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
6783 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
6784 return [self initWithInt32s:NULL forKeys:NULL count:0];
6788 NSAssert(!_autocreator,
6789 @"%@: Autocreator must be cleared before release, autocreator: %@",
6790 [self class], _autocreator);
6791 [_dictionary release];
6795 - (instancetype)copyWithZone:(NSZone *)zone {
6796 return [[GPBInt64Int32Dictionary allocWithZone:zone] initWithDictionary:self];
6799 - (BOOL)isEqual:(id)other {
6800 if (self == other) {
6803 if (![other isKindOfClass:[GPBInt64Int32Dictionary class]]) {
6806 GPBInt64Int32Dictionary *otherDictionary = other;
6807 return [_dictionary isEqual:otherDictionary->_dictionary];
6810 - (NSUInteger)hash {
6811 return _dictionary.count;
6814 - (NSString *)description {
6815 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
6818 - (NSUInteger)count {
6819 return _dictionary.count;
6822 - (void)enumerateKeysAndInt32sUsingBlock:
6823 (void (NS_NOESCAPE ^)(int64_t key, int32_t value, BOOL *stop))block {
6825 NSDictionary *internal = _dictionary;
6826 NSEnumerator *keys = [internal keyEnumerator];
6828 while ((aKey = [keys nextObject])) {
6829 NSNumber *aValue = internal[aKey];
6830 block([aKey longLongValue], [aValue intValue], &stop);
6837 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
6838 NSDictionary *internal = _dictionary;
6839 NSUInteger count = internal.count;
6844 GPBDataType valueDataType = GPBGetFieldDataType(field);
6845 GPBDataType keyDataType = field.mapKeyDataType;
6847 NSEnumerator *keys = [internal keyEnumerator];
6849 while ((aKey = [keys nextObject])) {
6850 NSNumber *aValue = internal[aKey];
6851 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
6852 msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
6853 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
6855 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
6856 result += tagSize * count;
6860 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
6861 asField:(GPBFieldDescriptor *)field {
6862 GPBDataType valueDataType = GPBGetFieldDataType(field);
6863 GPBDataType keyDataType = field.mapKeyDataType;
6864 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
6865 NSDictionary *internal = _dictionary;
6866 NSEnumerator *keys = [internal keyEnumerator];
6868 while ((aKey = [keys nextObject])) {
6869 NSNumber *aValue = internal[aKey];
6870 [outputStream writeInt32NoTag:tag];
6871 // Write the size of the message.
6872 int64_t unwrappedKey = [aKey longLongValue];
6873 int32_t unwrappedValue = [aValue intValue];
6874 size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
6875 msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
6876 [outputStream writeInt32NoTag:(int32_t)msgSize];
6877 // Write the fields.
6878 WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
6879 WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
6883 - (void)setGPBGenericValue:(GPBGenericValue *)value
6884 forGPBGenericValueKey:(GPBGenericValue *)key {
6885 [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueInt64)];
6888 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
6889 [self enumerateKeysAndInt32sUsingBlock:^(int64_t key, int32_t value, __unused BOOL *stop) {
6890 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%d", value]);
6894 - (BOOL)getInt32:(nullable int32_t *)value forKey:(int64_t)key {
6895 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
6896 if (wrapped && value) {
6897 *value = [wrapped intValue];
6899 return (wrapped != NULL);
6902 - (void)addEntriesFromDictionary:(GPBInt64Int32Dictionary *)otherDictionary {
6903 if (otherDictionary) {
6904 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
6906 GPBAutocreatedDictionaryModified(_autocreator, self);
6911 - (void)setInt32:(int32_t)value forKey:(int64_t)key {
6912 [_dictionary setObject:@(value) forKey:@(key)];
6914 GPBAutocreatedDictionaryModified(_autocreator, self);
6918 - (void)removeInt32ForKey:(int64_t)aKey {
6919 [_dictionary removeObjectForKey:@(aKey)];
6923 [_dictionary removeAllObjects];
6928 #pragma mark - Int64 -> UInt64
6930 @implementation GPBInt64UInt64Dictionary {
6932 NSMutableDictionary *_dictionary;
6935 - (instancetype)init {
6936 return [self initWithUInt64s:NULL forKeys:NULL count:0];
6939 - (instancetype)initWithUInt64s:(const uint64_t [])values
6940 forKeys:(const int64_t [])keys
6941 count:(NSUInteger)count {
6942 self = [super init];
6944 _dictionary = [[NSMutableDictionary alloc] init];
6945 if (count && values && keys) {
6946 for (NSUInteger i = 0; i < count; ++i) {
6947 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
6954 - (instancetype)initWithDictionary:(GPBInt64UInt64Dictionary *)dictionary {
6955 self = [self initWithUInt64s:NULL forKeys:NULL count:0];
6958 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
6964 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
6965 return [self initWithUInt64s:NULL forKeys:NULL count:0];
6969 NSAssert(!_autocreator,
6970 @"%@: Autocreator must be cleared before release, autocreator: %@",
6971 [self class], _autocreator);
6972 [_dictionary release];
6976 - (instancetype)copyWithZone:(NSZone *)zone {
6977 return [[GPBInt64UInt64Dictionary allocWithZone:zone] initWithDictionary:self];
6980 - (BOOL)isEqual:(id)other {
6981 if (self == other) {
6984 if (![other isKindOfClass:[GPBInt64UInt64Dictionary class]]) {
6987 GPBInt64UInt64Dictionary *otherDictionary = other;
6988 return [_dictionary isEqual:otherDictionary->_dictionary];
6991 - (NSUInteger)hash {
6992 return _dictionary.count;
6995 - (NSString *)description {
6996 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
6999 - (NSUInteger)count {
7000 return _dictionary.count;
7003 - (void)enumerateKeysAndUInt64sUsingBlock:
7004 (void (NS_NOESCAPE ^)(int64_t key, uint64_t value, BOOL *stop))block {
7006 NSDictionary *internal = _dictionary;
7007 NSEnumerator *keys = [internal keyEnumerator];
7009 while ((aKey = [keys nextObject])) {
7010 NSNumber *aValue = internal[aKey];
7011 block([aKey longLongValue], [aValue unsignedLongLongValue], &stop);
7018 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
7019 NSDictionary *internal = _dictionary;
7020 NSUInteger count = internal.count;
7025 GPBDataType valueDataType = GPBGetFieldDataType(field);
7026 GPBDataType keyDataType = field.mapKeyDataType;
7028 NSEnumerator *keys = [internal keyEnumerator];
7030 while ((aKey = [keys nextObject])) {
7031 NSNumber *aValue = internal[aKey];
7032 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
7033 msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
7034 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
7036 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
7037 result += tagSize * count;
7041 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
7042 asField:(GPBFieldDescriptor *)field {
7043 GPBDataType valueDataType = GPBGetFieldDataType(field);
7044 GPBDataType keyDataType = field.mapKeyDataType;
7045 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
7046 NSDictionary *internal = _dictionary;
7047 NSEnumerator *keys = [internal keyEnumerator];
7049 while ((aKey = [keys nextObject])) {
7050 NSNumber *aValue = internal[aKey];
7051 [outputStream writeInt32NoTag:tag];
7052 // Write the size of the message.
7053 int64_t unwrappedKey = [aKey longLongValue];
7054 uint64_t unwrappedValue = [aValue unsignedLongLongValue];
7055 size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
7056 msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
7057 [outputStream writeInt32NoTag:(int32_t)msgSize];
7058 // Write the fields.
7059 WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
7060 WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
7064 - (void)setGPBGenericValue:(GPBGenericValue *)value
7065 forGPBGenericValueKey:(GPBGenericValue *)key {
7066 [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueInt64)];
7069 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
7070 [self enumerateKeysAndUInt64sUsingBlock:^(int64_t key, uint64_t value, __unused BOOL *stop) {
7071 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%llu", value]);
7075 - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(int64_t)key {
7076 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
7077 if (wrapped && value) {
7078 *value = [wrapped unsignedLongLongValue];
7080 return (wrapped != NULL);
7083 - (void)addEntriesFromDictionary:(GPBInt64UInt64Dictionary *)otherDictionary {
7084 if (otherDictionary) {
7085 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
7087 GPBAutocreatedDictionaryModified(_autocreator, self);
7092 - (void)setUInt64:(uint64_t)value forKey:(int64_t)key {
7093 [_dictionary setObject:@(value) forKey:@(key)];
7095 GPBAutocreatedDictionaryModified(_autocreator, self);
7099 - (void)removeUInt64ForKey:(int64_t)aKey {
7100 [_dictionary removeObjectForKey:@(aKey)];
7104 [_dictionary removeAllObjects];
7109 #pragma mark - Int64 -> Int64
7111 @implementation GPBInt64Int64Dictionary {
7113 NSMutableDictionary *_dictionary;
7116 - (instancetype)init {
7117 return [self initWithInt64s:NULL forKeys:NULL count:0];
7120 - (instancetype)initWithInt64s:(const int64_t [])values
7121 forKeys:(const int64_t [])keys
7122 count:(NSUInteger)count {
7123 self = [super init];
7125 _dictionary = [[NSMutableDictionary alloc] init];
7126 if (count && values && keys) {
7127 for (NSUInteger i = 0; i < count; ++i) {
7128 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
7135 - (instancetype)initWithDictionary:(GPBInt64Int64Dictionary *)dictionary {
7136 self = [self initWithInt64s:NULL forKeys:NULL count:0];
7139 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
7145 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
7146 return [self initWithInt64s:NULL forKeys:NULL count:0];
7150 NSAssert(!_autocreator,
7151 @"%@: Autocreator must be cleared before release, autocreator: %@",
7152 [self class], _autocreator);
7153 [_dictionary release];
7157 - (instancetype)copyWithZone:(NSZone *)zone {
7158 return [[GPBInt64Int64Dictionary allocWithZone:zone] initWithDictionary:self];
7161 - (BOOL)isEqual:(id)other {
7162 if (self == other) {
7165 if (![other isKindOfClass:[GPBInt64Int64Dictionary class]]) {
7168 GPBInt64Int64Dictionary *otherDictionary = other;
7169 return [_dictionary isEqual:otherDictionary->_dictionary];
7172 - (NSUInteger)hash {
7173 return _dictionary.count;
7176 - (NSString *)description {
7177 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
7180 - (NSUInteger)count {
7181 return _dictionary.count;
7184 - (void)enumerateKeysAndInt64sUsingBlock:
7185 (void (NS_NOESCAPE ^)(int64_t key, int64_t value, BOOL *stop))block {
7187 NSDictionary *internal = _dictionary;
7188 NSEnumerator *keys = [internal keyEnumerator];
7190 while ((aKey = [keys nextObject])) {
7191 NSNumber *aValue = internal[aKey];
7192 block([aKey longLongValue], [aValue longLongValue], &stop);
7199 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
7200 NSDictionary *internal = _dictionary;
7201 NSUInteger count = internal.count;
7206 GPBDataType valueDataType = GPBGetFieldDataType(field);
7207 GPBDataType keyDataType = field.mapKeyDataType;
7209 NSEnumerator *keys = [internal keyEnumerator];
7211 while ((aKey = [keys nextObject])) {
7212 NSNumber *aValue = internal[aKey];
7213 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
7214 msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
7215 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
7217 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
7218 result += tagSize * count;
7222 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
7223 asField:(GPBFieldDescriptor *)field {
7224 GPBDataType valueDataType = GPBGetFieldDataType(field);
7225 GPBDataType keyDataType = field.mapKeyDataType;
7226 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
7227 NSDictionary *internal = _dictionary;
7228 NSEnumerator *keys = [internal keyEnumerator];
7230 while ((aKey = [keys nextObject])) {
7231 NSNumber *aValue = internal[aKey];
7232 [outputStream writeInt32NoTag:tag];
7233 // Write the size of the message.
7234 int64_t unwrappedKey = [aKey longLongValue];
7235 int64_t unwrappedValue = [aValue longLongValue];
7236 size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
7237 msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
7238 [outputStream writeInt32NoTag:(int32_t)msgSize];
7239 // Write the fields.
7240 WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
7241 WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
7245 - (void)setGPBGenericValue:(GPBGenericValue *)value
7246 forGPBGenericValueKey:(GPBGenericValue *)key {
7247 [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueInt64)];
7250 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
7251 [self enumerateKeysAndInt64sUsingBlock:^(int64_t key, int64_t value, __unused BOOL *stop) {
7252 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%lld", value]);
7256 - (BOOL)getInt64:(nullable int64_t *)value forKey:(int64_t)key {
7257 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
7258 if (wrapped && value) {
7259 *value = [wrapped longLongValue];
7261 return (wrapped != NULL);
7264 - (void)addEntriesFromDictionary:(GPBInt64Int64Dictionary *)otherDictionary {
7265 if (otherDictionary) {
7266 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
7268 GPBAutocreatedDictionaryModified(_autocreator, self);
7273 - (void)setInt64:(int64_t)value forKey:(int64_t)key {
7274 [_dictionary setObject:@(value) forKey:@(key)];
7276 GPBAutocreatedDictionaryModified(_autocreator, self);
7280 - (void)removeInt64ForKey:(int64_t)aKey {
7281 [_dictionary removeObjectForKey:@(aKey)];
7285 [_dictionary removeAllObjects];
7290 #pragma mark - Int64 -> Bool
7292 @implementation GPBInt64BoolDictionary {
7294 NSMutableDictionary *_dictionary;
7297 - (instancetype)init {
7298 return [self initWithBools:NULL forKeys:NULL count:0];
7301 - (instancetype)initWithBools:(const BOOL [])values
7302 forKeys:(const int64_t [])keys
7303 count:(NSUInteger)count {
7304 self = [super init];
7306 _dictionary = [[NSMutableDictionary alloc] init];
7307 if (count && values && keys) {
7308 for (NSUInteger i = 0; i < count; ++i) {
7309 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
7316 - (instancetype)initWithDictionary:(GPBInt64BoolDictionary *)dictionary {
7317 self = [self initWithBools:NULL forKeys:NULL count:0];
7320 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
7326 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
7327 return [self initWithBools:NULL forKeys:NULL count:0];
7331 NSAssert(!_autocreator,
7332 @"%@: Autocreator must be cleared before release, autocreator: %@",
7333 [self class], _autocreator);
7334 [_dictionary release];
7338 - (instancetype)copyWithZone:(NSZone *)zone {
7339 return [[GPBInt64BoolDictionary allocWithZone:zone] initWithDictionary:self];
7342 - (BOOL)isEqual:(id)other {
7343 if (self == other) {
7346 if (![other isKindOfClass:[GPBInt64BoolDictionary class]]) {
7349 GPBInt64BoolDictionary *otherDictionary = other;
7350 return [_dictionary isEqual:otherDictionary->_dictionary];
7353 - (NSUInteger)hash {
7354 return _dictionary.count;
7357 - (NSString *)description {
7358 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
7361 - (NSUInteger)count {
7362 return _dictionary.count;
7365 - (void)enumerateKeysAndBoolsUsingBlock:
7366 (void (NS_NOESCAPE ^)(int64_t key, BOOL value, BOOL *stop))block {
7368 NSDictionary *internal = _dictionary;
7369 NSEnumerator *keys = [internal keyEnumerator];
7371 while ((aKey = [keys nextObject])) {
7372 NSNumber *aValue = internal[aKey];
7373 block([aKey longLongValue], [aValue boolValue], &stop);
7380 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
7381 NSDictionary *internal = _dictionary;
7382 NSUInteger count = internal.count;
7387 GPBDataType valueDataType = GPBGetFieldDataType(field);
7388 GPBDataType keyDataType = field.mapKeyDataType;
7390 NSEnumerator *keys = [internal keyEnumerator];
7392 while ((aKey = [keys nextObject])) {
7393 NSNumber *aValue = internal[aKey];
7394 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
7395 msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
7396 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
7398 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
7399 result += tagSize * count;
7403 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
7404 asField:(GPBFieldDescriptor *)field {
7405 GPBDataType valueDataType = GPBGetFieldDataType(field);
7406 GPBDataType keyDataType = field.mapKeyDataType;
7407 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
7408 NSDictionary *internal = _dictionary;
7409 NSEnumerator *keys = [internal keyEnumerator];
7411 while ((aKey = [keys nextObject])) {
7412 NSNumber *aValue = internal[aKey];
7413 [outputStream writeInt32NoTag:tag];
7414 // Write the size of the message.
7415 int64_t unwrappedKey = [aKey longLongValue];
7416 BOOL unwrappedValue = [aValue boolValue];
7417 size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
7418 msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
7419 [outputStream writeInt32NoTag:(int32_t)msgSize];
7420 // Write the fields.
7421 WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
7422 WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
7426 - (void)setGPBGenericValue:(GPBGenericValue *)value
7427 forGPBGenericValueKey:(GPBGenericValue *)key {
7428 [_dictionary setObject:@(value->valueBool) forKey:@(key->valueInt64)];
7431 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
7432 [self enumerateKeysAndBoolsUsingBlock:^(int64_t key, BOOL value, __unused BOOL *stop) {
7433 block([NSString stringWithFormat:@"%lld", key], (value ? @"true" : @"false"));
7437 - (BOOL)getBool:(nullable BOOL *)value forKey:(int64_t)key {
7438 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
7439 if (wrapped && value) {
7440 *value = [wrapped boolValue];
7442 return (wrapped != NULL);
7445 - (void)addEntriesFromDictionary:(GPBInt64BoolDictionary *)otherDictionary {
7446 if (otherDictionary) {
7447 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
7449 GPBAutocreatedDictionaryModified(_autocreator, self);
7454 - (void)setBool:(BOOL)value forKey:(int64_t)key {
7455 [_dictionary setObject:@(value) forKey:@(key)];
7457 GPBAutocreatedDictionaryModified(_autocreator, self);
7461 - (void)removeBoolForKey:(int64_t)aKey {
7462 [_dictionary removeObjectForKey:@(aKey)];
7466 [_dictionary removeAllObjects];
7471 #pragma mark - Int64 -> Float
7473 @implementation GPBInt64FloatDictionary {
7475 NSMutableDictionary *_dictionary;
7478 - (instancetype)init {
7479 return [self initWithFloats:NULL forKeys:NULL count:0];
7482 - (instancetype)initWithFloats:(const float [])values
7483 forKeys:(const int64_t [])keys
7484 count:(NSUInteger)count {
7485 self = [super init];
7487 _dictionary = [[NSMutableDictionary alloc] init];
7488 if (count && values && keys) {
7489 for (NSUInteger i = 0; i < count; ++i) {
7490 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
7497 - (instancetype)initWithDictionary:(GPBInt64FloatDictionary *)dictionary {
7498 self = [self initWithFloats:NULL forKeys:NULL count:0];
7501 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
7507 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
7508 return [self initWithFloats:NULL forKeys:NULL count:0];
7512 NSAssert(!_autocreator,
7513 @"%@: Autocreator must be cleared before release, autocreator: %@",
7514 [self class], _autocreator);
7515 [_dictionary release];
7519 - (instancetype)copyWithZone:(NSZone *)zone {
7520 return [[GPBInt64FloatDictionary allocWithZone:zone] initWithDictionary:self];
7523 - (BOOL)isEqual:(id)other {
7524 if (self == other) {
7527 if (![other isKindOfClass:[GPBInt64FloatDictionary class]]) {
7530 GPBInt64FloatDictionary *otherDictionary = other;
7531 return [_dictionary isEqual:otherDictionary->_dictionary];
7534 - (NSUInteger)hash {
7535 return _dictionary.count;
7538 - (NSString *)description {
7539 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
7542 - (NSUInteger)count {
7543 return _dictionary.count;
7546 - (void)enumerateKeysAndFloatsUsingBlock:
7547 (void (NS_NOESCAPE ^)(int64_t key, float value, BOOL *stop))block {
7549 NSDictionary *internal = _dictionary;
7550 NSEnumerator *keys = [internal keyEnumerator];
7552 while ((aKey = [keys nextObject])) {
7553 NSNumber *aValue = internal[aKey];
7554 block([aKey longLongValue], [aValue floatValue], &stop);
7561 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
7562 NSDictionary *internal = _dictionary;
7563 NSUInteger count = internal.count;
7568 GPBDataType valueDataType = GPBGetFieldDataType(field);
7569 GPBDataType keyDataType = field.mapKeyDataType;
7571 NSEnumerator *keys = [internal keyEnumerator];
7573 while ((aKey = [keys nextObject])) {
7574 NSNumber *aValue = internal[aKey];
7575 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
7576 msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
7577 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
7579 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
7580 result += tagSize * count;
7584 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
7585 asField:(GPBFieldDescriptor *)field {
7586 GPBDataType valueDataType = GPBGetFieldDataType(field);
7587 GPBDataType keyDataType = field.mapKeyDataType;
7588 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
7589 NSDictionary *internal = _dictionary;
7590 NSEnumerator *keys = [internal keyEnumerator];
7592 while ((aKey = [keys nextObject])) {
7593 NSNumber *aValue = internal[aKey];
7594 [outputStream writeInt32NoTag:tag];
7595 // Write the size of the message.
7596 int64_t unwrappedKey = [aKey longLongValue];
7597 float unwrappedValue = [aValue floatValue];
7598 size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
7599 msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
7600 [outputStream writeInt32NoTag:(int32_t)msgSize];
7601 // Write the fields.
7602 WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
7603 WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
7607 - (void)setGPBGenericValue:(GPBGenericValue *)value
7608 forGPBGenericValueKey:(GPBGenericValue *)key {
7609 [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueInt64)];
7612 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
7613 [self enumerateKeysAndFloatsUsingBlock:^(int64_t key, float value, __unused BOOL *stop) {
7614 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
7618 - (BOOL)getFloat:(nullable float *)value forKey:(int64_t)key {
7619 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
7620 if (wrapped && value) {
7621 *value = [wrapped floatValue];
7623 return (wrapped != NULL);
7626 - (void)addEntriesFromDictionary:(GPBInt64FloatDictionary *)otherDictionary {
7627 if (otherDictionary) {
7628 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
7630 GPBAutocreatedDictionaryModified(_autocreator, self);
7635 - (void)setFloat:(float)value forKey:(int64_t)key {
7636 [_dictionary setObject:@(value) forKey:@(key)];
7638 GPBAutocreatedDictionaryModified(_autocreator, self);
7642 - (void)removeFloatForKey:(int64_t)aKey {
7643 [_dictionary removeObjectForKey:@(aKey)];
7647 [_dictionary removeAllObjects];
7652 #pragma mark - Int64 -> Double
7654 @implementation GPBInt64DoubleDictionary {
7656 NSMutableDictionary *_dictionary;
7659 - (instancetype)init {
7660 return [self initWithDoubles:NULL forKeys:NULL count:0];
7663 - (instancetype)initWithDoubles:(const double [])values
7664 forKeys:(const int64_t [])keys
7665 count:(NSUInteger)count {
7666 self = [super init];
7668 _dictionary = [[NSMutableDictionary alloc] init];
7669 if (count && values && keys) {
7670 for (NSUInteger i = 0; i < count; ++i) {
7671 [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
7678 - (instancetype)initWithDictionary:(GPBInt64DoubleDictionary *)dictionary {
7679 self = [self initWithDoubles:NULL forKeys:NULL count:0];
7682 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
7688 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
7689 return [self initWithDoubles:NULL forKeys:NULL count:0];
7693 NSAssert(!_autocreator,
7694 @"%@: Autocreator must be cleared before release, autocreator: %@",
7695 [self class], _autocreator);
7696 [_dictionary release];
7700 - (instancetype)copyWithZone:(NSZone *)zone {
7701 return [[GPBInt64DoubleDictionary allocWithZone:zone] initWithDictionary:self];
7704 - (BOOL)isEqual:(id)other {
7705 if (self == other) {
7708 if (![other isKindOfClass:[GPBInt64DoubleDictionary class]]) {
7711 GPBInt64DoubleDictionary *otherDictionary = other;
7712 return [_dictionary isEqual:otherDictionary->_dictionary];
7715 - (NSUInteger)hash {
7716 return _dictionary.count;
7719 - (NSString *)description {
7720 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
7723 - (NSUInteger)count {
7724 return _dictionary.count;
7727 - (void)enumerateKeysAndDoublesUsingBlock:
7728 (void (NS_NOESCAPE ^)(int64_t key, double value, BOOL *stop))block {
7730 NSDictionary *internal = _dictionary;
7731 NSEnumerator *keys = [internal keyEnumerator];
7733 while ((aKey = [keys nextObject])) {
7734 NSNumber *aValue = internal[aKey];
7735 block([aKey longLongValue], [aValue doubleValue], &stop);
7742 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
7743 NSDictionary *internal = _dictionary;
7744 NSUInteger count = internal.count;
7749 GPBDataType valueDataType = GPBGetFieldDataType(field);
7750 GPBDataType keyDataType = field.mapKeyDataType;
7752 NSEnumerator *keys = [internal keyEnumerator];
7754 while ((aKey = [keys nextObject])) {
7755 NSNumber *aValue = internal[aKey];
7756 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
7757 msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
7758 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
7760 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
7761 result += tagSize * count;
7765 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
7766 asField:(GPBFieldDescriptor *)field {
7767 GPBDataType valueDataType = GPBGetFieldDataType(field);
7768 GPBDataType keyDataType = field.mapKeyDataType;
7769 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
7770 NSDictionary *internal = _dictionary;
7771 NSEnumerator *keys = [internal keyEnumerator];
7773 while ((aKey = [keys nextObject])) {
7774 NSNumber *aValue = internal[aKey];
7775 [outputStream writeInt32NoTag:tag];
7776 // Write the size of the message.
7777 int64_t unwrappedKey = [aKey longLongValue];
7778 double unwrappedValue = [aValue doubleValue];
7779 size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
7780 msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
7781 [outputStream writeInt32NoTag:(int32_t)msgSize];
7782 // Write the fields.
7783 WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
7784 WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
7788 - (void)setGPBGenericValue:(GPBGenericValue *)value
7789 forGPBGenericValueKey:(GPBGenericValue *)key {
7790 [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueInt64)];
7793 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
7794 [self enumerateKeysAndDoublesUsingBlock:^(int64_t key, double value, __unused BOOL *stop) {
7795 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
7799 - (BOOL)getDouble:(nullable double *)value forKey:(int64_t)key {
7800 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
7801 if (wrapped && value) {
7802 *value = [wrapped doubleValue];
7804 return (wrapped != NULL);
7807 - (void)addEntriesFromDictionary:(GPBInt64DoubleDictionary *)otherDictionary {
7808 if (otherDictionary) {
7809 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
7811 GPBAutocreatedDictionaryModified(_autocreator, self);
7816 - (void)setDouble:(double)value forKey:(int64_t)key {
7817 [_dictionary setObject:@(value) forKey:@(key)];
7819 GPBAutocreatedDictionaryModified(_autocreator, self);
7823 - (void)removeDoubleForKey:(int64_t)aKey {
7824 [_dictionary removeObjectForKey:@(aKey)];
7828 [_dictionary removeAllObjects];
7833 #pragma mark - Int64 -> Enum
7835 @implementation GPBInt64EnumDictionary {
7837 NSMutableDictionary *_dictionary;
7838 GPBEnumValidationFunc _validationFunc;
7841 @synthesize validationFunc = _validationFunc;
7843 - (instancetype)init {
7844 return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
7847 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
7848 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
7851 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
7852 rawValues:(const int32_t [])rawValues
7853 forKeys:(const int64_t [])keys
7854 count:(NSUInteger)count {
7855 self = [super init];
7857 _dictionary = [[NSMutableDictionary alloc] init];
7858 _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
7859 if (count && rawValues && keys) {
7860 for (NSUInteger i = 0; i < count; ++i) {
7861 [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])];
7868 - (instancetype)initWithDictionary:(GPBInt64EnumDictionary *)dictionary {
7869 self = [self initWithValidationFunction:dictionary.validationFunc
7875 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
7881 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
7882 capacity:(__unused NSUInteger)numItems {
7883 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
7887 NSAssert(!_autocreator,
7888 @"%@: Autocreator must be cleared before release, autocreator: %@",
7889 [self class], _autocreator);
7890 [_dictionary release];
7894 - (instancetype)copyWithZone:(NSZone *)zone {
7895 return [[GPBInt64EnumDictionary allocWithZone:zone] initWithDictionary:self];
7898 - (BOOL)isEqual:(id)other {
7899 if (self == other) {
7902 if (![other isKindOfClass:[GPBInt64EnumDictionary class]]) {
7905 GPBInt64EnumDictionary *otherDictionary = other;
7906 return [_dictionary isEqual:otherDictionary->_dictionary];
7909 - (NSUInteger)hash {
7910 return _dictionary.count;
7913 - (NSString *)description {
7914 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
7917 - (NSUInteger)count {
7918 return _dictionary.count;
7921 - (void)enumerateKeysAndRawValuesUsingBlock:
7922 (void (NS_NOESCAPE ^)(int64_t key, int32_t value, BOOL *stop))block {
7924 NSDictionary *internal = _dictionary;
7925 NSEnumerator *keys = [internal keyEnumerator];
7927 while ((aKey = [keys nextObject])) {
7928 NSNumber *aValue = internal[aKey];
7929 block([aKey longLongValue], [aValue intValue], &stop);
7936 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
7937 NSDictionary *internal = _dictionary;
7938 NSUInteger count = internal.count;
7943 GPBDataType valueDataType = GPBGetFieldDataType(field);
7944 GPBDataType keyDataType = field.mapKeyDataType;
7946 NSEnumerator *keys = [internal keyEnumerator];
7948 while ((aKey = [keys nextObject])) {
7949 NSNumber *aValue = internal[aKey];
7950 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
7951 msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
7952 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
7954 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
7955 result += tagSize * count;
7959 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
7960 asField:(GPBFieldDescriptor *)field {
7961 GPBDataType valueDataType = GPBGetFieldDataType(field);
7962 GPBDataType keyDataType = field.mapKeyDataType;
7963 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
7964 NSDictionary *internal = _dictionary;
7965 NSEnumerator *keys = [internal keyEnumerator];
7967 while ((aKey = [keys nextObject])) {
7968 NSNumber *aValue = internal[aKey];
7969 [outputStream writeInt32NoTag:tag];
7970 // Write the size of the message.
7971 int64_t unwrappedKey = [aKey longLongValue];
7972 int32_t unwrappedValue = [aValue intValue];
7973 size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
7974 msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
7975 [outputStream writeInt32NoTag:(int32_t)msgSize];
7976 // Write the fields.
7977 WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
7978 WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
7982 - (NSData *)serializedDataForUnknownValue:(int32_t)value
7983 forKey:(GPBGenericValue *)key
7984 keyDataType:(GPBDataType)keyDataType {
7985 size_t msgSize = ComputeDictInt64FieldSize(key->valueInt64, kMapKeyFieldNumber, keyDataType);
7986 msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
7987 NSMutableData *data = [NSMutableData dataWithLength:msgSize];
7988 GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
7989 WriteDictInt64Field(outputStream, key->valueInt64, kMapKeyFieldNumber, keyDataType);
7990 WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
7991 [outputStream flush];
7992 [outputStream release];
7995 - (void)setGPBGenericValue:(GPBGenericValue *)value
7996 forGPBGenericValueKey:(GPBGenericValue *)key {
7997 [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueInt64)];
8000 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
8001 [self enumerateKeysAndRawValuesUsingBlock:^(int64_t key, int32_t value, __unused BOOL *stop) {
8002 block([NSString stringWithFormat:@"%lld", key], @(value));
8006 - (BOOL)getEnum:(int32_t *)value forKey:(int64_t)key {
8007 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
8008 if (wrapped && value) {
8009 int32_t result = [wrapped intValue];
8010 if (!_validationFunc(result)) {
8011 result = kGPBUnrecognizedEnumeratorValue;
8015 return (wrapped != NULL);
8018 - (BOOL)getRawValue:(int32_t *)rawValue forKey:(int64_t)key {
8019 NSNumber *wrapped = [_dictionary objectForKey:@(key)];
8020 if (wrapped && rawValue) {
8021 *rawValue = [wrapped intValue];
8023 return (wrapped != NULL);
8026 - (void)enumerateKeysAndEnumsUsingBlock:
8027 (void (NS_NOESCAPE ^)(int64_t key, int32_t value, BOOL *stop))block {
8028 GPBEnumValidationFunc func = _validationFunc;
8030 NSEnumerator *keys = [_dictionary keyEnumerator];
8032 while ((aKey = [keys nextObject])) {
8033 NSNumber *aValue = _dictionary[aKey];
8034 int32_t unwrapped = [aValue intValue];
8035 if (!func(unwrapped)) {
8036 unwrapped = kGPBUnrecognizedEnumeratorValue;
8038 block([aKey longLongValue], unwrapped, &stop);
8045 - (void)addRawEntriesFromDictionary:(GPBInt64EnumDictionary *)otherDictionary {
8046 if (otherDictionary) {
8047 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
8049 GPBAutocreatedDictionaryModified(_autocreator, self);
8054 - (void)setRawValue:(int32_t)value forKey:(int64_t)key {
8055 [_dictionary setObject:@(value) forKey:@(key)];
8057 GPBAutocreatedDictionaryModified(_autocreator, self);
8061 - (void)removeEnumForKey:(int64_t)aKey {
8062 [_dictionary removeObjectForKey:@(aKey)];
8066 [_dictionary removeAllObjects];
8069 - (void)setEnum:(int32_t)value forKey:(int64_t)key {
8070 if (!_validationFunc(value)) {
8071 [NSException raise:NSInvalidArgumentException
8072 format:@"GPBInt64EnumDictionary: Attempt to set an unknown enum value (%d)",
8076 [_dictionary setObject:@(value) forKey:@(key)];
8078 GPBAutocreatedDictionaryModified(_autocreator, self);
8084 #pragma mark - Int64 -> Object
8086 @implementation GPBInt64ObjectDictionary {
8088 NSMutableDictionary *_dictionary;
8091 - (instancetype)init {
8092 return [self initWithObjects:NULL forKeys:NULL count:0];
8095 - (instancetype)initWithObjects:(const id [])objects
8096 forKeys:(const int64_t [])keys
8097 count:(NSUInteger)count {
8098 self = [super init];
8100 _dictionary = [[NSMutableDictionary alloc] init];
8101 if (count && objects && keys) {
8102 for (NSUInteger i = 0; i < count; ++i) {
8104 [NSException raise:NSInvalidArgumentException
8105 format:@"Attempting to add nil object to a Dictionary"];
8107 [_dictionary setObject:objects[i] forKey:@(keys[i])];
8114 - (instancetype)initWithDictionary:(GPBInt64ObjectDictionary *)dictionary {
8115 self = [self initWithObjects:NULL forKeys:NULL count:0];
8118 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
8124 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
8125 return [self initWithObjects:NULL forKeys:NULL count:0];
8129 NSAssert(!_autocreator,
8130 @"%@: Autocreator must be cleared before release, autocreator: %@",
8131 [self class], _autocreator);
8132 [_dictionary release];
8136 - (instancetype)copyWithZone:(NSZone *)zone {
8137 return [[GPBInt64ObjectDictionary allocWithZone:zone] initWithDictionary:self];
8140 - (BOOL)isEqual:(id)other {
8141 if (self == other) {
8144 if (![other isKindOfClass:[GPBInt64ObjectDictionary class]]) {
8147 GPBInt64ObjectDictionary *otherDictionary = other;
8148 return [_dictionary isEqual:otherDictionary->_dictionary];
8151 - (NSUInteger)hash {
8152 return _dictionary.count;
8155 - (NSString *)description {
8156 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
8159 - (NSUInteger)count {
8160 return _dictionary.count;
8163 - (void)enumerateKeysAndObjectsUsingBlock:
8164 (void (NS_NOESCAPE ^)(int64_t key, id object, BOOL *stop))block {
8166 NSDictionary *internal = _dictionary;
8167 NSEnumerator *keys = [internal keyEnumerator];
8169 while ((aKey = [keys nextObject])) {
8170 id aObject = internal[aKey];
8171 block([aKey longLongValue], aObject, &stop);
8178 - (BOOL)isInitialized {
8179 for (GPBMessage *msg in [_dictionary objectEnumerator]) {
8180 if (!msg.initialized) {
8187 - (instancetype)deepCopyWithZone:(NSZone *)zone {
8188 GPBInt64ObjectDictionary *newDict =
8189 [[GPBInt64ObjectDictionary alloc] init];
8190 NSEnumerator *keys = [_dictionary keyEnumerator];
8192 NSMutableDictionary *internalDict = newDict->_dictionary;
8193 while ((aKey = [keys nextObject])) {
8194 GPBMessage *msg = _dictionary[aKey];
8195 GPBMessage *copiedMsg = [msg copyWithZone:zone];
8196 [internalDict setObject:copiedMsg forKey:aKey];
8197 [copiedMsg release];
8202 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
8203 NSDictionary *internal = _dictionary;
8204 NSUInteger count = internal.count;
8209 GPBDataType valueDataType = GPBGetFieldDataType(field);
8210 GPBDataType keyDataType = field.mapKeyDataType;
8212 NSEnumerator *keys = [internal keyEnumerator];
8214 while ((aKey = [keys nextObject])) {
8215 id aObject = internal[aKey];
8216 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
8217 msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
8218 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
8220 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
8221 result += tagSize * count;
8225 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
8226 asField:(GPBFieldDescriptor *)field {
8227 GPBDataType valueDataType = GPBGetFieldDataType(field);
8228 GPBDataType keyDataType = field.mapKeyDataType;
8229 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
8230 NSDictionary *internal = _dictionary;
8231 NSEnumerator *keys = [internal keyEnumerator];
8233 while ((aKey = [keys nextObject])) {
8234 id aObject = internal[aKey];
8235 [outputStream writeInt32NoTag:tag];
8236 // Write the size of the message.
8237 int64_t unwrappedKey = [aKey longLongValue];
8238 id unwrappedValue = aObject;
8239 size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
8240 msgSize += ComputeDictObjectFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
8241 [outputStream writeInt32NoTag:(int32_t)msgSize];
8242 // Write the fields.
8243 WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
8244 WriteDictObjectField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
8248 - (void)setGPBGenericValue:(GPBGenericValue *)value
8249 forGPBGenericValueKey:(GPBGenericValue *)key {
8250 [_dictionary setObject:value->valueString forKey:@(key->valueInt64)];
8253 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
8254 [self enumerateKeysAndObjectsUsingBlock:^(int64_t key, id object, __unused BOOL *stop) {
8255 block([NSString stringWithFormat:@"%lld", key], object);
8259 - (id)objectForKey:(int64_t)key {
8260 id result = [_dictionary objectForKey:@(key)];
8264 - (void)addEntriesFromDictionary:(GPBInt64ObjectDictionary *)otherDictionary {
8265 if (otherDictionary) {
8266 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
8268 GPBAutocreatedDictionaryModified(_autocreator, self);
8273 - (void)setObject:(id)object forKey:(int64_t)key {
8275 [NSException raise:NSInvalidArgumentException
8276 format:@"Attempting to add nil object to a Dictionary"];
8278 [_dictionary setObject:object forKey:@(key)];
8280 GPBAutocreatedDictionaryModified(_autocreator, self);
8284 - (void)removeObjectForKey:(int64_t)aKey {
8285 [_dictionary removeObjectForKey:@(aKey)];
8289 [_dictionary removeAllObjects];
8294 //%PDDM-EXPAND DICTIONARY_POD_IMPL_FOR_KEY(String, NSString, *, OBJECT)
8295 // This block of code is generated, do not edit it directly.
8297 #pragma mark - String -> UInt32
8299 @implementation GPBStringUInt32Dictionary {
8301 NSMutableDictionary *_dictionary;
8304 - (instancetype)init {
8305 return [self initWithUInt32s:NULL forKeys:NULL count:0];
8308 - (instancetype)initWithUInt32s:(const uint32_t [])values
8309 forKeys:(const NSString * [])keys
8310 count:(NSUInteger)count {
8311 self = [super init];
8313 _dictionary = [[NSMutableDictionary alloc] init];
8314 if (count && values && keys) {
8315 for (NSUInteger i = 0; i < count; ++i) {
8317 [NSException raise:NSInvalidArgumentException
8318 format:@"Attempting to add nil key to a Dictionary"];
8320 [_dictionary setObject:@(values[i]) forKey:keys[i]];
8327 - (instancetype)initWithDictionary:(GPBStringUInt32Dictionary *)dictionary {
8328 self = [self initWithUInt32s:NULL forKeys:NULL count:0];
8331 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
8337 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
8338 return [self initWithUInt32s:NULL forKeys:NULL count:0];
8342 NSAssert(!_autocreator,
8343 @"%@: Autocreator must be cleared before release, autocreator: %@",
8344 [self class], _autocreator);
8345 [_dictionary release];
8349 - (instancetype)copyWithZone:(NSZone *)zone {
8350 return [[GPBStringUInt32Dictionary allocWithZone:zone] initWithDictionary:self];
8353 - (BOOL)isEqual:(id)other {
8354 if (self == other) {
8357 if (![other isKindOfClass:[GPBStringUInt32Dictionary class]]) {
8360 GPBStringUInt32Dictionary *otherDictionary = other;
8361 return [_dictionary isEqual:otherDictionary->_dictionary];
8364 - (NSUInteger)hash {
8365 return _dictionary.count;
8368 - (NSString *)description {
8369 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
8372 - (NSUInteger)count {
8373 return _dictionary.count;
8376 - (void)enumerateKeysAndUInt32sUsingBlock:
8377 (void (NS_NOESCAPE ^)(NSString *key, uint32_t value, BOOL *stop))block {
8379 NSDictionary *internal = _dictionary;
8380 NSEnumerator *keys = [internal keyEnumerator];
8382 while ((aKey = [keys nextObject])) {
8383 NSNumber *aValue = internal[aKey];
8384 block(aKey, [aValue unsignedIntValue], &stop);
8391 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
8392 NSDictionary *internal = _dictionary;
8393 NSUInteger count = internal.count;
8398 GPBDataType valueDataType = GPBGetFieldDataType(field);
8399 GPBDataType keyDataType = field.mapKeyDataType;
8401 NSEnumerator *keys = [internal keyEnumerator];
8403 while ((aKey = [keys nextObject])) {
8404 NSNumber *aValue = internal[aKey];
8405 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
8406 msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
8407 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
8409 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
8410 result += tagSize * count;
8414 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
8415 asField:(GPBFieldDescriptor *)field {
8416 GPBDataType valueDataType = GPBGetFieldDataType(field);
8417 GPBDataType keyDataType = field.mapKeyDataType;
8418 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
8419 NSDictionary *internal = _dictionary;
8420 NSEnumerator *keys = [internal keyEnumerator];
8422 while ((aKey = [keys nextObject])) {
8423 NSNumber *aValue = internal[aKey];
8424 [outputStream writeInt32NoTag:tag];
8425 // Write the size of the message.
8426 NSString *unwrappedKey = aKey;
8427 uint32_t unwrappedValue = [aValue unsignedIntValue];
8428 size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
8429 msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
8430 [outputStream writeInt32NoTag:(int32_t)msgSize];
8431 // Write the fields.
8432 WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
8433 WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
8437 - (void)setGPBGenericValue:(GPBGenericValue *)value
8438 forGPBGenericValueKey:(GPBGenericValue *)key {
8439 [_dictionary setObject:@(value->valueUInt32) forKey:key->valueString];
8442 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
8443 [self enumerateKeysAndUInt32sUsingBlock:^(NSString *key, uint32_t value, __unused BOOL *stop) {
8444 block(key, [NSString stringWithFormat:@"%u", value]);
8448 - (BOOL)getUInt32:(nullable uint32_t *)value forKey:(NSString *)key {
8449 NSNumber *wrapped = [_dictionary objectForKey:key];
8450 if (wrapped && value) {
8451 *value = [wrapped unsignedIntValue];
8453 return (wrapped != NULL);
8456 - (void)addEntriesFromDictionary:(GPBStringUInt32Dictionary *)otherDictionary {
8457 if (otherDictionary) {
8458 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
8460 GPBAutocreatedDictionaryModified(_autocreator, self);
8465 - (void)setUInt32:(uint32_t)value forKey:(NSString *)key {
8467 [NSException raise:NSInvalidArgumentException
8468 format:@"Attempting to add nil key to a Dictionary"];
8470 [_dictionary setObject:@(value) forKey:key];
8472 GPBAutocreatedDictionaryModified(_autocreator, self);
8476 - (void)removeUInt32ForKey:(NSString *)aKey {
8477 [_dictionary removeObjectForKey:aKey];
8481 [_dictionary removeAllObjects];
8486 #pragma mark - String -> Int32
8488 @implementation GPBStringInt32Dictionary {
8490 NSMutableDictionary *_dictionary;
8493 - (instancetype)init {
8494 return [self initWithInt32s:NULL forKeys:NULL count:0];
8497 - (instancetype)initWithInt32s:(const int32_t [])values
8498 forKeys:(const NSString * [])keys
8499 count:(NSUInteger)count {
8500 self = [super init];
8502 _dictionary = [[NSMutableDictionary alloc] init];
8503 if (count && values && keys) {
8504 for (NSUInteger i = 0; i < count; ++i) {
8506 [NSException raise:NSInvalidArgumentException
8507 format:@"Attempting to add nil key to a Dictionary"];
8509 [_dictionary setObject:@(values[i]) forKey:keys[i]];
8516 - (instancetype)initWithDictionary:(GPBStringInt32Dictionary *)dictionary {
8517 self = [self initWithInt32s:NULL forKeys:NULL count:0];
8520 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
8526 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
8527 return [self initWithInt32s:NULL forKeys:NULL count:0];
8531 NSAssert(!_autocreator,
8532 @"%@: Autocreator must be cleared before release, autocreator: %@",
8533 [self class], _autocreator);
8534 [_dictionary release];
8538 - (instancetype)copyWithZone:(NSZone *)zone {
8539 return [[GPBStringInt32Dictionary allocWithZone:zone] initWithDictionary:self];
8542 - (BOOL)isEqual:(id)other {
8543 if (self == other) {
8546 if (![other isKindOfClass:[GPBStringInt32Dictionary class]]) {
8549 GPBStringInt32Dictionary *otherDictionary = other;
8550 return [_dictionary isEqual:otherDictionary->_dictionary];
8553 - (NSUInteger)hash {
8554 return _dictionary.count;
8557 - (NSString *)description {
8558 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
8561 - (NSUInteger)count {
8562 return _dictionary.count;
8565 - (void)enumerateKeysAndInt32sUsingBlock:
8566 (void (NS_NOESCAPE ^)(NSString *key, int32_t value, BOOL *stop))block {
8568 NSDictionary *internal = _dictionary;
8569 NSEnumerator *keys = [internal keyEnumerator];
8571 while ((aKey = [keys nextObject])) {
8572 NSNumber *aValue = internal[aKey];
8573 block(aKey, [aValue intValue], &stop);
8580 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
8581 NSDictionary *internal = _dictionary;
8582 NSUInteger count = internal.count;
8587 GPBDataType valueDataType = GPBGetFieldDataType(field);
8588 GPBDataType keyDataType = field.mapKeyDataType;
8590 NSEnumerator *keys = [internal keyEnumerator];
8592 while ((aKey = [keys nextObject])) {
8593 NSNumber *aValue = internal[aKey];
8594 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
8595 msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
8596 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
8598 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
8599 result += tagSize * count;
8603 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
8604 asField:(GPBFieldDescriptor *)field {
8605 GPBDataType valueDataType = GPBGetFieldDataType(field);
8606 GPBDataType keyDataType = field.mapKeyDataType;
8607 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
8608 NSDictionary *internal = _dictionary;
8609 NSEnumerator *keys = [internal keyEnumerator];
8611 while ((aKey = [keys nextObject])) {
8612 NSNumber *aValue = internal[aKey];
8613 [outputStream writeInt32NoTag:tag];
8614 // Write the size of the message.
8615 NSString *unwrappedKey = aKey;
8616 int32_t unwrappedValue = [aValue intValue];
8617 size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
8618 msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
8619 [outputStream writeInt32NoTag:(int32_t)msgSize];
8620 // Write the fields.
8621 WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
8622 WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
8626 - (void)setGPBGenericValue:(GPBGenericValue *)value
8627 forGPBGenericValueKey:(GPBGenericValue *)key {
8628 [_dictionary setObject:@(value->valueInt32) forKey:key->valueString];
8631 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
8632 [self enumerateKeysAndInt32sUsingBlock:^(NSString *key, int32_t value, __unused BOOL *stop) {
8633 block(key, [NSString stringWithFormat:@"%d", value]);
8637 - (BOOL)getInt32:(nullable int32_t *)value forKey:(NSString *)key {
8638 NSNumber *wrapped = [_dictionary objectForKey:key];
8639 if (wrapped && value) {
8640 *value = [wrapped intValue];
8642 return (wrapped != NULL);
8645 - (void)addEntriesFromDictionary:(GPBStringInt32Dictionary *)otherDictionary {
8646 if (otherDictionary) {
8647 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
8649 GPBAutocreatedDictionaryModified(_autocreator, self);
8654 - (void)setInt32:(int32_t)value forKey:(NSString *)key {
8656 [NSException raise:NSInvalidArgumentException
8657 format:@"Attempting to add nil key to a Dictionary"];
8659 [_dictionary setObject:@(value) forKey:key];
8661 GPBAutocreatedDictionaryModified(_autocreator, self);
8665 - (void)removeInt32ForKey:(NSString *)aKey {
8666 [_dictionary removeObjectForKey:aKey];
8670 [_dictionary removeAllObjects];
8675 #pragma mark - String -> UInt64
8677 @implementation GPBStringUInt64Dictionary {
8679 NSMutableDictionary *_dictionary;
8682 - (instancetype)init {
8683 return [self initWithUInt64s:NULL forKeys:NULL count:0];
8686 - (instancetype)initWithUInt64s:(const uint64_t [])values
8687 forKeys:(const NSString * [])keys
8688 count:(NSUInteger)count {
8689 self = [super init];
8691 _dictionary = [[NSMutableDictionary alloc] init];
8692 if (count && values && keys) {
8693 for (NSUInteger i = 0; i < count; ++i) {
8695 [NSException raise:NSInvalidArgumentException
8696 format:@"Attempting to add nil key to a Dictionary"];
8698 [_dictionary setObject:@(values[i]) forKey:keys[i]];
8705 - (instancetype)initWithDictionary:(GPBStringUInt64Dictionary *)dictionary {
8706 self = [self initWithUInt64s:NULL forKeys:NULL count:0];
8709 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
8715 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
8716 return [self initWithUInt64s:NULL forKeys:NULL count:0];
8720 NSAssert(!_autocreator,
8721 @"%@: Autocreator must be cleared before release, autocreator: %@",
8722 [self class], _autocreator);
8723 [_dictionary release];
8727 - (instancetype)copyWithZone:(NSZone *)zone {
8728 return [[GPBStringUInt64Dictionary allocWithZone:zone] initWithDictionary:self];
8731 - (BOOL)isEqual:(id)other {
8732 if (self == other) {
8735 if (![other isKindOfClass:[GPBStringUInt64Dictionary class]]) {
8738 GPBStringUInt64Dictionary *otherDictionary = other;
8739 return [_dictionary isEqual:otherDictionary->_dictionary];
8742 - (NSUInteger)hash {
8743 return _dictionary.count;
8746 - (NSString *)description {
8747 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
8750 - (NSUInteger)count {
8751 return _dictionary.count;
8754 - (void)enumerateKeysAndUInt64sUsingBlock:
8755 (void (NS_NOESCAPE ^)(NSString *key, uint64_t value, BOOL *stop))block {
8757 NSDictionary *internal = _dictionary;
8758 NSEnumerator *keys = [internal keyEnumerator];
8760 while ((aKey = [keys nextObject])) {
8761 NSNumber *aValue = internal[aKey];
8762 block(aKey, [aValue unsignedLongLongValue], &stop);
8769 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
8770 NSDictionary *internal = _dictionary;
8771 NSUInteger count = internal.count;
8776 GPBDataType valueDataType = GPBGetFieldDataType(field);
8777 GPBDataType keyDataType = field.mapKeyDataType;
8779 NSEnumerator *keys = [internal keyEnumerator];
8781 while ((aKey = [keys nextObject])) {
8782 NSNumber *aValue = internal[aKey];
8783 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
8784 msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
8785 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
8787 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
8788 result += tagSize * count;
8792 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
8793 asField:(GPBFieldDescriptor *)field {
8794 GPBDataType valueDataType = GPBGetFieldDataType(field);
8795 GPBDataType keyDataType = field.mapKeyDataType;
8796 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
8797 NSDictionary *internal = _dictionary;
8798 NSEnumerator *keys = [internal keyEnumerator];
8800 while ((aKey = [keys nextObject])) {
8801 NSNumber *aValue = internal[aKey];
8802 [outputStream writeInt32NoTag:tag];
8803 // Write the size of the message.
8804 NSString *unwrappedKey = aKey;
8805 uint64_t unwrappedValue = [aValue unsignedLongLongValue];
8806 size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
8807 msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
8808 [outputStream writeInt32NoTag:(int32_t)msgSize];
8809 // Write the fields.
8810 WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
8811 WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
8815 - (void)setGPBGenericValue:(GPBGenericValue *)value
8816 forGPBGenericValueKey:(GPBGenericValue *)key {
8817 [_dictionary setObject:@(value->valueUInt64) forKey:key->valueString];
8820 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
8821 [self enumerateKeysAndUInt64sUsingBlock:^(NSString *key, uint64_t value, __unused BOOL *stop) {
8822 block(key, [NSString stringWithFormat:@"%llu", value]);
8826 - (BOOL)getUInt64:(nullable uint64_t *)value forKey:(NSString *)key {
8827 NSNumber *wrapped = [_dictionary objectForKey:key];
8828 if (wrapped && value) {
8829 *value = [wrapped unsignedLongLongValue];
8831 return (wrapped != NULL);
8834 - (void)addEntriesFromDictionary:(GPBStringUInt64Dictionary *)otherDictionary {
8835 if (otherDictionary) {
8836 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
8838 GPBAutocreatedDictionaryModified(_autocreator, self);
8843 - (void)setUInt64:(uint64_t)value forKey:(NSString *)key {
8845 [NSException raise:NSInvalidArgumentException
8846 format:@"Attempting to add nil key to a Dictionary"];
8848 [_dictionary setObject:@(value) forKey:key];
8850 GPBAutocreatedDictionaryModified(_autocreator, self);
8854 - (void)removeUInt64ForKey:(NSString *)aKey {
8855 [_dictionary removeObjectForKey:aKey];
8859 [_dictionary removeAllObjects];
8864 #pragma mark - String -> Int64
8866 @implementation GPBStringInt64Dictionary {
8868 NSMutableDictionary *_dictionary;
8871 - (instancetype)init {
8872 return [self initWithInt64s:NULL forKeys:NULL count:0];
8875 - (instancetype)initWithInt64s:(const int64_t [])values
8876 forKeys:(const NSString * [])keys
8877 count:(NSUInteger)count {
8878 self = [super init];
8880 _dictionary = [[NSMutableDictionary alloc] init];
8881 if (count && values && keys) {
8882 for (NSUInteger i = 0; i < count; ++i) {
8884 [NSException raise:NSInvalidArgumentException
8885 format:@"Attempting to add nil key to a Dictionary"];
8887 [_dictionary setObject:@(values[i]) forKey:keys[i]];
8894 - (instancetype)initWithDictionary:(GPBStringInt64Dictionary *)dictionary {
8895 self = [self initWithInt64s:NULL forKeys:NULL count:0];
8898 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
8904 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
8905 return [self initWithInt64s:NULL forKeys:NULL count:0];
8909 NSAssert(!_autocreator,
8910 @"%@: Autocreator must be cleared before release, autocreator: %@",
8911 [self class], _autocreator);
8912 [_dictionary release];
8916 - (instancetype)copyWithZone:(NSZone *)zone {
8917 return [[GPBStringInt64Dictionary allocWithZone:zone] initWithDictionary:self];
8920 - (BOOL)isEqual:(id)other {
8921 if (self == other) {
8924 if (![other isKindOfClass:[GPBStringInt64Dictionary class]]) {
8927 GPBStringInt64Dictionary *otherDictionary = other;
8928 return [_dictionary isEqual:otherDictionary->_dictionary];
8931 - (NSUInteger)hash {
8932 return _dictionary.count;
8935 - (NSString *)description {
8936 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
8939 - (NSUInteger)count {
8940 return _dictionary.count;
8943 - (void)enumerateKeysAndInt64sUsingBlock:
8944 (void (NS_NOESCAPE ^)(NSString *key, int64_t value, BOOL *stop))block {
8946 NSDictionary *internal = _dictionary;
8947 NSEnumerator *keys = [internal keyEnumerator];
8949 while ((aKey = [keys nextObject])) {
8950 NSNumber *aValue = internal[aKey];
8951 block(aKey, [aValue longLongValue], &stop);
8958 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
8959 NSDictionary *internal = _dictionary;
8960 NSUInteger count = internal.count;
8965 GPBDataType valueDataType = GPBGetFieldDataType(field);
8966 GPBDataType keyDataType = field.mapKeyDataType;
8968 NSEnumerator *keys = [internal keyEnumerator];
8970 while ((aKey = [keys nextObject])) {
8971 NSNumber *aValue = internal[aKey];
8972 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
8973 msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
8974 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
8976 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
8977 result += tagSize * count;
8981 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
8982 asField:(GPBFieldDescriptor *)field {
8983 GPBDataType valueDataType = GPBGetFieldDataType(field);
8984 GPBDataType keyDataType = field.mapKeyDataType;
8985 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
8986 NSDictionary *internal = _dictionary;
8987 NSEnumerator *keys = [internal keyEnumerator];
8989 while ((aKey = [keys nextObject])) {
8990 NSNumber *aValue = internal[aKey];
8991 [outputStream writeInt32NoTag:tag];
8992 // Write the size of the message.
8993 NSString *unwrappedKey = aKey;
8994 int64_t unwrappedValue = [aValue longLongValue];
8995 size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
8996 msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
8997 [outputStream writeInt32NoTag:(int32_t)msgSize];
8998 // Write the fields.
8999 WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
9000 WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
9004 - (void)setGPBGenericValue:(GPBGenericValue *)value
9005 forGPBGenericValueKey:(GPBGenericValue *)key {
9006 [_dictionary setObject:@(value->valueInt64) forKey:key->valueString];
9009 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
9010 [self enumerateKeysAndInt64sUsingBlock:^(NSString *key, int64_t value, __unused BOOL *stop) {
9011 block(key, [NSString stringWithFormat:@"%lld", value]);
9015 - (BOOL)getInt64:(nullable int64_t *)value forKey:(NSString *)key {
9016 NSNumber *wrapped = [_dictionary objectForKey:key];
9017 if (wrapped && value) {
9018 *value = [wrapped longLongValue];
9020 return (wrapped != NULL);
9023 - (void)addEntriesFromDictionary:(GPBStringInt64Dictionary *)otherDictionary {
9024 if (otherDictionary) {
9025 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
9027 GPBAutocreatedDictionaryModified(_autocreator, self);
9032 - (void)setInt64:(int64_t)value forKey:(NSString *)key {
9034 [NSException raise:NSInvalidArgumentException
9035 format:@"Attempting to add nil key to a Dictionary"];
9037 [_dictionary setObject:@(value) forKey:key];
9039 GPBAutocreatedDictionaryModified(_autocreator, self);
9043 - (void)removeInt64ForKey:(NSString *)aKey {
9044 [_dictionary removeObjectForKey:aKey];
9048 [_dictionary removeAllObjects];
9053 #pragma mark - String -> Bool
9055 @implementation GPBStringBoolDictionary {
9057 NSMutableDictionary *_dictionary;
9060 - (instancetype)init {
9061 return [self initWithBools:NULL forKeys:NULL count:0];
9064 - (instancetype)initWithBools:(const BOOL [])values
9065 forKeys:(const NSString * [])keys
9066 count:(NSUInteger)count {
9067 self = [super init];
9069 _dictionary = [[NSMutableDictionary alloc] init];
9070 if (count && values && keys) {
9071 for (NSUInteger i = 0; i < count; ++i) {
9073 [NSException raise:NSInvalidArgumentException
9074 format:@"Attempting to add nil key to a Dictionary"];
9076 [_dictionary setObject:@(values[i]) forKey:keys[i]];
9083 - (instancetype)initWithDictionary:(GPBStringBoolDictionary *)dictionary {
9084 self = [self initWithBools:NULL forKeys:NULL count:0];
9087 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
9093 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
9094 return [self initWithBools:NULL forKeys:NULL count:0];
9098 NSAssert(!_autocreator,
9099 @"%@: Autocreator must be cleared before release, autocreator: %@",
9100 [self class], _autocreator);
9101 [_dictionary release];
9105 - (instancetype)copyWithZone:(NSZone *)zone {
9106 return [[GPBStringBoolDictionary allocWithZone:zone] initWithDictionary:self];
9109 - (BOOL)isEqual:(id)other {
9110 if (self == other) {
9113 if (![other isKindOfClass:[GPBStringBoolDictionary class]]) {
9116 GPBStringBoolDictionary *otherDictionary = other;
9117 return [_dictionary isEqual:otherDictionary->_dictionary];
9120 - (NSUInteger)hash {
9121 return _dictionary.count;
9124 - (NSString *)description {
9125 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
9128 - (NSUInteger)count {
9129 return _dictionary.count;
9132 - (void)enumerateKeysAndBoolsUsingBlock:
9133 (void (NS_NOESCAPE ^)(NSString *key, BOOL value, BOOL *stop))block {
9135 NSDictionary *internal = _dictionary;
9136 NSEnumerator *keys = [internal keyEnumerator];
9138 while ((aKey = [keys nextObject])) {
9139 NSNumber *aValue = internal[aKey];
9140 block(aKey, [aValue boolValue], &stop);
9147 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
9148 NSDictionary *internal = _dictionary;
9149 NSUInteger count = internal.count;
9154 GPBDataType valueDataType = GPBGetFieldDataType(field);
9155 GPBDataType keyDataType = field.mapKeyDataType;
9157 NSEnumerator *keys = [internal keyEnumerator];
9159 while ((aKey = [keys nextObject])) {
9160 NSNumber *aValue = internal[aKey];
9161 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
9162 msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
9163 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
9165 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
9166 result += tagSize * count;
9170 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
9171 asField:(GPBFieldDescriptor *)field {
9172 GPBDataType valueDataType = GPBGetFieldDataType(field);
9173 GPBDataType keyDataType = field.mapKeyDataType;
9174 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
9175 NSDictionary *internal = _dictionary;
9176 NSEnumerator *keys = [internal keyEnumerator];
9178 while ((aKey = [keys nextObject])) {
9179 NSNumber *aValue = internal[aKey];
9180 [outputStream writeInt32NoTag:tag];
9181 // Write the size of the message.
9182 NSString *unwrappedKey = aKey;
9183 BOOL unwrappedValue = [aValue boolValue];
9184 size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
9185 msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
9186 [outputStream writeInt32NoTag:(int32_t)msgSize];
9187 // Write the fields.
9188 WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
9189 WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
9193 - (void)setGPBGenericValue:(GPBGenericValue *)value
9194 forGPBGenericValueKey:(GPBGenericValue *)key {
9195 [_dictionary setObject:@(value->valueBool) forKey:key->valueString];
9198 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
9199 [self enumerateKeysAndBoolsUsingBlock:^(NSString *key, BOOL value, __unused BOOL *stop) {
9200 block(key, (value ? @"true" : @"false"));
9204 - (BOOL)getBool:(nullable BOOL *)value forKey:(NSString *)key {
9205 NSNumber *wrapped = [_dictionary objectForKey:key];
9206 if (wrapped && value) {
9207 *value = [wrapped boolValue];
9209 return (wrapped != NULL);
9212 - (void)addEntriesFromDictionary:(GPBStringBoolDictionary *)otherDictionary {
9213 if (otherDictionary) {
9214 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
9216 GPBAutocreatedDictionaryModified(_autocreator, self);
9221 - (void)setBool:(BOOL)value forKey:(NSString *)key {
9223 [NSException raise:NSInvalidArgumentException
9224 format:@"Attempting to add nil key to a Dictionary"];
9226 [_dictionary setObject:@(value) forKey:key];
9228 GPBAutocreatedDictionaryModified(_autocreator, self);
9232 - (void)removeBoolForKey:(NSString *)aKey {
9233 [_dictionary removeObjectForKey:aKey];
9237 [_dictionary removeAllObjects];
9242 #pragma mark - String -> Float
9244 @implementation GPBStringFloatDictionary {
9246 NSMutableDictionary *_dictionary;
9249 - (instancetype)init {
9250 return [self initWithFloats:NULL forKeys:NULL count:0];
9253 - (instancetype)initWithFloats:(const float [])values
9254 forKeys:(const NSString * [])keys
9255 count:(NSUInteger)count {
9256 self = [super init];
9258 _dictionary = [[NSMutableDictionary alloc] init];
9259 if (count && values && keys) {
9260 for (NSUInteger i = 0; i < count; ++i) {
9262 [NSException raise:NSInvalidArgumentException
9263 format:@"Attempting to add nil key to a Dictionary"];
9265 [_dictionary setObject:@(values[i]) forKey:keys[i]];
9272 - (instancetype)initWithDictionary:(GPBStringFloatDictionary *)dictionary {
9273 self = [self initWithFloats:NULL forKeys:NULL count:0];
9276 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
9282 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
9283 return [self initWithFloats:NULL forKeys:NULL count:0];
9287 NSAssert(!_autocreator,
9288 @"%@: Autocreator must be cleared before release, autocreator: %@",
9289 [self class], _autocreator);
9290 [_dictionary release];
9294 - (instancetype)copyWithZone:(NSZone *)zone {
9295 return [[GPBStringFloatDictionary allocWithZone:zone] initWithDictionary:self];
9298 - (BOOL)isEqual:(id)other {
9299 if (self == other) {
9302 if (![other isKindOfClass:[GPBStringFloatDictionary class]]) {
9305 GPBStringFloatDictionary *otherDictionary = other;
9306 return [_dictionary isEqual:otherDictionary->_dictionary];
9309 - (NSUInteger)hash {
9310 return _dictionary.count;
9313 - (NSString *)description {
9314 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
9317 - (NSUInteger)count {
9318 return _dictionary.count;
9321 - (void)enumerateKeysAndFloatsUsingBlock:
9322 (void (NS_NOESCAPE ^)(NSString *key, float value, BOOL *stop))block {
9324 NSDictionary *internal = _dictionary;
9325 NSEnumerator *keys = [internal keyEnumerator];
9327 while ((aKey = [keys nextObject])) {
9328 NSNumber *aValue = internal[aKey];
9329 block(aKey, [aValue floatValue], &stop);
9336 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
9337 NSDictionary *internal = _dictionary;
9338 NSUInteger count = internal.count;
9343 GPBDataType valueDataType = GPBGetFieldDataType(field);
9344 GPBDataType keyDataType = field.mapKeyDataType;
9346 NSEnumerator *keys = [internal keyEnumerator];
9348 while ((aKey = [keys nextObject])) {
9349 NSNumber *aValue = internal[aKey];
9350 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
9351 msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
9352 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
9354 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
9355 result += tagSize * count;
9359 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
9360 asField:(GPBFieldDescriptor *)field {
9361 GPBDataType valueDataType = GPBGetFieldDataType(field);
9362 GPBDataType keyDataType = field.mapKeyDataType;
9363 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
9364 NSDictionary *internal = _dictionary;
9365 NSEnumerator *keys = [internal keyEnumerator];
9367 while ((aKey = [keys nextObject])) {
9368 NSNumber *aValue = internal[aKey];
9369 [outputStream writeInt32NoTag:tag];
9370 // Write the size of the message.
9371 NSString *unwrappedKey = aKey;
9372 float unwrappedValue = [aValue floatValue];
9373 size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
9374 msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
9375 [outputStream writeInt32NoTag:(int32_t)msgSize];
9376 // Write the fields.
9377 WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
9378 WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
9382 - (void)setGPBGenericValue:(GPBGenericValue *)value
9383 forGPBGenericValueKey:(GPBGenericValue *)key {
9384 [_dictionary setObject:@(value->valueFloat) forKey:key->valueString];
9387 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
9388 [self enumerateKeysAndFloatsUsingBlock:^(NSString *key, float value, __unused BOOL *stop) {
9389 block(key, [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
9393 - (BOOL)getFloat:(nullable float *)value forKey:(NSString *)key {
9394 NSNumber *wrapped = [_dictionary objectForKey:key];
9395 if (wrapped && value) {
9396 *value = [wrapped floatValue];
9398 return (wrapped != NULL);
9401 - (void)addEntriesFromDictionary:(GPBStringFloatDictionary *)otherDictionary {
9402 if (otherDictionary) {
9403 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
9405 GPBAutocreatedDictionaryModified(_autocreator, self);
9410 - (void)setFloat:(float)value forKey:(NSString *)key {
9412 [NSException raise:NSInvalidArgumentException
9413 format:@"Attempting to add nil key to a Dictionary"];
9415 [_dictionary setObject:@(value) forKey:key];
9417 GPBAutocreatedDictionaryModified(_autocreator, self);
9421 - (void)removeFloatForKey:(NSString *)aKey {
9422 [_dictionary removeObjectForKey:aKey];
9426 [_dictionary removeAllObjects];
9431 #pragma mark - String -> Double
9433 @implementation GPBStringDoubleDictionary {
9435 NSMutableDictionary *_dictionary;
9438 - (instancetype)init {
9439 return [self initWithDoubles:NULL forKeys:NULL count:0];
9442 - (instancetype)initWithDoubles:(const double [])values
9443 forKeys:(const NSString * [])keys
9444 count:(NSUInteger)count {
9445 self = [super init];
9447 _dictionary = [[NSMutableDictionary alloc] init];
9448 if (count && values && keys) {
9449 for (NSUInteger i = 0; i < count; ++i) {
9451 [NSException raise:NSInvalidArgumentException
9452 format:@"Attempting to add nil key to a Dictionary"];
9454 [_dictionary setObject:@(values[i]) forKey:keys[i]];
9461 - (instancetype)initWithDictionary:(GPBStringDoubleDictionary *)dictionary {
9462 self = [self initWithDoubles:NULL forKeys:NULL count:0];
9465 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
9471 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
9472 return [self initWithDoubles:NULL forKeys:NULL count:0];
9476 NSAssert(!_autocreator,
9477 @"%@: Autocreator must be cleared before release, autocreator: %@",
9478 [self class], _autocreator);
9479 [_dictionary release];
9483 - (instancetype)copyWithZone:(NSZone *)zone {
9484 return [[GPBStringDoubleDictionary allocWithZone:zone] initWithDictionary:self];
9487 - (BOOL)isEqual:(id)other {
9488 if (self == other) {
9491 if (![other isKindOfClass:[GPBStringDoubleDictionary class]]) {
9494 GPBStringDoubleDictionary *otherDictionary = other;
9495 return [_dictionary isEqual:otherDictionary->_dictionary];
9498 - (NSUInteger)hash {
9499 return _dictionary.count;
9502 - (NSString *)description {
9503 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
9506 - (NSUInteger)count {
9507 return _dictionary.count;
9510 - (void)enumerateKeysAndDoublesUsingBlock:
9511 (void (NS_NOESCAPE ^)(NSString *key, double value, BOOL *stop))block {
9513 NSDictionary *internal = _dictionary;
9514 NSEnumerator *keys = [internal keyEnumerator];
9516 while ((aKey = [keys nextObject])) {
9517 NSNumber *aValue = internal[aKey];
9518 block(aKey, [aValue doubleValue], &stop);
9525 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
9526 NSDictionary *internal = _dictionary;
9527 NSUInteger count = internal.count;
9532 GPBDataType valueDataType = GPBGetFieldDataType(field);
9533 GPBDataType keyDataType = field.mapKeyDataType;
9535 NSEnumerator *keys = [internal keyEnumerator];
9537 while ((aKey = [keys nextObject])) {
9538 NSNumber *aValue = internal[aKey];
9539 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
9540 msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
9541 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
9543 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
9544 result += tagSize * count;
9548 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
9549 asField:(GPBFieldDescriptor *)field {
9550 GPBDataType valueDataType = GPBGetFieldDataType(field);
9551 GPBDataType keyDataType = field.mapKeyDataType;
9552 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
9553 NSDictionary *internal = _dictionary;
9554 NSEnumerator *keys = [internal keyEnumerator];
9556 while ((aKey = [keys nextObject])) {
9557 NSNumber *aValue = internal[aKey];
9558 [outputStream writeInt32NoTag:tag];
9559 // Write the size of the message.
9560 NSString *unwrappedKey = aKey;
9561 double unwrappedValue = [aValue doubleValue];
9562 size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
9563 msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
9564 [outputStream writeInt32NoTag:(int32_t)msgSize];
9565 // Write the fields.
9566 WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
9567 WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
9571 - (void)setGPBGenericValue:(GPBGenericValue *)value
9572 forGPBGenericValueKey:(GPBGenericValue *)key {
9573 [_dictionary setObject:@(value->valueDouble) forKey:key->valueString];
9576 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
9577 [self enumerateKeysAndDoublesUsingBlock:^(NSString *key, double value, __unused BOOL *stop) {
9578 block(key, [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
9582 - (BOOL)getDouble:(nullable double *)value forKey:(NSString *)key {
9583 NSNumber *wrapped = [_dictionary objectForKey:key];
9584 if (wrapped && value) {
9585 *value = [wrapped doubleValue];
9587 return (wrapped != NULL);
9590 - (void)addEntriesFromDictionary:(GPBStringDoubleDictionary *)otherDictionary {
9591 if (otherDictionary) {
9592 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
9594 GPBAutocreatedDictionaryModified(_autocreator, self);
9599 - (void)setDouble:(double)value forKey:(NSString *)key {
9601 [NSException raise:NSInvalidArgumentException
9602 format:@"Attempting to add nil key to a Dictionary"];
9604 [_dictionary setObject:@(value) forKey:key];
9606 GPBAutocreatedDictionaryModified(_autocreator, self);
9610 - (void)removeDoubleForKey:(NSString *)aKey {
9611 [_dictionary removeObjectForKey:aKey];
9615 [_dictionary removeAllObjects];
9620 #pragma mark - String -> Enum
9622 @implementation GPBStringEnumDictionary {
9624 NSMutableDictionary *_dictionary;
9625 GPBEnumValidationFunc _validationFunc;
9628 @synthesize validationFunc = _validationFunc;
9630 - (instancetype)init {
9631 return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
9634 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
9635 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
9638 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
9639 rawValues:(const int32_t [])rawValues
9640 forKeys:(const NSString * [])keys
9641 count:(NSUInteger)count {
9642 self = [super init];
9644 _dictionary = [[NSMutableDictionary alloc] init];
9645 _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
9646 if (count && rawValues && keys) {
9647 for (NSUInteger i = 0; i < count; ++i) {
9649 [NSException raise:NSInvalidArgumentException
9650 format:@"Attempting to add nil key to a Dictionary"];
9652 [_dictionary setObject:@(rawValues[i]) forKey:keys[i]];
9659 - (instancetype)initWithDictionary:(GPBStringEnumDictionary *)dictionary {
9660 self = [self initWithValidationFunction:dictionary.validationFunc
9666 [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
9672 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
9673 capacity:(__unused NSUInteger)numItems {
9674 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
9678 NSAssert(!_autocreator,
9679 @"%@: Autocreator must be cleared before release, autocreator: %@",
9680 [self class], _autocreator);
9681 [_dictionary release];
9685 - (instancetype)copyWithZone:(NSZone *)zone {
9686 return [[GPBStringEnumDictionary allocWithZone:zone] initWithDictionary:self];
9689 - (BOOL)isEqual:(id)other {
9690 if (self == other) {
9693 if (![other isKindOfClass:[GPBStringEnumDictionary class]]) {
9696 GPBStringEnumDictionary *otherDictionary = other;
9697 return [_dictionary isEqual:otherDictionary->_dictionary];
9700 - (NSUInteger)hash {
9701 return _dictionary.count;
9704 - (NSString *)description {
9705 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
9708 - (NSUInteger)count {
9709 return _dictionary.count;
9712 - (void)enumerateKeysAndRawValuesUsingBlock:
9713 (void (NS_NOESCAPE ^)(NSString *key, int32_t value, BOOL *stop))block {
9715 NSDictionary *internal = _dictionary;
9716 NSEnumerator *keys = [internal keyEnumerator];
9718 while ((aKey = [keys nextObject])) {
9719 NSNumber *aValue = internal[aKey];
9720 block(aKey, [aValue intValue], &stop);
9727 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
9728 NSDictionary *internal = _dictionary;
9729 NSUInteger count = internal.count;
9734 GPBDataType valueDataType = GPBGetFieldDataType(field);
9735 GPBDataType keyDataType = field.mapKeyDataType;
9737 NSEnumerator *keys = [internal keyEnumerator];
9739 while ((aKey = [keys nextObject])) {
9740 NSNumber *aValue = internal[aKey];
9741 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
9742 msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
9743 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
9745 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
9746 result += tagSize * count;
9750 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
9751 asField:(GPBFieldDescriptor *)field {
9752 GPBDataType valueDataType = GPBGetFieldDataType(field);
9753 GPBDataType keyDataType = field.mapKeyDataType;
9754 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
9755 NSDictionary *internal = _dictionary;
9756 NSEnumerator *keys = [internal keyEnumerator];
9758 while ((aKey = [keys nextObject])) {
9759 NSNumber *aValue = internal[aKey];
9760 [outputStream writeInt32NoTag:tag];
9761 // Write the size of the message.
9762 NSString *unwrappedKey = aKey;
9763 int32_t unwrappedValue = [aValue intValue];
9764 size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
9765 msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
9766 [outputStream writeInt32NoTag:(int32_t)msgSize];
9767 // Write the fields.
9768 WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
9769 WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
9773 - (NSData *)serializedDataForUnknownValue:(int32_t)value
9774 forKey:(GPBGenericValue *)key
9775 keyDataType:(GPBDataType)keyDataType {
9776 size_t msgSize = ComputeDictStringFieldSize(key->valueString, kMapKeyFieldNumber, keyDataType);
9777 msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
9778 NSMutableData *data = [NSMutableData dataWithLength:msgSize];
9779 GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
9780 WriteDictStringField(outputStream, key->valueString, kMapKeyFieldNumber, keyDataType);
9781 WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
9782 [outputStream flush];
9783 [outputStream release];
9786 - (void)setGPBGenericValue:(GPBGenericValue *)value
9787 forGPBGenericValueKey:(GPBGenericValue *)key {
9788 [_dictionary setObject:@(value->valueEnum) forKey:key->valueString];
9791 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
9792 [self enumerateKeysAndRawValuesUsingBlock:^(NSString *key, int32_t value, __unused BOOL *stop) {
9793 block(key, @(value));
9797 - (BOOL)getEnum:(int32_t *)value forKey:(NSString *)key {
9798 NSNumber *wrapped = [_dictionary objectForKey:key];
9799 if (wrapped && value) {
9800 int32_t result = [wrapped intValue];
9801 if (!_validationFunc(result)) {
9802 result = kGPBUnrecognizedEnumeratorValue;
9806 return (wrapped != NULL);
9809 - (BOOL)getRawValue:(int32_t *)rawValue forKey:(NSString *)key {
9810 NSNumber *wrapped = [_dictionary objectForKey:key];
9811 if (wrapped && rawValue) {
9812 *rawValue = [wrapped intValue];
9814 return (wrapped != NULL);
9817 - (void)enumerateKeysAndEnumsUsingBlock:
9818 (void (NS_NOESCAPE ^)(NSString *key, int32_t value, BOOL *stop))block {
9819 GPBEnumValidationFunc func = _validationFunc;
9821 NSEnumerator *keys = [_dictionary keyEnumerator];
9823 while ((aKey = [keys nextObject])) {
9824 NSNumber *aValue = _dictionary[aKey];
9825 int32_t unwrapped = [aValue intValue];
9826 if (!func(unwrapped)) {
9827 unwrapped = kGPBUnrecognizedEnumeratorValue;
9829 block(aKey, unwrapped, &stop);
9836 - (void)addRawEntriesFromDictionary:(GPBStringEnumDictionary *)otherDictionary {
9837 if (otherDictionary) {
9838 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
9840 GPBAutocreatedDictionaryModified(_autocreator, self);
9845 - (void)setRawValue:(int32_t)value forKey:(NSString *)key {
9847 [NSException raise:NSInvalidArgumentException
9848 format:@"Attempting to add nil key to a Dictionary"];
9850 [_dictionary setObject:@(value) forKey:key];
9852 GPBAutocreatedDictionaryModified(_autocreator, self);
9856 - (void)removeEnumForKey:(NSString *)aKey {
9857 [_dictionary removeObjectForKey:aKey];
9861 [_dictionary removeAllObjects];
9864 - (void)setEnum:(int32_t)value forKey:(NSString *)key {
9866 [NSException raise:NSInvalidArgumentException
9867 format:@"Attempting to add nil key to a Dictionary"];
9869 if (!_validationFunc(value)) {
9870 [NSException raise:NSInvalidArgumentException
9871 format:@"GPBStringEnumDictionary: Attempt to set an unknown enum value (%d)",
9875 [_dictionary setObject:@(value) forKey:key];
9877 GPBAutocreatedDictionaryModified(_autocreator, self);
9883 //%PDDM-EXPAND-END (5 expansions)
9886 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(UInt32, uint32_t)
9887 // This block of code is generated, do not edit it directly.
9889 #pragma mark - Bool -> UInt32
9891 @implementation GPBBoolUInt32Dictionary {
9893 uint32_t _values[2];
9897 - (instancetype)init {
9898 return [self initWithUInt32s:NULL forKeys:NULL count:0];
9901 - (instancetype)initWithUInt32s:(const uint32_t [])values
9902 forKeys:(const BOOL [])keys
9903 count:(NSUInteger)count {
9904 self = [super init];
9906 for (NSUInteger i = 0; i < count; ++i) {
9907 int idx = keys[i] ? 1 : 0;
9908 _values[idx] = values[i];
9909 _valueSet[idx] = YES;
9915 - (instancetype)initWithDictionary:(GPBBoolUInt32Dictionary *)dictionary {
9916 self = [self initWithUInt32s:NULL forKeys:NULL count:0];
9919 for (int i = 0; i < 2; ++i) {
9920 if (dictionary->_valueSet[i]) {
9921 _values[i] = dictionary->_values[i];
9930 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
9931 return [self initWithUInt32s:NULL forKeys:NULL count:0];
9934 #if !defined(NS_BLOCK_ASSERTIONS)
9936 NSAssert(!_autocreator,
9937 @"%@: Autocreator must be cleared before release, autocreator: %@",
9938 [self class], _autocreator);
9941 #endif // !defined(NS_BLOCK_ASSERTIONS)
9943 - (instancetype)copyWithZone:(NSZone *)zone {
9944 return [[GPBBoolUInt32Dictionary allocWithZone:zone] initWithDictionary:self];
9947 - (BOOL)isEqual:(id)other {
9948 if (self == other) {
9951 if (![other isKindOfClass:[GPBBoolUInt32Dictionary class]]) {
9954 GPBBoolUInt32Dictionary *otherDictionary = other;
9955 if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
9956 (_valueSet[1] != otherDictionary->_valueSet[1])) {
9959 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
9960 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
9966 - (NSUInteger)hash {
9967 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
9970 - (NSString *)description {
9971 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
9973 [result appendFormat:@"NO: %u", _values[0]];
9976 [result appendFormat:@"YES: %u", _values[1]];
9978 [result appendString:@" }"];
9982 - (NSUInteger)count {
9983 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
9986 - (BOOL)getUInt32:(uint32_t *)value forKey:(BOOL)key {
9987 int idx = (key ? 1 : 0);
9988 if (_valueSet[idx]) {
9990 *value = _values[idx];
9997 - (void)setGPBGenericValue:(GPBGenericValue *)value
9998 forGPBGenericValueKey:(GPBGenericValue *)key {
9999 int idx = (key->valueBool ? 1 : 0);
10000 _values[idx] = value->valueUInt32;
10001 _valueSet[idx] = YES;
10004 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
10005 if (_valueSet[0]) {
10006 block(@"false", [NSString stringWithFormat:@"%u", _values[0]]);
10008 if (_valueSet[1]) {
10009 block(@"true", [NSString stringWithFormat:@"%u", _values[1]]);
10013 - (void)enumerateKeysAndUInt32sUsingBlock:
10014 (void (NS_NOESCAPE ^)(BOOL key, uint32_t value, BOOL *stop))block {
10016 if (_valueSet[0]) {
10017 block(NO, _values[0], &stop);
10019 if (!stop && _valueSet[1]) {
10020 block(YES, _values[1], &stop);
10024 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
10025 GPBDataType valueDataType = GPBGetFieldDataType(field);
10026 NSUInteger count = 0;
10028 for (int i = 0; i < 2; ++i) {
10029 if (_valueSet[i]) {
10031 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10032 msgSize += ComputeDictUInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
10033 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
10036 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
10037 result += tagSize * count;
10041 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
10042 asField:(GPBFieldDescriptor *)field {
10043 GPBDataType valueDataType = GPBGetFieldDataType(field);
10044 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
10045 for (int i = 0; i < 2; ++i) {
10046 if (_valueSet[i]) {
10048 [outputStream writeInt32NoTag:tag];
10049 // Write the size of the message.
10050 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10051 msgSize += ComputeDictUInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
10052 [outputStream writeInt32NoTag:(int32_t)msgSize];
10053 // Write the fields.
10054 WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10055 WriteDictUInt32Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
10060 - (void)addEntriesFromDictionary:(GPBBoolUInt32Dictionary *)otherDictionary {
10061 if (otherDictionary) {
10062 for (int i = 0; i < 2; ++i) {
10063 if (otherDictionary->_valueSet[i]) {
10064 _valueSet[i] = YES;
10065 _values[i] = otherDictionary->_values[i];
10068 if (_autocreator) {
10069 GPBAutocreatedDictionaryModified(_autocreator, self);
10074 - (void)setUInt32:(uint32_t)value forKey:(BOOL)key {
10075 int idx = (key ? 1 : 0);
10076 _values[idx] = value;
10077 _valueSet[idx] = YES;
10078 if (_autocreator) {
10079 GPBAutocreatedDictionaryModified(_autocreator, self);
10083 - (void)removeUInt32ForKey:(BOOL)aKey {
10084 _valueSet[aKey ? 1 : 0] = NO;
10087 - (void)removeAll {
10094 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Int32, int32_t)
10095 // This block of code is generated, do not edit it directly.
10097 #pragma mark - Bool -> Int32
10099 @implementation GPBBoolInt32Dictionary {
10101 int32_t _values[2];
10105 - (instancetype)init {
10106 return [self initWithInt32s:NULL forKeys:NULL count:0];
10109 - (instancetype)initWithInt32s:(const int32_t [])values
10110 forKeys:(const BOOL [])keys
10111 count:(NSUInteger)count {
10112 self = [super init];
10114 for (NSUInteger i = 0; i < count; ++i) {
10115 int idx = keys[i] ? 1 : 0;
10116 _values[idx] = values[i];
10117 _valueSet[idx] = YES;
10123 - (instancetype)initWithDictionary:(GPBBoolInt32Dictionary *)dictionary {
10124 self = [self initWithInt32s:NULL forKeys:NULL count:0];
10127 for (int i = 0; i < 2; ++i) {
10128 if (dictionary->_valueSet[i]) {
10129 _values[i] = dictionary->_values[i];
10130 _valueSet[i] = YES;
10138 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
10139 return [self initWithInt32s:NULL forKeys:NULL count:0];
10142 #if !defined(NS_BLOCK_ASSERTIONS)
10144 NSAssert(!_autocreator,
10145 @"%@: Autocreator must be cleared before release, autocreator: %@",
10146 [self class], _autocreator);
10149 #endif // !defined(NS_BLOCK_ASSERTIONS)
10151 - (instancetype)copyWithZone:(NSZone *)zone {
10152 return [[GPBBoolInt32Dictionary allocWithZone:zone] initWithDictionary:self];
10155 - (BOOL)isEqual:(id)other {
10156 if (self == other) {
10159 if (![other isKindOfClass:[GPBBoolInt32Dictionary class]]) {
10162 GPBBoolInt32Dictionary *otherDictionary = other;
10163 if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
10164 (_valueSet[1] != otherDictionary->_valueSet[1])) {
10167 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
10168 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
10174 - (NSUInteger)hash {
10175 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
10178 - (NSString *)description {
10179 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
10180 if (_valueSet[0]) {
10181 [result appendFormat:@"NO: %d", _values[0]];
10183 if (_valueSet[1]) {
10184 [result appendFormat:@"YES: %d", _values[1]];
10186 [result appendString:@" }"];
10190 - (NSUInteger)count {
10191 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
10194 - (BOOL)getInt32:(int32_t *)value forKey:(BOOL)key {
10195 int idx = (key ? 1 : 0);
10196 if (_valueSet[idx]) {
10198 *value = _values[idx];
10205 - (void)setGPBGenericValue:(GPBGenericValue *)value
10206 forGPBGenericValueKey:(GPBGenericValue *)key {
10207 int idx = (key->valueBool ? 1 : 0);
10208 _values[idx] = value->valueInt32;
10209 _valueSet[idx] = YES;
10212 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
10213 if (_valueSet[0]) {
10214 block(@"false", [NSString stringWithFormat:@"%d", _values[0]]);
10216 if (_valueSet[1]) {
10217 block(@"true", [NSString stringWithFormat:@"%d", _values[1]]);
10221 - (void)enumerateKeysAndInt32sUsingBlock:
10222 (void (NS_NOESCAPE ^)(BOOL key, int32_t value, BOOL *stop))block {
10224 if (_valueSet[0]) {
10225 block(NO, _values[0], &stop);
10227 if (!stop && _valueSet[1]) {
10228 block(YES, _values[1], &stop);
10232 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
10233 GPBDataType valueDataType = GPBGetFieldDataType(field);
10234 NSUInteger count = 0;
10236 for (int i = 0; i < 2; ++i) {
10237 if (_valueSet[i]) {
10239 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10240 msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
10241 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
10244 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
10245 result += tagSize * count;
10249 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
10250 asField:(GPBFieldDescriptor *)field {
10251 GPBDataType valueDataType = GPBGetFieldDataType(field);
10252 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
10253 for (int i = 0; i < 2; ++i) {
10254 if (_valueSet[i]) {
10256 [outputStream writeInt32NoTag:tag];
10257 // Write the size of the message.
10258 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10259 msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
10260 [outputStream writeInt32NoTag:(int32_t)msgSize];
10261 // Write the fields.
10262 WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10263 WriteDictInt32Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
10268 - (void)addEntriesFromDictionary:(GPBBoolInt32Dictionary *)otherDictionary {
10269 if (otherDictionary) {
10270 for (int i = 0; i < 2; ++i) {
10271 if (otherDictionary->_valueSet[i]) {
10272 _valueSet[i] = YES;
10273 _values[i] = otherDictionary->_values[i];
10276 if (_autocreator) {
10277 GPBAutocreatedDictionaryModified(_autocreator, self);
10282 - (void)setInt32:(int32_t)value forKey:(BOOL)key {
10283 int idx = (key ? 1 : 0);
10284 _values[idx] = value;
10285 _valueSet[idx] = YES;
10286 if (_autocreator) {
10287 GPBAutocreatedDictionaryModified(_autocreator, self);
10291 - (void)removeInt32ForKey:(BOOL)aKey {
10292 _valueSet[aKey ? 1 : 0] = NO;
10295 - (void)removeAll {
10302 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(UInt64, uint64_t)
10303 // This block of code is generated, do not edit it directly.
10305 #pragma mark - Bool -> UInt64
10307 @implementation GPBBoolUInt64Dictionary {
10309 uint64_t _values[2];
10313 - (instancetype)init {
10314 return [self initWithUInt64s:NULL forKeys:NULL count:0];
10317 - (instancetype)initWithUInt64s:(const uint64_t [])values
10318 forKeys:(const BOOL [])keys
10319 count:(NSUInteger)count {
10320 self = [super init];
10322 for (NSUInteger i = 0; i < count; ++i) {
10323 int idx = keys[i] ? 1 : 0;
10324 _values[idx] = values[i];
10325 _valueSet[idx] = YES;
10331 - (instancetype)initWithDictionary:(GPBBoolUInt64Dictionary *)dictionary {
10332 self = [self initWithUInt64s:NULL forKeys:NULL count:0];
10335 for (int i = 0; i < 2; ++i) {
10336 if (dictionary->_valueSet[i]) {
10337 _values[i] = dictionary->_values[i];
10338 _valueSet[i] = YES;
10346 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
10347 return [self initWithUInt64s:NULL forKeys:NULL count:0];
10350 #if !defined(NS_BLOCK_ASSERTIONS)
10352 NSAssert(!_autocreator,
10353 @"%@: Autocreator must be cleared before release, autocreator: %@",
10354 [self class], _autocreator);
10357 #endif // !defined(NS_BLOCK_ASSERTIONS)
10359 - (instancetype)copyWithZone:(NSZone *)zone {
10360 return [[GPBBoolUInt64Dictionary allocWithZone:zone] initWithDictionary:self];
10363 - (BOOL)isEqual:(id)other {
10364 if (self == other) {
10367 if (![other isKindOfClass:[GPBBoolUInt64Dictionary class]]) {
10370 GPBBoolUInt64Dictionary *otherDictionary = other;
10371 if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
10372 (_valueSet[1] != otherDictionary->_valueSet[1])) {
10375 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
10376 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
10382 - (NSUInteger)hash {
10383 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
10386 - (NSString *)description {
10387 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
10388 if (_valueSet[0]) {
10389 [result appendFormat:@"NO: %llu", _values[0]];
10391 if (_valueSet[1]) {
10392 [result appendFormat:@"YES: %llu", _values[1]];
10394 [result appendString:@" }"];
10398 - (NSUInteger)count {
10399 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
10402 - (BOOL)getUInt64:(uint64_t *)value forKey:(BOOL)key {
10403 int idx = (key ? 1 : 0);
10404 if (_valueSet[idx]) {
10406 *value = _values[idx];
10413 - (void)setGPBGenericValue:(GPBGenericValue *)value
10414 forGPBGenericValueKey:(GPBGenericValue *)key {
10415 int idx = (key->valueBool ? 1 : 0);
10416 _values[idx] = value->valueUInt64;
10417 _valueSet[idx] = YES;
10420 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
10421 if (_valueSet[0]) {
10422 block(@"false", [NSString stringWithFormat:@"%llu", _values[0]]);
10424 if (_valueSet[1]) {
10425 block(@"true", [NSString stringWithFormat:@"%llu", _values[1]]);
10429 - (void)enumerateKeysAndUInt64sUsingBlock:
10430 (void (NS_NOESCAPE ^)(BOOL key, uint64_t value, BOOL *stop))block {
10432 if (_valueSet[0]) {
10433 block(NO, _values[0], &stop);
10435 if (!stop && _valueSet[1]) {
10436 block(YES, _values[1], &stop);
10440 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
10441 GPBDataType valueDataType = GPBGetFieldDataType(field);
10442 NSUInteger count = 0;
10444 for (int i = 0; i < 2; ++i) {
10445 if (_valueSet[i]) {
10447 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10448 msgSize += ComputeDictUInt64FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
10449 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
10452 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
10453 result += tagSize * count;
10457 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
10458 asField:(GPBFieldDescriptor *)field {
10459 GPBDataType valueDataType = GPBGetFieldDataType(field);
10460 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
10461 for (int i = 0; i < 2; ++i) {
10462 if (_valueSet[i]) {
10464 [outputStream writeInt32NoTag:tag];
10465 // Write the size of the message.
10466 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10467 msgSize += ComputeDictUInt64FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
10468 [outputStream writeInt32NoTag:(int32_t)msgSize];
10469 // Write the fields.
10470 WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10471 WriteDictUInt64Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
10476 - (void)addEntriesFromDictionary:(GPBBoolUInt64Dictionary *)otherDictionary {
10477 if (otherDictionary) {
10478 for (int i = 0; i < 2; ++i) {
10479 if (otherDictionary->_valueSet[i]) {
10480 _valueSet[i] = YES;
10481 _values[i] = otherDictionary->_values[i];
10484 if (_autocreator) {
10485 GPBAutocreatedDictionaryModified(_autocreator, self);
10490 - (void)setUInt64:(uint64_t)value forKey:(BOOL)key {
10491 int idx = (key ? 1 : 0);
10492 _values[idx] = value;
10493 _valueSet[idx] = YES;
10494 if (_autocreator) {
10495 GPBAutocreatedDictionaryModified(_autocreator, self);
10499 - (void)removeUInt64ForKey:(BOOL)aKey {
10500 _valueSet[aKey ? 1 : 0] = NO;
10503 - (void)removeAll {
10510 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Int64, int64_t)
10511 // This block of code is generated, do not edit it directly.
10513 #pragma mark - Bool -> Int64
10515 @implementation GPBBoolInt64Dictionary {
10517 int64_t _values[2];
10521 - (instancetype)init {
10522 return [self initWithInt64s:NULL forKeys:NULL count:0];
10525 - (instancetype)initWithInt64s:(const int64_t [])values
10526 forKeys:(const BOOL [])keys
10527 count:(NSUInteger)count {
10528 self = [super init];
10530 for (NSUInteger i = 0; i < count; ++i) {
10531 int idx = keys[i] ? 1 : 0;
10532 _values[idx] = values[i];
10533 _valueSet[idx] = YES;
10539 - (instancetype)initWithDictionary:(GPBBoolInt64Dictionary *)dictionary {
10540 self = [self initWithInt64s:NULL forKeys:NULL count:0];
10543 for (int i = 0; i < 2; ++i) {
10544 if (dictionary->_valueSet[i]) {
10545 _values[i] = dictionary->_values[i];
10546 _valueSet[i] = YES;
10554 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
10555 return [self initWithInt64s:NULL forKeys:NULL count:0];
10558 #if !defined(NS_BLOCK_ASSERTIONS)
10560 NSAssert(!_autocreator,
10561 @"%@: Autocreator must be cleared before release, autocreator: %@",
10562 [self class], _autocreator);
10565 #endif // !defined(NS_BLOCK_ASSERTIONS)
10567 - (instancetype)copyWithZone:(NSZone *)zone {
10568 return [[GPBBoolInt64Dictionary allocWithZone:zone] initWithDictionary:self];
10571 - (BOOL)isEqual:(id)other {
10572 if (self == other) {
10575 if (![other isKindOfClass:[GPBBoolInt64Dictionary class]]) {
10578 GPBBoolInt64Dictionary *otherDictionary = other;
10579 if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
10580 (_valueSet[1] != otherDictionary->_valueSet[1])) {
10583 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
10584 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
10590 - (NSUInteger)hash {
10591 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
10594 - (NSString *)description {
10595 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
10596 if (_valueSet[0]) {
10597 [result appendFormat:@"NO: %lld", _values[0]];
10599 if (_valueSet[1]) {
10600 [result appendFormat:@"YES: %lld", _values[1]];
10602 [result appendString:@" }"];
10606 - (NSUInteger)count {
10607 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
10610 - (BOOL)getInt64:(int64_t *)value forKey:(BOOL)key {
10611 int idx = (key ? 1 : 0);
10612 if (_valueSet[idx]) {
10614 *value = _values[idx];
10621 - (void)setGPBGenericValue:(GPBGenericValue *)value
10622 forGPBGenericValueKey:(GPBGenericValue *)key {
10623 int idx = (key->valueBool ? 1 : 0);
10624 _values[idx] = value->valueInt64;
10625 _valueSet[idx] = YES;
10628 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
10629 if (_valueSet[0]) {
10630 block(@"false", [NSString stringWithFormat:@"%lld", _values[0]]);
10632 if (_valueSet[1]) {
10633 block(@"true", [NSString stringWithFormat:@"%lld", _values[1]]);
10637 - (void)enumerateKeysAndInt64sUsingBlock:
10638 (void (NS_NOESCAPE ^)(BOOL key, int64_t value, BOOL *stop))block {
10640 if (_valueSet[0]) {
10641 block(NO, _values[0], &stop);
10643 if (!stop && _valueSet[1]) {
10644 block(YES, _values[1], &stop);
10648 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
10649 GPBDataType valueDataType = GPBGetFieldDataType(field);
10650 NSUInteger count = 0;
10652 for (int i = 0; i < 2; ++i) {
10653 if (_valueSet[i]) {
10655 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10656 msgSize += ComputeDictInt64FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
10657 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
10660 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
10661 result += tagSize * count;
10665 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
10666 asField:(GPBFieldDescriptor *)field {
10667 GPBDataType valueDataType = GPBGetFieldDataType(field);
10668 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
10669 for (int i = 0; i < 2; ++i) {
10670 if (_valueSet[i]) {
10672 [outputStream writeInt32NoTag:tag];
10673 // Write the size of the message.
10674 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10675 msgSize += ComputeDictInt64FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
10676 [outputStream writeInt32NoTag:(int32_t)msgSize];
10677 // Write the fields.
10678 WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10679 WriteDictInt64Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
10684 - (void)addEntriesFromDictionary:(GPBBoolInt64Dictionary *)otherDictionary {
10685 if (otherDictionary) {
10686 for (int i = 0; i < 2; ++i) {
10687 if (otherDictionary->_valueSet[i]) {
10688 _valueSet[i] = YES;
10689 _values[i] = otherDictionary->_values[i];
10692 if (_autocreator) {
10693 GPBAutocreatedDictionaryModified(_autocreator, self);
10698 - (void)setInt64:(int64_t)value forKey:(BOOL)key {
10699 int idx = (key ? 1 : 0);
10700 _values[idx] = value;
10701 _valueSet[idx] = YES;
10702 if (_autocreator) {
10703 GPBAutocreatedDictionaryModified(_autocreator, self);
10707 - (void)removeInt64ForKey:(BOOL)aKey {
10708 _valueSet[aKey ? 1 : 0] = NO;
10711 - (void)removeAll {
10718 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Bool, BOOL)
10719 // This block of code is generated, do not edit it directly.
10721 #pragma mark - Bool -> Bool
10723 @implementation GPBBoolBoolDictionary {
10729 - (instancetype)init {
10730 return [self initWithBools:NULL forKeys:NULL count:0];
10733 - (instancetype)initWithBools:(const BOOL [])values
10734 forKeys:(const BOOL [])keys
10735 count:(NSUInteger)count {
10736 self = [super init];
10738 for (NSUInteger i = 0; i < count; ++i) {
10739 int idx = keys[i] ? 1 : 0;
10740 _values[idx] = values[i];
10741 _valueSet[idx] = YES;
10747 - (instancetype)initWithDictionary:(GPBBoolBoolDictionary *)dictionary {
10748 self = [self initWithBools:NULL forKeys:NULL count:0];
10751 for (int i = 0; i < 2; ++i) {
10752 if (dictionary->_valueSet[i]) {
10753 _values[i] = dictionary->_values[i];
10754 _valueSet[i] = YES;
10762 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
10763 return [self initWithBools:NULL forKeys:NULL count:0];
10766 #if !defined(NS_BLOCK_ASSERTIONS)
10768 NSAssert(!_autocreator,
10769 @"%@: Autocreator must be cleared before release, autocreator: %@",
10770 [self class], _autocreator);
10773 #endif // !defined(NS_BLOCK_ASSERTIONS)
10775 - (instancetype)copyWithZone:(NSZone *)zone {
10776 return [[GPBBoolBoolDictionary allocWithZone:zone] initWithDictionary:self];
10779 - (BOOL)isEqual:(id)other {
10780 if (self == other) {
10783 if (![other isKindOfClass:[GPBBoolBoolDictionary class]]) {
10786 GPBBoolBoolDictionary *otherDictionary = other;
10787 if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
10788 (_valueSet[1] != otherDictionary->_valueSet[1])) {
10791 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
10792 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
10798 - (NSUInteger)hash {
10799 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
10802 - (NSString *)description {
10803 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
10804 if (_valueSet[0]) {
10805 [result appendFormat:@"NO: %d", _values[0]];
10807 if (_valueSet[1]) {
10808 [result appendFormat:@"YES: %d", _values[1]];
10810 [result appendString:@" }"];
10814 - (NSUInteger)count {
10815 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
10818 - (BOOL)getBool:(BOOL *)value forKey:(BOOL)key {
10819 int idx = (key ? 1 : 0);
10820 if (_valueSet[idx]) {
10822 *value = _values[idx];
10829 - (void)setGPBGenericValue:(GPBGenericValue *)value
10830 forGPBGenericValueKey:(GPBGenericValue *)key {
10831 int idx = (key->valueBool ? 1 : 0);
10832 _values[idx] = value->valueBool;
10833 _valueSet[idx] = YES;
10836 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
10837 if (_valueSet[0]) {
10838 block(@"false", (_values[0] ? @"true" : @"false"));
10840 if (_valueSet[1]) {
10841 block(@"true", (_values[1] ? @"true" : @"false"));
10845 - (void)enumerateKeysAndBoolsUsingBlock:
10846 (void (NS_NOESCAPE ^)(BOOL key, BOOL value, BOOL *stop))block {
10848 if (_valueSet[0]) {
10849 block(NO, _values[0], &stop);
10851 if (!stop && _valueSet[1]) {
10852 block(YES, _values[1], &stop);
10856 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
10857 GPBDataType valueDataType = GPBGetFieldDataType(field);
10858 NSUInteger count = 0;
10860 for (int i = 0; i < 2; ++i) {
10861 if (_valueSet[i]) {
10863 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10864 msgSize += ComputeDictBoolFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
10865 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
10868 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
10869 result += tagSize * count;
10873 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
10874 asField:(GPBFieldDescriptor *)field {
10875 GPBDataType valueDataType = GPBGetFieldDataType(field);
10876 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
10877 for (int i = 0; i < 2; ++i) {
10878 if (_valueSet[i]) {
10880 [outputStream writeInt32NoTag:tag];
10881 // Write the size of the message.
10882 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10883 msgSize += ComputeDictBoolFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
10884 [outputStream writeInt32NoTag:(int32_t)msgSize];
10885 // Write the fields.
10886 WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10887 WriteDictBoolField(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
10892 - (void)addEntriesFromDictionary:(GPBBoolBoolDictionary *)otherDictionary {
10893 if (otherDictionary) {
10894 for (int i = 0; i < 2; ++i) {
10895 if (otherDictionary->_valueSet[i]) {
10896 _valueSet[i] = YES;
10897 _values[i] = otherDictionary->_values[i];
10900 if (_autocreator) {
10901 GPBAutocreatedDictionaryModified(_autocreator, self);
10906 - (void)setBool:(BOOL)value forKey:(BOOL)key {
10907 int idx = (key ? 1 : 0);
10908 _values[idx] = value;
10909 _valueSet[idx] = YES;
10910 if (_autocreator) {
10911 GPBAutocreatedDictionaryModified(_autocreator, self);
10915 - (void)removeBoolForKey:(BOOL)aKey {
10916 _valueSet[aKey ? 1 : 0] = NO;
10919 - (void)removeAll {
10926 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Float, float)
10927 // This block of code is generated, do not edit it directly.
10929 #pragma mark - Bool -> Float
10931 @implementation GPBBoolFloatDictionary {
10937 - (instancetype)init {
10938 return [self initWithFloats:NULL forKeys:NULL count:0];
10941 - (instancetype)initWithFloats:(const float [])values
10942 forKeys:(const BOOL [])keys
10943 count:(NSUInteger)count {
10944 self = [super init];
10946 for (NSUInteger i = 0; i < count; ++i) {
10947 int idx = keys[i] ? 1 : 0;
10948 _values[idx] = values[i];
10949 _valueSet[idx] = YES;
10955 - (instancetype)initWithDictionary:(GPBBoolFloatDictionary *)dictionary {
10956 self = [self initWithFloats:NULL forKeys:NULL count:0];
10959 for (int i = 0; i < 2; ++i) {
10960 if (dictionary->_valueSet[i]) {
10961 _values[i] = dictionary->_values[i];
10962 _valueSet[i] = YES;
10970 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
10971 return [self initWithFloats:NULL forKeys:NULL count:0];
10974 #if !defined(NS_BLOCK_ASSERTIONS)
10976 NSAssert(!_autocreator,
10977 @"%@: Autocreator must be cleared before release, autocreator: %@",
10978 [self class], _autocreator);
10981 #endif // !defined(NS_BLOCK_ASSERTIONS)
10983 - (instancetype)copyWithZone:(NSZone *)zone {
10984 return [[GPBBoolFloatDictionary allocWithZone:zone] initWithDictionary:self];
10987 - (BOOL)isEqual:(id)other {
10988 if (self == other) {
10991 if (![other isKindOfClass:[GPBBoolFloatDictionary class]]) {
10994 GPBBoolFloatDictionary *otherDictionary = other;
10995 if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
10996 (_valueSet[1] != otherDictionary->_valueSet[1])) {
10999 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
11000 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
11006 - (NSUInteger)hash {
11007 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
11010 - (NSString *)description {
11011 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
11012 if (_valueSet[0]) {
11013 [result appendFormat:@"NO: %f", _values[0]];
11015 if (_valueSet[1]) {
11016 [result appendFormat:@"YES: %f", _values[1]];
11018 [result appendString:@" }"];
11022 - (NSUInteger)count {
11023 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
11026 - (BOOL)getFloat:(float *)value forKey:(BOOL)key {
11027 int idx = (key ? 1 : 0);
11028 if (_valueSet[idx]) {
11030 *value = _values[idx];
11037 - (void)setGPBGenericValue:(GPBGenericValue *)value
11038 forGPBGenericValueKey:(GPBGenericValue *)key {
11039 int idx = (key->valueBool ? 1 : 0);
11040 _values[idx] = value->valueFloat;
11041 _valueSet[idx] = YES;
11044 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
11045 if (_valueSet[0]) {
11046 block(@"false", [NSString stringWithFormat:@"%.*g", FLT_DIG, _values[0]]);
11048 if (_valueSet[1]) {
11049 block(@"true", [NSString stringWithFormat:@"%.*g", FLT_DIG, _values[1]]);
11053 - (void)enumerateKeysAndFloatsUsingBlock:
11054 (void (NS_NOESCAPE ^)(BOOL key, float value, BOOL *stop))block {
11056 if (_valueSet[0]) {
11057 block(NO, _values[0], &stop);
11059 if (!stop && _valueSet[1]) {
11060 block(YES, _values[1], &stop);
11064 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
11065 GPBDataType valueDataType = GPBGetFieldDataType(field);
11066 NSUInteger count = 0;
11068 for (int i = 0; i < 2; ++i) {
11069 if (_valueSet[i]) {
11071 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11072 msgSize += ComputeDictFloatFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
11073 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
11076 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
11077 result += tagSize * count;
11081 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
11082 asField:(GPBFieldDescriptor *)field {
11083 GPBDataType valueDataType = GPBGetFieldDataType(field);
11084 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
11085 for (int i = 0; i < 2; ++i) {
11086 if (_valueSet[i]) {
11088 [outputStream writeInt32NoTag:tag];
11089 // Write the size of the message.
11090 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11091 msgSize += ComputeDictFloatFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
11092 [outputStream writeInt32NoTag:(int32_t)msgSize];
11093 // Write the fields.
11094 WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11095 WriteDictFloatField(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
11100 - (void)addEntriesFromDictionary:(GPBBoolFloatDictionary *)otherDictionary {
11101 if (otherDictionary) {
11102 for (int i = 0; i < 2; ++i) {
11103 if (otherDictionary->_valueSet[i]) {
11104 _valueSet[i] = YES;
11105 _values[i] = otherDictionary->_values[i];
11108 if (_autocreator) {
11109 GPBAutocreatedDictionaryModified(_autocreator, self);
11114 - (void)setFloat:(float)value forKey:(BOOL)key {
11115 int idx = (key ? 1 : 0);
11116 _values[idx] = value;
11117 _valueSet[idx] = YES;
11118 if (_autocreator) {
11119 GPBAutocreatedDictionaryModified(_autocreator, self);
11123 - (void)removeFloatForKey:(BOOL)aKey {
11124 _valueSet[aKey ? 1 : 0] = NO;
11127 - (void)removeAll {
11134 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Double, double)
11135 // This block of code is generated, do not edit it directly.
11137 #pragma mark - Bool -> Double
11139 @implementation GPBBoolDoubleDictionary {
11145 - (instancetype)init {
11146 return [self initWithDoubles:NULL forKeys:NULL count:0];
11149 - (instancetype)initWithDoubles:(const double [])values
11150 forKeys:(const BOOL [])keys
11151 count:(NSUInteger)count {
11152 self = [super init];
11154 for (NSUInteger i = 0; i < count; ++i) {
11155 int idx = keys[i] ? 1 : 0;
11156 _values[idx] = values[i];
11157 _valueSet[idx] = YES;
11163 - (instancetype)initWithDictionary:(GPBBoolDoubleDictionary *)dictionary {
11164 self = [self initWithDoubles:NULL forKeys:NULL count:0];
11167 for (int i = 0; i < 2; ++i) {
11168 if (dictionary->_valueSet[i]) {
11169 _values[i] = dictionary->_values[i];
11170 _valueSet[i] = YES;
11178 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
11179 return [self initWithDoubles:NULL forKeys:NULL count:0];
11182 #if !defined(NS_BLOCK_ASSERTIONS)
11184 NSAssert(!_autocreator,
11185 @"%@: Autocreator must be cleared before release, autocreator: %@",
11186 [self class], _autocreator);
11189 #endif // !defined(NS_BLOCK_ASSERTIONS)
11191 - (instancetype)copyWithZone:(NSZone *)zone {
11192 return [[GPBBoolDoubleDictionary allocWithZone:zone] initWithDictionary:self];
11195 - (BOOL)isEqual:(id)other {
11196 if (self == other) {
11199 if (![other isKindOfClass:[GPBBoolDoubleDictionary class]]) {
11202 GPBBoolDoubleDictionary *otherDictionary = other;
11203 if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
11204 (_valueSet[1] != otherDictionary->_valueSet[1])) {
11207 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
11208 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
11214 - (NSUInteger)hash {
11215 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
11218 - (NSString *)description {
11219 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
11220 if (_valueSet[0]) {
11221 [result appendFormat:@"NO: %lf", _values[0]];
11223 if (_valueSet[1]) {
11224 [result appendFormat:@"YES: %lf", _values[1]];
11226 [result appendString:@" }"];
11230 - (NSUInteger)count {
11231 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
11234 - (BOOL)getDouble:(double *)value forKey:(BOOL)key {
11235 int idx = (key ? 1 : 0);
11236 if (_valueSet[idx]) {
11238 *value = _values[idx];
11245 - (void)setGPBGenericValue:(GPBGenericValue *)value
11246 forGPBGenericValueKey:(GPBGenericValue *)key {
11247 int idx = (key->valueBool ? 1 : 0);
11248 _values[idx] = value->valueDouble;
11249 _valueSet[idx] = YES;
11252 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
11253 if (_valueSet[0]) {
11254 block(@"false", [NSString stringWithFormat:@"%.*lg", DBL_DIG, _values[0]]);
11256 if (_valueSet[1]) {
11257 block(@"true", [NSString stringWithFormat:@"%.*lg", DBL_DIG, _values[1]]);
11261 - (void)enumerateKeysAndDoublesUsingBlock:
11262 (void (NS_NOESCAPE ^)(BOOL key, double value, BOOL *stop))block {
11264 if (_valueSet[0]) {
11265 block(NO, _values[0], &stop);
11267 if (!stop && _valueSet[1]) {
11268 block(YES, _values[1], &stop);
11272 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
11273 GPBDataType valueDataType = GPBGetFieldDataType(field);
11274 NSUInteger count = 0;
11276 for (int i = 0; i < 2; ++i) {
11277 if (_valueSet[i]) {
11279 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11280 msgSize += ComputeDictDoubleFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
11281 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
11284 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
11285 result += tagSize * count;
11289 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
11290 asField:(GPBFieldDescriptor *)field {
11291 GPBDataType valueDataType = GPBGetFieldDataType(field);
11292 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
11293 for (int i = 0; i < 2; ++i) {
11294 if (_valueSet[i]) {
11296 [outputStream writeInt32NoTag:tag];
11297 // Write the size of the message.
11298 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11299 msgSize += ComputeDictDoubleFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
11300 [outputStream writeInt32NoTag:(int32_t)msgSize];
11301 // Write the fields.
11302 WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11303 WriteDictDoubleField(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
11308 - (void)addEntriesFromDictionary:(GPBBoolDoubleDictionary *)otherDictionary {
11309 if (otherDictionary) {
11310 for (int i = 0; i < 2; ++i) {
11311 if (otherDictionary->_valueSet[i]) {
11312 _valueSet[i] = YES;
11313 _values[i] = otherDictionary->_values[i];
11316 if (_autocreator) {
11317 GPBAutocreatedDictionaryModified(_autocreator, self);
11322 - (void)setDouble:(double)value forKey:(BOOL)key {
11323 int idx = (key ? 1 : 0);
11324 _values[idx] = value;
11325 _valueSet[idx] = YES;
11326 if (_autocreator) {
11327 GPBAutocreatedDictionaryModified(_autocreator, self);
11331 - (void)removeDoubleForKey:(BOOL)aKey {
11332 _valueSet[aKey ? 1 : 0] = NO;
11335 - (void)removeAll {
11342 //%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_OBJECT_IMPL(Object, id)
11343 // This block of code is generated, do not edit it directly.
11345 #pragma mark - Bool -> Object
11347 @implementation GPBBoolObjectDictionary {
11352 - (instancetype)init {
11353 return [self initWithObjects:NULL forKeys:NULL count:0];
11356 - (instancetype)initWithObjects:(const id [])objects
11357 forKeys:(const BOOL [])keys
11358 count:(NSUInteger)count {
11359 self = [super init];
11361 for (NSUInteger i = 0; i < count; ++i) {
11363 [NSException raise:NSInvalidArgumentException
11364 format:@"Attempting to add nil object to a Dictionary"];
11366 int idx = keys[i] ? 1 : 0;
11367 [_values[idx] release];
11368 _values[idx] = (id)[objects[i] retain];
11374 - (instancetype)initWithDictionary:(GPBBoolObjectDictionary *)dictionary {
11375 self = [self initWithObjects:NULL forKeys:NULL count:0];
11378 _values[0] = [dictionary->_values[0] retain];
11379 _values[1] = [dictionary->_values[1] retain];
11385 - (instancetype)initWithCapacity:(__unused NSUInteger)numItems {
11386 return [self initWithObjects:NULL forKeys:NULL count:0];
11390 NSAssert(!_autocreator,
11391 @"%@: Autocreator must be cleared before release, autocreator: %@",
11392 [self class], _autocreator);
11393 [_values[0] release];
11394 [_values[1] release];
11398 - (instancetype)copyWithZone:(NSZone *)zone {
11399 return [[GPBBoolObjectDictionary allocWithZone:zone] initWithDictionary:self];
11402 - (BOOL)isEqual:(id)other {
11403 if (self == other) {
11406 if (![other isKindOfClass:[GPBBoolObjectDictionary class]]) {
11409 GPBBoolObjectDictionary *otherDictionary = other;
11410 if (((_values[0] != nil) != (otherDictionary->_values[0] != nil)) ||
11411 ((_values[1] != nil) != (otherDictionary->_values[1] != nil))) {
11414 if (((_values[0] != nil) && (![_values[0] isEqual:otherDictionary->_values[0]])) ||
11415 ((_values[1] != nil) && (![_values[1] isEqual:otherDictionary->_values[1]]))) {
11421 - (NSUInteger)hash {
11422 return ((_values[0] != nil) ? 1 : 0) + ((_values[1] != nil) ? 1 : 0);
11425 - (NSString *)description {
11426 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
11427 if ((_values[0] != nil)) {
11428 [result appendFormat:@"NO: %@", _values[0]];
11430 if ((_values[1] != nil)) {
11431 [result appendFormat:@"YES: %@", _values[1]];
11433 [result appendString:@" }"];
11437 - (NSUInteger)count {
11438 return ((_values[0] != nil) ? 1 : 0) + ((_values[1] != nil) ? 1 : 0);
11441 - (id)objectForKey:(BOOL)key {
11442 return _values[key ? 1 : 0];
11445 - (void)setGPBGenericValue:(GPBGenericValue *)value
11446 forGPBGenericValueKey:(GPBGenericValue *)key {
11447 int idx = (key->valueBool ? 1 : 0);
11448 [_values[idx] release];
11449 _values[idx] = [value->valueString retain];
11452 - (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
11453 if (_values[0] != nil) {
11454 block(@"false", _values[0]);
11456 if ((_values[1] != nil)) {
11457 block(@"true", _values[1]);
11461 - (void)enumerateKeysAndObjectsUsingBlock:
11462 (void (NS_NOESCAPE ^)(BOOL key, id object, BOOL *stop))block {
11464 if (_values[0] != nil) {
11465 block(NO, _values[0], &stop);
11467 if (!stop && (_values[1] != nil)) {
11468 block(YES, _values[1], &stop);
11472 - (BOOL)isInitialized {
11473 if (_values[0] && ![_values[0] isInitialized]) {
11476 if (_values[1] && ![_values[1] isInitialized]) {
11482 - (instancetype)deepCopyWithZone:(NSZone *)zone {
11483 GPBBoolObjectDictionary *newDict =
11484 [[GPBBoolObjectDictionary alloc] init];
11485 for (int i = 0; i < 2; ++i) {
11486 if (_values[i] != nil) {
11487 newDict->_values[i] = [_values[i] copyWithZone:zone];
11493 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
11494 GPBDataType valueDataType = GPBGetFieldDataType(field);
11495 NSUInteger count = 0;
11497 for (int i = 0; i < 2; ++i) {
11498 if (_values[i] != nil) {
11500 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11501 msgSize += ComputeDictObjectFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
11502 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
11505 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
11506 result += tagSize * count;
11510 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
11511 asField:(GPBFieldDescriptor *)field {
11512 GPBDataType valueDataType = GPBGetFieldDataType(field);
11513 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
11514 for (int i = 0; i < 2; ++i) {
11515 if (_values[i] != nil) {
11517 [outputStream writeInt32NoTag:tag];
11518 // Write the size of the message.
11519 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11520 msgSize += ComputeDictObjectFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
11521 [outputStream writeInt32NoTag:(int32_t)msgSize];
11522 // Write the fields.
11523 WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11524 WriteDictObjectField(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
11529 - (void)addEntriesFromDictionary:(GPBBoolObjectDictionary *)otherDictionary {
11530 if (otherDictionary) {
11531 for (int i = 0; i < 2; ++i) {
11532 if (otherDictionary->_values[i] != nil) {
11533 [_values[i] release];
11534 _values[i] = [otherDictionary->_values[i] retain];
11537 if (_autocreator) {
11538 GPBAutocreatedDictionaryModified(_autocreator, self);
11543 - (void)setObject:(id)object forKey:(BOOL)key {
11545 [NSException raise:NSInvalidArgumentException
11546 format:@"Attempting to add nil object to a Dictionary"];
11548 int idx = (key ? 1 : 0);
11549 [_values[idx] release];
11550 _values[idx] = [object retain];
11551 if (_autocreator) {
11552 GPBAutocreatedDictionaryModified(_autocreator, self);
11556 - (void)removeObjectForKey:(BOOL)aKey {
11557 int idx = (aKey ? 1 : 0);
11558 [_values[idx] release];
11559 _values[idx] = nil;
11562 - (void)removeAll {
11563 for (int i = 0; i < 2; ++i) {
11564 [_values[i] release];
11571 //%PDDM-EXPAND-END (8 expansions)
11575 #pragma mark - Bool -> Enum
11577 @implementation GPBBoolEnumDictionary {
11579 GPBEnumValidationFunc _validationFunc;
11580 int32_t _values[2];
11584 @synthesize validationFunc = _validationFunc;
11586 - (instancetype)init {
11587 return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
11590 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
11591 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
11594 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
11595 rawValues:(const int32_t[])rawValues
11596 forKeys:(const BOOL[])keys
11597 count:(NSUInteger)count {
11598 self = [super init];
11600 _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
11601 for (NSUInteger i = 0; i < count; ++i) {
11602 int idx = keys[i] ? 1 : 0;
11603 _values[idx] = rawValues[i];
11604 _valueSet[idx] = YES;
11610 - (instancetype)initWithDictionary:(GPBBoolEnumDictionary *)dictionary {
11611 self = [self initWithValidationFunction:dictionary.validationFunc
11617 for (int i = 0; i < 2; ++i) {
11618 if (dictionary->_valueSet[i]) {
11619 _values[i] = dictionary->_values[i];
11620 _valueSet[i] = YES;
11628 - (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
11629 capacity:(__unused NSUInteger)numItems {
11630 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
11633 #if !defined(NS_BLOCK_ASSERTIONS)
11635 NSAssert(!_autocreator, @"%@: Autocreator must be cleared before release, autocreator: %@",
11636 [self class], _autocreator);
11639 #endif // !defined(NS_BLOCK_ASSERTIONS)
11641 - (instancetype)copyWithZone:(NSZone *)zone {
11642 return [[GPBBoolEnumDictionary allocWithZone:zone] initWithDictionary:self];
11645 - (BOOL)isEqual:(id)other {
11646 if (self == other) {
11649 if (![other isKindOfClass:[GPBBoolEnumDictionary class]]) {
11652 GPBBoolEnumDictionary *otherDictionary = other;
11653 if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
11654 (_valueSet[1] != otherDictionary->_valueSet[1])) {
11657 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
11658 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
11664 - (NSUInteger)hash {
11665 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
11668 - (NSString *)description {
11669 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
11670 if (_valueSet[0]) {
11671 [result appendFormat:@"NO: %d", _values[0]];
11673 if (_valueSet[1]) {
11674 [result appendFormat:@"YES: %d", _values[1]];
11676 [result appendString:@" }"];
11680 - (NSUInteger)count {
11681 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
11684 - (BOOL)getEnum:(int32_t *)value forKey:(BOOL)key {
11685 int idx = (key ? 1 : 0);
11686 if (_valueSet[idx]) {
11688 int32_t result = _values[idx];
11689 if (!_validationFunc(result)) {
11690 result = kGPBUnrecognizedEnumeratorValue;
11699 - (BOOL)getRawValue:(int32_t *)rawValue forKey:(BOOL)key {
11700 int idx = (key ? 1 : 0);
11701 if (_valueSet[idx]) {
11703 *rawValue = _values[idx];
11710 - (void)enumerateKeysAndRawValuesUsingBlock:(void(NS_NOESCAPE ^)(BOOL key, int32_t value,
11711 BOOL *stop))block {
11713 if (_valueSet[0]) {
11714 block(NO, _values[0], &stop);
11716 if (!stop && _valueSet[1]) {
11717 block(YES, _values[1], &stop);
11721 - (void)enumerateKeysAndEnumsUsingBlock:(void(NS_NOESCAPE ^)(BOOL key, int32_t rawValue,
11722 BOOL *stop))block {
11724 GPBEnumValidationFunc func = _validationFunc;
11725 int32_t validatedValue;
11726 if (_valueSet[0]) {
11727 validatedValue = _values[0];
11728 if (!func(validatedValue)) {
11729 validatedValue = kGPBUnrecognizedEnumeratorValue;
11731 block(NO, validatedValue, &stop);
11733 if (!stop && _valueSet[1]) {
11734 validatedValue = _values[1];
11735 if (!func(validatedValue)) {
11736 validatedValue = kGPBUnrecognizedEnumeratorValue;
11738 block(YES, validatedValue, &stop);
11742 // clang-format off
11744 //%PDDM-EXPAND SERIAL_DATA_FOR_ENTRY_POD_Enum(Bool)
11745 // This block of code is generated, do not edit it directly.
11747 - (NSData *)serializedDataForUnknownValue:(int32_t)value
11748 forKey:(GPBGenericValue *)key
11749 keyDataType:(GPBDataType)keyDataType {
11750 size_t msgSize = ComputeDictBoolFieldSize(key->valueBool, kMapKeyFieldNumber, keyDataType);
11751 msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
11752 NSMutableData *data = [NSMutableData dataWithLength:msgSize];
11753 GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
11754 WriteDictBoolField(outputStream, key->valueBool, kMapKeyFieldNumber, keyDataType);
11755 WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
11756 [outputStream flush];
11757 [outputStream release];
11761 //%PDDM-EXPAND-END SERIAL_DATA_FOR_ENTRY_POD_Enum(Bool)
11765 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
11766 GPBDataType valueDataType = GPBGetFieldDataType(field);
11767 NSUInteger count = 0;
11769 for (int i = 0; i < 2; ++i) {
11770 if (_valueSet[i]) {
11772 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11773 msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
11774 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
11777 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
11778 result += tagSize * count;
11782 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
11783 asField:(GPBFieldDescriptor *)field {
11784 GPBDataType valueDataType = GPBGetFieldDataType(field);
11785 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
11786 for (int i = 0; i < 2; ++i) {
11787 if (_valueSet[i]) {
11789 [outputStream writeInt32NoTag:tag];
11790 // Write the size of the message.
11791 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11792 msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
11793 [outputStream writeInt32NoTag:(int32_t)msgSize];
11794 // Write the fields.
11795 WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11796 WriteDictInt32Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
11801 - (void)enumerateForTextFormat:(void(NS_NOESCAPE ^)(id keyObj, id valueObj))block {
11802 if (_valueSet[0]) {
11803 block(@"false", @(_values[0]));
11805 if (_valueSet[1]) {
11806 block(@"true", @(_values[1]));
11810 - (void)setGPBGenericValue:(GPBGenericValue *)value forGPBGenericValueKey:(GPBGenericValue *)key {
11811 int idx = (key->valueBool ? 1 : 0);
11812 _values[idx] = value->valueInt32;
11813 _valueSet[idx] = YES;
11816 - (void)addRawEntriesFromDictionary:(GPBBoolEnumDictionary *)otherDictionary {
11817 if (otherDictionary) {
11818 for (int i = 0; i < 2; ++i) {
11819 if (otherDictionary->_valueSet[i]) {
11820 _valueSet[i] = YES;
11821 _values[i] = otherDictionary->_values[i];
11824 if (_autocreator) {
11825 GPBAutocreatedDictionaryModified(_autocreator, self);
11830 - (void)setEnum:(int32_t)value forKey:(BOOL)key {
11831 if (!_validationFunc(value)) {
11832 [NSException raise:NSInvalidArgumentException
11833 format:@"GPBBoolEnumDictionary: Attempt to set an unknown enum value (%d)", value];
11835 int idx = (key ? 1 : 0);
11836 _values[idx] = value;
11837 _valueSet[idx] = YES;
11838 if (_autocreator) {
11839 GPBAutocreatedDictionaryModified(_autocreator, self);
11843 - (void)setRawValue:(int32_t)rawValue forKey:(BOOL)key {
11844 int idx = (key ? 1 : 0);
11845 _values[idx] = rawValue;
11846 _valueSet[idx] = YES;
11847 if (_autocreator) {
11848 GPBAutocreatedDictionaryModified(_autocreator, self);
11852 - (void)removeEnumForKey:(BOOL)aKey {
11853 _valueSet[aKey ? 1 : 0] = NO;
11856 - (void)removeAll {
11863 #pragma mark - NSDictionary Subclass
11865 @implementation GPBAutocreatedDictionary {
11866 NSMutableDictionary *_dictionary;
11870 NSAssert(!_autocreator, @"%@: Autocreator must be cleared before release, autocreator: %@",
11871 [self class], _autocreator);
11872 [_dictionary release];
11876 #pragma mark Required NSDictionary overrides
11878 - (instancetype)initWithObjects:(const id[])objects
11879 forKeys:(const id<NSCopying>[])keys
11880 count:(NSUInteger)count {
11881 self = [super init];
11883 _dictionary = [[NSMutableDictionary alloc] initWithObjects:objects forKeys:keys count:count];
11888 - (NSUInteger)count {
11889 return [_dictionary count];
11892 - (id)objectForKey:(id)aKey {
11893 return [_dictionary objectForKey:aKey];
11896 - (NSEnumerator *)keyEnumerator {
11897 if (_dictionary == nil) {
11898 _dictionary = [[NSMutableDictionary alloc] init];
11900 return [_dictionary keyEnumerator];
11903 #pragma mark Required NSMutableDictionary overrides
11905 // Only need to call GPBAutocreatedDictionaryModified() when adding things
11906 // since we only autocreate empty dictionaries.
11908 - (void)setObject:(id)anObject forKey:(id<NSCopying>)aKey {
11909 if (_dictionary == nil) {
11910 _dictionary = [[NSMutableDictionary alloc] init];
11912 [_dictionary setObject:anObject forKey:aKey];
11913 if (_autocreator) {
11914 GPBAutocreatedDictionaryModified(_autocreator, self);
11918 - (void)removeObjectForKey:(id)aKey {
11919 [_dictionary removeObjectForKey:aKey];
11922 #pragma mark Extra things hooked
11924 - (id)copyWithZone:(NSZone *)zone {
11925 if (_dictionary == nil) {
11926 return [[NSMutableDictionary allocWithZone:zone] init];
11928 return [_dictionary copyWithZone:zone];
11931 - (id)mutableCopyWithZone:(NSZone *)zone {
11932 if (_dictionary == nil) {
11933 return [[NSMutableDictionary allocWithZone:zone] init];
11935 return [_dictionary mutableCopyWithZone:zone];
11938 // Not really needed, but subscripting is likely common enough it doesn't hurt
11939 // to ensure it goes directly to the real NSMutableDictionary.
11940 - (id)objectForKeyedSubscript:(id)key {
11941 return [_dictionary objectForKeyedSubscript:key];
11944 // Not really needed, but subscripting is likely common enough it doesn't hurt
11945 // to ensure it goes directly to the real NSMutableDictionary.
11946 - (void)setObject:(id)obj forKeyedSubscript:(id<NSCopying>)key {
11947 if (_dictionary == nil) {
11948 _dictionary = [[NSMutableDictionary alloc] init];
11950 [_dictionary setObject:obj forKeyedSubscript:key];
11951 if (_autocreator) {
11952 GPBAutocreatedDictionaryModified(_autocreator, self);
11956 - (void)enumerateKeysAndObjectsUsingBlock:(void(NS_NOESCAPE ^)(id key, id obj, BOOL *stop))block {
11957 [_dictionary enumerateKeysAndObjectsUsingBlock:block];
11960 - (void)enumerateKeysAndObjectsWithOptions:(NSEnumerationOptions)opts
11961 usingBlock:(void(NS_NOESCAPE ^)(id key, id obj, BOOL *stop))block {
11962 [_dictionary enumerateKeysAndObjectsWithOptions:opts usingBlock:block];
11967 #pragma clang diagnostic pop