1// Protocol Buffers - Google's data interchange format 2// Copyright 2008 Google Inc. All rights reserved. 3// https://developers.google.com/protocol-buffers/ 4// 5// Redistribution and use in source and binary forms, with or without 6// modification, are permitted provided that the following conditions are 7// met: 8// 9// * Redistributions of source code must retain the above copyright 10// notice, this list of conditions and the following disclaimer. 11// * Redistributions in binary form must reproduce the above 12// copyright notice, this list of conditions and the following disclaimer 13// in the documentation and/or other materials provided with the 14// distribution. 15// * Neither the name of Google Inc. nor the names of its 16// contributors may be used to endorse or promote products derived from 17// this software without specific prior written permission. 18// 19// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 31#import "GPBDictionary_PackagePrivate.h" 32 33#import "GPBCodedInputStream_PackagePrivate.h" 34#import "GPBCodedOutputStream_PackagePrivate.h" 35#import "GPBDescriptor_PackagePrivate.h" 36#import "GPBMessage_PackagePrivate.h" 37#import "GPBUtilities_PackagePrivate.h" 38 39// ------------------------------ NOTE ------------------------------ 40// At the moment, this is all using NSNumbers in NSDictionaries under 41// the hood, but it is all hidden so we can come back and optimize 42// with direct CFDictionary usage later. The reason that wasn't 43// done yet is needing to support 32bit iOS builds. Otherwise 44// it would be pretty simple to store all this data in CFDictionaries 45// directly. 46// ------------------------------------------------------------------ 47 48// Direct access is use for speed, to avoid even internally declaring things 49// read/write, etc. The warning is enabled in the project to ensure code calling 50// protos can turn on -Wdirect-ivar-access without issues. 51#pragma clang diagnostic push 52#pragma clang diagnostic ignored "-Wdirect-ivar-access" 53 54// Used to include code only visible to specific versions of the static 55// analyzer. Useful for wrapping code that only exists to silence the analyzer. 56// Determine the values you want to use for BEGIN_APPLE_BUILD_VERSION, 57// END_APPLE_BUILD_VERSION using: 58// xcrun clang -dM -E -x c /dev/null | grep __apple_build_version__ 59// Example usage: 60// #if GPB_STATIC_ANALYZER_ONLY(5621, 5623) ... #endif 61#define GPB_STATIC_ANALYZER_ONLY(BEGIN_APPLE_BUILD_VERSION, END_APPLE_BUILD_VERSION) \ 62 (defined(__clang_analyzer__) && \ 63 (__apple_build_version__ >= BEGIN_APPLE_BUILD_VERSION && \ 64 __apple_build_version__ <= END_APPLE_BUILD_VERSION)) 65 66enum { 67 kMapKeyFieldNumber = 1, 68 kMapValueFieldNumber = 2, 69}; 70 71static BOOL DictDefault_IsValidValue(int32_t value) { 72 // Anything but the bad value marker is allowed. 73 return (value != kGPBUnrecognizedEnumeratorValue); 74} 75 76//%PDDM-DEFINE SERIALIZE_SUPPORT_2_TYPE(VALUE_NAME, VALUE_TYPE, GPBDATATYPE_NAME1, GPBDATATYPE_NAME2) 77//%static size_t ComputeDict##VALUE_NAME##FieldSize(VALUE_TYPE value, uint32_t fieldNum, GPBDataType dataType) { 78//% if (dataType == GPBDataType##GPBDATATYPE_NAME1) { 79//% return GPBCompute##GPBDATATYPE_NAME1##Size(fieldNum, value); 80//% } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) { 81//% return GPBCompute##GPBDATATYPE_NAME2##Size(fieldNum, value); 82//% } else { 83//% NSCAssert(NO, @"Unexpected type %d", dataType); 84//% return 0; 85//% } 86//%} 87//% 88//%static void WriteDict##VALUE_NAME##Field(GPBCodedOutputStream *stream, VALUE_TYPE value, uint32_t fieldNum, GPBDataType dataType) { 89//% if (dataType == GPBDataType##GPBDATATYPE_NAME1) { 90//% [stream write##GPBDATATYPE_NAME1##:fieldNum value:value]; 91//% } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) { 92//% [stream write##GPBDATATYPE_NAME2##:fieldNum value:value]; 93//% } else { 94//% NSCAssert(NO, @"Unexpected type %d", dataType); 95//% } 96//%} 97//% 98//%PDDM-DEFINE SERIALIZE_SUPPORT_3_TYPE(VALUE_NAME, VALUE_TYPE, GPBDATATYPE_NAME1, GPBDATATYPE_NAME2, GPBDATATYPE_NAME3) 99//%static size_t ComputeDict##VALUE_NAME##FieldSize(VALUE_TYPE value, uint32_t fieldNum, GPBDataType dataType) { 100//% if (dataType == GPBDataType##GPBDATATYPE_NAME1) { 101//% return GPBCompute##GPBDATATYPE_NAME1##Size(fieldNum, value); 102//% } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) { 103//% return GPBCompute##GPBDATATYPE_NAME2##Size(fieldNum, value); 104//% } else if (dataType == GPBDataType##GPBDATATYPE_NAME3) { 105//% return GPBCompute##GPBDATATYPE_NAME3##Size(fieldNum, value); 106//% } else { 107//% NSCAssert(NO, @"Unexpected type %d", dataType); 108//% return 0; 109//% } 110//%} 111//% 112//%static void WriteDict##VALUE_NAME##Field(GPBCodedOutputStream *stream, VALUE_TYPE value, uint32_t fieldNum, GPBDataType dataType) { 113//% if (dataType == GPBDataType##GPBDATATYPE_NAME1) { 114//% [stream write##GPBDATATYPE_NAME1##:fieldNum value:value]; 115//% } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) { 116//% [stream write##GPBDATATYPE_NAME2##:fieldNum value:value]; 117//% } else if (dataType == GPBDataType##GPBDATATYPE_NAME3) { 118//% [stream write##GPBDATATYPE_NAME3##:fieldNum value:value]; 119//% } else { 120//% NSCAssert(NO, @"Unexpected type %d", dataType); 121//% } 122//%} 123//% 124//%PDDM-DEFINE SIMPLE_SERIALIZE_SUPPORT(VALUE_NAME, VALUE_TYPE, VisP) 125//%static size_t ComputeDict##VALUE_NAME##FieldSize(VALUE_TYPE VisP##value, uint32_t fieldNum, GPBDataType dataType) { 126//% NSCAssert(dataType == GPBDataType##VALUE_NAME, @"bad type: %d", dataType); 127//% #pragma unused(dataType) // For when asserts are off in release. 128//% return GPBCompute##VALUE_NAME##Size(fieldNum, value); 129//%} 130//% 131//%static void WriteDict##VALUE_NAME##Field(GPBCodedOutputStream *stream, VALUE_TYPE VisP##value, uint32_t fieldNum, GPBDataType dataType) { 132//% NSCAssert(dataType == GPBDataType##VALUE_NAME, @"bad type: %d", dataType); 133//% #pragma unused(dataType) // For when asserts are off in release. 134//% [stream write##VALUE_NAME##:fieldNum value:value]; 135//%} 136//% 137//%PDDM-DEFINE SERIALIZE_SUPPORT_HELPERS() 138//%SERIALIZE_SUPPORT_3_TYPE(Int32, int32_t, Int32, SInt32, SFixed32) 139//%SERIALIZE_SUPPORT_2_TYPE(UInt32, uint32_t, UInt32, Fixed32) 140//%SERIALIZE_SUPPORT_3_TYPE(Int64, int64_t, Int64, SInt64, SFixed64) 141//%SERIALIZE_SUPPORT_2_TYPE(UInt64, uint64_t, UInt64, Fixed64) 142//%SIMPLE_SERIALIZE_SUPPORT(Bool, BOOL, ) 143//%SIMPLE_SERIALIZE_SUPPORT(Enum, int32_t, ) 144//%SIMPLE_SERIALIZE_SUPPORT(Float, float, ) 145//%SIMPLE_SERIALIZE_SUPPORT(Double, double, ) 146//%SIMPLE_SERIALIZE_SUPPORT(String, NSString, *) 147//%SERIALIZE_SUPPORT_3_TYPE(Object, id, Message, String, Bytes) 148//%PDDM-EXPAND SERIALIZE_SUPPORT_HELPERS() 149// This block of code is generated, do not edit it directly. 150// clang-format off 151 152static size_t ComputeDictInt32FieldSize(int32_t value, uint32_t fieldNum, GPBDataType dataType) { 153 if (dataType == GPBDataTypeInt32) { 154 return GPBComputeInt32Size(fieldNum, value); 155 } else if (dataType == GPBDataTypeSInt32) { 156 return GPBComputeSInt32Size(fieldNum, value); 157 } else if (dataType == GPBDataTypeSFixed32) { 158 return GPBComputeSFixed32Size(fieldNum, value); 159 } else { 160 NSCAssert(NO, @"Unexpected type %d", dataType); 161 return 0; 162 } 163} 164 165static void WriteDictInt32Field(GPBCodedOutputStream *stream, int32_t value, uint32_t fieldNum, GPBDataType dataType) { 166 if (dataType == GPBDataTypeInt32) { 167 [stream writeInt32:fieldNum value:value]; 168 } else if (dataType == GPBDataTypeSInt32) { 169 [stream writeSInt32:fieldNum value:value]; 170 } else if (dataType == GPBDataTypeSFixed32) { 171 [stream writeSFixed32:fieldNum value:value]; 172 } else { 173 NSCAssert(NO, @"Unexpected type %d", dataType); 174 } 175} 176 177static size_t ComputeDictUInt32FieldSize(uint32_t value, uint32_t fieldNum, GPBDataType dataType) { 178 if (dataType == GPBDataTypeUInt32) { 179 return GPBComputeUInt32Size(fieldNum, value); 180 } else if (dataType == GPBDataTypeFixed32) { 181 return GPBComputeFixed32Size(fieldNum, value); 182 } else { 183 NSCAssert(NO, @"Unexpected type %d", dataType); 184 return 0; 185 } 186} 187 188static void WriteDictUInt32Field(GPBCodedOutputStream *stream, uint32_t value, uint32_t fieldNum, GPBDataType dataType) { 189 if (dataType == GPBDataTypeUInt32) { 190 [stream writeUInt32:fieldNum value:value]; 191 } else if (dataType == GPBDataTypeFixed32) { 192 [stream writeFixed32:fieldNum value:value]; 193 } else { 194 NSCAssert(NO, @"Unexpected type %d", dataType); 195 } 196} 197 198static size_t ComputeDictInt64FieldSize(int64_t value, uint32_t fieldNum, GPBDataType dataType) { 199 if (dataType == GPBDataTypeInt64) { 200 return GPBComputeInt64Size(fieldNum, value); 201 } else if (dataType == GPBDataTypeSInt64) { 202 return GPBComputeSInt64Size(fieldNum, value); 203 } else if (dataType == GPBDataTypeSFixed64) { 204 return GPBComputeSFixed64Size(fieldNum, value); 205 } else { 206 NSCAssert(NO, @"Unexpected type %d", dataType); 207 return 0; 208 } 209} 210 211static void WriteDictInt64Field(GPBCodedOutputStream *stream, int64_t value, uint32_t fieldNum, GPBDataType dataType) { 212 if (dataType == GPBDataTypeInt64) { 213 [stream writeInt64:fieldNum value:value]; 214 } else if (dataType == GPBDataTypeSInt64) { 215 [stream writeSInt64:fieldNum value:value]; 216 } else if (dataType == GPBDataTypeSFixed64) { 217 [stream writeSFixed64:fieldNum value:value]; 218 } else { 219 NSCAssert(NO, @"Unexpected type %d", dataType); 220 } 221} 222 223static size_t ComputeDictUInt64FieldSize(uint64_t value, uint32_t fieldNum, GPBDataType dataType) { 224 if (dataType == GPBDataTypeUInt64) { 225 return GPBComputeUInt64Size(fieldNum, value); 226 } else if (dataType == GPBDataTypeFixed64) { 227 return GPBComputeFixed64Size(fieldNum, value); 228 } else { 229 NSCAssert(NO, @"Unexpected type %d", dataType); 230 return 0; 231 } 232} 233 234static void WriteDictUInt64Field(GPBCodedOutputStream *stream, uint64_t value, uint32_t fieldNum, GPBDataType dataType) { 235 if (dataType == GPBDataTypeUInt64) { 236 [stream writeUInt64:fieldNum value:value]; 237 } else if (dataType == GPBDataTypeFixed64) { 238 [stream writeFixed64:fieldNum value:value]; 239 } else { 240 NSCAssert(NO, @"Unexpected type %d", dataType); 241 } 242} 243 244static size_t ComputeDictBoolFieldSize(BOOL value, uint32_t fieldNum, GPBDataType dataType) { 245 NSCAssert(dataType == GPBDataTypeBool, @"bad type: %d", dataType); 246 #pragma unused(dataType) // For when asserts are off in release. 247 return GPBComputeBoolSize(fieldNum, value); 248} 249 250static void WriteDictBoolField(GPBCodedOutputStream *stream, BOOL value, uint32_t fieldNum, GPBDataType dataType) { 251 NSCAssert(dataType == GPBDataTypeBool, @"bad type: %d", dataType); 252 #pragma unused(dataType) // For when asserts are off in release. 253 [stream writeBool:fieldNum value:value]; 254} 255 256static size_t ComputeDictEnumFieldSize(int32_t value, uint32_t fieldNum, GPBDataType dataType) { 257 NSCAssert(dataType == GPBDataTypeEnum, @"bad type: %d", dataType); 258 #pragma unused(dataType) // For when asserts are off in release. 259 return GPBComputeEnumSize(fieldNum, value); 260} 261 262static void WriteDictEnumField(GPBCodedOutputStream *stream, int32_t value, uint32_t fieldNum, GPBDataType dataType) { 263 NSCAssert(dataType == GPBDataTypeEnum, @"bad type: %d", dataType); 264 #pragma unused(dataType) // For when asserts are off in release. 265 [stream writeEnum:fieldNum value:value]; 266} 267 268static size_t ComputeDictFloatFieldSize(float value, uint32_t fieldNum, GPBDataType dataType) { 269 NSCAssert(dataType == GPBDataTypeFloat, @"bad type: %d", dataType); 270 #pragma unused(dataType) // For when asserts are off in release. 271 return GPBComputeFloatSize(fieldNum, value); 272} 273 274static void WriteDictFloatField(GPBCodedOutputStream *stream, float value, uint32_t fieldNum, GPBDataType dataType) { 275 NSCAssert(dataType == GPBDataTypeFloat, @"bad type: %d", dataType); 276 #pragma unused(dataType) // For when asserts are off in release. 277 [stream writeFloat:fieldNum value:value]; 278} 279 280static size_t ComputeDictDoubleFieldSize(double value, uint32_t fieldNum, GPBDataType dataType) { 281 NSCAssert(dataType == GPBDataTypeDouble, @"bad type: %d", dataType); 282 #pragma unused(dataType) // For when asserts are off in release. 283 return GPBComputeDoubleSize(fieldNum, value); 284} 285 286static void WriteDictDoubleField(GPBCodedOutputStream *stream, double value, uint32_t fieldNum, GPBDataType dataType) { 287 NSCAssert(dataType == GPBDataTypeDouble, @"bad type: %d", dataType); 288 #pragma unused(dataType) // For when asserts are off in release. 289 [stream writeDouble:fieldNum value:value]; 290} 291 292static size_t ComputeDictStringFieldSize(NSString *value, uint32_t fieldNum, GPBDataType dataType) { 293 NSCAssert(dataType == GPBDataTypeString, @"bad type: %d", dataType); 294 #pragma unused(dataType) // For when asserts are off in release. 295 return GPBComputeStringSize(fieldNum, value); 296} 297 298static void WriteDictStringField(GPBCodedOutputStream *stream, NSString *value, uint32_t fieldNum, GPBDataType dataType) { 299 NSCAssert(dataType == GPBDataTypeString, @"bad type: %d", dataType); 300 #pragma unused(dataType) // For when asserts are off in release. 301 [stream writeString:fieldNum value:value]; 302} 303 304static size_t ComputeDictObjectFieldSize(id value, uint32_t fieldNum, GPBDataType dataType) { 305 if (dataType == GPBDataTypeMessage) { 306 return GPBComputeMessageSize(fieldNum, value); 307 } else if (dataType == GPBDataTypeString) { 308 return GPBComputeStringSize(fieldNum, value); 309 } else if (dataType == GPBDataTypeBytes) { 310 return GPBComputeBytesSize(fieldNum, value); 311 } else { 312 NSCAssert(NO, @"Unexpected type %d", dataType); 313 return 0; 314 } 315} 316 317static void WriteDictObjectField(GPBCodedOutputStream *stream, id value, uint32_t fieldNum, GPBDataType dataType) { 318 if (dataType == GPBDataTypeMessage) { 319 [stream writeMessage:fieldNum value:value]; 320 } else if (dataType == GPBDataTypeString) { 321 [stream writeString:fieldNum value:value]; 322 } else if (dataType == GPBDataTypeBytes) { 323 [stream writeBytes:fieldNum value:value]; 324 } else { 325 NSCAssert(NO, @"Unexpected type %d", dataType); 326 } 327} 328 329// clang-format on 330//%PDDM-EXPAND-END SERIALIZE_SUPPORT_HELPERS() 331 332size_t GPBDictionaryComputeSizeInternalHelper(NSDictionary *dict, GPBFieldDescriptor *field) { 333 GPBDataType mapValueType = GPBGetFieldDataType(field); 334 size_t result = 0; 335 NSString *key; 336 NSEnumerator *keys = [dict keyEnumerator]; 337 while ((key = [keys nextObject])) { 338 id obj = dict[key]; 339 size_t msgSize = GPBComputeStringSize(kMapKeyFieldNumber, key); 340 msgSize += ComputeDictObjectFieldSize(obj, kMapValueFieldNumber, mapValueType); 341 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 342 } 343 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 344 result += tagSize * dict.count; 345 return result; 346} 347 348void GPBDictionaryWriteToStreamInternalHelper(GPBCodedOutputStream *outputStream, 349 NSDictionary *dict, 350 GPBFieldDescriptor *field) { 351 NSCAssert(field.mapKeyDataType == GPBDataTypeString, @"Unexpected key type"); 352 GPBDataType mapValueType = GPBGetFieldDataType(field); 353 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 354 NSString *key; 355 NSEnumerator *keys = [dict keyEnumerator]; 356 while ((key = [keys nextObject])) { 357 id obj = dict[key]; 358 // Write the tag. 359 [outputStream writeInt32NoTag:tag]; 360 // Write the size of the message. 361 size_t msgSize = GPBComputeStringSize(kMapKeyFieldNumber, key); 362 msgSize += ComputeDictObjectFieldSize(obj, kMapValueFieldNumber, mapValueType); 363 364 // Write the size and fields. 365 [outputStream writeInt32NoTag:(int32_t)msgSize]; 366 [outputStream writeString:kMapKeyFieldNumber value:key]; 367 WriteDictObjectField(outputStream, obj, kMapValueFieldNumber, mapValueType); 368 } 369} 370 371BOOL GPBDictionaryIsInitializedInternalHelper(NSDictionary *dict, GPBFieldDescriptor *field) { 372 NSCAssert(field.mapKeyDataType == GPBDataTypeString, @"Unexpected key type"); 373 NSCAssert(GPBGetFieldDataType(field) == GPBDataTypeMessage, @"Unexpected value type"); 374 #pragma unused(field) // For when asserts are off in release. 375 GPBMessage *msg; 376 NSEnumerator *objects = [dict objectEnumerator]; 377 while ((msg = [objects nextObject])) { 378 if (!msg.initialized) { 379 return NO; 380 } 381 } 382 return YES; 383} 384 385// Note: if the type is an object, it the retain pass back to the caller. 386static void ReadValue(GPBCodedInputStream *stream, 387 GPBGenericValue *valueToFill, 388 GPBDataType type, 389 GPBExtensionRegistry *registry, 390 GPBFieldDescriptor *field) { 391 switch (type) { 392 case GPBDataTypeBool: 393 valueToFill->valueBool = GPBCodedInputStreamReadBool(&stream->state_); 394 break; 395 case GPBDataTypeFixed32: 396 valueToFill->valueUInt32 = GPBCodedInputStreamReadFixed32(&stream->state_); 397 break; 398 case GPBDataTypeSFixed32: 399 valueToFill->valueInt32 = GPBCodedInputStreamReadSFixed32(&stream->state_); 400 break; 401 case GPBDataTypeFloat: 402 valueToFill->valueFloat = GPBCodedInputStreamReadFloat(&stream->state_); 403 break; 404 case GPBDataTypeFixed64: 405 valueToFill->valueUInt64 = GPBCodedInputStreamReadFixed64(&stream->state_); 406 break; 407 case GPBDataTypeSFixed64: 408 valueToFill->valueInt64 = GPBCodedInputStreamReadSFixed64(&stream->state_); 409 break; 410 case GPBDataTypeDouble: 411 valueToFill->valueDouble = GPBCodedInputStreamReadDouble(&stream->state_); 412 break; 413 case GPBDataTypeInt32: 414 valueToFill->valueInt32 = GPBCodedInputStreamReadInt32(&stream->state_); 415 break; 416 case GPBDataTypeInt64: 417 valueToFill->valueInt64 = GPBCodedInputStreamReadInt64(&stream->state_); 418 break; 419 case GPBDataTypeSInt32: 420 valueToFill->valueInt32 = GPBCodedInputStreamReadSInt32(&stream->state_); 421 break; 422 case GPBDataTypeSInt64: 423 valueToFill->valueInt64 = GPBCodedInputStreamReadSInt64(&stream->state_); 424 break; 425 case GPBDataTypeUInt32: 426 valueToFill->valueUInt32 = GPBCodedInputStreamReadUInt32(&stream->state_); 427 break; 428 case GPBDataTypeUInt64: 429 valueToFill->valueUInt64 = GPBCodedInputStreamReadUInt64(&stream->state_); 430 break; 431 case GPBDataTypeBytes: 432 [valueToFill->valueData release]; 433 valueToFill->valueData = GPBCodedInputStreamReadRetainedBytes(&stream->state_); 434 break; 435 case GPBDataTypeString: 436 [valueToFill->valueString release]; 437 valueToFill->valueString = GPBCodedInputStreamReadRetainedString(&stream->state_); 438 break; 439 case GPBDataTypeMessage: { 440 GPBMessage *message = [[field.msgClass alloc] init]; 441 [stream readMessage:message extensionRegistry:registry]; 442 [valueToFill->valueMessage release]; 443 valueToFill->valueMessage = message; 444 break; 445 } 446 case GPBDataTypeGroup: 447 NSCAssert(NO, @"Can't happen"); 448 break; 449 case GPBDataTypeEnum: 450 valueToFill->valueEnum = GPBCodedInputStreamReadEnum(&stream->state_); 451 break; 452 } 453} 454 455void GPBDictionaryReadEntry(id mapDictionary, 456 GPBCodedInputStream *stream, 457 GPBExtensionRegistry *registry, 458 GPBFieldDescriptor *field, 459 GPBMessage *parentMessage) { 460 GPBDataType keyDataType = field.mapKeyDataType; 461 GPBDataType valueDataType = GPBGetFieldDataType(field); 462 463 GPBGenericValue key; 464 GPBGenericValue value; 465 // Zero them (but pick up any enum default for proto2). 466 key.valueString = value.valueString = nil; 467 if (valueDataType == GPBDataTypeEnum) { 468 value = field.defaultValue; 469 } 470 471 GPBCodedInputStreamState *state = &stream->state_; 472 uint32_t keyTag = 473 GPBWireFormatMakeTag(kMapKeyFieldNumber, GPBWireFormatForType(keyDataType, NO)); 474 uint32_t valueTag = 475 GPBWireFormatMakeTag(kMapValueFieldNumber, GPBWireFormatForType(valueDataType, NO)); 476 477 BOOL hitError = NO; 478 while (YES) { 479 uint32_t tag = GPBCodedInputStreamReadTag(state); 480 if (tag == keyTag) { 481 ReadValue(stream, &key, keyDataType, registry, field); 482 } else if (tag == valueTag) { 483 ReadValue(stream, &value, valueDataType, registry, field); 484 } else if (tag == 0) { 485 // zero signals EOF / limit reached 486 break; 487 } else { // Unknown 488 if (![stream skipField:tag]){ 489 hitError = YES; 490 break; 491 } 492 } 493 } 494 495 if (!hitError) { 496 // Handle the special defaults and/or missing key/value. 497 if ((keyDataType == GPBDataTypeString) && (key.valueString == nil)) { 498 key.valueString = [@"" retain]; 499 } 500 if (GPBDataTypeIsObject(valueDataType) && value.valueString == nil) { 501#pragma clang diagnostic push 502#pragma clang diagnostic ignored "-Wswitch-enum" 503 switch (valueDataType) { 504 case GPBDataTypeString: 505 value.valueString = [@"" retain]; 506 break; 507 case GPBDataTypeBytes: 508 value.valueData = [GPBEmptyNSData() retain]; 509 break; 510#if defined(__clang_analyzer__) 511 case GPBDataTypeGroup: 512 // Maps can't really have Groups as the value type, but this case is needed 513 // so the analyzer won't report the possibility of send nil in for the value 514 // in the NSMutableDictionary case below. 515#endif 516 case GPBDataTypeMessage: { 517 value.valueMessage = [[field.msgClass alloc] init]; 518 break; 519 } 520 default: 521 // Nothing 522 break; 523 } 524#pragma clang diagnostic pop 525 } 526 527 if ((keyDataType == GPBDataTypeString) && GPBDataTypeIsObject(valueDataType)) { 528#if GPB_STATIC_ANALYZER_ONLY(6020053, 7000181) 529 // Limited to Xcode 6.4 - 7.2, are known to fail here. The upper end can 530 // be raised as needed for new Xcodes. 531 // 532 // This is only needed on a "shallow" analyze; on a "deep" analyze, the 533 // existing code path gets this correct. In shallow, the analyzer decides 534 // GPBDataTypeIsObject(valueDataType) is both false and true on a single 535 // path through this function, allowing nil to be used for the 536 // setObject:forKey:. 537 if (value.valueString == nil) { 538 value.valueString = [@"" retain]; 539 } 540#endif 541 // mapDictionary is an NSMutableDictionary 542 [(NSMutableDictionary *)mapDictionary setObject:value.valueString 543 forKey:key.valueString]; 544 } else { 545 if (valueDataType == GPBDataTypeEnum) { 546 if (GPBHasPreservingUnknownEnumSemantics([parentMessage descriptor].file.syntax) || 547 [field isValidEnumValue:value.valueEnum]) { 548 [mapDictionary setGPBGenericValue:&value forGPBGenericValueKey:&key]; 549 } else { 550 NSData *data = [mapDictionary serializedDataForUnknownValue:value.valueEnum 551 forKey:&key 552 keyDataType:keyDataType]; 553 [parentMessage addUnknownMapEntry:GPBFieldNumber(field) value:data]; 554 } 555 } else { 556 [mapDictionary setGPBGenericValue:&value forGPBGenericValueKey:&key]; 557 } 558 } 559 } 560 561 if (GPBDataTypeIsObject(keyDataType)) { 562 [key.valueString release]; 563 } 564 if (GPBDataTypeIsObject(valueDataType)) { 565 [value.valueString release]; 566 } 567} 568 569// 570// Macros for the common basic cases. 571// 572 573//%PDDM-DEFINE DICTIONARY_IMPL_FOR_POD_KEY(KEY_NAME, KEY_TYPE) 574//%DICTIONARY_POD_IMPL_FOR_KEY(KEY_NAME, KEY_TYPE, , POD) 575//%DICTIONARY_POD_KEY_TO_OBJECT_IMPL(KEY_NAME, KEY_TYPE, Object, id) 576 577//%PDDM-DEFINE DICTIONARY_POD_IMPL_FOR_KEY(KEY_NAME, KEY_TYPE, KisP, KHELPER) 578//%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, UInt32, uint32_t, KHELPER) 579//%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Int32, int32_t, KHELPER) 580//%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, UInt64, uint64_t, KHELPER) 581//%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Int64, int64_t, KHELPER) 582//%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Bool, BOOL, KHELPER) 583//%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Float, float, KHELPER) 584//%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Double, double, KHELPER) 585//%DICTIONARY_KEY_TO_ENUM_IMPL(KEY_NAME, KEY_TYPE, KisP, Enum, int32_t, KHELPER) 586 587//%PDDM-DEFINE DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER) 588//%DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, POD, VALUE_NAME, value) 589 590//%PDDM-DEFINE DICTIONARY_POD_KEY_TO_OBJECT_IMPL(KEY_NAME, KEY_TYPE, VALUE_NAME, VALUE_TYPE) 591//%DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, , VALUE_NAME, VALUE_TYPE, POD, OBJECT, Object, object) 592 593//%PDDM-DEFINE DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR) 594//%#pragma mark - KEY_NAME -> VALUE_NAME 595//% 596//%@implementation GPB##KEY_NAME##VALUE_NAME##Dictionary { 597//% @package 598//% NSMutableDictionary *_dictionary; 599//%} 600//% 601//%- (instancetype)init { 602//% return [self initWith##VNAME##s:NULL forKeys:NULL count:0]; 603//%} 604//% 605//%- (instancetype)initWith##VNAME##s:(const VALUE_TYPE [])##VNAME_VAR##s 606//% ##VNAME$S## forKeys:(const KEY_TYPE##KisP$S##KisP [])keys 607//% ##VNAME$S## count:(NSUInteger)count { 608//% self = [super init]; 609//% if (self) { 610//% _dictionary = [[NSMutableDictionary alloc] init]; 611//% if (count && VNAME_VAR##s && keys) { 612//% for (NSUInteger i = 0; i < count; ++i) { 613//%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])]; 614//% } 615//% } 616//% } 617//% return self; 618//%} 619//% 620//%- (instancetype)initWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary { 621//% self = [self initWith##VNAME##s:NULL forKeys:NULL count:0]; 622//% if (self) { 623//% if (dictionary) { 624//% [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 625//% } 626//% } 627//% return self; 628//%} 629//% 630//%- (instancetype)initWithCapacity:(NSUInteger)numItems { 631//% #pragma unused(numItems) 632//% return [self initWith##VNAME##s:NULL forKeys:NULL count:0]; 633//%} 634//% 635//%DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, ) 636//% 637//%VALUE_FOR_KEY_##VHELPER(KEY_TYPE##KisP$S##KisP, VALUE_NAME, VALUE_TYPE, KHELPER) 638//% 639//%DICTIONARY_MUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, ) 640//% 641//%@end 642//% 643 644//%PDDM-DEFINE DICTIONARY_KEY_TO_ENUM_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER) 645//%DICTIONARY_KEY_TO_ENUM_IMPL2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, POD) 646//%PDDM-DEFINE DICTIONARY_KEY_TO_ENUM_IMPL2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER) 647//%#pragma mark - KEY_NAME -> VALUE_NAME 648//% 649//%@implementation GPB##KEY_NAME##VALUE_NAME##Dictionary { 650//% @package 651//% NSMutableDictionary *_dictionary; 652//% GPBEnumValidationFunc _validationFunc; 653//%} 654//% 655//%@synthesize validationFunc = _validationFunc; 656//% 657//%- (instancetype)init { 658//% return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0]; 659//%} 660//% 661//%- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func { 662//% return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0]; 663//%} 664//% 665//%- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func 666//% rawValues:(const VALUE_TYPE [])rawValues 667//% forKeys:(const KEY_TYPE##KisP$S##KisP [])keys 668//% count:(NSUInteger)count { 669//% self = [super init]; 670//% if (self) { 671//% _dictionary = [[NSMutableDictionary alloc] init]; 672//% _validationFunc = (func != NULL ? func : DictDefault_IsValidValue); 673//% if (count && rawValues && keys) { 674//% for (NSUInteger i = 0; i < count; ++i) { 675//%DICTIONARY_VALIDATE_KEY_##KHELPER(keys[i], ______) [_dictionary setObject:WRAPPED##VHELPER(rawValues[i]) forKey:WRAPPED##KHELPER(keys[i])]; 676//% } 677//% } 678//% } 679//% return self; 680//%} 681//% 682//%- (instancetype)initWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary { 683//% self = [self initWithValidationFunction:dictionary.validationFunc 684//% rawValues:NULL 685//% forKeys:NULL 686//% count:0]; 687//% if (self) { 688//% if (dictionary) { 689//% [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 690//% } 691//% } 692//% return self; 693//%} 694//% 695//%- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func 696//% capacity:(NSUInteger)numItems { 697//% #pragma unused(numItems) 698//% return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0]; 699//%} 700//% 701//%DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, Value, value, Raw) 702//% 703//%- (BOOL)getEnum:(VALUE_TYPE *)value forKey:(KEY_TYPE##KisP$S##KisP)key { 704//% NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)]; 705//% if (wrapped && value) { 706//% VALUE_TYPE result = UNWRAP##VALUE_NAME(wrapped); 707//% if (!_validationFunc(result)) { 708//% result = kGPBUnrecognizedEnumeratorValue; 709//% } 710//% *value = result; 711//% } 712//% return (wrapped != NULL); 713//%} 714//% 715//%- (BOOL)getRawValue:(VALUE_TYPE *)rawValue forKey:(KEY_TYPE##KisP$S##KisP)key { 716//% NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)]; 717//% if (wrapped && rawValue) { 718//% *rawValue = UNWRAP##VALUE_NAME(wrapped); 719//% } 720//% return (wrapped != NULL); 721//%} 722//% 723//%- (void)enumerateKeysAndEnumsUsingBlock: 724//% (void (NS_NOESCAPE ^)(KEY_TYPE KisP##key, VALUE_TYPE value, BOOL *stop))block { 725//% GPBEnumValidationFunc func = _validationFunc; 726//% BOOL stop = NO; 727//% NSEnumerator *keys = [_dictionary keyEnumerator]; 728//% ENUM_TYPE##KHELPER(KEY_TYPE)##aKey; 729//% while ((aKey = [keys nextObject])) { 730//% ENUM_TYPE##VHELPER(VALUE_TYPE)##aValue = _dictionary[aKey]; 731//% VALUE_TYPE unwrapped = UNWRAP##VALUE_NAME(aValue); 732//% if (!func(unwrapped)) { 733//% unwrapped = kGPBUnrecognizedEnumeratorValue; 734//% } 735//% block(UNWRAP##KEY_NAME(aKey), unwrapped, &stop); 736//% if (stop) { 737//% break; 738//% } 739//% } 740//%} 741//% 742//%DICTIONARY_MUTABLE_CORE2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, Value, Enum, value, Raw) 743//% 744//%- (void)setEnum:(VALUE_TYPE)value forKey:(KEY_TYPE##KisP$S##KisP)key { 745//%DICTIONARY_VALIDATE_KEY_##KHELPER(key, ) if (!_validationFunc(value)) { 746//% [NSException raise:NSInvalidArgumentException 747//% format:@"GPB##KEY_NAME##VALUE_NAME##Dictionary: Attempt to set an unknown enum value (%d)", 748//% value]; 749//% } 750//% 751//% [_dictionary setObject:WRAPPED##VHELPER(value) forKey:WRAPPED##KHELPER(key)]; 752//% if (_autocreator) { 753//% GPBAutocreatedDictionaryModified(_autocreator, self); 754//% } 755//%} 756//% 757//%@end 758//% 759 760//%PDDM-DEFINE DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, ACCESSOR_NAME) 761//%- (void)dealloc { 762//% NSAssert(!_autocreator, 763//% @"%@: Autocreator must be cleared before release, autocreator: %@", 764//% [self class], _autocreator); 765//% [_dictionary release]; 766//% [super dealloc]; 767//%} 768//% 769//%- (instancetype)copyWithZone:(NSZone *)zone { 770//% return [[GPB##KEY_NAME##VALUE_NAME##Dictionary allocWithZone:zone] initWithDictionary:self]; 771//%} 772//% 773//%- (BOOL)isEqual:(id)other { 774//% if (self == other) { 775//% return YES; 776//% } 777//% if (![other isKindOfClass:[GPB##KEY_NAME##VALUE_NAME##Dictionary class]]) { 778//% return NO; 779//% } 780//% GPB##KEY_NAME##VALUE_NAME##Dictionary *otherDictionary = other; 781//% return [_dictionary isEqual:otherDictionary->_dictionary]; 782//%} 783//% 784//%- (NSUInteger)hash { 785//% return _dictionary.count; 786//%} 787//% 788//%- (NSString *)description { 789//% return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 790//%} 791//% 792//%- (NSUInteger)count { 793//% return _dictionary.count; 794//%} 795//% 796//%- (void)enumerateKeysAnd##ACCESSOR_NAME##VNAME##sUsingBlock: 797//% (void (NS_NOESCAPE ^)(KEY_TYPE KisP##key, VALUE_TYPE VNAME_VAR, BOOL *stop))block { 798//% BOOL stop = NO; 799//% NSDictionary *internal = _dictionary; 800//% NSEnumerator *keys = [internal keyEnumerator]; 801//% ENUM_TYPE##KHELPER(KEY_TYPE)##aKey; 802//% while ((aKey = [keys nextObject])) { 803//% ENUM_TYPE##VHELPER(VALUE_TYPE)##a##VNAME_VAR$u = internal[aKey]; 804//% block(UNWRAP##KEY_NAME(aKey), UNWRAP##VALUE_NAME(a##VNAME_VAR$u), &stop); 805//% if (stop) { 806//% break; 807//% } 808//% } 809//%} 810//% 811//%EXTRA_METHODS_##VHELPER(KEY_NAME, VALUE_NAME)- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 812//% NSDictionary *internal = _dictionary; 813//% NSUInteger count = internal.count; 814//% if (count == 0) { 815//% return 0; 816//% } 817//% 818//% GPBDataType valueDataType = GPBGetFieldDataType(field); 819//% GPBDataType keyDataType = field.mapKeyDataType; 820//% size_t result = 0; 821//% NSEnumerator *keys = [internal keyEnumerator]; 822//% ENUM_TYPE##KHELPER(KEY_TYPE)##aKey; 823//% while ((aKey = [keys nextObject])) { 824//% ENUM_TYPE##VHELPER(VALUE_TYPE)##a##VNAME_VAR$u = internal[aKey]; 825//% size_t msgSize = ComputeDict##KEY_NAME##FieldSize(UNWRAP##KEY_NAME(aKey), kMapKeyFieldNumber, keyDataType); 826//% msgSize += ComputeDict##VALUE_NAME##FieldSize(UNWRAP##VALUE_NAME(a##VNAME_VAR$u), kMapValueFieldNumber, valueDataType); 827//% result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 828//% } 829//% size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 830//% result += tagSize * count; 831//% return result; 832//%} 833//% 834//%- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 835//% asField:(GPBFieldDescriptor *)field { 836//% GPBDataType valueDataType = GPBGetFieldDataType(field); 837//% GPBDataType keyDataType = field.mapKeyDataType; 838//% uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 839//% NSDictionary *internal = _dictionary; 840//% NSEnumerator *keys = [internal keyEnumerator]; 841//% ENUM_TYPE##KHELPER(KEY_TYPE)##aKey; 842//% while ((aKey = [keys nextObject])) { 843//% ENUM_TYPE##VHELPER(VALUE_TYPE)##a##VNAME_VAR$u = internal[aKey]; 844//% [outputStream writeInt32NoTag:tag]; 845//% // Write the size of the message. 846//% KEY_TYPE KisP##unwrappedKey = UNWRAP##KEY_NAME(aKey); 847//% VALUE_TYPE unwrappedValue = UNWRAP##VALUE_NAME(a##VNAME_VAR$u); 848//% size_t msgSize = ComputeDict##KEY_NAME##FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 849//% msgSize += ComputeDict##VALUE_NAME##FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 850//% [outputStream writeInt32NoTag:(int32_t)msgSize]; 851//% // Write the fields. 852//% WriteDict##KEY_NAME##Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 853//% WriteDict##VALUE_NAME##Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 854//% } 855//%} 856//% 857//%SERIAL_DATA_FOR_ENTRY_##VHELPER(KEY_NAME, VALUE_NAME)- (void)setGPBGenericValue:(GPBGenericValue *)value 858//% forGPBGenericValueKey:(GPBGenericValue *)key { 859//% [_dictionary setObject:WRAPPED##VHELPER(value->##GPBVALUE_##VHELPER(VALUE_NAME)##) forKey:WRAPPED##KHELPER(key->value##KEY_NAME)]; 860//%} 861//% 862//%- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 863//% [self enumerateKeysAnd##ACCESSOR_NAME##VNAME##sUsingBlock:^(KEY_TYPE KisP##key, VALUE_TYPE VNAME_VAR, BOOL *stop) { 864//% #pragma unused(stop) 865//% block(TEXT_FORMAT_OBJ##KEY_NAME(key), TEXT_FORMAT_OBJ##VALUE_NAME(VNAME_VAR)); 866//% }]; 867//%} 868//%PDDM-DEFINE DICTIONARY_MUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, ACCESSOR_NAME) 869//%DICTIONARY_MUTABLE_CORE2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME, VNAME_VAR, ACCESSOR_NAME) 870//%PDDM-DEFINE DICTIONARY_MUTABLE_CORE2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_REMOVE, VNAME_VAR, ACCESSOR_NAME) 871//%- (void)add##ACCESSOR_NAME##EntriesFromDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)otherDictionary { 872//% if (otherDictionary) { 873//% [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 874//% if (_autocreator) { 875//% GPBAutocreatedDictionaryModified(_autocreator, self); 876//% } 877//% } 878//%} 879//% 880//%- (void)set##ACCESSOR_NAME##VNAME##:(VALUE_TYPE)VNAME_VAR forKey:(KEY_TYPE##KisP$S##KisP)key { 881//%DICTIONARY_VALIDATE_VALUE_##VHELPER(VNAME_VAR, )##DICTIONARY_VALIDATE_KEY_##KHELPER(key, ) [_dictionary setObject:WRAPPED##VHELPER(VNAME_VAR) forKey:WRAPPED##KHELPER(key)]; 882//% if (_autocreator) { 883//% GPBAutocreatedDictionaryModified(_autocreator, self); 884//% } 885//%} 886//% 887//%- (void)remove##VNAME_REMOVE##ForKey:(KEY_TYPE##KisP$S##KisP)aKey { 888//% [_dictionary removeObjectForKey:WRAPPED##KHELPER(aKey)]; 889//%} 890//% 891//%- (void)removeAll { 892//% [_dictionary removeAllObjects]; 893//%} 894 895// 896// Custom Generation for Bool keys 897// 898 899//%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_POD_IMPL(VALUE_NAME, VALUE_TYPE) 900//%DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, POD, VALUE_NAME, value) 901//%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_OBJECT_IMPL(VALUE_NAME, VALUE_TYPE) 902//%DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, OBJECT, Object, object) 903 904//%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, HELPER, VNAME, VNAME_VAR) 905//%#pragma mark - Bool -> VALUE_NAME 906//% 907//%@implementation GPBBool##VALUE_NAME##Dictionary { 908//% @package 909//% VALUE_TYPE _values[2]; 910//%BOOL_DICT_HAS_STORAGE_##HELPER()} 911//% 912//%- (instancetype)init { 913//% return [self initWith##VNAME##s:NULL forKeys:NULL count:0]; 914//%} 915//% 916//%BOOL_DICT_INITS_##HELPER(VALUE_NAME, VALUE_TYPE) 917//% 918//%- (instancetype)initWithCapacity:(NSUInteger)numItems { 919//% #pragma unused(numItems) 920//% return [self initWith##VNAME##s:NULL forKeys:NULL count:0]; 921//%} 922//% 923//%BOOL_DICT_DEALLOC##HELPER() 924//% 925//%- (instancetype)copyWithZone:(NSZone *)zone { 926//% return [[GPBBool##VALUE_NAME##Dictionary allocWithZone:zone] initWithDictionary:self]; 927//%} 928//% 929//%- (BOOL)isEqual:(id)other { 930//% if (self == other) { 931//% return YES; 932//% } 933//% if (![other isKindOfClass:[GPBBool##VALUE_NAME##Dictionary class]]) { 934//% return NO; 935//% } 936//% GPBBool##VALUE_NAME##Dictionary *otherDictionary = other; 937//% if ((BOOL_DICT_W_HAS##HELPER(0, ) != BOOL_DICT_W_HAS##HELPER(0, otherDictionary->)) || 938//% (BOOL_DICT_W_HAS##HELPER(1, ) != BOOL_DICT_W_HAS##HELPER(1, otherDictionary->))) { 939//% return NO; 940//% } 941//% if ((BOOL_DICT_W_HAS##HELPER(0, ) && (NEQ_##HELPER(_values[0], otherDictionary->_values[0]))) || 942//% (BOOL_DICT_W_HAS##HELPER(1, ) && (NEQ_##HELPER(_values[1], otherDictionary->_values[1])))) { 943//% return NO; 944//% } 945//% return YES; 946//%} 947//% 948//%- (NSUInteger)hash { 949//% return (BOOL_DICT_W_HAS##HELPER(0, ) ? 1 : 0) + (BOOL_DICT_W_HAS##HELPER(1, ) ? 1 : 0); 950//%} 951//% 952//%- (NSString *)description { 953//% NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self]; 954//% if (BOOL_DICT_W_HAS##HELPER(0, )) { 955//% [result appendFormat:@"NO: STR_FORMAT_##HELPER(VALUE_NAME)", _values[0]]; 956//% } 957//% if (BOOL_DICT_W_HAS##HELPER(1, )) { 958//% [result appendFormat:@"YES: STR_FORMAT_##HELPER(VALUE_NAME)", _values[1]]; 959//% } 960//% [result appendString:@" }"]; 961//% return result; 962//%} 963//% 964//%- (NSUInteger)count { 965//% return (BOOL_DICT_W_HAS##HELPER(0, ) ? 1 : 0) + (BOOL_DICT_W_HAS##HELPER(1, ) ? 1 : 0); 966//%} 967//% 968//%BOOL_VALUE_FOR_KEY_##HELPER(VALUE_NAME, VALUE_TYPE) 969//% 970//%BOOL_SET_GPBVALUE_FOR_KEY_##HELPER(VALUE_NAME, VALUE_TYPE, VisP) 971//% 972//%- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 973//% if (BOOL_DICT_HAS##HELPER(0, )) { 974//% block(@"false", TEXT_FORMAT_OBJ##VALUE_NAME(_values[0])); 975//% } 976//% if (BOOL_DICT_W_HAS##HELPER(1, )) { 977//% block(@"true", TEXT_FORMAT_OBJ##VALUE_NAME(_values[1])); 978//% } 979//%} 980//% 981//%- (void)enumerateKeysAnd##VNAME##sUsingBlock: 982//% (void (NS_NOESCAPE ^)(BOOL key, VALUE_TYPE VNAME_VAR, BOOL *stop))block { 983//% BOOL stop = NO; 984//% if (BOOL_DICT_HAS##HELPER(0, )) { 985//% block(NO, _values[0], &stop); 986//% } 987//% if (!stop && BOOL_DICT_W_HAS##HELPER(1, )) { 988//% block(YES, _values[1], &stop); 989//% } 990//%} 991//% 992//%BOOL_EXTRA_METHODS_##HELPER(Bool, VALUE_NAME)- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 993//% GPBDataType valueDataType = GPBGetFieldDataType(field); 994//% NSUInteger count = 0; 995//% size_t result = 0; 996//% for (int i = 0; i < 2; ++i) { 997//% if (BOOL_DICT_HAS##HELPER(i, )) { 998//% ++count; 999//% size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool); 1000//% msgSize += ComputeDict##VALUE_NAME##FieldSize(_values[i], kMapValueFieldNumber, valueDataType); 1001//% result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 1002//% } 1003//% } 1004//% size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 1005//% result += tagSize * count; 1006//% return result; 1007//%} 1008//% 1009//%- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 1010//% asField:(GPBFieldDescriptor *)field { 1011//% GPBDataType valueDataType = GPBGetFieldDataType(field); 1012//% uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 1013//% for (int i = 0; i < 2; ++i) { 1014//% if (BOOL_DICT_HAS##HELPER(i, )) { 1015//% // Write the tag. 1016//% [outputStream writeInt32NoTag:tag]; 1017//% // Write the size of the message. 1018//% size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool); 1019//% msgSize += ComputeDict##VALUE_NAME##FieldSize(_values[i], kMapValueFieldNumber, valueDataType); 1020//% [outputStream writeInt32NoTag:(int32_t)msgSize]; 1021//% // Write the fields. 1022//% WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool); 1023//% WriteDict##VALUE_NAME##Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType); 1024//% } 1025//% } 1026//%} 1027//% 1028//%BOOL_DICT_MUTATIONS_##HELPER(VALUE_NAME, VALUE_TYPE) 1029//% 1030//%@end 1031//% 1032 1033 1034// 1035// Helpers for PODs 1036// 1037 1038//%PDDM-DEFINE VALUE_FOR_KEY_POD(KEY_TYPE, VALUE_NAME, VALUE_TYPE, KHELPER) 1039//%- (BOOL)get##VALUE_NAME##:(nullable VALUE_TYPE *)value forKey:(KEY_TYPE)key { 1040//% NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)]; 1041//% if (wrapped && value) { 1042//% *value = UNWRAP##VALUE_NAME(wrapped); 1043//% } 1044//% return (wrapped != NULL); 1045//%} 1046//%PDDM-DEFINE WRAPPEDPOD(VALUE) 1047//%@(VALUE) 1048//%PDDM-DEFINE UNWRAPUInt32(VALUE) 1049//%[VALUE unsignedIntValue] 1050//%PDDM-DEFINE UNWRAPInt32(VALUE) 1051//%[VALUE intValue] 1052//%PDDM-DEFINE UNWRAPUInt64(VALUE) 1053//%[VALUE unsignedLongLongValue] 1054//%PDDM-DEFINE UNWRAPInt64(VALUE) 1055//%[VALUE longLongValue] 1056//%PDDM-DEFINE UNWRAPBool(VALUE) 1057//%[VALUE boolValue] 1058//%PDDM-DEFINE UNWRAPFloat(VALUE) 1059//%[VALUE floatValue] 1060//%PDDM-DEFINE UNWRAPDouble(VALUE) 1061//%[VALUE doubleValue] 1062//%PDDM-DEFINE UNWRAPEnum(VALUE) 1063//%[VALUE intValue] 1064//%PDDM-DEFINE TEXT_FORMAT_OBJUInt32(VALUE) 1065//%[NSString stringWithFormat:@"%u", VALUE] 1066//%PDDM-DEFINE TEXT_FORMAT_OBJInt32(VALUE) 1067//%[NSString stringWithFormat:@"%d", VALUE] 1068//%PDDM-DEFINE TEXT_FORMAT_OBJUInt64(VALUE) 1069//%[NSString stringWithFormat:@"%llu", VALUE] 1070//%PDDM-DEFINE TEXT_FORMAT_OBJInt64(VALUE) 1071//%[NSString stringWithFormat:@"%lld", VALUE] 1072//%PDDM-DEFINE TEXT_FORMAT_OBJBool(VALUE) 1073//%(VALUE ? @"true" : @"false") 1074//%PDDM-DEFINE TEXT_FORMAT_OBJFloat(VALUE) 1075//%[NSString stringWithFormat:@"%.*g", FLT_DIG, VALUE] 1076//%PDDM-DEFINE TEXT_FORMAT_OBJDouble(VALUE) 1077//%[NSString stringWithFormat:@"%.*lg", DBL_DIG, VALUE] 1078//%PDDM-DEFINE TEXT_FORMAT_OBJEnum(VALUE) 1079//%@(VALUE) 1080//%PDDM-DEFINE ENUM_TYPEPOD(TYPE) 1081//%NSNumber * 1082//%PDDM-DEFINE NEQ_POD(VAL1, VAL2) 1083//%VAL1 != VAL2 1084//%PDDM-DEFINE EXTRA_METHODS_POD(KEY_NAME, VALUE_NAME) 1085// Empty 1086//%PDDM-DEFINE BOOL_EXTRA_METHODS_POD(KEY_NAME, VALUE_NAME) 1087// Empty 1088//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD(KEY_NAME, VALUE_NAME) 1089//%SERIAL_DATA_FOR_ENTRY_POD_##VALUE_NAME(KEY_NAME) 1090//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_UInt32(KEY_NAME) 1091// Empty 1092//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Int32(KEY_NAME) 1093// Empty 1094//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_UInt64(KEY_NAME) 1095// Empty 1096//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Int64(KEY_NAME) 1097// Empty 1098//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Bool(KEY_NAME) 1099// Empty 1100//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Float(KEY_NAME) 1101// Empty 1102//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Double(KEY_NAME) 1103// Empty 1104//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Enum(KEY_NAME) 1105//%- (NSData *)serializedDataForUnknownValue:(int32_t)value 1106//% forKey:(GPBGenericValue *)key 1107//% keyDataType:(GPBDataType)keyDataType { 1108//% size_t msgSize = ComputeDict##KEY_NAME##FieldSize(key->value##KEY_NAME, kMapKeyFieldNumber, keyDataType); 1109//% msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum); 1110//% NSMutableData *data = [NSMutableData dataWithLength:msgSize]; 1111//% GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data]; 1112//% WriteDict##KEY_NAME##Field(outputStream, key->value##KEY_NAME, kMapKeyFieldNumber, keyDataType); 1113//% WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum); 1114//% [outputStream release]; 1115//% return data; 1116//%} 1117//% 1118//%PDDM-DEFINE GPBVALUE_POD(VALUE_NAME) 1119//%value##VALUE_NAME 1120//%PDDM-DEFINE DICTIONARY_VALIDATE_VALUE_POD(VALUE_NAME, EXTRA_INDENT) 1121// Empty 1122//%PDDM-DEFINE DICTIONARY_VALIDATE_KEY_POD(KEY_NAME, EXTRA_INDENT) 1123// Empty 1124 1125//%PDDM-DEFINE BOOL_DICT_HAS_STORAGE_POD() 1126//% BOOL _valueSet[2]; 1127//% 1128//%PDDM-DEFINE BOOL_DICT_INITS_POD(VALUE_NAME, VALUE_TYPE) 1129//%- (instancetype)initWith##VALUE_NAME##s:(const VALUE_TYPE [])values 1130//% ##VALUE_NAME$S## forKeys:(const BOOL [])keys 1131//% ##VALUE_NAME$S## count:(NSUInteger)count { 1132//% self = [super init]; 1133//% if (self) { 1134//% for (NSUInteger i = 0; i < count; ++i) { 1135//% int idx = keys[i] ? 1 : 0; 1136//% _values[idx] = values[i]; 1137//% _valueSet[idx] = YES; 1138//% } 1139//% } 1140//% return self; 1141//%} 1142//% 1143//%- (instancetype)initWithDictionary:(GPBBool##VALUE_NAME##Dictionary *)dictionary { 1144//% self = [self initWith##VALUE_NAME##s:NULL forKeys:NULL count:0]; 1145//% if (self) { 1146//% if (dictionary) { 1147//% for (int i = 0; i < 2; ++i) { 1148//% if (dictionary->_valueSet[i]) { 1149//% _values[i] = dictionary->_values[i]; 1150//% _valueSet[i] = YES; 1151//% } 1152//% } 1153//% } 1154//% } 1155//% return self; 1156//%} 1157//%PDDM-DEFINE BOOL_DICT_DEALLOCPOD() 1158//%#if !defined(NS_BLOCK_ASSERTIONS) 1159//%- (void)dealloc { 1160//% NSAssert(!_autocreator, 1161//% @"%@: Autocreator must be cleared before release, autocreator: %@", 1162//% [self class], _autocreator); 1163//% [super dealloc]; 1164//%} 1165//%#endif // !defined(NS_BLOCK_ASSERTIONS) 1166//%PDDM-DEFINE BOOL_DICT_W_HASPOD(IDX, REF) 1167//%BOOL_DICT_HASPOD(IDX, REF) 1168//%PDDM-DEFINE BOOL_DICT_HASPOD(IDX, REF) 1169//%REF##_valueSet[IDX] 1170//%PDDM-DEFINE BOOL_VALUE_FOR_KEY_POD(VALUE_NAME, VALUE_TYPE) 1171//%- (BOOL)get##VALUE_NAME##:(VALUE_TYPE *)value forKey:(BOOL)key { 1172//% int idx = (key ? 1 : 0); 1173//% if (_valueSet[idx]) { 1174//% if (value) { 1175//% *value = _values[idx]; 1176//% } 1177//% return YES; 1178//% } 1179//% return NO; 1180//%} 1181//%PDDM-DEFINE BOOL_SET_GPBVALUE_FOR_KEY_POD(VALUE_NAME, VALUE_TYPE, VisP) 1182//%- (void)setGPBGenericValue:(GPBGenericValue *)value 1183//% forGPBGenericValueKey:(GPBGenericValue *)key { 1184//% int idx = (key->valueBool ? 1 : 0); 1185//% _values[idx] = value->value##VALUE_NAME; 1186//% _valueSet[idx] = YES; 1187//%} 1188//%PDDM-DEFINE BOOL_DICT_MUTATIONS_POD(VALUE_NAME, VALUE_TYPE) 1189//%- (void)addEntriesFromDictionary:(GPBBool##VALUE_NAME##Dictionary *)otherDictionary { 1190//% if (otherDictionary) { 1191//% for (int i = 0; i < 2; ++i) { 1192//% if (otherDictionary->_valueSet[i]) { 1193//% _valueSet[i] = YES; 1194//% _values[i] = otherDictionary->_values[i]; 1195//% } 1196//% } 1197//% if (_autocreator) { 1198//% GPBAutocreatedDictionaryModified(_autocreator, self); 1199//% } 1200//% } 1201//%} 1202//% 1203//%- (void)set##VALUE_NAME:(VALUE_TYPE)value forKey:(BOOL)key { 1204//% int idx = (key ? 1 : 0); 1205//% _values[idx] = value; 1206//% _valueSet[idx] = YES; 1207//% if (_autocreator) { 1208//% GPBAutocreatedDictionaryModified(_autocreator, self); 1209//% } 1210//%} 1211//% 1212//%- (void)remove##VALUE_NAME##ForKey:(BOOL)aKey { 1213//% _valueSet[aKey ? 1 : 0] = NO; 1214//%} 1215//% 1216//%- (void)removeAll { 1217//% _valueSet[0] = NO; 1218//% _valueSet[1] = NO; 1219//%} 1220//%PDDM-DEFINE STR_FORMAT_POD(VALUE_NAME) 1221//%STR_FORMAT_##VALUE_NAME() 1222//%PDDM-DEFINE STR_FORMAT_UInt32() 1223//%%u 1224//%PDDM-DEFINE STR_FORMAT_Int32() 1225//%%d 1226//%PDDM-DEFINE STR_FORMAT_UInt64() 1227//%%llu 1228//%PDDM-DEFINE STR_FORMAT_Int64() 1229//%%lld 1230//%PDDM-DEFINE STR_FORMAT_Bool() 1231//%%d 1232//%PDDM-DEFINE STR_FORMAT_Float() 1233//%%f 1234//%PDDM-DEFINE STR_FORMAT_Double() 1235//%%lf 1236 1237// 1238// Helpers for Objects 1239// 1240 1241//%PDDM-DEFINE VALUE_FOR_KEY_OBJECT(KEY_TYPE, VALUE_NAME, VALUE_TYPE, KHELPER) 1242//%- (VALUE_TYPE)objectForKey:(KEY_TYPE)key { 1243//% VALUE_TYPE result = [_dictionary objectForKey:WRAPPED##KHELPER(key)]; 1244//% return result; 1245//%} 1246//%PDDM-DEFINE WRAPPEDOBJECT(VALUE) 1247//%VALUE 1248//%PDDM-DEFINE UNWRAPString(VALUE) 1249//%VALUE 1250//%PDDM-DEFINE UNWRAPObject(VALUE) 1251//%VALUE 1252//%PDDM-DEFINE TEXT_FORMAT_OBJString(VALUE) 1253//%VALUE 1254//%PDDM-DEFINE TEXT_FORMAT_OBJObject(VALUE) 1255//%VALUE 1256//%PDDM-DEFINE ENUM_TYPEOBJECT(TYPE) 1257//%ENUM_TYPEOBJECT_##TYPE() 1258//%PDDM-DEFINE ENUM_TYPEOBJECT_NSString() 1259//%NSString * 1260//%PDDM-DEFINE ENUM_TYPEOBJECT_id() 1261//%id ## 1262//%PDDM-DEFINE NEQ_OBJECT(VAL1, VAL2) 1263//%![VAL1 isEqual:VAL2] 1264//%PDDM-DEFINE EXTRA_METHODS_OBJECT(KEY_NAME, VALUE_NAME) 1265//%- (BOOL)isInitialized { 1266//% for (GPBMessage *msg in [_dictionary objectEnumerator]) { 1267//% if (!msg.initialized) { 1268//% return NO; 1269//% } 1270//% } 1271//% return YES; 1272//%} 1273//% 1274//%- (instancetype)deepCopyWithZone:(NSZone *)zone { 1275//% GPB##KEY_NAME##VALUE_NAME##Dictionary *newDict = 1276//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] init]; 1277//% NSEnumerator *keys = [_dictionary keyEnumerator]; 1278//% id aKey; 1279//% NSMutableDictionary *internalDict = newDict->_dictionary; 1280//% while ((aKey = [keys nextObject])) { 1281//% GPBMessage *msg = _dictionary[aKey]; 1282//% GPBMessage *copiedMsg = [msg copyWithZone:zone]; 1283//% [internalDict setObject:copiedMsg forKey:aKey]; 1284//% [copiedMsg release]; 1285//% } 1286//% return newDict; 1287//%} 1288//% 1289//% 1290//%PDDM-DEFINE BOOL_EXTRA_METHODS_OBJECT(KEY_NAME, VALUE_NAME) 1291//%- (BOOL)isInitialized { 1292//% if (_values[0] && ![_values[0] isInitialized]) { 1293//% return NO; 1294//% } 1295//% if (_values[1] && ![_values[1] isInitialized]) { 1296//% return NO; 1297//% } 1298//% return YES; 1299//%} 1300//% 1301//%- (instancetype)deepCopyWithZone:(NSZone *)zone { 1302//% GPB##KEY_NAME##VALUE_NAME##Dictionary *newDict = 1303//% [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] init]; 1304//% for (int i = 0; i < 2; ++i) { 1305//% if (_values[i] != nil) { 1306//% newDict->_values[i] = [_values[i] copyWithZone:zone]; 1307//% } 1308//% } 1309//% return newDict; 1310//%} 1311//% 1312//% 1313//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_OBJECT(KEY_NAME, VALUE_NAME) 1314// Empty 1315//%PDDM-DEFINE GPBVALUE_OBJECT(VALUE_NAME) 1316//%valueString 1317//%PDDM-DEFINE DICTIONARY_VALIDATE_VALUE_OBJECT(VALUE_NAME, EXTRA_INDENT) 1318//%##EXTRA_INDENT$S## if (!##VALUE_NAME) { 1319//%##EXTRA_INDENT$S## [NSException raise:NSInvalidArgumentException 1320//%##EXTRA_INDENT$S## format:@"Attempting to add nil object to a Dictionary"]; 1321//%##EXTRA_INDENT$S## } 1322//% 1323//%PDDM-DEFINE DICTIONARY_VALIDATE_KEY_OBJECT(KEY_NAME, EXTRA_INDENT) 1324//%##EXTRA_INDENT$S## if (!##KEY_NAME) { 1325//%##EXTRA_INDENT$S## [NSException raise:NSInvalidArgumentException 1326//%##EXTRA_INDENT$S## format:@"Attempting to add nil key to a Dictionary"]; 1327//%##EXTRA_INDENT$S## } 1328//% 1329 1330//%PDDM-DEFINE BOOL_DICT_HAS_STORAGE_OBJECT() 1331// Empty 1332//%PDDM-DEFINE BOOL_DICT_INITS_OBJECT(VALUE_NAME, VALUE_TYPE) 1333//%- (instancetype)initWithObjects:(const VALUE_TYPE [])objects 1334//% forKeys:(const BOOL [])keys 1335//% count:(NSUInteger)count { 1336//% self = [super init]; 1337//% if (self) { 1338//% for (NSUInteger i = 0; i < count; ++i) { 1339//% if (!objects[i]) { 1340//% [NSException raise:NSInvalidArgumentException 1341//% format:@"Attempting to add nil object to a Dictionary"]; 1342//% } 1343//% int idx = keys[i] ? 1 : 0; 1344//% [_values[idx] release]; 1345//% _values[idx] = (VALUE_TYPE)[objects[i] retain]; 1346//% } 1347//% } 1348//% return self; 1349//%} 1350//% 1351//%- (instancetype)initWithDictionary:(GPBBool##VALUE_NAME##Dictionary *)dictionary { 1352//% self = [self initWithObjects:NULL forKeys:NULL count:0]; 1353//% if (self) { 1354//% if (dictionary) { 1355//% _values[0] = [dictionary->_values[0] retain]; 1356//% _values[1] = [dictionary->_values[1] retain]; 1357//% } 1358//% } 1359//% return self; 1360//%} 1361//%PDDM-DEFINE BOOL_DICT_DEALLOCOBJECT() 1362//%- (void)dealloc { 1363//% NSAssert(!_autocreator, 1364//% @"%@: Autocreator must be cleared before release, autocreator: %@", 1365//% [self class], _autocreator); 1366//% [_values[0] release]; 1367//% [_values[1] release]; 1368//% [super dealloc]; 1369//%} 1370//%PDDM-DEFINE BOOL_DICT_W_HASOBJECT(IDX, REF) 1371//%(BOOL_DICT_HASOBJECT(IDX, REF)) 1372//%PDDM-DEFINE BOOL_DICT_HASOBJECT(IDX, REF) 1373//%REF##_values[IDX] != nil 1374//%PDDM-DEFINE BOOL_VALUE_FOR_KEY_OBJECT(VALUE_NAME, VALUE_TYPE) 1375//%- (VALUE_TYPE)objectForKey:(BOOL)key { 1376//% return _values[key ? 1 : 0]; 1377//%} 1378//%PDDM-DEFINE BOOL_SET_GPBVALUE_FOR_KEY_OBJECT(VALUE_NAME, VALUE_TYPE, VisP) 1379//%- (void)setGPBGenericValue:(GPBGenericValue *)value 1380//% forGPBGenericValueKey:(GPBGenericValue *)key { 1381//% int idx = (key->valueBool ? 1 : 0); 1382//% [_values[idx] release]; 1383//% _values[idx] = [value->valueString retain]; 1384//%} 1385 1386//%PDDM-DEFINE BOOL_DICT_MUTATIONS_OBJECT(VALUE_NAME, VALUE_TYPE) 1387//%- (void)addEntriesFromDictionary:(GPBBool##VALUE_NAME##Dictionary *)otherDictionary { 1388//% if (otherDictionary) { 1389//% for (int i = 0; i < 2; ++i) { 1390//% if (otherDictionary->_values[i] != nil) { 1391//% [_values[i] release]; 1392//% _values[i] = [otherDictionary->_values[i] retain]; 1393//% } 1394//% } 1395//% if (_autocreator) { 1396//% GPBAutocreatedDictionaryModified(_autocreator, self); 1397//% } 1398//% } 1399//%} 1400//% 1401//%- (void)setObject:(VALUE_TYPE)object forKey:(BOOL)key { 1402//% if (!object) { 1403//% [NSException raise:NSInvalidArgumentException 1404//% format:@"Attempting to add nil object to a Dictionary"]; 1405//% } 1406//% int idx = (key ? 1 : 0); 1407//% [_values[idx] release]; 1408//% _values[idx] = [object retain]; 1409//% if (_autocreator) { 1410//% GPBAutocreatedDictionaryModified(_autocreator, self); 1411//% } 1412//%} 1413//% 1414//%- (void)removeObjectForKey:(BOOL)aKey { 1415//% int idx = (aKey ? 1 : 0); 1416//% [_values[idx] release]; 1417//% _values[idx] = nil; 1418//%} 1419//% 1420//%- (void)removeAll { 1421//% for (int i = 0; i < 2; ++i) { 1422//% [_values[i] release]; 1423//% _values[i] = nil; 1424//% } 1425//%} 1426//%PDDM-DEFINE STR_FORMAT_OBJECT(VALUE_NAME) 1427//%%@ 1428 1429 1430//%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(UInt32, uint32_t) 1431// This block of code is generated, do not edit it directly. 1432// clang-format off 1433 1434#pragma mark - UInt32 -> UInt32 1435 1436@implementation GPBUInt32UInt32Dictionary { 1437 @package 1438 NSMutableDictionary *_dictionary; 1439} 1440 1441- (instancetype)init { 1442 return [self initWithUInt32s:NULL forKeys:NULL count:0]; 1443} 1444 1445- (instancetype)initWithUInt32s:(const uint32_t [])values 1446 forKeys:(const uint32_t [])keys 1447 count:(NSUInteger)count { 1448 self = [super init]; 1449 if (self) { 1450 _dictionary = [[NSMutableDictionary alloc] init]; 1451 if (count && values && keys) { 1452 for (NSUInteger i = 0; i < count; ++i) { 1453 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; 1454 } 1455 } 1456 } 1457 return self; 1458} 1459 1460- (instancetype)initWithDictionary:(GPBUInt32UInt32Dictionary *)dictionary { 1461 self = [self initWithUInt32s:NULL forKeys:NULL count:0]; 1462 if (self) { 1463 if (dictionary) { 1464 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 1465 } 1466 } 1467 return self; 1468} 1469 1470- (instancetype)initWithCapacity:(NSUInteger)numItems { 1471 #pragma unused(numItems) 1472 return [self initWithUInt32s:NULL forKeys:NULL count:0]; 1473} 1474 1475- (void)dealloc { 1476 NSAssert(!_autocreator, 1477 @"%@: Autocreator must be cleared before release, autocreator: %@", 1478 [self class], _autocreator); 1479 [_dictionary release]; 1480 [super dealloc]; 1481} 1482 1483- (instancetype)copyWithZone:(NSZone *)zone { 1484 return [[GPBUInt32UInt32Dictionary allocWithZone:zone] initWithDictionary:self]; 1485} 1486 1487- (BOOL)isEqual:(id)other { 1488 if (self == other) { 1489 return YES; 1490 } 1491 if (![other isKindOfClass:[GPBUInt32UInt32Dictionary class]]) { 1492 return NO; 1493 } 1494 GPBUInt32UInt32Dictionary *otherDictionary = other; 1495 return [_dictionary isEqual:otherDictionary->_dictionary]; 1496} 1497 1498- (NSUInteger)hash { 1499 return _dictionary.count; 1500} 1501 1502- (NSString *)description { 1503 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 1504} 1505 1506- (NSUInteger)count { 1507 return _dictionary.count; 1508} 1509 1510- (void)enumerateKeysAndUInt32sUsingBlock: 1511 (void (NS_NOESCAPE ^)(uint32_t key, uint32_t value, BOOL *stop))block { 1512 BOOL stop = NO; 1513 NSDictionary *internal = _dictionary; 1514 NSEnumerator *keys = [internal keyEnumerator]; 1515 NSNumber *aKey; 1516 while ((aKey = [keys nextObject])) { 1517 NSNumber *aValue = internal[aKey]; 1518 block([aKey unsignedIntValue], [aValue unsignedIntValue], &stop); 1519 if (stop) { 1520 break; 1521 } 1522 } 1523} 1524 1525- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 1526 NSDictionary *internal = _dictionary; 1527 NSUInteger count = internal.count; 1528 if (count == 0) { 1529 return 0; 1530 } 1531 1532 GPBDataType valueDataType = GPBGetFieldDataType(field); 1533 GPBDataType keyDataType = field.mapKeyDataType; 1534 size_t result = 0; 1535 NSEnumerator *keys = [internal keyEnumerator]; 1536 NSNumber *aKey; 1537 while ((aKey = [keys nextObject])) { 1538 NSNumber *aValue = internal[aKey]; 1539 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType); 1540 msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType); 1541 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 1542 } 1543 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 1544 result += tagSize * count; 1545 return result; 1546} 1547 1548- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 1549 asField:(GPBFieldDescriptor *)field { 1550 GPBDataType valueDataType = GPBGetFieldDataType(field); 1551 GPBDataType keyDataType = field.mapKeyDataType; 1552 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 1553 NSDictionary *internal = _dictionary; 1554 NSEnumerator *keys = [internal keyEnumerator]; 1555 NSNumber *aKey; 1556 while ((aKey = [keys nextObject])) { 1557 NSNumber *aValue = internal[aKey]; 1558 [outputStream writeInt32NoTag:tag]; 1559 // Write the size of the message. 1560 uint32_t unwrappedKey = [aKey unsignedIntValue]; 1561 uint32_t unwrappedValue = [aValue unsignedIntValue]; 1562 size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 1563 msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 1564 [outputStream writeInt32NoTag:(int32_t)msgSize]; 1565 // Write the fields. 1566 WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 1567 WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 1568 } 1569} 1570 1571- (void)setGPBGenericValue:(GPBGenericValue *)value 1572 forGPBGenericValueKey:(GPBGenericValue *)key { 1573 [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueUInt32)]; 1574} 1575 1576- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 1577 [self enumerateKeysAndUInt32sUsingBlock:^(uint32_t key, uint32_t value, BOOL *stop) { 1578 #pragma unused(stop) 1579 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%u", value]); 1580 }]; 1581} 1582 1583- (BOOL)getUInt32:(nullable uint32_t *)value forKey:(uint32_t)key { 1584 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; 1585 if (wrapped && value) { 1586 *value = [wrapped unsignedIntValue]; 1587 } 1588 return (wrapped != NULL); 1589} 1590 1591- (void)addEntriesFromDictionary:(GPBUInt32UInt32Dictionary *)otherDictionary { 1592 if (otherDictionary) { 1593 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 1594 if (_autocreator) { 1595 GPBAutocreatedDictionaryModified(_autocreator, self); 1596 } 1597 } 1598} 1599 1600- (void)setUInt32:(uint32_t)value forKey:(uint32_t)key { 1601 [_dictionary setObject:@(value) forKey:@(key)]; 1602 if (_autocreator) { 1603 GPBAutocreatedDictionaryModified(_autocreator, self); 1604 } 1605} 1606 1607- (void)removeUInt32ForKey:(uint32_t)aKey { 1608 [_dictionary removeObjectForKey:@(aKey)]; 1609} 1610 1611- (void)removeAll { 1612 [_dictionary removeAllObjects]; 1613} 1614 1615@end 1616 1617#pragma mark - UInt32 -> Int32 1618 1619@implementation GPBUInt32Int32Dictionary { 1620 @package 1621 NSMutableDictionary *_dictionary; 1622} 1623 1624- (instancetype)init { 1625 return [self initWithInt32s:NULL forKeys:NULL count:0]; 1626} 1627 1628- (instancetype)initWithInt32s:(const int32_t [])values 1629 forKeys:(const uint32_t [])keys 1630 count:(NSUInteger)count { 1631 self = [super init]; 1632 if (self) { 1633 _dictionary = [[NSMutableDictionary alloc] init]; 1634 if (count && values && keys) { 1635 for (NSUInteger i = 0; i < count; ++i) { 1636 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; 1637 } 1638 } 1639 } 1640 return self; 1641} 1642 1643- (instancetype)initWithDictionary:(GPBUInt32Int32Dictionary *)dictionary { 1644 self = [self initWithInt32s:NULL forKeys:NULL count:0]; 1645 if (self) { 1646 if (dictionary) { 1647 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 1648 } 1649 } 1650 return self; 1651} 1652 1653- (instancetype)initWithCapacity:(NSUInteger)numItems { 1654 #pragma unused(numItems) 1655 return [self initWithInt32s:NULL forKeys:NULL count:0]; 1656} 1657 1658- (void)dealloc { 1659 NSAssert(!_autocreator, 1660 @"%@: Autocreator must be cleared before release, autocreator: %@", 1661 [self class], _autocreator); 1662 [_dictionary release]; 1663 [super dealloc]; 1664} 1665 1666- (instancetype)copyWithZone:(NSZone *)zone { 1667 return [[GPBUInt32Int32Dictionary allocWithZone:zone] initWithDictionary:self]; 1668} 1669 1670- (BOOL)isEqual:(id)other { 1671 if (self == other) { 1672 return YES; 1673 } 1674 if (![other isKindOfClass:[GPBUInt32Int32Dictionary class]]) { 1675 return NO; 1676 } 1677 GPBUInt32Int32Dictionary *otherDictionary = other; 1678 return [_dictionary isEqual:otherDictionary->_dictionary]; 1679} 1680 1681- (NSUInteger)hash { 1682 return _dictionary.count; 1683} 1684 1685- (NSString *)description { 1686 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 1687} 1688 1689- (NSUInteger)count { 1690 return _dictionary.count; 1691} 1692 1693- (void)enumerateKeysAndInt32sUsingBlock: 1694 (void (NS_NOESCAPE ^)(uint32_t key, int32_t value, BOOL *stop))block { 1695 BOOL stop = NO; 1696 NSDictionary *internal = _dictionary; 1697 NSEnumerator *keys = [internal keyEnumerator]; 1698 NSNumber *aKey; 1699 while ((aKey = [keys nextObject])) { 1700 NSNumber *aValue = internal[aKey]; 1701 block([aKey unsignedIntValue], [aValue intValue], &stop); 1702 if (stop) { 1703 break; 1704 } 1705 } 1706} 1707 1708- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 1709 NSDictionary *internal = _dictionary; 1710 NSUInteger count = internal.count; 1711 if (count == 0) { 1712 return 0; 1713 } 1714 1715 GPBDataType valueDataType = GPBGetFieldDataType(field); 1716 GPBDataType keyDataType = field.mapKeyDataType; 1717 size_t result = 0; 1718 NSEnumerator *keys = [internal keyEnumerator]; 1719 NSNumber *aKey; 1720 while ((aKey = [keys nextObject])) { 1721 NSNumber *aValue = internal[aKey]; 1722 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType); 1723 msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType); 1724 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 1725 } 1726 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 1727 result += tagSize * count; 1728 return result; 1729} 1730 1731- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 1732 asField:(GPBFieldDescriptor *)field { 1733 GPBDataType valueDataType = GPBGetFieldDataType(field); 1734 GPBDataType keyDataType = field.mapKeyDataType; 1735 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 1736 NSDictionary *internal = _dictionary; 1737 NSEnumerator *keys = [internal keyEnumerator]; 1738 NSNumber *aKey; 1739 while ((aKey = [keys nextObject])) { 1740 NSNumber *aValue = internal[aKey]; 1741 [outputStream writeInt32NoTag:tag]; 1742 // Write the size of the message. 1743 uint32_t unwrappedKey = [aKey unsignedIntValue]; 1744 int32_t unwrappedValue = [aValue intValue]; 1745 size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 1746 msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 1747 [outputStream writeInt32NoTag:(int32_t)msgSize]; 1748 // Write the fields. 1749 WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 1750 WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 1751 } 1752} 1753 1754- (void)setGPBGenericValue:(GPBGenericValue *)value 1755 forGPBGenericValueKey:(GPBGenericValue *)key { 1756 [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueUInt32)]; 1757} 1758 1759- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 1760 [self enumerateKeysAndInt32sUsingBlock:^(uint32_t key, int32_t value, BOOL *stop) { 1761 #pragma unused(stop) 1762 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%d", value]); 1763 }]; 1764} 1765 1766- (BOOL)getInt32:(nullable int32_t *)value forKey:(uint32_t)key { 1767 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; 1768 if (wrapped && value) { 1769 *value = [wrapped intValue]; 1770 } 1771 return (wrapped != NULL); 1772} 1773 1774- (void)addEntriesFromDictionary:(GPBUInt32Int32Dictionary *)otherDictionary { 1775 if (otherDictionary) { 1776 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 1777 if (_autocreator) { 1778 GPBAutocreatedDictionaryModified(_autocreator, self); 1779 } 1780 } 1781} 1782 1783- (void)setInt32:(int32_t)value forKey:(uint32_t)key { 1784 [_dictionary setObject:@(value) forKey:@(key)]; 1785 if (_autocreator) { 1786 GPBAutocreatedDictionaryModified(_autocreator, self); 1787 } 1788} 1789 1790- (void)removeInt32ForKey:(uint32_t)aKey { 1791 [_dictionary removeObjectForKey:@(aKey)]; 1792} 1793 1794- (void)removeAll { 1795 [_dictionary removeAllObjects]; 1796} 1797 1798@end 1799 1800#pragma mark - UInt32 -> UInt64 1801 1802@implementation GPBUInt32UInt64Dictionary { 1803 @package 1804 NSMutableDictionary *_dictionary; 1805} 1806 1807- (instancetype)init { 1808 return [self initWithUInt64s:NULL forKeys:NULL count:0]; 1809} 1810 1811- (instancetype)initWithUInt64s:(const uint64_t [])values 1812 forKeys:(const uint32_t [])keys 1813 count:(NSUInteger)count { 1814 self = [super init]; 1815 if (self) { 1816 _dictionary = [[NSMutableDictionary alloc] init]; 1817 if (count && values && keys) { 1818 for (NSUInteger i = 0; i < count; ++i) { 1819 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; 1820 } 1821 } 1822 } 1823 return self; 1824} 1825 1826- (instancetype)initWithDictionary:(GPBUInt32UInt64Dictionary *)dictionary { 1827 self = [self initWithUInt64s:NULL forKeys:NULL count:0]; 1828 if (self) { 1829 if (dictionary) { 1830 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 1831 } 1832 } 1833 return self; 1834} 1835 1836- (instancetype)initWithCapacity:(NSUInteger)numItems { 1837 #pragma unused(numItems) 1838 return [self initWithUInt64s:NULL forKeys:NULL count:0]; 1839} 1840 1841- (void)dealloc { 1842 NSAssert(!_autocreator, 1843 @"%@: Autocreator must be cleared before release, autocreator: %@", 1844 [self class], _autocreator); 1845 [_dictionary release]; 1846 [super dealloc]; 1847} 1848 1849- (instancetype)copyWithZone:(NSZone *)zone { 1850 return [[GPBUInt32UInt64Dictionary allocWithZone:zone] initWithDictionary:self]; 1851} 1852 1853- (BOOL)isEqual:(id)other { 1854 if (self == other) { 1855 return YES; 1856 } 1857 if (![other isKindOfClass:[GPBUInt32UInt64Dictionary class]]) { 1858 return NO; 1859 } 1860 GPBUInt32UInt64Dictionary *otherDictionary = other; 1861 return [_dictionary isEqual:otherDictionary->_dictionary]; 1862} 1863 1864- (NSUInteger)hash { 1865 return _dictionary.count; 1866} 1867 1868- (NSString *)description { 1869 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 1870} 1871 1872- (NSUInteger)count { 1873 return _dictionary.count; 1874} 1875 1876- (void)enumerateKeysAndUInt64sUsingBlock: 1877 (void (NS_NOESCAPE ^)(uint32_t key, uint64_t value, BOOL *stop))block { 1878 BOOL stop = NO; 1879 NSDictionary *internal = _dictionary; 1880 NSEnumerator *keys = [internal keyEnumerator]; 1881 NSNumber *aKey; 1882 while ((aKey = [keys nextObject])) { 1883 NSNumber *aValue = internal[aKey]; 1884 block([aKey unsignedIntValue], [aValue unsignedLongLongValue], &stop); 1885 if (stop) { 1886 break; 1887 } 1888 } 1889} 1890 1891- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 1892 NSDictionary *internal = _dictionary; 1893 NSUInteger count = internal.count; 1894 if (count == 0) { 1895 return 0; 1896 } 1897 1898 GPBDataType valueDataType = GPBGetFieldDataType(field); 1899 GPBDataType keyDataType = field.mapKeyDataType; 1900 size_t result = 0; 1901 NSEnumerator *keys = [internal keyEnumerator]; 1902 NSNumber *aKey; 1903 while ((aKey = [keys nextObject])) { 1904 NSNumber *aValue = internal[aKey]; 1905 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType); 1906 msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType); 1907 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 1908 } 1909 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 1910 result += tagSize * count; 1911 return result; 1912} 1913 1914- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 1915 asField:(GPBFieldDescriptor *)field { 1916 GPBDataType valueDataType = GPBGetFieldDataType(field); 1917 GPBDataType keyDataType = field.mapKeyDataType; 1918 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 1919 NSDictionary *internal = _dictionary; 1920 NSEnumerator *keys = [internal keyEnumerator]; 1921 NSNumber *aKey; 1922 while ((aKey = [keys nextObject])) { 1923 NSNumber *aValue = internal[aKey]; 1924 [outputStream writeInt32NoTag:tag]; 1925 // Write the size of the message. 1926 uint32_t unwrappedKey = [aKey unsignedIntValue]; 1927 uint64_t unwrappedValue = [aValue unsignedLongLongValue]; 1928 size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 1929 msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 1930 [outputStream writeInt32NoTag:(int32_t)msgSize]; 1931 // Write the fields. 1932 WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 1933 WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 1934 } 1935} 1936 1937- (void)setGPBGenericValue:(GPBGenericValue *)value 1938 forGPBGenericValueKey:(GPBGenericValue *)key { 1939 [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueUInt32)]; 1940} 1941 1942- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 1943 [self enumerateKeysAndUInt64sUsingBlock:^(uint32_t key, uint64_t value, BOOL *stop) { 1944 #pragma unused(stop) 1945 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%llu", value]); 1946 }]; 1947} 1948 1949- (BOOL)getUInt64:(nullable uint64_t *)value forKey:(uint32_t)key { 1950 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; 1951 if (wrapped && value) { 1952 *value = [wrapped unsignedLongLongValue]; 1953 } 1954 return (wrapped != NULL); 1955} 1956 1957- (void)addEntriesFromDictionary:(GPBUInt32UInt64Dictionary *)otherDictionary { 1958 if (otherDictionary) { 1959 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 1960 if (_autocreator) { 1961 GPBAutocreatedDictionaryModified(_autocreator, self); 1962 } 1963 } 1964} 1965 1966- (void)setUInt64:(uint64_t)value forKey:(uint32_t)key { 1967 [_dictionary setObject:@(value) forKey:@(key)]; 1968 if (_autocreator) { 1969 GPBAutocreatedDictionaryModified(_autocreator, self); 1970 } 1971} 1972 1973- (void)removeUInt64ForKey:(uint32_t)aKey { 1974 [_dictionary removeObjectForKey:@(aKey)]; 1975} 1976 1977- (void)removeAll { 1978 [_dictionary removeAllObjects]; 1979} 1980 1981@end 1982 1983#pragma mark - UInt32 -> Int64 1984 1985@implementation GPBUInt32Int64Dictionary { 1986 @package 1987 NSMutableDictionary *_dictionary; 1988} 1989 1990- (instancetype)init { 1991 return [self initWithInt64s:NULL forKeys:NULL count:0]; 1992} 1993 1994- (instancetype)initWithInt64s:(const int64_t [])values 1995 forKeys:(const uint32_t [])keys 1996 count:(NSUInteger)count { 1997 self = [super init]; 1998 if (self) { 1999 _dictionary = [[NSMutableDictionary alloc] init]; 2000 if (count && values && keys) { 2001 for (NSUInteger i = 0; i < count; ++i) { 2002 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; 2003 } 2004 } 2005 } 2006 return self; 2007} 2008 2009- (instancetype)initWithDictionary:(GPBUInt32Int64Dictionary *)dictionary { 2010 self = [self initWithInt64s:NULL forKeys:NULL count:0]; 2011 if (self) { 2012 if (dictionary) { 2013 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 2014 } 2015 } 2016 return self; 2017} 2018 2019- (instancetype)initWithCapacity:(NSUInteger)numItems { 2020 #pragma unused(numItems) 2021 return [self initWithInt64s:NULL forKeys:NULL count:0]; 2022} 2023 2024- (void)dealloc { 2025 NSAssert(!_autocreator, 2026 @"%@: Autocreator must be cleared before release, autocreator: %@", 2027 [self class], _autocreator); 2028 [_dictionary release]; 2029 [super dealloc]; 2030} 2031 2032- (instancetype)copyWithZone:(NSZone *)zone { 2033 return [[GPBUInt32Int64Dictionary allocWithZone:zone] initWithDictionary:self]; 2034} 2035 2036- (BOOL)isEqual:(id)other { 2037 if (self == other) { 2038 return YES; 2039 } 2040 if (![other isKindOfClass:[GPBUInt32Int64Dictionary class]]) { 2041 return NO; 2042 } 2043 GPBUInt32Int64Dictionary *otherDictionary = other; 2044 return [_dictionary isEqual:otherDictionary->_dictionary]; 2045} 2046 2047- (NSUInteger)hash { 2048 return _dictionary.count; 2049} 2050 2051- (NSString *)description { 2052 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 2053} 2054 2055- (NSUInteger)count { 2056 return _dictionary.count; 2057} 2058 2059- (void)enumerateKeysAndInt64sUsingBlock: 2060 (void (NS_NOESCAPE ^)(uint32_t key, int64_t value, BOOL *stop))block { 2061 BOOL stop = NO; 2062 NSDictionary *internal = _dictionary; 2063 NSEnumerator *keys = [internal keyEnumerator]; 2064 NSNumber *aKey; 2065 while ((aKey = [keys nextObject])) { 2066 NSNumber *aValue = internal[aKey]; 2067 block([aKey unsignedIntValue], [aValue longLongValue], &stop); 2068 if (stop) { 2069 break; 2070 } 2071 } 2072} 2073 2074- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 2075 NSDictionary *internal = _dictionary; 2076 NSUInteger count = internal.count; 2077 if (count == 0) { 2078 return 0; 2079 } 2080 2081 GPBDataType valueDataType = GPBGetFieldDataType(field); 2082 GPBDataType keyDataType = field.mapKeyDataType; 2083 size_t result = 0; 2084 NSEnumerator *keys = [internal keyEnumerator]; 2085 NSNumber *aKey; 2086 while ((aKey = [keys nextObject])) { 2087 NSNumber *aValue = internal[aKey]; 2088 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType); 2089 msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType); 2090 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 2091 } 2092 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 2093 result += tagSize * count; 2094 return result; 2095} 2096 2097- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 2098 asField:(GPBFieldDescriptor *)field { 2099 GPBDataType valueDataType = GPBGetFieldDataType(field); 2100 GPBDataType keyDataType = field.mapKeyDataType; 2101 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 2102 NSDictionary *internal = _dictionary; 2103 NSEnumerator *keys = [internal keyEnumerator]; 2104 NSNumber *aKey; 2105 while ((aKey = [keys nextObject])) { 2106 NSNumber *aValue = internal[aKey]; 2107 [outputStream writeInt32NoTag:tag]; 2108 // Write the size of the message. 2109 uint32_t unwrappedKey = [aKey unsignedIntValue]; 2110 int64_t unwrappedValue = [aValue longLongValue]; 2111 size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 2112 msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 2113 [outputStream writeInt32NoTag:(int32_t)msgSize]; 2114 // Write the fields. 2115 WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 2116 WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 2117 } 2118} 2119 2120- (void)setGPBGenericValue:(GPBGenericValue *)value 2121 forGPBGenericValueKey:(GPBGenericValue *)key { 2122 [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueUInt32)]; 2123} 2124 2125- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 2126 [self enumerateKeysAndInt64sUsingBlock:^(uint32_t key, int64_t value, BOOL *stop) { 2127 #pragma unused(stop) 2128 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%lld", value]); 2129 }]; 2130} 2131 2132- (BOOL)getInt64:(nullable int64_t *)value forKey:(uint32_t)key { 2133 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; 2134 if (wrapped && value) { 2135 *value = [wrapped longLongValue]; 2136 } 2137 return (wrapped != NULL); 2138} 2139 2140- (void)addEntriesFromDictionary:(GPBUInt32Int64Dictionary *)otherDictionary { 2141 if (otherDictionary) { 2142 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 2143 if (_autocreator) { 2144 GPBAutocreatedDictionaryModified(_autocreator, self); 2145 } 2146 } 2147} 2148 2149- (void)setInt64:(int64_t)value forKey:(uint32_t)key { 2150 [_dictionary setObject:@(value) forKey:@(key)]; 2151 if (_autocreator) { 2152 GPBAutocreatedDictionaryModified(_autocreator, self); 2153 } 2154} 2155 2156- (void)removeInt64ForKey:(uint32_t)aKey { 2157 [_dictionary removeObjectForKey:@(aKey)]; 2158} 2159 2160- (void)removeAll { 2161 [_dictionary removeAllObjects]; 2162} 2163 2164@end 2165 2166#pragma mark - UInt32 -> Bool 2167 2168@implementation GPBUInt32BoolDictionary { 2169 @package 2170 NSMutableDictionary *_dictionary; 2171} 2172 2173- (instancetype)init { 2174 return [self initWithBools:NULL forKeys:NULL count:0]; 2175} 2176 2177- (instancetype)initWithBools:(const BOOL [])values 2178 forKeys:(const uint32_t [])keys 2179 count:(NSUInteger)count { 2180 self = [super init]; 2181 if (self) { 2182 _dictionary = [[NSMutableDictionary alloc] init]; 2183 if (count && values && keys) { 2184 for (NSUInteger i = 0; i < count; ++i) { 2185 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; 2186 } 2187 } 2188 } 2189 return self; 2190} 2191 2192- (instancetype)initWithDictionary:(GPBUInt32BoolDictionary *)dictionary { 2193 self = [self initWithBools:NULL forKeys:NULL count:0]; 2194 if (self) { 2195 if (dictionary) { 2196 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 2197 } 2198 } 2199 return self; 2200} 2201 2202- (instancetype)initWithCapacity:(NSUInteger)numItems { 2203 #pragma unused(numItems) 2204 return [self initWithBools:NULL forKeys:NULL count:0]; 2205} 2206 2207- (void)dealloc { 2208 NSAssert(!_autocreator, 2209 @"%@: Autocreator must be cleared before release, autocreator: %@", 2210 [self class], _autocreator); 2211 [_dictionary release]; 2212 [super dealloc]; 2213} 2214 2215- (instancetype)copyWithZone:(NSZone *)zone { 2216 return [[GPBUInt32BoolDictionary allocWithZone:zone] initWithDictionary:self]; 2217} 2218 2219- (BOOL)isEqual:(id)other { 2220 if (self == other) { 2221 return YES; 2222 } 2223 if (![other isKindOfClass:[GPBUInt32BoolDictionary class]]) { 2224 return NO; 2225 } 2226 GPBUInt32BoolDictionary *otherDictionary = other; 2227 return [_dictionary isEqual:otherDictionary->_dictionary]; 2228} 2229 2230- (NSUInteger)hash { 2231 return _dictionary.count; 2232} 2233 2234- (NSString *)description { 2235 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 2236} 2237 2238- (NSUInteger)count { 2239 return _dictionary.count; 2240} 2241 2242- (void)enumerateKeysAndBoolsUsingBlock: 2243 (void (NS_NOESCAPE ^)(uint32_t key, BOOL value, BOOL *stop))block { 2244 BOOL stop = NO; 2245 NSDictionary *internal = _dictionary; 2246 NSEnumerator *keys = [internal keyEnumerator]; 2247 NSNumber *aKey; 2248 while ((aKey = [keys nextObject])) { 2249 NSNumber *aValue = internal[aKey]; 2250 block([aKey unsignedIntValue], [aValue boolValue], &stop); 2251 if (stop) { 2252 break; 2253 } 2254 } 2255} 2256 2257- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 2258 NSDictionary *internal = _dictionary; 2259 NSUInteger count = internal.count; 2260 if (count == 0) { 2261 return 0; 2262 } 2263 2264 GPBDataType valueDataType = GPBGetFieldDataType(field); 2265 GPBDataType keyDataType = field.mapKeyDataType; 2266 size_t result = 0; 2267 NSEnumerator *keys = [internal keyEnumerator]; 2268 NSNumber *aKey; 2269 while ((aKey = [keys nextObject])) { 2270 NSNumber *aValue = internal[aKey]; 2271 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType); 2272 msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType); 2273 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 2274 } 2275 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 2276 result += tagSize * count; 2277 return result; 2278} 2279 2280- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 2281 asField:(GPBFieldDescriptor *)field { 2282 GPBDataType valueDataType = GPBGetFieldDataType(field); 2283 GPBDataType keyDataType = field.mapKeyDataType; 2284 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 2285 NSDictionary *internal = _dictionary; 2286 NSEnumerator *keys = [internal keyEnumerator]; 2287 NSNumber *aKey; 2288 while ((aKey = [keys nextObject])) { 2289 NSNumber *aValue = internal[aKey]; 2290 [outputStream writeInt32NoTag:tag]; 2291 // Write the size of the message. 2292 uint32_t unwrappedKey = [aKey unsignedIntValue]; 2293 BOOL unwrappedValue = [aValue boolValue]; 2294 size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 2295 msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 2296 [outputStream writeInt32NoTag:(int32_t)msgSize]; 2297 // Write the fields. 2298 WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 2299 WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 2300 } 2301} 2302 2303- (void)setGPBGenericValue:(GPBGenericValue *)value 2304 forGPBGenericValueKey:(GPBGenericValue *)key { 2305 [_dictionary setObject:@(value->valueBool) forKey:@(key->valueUInt32)]; 2306} 2307 2308- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 2309 [self enumerateKeysAndBoolsUsingBlock:^(uint32_t key, BOOL value, BOOL *stop) { 2310 #pragma unused(stop) 2311 block([NSString stringWithFormat:@"%u", key], (value ? @"true" : @"false")); 2312 }]; 2313} 2314 2315- (BOOL)getBool:(nullable BOOL *)value forKey:(uint32_t)key { 2316 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; 2317 if (wrapped && value) { 2318 *value = [wrapped boolValue]; 2319 } 2320 return (wrapped != NULL); 2321} 2322 2323- (void)addEntriesFromDictionary:(GPBUInt32BoolDictionary *)otherDictionary { 2324 if (otherDictionary) { 2325 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 2326 if (_autocreator) { 2327 GPBAutocreatedDictionaryModified(_autocreator, self); 2328 } 2329 } 2330} 2331 2332- (void)setBool:(BOOL)value forKey:(uint32_t)key { 2333 [_dictionary setObject:@(value) forKey:@(key)]; 2334 if (_autocreator) { 2335 GPBAutocreatedDictionaryModified(_autocreator, self); 2336 } 2337} 2338 2339- (void)removeBoolForKey:(uint32_t)aKey { 2340 [_dictionary removeObjectForKey:@(aKey)]; 2341} 2342 2343- (void)removeAll { 2344 [_dictionary removeAllObjects]; 2345} 2346 2347@end 2348 2349#pragma mark - UInt32 -> Float 2350 2351@implementation GPBUInt32FloatDictionary { 2352 @package 2353 NSMutableDictionary *_dictionary; 2354} 2355 2356- (instancetype)init { 2357 return [self initWithFloats:NULL forKeys:NULL count:0]; 2358} 2359 2360- (instancetype)initWithFloats:(const float [])values 2361 forKeys:(const uint32_t [])keys 2362 count:(NSUInteger)count { 2363 self = [super init]; 2364 if (self) { 2365 _dictionary = [[NSMutableDictionary alloc] init]; 2366 if (count && values && keys) { 2367 for (NSUInteger i = 0; i < count; ++i) { 2368 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; 2369 } 2370 } 2371 } 2372 return self; 2373} 2374 2375- (instancetype)initWithDictionary:(GPBUInt32FloatDictionary *)dictionary { 2376 self = [self initWithFloats:NULL forKeys:NULL count:0]; 2377 if (self) { 2378 if (dictionary) { 2379 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 2380 } 2381 } 2382 return self; 2383} 2384 2385- (instancetype)initWithCapacity:(NSUInteger)numItems { 2386 #pragma unused(numItems) 2387 return [self initWithFloats:NULL forKeys:NULL count:0]; 2388} 2389 2390- (void)dealloc { 2391 NSAssert(!_autocreator, 2392 @"%@: Autocreator must be cleared before release, autocreator: %@", 2393 [self class], _autocreator); 2394 [_dictionary release]; 2395 [super dealloc]; 2396} 2397 2398- (instancetype)copyWithZone:(NSZone *)zone { 2399 return [[GPBUInt32FloatDictionary allocWithZone:zone] initWithDictionary:self]; 2400} 2401 2402- (BOOL)isEqual:(id)other { 2403 if (self == other) { 2404 return YES; 2405 } 2406 if (![other isKindOfClass:[GPBUInt32FloatDictionary class]]) { 2407 return NO; 2408 } 2409 GPBUInt32FloatDictionary *otherDictionary = other; 2410 return [_dictionary isEqual:otherDictionary->_dictionary]; 2411} 2412 2413- (NSUInteger)hash { 2414 return _dictionary.count; 2415} 2416 2417- (NSString *)description { 2418 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 2419} 2420 2421- (NSUInteger)count { 2422 return _dictionary.count; 2423} 2424 2425- (void)enumerateKeysAndFloatsUsingBlock: 2426 (void (NS_NOESCAPE ^)(uint32_t key, float value, BOOL *stop))block { 2427 BOOL stop = NO; 2428 NSDictionary *internal = _dictionary; 2429 NSEnumerator *keys = [internal keyEnumerator]; 2430 NSNumber *aKey; 2431 while ((aKey = [keys nextObject])) { 2432 NSNumber *aValue = internal[aKey]; 2433 block([aKey unsignedIntValue], [aValue floatValue], &stop); 2434 if (stop) { 2435 break; 2436 } 2437 } 2438} 2439 2440- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 2441 NSDictionary *internal = _dictionary; 2442 NSUInteger count = internal.count; 2443 if (count == 0) { 2444 return 0; 2445 } 2446 2447 GPBDataType valueDataType = GPBGetFieldDataType(field); 2448 GPBDataType keyDataType = field.mapKeyDataType; 2449 size_t result = 0; 2450 NSEnumerator *keys = [internal keyEnumerator]; 2451 NSNumber *aKey; 2452 while ((aKey = [keys nextObject])) { 2453 NSNumber *aValue = internal[aKey]; 2454 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType); 2455 msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType); 2456 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 2457 } 2458 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 2459 result += tagSize * count; 2460 return result; 2461} 2462 2463- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 2464 asField:(GPBFieldDescriptor *)field { 2465 GPBDataType valueDataType = GPBGetFieldDataType(field); 2466 GPBDataType keyDataType = field.mapKeyDataType; 2467 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 2468 NSDictionary *internal = _dictionary; 2469 NSEnumerator *keys = [internal keyEnumerator]; 2470 NSNumber *aKey; 2471 while ((aKey = [keys nextObject])) { 2472 NSNumber *aValue = internal[aKey]; 2473 [outputStream writeInt32NoTag:tag]; 2474 // Write the size of the message. 2475 uint32_t unwrappedKey = [aKey unsignedIntValue]; 2476 float unwrappedValue = [aValue floatValue]; 2477 size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 2478 msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 2479 [outputStream writeInt32NoTag:(int32_t)msgSize]; 2480 // Write the fields. 2481 WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 2482 WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 2483 } 2484} 2485 2486- (void)setGPBGenericValue:(GPBGenericValue *)value 2487 forGPBGenericValueKey:(GPBGenericValue *)key { 2488 [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueUInt32)]; 2489} 2490 2491- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 2492 [self enumerateKeysAndFloatsUsingBlock:^(uint32_t key, float value, BOOL *stop) { 2493 #pragma unused(stop) 2494 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]); 2495 }]; 2496} 2497 2498- (BOOL)getFloat:(nullable float *)value forKey:(uint32_t)key { 2499 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; 2500 if (wrapped && value) { 2501 *value = [wrapped floatValue]; 2502 } 2503 return (wrapped != NULL); 2504} 2505 2506- (void)addEntriesFromDictionary:(GPBUInt32FloatDictionary *)otherDictionary { 2507 if (otherDictionary) { 2508 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 2509 if (_autocreator) { 2510 GPBAutocreatedDictionaryModified(_autocreator, self); 2511 } 2512 } 2513} 2514 2515- (void)setFloat:(float)value forKey:(uint32_t)key { 2516 [_dictionary setObject:@(value) forKey:@(key)]; 2517 if (_autocreator) { 2518 GPBAutocreatedDictionaryModified(_autocreator, self); 2519 } 2520} 2521 2522- (void)removeFloatForKey:(uint32_t)aKey { 2523 [_dictionary removeObjectForKey:@(aKey)]; 2524} 2525 2526- (void)removeAll { 2527 [_dictionary removeAllObjects]; 2528} 2529 2530@end 2531 2532#pragma mark - UInt32 -> Double 2533 2534@implementation GPBUInt32DoubleDictionary { 2535 @package 2536 NSMutableDictionary *_dictionary; 2537} 2538 2539- (instancetype)init { 2540 return [self initWithDoubles:NULL forKeys:NULL count:0]; 2541} 2542 2543- (instancetype)initWithDoubles:(const double [])values 2544 forKeys:(const uint32_t [])keys 2545 count:(NSUInteger)count { 2546 self = [super init]; 2547 if (self) { 2548 _dictionary = [[NSMutableDictionary alloc] init]; 2549 if (count && values && keys) { 2550 for (NSUInteger i = 0; i < count; ++i) { 2551 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; 2552 } 2553 } 2554 } 2555 return self; 2556} 2557 2558- (instancetype)initWithDictionary:(GPBUInt32DoubleDictionary *)dictionary { 2559 self = [self initWithDoubles:NULL forKeys:NULL count:0]; 2560 if (self) { 2561 if (dictionary) { 2562 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 2563 } 2564 } 2565 return self; 2566} 2567 2568- (instancetype)initWithCapacity:(NSUInteger)numItems { 2569 #pragma unused(numItems) 2570 return [self initWithDoubles:NULL forKeys:NULL count:0]; 2571} 2572 2573- (void)dealloc { 2574 NSAssert(!_autocreator, 2575 @"%@: Autocreator must be cleared before release, autocreator: %@", 2576 [self class], _autocreator); 2577 [_dictionary release]; 2578 [super dealloc]; 2579} 2580 2581- (instancetype)copyWithZone:(NSZone *)zone { 2582 return [[GPBUInt32DoubleDictionary allocWithZone:zone] initWithDictionary:self]; 2583} 2584 2585- (BOOL)isEqual:(id)other { 2586 if (self == other) { 2587 return YES; 2588 } 2589 if (![other isKindOfClass:[GPBUInt32DoubleDictionary class]]) { 2590 return NO; 2591 } 2592 GPBUInt32DoubleDictionary *otherDictionary = other; 2593 return [_dictionary isEqual:otherDictionary->_dictionary]; 2594} 2595 2596- (NSUInteger)hash { 2597 return _dictionary.count; 2598} 2599 2600- (NSString *)description { 2601 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 2602} 2603 2604- (NSUInteger)count { 2605 return _dictionary.count; 2606} 2607 2608- (void)enumerateKeysAndDoublesUsingBlock: 2609 (void (NS_NOESCAPE ^)(uint32_t key, double value, BOOL *stop))block { 2610 BOOL stop = NO; 2611 NSDictionary *internal = _dictionary; 2612 NSEnumerator *keys = [internal keyEnumerator]; 2613 NSNumber *aKey; 2614 while ((aKey = [keys nextObject])) { 2615 NSNumber *aValue = internal[aKey]; 2616 block([aKey unsignedIntValue], [aValue doubleValue], &stop); 2617 if (stop) { 2618 break; 2619 } 2620 } 2621} 2622 2623- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 2624 NSDictionary *internal = _dictionary; 2625 NSUInteger count = internal.count; 2626 if (count == 0) { 2627 return 0; 2628 } 2629 2630 GPBDataType valueDataType = GPBGetFieldDataType(field); 2631 GPBDataType keyDataType = field.mapKeyDataType; 2632 size_t result = 0; 2633 NSEnumerator *keys = [internal keyEnumerator]; 2634 NSNumber *aKey; 2635 while ((aKey = [keys nextObject])) { 2636 NSNumber *aValue = internal[aKey]; 2637 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType); 2638 msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType); 2639 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 2640 } 2641 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 2642 result += tagSize * count; 2643 return result; 2644} 2645 2646- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 2647 asField:(GPBFieldDescriptor *)field { 2648 GPBDataType valueDataType = GPBGetFieldDataType(field); 2649 GPBDataType keyDataType = field.mapKeyDataType; 2650 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 2651 NSDictionary *internal = _dictionary; 2652 NSEnumerator *keys = [internal keyEnumerator]; 2653 NSNumber *aKey; 2654 while ((aKey = [keys nextObject])) { 2655 NSNumber *aValue = internal[aKey]; 2656 [outputStream writeInt32NoTag:tag]; 2657 // Write the size of the message. 2658 uint32_t unwrappedKey = [aKey unsignedIntValue]; 2659 double unwrappedValue = [aValue doubleValue]; 2660 size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 2661 msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 2662 [outputStream writeInt32NoTag:(int32_t)msgSize]; 2663 // Write the fields. 2664 WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 2665 WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 2666 } 2667} 2668 2669- (void)setGPBGenericValue:(GPBGenericValue *)value 2670 forGPBGenericValueKey:(GPBGenericValue *)key { 2671 [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueUInt32)]; 2672} 2673 2674- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 2675 [self enumerateKeysAndDoublesUsingBlock:^(uint32_t key, double value, BOOL *stop) { 2676 #pragma unused(stop) 2677 block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]); 2678 }]; 2679} 2680 2681- (BOOL)getDouble:(nullable double *)value forKey:(uint32_t)key { 2682 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; 2683 if (wrapped && value) { 2684 *value = [wrapped doubleValue]; 2685 } 2686 return (wrapped != NULL); 2687} 2688 2689- (void)addEntriesFromDictionary:(GPBUInt32DoubleDictionary *)otherDictionary { 2690 if (otherDictionary) { 2691 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 2692 if (_autocreator) { 2693 GPBAutocreatedDictionaryModified(_autocreator, self); 2694 } 2695 } 2696} 2697 2698- (void)setDouble:(double)value forKey:(uint32_t)key { 2699 [_dictionary setObject:@(value) forKey:@(key)]; 2700 if (_autocreator) { 2701 GPBAutocreatedDictionaryModified(_autocreator, self); 2702 } 2703} 2704 2705- (void)removeDoubleForKey:(uint32_t)aKey { 2706 [_dictionary removeObjectForKey:@(aKey)]; 2707} 2708 2709- (void)removeAll { 2710 [_dictionary removeAllObjects]; 2711} 2712 2713@end 2714 2715#pragma mark - UInt32 -> Enum 2716 2717@implementation GPBUInt32EnumDictionary { 2718 @package 2719 NSMutableDictionary *_dictionary; 2720 GPBEnumValidationFunc _validationFunc; 2721} 2722 2723@synthesize validationFunc = _validationFunc; 2724 2725- (instancetype)init { 2726 return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0]; 2727} 2728 2729- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func { 2730 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0]; 2731} 2732 2733- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func 2734 rawValues:(const int32_t [])rawValues 2735 forKeys:(const uint32_t [])keys 2736 count:(NSUInteger)count { 2737 self = [super init]; 2738 if (self) { 2739 _dictionary = [[NSMutableDictionary alloc] init]; 2740 _validationFunc = (func != NULL ? func : DictDefault_IsValidValue); 2741 if (count && rawValues && keys) { 2742 for (NSUInteger i = 0; i < count; ++i) { 2743 [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])]; 2744 } 2745 } 2746 } 2747 return self; 2748} 2749 2750- (instancetype)initWithDictionary:(GPBUInt32EnumDictionary *)dictionary { 2751 self = [self initWithValidationFunction:dictionary.validationFunc 2752 rawValues:NULL 2753 forKeys:NULL 2754 count:0]; 2755 if (self) { 2756 if (dictionary) { 2757 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 2758 } 2759 } 2760 return self; 2761} 2762 2763- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func 2764 capacity:(NSUInteger)numItems { 2765 #pragma unused(numItems) 2766 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0]; 2767} 2768 2769- (void)dealloc { 2770 NSAssert(!_autocreator, 2771 @"%@: Autocreator must be cleared before release, autocreator: %@", 2772 [self class], _autocreator); 2773 [_dictionary release]; 2774 [super dealloc]; 2775} 2776 2777- (instancetype)copyWithZone:(NSZone *)zone { 2778 return [[GPBUInt32EnumDictionary allocWithZone:zone] initWithDictionary:self]; 2779} 2780 2781- (BOOL)isEqual:(id)other { 2782 if (self == other) { 2783 return YES; 2784 } 2785 if (![other isKindOfClass:[GPBUInt32EnumDictionary class]]) { 2786 return NO; 2787 } 2788 GPBUInt32EnumDictionary *otherDictionary = other; 2789 return [_dictionary isEqual:otherDictionary->_dictionary]; 2790} 2791 2792- (NSUInteger)hash { 2793 return _dictionary.count; 2794} 2795 2796- (NSString *)description { 2797 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 2798} 2799 2800- (NSUInteger)count { 2801 return _dictionary.count; 2802} 2803 2804- (void)enumerateKeysAndRawValuesUsingBlock: 2805 (void (NS_NOESCAPE ^)(uint32_t key, int32_t value, BOOL *stop))block { 2806 BOOL stop = NO; 2807 NSDictionary *internal = _dictionary; 2808 NSEnumerator *keys = [internal keyEnumerator]; 2809 NSNumber *aKey; 2810 while ((aKey = [keys nextObject])) { 2811 NSNumber *aValue = internal[aKey]; 2812 block([aKey unsignedIntValue], [aValue intValue], &stop); 2813 if (stop) { 2814 break; 2815 } 2816 } 2817} 2818 2819- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 2820 NSDictionary *internal = _dictionary; 2821 NSUInteger count = internal.count; 2822 if (count == 0) { 2823 return 0; 2824 } 2825 2826 GPBDataType valueDataType = GPBGetFieldDataType(field); 2827 GPBDataType keyDataType = field.mapKeyDataType; 2828 size_t result = 0; 2829 NSEnumerator *keys = [internal keyEnumerator]; 2830 NSNumber *aKey; 2831 while ((aKey = [keys nextObject])) { 2832 NSNumber *aValue = internal[aKey]; 2833 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType); 2834 msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType); 2835 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 2836 } 2837 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 2838 result += tagSize * count; 2839 return result; 2840} 2841 2842- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 2843 asField:(GPBFieldDescriptor *)field { 2844 GPBDataType valueDataType = GPBGetFieldDataType(field); 2845 GPBDataType keyDataType = field.mapKeyDataType; 2846 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 2847 NSDictionary *internal = _dictionary; 2848 NSEnumerator *keys = [internal keyEnumerator]; 2849 NSNumber *aKey; 2850 while ((aKey = [keys nextObject])) { 2851 NSNumber *aValue = internal[aKey]; 2852 [outputStream writeInt32NoTag:tag]; 2853 // Write the size of the message. 2854 uint32_t unwrappedKey = [aKey unsignedIntValue]; 2855 int32_t unwrappedValue = [aValue intValue]; 2856 size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 2857 msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 2858 [outputStream writeInt32NoTag:(int32_t)msgSize]; 2859 // Write the fields. 2860 WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 2861 WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 2862 } 2863} 2864 2865- (NSData *)serializedDataForUnknownValue:(int32_t)value 2866 forKey:(GPBGenericValue *)key 2867 keyDataType:(GPBDataType)keyDataType { 2868 size_t msgSize = ComputeDictUInt32FieldSize(key->valueUInt32, kMapKeyFieldNumber, keyDataType); 2869 msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum); 2870 NSMutableData *data = [NSMutableData dataWithLength:msgSize]; 2871 GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data]; 2872 WriteDictUInt32Field(outputStream, key->valueUInt32, kMapKeyFieldNumber, keyDataType); 2873 WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum); 2874 [outputStream release]; 2875 return data; 2876} 2877- (void)setGPBGenericValue:(GPBGenericValue *)value 2878 forGPBGenericValueKey:(GPBGenericValue *)key { 2879 [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueUInt32)]; 2880} 2881 2882- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 2883 [self enumerateKeysAndRawValuesUsingBlock:^(uint32_t key, int32_t value, BOOL *stop) { 2884 #pragma unused(stop) 2885 block([NSString stringWithFormat:@"%u", key], @(value)); 2886 }]; 2887} 2888 2889- (BOOL)getEnum:(int32_t *)value forKey:(uint32_t)key { 2890 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; 2891 if (wrapped && value) { 2892 int32_t result = [wrapped intValue]; 2893 if (!_validationFunc(result)) { 2894 result = kGPBUnrecognizedEnumeratorValue; 2895 } 2896 *value = result; 2897 } 2898 return (wrapped != NULL); 2899} 2900 2901- (BOOL)getRawValue:(int32_t *)rawValue forKey:(uint32_t)key { 2902 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; 2903 if (wrapped && rawValue) { 2904 *rawValue = [wrapped intValue]; 2905 } 2906 return (wrapped != NULL); 2907} 2908 2909- (void)enumerateKeysAndEnumsUsingBlock: 2910 (void (NS_NOESCAPE ^)(uint32_t key, int32_t value, BOOL *stop))block { 2911 GPBEnumValidationFunc func = _validationFunc; 2912 BOOL stop = NO; 2913 NSEnumerator *keys = [_dictionary keyEnumerator]; 2914 NSNumber *aKey; 2915 while ((aKey = [keys nextObject])) { 2916 NSNumber *aValue = _dictionary[aKey]; 2917 int32_t unwrapped = [aValue intValue]; 2918 if (!func(unwrapped)) { 2919 unwrapped = kGPBUnrecognizedEnumeratorValue; 2920 } 2921 block([aKey unsignedIntValue], unwrapped, &stop); 2922 if (stop) { 2923 break; 2924 } 2925 } 2926} 2927 2928- (void)addRawEntriesFromDictionary:(GPBUInt32EnumDictionary *)otherDictionary { 2929 if (otherDictionary) { 2930 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 2931 if (_autocreator) { 2932 GPBAutocreatedDictionaryModified(_autocreator, self); 2933 } 2934 } 2935} 2936 2937- (void)setRawValue:(int32_t)value forKey:(uint32_t)key { 2938 [_dictionary setObject:@(value) forKey:@(key)]; 2939 if (_autocreator) { 2940 GPBAutocreatedDictionaryModified(_autocreator, self); 2941 } 2942} 2943 2944- (void)removeEnumForKey:(uint32_t)aKey { 2945 [_dictionary removeObjectForKey:@(aKey)]; 2946} 2947 2948- (void)removeAll { 2949 [_dictionary removeAllObjects]; 2950} 2951 2952- (void)setEnum:(int32_t)value forKey:(uint32_t)key { 2953 if (!_validationFunc(value)) { 2954 [NSException raise:NSInvalidArgumentException 2955 format:@"GPBUInt32EnumDictionary: Attempt to set an unknown enum value (%d)", 2956 value]; 2957 } 2958 2959 [_dictionary setObject:@(value) forKey:@(key)]; 2960 if (_autocreator) { 2961 GPBAutocreatedDictionaryModified(_autocreator, self); 2962 } 2963} 2964 2965@end 2966 2967#pragma mark - UInt32 -> Object 2968 2969@implementation GPBUInt32ObjectDictionary { 2970 @package 2971 NSMutableDictionary *_dictionary; 2972} 2973 2974- (instancetype)init { 2975 return [self initWithObjects:NULL forKeys:NULL count:0]; 2976} 2977 2978- (instancetype)initWithObjects:(const id [])objects 2979 forKeys:(const uint32_t [])keys 2980 count:(NSUInteger)count { 2981 self = [super init]; 2982 if (self) { 2983 _dictionary = [[NSMutableDictionary alloc] init]; 2984 if (count && objects && keys) { 2985 for (NSUInteger i = 0; i < count; ++i) { 2986 if (!objects[i]) { 2987 [NSException raise:NSInvalidArgumentException 2988 format:@"Attempting to add nil object to a Dictionary"]; 2989 } 2990 [_dictionary setObject:objects[i] forKey:@(keys[i])]; 2991 } 2992 } 2993 } 2994 return self; 2995} 2996 2997- (instancetype)initWithDictionary:(GPBUInt32ObjectDictionary *)dictionary { 2998 self = [self initWithObjects:NULL forKeys:NULL count:0]; 2999 if (self) { 3000 if (dictionary) { 3001 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 3002 } 3003 } 3004 return self; 3005} 3006 3007- (instancetype)initWithCapacity:(NSUInteger)numItems { 3008 #pragma unused(numItems) 3009 return [self initWithObjects:NULL forKeys:NULL count:0]; 3010} 3011 3012- (void)dealloc { 3013 NSAssert(!_autocreator, 3014 @"%@: Autocreator must be cleared before release, autocreator: %@", 3015 [self class], _autocreator); 3016 [_dictionary release]; 3017 [super dealloc]; 3018} 3019 3020- (instancetype)copyWithZone:(NSZone *)zone { 3021 return [[GPBUInt32ObjectDictionary allocWithZone:zone] initWithDictionary:self]; 3022} 3023 3024- (BOOL)isEqual:(id)other { 3025 if (self == other) { 3026 return YES; 3027 } 3028 if (![other isKindOfClass:[GPBUInt32ObjectDictionary class]]) { 3029 return NO; 3030 } 3031 GPBUInt32ObjectDictionary *otherDictionary = other; 3032 return [_dictionary isEqual:otherDictionary->_dictionary]; 3033} 3034 3035- (NSUInteger)hash { 3036 return _dictionary.count; 3037} 3038 3039- (NSString *)description { 3040 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 3041} 3042 3043- (NSUInteger)count { 3044 return _dictionary.count; 3045} 3046 3047- (void)enumerateKeysAndObjectsUsingBlock: 3048 (void (NS_NOESCAPE ^)(uint32_t key, id object, BOOL *stop))block { 3049 BOOL stop = NO; 3050 NSDictionary *internal = _dictionary; 3051 NSEnumerator *keys = [internal keyEnumerator]; 3052 NSNumber *aKey; 3053 while ((aKey = [keys nextObject])) { 3054 id aObject = internal[aKey]; 3055 block([aKey unsignedIntValue], aObject, &stop); 3056 if (stop) { 3057 break; 3058 } 3059 } 3060} 3061 3062- (BOOL)isInitialized { 3063 for (GPBMessage *msg in [_dictionary objectEnumerator]) { 3064 if (!msg.initialized) { 3065 return NO; 3066 } 3067 } 3068 return YES; 3069} 3070 3071- (instancetype)deepCopyWithZone:(NSZone *)zone { 3072 GPBUInt32ObjectDictionary *newDict = 3073 [[GPBUInt32ObjectDictionary alloc] init]; 3074 NSEnumerator *keys = [_dictionary keyEnumerator]; 3075 id aKey; 3076 NSMutableDictionary *internalDict = newDict->_dictionary; 3077 while ((aKey = [keys nextObject])) { 3078 GPBMessage *msg = _dictionary[aKey]; 3079 GPBMessage *copiedMsg = [msg copyWithZone:zone]; 3080 [internalDict setObject:copiedMsg forKey:aKey]; 3081 [copiedMsg release]; 3082 } 3083 return newDict; 3084} 3085 3086- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 3087 NSDictionary *internal = _dictionary; 3088 NSUInteger count = internal.count; 3089 if (count == 0) { 3090 return 0; 3091 } 3092 3093 GPBDataType valueDataType = GPBGetFieldDataType(field); 3094 GPBDataType keyDataType = field.mapKeyDataType; 3095 size_t result = 0; 3096 NSEnumerator *keys = [internal keyEnumerator]; 3097 NSNumber *aKey; 3098 while ((aKey = [keys nextObject])) { 3099 id aObject = internal[aKey]; 3100 size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType); 3101 msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType); 3102 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 3103 } 3104 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 3105 result += tagSize * count; 3106 return result; 3107} 3108 3109- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 3110 asField:(GPBFieldDescriptor *)field { 3111 GPBDataType valueDataType = GPBGetFieldDataType(field); 3112 GPBDataType keyDataType = field.mapKeyDataType; 3113 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 3114 NSDictionary *internal = _dictionary; 3115 NSEnumerator *keys = [internal keyEnumerator]; 3116 NSNumber *aKey; 3117 while ((aKey = [keys nextObject])) { 3118 id aObject = internal[aKey]; 3119 [outputStream writeInt32NoTag:tag]; 3120 // Write the size of the message. 3121 uint32_t unwrappedKey = [aKey unsignedIntValue]; 3122 id unwrappedValue = aObject; 3123 size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 3124 msgSize += ComputeDictObjectFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 3125 [outputStream writeInt32NoTag:(int32_t)msgSize]; 3126 // Write the fields. 3127 WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 3128 WriteDictObjectField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 3129 } 3130} 3131 3132- (void)setGPBGenericValue:(GPBGenericValue *)value 3133 forGPBGenericValueKey:(GPBGenericValue *)key { 3134 [_dictionary setObject:value->valueString forKey:@(key->valueUInt32)]; 3135} 3136 3137- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 3138 [self enumerateKeysAndObjectsUsingBlock:^(uint32_t key, id object, BOOL *stop) { 3139 #pragma unused(stop) 3140 block([NSString stringWithFormat:@"%u", key], object); 3141 }]; 3142} 3143 3144- (id)objectForKey:(uint32_t)key { 3145 id result = [_dictionary objectForKey:@(key)]; 3146 return result; 3147} 3148 3149- (void)addEntriesFromDictionary:(GPBUInt32ObjectDictionary *)otherDictionary { 3150 if (otherDictionary) { 3151 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 3152 if (_autocreator) { 3153 GPBAutocreatedDictionaryModified(_autocreator, self); 3154 } 3155 } 3156} 3157 3158- (void)setObject:(id)object forKey:(uint32_t)key { 3159 if (!object) { 3160 [NSException raise:NSInvalidArgumentException 3161 format:@"Attempting to add nil object to a Dictionary"]; 3162 } 3163 [_dictionary setObject:object forKey:@(key)]; 3164 if (_autocreator) { 3165 GPBAutocreatedDictionaryModified(_autocreator, self); 3166 } 3167} 3168 3169- (void)removeObjectForKey:(uint32_t)aKey { 3170 [_dictionary removeObjectForKey:@(aKey)]; 3171} 3172 3173- (void)removeAll { 3174 [_dictionary removeAllObjects]; 3175} 3176 3177@end 3178 3179// clang-format on 3180//%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(Int32, int32_t) 3181// This block of code is generated, do not edit it directly. 3182// clang-format off 3183 3184#pragma mark - Int32 -> UInt32 3185 3186@implementation GPBInt32UInt32Dictionary { 3187 @package 3188 NSMutableDictionary *_dictionary; 3189} 3190 3191- (instancetype)init { 3192 return [self initWithUInt32s:NULL forKeys:NULL count:0]; 3193} 3194 3195- (instancetype)initWithUInt32s:(const uint32_t [])values 3196 forKeys:(const int32_t [])keys 3197 count:(NSUInteger)count { 3198 self = [super init]; 3199 if (self) { 3200 _dictionary = [[NSMutableDictionary alloc] init]; 3201 if (count && values && keys) { 3202 for (NSUInteger i = 0; i < count; ++i) { 3203 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; 3204 } 3205 } 3206 } 3207 return self; 3208} 3209 3210- (instancetype)initWithDictionary:(GPBInt32UInt32Dictionary *)dictionary { 3211 self = [self initWithUInt32s:NULL forKeys:NULL count:0]; 3212 if (self) { 3213 if (dictionary) { 3214 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 3215 } 3216 } 3217 return self; 3218} 3219 3220- (instancetype)initWithCapacity:(NSUInteger)numItems { 3221 #pragma unused(numItems) 3222 return [self initWithUInt32s:NULL forKeys:NULL count:0]; 3223} 3224 3225- (void)dealloc { 3226 NSAssert(!_autocreator, 3227 @"%@: Autocreator must be cleared before release, autocreator: %@", 3228 [self class], _autocreator); 3229 [_dictionary release]; 3230 [super dealloc]; 3231} 3232 3233- (instancetype)copyWithZone:(NSZone *)zone { 3234 return [[GPBInt32UInt32Dictionary allocWithZone:zone] initWithDictionary:self]; 3235} 3236 3237- (BOOL)isEqual:(id)other { 3238 if (self == other) { 3239 return YES; 3240 } 3241 if (![other isKindOfClass:[GPBInt32UInt32Dictionary class]]) { 3242 return NO; 3243 } 3244 GPBInt32UInt32Dictionary *otherDictionary = other; 3245 return [_dictionary isEqual:otherDictionary->_dictionary]; 3246} 3247 3248- (NSUInteger)hash { 3249 return _dictionary.count; 3250} 3251 3252- (NSString *)description { 3253 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 3254} 3255 3256- (NSUInteger)count { 3257 return _dictionary.count; 3258} 3259 3260- (void)enumerateKeysAndUInt32sUsingBlock: 3261 (void (NS_NOESCAPE ^)(int32_t key, uint32_t value, BOOL *stop))block { 3262 BOOL stop = NO; 3263 NSDictionary *internal = _dictionary; 3264 NSEnumerator *keys = [internal keyEnumerator]; 3265 NSNumber *aKey; 3266 while ((aKey = [keys nextObject])) { 3267 NSNumber *aValue = internal[aKey]; 3268 block([aKey intValue], [aValue unsignedIntValue], &stop); 3269 if (stop) { 3270 break; 3271 } 3272 } 3273} 3274 3275- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 3276 NSDictionary *internal = _dictionary; 3277 NSUInteger count = internal.count; 3278 if (count == 0) { 3279 return 0; 3280 } 3281 3282 GPBDataType valueDataType = GPBGetFieldDataType(field); 3283 GPBDataType keyDataType = field.mapKeyDataType; 3284 size_t result = 0; 3285 NSEnumerator *keys = [internal keyEnumerator]; 3286 NSNumber *aKey; 3287 while ((aKey = [keys nextObject])) { 3288 NSNumber *aValue = internal[aKey]; 3289 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType); 3290 msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType); 3291 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 3292 } 3293 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 3294 result += tagSize * count; 3295 return result; 3296} 3297 3298- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 3299 asField:(GPBFieldDescriptor *)field { 3300 GPBDataType valueDataType = GPBGetFieldDataType(field); 3301 GPBDataType keyDataType = field.mapKeyDataType; 3302 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 3303 NSDictionary *internal = _dictionary; 3304 NSEnumerator *keys = [internal keyEnumerator]; 3305 NSNumber *aKey; 3306 while ((aKey = [keys nextObject])) { 3307 NSNumber *aValue = internal[aKey]; 3308 [outputStream writeInt32NoTag:tag]; 3309 // Write the size of the message. 3310 int32_t unwrappedKey = [aKey intValue]; 3311 uint32_t unwrappedValue = [aValue unsignedIntValue]; 3312 size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 3313 msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 3314 [outputStream writeInt32NoTag:(int32_t)msgSize]; 3315 // Write the fields. 3316 WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 3317 WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 3318 } 3319} 3320 3321- (void)setGPBGenericValue:(GPBGenericValue *)value 3322 forGPBGenericValueKey:(GPBGenericValue *)key { 3323 [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueInt32)]; 3324} 3325 3326- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 3327 [self enumerateKeysAndUInt32sUsingBlock:^(int32_t key, uint32_t value, BOOL *stop) { 3328 #pragma unused(stop) 3329 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%u", value]); 3330 }]; 3331} 3332 3333- (BOOL)getUInt32:(nullable uint32_t *)value forKey:(int32_t)key { 3334 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; 3335 if (wrapped && value) { 3336 *value = [wrapped unsignedIntValue]; 3337 } 3338 return (wrapped != NULL); 3339} 3340 3341- (void)addEntriesFromDictionary:(GPBInt32UInt32Dictionary *)otherDictionary { 3342 if (otherDictionary) { 3343 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 3344 if (_autocreator) { 3345 GPBAutocreatedDictionaryModified(_autocreator, self); 3346 } 3347 } 3348} 3349 3350- (void)setUInt32:(uint32_t)value forKey:(int32_t)key { 3351 [_dictionary setObject:@(value) forKey:@(key)]; 3352 if (_autocreator) { 3353 GPBAutocreatedDictionaryModified(_autocreator, self); 3354 } 3355} 3356 3357- (void)removeUInt32ForKey:(int32_t)aKey { 3358 [_dictionary removeObjectForKey:@(aKey)]; 3359} 3360 3361- (void)removeAll { 3362 [_dictionary removeAllObjects]; 3363} 3364 3365@end 3366 3367#pragma mark - Int32 -> Int32 3368 3369@implementation GPBInt32Int32Dictionary { 3370 @package 3371 NSMutableDictionary *_dictionary; 3372} 3373 3374- (instancetype)init { 3375 return [self initWithInt32s:NULL forKeys:NULL count:0]; 3376} 3377 3378- (instancetype)initWithInt32s:(const int32_t [])values 3379 forKeys:(const int32_t [])keys 3380 count:(NSUInteger)count { 3381 self = [super init]; 3382 if (self) { 3383 _dictionary = [[NSMutableDictionary alloc] init]; 3384 if (count && values && keys) { 3385 for (NSUInteger i = 0; i < count; ++i) { 3386 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; 3387 } 3388 } 3389 } 3390 return self; 3391} 3392 3393- (instancetype)initWithDictionary:(GPBInt32Int32Dictionary *)dictionary { 3394 self = [self initWithInt32s:NULL forKeys:NULL count:0]; 3395 if (self) { 3396 if (dictionary) { 3397 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 3398 } 3399 } 3400 return self; 3401} 3402 3403- (instancetype)initWithCapacity:(NSUInteger)numItems { 3404 #pragma unused(numItems) 3405 return [self initWithInt32s:NULL forKeys:NULL count:0]; 3406} 3407 3408- (void)dealloc { 3409 NSAssert(!_autocreator, 3410 @"%@: Autocreator must be cleared before release, autocreator: %@", 3411 [self class], _autocreator); 3412 [_dictionary release]; 3413 [super dealloc]; 3414} 3415 3416- (instancetype)copyWithZone:(NSZone *)zone { 3417 return [[GPBInt32Int32Dictionary allocWithZone:zone] initWithDictionary:self]; 3418} 3419 3420- (BOOL)isEqual:(id)other { 3421 if (self == other) { 3422 return YES; 3423 } 3424 if (![other isKindOfClass:[GPBInt32Int32Dictionary class]]) { 3425 return NO; 3426 } 3427 GPBInt32Int32Dictionary *otherDictionary = other; 3428 return [_dictionary isEqual:otherDictionary->_dictionary]; 3429} 3430 3431- (NSUInteger)hash { 3432 return _dictionary.count; 3433} 3434 3435- (NSString *)description { 3436 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 3437} 3438 3439- (NSUInteger)count { 3440 return _dictionary.count; 3441} 3442 3443- (void)enumerateKeysAndInt32sUsingBlock: 3444 (void (NS_NOESCAPE ^)(int32_t key, int32_t value, BOOL *stop))block { 3445 BOOL stop = NO; 3446 NSDictionary *internal = _dictionary; 3447 NSEnumerator *keys = [internal keyEnumerator]; 3448 NSNumber *aKey; 3449 while ((aKey = [keys nextObject])) { 3450 NSNumber *aValue = internal[aKey]; 3451 block([aKey intValue], [aValue intValue], &stop); 3452 if (stop) { 3453 break; 3454 } 3455 } 3456} 3457 3458- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 3459 NSDictionary *internal = _dictionary; 3460 NSUInteger count = internal.count; 3461 if (count == 0) { 3462 return 0; 3463 } 3464 3465 GPBDataType valueDataType = GPBGetFieldDataType(field); 3466 GPBDataType keyDataType = field.mapKeyDataType; 3467 size_t result = 0; 3468 NSEnumerator *keys = [internal keyEnumerator]; 3469 NSNumber *aKey; 3470 while ((aKey = [keys nextObject])) { 3471 NSNumber *aValue = internal[aKey]; 3472 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType); 3473 msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType); 3474 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 3475 } 3476 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 3477 result += tagSize * count; 3478 return result; 3479} 3480 3481- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 3482 asField:(GPBFieldDescriptor *)field { 3483 GPBDataType valueDataType = GPBGetFieldDataType(field); 3484 GPBDataType keyDataType = field.mapKeyDataType; 3485 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 3486 NSDictionary *internal = _dictionary; 3487 NSEnumerator *keys = [internal keyEnumerator]; 3488 NSNumber *aKey; 3489 while ((aKey = [keys nextObject])) { 3490 NSNumber *aValue = internal[aKey]; 3491 [outputStream writeInt32NoTag:tag]; 3492 // Write the size of the message. 3493 int32_t unwrappedKey = [aKey intValue]; 3494 int32_t unwrappedValue = [aValue intValue]; 3495 size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 3496 msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 3497 [outputStream writeInt32NoTag:(int32_t)msgSize]; 3498 // Write the fields. 3499 WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 3500 WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 3501 } 3502} 3503 3504- (void)setGPBGenericValue:(GPBGenericValue *)value 3505 forGPBGenericValueKey:(GPBGenericValue *)key { 3506 [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueInt32)]; 3507} 3508 3509- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 3510 [self enumerateKeysAndInt32sUsingBlock:^(int32_t key, int32_t value, BOOL *stop) { 3511 #pragma unused(stop) 3512 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%d", value]); 3513 }]; 3514} 3515 3516- (BOOL)getInt32:(nullable int32_t *)value forKey:(int32_t)key { 3517 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; 3518 if (wrapped && value) { 3519 *value = [wrapped intValue]; 3520 } 3521 return (wrapped != NULL); 3522} 3523 3524- (void)addEntriesFromDictionary:(GPBInt32Int32Dictionary *)otherDictionary { 3525 if (otherDictionary) { 3526 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 3527 if (_autocreator) { 3528 GPBAutocreatedDictionaryModified(_autocreator, self); 3529 } 3530 } 3531} 3532 3533- (void)setInt32:(int32_t)value forKey:(int32_t)key { 3534 [_dictionary setObject:@(value) forKey:@(key)]; 3535 if (_autocreator) { 3536 GPBAutocreatedDictionaryModified(_autocreator, self); 3537 } 3538} 3539 3540- (void)removeInt32ForKey:(int32_t)aKey { 3541 [_dictionary removeObjectForKey:@(aKey)]; 3542} 3543 3544- (void)removeAll { 3545 [_dictionary removeAllObjects]; 3546} 3547 3548@end 3549 3550#pragma mark - Int32 -> UInt64 3551 3552@implementation GPBInt32UInt64Dictionary { 3553 @package 3554 NSMutableDictionary *_dictionary; 3555} 3556 3557- (instancetype)init { 3558 return [self initWithUInt64s:NULL forKeys:NULL count:0]; 3559} 3560 3561- (instancetype)initWithUInt64s:(const uint64_t [])values 3562 forKeys:(const int32_t [])keys 3563 count:(NSUInteger)count { 3564 self = [super init]; 3565 if (self) { 3566 _dictionary = [[NSMutableDictionary alloc] init]; 3567 if (count && values && keys) { 3568 for (NSUInteger i = 0; i < count; ++i) { 3569 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; 3570 } 3571 } 3572 } 3573 return self; 3574} 3575 3576- (instancetype)initWithDictionary:(GPBInt32UInt64Dictionary *)dictionary { 3577 self = [self initWithUInt64s:NULL forKeys:NULL count:0]; 3578 if (self) { 3579 if (dictionary) { 3580 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 3581 } 3582 } 3583 return self; 3584} 3585 3586- (instancetype)initWithCapacity:(NSUInteger)numItems { 3587 #pragma unused(numItems) 3588 return [self initWithUInt64s:NULL forKeys:NULL count:0]; 3589} 3590 3591- (void)dealloc { 3592 NSAssert(!_autocreator, 3593 @"%@: Autocreator must be cleared before release, autocreator: %@", 3594 [self class], _autocreator); 3595 [_dictionary release]; 3596 [super dealloc]; 3597} 3598 3599- (instancetype)copyWithZone:(NSZone *)zone { 3600 return [[GPBInt32UInt64Dictionary allocWithZone:zone] initWithDictionary:self]; 3601} 3602 3603- (BOOL)isEqual:(id)other { 3604 if (self == other) { 3605 return YES; 3606 } 3607 if (![other isKindOfClass:[GPBInt32UInt64Dictionary class]]) { 3608 return NO; 3609 } 3610 GPBInt32UInt64Dictionary *otherDictionary = other; 3611 return [_dictionary isEqual:otherDictionary->_dictionary]; 3612} 3613 3614- (NSUInteger)hash { 3615 return _dictionary.count; 3616} 3617 3618- (NSString *)description { 3619 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 3620} 3621 3622- (NSUInteger)count { 3623 return _dictionary.count; 3624} 3625 3626- (void)enumerateKeysAndUInt64sUsingBlock: 3627 (void (NS_NOESCAPE ^)(int32_t key, uint64_t value, BOOL *stop))block { 3628 BOOL stop = NO; 3629 NSDictionary *internal = _dictionary; 3630 NSEnumerator *keys = [internal keyEnumerator]; 3631 NSNumber *aKey; 3632 while ((aKey = [keys nextObject])) { 3633 NSNumber *aValue = internal[aKey]; 3634 block([aKey intValue], [aValue unsignedLongLongValue], &stop); 3635 if (stop) { 3636 break; 3637 } 3638 } 3639} 3640 3641- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 3642 NSDictionary *internal = _dictionary; 3643 NSUInteger count = internal.count; 3644 if (count == 0) { 3645 return 0; 3646 } 3647 3648 GPBDataType valueDataType = GPBGetFieldDataType(field); 3649 GPBDataType keyDataType = field.mapKeyDataType; 3650 size_t result = 0; 3651 NSEnumerator *keys = [internal keyEnumerator]; 3652 NSNumber *aKey; 3653 while ((aKey = [keys nextObject])) { 3654 NSNumber *aValue = internal[aKey]; 3655 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType); 3656 msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType); 3657 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 3658 } 3659 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 3660 result += tagSize * count; 3661 return result; 3662} 3663 3664- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 3665 asField:(GPBFieldDescriptor *)field { 3666 GPBDataType valueDataType = GPBGetFieldDataType(field); 3667 GPBDataType keyDataType = field.mapKeyDataType; 3668 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 3669 NSDictionary *internal = _dictionary; 3670 NSEnumerator *keys = [internal keyEnumerator]; 3671 NSNumber *aKey; 3672 while ((aKey = [keys nextObject])) { 3673 NSNumber *aValue = internal[aKey]; 3674 [outputStream writeInt32NoTag:tag]; 3675 // Write the size of the message. 3676 int32_t unwrappedKey = [aKey intValue]; 3677 uint64_t unwrappedValue = [aValue unsignedLongLongValue]; 3678 size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 3679 msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 3680 [outputStream writeInt32NoTag:(int32_t)msgSize]; 3681 // Write the fields. 3682 WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 3683 WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 3684 } 3685} 3686 3687- (void)setGPBGenericValue:(GPBGenericValue *)value 3688 forGPBGenericValueKey:(GPBGenericValue *)key { 3689 [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueInt32)]; 3690} 3691 3692- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 3693 [self enumerateKeysAndUInt64sUsingBlock:^(int32_t key, uint64_t value, BOOL *stop) { 3694 #pragma unused(stop) 3695 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%llu", value]); 3696 }]; 3697} 3698 3699- (BOOL)getUInt64:(nullable uint64_t *)value forKey:(int32_t)key { 3700 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; 3701 if (wrapped && value) { 3702 *value = [wrapped unsignedLongLongValue]; 3703 } 3704 return (wrapped != NULL); 3705} 3706 3707- (void)addEntriesFromDictionary:(GPBInt32UInt64Dictionary *)otherDictionary { 3708 if (otherDictionary) { 3709 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 3710 if (_autocreator) { 3711 GPBAutocreatedDictionaryModified(_autocreator, self); 3712 } 3713 } 3714} 3715 3716- (void)setUInt64:(uint64_t)value forKey:(int32_t)key { 3717 [_dictionary setObject:@(value) forKey:@(key)]; 3718 if (_autocreator) { 3719 GPBAutocreatedDictionaryModified(_autocreator, self); 3720 } 3721} 3722 3723- (void)removeUInt64ForKey:(int32_t)aKey { 3724 [_dictionary removeObjectForKey:@(aKey)]; 3725} 3726 3727- (void)removeAll { 3728 [_dictionary removeAllObjects]; 3729} 3730 3731@end 3732 3733#pragma mark - Int32 -> Int64 3734 3735@implementation GPBInt32Int64Dictionary { 3736 @package 3737 NSMutableDictionary *_dictionary; 3738} 3739 3740- (instancetype)init { 3741 return [self initWithInt64s:NULL forKeys:NULL count:0]; 3742} 3743 3744- (instancetype)initWithInt64s:(const int64_t [])values 3745 forKeys:(const int32_t [])keys 3746 count:(NSUInteger)count { 3747 self = [super init]; 3748 if (self) { 3749 _dictionary = [[NSMutableDictionary alloc] init]; 3750 if (count && values && keys) { 3751 for (NSUInteger i = 0; i < count; ++i) { 3752 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; 3753 } 3754 } 3755 } 3756 return self; 3757} 3758 3759- (instancetype)initWithDictionary:(GPBInt32Int64Dictionary *)dictionary { 3760 self = [self initWithInt64s:NULL forKeys:NULL count:0]; 3761 if (self) { 3762 if (dictionary) { 3763 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 3764 } 3765 } 3766 return self; 3767} 3768 3769- (instancetype)initWithCapacity:(NSUInteger)numItems { 3770 #pragma unused(numItems) 3771 return [self initWithInt64s:NULL forKeys:NULL count:0]; 3772} 3773 3774- (void)dealloc { 3775 NSAssert(!_autocreator, 3776 @"%@: Autocreator must be cleared before release, autocreator: %@", 3777 [self class], _autocreator); 3778 [_dictionary release]; 3779 [super dealloc]; 3780} 3781 3782- (instancetype)copyWithZone:(NSZone *)zone { 3783 return [[GPBInt32Int64Dictionary allocWithZone:zone] initWithDictionary:self]; 3784} 3785 3786- (BOOL)isEqual:(id)other { 3787 if (self == other) { 3788 return YES; 3789 } 3790 if (![other isKindOfClass:[GPBInt32Int64Dictionary class]]) { 3791 return NO; 3792 } 3793 GPBInt32Int64Dictionary *otherDictionary = other; 3794 return [_dictionary isEqual:otherDictionary->_dictionary]; 3795} 3796 3797- (NSUInteger)hash { 3798 return _dictionary.count; 3799} 3800 3801- (NSString *)description { 3802 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 3803} 3804 3805- (NSUInteger)count { 3806 return _dictionary.count; 3807} 3808 3809- (void)enumerateKeysAndInt64sUsingBlock: 3810 (void (NS_NOESCAPE ^)(int32_t key, int64_t value, BOOL *stop))block { 3811 BOOL stop = NO; 3812 NSDictionary *internal = _dictionary; 3813 NSEnumerator *keys = [internal keyEnumerator]; 3814 NSNumber *aKey; 3815 while ((aKey = [keys nextObject])) { 3816 NSNumber *aValue = internal[aKey]; 3817 block([aKey intValue], [aValue longLongValue], &stop); 3818 if (stop) { 3819 break; 3820 } 3821 } 3822} 3823 3824- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 3825 NSDictionary *internal = _dictionary; 3826 NSUInteger count = internal.count; 3827 if (count == 0) { 3828 return 0; 3829 } 3830 3831 GPBDataType valueDataType = GPBGetFieldDataType(field); 3832 GPBDataType keyDataType = field.mapKeyDataType; 3833 size_t result = 0; 3834 NSEnumerator *keys = [internal keyEnumerator]; 3835 NSNumber *aKey; 3836 while ((aKey = [keys nextObject])) { 3837 NSNumber *aValue = internal[aKey]; 3838 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType); 3839 msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType); 3840 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 3841 } 3842 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 3843 result += tagSize * count; 3844 return result; 3845} 3846 3847- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 3848 asField:(GPBFieldDescriptor *)field { 3849 GPBDataType valueDataType = GPBGetFieldDataType(field); 3850 GPBDataType keyDataType = field.mapKeyDataType; 3851 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 3852 NSDictionary *internal = _dictionary; 3853 NSEnumerator *keys = [internal keyEnumerator]; 3854 NSNumber *aKey; 3855 while ((aKey = [keys nextObject])) { 3856 NSNumber *aValue = internal[aKey]; 3857 [outputStream writeInt32NoTag:tag]; 3858 // Write the size of the message. 3859 int32_t unwrappedKey = [aKey intValue]; 3860 int64_t unwrappedValue = [aValue longLongValue]; 3861 size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 3862 msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 3863 [outputStream writeInt32NoTag:(int32_t)msgSize]; 3864 // Write the fields. 3865 WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 3866 WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 3867 } 3868} 3869 3870- (void)setGPBGenericValue:(GPBGenericValue *)value 3871 forGPBGenericValueKey:(GPBGenericValue *)key { 3872 [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueInt32)]; 3873} 3874 3875- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 3876 [self enumerateKeysAndInt64sUsingBlock:^(int32_t key, int64_t value, BOOL *stop) { 3877 #pragma unused(stop) 3878 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%lld", value]); 3879 }]; 3880} 3881 3882- (BOOL)getInt64:(nullable int64_t *)value forKey:(int32_t)key { 3883 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; 3884 if (wrapped && value) { 3885 *value = [wrapped longLongValue]; 3886 } 3887 return (wrapped != NULL); 3888} 3889 3890- (void)addEntriesFromDictionary:(GPBInt32Int64Dictionary *)otherDictionary { 3891 if (otherDictionary) { 3892 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 3893 if (_autocreator) { 3894 GPBAutocreatedDictionaryModified(_autocreator, self); 3895 } 3896 } 3897} 3898 3899- (void)setInt64:(int64_t)value forKey:(int32_t)key { 3900 [_dictionary setObject:@(value) forKey:@(key)]; 3901 if (_autocreator) { 3902 GPBAutocreatedDictionaryModified(_autocreator, self); 3903 } 3904} 3905 3906- (void)removeInt64ForKey:(int32_t)aKey { 3907 [_dictionary removeObjectForKey:@(aKey)]; 3908} 3909 3910- (void)removeAll { 3911 [_dictionary removeAllObjects]; 3912} 3913 3914@end 3915 3916#pragma mark - Int32 -> Bool 3917 3918@implementation GPBInt32BoolDictionary { 3919 @package 3920 NSMutableDictionary *_dictionary; 3921} 3922 3923- (instancetype)init { 3924 return [self initWithBools:NULL forKeys:NULL count:0]; 3925} 3926 3927- (instancetype)initWithBools:(const BOOL [])values 3928 forKeys:(const int32_t [])keys 3929 count:(NSUInteger)count { 3930 self = [super init]; 3931 if (self) { 3932 _dictionary = [[NSMutableDictionary alloc] init]; 3933 if (count && values && keys) { 3934 for (NSUInteger i = 0; i < count; ++i) { 3935 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; 3936 } 3937 } 3938 } 3939 return self; 3940} 3941 3942- (instancetype)initWithDictionary:(GPBInt32BoolDictionary *)dictionary { 3943 self = [self initWithBools:NULL forKeys:NULL count:0]; 3944 if (self) { 3945 if (dictionary) { 3946 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 3947 } 3948 } 3949 return self; 3950} 3951 3952- (instancetype)initWithCapacity:(NSUInteger)numItems { 3953 #pragma unused(numItems) 3954 return [self initWithBools:NULL forKeys:NULL count:0]; 3955} 3956 3957- (void)dealloc { 3958 NSAssert(!_autocreator, 3959 @"%@: Autocreator must be cleared before release, autocreator: %@", 3960 [self class], _autocreator); 3961 [_dictionary release]; 3962 [super dealloc]; 3963} 3964 3965- (instancetype)copyWithZone:(NSZone *)zone { 3966 return [[GPBInt32BoolDictionary allocWithZone:zone] initWithDictionary:self]; 3967} 3968 3969- (BOOL)isEqual:(id)other { 3970 if (self == other) { 3971 return YES; 3972 } 3973 if (![other isKindOfClass:[GPBInt32BoolDictionary class]]) { 3974 return NO; 3975 } 3976 GPBInt32BoolDictionary *otherDictionary = other; 3977 return [_dictionary isEqual:otherDictionary->_dictionary]; 3978} 3979 3980- (NSUInteger)hash { 3981 return _dictionary.count; 3982} 3983 3984- (NSString *)description { 3985 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 3986} 3987 3988- (NSUInteger)count { 3989 return _dictionary.count; 3990} 3991 3992- (void)enumerateKeysAndBoolsUsingBlock: 3993 (void (NS_NOESCAPE ^)(int32_t key, BOOL value, BOOL *stop))block { 3994 BOOL stop = NO; 3995 NSDictionary *internal = _dictionary; 3996 NSEnumerator *keys = [internal keyEnumerator]; 3997 NSNumber *aKey; 3998 while ((aKey = [keys nextObject])) { 3999 NSNumber *aValue = internal[aKey]; 4000 block([aKey intValue], [aValue boolValue], &stop); 4001 if (stop) { 4002 break; 4003 } 4004 } 4005} 4006 4007- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 4008 NSDictionary *internal = _dictionary; 4009 NSUInteger count = internal.count; 4010 if (count == 0) { 4011 return 0; 4012 } 4013 4014 GPBDataType valueDataType = GPBGetFieldDataType(field); 4015 GPBDataType keyDataType = field.mapKeyDataType; 4016 size_t result = 0; 4017 NSEnumerator *keys = [internal keyEnumerator]; 4018 NSNumber *aKey; 4019 while ((aKey = [keys nextObject])) { 4020 NSNumber *aValue = internal[aKey]; 4021 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType); 4022 msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType); 4023 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 4024 } 4025 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 4026 result += tagSize * count; 4027 return result; 4028} 4029 4030- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 4031 asField:(GPBFieldDescriptor *)field { 4032 GPBDataType valueDataType = GPBGetFieldDataType(field); 4033 GPBDataType keyDataType = field.mapKeyDataType; 4034 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 4035 NSDictionary *internal = _dictionary; 4036 NSEnumerator *keys = [internal keyEnumerator]; 4037 NSNumber *aKey; 4038 while ((aKey = [keys nextObject])) { 4039 NSNumber *aValue = internal[aKey]; 4040 [outputStream writeInt32NoTag:tag]; 4041 // Write the size of the message. 4042 int32_t unwrappedKey = [aKey intValue]; 4043 BOOL unwrappedValue = [aValue boolValue]; 4044 size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 4045 msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 4046 [outputStream writeInt32NoTag:(int32_t)msgSize]; 4047 // Write the fields. 4048 WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 4049 WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 4050 } 4051} 4052 4053- (void)setGPBGenericValue:(GPBGenericValue *)value 4054 forGPBGenericValueKey:(GPBGenericValue *)key { 4055 [_dictionary setObject:@(value->valueBool) forKey:@(key->valueInt32)]; 4056} 4057 4058- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 4059 [self enumerateKeysAndBoolsUsingBlock:^(int32_t key, BOOL value, BOOL *stop) { 4060 #pragma unused(stop) 4061 block([NSString stringWithFormat:@"%d", key], (value ? @"true" : @"false")); 4062 }]; 4063} 4064 4065- (BOOL)getBool:(nullable BOOL *)value forKey:(int32_t)key { 4066 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; 4067 if (wrapped && value) { 4068 *value = [wrapped boolValue]; 4069 } 4070 return (wrapped != NULL); 4071} 4072 4073- (void)addEntriesFromDictionary:(GPBInt32BoolDictionary *)otherDictionary { 4074 if (otherDictionary) { 4075 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 4076 if (_autocreator) { 4077 GPBAutocreatedDictionaryModified(_autocreator, self); 4078 } 4079 } 4080} 4081 4082- (void)setBool:(BOOL)value forKey:(int32_t)key { 4083 [_dictionary setObject:@(value) forKey:@(key)]; 4084 if (_autocreator) { 4085 GPBAutocreatedDictionaryModified(_autocreator, self); 4086 } 4087} 4088 4089- (void)removeBoolForKey:(int32_t)aKey { 4090 [_dictionary removeObjectForKey:@(aKey)]; 4091} 4092 4093- (void)removeAll { 4094 [_dictionary removeAllObjects]; 4095} 4096 4097@end 4098 4099#pragma mark - Int32 -> Float 4100 4101@implementation GPBInt32FloatDictionary { 4102 @package 4103 NSMutableDictionary *_dictionary; 4104} 4105 4106- (instancetype)init { 4107 return [self initWithFloats:NULL forKeys:NULL count:0]; 4108} 4109 4110- (instancetype)initWithFloats:(const float [])values 4111 forKeys:(const int32_t [])keys 4112 count:(NSUInteger)count { 4113 self = [super init]; 4114 if (self) { 4115 _dictionary = [[NSMutableDictionary alloc] init]; 4116 if (count && values && keys) { 4117 for (NSUInteger i = 0; i < count; ++i) { 4118 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; 4119 } 4120 } 4121 } 4122 return self; 4123} 4124 4125- (instancetype)initWithDictionary:(GPBInt32FloatDictionary *)dictionary { 4126 self = [self initWithFloats:NULL forKeys:NULL count:0]; 4127 if (self) { 4128 if (dictionary) { 4129 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 4130 } 4131 } 4132 return self; 4133} 4134 4135- (instancetype)initWithCapacity:(NSUInteger)numItems { 4136 #pragma unused(numItems) 4137 return [self initWithFloats:NULL forKeys:NULL count:0]; 4138} 4139 4140- (void)dealloc { 4141 NSAssert(!_autocreator, 4142 @"%@: Autocreator must be cleared before release, autocreator: %@", 4143 [self class], _autocreator); 4144 [_dictionary release]; 4145 [super dealloc]; 4146} 4147 4148- (instancetype)copyWithZone:(NSZone *)zone { 4149 return [[GPBInt32FloatDictionary allocWithZone:zone] initWithDictionary:self]; 4150} 4151 4152- (BOOL)isEqual:(id)other { 4153 if (self == other) { 4154 return YES; 4155 } 4156 if (![other isKindOfClass:[GPBInt32FloatDictionary class]]) { 4157 return NO; 4158 } 4159 GPBInt32FloatDictionary *otherDictionary = other; 4160 return [_dictionary isEqual:otherDictionary->_dictionary]; 4161} 4162 4163- (NSUInteger)hash { 4164 return _dictionary.count; 4165} 4166 4167- (NSString *)description { 4168 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 4169} 4170 4171- (NSUInteger)count { 4172 return _dictionary.count; 4173} 4174 4175- (void)enumerateKeysAndFloatsUsingBlock: 4176 (void (NS_NOESCAPE ^)(int32_t key, float value, BOOL *stop))block { 4177 BOOL stop = NO; 4178 NSDictionary *internal = _dictionary; 4179 NSEnumerator *keys = [internal keyEnumerator]; 4180 NSNumber *aKey; 4181 while ((aKey = [keys nextObject])) { 4182 NSNumber *aValue = internal[aKey]; 4183 block([aKey intValue], [aValue floatValue], &stop); 4184 if (stop) { 4185 break; 4186 } 4187 } 4188} 4189 4190- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 4191 NSDictionary *internal = _dictionary; 4192 NSUInteger count = internal.count; 4193 if (count == 0) { 4194 return 0; 4195 } 4196 4197 GPBDataType valueDataType = GPBGetFieldDataType(field); 4198 GPBDataType keyDataType = field.mapKeyDataType; 4199 size_t result = 0; 4200 NSEnumerator *keys = [internal keyEnumerator]; 4201 NSNumber *aKey; 4202 while ((aKey = [keys nextObject])) { 4203 NSNumber *aValue = internal[aKey]; 4204 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType); 4205 msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType); 4206 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 4207 } 4208 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 4209 result += tagSize * count; 4210 return result; 4211} 4212 4213- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 4214 asField:(GPBFieldDescriptor *)field { 4215 GPBDataType valueDataType = GPBGetFieldDataType(field); 4216 GPBDataType keyDataType = field.mapKeyDataType; 4217 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 4218 NSDictionary *internal = _dictionary; 4219 NSEnumerator *keys = [internal keyEnumerator]; 4220 NSNumber *aKey; 4221 while ((aKey = [keys nextObject])) { 4222 NSNumber *aValue = internal[aKey]; 4223 [outputStream writeInt32NoTag:tag]; 4224 // Write the size of the message. 4225 int32_t unwrappedKey = [aKey intValue]; 4226 float unwrappedValue = [aValue floatValue]; 4227 size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 4228 msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 4229 [outputStream writeInt32NoTag:(int32_t)msgSize]; 4230 // Write the fields. 4231 WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 4232 WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 4233 } 4234} 4235 4236- (void)setGPBGenericValue:(GPBGenericValue *)value 4237 forGPBGenericValueKey:(GPBGenericValue *)key { 4238 [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueInt32)]; 4239} 4240 4241- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 4242 [self enumerateKeysAndFloatsUsingBlock:^(int32_t key, float value, BOOL *stop) { 4243 #pragma unused(stop) 4244 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]); 4245 }]; 4246} 4247 4248- (BOOL)getFloat:(nullable float *)value forKey:(int32_t)key { 4249 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; 4250 if (wrapped && value) { 4251 *value = [wrapped floatValue]; 4252 } 4253 return (wrapped != NULL); 4254} 4255 4256- (void)addEntriesFromDictionary:(GPBInt32FloatDictionary *)otherDictionary { 4257 if (otherDictionary) { 4258 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 4259 if (_autocreator) { 4260 GPBAutocreatedDictionaryModified(_autocreator, self); 4261 } 4262 } 4263} 4264 4265- (void)setFloat:(float)value forKey:(int32_t)key { 4266 [_dictionary setObject:@(value) forKey:@(key)]; 4267 if (_autocreator) { 4268 GPBAutocreatedDictionaryModified(_autocreator, self); 4269 } 4270} 4271 4272- (void)removeFloatForKey:(int32_t)aKey { 4273 [_dictionary removeObjectForKey:@(aKey)]; 4274} 4275 4276- (void)removeAll { 4277 [_dictionary removeAllObjects]; 4278} 4279 4280@end 4281 4282#pragma mark - Int32 -> Double 4283 4284@implementation GPBInt32DoubleDictionary { 4285 @package 4286 NSMutableDictionary *_dictionary; 4287} 4288 4289- (instancetype)init { 4290 return [self initWithDoubles:NULL forKeys:NULL count:0]; 4291} 4292 4293- (instancetype)initWithDoubles:(const double [])values 4294 forKeys:(const int32_t [])keys 4295 count:(NSUInteger)count { 4296 self = [super init]; 4297 if (self) { 4298 _dictionary = [[NSMutableDictionary alloc] init]; 4299 if (count && values && keys) { 4300 for (NSUInteger i = 0; i < count; ++i) { 4301 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; 4302 } 4303 } 4304 } 4305 return self; 4306} 4307 4308- (instancetype)initWithDictionary:(GPBInt32DoubleDictionary *)dictionary { 4309 self = [self initWithDoubles:NULL forKeys:NULL count:0]; 4310 if (self) { 4311 if (dictionary) { 4312 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 4313 } 4314 } 4315 return self; 4316} 4317 4318- (instancetype)initWithCapacity:(NSUInteger)numItems { 4319 #pragma unused(numItems) 4320 return [self initWithDoubles:NULL forKeys:NULL count:0]; 4321} 4322 4323- (void)dealloc { 4324 NSAssert(!_autocreator, 4325 @"%@: Autocreator must be cleared before release, autocreator: %@", 4326 [self class], _autocreator); 4327 [_dictionary release]; 4328 [super dealloc]; 4329} 4330 4331- (instancetype)copyWithZone:(NSZone *)zone { 4332 return [[GPBInt32DoubleDictionary allocWithZone:zone] initWithDictionary:self]; 4333} 4334 4335- (BOOL)isEqual:(id)other { 4336 if (self == other) { 4337 return YES; 4338 } 4339 if (![other isKindOfClass:[GPBInt32DoubleDictionary class]]) { 4340 return NO; 4341 } 4342 GPBInt32DoubleDictionary *otherDictionary = other; 4343 return [_dictionary isEqual:otherDictionary->_dictionary]; 4344} 4345 4346- (NSUInteger)hash { 4347 return _dictionary.count; 4348} 4349 4350- (NSString *)description { 4351 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 4352} 4353 4354- (NSUInteger)count { 4355 return _dictionary.count; 4356} 4357 4358- (void)enumerateKeysAndDoublesUsingBlock: 4359 (void (NS_NOESCAPE ^)(int32_t key, double value, BOOL *stop))block { 4360 BOOL stop = NO; 4361 NSDictionary *internal = _dictionary; 4362 NSEnumerator *keys = [internal keyEnumerator]; 4363 NSNumber *aKey; 4364 while ((aKey = [keys nextObject])) { 4365 NSNumber *aValue = internal[aKey]; 4366 block([aKey intValue], [aValue doubleValue], &stop); 4367 if (stop) { 4368 break; 4369 } 4370 } 4371} 4372 4373- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 4374 NSDictionary *internal = _dictionary; 4375 NSUInteger count = internal.count; 4376 if (count == 0) { 4377 return 0; 4378 } 4379 4380 GPBDataType valueDataType = GPBGetFieldDataType(field); 4381 GPBDataType keyDataType = field.mapKeyDataType; 4382 size_t result = 0; 4383 NSEnumerator *keys = [internal keyEnumerator]; 4384 NSNumber *aKey; 4385 while ((aKey = [keys nextObject])) { 4386 NSNumber *aValue = internal[aKey]; 4387 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType); 4388 msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType); 4389 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 4390 } 4391 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 4392 result += tagSize * count; 4393 return result; 4394} 4395 4396- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 4397 asField:(GPBFieldDescriptor *)field { 4398 GPBDataType valueDataType = GPBGetFieldDataType(field); 4399 GPBDataType keyDataType = field.mapKeyDataType; 4400 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 4401 NSDictionary *internal = _dictionary; 4402 NSEnumerator *keys = [internal keyEnumerator]; 4403 NSNumber *aKey; 4404 while ((aKey = [keys nextObject])) { 4405 NSNumber *aValue = internal[aKey]; 4406 [outputStream writeInt32NoTag:tag]; 4407 // Write the size of the message. 4408 int32_t unwrappedKey = [aKey intValue]; 4409 double unwrappedValue = [aValue doubleValue]; 4410 size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 4411 msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 4412 [outputStream writeInt32NoTag:(int32_t)msgSize]; 4413 // Write the fields. 4414 WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 4415 WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 4416 } 4417} 4418 4419- (void)setGPBGenericValue:(GPBGenericValue *)value 4420 forGPBGenericValueKey:(GPBGenericValue *)key { 4421 [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueInt32)]; 4422} 4423 4424- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 4425 [self enumerateKeysAndDoublesUsingBlock:^(int32_t key, double value, BOOL *stop) { 4426 #pragma unused(stop) 4427 block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]); 4428 }]; 4429} 4430 4431- (BOOL)getDouble:(nullable double *)value forKey:(int32_t)key { 4432 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; 4433 if (wrapped && value) { 4434 *value = [wrapped doubleValue]; 4435 } 4436 return (wrapped != NULL); 4437} 4438 4439- (void)addEntriesFromDictionary:(GPBInt32DoubleDictionary *)otherDictionary { 4440 if (otherDictionary) { 4441 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 4442 if (_autocreator) { 4443 GPBAutocreatedDictionaryModified(_autocreator, self); 4444 } 4445 } 4446} 4447 4448- (void)setDouble:(double)value forKey:(int32_t)key { 4449 [_dictionary setObject:@(value) forKey:@(key)]; 4450 if (_autocreator) { 4451 GPBAutocreatedDictionaryModified(_autocreator, self); 4452 } 4453} 4454 4455- (void)removeDoubleForKey:(int32_t)aKey { 4456 [_dictionary removeObjectForKey:@(aKey)]; 4457} 4458 4459- (void)removeAll { 4460 [_dictionary removeAllObjects]; 4461} 4462 4463@end 4464 4465#pragma mark - Int32 -> Enum 4466 4467@implementation GPBInt32EnumDictionary { 4468 @package 4469 NSMutableDictionary *_dictionary; 4470 GPBEnumValidationFunc _validationFunc; 4471} 4472 4473@synthesize validationFunc = _validationFunc; 4474 4475- (instancetype)init { 4476 return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0]; 4477} 4478 4479- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func { 4480 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0]; 4481} 4482 4483- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func 4484 rawValues:(const int32_t [])rawValues 4485 forKeys:(const int32_t [])keys 4486 count:(NSUInteger)count { 4487 self = [super init]; 4488 if (self) { 4489 _dictionary = [[NSMutableDictionary alloc] init]; 4490 _validationFunc = (func != NULL ? func : DictDefault_IsValidValue); 4491 if (count && rawValues && keys) { 4492 for (NSUInteger i = 0; i < count; ++i) { 4493 [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])]; 4494 } 4495 } 4496 } 4497 return self; 4498} 4499 4500- (instancetype)initWithDictionary:(GPBInt32EnumDictionary *)dictionary { 4501 self = [self initWithValidationFunction:dictionary.validationFunc 4502 rawValues:NULL 4503 forKeys:NULL 4504 count:0]; 4505 if (self) { 4506 if (dictionary) { 4507 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 4508 } 4509 } 4510 return self; 4511} 4512 4513- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func 4514 capacity:(NSUInteger)numItems { 4515 #pragma unused(numItems) 4516 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0]; 4517} 4518 4519- (void)dealloc { 4520 NSAssert(!_autocreator, 4521 @"%@: Autocreator must be cleared before release, autocreator: %@", 4522 [self class], _autocreator); 4523 [_dictionary release]; 4524 [super dealloc]; 4525} 4526 4527- (instancetype)copyWithZone:(NSZone *)zone { 4528 return [[GPBInt32EnumDictionary allocWithZone:zone] initWithDictionary:self]; 4529} 4530 4531- (BOOL)isEqual:(id)other { 4532 if (self == other) { 4533 return YES; 4534 } 4535 if (![other isKindOfClass:[GPBInt32EnumDictionary class]]) { 4536 return NO; 4537 } 4538 GPBInt32EnumDictionary *otherDictionary = other; 4539 return [_dictionary isEqual:otherDictionary->_dictionary]; 4540} 4541 4542- (NSUInteger)hash { 4543 return _dictionary.count; 4544} 4545 4546- (NSString *)description { 4547 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 4548} 4549 4550- (NSUInteger)count { 4551 return _dictionary.count; 4552} 4553 4554- (void)enumerateKeysAndRawValuesUsingBlock: 4555 (void (NS_NOESCAPE ^)(int32_t key, int32_t value, BOOL *stop))block { 4556 BOOL stop = NO; 4557 NSDictionary *internal = _dictionary; 4558 NSEnumerator *keys = [internal keyEnumerator]; 4559 NSNumber *aKey; 4560 while ((aKey = [keys nextObject])) { 4561 NSNumber *aValue = internal[aKey]; 4562 block([aKey intValue], [aValue intValue], &stop); 4563 if (stop) { 4564 break; 4565 } 4566 } 4567} 4568 4569- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 4570 NSDictionary *internal = _dictionary; 4571 NSUInteger count = internal.count; 4572 if (count == 0) { 4573 return 0; 4574 } 4575 4576 GPBDataType valueDataType = GPBGetFieldDataType(field); 4577 GPBDataType keyDataType = field.mapKeyDataType; 4578 size_t result = 0; 4579 NSEnumerator *keys = [internal keyEnumerator]; 4580 NSNumber *aKey; 4581 while ((aKey = [keys nextObject])) { 4582 NSNumber *aValue = internal[aKey]; 4583 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType); 4584 msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType); 4585 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 4586 } 4587 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 4588 result += tagSize * count; 4589 return result; 4590} 4591 4592- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 4593 asField:(GPBFieldDescriptor *)field { 4594 GPBDataType valueDataType = GPBGetFieldDataType(field); 4595 GPBDataType keyDataType = field.mapKeyDataType; 4596 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 4597 NSDictionary *internal = _dictionary; 4598 NSEnumerator *keys = [internal keyEnumerator]; 4599 NSNumber *aKey; 4600 while ((aKey = [keys nextObject])) { 4601 NSNumber *aValue = internal[aKey]; 4602 [outputStream writeInt32NoTag:tag]; 4603 // Write the size of the message. 4604 int32_t unwrappedKey = [aKey intValue]; 4605 int32_t unwrappedValue = [aValue intValue]; 4606 size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 4607 msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 4608 [outputStream writeInt32NoTag:(int32_t)msgSize]; 4609 // Write the fields. 4610 WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 4611 WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 4612 } 4613} 4614 4615- (NSData *)serializedDataForUnknownValue:(int32_t)value 4616 forKey:(GPBGenericValue *)key 4617 keyDataType:(GPBDataType)keyDataType { 4618 size_t msgSize = ComputeDictInt32FieldSize(key->valueInt32, kMapKeyFieldNumber, keyDataType); 4619 msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum); 4620 NSMutableData *data = [NSMutableData dataWithLength:msgSize]; 4621 GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data]; 4622 WriteDictInt32Field(outputStream, key->valueInt32, kMapKeyFieldNumber, keyDataType); 4623 WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum); 4624 [outputStream release]; 4625 return data; 4626} 4627- (void)setGPBGenericValue:(GPBGenericValue *)value 4628 forGPBGenericValueKey:(GPBGenericValue *)key { 4629 [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueInt32)]; 4630} 4631 4632- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 4633 [self enumerateKeysAndRawValuesUsingBlock:^(int32_t key, int32_t value, BOOL *stop) { 4634 #pragma unused(stop) 4635 block([NSString stringWithFormat:@"%d", key], @(value)); 4636 }]; 4637} 4638 4639- (BOOL)getEnum:(int32_t *)value forKey:(int32_t)key { 4640 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; 4641 if (wrapped && value) { 4642 int32_t result = [wrapped intValue]; 4643 if (!_validationFunc(result)) { 4644 result = kGPBUnrecognizedEnumeratorValue; 4645 } 4646 *value = result; 4647 } 4648 return (wrapped != NULL); 4649} 4650 4651- (BOOL)getRawValue:(int32_t *)rawValue forKey:(int32_t)key { 4652 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; 4653 if (wrapped && rawValue) { 4654 *rawValue = [wrapped intValue]; 4655 } 4656 return (wrapped != NULL); 4657} 4658 4659- (void)enumerateKeysAndEnumsUsingBlock: 4660 (void (NS_NOESCAPE ^)(int32_t key, int32_t value, BOOL *stop))block { 4661 GPBEnumValidationFunc func = _validationFunc; 4662 BOOL stop = NO; 4663 NSEnumerator *keys = [_dictionary keyEnumerator]; 4664 NSNumber *aKey; 4665 while ((aKey = [keys nextObject])) { 4666 NSNumber *aValue = _dictionary[aKey]; 4667 int32_t unwrapped = [aValue intValue]; 4668 if (!func(unwrapped)) { 4669 unwrapped = kGPBUnrecognizedEnumeratorValue; 4670 } 4671 block([aKey intValue], unwrapped, &stop); 4672 if (stop) { 4673 break; 4674 } 4675 } 4676} 4677 4678- (void)addRawEntriesFromDictionary:(GPBInt32EnumDictionary *)otherDictionary { 4679 if (otherDictionary) { 4680 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 4681 if (_autocreator) { 4682 GPBAutocreatedDictionaryModified(_autocreator, self); 4683 } 4684 } 4685} 4686 4687- (void)setRawValue:(int32_t)value forKey:(int32_t)key { 4688 [_dictionary setObject:@(value) forKey:@(key)]; 4689 if (_autocreator) { 4690 GPBAutocreatedDictionaryModified(_autocreator, self); 4691 } 4692} 4693 4694- (void)removeEnumForKey:(int32_t)aKey { 4695 [_dictionary removeObjectForKey:@(aKey)]; 4696} 4697 4698- (void)removeAll { 4699 [_dictionary removeAllObjects]; 4700} 4701 4702- (void)setEnum:(int32_t)value forKey:(int32_t)key { 4703 if (!_validationFunc(value)) { 4704 [NSException raise:NSInvalidArgumentException 4705 format:@"GPBInt32EnumDictionary: Attempt to set an unknown enum value (%d)", 4706 value]; 4707 } 4708 4709 [_dictionary setObject:@(value) forKey:@(key)]; 4710 if (_autocreator) { 4711 GPBAutocreatedDictionaryModified(_autocreator, self); 4712 } 4713} 4714 4715@end 4716 4717#pragma mark - Int32 -> Object 4718 4719@implementation GPBInt32ObjectDictionary { 4720 @package 4721 NSMutableDictionary *_dictionary; 4722} 4723 4724- (instancetype)init { 4725 return [self initWithObjects:NULL forKeys:NULL count:0]; 4726} 4727 4728- (instancetype)initWithObjects:(const id [])objects 4729 forKeys:(const int32_t [])keys 4730 count:(NSUInteger)count { 4731 self = [super init]; 4732 if (self) { 4733 _dictionary = [[NSMutableDictionary alloc] init]; 4734 if (count && objects && keys) { 4735 for (NSUInteger i = 0; i < count; ++i) { 4736 if (!objects[i]) { 4737 [NSException raise:NSInvalidArgumentException 4738 format:@"Attempting to add nil object to a Dictionary"]; 4739 } 4740 [_dictionary setObject:objects[i] forKey:@(keys[i])]; 4741 } 4742 } 4743 } 4744 return self; 4745} 4746 4747- (instancetype)initWithDictionary:(GPBInt32ObjectDictionary *)dictionary { 4748 self = [self initWithObjects:NULL forKeys:NULL count:0]; 4749 if (self) { 4750 if (dictionary) { 4751 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 4752 } 4753 } 4754 return self; 4755} 4756 4757- (instancetype)initWithCapacity:(NSUInteger)numItems { 4758 #pragma unused(numItems) 4759 return [self initWithObjects:NULL forKeys:NULL count:0]; 4760} 4761 4762- (void)dealloc { 4763 NSAssert(!_autocreator, 4764 @"%@: Autocreator must be cleared before release, autocreator: %@", 4765 [self class], _autocreator); 4766 [_dictionary release]; 4767 [super dealloc]; 4768} 4769 4770- (instancetype)copyWithZone:(NSZone *)zone { 4771 return [[GPBInt32ObjectDictionary allocWithZone:zone] initWithDictionary:self]; 4772} 4773 4774- (BOOL)isEqual:(id)other { 4775 if (self == other) { 4776 return YES; 4777 } 4778 if (![other isKindOfClass:[GPBInt32ObjectDictionary class]]) { 4779 return NO; 4780 } 4781 GPBInt32ObjectDictionary *otherDictionary = other; 4782 return [_dictionary isEqual:otherDictionary->_dictionary]; 4783} 4784 4785- (NSUInteger)hash { 4786 return _dictionary.count; 4787} 4788 4789- (NSString *)description { 4790 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 4791} 4792 4793- (NSUInteger)count { 4794 return _dictionary.count; 4795} 4796 4797- (void)enumerateKeysAndObjectsUsingBlock: 4798 (void (NS_NOESCAPE ^)(int32_t key, id object, BOOL *stop))block { 4799 BOOL stop = NO; 4800 NSDictionary *internal = _dictionary; 4801 NSEnumerator *keys = [internal keyEnumerator]; 4802 NSNumber *aKey; 4803 while ((aKey = [keys nextObject])) { 4804 id aObject = internal[aKey]; 4805 block([aKey intValue], aObject, &stop); 4806 if (stop) { 4807 break; 4808 } 4809 } 4810} 4811 4812- (BOOL)isInitialized { 4813 for (GPBMessage *msg in [_dictionary objectEnumerator]) { 4814 if (!msg.initialized) { 4815 return NO; 4816 } 4817 } 4818 return YES; 4819} 4820 4821- (instancetype)deepCopyWithZone:(NSZone *)zone { 4822 GPBInt32ObjectDictionary *newDict = 4823 [[GPBInt32ObjectDictionary alloc] init]; 4824 NSEnumerator *keys = [_dictionary keyEnumerator]; 4825 id aKey; 4826 NSMutableDictionary *internalDict = newDict->_dictionary; 4827 while ((aKey = [keys nextObject])) { 4828 GPBMessage *msg = _dictionary[aKey]; 4829 GPBMessage *copiedMsg = [msg copyWithZone:zone]; 4830 [internalDict setObject:copiedMsg forKey:aKey]; 4831 [copiedMsg release]; 4832 } 4833 return newDict; 4834} 4835 4836- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 4837 NSDictionary *internal = _dictionary; 4838 NSUInteger count = internal.count; 4839 if (count == 0) { 4840 return 0; 4841 } 4842 4843 GPBDataType valueDataType = GPBGetFieldDataType(field); 4844 GPBDataType keyDataType = field.mapKeyDataType; 4845 size_t result = 0; 4846 NSEnumerator *keys = [internal keyEnumerator]; 4847 NSNumber *aKey; 4848 while ((aKey = [keys nextObject])) { 4849 id aObject = internal[aKey]; 4850 size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType); 4851 msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType); 4852 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 4853 } 4854 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 4855 result += tagSize * count; 4856 return result; 4857} 4858 4859- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 4860 asField:(GPBFieldDescriptor *)field { 4861 GPBDataType valueDataType = GPBGetFieldDataType(field); 4862 GPBDataType keyDataType = field.mapKeyDataType; 4863 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 4864 NSDictionary *internal = _dictionary; 4865 NSEnumerator *keys = [internal keyEnumerator]; 4866 NSNumber *aKey; 4867 while ((aKey = [keys nextObject])) { 4868 id aObject = internal[aKey]; 4869 [outputStream writeInt32NoTag:tag]; 4870 // Write the size of the message. 4871 int32_t unwrappedKey = [aKey intValue]; 4872 id unwrappedValue = aObject; 4873 size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 4874 msgSize += ComputeDictObjectFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 4875 [outputStream writeInt32NoTag:(int32_t)msgSize]; 4876 // Write the fields. 4877 WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 4878 WriteDictObjectField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 4879 } 4880} 4881 4882- (void)setGPBGenericValue:(GPBGenericValue *)value 4883 forGPBGenericValueKey:(GPBGenericValue *)key { 4884 [_dictionary setObject:value->valueString forKey:@(key->valueInt32)]; 4885} 4886 4887- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 4888 [self enumerateKeysAndObjectsUsingBlock:^(int32_t key, id object, BOOL *stop) { 4889 #pragma unused(stop) 4890 block([NSString stringWithFormat:@"%d", key], object); 4891 }]; 4892} 4893 4894- (id)objectForKey:(int32_t)key { 4895 id result = [_dictionary objectForKey:@(key)]; 4896 return result; 4897} 4898 4899- (void)addEntriesFromDictionary:(GPBInt32ObjectDictionary *)otherDictionary { 4900 if (otherDictionary) { 4901 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 4902 if (_autocreator) { 4903 GPBAutocreatedDictionaryModified(_autocreator, self); 4904 } 4905 } 4906} 4907 4908- (void)setObject:(id)object forKey:(int32_t)key { 4909 if (!object) { 4910 [NSException raise:NSInvalidArgumentException 4911 format:@"Attempting to add nil object to a Dictionary"]; 4912 } 4913 [_dictionary setObject:object forKey:@(key)]; 4914 if (_autocreator) { 4915 GPBAutocreatedDictionaryModified(_autocreator, self); 4916 } 4917} 4918 4919- (void)removeObjectForKey:(int32_t)aKey { 4920 [_dictionary removeObjectForKey:@(aKey)]; 4921} 4922 4923- (void)removeAll { 4924 [_dictionary removeAllObjects]; 4925} 4926 4927@end 4928 4929// clang-format on 4930//%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(UInt64, uint64_t) 4931// This block of code is generated, do not edit it directly. 4932// clang-format off 4933 4934#pragma mark - UInt64 -> UInt32 4935 4936@implementation GPBUInt64UInt32Dictionary { 4937 @package 4938 NSMutableDictionary *_dictionary; 4939} 4940 4941- (instancetype)init { 4942 return [self initWithUInt32s:NULL forKeys:NULL count:0]; 4943} 4944 4945- (instancetype)initWithUInt32s:(const uint32_t [])values 4946 forKeys:(const uint64_t [])keys 4947 count:(NSUInteger)count { 4948 self = [super init]; 4949 if (self) { 4950 _dictionary = [[NSMutableDictionary alloc] init]; 4951 if (count && values && keys) { 4952 for (NSUInteger i = 0; i < count; ++i) { 4953 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; 4954 } 4955 } 4956 } 4957 return self; 4958} 4959 4960- (instancetype)initWithDictionary:(GPBUInt64UInt32Dictionary *)dictionary { 4961 self = [self initWithUInt32s:NULL forKeys:NULL count:0]; 4962 if (self) { 4963 if (dictionary) { 4964 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 4965 } 4966 } 4967 return self; 4968} 4969 4970- (instancetype)initWithCapacity:(NSUInteger)numItems { 4971 #pragma unused(numItems) 4972 return [self initWithUInt32s:NULL forKeys:NULL count:0]; 4973} 4974 4975- (void)dealloc { 4976 NSAssert(!_autocreator, 4977 @"%@: Autocreator must be cleared before release, autocreator: %@", 4978 [self class], _autocreator); 4979 [_dictionary release]; 4980 [super dealloc]; 4981} 4982 4983- (instancetype)copyWithZone:(NSZone *)zone { 4984 return [[GPBUInt64UInt32Dictionary allocWithZone:zone] initWithDictionary:self]; 4985} 4986 4987- (BOOL)isEqual:(id)other { 4988 if (self == other) { 4989 return YES; 4990 } 4991 if (![other isKindOfClass:[GPBUInt64UInt32Dictionary class]]) { 4992 return NO; 4993 } 4994 GPBUInt64UInt32Dictionary *otherDictionary = other; 4995 return [_dictionary isEqual:otherDictionary->_dictionary]; 4996} 4997 4998- (NSUInteger)hash { 4999 return _dictionary.count; 5000} 5001 5002- (NSString *)description { 5003 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 5004} 5005 5006- (NSUInteger)count { 5007 return _dictionary.count; 5008} 5009 5010- (void)enumerateKeysAndUInt32sUsingBlock: 5011 (void (NS_NOESCAPE ^)(uint64_t key, uint32_t value, BOOL *stop))block { 5012 BOOL stop = NO; 5013 NSDictionary *internal = _dictionary; 5014 NSEnumerator *keys = [internal keyEnumerator]; 5015 NSNumber *aKey; 5016 while ((aKey = [keys nextObject])) { 5017 NSNumber *aValue = internal[aKey]; 5018 block([aKey unsignedLongLongValue], [aValue unsignedIntValue], &stop); 5019 if (stop) { 5020 break; 5021 } 5022 } 5023} 5024 5025- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 5026 NSDictionary *internal = _dictionary; 5027 NSUInteger count = internal.count; 5028 if (count == 0) { 5029 return 0; 5030 } 5031 5032 GPBDataType valueDataType = GPBGetFieldDataType(field); 5033 GPBDataType keyDataType = field.mapKeyDataType; 5034 size_t result = 0; 5035 NSEnumerator *keys = [internal keyEnumerator]; 5036 NSNumber *aKey; 5037 while ((aKey = [keys nextObject])) { 5038 NSNumber *aValue = internal[aKey]; 5039 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType); 5040 msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType); 5041 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 5042 } 5043 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 5044 result += tagSize * count; 5045 return result; 5046} 5047 5048- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 5049 asField:(GPBFieldDescriptor *)field { 5050 GPBDataType valueDataType = GPBGetFieldDataType(field); 5051 GPBDataType keyDataType = field.mapKeyDataType; 5052 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 5053 NSDictionary *internal = _dictionary; 5054 NSEnumerator *keys = [internal keyEnumerator]; 5055 NSNumber *aKey; 5056 while ((aKey = [keys nextObject])) { 5057 NSNumber *aValue = internal[aKey]; 5058 [outputStream writeInt32NoTag:tag]; 5059 // Write the size of the message. 5060 uint64_t unwrappedKey = [aKey unsignedLongLongValue]; 5061 uint32_t unwrappedValue = [aValue unsignedIntValue]; 5062 size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 5063 msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 5064 [outputStream writeInt32NoTag:(int32_t)msgSize]; 5065 // Write the fields. 5066 WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 5067 WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 5068 } 5069} 5070 5071- (void)setGPBGenericValue:(GPBGenericValue *)value 5072 forGPBGenericValueKey:(GPBGenericValue *)key { 5073 [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueUInt64)]; 5074} 5075 5076- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 5077 [self enumerateKeysAndUInt32sUsingBlock:^(uint64_t key, uint32_t value, BOOL *stop) { 5078 #pragma unused(stop) 5079 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%u", value]); 5080 }]; 5081} 5082 5083- (BOOL)getUInt32:(nullable uint32_t *)value forKey:(uint64_t)key { 5084 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; 5085 if (wrapped && value) { 5086 *value = [wrapped unsignedIntValue]; 5087 } 5088 return (wrapped != NULL); 5089} 5090 5091- (void)addEntriesFromDictionary:(GPBUInt64UInt32Dictionary *)otherDictionary { 5092 if (otherDictionary) { 5093 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 5094 if (_autocreator) { 5095 GPBAutocreatedDictionaryModified(_autocreator, self); 5096 } 5097 } 5098} 5099 5100- (void)setUInt32:(uint32_t)value forKey:(uint64_t)key { 5101 [_dictionary setObject:@(value) forKey:@(key)]; 5102 if (_autocreator) { 5103 GPBAutocreatedDictionaryModified(_autocreator, self); 5104 } 5105} 5106 5107- (void)removeUInt32ForKey:(uint64_t)aKey { 5108 [_dictionary removeObjectForKey:@(aKey)]; 5109} 5110 5111- (void)removeAll { 5112 [_dictionary removeAllObjects]; 5113} 5114 5115@end 5116 5117#pragma mark - UInt64 -> Int32 5118 5119@implementation GPBUInt64Int32Dictionary { 5120 @package 5121 NSMutableDictionary *_dictionary; 5122} 5123 5124- (instancetype)init { 5125 return [self initWithInt32s:NULL forKeys:NULL count:0]; 5126} 5127 5128- (instancetype)initWithInt32s:(const int32_t [])values 5129 forKeys:(const uint64_t [])keys 5130 count:(NSUInteger)count { 5131 self = [super init]; 5132 if (self) { 5133 _dictionary = [[NSMutableDictionary alloc] init]; 5134 if (count && values && keys) { 5135 for (NSUInteger i = 0; i < count; ++i) { 5136 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; 5137 } 5138 } 5139 } 5140 return self; 5141} 5142 5143- (instancetype)initWithDictionary:(GPBUInt64Int32Dictionary *)dictionary { 5144 self = [self initWithInt32s:NULL forKeys:NULL count:0]; 5145 if (self) { 5146 if (dictionary) { 5147 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 5148 } 5149 } 5150 return self; 5151} 5152 5153- (instancetype)initWithCapacity:(NSUInteger)numItems { 5154 #pragma unused(numItems) 5155 return [self initWithInt32s:NULL forKeys:NULL count:0]; 5156} 5157 5158- (void)dealloc { 5159 NSAssert(!_autocreator, 5160 @"%@: Autocreator must be cleared before release, autocreator: %@", 5161 [self class], _autocreator); 5162 [_dictionary release]; 5163 [super dealloc]; 5164} 5165 5166- (instancetype)copyWithZone:(NSZone *)zone { 5167 return [[GPBUInt64Int32Dictionary allocWithZone:zone] initWithDictionary:self]; 5168} 5169 5170- (BOOL)isEqual:(id)other { 5171 if (self == other) { 5172 return YES; 5173 } 5174 if (![other isKindOfClass:[GPBUInt64Int32Dictionary class]]) { 5175 return NO; 5176 } 5177 GPBUInt64Int32Dictionary *otherDictionary = other; 5178 return [_dictionary isEqual:otherDictionary->_dictionary]; 5179} 5180 5181- (NSUInteger)hash { 5182 return _dictionary.count; 5183} 5184 5185- (NSString *)description { 5186 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 5187} 5188 5189- (NSUInteger)count { 5190 return _dictionary.count; 5191} 5192 5193- (void)enumerateKeysAndInt32sUsingBlock: 5194 (void (NS_NOESCAPE ^)(uint64_t key, int32_t value, BOOL *stop))block { 5195 BOOL stop = NO; 5196 NSDictionary *internal = _dictionary; 5197 NSEnumerator *keys = [internal keyEnumerator]; 5198 NSNumber *aKey; 5199 while ((aKey = [keys nextObject])) { 5200 NSNumber *aValue = internal[aKey]; 5201 block([aKey unsignedLongLongValue], [aValue intValue], &stop); 5202 if (stop) { 5203 break; 5204 } 5205 } 5206} 5207 5208- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 5209 NSDictionary *internal = _dictionary; 5210 NSUInteger count = internal.count; 5211 if (count == 0) { 5212 return 0; 5213 } 5214 5215 GPBDataType valueDataType = GPBGetFieldDataType(field); 5216 GPBDataType keyDataType = field.mapKeyDataType; 5217 size_t result = 0; 5218 NSEnumerator *keys = [internal keyEnumerator]; 5219 NSNumber *aKey; 5220 while ((aKey = [keys nextObject])) { 5221 NSNumber *aValue = internal[aKey]; 5222 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType); 5223 msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType); 5224 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 5225 } 5226 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 5227 result += tagSize * count; 5228 return result; 5229} 5230 5231- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 5232 asField:(GPBFieldDescriptor *)field { 5233 GPBDataType valueDataType = GPBGetFieldDataType(field); 5234 GPBDataType keyDataType = field.mapKeyDataType; 5235 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 5236 NSDictionary *internal = _dictionary; 5237 NSEnumerator *keys = [internal keyEnumerator]; 5238 NSNumber *aKey; 5239 while ((aKey = [keys nextObject])) { 5240 NSNumber *aValue = internal[aKey]; 5241 [outputStream writeInt32NoTag:tag]; 5242 // Write the size of the message. 5243 uint64_t unwrappedKey = [aKey unsignedLongLongValue]; 5244 int32_t unwrappedValue = [aValue intValue]; 5245 size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 5246 msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 5247 [outputStream writeInt32NoTag:(int32_t)msgSize]; 5248 // Write the fields. 5249 WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 5250 WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 5251 } 5252} 5253 5254- (void)setGPBGenericValue:(GPBGenericValue *)value 5255 forGPBGenericValueKey:(GPBGenericValue *)key { 5256 [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueUInt64)]; 5257} 5258 5259- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 5260 [self enumerateKeysAndInt32sUsingBlock:^(uint64_t key, int32_t value, BOOL *stop) { 5261 #pragma unused(stop) 5262 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%d", value]); 5263 }]; 5264} 5265 5266- (BOOL)getInt32:(nullable int32_t *)value forKey:(uint64_t)key { 5267 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; 5268 if (wrapped && value) { 5269 *value = [wrapped intValue]; 5270 } 5271 return (wrapped != NULL); 5272} 5273 5274- (void)addEntriesFromDictionary:(GPBUInt64Int32Dictionary *)otherDictionary { 5275 if (otherDictionary) { 5276 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 5277 if (_autocreator) { 5278 GPBAutocreatedDictionaryModified(_autocreator, self); 5279 } 5280 } 5281} 5282 5283- (void)setInt32:(int32_t)value forKey:(uint64_t)key { 5284 [_dictionary setObject:@(value) forKey:@(key)]; 5285 if (_autocreator) { 5286 GPBAutocreatedDictionaryModified(_autocreator, self); 5287 } 5288} 5289 5290- (void)removeInt32ForKey:(uint64_t)aKey { 5291 [_dictionary removeObjectForKey:@(aKey)]; 5292} 5293 5294- (void)removeAll { 5295 [_dictionary removeAllObjects]; 5296} 5297 5298@end 5299 5300#pragma mark - UInt64 -> UInt64 5301 5302@implementation GPBUInt64UInt64Dictionary { 5303 @package 5304 NSMutableDictionary *_dictionary; 5305} 5306 5307- (instancetype)init { 5308 return [self initWithUInt64s:NULL forKeys:NULL count:0]; 5309} 5310 5311- (instancetype)initWithUInt64s:(const uint64_t [])values 5312 forKeys:(const uint64_t [])keys 5313 count:(NSUInteger)count { 5314 self = [super init]; 5315 if (self) { 5316 _dictionary = [[NSMutableDictionary alloc] init]; 5317 if (count && values && keys) { 5318 for (NSUInteger i = 0; i < count; ++i) { 5319 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; 5320 } 5321 } 5322 } 5323 return self; 5324} 5325 5326- (instancetype)initWithDictionary:(GPBUInt64UInt64Dictionary *)dictionary { 5327 self = [self initWithUInt64s:NULL forKeys:NULL count:0]; 5328 if (self) { 5329 if (dictionary) { 5330 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 5331 } 5332 } 5333 return self; 5334} 5335 5336- (instancetype)initWithCapacity:(NSUInteger)numItems { 5337 #pragma unused(numItems) 5338 return [self initWithUInt64s:NULL forKeys:NULL count:0]; 5339} 5340 5341- (void)dealloc { 5342 NSAssert(!_autocreator, 5343 @"%@: Autocreator must be cleared before release, autocreator: %@", 5344 [self class], _autocreator); 5345 [_dictionary release]; 5346 [super dealloc]; 5347} 5348 5349- (instancetype)copyWithZone:(NSZone *)zone { 5350 return [[GPBUInt64UInt64Dictionary allocWithZone:zone] initWithDictionary:self]; 5351} 5352 5353- (BOOL)isEqual:(id)other { 5354 if (self == other) { 5355 return YES; 5356 } 5357 if (![other isKindOfClass:[GPBUInt64UInt64Dictionary class]]) { 5358 return NO; 5359 } 5360 GPBUInt64UInt64Dictionary *otherDictionary = other; 5361 return [_dictionary isEqual:otherDictionary->_dictionary]; 5362} 5363 5364- (NSUInteger)hash { 5365 return _dictionary.count; 5366} 5367 5368- (NSString *)description { 5369 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 5370} 5371 5372- (NSUInteger)count { 5373 return _dictionary.count; 5374} 5375 5376- (void)enumerateKeysAndUInt64sUsingBlock: 5377 (void (NS_NOESCAPE ^)(uint64_t key, uint64_t value, BOOL *stop))block { 5378 BOOL stop = NO; 5379 NSDictionary *internal = _dictionary; 5380 NSEnumerator *keys = [internal keyEnumerator]; 5381 NSNumber *aKey; 5382 while ((aKey = [keys nextObject])) { 5383 NSNumber *aValue = internal[aKey]; 5384 block([aKey unsignedLongLongValue], [aValue unsignedLongLongValue], &stop); 5385 if (stop) { 5386 break; 5387 } 5388 } 5389} 5390 5391- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 5392 NSDictionary *internal = _dictionary; 5393 NSUInteger count = internal.count; 5394 if (count == 0) { 5395 return 0; 5396 } 5397 5398 GPBDataType valueDataType = GPBGetFieldDataType(field); 5399 GPBDataType keyDataType = field.mapKeyDataType; 5400 size_t result = 0; 5401 NSEnumerator *keys = [internal keyEnumerator]; 5402 NSNumber *aKey; 5403 while ((aKey = [keys nextObject])) { 5404 NSNumber *aValue = internal[aKey]; 5405 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType); 5406 msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType); 5407 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 5408 } 5409 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 5410 result += tagSize * count; 5411 return result; 5412} 5413 5414- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 5415 asField:(GPBFieldDescriptor *)field { 5416 GPBDataType valueDataType = GPBGetFieldDataType(field); 5417 GPBDataType keyDataType = field.mapKeyDataType; 5418 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 5419 NSDictionary *internal = _dictionary; 5420 NSEnumerator *keys = [internal keyEnumerator]; 5421 NSNumber *aKey; 5422 while ((aKey = [keys nextObject])) { 5423 NSNumber *aValue = internal[aKey]; 5424 [outputStream writeInt32NoTag:tag]; 5425 // Write the size of the message. 5426 uint64_t unwrappedKey = [aKey unsignedLongLongValue]; 5427 uint64_t unwrappedValue = [aValue unsignedLongLongValue]; 5428 size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 5429 msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 5430 [outputStream writeInt32NoTag:(int32_t)msgSize]; 5431 // Write the fields. 5432 WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 5433 WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 5434 } 5435} 5436 5437- (void)setGPBGenericValue:(GPBGenericValue *)value 5438 forGPBGenericValueKey:(GPBGenericValue *)key { 5439 [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueUInt64)]; 5440} 5441 5442- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 5443 [self enumerateKeysAndUInt64sUsingBlock:^(uint64_t key, uint64_t value, BOOL *stop) { 5444 #pragma unused(stop) 5445 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%llu", value]); 5446 }]; 5447} 5448 5449- (BOOL)getUInt64:(nullable uint64_t *)value forKey:(uint64_t)key { 5450 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; 5451 if (wrapped && value) { 5452 *value = [wrapped unsignedLongLongValue]; 5453 } 5454 return (wrapped != NULL); 5455} 5456 5457- (void)addEntriesFromDictionary:(GPBUInt64UInt64Dictionary *)otherDictionary { 5458 if (otherDictionary) { 5459 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 5460 if (_autocreator) { 5461 GPBAutocreatedDictionaryModified(_autocreator, self); 5462 } 5463 } 5464} 5465 5466- (void)setUInt64:(uint64_t)value forKey:(uint64_t)key { 5467 [_dictionary setObject:@(value) forKey:@(key)]; 5468 if (_autocreator) { 5469 GPBAutocreatedDictionaryModified(_autocreator, self); 5470 } 5471} 5472 5473- (void)removeUInt64ForKey:(uint64_t)aKey { 5474 [_dictionary removeObjectForKey:@(aKey)]; 5475} 5476 5477- (void)removeAll { 5478 [_dictionary removeAllObjects]; 5479} 5480 5481@end 5482 5483#pragma mark - UInt64 -> Int64 5484 5485@implementation GPBUInt64Int64Dictionary { 5486 @package 5487 NSMutableDictionary *_dictionary; 5488} 5489 5490- (instancetype)init { 5491 return [self initWithInt64s:NULL forKeys:NULL count:0]; 5492} 5493 5494- (instancetype)initWithInt64s:(const int64_t [])values 5495 forKeys:(const uint64_t [])keys 5496 count:(NSUInteger)count { 5497 self = [super init]; 5498 if (self) { 5499 _dictionary = [[NSMutableDictionary alloc] init]; 5500 if (count && values && keys) { 5501 for (NSUInteger i = 0; i < count; ++i) { 5502 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; 5503 } 5504 } 5505 } 5506 return self; 5507} 5508 5509- (instancetype)initWithDictionary:(GPBUInt64Int64Dictionary *)dictionary { 5510 self = [self initWithInt64s:NULL forKeys:NULL count:0]; 5511 if (self) { 5512 if (dictionary) { 5513 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 5514 } 5515 } 5516 return self; 5517} 5518 5519- (instancetype)initWithCapacity:(NSUInteger)numItems { 5520 #pragma unused(numItems) 5521 return [self initWithInt64s:NULL forKeys:NULL count:0]; 5522} 5523 5524- (void)dealloc { 5525 NSAssert(!_autocreator, 5526 @"%@: Autocreator must be cleared before release, autocreator: %@", 5527 [self class], _autocreator); 5528 [_dictionary release]; 5529 [super dealloc]; 5530} 5531 5532- (instancetype)copyWithZone:(NSZone *)zone { 5533 return [[GPBUInt64Int64Dictionary allocWithZone:zone] initWithDictionary:self]; 5534} 5535 5536- (BOOL)isEqual:(id)other { 5537 if (self == other) { 5538 return YES; 5539 } 5540 if (![other isKindOfClass:[GPBUInt64Int64Dictionary class]]) { 5541 return NO; 5542 } 5543 GPBUInt64Int64Dictionary *otherDictionary = other; 5544 return [_dictionary isEqual:otherDictionary->_dictionary]; 5545} 5546 5547- (NSUInteger)hash { 5548 return _dictionary.count; 5549} 5550 5551- (NSString *)description { 5552 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 5553} 5554 5555- (NSUInteger)count { 5556 return _dictionary.count; 5557} 5558 5559- (void)enumerateKeysAndInt64sUsingBlock: 5560 (void (NS_NOESCAPE ^)(uint64_t key, int64_t value, BOOL *stop))block { 5561 BOOL stop = NO; 5562 NSDictionary *internal = _dictionary; 5563 NSEnumerator *keys = [internal keyEnumerator]; 5564 NSNumber *aKey; 5565 while ((aKey = [keys nextObject])) { 5566 NSNumber *aValue = internal[aKey]; 5567 block([aKey unsignedLongLongValue], [aValue longLongValue], &stop); 5568 if (stop) { 5569 break; 5570 } 5571 } 5572} 5573 5574- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 5575 NSDictionary *internal = _dictionary; 5576 NSUInteger count = internal.count; 5577 if (count == 0) { 5578 return 0; 5579 } 5580 5581 GPBDataType valueDataType = GPBGetFieldDataType(field); 5582 GPBDataType keyDataType = field.mapKeyDataType; 5583 size_t result = 0; 5584 NSEnumerator *keys = [internal keyEnumerator]; 5585 NSNumber *aKey; 5586 while ((aKey = [keys nextObject])) { 5587 NSNumber *aValue = internal[aKey]; 5588 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType); 5589 msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType); 5590 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 5591 } 5592 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 5593 result += tagSize * count; 5594 return result; 5595} 5596 5597- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 5598 asField:(GPBFieldDescriptor *)field { 5599 GPBDataType valueDataType = GPBGetFieldDataType(field); 5600 GPBDataType keyDataType = field.mapKeyDataType; 5601 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 5602 NSDictionary *internal = _dictionary; 5603 NSEnumerator *keys = [internal keyEnumerator]; 5604 NSNumber *aKey; 5605 while ((aKey = [keys nextObject])) { 5606 NSNumber *aValue = internal[aKey]; 5607 [outputStream writeInt32NoTag:tag]; 5608 // Write the size of the message. 5609 uint64_t unwrappedKey = [aKey unsignedLongLongValue]; 5610 int64_t unwrappedValue = [aValue longLongValue]; 5611 size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 5612 msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 5613 [outputStream writeInt32NoTag:(int32_t)msgSize]; 5614 // Write the fields. 5615 WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 5616 WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 5617 } 5618} 5619 5620- (void)setGPBGenericValue:(GPBGenericValue *)value 5621 forGPBGenericValueKey:(GPBGenericValue *)key { 5622 [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueUInt64)]; 5623} 5624 5625- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 5626 [self enumerateKeysAndInt64sUsingBlock:^(uint64_t key, int64_t value, BOOL *stop) { 5627 #pragma unused(stop) 5628 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%lld", value]); 5629 }]; 5630} 5631 5632- (BOOL)getInt64:(nullable int64_t *)value forKey:(uint64_t)key { 5633 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; 5634 if (wrapped && value) { 5635 *value = [wrapped longLongValue]; 5636 } 5637 return (wrapped != NULL); 5638} 5639 5640- (void)addEntriesFromDictionary:(GPBUInt64Int64Dictionary *)otherDictionary { 5641 if (otherDictionary) { 5642 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 5643 if (_autocreator) { 5644 GPBAutocreatedDictionaryModified(_autocreator, self); 5645 } 5646 } 5647} 5648 5649- (void)setInt64:(int64_t)value forKey:(uint64_t)key { 5650 [_dictionary setObject:@(value) forKey:@(key)]; 5651 if (_autocreator) { 5652 GPBAutocreatedDictionaryModified(_autocreator, self); 5653 } 5654} 5655 5656- (void)removeInt64ForKey:(uint64_t)aKey { 5657 [_dictionary removeObjectForKey:@(aKey)]; 5658} 5659 5660- (void)removeAll { 5661 [_dictionary removeAllObjects]; 5662} 5663 5664@end 5665 5666#pragma mark - UInt64 -> Bool 5667 5668@implementation GPBUInt64BoolDictionary { 5669 @package 5670 NSMutableDictionary *_dictionary; 5671} 5672 5673- (instancetype)init { 5674 return [self initWithBools:NULL forKeys:NULL count:0]; 5675} 5676 5677- (instancetype)initWithBools:(const BOOL [])values 5678 forKeys:(const uint64_t [])keys 5679 count:(NSUInteger)count { 5680 self = [super init]; 5681 if (self) { 5682 _dictionary = [[NSMutableDictionary alloc] init]; 5683 if (count && values && keys) { 5684 for (NSUInteger i = 0; i < count; ++i) { 5685 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; 5686 } 5687 } 5688 } 5689 return self; 5690} 5691 5692- (instancetype)initWithDictionary:(GPBUInt64BoolDictionary *)dictionary { 5693 self = [self initWithBools:NULL forKeys:NULL count:0]; 5694 if (self) { 5695 if (dictionary) { 5696 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 5697 } 5698 } 5699 return self; 5700} 5701 5702- (instancetype)initWithCapacity:(NSUInteger)numItems { 5703 #pragma unused(numItems) 5704 return [self initWithBools:NULL forKeys:NULL count:0]; 5705} 5706 5707- (void)dealloc { 5708 NSAssert(!_autocreator, 5709 @"%@: Autocreator must be cleared before release, autocreator: %@", 5710 [self class], _autocreator); 5711 [_dictionary release]; 5712 [super dealloc]; 5713} 5714 5715- (instancetype)copyWithZone:(NSZone *)zone { 5716 return [[GPBUInt64BoolDictionary allocWithZone:zone] initWithDictionary:self]; 5717} 5718 5719- (BOOL)isEqual:(id)other { 5720 if (self == other) { 5721 return YES; 5722 } 5723 if (![other isKindOfClass:[GPBUInt64BoolDictionary class]]) { 5724 return NO; 5725 } 5726 GPBUInt64BoolDictionary *otherDictionary = other; 5727 return [_dictionary isEqual:otherDictionary->_dictionary]; 5728} 5729 5730- (NSUInteger)hash { 5731 return _dictionary.count; 5732} 5733 5734- (NSString *)description { 5735 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 5736} 5737 5738- (NSUInteger)count { 5739 return _dictionary.count; 5740} 5741 5742- (void)enumerateKeysAndBoolsUsingBlock: 5743 (void (NS_NOESCAPE ^)(uint64_t key, BOOL value, BOOL *stop))block { 5744 BOOL stop = NO; 5745 NSDictionary *internal = _dictionary; 5746 NSEnumerator *keys = [internal keyEnumerator]; 5747 NSNumber *aKey; 5748 while ((aKey = [keys nextObject])) { 5749 NSNumber *aValue = internal[aKey]; 5750 block([aKey unsignedLongLongValue], [aValue boolValue], &stop); 5751 if (stop) { 5752 break; 5753 } 5754 } 5755} 5756 5757- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 5758 NSDictionary *internal = _dictionary; 5759 NSUInteger count = internal.count; 5760 if (count == 0) { 5761 return 0; 5762 } 5763 5764 GPBDataType valueDataType = GPBGetFieldDataType(field); 5765 GPBDataType keyDataType = field.mapKeyDataType; 5766 size_t result = 0; 5767 NSEnumerator *keys = [internal keyEnumerator]; 5768 NSNumber *aKey; 5769 while ((aKey = [keys nextObject])) { 5770 NSNumber *aValue = internal[aKey]; 5771 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType); 5772 msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType); 5773 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 5774 } 5775 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 5776 result += tagSize * count; 5777 return result; 5778} 5779 5780- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 5781 asField:(GPBFieldDescriptor *)field { 5782 GPBDataType valueDataType = GPBGetFieldDataType(field); 5783 GPBDataType keyDataType = field.mapKeyDataType; 5784 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 5785 NSDictionary *internal = _dictionary; 5786 NSEnumerator *keys = [internal keyEnumerator]; 5787 NSNumber *aKey; 5788 while ((aKey = [keys nextObject])) { 5789 NSNumber *aValue = internal[aKey]; 5790 [outputStream writeInt32NoTag:tag]; 5791 // Write the size of the message. 5792 uint64_t unwrappedKey = [aKey unsignedLongLongValue]; 5793 BOOL unwrappedValue = [aValue boolValue]; 5794 size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 5795 msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 5796 [outputStream writeInt32NoTag:(int32_t)msgSize]; 5797 // Write the fields. 5798 WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 5799 WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 5800 } 5801} 5802 5803- (void)setGPBGenericValue:(GPBGenericValue *)value 5804 forGPBGenericValueKey:(GPBGenericValue *)key { 5805 [_dictionary setObject:@(value->valueBool) forKey:@(key->valueUInt64)]; 5806} 5807 5808- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 5809 [self enumerateKeysAndBoolsUsingBlock:^(uint64_t key, BOOL value, BOOL *stop) { 5810 #pragma unused(stop) 5811 block([NSString stringWithFormat:@"%llu", key], (value ? @"true" : @"false")); 5812 }]; 5813} 5814 5815- (BOOL)getBool:(nullable BOOL *)value forKey:(uint64_t)key { 5816 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; 5817 if (wrapped && value) { 5818 *value = [wrapped boolValue]; 5819 } 5820 return (wrapped != NULL); 5821} 5822 5823- (void)addEntriesFromDictionary:(GPBUInt64BoolDictionary *)otherDictionary { 5824 if (otherDictionary) { 5825 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 5826 if (_autocreator) { 5827 GPBAutocreatedDictionaryModified(_autocreator, self); 5828 } 5829 } 5830} 5831 5832- (void)setBool:(BOOL)value forKey:(uint64_t)key { 5833 [_dictionary setObject:@(value) forKey:@(key)]; 5834 if (_autocreator) { 5835 GPBAutocreatedDictionaryModified(_autocreator, self); 5836 } 5837} 5838 5839- (void)removeBoolForKey:(uint64_t)aKey { 5840 [_dictionary removeObjectForKey:@(aKey)]; 5841} 5842 5843- (void)removeAll { 5844 [_dictionary removeAllObjects]; 5845} 5846 5847@end 5848 5849#pragma mark - UInt64 -> Float 5850 5851@implementation GPBUInt64FloatDictionary { 5852 @package 5853 NSMutableDictionary *_dictionary; 5854} 5855 5856- (instancetype)init { 5857 return [self initWithFloats:NULL forKeys:NULL count:0]; 5858} 5859 5860- (instancetype)initWithFloats:(const float [])values 5861 forKeys:(const uint64_t [])keys 5862 count:(NSUInteger)count { 5863 self = [super init]; 5864 if (self) { 5865 _dictionary = [[NSMutableDictionary alloc] init]; 5866 if (count && values && keys) { 5867 for (NSUInteger i = 0; i < count; ++i) { 5868 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; 5869 } 5870 } 5871 } 5872 return self; 5873} 5874 5875- (instancetype)initWithDictionary:(GPBUInt64FloatDictionary *)dictionary { 5876 self = [self initWithFloats:NULL forKeys:NULL count:0]; 5877 if (self) { 5878 if (dictionary) { 5879 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 5880 } 5881 } 5882 return self; 5883} 5884 5885- (instancetype)initWithCapacity:(NSUInteger)numItems { 5886 #pragma unused(numItems) 5887 return [self initWithFloats:NULL forKeys:NULL count:0]; 5888} 5889 5890- (void)dealloc { 5891 NSAssert(!_autocreator, 5892 @"%@: Autocreator must be cleared before release, autocreator: %@", 5893 [self class], _autocreator); 5894 [_dictionary release]; 5895 [super dealloc]; 5896} 5897 5898- (instancetype)copyWithZone:(NSZone *)zone { 5899 return [[GPBUInt64FloatDictionary allocWithZone:zone] initWithDictionary:self]; 5900} 5901 5902- (BOOL)isEqual:(id)other { 5903 if (self == other) { 5904 return YES; 5905 } 5906 if (![other isKindOfClass:[GPBUInt64FloatDictionary class]]) { 5907 return NO; 5908 } 5909 GPBUInt64FloatDictionary *otherDictionary = other; 5910 return [_dictionary isEqual:otherDictionary->_dictionary]; 5911} 5912 5913- (NSUInteger)hash { 5914 return _dictionary.count; 5915} 5916 5917- (NSString *)description { 5918 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 5919} 5920 5921- (NSUInteger)count { 5922 return _dictionary.count; 5923} 5924 5925- (void)enumerateKeysAndFloatsUsingBlock: 5926 (void (NS_NOESCAPE ^)(uint64_t key, float value, BOOL *stop))block { 5927 BOOL stop = NO; 5928 NSDictionary *internal = _dictionary; 5929 NSEnumerator *keys = [internal keyEnumerator]; 5930 NSNumber *aKey; 5931 while ((aKey = [keys nextObject])) { 5932 NSNumber *aValue = internal[aKey]; 5933 block([aKey unsignedLongLongValue], [aValue floatValue], &stop); 5934 if (stop) { 5935 break; 5936 } 5937 } 5938} 5939 5940- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 5941 NSDictionary *internal = _dictionary; 5942 NSUInteger count = internal.count; 5943 if (count == 0) { 5944 return 0; 5945 } 5946 5947 GPBDataType valueDataType = GPBGetFieldDataType(field); 5948 GPBDataType keyDataType = field.mapKeyDataType; 5949 size_t result = 0; 5950 NSEnumerator *keys = [internal keyEnumerator]; 5951 NSNumber *aKey; 5952 while ((aKey = [keys nextObject])) { 5953 NSNumber *aValue = internal[aKey]; 5954 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType); 5955 msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType); 5956 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 5957 } 5958 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 5959 result += tagSize * count; 5960 return result; 5961} 5962 5963- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 5964 asField:(GPBFieldDescriptor *)field { 5965 GPBDataType valueDataType = GPBGetFieldDataType(field); 5966 GPBDataType keyDataType = field.mapKeyDataType; 5967 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 5968 NSDictionary *internal = _dictionary; 5969 NSEnumerator *keys = [internal keyEnumerator]; 5970 NSNumber *aKey; 5971 while ((aKey = [keys nextObject])) { 5972 NSNumber *aValue = internal[aKey]; 5973 [outputStream writeInt32NoTag:tag]; 5974 // Write the size of the message. 5975 uint64_t unwrappedKey = [aKey unsignedLongLongValue]; 5976 float unwrappedValue = [aValue floatValue]; 5977 size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 5978 msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 5979 [outputStream writeInt32NoTag:(int32_t)msgSize]; 5980 // Write the fields. 5981 WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 5982 WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 5983 } 5984} 5985 5986- (void)setGPBGenericValue:(GPBGenericValue *)value 5987 forGPBGenericValueKey:(GPBGenericValue *)key { 5988 [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueUInt64)]; 5989} 5990 5991- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 5992 [self enumerateKeysAndFloatsUsingBlock:^(uint64_t key, float value, BOOL *stop) { 5993 #pragma unused(stop) 5994 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]); 5995 }]; 5996} 5997 5998- (BOOL)getFloat:(nullable float *)value forKey:(uint64_t)key { 5999 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; 6000 if (wrapped && value) { 6001 *value = [wrapped floatValue]; 6002 } 6003 return (wrapped != NULL); 6004} 6005 6006- (void)addEntriesFromDictionary:(GPBUInt64FloatDictionary *)otherDictionary { 6007 if (otherDictionary) { 6008 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 6009 if (_autocreator) { 6010 GPBAutocreatedDictionaryModified(_autocreator, self); 6011 } 6012 } 6013} 6014 6015- (void)setFloat:(float)value forKey:(uint64_t)key { 6016 [_dictionary setObject:@(value) forKey:@(key)]; 6017 if (_autocreator) { 6018 GPBAutocreatedDictionaryModified(_autocreator, self); 6019 } 6020} 6021 6022- (void)removeFloatForKey:(uint64_t)aKey { 6023 [_dictionary removeObjectForKey:@(aKey)]; 6024} 6025 6026- (void)removeAll { 6027 [_dictionary removeAllObjects]; 6028} 6029 6030@end 6031 6032#pragma mark - UInt64 -> Double 6033 6034@implementation GPBUInt64DoubleDictionary { 6035 @package 6036 NSMutableDictionary *_dictionary; 6037} 6038 6039- (instancetype)init { 6040 return [self initWithDoubles:NULL forKeys:NULL count:0]; 6041} 6042 6043- (instancetype)initWithDoubles:(const double [])values 6044 forKeys:(const uint64_t [])keys 6045 count:(NSUInteger)count { 6046 self = [super init]; 6047 if (self) { 6048 _dictionary = [[NSMutableDictionary alloc] init]; 6049 if (count && values && keys) { 6050 for (NSUInteger i = 0; i < count; ++i) { 6051 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; 6052 } 6053 } 6054 } 6055 return self; 6056} 6057 6058- (instancetype)initWithDictionary:(GPBUInt64DoubleDictionary *)dictionary { 6059 self = [self initWithDoubles:NULL forKeys:NULL count:0]; 6060 if (self) { 6061 if (dictionary) { 6062 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 6063 } 6064 } 6065 return self; 6066} 6067 6068- (instancetype)initWithCapacity:(NSUInteger)numItems { 6069 #pragma unused(numItems) 6070 return [self initWithDoubles:NULL forKeys:NULL count:0]; 6071} 6072 6073- (void)dealloc { 6074 NSAssert(!_autocreator, 6075 @"%@: Autocreator must be cleared before release, autocreator: %@", 6076 [self class], _autocreator); 6077 [_dictionary release]; 6078 [super dealloc]; 6079} 6080 6081- (instancetype)copyWithZone:(NSZone *)zone { 6082 return [[GPBUInt64DoubleDictionary allocWithZone:zone] initWithDictionary:self]; 6083} 6084 6085- (BOOL)isEqual:(id)other { 6086 if (self == other) { 6087 return YES; 6088 } 6089 if (![other isKindOfClass:[GPBUInt64DoubleDictionary class]]) { 6090 return NO; 6091 } 6092 GPBUInt64DoubleDictionary *otherDictionary = other; 6093 return [_dictionary isEqual:otherDictionary->_dictionary]; 6094} 6095 6096- (NSUInteger)hash { 6097 return _dictionary.count; 6098} 6099 6100- (NSString *)description { 6101 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 6102} 6103 6104- (NSUInteger)count { 6105 return _dictionary.count; 6106} 6107 6108- (void)enumerateKeysAndDoublesUsingBlock: 6109 (void (NS_NOESCAPE ^)(uint64_t key, double value, BOOL *stop))block { 6110 BOOL stop = NO; 6111 NSDictionary *internal = _dictionary; 6112 NSEnumerator *keys = [internal keyEnumerator]; 6113 NSNumber *aKey; 6114 while ((aKey = [keys nextObject])) { 6115 NSNumber *aValue = internal[aKey]; 6116 block([aKey unsignedLongLongValue], [aValue doubleValue], &stop); 6117 if (stop) { 6118 break; 6119 } 6120 } 6121} 6122 6123- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 6124 NSDictionary *internal = _dictionary; 6125 NSUInteger count = internal.count; 6126 if (count == 0) { 6127 return 0; 6128 } 6129 6130 GPBDataType valueDataType = GPBGetFieldDataType(field); 6131 GPBDataType keyDataType = field.mapKeyDataType; 6132 size_t result = 0; 6133 NSEnumerator *keys = [internal keyEnumerator]; 6134 NSNumber *aKey; 6135 while ((aKey = [keys nextObject])) { 6136 NSNumber *aValue = internal[aKey]; 6137 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType); 6138 msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType); 6139 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 6140 } 6141 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 6142 result += tagSize * count; 6143 return result; 6144} 6145 6146- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 6147 asField:(GPBFieldDescriptor *)field { 6148 GPBDataType valueDataType = GPBGetFieldDataType(field); 6149 GPBDataType keyDataType = field.mapKeyDataType; 6150 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 6151 NSDictionary *internal = _dictionary; 6152 NSEnumerator *keys = [internal keyEnumerator]; 6153 NSNumber *aKey; 6154 while ((aKey = [keys nextObject])) { 6155 NSNumber *aValue = internal[aKey]; 6156 [outputStream writeInt32NoTag:tag]; 6157 // Write the size of the message. 6158 uint64_t unwrappedKey = [aKey unsignedLongLongValue]; 6159 double unwrappedValue = [aValue doubleValue]; 6160 size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 6161 msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 6162 [outputStream writeInt32NoTag:(int32_t)msgSize]; 6163 // Write the fields. 6164 WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 6165 WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 6166 } 6167} 6168 6169- (void)setGPBGenericValue:(GPBGenericValue *)value 6170 forGPBGenericValueKey:(GPBGenericValue *)key { 6171 [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueUInt64)]; 6172} 6173 6174- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 6175 [self enumerateKeysAndDoublesUsingBlock:^(uint64_t key, double value, BOOL *stop) { 6176 #pragma unused(stop) 6177 block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]); 6178 }]; 6179} 6180 6181- (BOOL)getDouble:(nullable double *)value forKey:(uint64_t)key { 6182 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; 6183 if (wrapped && value) { 6184 *value = [wrapped doubleValue]; 6185 } 6186 return (wrapped != NULL); 6187} 6188 6189- (void)addEntriesFromDictionary:(GPBUInt64DoubleDictionary *)otherDictionary { 6190 if (otherDictionary) { 6191 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 6192 if (_autocreator) { 6193 GPBAutocreatedDictionaryModified(_autocreator, self); 6194 } 6195 } 6196} 6197 6198- (void)setDouble:(double)value forKey:(uint64_t)key { 6199 [_dictionary setObject:@(value) forKey:@(key)]; 6200 if (_autocreator) { 6201 GPBAutocreatedDictionaryModified(_autocreator, self); 6202 } 6203} 6204 6205- (void)removeDoubleForKey:(uint64_t)aKey { 6206 [_dictionary removeObjectForKey:@(aKey)]; 6207} 6208 6209- (void)removeAll { 6210 [_dictionary removeAllObjects]; 6211} 6212 6213@end 6214 6215#pragma mark - UInt64 -> Enum 6216 6217@implementation GPBUInt64EnumDictionary { 6218 @package 6219 NSMutableDictionary *_dictionary; 6220 GPBEnumValidationFunc _validationFunc; 6221} 6222 6223@synthesize validationFunc = _validationFunc; 6224 6225- (instancetype)init { 6226 return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0]; 6227} 6228 6229- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func { 6230 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0]; 6231} 6232 6233- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func 6234 rawValues:(const int32_t [])rawValues 6235 forKeys:(const uint64_t [])keys 6236 count:(NSUInteger)count { 6237 self = [super init]; 6238 if (self) { 6239 _dictionary = [[NSMutableDictionary alloc] init]; 6240 _validationFunc = (func != NULL ? func : DictDefault_IsValidValue); 6241 if (count && rawValues && keys) { 6242 for (NSUInteger i = 0; i < count; ++i) { 6243 [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])]; 6244 } 6245 } 6246 } 6247 return self; 6248} 6249 6250- (instancetype)initWithDictionary:(GPBUInt64EnumDictionary *)dictionary { 6251 self = [self initWithValidationFunction:dictionary.validationFunc 6252 rawValues:NULL 6253 forKeys:NULL 6254 count:0]; 6255 if (self) { 6256 if (dictionary) { 6257 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 6258 } 6259 } 6260 return self; 6261} 6262 6263- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func 6264 capacity:(NSUInteger)numItems { 6265 #pragma unused(numItems) 6266 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0]; 6267} 6268 6269- (void)dealloc { 6270 NSAssert(!_autocreator, 6271 @"%@: Autocreator must be cleared before release, autocreator: %@", 6272 [self class], _autocreator); 6273 [_dictionary release]; 6274 [super dealloc]; 6275} 6276 6277- (instancetype)copyWithZone:(NSZone *)zone { 6278 return [[GPBUInt64EnumDictionary allocWithZone:zone] initWithDictionary:self]; 6279} 6280 6281- (BOOL)isEqual:(id)other { 6282 if (self == other) { 6283 return YES; 6284 } 6285 if (![other isKindOfClass:[GPBUInt64EnumDictionary class]]) { 6286 return NO; 6287 } 6288 GPBUInt64EnumDictionary *otherDictionary = other; 6289 return [_dictionary isEqual:otherDictionary->_dictionary]; 6290} 6291 6292- (NSUInteger)hash { 6293 return _dictionary.count; 6294} 6295 6296- (NSString *)description { 6297 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 6298} 6299 6300- (NSUInteger)count { 6301 return _dictionary.count; 6302} 6303 6304- (void)enumerateKeysAndRawValuesUsingBlock: 6305 (void (NS_NOESCAPE ^)(uint64_t key, int32_t value, BOOL *stop))block { 6306 BOOL stop = NO; 6307 NSDictionary *internal = _dictionary; 6308 NSEnumerator *keys = [internal keyEnumerator]; 6309 NSNumber *aKey; 6310 while ((aKey = [keys nextObject])) { 6311 NSNumber *aValue = internal[aKey]; 6312 block([aKey unsignedLongLongValue], [aValue intValue], &stop); 6313 if (stop) { 6314 break; 6315 } 6316 } 6317} 6318 6319- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 6320 NSDictionary *internal = _dictionary; 6321 NSUInteger count = internal.count; 6322 if (count == 0) { 6323 return 0; 6324 } 6325 6326 GPBDataType valueDataType = GPBGetFieldDataType(field); 6327 GPBDataType keyDataType = field.mapKeyDataType; 6328 size_t result = 0; 6329 NSEnumerator *keys = [internal keyEnumerator]; 6330 NSNumber *aKey; 6331 while ((aKey = [keys nextObject])) { 6332 NSNumber *aValue = internal[aKey]; 6333 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType); 6334 msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType); 6335 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 6336 } 6337 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 6338 result += tagSize * count; 6339 return result; 6340} 6341 6342- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 6343 asField:(GPBFieldDescriptor *)field { 6344 GPBDataType valueDataType = GPBGetFieldDataType(field); 6345 GPBDataType keyDataType = field.mapKeyDataType; 6346 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 6347 NSDictionary *internal = _dictionary; 6348 NSEnumerator *keys = [internal keyEnumerator]; 6349 NSNumber *aKey; 6350 while ((aKey = [keys nextObject])) { 6351 NSNumber *aValue = internal[aKey]; 6352 [outputStream writeInt32NoTag:tag]; 6353 // Write the size of the message. 6354 uint64_t unwrappedKey = [aKey unsignedLongLongValue]; 6355 int32_t unwrappedValue = [aValue intValue]; 6356 size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 6357 msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 6358 [outputStream writeInt32NoTag:(int32_t)msgSize]; 6359 // Write the fields. 6360 WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 6361 WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 6362 } 6363} 6364 6365- (NSData *)serializedDataForUnknownValue:(int32_t)value 6366 forKey:(GPBGenericValue *)key 6367 keyDataType:(GPBDataType)keyDataType { 6368 size_t msgSize = ComputeDictUInt64FieldSize(key->valueUInt64, kMapKeyFieldNumber, keyDataType); 6369 msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum); 6370 NSMutableData *data = [NSMutableData dataWithLength:msgSize]; 6371 GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data]; 6372 WriteDictUInt64Field(outputStream, key->valueUInt64, kMapKeyFieldNumber, keyDataType); 6373 WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum); 6374 [outputStream release]; 6375 return data; 6376} 6377- (void)setGPBGenericValue:(GPBGenericValue *)value 6378 forGPBGenericValueKey:(GPBGenericValue *)key { 6379 [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueUInt64)]; 6380} 6381 6382- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 6383 [self enumerateKeysAndRawValuesUsingBlock:^(uint64_t key, int32_t value, BOOL *stop) { 6384 #pragma unused(stop) 6385 block([NSString stringWithFormat:@"%llu", key], @(value)); 6386 }]; 6387} 6388 6389- (BOOL)getEnum:(int32_t *)value forKey:(uint64_t)key { 6390 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; 6391 if (wrapped && value) { 6392 int32_t result = [wrapped intValue]; 6393 if (!_validationFunc(result)) { 6394 result = kGPBUnrecognizedEnumeratorValue; 6395 } 6396 *value = result; 6397 } 6398 return (wrapped != NULL); 6399} 6400 6401- (BOOL)getRawValue:(int32_t *)rawValue forKey:(uint64_t)key { 6402 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; 6403 if (wrapped && rawValue) { 6404 *rawValue = [wrapped intValue]; 6405 } 6406 return (wrapped != NULL); 6407} 6408 6409- (void)enumerateKeysAndEnumsUsingBlock: 6410 (void (NS_NOESCAPE ^)(uint64_t key, int32_t value, BOOL *stop))block { 6411 GPBEnumValidationFunc func = _validationFunc; 6412 BOOL stop = NO; 6413 NSEnumerator *keys = [_dictionary keyEnumerator]; 6414 NSNumber *aKey; 6415 while ((aKey = [keys nextObject])) { 6416 NSNumber *aValue = _dictionary[aKey]; 6417 int32_t unwrapped = [aValue intValue]; 6418 if (!func(unwrapped)) { 6419 unwrapped = kGPBUnrecognizedEnumeratorValue; 6420 } 6421 block([aKey unsignedLongLongValue], unwrapped, &stop); 6422 if (stop) { 6423 break; 6424 } 6425 } 6426} 6427 6428- (void)addRawEntriesFromDictionary:(GPBUInt64EnumDictionary *)otherDictionary { 6429 if (otherDictionary) { 6430 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 6431 if (_autocreator) { 6432 GPBAutocreatedDictionaryModified(_autocreator, self); 6433 } 6434 } 6435} 6436 6437- (void)setRawValue:(int32_t)value forKey:(uint64_t)key { 6438 [_dictionary setObject:@(value) forKey:@(key)]; 6439 if (_autocreator) { 6440 GPBAutocreatedDictionaryModified(_autocreator, self); 6441 } 6442} 6443 6444- (void)removeEnumForKey:(uint64_t)aKey { 6445 [_dictionary removeObjectForKey:@(aKey)]; 6446} 6447 6448- (void)removeAll { 6449 [_dictionary removeAllObjects]; 6450} 6451 6452- (void)setEnum:(int32_t)value forKey:(uint64_t)key { 6453 if (!_validationFunc(value)) { 6454 [NSException raise:NSInvalidArgumentException 6455 format:@"GPBUInt64EnumDictionary: Attempt to set an unknown enum value (%d)", 6456 value]; 6457 } 6458 6459 [_dictionary setObject:@(value) forKey:@(key)]; 6460 if (_autocreator) { 6461 GPBAutocreatedDictionaryModified(_autocreator, self); 6462 } 6463} 6464 6465@end 6466 6467#pragma mark - UInt64 -> Object 6468 6469@implementation GPBUInt64ObjectDictionary { 6470 @package 6471 NSMutableDictionary *_dictionary; 6472} 6473 6474- (instancetype)init { 6475 return [self initWithObjects:NULL forKeys:NULL count:0]; 6476} 6477 6478- (instancetype)initWithObjects:(const id [])objects 6479 forKeys:(const uint64_t [])keys 6480 count:(NSUInteger)count { 6481 self = [super init]; 6482 if (self) { 6483 _dictionary = [[NSMutableDictionary alloc] init]; 6484 if (count && objects && keys) { 6485 for (NSUInteger i = 0; i < count; ++i) { 6486 if (!objects[i]) { 6487 [NSException raise:NSInvalidArgumentException 6488 format:@"Attempting to add nil object to a Dictionary"]; 6489 } 6490 [_dictionary setObject:objects[i] forKey:@(keys[i])]; 6491 } 6492 } 6493 } 6494 return self; 6495} 6496 6497- (instancetype)initWithDictionary:(GPBUInt64ObjectDictionary *)dictionary { 6498 self = [self initWithObjects:NULL forKeys:NULL count:0]; 6499 if (self) { 6500 if (dictionary) { 6501 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 6502 } 6503 } 6504 return self; 6505} 6506 6507- (instancetype)initWithCapacity:(NSUInteger)numItems { 6508 #pragma unused(numItems) 6509 return [self initWithObjects:NULL forKeys:NULL count:0]; 6510} 6511 6512- (void)dealloc { 6513 NSAssert(!_autocreator, 6514 @"%@: Autocreator must be cleared before release, autocreator: %@", 6515 [self class], _autocreator); 6516 [_dictionary release]; 6517 [super dealloc]; 6518} 6519 6520- (instancetype)copyWithZone:(NSZone *)zone { 6521 return [[GPBUInt64ObjectDictionary allocWithZone:zone] initWithDictionary:self]; 6522} 6523 6524- (BOOL)isEqual:(id)other { 6525 if (self == other) { 6526 return YES; 6527 } 6528 if (![other isKindOfClass:[GPBUInt64ObjectDictionary class]]) { 6529 return NO; 6530 } 6531 GPBUInt64ObjectDictionary *otherDictionary = other; 6532 return [_dictionary isEqual:otherDictionary->_dictionary]; 6533} 6534 6535- (NSUInteger)hash { 6536 return _dictionary.count; 6537} 6538 6539- (NSString *)description { 6540 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 6541} 6542 6543- (NSUInteger)count { 6544 return _dictionary.count; 6545} 6546 6547- (void)enumerateKeysAndObjectsUsingBlock: 6548 (void (NS_NOESCAPE ^)(uint64_t key, id object, BOOL *stop))block { 6549 BOOL stop = NO; 6550 NSDictionary *internal = _dictionary; 6551 NSEnumerator *keys = [internal keyEnumerator]; 6552 NSNumber *aKey; 6553 while ((aKey = [keys nextObject])) { 6554 id aObject = internal[aKey]; 6555 block([aKey unsignedLongLongValue], aObject, &stop); 6556 if (stop) { 6557 break; 6558 } 6559 } 6560} 6561 6562- (BOOL)isInitialized { 6563 for (GPBMessage *msg in [_dictionary objectEnumerator]) { 6564 if (!msg.initialized) { 6565 return NO; 6566 } 6567 } 6568 return YES; 6569} 6570 6571- (instancetype)deepCopyWithZone:(NSZone *)zone { 6572 GPBUInt64ObjectDictionary *newDict = 6573 [[GPBUInt64ObjectDictionary alloc] init]; 6574 NSEnumerator *keys = [_dictionary keyEnumerator]; 6575 id aKey; 6576 NSMutableDictionary *internalDict = newDict->_dictionary; 6577 while ((aKey = [keys nextObject])) { 6578 GPBMessage *msg = _dictionary[aKey]; 6579 GPBMessage *copiedMsg = [msg copyWithZone:zone]; 6580 [internalDict setObject:copiedMsg forKey:aKey]; 6581 [copiedMsg release]; 6582 } 6583 return newDict; 6584} 6585 6586- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 6587 NSDictionary *internal = _dictionary; 6588 NSUInteger count = internal.count; 6589 if (count == 0) { 6590 return 0; 6591 } 6592 6593 GPBDataType valueDataType = GPBGetFieldDataType(field); 6594 GPBDataType keyDataType = field.mapKeyDataType; 6595 size_t result = 0; 6596 NSEnumerator *keys = [internal keyEnumerator]; 6597 NSNumber *aKey; 6598 while ((aKey = [keys nextObject])) { 6599 id aObject = internal[aKey]; 6600 size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType); 6601 msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType); 6602 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 6603 } 6604 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 6605 result += tagSize * count; 6606 return result; 6607} 6608 6609- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 6610 asField:(GPBFieldDescriptor *)field { 6611 GPBDataType valueDataType = GPBGetFieldDataType(field); 6612 GPBDataType keyDataType = field.mapKeyDataType; 6613 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 6614 NSDictionary *internal = _dictionary; 6615 NSEnumerator *keys = [internal keyEnumerator]; 6616 NSNumber *aKey; 6617 while ((aKey = [keys nextObject])) { 6618 id aObject = internal[aKey]; 6619 [outputStream writeInt32NoTag:tag]; 6620 // Write the size of the message. 6621 uint64_t unwrappedKey = [aKey unsignedLongLongValue]; 6622 id unwrappedValue = aObject; 6623 size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 6624 msgSize += ComputeDictObjectFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 6625 [outputStream writeInt32NoTag:(int32_t)msgSize]; 6626 // Write the fields. 6627 WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 6628 WriteDictObjectField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 6629 } 6630} 6631 6632- (void)setGPBGenericValue:(GPBGenericValue *)value 6633 forGPBGenericValueKey:(GPBGenericValue *)key { 6634 [_dictionary setObject:value->valueString forKey:@(key->valueUInt64)]; 6635} 6636 6637- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 6638 [self enumerateKeysAndObjectsUsingBlock:^(uint64_t key, id object, BOOL *stop) { 6639 #pragma unused(stop) 6640 block([NSString stringWithFormat:@"%llu", key], object); 6641 }]; 6642} 6643 6644- (id)objectForKey:(uint64_t)key { 6645 id result = [_dictionary objectForKey:@(key)]; 6646 return result; 6647} 6648 6649- (void)addEntriesFromDictionary:(GPBUInt64ObjectDictionary *)otherDictionary { 6650 if (otherDictionary) { 6651 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 6652 if (_autocreator) { 6653 GPBAutocreatedDictionaryModified(_autocreator, self); 6654 } 6655 } 6656} 6657 6658- (void)setObject:(id)object forKey:(uint64_t)key { 6659 if (!object) { 6660 [NSException raise:NSInvalidArgumentException 6661 format:@"Attempting to add nil object to a Dictionary"]; 6662 } 6663 [_dictionary setObject:object forKey:@(key)]; 6664 if (_autocreator) { 6665 GPBAutocreatedDictionaryModified(_autocreator, self); 6666 } 6667} 6668 6669- (void)removeObjectForKey:(uint64_t)aKey { 6670 [_dictionary removeObjectForKey:@(aKey)]; 6671} 6672 6673- (void)removeAll { 6674 [_dictionary removeAllObjects]; 6675} 6676 6677@end 6678 6679// clang-format on 6680//%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(Int64, int64_t) 6681// This block of code is generated, do not edit it directly. 6682// clang-format off 6683 6684#pragma mark - Int64 -> UInt32 6685 6686@implementation GPBInt64UInt32Dictionary { 6687 @package 6688 NSMutableDictionary *_dictionary; 6689} 6690 6691- (instancetype)init { 6692 return [self initWithUInt32s:NULL forKeys:NULL count:0]; 6693} 6694 6695- (instancetype)initWithUInt32s:(const uint32_t [])values 6696 forKeys:(const int64_t [])keys 6697 count:(NSUInteger)count { 6698 self = [super init]; 6699 if (self) { 6700 _dictionary = [[NSMutableDictionary alloc] init]; 6701 if (count && values && keys) { 6702 for (NSUInteger i = 0; i < count; ++i) { 6703 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; 6704 } 6705 } 6706 } 6707 return self; 6708} 6709 6710- (instancetype)initWithDictionary:(GPBInt64UInt32Dictionary *)dictionary { 6711 self = [self initWithUInt32s:NULL forKeys:NULL count:0]; 6712 if (self) { 6713 if (dictionary) { 6714 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 6715 } 6716 } 6717 return self; 6718} 6719 6720- (instancetype)initWithCapacity:(NSUInteger)numItems { 6721 #pragma unused(numItems) 6722 return [self initWithUInt32s:NULL forKeys:NULL count:0]; 6723} 6724 6725- (void)dealloc { 6726 NSAssert(!_autocreator, 6727 @"%@: Autocreator must be cleared before release, autocreator: %@", 6728 [self class], _autocreator); 6729 [_dictionary release]; 6730 [super dealloc]; 6731} 6732 6733- (instancetype)copyWithZone:(NSZone *)zone { 6734 return [[GPBInt64UInt32Dictionary allocWithZone:zone] initWithDictionary:self]; 6735} 6736 6737- (BOOL)isEqual:(id)other { 6738 if (self == other) { 6739 return YES; 6740 } 6741 if (![other isKindOfClass:[GPBInt64UInt32Dictionary class]]) { 6742 return NO; 6743 } 6744 GPBInt64UInt32Dictionary *otherDictionary = other; 6745 return [_dictionary isEqual:otherDictionary->_dictionary]; 6746} 6747 6748- (NSUInteger)hash { 6749 return _dictionary.count; 6750} 6751 6752- (NSString *)description { 6753 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 6754} 6755 6756- (NSUInteger)count { 6757 return _dictionary.count; 6758} 6759 6760- (void)enumerateKeysAndUInt32sUsingBlock: 6761 (void (NS_NOESCAPE ^)(int64_t key, uint32_t value, BOOL *stop))block { 6762 BOOL stop = NO; 6763 NSDictionary *internal = _dictionary; 6764 NSEnumerator *keys = [internal keyEnumerator]; 6765 NSNumber *aKey; 6766 while ((aKey = [keys nextObject])) { 6767 NSNumber *aValue = internal[aKey]; 6768 block([aKey longLongValue], [aValue unsignedIntValue], &stop); 6769 if (stop) { 6770 break; 6771 } 6772 } 6773} 6774 6775- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 6776 NSDictionary *internal = _dictionary; 6777 NSUInteger count = internal.count; 6778 if (count == 0) { 6779 return 0; 6780 } 6781 6782 GPBDataType valueDataType = GPBGetFieldDataType(field); 6783 GPBDataType keyDataType = field.mapKeyDataType; 6784 size_t result = 0; 6785 NSEnumerator *keys = [internal keyEnumerator]; 6786 NSNumber *aKey; 6787 while ((aKey = [keys nextObject])) { 6788 NSNumber *aValue = internal[aKey]; 6789 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType); 6790 msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType); 6791 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 6792 } 6793 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 6794 result += tagSize * count; 6795 return result; 6796} 6797 6798- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 6799 asField:(GPBFieldDescriptor *)field { 6800 GPBDataType valueDataType = GPBGetFieldDataType(field); 6801 GPBDataType keyDataType = field.mapKeyDataType; 6802 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 6803 NSDictionary *internal = _dictionary; 6804 NSEnumerator *keys = [internal keyEnumerator]; 6805 NSNumber *aKey; 6806 while ((aKey = [keys nextObject])) { 6807 NSNumber *aValue = internal[aKey]; 6808 [outputStream writeInt32NoTag:tag]; 6809 // Write the size of the message. 6810 int64_t unwrappedKey = [aKey longLongValue]; 6811 uint32_t unwrappedValue = [aValue unsignedIntValue]; 6812 size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 6813 msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 6814 [outputStream writeInt32NoTag:(int32_t)msgSize]; 6815 // Write the fields. 6816 WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 6817 WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 6818 } 6819} 6820 6821- (void)setGPBGenericValue:(GPBGenericValue *)value 6822 forGPBGenericValueKey:(GPBGenericValue *)key { 6823 [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueInt64)]; 6824} 6825 6826- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 6827 [self enumerateKeysAndUInt32sUsingBlock:^(int64_t key, uint32_t value, BOOL *stop) { 6828 #pragma unused(stop) 6829 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%u", value]); 6830 }]; 6831} 6832 6833- (BOOL)getUInt32:(nullable uint32_t *)value forKey:(int64_t)key { 6834 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; 6835 if (wrapped && value) { 6836 *value = [wrapped unsignedIntValue]; 6837 } 6838 return (wrapped != NULL); 6839} 6840 6841- (void)addEntriesFromDictionary:(GPBInt64UInt32Dictionary *)otherDictionary { 6842 if (otherDictionary) { 6843 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 6844 if (_autocreator) { 6845 GPBAutocreatedDictionaryModified(_autocreator, self); 6846 } 6847 } 6848} 6849 6850- (void)setUInt32:(uint32_t)value forKey:(int64_t)key { 6851 [_dictionary setObject:@(value) forKey:@(key)]; 6852 if (_autocreator) { 6853 GPBAutocreatedDictionaryModified(_autocreator, self); 6854 } 6855} 6856 6857- (void)removeUInt32ForKey:(int64_t)aKey { 6858 [_dictionary removeObjectForKey:@(aKey)]; 6859} 6860 6861- (void)removeAll { 6862 [_dictionary removeAllObjects]; 6863} 6864 6865@end 6866 6867#pragma mark - Int64 -> Int32 6868 6869@implementation GPBInt64Int32Dictionary { 6870 @package 6871 NSMutableDictionary *_dictionary; 6872} 6873 6874- (instancetype)init { 6875 return [self initWithInt32s:NULL forKeys:NULL count:0]; 6876} 6877 6878- (instancetype)initWithInt32s:(const int32_t [])values 6879 forKeys:(const int64_t [])keys 6880 count:(NSUInteger)count { 6881 self = [super init]; 6882 if (self) { 6883 _dictionary = [[NSMutableDictionary alloc] init]; 6884 if (count && values && keys) { 6885 for (NSUInteger i = 0; i < count; ++i) { 6886 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; 6887 } 6888 } 6889 } 6890 return self; 6891} 6892 6893- (instancetype)initWithDictionary:(GPBInt64Int32Dictionary *)dictionary { 6894 self = [self initWithInt32s:NULL forKeys:NULL count:0]; 6895 if (self) { 6896 if (dictionary) { 6897 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 6898 } 6899 } 6900 return self; 6901} 6902 6903- (instancetype)initWithCapacity:(NSUInteger)numItems { 6904 #pragma unused(numItems) 6905 return [self initWithInt32s:NULL forKeys:NULL count:0]; 6906} 6907 6908- (void)dealloc { 6909 NSAssert(!_autocreator, 6910 @"%@: Autocreator must be cleared before release, autocreator: %@", 6911 [self class], _autocreator); 6912 [_dictionary release]; 6913 [super dealloc]; 6914} 6915 6916- (instancetype)copyWithZone:(NSZone *)zone { 6917 return [[GPBInt64Int32Dictionary allocWithZone:zone] initWithDictionary:self]; 6918} 6919 6920- (BOOL)isEqual:(id)other { 6921 if (self == other) { 6922 return YES; 6923 } 6924 if (![other isKindOfClass:[GPBInt64Int32Dictionary class]]) { 6925 return NO; 6926 } 6927 GPBInt64Int32Dictionary *otherDictionary = other; 6928 return [_dictionary isEqual:otherDictionary->_dictionary]; 6929} 6930 6931- (NSUInteger)hash { 6932 return _dictionary.count; 6933} 6934 6935- (NSString *)description { 6936 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 6937} 6938 6939- (NSUInteger)count { 6940 return _dictionary.count; 6941} 6942 6943- (void)enumerateKeysAndInt32sUsingBlock: 6944 (void (NS_NOESCAPE ^)(int64_t key, int32_t value, BOOL *stop))block { 6945 BOOL stop = NO; 6946 NSDictionary *internal = _dictionary; 6947 NSEnumerator *keys = [internal keyEnumerator]; 6948 NSNumber *aKey; 6949 while ((aKey = [keys nextObject])) { 6950 NSNumber *aValue = internal[aKey]; 6951 block([aKey longLongValue], [aValue intValue], &stop); 6952 if (stop) { 6953 break; 6954 } 6955 } 6956} 6957 6958- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 6959 NSDictionary *internal = _dictionary; 6960 NSUInteger count = internal.count; 6961 if (count == 0) { 6962 return 0; 6963 } 6964 6965 GPBDataType valueDataType = GPBGetFieldDataType(field); 6966 GPBDataType keyDataType = field.mapKeyDataType; 6967 size_t result = 0; 6968 NSEnumerator *keys = [internal keyEnumerator]; 6969 NSNumber *aKey; 6970 while ((aKey = [keys nextObject])) { 6971 NSNumber *aValue = internal[aKey]; 6972 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType); 6973 msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType); 6974 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 6975 } 6976 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 6977 result += tagSize * count; 6978 return result; 6979} 6980 6981- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 6982 asField:(GPBFieldDescriptor *)field { 6983 GPBDataType valueDataType = GPBGetFieldDataType(field); 6984 GPBDataType keyDataType = field.mapKeyDataType; 6985 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 6986 NSDictionary *internal = _dictionary; 6987 NSEnumerator *keys = [internal keyEnumerator]; 6988 NSNumber *aKey; 6989 while ((aKey = [keys nextObject])) { 6990 NSNumber *aValue = internal[aKey]; 6991 [outputStream writeInt32NoTag:tag]; 6992 // Write the size of the message. 6993 int64_t unwrappedKey = [aKey longLongValue]; 6994 int32_t unwrappedValue = [aValue intValue]; 6995 size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 6996 msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 6997 [outputStream writeInt32NoTag:(int32_t)msgSize]; 6998 // Write the fields. 6999 WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 7000 WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 7001 } 7002} 7003 7004- (void)setGPBGenericValue:(GPBGenericValue *)value 7005 forGPBGenericValueKey:(GPBGenericValue *)key { 7006 [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueInt64)]; 7007} 7008 7009- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 7010 [self enumerateKeysAndInt32sUsingBlock:^(int64_t key, int32_t value, BOOL *stop) { 7011 #pragma unused(stop) 7012 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%d", value]); 7013 }]; 7014} 7015 7016- (BOOL)getInt32:(nullable int32_t *)value forKey:(int64_t)key { 7017 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; 7018 if (wrapped && value) { 7019 *value = [wrapped intValue]; 7020 } 7021 return (wrapped != NULL); 7022} 7023 7024- (void)addEntriesFromDictionary:(GPBInt64Int32Dictionary *)otherDictionary { 7025 if (otherDictionary) { 7026 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 7027 if (_autocreator) { 7028 GPBAutocreatedDictionaryModified(_autocreator, self); 7029 } 7030 } 7031} 7032 7033- (void)setInt32:(int32_t)value forKey:(int64_t)key { 7034 [_dictionary setObject:@(value) forKey:@(key)]; 7035 if (_autocreator) { 7036 GPBAutocreatedDictionaryModified(_autocreator, self); 7037 } 7038} 7039 7040- (void)removeInt32ForKey:(int64_t)aKey { 7041 [_dictionary removeObjectForKey:@(aKey)]; 7042} 7043 7044- (void)removeAll { 7045 [_dictionary removeAllObjects]; 7046} 7047 7048@end 7049 7050#pragma mark - Int64 -> UInt64 7051 7052@implementation GPBInt64UInt64Dictionary { 7053 @package 7054 NSMutableDictionary *_dictionary; 7055} 7056 7057- (instancetype)init { 7058 return [self initWithUInt64s:NULL forKeys:NULL count:0]; 7059} 7060 7061- (instancetype)initWithUInt64s:(const uint64_t [])values 7062 forKeys:(const int64_t [])keys 7063 count:(NSUInteger)count { 7064 self = [super init]; 7065 if (self) { 7066 _dictionary = [[NSMutableDictionary alloc] init]; 7067 if (count && values && keys) { 7068 for (NSUInteger i = 0; i < count; ++i) { 7069 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; 7070 } 7071 } 7072 } 7073 return self; 7074} 7075 7076- (instancetype)initWithDictionary:(GPBInt64UInt64Dictionary *)dictionary { 7077 self = [self initWithUInt64s:NULL forKeys:NULL count:0]; 7078 if (self) { 7079 if (dictionary) { 7080 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 7081 } 7082 } 7083 return self; 7084} 7085 7086- (instancetype)initWithCapacity:(NSUInteger)numItems { 7087 #pragma unused(numItems) 7088 return [self initWithUInt64s:NULL forKeys:NULL count:0]; 7089} 7090 7091- (void)dealloc { 7092 NSAssert(!_autocreator, 7093 @"%@: Autocreator must be cleared before release, autocreator: %@", 7094 [self class], _autocreator); 7095 [_dictionary release]; 7096 [super dealloc]; 7097} 7098 7099- (instancetype)copyWithZone:(NSZone *)zone { 7100 return [[GPBInt64UInt64Dictionary allocWithZone:zone] initWithDictionary:self]; 7101} 7102 7103- (BOOL)isEqual:(id)other { 7104 if (self == other) { 7105 return YES; 7106 } 7107 if (![other isKindOfClass:[GPBInt64UInt64Dictionary class]]) { 7108 return NO; 7109 } 7110 GPBInt64UInt64Dictionary *otherDictionary = other; 7111 return [_dictionary isEqual:otherDictionary->_dictionary]; 7112} 7113 7114- (NSUInteger)hash { 7115 return _dictionary.count; 7116} 7117 7118- (NSString *)description { 7119 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 7120} 7121 7122- (NSUInteger)count { 7123 return _dictionary.count; 7124} 7125 7126- (void)enumerateKeysAndUInt64sUsingBlock: 7127 (void (NS_NOESCAPE ^)(int64_t key, uint64_t value, BOOL *stop))block { 7128 BOOL stop = NO; 7129 NSDictionary *internal = _dictionary; 7130 NSEnumerator *keys = [internal keyEnumerator]; 7131 NSNumber *aKey; 7132 while ((aKey = [keys nextObject])) { 7133 NSNumber *aValue = internal[aKey]; 7134 block([aKey longLongValue], [aValue unsignedLongLongValue], &stop); 7135 if (stop) { 7136 break; 7137 } 7138 } 7139} 7140 7141- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 7142 NSDictionary *internal = _dictionary; 7143 NSUInteger count = internal.count; 7144 if (count == 0) { 7145 return 0; 7146 } 7147 7148 GPBDataType valueDataType = GPBGetFieldDataType(field); 7149 GPBDataType keyDataType = field.mapKeyDataType; 7150 size_t result = 0; 7151 NSEnumerator *keys = [internal keyEnumerator]; 7152 NSNumber *aKey; 7153 while ((aKey = [keys nextObject])) { 7154 NSNumber *aValue = internal[aKey]; 7155 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType); 7156 msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType); 7157 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 7158 } 7159 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 7160 result += tagSize * count; 7161 return result; 7162} 7163 7164- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 7165 asField:(GPBFieldDescriptor *)field { 7166 GPBDataType valueDataType = GPBGetFieldDataType(field); 7167 GPBDataType keyDataType = field.mapKeyDataType; 7168 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 7169 NSDictionary *internal = _dictionary; 7170 NSEnumerator *keys = [internal keyEnumerator]; 7171 NSNumber *aKey; 7172 while ((aKey = [keys nextObject])) { 7173 NSNumber *aValue = internal[aKey]; 7174 [outputStream writeInt32NoTag:tag]; 7175 // Write the size of the message. 7176 int64_t unwrappedKey = [aKey longLongValue]; 7177 uint64_t unwrappedValue = [aValue unsignedLongLongValue]; 7178 size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 7179 msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 7180 [outputStream writeInt32NoTag:(int32_t)msgSize]; 7181 // Write the fields. 7182 WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 7183 WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 7184 } 7185} 7186 7187- (void)setGPBGenericValue:(GPBGenericValue *)value 7188 forGPBGenericValueKey:(GPBGenericValue *)key { 7189 [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueInt64)]; 7190} 7191 7192- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 7193 [self enumerateKeysAndUInt64sUsingBlock:^(int64_t key, uint64_t value, BOOL *stop) { 7194 #pragma unused(stop) 7195 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%llu", value]); 7196 }]; 7197} 7198 7199- (BOOL)getUInt64:(nullable uint64_t *)value forKey:(int64_t)key { 7200 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; 7201 if (wrapped && value) { 7202 *value = [wrapped unsignedLongLongValue]; 7203 } 7204 return (wrapped != NULL); 7205} 7206 7207- (void)addEntriesFromDictionary:(GPBInt64UInt64Dictionary *)otherDictionary { 7208 if (otherDictionary) { 7209 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 7210 if (_autocreator) { 7211 GPBAutocreatedDictionaryModified(_autocreator, self); 7212 } 7213 } 7214} 7215 7216- (void)setUInt64:(uint64_t)value forKey:(int64_t)key { 7217 [_dictionary setObject:@(value) forKey:@(key)]; 7218 if (_autocreator) { 7219 GPBAutocreatedDictionaryModified(_autocreator, self); 7220 } 7221} 7222 7223- (void)removeUInt64ForKey:(int64_t)aKey { 7224 [_dictionary removeObjectForKey:@(aKey)]; 7225} 7226 7227- (void)removeAll { 7228 [_dictionary removeAllObjects]; 7229} 7230 7231@end 7232 7233#pragma mark - Int64 -> Int64 7234 7235@implementation GPBInt64Int64Dictionary { 7236 @package 7237 NSMutableDictionary *_dictionary; 7238} 7239 7240- (instancetype)init { 7241 return [self initWithInt64s:NULL forKeys:NULL count:0]; 7242} 7243 7244- (instancetype)initWithInt64s:(const int64_t [])values 7245 forKeys:(const int64_t [])keys 7246 count:(NSUInteger)count { 7247 self = [super init]; 7248 if (self) { 7249 _dictionary = [[NSMutableDictionary alloc] init]; 7250 if (count && values && keys) { 7251 for (NSUInteger i = 0; i < count; ++i) { 7252 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; 7253 } 7254 } 7255 } 7256 return self; 7257} 7258 7259- (instancetype)initWithDictionary:(GPBInt64Int64Dictionary *)dictionary { 7260 self = [self initWithInt64s:NULL forKeys:NULL count:0]; 7261 if (self) { 7262 if (dictionary) { 7263 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 7264 } 7265 } 7266 return self; 7267} 7268 7269- (instancetype)initWithCapacity:(NSUInteger)numItems { 7270 #pragma unused(numItems) 7271 return [self initWithInt64s:NULL forKeys:NULL count:0]; 7272} 7273 7274- (void)dealloc { 7275 NSAssert(!_autocreator, 7276 @"%@: Autocreator must be cleared before release, autocreator: %@", 7277 [self class], _autocreator); 7278 [_dictionary release]; 7279 [super dealloc]; 7280} 7281 7282- (instancetype)copyWithZone:(NSZone *)zone { 7283 return [[GPBInt64Int64Dictionary allocWithZone:zone] initWithDictionary:self]; 7284} 7285 7286- (BOOL)isEqual:(id)other { 7287 if (self == other) { 7288 return YES; 7289 } 7290 if (![other isKindOfClass:[GPBInt64Int64Dictionary class]]) { 7291 return NO; 7292 } 7293 GPBInt64Int64Dictionary *otherDictionary = other; 7294 return [_dictionary isEqual:otherDictionary->_dictionary]; 7295} 7296 7297- (NSUInteger)hash { 7298 return _dictionary.count; 7299} 7300 7301- (NSString *)description { 7302 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 7303} 7304 7305- (NSUInteger)count { 7306 return _dictionary.count; 7307} 7308 7309- (void)enumerateKeysAndInt64sUsingBlock: 7310 (void (NS_NOESCAPE ^)(int64_t key, int64_t value, BOOL *stop))block { 7311 BOOL stop = NO; 7312 NSDictionary *internal = _dictionary; 7313 NSEnumerator *keys = [internal keyEnumerator]; 7314 NSNumber *aKey; 7315 while ((aKey = [keys nextObject])) { 7316 NSNumber *aValue = internal[aKey]; 7317 block([aKey longLongValue], [aValue longLongValue], &stop); 7318 if (stop) { 7319 break; 7320 } 7321 } 7322} 7323 7324- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 7325 NSDictionary *internal = _dictionary; 7326 NSUInteger count = internal.count; 7327 if (count == 0) { 7328 return 0; 7329 } 7330 7331 GPBDataType valueDataType = GPBGetFieldDataType(field); 7332 GPBDataType keyDataType = field.mapKeyDataType; 7333 size_t result = 0; 7334 NSEnumerator *keys = [internal keyEnumerator]; 7335 NSNumber *aKey; 7336 while ((aKey = [keys nextObject])) { 7337 NSNumber *aValue = internal[aKey]; 7338 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType); 7339 msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType); 7340 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 7341 } 7342 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 7343 result += tagSize * count; 7344 return result; 7345} 7346 7347- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 7348 asField:(GPBFieldDescriptor *)field { 7349 GPBDataType valueDataType = GPBGetFieldDataType(field); 7350 GPBDataType keyDataType = field.mapKeyDataType; 7351 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 7352 NSDictionary *internal = _dictionary; 7353 NSEnumerator *keys = [internal keyEnumerator]; 7354 NSNumber *aKey; 7355 while ((aKey = [keys nextObject])) { 7356 NSNumber *aValue = internal[aKey]; 7357 [outputStream writeInt32NoTag:tag]; 7358 // Write the size of the message. 7359 int64_t unwrappedKey = [aKey longLongValue]; 7360 int64_t unwrappedValue = [aValue longLongValue]; 7361 size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 7362 msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 7363 [outputStream writeInt32NoTag:(int32_t)msgSize]; 7364 // Write the fields. 7365 WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 7366 WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 7367 } 7368} 7369 7370- (void)setGPBGenericValue:(GPBGenericValue *)value 7371 forGPBGenericValueKey:(GPBGenericValue *)key { 7372 [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueInt64)]; 7373} 7374 7375- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 7376 [self enumerateKeysAndInt64sUsingBlock:^(int64_t key, int64_t value, BOOL *stop) { 7377 #pragma unused(stop) 7378 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%lld", value]); 7379 }]; 7380} 7381 7382- (BOOL)getInt64:(nullable int64_t *)value forKey:(int64_t)key { 7383 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; 7384 if (wrapped && value) { 7385 *value = [wrapped longLongValue]; 7386 } 7387 return (wrapped != NULL); 7388} 7389 7390- (void)addEntriesFromDictionary:(GPBInt64Int64Dictionary *)otherDictionary { 7391 if (otherDictionary) { 7392 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 7393 if (_autocreator) { 7394 GPBAutocreatedDictionaryModified(_autocreator, self); 7395 } 7396 } 7397} 7398 7399- (void)setInt64:(int64_t)value forKey:(int64_t)key { 7400 [_dictionary setObject:@(value) forKey:@(key)]; 7401 if (_autocreator) { 7402 GPBAutocreatedDictionaryModified(_autocreator, self); 7403 } 7404} 7405 7406- (void)removeInt64ForKey:(int64_t)aKey { 7407 [_dictionary removeObjectForKey:@(aKey)]; 7408} 7409 7410- (void)removeAll { 7411 [_dictionary removeAllObjects]; 7412} 7413 7414@end 7415 7416#pragma mark - Int64 -> Bool 7417 7418@implementation GPBInt64BoolDictionary { 7419 @package 7420 NSMutableDictionary *_dictionary; 7421} 7422 7423- (instancetype)init { 7424 return [self initWithBools:NULL forKeys:NULL count:0]; 7425} 7426 7427- (instancetype)initWithBools:(const BOOL [])values 7428 forKeys:(const int64_t [])keys 7429 count:(NSUInteger)count { 7430 self = [super init]; 7431 if (self) { 7432 _dictionary = [[NSMutableDictionary alloc] init]; 7433 if (count && values && keys) { 7434 for (NSUInteger i = 0; i < count; ++i) { 7435 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; 7436 } 7437 } 7438 } 7439 return self; 7440} 7441 7442- (instancetype)initWithDictionary:(GPBInt64BoolDictionary *)dictionary { 7443 self = [self initWithBools:NULL forKeys:NULL count:0]; 7444 if (self) { 7445 if (dictionary) { 7446 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 7447 } 7448 } 7449 return self; 7450} 7451 7452- (instancetype)initWithCapacity:(NSUInteger)numItems { 7453 #pragma unused(numItems) 7454 return [self initWithBools:NULL forKeys:NULL count:0]; 7455} 7456 7457- (void)dealloc { 7458 NSAssert(!_autocreator, 7459 @"%@: Autocreator must be cleared before release, autocreator: %@", 7460 [self class], _autocreator); 7461 [_dictionary release]; 7462 [super dealloc]; 7463} 7464 7465- (instancetype)copyWithZone:(NSZone *)zone { 7466 return [[GPBInt64BoolDictionary allocWithZone:zone] initWithDictionary:self]; 7467} 7468 7469- (BOOL)isEqual:(id)other { 7470 if (self == other) { 7471 return YES; 7472 } 7473 if (![other isKindOfClass:[GPBInt64BoolDictionary class]]) { 7474 return NO; 7475 } 7476 GPBInt64BoolDictionary *otherDictionary = other; 7477 return [_dictionary isEqual:otherDictionary->_dictionary]; 7478} 7479 7480- (NSUInteger)hash { 7481 return _dictionary.count; 7482} 7483 7484- (NSString *)description { 7485 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 7486} 7487 7488- (NSUInteger)count { 7489 return _dictionary.count; 7490} 7491 7492- (void)enumerateKeysAndBoolsUsingBlock: 7493 (void (NS_NOESCAPE ^)(int64_t key, BOOL value, BOOL *stop))block { 7494 BOOL stop = NO; 7495 NSDictionary *internal = _dictionary; 7496 NSEnumerator *keys = [internal keyEnumerator]; 7497 NSNumber *aKey; 7498 while ((aKey = [keys nextObject])) { 7499 NSNumber *aValue = internal[aKey]; 7500 block([aKey longLongValue], [aValue boolValue], &stop); 7501 if (stop) { 7502 break; 7503 } 7504 } 7505} 7506 7507- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 7508 NSDictionary *internal = _dictionary; 7509 NSUInteger count = internal.count; 7510 if (count == 0) { 7511 return 0; 7512 } 7513 7514 GPBDataType valueDataType = GPBGetFieldDataType(field); 7515 GPBDataType keyDataType = field.mapKeyDataType; 7516 size_t result = 0; 7517 NSEnumerator *keys = [internal keyEnumerator]; 7518 NSNumber *aKey; 7519 while ((aKey = [keys nextObject])) { 7520 NSNumber *aValue = internal[aKey]; 7521 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType); 7522 msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType); 7523 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 7524 } 7525 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 7526 result += tagSize * count; 7527 return result; 7528} 7529 7530- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 7531 asField:(GPBFieldDescriptor *)field { 7532 GPBDataType valueDataType = GPBGetFieldDataType(field); 7533 GPBDataType keyDataType = field.mapKeyDataType; 7534 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 7535 NSDictionary *internal = _dictionary; 7536 NSEnumerator *keys = [internal keyEnumerator]; 7537 NSNumber *aKey; 7538 while ((aKey = [keys nextObject])) { 7539 NSNumber *aValue = internal[aKey]; 7540 [outputStream writeInt32NoTag:tag]; 7541 // Write the size of the message. 7542 int64_t unwrappedKey = [aKey longLongValue]; 7543 BOOL unwrappedValue = [aValue boolValue]; 7544 size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 7545 msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 7546 [outputStream writeInt32NoTag:(int32_t)msgSize]; 7547 // Write the fields. 7548 WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 7549 WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 7550 } 7551} 7552 7553- (void)setGPBGenericValue:(GPBGenericValue *)value 7554 forGPBGenericValueKey:(GPBGenericValue *)key { 7555 [_dictionary setObject:@(value->valueBool) forKey:@(key->valueInt64)]; 7556} 7557 7558- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 7559 [self enumerateKeysAndBoolsUsingBlock:^(int64_t key, BOOL value, BOOL *stop) { 7560 #pragma unused(stop) 7561 block([NSString stringWithFormat:@"%lld", key], (value ? @"true" : @"false")); 7562 }]; 7563} 7564 7565- (BOOL)getBool:(nullable BOOL *)value forKey:(int64_t)key { 7566 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; 7567 if (wrapped && value) { 7568 *value = [wrapped boolValue]; 7569 } 7570 return (wrapped != NULL); 7571} 7572 7573- (void)addEntriesFromDictionary:(GPBInt64BoolDictionary *)otherDictionary { 7574 if (otherDictionary) { 7575 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 7576 if (_autocreator) { 7577 GPBAutocreatedDictionaryModified(_autocreator, self); 7578 } 7579 } 7580} 7581 7582- (void)setBool:(BOOL)value forKey:(int64_t)key { 7583 [_dictionary setObject:@(value) forKey:@(key)]; 7584 if (_autocreator) { 7585 GPBAutocreatedDictionaryModified(_autocreator, self); 7586 } 7587} 7588 7589- (void)removeBoolForKey:(int64_t)aKey { 7590 [_dictionary removeObjectForKey:@(aKey)]; 7591} 7592 7593- (void)removeAll { 7594 [_dictionary removeAllObjects]; 7595} 7596 7597@end 7598 7599#pragma mark - Int64 -> Float 7600 7601@implementation GPBInt64FloatDictionary { 7602 @package 7603 NSMutableDictionary *_dictionary; 7604} 7605 7606- (instancetype)init { 7607 return [self initWithFloats:NULL forKeys:NULL count:0]; 7608} 7609 7610- (instancetype)initWithFloats:(const float [])values 7611 forKeys:(const int64_t [])keys 7612 count:(NSUInteger)count { 7613 self = [super init]; 7614 if (self) { 7615 _dictionary = [[NSMutableDictionary alloc] init]; 7616 if (count && values && keys) { 7617 for (NSUInteger i = 0; i < count; ++i) { 7618 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; 7619 } 7620 } 7621 } 7622 return self; 7623} 7624 7625- (instancetype)initWithDictionary:(GPBInt64FloatDictionary *)dictionary { 7626 self = [self initWithFloats:NULL forKeys:NULL count:0]; 7627 if (self) { 7628 if (dictionary) { 7629 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 7630 } 7631 } 7632 return self; 7633} 7634 7635- (instancetype)initWithCapacity:(NSUInteger)numItems { 7636 #pragma unused(numItems) 7637 return [self initWithFloats:NULL forKeys:NULL count:0]; 7638} 7639 7640- (void)dealloc { 7641 NSAssert(!_autocreator, 7642 @"%@: Autocreator must be cleared before release, autocreator: %@", 7643 [self class], _autocreator); 7644 [_dictionary release]; 7645 [super dealloc]; 7646} 7647 7648- (instancetype)copyWithZone:(NSZone *)zone { 7649 return [[GPBInt64FloatDictionary allocWithZone:zone] initWithDictionary:self]; 7650} 7651 7652- (BOOL)isEqual:(id)other { 7653 if (self == other) { 7654 return YES; 7655 } 7656 if (![other isKindOfClass:[GPBInt64FloatDictionary class]]) { 7657 return NO; 7658 } 7659 GPBInt64FloatDictionary *otherDictionary = other; 7660 return [_dictionary isEqual:otherDictionary->_dictionary]; 7661} 7662 7663- (NSUInteger)hash { 7664 return _dictionary.count; 7665} 7666 7667- (NSString *)description { 7668 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 7669} 7670 7671- (NSUInteger)count { 7672 return _dictionary.count; 7673} 7674 7675- (void)enumerateKeysAndFloatsUsingBlock: 7676 (void (NS_NOESCAPE ^)(int64_t key, float value, BOOL *stop))block { 7677 BOOL stop = NO; 7678 NSDictionary *internal = _dictionary; 7679 NSEnumerator *keys = [internal keyEnumerator]; 7680 NSNumber *aKey; 7681 while ((aKey = [keys nextObject])) { 7682 NSNumber *aValue = internal[aKey]; 7683 block([aKey longLongValue], [aValue floatValue], &stop); 7684 if (stop) { 7685 break; 7686 } 7687 } 7688} 7689 7690- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 7691 NSDictionary *internal = _dictionary; 7692 NSUInteger count = internal.count; 7693 if (count == 0) { 7694 return 0; 7695 } 7696 7697 GPBDataType valueDataType = GPBGetFieldDataType(field); 7698 GPBDataType keyDataType = field.mapKeyDataType; 7699 size_t result = 0; 7700 NSEnumerator *keys = [internal keyEnumerator]; 7701 NSNumber *aKey; 7702 while ((aKey = [keys nextObject])) { 7703 NSNumber *aValue = internal[aKey]; 7704 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType); 7705 msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType); 7706 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 7707 } 7708 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 7709 result += tagSize * count; 7710 return result; 7711} 7712 7713- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 7714 asField:(GPBFieldDescriptor *)field { 7715 GPBDataType valueDataType = GPBGetFieldDataType(field); 7716 GPBDataType keyDataType = field.mapKeyDataType; 7717 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 7718 NSDictionary *internal = _dictionary; 7719 NSEnumerator *keys = [internal keyEnumerator]; 7720 NSNumber *aKey; 7721 while ((aKey = [keys nextObject])) { 7722 NSNumber *aValue = internal[aKey]; 7723 [outputStream writeInt32NoTag:tag]; 7724 // Write the size of the message. 7725 int64_t unwrappedKey = [aKey longLongValue]; 7726 float unwrappedValue = [aValue floatValue]; 7727 size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 7728 msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 7729 [outputStream writeInt32NoTag:(int32_t)msgSize]; 7730 // Write the fields. 7731 WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 7732 WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 7733 } 7734} 7735 7736- (void)setGPBGenericValue:(GPBGenericValue *)value 7737 forGPBGenericValueKey:(GPBGenericValue *)key { 7738 [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueInt64)]; 7739} 7740 7741- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 7742 [self enumerateKeysAndFloatsUsingBlock:^(int64_t key, float value, BOOL *stop) { 7743 #pragma unused(stop) 7744 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]); 7745 }]; 7746} 7747 7748- (BOOL)getFloat:(nullable float *)value forKey:(int64_t)key { 7749 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; 7750 if (wrapped && value) { 7751 *value = [wrapped floatValue]; 7752 } 7753 return (wrapped != NULL); 7754} 7755 7756- (void)addEntriesFromDictionary:(GPBInt64FloatDictionary *)otherDictionary { 7757 if (otherDictionary) { 7758 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 7759 if (_autocreator) { 7760 GPBAutocreatedDictionaryModified(_autocreator, self); 7761 } 7762 } 7763} 7764 7765- (void)setFloat:(float)value forKey:(int64_t)key { 7766 [_dictionary setObject:@(value) forKey:@(key)]; 7767 if (_autocreator) { 7768 GPBAutocreatedDictionaryModified(_autocreator, self); 7769 } 7770} 7771 7772- (void)removeFloatForKey:(int64_t)aKey { 7773 [_dictionary removeObjectForKey:@(aKey)]; 7774} 7775 7776- (void)removeAll { 7777 [_dictionary removeAllObjects]; 7778} 7779 7780@end 7781 7782#pragma mark - Int64 -> Double 7783 7784@implementation GPBInt64DoubleDictionary { 7785 @package 7786 NSMutableDictionary *_dictionary; 7787} 7788 7789- (instancetype)init { 7790 return [self initWithDoubles:NULL forKeys:NULL count:0]; 7791} 7792 7793- (instancetype)initWithDoubles:(const double [])values 7794 forKeys:(const int64_t [])keys 7795 count:(NSUInteger)count { 7796 self = [super init]; 7797 if (self) { 7798 _dictionary = [[NSMutableDictionary alloc] init]; 7799 if (count && values && keys) { 7800 for (NSUInteger i = 0; i < count; ++i) { 7801 [_dictionary setObject:@(values[i]) forKey:@(keys[i])]; 7802 } 7803 } 7804 } 7805 return self; 7806} 7807 7808- (instancetype)initWithDictionary:(GPBInt64DoubleDictionary *)dictionary { 7809 self = [self initWithDoubles:NULL forKeys:NULL count:0]; 7810 if (self) { 7811 if (dictionary) { 7812 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 7813 } 7814 } 7815 return self; 7816} 7817 7818- (instancetype)initWithCapacity:(NSUInteger)numItems { 7819 #pragma unused(numItems) 7820 return [self initWithDoubles:NULL forKeys:NULL count:0]; 7821} 7822 7823- (void)dealloc { 7824 NSAssert(!_autocreator, 7825 @"%@: Autocreator must be cleared before release, autocreator: %@", 7826 [self class], _autocreator); 7827 [_dictionary release]; 7828 [super dealloc]; 7829} 7830 7831- (instancetype)copyWithZone:(NSZone *)zone { 7832 return [[GPBInt64DoubleDictionary allocWithZone:zone] initWithDictionary:self]; 7833} 7834 7835- (BOOL)isEqual:(id)other { 7836 if (self == other) { 7837 return YES; 7838 } 7839 if (![other isKindOfClass:[GPBInt64DoubleDictionary class]]) { 7840 return NO; 7841 } 7842 GPBInt64DoubleDictionary *otherDictionary = other; 7843 return [_dictionary isEqual:otherDictionary->_dictionary]; 7844} 7845 7846- (NSUInteger)hash { 7847 return _dictionary.count; 7848} 7849 7850- (NSString *)description { 7851 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 7852} 7853 7854- (NSUInteger)count { 7855 return _dictionary.count; 7856} 7857 7858- (void)enumerateKeysAndDoublesUsingBlock: 7859 (void (NS_NOESCAPE ^)(int64_t key, double value, BOOL *stop))block { 7860 BOOL stop = NO; 7861 NSDictionary *internal = _dictionary; 7862 NSEnumerator *keys = [internal keyEnumerator]; 7863 NSNumber *aKey; 7864 while ((aKey = [keys nextObject])) { 7865 NSNumber *aValue = internal[aKey]; 7866 block([aKey longLongValue], [aValue doubleValue], &stop); 7867 if (stop) { 7868 break; 7869 } 7870 } 7871} 7872 7873- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 7874 NSDictionary *internal = _dictionary; 7875 NSUInteger count = internal.count; 7876 if (count == 0) { 7877 return 0; 7878 } 7879 7880 GPBDataType valueDataType = GPBGetFieldDataType(field); 7881 GPBDataType keyDataType = field.mapKeyDataType; 7882 size_t result = 0; 7883 NSEnumerator *keys = [internal keyEnumerator]; 7884 NSNumber *aKey; 7885 while ((aKey = [keys nextObject])) { 7886 NSNumber *aValue = internal[aKey]; 7887 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType); 7888 msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType); 7889 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 7890 } 7891 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 7892 result += tagSize * count; 7893 return result; 7894} 7895 7896- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 7897 asField:(GPBFieldDescriptor *)field { 7898 GPBDataType valueDataType = GPBGetFieldDataType(field); 7899 GPBDataType keyDataType = field.mapKeyDataType; 7900 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 7901 NSDictionary *internal = _dictionary; 7902 NSEnumerator *keys = [internal keyEnumerator]; 7903 NSNumber *aKey; 7904 while ((aKey = [keys nextObject])) { 7905 NSNumber *aValue = internal[aKey]; 7906 [outputStream writeInt32NoTag:tag]; 7907 // Write the size of the message. 7908 int64_t unwrappedKey = [aKey longLongValue]; 7909 double unwrappedValue = [aValue doubleValue]; 7910 size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 7911 msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 7912 [outputStream writeInt32NoTag:(int32_t)msgSize]; 7913 // Write the fields. 7914 WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 7915 WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 7916 } 7917} 7918 7919- (void)setGPBGenericValue:(GPBGenericValue *)value 7920 forGPBGenericValueKey:(GPBGenericValue *)key { 7921 [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueInt64)]; 7922} 7923 7924- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 7925 [self enumerateKeysAndDoublesUsingBlock:^(int64_t key, double value, BOOL *stop) { 7926 #pragma unused(stop) 7927 block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]); 7928 }]; 7929} 7930 7931- (BOOL)getDouble:(nullable double *)value forKey:(int64_t)key { 7932 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; 7933 if (wrapped && value) { 7934 *value = [wrapped doubleValue]; 7935 } 7936 return (wrapped != NULL); 7937} 7938 7939- (void)addEntriesFromDictionary:(GPBInt64DoubleDictionary *)otherDictionary { 7940 if (otherDictionary) { 7941 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 7942 if (_autocreator) { 7943 GPBAutocreatedDictionaryModified(_autocreator, self); 7944 } 7945 } 7946} 7947 7948- (void)setDouble:(double)value forKey:(int64_t)key { 7949 [_dictionary setObject:@(value) forKey:@(key)]; 7950 if (_autocreator) { 7951 GPBAutocreatedDictionaryModified(_autocreator, self); 7952 } 7953} 7954 7955- (void)removeDoubleForKey:(int64_t)aKey { 7956 [_dictionary removeObjectForKey:@(aKey)]; 7957} 7958 7959- (void)removeAll { 7960 [_dictionary removeAllObjects]; 7961} 7962 7963@end 7964 7965#pragma mark - Int64 -> Enum 7966 7967@implementation GPBInt64EnumDictionary { 7968 @package 7969 NSMutableDictionary *_dictionary; 7970 GPBEnumValidationFunc _validationFunc; 7971} 7972 7973@synthesize validationFunc = _validationFunc; 7974 7975- (instancetype)init { 7976 return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0]; 7977} 7978 7979- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func { 7980 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0]; 7981} 7982 7983- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func 7984 rawValues:(const int32_t [])rawValues 7985 forKeys:(const int64_t [])keys 7986 count:(NSUInteger)count { 7987 self = [super init]; 7988 if (self) { 7989 _dictionary = [[NSMutableDictionary alloc] init]; 7990 _validationFunc = (func != NULL ? func : DictDefault_IsValidValue); 7991 if (count && rawValues && keys) { 7992 for (NSUInteger i = 0; i < count; ++i) { 7993 [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])]; 7994 } 7995 } 7996 } 7997 return self; 7998} 7999 8000- (instancetype)initWithDictionary:(GPBInt64EnumDictionary *)dictionary { 8001 self = [self initWithValidationFunction:dictionary.validationFunc 8002 rawValues:NULL 8003 forKeys:NULL 8004 count:0]; 8005 if (self) { 8006 if (dictionary) { 8007 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 8008 } 8009 } 8010 return self; 8011} 8012 8013- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func 8014 capacity:(NSUInteger)numItems { 8015 #pragma unused(numItems) 8016 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0]; 8017} 8018 8019- (void)dealloc { 8020 NSAssert(!_autocreator, 8021 @"%@: Autocreator must be cleared before release, autocreator: %@", 8022 [self class], _autocreator); 8023 [_dictionary release]; 8024 [super dealloc]; 8025} 8026 8027- (instancetype)copyWithZone:(NSZone *)zone { 8028 return [[GPBInt64EnumDictionary allocWithZone:zone] initWithDictionary:self]; 8029} 8030 8031- (BOOL)isEqual:(id)other { 8032 if (self == other) { 8033 return YES; 8034 } 8035 if (![other isKindOfClass:[GPBInt64EnumDictionary class]]) { 8036 return NO; 8037 } 8038 GPBInt64EnumDictionary *otherDictionary = other; 8039 return [_dictionary isEqual:otherDictionary->_dictionary]; 8040} 8041 8042- (NSUInteger)hash { 8043 return _dictionary.count; 8044} 8045 8046- (NSString *)description { 8047 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 8048} 8049 8050- (NSUInteger)count { 8051 return _dictionary.count; 8052} 8053 8054- (void)enumerateKeysAndRawValuesUsingBlock: 8055 (void (NS_NOESCAPE ^)(int64_t key, int32_t value, BOOL *stop))block { 8056 BOOL stop = NO; 8057 NSDictionary *internal = _dictionary; 8058 NSEnumerator *keys = [internal keyEnumerator]; 8059 NSNumber *aKey; 8060 while ((aKey = [keys nextObject])) { 8061 NSNumber *aValue = internal[aKey]; 8062 block([aKey longLongValue], [aValue intValue], &stop); 8063 if (stop) { 8064 break; 8065 } 8066 } 8067} 8068 8069- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 8070 NSDictionary *internal = _dictionary; 8071 NSUInteger count = internal.count; 8072 if (count == 0) { 8073 return 0; 8074 } 8075 8076 GPBDataType valueDataType = GPBGetFieldDataType(field); 8077 GPBDataType keyDataType = field.mapKeyDataType; 8078 size_t result = 0; 8079 NSEnumerator *keys = [internal keyEnumerator]; 8080 NSNumber *aKey; 8081 while ((aKey = [keys nextObject])) { 8082 NSNumber *aValue = internal[aKey]; 8083 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType); 8084 msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType); 8085 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 8086 } 8087 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 8088 result += tagSize * count; 8089 return result; 8090} 8091 8092- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 8093 asField:(GPBFieldDescriptor *)field { 8094 GPBDataType valueDataType = GPBGetFieldDataType(field); 8095 GPBDataType keyDataType = field.mapKeyDataType; 8096 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 8097 NSDictionary *internal = _dictionary; 8098 NSEnumerator *keys = [internal keyEnumerator]; 8099 NSNumber *aKey; 8100 while ((aKey = [keys nextObject])) { 8101 NSNumber *aValue = internal[aKey]; 8102 [outputStream writeInt32NoTag:tag]; 8103 // Write the size of the message. 8104 int64_t unwrappedKey = [aKey longLongValue]; 8105 int32_t unwrappedValue = [aValue intValue]; 8106 size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 8107 msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 8108 [outputStream writeInt32NoTag:(int32_t)msgSize]; 8109 // Write the fields. 8110 WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 8111 WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 8112 } 8113} 8114 8115- (NSData *)serializedDataForUnknownValue:(int32_t)value 8116 forKey:(GPBGenericValue *)key 8117 keyDataType:(GPBDataType)keyDataType { 8118 size_t msgSize = ComputeDictInt64FieldSize(key->valueInt64, kMapKeyFieldNumber, keyDataType); 8119 msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum); 8120 NSMutableData *data = [NSMutableData dataWithLength:msgSize]; 8121 GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data]; 8122 WriteDictInt64Field(outputStream, key->valueInt64, kMapKeyFieldNumber, keyDataType); 8123 WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum); 8124 [outputStream release]; 8125 return data; 8126} 8127- (void)setGPBGenericValue:(GPBGenericValue *)value 8128 forGPBGenericValueKey:(GPBGenericValue *)key { 8129 [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueInt64)]; 8130} 8131 8132- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 8133 [self enumerateKeysAndRawValuesUsingBlock:^(int64_t key, int32_t value, BOOL *stop) { 8134 #pragma unused(stop) 8135 block([NSString stringWithFormat:@"%lld", key], @(value)); 8136 }]; 8137} 8138 8139- (BOOL)getEnum:(int32_t *)value forKey:(int64_t)key { 8140 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; 8141 if (wrapped && value) { 8142 int32_t result = [wrapped intValue]; 8143 if (!_validationFunc(result)) { 8144 result = kGPBUnrecognizedEnumeratorValue; 8145 } 8146 *value = result; 8147 } 8148 return (wrapped != NULL); 8149} 8150 8151- (BOOL)getRawValue:(int32_t *)rawValue forKey:(int64_t)key { 8152 NSNumber *wrapped = [_dictionary objectForKey:@(key)]; 8153 if (wrapped && rawValue) { 8154 *rawValue = [wrapped intValue]; 8155 } 8156 return (wrapped != NULL); 8157} 8158 8159- (void)enumerateKeysAndEnumsUsingBlock: 8160 (void (NS_NOESCAPE ^)(int64_t key, int32_t value, BOOL *stop))block { 8161 GPBEnumValidationFunc func = _validationFunc; 8162 BOOL stop = NO; 8163 NSEnumerator *keys = [_dictionary keyEnumerator]; 8164 NSNumber *aKey; 8165 while ((aKey = [keys nextObject])) { 8166 NSNumber *aValue = _dictionary[aKey]; 8167 int32_t unwrapped = [aValue intValue]; 8168 if (!func(unwrapped)) { 8169 unwrapped = kGPBUnrecognizedEnumeratorValue; 8170 } 8171 block([aKey longLongValue], unwrapped, &stop); 8172 if (stop) { 8173 break; 8174 } 8175 } 8176} 8177 8178- (void)addRawEntriesFromDictionary:(GPBInt64EnumDictionary *)otherDictionary { 8179 if (otherDictionary) { 8180 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 8181 if (_autocreator) { 8182 GPBAutocreatedDictionaryModified(_autocreator, self); 8183 } 8184 } 8185} 8186 8187- (void)setRawValue:(int32_t)value forKey:(int64_t)key { 8188 [_dictionary setObject:@(value) forKey:@(key)]; 8189 if (_autocreator) { 8190 GPBAutocreatedDictionaryModified(_autocreator, self); 8191 } 8192} 8193 8194- (void)removeEnumForKey:(int64_t)aKey { 8195 [_dictionary removeObjectForKey:@(aKey)]; 8196} 8197 8198- (void)removeAll { 8199 [_dictionary removeAllObjects]; 8200} 8201 8202- (void)setEnum:(int32_t)value forKey:(int64_t)key { 8203 if (!_validationFunc(value)) { 8204 [NSException raise:NSInvalidArgumentException 8205 format:@"GPBInt64EnumDictionary: Attempt to set an unknown enum value (%d)", 8206 value]; 8207 } 8208 8209 [_dictionary setObject:@(value) forKey:@(key)]; 8210 if (_autocreator) { 8211 GPBAutocreatedDictionaryModified(_autocreator, self); 8212 } 8213} 8214 8215@end 8216 8217#pragma mark - Int64 -> Object 8218 8219@implementation GPBInt64ObjectDictionary { 8220 @package 8221 NSMutableDictionary *_dictionary; 8222} 8223 8224- (instancetype)init { 8225 return [self initWithObjects:NULL forKeys:NULL count:0]; 8226} 8227 8228- (instancetype)initWithObjects:(const id [])objects 8229 forKeys:(const int64_t [])keys 8230 count:(NSUInteger)count { 8231 self = [super init]; 8232 if (self) { 8233 _dictionary = [[NSMutableDictionary alloc] init]; 8234 if (count && objects && keys) { 8235 for (NSUInteger i = 0; i < count; ++i) { 8236 if (!objects[i]) { 8237 [NSException raise:NSInvalidArgumentException 8238 format:@"Attempting to add nil object to a Dictionary"]; 8239 } 8240 [_dictionary setObject:objects[i] forKey:@(keys[i])]; 8241 } 8242 } 8243 } 8244 return self; 8245} 8246 8247- (instancetype)initWithDictionary:(GPBInt64ObjectDictionary *)dictionary { 8248 self = [self initWithObjects:NULL forKeys:NULL count:0]; 8249 if (self) { 8250 if (dictionary) { 8251 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 8252 } 8253 } 8254 return self; 8255} 8256 8257- (instancetype)initWithCapacity:(NSUInteger)numItems { 8258 #pragma unused(numItems) 8259 return [self initWithObjects:NULL forKeys:NULL count:0]; 8260} 8261 8262- (void)dealloc { 8263 NSAssert(!_autocreator, 8264 @"%@: Autocreator must be cleared before release, autocreator: %@", 8265 [self class], _autocreator); 8266 [_dictionary release]; 8267 [super dealloc]; 8268} 8269 8270- (instancetype)copyWithZone:(NSZone *)zone { 8271 return [[GPBInt64ObjectDictionary allocWithZone:zone] initWithDictionary:self]; 8272} 8273 8274- (BOOL)isEqual:(id)other { 8275 if (self == other) { 8276 return YES; 8277 } 8278 if (![other isKindOfClass:[GPBInt64ObjectDictionary class]]) { 8279 return NO; 8280 } 8281 GPBInt64ObjectDictionary *otherDictionary = other; 8282 return [_dictionary isEqual:otherDictionary->_dictionary]; 8283} 8284 8285- (NSUInteger)hash { 8286 return _dictionary.count; 8287} 8288 8289- (NSString *)description { 8290 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 8291} 8292 8293- (NSUInteger)count { 8294 return _dictionary.count; 8295} 8296 8297- (void)enumerateKeysAndObjectsUsingBlock: 8298 (void (NS_NOESCAPE ^)(int64_t key, id object, BOOL *stop))block { 8299 BOOL stop = NO; 8300 NSDictionary *internal = _dictionary; 8301 NSEnumerator *keys = [internal keyEnumerator]; 8302 NSNumber *aKey; 8303 while ((aKey = [keys nextObject])) { 8304 id aObject = internal[aKey]; 8305 block([aKey longLongValue], aObject, &stop); 8306 if (stop) { 8307 break; 8308 } 8309 } 8310} 8311 8312- (BOOL)isInitialized { 8313 for (GPBMessage *msg in [_dictionary objectEnumerator]) { 8314 if (!msg.initialized) { 8315 return NO; 8316 } 8317 } 8318 return YES; 8319} 8320 8321- (instancetype)deepCopyWithZone:(NSZone *)zone { 8322 GPBInt64ObjectDictionary *newDict = 8323 [[GPBInt64ObjectDictionary alloc] init]; 8324 NSEnumerator *keys = [_dictionary keyEnumerator]; 8325 id aKey; 8326 NSMutableDictionary *internalDict = newDict->_dictionary; 8327 while ((aKey = [keys nextObject])) { 8328 GPBMessage *msg = _dictionary[aKey]; 8329 GPBMessage *copiedMsg = [msg copyWithZone:zone]; 8330 [internalDict setObject:copiedMsg forKey:aKey]; 8331 [copiedMsg release]; 8332 } 8333 return newDict; 8334} 8335 8336- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 8337 NSDictionary *internal = _dictionary; 8338 NSUInteger count = internal.count; 8339 if (count == 0) { 8340 return 0; 8341 } 8342 8343 GPBDataType valueDataType = GPBGetFieldDataType(field); 8344 GPBDataType keyDataType = field.mapKeyDataType; 8345 size_t result = 0; 8346 NSEnumerator *keys = [internal keyEnumerator]; 8347 NSNumber *aKey; 8348 while ((aKey = [keys nextObject])) { 8349 id aObject = internal[aKey]; 8350 size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType); 8351 msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType); 8352 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 8353 } 8354 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 8355 result += tagSize * count; 8356 return result; 8357} 8358 8359- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 8360 asField:(GPBFieldDescriptor *)field { 8361 GPBDataType valueDataType = GPBGetFieldDataType(field); 8362 GPBDataType keyDataType = field.mapKeyDataType; 8363 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 8364 NSDictionary *internal = _dictionary; 8365 NSEnumerator *keys = [internal keyEnumerator]; 8366 NSNumber *aKey; 8367 while ((aKey = [keys nextObject])) { 8368 id aObject = internal[aKey]; 8369 [outputStream writeInt32NoTag:tag]; 8370 // Write the size of the message. 8371 int64_t unwrappedKey = [aKey longLongValue]; 8372 id unwrappedValue = aObject; 8373 size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 8374 msgSize += ComputeDictObjectFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 8375 [outputStream writeInt32NoTag:(int32_t)msgSize]; 8376 // Write the fields. 8377 WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 8378 WriteDictObjectField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 8379 } 8380} 8381 8382- (void)setGPBGenericValue:(GPBGenericValue *)value 8383 forGPBGenericValueKey:(GPBGenericValue *)key { 8384 [_dictionary setObject:value->valueString forKey:@(key->valueInt64)]; 8385} 8386 8387- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 8388 [self enumerateKeysAndObjectsUsingBlock:^(int64_t key, id object, BOOL *stop) { 8389 #pragma unused(stop) 8390 block([NSString stringWithFormat:@"%lld", key], object); 8391 }]; 8392} 8393 8394- (id)objectForKey:(int64_t)key { 8395 id result = [_dictionary objectForKey:@(key)]; 8396 return result; 8397} 8398 8399- (void)addEntriesFromDictionary:(GPBInt64ObjectDictionary *)otherDictionary { 8400 if (otherDictionary) { 8401 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 8402 if (_autocreator) { 8403 GPBAutocreatedDictionaryModified(_autocreator, self); 8404 } 8405 } 8406} 8407 8408- (void)setObject:(id)object forKey:(int64_t)key { 8409 if (!object) { 8410 [NSException raise:NSInvalidArgumentException 8411 format:@"Attempting to add nil object to a Dictionary"]; 8412 } 8413 [_dictionary setObject:object forKey:@(key)]; 8414 if (_autocreator) { 8415 GPBAutocreatedDictionaryModified(_autocreator, self); 8416 } 8417} 8418 8419- (void)removeObjectForKey:(int64_t)aKey { 8420 [_dictionary removeObjectForKey:@(aKey)]; 8421} 8422 8423- (void)removeAll { 8424 [_dictionary removeAllObjects]; 8425} 8426 8427@end 8428 8429// clang-format on 8430//%PDDM-EXPAND DICTIONARY_POD_IMPL_FOR_KEY(String, NSString, *, OBJECT) 8431// This block of code is generated, do not edit it directly. 8432// clang-format off 8433 8434#pragma mark - String -> UInt32 8435 8436@implementation GPBStringUInt32Dictionary { 8437 @package 8438 NSMutableDictionary *_dictionary; 8439} 8440 8441- (instancetype)init { 8442 return [self initWithUInt32s:NULL forKeys:NULL count:0]; 8443} 8444 8445- (instancetype)initWithUInt32s:(const uint32_t [])values 8446 forKeys:(const NSString * [])keys 8447 count:(NSUInteger)count { 8448 self = [super init]; 8449 if (self) { 8450 _dictionary = [[NSMutableDictionary alloc] init]; 8451 if (count && values && keys) { 8452 for (NSUInteger i = 0; i < count; ++i) { 8453 if (!keys[i]) { 8454 [NSException raise:NSInvalidArgumentException 8455 format:@"Attempting to add nil key to a Dictionary"]; 8456 } 8457 [_dictionary setObject:@(values[i]) forKey:keys[i]]; 8458 } 8459 } 8460 } 8461 return self; 8462} 8463 8464- (instancetype)initWithDictionary:(GPBStringUInt32Dictionary *)dictionary { 8465 self = [self initWithUInt32s:NULL forKeys:NULL count:0]; 8466 if (self) { 8467 if (dictionary) { 8468 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 8469 } 8470 } 8471 return self; 8472} 8473 8474- (instancetype)initWithCapacity:(NSUInteger)numItems { 8475 #pragma unused(numItems) 8476 return [self initWithUInt32s:NULL forKeys:NULL count:0]; 8477} 8478 8479- (void)dealloc { 8480 NSAssert(!_autocreator, 8481 @"%@: Autocreator must be cleared before release, autocreator: %@", 8482 [self class], _autocreator); 8483 [_dictionary release]; 8484 [super dealloc]; 8485} 8486 8487- (instancetype)copyWithZone:(NSZone *)zone { 8488 return [[GPBStringUInt32Dictionary allocWithZone:zone] initWithDictionary:self]; 8489} 8490 8491- (BOOL)isEqual:(id)other { 8492 if (self == other) { 8493 return YES; 8494 } 8495 if (![other isKindOfClass:[GPBStringUInt32Dictionary class]]) { 8496 return NO; 8497 } 8498 GPBStringUInt32Dictionary *otherDictionary = other; 8499 return [_dictionary isEqual:otherDictionary->_dictionary]; 8500} 8501 8502- (NSUInteger)hash { 8503 return _dictionary.count; 8504} 8505 8506- (NSString *)description { 8507 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 8508} 8509 8510- (NSUInteger)count { 8511 return _dictionary.count; 8512} 8513 8514- (void)enumerateKeysAndUInt32sUsingBlock: 8515 (void (NS_NOESCAPE ^)(NSString *key, uint32_t value, BOOL *stop))block { 8516 BOOL stop = NO; 8517 NSDictionary *internal = _dictionary; 8518 NSEnumerator *keys = [internal keyEnumerator]; 8519 NSString *aKey; 8520 while ((aKey = [keys nextObject])) { 8521 NSNumber *aValue = internal[aKey]; 8522 block(aKey, [aValue unsignedIntValue], &stop); 8523 if (stop) { 8524 break; 8525 } 8526 } 8527} 8528 8529- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 8530 NSDictionary *internal = _dictionary; 8531 NSUInteger count = internal.count; 8532 if (count == 0) { 8533 return 0; 8534 } 8535 8536 GPBDataType valueDataType = GPBGetFieldDataType(field); 8537 GPBDataType keyDataType = field.mapKeyDataType; 8538 size_t result = 0; 8539 NSEnumerator *keys = [internal keyEnumerator]; 8540 NSString *aKey; 8541 while ((aKey = [keys nextObject])) { 8542 NSNumber *aValue = internal[aKey]; 8543 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType); 8544 msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType); 8545 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 8546 } 8547 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 8548 result += tagSize * count; 8549 return result; 8550} 8551 8552- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 8553 asField:(GPBFieldDescriptor *)field { 8554 GPBDataType valueDataType = GPBGetFieldDataType(field); 8555 GPBDataType keyDataType = field.mapKeyDataType; 8556 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 8557 NSDictionary *internal = _dictionary; 8558 NSEnumerator *keys = [internal keyEnumerator]; 8559 NSString *aKey; 8560 while ((aKey = [keys nextObject])) { 8561 NSNumber *aValue = internal[aKey]; 8562 [outputStream writeInt32NoTag:tag]; 8563 // Write the size of the message. 8564 NSString *unwrappedKey = aKey; 8565 uint32_t unwrappedValue = [aValue unsignedIntValue]; 8566 size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 8567 msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 8568 [outputStream writeInt32NoTag:(int32_t)msgSize]; 8569 // Write the fields. 8570 WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 8571 WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 8572 } 8573} 8574 8575- (void)setGPBGenericValue:(GPBGenericValue *)value 8576 forGPBGenericValueKey:(GPBGenericValue *)key { 8577 [_dictionary setObject:@(value->valueUInt32) forKey:key->valueString]; 8578} 8579 8580- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 8581 [self enumerateKeysAndUInt32sUsingBlock:^(NSString *key, uint32_t value, BOOL *stop) { 8582 #pragma unused(stop) 8583 block(key, [NSString stringWithFormat:@"%u", value]); 8584 }]; 8585} 8586 8587- (BOOL)getUInt32:(nullable uint32_t *)value forKey:(NSString *)key { 8588 NSNumber *wrapped = [_dictionary objectForKey:key]; 8589 if (wrapped && value) { 8590 *value = [wrapped unsignedIntValue]; 8591 } 8592 return (wrapped != NULL); 8593} 8594 8595- (void)addEntriesFromDictionary:(GPBStringUInt32Dictionary *)otherDictionary { 8596 if (otherDictionary) { 8597 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 8598 if (_autocreator) { 8599 GPBAutocreatedDictionaryModified(_autocreator, self); 8600 } 8601 } 8602} 8603 8604- (void)setUInt32:(uint32_t)value forKey:(NSString *)key { 8605 if (!key) { 8606 [NSException raise:NSInvalidArgumentException 8607 format:@"Attempting to add nil key to a Dictionary"]; 8608 } 8609 [_dictionary setObject:@(value) forKey:key]; 8610 if (_autocreator) { 8611 GPBAutocreatedDictionaryModified(_autocreator, self); 8612 } 8613} 8614 8615- (void)removeUInt32ForKey:(NSString *)aKey { 8616 [_dictionary removeObjectForKey:aKey]; 8617} 8618 8619- (void)removeAll { 8620 [_dictionary removeAllObjects]; 8621} 8622 8623@end 8624 8625#pragma mark - String -> Int32 8626 8627@implementation GPBStringInt32Dictionary { 8628 @package 8629 NSMutableDictionary *_dictionary; 8630} 8631 8632- (instancetype)init { 8633 return [self initWithInt32s:NULL forKeys:NULL count:0]; 8634} 8635 8636- (instancetype)initWithInt32s:(const int32_t [])values 8637 forKeys:(const NSString * [])keys 8638 count:(NSUInteger)count { 8639 self = [super init]; 8640 if (self) { 8641 _dictionary = [[NSMutableDictionary alloc] init]; 8642 if (count && values && keys) { 8643 for (NSUInteger i = 0; i < count; ++i) { 8644 if (!keys[i]) { 8645 [NSException raise:NSInvalidArgumentException 8646 format:@"Attempting to add nil key to a Dictionary"]; 8647 } 8648 [_dictionary setObject:@(values[i]) forKey:keys[i]]; 8649 } 8650 } 8651 } 8652 return self; 8653} 8654 8655- (instancetype)initWithDictionary:(GPBStringInt32Dictionary *)dictionary { 8656 self = [self initWithInt32s:NULL forKeys:NULL count:0]; 8657 if (self) { 8658 if (dictionary) { 8659 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 8660 } 8661 } 8662 return self; 8663} 8664 8665- (instancetype)initWithCapacity:(NSUInteger)numItems { 8666 #pragma unused(numItems) 8667 return [self initWithInt32s:NULL forKeys:NULL count:0]; 8668} 8669 8670- (void)dealloc { 8671 NSAssert(!_autocreator, 8672 @"%@: Autocreator must be cleared before release, autocreator: %@", 8673 [self class], _autocreator); 8674 [_dictionary release]; 8675 [super dealloc]; 8676} 8677 8678- (instancetype)copyWithZone:(NSZone *)zone { 8679 return [[GPBStringInt32Dictionary allocWithZone:zone] initWithDictionary:self]; 8680} 8681 8682- (BOOL)isEqual:(id)other { 8683 if (self == other) { 8684 return YES; 8685 } 8686 if (![other isKindOfClass:[GPBStringInt32Dictionary class]]) { 8687 return NO; 8688 } 8689 GPBStringInt32Dictionary *otherDictionary = other; 8690 return [_dictionary isEqual:otherDictionary->_dictionary]; 8691} 8692 8693- (NSUInteger)hash { 8694 return _dictionary.count; 8695} 8696 8697- (NSString *)description { 8698 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 8699} 8700 8701- (NSUInteger)count { 8702 return _dictionary.count; 8703} 8704 8705- (void)enumerateKeysAndInt32sUsingBlock: 8706 (void (NS_NOESCAPE ^)(NSString *key, int32_t value, BOOL *stop))block { 8707 BOOL stop = NO; 8708 NSDictionary *internal = _dictionary; 8709 NSEnumerator *keys = [internal keyEnumerator]; 8710 NSString *aKey; 8711 while ((aKey = [keys nextObject])) { 8712 NSNumber *aValue = internal[aKey]; 8713 block(aKey, [aValue intValue], &stop); 8714 if (stop) { 8715 break; 8716 } 8717 } 8718} 8719 8720- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 8721 NSDictionary *internal = _dictionary; 8722 NSUInteger count = internal.count; 8723 if (count == 0) { 8724 return 0; 8725 } 8726 8727 GPBDataType valueDataType = GPBGetFieldDataType(field); 8728 GPBDataType keyDataType = field.mapKeyDataType; 8729 size_t result = 0; 8730 NSEnumerator *keys = [internal keyEnumerator]; 8731 NSString *aKey; 8732 while ((aKey = [keys nextObject])) { 8733 NSNumber *aValue = internal[aKey]; 8734 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType); 8735 msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType); 8736 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 8737 } 8738 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 8739 result += tagSize * count; 8740 return result; 8741} 8742 8743- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 8744 asField:(GPBFieldDescriptor *)field { 8745 GPBDataType valueDataType = GPBGetFieldDataType(field); 8746 GPBDataType keyDataType = field.mapKeyDataType; 8747 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 8748 NSDictionary *internal = _dictionary; 8749 NSEnumerator *keys = [internal keyEnumerator]; 8750 NSString *aKey; 8751 while ((aKey = [keys nextObject])) { 8752 NSNumber *aValue = internal[aKey]; 8753 [outputStream writeInt32NoTag:tag]; 8754 // Write the size of the message. 8755 NSString *unwrappedKey = aKey; 8756 int32_t unwrappedValue = [aValue intValue]; 8757 size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 8758 msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 8759 [outputStream writeInt32NoTag:(int32_t)msgSize]; 8760 // Write the fields. 8761 WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 8762 WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 8763 } 8764} 8765 8766- (void)setGPBGenericValue:(GPBGenericValue *)value 8767 forGPBGenericValueKey:(GPBGenericValue *)key { 8768 [_dictionary setObject:@(value->valueInt32) forKey:key->valueString]; 8769} 8770 8771- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 8772 [self enumerateKeysAndInt32sUsingBlock:^(NSString *key, int32_t value, BOOL *stop) { 8773 #pragma unused(stop) 8774 block(key, [NSString stringWithFormat:@"%d", value]); 8775 }]; 8776} 8777 8778- (BOOL)getInt32:(nullable int32_t *)value forKey:(NSString *)key { 8779 NSNumber *wrapped = [_dictionary objectForKey:key]; 8780 if (wrapped && value) { 8781 *value = [wrapped intValue]; 8782 } 8783 return (wrapped != NULL); 8784} 8785 8786- (void)addEntriesFromDictionary:(GPBStringInt32Dictionary *)otherDictionary { 8787 if (otherDictionary) { 8788 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 8789 if (_autocreator) { 8790 GPBAutocreatedDictionaryModified(_autocreator, self); 8791 } 8792 } 8793} 8794 8795- (void)setInt32:(int32_t)value forKey:(NSString *)key { 8796 if (!key) { 8797 [NSException raise:NSInvalidArgumentException 8798 format:@"Attempting to add nil key to a Dictionary"]; 8799 } 8800 [_dictionary setObject:@(value) forKey:key]; 8801 if (_autocreator) { 8802 GPBAutocreatedDictionaryModified(_autocreator, self); 8803 } 8804} 8805 8806- (void)removeInt32ForKey:(NSString *)aKey { 8807 [_dictionary removeObjectForKey:aKey]; 8808} 8809 8810- (void)removeAll { 8811 [_dictionary removeAllObjects]; 8812} 8813 8814@end 8815 8816#pragma mark - String -> UInt64 8817 8818@implementation GPBStringUInt64Dictionary { 8819 @package 8820 NSMutableDictionary *_dictionary; 8821} 8822 8823- (instancetype)init { 8824 return [self initWithUInt64s:NULL forKeys:NULL count:0]; 8825} 8826 8827- (instancetype)initWithUInt64s:(const uint64_t [])values 8828 forKeys:(const NSString * [])keys 8829 count:(NSUInteger)count { 8830 self = [super init]; 8831 if (self) { 8832 _dictionary = [[NSMutableDictionary alloc] init]; 8833 if (count && values && keys) { 8834 for (NSUInteger i = 0; i < count; ++i) { 8835 if (!keys[i]) { 8836 [NSException raise:NSInvalidArgumentException 8837 format:@"Attempting to add nil key to a Dictionary"]; 8838 } 8839 [_dictionary setObject:@(values[i]) forKey:keys[i]]; 8840 } 8841 } 8842 } 8843 return self; 8844} 8845 8846- (instancetype)initWithDictionary:(GPBStringUInt64Dictionary *)dictionary { 8847 self = [self initWithUInt64s:NULL forKeys:NULL count:0]; 8848 if (self) { 8849 if (dictionary) { 8850 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 8851 } 8852 } 8853 return self; 8854} 8855 8856- (instancetype)initWithCapacity:(NSUInteger)numItems { 8857 #pragma unused(numItems) 8858 return [self initWithUInt64s:NULL forKeys:NULL count:0]; 8859} 8860 8861- (void)dealloc { 8862 NSAssert(!_autocreator, 8863 @"%@: Autocreator must be cleared before release, autocreator: %@", 8864 [self class], _autocreator); 8865 [_dictionary release]; 8866 [super dealloc]; 8867} 8868 8869- (instancetype)copyWithZone:(NSZone *)zone { 8870 return [[GPBStringUInt64Dictionary allocWithZone:zone] initWithDictionary:self]; 8871} 8872 8873- (BOOL)isEqual:(id)other { 8874 if (self == other) { 8875 return YES; 8876 } 8877 if (![other isKindOfClass:[GPBStringUInt64Dictionary class]]) { 8878 return NO; 8879 } 8880 GPBStringUInt64Dictionary *otherDictionary = other; 8881 return [_dictionary isEqual:otherDictionary->_dictionary]; 8882} 8883 8884- (NSUInteger)hash { 8885 return _dictionary.count; 8886} 8887 8888- (NSString *)description { 8889 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 8890} 8891 8892- (NSUInteger)count { 8893 return _dictionary.count; 8894} 8895 8896- (void)enumerateKeysAndUInt64sUsingBlock: 8897 (void (NS_NOESCAPE ^)(NSString *key, uint64_t value, BOOL *stop))block { 8898 BOOL stop = NO; 8899 NSDictionary *internal = _dictionary; 8900 NSEnumerator *keys = [internal keyEnumerator]; 8901 NSString *aKey; 8902 while ((aKey = [keys nextObject])) { 8903 NSNumber *aValue = internal[aKey]; 8904 block(aKey, [aValue unsignedLongLongValue], &stop); 8905 if (stop) { 8906 break; 8907 } 8908 } 8909} 8910 8911- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 8912 NSDictionary *internal = _dictionary; 8913 NSUInteger count = internal.count; 8914 if (count == 0) { 8915 return 0; 8916 } 8917 8918 GPBDataType valueDataType = GPBGetFieldDataType(field); 8919 GPBDataType keyDataType = field.mapKeyDataType; 8920 size_t result = 0; 8921 NSEnumerator *keys = [internal keyEnumerator]; 8922 NSString *aKey; 8923 while ((aKey = [keys nextObject])) { 8924 NSNumber *aValue = internal[aKey]; 8925 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType); 8926 msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType); 8927 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 8928 } 8929 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 8930 result += tagSize * count; 8931 return result; 8932} 8933 8934- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 8935 asField:(GPBFieldDescriptor *)field { 8936 GPBDataType valueDataType = GPBGetFieldDataType(field); 8937 GPBDataType keyDataType = field.mapKeyDataType; 8938 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 8939 NSDictionary *internal = _dictionary; 8940 NSEnumerator *keys = [internal keyEnumerator]; 8941 NSString *aKey; 8942 while ((aKey = [keys nextObject])) { 8943 NSNumber *aValue = internal[aKey]; 8944 [outputStream writeInt32NoTag:tag]; 8945 // Write the size of the message. 8946 NSString *unwrappedKey = aKey; 8947 uint64_t unwrappedValue = [aValue unsignedLongLongValue]; 8948 size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 8949 msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 8950 [outputStream writeInt32NoTag:(int32_t)msgSize]; 8951 // Write the fields. 8952 WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 8953 WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 8954 } 8955} 8956 8957- (void)setGPBGenericValue:(GPBGenericValue *)value 8958 forGPBGenericValueKey:(GPBGenericValue *)key { 8959 [_dictionary setObject:@(value->valueUInt64) forKey:key->valueString]; 8960} 8961 8962- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 8963 [self enumerateKeysAndUInt64sUsingBlock:^(NSString *key, uint64_t value, BOOL *stop) { 8964 #pragma unused(stop) 8965 block(key, [NSString stringWithFormat:@"%llu", value]); 8966 }]; 8967} 8968 8969- (BOOL)getUInt64:(nullable uint64_t *)value forKey:(NSString *)key { 8970 NSNumber *wrapped = [_dictionary objectForKey:key]; 8971 if (wrapped && value) { 8972 *value = [wrapped unsignedLongLongValue]; 8973 } 8974 return (wrapped != NULL); 8975} 8976 8977- (void)addEntriesFromDictionary:(GPBStringUInt64Dictionary *)otherDictionary { 8978 if (otherDictionary) { 8979 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 8980 if (_autocreator) { 8981 GPBAutocreatedDictionaryModified(_autocreator, self); 8982 } 8983 } 8984} 8985 8986- (void)setUInt64:(uint64_t)value forKey:(NSString *)key { 8987 if (!key) { 8988 [NSException raise:NSInvalidArgumentException 8989 format:@"Attempting to add nil key to a Dictionary"]; 8990 } 8991 [_dictionary setObject:@(value) forKey:key]; 8992 if (_autocreator) { 8993 GPBAutocreatedDictionaryModified(_autocreator, self); 8994 } 8995} 8996 8997- (void)removeUInt64ForKey:(NSString *)aKey { 8998 [_dictionary removeObjectForKey:aKey]; 8999} 9000 9001- (void)removeAll { 9002 [_dictionary removeAllObjects]; 9003} 9004 9005@end 9006 9007#pragma mark - String -> Int64 9008 9009@implementation GPBStringInt64Dictionary { 9010 @package 9011 NSMutableDictionary *_dictionary; 9012} 9013 9014- (instancetype)init { 9015 return [self initWithInt64s:NULL forKeys:NULL count:0]; 9016} 9017 9018- (instancetype)initWithInt64s:(const int64_t [])values 9019 forKeys:(const NSString * [])keys 9020 count:(NSUInteger)count { 9021 self = [super init]; 9022 if (self) { 9023 _dictionary = [[NSMutableDictionary alloc] init]; 9024 if (count && values && keys) { 9025 for (NSUInteger i = 0; i < count; ++i) { 9026 if (!keys[i]) { 9027 [NSException raise:NSInvalidArgumentException 9028 format:@"Attempting to add nil key to a Dictionary"]; 9029 } 9030 [_dictionary setObject:@(values[i]) forKey:keys[i]]; 9031 } 9032 } 9033 } 9034 return self; 9035} 9036 9037- (instancetype)initWithDictionary:(GPBStringInt64Dictionary *)dictionary { 9038 self = [self initWithInt64s:NULL forKeys:NULL count:0]; 9039 if (self) { 9040 if (dictionary) { 9041 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 9042 } 9043 } 9044 return self; 9045} 9046 9047- (instancetype)initWithCapacity:(NSUInteger)numItems { 9048 #pragma unused(numItems) 9049 return [self initWithInt64s:NULL forKeys:NULL count:0]; 9050} 9051 9052- (void)dealloc { 9053 NSAssert(!_autocreator, 9054 @"%@: Autocreator must be cleared before release, autocreator: %@", 9055 [self class], _autocreator); 9056 [_dictionary release]; 9057 [super dealloc]; 9058} 9059 9060- (instancetype)copyWithZone:(NSZone *)zone { 9061 return [[GPBStringInt64Dictionary allocWithZone:zone] initWithDictionary:self]; 9062} 9063 9064- (BOOL)isEqual:(id)other { 9065 if (self == other) { 9066 return YES; 9067 } 9068 if (![other isKindOfClass:[GPBStringInt64Dictionary class]]) { 9069 return NO; 9070 } 9071 GPBStringInt64Dictionary *otherDictionary = other; 9072 return [_dictionary isEqual:otherDictionary->_dictionary]; 9073} 9074 9075- (NSUInteger)hash { 9076 return _dictionary.count; 9077} 9078 9079- (NSString *)description { 9080 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 9081} 9082 9083- (NSUInteger)count { 9084 return _dictionary.count; 9085} 9086 9087- (void)enumerateKeysAndInt64sUsingBlock: 9088 (void (NS_NOESCAPE ^)(NSString *key, int64_t value, BOOL *stop))block { 9089 BOOL stop = NO; 9090 NSDictionary *internal = _dictionary; 9091 NSEnumerator *keys = [internal keyEnumerator]; 9092 NSString *aKey; 9093 while ((aKey = [keys nextObject])) { 9094 NSNumber *aValue = internal[aKey]; 9095 block(aKey, [aValue longLongValue], &stop); 9096 if (stop) { 9097 break; 9098 } 9099 } 9100} 9101 9102- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 9103 NSDictionary *internal = _dictionary; 9104 NSUInteger count = internal.count; 9105 if (count == 0) { 9106 return 0; 9107 } 9108 9109 GPBDataType valueDataType = GPBGetFieldDataType(field); 9110 GPBDataType keyDataType = field.mapKeyDataType; 9111 size_t result = 0; 9112 NSEnumerator *keys = [internal keyEnumerator]; 9113 NSString *aKey; 9114 while ((aKey = [keys nextObject])) { 9115 NSNumber *aValue = internal[aKey]; 9116 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType); 9117 msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType); 9118 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 9119 } 9120 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 9121 result += tagSize * count; 9122 return result; 9123} 9124 9125- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 9126 asField:(GPBFieldDescriptor *)field { 9127 GPBDataType valueDataType = GPBGetFieldDataType(field); 9128 GPBDataType keyDataType = field.mapKeyDataType; 9129 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 9130 NSDictionary *internal = _dictionary; 9131 NSEnumerator *keys = [internal keyEnumerator]; 9132 NSString *aKey; 9133 while ((aKey = [keys nextObject])) { 9134 NSNumber *aValue = internal[aKey]; 9135 [outputStream writeInt32NoTag:tag]; 9136 // Write the size of the message. 9137 NSString *unwrappedKey = aKey; 9138 int64_t unwrappedValue = [aValue longLongValue]; 9139 size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 9140 msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 9141 [outputStream writeInt32NoTag:(int32_t)msgSize]; 9142 // Write the fields. 9143 WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 9144 WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 9145 } 9146} 9147 9148- (void)setGPBGenericValue:(GPBGenericValue *)value 9149 forGPBGenericValueKey:(GPBGenericValue *)key { 9150 [_dictionary setObject:@(value->valueInt64) forKey:key->valueString]; 9151} 9152 9153- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 9154 [self enumerateKeysAndInt64sUsingBlock:^(NSString *key, int64_t value, BOOL *stop) { 9155 #pragma unused(stop) 9156 block(key, [NSString stringWithFormat:@"%lld", value]); 9157 }]; 9158} 9159 9160- (BOOL)getInt64:(nullable int64_t *)value forKey:(NSString *)key { 9161 NSNumber *wrapped = [_dictionary objectForKey:key]; 9162 if (wrapped && value) { 9163 *value = [wrapped longLongValue]; 9164 } 9165 return (wrapped != NULL); 9166} 9167 9168- (void)addEntriesFromDictionary:(GPBStringInt64Dictionary *)otherDictionary { 9169 if (otherDictionary) { 9170 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 9171 if (_autocreator) { 9172 GPBAutocreatedDictionaryModified(_autocreator, self); 9173 } 9174 } 9175} 9176 9177- (void)setInt64:(int64_t)value forKey:(NSString *)key { 9178 if (!key) { 9179 [NSException raise:NSInvalidArgumentException 9180 format:@"Attempting to add nil key to a Dictionary"]; 9181 } 9182 [_dictionary setObject:@(value) forKey:key]; 9183 if (_autocreator) { 9184 GPBAutocreatedDictionaryModified(_autocreator, self); 9185 } 9186} 9187 9188- (void)removeInt64ForKey:(NSString *)aKey { 9189 [_dictionary removeObjectForKey:aKey]; 9190} 9191 9192- (void)removeAll { 9193 [_dictionary removeAllObjects]; 9194} 9195 9196@end 9197 9198#pragma mark - String -> Bool 9199 9200@implementation GPBStringBoolDictionary { 9201 @package 9202 NSMutableDictionary *_dictionary; 9203} 9204 9205- (instancetype)init { 9206 return [self initWithBools:NULL forKeys:NULL count:0]; 9207} 9208 9209- (instancetype)initWithBools:(const BOOL [])values 9210 forKeys:(const NSString * [])keys 9211 count:(NSUInteger)count { 9212 self = [super init]; 9213 if (self) { 9214 _dictionary = [[NSMutableDictionary alloc] init]; 9215 if (count && values && keys) { 9216 for (NSUInteger i = 0; i < count; ++i) { 9217 if (!keys[i]) { 9218 [NSException raise:NSInvalidArgumentException 9219 format:@"Attempting to add nil key to a Dictionary"]; 9220 } 9221 [_dictionary setObject:@(values[i]) forKey:keys[i]]; 9222 } 9223 } 9224 } 9225 return self; 9226} 9227 9228- (instancetype)initWithDictionary:(GPBStringBoolDictionary *)dictionary { 9229 self = [self initWithBools:NULL forKeys:NULL count:0]; 9230 if (self) { 9231 if (dictionary) { 9232 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 9233 } 9234 } 9235 return self; 9236} 9237 9238- (instancetype)initWithCapacity:(NSUInteger)numItems { 9239 #pragma unused(numItems) 9240 return [self initWithBools:NULL forKeys:NULL count:0]; 9241} 9242 9243- (void)dealloc { 9244 NSAssert(!_autocreator, 9245 @"%@: Autocreator must be cleared before release, autocreator: %@", 9246 [self class], _autocreator); 9247 [_dictionary release]; 9248 [super dealloc]; 9249} 9250 9251- (instancetype)copyWithZone:(NSZone *)zone { 9252 return [[GPBStringBoolDictionary allocWithZone:zone] initWithDictionary:self]; 9253} 9254 9255- (BOOL)isEqual:(id)other { 9256 if (self == other) { 9257 return YES; 9258 } 9259 if (![other isKindOfClass:[GPBStringBoolDictionary class]]) { 9260 return NO; 9261 } 9262 GPBStringBoolDictionary *otherDictionary = other; 9263 return [_dictionary isEqual:otherDictionary->_dictionary]; 9264} 9265 9266- (NSUInteger)hash { 9267 return _dictionary.count; 9268} 9269 9270- (NSString *)description { 9271 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 9272} 9273 9274- (NSUInteger)count { 9275 return _dictionary.count; 9276} 9277 9278- (void)enumerateKeysAndBoolsUsingBlock: 9279 (void (NS_NOESCAPE ^)(NSString *key, BOOL value, BOOL *stop))block { 9280 BOOL stop = NO; 9281 NSDictionary *internal = _dictionary; 9282 NSEnumerator *keys = [internal keyEnumerator]; 9283 NSString *aKey; 9284 while ((aKey = [keys nextObject])) { 9285 NSNumber *aValue = internal[aKey]; 9286 block(aKey, [aValue boolValue], &stop); 9287 if (stop) { 9288 break; 9289 } 9290 } 9291} 9292 9293- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 9294 NSDictionary *internal = _dictionary; 9295 NSUInteger count = internal.count; 9296 if (count == 0) { 9297 return 0; 9298 } 9299 9300 GPBDataType valueDataType = GPBGetFieldDataType(field); 9301 GPBDataType keyDataType = field.mapKeyDataType; 9302 size_t result = 0; 9303 NSEnumerator *keys = [internal keyEnumerator]; 9304 NSString *aKey; 9305 while ((aKey = [keys nextObject])) { 9306 NSNumber *aValue = internal[aKey]; 9307 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType); 9308 msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType); 9309 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 9310 } 9311 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 9312 result += tagSize * count; 9313 return result; 9314} 9315 9316- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 9317 asField:(GPBFieldDescriptor *)field { 9318 GPBDataType valueDataType = GPBGetFieldDataType(field); 9319 GPBDataType keyDataType = field.mapKeyDataType; 9320 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 9321 NSDictionary *internal = _dictionary; 9322 NSEnumerator *keys = [internal keyEnumerator]; 9323 NSString *aKey; 9324 while ((aKey = [keys nextObject])) { 9325 NSNumber *aValue = internal[aKey]; 9326 [outputStream writeInt32NoTag:tag]; 9327 // Write the size of the message. 9328 NSString *unwrappedKey = aKey; 9329 BOOL unwrappedValue = [aValue boolValue]; 9330 size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 9331 msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 9332 [outputStream writeInt32NoTag:(int32_t)msgSize]; 9333 // Write the fields. 9334 WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 9335 WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 9336 } 9337} 9338 9339- (void)setGPBGenericValue:(GPBGenericValue *)value 9340 forGPBGenericValueKey:(GPBGenericValue *)key { 9341 [_dictionary setObject:@(value->valueBool) forKey:key->valueString]; 9342} 9343 9344- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 9345 [self enumerateKeysAndBoolsUsingBlock:^(NSString *key, BOOL value, BOOL *stop) { 9346 #pragma unused(stop) 9347 block(key, (value ? @"true" : @"false")); 9348 }]; 9349} 9350 9351- (BOOL)getBool:(nullable BOOL *)value forKey:(NSString *)key { 9352 NSNumber *wrapped = [_dictionary objectForKey:key]; 9353 if (wrapped && value) { 9354 *value = [wrapped boolValue]; 9355 } 9356 return (wrapped != NULL); 9357} 9358 9359- (void)addEntriesFromDictionary:(GPBStringBoolDictionary *)otherDictionary { 9360 if (otherDictionary) { 9361 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 9362 if (_autocreator) { 9363 GPBAutocreatedDictionaryModified(_autocreator, self); 9364 } 9365 } 9366} 9367 9368- (void)setBool:(BOOL)value forKey:(NSString *)key { 9369 if (!key) { 9370 [NSException raise:NSInvalidArgumentException 9371 format:@"Attempting to add nil key to a Dictionary"]; 9372 } 9373 [_dictionary setObject:@(value) forKey:key]; 9374 if (_autocreator) { 9375 GPBAutocreatedDictionaryModified(_autocreator, self); 9376 } 9377} 9378 9379- (void)removeBoolForKey:(NSString *)aKey { 9380 [_dictionary removeObjectForKey:aKey]; 9381} 9382 9383- (void)removeAll { 9384 [_dictionary removeAllObjects]; 9385} 9386 9387@end 9388 9389#pragma mark - String -> Float 9390 9391@implementation GPBStringFloatDictionary { 9392 @package 9393 NSMutableDictionary *_dictionary; 9394} 9395 9396- (instancetype)init { 9397 return [self initWithFloats:NULL forKeys:NULL count:0]; 9398} 9399 9400- (instancetype)initWithFloats:(const float [])values 9401 forKeys:(const NSString * [])keys 9402 count:(NSUInteger)count { 9403 self = [super init]; 9404 if (self) { 9405 _dictionary = [[NSMutableDictionary alloc] init]; 9406 if (count && values && keys) { 9407 for (NSUInteger i = 0; i < count; ++i) { 9408 if (!keys[i]) { 9409 [NSException raise:NSInvalidArgumentException 9410 format:@"Attempting to add nil key to a Dictionary"]; 9411 } 9412 [_dictionary setObject:@(values[i]) forKey:keys[i]]; 9413 } 9414 } 9415 } 9416 return self; 9417} 9418 9419- (instancetype)initWithDictionary:(GPBStringFloatDictionary *)dictionary { 9420 self = [self initWithFloats:NULL forKeys:NULL count:0]; 9421 if (self) { 9422 if (dictionary) { 9423 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 9424 } 9425 } 9426 return self; 9427} 9428 9429- (instancetype)initWithCapacity:(NSUInteger)numItems { 9430 #pragma unused(numItems) 9431 return [self initWithFloats:NULL forKeys:NULL count:0]; 9432} 9433 9434- (void)dealloc { 9435 NSAssert(!_autocreator, 9436 @"%@: Autocreator must be cleared before release, autocreator: %@", 9437 [self class], _autocreator); 9438 [_dictionary release]; 9439 [super dealloc]; 9440} 9441 9442- (instancetype)copyWithZone:(NSZone *)zone { 9443 return [[GPBStringFloatDictionary allocWithZone:zone] initWithDictionary:self]; 9444} 9445 9446- (BOOL)isEqual:(id)other { 9447 if (self == other) { 9448 return YES; 9449 } 9450 if (![other isKindOfClass:[GPBStringFloatDictionary class]]) { 9451 return NO; 9452 } 9453 GPBStringFloatDictionary *otherDictionary = other; 9454 return [_dictionary isEqual:otherDictionary->_dictionary]; 9455} 9456 9457- (NSUInteger)hash { 9458 return _dictionary.count; 9459} 9460 9461- (NSString *)description { 9462 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 9463} 9464 9465- (NSUInteger)count { 9466 return _dictionary.count; 9467} 9468 9469- (void)enumerateKeysAndFloatsUsingBlock: 9470 (void (NS_NOESCAPE ^)(NSString *key, float value, BOOL *stop))block { 9471 BOOL stop = NO; 9472 NSDictionary *internal = _dictionary; 9473 NSEnumerator *keys = [internal keyEnumerator]; 9474 NSString *aKey; 9475 while ((aKey = [keys nextObject])) { 9476 NSNumber *aValue = internal[aKey]; 9477 block(aKey, [aValue floatValue], &stop); 9478 if (stop) { 9479 break; 9480 } 9481 } 9482} 9483 9484- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 9485 NSDictionary *internal = _dictionary; 9486 NSUInteger count = internal.count; 9487 if (count == 0) { 9488 return 0; 9489 } 9490 9491 GPBDataType valueDataType = GPBGetFieldDataType(field); 9492 GPBDataType keyDataType = field.mapKeyDataType; 9493 size_t result = 0; 9494 NSEnumerator *keys = [internal keyEnumerator]; 9495 NSString *aKey; 9496 while ((aKey = [keys nextObject])) { 9497 NSNumber *aValue = internal[aKey]; 9498 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType); 9499 msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType); 9500 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 9501 } 9502 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 9503 result += tagSize * count; 9504 return result; 9505} 9506 9507- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 9508 asField:(GPBFieldDescriptor *)field { 9509 GPBDataType valueDataType = GPBGetFieldDataType(field); 9510 GPBDataType keyDataType = field.mapKeyDataType; 9511 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 9512 NSDictionary *internal = _dictionary; 9513 NSEnumerator *keys = [internal keyEnumerator]; 9514 NSString *aKey; 9515 while ((aKey = [keys nextObject])) { 9516 NSNumber *aValue = internal[aKey]; 9517 [outputStream writeInt32NoTag:tag]; 9518 // Write the size of the message. 9519 NSString *unwrappedKey = aKey; 9520 float unwrappedValue = [aValue floatValue]; 9521 size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 9522 msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 9523 [outputStream writeInt32NoTag:(int32_t)msgSize]; 9524 // Write the fields. 9525 WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 9526 WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 9527 } 9528} 9529 9530- (void)setGPBGenericValue:(GPBGenericValue *)value 9531 forGPBGenericValueKey:(GPBGenericValue *)key { 9532 [_dictionary setObject:@(value->valueFloat) forKey:key->valueString]; 9533} 9534 9535- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 9536 [self enumerateKeysAndFloatsUsingBlock:^(NSString *key, float value, BOOL *stop) { 9537 #pragma unused(stop) 9538 block(key, [NSString stringWithFormat:@"%.*g", FLT_DIG, value]); 9539 }]; 9540} 9541 9542- (BOOL)getFloat:(nullable float *)value forKey:(NSString *)key { 9543 NSNumber *wrapped = [_dictionary objectForKey:key]; 9544 if (wrapped && value) { 9545 *value = [wrapped floatValue]; 9546 } 9547 return (wrapped != NULL); 9548} 9549 9550- (void)addEntriesFromDictionary:(GPBStringFloatDictionary *)otherDictionary { 9551 if (otherDictionary) { 9552 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 9553 if (_autocreator) { 9554 GPBAutocreatedDictionaryModified(_autocreator, self); 9555 } 9556 } 9557} 9558 9559- (void)setFloat:(float)value forKey:(NSString *)key { 9560 if (!key) { 9561 [NSException raise:NSInvalidArgumentException 9562 format:@"Attempting to add nil key to a Dictionary"]; 9563 } 9564 [_dictionary setObject:@(value) forKey:key]; 9565 if (_autocreator) { 9566 GPBAutocreatedDictionaryModified(_autocreator, self); 9567 } 9568} 9569 9570- (void)removeFloatForKey:(NSString *)aKey { 9571 [_dictionary removeObjectForKey:aKey]; 9572} 9573 9574- (void)removeAll { 9575 [_dictionary removeAllObjects]; 9576} 9577 9578@end 9579 9580#pragma mark - String -> Double 9581 9582@implementation GPBStringDoubleDictionary { 9583 @package 9584 NSMutableDictionary *_dictionary; 9585} 9586 9587- (instancetype)init { 9588 return [self initWithDoubles:NULL forKeys:NULL count:0]; 9589} 9590 9591- (instancetype)initWithDoubles:(const double [])values 9592 forKeys:(const NSString * [])keys 9593 count:(NSUInteger)count { 9594 self = [super init]; 9595 if (self) { 9596 _dictionary = [[NSMutableDictionary alloc] init]; 9597 if (count && values && keys) { 9598 for (NSUInteger i = 0; i < count; ++i) { 9599 if (!keys[i]) { 9600 [NSException raise:NSInvalidArgumentException 9601 format:@"Attempting to add nil key to a Dictionary"]; 9602 } 9603 [_dictionary setObject:@(values[i]) forKey:keys[i]]; 9604 } 9605 } 9606 } 9607 return self; 9608} 9609 9610- (instancetype)initWithDictionary:(GPBStringDoubleDictionary *)dictionary { 9611 self = [self initWithDoubles:NULL forKeys:NULL count:0]; 9612 if (self) { 9613 if (dictionary) { 9614 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 9615 } 9616 } 9617 return self; 9618} 9619 9620- (instancetype)initWithCapacity:(NSUInteger)numItems { 9621 #pragma unused(numItems) 9622 return [self initWithDoubles:NULL forKeys:NULL count:0]; 9623} 9624 9625- (void)dealloc { 9626 NSAssert(!_autocreator, 9627 @"%@: Autocreator must be cleared before release, autocreator: %@", 9628 [self class], _autocreator); 9629 [_dictionary release]; 9630 [super dealloc]; 9631} 9632 9633- (instancetype)copyWithZone:(NSZone *)zone { 9634 return [[GPBStringDoubleDictionary allocWithZone:zone] initWithDictionary:self]; 9635} 9636 9637- (BOOL)isEqual:(id)other { 9638 if (self == other) { 9639 return YES; 9640 } 9641 if (![other isKindOfClass:[GPBStringDoubleDictionary class]]) { 9642 return NO; 9643 } 9644 GPBStringDoubleDictionary *otherDictionary = other; 9645 return [_dictionary isEqual:otherDictionary->_dictionary]; 9646} 9647 9648- (NSUInteger)hash { 9649 return _dictionary.count; 9650} 9651 9652- (NSString *)description { 9653 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 9654} 9655 9656- (NSUInteger)count { 9657 return _dictionary.count; 9658} 9659 9660- (void)enumerateKeysAndDoublesUsingBlock: 9661 (void (NS_NOESCAPE ^)(NSString *key, double value, BOOL *stop))block { 9662 BOOL stop = NO; 9663 NSDictionary *internal = _dictionary; 9664 NSEnumerator *keys = [internal keyEnumerator]; 9665 NSString *aKey; 9666 while ((aKey = [keys nextObject])) { 9667 NSNumber *aValue = internal[aKey]; 9668 block(aKey, [aValue doubleValue], &stop); 9669 if (stop) { 9670 break; 9671 } 9672 } 9673} 9674 9675- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 9676 NSDictionary *internal = _dictionary; 9677 NSUInteger count = internal.count; 9678 if (count == 0) { 9679 return 0; 9680 } 9681 9682 GPBDataType valueDataType = GPBGetFieldDataType(field); 9683 GPBDataType keyDataType = field.mapKeyDataType; 9684 size_t result = 0; 9685 NSEnumerator *keys = [internal keyEnumerator]; 9686 NSString *aKey; 9687 while ((aKey = [keys nextObject])) { 9688 NSNumber *aValue = internal[aKey]; 9689 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType); 9690 msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType); 9691 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 9692 } 9693 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 9694 result += tagSize * count; 9695 return result; 9696} 9697 9698- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 9699 asField:(GPBFieldDescriptor *)field { 9700 GPBDataType valueDataType = GPBGetFieldDataType(field); 9701 GPBDataType keyDataType = field.mapKeyDataType; 9702 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 9703 NSDictionary *internal = _dictionary; 9704 NSEnumerator *keys = [internal keyEnumerator]; 9705 NSString *aKey; 9706 while ((aKey = [keys nextObject])) { 9707 NSNumber *aValue = internal[aKey]; 9708 [outputStream writeInt32NoTag:tag]; 9709 // Write the size of the message. 9710 NSString *unwrappedKey = aKey; 9711 double unwrappedValue = [aValue doubleValue]; 9712 size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 9713 msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 9714 [outputStream writeInt32NoTag:(int32_t)msgSize]; 9715 // Write the fields. 9716 WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 9717 WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 9718 } 9719} 9720 9721- (void)setGPBGenericValue:(GPBGenericValue *)value 9722 forGPBGenericValueKey:(GPBGenericValue *)key { 9723 [_dictionary setObject:@(value->valueDouble) forKey:key->valueString]; 9724} 9725 9726- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 9727 [self enumerateKeysAndDoublesUsingBlock:^(NSString *key, double value, BOOL *stop) { 9728 #pragma unused(stop) 9729 block(key, [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]); 9730 }]; 9731} 9732 9733- (BOOL)getDouble:(nullable double *)value forKey:(NSString *)key { 9734 NSNumber *wrapped = [_dictionary objectForKey:key]; 9735 if (wrapped && value) { 9736 *value = [wrapped doubleValue]; 9737 } 9738 return (wrapped != NULL); 9739} 9740 9741- (void)addEntriesFromDictionary:(GPBStringDoubleDictionary *)otherDictionary { 9742 if (otherDictionary) { 9743 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 9744 if (_autocreator) { 9745 GPBAutocreatedDictionaryModified(_autocreator, self); 9746 } 9747 } 9748} 9749 9750- (void)setDouble:(double)value forKey:(NSString *)key { 9751 if (!key) { 9752 [NSException raise:NSInvalidArgumentException 9753 format:@"Attempting to add nil key to a Dictionary"]; 9754 } 9755 [_dictionary setObject:@(value) forKey:key]; 9756 if (_autocreator) { 9757 GPBAutocreatedDictionaryModified(_autocreator, self); 9758 } 9759} 9760 9761- (void)removeDoubleForKey:(NSString *)aKey { 9762 [_dictionary removeObjectForKey:aKey]; 9763} 9764 9765- (void)removeAll { 9766 [_dictionary removeAllObjects]; 9767} 9768 9769@end 9770 9771#pragma mark - String -> Enum 9772 9773@implementation GPBStringEnumDictionary { 9774 @package 9775 NSMutableDictionary *_dictionary; 9776 GPBEnumValidationFunc _validationFunc; 9777} 9778 9779@synthesize validationFunc = _validationFunc; 9780 9781- (instancetype)init { 9782 return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0]; 9783} 9784 9785- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func { 9786 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0]; 9787} 9788 9789- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func 9790 rawValues:(const int32_t [])rawValues 9791 forKeys:(const NSString * [])keys 9792 count:(NSUInteger)count { 9793 self = [super init]; 9794 if (self) { 9795 _dictionary = [[NSMutableDictionary alloc] init]; 9796 _validationFunc = (func != NULL ? func : DictDefault_IsValidValue); 9797 if (count && rawValues && keys) { 9798 for (NSUInteger i = 0; i < count; ++i) { 9799 if (!keys[i]) { 9800 [NSException raise:NSInvalidArgumentException 9801 format:@"Attempting to add nil key to a Dictionary"]; 9802 } 9803 [_dictionary setObject:@(rawValues[i]) forKey:keys[i]]; 9804 } 9805 } 9806 } 9807 return self; 9808} 9809 9810- (instancetype)initWithDictionary:(GPBStringEnumDictionary *)dictionary { 9811 self = [self initWithValidationFunction:dictionary.validationFunc 9812 rawValues:NULL 9813 forKeys:NULL 9814 count:0]; 9815 if (self) { 9816 if (dictionary) { 9817 [_dictionary addEntriesFromDictionary:dictionary->_dictionary]; 9818 } 9819 } 9820 return self; 9821} 9822 9823- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func 9824 capacity:(NSUInteger)numItems { 9825 #pragma unused(numItems) 9826 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0]; 9827} 9828 9829- (void)dealloc { 9830 NSAssert(!_autocreator, 9831 @"%@: Autocreator must be cleared before release, autocreator: %@", 9832 [self class], _autocreator); 9833 [_dictionary release]; 9834 [super dealloc]; 9835} 9836 9837- (instancetype)copyWithZone:(NSZone *)zone { 9838 return [[GPBStringEnumDictionary allocWithZone:zone] initWithDictionary:self]; 9839} 9840 9841- (BOOL)isEqual:(id)other { 9842 if (self == other) { 9843 return YES; 9844 } 9845 if (![other isKindOfClass:[GPBStringEnumDictionary class]]) { 9846 return NO; 9847 } 9848 GPBStringEnumDictionary *otherDictionary = other; 9849 return [_dictionary isEqual:otherDictionary->_dictionary]; 9850} 9851 9852- (NSUInteger)hash { 9853 return _dictionary.count; 9854} 9855 9856- (NSString *)description { 9857 return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary]; 9858} 9859 9860- (NSUInteger)count { 9861 return _dictionary.count; 9862} 9863 9864- (void)enumerateKeysAndRawValuesUsingBlock: 9865 (void (NS_NOESCAPE ^)(NSString *key, int32_t value, BOOL *stop))block { 9866 BOOL stop = NO; 9867 NSDictionary *internal = _dictionary; 9868 NSEnumerator *keys = [internal keyEnumerator]; 9869 NSString *aKey; 9870 while ((aKey = [keys nextObject])) { 9871 NSNumber *aValue = internal[aKey]; 9872 block(aKey, [aValue intValue], &stop); 9873 if (stop) { 9874 break; 9875 } 9876 } 9877} 9878 9879- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 9880 NSDictionary *internal = _dictionary; 9881 NSUInteger count = internal.count; 9882 if (count == 0) { 9883 return 0; 9884 } 9885 9886 GPBDataType valueDataType = GPBGetFieldDataType(field); 9887 GPBDataType keyDataType = field.mapKeyDataType; 9888 size_t result = 0; 9889 NSEnumerator *keys = [internal keyEnumerator]; 9890 NSString *aKey; 9891 while ((aKey = [keys nextObject])) { 9892 NSNumber *aValue = internal[aKey]; 9893 size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType); 9894 msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType); 9895 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 9896 } 9897 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 9898 result += tagSize * count; 9899 return result; 9900} 9901 9902- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 9903 asField:(GPBFieldDescriptor *)field { 9904 GPBDataType valueDataType = GPBGetFieldDataType(field); 9905 GPBDataType keyDataType = field.mapKeyDataType; 9906 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 9907 NSDictionary *internal = _dictionary; 9908 NSEnumerator *keys = [internal keyEnumerator]; 9909 NSString *aKey; 9910 while ((aKey = [keys nextObject])) { 9911 NSNumber *aValue = internal[aKey]; 9912 [outputStream writeInt32NoTag:tag]; 9913 // Write the size of the message. 9914 NSString *unwrappedKey = aKey; 9915 int32_t unwrappedValue = [aValue intValue]; 9916 size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType); 9917 msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType); 9918 [outputStream writeInt32NoTag:(int32_t)msgSize]; 9919 // Write the fields. 9920 WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType); 9921 WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType); 9922 } 9923} 9924 9925- (NSData *)serializedDataForUnknownValue:(int32_t)value 9926 forKey:(GPBGenericValue *)key 9927 keyDataType:(GPBDataType)keyDataType { 9928 size_t msgSize = ComputeDictStringFieldSize(key->valueString, kMapKeyFieldNumber, keyDataType); 9929 msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum); 9930 NSMutableData *data = [NSMutableData dataWithLength:msgSize]; 9931 GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data]; 9932 WriteDictStringField(outputStream, key->valueString, kMapKeyFieldNumber, keyDataType); 9933 WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum); 9934 [outputStream release]; 9935 return data; 9936} 9937- (void)setGPBGenericValue:(GPBGenericValue *)value 9938 forGPBGenericValueKey:(GPBGenericValue *)key { 9939 [_dictionary setObject:@(value->valueEnum) forKey:key->valueString]; 9940} 9941 9942- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 9943 [self enumerateKeysAndRawValuesUsingBlock:^(NSString *key, int32_t value, BOOL *stop) { 9944 #pragma unused(stop) 9945 block(key, @(value)); 9946 }]; 9947} 9948 9949- (BOOL)getEnum:(int32_t *)value forKey:(NSString *)key { 9950 NSNumber *wrapped = [_dictionary objectForKey:key]; 9951 if (wrapped && value) { 9952 int32_t result = [wrapped intValue]; 9953 if (!_validationFunc(result)) { 9954 result = kGPBUnrecognizedEnumeratorValue; 9955 } 9956 *value = result; 9957 } 9958 return (wrapped != NULL); 9959} 9960 9961- (BOOL)getRawValue:(int32_t *)rawValue forKey:(NSString *)key { 9962 NSNumber *wrapped = [_dictionary objectForKey:key]; 9963 if (wrapped && rawValue) { 9964 *rawValue = [wrapped intValue]; 9965 } 9966 return (wrapped != NULL); 9967} 9968 9969- (void)enumerateKeysAndEnumsUsingBlock: 9970 (void (NS_NOESCAPE ^)(NSString *key, int32_t value, BOOL *stop))block { 9971 GPBEnumValidationFunc func = _validationFunc; 9972 BOOL stop = NO; 9973 NSEnumerator *keys = [_dictionary keyEnumerator]; 9974 NSString *aKey; 9975 while ((aKey = [keys nextObject])) { 9976 NSNumber *aValue = _dictionary[aKey]; 9977 int32_t unwrapped = [aValue intValue]; 9978 if (!func(unwrapped)) { 9979 unwrapped = kGPBUnrecognizedEnumeratorValue; 9980 } 9981 block(aKey, unwrapped, &stop); 9982 if (stop) { 9983 break; 9984 } 9985 } 9986} 9987 9988- (void)addRawEntriesFromDictionary:(GPBStringEnumDictionary *)otherDictionary { 9989 if (otherDictionary) { 9990 [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary]; 9991 if (_autocreator) { 9992 GPBAutocreatedDictionaryModified(_autocreator, self); 9993 } 9994 } 9995} 9996 9997- (void)setRawValue:(int32_t)value forKey:(NSString *)key { 9998 if (!key) { 9999 [NSException raise:NSInvalidArgumentException 10000 format:@"Attempting to add nil key to a Dictionary"]; 10001 } 10002 [_dictionary setObject:@(value) forKey:key]; 10003 if (_autocreator) { 10004 GPBAutocreatedDictionaryModified(_autocreator, self); 10005 } 10006} 10007 10008- (void)removeEnumForKey:(NSString *)aKey { 10009 [_dictionary removeObjectForKey:aKey]; 10010} 10011 10012- (void)removeAll { 10013 [_dictionary removeAllObjects]; 10014} 10015 10016- (void)setEnum:(int32_t)value forKey:(NSString *)key { 10017 if (!key) { 10018 [NSException raise:NSInvalidArgumentException 10019 format:@"Attempting to add nil key to a Dictionary"]; 10020 } 10021 if (!_validationFunc(value)) { 10022 [NSException raise:NSInvalidArgumentException 10023 format:@"GPBStringEnumDictionary: Attempt to set an unknown enum value (%d)", 10024 value]; 10025 } 10026 10027 [_dictionary setObject:@(value) forKey:key]; 10028 if (_autocreator) { 10029 GPBAutocreatedDictionaryModified(_autocreator, self); 10030 } 10031} 10032 10033@end 10034 10035// clang-format on 10036//%PDDM-EXPAND-END (5 expansions) 10037 10038 10039//%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(UInt32, uint32_t) 10040// This block of code is generated, do not edit it directly. 10041// clang-format off 10042 10043#pragma mark - Bool -> UInt32 10044 10045@implementation GPBBoolUInt32Dictionary { 10046 @package 10047 uint32_t _values[2]; 10048 BOOL _valueSet[2]; 10049} 10050 10051- (instancetype)init { 10052 return [self initWithUInt32s:NULL forKeys:NULL count:0]; 10053} 10054 10055- (instancetype)initWithUInt32s:(const uint32_t [])values 10056 forKeys:(const BOOL [])keys 10057 count:(NSUInteger)count { 10058 self = [super init]; 10059 if (self) { 10060 for (NSUInteger i = 0; i < count; ++i) { 10061 int idx = keys[i] ? 1 : 0; 10062 _values[idx] = values[i]; 10063 _valueSet[idx] = YES; 10064 } 10065 } 10066 return self; 10067} 10068 10069- (instancetype)initWithDictionary:(GPBBoolUInt32Dictionary *)dictionary { 10070 self = [self initWithUInt32s:NULL forKeys:NULL count:0]; 10071 if (self) { 10072 if (dictionary) { 10073 for (int i = 0; i < 2; ++i) { 10074 if (dictionary->_valueSet[i]) { 10075 _values[i] = dictionary->_values[i]; 10076 _valueSet[i] = YES; 10077 } 10078 } 10079 } 10080 } 10081 return self; 10082} 10083 10084- (instancetype)initWithCapacity:(NSUInteger)numItems { 10085 #pragma unused(numItems) 10086 return [self initWithUInt32s:NULL forKeys:NULL count:0]; 10087} 10088 10089#if !defined(NS_BLOCK_ASSERTIONS) 10090- (void)dealloc { 10091 NSAssert(!_autocreator, 10092 @"%@: Autocreator must be cleared before release, autocreator: %@", 10093 [self class], _autocreator); 10094 [super dealloc]; 10095} 10096#endif // !defined(NS_BLOCK_ASSERTIONS) 10097 10098- (instancetype)copyWithZone:(NSZone *)zone { 10099 return [[GPBBoolUInt32Dictionary allocWithZone:zone] initWithDictionary:self]; 10100} 10101 10102- (BOOL)isEqual:(id)other { 10103 if (self == other) { 10104 return YES; 10105 } 10106 if (![other isKindOfClass:[GPBBoolUInt32Dictionary class]]) { 10107 return NO; 10108 } 10109 GPBBoolUInt32Dictionary *otherDictionary = other; 10110 if ((_valueSet[0] != otherDictionary->_valueSet[0]) || 10111 (_valueSet[1] != otherDictionary->_valueSet[1])) { 10112 return NO; 10113 } 10114 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) || 10115 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) { 10116 return NO; 10117 } 10118 return YES; 10119} 10120 10121- (NSUInteger)hash { 10122 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); 10123} 10124 10125- (NSString *)description { 10126 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self]; 10127 if (_valueSet[0]) { 10128 [result appendFormat:@"NO: %u", _values[0]]; 10129 } 10130 if (_valueSet[1]) { 10131 [result appendFormat:@"YES: %u", _values[1]]; 10132 } 10133 [result appendString:@" }"]; 10134 return result; 10135} 10136 10137- (NSUInteger)count { 10138 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); 10139} 10140 10141- (BOOL)getUInt32:(uint32_t *)value forKey:(BOOL)key { 10142 int idx = (key ? 1 : 0); 10143 if (_valueSet[idx]) { 10144 if (value) { 10145 *value = _values[idx]; 10146 } 10147 return YES; 10148 } 10149 return NO; 10150} 10151 10152- (void)setGPBGenericValue:(GPBGenericValue *)value 10153 forGPBGenericValueKey:(GPBGenericValue *)key { 10154 int idx = (key->valueBool ? 1 : 0); 10155 _values[idx] = value->valueUInt32; 10156 _valueSet[idx] = YES; 10157} 10158 10159- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 10160 if (_valueSet[0]) { 10161 block(@"false", [NSString stringWithFormat:@"%u", _values[0]]); 10162 } 10163 if (_valueSet[1]) { 10164 block(@"true", [NSString stringWithFormat:@"%u", _values[1]]); 10165 } 10166} 10167 10168- (void)enumerateKeysAndUInt32sUsingBlock: 10169 (void (NS_NOESCAPE ^)(BOOL key, uint32_t value, BOOL *stop))block { 10170 BOOL stop = NO; 10171 if (_valueSet[0]) { 10172 block(NO, _values[0], &stop); 10173 } 10174 if (!stop && _valueSet[1]) { 10175 block(YES, _values[1], &stop); 10176 } 10177} 10178 10179- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 10180 GPBDataType valueDataType = GPBGetFieldDataType(field); 10181 NSUInteger count = 0; 10182 size_t result = 0; 10183 for (int i = 0; i < 2; ++i) { 10184 if (_valueSet[i]) { 10185 ++count; 10186 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool); 10187 msgSize += ComputeDictUInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType); 10188 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 10189 } 10190 } 10191 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 10192 result += tagSize * count; 10193 return result; 10194} 10195 10196- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 10197 asField:(GPBFieldDescriptor *)field { 10198 GPBDataType valueDataType = GPBGetFieldDataType(field); 10199 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 10200 for (int i = 0; i < 2; ++i) { 10201 if (_valueSet[i]) { 10202 // Write the tag. 10203 [outputStream writeInt32NoTag:tag]; 10204 // Write the size of the message. 10205 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool); 10206 msgSize += ComputeDictUInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType); 10207 [outputStream writeInt32NoTag:(int32_t)msgSize]; 10208 // Write the fields. 10209 WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool); 10210 WriteDictUInt32Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType); 10211 } 10212 } 10213} 10214 10215- (void)addEntriesFromDictionary:(GPBBoolUInt32Dictionary *)otherDictionary { 10216 if (otherDictionary) { 10217 for (int i = 0; i < 2; ++i) { 10218 if (otherDictionary->_valueSet[i]) { 10219 _valueSet[i] = YES; 10220 _values[i] = otherDictionary->_values[i]; 10221 } 10222 } 10223 if (_autocreator) { 10224 GPBAutocreatedDictionaryModified(_autocreator, self); 10225 } 10226 } 10227} 10228 10229- (void)setUInt32:(uint32_t)value forKey:(BOOL)key { 10230 int idx = (key ? 1 : 0); 10231 _values[idx] = value; 10232 _valueSet[idx] = YES; 10233 if (_autocreator) { 10234 GPBAutocreatedDictionaryModified(_autocreator, self); 10235 } 10236} 10237 10238- (void)removeUInt32ForKey:(BOOL)aKey { 10239 _valueSet[aKey ? 1 : 0] = NO; 10240} 10241 10242- (void)removeAll { 10243 _valueSet[0] = NO; 10244 _valueSet[1] = NO; 10245} 10246 10247@end 10248 10249// clang-format on 10250//%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Int32, int32_t) 10251// This block of code is generated, do not edit it directly. 10252// clang-format off 10253 10254#pragma mark - Bool -> Int32 10255 10256@implementation GPBBoolInt32Dictionary { 10257 @package 10258 int32_t _values[2]; 10259 BOOL _valueSet[2]; 10260} 10261 10262- (instancetype)init { 10263 return [self initWithInt32s:NULL forKeys:NULL count:0]; 10264} 10265 10266- (instancetype)initWithInt32s:(const int32_t [])values 10267 forKeys:(const BOOL [])keys 10268 count:(NSUInteger)count { 10269 self = [super init]; 10270 if (self) { 10271 for (NSUInteger i = 0; i < count; ++i) { 10272 int idx = keys[i] ? 1 : 0; 10273 _values[idx] = values[i]; 10274 _valueSet[idx] = YES; 10275 } 10276 } 10277 return self; 10278} 10279 10280- (instancetype)initWithDictionary:(GPBBoolInt32Dictionary *)dictionary { 10281 self = [self initWithInt32s:NULL forKeys:NULL count:0]; 10282 if (self) { 10283 if (dictionary) { 10284 for (int i = 0; i < 2; ++i) { 10285 if (dictionary->_valueSet[i]) { 10286 _values[i] = dictionary->_values[i]; 10287 _valueSet[i] = YES; 10288 } 10289 } 10290 } 10291 } 10292 return self; 10293} 10294 10295- (instancetype)initWithCapacity:(NSUInteger)numItems { 10296 #pragma unused(numItems) 10297 return [self initWithInt32s:NULL forKeys:NULL count:0]; 10298} 10299 10300#if !defined(NS_BLOCK_ASSERTIONS) 10301- (void)dealloc { 10302 NSAssert(!_autocreator, 10303 @"%@: Autocreator must be cleared before release, autocreator: %@", 10304 [self class], _autocreator); 10305 [super dealloc]; 10306} 10307#endif // !defined(NS_BLOCK_ASSERTIONS) 10308 10309- (instancetype)copyWithZone:(NSZone *)zone { 10310 return [[GPBBoolInt32Dictionary allocWithZone:zone] initWithDictionary:self]; 10311} 10312 10313- (BOOL)isEqual:(id)other { 10314 if (self == other) { 10315 return YES; 10316 } 10317 if (![other isKindOfClass:[GPBBoolInt32Dictionary class]]) { 10318 return NO; 10319 } 10320 GPBBoolInt32Dictionary *otherDictionary = other; 10321 if ((_valueSet[0] != otherDictionary->_valueSet[0]) || 10322 (_valueSet[1] != otherDictionary->_valueSet[1])) { 10323 return NO; 10324 } 10325 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) || 10326 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) { 10327 return NO; 10328 } 10329 return YES; 10330} 10331 10332- (NSUInteger)hash { 10333 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); 10334} 10335 10336- (NSString *)description { 10337 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self]; 10338 if (_valueSet[0]) { 10339 [result appendFormat:@"NO: %d", _values[0]]; 10340 } 10341 if (_valueSet[1]) { 10342 [result appendFormat:@"YES: %d", _values[1]]; 10343 } 10344 [result appendString:@" }"]; 10345 return result; 10346} 10347 10348- (NSUInteger)count { 10349 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); 10350} 10351 10352- (BOOL)getInt32:(int32_t *)value forKey:(BOOL)key { 10353 int idx = (key ? 1 : 0); 10354 if (_valueSet[idx]) { 10355 if (value) { 10356 *value = _values[idx]; 10357 } 10358 return YES; 10359 } 10360 return NO; 10361} 10362 10363- (void)setGPBGenericValue:(GPBGenericValue *)value 10364 forGPBGenericValueKey:(GPBGenericValue *)key { 10365 int idx = (key->valueBool ? 1 : 0); 10366 _values[idx] = value->valueInt32; 10367 _valueSet[idx] = YES; 10368} 10369 10370- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 10371 if (_valueSet[0]) { 10372 block(@"false", [NSString stringWithFormat:@"%d", _values[0]]); 10373 } 10374 if (_valueSet[1]) { 10375 block(@"true", [NSString stringWithFormat:@"%d", _values[1]]); 10376 } 10377} 10378 10379- (void)enumerateKeysAndInt32sUsingBlock: 10380 (void (NS_NOESCAPE ^)(BOOL key, int32_t value, BOOL *stop))block { 10381 BOOL stop = NO; 10382 if (_valueSet[0]) { 10383 block(NO, _values[0], &stop); 10384 } 10385 if (!stop && _valueSet[1]) { 10386 block(YES, _values[1], &stop); 10387 } 10388} 10389 10390- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 10391 GPBDataType valueDataType = GPBGetFieldDataType(field); 10392 NSUInteger count = 0; 10393 size_t result = 0; 10394 for (int i = 0; i < 2; ++i) { 10395 if (_valueSet[i]) { 10396 ++count; 10397 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool); 10398 msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType); 10399 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 10400 } 10401 } 10402 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 10403 result += tagSize * count; 10404 return result; 10405} 10406 10407- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 10408 asField:(GPBFieldDescriptor *)field { 10409 GPBDataType valueDataType = GPBGetFieldDataType(field); 10410 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 10411 for (int i = 0; i < 2; ++i) { 10412 if (_valueSet[i]) { 10413 // Write the tag. 10414 [outputStream writeInt32NoTag:tag]; 10415 // Write the size of the message. 10416 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool); 10417 msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType); 10418 [outputStream writeInt32NoTag:(int32_t)msgSize]; 10419 // Write the fields. 10420 WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool); 10421 WriteDictInt32Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType); 10422 } 10423 } 10424} 10425 10426- (void)addEntriesFromDictionary:(GPBBoolInt32Dictionary *)otherDictionary { 10427 if (otherDictionary) { 10428 for (int i = 0; i < 2; ++i) { 10429 if (otherDictionary->_valueSet[i]) { 10430 _valueSet[i] = YES; 10431 _values[i] = otherDictionary->_values[i]; 10432 } 10433 } 10434 if (_autocreator) { 10435 GPBAutocreatedDictionaryModified(_autocreator, self); 10436 } 10437 } 10438} 10439 10440- (void)setInt32:(int32_t)value forKey:(BOOL)key { 10441 int idx = (key ? 1 : 0); 10442 _values[idx] = value; 10443 _valueSet[idx] = YES; 10444 if (_autocreator) { 10445 GPBAutocreatedDictionaryModified(_autocreator, self); 10446 } 10447} 10448 10449- (void)removeInt32ForKey:(BOOL)aKey { 10450 _valueSet[aKey ? 1 : 0] = NO; 10451} 10452 10453- (void)removeAll { 10454 _valueSet[0] = NO; 10455 _valueSet[1] = NO; 10456} 10457 10458@end 10459 10460// clang-format on 10461//%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(UInt64, uint64_t) 10462// This block of code is generated, do not edit it directly. 10463// clang-format off 10464 10465#pragma mark - Bool -> UInt64 10466 10467@implementation GPBBoolUInt64Dictionary { 10468 @package 10469 uint64_t _values[2]; 10470 BOOL _valueSet[2]; 10471} 10472 10473- (instancetype)init { 10474 return [self initWithUInt64s:NULL forKeys:NULL count:0]; 10475} 10476 10477- (instancetype)initWithUInt64s:(const uint64_t [])values 10478 forKeys:(const BOOL [])keys 10479 count:(NSUInteger)count { 10480 self = [super init]; 10481 if (self) { 10482 for (NSUInteger i = 0; i < count; ++i) { 10483 int idx = keys[i] ? 1 : 0; 10484 _values[idx] = values[i]; 10485 _valueSet[idx] = YES; 10486 } 10487 } 10488 return self; 10489} 10490 10491- (instancetype)initWithDictionary:(GPBBoolUInt64Dictionary *)dictionary { 10492 self = [self initWithUInt64s:NULL forKeys:NULL count:0]; 10493 if (self) { 10494 if (dictionary) { 10495 for (int i = 0; i < 2; ++i) { 10496 if (dictionary->_valueSet[i]) { 10497 _values[i] = dictionary->_values[i]; 10498 _valueSet[i] = YES; 10499 } 10500 } 10501 } 10502 } 10503 return self; 10504} 10505 10506- (instancetype)initWithCapacity:(NSUInteger)numItems { 10507 #pragma unused(numItems) 10508 return [self initWithUInt64s:NULL forKeys:NULL count:0]; 10509} 10510 10511#if !defined(NS_BLOCK_ASSERTIONS) 10512- (void)dealloc { 10513 NSAssert(!_autocreator, 10514 @"%@: Autocreator must be cleared before release, autocreator: %@", 10515 [self class], _autocreator); 10516 [super dealloc]; 10517} 10518#endif // !defined(NS_BLOCK_ASSERTIONS) 10519 10520- (instancetype)copyWithZone:(NSZone *)zone { 10521 return [[GPBBoolUInt64Dictionary allocWithZone:zone] initWithDictionary:self]; 10522} 10523 10524- (BOOL)isEqual:(id)other { 10525 if (self == other) { 10526 return YES; 10527 } 10528 if (![other isKindOfClass:[GPBBoolUInt64Dictionary class]]) { 10529 return NO; 10530 } 10531 GPBBoolUInt64Dictionary *otherDictionary = other; 10532 if ((_valueSet[0] != otherDictionary->_valueSet[0]) || 10533 (_valueSet[1] != otherDictionary->_valueSet[1])) { 10534 return NO; 10535 } 10536 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) || 10537 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) { 10538 return NO; 10539 } 10540 return YES; 10541} 10542 10543- (NSUInteger)hash { 10544 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); 10545} 10546 10547- (NSString *)description { 10548 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self]; 10549 if (_valueSet[0]) { 10550 [result appendFormat:@"NO: %llu", _values[0]]; 10551 } 10552 if (_valueSet[1]) { 10553 [result appendFormat:@"YES: %llu", _values[1]]; 10554 } 10555 [result appendString:@" }"]; 10556 return result; 10557} 10558 10559- (NSUInteger)count { 10560 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); 10561} 10562 10563- (BOOL)getUInt64:(uint64_t *)value forKey:(BOOL)key { 10564 int idx = (key ? 1 : 0); 10565 if (_valueSet[idx]) { 10566 if (value) { 10567 *value = _values[idx]; 10568 } 10569 return YES; 10570 } 10571 return NO; 10572} 10573 10574- (void)setGPBGenericValue:(GPBGenericValue *)value 10575 forGPBGenericValueKey:(GPBGenericValue *)key { 10576 int idx = (key->valueBool ? 1 : 0); 10577 _values[idx] = value->valueUInt64; 10578 _valueSet[idx] = YES; 10579} 10580 10581- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 10582 if (_valueSet[0]) { 10583 block(@"false", [NSString stringWithFormat:@"%llu", _values[0]]); 10584 } 10585 if (_valueSet[1]) { 10586 block(@"true", [NSString stringWithFormat:@"%llu", _values[1]]); 10587 } 10588} 10589 10590- (void)enumerateKeysAndUInt64sUsingBlock: 10591 (void (NS_NOESCAPE ^)(BOOL key, uint64_t value, BOOL *stop))block { 10592 BOOL stop = NO; 10593 if (_valueSet[0]) { 10594 block(NO, _values[0], &stop); 10595 } 10596 if (!stop && _valueSet[1]) { 10597 block(YES, _values[1], &stop); 10598 } 10599} 10600 10601- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 10602 GPBDataType valueDataType = GPBGetFieldDataType(field); 10603 NSUInteger count = 0; 10604 size_t result = 0; 10605 for (int i = 0; i < 2; ++i) { 10606 if (_valueSet[i]) { 10607 ++count; 10608 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool); 10609 msgSize += ComputeDictUInt64FieldSize(_values[i], kMapValueFieldNumber, valueDataType); 10610 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 10611 } 10612 } 10613 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 10614 result += tagSize * count; 10615 return result; 10616} 10617 10618- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 10619 asField:(GPBFieldDescriptor *)field { 10620 GPBDataType valueDataType = GPBGetFieldDataType(field); 10621 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 10622 for (int i = 0; i < 2; ++i) { 10623 if (_valueSet[i]) { 10624 // Write the tag. 10625 [outputStream writeInt32NoTag:tag]; 10626 // Write the size of the message. 10627 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool); 10628 msgSize += ComputeDictUInt64FieldSize(_values[i], kMapValueFieldNumber, valueDataType); 10629 [outputStream writeInt32NoTag:(int32_t)msgSize]; 10630 // Write the fields. 10631 WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool); 10632 WriteDictUInt64Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType); 10633 } 10634 } 10635} 10636 10637- (void)addEntriesFromDictionary:(GPBBoolUInt64Dictionary *)otherDictionary { 10638 if (otherDictionary) { 10639 for (int i = 0; i < 2; ++i) { 10640 if (otherDictionary->_valueSet[i]) { 10641 _valueSet[i] = YES; 10642 _values[i] = otherDictionary->_values[i]; 10643 } 10644 } 10645 if (_autocreator) { 10646 GPBAutocreatedDictionaryModified(_autocreator, self); 10647 } 10648 } 10649} 10650 10651- (void)setUInt64:(uint64_t)value forKey:(BOOL)key { 10652 int idx = (key ? 1 : 0); 10653 _values[idx] = value; 10654 _valueSet[idx] = YES; 10655 if (_autocreator) { 10656 GPBAutocreatedDictionaryModified(_autocreator, self); 10657 } 10658} 10659 10660- (void)removeUInt64ForKey:(BOOL)aKey { 10661 _valueSet[aKey ? 1 : 0] = NO; 10662} 10663 10664- (void)removeAll { 10665 _valueSet[0] = NO; 10666 _valueSet[1] = NO; 10667} 10668 10669@end 10670 10671// clang-format on 10672//%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Int64, int64_t) 10673// This block of code is generated, do not edit it directly. 10674// clang-format off 10675 10676#pragma mark - Bool -> Int64 10677 10678@implementation GPBBoolInt64Dictionary { 10679 @package 10680 int64_t _values[2]; 10681 BOOL _valueSet[2]; 10682} 10683 10684- (instancetype)init { 10685 return [self initWithInt64s:NULL forKeys:NULL count:0]; 10686} 10687 10688- (instancetype)initWithInt64s:(const int64_t [])values 10689 forKeys:(const BOOL [])keys 10690 count:(NSUInteger)count { 10691 self = [super init]; 10692 if (self) { 10693 for (NSUInteger i = 0; i < count; ++i) { 10694 int idx = keys[i] ? 1 : 0; 10695 _values[idx] = values[i]; 10696 _valueSet[idx] = YES; 10697 } 10698 } 10699 return self; 10700} 10701 10702- (instancetype)initWithDictionary:(GPBBoolInt64Dictionary *)dictionary { 10703 self = [self initWithInt64s:NULL forKeys:NULL count:0]; 10704 if (self) { 10705 if (dictionary) { 10706 for (int i = 0; i < 2; ++i) { 10707 if (dictionary->_valueSet[i]) { 10708 _values[i] = dictionary->_values[i]; 10709 _valueSet[i] = YES; 10710 } 10711 } 10712 } 10713 } 10714 return self; 10715} 10716 10717- (instancetype)initWithCapacity:(NSUInteger)numItems { 10718 #pragma unused(numItems) 10719 return [self initWithInt64s:NULL forKeys:NULL count:0]; 10720} 10721 10722#if !defined(NS_BLOCK_ASSERTIONS) 10723- (void)dealloc { 10724 NSAssert(!_autocreator, 10725 @"%@: Autocreator must be cleared before release, autocreator: %@", 10726 [self class], _autocreator); 10727 [super dealloc]; 10728} 10729#endif // !defined(NS_BLOCK_ASSERTIONS) 10730 10731- (instancetype)copyWithZone:(NSZone *)zone { 10732 return [[GPBBoolInt64Dictionary allocWithZone:zone] initWithDictionary:self]; 10733} 10734 10735- (BOOL)isEqual:(id)other { 10736 if (self == other) { 10737 return YES; 10738 } 10739 if (![other isKindOfClass:[GPBBoolInt64Dictionary class]]) { 10740 return NO; 10741 } 10742 GPBBoolInt64Dictionary *otherDictionary = other; 10743 if ((_valueSet[0] != otherDictionary->_valueSet[0]) || 10744 (_valueSet[1] != otherDictionary->_valueSet[1])) { 10745 return NO; 10746 } 10747 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) || 10748 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) { 10749 return NO; 10750 } 10751 return YES; 10752} 10753 10754- (NSUInteger)hash { 10755 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); 10756} 10757 10758- (NSString *)description { 10759 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self]; 10760 if (_valueSet[0]) { 10761 [result appendFormat:@"NO: %lld", _values[0]]; 10762 } 10763 if (_valueSet[1]) { 10764 [result appendFormat:@"YES: %lld", _values[1]]; 10765 } 10766 [result appendString:@" }"]; 10767 return result; 10768} 10769 10770- (NSUInteger)count { 10771 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); 10772} 10773 10774- (BOOL)getInt64:(int64_t *)value forKey:(BOOL)key { 10775 int idx = (key ? 1 : 0); 10776 if (_valueSet[idx]) { 10777 if (value) { 10778 *value = _values[idx]; 10779 } 10780 return YES; 10781 } 10782 return NO; 10783} 10784 10785- (void)setGPBGenericValue:(GPBGenericValue *)value 10786 forGPBGenericValueKey:(GPBGenericValue *)key { 10787 int idx = (key->valueBool ? 1 : 0); 10788 _values[idx] = value->valueInt64; 10789 _valueSet[idx] = YES; 10790} 10791 10792- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 10793 if (_valueSet[0]) { 10794 block(@"false", [NSString stringWithFormat:@"%lld", _values[0]]); 10795 } 10796 if (_valueSet[1]) { 10797 block(@"true", [NSString stringWithFormat:@"%lld", _values[1]]); 10798 } 10799} 10800 10801- (void)enumerateKeysAndInt64sUsingBlock: 10802 (void (NS_NOESCAPE ^)(BOOL key, int64_t value, BOOL *stop))block { 10803 BOOL stop = NO; 10804 if (_valueSet[0]) { 10805 block(NO, _values[0], &stop); 10806 } 10807 if (!stop && _valueSet[1]) { 10808 block(YES, _values[1], &stop); 10809 } 10810} 10811 10812- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 10813 GPBDataType valueDataType = GPBGetFieldDataType(field); 10814 NSUInteger count = 0; 10815 size_t result = 0; 10816 for (int i = 0; i < 2; ++i) { 10817 if (_valueSet[i]) { 10818 ++count; 10819 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool); 10820 msgSize += ComputeDictInt64FieldSize(_values[i], kMapValueFieldNumber, valueDataType); 10821 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 10822 } 10823 } 10824 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 10825 result += tagSize * count; 10826 return result; 10827} 10828 10829- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 10830 asField:(GPBFieldDescriptor *)field { 10831 GPBDataType valueDataType = GPBGetFieldDataType(field); 10832 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 10833 for (int i = 0; i < 2; ++i) { 10834 if (_valueSet[i]) { 10835 // Write the tag. 10836 [outputStream writeInt32NoTag:tag]; 10837 // Write the size of the message. 10838 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool); 10839 msgSize += ComputeDictInt64FieldSize(_values[i], kMapValueFieldNumber, valueDataType); 10840 [outputStream writeInt32NoTag:(int32_t)msgSize]; 10841 // Write the fields. 10842 WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool); 10843 WriteDictInt64Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType); 10844 } 10845 } 10846} 10847 10848- (void)addEntriesFromDictionary:(GPBBoolInt64Dictionary *)otherDictionary { 10849 if (otherDictionary) { 10850 for (int i = 0; i < 2; ++i) { 10851 if (otherDictionary->_valueSet[i]) { 10852 _valueSet[i] = YES; 10853 _values[i] = otherDictionary->_values[i]; 10854 } 10855 } 10856 if (_autocreator) { 10857 GPBAutocreatedDictionaryModified(_autocreator, self); 10858 } 10859 } 10860} 10861 10862- (void)setInt64:(int64_t)value forKey:(BOOL)key { 10863 int idx = (key ? 1 : 0); 10864 _values[idx] = value; 10865 _valueSet[idx] = YES; 10866 if (_autocreator) { 10867 GPBAutocreatedDictionaryModified(_autocreator, self); 10868 } 10869} 10870 10871- (void)removeInt64ForKey:(BOOL)aKey { 10872 _valueSet[aKey ? 1 : 0] = NO; 10873} 10874 10875- (void)removeAll { 10876 _valueSet[0] = NO; 10877 _valueSet[1] = NO; 10878} 10879 10880@end 10881 10882// clang-format on 10883//%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Bool, BOOL) 10884// This block of code is generated, do not edit it directly. 10885// clang-format off 10886 10887#pragma mark - Bool -> Bool 10888 10889@implementation GPBBoolBoolDictionary { 10890 @package 10891 BOOL _values[2]; 10892 BOOL _valueSet[2]; 10893} 10894 10895- (instancetype)init { 10896 return [self initWithBools:NULL forKeys:NULL count:0]; 10897} 10898 10899- (instancetype)initWithBools:(const BOOL [])values 10900 forKeys:(const BOOL [])keys 10901 count:(NSUInteger)count { 10902 self = [super init]; 10903 if (self) { 10904 for (NSUInteger i = 0; i < count; ++i) { 10905 int idx = keys[i] ? 1 : 0; 10906 _values[idx] = values[i]; 10907 _valueSet[idx] = YES; 10908 } 10909 } 10910 return self; 10911} 10912 10913- (instancetype)initWithDictionary:(GPBBoolBoolDictionary *)dictionary { 10914 self = [self initWithBools:NULL forKeys:NULL count:0]; 10915 if (self) { 10916 if (dictionary) { 10917 for (int i = 0; i < 2; ++i) { 10918 if (dictionary->_valueSet[i]) { 10919 _values[i] = dictionary->_values[i]; 10920 _valueSet[i] = YES; 10921 } 10922 } 10923 } 10924 } 10925 return self; 10926} 10927 10928- (instancetype)initWithCapacity:(NSUInteger)numItems { 10929 #pragma unused(numItems) 10930 return [self initWithBools:NULL forKeys:NULL count:0]; 10931} 10932 10933#if !defined(NS_BLOCK_ASSERTIONS) 10934- (void)dealloc { 10935 NSAssert(!_autocreator, 10936 @"%@: Autocreator must be cleared before release, autocreator: %@", 10937 [self class], _autocreator); 10938 [super dealloc]; 10939} 10940#endif // !defined(NS_BLOCK_ASSERTIONS) 10941 10942- (instancetype)copyWithZone:(NSZone *)zone { 10943 return [[GPBBoolBoolDictionary allocWithZone:zone] initWithDictionary:self]; 10944} 10945 10946- (BOOL)isEqual:(id)other { 10947 if (self == other) { 10948 return YES; 10949 } 10950 if (![other isKindOfClass:[GPBBoolBoolDictionary class]]) { 10951 return NO; 10952 } 10953 GPBBoolBoolDictionary *otherDictionary = other; 10954 if ((_valueSet[0] != otherDictionary->_valueSet[0]) || 10955 (_valueSet[1] != otherDictionary->_valueSet[1])) { 10956 return NO; 10957 } 10958 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) || 10959 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) { 10960 return NO; 10961 } 10962 return YES; 10963} 10964 10965- (NSUInteger)hash { 10966 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); 10967} 10968 10969- (NSString *)description { 10970 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self]; 10971 if (_valueSet[0]) { 10972 [result appendFormat:@"NO: %d", _values[0]]; 10973 } 10974 if (_valueSet[1]) { 10975 [result appendFormat:@"YES: %d", _values[1]]; 10976 } 10977 [result appendString:@" }"]; 10978 return result; 10979} 10980 10981- (NSUInteger)count { 10982 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); 10983} 10984 10985- (BOOL)getBool:(BOOL *)value forKey:(BOOL)key { 10986 int idx = (key ? 1 : 0); 10987 if (_valueSet[idx]) { 10988 if (value) { 10989 *value = _values[idx]; 10990 } 10991 return YES; 10992 } 10993 return NO; 10994} 10995 10996- (void)setGPBGenericValue:(GPBGenericValue *)value 10997 forGPBGenericValueKey:(GPBGenericValue *)key { 10998 int idx = (key->valueBool ? 1 : 0); 10999 _values[idx] = value->valueBool; 11000 _valueSet[idx] = YES; 11001} 11002 11003- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 11004 if (_valueSet[0]) { 11005 block(@"false", (_values[0] ? @"true" : @"false")); 11006 } 11007 if (_valueSet[1]) { 11008 block(@"true", (_values[1] ? @"true" : @"false")); 11009 } 11010} 11011 11012- (void)enumerateKeysAndBoolsUsingBlock: 11013 (void (NS_NOESCAPE ^)(BOOL key, BOOL value, BOOL *stop))block { 11014 BOOL stop = NO; 11015 if (_valueSet[0]) { 11016 block(NO, _values[0], &stop); 11017 } 11018 if (!stop && _valueSet[1]) { 11019 block(YES, _values[1], &stop); 11020 } 11021} 11022 11023- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 11024 GPBDataType valueDataType = GPBGetFieldDataType(field); 11025 NSUInteger count = 0; 11026 size_t result = 0; 11027 for (int i = 0; i < 2; ++i) { 11028 if (_valueSet[i]) { 11029 ++count; 11030 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool); 11031 msgSize += ComputeDictBoolFieldSize(_values[i], kMapValueFieldNumber, valueDataType); 11032 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 11033 } 11034 } 11035 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 11036 result += tagSize * count; 11037 return result; 11038} 11039 11040- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 11041 asField:(GPBFieldDescriptor *)field { 11042 GPBDataType valueDataType = GPBGetFieldDataType(field); 11043 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 11044 for (int i = 0; i < 2; ++i) { 11045 if (_valueSet[i]) { 11046 // Write the tag. 11047 [outputStream writeInt32NoTag:tag]; 11048 // Write the size of the message. 11049 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool); 11050 msgSize += ComputeDictBoolFieldSize(_values[i], kMapValueFieldNumber, valueDataType); 11051 [outputStream writeInt32NoTag:(int32_t)msgSize]; 11052 // Write the fields. 11053 WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool); 11054 WriteDictBoolField(outputStream, _values[i], kMapValueFieldNumber, valueDataType); 11055 } 11056 } 11057} 11058 11059- (void)addEntriesFromDictionary:(GPBBoolBoolDictionary *)otherDictionary { 11060 if (otherDictionary) { 11061 for (int i = 0; i < 2; ++i) { 11062 if (otherDictionary->_valueSet[i]) { 11063 _valueSet[i] = YES; 11064 _values[i] = otherDictionary->_values[i]; 11065 } 11066 } 11067 if (_autocreator) { 11068 GPBAutocreatedDictionaryModified(_autocreator, self); 11069 } 11070 } 11071} 11072 11073- (void)setBool:(BOOL)value forKey:(BOOL)key { 11074 int idx = (key ? 1 : 0); 11075 _values[idx] = value; 11076 _valueSet[idx] = YES; 11077 if (_autocreator) { 11078 GPBAutocreatedDictionaryModified(_autocreator, self); 11079 } 11080} 11081 11082- (void)removeBoolForKey:(BOOL)aKey { 11083 _valueSet[aKey ? 1 : 0] = NO; 11084} 11085 11086- (void)removeAll { 11087 _valueSet[0] = NO; 11088 _valueSet[1] = NO; 11089} 11090 11091@end 11092 11093// clang-format on 11094//%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Float, float) 11095// This block of code is generated, do not edit it directly. 11096// clang-format off 11097 11098#pragma mark - Bool -> Float 11099 11100@implementation GPBBoolFloatDictionary { 11101 @package 11102 float _values[2]; 11103 BOOL _valueSet[2]; 11104} 11105 11106- (instancetype)init { 11107 return [self initWithFloats:NULL forKeys:NULL count:0]; 11108} 11109 11110- (instancetype)initWithFloats:(const float [])values 11111 forKeys:(const BOOL [])keys 11112 count:(NSUInteger)count { 11113 self = [super init]; 11114 if (self) { 11115 for (NSUInteger i = 0; i < count; ++i) { 11116 int idx = keys[i] ? 1 : 0; 11117 _values[idx] = values[i]; 11118 _valueSet[idx] = YES; 11119 } 11120 } 11121 return self; 11122} 11123 11124- (instancetype)initWithDictionary:(GPBBoolFloatDictionary *)dictionary { 11125 self = [self initWithFloats:NULL forKeys:NULL count:0]; 11126 if (self) { 11127 if (dictionary) { 11128 for (int i = 0; i < 2; ++i) { 11129 if (dictionary->_valueSet[i]) { 11130 _values[i] = dictionary->_values[i]; 11131 _valueSet[i] = YES; 11132 } 11133 } 11134 } 11135 } 11136 return self; 11137} 11138 11139- (instancetype)initWithCapacity:(NSUInteger)numItems { 11140 #pragma unused(numItems) 11141 return [self initWithFloats:NULL forKeys:NULL count:0]; 11142} 11143 11144#if !defined(NS_BLOCK_ASSERTIONS) 11145- (void)dealloc { 11146 NSAssert(!_autocreator, 11147 @"%@: Autocreator must be cleared before release, autocreator: %@", 11148 [self class], _autocreator); 11149 [super dealloc]; 11150} 11151#endif // !defined(NS_BLOCK_ASSERTIONS) 11152 11153- (instancetype)copyWithZone:(NSZone *)zone { 11154 return [[GPBBoolFloatDictionary allocWithZone:zone] initWithDictionary:self]; 11155} 11156 11157- (BOOL)isEqual:(id)other { 11158 if (self == other) { 11159 return YES; 11160 } 11161 if (![other isKindOfClass:[GPBBoolFloatDictionary class]]) { 11162 return NO; 11163 } 11164 GPBBoolFloatDictionary *otherDictionary = other; 11165 if ((_valueSet[0] != otherDictionary->_valueSet[0]) || 11166 (_valueSet[1] != otherDictionary->_valueSet[1])) { 11167 return NO; 11168 } 11169 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) || 11170 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) { 11171 return NO; 11172 } 11173 return YES; 11174} 11175 11176- (NSUInteger)hash { 11177 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); 11178} 11179 11180- (NSString *)description { 11181 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self]; 11182 if (_valueSet[0]) { 11183 [result appendFormat:@"NO: %f", _values[0]]; 11184 } 11185 if (_valueSet[1]) { 11186 [result appendFormat:@"YES: %f", _values[1]]; 11187 } 11188 [result appendString:@" }"]; 11189 return result; 11190} 11191 11192- (NSUInteger)count { 11193 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); 11194} 11195 11196- (BOOL)getFloat:(float *)value forKey:(BOOL)key { 11197 int idx = (key ? 1 : 0); 11198 if (_valueSet[idx]) { 11199 if (value) { 11200 *value = _values[idx]; 11201 } 11202 return YES; 11203 } 11204 return NO; 11205} 11206 11207- (void)setGPBGenericValue:(GPBGenericValue *)value 11208 forGPBGenericValueKey:(GPBGenericValue *)key { 11209 int idx = (key->valueBool ? 1 : 0); 11210 _values[idx] = value->valueFloat; 11211 _valueSet[idx] = YES; 11212} 11213 11214- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 11215 if (_valueSet[0]) { 11216 block(@"false", [NSString stringWithFormat:@"%.*g", FLT_DIG, _values[0]]); 11217 } 11218 if (_valueSet[1]) { 11219 block(@"true", [NSString stringWithFormat:@"%.*g", FLT_DIG, _values[1]]); 11220 } 11221} 11222 11223- (void)enumerateKeysAndFloatsUsingBlock: 11224 (void (NS_NOESCAPE ^)(BOOL key, float value, BOOL *stop))block { 11225 BOOL stop = NO; 11226 if (_valueSet[0]) { 11227 block(NO, _values[0], &stop); 11228 } 11229 if (!stop && _valueSet[1]) { 11230 block(YES, _values[1], &stop); 11231 } 11232} 11233 11234- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 11235 GPBDataType valueDataType = GPBGetFieldDataType(field); 11236 NSUInteger count = 0; 11237 size_t result = 0; 11238 for (int i = 0; i < 2; ++i) { 11239 if (_valueSet[i]) { 11240 ++count; 11241 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool); 11242 msgSize += ComputeDictFloatFieldSize(_values[i], kMapValueFieldNumber, valueDataType); 11243 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 11244 } 11245 } 11246 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 11247 result += tagSize * count; 11248 return result; 11249} 11250 11251- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 11252 asField:(GPBFieldDescriptor *)field { 11253 GPBDataType valueDataType = GPBGetFieldDataType(field); 11254 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 11255 for (int i = 0; i < 2; ++i) { 11256 if (_valueSet[i]) { 11257 // Write the tag. 11258 [outputStream writeInt32NoTag:tag]; 11259 // Write the size of the message. 11260 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool); 11261 msgSize += ComputeDictFloatFieldSize(_values[i], kMapValueFieldNumber, valueDataType); 11262 [outputStream writeInt32NoTag:(int32_t)msgSize]; 11263 // Write the fields. 11264 WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool); 11265 WriteDictFloatField(outputStream, _values[i], kMapValueFieldNumber, valueDataType); 11266 } 11267 } 11268} 11269 11270- (void)addEntriesFromDictionary:(GPBBoolFloatDictionary *)otherDictionary { 11271 if (otherDictionary) { 11272 for (int i = 0; i < 2; ++i) { 11273 if (otherDictionary->_valueSet[i]) { 11274 _valueSet[i] = YES; 11275 _values[i] = otherDictionary->_values[i]; 11276 } 11277 } 11278 if (_autocreator) { 11279 GPBAutocreatedDictionaryModified(_autocreator, self); 11280 } 11281 } 11282} 11283 11284- (void)setFloat:(float)value forKey:(BOOL)key { 11285 int idx = (key ? 1 : 0); 11286 _values[idx] = value; 11287 _valueSet[idx] = YES; 11288 if (_autocreator) { 11289 GPBAutocreatedDictionaryModified(_autocreator, self); 11290 } 11291} 11292 11293- (void)removeFloatForKey:(BOOL)aKey { 11294 _valueSet[aKey ? 1 : 0] = NO; 11295} 11296 11297- (void)removeAll { 11298 _valueSet[0] = NO; 11299 _valueSet[1] = NO; 11300} 11301 11302@end 11303 11304// clang-format on 11305//%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Double, double) 11306// This block of code is generated, do not edit it directly. 11307// clang-format off 11308 11309#pragma mark - Bool -> Double 11310 11311@implementation GPBBoolDoubleDictionary { 11312 @package 11313 double _values[2]; 11314 BOOL _valueSet[2]; 11315} 11316 11317- (instancetype)init { 11318 return [self initWithDoubles:NULL forKeys:NULL count:0]; 11319} 11320 11321- (instancetype)initWithDoubles:(const double [])values 11322 forKeys:(const BOOL [])keys 11323 count:(NSUInteger)count { 11324 self = [super init]; 11325 if (self) { 11326 for (NSUInteger i = 0; i < count; ++i) { 11327 int idx = keys[i] ? 1 : 0; 11328 _values[idx] = values[i]; 11329 _valueSet[idx] = YES; 11330 } 11331 } 11332 return self; 11333} 11334 11335- (instancetype)initWithDictionary:(GPBBoolDoubleDictionary *)dictionary { 11336 self = [self initWithDoubles:NULL forKeys:NULL count:0]; 11337 if (self) { 11338 if (dictionary) { 11339 for (int i = 0; i < 2; ++i) { 11340 if (dictionary->_valueSet[i]) { 11341 _values[i] = dictionary->_values[i]; 11342 _valueSet[i] = YES; 11343 } 11344 } 11345 } 11346 } 11347 return self; 11348} 11349 11350- (instancetype)initWithCapacity:(NSUInteger)numItems { 11351 #pragma unused(numItems) 11352 return [self initWithDoubles:NULL forKeys:NULL count:0]; 11353} 11354 11355#if !defined(NS_BLOCK_ASSERTIONS) 11356- (void)dealloc { 11357 NSAssert(!_autocreator, 11358 @"%@: Autocreator must be cleared before release, autocreator: %@", 11359 [self class], _autocreator); 11360 [super dealloc]; 11361} 11362#endif // !defined(NS_BLOCK_ASSERTIONS) 11363 11364- (instancetype)copyWithZone:(NSZone *)zone { 11365 return [[GPBBoolDoubleDictionary allocWithZone:zone] initWithDictionary:self]; 11366} 11367 11368- (BOOL)isEqual:(id)other { 11369 if (self == other) { 11370 return YES; 11371 } 11372 if (![other isKindOfClass:[GPBBoolDoubleDictionary class]]) { 11373 return NO; 11374 } 11375 GPBBoolDoubleDictionary *otherDictionary = other; 11376 if ((_valueSet[0] != otherDictionary->_valueSet[0]) || 11377 (_valueSet[1] != otherDictionary->_valueSet[1])) { 11378 return NO; 11379 } 11380 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) || 11381 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) { 11382 return NO; 11383 } 11384 return YES; 11385} 11386 11387- (NSUInteger)hash { 11388 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); 11389} 11390 11391- (NSString *)description { 11392 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self]; 11393 if (_valueSet[0]) { 11394 [result appendFormat:@"NO: %lf", _values[0]]; 11395 } 11396 if (_valueSet[1]) { 11397 [result appendFormat:@"YES: %lf", _values[1]]; 11398 } 11399 [result appendString:@" }"]; 11400 return result; 11401} 11402 11403- (NSUInteger)count { 11404 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); 11405} 11406 11407- (BOOL)getDouble:(double *)value forKey:(BOOL)key { 11408 int idx = (key ? 1 : 0); 11409 if (_valueSet[idx]) { 11410 if (value) { 11411 *value = _values[idx]; 11412 } 11413 return YES; 11414 } 11415 return NO; 11416} 11417 11418- (void)setGPBGenericValue:(GPBGenericValue *)value 11419 forGPBGenericValueKey:(GPBGenericValue *)key { 11420 int idx = (key->valueBool ? 1 : 0); 11421 _values[idx] = value->valueDouble; 11422 _valueSet[idx] = YES; 11423} 11424 11425- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 11426 if (_valueSet[0]) { 11427 block(@"false", [NSString stringWithFormat:@"%.*lg", DBL_DIG, _values[0]]); 11428 } 11429 if (_valueSet[1]) { 11430 block(@"true", [NSString stringWithFormat:@"%.*lg", DBL_DIG, _values[1]]); 11431 } 11432} 11433 11434- (void)enumerateKeysAndDoublesUsingBlock: 11435 (void (NS_NOESCAPE ^)(BOOL key, double value, BOOL *stop))block { 11436 BOOL stop = NO; 11437 if (_valueSet[0]) { 11438 block(NO, _values[0], &stop); 11439 } 11440 if (!stop && _valueSet[1]) { 11441 block(YES, _values[1], &stop); 11442 } 11443} 11444 11445- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 11446 GPBDataType valueDataType = GPBGetFieldDataType(field); 11447 NSUInteger count = 0; 11448 size_t result = 0; 11449 for (int i = 0; i < 2; ++i) { 11450 if (_valueSet[i]) { 11451 ++count; 11452 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool); 11453 msgSize += ComputeDictDoubleFieldSize(_values[i], kMapValueFieldNumber, valueDataType); 11454 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 11455 } 11456 } 11457 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 11458 result += tagSize * count; 11459 return result; 11460} 11461 11462- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 11463 asField:(GPBFieldDescriptor *)field { 11464 GPBDataType valueDataType = GPBGetFieldDataType(field); 11465 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 11466 for (int i = 0; i < 2; ++i) { 11467 if (_valueSet[i]) { 11468 // Write the tag. 11469 [outputStream writeInt32NoTag:tag]; 11470 // Write the size of the message. 11471 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool); 11472 msgSize += ComputeDictDoubleFieldSize(_values[i], kMapValueFieldNumber, valueDataType); 11473 [outputStream writeInt32NoTag:(int32_t)msgSize]; 11474 // Write the fields. 11475 WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool); 11476 WriteDictDoubleField(outputStream, _values[i], kMapValueFieldNumber, valueDataType); 11477 } 11478 } 11479} 11480 11481- (void)addEntriesFromDictionary:(GPBBoolDoubleDictionary *)otherDictionary { 11482 if (otherDictionary) { 11483 for (int i = 0; i < 2; ++i) { 11484 if (otherDictionary->_valueSet[i]) { 11485 _valueSet[i] = YES; 11486 _values[i] = otherDictionary->_values[i]; 11487 } 11488 } 11489 if (_autocreator) { 11490 GPBAutocreatedDictionaryModified(_autocreator, self); 11491 } 11492 } 11493} 11494 11495- (void)setDouble:(double)value forKey:(BOOL)key { 11496 int idx = (key ? 1 : 0); 11497 _values[idx] = value; 11498 _valueSet[idx] = YES; 11499 if (_autocreator) { 11500 GPBAutocreatedDictionaryModified(_autocreator, self); 11501 } 11502} 11503 11504- (void)removeDoubleForKey:(BOOL)aKey { 11505 _valueSet[aKey ? 1 : 0] = NO; 11506} 11507 11508- (void)removeAll { 11509 _valueSet[0] = NO; 11510 _valueSet[1] = NO; 11511} 11512 11513@end 11514 11515// clang-format on 11516//%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_OBJECT_IMPL(Object, id) 11517// This block of code is generated, do not edit it directly. 11518// clang-format off 11519 11520#pragma mark - Bool -> Object 11521 11522@implementation GPBBoolObjectDictionary { 11523 @package 11524 id _values[2]; 11525} 11526 11527- (instancetype)init { 11528 return [self initWithObjects:NULL forKeys:NULL count:0]; 11529} 11530 11531- (instancetype)initWithObjects:(const id [])objects 11532 forKeys:(const BOOL [])keys 11533 count:(NSUInteger)count { 11534 self = [super init]; 11535 if (self) { 11536 for (NSUInteger i = 0; i < count; ++i) { 11537 if (!objects[i]) { 11538 [NSException raise:NSInvalidArgumentException 11539 format:@"Attempting to add nil object to a Dictionary"]; 11540 } 11541 int idx = keys[i] ? 1 : 0; 11542 [_values[idx] release]; 11543 _values[idx] = (id)[objects[i] retain]; 11544 } 11545 } 11546 return self; 11547} 11548 11549- (instancetype)initWithDictionary:(GPBBoolObjectDictionary *)dictionary { 11550 self = [self initWithObjects:NULL forKeys:NULL count:0]; 11551 if (self) { 11552 if (dictionary) { 11553 _values[0] = [dictionary->_values[0] retain]; 11554 _values[1] = [dictionary->_values[1] retain]; 11555 } 11556 } 11557 return self; 11558} 11559 11560- (instancetype)initWithCapacity:(NSUInteger)numItems { 11561 #pragma unused(numItems) 11562 return [self initWithObjects:NULL forKeys:NULL count:0]; 11563} 11564 11565- (void)dealloc { 11566 NSAssert(!_autocreator, 11567 @"%@: Autocreator must be cleared before release, autocreator: %@", 11568 [self class], _autocreator); 11569 [_values[0] release]; 11570 [_values[1] release]; 11571 [super dealloc]; 11572} 11573 11574- (instancetype)copyWithZone:(NSZone *)zone { 11575 return [[GPBBoolObjectDictionary allocWithZone:zone] initWithDictionary:self]; 11576} 11577 11578- (BOOL)isEqual:(id)other { 11579 if (self == other) { 11580 return YES; 11581 } 11582 if (![other isKindOfClass:[GPBBoolObjectDictionary class]]) { 11583 return NO; 11584 } 11585 GPBBoolObjectDictionary *otherDictionary = other; 11586 if (((_values[0] != nil) != (otherDictionary->_values[0] != nil)) || 11587 ((_values[1] != nil) != (otherDictionary->_values[1] != nil))) { 11588 return NO; 11589 } 11590 if (((_values[0] != nil) && (![_values[0] isEqual:otherDictionary->_values[0]])) || 11591 ((_values[1] != nil) && (![_values[1] isEqual:otherDictionary->_values[1]]))) { 11592 return NO; 11593 } 11594 return YES; 11595} 11596 11597- (NSUInteger)hash { 11598 return ((_values[0] != nil) ? 1 : 0) + ((_values[1] != nil) ? 1 : 0); 11599} 11600 11601- (NSString *)description { 11602 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self]; 11603 if ((_values[0] != nil)) { 11604 [result appendFormat:@"NO: %@", _values[0]]; 11605 } 11606 if ((_values[1] != nil)) { 11607 [result appendFormat:@"YES: %@", _values[1]]; 11608 } 11609 [result appendString:@" }"]; 11610 return result; 11611} 11612 11613- (NSUInteger)count { 11614 return ((_values[0] != nil) ? 1 : 0) + ((_values[1] != nil) ? 1 : 0); 11615} 11616 11617- (id)objectForKey:(BOOL)key { 11618 return _values[key ? 1 : 0]; 11619} 11620 11621- (void)setGPBGenericValue:(GPBGenericValue *)value 11622 forGPBGenericValueKey:(GPBGenericValue *)key { 11623 int idx = (key->valueBool ? 1 : 0); 11624 [_values[idx] release]; 11625 _values[idx] = [value->valueString retain]; 11626} 11627 11628- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 11629 if (_values[0] != nil) { 11630 block(@"false", _values[0]); 11631 } 11632 if ((_values[1] != nil)) { 11633 block(@"true", _values[1]); 11634 } 11635} 11636 11637- (void)enumerateKeysAndObjectsUsingBlock: 11638 (void (NS_NOESCAPE ^)(BOOL key, id object, BOOL *stop))block { 11639 BOOL stop = NO; 11640 if (_values[0] != nil) { 11641 block(NO, _values[0], &stop); 11642 } 11643 if (!stop && (_values[1] != nil)) { 11644 block(YES, _values[1], &stop); 11645 } 11646} 11647 11648- (BOOL)isInitialized { 11649 if (_values[0] && ![_values[0] isInitialized]) { 11650 return NO; 11651 } 11652 if (_values[1] && ![_values[1] isInitialized]) { 11653 return NO; 11654 } 11655 return YES; 11656} 11657 11658- (instancetype)deepCopyWithZone:(NSZone *)zone { 11659 GPBBoolObjectDictionary *newDict = 11660 [[GPBBoolObjectDictionary alloc] init]; 11661 for (int i = 0; i < 2; ++i) { 11662 if (_values[i] != nil) { 11663 newDict->_values[i] = [_values[i] copyWithZone:zone]; 11664 } 11665 } 11666 return newDict; 11667} 11668 11669- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 11670 GPBDataType valueDataType = GPBGetFieldDataType(field); 11671 NSUInteger count = 0; 11672 size_t result = 0; 11673 for (int i = 0; i < 2; ++i) { 11674 if (_values[i] != nil) { 11675 ++count; 11676 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool); 11677 msgSize += ComputeDictObjectFieldSize(_values[i], kMapValueFieldNumber, valueDataType); 11678 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 11679 } 11680 } 11681 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 11682 result += tagSize * count; 11683 return result; 11684} 11685 11686- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 11687 asField:(GPBFieldDescriptor *)field { 11688 GPBDataType valueDataType = GPBGetFieldDataType(field); 11689 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 11690 for (int i = 0; i < 2; ++i) { 11691 if (_values[i] != nil) { 11692 // Write the tag. 11693 [outputStream writeInt32NoTag:tag]; 11694 // Write the size of the message. 11695 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool); 11696 msgSize += ComputeDictObjectFieldSize(_values[i], kMapValueFieldNumber, valueDataType); 11697 [outputStream writeInt32NoTag:(int32_t)msgSize]; 11698 // Write the fields. 11699 WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool); 11700 WriteDictObjectField(outputStream, _values[i], kMapValueFieldNumber, valueDataType); 11701 } 11702 } 11703} 11704 11705- (void)addEntriesFromDictionary:(GPBBoolObjectDictionary *)otherDictionary { 11706 if (otherDictionary) { 11707 for (int i = 0; i < 2; ++i) { 11708 if (otherDictionary->_values[i] != nil) { 11709 [_values[i] release]; 11710 _values[i] = [otherDictionary->_values[i] retain]; 11711 } 11712 } 11713 if (_autocreator) { 11714 GPBAutocreatedDictionaryModified(_autocreator, self); 11715 } 11716 } 11717} 11718 11719- (void)setObject:(id)object forKey:(BOOL)key { 11720 if (!object) { 11721 [NSException raise:NSInvalidArgumentException 11722 format:@"Attempting to add nil object to a Dictionary"]; 11723 } 11724 int idx = (key ? 1 : 0); 11725 [_values[idx] release]; 11726 _values[idx] = [object retain]; 11727 if (_autocreator) { 11728 GPBAutocreatedDictionaryModified(_autocreator, self); 11729 } 11730} 11731 11732- (void)removeObjectForKey:(BOOL)aKey { 11733 int idx = (aKey ? 1 : 0); 11734 [_values[idx] release]; 11735 _values[idx] = nil; 11736} 11737 11738- (void)removeAll { 11739 for (int i = 0; i < 2; ++i) { 11740 [_values[i] release]; 11741 _values[i] = nil; 11742 } 11743} 11744 11745@end 11746 11747// clang-format on 11748//%PDDM-EXPAND-END (8 expansions) 11749 11750#pragma mark - Bool -> Enum 11751 11752@implementation GPBBoolEnumDictionary { 11753 @package 11754 GPBEnumValidationFunc _validationFunc; 11755 int32_t _values[2]; 11756 BOOL _valueSet[2]; 11757} 11758 11759@synthesize validationFunc = _validationFunc; 11760 11761- (instancetype)init { 11762 return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0]; 11763} 11764 11765- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func { 11766 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0]; 11767} 11768 11769- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func 11770 rawValues:(const int32_t [])rawValues 11771 forKeys:(const BOOL [])keys 11772 count:(NSUInteger)count { 11773 self = [super init]; 11774 if (self) { 11775 _validationFunc = (func != NULL ? func : DictDefault_IsValidValue); 11776 for (NSUInteger i = 0; i < count; ++i) { 11777 int idx = keys[i] ? 1 : 0; 11778 _values[idx] = rawValues[i]; 11779 _valueSet[idx] = YES; 11780 } 11781 } 11782 return self; 11783} 11784 11785- (instancetype)initWithDictionary:(GPBBoolEnumDictionary *)dictionary { 11786 self = [self initWithValidationFunction:dictionary.validationFunc 11787 rawValues:NULL 11788 forKeys:NULL 11789 count:0]; 11790 if (self) { 11791 if (dictionary) { 11792 for (int i = 0; i < 2; ++i) { 11793 if (dictionary->_valueSet[i]) { 11794 _values[i] = dictionary->_values[i]; 11795 _valueSet[i] = YES; 11796 } 11797 } 11798 } 11799 } 11800 return self; 11801} 11802 11803- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func 11804 capacity:(NSUInteger)numItems { 11805#pragma unused(numItems) 11806 return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0]; 11807} 11808 11809#if !defined(NS_BLOCK_ASSERTIONS) 11810- (void)dealloc { 11811 NSAssert(!_autocreator, 11812 @"%@: Autocreator must be cleared before release, autocreator: %@", 11813 [self class], _autocreator); 11814 [super dealloc]; 11815} 11816#endif // !defined(NS_BLOCK_ASSERTIONS) 11817 11818- (instancetype)copyWithZone:(NSZone *)zone { 11819 return [[GPBBoolEnumDictionary allocWithZone:zone] initWithDictionary:self]; 11820} 11821 11822- (BOOL)isEqual:(id)other { 11823 if (self == other) { 11824 return YES; 11825 } 11826 if (![other isKindOfClass:[GPBBoolEnumDictionary class]]) { 11827 return NO; 11828 } 11829 GPBBoolEnumDictionary *otherDictionary = other; 11830 if ((_valueSet[0] != otherDictionary->_valueSet[0]) || 11831 (_valueSet[1] != otherDictionary->_valueSet[1])) { 11832 return NO; 11833 } 11834 if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) || 11835 (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) { 11836 return NO; 11837 } 11838 return YES; 11839} 11840 11841- (NSUInteger)hash { 11842 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); 11843} 11844 11845- (NSString *)description { 11846 NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self]; 11847 if (_valueSet[0]) { 11848 [result appendFormat:@"NO: %d", _values[0]]; 11849 } 11850 if (_valueSet[1]) { 11851 [result appendFormat:@"YES: %d", _values[1]]; 11852 } 11853 [result appendString:@" }"]; 11854 return result; 11855} 11856 11857- (NSUInteger)count { 11858 return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0); 11859} 11860 11861- (BOOL)getEnum:(int32_t*)value forKey:(BOOL)key { 11862 int idx = (key ? 1 : 0); 11863 if (_valueSet[idx]) { 11864 if (value) { 11865 int32_t result = _values[idx]; 11866 if (!_validationFunc(result)) { 11867 result = kGPBUnrecognizedEnumeratorValue; 11868 } 11869 *value = result; 11870 } 11871 return YES; 11872 } 11873 return NO; 11874} 11875 11876- (BOOL)getRawValue:(int32_t*)rawValue forKey:(BOOL)key { 11877 int idx = (key ? 1 : 0); 11878 if (_valueSet[idx]) { 11879 if (rawValue) { 11880 *rawValue = _values[idx]; 11881 } 11882 return YES; 11883 } 11884 return NO; 11885} 11886 11887- (void)enumerateKeysAndRawValuesUsingBlock: 11888 (void (NS_NOESCAPE ^)(BOOL key, int32_t value, BOOL *stop))block { 11889 BOOL stop = NO; 11890 if (_valueSet[0]) { 11891 block(NO, _values[0], &stop); 11892 } 11893 if (!stop && _valueSet[1]) { 11894 block(YES, _values[1], &stop); 11895 } 11896} 11897 11898- (void)enumerateKeysAndEnumsUsingBlock: 11899 (void (NS_NOESCAPE ^)(BOOL key, int32_t rawValue, BOOL *stop))block { 11900 BOOL stop = NO; 11901 GPBEnumValidationFunc func = _validationFunc; 11902 int32_t validatedValue; 11903 if (_valueSet[0]) { 11904 validatedValue = _values[0]; 11905 if (!func(validatedValue)) { 11906 validatedValue = kGPBUnrecognizedEnumeratorValue; 11907 } 11908 block(NO, validatedValue, &stop); 11909 } 11910 if (!stop && _valueSet[1]) { 11911 validatedValue = _values[1]; 11912 if (!func(validatedValue)) { 11913 validatedValue = kGPBUnrecognizedEnumeratorValue; 11914 } 11915 block(YES, validatedValue, &stop); 11916 } 11917} 11918 11919//%PDDM-EXPAND SERIAL_DATA_FOR_ENTRY_POD_Enum(Bool) 11920// This block of code is generated, do not edit it directly. 11921// clang-format off 11922 11923- (NSData *)serializedDataForUnknownValue:(int32_t)value 11924 forKey:(GPBGenericValue *)key 11925 keyDataType:(GPBDataType)keyDataType { 11926 size_t msgSize = ComputeDictBoolFieldSize(key->valueBool, kMapKeyFieldNumber, keyDataType); 11927 msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum); 11928 NSMutableData *data = [NSMutableData dataWithLength:msgSize]; 11929 GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data]; 11930 WriteDictBoolField(outputStream, key->valueBool, kMapKeyFieldNumber, keyDataType); 11931 WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum); 11932 [outputStream release]; 11933 return data; 11934} 11935 11936// clang-format on 11937//%PDDM-EXPAND-END SERIAL_DATA_FOR_ENTRY_POD_Enum(Bool) 11938 11939- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field { 11940 GPBDataType valueDataType = GPBGetFieldDataType(field); 11941 NSUInteger count = 0; 11942 size_t result = 0; 11943 for (int i = 0; i < 2; ++i) { 11944 if (_valueSet[i]) { 11945 ++count; 11946 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool); 11947 msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType); 11948 result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize; 11949 } 11950 } 11951 size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage); 11952 result += tagSize * count; 11953 return result; 11954} 11955 11956- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream 11957 asField:(GPBFieldDescriptor *)field { 11958 GPBDataType valueDataType = GPBGetFieldDataType(field); 11959 uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited); 11960 for (int i = 0; i < 2; ++i) { 11961 if (_valueSet[i]) { 11962 // Write the tag. 11963 [outputStream writeInt32NoTag:tag]; 11964 // Write the size of the message. 11965 size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool); 11966 msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType); 11967 [outputStream writeInt32NoTag:(int32_t)msgSize]; 11968 // Write the fields. 11969 WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool); 11970 WriteDictInt32Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType); 11971 } 11972 } 11973} 11974 11975- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block { 11976 if (_valueSet[0]) { 11977 block(@"false", @(_values[0])); 11978 } 11979 if (_valueSet[1]) { 11980 block(@"true", @(_values[1])); 11981 } 11982} 11983 11984- (void)setGPBGenericValue:(GPBGenericValue *)value 11985 forGPBGenericValueKey:(GPBGenericValue *)key { 11986 int idx = (key->valueBool ? 1 : 0); 11987 _values[idx] = value->valueInt32; 11988 _valueSet[idx] = YES; 11989} 11990 11991- (void)addRawEntriesFromDictionary:(GPBBoolEnumDictionary *)otherDictionary { 11992 if (otherDictionary) { 11993 for (int i = 0; i < 2; ++i) { 11994 if (otherDictionary->_valueSet[i]) { 11995 _valueSet[i] = YES; 11996 _values[i] = otherDictionary->_values[i]; 11997 } 11998 } 11999 if (_autocreator) { 12000 GPBAutocreatedDictionaryModified(_autocreator, self); 12001 } 12002 } 12003} 12004 12005- (void)setEnum:(int32_t)value forKey:(BOOL)key { 12006 if (!_validationFunc(value)) { 12007 [NSException raise:NSInvalidArgumentException 12008 format:@"GPBBoolEnumDictionary: Attempt to set an unknown enum value (%d)", 12009 value]; 12010 } 12011 int idx = (key ? 1 : 0); 12012 _values[idx] = value; 12013 _valueSet[idx] = YES; 12014 if (_autocreator) { 12015 GPBAutocreatedDictionaryModified(_autocreator, self); 12016 } 12017} 12018 12019- (void)setRawValue:(int32_t)rawValue forKey:(BOOL)key { 12020 int idx = (key ? 1 : 0); 12021 _values[idx] = rawValue; 12022 _valueSet[idx] = YES; 12023 if (_autocreator) { 12024 GPBAutocreatedDictionaryModified(_autocreator, self); 12025 } 12026} 12027 12028- (void)removeEnumForKey:(BOOL)aKey { 12029 _valueSet[aKey ? 1 : 0] = NO; 12030} 12031 12032- (void)removeAll { 12033 _valueSet[0] = NO; 12034 _valueSet[1] = NO; 12035} 12036 12037@end 12038 12039#pragma mark - NSDictionary Subclass 12040 12041@implementation GPBAutocreatedDictionary { 12042 NSMutableDictionary *_dictionary; 12043} 12044 12045- (void)dealloc { 12046 NSAssert(!_autocreator, 12047 @"%@: Autocreator must be cleared before release, autocreator: %@", 12048 [self class], _autocreator); 12049 [_dictionary release]; 12050 [super dealloc]; 12051} 12052 12053#pragma mark Required NSDictionary overrides 12054 12055- (instancetype)initWithObjects:(const id [])objects 12056 forKeys:(const id<NSCopying> [])keys 12057 count:(NSUInteger)count { 12058 self = [super init]; 12059 if (self) { 12060 _dictionary = [[NSMutableDictionary alloc] initWithObjects:objects 12061 forKeys:keys 12062 count:count]; 12063 } 12064 return self; 12065} 12066 12067- (NSUInteger)count { 12068 return [_dictionary count]; 12069} 12070 12071- (id)objectForKey:(id)aKey { 12072 return [_dictionary objectForKey:aKey]; 12073} 12074 12075- (NSEnumerator *)keyEnumerator { 12076 if (_dictionary == nil) { 12077 _dictionary = [[NSMutableDictionary alloc] init]; 12078 } 12079 return [_dictionary keyEnumerator]; 12080} 12081 12082#pragma mark Required NSMutableDictionary overrides 12083 12084// Only need to call GPBAutocreatedDictionaryModified() when adding things 12085// since we only autocreate empty dictionaries. 12086 12087- (void)setObject:(id)anObject forKey:(id<NSCopying>)aKey { 12088 if (_dictionary == nil) { 12089 _dictionary = [[NSMutableDictionary alloc] init]; 12090 } 12091 [_dictionary setObject:anObject forKey:aKey]; 12092 if (_autocreator) { 12093 GPBAutocreatedDictionaryModified(_autocreator, self); 12094 } 12095} 12096 12097- (void)removeObjectForKey:(id)aKey { 12098 [_dictionary removeObjectForKey:aKey]; 12099} 12100 12101#pragma mark Extra things hooked 12102 12103- (id)copyWithZone:(NSZone *)zone { 12104 if (_dictionary == nil) { 12105 return [[NSMutableDictionary allocWithZone:zone] init]; 12106 } 12107 return [_dictionary copyWithZone:zone]; 12108} 12109 12110- (id)mutableCopyWithZone:(NSZone *)zone { 12111 if (_dictionary == nil) { 12112 return [[NSMutableDictionary allocWithZone:zone] init]; 12113 } 12114 return [_dictionary mutableCopyWithZone:zone]; 12115} 12116 12117// Not really needed, but subscripting is likely common enough it doesn't hurt 12118// to ensure it goes directly to the real NSMutableDictionary. 12119- (id)objectForKeyedSubscript:(id)key { 12120 return [_dictionary objectForKeyedSubscript:key]; 12121} 12122 12123// Not really needed, but subscripting is likely common enough it doesn't hurt 12124// to ensure it goes directly to the real NSMutableDictionary. 12125- (void)setObject:(id)obj forKeyedSubscript:(id<NSCopying>)key { 12126 if (_dictionary == nil) { 12127 _dictionary = [[NSMutableDictionary alloc] init]; 12128 } 12129 [_dictionary setObject:obj forKeyedSubscript:key]; 12130 if (_autocreator) { 12131 GPBAutocreatedDictionaryModified(_autocreator, self); 12132 } 12133} 12134 12135- (void)enumerateKeysAndObjectsUsingBlock:(void (NS_NOESCAPE ^)(id key, 12136 id obj, 12137 BOOL *stop))block { 12138 [_dictionary enumerateKeysAndObjectsUsingBlock:block]; 12139} 12140 12141- (void)enumerateKeysAndObjectsWithOptions:(NSEnumerationOptions)opts 12142 usingBlock:(void (NS_NOESCAPE ^)(id key, 12143 id obj, 12144 BOOL *stop))block { 12145 [_dictionary enumerateKeysAndObjectsWithOptions:opts usingBlock:block]; 12146} 12147 12148@end 12149 12150#pragma clang diagnostic pop 12151