1ffe3c632Sopenharmony_ci// Protocol Buffers - Google's data interchange format
2ffe3c632Sopenharmony_ci// Copyright 2008 Google Inc.  All rights reserved.
3ffe3c632Sopenharmony_ci// https://developers.google.com/protocol-buffers/
4ffe3c632Sopenharmony_ci//
5ffe3c632Sopenharmony_ci// Redistribution and use in source and binary forms, with or without
6ffe3c632Sopenharmony_ci// modification, are permitted provided that the following conditions are
7ffe3c632Sopenharmony_ci// met:
8ffe3c632Sopenharmony_ci//
9ffe3c632Sopenharmony_ci//     * Redistributions of source code must retain the above copyright
10ffe3c632Sopenharmony_ci// notice, this list of conditions and the following disclaimer.
11ffe3c632Sopenharmony_ci//     * Redistributions in binary form must reproduce the above
12ffe3c632Sopenharmony_ci// copyright notice, this list of conditions and the following disclaimer
13ffe3c632Sopenharmony_ci// in the documentation and/or other materials provided with the
14ffe3c632Sopenharmony_ci// distribution.
15ffe3c632Sopenharmony_ci//     * Neither the name of Google Inc. nor the names of its
16ffe3c632Sopenharmony_ci// contributors may be used to endorse or promote products derived from
17ffe3c632Sopenharmony_ci// this software without specific prior written permission.
18ffe3c632Sopenharmony_ci//
19ffe3c632Sopenharmony_ci// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20ffe3c632Sopenharmony_ci// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21ffe3c632Sopenharmony_ci// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22ffe3c632Sopenharmony_ci// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23ffe3c632Sopenharmony_ci// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24ffe3c632Sopenharmony_ci// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25ffe3c632Sopenharmony_ci// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26ffe3c632Sopenharmony_ci// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27ffe3c632Sopenharmony_ci// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28ffe3c632Sopenharmony_ci// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29ffe3c632Sopenharmony_ci// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30ffe3c632Sopenharmony_ci
31ffe3c632Sopenharmony_ci#import "GPBDictionary_PackagePrivate.h"
32ffe3c632Sopenharmony_ci
33ffe3c632Sopenharmony_ci#import "GPBCodedInputStream_PackagePrivate.h"
34ffe3c632Sopenharmony_ci#import "GPBCodedOutputStream_PackagePrivate.h"
35ffe3c632Sopenharmony_ci#import "GPBDescriptor_PackagePrivate.h"
36ffe3c632Sopenharmony_ci#import "GPBMessage_PackagePrivate.h"
37ffe3c632Sopenharmony_ci#import "GPBUtilities_PackagePrivate.h"
38ffe3c632Sopenharmony_ci
39ffe3c632Sopenharmony_ci// ------------------------------ NOTE ------------------------------
40ffe3c632Sopenharmony_ci// At the moment, this is all using NSNumbers in NSDictionaries under
41ffe3c632Sopenharmony_ci// the hood, but it is all hidden so we can come back and optimize
42ffe3c632Sopenharmony_ci// with direct CFDictionary usage later.  The reason that wasn't
43ffe3c632Sopenharmony_ci// done yet is needing to support 32bit iOS builds.  Otherwise
44ffe3c632Sopenharmony_ci// it would be pretty simple to store all this data in CFDictionaries
45ffe3c632Sopenharmony_ci// directly.
46ffe3c632Sopenharmony_ci// ------------------------------------------------------------------
47ffe3c632Sopenharmony_ci
48ffe3c632Sopenharmony_ci// Direct access is use for speed, to avoid even internally declaring things
49ffe3c632Sopenharmony_ci// read/write, etc. The warning is enabled in the project to ensure code calling
50ffe3c632Sopenharmony_ci// protos can turn on -Wdirect-ivar-access without issues.
51ffe3c632Sopenharmony_ci#pragma clang diagnostic push
52ffe3c632Sopenharmony_ci#pragma clang diagnostic ignored "-Wdirect-ivar-access"
53ffe3c632Sopenharmony_ci
54ffe3c632Sopenharmony_ci// Used to include code only visible to specific versions of the static
55ffe3c632Sopenharmony_ci// analyzer. Useful for wrapping code that only exists to silence the analyzer.
56ffe3c632Sopenharmony_ci// Determine the values you want to use for BEGIN_APPLE_BUILD_VERSION,
57ffe3c632Sopenharmony_ci// END_APPLE_BUILD_VERSION using:
58ffe3c632Sopenharmony_ci//   xcrun clang -dM -E -x c /dev/null | grep __apple_build_version__
59ffe3c632Sopenharmony_ci// Example usage:
60ffe3c632Sopenharmony_ci//  #if GPB_STATIC_ANALYZER_ONLY(5621, 5623) ... #endif
61ffe3c632Sopenharmony_ci#define GPB_STATIC_ANALYZER_ONLY(BEGIN_APPLE_BUILD_VERSION, END_APPLE_BUILD_VERSION) \
62ffe3c632Sopenharmony_ci    (defined(__clang_analyzer__) && \
63ffe3c632Sopenharmony_ci     (__apple_build_version__ >= BEGIN_APPLE_BUILD_VERSION && \
64ffe3c632Sopenharmony_ci      __apple_build_version__ <= END_APPLE_BUILD_VERSION))
65ffe3c632Sopenharmony_ci
66ffe3c632Sopenharmony_cienum {
67ffe3c632Sopenharmony_ci  kMapKeyFieldNumber = 1,
68ffe3c632Sopenharmony_ci  kMapValueFieldNumber = 2,
69ffe3c632Sopenharmony_ci};
70ffe3c632Sopenharmony_ci
71ffe3c632Sopenharmony_cistatic BOOL DictDefault_IsValidValue(int32_t value) {
72ffe3c632Sopenharmony_ci  // Anything but the bad value marker is allowed.
73ffe3c632Sopenharmony_ci  return (value != kGPBUnrecognizedEnumeratorValue);
74ffe3c632Sopenharmony_ci}
75ffe3c632Sopenharmony_ci
76ffe3c632Sopenharmony_ci//%PDDM-DEFINE SERIALIZE_SUPPORT_2_TYPE(VALUE_NAME, VALUE_TYPE, GPBDATATYPE_NAME1, GPBDATATYPE_NAME2)
77ffe3c632Sopenharmony_ci//%static size_t ComputeDict##VALUE_NAME##FieldSize(VALUE_TYPE value, uint32_t fieldNum, GPBDataType dataType) {
78ffe3c632Sopenharmony_ci//%  if (dataType == GPBDataType##GPBDATATYPE_NAME1) {
79ffe3c632Sopenharmony_ci//%    return GPBCompute##GPBDATATYPE_NAME1##Size(fieldNum, value);
80ffe3c632Sopenharmony_ci//%  } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) {
81ffe3c632Sopenharmony_ci//%    return GPBCompute##GPBDATATYPE_NAME2##Size(fieldNum, value);
82ffe3c632Sopenharmony_ci//%  } else {
83ffe3c632Sopenharmony_ci//%    NSCAssert(NO, @"Unexpected type %d", dataType);
84ffe3c632Sopenharmony_ci//%    return 0;
85ffe3c632Sopenharmony_ci//%  }
86ffe3c632Sopenharmony_ci//%}
87ffe3c632Sopenharmony_ci//%
88ffe3c632Sopenharmony_ci//%static void WriteDict##VALUE_NAME##Field(GPBCodedOutputStream *stream, VALUE_TYPE value, uint32_t fieldNum, GPBDataType dataType) {
89ffe3c632Sopenharmony_ci//%  if (dataType == GPBDataType##GPBDATATYPE_NAME1) {
90ffe3c632Sopenharmony_ci//%    [stream write##GPBDATATYPE_NAME1##:fieldNum value:value];
91ffe3c632Sopenharmony_ci//%  } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) {
92ffe3c632Sopenharmony_ci//%    [stream write##GPBDATATYPE_NAME2##:fieldNum value:value];
93ffe3c632Sopenharmony_ci//%  } else {
94ffe3c632Sopenharmony_ci//%    NSCAssert(NO, @"Unexpected type %d", dataType);
95ffe3c632Sopenharmony_ci//%  }
96ffe3c632Sopenharmony_ci//%}
97ffe3c632Sopenharmony_ci//%
98ffe3c632Sopenharmony_ci//%PDDM-DEFINE SERIALIZE_SUPPORT_3_TYPE(VALUE_NAME, VALUE_TYPE, GPBDATATYPE_NAME1, GPBDATATYPE_NAME2, GPBDATATYPE_NAME3)
99ffe3c632Sopenharmony_ci//%static size_t ComputeDict##VALUE_NAME##FieldSize(VALUE_TYPE value, uint32_t fieldNum, GPBDataType dataType) {
100ffe3c632Sopenharmony_ci//%  if (dataType == GPBDataType##GPBDATATYPE_NAME1) {
101ffe3c632Sopenharmony_ci//%    return GPBCompute##GPBDATATYPE_NAME1##Size(fieldNum, value);
102ffe3c632Sopenharmony_ci//%  } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) {
103ffe3c632Sopenharmony_ci//%    return GPBCompute##GPBDATATYPE_NAME2##Size(fieldNum, value);
104ffe3c632Sopenharmony_ci//%  } else if (dataType == GPBDataType##GPBDATATYPE_NAME3) {
105ffe3c632Sopenharmony_ci//%    return GPBCompute##GPBDATATYPE_NAME3##Size(fieldNum, value);
106ffe3c632Sopenharmony_ci//%  } else {
107ffe3c632Sopenharmony_ci//%    NSCAssert(NO, @"Unexpected type %d", dataType);
108ffe3c632Sopenharmony_ci//%    return 0;
109ffe3c632Sopenharmony_ci//%  }
110ffe3c632Sopenharmony_ci//%}
111ffe3c632Sopenharmony_ci//%
112ffe3c632Sopenharmony_ci//%static void WriteDict##VALUE_NAME##Field(GPBCodedOutputStream *stream, VALUE_TYPE value, uint32_t fieldNum, GPBDataType dataType) {
113ffe3c632Sopenharmony_ci//%  if (dataType == GPBDataType##GPBDATATYPE_NAME1) {
114ffe3c632Sopenharmony_ci//%    [stream write##GPBDATATYPE_NAME1##:fieldNum value:value];
115ffe3c632Sopenharmony_ci//%  } else if (dataType == GPBDataType##GPBDATATYPE_NAME2) {
116ffe3c632Sopenharmony_ci//%    [stream write##GPBDATATYPE_NAME2##:fieldNum value:value];
117ffe3c632Sopenharmony_ci//%  } else if (dataType == GPBDataType##GPBDATATYPE_NAME3) {
118ffe3c632Sopenharmony_ci//%    [stream write##GPBDATATYPE_NAME3##:fieldNum value:value];
119ffe3c632Sopenharmony_ci//%  } else {
120ffe3c632Sopenharmony_ci//%    NSCAssert(NO, @"Unexpected type %d", dataType);
121ffe3c632Sopenharmony_ci//%  }
122ffe3c632Sopenharmony_ci//%}
123ffe3c632Sopenharmony_ci//%
124ffe3c632Sopenharmony_ci//%PDDM-DEFINE SIMPLE_SERIALIZE_SUPPORT(VALUE_NAME, VALUE_TYPE, VisP)
125ffe3c632Sopenharmony_ci//%static size_t ComputeDict##VALUE_NAME##FieldSize(VALUE_TYPE VisP##value, uint32_t fieldNum, GPBDataType dataType) {
126ffe3c632Sopenharmony_ci//%  NSCAssert(dataType == GPBDataType##VALUE_NAME, @"bad type: %d", dataType);
127ffe3c632Sopenharmony_ci//%  #pragma unused(dataType)  // For when asserts are off in release.
128ffe3c632Sopenharmony_ci//%  return GPBCompute##VALUE_NAME##Size(fieldNum, value);
129ffe3c632Sopenharmony_ci//%}
130ffe3c632Sopenharmony_ci//%
131ffe3c632Sopenharmony_ci//%static void WriteDict##VALUE_NAME##Field(GPBCodedOutputStream *stream, VALUE_TYPE VisP##value, uint32_t fieldNum, GPBDataType dataType) {
132ffe3c632Sopenharmony_ci//%  NSCAssert(dataType == GPBDataType##VALUE_NAME, @"bad type: %d", dataType);
133ffe3c632Sopenharmony_ci//%  #pragma unused(dataType)  // For when asserts are off in release.
134ffe3c632Sopenharmony_ci//%  [stream write##VALUE_NAME##:fieldNum value:value];
135ffe3c632Sopenharmony_ci//%}
136ffe3c632Sopenharmony_ci//%
137ffe3c632Sopenharmony_ci//%PDDM-DEFINE SERIALIZE_SUPPORT_HELPERS()
138ffe3c632Sopenharmony_ci//%SERIALIZE_SUPPORT_3_TYPE(Int32, int32_t, Int32, SInt32, SFixed32)
139ffe3c632Sopenharmony_ci//%SERIALIZE_SUPPORT_2_TYPE(UInt32, uint32_t, UInt32, Fixed32)
140ffe3c632Sopenharmony_ci//%SERIALIZE_SUPPORT_3_TYPE(Int64, int64_t, Int64, SInt64, SFixed64)
141ffe3c632Sopenharmony_ci//%SERIALIZE_SUPPORT_2_TYPE(UInt64, uint64_t, UInt64, Fixed64)
142ffe3c632Sopenharmony_ci//%SIMPLE_SERIALIZE_SUPPORT(Bool, BOOL, )
143ffe3c632Sopenharmony_ci//%SIMPLE_SERIALIZE_SUPPORT(Enum, int32_t, )
144ffe3c632Sopenharmony_ci//%SIMPLE_SERIALIZE_SUPPORT(Float, float, )
145ffe3c632Sopenharmony_ci//%SIMPLE_SERIALIZE_SUPPORT(Double, double, )
146ffe3c632Sopenharmony_ci//%SIMPLE_SERIALIZE_SUPPORT(String, NSString, *)
147ffe3c632Sopenharmony_ci//%SERIALIZE_SUPPORT_3_TYPE(Object, id, Message, String, Bytes)
148ffe3c632Sopenharmony_ci//%PDDM-EXPAND SERIALIZE_SUPPORT_HELPERS()
149ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly.
150ffe3c632Sopenharmony_ci// clang-format off
151ffe3c632Sopenharmony_ci
152ffe3c632Sopenharmony_cistatic size_t ComputeDictInt32FieldSize(int32_t value, uint32_t fieldNum, GPBDataType dataType) {
153ffe3c632Sopenharmony_ci  if (dataType == GPBDataTypeInt32) {
154ffe3c632Sopenharmony_ci    return GPBComputeInt32Size(fieldNum, value);
155ffe3c632Sopenharmony_ci  } else if (dataType == GPBDataTypeSInt32) {
156ffe3c632Sopenharmony_ci    return GPBComputeSInt32Size(fieldNum, value);
157ffe3c632Sopenharmony_ci  } else if (dataType == GPBDataTypeSFixed32) {
158ffe3c632Sopenharmony_ci    return GPBComputeSFixed32Size(fieldNum, value);
159ffe3c632Sopenharmony_ci  } else {
160ffe3c632Sopenharmony_ci    NSCAssert(NO, @"Unexpected type %d", dataType);
161ffe3c632Sopenharmony_ci    return 0;
162ffe3c632Sopenharmony_ci  }
163ffe3c632Sopenharmony_ci}
164ffe3c632Sopenharmony_ci
165ffe3c632Sopenharmony_cistatic void WriteDictInt32Field(GPBCodedOutputStream *stream, int32_t value, uint32_t fieldNum, GPBDataType dataType) {
166ffe3c632Sopenharmony_ci  if (dataType == GPBDataTypeInt32) {
167ffe3c632Sopenharmony_ci    [stream writeInt32:fieldNum value:value];
168ffe3c632Sopenharmony_ci  } else if (dataType == GPBDataTypeSInt32) {
169ffe3c632Sopenharmony_ci    [stream writeSInt32:fieldNum value:value];
170ffe3c632Sopenharmony_ci  } else if (dataType == GPBDataTypeSFixed32) {
171ffe3c632Sopenharmony_ci    [stream writeSFixed32:fieldNum value:value];
172ffe3c632Sopenharmony_ci  } else {
173ffe3c632Sopenharmony_ci    NSCAssert(NO, @"Unexpected type %d", dataType);
174ffe3c632Sopenharmony_ci  }
175ffe3c632Sopenharmony_ci}
176ffe3c632Sopenharmony_ci
177ffe3c632Sopenharmony_cistatic size_t ComputeDictUInt32FieldSize(uint32_t value, uint32_t fieldNum, GPBDataType dataType) {
178ffe3c632Sopenharmony_ci  if (dataType == GPBDataTypeUInt32) {
179ffe3c632Sopenharmony_ci    return GPBComputeUInt32Size(fieldNum, value);
180ffe3c632Sopenharmony_ci  } else if (dataType == GPBDataTypeFixed32) {
181ffe3c632Sopenharmony_ci    return GPBComputeFixed32Size(fieldNum, value);
182ffe3c632Sopenharmony_ci  } else {
183ffe3c632Sopenharmony_ci    NSCAssert(NO, @"Unexpected type %d", dataType);
184ffe3c632Sopenharmony_ci    return 0;
185ffe3c632Sopenharmony_ci  }
186ffe3c632Sopenharmony_ci}
187ffe3c632Sopenharmony_ci
188ffe3c632Sopenharmony_cistatic void WriteDictUInt32Field(GPBCodedOutputStream *stream, uint32_t value, uint32_t fieldNum, GPBDataType dataType) {
189ffe3c632Sopenharmony_ci  if (dataType == GPBDataTypeUInt32) {
190ffe3c632Sopenharmony_ci    [stream writeUInt32:fieldNum value:value];
191ffe3c632Sopenharmony_ci  } else if (dataType == GPBDataTypeFixed32) {
192ffe3c632Sopenharmony_ci    [stream writeFixed32:fieldNum value:value];
193ffe3c632Sopenharmony_ci  } else {
194ffe3c632Sopenharmony_ci    NSCAssert(NO, @"Unexpected type %d", dataType);
195ffe3c632Sopenharmony_ci  }
196ffe3c632Sopenharmony_ci}
197ffe3c632Sopenharmony_ci
198ffe3c632Sopenharmony_cistatic size_t ComputeDictInt64FieldSize(int64_t value, uint32_t fieldNum, GPBDataType dataType) {
199ffe3c632Sopenharmony_ci  if (dataType == GPBDataTypeInt64) {
200ffe3c632Sopenharmony_ci    return GPBComputeInt64Size(fieldNum, value);
201ffe3c632Sopenharmony_ci  } else if (dataType == GPBDataTypeSInt64) {
202ffe3c632Sopenharmony_ci    return GPBComputeSInt64Size(fieldNum, value);
203ffe3c632Sopenharmony_ci  } else if (dataType == GPBDataTypeSFixed64) {
204ffe3c632Sopenharmony_ci    return GPBComputeSFixed64Size(fieldNum, value);
205ffe3c632Sopenharmony_ci  } else {
206ffe3c632Sopenharmony_ci    NSCAssert(NO, @"Unexpected type %d", dataType);
207ffe3c632Sopenharmony_ci    return 0;
208ffe3c632Sopenharmony_ci  }
209ffe3c632Sopenharmony_ci}
210ffe3c632Sopenharmony_ci
211ffe3c632Sopenharmony_cistatic void WriteDictInt64Field(GPBCodedOutputStream *stream, int64_t value, uint32_t fieldNum, GPBDataType dataType) {
212ffe3c632Sopenharmony_ci  if (dataType == GPBDataTypeInt64) {
213ffe3c632Sopenharmony_ci    [stream writeInt64:fieldNum value:value];
214ffe3c632Sopenharmony_ci  } else if (dataType == GPBDataTypeSInt64) {
215ffe3c632Sopenharmony_ci    [stream writeSInt64:fieldNum value:value];
216ffe3c632Sopenharmony_ci  } else if (dataType == GPBDataTypeSFixed64) {
217ffe3c632Sopenharmony_ci    [stream writeSFixed64:fieldNum value:value];
218ffe3c632Sopenharmony_ci  } else {
219ffe3c632Sopenharmony_ci    NSCAssert(NO, @"Unexpected type %d", dataType);
220ffe3c632Sopenharmony_ci  }
221ffe3c632Sopenharmony_ci}
222ffe3c632Sopenharmony_ci
223ffe3c632Sopenharmony_cistatic size_t ComputeDictUInt64FieldSize(uint64_t value, uint32_t fieldNum, GPBDataType dataType) {
224ffe3c632Sopenharmony_ci  if (dataType == GPBDataTypeUInt64) {
225ffe3c632Sopenharmony_ci    return GPBComputeUInt64Size(fieldNum, value);
226ffe3c632Sopenharmony_ci  } else if (dataType == GPBDataTypeFixed64) {
227ffe3c632Sopenharmony_ci    return GPBComputeFixed64Size(fieldNum, value);
228ffe3c632Sopenharmony_ci  } else {
229ffe3c632Sopenharmony_ci    NSCAssert(NO, @"Unexpected type %d", dataType);
230ffe3c632Sopenharmony_ci    return 0;
231ffe3c632Sopenharmony_ci  }
232ffe3c632Sopenharmony_ci}
233ffe3c632Sopenharmony_ci
234ffe3c632Sopenharmony_cistatic void WriteDictUInt64Field(GPBCodedOutputStream *stream, uint64_t value, uint32_t fieldNum, GPBDataType dataType) {
235ffe3c632Sopenharmony_ci  if (dataType == GPBDataTypeUInt64) {
236ffe3c632Sopenharmony_ci    [stream writeUInt64:fieldNum value:value];
237ffe3c632Sopenharmony_ci  } else if (dataType == GPBDataTypeFixed64) {
238ffe3c632Sopenharmony_ci    [stream writeFixed64:fieldNum value:value];
239ffe3c632Sopenharmony_ci  } else {
240ffe3c632Sopenharmony_ci    NSCAssert(NO, @"Unexpected type %d", dataType);
241ffe3c632Sopenharmony_ci  }
242ffe3c632Sopenharmony_ci}
243ffe3c632Sopenharmony_ci
244ffe3c632Sopenharmony_cistatic size_t ComputeDictBoolFieldSize(BOOL value, uint32_t fieldNum, GPBDataType dataType) {
245ffe3c632Sopenharmony_ci  NSCAssert(dataType == GPBDataTypeBool, @"bad type: %d", dataType);
246ffe3c632Sopenharmony_ci  #pragma unused(dataType)  // For when asserts are off in release.
247ffe3c632Sopenharmony_ci  return GPBComputeBoolSize(fieldNum, value);
248ffe3c632Sopenharmony_ci}
249ffe3c632Sopenharmony_ci
250ffe3c632Sopenharmony_cistatic void WriteDictBoolField(GPBCodedOutputStream *stream, BOOL value, uint32_t fieldNum, GPBDataType dataType) {
251ffe3c632Sopenharmony_ci  NSCAssert(dataType == GPBDataTypeBool, @"bad type: %d", dataType);
252ffe3c632Sopenharmony_ci  #pragma unused(dataType)  // For when asserts are off in release.
253ffe3c632Sopenharmony_ci  [stream writeBool:fieldNum value:value];
254ffe3c632Sopenharmony_ci}
255ffe3c632Sopenharmony_ci
256ffe3c632Sopenharmony_cistatic size_t ComputeDictEnumFieldSize(int32_t value, uint32_t fieldNum, GPBDataType dataType) {
257ffe3c632Sopenharmony_ci  NSCAssert(dataType == GPBDataTypeEnum, @"bad type: %d", dataType);
258ffe3c632Sopenharmony_ci  #pragma unused(dataType)  // For when asserts are off in release.
259ffe3c632Sopenharmony_ci  return GPBComputeEnumSize(fieldNum, value);
260ffe3c632Sopenharmony_ci}
261ffe3c632Sopenharmony_ci
262ffe3c632Sopenharmony_cistatic void WriteDictEnumField(GPBCodedOutputStream *stream, int32_t value, uint32_t fieldNum, GPBDataType dataType) {
263ffe3c632Sopenharmony_ci  NSCAssert(dataType == GPBDataTypeEnum, @"bad type: %d", dataType);
264ffe3c632Sopenharmony_ci  #pragma unused(dataType)  // For when asserts are off in release.
265ffe3c632Sopenharmony_ci  [stream writeEnum:fieldNum value:value];
266ffe3c632Sopenharmony_ci}
267ffe3c632Sopenharmony_ci
268ffe3c632Sopenharmony_cistatic size_t ComputeDictFloatFieldSize(float value, uint32_t fieldNum, GPBDataType dataType) {
269ffe3c632Sopenharmony_ci  NSCAssert(dataType == GPBDataTypeFloat, @"bad type: %d", dataType);
270ffe3c632Sopenharmony_ci  #pragma unused(dataType)  // For when asserts are off in release.
271ffe3c632Sopenharmony_ci  return GPBComputeFloatSize(fieldNum, value);
272ffe3c632Sopenharmony_ci}
273ffe3c632Sopenharmony_ci
274ffe3c632Sopenharmony_cistatic void WriteDictFloatField(GPBCodedOutputStream *stream, float value, uint32_t fieldNum, GPBDataType dataType) {
275ffe3c632Sopenharmony_ci  NSCAssert(dataType == GPBDataTypeFloat, @"bad type: %d", dataType);
276ffe3c632Sopenharmony_ci  #pragma unused(dataType)  // For when asserts are off in release.
277ffe3c632Sopenharmony_ci  [stream writeFloat:fieldNum value:value];
278ffe3c632Sopenharmony_ci}
279ffe3c632Sopenharmony_ci
280ffe3c632Sopenharmony_cistatic size_t ComputeDictDoubleFieldSize(double value, uint32_t fieldNum, GPBDataType dataType) {
281ffe3c632Sopenharmony_ci  NSCAssert(dataType == GPBDataTypeDouble, @"bad type: %d", dataType);
282ffe3c632Sopenharmony_ci  #pragma unused(dataType)  // For when asserts are off in release.
283ffe3c632Sopenharmony_ci  return GPBComputeDoubleSize(fieldNum, value);
284ffe3c632Sopenharmony_ci}
285ffe3c632Sopenharmony_ci
286ffe3c632Sopenharmony_cistatic void WriteDictDoubleField(GPBCodedOutputStream *stream, double value, uint32_t fieldNum, GPBDataType dataType) {
287ffe3c632Sopenharmony_ci  NSCAssert(dataType == GPBDataTypeDouble, @"bad type: %d", dataType);
288ffe3c632Sopenharmony_ci  #pragma unused(dataType)  // For when asserts are off in release.
289ffe3c632Sopenharmony_ci  [stream writeDouble:fieldNum value:value];
290ffe3c632Sopenharmony_ci}
291ffe3c632Sopenharmony_ci
292ffe3c632Sopenharmony_cistatic size_t ComputeDictStringFieldSize(NSString *value, uint32_t fieldNum, GPBDataType dataType) {
293ffe3c632Sopenharmony_ci  NSCAssert(dataType == GPBDataTypeString, @"bad type: %d", dataType);
294ffe3c632Sopenharmony_ci  #pragma unused(dataType)  // For when asserts are off in release.
295ffe3c632Sopenharmony_ci  return GPBComputeStringSize(fieldNum, value);
296ffe3c632Sopenharmony_ci}
297ffe3c632Sopenharmony_ci
298ffe3c632Sopenharmony_cistatic void WriteDictStringField(GPBCodedOutputStream *stream, NSString *value, uint32_t fieldNum, GPBDataType dataType) {
299ffe3c632Sopenharmony_ci  NSCAssert(dataType == GPBDataTypeString, @"bad type: %d", dataType);
300ffe3c632Sopenharmony_ci  #pragma unused(dataType)  // For when asserts are off in release.
301ffe3c632Sopenharmony_ci  [stream writeString:fieldNum value:value];
302ffe3c632Sopenharmony_ci}
303ffe3c632Sopenharmony_ci
304ffe3c632Sopenharmony_cistatic size_t ComputeDictObjectFieldSize(id value, uint32_t fieldNum, GPBDataType dataType) {
305ffe3c632Sopenharmony_ci  if (dataType == GPBDataTypeMessage) {
306ffe3c632Sopenharmony_ci    return GPBComputeMessageSize(fieldNum, value);
307ffe3c632Sopenharmony_ci  } else if (dataType == GPBDataTypeString) {
308ffe3c632Sopenharmony_ci    return GPBComputeStringSize(fieldNum, value);
309ffe3c632Sopenharmony_ci  } else if (dataType == GPBDataTypeBytes) {
310ffe3c632Sopenharmony_ci    return GPBComputeBytesSize(fieldNum, value);
311ffe3c632Sopenharmony_ci  } else {
312ffe3c632Sopenharmony_ci    NSCAssert(NO, @"Unexpected type %d", dataType);
313ffe3c632Sopenharmony_ci    return 0;
314ffe3c632Sopenharmony_ci  }
315ffe3c632Sopenharmony_ci}
316ffe3c632Sopenharmony_ci
317ffe3c632Sopenharmony_cistatic void WriteDictObjectField(GPBCodedOutputStream *stream, id value, uint32_t fieldNum, GPBDataType dataType) {
318ffe3c632Sopenharmony_ci  if (dataType == GPBDataTypeMessage) {
319ffe3c632Sopenharmony_ci    [stream writeMessage:fieldNum value:value];
320ffe3c632Sopenharmony_ci  } else if (dataType == GPBDataTypeString) {
321ffe3c632Sopenharmony_ci    [stream writeString:fieldNum value:value];
322ffe3c632Sopenharmony_ci  } else if (dataType == GPBDataTypeBytes) {
323ffe3c632Sopenharmony_ci    [stream writeBytes:fieldNum value:value];
324ffe3c632Sopenharmony_ci  } else {
325ffe3c632Sopenharmony_ci    NSCAssert(NO, @"Unexpected type %d", dataType);
326ffe3c632Sopenharmony_ci  }
327ffe3c632Sopenharmony_ci}
328ffe3c632Sopenharmony_ci
329ffe3c632Sopenharmony_ci// clang-format on
330ffe3c632Sopenharmony_ci//%PDDM-EXPAND-END SERIALIZE_SUPPORT_HELPERS()
331ffe3c632Sopenharmony_ci
332ffe3c632Sopenharmony_cisize_t GPBDictionaryComputeSizeInternalHelper(NSDictionary *dict, GPBFieldDescriptor *field) {
333ffe3c632Sopenharmony_ci  GPBDataType mapValueType = GPBGetFieldDataType(field);
334ffe3c632Sopenharmony_ci  size_t result = 0;
335ffe3c632Sopenharmony_ci  NSString *key;
336ffe3c632Sopenharmony_ci  NSEnumerator *keys = [dict keyEnumerator];
337ffe3c632Sopenharmony_ci  while ((key = [keys nextObject])) {
338ffe3c632Sopenharmony_ci    id obj = dict[key];
339ffe3c632Sopenharmony_ci    size_t msgSize = GPBComputeStringSize(kMapKeyFieldNumber, key);
340ffe3c632Sopenharmony_ci    msgSize += ComputeDictObjectFieldSize(obj, kMapValueFieldNumber, mapValueType);
341ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
342ffe3c632Sopenharmony_ci  }
343ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
344ffe3c632Sopenharmony_ci  result += tagSize * dict.count;
345ffe3c632Sopenharmony_ci  return result;
346ffe3c632Sopenharmony_ci}
347ffe3c632Sopenharmony_ci
348ffe3c632Sopenharmony_civoid GPBDictionaryWriteToStreamInternalHelper(GPBCodedOutputStream *outputStream,
349ffe3c632Sopenharmony_ci                                              NSDictionary *dict,
350ffe3c632Sopenharmony_ci                                              GPBFieldDescriptor *field) {
351ffe3c632Sopenharmony_ci  NSCAssert(field.mapKeyDataType == GPBDataTypeString, @"Unexpected key type");
352ffe3c632Sopenharmony_ci  GPBDataType mapValueType = GPBGetFieldDataType(field);
353ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
354ffe3c632Sopenharmony_ci  NSString *key;
355ffe3c632Sopenharmony_ci  NSEnumerator *keys = [dict keyEnumerator];
356ffe3c632Sopenharmony_ci  while ((key = [keys nextObject])) {
357ffe3c632Sopenharmony_ci    id obj = dict[key];
358ffe3c632Sopenharmony_ci    // Write the tag.
359ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
360ffe3c632Sopenharmony_ci    // Write the size of the message.
361ffe3c632Sopenharmony_ci    size_t msgSize = GPBComputeStringSize(kMapKeyFieldNumber, key);
362ffe3c632Sopenharmony_ci    msgSize += ComputeDictObjectFieldSize(obj, kMapValueFieldNumber, mapValueType);
363ffe3c632Sopenharmony_ci
364ffe3c632Sopenharmony_ci    // Write the size and fields.
365ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
366ffe3c632Sopenharmony_ci    [outputStream writeString:kMapKeyFieldNumber value:key];
367ffe3c632Sopenharmony_ci    WriteDictObjectField(outputStream, obj, kMapValueFieldNumber, mapValueType);
368ffe3c632Sopenharmony_ci  }
369ffe3c632Sopenharmony_ci}
370ffe3c632Sopenharmony_ci
371ffe3c632Sopenharmony_ciBOOL GPBDictionaryIsInitializedInternalHelper(NSDictionary *dict, GPBFieldDescriptor *field) {
372ffe3c632Sopenharmony_ci  NSCAssert(field.mapKeyDataType == GPBDataTypeString, @"Unexpected key type");
373ffe3c632Sopenharmony_ci  NSCAssert(GPBGetFieldDataType(field) == GPBDataTypeMessage, @"Unexpected value type");
374ffe3c632Sopenharmony_ci  #pragma unused(field)  // For when asserts are off in release.
375ffe3c632Sopenharmony_ci  GPBMessage *msg;
376ffe3c632Sopenharmony_ci  NSEnumerator *objects = [dict objectEnumerator];
377ffe3c632Sopenharmony_ci  while ((msg = [objects nextObject])) {
378ffe3c632Sopenharmony_ci    if (!msg.initialized) {
379ffe3c632Sopenharmony_ci      return NO;
380ffe3c632Sopenharmony_ci    }
381ffe3c632Sopenharmony_ci  }
382ffe3c632Sopenharmony_ci  return YES;
383ffe3c632Sopenharmony_ci}
384ffe3c632Sopenharmony_ci
385ffe3c632Sopenharmony_ci// Note: if the type is an object, it the retain pass back to the caller.
386ffe3c632Sopenharmony_cistatic void ReadValue(GPBCodedInputStream *stream,
387ffe3c632Sopenharmony_ci                      GPBGenericValue *valueToFill,
388ffe3c632Sopenharmony_ci                      GPBDataType type,
389ffe3c632Sopenharmony_ci                      GPBExtensionRegistry *registry,
390ffe3c632Sopenharmony_ci                      GPBFieldDescriptor *field) {
391ffe3c632Sopenharmony_ci  switch (type) {
392ffe3c632Sopenharmony_ci    case GPBDataTypeBool:
393ffe3c632Sopenharmony_ci      valueToFill->valueBool = GPBCodedInputStreamReadBool(&stream->state_);
394ffe3c632Sopenharmony_ci      break;
395ffe3c632Sopenharmony_ci    case GPBDataTypeFixed32:
396ffe3c632Sopenharmony_ci      valueToFill->valueUInt32 = GPBCodedInputStreamReadFixed32(&stream->state_);
397ffe3c632Sopenharmony_ci      break;
398ffe3c632Sopenharmony_ci    case GPBDataTypeSFixed32:
399ffe3c632Sopenharmony_ci      valueToFill->valueInt32 = GPBCodedInputStreamReadSFixed32(&stream->state_);
400ffe3c632Sopenharmony_ci      break;
401ffe3c632Sopenharmony_ci    case GPBDataTypeFloat:
402ffe3c632Sopenharmony_ci      valueToFill->valueFloat = GPBCodedInputStreamReadFloat(&stream->state_);
403ffe3c632Sopenharmony_ci      break;
404ffe3c632Sopenharmony_ci    case GPBDataTypeFixed64:
405ffe3c632Sopenharmony_ci      valueToFill->valueUInt64 = GPBCodedInputStreamReadFixed64(&stream->state_);
406ffe3c632Sopenharmony_ci      break;
407ffe3c632Sopenharmony_ci    case GPBDataTypeSFixed64:
408ffe3c632Sopenharmony_ci      valueToFill->valueInt64 = GPBCodedInputStreamReadSFixed64(&stream->state_);
409ffe3c632Sopenharmony_ci      break;
410ffe3c632Sopenharmony_ci    case GPBDataTypeDouble:
411ffe3c632Sopenharmony_ci      valueToFill->valueDouble = GPBCodedInputStreamReadDouble(&stream->state_);
412ffe3c632Sopenharmony_ci      break;
413ffe3c632Sopenharmony_ci    case GPBDataTypeInt32:
414ffe3c632Sopenharmony_ci      valueToFill->valueInt32 = GPBCodedInputStreamReadInt32(&stream->state_);
415ffe3c632Sopenharmony_ci      break;
416ffe3c632Sopenharmony_ci    case GPBDataTypeInt64:
417ffe3c632Sopenharmony_ci      valueToFill->valueInt64 = GPBCodedInputStreamReadInt64(&stream->state_);
418ffe3c632Sopenharmony_ci      break;
419ffe3c632Sopenharmony_ci    case GPBDataTypeSInt32:
420ffe3c632Sopenharmony_ci      valueToFill->valueInt32 = GPBCodedInputStreamReadSInt32(&stream->state_);
421ffe3c632Sopenharmony_ci      break;
422ffe3c632Sopenharmony_ci    case GPBDataTypeSInt64:
423ffe3c632Sopenharmony_ci      valueToFill->valueInt64 = GPBCodedInputStreamReadSInt64(&stream->state_);
424ffe3c632Sopenharmony_ci      break;
425ffe3c632Sopenharmony_ci    case GPBDataTypeUInt32:
426ffe3c632Sopenharmony_ci      valueToFill->valueUInt32 = GPBCodedInputStreamReadUInt32(&stream->state_);
427ffe3c632Sopenharmony_ci      break;
428ffe3c632Sopenharmony_ci    case GPBDataTypeUInt64:
429ffe3c632Sopenharmony_ci      valueToFill->valueUInt64 = GPBCodedInputStreamReadUInt64(&stream->state_);
430ffe3c632Sopenharmony_ci      break;
431ffe3c632Sopenharmony_ci    case GPBDataTypeBytes:
432ffe3c632Sopenharmony_ci      [valueToFill->valueData release];
433ffe3c632Sopenharmony_ci      valueToFill->valueData = GPBCodedInputStreamReadRetainedBytes(&stream->state_);
434ffe3c632Sopenharmony_ci      break;
435ffe3c632Sopenharmony_ci    case GPBDataTypeString:
436ffe3c632Sopenharmony_ci      [valueToFill->valueString release];
437ffe3c632Sopenharmony_ci      valueToFill->valueString = GPBCodedInputStreamReadRetainedString(&stream->state_);
438ffe3c632Sopenharmony_ci      break;
439ffe3c632Sopenharmony_ci    case GPBDataTypeMessage: {
440ffe3c632Sopenharmony_ci      GPBMessage *message = [[field.msgClass alloc] init];
441ffe3c632Sopenharmony_ci      [stream readMessage:message extensionRegistry:registry];
442ffe3c632Sopenharmony_ci      [valueToFill->valueMessage release];
443ffe3c632Sopenharmony_ci      valueToFill->valueMessage = message;
444ffe3c632Sopenharmony_ci      break;
445ffe3c632Sopenharmony_ci    }
446ffe3c632Sopenharmony_ci    case GPBDataTypeGroup:
447ffe3c632Sopenharmony_ci      NSCAssert(NO, @"Can't happen");
448ffe3c632Sopenharmony_ci      break;
449ffe3c632Sopenharmony_ci    case GPBDataTypeEnum:
450ffe3c632Sopenharmony_ci      valueToFill->valueEnum = GPBCodedInputStreamReadEnum(&stream->state_);
451ffe3c632Sopenharmony_ci      break;
452ffe3c632Sopenharmony_ci  }
453ffe3c632Sopenharmony_ci}
454ffe3c632Sopenharmony_ci
455ffe3c632Sopenharmony_civoid GPBDictionaryReadEntry(id mapDictionary,
456ffe3c632Sopenharmony_ci                            GPBCodedInputStream *stream,
457ffe3c632Sopenharmony_ci                            GPBExtensionRegistry *registry,
458ffe3c632Sopenharmony_ci                            GPBFieldDescriptor *field,
459ffe3c632Sopenharmony_ci                            GPBMessage *parentMessage) {
460ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
461ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
462ffe3c632Sopenharmony_ci
463ffe3c632Sopenharmony_ci  GPBGenericValue key;
464ffe3c632Sopenharmony_ci  GPBGenericValue value;
465ffe3c632Sopenharmony_ci  // Zero them (but pick up any enum default for proto2).
466ffe3c632Sopenharmony_ci  key.valueString = value.valueString = nil;
467ffe3c632Sopenharmony_ci  if (valueDataType == GPBDataTypeEnum) {
468ffe3c632Sopenharmony_ci    value = field.defaultValue;
469ffe3c632Sopenharmony_ci  }
470ffe3c632Sopenharmony_ci
471ffe3c632Sopenharmony_ci  GPBCodedInputStreamState *state = &stream->state_;
472ffe3c632Sopenharmony_ci  uint32_t keyTag =
473ffe3c632Sopenharmony_ci      GPBWireFormatMakeTag(kMapKeyFieldNumber, GPBWireFormatForType(keyDataType, NO));
474ffe3c632Sopenharmony_ci  uint32_t valueTag =
475ffe3c632Sopenharmony_ci      GPBWireFormatMakeTag(kMapValueFieldNumber, GPBWireFormatForType(valueDataType, NO));
476ffe3c632Sopenharmony_ci
477ffe3c632Sopenharmony_ci  BOOL hitError = NO;
478ffe3c632Sopenharmony_ci  while (YES) {
479ffe3c632Sopenharmony_ci    uint32_t tag = GPBCodedInputStreamReadTag(state);
480ffe3c632Sopenharmony_ci    if (tag == keyTag) {
481ffe3c632Sopenharmony_ci      ReadValue(stream, &key, keyDataType, registry, field);
482ffe3c632Sopenharmony_ci    } else if (tag == valueTag) {
483ffe3c632Sopenharmony_ci      ReadValue(stream, &value, valueDataType, registry, field);
484ffe3c632Sopenharmony_ci    } else if (tag == 0) {
485ffe3c632Sopenharmony_ci      // zero signals EOF / limit reached
486ffe3c632Sopenharmony_ci      break;
487ffe3c632Sopenharmony_ci    } else {  // Unknown
488ffe3c632Sopenharmony_ci      if (![stream skipField:tag]){
489ffe3c632Sopenharmony_ci        hitError = YES;
490ffe3c632Sopenharmony_ci        break;
491ffe3c632Sopenharmony_ci      }
492ffe3c632Sopenharmony_ci    }
493ffe3c632Sopenharmony_ci  }
494ffe3c632Sopenharmony_ci
495ffe3c632Sopenharmony_ci  if (!hitError) {
496ffe3c632Sopenharmony_ci    // Handle the special defaults and/or missing key/value.
497ffe3c632Sopenharmony_ci    if ((keyDataType == GPBDataTypeString) && (key.valueString == nil)) {
498ffe3c632Sopenharmony_ci      key.valueString = [@"" retain];
499ffe3c632Sopenharmony_ci    }
500ffe3c632Sopenharmony_ci    if (GPBDataTypeIsObject(valueDataType) && value.valueString == nil) {
501ffe3c632Sopenharmony_ci#pragma clang diagnostic push
502ffe3c632Sopenharmony_ci#pragma clang diagnostic ignored "-Wswitch-enum"
503ffe3c632Sopenharmony_ci      switch (valueDataType) {
504ffe3c632Sopenharmony_ci        case GPBDataTypeString:
505ffe3c632Sopenharmony_ci          value.valueString = [@"" retain];
506ffe3c632Sopenharmony_ci          break;
507ffe3c632Sopenharmony_ci        case GPBDataTypeBytes:
508ffe3c632Sopenharmony_ci          value.valueData = [GPBEmptyNSData() retain];
509ffe3c632Sopenharmony_ci          break;
510ffe3c632Sopenharmony_ci#if defined(__clang_analyzer__)
511ffe3c632Sopenharmony_ci        case GPBDataTypeGroup:
512ffe3c632Sopenharmony_ci          // Maps can't really have Groups as the value type, but this case is needed
513ffe3c632Sopenharmony_ci          // so the analyzer won't report the possibility of send nil in for the value
514ffe3c632Sopenharmony_ci          // in the NSMutableDictionary case below.
515ffe3c632Sopenharmony_ci#endif
516ffe3c632Sopenharmony_ci        case GPBDataTypeMessage: {
517ffe3c632Sopenharmony_ci          value.valueMessage = [[field.msgClass alloc] init];
518ffe3c632Sopenharmony_ci          break;
519ffe3c632Sopenharmony_ci        }
520ffe3c632Sopenharmony_ci        default:
521ffe3c632Sopenharmony_ci          // Nothing
522ffe3c632Sopenharmony_ci          break;
523ffe3c632Sopenharmony_ci      }
524ffe3c632Sopenharmony_ci#pragma clang diagnostic pop
525ffe3c632Sopenharmony_ci    }
526ffe3c632Sopenharmony_ci
527ffe3c632Sopenharmony_ci    if ((keyDataType == GPBDataTypeString) && GPBDataTypeIsObject(valueDataType)) {
528ffe3c632Sopenharmony_ci#if GPB_STATIC_ANALYZER_ONLY(6020053, 7000181)
529ffe3c632Sopenharmony_ci     // Limited to Xcode 6.4 - 7.2, are known to fail here. The upper end can
530ffe3c632Sopenharmony_ci     // be raised as needed for new Xcodes.
531ffe3c632Sopenharmony_ci     //
532ffe3c632Sopenharmony_ci     // This is only needed on a "shallow" analyze; on a "deep" analyze, the
533ffe3c632Sopenharmony_ci     // existing code path gets this correct. In shallow, the analyzer decides
534ffe3c632Sopenharmony_ci     // GPBDataTypeIsObject(valueDataType) is both false and true on a single
535ffe3c632Sopenharmony_ci     // path through this function, allowing nil to be used for the
536ffe3c632Sopenharmony_ci     // setObject:forKey:.
537ffe3c632Sopenharmony_ci     if (value.valueString == nil) {
538ffe3c632Sopenharmony_ci       value.valueString = [@"" retain];
539ffe3c632Sopenharmony_ci     }
540ffe3c632Sopenharmony_ci#endif
541ffe3c632Sopenharmony_ci      // mapDictionary is an NSMutableDictionary
542ffe3c632Sopenharmony_ci      [(NSMutableDictionary *)mapDictionary setObject:value.valueString
543ffe3c632Sopenharmony_ci                                               forKey:key.valueString];
544ffe3c632Sopenharmony_ci    } else {
545ffe3c632Sopenharmony_ci      if (valueDataType == GPBDataTypeEnum) {
546ffe3c632Sopenharmony_ci        if (GPBHasPreservingUnknownEnumSemantics([parentMessage descriptor].file.syntax) ||
547ffe3c632Sopenharmony_ci            [field isValidEnumValue:value.valueEnum]) {
548ffe3c632Sopenharmony_ci          [mapDictionary setGPBGenericValue:&value forGPBGenericValueKey:&key];
549ffe3c632Sopenharmony_ci        } else {
550ffe3c632Sopenharmony_ci          NSData *data = [mapDictionary serializedDataForUnknownValue:value.valueEnum
551ffe3c632Sopenharmony_ci                                                               forKey:&key
552ffe3c632Sopenharmony_ci                                                          keyDataType:keyDataType];
553ffe3c632Sopenharmony_ci          [parentMessage addUnknownMapEntry:GPBFieldNumber(field) value:data];
554ffe3c632Sopenharmony_ci        }
555ffe3c632Sopenharmony_ci      } else {
556ffe3c632Sopenharmony_ci        [mapDictionary setGPBGenericValue:&value forGPBGenericValueKey:&key];
557ffe3c632Sopenharmony_ci      }
558ffe3c632Sopenharmony_ci    }
559ffe3c632Sopenharmony_ci  }
560ffe3c632Sopenharmony_ci
561ffe3c632Sopenharmony_ci  if (GPBDataTypeIsObject(keyDataType)) {
562ffe3c632Sopenharmony_ci    [key.valueString release];
563ffe3c632Sopenharmony_ci  }
564ffe3c632Sopenharmony_ci  if (GPBDataTypeIsObject(valueDataType)) {
565ffe3c632Sopenharmony_ci    [value.valueString release];
566ffe3c632Sopenharmony_ci  }
567ffe3c632Sopenharmony_ci}
568ffe3c632Sopenharmony_ci
569ffe3c632Sopenharmony_ci//
570ffe3c632Sopenharmony_ci// Macros for the common basic cases.
571ffe3c632Sopenharmony_ci//
572ffe3c632Sopenharmony_ci
573ffe3c632Sopenharmony_ci//%PDDM-DEFINE DICTIONARY_IMPL_FOR_POD_KEY(KEY_NAME, KEY_TYPE)
574ffe3c632Sopenharmony_ci//%DICTIONARY_POD_IMPL_FOR_KEY(KEY_NAME, KEY_TYPE, , POD)
575ffe3c632Sopenharmony_ci//%DICTIONARY_POD_KEY_TO_OBJECT_IMPL(KEY_NAME, KEY_TYPE, Object, id)
576ffe3c632Sopenharmony_ci
577ffe3c632Sopenharmony_ci//%PDDM-DEFINE DICTIONARY_POD_IMPL_FOR_KEY(KEY_NAME, KEY_TYPE, KisP, KHELPER)
578ffe3c632Sopenharmony_ci//%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, UInt32, uint32_t, KHELPER)
579ffe3c632Sopenharmony_ci//%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Int32, int32_t, KHELPER)
580ffe3c632Sopenharmony_ci//%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, UInt64, uint64_t, KHELPER)
581ffe3c632Sopenharmony_ci//%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Int64, int64_t, KHELPER)
582ffe3c632Sopenharmony_ci//%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Bool, BOOL, KHELPER)
583ffe3c632Sopenharmony_ci//%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Float, float, KHELPER)
584ffe3c632Sopenharmony_ci//%DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, Double, double, KHELPER)
585ffe3c632Sopenharmony_ci//%DICTIONARY_KEY_TO_ENUM_IMPL(KEY_NAME, KEY_TYPE, KisP, Enum, int32_t, KHELPER)
586ffe3c632Sopenharmony_ci
587ffe3c632Sopenharmony_ci//%PDDM-DEFINE DICTIONARY_KEY_TO_POD_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER)
588ffe3c632Sopenharmony_ci//%DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, POD, VALUE_NAME, value)
589ffe3c632Sopenharmony_ci
590ffe3c632Sopenharmony_ci//%PDDM-DEFINE DICTIONARY_POD_KEY_TO_OBJECT_IMPL(KEY_NAME, KEY_TYPE, VALUE_NAME, VALUE_TYPE)
591ffe3c632Sopenharmony_ci//%DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, , VALUE_NAME, VALUE_TYPE, POD, OBJECT, Object, object)
592ffe3c632Sopenharmony_ci
593ffe3c632Sopenharmony_ci//%PDDM-DEFINE DICTIONARY_COMMON_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR)
594ffe3c632Sopenharmony_ci//%#pragma mark - KEY_NAME -> VALUE_NAME
595ffe3c632Sopenharmony_ci//%
596ffe3c632Sopenharmony_ci//%@implementation GPB##KEY_NAME##VALUE_NAME##Dictionary {
597ffe3c632Sopenharmony_ci//% @package
598ffe3c632Sopenharmony_ci//%  NSMutableDictionary *_dictionary;
599ffe3c632Sopenharmony_ci//%}
600ffe3c632Sopenharmony_ci//%
601ffe3c632Sopenharmony_ci//%- (instancetype)init {
602ffe3c632Sopenharmony_ci//%  return [self initWith##VNAME##s:NULL forKeys:NULL count:0];
603ffe3c632Sopenharmony_ci//%}
604ffe3c632Sopenharmony_ci//%
605ffe3c632Sopenharmony_ci//%- (instancetype)initWith##VNAME##s:(const VALUE_TYPE [])##VNAME_VAR##s
606ffe3c632Sopenharmony_ci//%                ##VNAME$S##  forKeys:(const KEY_TYPE##KisP$S##KisP [])keys
607ffe3c632Sopenharmony_ci//%                ##VNAME$S##    count:(NSUInteger)count {
608ffe3c632Sopenharmony_ci//%  self = [super init];
609ffe3c632Sopenharmony_ci//%  if (self) {
610ffe3c632Sopenharmony_ci//%    _dictionary = [[NSMutableDictionary alloc] init];
611ffe3c632Sopenharmony_ci//%    if (count && VNAME_VAR##s && keys) {
612ffe3c632Sopenharmony_ci//%      for (NSUInteger i = 0; i < count; ++i) {
613ffe3c632Sopenharmony_ci//%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])];
614ffe3c632Sopenharmony_ci//%      }
615ffe3c632Sopenharmony_ci//%    }
616ffe3c632Sopenharmony_ci//%  }
617ffe3c632Sopenharmony_ci//%  return self;
618ffe3c632Sopenharmony_ci//%}
619ffe3c632Sopenharmony_ci//%
620ffe3c632Sopenharmony_ci//%- (instancetype)initWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary {
621ffe3c632Sopenharmony_ci//%  self = [self initWith##VNAME##s:NULL forKeys:NULL count:0];
622ffe3c632Sopenharmony_ci//%  if (self) {
623ffe3c632Sopenharmony_ci//%    if (dictionary) {
624ffe3c632Sopenharmony_ci//%      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
625ffe3c632Sopenharmony_ci//%    }
626ffe3c632Sopenharmony_ci//%  }
627ffe3c632Sopenharmony_ci//%  return self;
628ffe3c632Sopenharmony_ci//%}
629ffe3c632Sopenharmony_ci//%
630ffe3c632Sopenharmony_ci//%- (instancetype)initWithCapacity:(NSUInteger)numItems {
631ffe3c632Sopenharmony_ci//%  #pragma unused(numItems)
632ffe3c632Sopenharmony_ci//%  return [self initWith##VNAME##s:NULL forKeys:NULL count:0];
633ffe3c632Sopenharmony_ci//%}
634ffe3c632Sopenharmony_ci//%
635ffe3c632Sopenharmony_ci//%DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, )
636ffe3c632Sopenharmony_ci//%
637ffe3c632Sopenharmony_ci//%VALUE_FOR_KEY_##VHELPER(KEY_TYPE##KisP$S##KisP, VALUE_NAME, VALUE_TYPE, KHELPER)
638ffe3c632Sopenharmony_ci//%
639ffe3c632Sopenharmony_ci//%DICTIONARY_MUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, )
640ffe3c632Sopenharmony_ci//%
641ffe3c632Sopenharmony_ci//%@end
642ffe3c632Sopenharmony_ci//%
643ffe3c632Sopenharmony_ci
644ffe3c632Sopenharmony_ci//%PDDM-DEFINE DICTIONARY_KEY_TO_ENUM_IMPL(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER)
645ffe3c632Sopenharmony_ci//%DICTIONARY_KEY_TO_ENUM_IMPL2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, POD)
646ffe3c632Sopenharmony_ci//%PDDM-DEFINE DICTIONARY_KEY_TO_ENUM_IMPL2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER)
647ffe3c632Sopenharmony_ci//%#pragma mark - KEY_NAME -> VALUE_NAME
648ffe3c632Sopenharmony_ci//%
649ffe3c632Sopenharmony_ci//%@implementation GPB##KEY_NAME##VALUE_NAME##Dictionary {
650ffe3c632Sopenharmony_ci//% @package
651ffe3c632Sopenharmony_ci//%  NSMutableDictionary *_dictionary;
652ffe3c632Sopenharmony_ci//%  GPBEnumValidationFunc _validationFunc;
653ffe3c632Sopenharmony_ci//%}
654ffe3c632Sopenharmony_ci//%
655ffe3c632Sopenharmony_ci//%@synthesize validationFunc = _validationFunc;
656ffe3c632Sopenharmony_ci//%
657ffe3c632Sopenharmony_ci//%- (instancetype)init {
658ffe3c632Sopenharmony_ci//%  return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
659ffe3c632Sopenharmony_ci//%}
660ffe3c632Sopenharmony_ci//%
661ffe3c632Sopenharmony_ci//%- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
662ffe3c632Sopenharmony_ci//%  return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
663ffe3c632Sopenharmony_ci//%}
664ffe3c632Sopenharmony_ci//%
665ffe3c632Sopenharmony_ci//%- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
666ffe3c632Sopenharmony_ci//%                                 rawValues:(const VALUE_TYPE [])rawValues
667ffe3c632Sopenharmony_ci//%                                   forKeys:(const KEY_TYPE##KisP$S##KisP [])keys
668ffe3c632Sopenharmony_ci//%                                     count:(NSUInteger)count {
669ffe3c632Sopenharmony_ci//%  self = [super init];
670ffe3c632Sopenharmony_ci//%  if (self) {
671ffe3c632Sopenharmony_ci//%    _dictionary = [[NSMutableDictionary alloc] init];
672ffe3c632Sopenharmony_ci//%    _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
673ffe3c632Sopenharmony_ci//%    if (count && rawValues && keys) {
674ffe3c632Sopenharmony_ci//%      for (NSUInteger i = 0; i < count; ++i) {
675ffe3c632Sopenharmony_ci//%DICTIONARY_VALIDATE_KEY_##KHELPER(keys[i], ______)        [_dictionary setObject:WRAPPED##VHELPER(rawValues[i]) forKey:WRAPPED##KHELPER(keys[i])];
676ffe3c632Sopenharmony_ci//%      }
677ffe3c632Sopenharmony_ci//%    }
678ffe3c632Sopenharmony_ci//%  }
679ffe3c632Sopenharmony_ci//%  return self;
680ffe3c632Sopenharmony_ci//%}
681ffe3c632Sopenharmony_ci//%
682ffe3c632Sopenharmony_ci//%- (instancetype)initWithDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)dictionary {
683ffe3c632Sopenharmony_ci//%  self = [self initWithValidationFunction:dictionary.validationFunc
684ffe3c632Sopenharmony_ci//%                                rawValues:NULL
685ffe3c632Sopenharmony_ci//%                                  forKeys:NULL
686ffe3c632Sopenharmony_ci//%                                    count:0];
687ffe3c632Sopenharmony_ci//%  if (self) {
688ffe3c632Sopenharmony_ci//%    if (dictionary) {
689ffe3c632Sopenharmony_ci//%      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
690ffe3c632Sopenharmony_ci//%    }
691ffe3c632Sopenharmony_ci//%  }
692ffe3c632Sopenharmony_ci//%  return self;
693ffe3c632Sopenharmony_ci//%}
694ffe3c632Sopenharmony_ci//%
695ffe3c632Sopenharmony_ci//%- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
696ffe3c632Sopenharmony_ci//%                                  capacity:(NSUInteger)numItems {
697ffe3c632Sopenharmony_ci//%  #pragma unused(numItems)
698ffe3c632Sopenharmony_ci//%  return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
699ffe3c632Sopenharmony_ci//%}
700ffe3c632Sopenharmony_ci//%
701ffe3c632Sopenharmony_ci//%DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, Value, value, Raw)
702ffe3c632Sopenharmony_ci//%
703ffe3c632Sopenharmony_ci//%- (BOOL)getEnum:(VALUE_TYPE *)value forKey:(KEY_TYPE##KisP$S##KisP)key {
704ffe3c632Sopenharmony_ci//%  NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)];
705ffe3c632Sopenharmony_ci//%  if (wrapped && value) {
706ffe3c632Sopenharmony_ci//%    VALUE_TYPE result = UNWRAP##VALUE_NAME(wrapped);
707ffe3c632Sopenharmony_ci//%    if (!_validationFunc(result)) {
708ffe3c632Sopenharmony_ci//%      result = kGPBUnrecognizedEnumeratorValue;
709ffe3c632Sopenharmony_ci//%    }
710ffe3c632Sopenharmony_ci//%    *value = result;
711ffe3c632Sopenharmony_ci//%  }
712ffe3c632Sopenharmony_ci//%  return (wrapped != NULL);
713ffe3c632Sopenharmony_ci//%}
714ffe3c632Sopenharmony_ci//%
715ffe3c632Sopenharmony_ci//%- (BOOL)getRawValue:(VALUE_TYPE *)rawValue forKey:(KEY_TYPE##KisP$S##KisP)key {
716ffe3c632Sopenharmony_ci//%  NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)];
717ffe3c632Sopenharmony_ci//%  if (wrapped && rawValue) {
718ffe3c632Sopenharmony_ci//%    *rawValue = UNWRAP##VALUE_NAME(wrapped);
719ffe3c632Sopenharmony_ci//%  }
720ffe3c632Sopenharmony_ci//%  return (wrapped != NULL);
721ffe3c632Sopenharmony_ci//%}
722ffe3c632Sopenharmony_ci//%
723ffe3c632Sopenharmony_ci//%- (void)enumerateKeysAndEnumsUsingBlock:
724ffe3c632Sopenharmony_ci//%    (void (NS_NOESCAPE ^)(KEY_TYPE KisP##key, VALUE_TYPE value, BOOL *stop))block {
725ffe3c632Sopenharmony_ci//%  GPBEnumValidationFunc func = _validationFunc;
726ffe3c632Sopenharmony_ci//%  BOOL stop = NO;
727ffe3c632Sopenharmony_ci//%  NSEnumerator *keys = [_dictionary keyEnumerator];
728ffe3c632Sopenharmony_ci//%  ENUM_TYPE##KHELPER(KEY_TYPE)##aKey;
729ffe3c632Sopenharmony_ci//%  while ((aKey = [keys nextObject])) {
730ffe3c632Sopenharmony_ci//%    ENUM_TYPE##VHELPER(VALUE_TYPE)##aValue = _dictionary[aKey];
731ffe3c632Sopenharmony_ci//%      VALUE_TYPE unwrapped = UNWRAP##VALUE_NAME(aValue);
732ffe3c632Sopenharmony_ci//%      if (!func(unwrapped)) {
733ffe3c632Sopenharmony_ci//%        unwrapped = kGPBUnrecognizedEnumeratorValue;
734ffe3c632Sopenharmony_ci//%      }
735ffe3c632Sopenharmony_ci//%    block(UNWRAP##KEY_NAME(aKey), unwrapped, &stop);
736ffe3c632Sopenharmony_ci//%    if (stop) {
737ffe3c632Sopenharmony_ci//%      break;
738ffe3c632Sopenharmony_ci//%    }
739ffe3c632Sopenharmony_ci//%  }
740ffe3c632Sopenharmony_ci//%}
741ffe3c632Sopenharmony_ci//%
742ffe3c632Sopenharmony_ci//%DICTIONARY_MUTABLE_CORE2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, Value, Enum, value, Raw)
743ffe3c632Sopenharmony_ci//%
744ffe3c632Sopenharmony_ci//%- (void)setEnum:(VALUE_TYPE)value forKey:(KEY_TYPE##KisP$S##KisP)key {
745ffe3c632Sopenharmony_ci//%DICTIONARY_VALIDATE_KEY_##KHELPER(key, )  if (!_validationFunc(value)) {
746ffe3c632Sopenharmony_ci//%    [NSException raise:NSInvalidArgumentException
747ffe3c632Sopenharmony_ci//%                format:@"GPB##KEY_NAME##VALUE_NAME##Dictionary: Attempt to set an unknown enum value (%d)",
748ffe3c632Sopenharmony_ci//%                       value];
749ffe3c632Sopenharmony_ci//%  }
750ffe3c632Sopenharmony_ci//%
751ffe3c632Sopenharmony_ci//%  [_dictionary setObject:WRAPPED##VHELPER(value) forKey:WRAPPED##KHELPER(key)];
752ffe3c632Sopenharmony_ci//%  if (_autocreator) {
753ffe3c632Sopenharmony_ci//%    GPBAutocreatedDictionaryModified(_autocreator, self);
754ffe3c632Sopenharmony_ci//%  }
755ffe3c632Sopenharmony_ci//%}
756ffe3c632Sopenharmony_ci//%
757ffe3c632Sopenharmony_ci//%@end
758ffe3c632Sopenharmony_ci//%
759ffe3c632Sopenharmony_ci
760ffe3c632Sopenharmony_ci//%PDDM-DEFINE DICTIONARY_IMMUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, ACCESSOR_NAME)
761ffe3c632Sopenharmony_ci//%- (void)dealloc {
762ffe3c632Sopenharmony_ci//%  NSAssert(!_autocreator,
763ffe3c632Sopenharmony_ci//%           @"%@: Autocreator must be cleared before release, autocreator: %@",
764ffe3c632Sopenharmony_ci//%           [self class], _autocreator);
765ffe3c632Sopenharmony_ci//%  [_dictionary release];
766ffe3c632Sopenharmony_ci//%  [super dealloc];
767ffe3c632Sopenharmony_ci//%}
768ffe3c632Sopenharmony_ci//%
769ffe3c632Sopenharmony_ci//%- (instancetype)copyWithZone:(NSZone *)zone {
770ffe3c632Sopenharmony_ci//%  return [[GPB##KEY_NAME##VALUE_NAME##Dictionary allocWithZone:zone] initWithDictionary:self];
771ffe3c632Sopenharmony_ci//%}
772ffe3c632Sopenharmony_ci//%
773ffe3c632Sopenharmony_ci//%- (BOOL)isEqual:(id)other {
774ffe3c632Sopenharmony_ci//%  if (self == other) {
775ffe3c632Sopenharmony_ci//%    return YES;
776ffe3c632Sopenharmony_ci//%  }
777ffe3c632Sopenharmony_ci//%  if (![other isKindOfClass:[GPB##KEY_NAME##VALUE_NAME##Dictionary class]]) {
778ffe3c632Sopenharmony_ci//%    return NO;
779ffe3c632Sopenharmony_ci//%  }
780ffe3c632Sopenharmony_ci//%  GPB##KEY_NAME##VALUE_NAME##Dictionary *otherDictionary = other;
781ffe3c632Sopenharmony_ci//%  return [_dictionary isEqual:otherDictionary->_dictionary];
782ffe3c632Sopenharmony_ci//%}
783ffe3c632Sopenharmony_ci//%
784ffe3c632Sopenharmony_ci//%- (NSUInteger)hash {
785ffe3c632Sopenharmony_ci//%  return _dictionary.count;
786ffe3c632Sopenharmony_ci//%}
787ffe3c632Sopenharmony_ci//%
788ffe3c632Sopenharmony_ci//%- (NSString *)description {
789ffe3c632Sopenharmony_ci//%  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
790ffe3c632Sopenharmony_ci//%}
791ffe3c632Sopenharmony_ci//%
792ffe3c632Sopenharmony_ci//%- (NSUInteger)count {
793ffe3c632Sopenharmony_ci//%  return _dictionary.count;
794ffe3c632Sopenharmony_ci//%}
795ffe3c632Sopenharmony_ci//%
796ffe3c632Sopenharmony_ci//%- (void)enumerateKeysAnd##ACCESSOR_NAME##VNAME##sUsingBlock:
797ffe3c632Sopenharmony_ci//%    (void (NS_NOESCAPE ^)(KEY_TYPE KisP##key, VALUE_TYPE VNAME_VAR, BOOL *stop))block {
798ffe3c632Sopenharmony_ci//%  BOOL stop = NO;
799ffe3c632Sopenharmony_ci//%  NSDictionary *internal = _dictionary;
800ffe3c632Sopenharmony_ci//%  NSEnumerator *keys = [internal keyEnumerator];
801ffe3c632Sopenharmony_ci//%  ENUM_TYPE##KHELPER(KEY_TYPE)##aKey;
802ffe3c632Sopenharmony_ci//%  while ((aKey = [keys nextObject])) {
803ffe3c632Sopenharmony_ci//%    ENUM_TYPE##VHELPER(VALUE_TYPE)##a##VNAME_VAR$u = internal[aKey];
804ffe3c632Sopenharmony_ci//%    block(UNWRAP##KEY_NAME(aKey), UNWRAP##VALUE_NAME(a##VNAME_VAR$u), &stop);
805ffe3c632Sopenharmony_ci//%    if (stop) {
806ffe3c632Sopenharmony_ci//%      break;
807ffe3c632Sopenharmony_ci//%    }
808ffe3c632Sopenharmony_ci//%  }
809ffe3c632Sopenharmony_ci//%}
810ffe3c632Sopenharmony_ci//%
811ffe3c632Sopenharmony_ci//%EXTRA_METHODS_##VHELPER(KEY_NAME, VALUE_NAME)- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
812ffe3c632Sopenharmony_ci//%  NSDictionary *internal = _dictionary;
813ffe3c632Sopenharmony_ci//%  NSUInteger count = internal.count;
814ffe3c632Sopenharmony_ci//%  if (count == 0) {
815ffe3c632Sopenharmony_ci//%    return 0;
816ffe3c632Sopenharmony_ci//%  }
817ffe3c632Sopenharmony_ci//%
818ffe3c632Sopenharmony_ci//%  GPBDataType valueDataType = GPBGetFieldDataType(field);
819ffe3c632Sopenharmony_ci//%  GPBDataType keyDataType = field.mapKeyDataType;
820ffe3c632Sopenharmony_ci//%  size_t result = 0;
821ffe3c632Sopenharmony_ci//%  NSEnumerator *keys = [internal keyEnumerator];
822ffe3c632Sopenharmony_ci//%  ENUM_TYPE##KHELPER(KEY_TYPE)##aKey;
823ffe3c632Sopenharmony_ci//%  while ((aKey = [keys nextObject])) {
824ffe3c632Sopenharmony_ci//%    ENUM_TYPE##VHELPER(VALUE_TYPE)##a##VNAME_VAR$u = internal[aKey];
825ffe3c632Sopenharmony_ci//%    size_t msgSize = ComputeDict##KEY_NAME##FieldSize(UNWRAP##KEY_NAME(aKey), kMapKeyFieldNumber, keyDataType);
826ffe3c632Sopenharmony_ci//%    msgSize += ComputeDict##VALUE_NAME##FieldSize(UNWRAP##VALUE_NAME(a##VNAME_VAR$u), kMapValueFieldNumber, valueDataType);
827ffe3c632Sopenharmony_ci//%    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
828ffe3c632Sopenharmony_ci//%  }
829ffe3c632Sopenharmony_ci//%  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
830ffe3c632Sopenharmony_ci//%  result += tagSize * count;
831ffe3c632Sopenharmony_ci//%  return result;
832ffe3c632Sopenharmony_ci//%}
833ffe3c632Sopenharmony_ci//%
834ffe3c632Sopenharmony_ci//%- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
835ffe3c632Sopenharmony_ci//%                         asField:(GPBFieldDescriptor *)field {
836ffe3c632Sopenharmony_ci//%  GPBDataType valueDataType = GPBGetFieldDataType(field);
837ffe3c632Sopenharmony_ci//%  GPBDataType keyDataType = field.mapKeyDataType;
838ffe3c632Sopenharmony_ci//%  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
839ffe3c632Sopenharmony_ci//%  NSDictionary *internal = _dictionary;
840ffe3c632Sopenharmony_ci//%  NSEnumerator *keys = [internal keyEnumerator];
841ffe3c632Sopenharmony_ci//%  ENUM_TYPE##KHELPER(KEY_TYPE)##aKey;
842ffe3c632Sopenharmony_ci//%  while ((aKey = [keys nextObject])) {
843ffe3c632Sopenharmony_ci//%    ENUM_TYPE##VHELPER(VALUE_TYPE)##a##VNAME_VAR$u = internal[aKey];
844ffe3c632Sopenharmony_ci//%    [outputStream writeInt32NoTag:tag];
845ffe3c632Sopenharmony_ci//%    // Write the size of the message.
846ffe3c632Sopenharmony_ci//%    KEY_TYPE KisP##unwrappedKey = UNWRAP##KEY_NAME(aKey);
847ffe3c632Sopenharmony_ci//%    VALUE_TYPE unwrappedValue = UNWRAP##VALUE_NAME(a##VNAME_VAR$u);
848ffe3c632Sopenharmony_ci//%    size_t msgSize = ComputeDict##KEY_NAME##FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
849ffe3c632Sopenharmony_ci//%    msgSize += ComputeDict##VALUE_NAME##FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
850ffe3c632Sopenharmony_ci//%    [outputStream writeInt32NoTag:(int32_t)msgSize];
851ffe3c632Sopenharmony_ci//%    // Write the fields.
852ffe3c632Sopenharmony_ci//%    WriteDict##KEY_NAME##Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
853ffe3c632Sopenharmony_ci//%    WriteDict##VALUE_NAME##Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
854ffe3c632Sopenharmony_ci//%  }
855ffe3c632Sopenharmony_ci//%}
856ffe3c632Sopenharmony_ci//%
857ffe3c632Sopenharmony_ci//%SERIAL_DATA_FOR_ENTRY_##VHELPER(KEY_NAME, VALUE_NAME)- (void)setGPBGenericValue:(GPBGenericValue *)value
858ffe3c632Sopenharmony_ci//%     forGPBGenericValueKey:(GPBGenericValue *)key {
859ffe3c632Sopenharmony_ci//%  [_dictionary setObject:WRAPPED##VHELPER(value->##GPBVALUE_##VHELPER(VALUE_NAME)##) forKey:WRAPPED##KHELPER(key->value##KEY_NAME)];
860ffe3c632Sopenharmony_ci//%}
861ffe3c632Sopenharmony_ci//%
862ffe3c632Sopenharmony_ci//%- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
863ffe3c632Sopenharmony_ci//%  [self enumerateKeysAnd##ACCESSOR_NAME##VNAME##sUsingBlock:^(KEY_TYPE KisP##key, VALUE_TYPE VNAME_VAR, BOOL *stop) {
864ffe3c632Sopenharmony_ci//%      #pragma unused(stop)
865ffe3c632Sopenharmony_ci//%      block(TEXT_FORMAT_OBJ##KEY_NAME(key), TEXT_FORMAT_OBJ##VALUE_NAME(VNAME_VAR));
866ffe3c632Sopenharmony_ci//%  }];
867ffe3c632Sopenharmony_ci//%}
868ffe3c632Sopenharmony_ci//%PDDM-DEFINE DICTIONARY_MUTABLE_CORE(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_VAR, ACCESSOR_NAME)
869ffe3c632Sopenharmony_ci//%DICTIONARY_MUTABLE_CORE2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME, VNAME_VAR, ACCESSOR_NAME)
870ffe3c632Sopenharmony_ci//%PDDM-DEFINE DICTIONARY_MUTABLE_CORE2(KEY_NAME, KEY_TYPE, KisP, VALUE_NAME, VALUE_TYPE, KHELPER, VHELPER, VNAME, VNAME_REMOVE, VNAME_VAR, ACCESSOR_NAME)
871ffe3c632Sopenharmony_ci//%- (void)add##ACCESSOR_NAME##EntriesFromDictionary:(GPB##KEY_NAME##VALUE_NAME##Dictionary *)otherDictionary {
872ffe3c632Sopenharmony_ci//%  if (otherDictionary) {
873ffe3c632Sopenharmony_ci//%    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
874ffe3c632Sopenharmony_ci//%    if (_autocreator) {
875ffe3c632Sopenharmony_ci//%      GPBAutocreatedDictionaryModified(_autocreator, self);
876ffe3c632Sopenharmony_ci//%    }
877ffe3c632Sopenharmony_ci//%  }
878ffe3c632Sopenharmony_ci//%}
879ffe3c632Sopenharmony_ci//%
880ffe3c632Sopenharmony_ci//%- (void)set##ACCESSOR_NAME##VNAME##:(VALUE_TYPE)VNAME_VAR forKey:(KEY_TYPE##KisP$S##KisP)key {
881ffe3c632Sopenharmony_ci//%DICTIONARY_VALIDATE_VALUE_##VHELPER(VNAME_VAR, )##DICTIONARY_VALIDATE_KEY_##KHELPER(key, )  [_dictionary setObject:WRAPPED##VHELPER(VNAME_VAR) forKey:WRAPPED##KHELPER(key)];
882ffe3c632Sopenharmony_ci//%  if (_autocreator) {
883ffe3c632Sopenharmony_ci//%    GPBAutocreatedDictionaryModified(_autocreator, self);
884ffe3c632Sopenharmony_ci//%  }
885ffe3c632Sopenharmony_ci//%}
886ffe3c632Sopenharmony_ci//%
887ffe3c632Sopenharmony_ci//%- (void)remove##VNAME_REMOVE##ForKey:(KEY_TYPE##KisP$S##KisP)aKey {
888ffe3c632Sopenharmony_ci//%  [_dictionary removeObjectForKey:WRAPPED##KHELPER(aKey)];
889ffe3c632Sopenharmony_ci//%}
890ffe3c632Sopenharmony_ci//%
891ffe3c632Sopenharmony_ci//%- (void)removeAll {
892ffe3c632Sopenharmony_ci//%  [_dictionary removeAllObjects];
893ffe3c632Sopenharmony_ci//%}
894ffe3c632Sopenharmony_ci
895ffe3c632Sopenharmony_ci//
896ffe3c632Sopenharmony_ci// Custom Generation for Bool keys
897ffe3c632Sopenharmony_ci//
898ffe3c632Sopenharmony_ci
899ffe3c632Sopenharmony_ci//%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_POD_IMPL(VALUE_NAME, VALUE_TYPE)
900ffe3c632Sopenharmony_ci//%DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, POD, VALUE_NAME, value)
901ffe3c632Sopenharmony_ci//%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_OBJECT_IMPL(VALUE_NAME, VALUE_TYPE)
902ffe3c632Sopenharmony_ci//%DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, OBJECT, Object, object)
903ffe3c632Sopenharmony_ci
904ffe3c632Sopenharmony_ci//%PDDM-DEFINE DICTIONARY_BOOL_KEY_TO_VALUE_IMPL(VALUE_NAME, VALUE_TYPE, HELPER, VNAME, VNAME_VAR)
905ffe3c632Sopenharmony_ci//%#pragma mark - Bool -> VALUE_NAME
906ffe3c632Sopenharmony_ci//%
907ffe3c632Sopenharmony_ci//%@implementation GPBBool##VALUE_NAME##Dictionary {
908ffe3c632Sopenharmony_ci//% @package
909ffe3c632Sopenharmony_ci//%  VALUE_TYPE _values[2];
910ffe3c632Sopenharmony_ci//%BOOL_DICT_HAS_STORAGE_##HELPER()}
911ffe3c632Sopenharmony_ci//%
912ffe3c632Sopenharmony_ci//%- (instancetype)init {
913ffe3c632Sopenharmony_ci//%  return [self initWith##VNAME##s:NULL forKeys:NULL count:0];
914ffe3c632Sopenharmony_ci//%}
915ffe3c632Sopenharmony_ci//%
916ffe3c632Sopenharmony_ci//%BOOL_DICT_INITS_##HELPER(VALUE_NAME, VALUE_TYPE)
917ffe3c632Sopenharmony_ci//%
918ffe3c632Sopenharmony_ci//%- (instancetype)initWithCapacity:(NSUInteger)numItems {
919ffe3c632Sopenharmony_ci//%  #pragma unused(numItems)
920ffe3c632Sopenharmony_ci//%  return [self initWith##VNAME##s:NULL forKeys:NULL count:0];
921ffe3c632Sopenharmony_ci//%}
922ffe3c632Sopenharmony_ci//%
923ffe3c632Sopenharmony_ci//%BOOL_DICT_DEALLOC##HELPER()
924ffe3c632Sopenharmony_ci//%
925ffe3c632Sopenharmony_ci//%- (instancetype)copyWithZone:(NSZone *)zone {
926ffe3c632Sopenharmony_ci//%  return [[GPBBool##VALUE_NAME##Dictionary allocWithZone:zone] initWithDictionary:self];
927ffe3c632Sopenharmony_ci//%}
928ffe3c632Sopenharmony_ci//%
929ffe3c632Sopenharmony_ci//%- (BOOL)isEqual:(id)other {
930ffe3c632Sopenharmony_ci//%  if (self == other) {
931ffe3c632Sopenharmony_ci//%    return YES;
932ffe3c632Sopenharmony_ci//%  }
933ffe3c632Sopenharmony_ci//%  if (![other isKindOfClass:[GPBBool##VALUE_NAME##Dictionary class]]) {
934ffe3c632Sopenharmony_ci//%    return NO;
935ffe3c632Sopenharmony_ci//%  }
936ffe3c632Sopenharmony_ci//%  GPBBool##VALUE_NAME##Dictionary *otherDictionary = other;
937ffe3c632Sopenharmony_ci//%  if ((BOOL_DICT_W_HAS##HELPER(0, ) != BOOL_DICT_W_HAS##HELPER(0, otherDictionary->)) ||
938ffe3c632Sopenharmony_ci//%      (BOOL_DICT_W_HAS##HELPER(1, ) != BOOL_DICT_W_HAS##HELPER(1, otherDictionary->))) {
939ffe3c632Sopenharmony_ci//%    return NO;
940ffe3c632Sopenharmony_ci//%  }
941ffe3c632Sopenharmony_ci//%  if ((BOOL_DICT_W_HAS##HELPER(0, ) && (NEQ_##HELPER(_values[0], otherDictionary->_values[0]))) ||
942ffe3c632Sopenharmony_ci//%      (BOOL_DICT_W_HAS##HELPER(1, ) && (NEQ_##HELPER(_values[1], otherDictionary->_values[1])))) {
943ffe3c632Sopenharmony_ci//%    return NO;
944ffe3c632Sopenharmony_ci//%  }
945ffe3c632Sopenharmony_ci//%  return YES;
946ffe3c632Sopenharmony_ci//%}
947ffe3c632Sopenharmony_ci//%
948ffe3c632Sopenharmony_ci//%- (NSUInteger)hash {
949ffe3c632Sopenharmony_ci//%  return (BOOL_DICT_W_HAS##HELPER(0, ) ? 1 : 0) + (BOOL_DICT_W_HAS##HELPER(1, ) ? 1 : 0);
950ffe3c632Sopenharmony_ci//%}
951ffe3c632Sopenharmony_ci//%
952ffe3c632Sopenharmony_ci//%- (NSString *)description {
953ffe3c632Sopenharmony_ci//%  NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
954ffe3c632Sopenharmony_ci//%  if (BOOL_DICT_W_HAS##HELPER(0, )) {
955ffe3c632Sopenharmony_ci//%    [result appendFormat:@"NO: STR_FORMAT_##HELPER(VALUE_NAME)", _values[0]];
956ffe3c632Sopenharmony_ci//%  }
957ffe3c632Sopenharmony_ci//%  if (BOOL_DICT_W_HAS##HELPER(1, )) {
958ffe3c632Sopenharmony_ci//%    [result appendFormat:@"YES: STR_FORMAT_##HELPER(VALUE_NAME)", _values[1]];
959ffe3c632Sopenharmony_ci//%  }
960ffe3c632Sopenharmony_ci//%  [result appendString:@" }"];
961ffe3c632Sopenharmony_ci//%  return result;
962ffe3c632Sopenharmony_ci//%}
963ffe3c632Sopenharmony_ci//%
964ffe3c632Sopenharmony_ci//%- (NSUInteger)count {
965ffe3c632Sopenharmony_ci//%  return (BOOL_DICT_W_HAS##HELPER(0, ) ? 1 : 0) + (BOOL_DICT_W_HAS##HELPER(1, ) ? 1 : 0);
966ffe3c632Sopenharmony_ci//%}
967ffe3c632Sopenharmony_ci//%
968ffe3c632Sopenharmony_ci//%BOOL_VALUE_FOR_KEY_##HELPER(VALUE_NAME, VALUE_TYPE)
969ffe3c632Sopenharmony_ci//%
970ffe3c632Sopenharmony_ci//%BOOL_SET_GPBVALUE_FOR_KEY_##HELPER(VALUE_NAME, VALUE_TYPE, VisP)
971ffe3c632Sopenharmony_ci//%
972ffe3c632Sopenharmony_ci//%- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
973ffe3c632Sopenharmony_ci//%  if (BOOL_DICT_HAS##HELPER(0, )) {
974ffe3c632Sopenharmony_ci//%    block(@"false", TEXT_FORMAT_OBJ##VALUE_NAME(_values[0]));
975ffe3c632Sopenharmony_ci//%  }
976ffe3c632Sopenharmony_ci//%  if (BOOL_DICT_W_HAS##HELPER(1, )) {
977ffe3c632Sopenharmony_ci//%    block(@"true", TEXT_FORMAT_OBJ##VALUE_NAME(_values[1]));
978ffe3c632Sopenharmony_ci//%  }
979ffe3c632Sopenharmony_ci//%}
980ffe3c632Sopenharmony_ci//%
981ffe3c632Sopenharmony_ci//%- (void)enumerateKeysAnd##VNAME##sUsingBlock:
982ffe3c632Sopenharmony_ci//%    (void (NS_NOESCAPE ^)(BOOL key, VALUE_TYPE VNAME_VAR, BOOL *stop))block {
983ffe3c632Sopenharmony_ci//%  BOOL stop = NO;
984ffe3c632Sopenharmony_ci//%  if (BOOL_DICT_HAS##HELPER(0, )) {
985ffe3c632Sopenharmony_ci//%    block(NO, _values[0], &stop);
986ffe3c632Sopenharmony_ci//%  }
987ffe3c632Sopenharmony_ci//%  if (!stop && BOOL_DICT_W_HAS##HELPER(1, )) {
988ffe3c632Sopenharmony_ci//%    block(YES, _values[1], &stop);
989ffe3c632Sopenharmony_ci//%  }
990ffe3c632Sopenharmony_ci//%}
991ffe3c632Sopenharmony_ci//%
992ffe3c632Sopenharmony_ci//%BOOL_EXTRA_METHODS_##HELPER(Bool, VALUE_NAME)- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
993ffe3c632Sopenharmony_ci//%  GPBDataType valueDataType = GPBGetFieldDataType(field);
994ffe3c632Sopenharmony_ci//%  NSUInteger count = 0;
995ffe3c632Sopenharmony_ci//%  size_t result = 0;
996ffe3c632Sopenharmony_ci//%  for (int i = 0; i < 2; ++i) {
997ffe3c632Sopenharmony_ci//%    if (BOOL_DICT_HAS##HELPER(i, )) {
998ffe3c632Sopenharmony_ci//%      ++count;
999ffe3c632Sopenharmony_ci//%      size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
1000ffe3c632Sopenharmony_ci//%      msgSize += ComputeDict##VALUE_NAME##FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
1001ffe3c632Sopenharmony_ci//%      result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
1002ffe3c632Sopenharmony_ci//%    }
1003ffe3c632Sopenharmony_ci//%  }
1004ffe3c632Sopenharmony_ci//%  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
1005ffe3c632Sopenharmony_ci//%  result += tagSize * count;
1006ffe3c632Sopenharmony_ci//%  return result;
1007ffe3c632Sopenharmony_ci//%}
1008ffe3c632Sopenharmony_ci//%
1009ffe3c632Sopenharmony_ci//%- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
1010ffe3c632Sopenharmony_ci//%                         asField:(GPBFieldDescriptor *)field {
1011ffe3c632Sopenharmony_ci//%  GPBDataType valueDataType = GPBGetFieldDataType(field);
1012ffe3c632Sopenharmony_ci//%  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
1013ffe3c632Sopenharmony_ci//%  for (int i = 0; i < 2; ++i) {
1014ffe3c632Sopenharmony_ci//%    if (BOOL_DICT_HAS##HELPER(i, )) {
1015ffe3c632Sopenharmony_ci//%      // Write the tag.
1016ffe3c632Sopenharmony_ci//%      [outputStream writeInt32NoTag:tag];
1017ffe3c632Sopenharmony_ci//%      // Write the size of the message.
1018ffe3c632Sopenharmony_ci//%      size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
1019ffe3c632Sopenharmony_ci//%      msgSize += ComputeDict##VALUE_NAME##FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
1020ffe3c632Sopenharmony_ci//%      [outputStream writeInt32NoTag:(int32_t)msgSize];
1021ffe3c632Sopenharmony_ci//%      // Write the fields.
1022ffe3c632Sopenharmony_ci//%      WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
1023ffe3c632Sopenharmony_ci//%      WriteDict##VALUE_NAME##Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
1024ffe3c632Sopenharmony_ci//%    }
1025ffe3c632Sopenharmony_ci//%  }
1026ffe3c632Sopenharmony_ci//%}
1027ffe3c632Sopenharmony_ci//%
1028ffe3c632Sopenharmony_ci//%BOOL_DICT_MUTATIONS_##HELPER(VALUE_NAME, VALUE_TYPE)
1029ffe3c632Sopenharmony_ci//%
1030ffe3c632Sopenharmony_ci//%@end
1031ffe3c632Sopenharmony_ci//%
1032ffe3c632Sopenharmony_ci
1033ffe3c632Sopenharmony_ci
1034ffe3c632Sopenharmony_ci//
1035ffe3c632Sopenharmony_ci// Helpers for PODs
1036ffe3c632Sopenharmony_ci//
1037ffe3c632Sopenharmony_ci
1038ffe3c632Sopenharmony_ci//%PDDM-DEFINE VALUE_FOR_KEY_POD(KEY_TYPE, VALUE_NAME, VALUE_TYPE, KHELPER)
1039ffe3c632Sopenharmony_ci//%- (BOOL)get##VALUE_NAME##:(nullable VALUE_TYPE *)value forKey:(KEY_TYPE)key {
1040ffe3c632Sopenharmony_ci//%  NSNumber *wrapped = [_dictionary objectForKey:WRAPPED##KHELPER(key)];
1041ffe3c632Sopenharmony_ci//%  if (wrapped && value) {
1042ffe3c632Sopenharmony_ci//%    *value = UNWRAP##VALUE_NAME(wrapped);
1043ffe3c632Sopenharmony_ci//%  }
1044ffe3c632Sopenharmony_ci//%  return (wrapped != NULL);
1045ffe3c632Sopenharmony_ci//%}
1046ffe3c632Sopenharmony_ci//%PDDM-DEFINE WRAPPEDPOD(VALUE)
1047ffe3c632Sopenharmony_ci//%@(VALUE)
1048ffe3c632Sopenharmony_ci//%PDDM-DEFINE UNWRAPUInt32(VALUE)
1049ffe3c632Sopenharmony_ci//%[VALUE unsignedIntValue]
1050ffe3c632Sopenharmony_ci//%PDDM-DEFINE UNWRAPInt32(VALUE)
1051ffe3c632Sopenharmony_ci//%[VALUE intValue]
1052ffe3c632Sopenharmony_ci//%PDDM-DEFINE UNWRAPUInt64(VALUE)
1053ffe3c632Sopenharmony_ci//%[VALUE unsignedLongLongValue]
1054ffe3c632Sopenharmony_ci//%PDDM-DEFINE UNWRAPInt64(VALUE)
1055ffe3c632Sopenharmony_ci//%[VALUE longLongValue]
1056ffe3c632Sopenharmony_ci//%PDDM-DEFINE UNWRAPBool(VALUE)
1057ffe3c632Sopenharmony_ci//%[VALUE boolValue]
1058ffe3c632Sopenharmony_ci//%PDDM-DEFINE UNWRAPFloat(VALUE)
1059ffe3c632Sopenharmony_ci//%[VALUE floatValue]
1060ffe3c632Sopenharmony_ci//%PDDM-DEFINE UNWRAPDouble(VALUE)
1061ffe3c632Sopenharmony_ci//%[VALUE doubleValue]
1062ffe3c632Sopenharmony_ci//%PDDM-DEFINE UNWRAPEnum(VALUE)
1063ffe3c632Sopenharmony_ci//%[VALUE intValue]
1064ffe3c632Sopenharmony_ci//%PDDM-DEFINE TEXT_FORMAT_OBJUInt32(VALUE)
1065ffe3c632Sopenharmony_ci//%[NSString stringWithFormat:@"%u", VALUE]
1066ffe3c632Sopenharmony_ci//%PDDM-DEFINE TEXT_FORMAT_OBJInt32(VALUE)
1067ffe3c632Sopenharmony_ci//%[NSString stringWithFormat:@"%d", VALUE]
1068ffe3c632Sopenharmony_ci//%PDDM-DEFINE TEXT_FORMAT_OBJUInt64(VALUE)
1069ffe3c632Sopenharmony_ci//%[NSString stringWithFormat:@"%llu", VALUE]
1070ffe3c632Sopenharmony_ci//%PDDM-DEFINE TEXT_FORMAT_OBJInt64(VALUE)
1071ffe3c632Sopenharmony_ci//%[NSString stringWithFormat:@"%lld", VALUE]
1072ffe3c632Sopenharmony_ci//%PDDM-DEFINE TEXT_FORMAT_OBJBool(VALUE)
1073ffe3c632Sopenharmony_ci//%(VALUE ? @"true" : @"false")
1074ffe3c632Sopenharmony_ci//%PDDM-DEFINE TEXT_FORMAT_OBJFloat(VALUE)
1075ffe3c632Sopenharmony_ci//%[NSString stringWithFormat:@"%.*g", FLT_DIG, VALUE]
1076ffe3c632Sopenharmony_ci//%PDDM-DEFINE TEXT_FORMAT_OBJDouble(VALUE)
1077ffe3c632Sopenharmony_ci//%[NSString stringWithFormat:@"%.*lg", DBL_DIG, VALUE]
1078ffe3c632Sopenharmony_ci//%PDDM-DEFINE TEXT_FORMAT_OBJEnum(VALUE)
1079ffe3c632Sopenharmony_ci//%@(VALUE)
1080ffe3c632Sopenharmony_ci//%PDDM-DEFINE ENUM_TYPEPOD(TYPE)
1081ffe3c632Sopenharmony_ci//%NSNumber *
1082ffe3c632Sopenharmony_ci//%PDDM-DEFINE NEQ_POD(VAL1, VAL2)
1083ffe3c632Sopenharmony_ci//%VAL1 != VAL2
1084ffe3c632Sopenharmony_ci//%PDDM-DEFINE EXTRA_METHODS_POD(KEY_NAME, VALUE_NAME)
1085ffe3c632Sopenharmony_ci// Empty
1086ffe3c632Sopenharmony_ci//%PDDM-DEFINE BOOL_EXTRA_METHODS_POD(KEY_NAME, VALUE_NAME)
1087ffe3c632Sopenharmony_ci// Empty
1088ffe3c632Sopenharmony_ci//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD(KEY_NAME, VALUE_NAME)
1089ffe3c632Sopenharmony_ci//%SERIAL_DATA_FOR_ENTRY_POD_##VALUE_NAME(KEY_NAME)
1090ffe3c632Sopenharmony_ci//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_UInt32(KEY_NAME)
1091ffe3c632Sopenharmony_ci// Empty
1092ffe3c632Sopenharmony_ci//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Int32(KEY_NAME)
1093ffe3c632Sopenharmony_ci// Empty
1094ffe3c632Sopenharmony_ci//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_UInt64(KEY_NAME)
1095ffe3c632Sopenharmony_ci// Empty
1096ffe3c632Sopenharmony_ci//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Int64(KEY_NAME)
1097ffe3c632Sopenharmony_ci// Empty
1098ffe3c632Sopenharmony_ci//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Bool(KEY_NAME)
1099ffe3c632Sopenharmony_ci// Empty
1100ffe3c632Sopenharmony_ci//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Float(KEY_NAME)
1101ffe3c632Sopenharmony_ci// Empty
1102ffe3c632Sopenharmony_ci//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Double(KEY_NAME)
1103ffe3c632Sopenharmony_ci// Empty
1104ffe3c632Sopenharmony_ci//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_POD_Enum(KEY_NAME)
1105ffe3c632Sopenharmony_ci//%- (NSData *)serializedDataForUnknownValue:(int32_t)value
1106ffe3c632Sopenharmony_ci//%                                   forKey:(GPBGenericValue *)key
1107ffe3c632Sopenharmony_ci//%                              keyDataType:(GPBDataType)keyDataType {
1108ffe3c632Sopenharmony_ci//%  size_t msgSize = ComputeDict##KEY_NAME##FieldSize(key->value##KEY_NAME, kMapKeyFieldNumber, keyDataType);
1109ffe3c632Sopenharmony_ci//%  msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
1110ffe3c632Sopenharmony_ci//%  NSMutableData *data = [NSMutableData dataWithLength:msgSize];
1111ffe3c632Sopenharmony_ci//%  GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
1112ffe3c632Sopenharmony_ci//%  WriteDict##KEY_NAME##Field(outputStream, key->value##KEY_NAME, kMapKeyFieldNumber, keyDataType);
1113ffe3c632Sopenharmony_ci//%  WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
1114ffe3c632Sopenharmony_ci//%  [outputStream release];
1115ffe3c632Sopenharmony_ci//%  return data;
1116ffe3c632Sopenharmony_ci//%}
1117ffe3c632Sopenharmony_ci//%
1118ffe3c632Sopenharmony_ci//%PDDM-DEFINE GPBVALUE_POD(VALUE_NAME)
1119ffe3c632Sopenharmony_ci//%value##VALUE_NAME
1120ffe3c632Sopenharmony_ci//%PDDM-DEFINE DICTIONARY_VALIDATE_VALUE_POD(VALUE_NAME, EXTRA_INDENT)
1121ffe3c632Sopenharmony_ci// Empty
1122ffe3c632Sopenharmony_ci//%PDDM-DEFINE DICTIONARY_VALIDATE_KEY_POD(KEY_NAME, EXTRA_INDENT)
1123ffe3c632Sopenharmony_ci// Empty
1124ffe3c632Sopenharmony_ci
1125ffe3c632Sopenharmony_ci//%PDDM-DEFINE BOOL_DICT_HAS_STORAGE_POD()
1126ffe3c632Sopenharmony_ci//%  BOOL _valueSet[2];
1127ffe3c632Sopenharmony_ci//%
1128ffe3c632Sopenharmony_ci//%PDDM-DEFINE BOOL_DICT_INITS_POD(VALUE_NAME, VALUE_TYPE)
1129ffe3c632Sopenharmony_ci//%- (instancetype)initWith##VALUE_NAME##s:(const VALUE_TYPE [])values
1130ffe3c632Sopenharmony_ci//%                 ##VALUE_NAME$S## forKeys:(const BOOL [])keys
1131ffe3c632Sopenharmony_ci//%                 ##VALUE_NAME$S##   count:(NSUInteger)count {
1132ffe3c632Sopenharmony_ci//%  self = [super init];
1133ffe3c632Sopenharmony_ci//%  if (self) {
1134ffe3c632Sopenharmony_ci//%    for (NSUInteger i = 0; i < count; ++i) {
1135ffe3c632Sopenharmony_ci//%      int idx = keys[i] ? 1 : 0;
1136ffe3c632Sopenharmony_ci//%      _values[idx] = values[i];
1137ffe3c632Sopenharmony_ci//%      _valueSet[idx] = YES;
1138ffe3c632Sopenharmony_ci//%    }
1139ffe3c632Sopenharmony_ci//%  }
1140ffe3c632Sopenharmony_ci//%  return self;
1141ffe3c632Sopenharmony_ci//%}
1142ffe3c632Sopenharmony_ci//%
1143ffe3c632Sopenharmony_ci//%- (instancetype)initWithDictionary:(GPBBool##VALUE_NAME##Dictionary *)dictionary {
1144ffe3c632Sopenharmony_ci//%  self = [self initWith##VALUE_NAME##s:NULL forKeys:NULL count:0];
1145ffe3c632Sopenharmony_ci//%  if (self) {
1146ffe3c632Sopenharmony_ci//%    if (dictionary) {
1147ffe3c632Sopenharmony_ci//%      for (int i = 0; i < 2; ++i) {
1148ffe3c632Sopenharmony_ci//%        if (dictionary->_valueSet[i]) {
1149ffe3c632Sopenharmony_ci//%          _values[i] = dictionary->_values[i];
1150ffe3c632Sopenharmony_ci//%          _valueSet[i] = YES;
1151ffe3c632Sopenharmony_ci//%        }
1152ffe3c632Sopenharmony_ci//%      }
1153ffe3c632Sopenharmony_ci//%    }
1154ffe3c632Sopenharmony_ci//%  }
1155ffe3c632Sopenharmony_ci//%  return self;
1156ffe3c632Sopenharmony_ci//%}
1157ffe3c632Sopenharmony_ci//%PDDM-DEFINE BOOL_DICT_DEALLOCPOD()
1158ffe3c632Sopenharmony_ci//%#if !defined(NS_BLOCK_ASSERTIONS)
1159ffe3c632Sopenharmony_ci//%- (void)dealloc {
1160ffe3c632Sopenharmony_ci//%  NSAssert(!_autocreator,
1161ffe3c632Sopenharmony_ci//%           @"%@: Autocreator must be cleared before release, autocreator: %@",
1162ffe3c632Sopenharmony_ci//%           [self class], _autocreator);
1163ffe3c632Sopenharmony_ci//%  [super dealloc];
1164ffe3c632Sopenharmony_ci//%}
1165ffe3c632Sopenharmony_ci//%#endif  // !defined(NS_BLOCK_ASSERTIONS)
1166ffe3c632Sopenharmony_ci//%PDDM-DEFINE BOOL_DICT_W_HASPOD(IDX, REF)
1167ffe3c632Sopenharmony_ci//%BOOL_DICT_HASPOD(IDX, REF)
1168ffe3c632Sopenharmony_ci//%PDDM-DEFINE BOOL_DICT_HASPOD(IDX, REF)
1169ffe3c632Sopenharmony_ci//%REF##_valueSet[IDX]
1170ffe3c632Sopenharmony_ci//%PDDM-DEFINE BOOL_VALUE_FOR_KEY_POD(VALUE_NAME, VALUE_TYPE)
1171ffe3c632Sopenharmony_ci//%- (BOOL)get##VALUE_NAME##:(VALUE_TYPE *)value forKey:(BOOL)key {
1172ffe3c632Sopenharmony_ci//%  int idx = (key ? 1 : 0);
1173ffe3c632Sopenharmony_ci//%  if (_valueSet[idx]) {
1174ffe3c632Sopenharmony_ci//%    if (value) {
1175ffe3c632Sopenharmony_ci//%      *value = _values[idx];
1176ffe3c632Sopenharmony_ci//%    }
1177ffe3c632Sopenharmony_ci//%    return YES;
1178ffe3c632Sopenharmony_ci//%  }
1179ffe3c632Sopenharmony_ci//%  return NO;
1180ffe3c632Sopenharmony_ci//%}
1181ffe3c632Sopenharmony_ci//%PDDM-DEFINE BOOL_SET_GPBVALUE_FOR_KEY_POD(VALUE_NAME, VALUE_TYPE, VisP)
1182ffe3c632Sopenharmony_ci//%- (void)setGPBGenericValue:(GPBGenericValue *)value
1183ffe3c632Sopenharmony_ci//%     forGPBGenericValueKey:(GPBGenericValue *)key {
1184ffe3c632Sopenharmony_ci//%  int idx = (key->valueBool ? 1 : 0);
1185ffe3c632Sopenharmony_ci//%  _values[idx] = value->value##VALUE_NAME;
1186ffe3c632Sopenharmony_ci//%  _valueSet[idx] = YES;
1187ffe3c632Sopenharmony_ci//%}
1188ffe3c632Sopenharmony_ci//%PDDM-DEFINE BOOL_DICT_MUTATIONS_POD(VALUE_NAME, VALUE_TYPE)
1189ffe3c632Sopenharmony_ci//%- (void)addEntriesFromDictionary:(GPBBool##VALUE_NAME##Dictionary *)otherDictionary {
1190ffe3c632Sopenharmony_ci//%  if (otherDictionary) {
1191ffe3c632Sopenharmony_ci//%    for (int i = 0; i < 2; ++i) {
1192ffe3c632Sopenharmony_ci//%      if (otherDictionary->_valueSet[i]) {
1193ffe3c632Sopenharmony_ci//%        _valueSet[i] = YES;
1194ffe3c632Sopenharmony_ci//%        _values[i] = otherDictionary->_values[i];
1195ffe3c632Sopenharmony_ci//%      }
1196ffe3c632Sopenharmony_ci//%    }
1197ffe3c632Sopenharmony_ci//%    if (_autocreator) {
1198ffe3c632Sopenharmony_ci//%      GPBAutocreatedDictionaryModified(_autocreator, self);
1199ffe3c632Sopenharmony_ci//%    }
1200ffe3c632Sopenharmony_ci//%  }
1201ffe3c632Sopenharmony_ci//%}
1202ffe3c632Sopenharmony_ci//%
1203ffe3c632Sopenharmony_ci//%- (void)set##VALUE_NAME:(VALUE_TYPE)value forKey:(BOOL)key {
1204ffe3c632Sopenharmony_ci//%  int idx = (key ? 1 : 0);
1205ffe3c632Sopenharmony_ci//%  _values[idx] = value;
1206ffe3c632Sopenharmony_ci//%  _valueSet[idx] = YES;
1207ffe3c632Sopenharmony_ci//%  if (_autocreator) {
1208ffe3c632Sopenharmony_ci//%    GPBAutocreatedDictionaryModified(_autocreator, self);
1209ffe3c632Sopenharmony_ci//%  }
1210ffe3c632Sopenharmony_ci//%}
1211ffe3c632Sopenharmony_ci//%
1212ffe3c632Sopenharmony_ci//%- (void)remove##VALUE_NAME##ForKey:(BOOL)aKey {
1213ffe3c632Sopenharmony_ci//%  _valueSet[aKey ? 1 : 0] = NO;
1214ffe3c632Sopenharmony_ci//%}
1215ffe3c632Sopenharmony_ci//%
1216ffe3c632Sopenharmony_ci//%- (void)removeAll {
1217ffe3c632Sopenharmony_ci//%  _valueSet[0] = NO;
1218ffe3c632Sopenharmony_ci//%  _valueSet[1] = NO;
1219ffe3c632Sopenharmony_ci//%}
1220ffe3c632Sopenharmony_ci//%PDDM-DEFINE STR_FORMAT_POD(VALUE_NAME)
1221ffe3c632Sopenharmony_ci//%STR_FORMAT_##VALUE_NAME()
1222ffe3c632Sopenharmony_ci//%PDDM-DEFINE STR_FORMAT_UInt32()
1223ffe3c632Sopenharmony_ci//%%u
1224ffe3c632Sopenharmony_ci//%PDDM-DEFINE STR_FORMAT_Int32()
1225ffe3c632Sopenharmony_ci//%%d
1226ffe3c632Sopenharmony_ci//%PDDM-DEFINE STR_FORMAT_UInt64()
1227ffe3c632Sopenharmony_ci//%%llu
1228ffe3c632Sopenharmony_ci//%PDDM-DEFINE STR_FORMAT_Int64()
1229ffe3c632Sopenharmony_ci//%%lld
1230ffe3c632Sopenharmony_ci//%PDDM-DEFINE STR_FORMAT_Bool()
1231ffe3c632Sopenharmony_ci//%%d
1232ffe3c632Sopenharmony_ci//%PDDM-DEFINE STR_FORMAT_Float()
1233ffe3c632Sopenharmony_ci//%%f
1234ffe3c632Sopenharmony_ci//%PDDM-DEFINE STR_FORMAT_Double()
1235ffe3c632Sopenharmony_ci//%%lf
1236ffe3c632Sopenharmony_ci
1237ffe3c632Sopenharmony_ci//
1238ffe3c632Sopenharmony_ci// Helpers for Objects
1239ffe3c632Sopenharmony_ci//
1240ffe3c632Sopenharmony_ci
1241ffe3c632Sopenharmony_ci//%PDDM-DEFINE VALUE_FOR_KEY_OBJECT(KEY_TYPE, VALUE_NAME, VALUE_TYPE, KHELPER)
1242ffe3c632Sopenharmony_ci//%- (VALUE_TYPE)objectForKey:(KEY_TYPE)key {
1243ffe3c632Sopenharmony_ci//%  VALUE_TYPE result = [_dictionary objectForKey:WRAPPED##KHELPER(key)];
1244ffe3c632Sopenharmony_ci//%  return result;
1245ffe3c632Sopenharmony_ci//%}
1246ffe3c632Sopenharmony_ci//%PDDM-DEFINE WRAPPEDOBJECT(VALUE)
1247ffe3c632Sopenharmony_ci//%VALUE
1248ffe3c632Sopenharmony_ci//%PDDM-DEFINE UNWRAPString(VALUE)
1249ffe3c632Sopenharmony_ci//%VALUE
1250ffe3c632Sopenharmony_ci//%PDDM-DEFINE UNWRAPObject(VALUE)
1251ffe3c632Sopenharmony_ci//%VALUE
1252ffe3c632Sopenharmony_ci//%PDDM-DEFINE TEXT_FORMAT_OBJString(VALUE)
1253ffe3c632Sopenharmony_ci//%VALUE
1254ffe3c632Sopenharmony_ci//%PDDM-DEFINE TEXT_FORMAT_OBJObject(VALUE)
1255ffe3c632Sopenharmony_ci//%VALUE
1256ffe3c632Sopenharmony_ci//%PDDM-DEFINE ENUM_TYPEOBJECT(TYPE)
1257ffe3c632Sopenharmony_ci//%ENUM_TYPEOBJECT_##TYPE()
1258ffe3c632Sopenharmony_ci//%PDDM-DEFINE ENUM_TYPEOBJECT_NSString()
1259ffe3c632Sopenharmony_ci//%NSString *
1260ffe3c632Sopenharmony_ci//%PDDM-DEFINE ENUM_TYPEOBJECT_id()
1261ffe3c632Sopenharmony_ci//%id ##
1262ffe3c632Sopenharmony_ci//%PDDM-DEFINE NEQ_OBJECT(VAL1, VAL2)
1263ffe3c632Sopenharmony_ci//%![VAL1 isEqual:VAL2]
1264ffe3c632Sopenharmony_ci//%PDDM-DEFINE EXTRA_METHODS_OBJECT(KEY_NAME, VALUE_NAME)
1265ffe3c632Sopenharmony_ci//%- (BOOL)isInitialized {
1266ffe3c632Sopenharmony_ci//%  for (GPBMessage *msg in [_dictionary objectEnumerator]) {
1267ffe3c632Sopenharmony_ci//%    if (!msg.initialized) {
1268ffe3c632Sopenharmony_ci//%      return NO;
1269ffe3c632Sopenharmony_ci//%    }
1270ffe3c632Sopenharmony_ci//%  }
1271ffe3c632Sopenharmony_ci//%  return YES;
1272ffe3c632Sopenharmony_ci//%}
1273ffe3c632Sopenharmony_ci//%
1274ffe3c632Sopenharmony_ci//%- (instancetype)deepCopyWithZone:(NSZone *)zone {
1275ffe3c632Sopenharmony_ci//%  GPB##KEY_NAME##VALUE_NAME##Dictionary *newDict =
1276ffe3c632Sopenharmony_ci//%      [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] init];
1277ffe3c632Sopenharmony_ci//%  NSEnumerator *keys = [_dictionary keyEnumerator];
1278ffe3c632Sopenharmony_ci//%  id aKey;
1279ffe3c632Sopenharmony_ci//%  NSMutableDictionary *internalDict = newDict->_dictionary;
1280ffe3c632Sopenharmony_ci//%  while ((aKey = [keys nextObject])) {
1281ffe3c632Sopenharmony_ci//%    GPBMessage *msg = _dictionary[aKey];
1282ffe3c632Sopenharmony_ci//%    GPBMessage *copiedMsg = [msg copyWithZone:zone];
1283ffe3c632Sopenharmony_ci//%    [internalDict setObject:copiedMsg forKey:aKey];
1284ffe3c632Sopenharmony_ci//%    [copiedMsg release];
1285ffe3c632Sopenharmony_ci//%  }
1286ffe3c632Sopenharmony_ci//%  return newDict;
1287ffe3c632Sopenharmony_ci//%}
1288ffe3c632Sopenharmony_ci//%
1289ffe3c632Sopenharmony_ci//%
1290ffe3c632Sopenharmony_ci//%PDDM-DEFINE BOOL_EXTRA_METHODS_OBJECT(KEY_NAME, VALUE_NAME)
1291ffe3c632Sopenharmony_ci//%- (BOOL)isInitialized {
1292ffe3c632Sopenharmony_ci//%  if (_values[0] && ![_values[0] isInitialized]) {
1293ffe3c632Sopenharmony_ci//%    return NO;
1294ffe3c632Sopenharmony_ci//%  }
1295ffe3c632Sopenharmony_ci//%  if (_values[1] && ![_values[1] isInitialized]) {
1296ffe3c632Sopenharmony_ci//%    return NO;
1297ffe3c632Sopenharmony_ci//%  }
1298ffe3c632Sopenharmony_ci//%  return YES;
1299ffe3c632Sopenharmony_ci//%}
1300ffe3c632Sopenharmony_ci//%
1301ffe3c632Sopenharmony_ci//%- (instancetype)deepCopyWithZone:(NSZone *)zone {
1302ffe3c632Sopenharmony_ci//%  GPB##KEY_NAME##VALUE_NAME##Dictionary *newDict =
1303ffe3c632Sopenharmony_ci//%      [[GPB##KEY_NAME##VALUE_NAME##Dictionary alloc] init];
1304ffe3c632Sopenharmony_ci//%  for (int i = 0; i < 2; ++i) {
1305ffe3c632Sopenharmony_ci//%    if (_values[i] != nil) {
1306ffe3c632Sopenharmony_ci//%      newDict->_values[i] = [_values[i] copyWithZone:zone];
1307ffe3c632Sopenharmony_ci//%    }
1308ffe3c632Sopenharmony_ci//%  }
1309ffe3c632Sopenharmony_ci//%  return newDict;
1310ffe3c632Sopenharmony_ci//%}
1311ffe3c632Sopenharmony_ci//%
1312ffe3c632Sopenharmony_ci//%
1313ffe3c632Sopenharmony_ci//%PDDM-DEFINE SERIAL_DATA_FOR_ENTRY_OBJECT(KEY_NAME, VALUE_NAME)
1314ffe3c632Sopenharmony_ci// Empty
1315ffe3c632Sopenharmony_ci//%PDDM-DEFINE GPBVALUE_OBJECT(VALUE_NAME)
1316ffe3c632Sopenharmony_ci//%valueString
1317ffe3c632Sopenharmony_ci//%PDDM-DEFINE DICTIONARY_VALIDATE_VALUE_OBJECT(VALUE_NAME, EXTRA_INDENT)
1318ffe3c632Sopenharmony_ci//%##EXTRA_INDENT$S##  if (!##VALUE_NAME) {
1319ffe3c632Sopenharmony_ci//%##EXTRA_INDENT$S##    [NSException raise:NSInvalidArgumentException
1320ffe3c632Sopenharmony_ci//%##EXTRA_INDENT$S##                format:@"Attempting to add nil object to a Dictionary"];
1321ffe3c632Sopenharmony_ci//%##EXTRA_INDENT$S##  }
1322ffe3c632Sopenharmony_ci//%
1323ffe3c632Sopenharmony_ci//%PDDM-DEFINE DICTIONARY_VALIDATE_KEY_OBJECT(KEY_NAME, EXTRA_INDENT)
1324ffe3c632Sopenharmony_ci//%##EXTRA_INDENT$S##  if (!##KEY_NAME) {
1325ffe3c632Sopenharmony_ci//%##EXTRA_INDENT$S##    [NSException raise:NSInvalidArgumentException
1326ffe3c632Sopenharmony_ci//%##EXTRA_INDENT$S##                format:@"Attempting to add nil key to a Dictionary"];
1327ffe3c632Sopenharmony_ci//%##EXTRA_INDENT$S##  }
1328ffe3c632Sopenharmony_ci//%
1329ffe3c632Sopenharmony_ci
1330ffe3c632Sopenharmony_ci//%PDDM-DEFINE BOOL_DICT_HAS_STORAGE_OBJECT()
1331ffe3c632Sopenharmony_ci// Empty
1332ffe3c632Sopenharmony_ci//%PDDM-DEFINE BOOL_DICT_INITS_OBJECT(VALUE_NAME, VALUE_TYPE)
1333ffe3c632Sopenharmony_ci//%- (instancetype)initWithObjects:(const VALUE_TYPE [])objects
1334ffe3c632Sopenharmony_ci//%                        forKeys:(const BOOL [])keys
1335ffe3c632Sopenharmony_ci//%                          count:(NSUInteger)count {
1336ffe3c632Sopenharmony_ci//%  self = [super init];
1337ffe3c632Sopenharmony_ci//%  if (self) {
1338ffe3c632Sopenharmony_ci//%    for (NSUInteger i = 0; i < count; ++i) {
1339ffe3c632Sopenharmony_ci//%      if (!objects[i]) {
1340ffe3c632Sopenharmony_ci//%        [NSException raise:NSInvalidArgumentException
1341ffe3c632Sopenharmony_ci//%                    format:@"Attempting to add nil object to a Dictionary"];
1342ffe3c632Sopenharmony_ci//%      }
1343ffe3c632Sopenharmony_ci//%      int idx = keys[i] ? 1 : 0;
1344ffe3c632Sopenharmony_ci//%      [_values[idx] release];
1345ffe3c632Sopenharmony_ci//%      _values[idx] = (VALUE_TYPE)[objects[i] retain];
1346ffe3c632Sopenharmony_ci//%    }
1347ffe3c632Sopenharmony_ci//%  }
1348ffe3c632Sopenharmony_ci//%  return self;
1349ffe3c632Sopenharmony_ci//%}
1350ffe3c632Sopenharmony_ci//%
1351ffe3c632Sopenharmony_ci//%- (instancetype)initWithDictionary:(GPBBool##VALUE_NAME##Dictionary *)dictionary {
1352ffe3c632Sopenharmony_ci//%  self = [self initWithObjects:NULL forKeys:NULL count:0];
1353ffe3c632Sopenharmony_ci//%  if (self) {
1354ffe3c632Sopenharmony_ci//%    if (dictionary) {
1355ffe3c632Sopenharmony_ci//%      _values[0] = [dictionary->_values[0] retain];
1356ffe3c632Sopenharmony_ci//%      _values[1] = [dictionary->_values[1] retain];
1357ffe3c632Sopenharmony_ci//%    }
1358ffe3c632Sopenharmony_ci//%  }
1359ffe3c632Sopenharmony_ci//%  return self;
1360ffe3c632Sopenharmony_ci//%}
1361ffe3c632Sopenharmony_ci//%PDDM-DEFINE BOOL_DICT_DEALLOCOBJECT()
1362ffe3c632Sopenharmony_ci//%- (void)dealloc {
1363ffe3c632Sopenharmony_ci//%  NSAssert(!_autocreator,
1364ffe3c632Sopenharmony_ci//%           @"%@: Autocreator must be cleared before release, autocreator: %@",
1365ffe3c632Sopenharmony_ci//%           [self class], _autocreator);
1366ffe3c632Sopenharmony_ci//%  [_values[0] release];
1367ffe3c632Sopenharmony_ci//%  [_values[1] release];
1368ffe3c632Sopenharmony_ci//%  [super dealloc];
1369ffe3c632Sopenharmony_ci//%}
1370ffe3c632Sopenharmony_ci//%PDDM-DEFINE BOOL_DICT_W_HASOBJECT(IDX, REF)
1371ffe3c632Sopenharmony_ci//%(BOOL_DICT_HASOBJECT(IDX, REF))
1372ffe3c632Sopenharmony_ci//%PDDM-DEFINE BOOL_DICT_HASOBJECT(IDX, REF)
1373ffe3c632Sopenharmony_ci//%REF##_values[IDX] != nil
1374ffe3c632Sopenharmony_ci//%PDDM-DEFINE BOOL_VALUE_FOR_KEY_OBJECT(VALUE_NAME, VALUE_TYPE)
1375ffe3c632Sopenharmony_ci//%- (VALUE_TYPE)objectForKey:(BOOL)key {
1376ffe3c632Sopenharmony_ci//%  return _values[key ? 1 : 0];
1377ffe3c632Sopenharmony_ci//%}
1378ffe3c632Sopenharmony_ci//%PDDM-DEFINE BOOL_SET_GPBVALUE_FOR_KEY_OBJECT(VALUE_NAME, VALUE_TYPE, VisP)
1379ffe3c632Sopenharmony_ci//%- (void)setGPBGenericValue:(GPBGenericValue *)value
1380ffe3c632Sopenharmony_ci//%     forGPBGenericValueKey:(GPBGenericValue *)key {
1381ffe3c632Sopenharmony_ci//%  int idx = (key->valueBool ? 1 : 0);
1382ffe3c632Sopenharmony_ci//%  [_values[idx] release];
1383ffe3c632Sopenharmony_ci//%  _values[idx] = [value->valueString retain];
1384ffe3c632Sopenharmony_ci//%}
1385ffe3c632Sopenharmony_ci
1386ffe3c632Sopenharmony_ci//%PDDM-DEFINE BOOL_DICT_MUTATIONS_OBJECT(VALUE_NAME, VALUE_TYPE)
1387ffe3c632Sopenharmony_ci//%- (void)addEntriesFromDictionary:(GPBBool##VALUE_NAME##Dictionary *)otherDictionary {
1388ffe3c632Sopenharmony_ci//%  if (otherDictionary) {
1389ffe3c632Sopenharmony_ci//%    for (int i = 0; i < 2; ++i) {
1390ffe3c632Sopenharmony_ci//%      if (otherDictionary->_values[i] != nil) {
1391ffe3c632Sopenharmony_ci//%        [_values[i] release];
1392ffe3c632Sopenharmony_ci//%        _values[i] = [otherDictionary->_values[i] retain];
1393ffe3c632Sopenharmony_ci//%      }
1394ffe3c632Sopenharmony_ci//%    }
1395ffe3c632Sopenharmony_ci//%    if (_autocreator) {
1396ffe3c632Sopenharmony_ci//%      GPBAutocreatedDictionaryModified(_autocreator, self);
1397ffe3c632Sopenharmony_ci//%    }
1398ffe3c632Sopenharmony_ci//%  }
1399ffe3c632Sopenharmony_ci//%}
1400ffe3c632Sopenharmony_ci//%
1401ffe3c632Sopenharmony_ci//%- (void)setObject:(VALUE_TYPE)object forKey:(BOOL)key {
1402ffe3c632Sopenharmony_ci//%  if (!object) {
1403ffe3c632Sopenharmony_ci//%    [NSException raise:NSInvalidArgumentException
1404ffe3c632Sopenharmony_ci//%                format:@"Attempting to add nil object to a Dictionary"];
1405ffe3c632Sopenharmony_ci//%  }
1406ffe3c632Sopenharmony_ci//%  int idx = (key ? 1 : 0);
1407ffe3c632Sopenharmony_ci//%  [_values[idx] release];
1408ffe3c632Sopenharmony_ci//%  _values[idx] = [object retain];
1409ffe3c632Sopenharmony_ci//%  if (_autocreator) {
1410ffe3c632Sopenharmony_ci//%    GPBAutocreatedDictionaryModified(_autocreator, self);
1411ffe3c632Sopenharmony_ci//%  }
1412ffe3c632Sopenharmony_ci//%}
1413ffe3c632Sopenharmony_ci//%
1414ffe3c632Sopenharmony_ci//%- (void)removeObjectForKey:(BOOL)aKey {
1415ffe3c632Sopenharmony_ci//%  int idx = (aKey ? 1 : 0);
1416ffe3c632Sopenharmony_ci//%  [_values[idx] release];
1417ffe3c632Sopenharmony_ci//%  _values[idx] = nil;
1418ffe3c632Sopenharmony_ci//%}
1419ffe3c632Sopenharmony_ci//%
1420ffe3c632Sopenharmony_ci//%- (void)removeAll {
1421ffe3c632Sopenharmony_ci//%  for (int i = 0; i < 2; ++i) {
1422ffe3c632Sopenharmony_ci//%    [_values[i] release];
1423ffe3c632Sopenharmony_ci//%    _values[i] = nil;
1424ffe3c632Sopenharmony_ci//%  }
1425ffe3c632Sopenharmony_ci//%}
1426ffe3c632Sopenharmony_ci//%PDDM-DEFINE STR_FORMAT_OBJECT(VALUE_NAME)
1427ffe3c632Sopenharmony_ci//%%@
1428ffe3c632Sopenharmony_ci
1429ffe3c632Sopenharmony_ci
1430ffe3c632Sopenharmony_ci//%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(UInt32, uint32_t)
1431ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly.
1432ffe3c632Sopenharmony_ci// clang-format off
1433ffe3c632Sopenharmony_ci
1434ffe3c632Sopenharmony_ci#pragma mark - UInt32 -> UInt32
1435ffe3c632Sopenharmony_ci
1436ffe3c632Sopenharmony_ci@implementation GPBUInt32UInt32Dictionary {
1437ffe3c632Sopenharmony_ci @package
1438ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
1439ffe3c632Sopenharmony_ci}
1440ffe3c632Sopenharmony_ci
1441ffe3c632Sopenharmony_ci- (instancetype)init {
1442ffe3c632Sopenharmony_ci  return [self initWithUInt32s:NULL forKeys:NULL count:0];
1443ffe3c632Sopenharmony_ci}
1444ffe3c632Sopenharmony_ci
1445ffe3c632Sopenharmony_ci- (instancetype)initWithUInt32s:(const uint32_t [])values
1446ffe3c632Sopenharmony_ci                        forKeys:(const uint32_t [])keys
1447ffe3c632Sopenharmony_ci                          count:(NSUInteger)count {
1448ffe3c632Sopenharmony_ci  self = [super init];
1449ffe3c632Sopenharmony_ci  if (self) {
1450ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
1451ffe3c632Sopenharmony_ci    if (count && values && keys) {
1452ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
1453ffe3c632Sopenharmony_ci        [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
1454ffe3c632Sopenharmony_ci      }
1455ffe3c632Sopenharmony_ci    }
1456ffe3c632Sopenharmony_ci  }
1457ffe3c632Sopenharmony_ci  return self;
1458ffe3c632Sopenharmony_ci}
1459ffe3c632Sopenharmony_ci
1460ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBUInt32UInt32Dictionary *)dictionary {
1461ffe3c632Sopenharmony_ci  self = [self initWithUInt32s:NULL forKeys:NULL count:0];
1462ffe3c632Sopenharmony_ci  if (self) {
1463ffe3c632Sopenharmony_ci    if (dictionary) {
1464ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
1465ffe3c632Sopenharmony_ci    }
1466ffe3c632Sopenharmony_ci  }
1467ffe3c632Sopenharmony_ci  return self;
1468ffe3c632Sopenharmony_ci}
1469ffe3c632Sopenharmony_ci
1470ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
1471ffe3c632Sopenharmony_ci  #pragma unused(numItems)
1472ffe3c632Sopenharmony_ci  return [self initWithUInt32s:NULL forKeys:NULL count:0];
1473ffe3c632Sopenharmony_ci}
1474ffe3c632Sopenharmony_ci
1475ffe3c632Sopenharmony_ci- (void)dealloc {
1476ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
1477ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
1478ffe3c632Sopenharmony_ci           [self class], _autocreator);
1479ffe3c632Sopenharmony_ci  [_dictionary release];
1480ffe3c632Sopenharmony_ci  [super dealloc];
1481ffe3c632Sopenharmony_ci}
1482ffe3c632Sopenharmony_ci
1483ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
1484ffe3c632Sopenharmony_ci  return [[GPBUInt32UInt32Dictionary allocWithZone:zone] initWithDictionary:self];
1485ffe3c632Sopenharmony_ci}
1486ffe3c632Sopenharmony_ci
1487ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
1488ffe3c632Sopenharmony_ci  if (self == other) {
1489ffe3c632Sopenharmony_ci    return YES;
1490ffe3c632Sopenharmony_ci  }
1491ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBUInt32UInt32Dictionary class]]) {
1492ffe3c632Sopenharmony_ci    return NO;
1493ffe3c632Sopenharmony_ci  }
1494ffe3c632Sopenharmony_ci  GPBUInt32UInt32Dictionary *otherDictionary = other;
1495ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
1496ffe3c632Sopenharmony_ci}
1497ffe3c632Sopenharmony_ci
1498ffe3c632Sopenharmony_ci- (NSUInteger)hash {
1499ffe3c632Sopenharmony_ci  return _dictionary.count;
1500ffe3c632Sopenharmony_ci}
1501ffe3c632Sopenharmony_ci
1502ffe3c632Sopenharmony_ci- (NSString *)description {
1503ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
1504ffe3c632Sopenharmony_ci}
1505ffe3c632Sopenharmony_ci
1506ffe3c632Sopenharmony_ci- (NSUInteger)count {
1507ffe3c632Sopenharmony_ci  return _dictionary.count;
1508ffe3c632Sopenharmony_ci}
1509ffe3c632Sopenharmony_ci
1510ffe3c632Sopenharmony_ci- (void)enumerateKeysAndUInt32sUsingBlock:
1511ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(uint32_t key, uint32_t value, BOOL *stop))block {
1512ffe3c632Sopenharmony_ci  BOOL stop = NO;
1513ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
1514ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
1515ffe3c632Sopenharmony_ci  NSNumber *aKey;
1516ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
1517ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
1518ffe3c632Sopenharmony_ci    block([aKey unsignedIntValue], [aValue unsignedIntValue], &stop);
1519ffe3c632Sopenharmony_ci    if (stop) {
1520ffe3c632Sopenharmony_ci      break;
1521ffe3c632Sopenharmony_ci    }
1522ffe3c632Sopenharmony_ci  }
1523ffe3c632Sopenharmony_ci}
1524ffe3c632Sopenharmony_ci
1525ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
1526ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
1527ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
1528ffe3c632Sopenharmony_ci  if (count == 0) {
1529ffe3c632Sopenharmony_ci    return 0;
1530ffe3c632Sopenharmony_ci  }
1531ffe3c632Sopenharmony_ci
1532ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
1533ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
1534ffe3c632Sopenharmony_ci  size_t result = 0;
1535ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
1536ffe3c632Sopenharmony_ci  NSNumber *aKey;
1537ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
1538ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
1539ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
1540ffe3c632Sopenharmony_ci    msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
1541ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
1542ffe3c632Sopenharmony_ci  }
1543ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
1544ffe3c632Sopenharmony_ci  result += tagSize * count;
1545ffe3c632Sopenharmony_ci  return result;
1546ffe3c632Sopenharmony_ci}
1547ffe3c632Sopenharmony_ci
1548ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
1549ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
1550ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
1551ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
1552ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
1553ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
1554ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
1555ffe3c632Sopenharmony_ci  NSNumber *aKey;
1556ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
1557ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
1558ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
1559ffe3c632Sopenharmony_ci    // Write the size of the message.
1560ffe3c632Sopenharmony_ci    uint32_t unwrappedKey = [aKey unsignedIntValue];
1561ffe3c632Sopenharmony_ci    uint32_t unwrappedValue = [aValue unsignedIntValue];
1562ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
1563ffe3c632Sopenharmony_ci    msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
1564ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
1565ffe3c632Sopenharmony_ci    // Write the fields.
1566ffe3c632Sopenharmony_ci    WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
1567ffe3c632Sopenharmony_ci    WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
1568ffe3c632Sopenharmony_ci  }
1569ffe3c632Sopenharmony_ci}
1570ffe3c632Sopenharmony_ci
1571ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
1572ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
1573ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueUInt32)];
1574ffe3c632Sopenharmony_ci}
1575ffe3c632Sopenharmony_ci
1576ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
1577ffe3c632Sopenharmony_ci  [self enumerateKeysAndUInt32sUsingBlock:^(uint32_t key, uint32_t value, BOOL *stop) {
1578ffe3c632Sopenharmony_ci      #pragma unused(stop)
1579ffe3c632Sopenharmony_ci      block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%u", value]);
1580ffe3c632Sopenharmony_ci  }];
1581ffe3c632Sopenharmony_ci}
1582ffe3c632Sopenharmony_ci
1583ffe3c632Sopenharmony_ci- (BOOL)getUInt32:(nullable uint32_t *)value forKey:(uint32_t)key {
1584ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:@(key)];
1585ffe3c632Sopenharmony_ci  if (wrapped && value) {
1586ffe3c632Sopenharmony_ci    *value = [wrapped unsignedIntValue];
1587ffe3c632Sopenharmony_ci  }
1588ffe3c632Sopenharmony_ci  return (wrapped != NULL);
1589ffe3c632Sopenharmony_ci}
1590ffe3c632Sopenharmony_ci
1591ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBUInt32UInt32Dictionary *)otherDictionary {
1592ffe3c632Sopenharmony_ci  if (otherDictionary) {
1593ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
1594ffe3c632Sopenharmony_ci    if (_autocreator) {
1595ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
1596ffe3c632Sopenharmony_ci    }
1597ffe3c632Sopenharmony_ci  }
1598ffe3c632Sopenharmony_ci}
1599ffe3c632Sopenharmony_ci
1600ffe3c632Sopenharmony_ci- (void)setUInt32:(uint32_t)value forKey:(uint32_t)key {
1601ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:@(key)];
1602ffe3c632Sopenharmony_ci  if (_autocreator) {
1603ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
1604ffe3c632Sopenharmony_ci  }
1605ffe3c632Sopenharmony_ci}
1606ffe3c632Sopenharmony_ci
1607ffe3c632Sopenharmony_ci- (void)removeUInt32ForKey:(uint32_t)aKey {
1608ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:@(aKey)];
1609ffe3c632Sopenharmony_ci}
1610ffe3c632Sopenharmony_ci
1611ffe3c632Sopenharmony_ci- (void)removeAll {
1612ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
1613ffe3c632Sopenharmony_ci}
1614ffe3c632Sopenharmony_ci
1615ffe3c632Sopenharmony_ci@end
1616ffe3c632Sopenharmony_ci
1617ffe3c632Sopenharmony_ci#pragma mark - UInt32 -> Int32
1618ffe3c632Sopenharmony_ci
1619ffe3c632Sopenharmony_ci@implementation GPBUInt32Int32Dictionary {
1620ffe3c632Sopenharmony_ci @package
1621ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
1622ffe3c632Sopenharmony_ci}
1623ffe3c632Sopenharmony_ci
1624ffe3c632Sopenharmony_ci- (instancetype)init {
1625ffe3c632Sopenharmony_ci  return [self initWithInt32s:NULL forKeys:NULL count:0];
1626ffe3c632Sopenharmony_ci}
1627ffe3c632Sopenharmony_ci
1628ffe3c632Sopenharmony_ci- (instancetype)initWithInt32s:(const int32_t [])values
1629ffe3c632Sopenharmony_ci                       forKeys:(const uint32_t [])keys
1630ffe3c632Sopenharmony_ci                         count:(NSUInteger)count {
1631ffe3c632Sopenharmony_ci  self = [super init];
1632ffe3c632Sopenharmony_ci  if (self) {
1633ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
1634ffe3c632Sopenharmony_ci    if (count && values && keys) {
1635ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
1636ffe3c632Sopenharmony_ci        [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
1637ffe3c632Sopenharmony_ci      }
1638ffe3c632Sopenharmony_ci    }
1639ffe3c632Sopenharmony_ci  }
1640ffe3c632Sopenharmony_ci  return self;
1641ffe3c632Sopenharmony_ci}
1642ffe3c632Sopenharmony_ci
1643ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBUInt32Int32Dictionary *)dictionary {
1644ffe3c632Sopenharmony_ci  self = [self initWithInt32s:NULL forKeys:NULL count:0];
1645ffe3c632Sopenharmony_ci  if (self) {
1646ffe3c632Sopenharmony_ci    if (dictionary) {
1647ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
1648ffe3c632Sopenharmony_ci    }
1649ffe3c632Sopenharmony_ci  }
1650ffe3c632Sopenharmony_ci  return self;
1651ffe3c632Sopenharmony_ci}
1652ffe3c632Sopenharmony_ci
1653ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
1654ffe3c632Sopenharmony_ci  #pragma unused(numItems)
1655ffe3c632Sopenharmony_ci  return [self initWithInt32s:NULL forKeys:NULL count:0];
1656ffe3c632Sopenharmony_ci}
1657ffe3c632Sopenharmony_ci
1658ffe3c632Sopenharmony_ci- (void)dealloc {
1659ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
1660ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
1661ffe3c632Sopenharmony_ci           [self class], _autocreator);
1662ffe3c632Sopenharmony_ci  [_dictionary release];
1663ffe3c632Sopenharmony_ci  [super dealloc];
1664ffe3c632Sopenharmony_ci}
1665ffe3c632Sopenharmony_ci
1666ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
1667ffe3c632Sopenharmony_ci  return [[GPBUInt32Int32Dictionary allocWithZone:zone] initWithDictionary:self];
1668ffe3c632Sopenharmony_ci}
1669ffe3c632Sopenharmony_ci
1670ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
1671ffe3c632Sopenharmony_ci  if (self == other) {
1672ffe3c632Sopenharmony_ci    return YES;
1673ffe3c632Sopenharmony_ci  }
1674ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBUInt32Int32Dictionary class]]) {
1675ffe3c632Sopenharmony_ci    return NO;
1676ffe3c632Sopenharmony_ci  }
1677ffe3c632Sopenharmony_ci  GPBUInt32Int32Dictionary *otherDictionary = other;
1678ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
1679ffe3c632Sopenharmony_ci}
1680ffe3c632Sopenharmony_ci
1681ffe3c632Sopenharmony_ci- (NSUInteger)hash {
1682ffe3c632Sopenharmony_ci  return _dictionary.count;
1683ffe3c632Sopenharmony_ci}
1684ffe3c632Sopenharmony_ci
1685ffe3c632Sopenharmony_ci- (NSString *)description {
1686ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
1687ffe3c632Sopenharmony_ci}
1688ffe3c632Sopenharmony_ci
1689ffe3c632Sopenharmony_ci- (NSUInteger)count {
1690ffe3c632Sopenharmony_ci  return _dictionary.count;
1691ffe3c632Sopenharmony_ci}
1692ffe3c632Sopenharmony_ci
1693ffe3c632Sopenharmony_ci- (void)enumerateKeysAndInt32sUsingBlock:
1694ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(uint32_t key, int32_t value, BOOL *stop))block {
1695ffe3c632Sopenharmony_ci  BOOL stop = NO;
1696ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
1697ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
1698ffe3c632Sopenharmony_ci  NSNumber *aKey;
1699ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
1700ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
1701ffe3c632Sopenharmony_ci    block([aKey unsignedIntValue], [aValue intValue], &stop);
1702ffe3c632Sopenharmony_ci    if (stop) {
1703ffe3c632Sopenharmony_ci      break;
1704ffe3c632Sopenharmony_ci    }
1705ffe3c632Sopenharmony_ci  }
1706ffe3c632Sopenharmony_ci}
1707ffe3c632Sopenharmony_ci
1708ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
1709ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
1710ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
1711ffe3c632Sopenharmony_ci  if (count == 0) {
1712ffe3c632Sopenharmony_ci    return 0;
1713ffe3c632Sopenharmony_ci  }
1714ffe3c632Sopenharmony_ci
1715ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
1716ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
1717ffe3c632Sopenharmony_ci  size_t result = 0;
1718ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
1719ffe3c632Sopenharmony_ci  NSNumber *aKey;
1720ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
1721ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
1722ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
1723ffe3c632Sopenharmony_ci    msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
1724ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
1725ffe3c632Sopenharmony_ci  }
1726ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
1727ffe3c632Sopenharmony_ci  result += tagSize * count;
1728ffe3c632Sopenharmony_ci  return result;
1729ffe3c632Sopenharmony_ci}
1730ffe3c632Sopenharmony_ci
1731ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
1732ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
1733ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
1734ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
1735ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
1736ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
1737ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
1738ffe3c632Sopenharmony_ci  NSNumber *aKey;
1739ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
1740ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
1741ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
1742ffe3c632Sopenharmony_ci    // Write the size of the message.
1743ffe3c632Sopenharmony_ci    uint32_t unwrappedKey = [aKey unsignedIntValue];
1744ffe3c632Sopenharmony_ci    int32_t unwrappedValue = [aValue intValue];
1745ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
1746ffe3c632Sopenharmony_ci    msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
1747ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
1748ffe3c632Sopenharmony_ci    // Write the fields.
1749ffe3c632Sopenharmony_ci    WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
1750ffe3c632Sopenharmony_ci    WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
1751ffe3c632Sopenharmony_ci  }
1752ffe3c632Sopenharmony_ci}
1753ffe3c632Sopenharmony_ci
1754ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
1755ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
1756ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueUInt32)];
1757ffe3c632Sopenharmony_ci}
1758ffe3c632Sopenharmony_ci
1759ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
1760ffe3c632Sopenharmony_ci  [self enumerateKeysAndInt32sUsingBlock:^(uint32_t key, int32_t value, BOOL *stop) {
1761ffe3c632Sopenharmony_ci      #pragma unused(stop)
1762ffe3c632Sopenharmony_ci      block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%d", value]);
1763ffe3c632Sopenharmony_ci  }];
1764ffe3c632Sopenharmony_ci}
1765ffe3c632Sopenharmony_ci
1766ffe3c632Sopenharmony_ci- (BOOL)getInt32:(nullable int32_t *)value forKey:(uint32_t)key {
1767ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:@(key)];
1768ffe3c632Sopenharmony_ci  if (wrapped && value) {
1769ffe3c632Sopenharmony_ci    *value = [wrapped intValue];
1770ffe3c632Sopenharmony_ci  }
1771ffe3c632Sopenharmony_ci  return (wrapped != NULL);
1772ffe3c632Sopenharmony_ci}
1773ffe3c632Sopenharmony_ci
1774ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBUInt32Int32Dictionary *)otherDictionary {
1775ffe3c632Sopenharmony_ci  if (otherDictionary) {
1776ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
1777ffe3c632Sopenharmony_ci    if (_autocreator) {
1778ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
1779ffe3c632Sopenharmony_ci    }
1780ffe3c632Sopenharmony_ci  }
1781ffe3c632Sopenharmony_ci}
1782ffe3c632Sopenharmony_ci
1783ffe3c632Sopenharmony_ci- (void)setInt32:(int32_t)value forKey:(uint32_t)key {
1784ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:@(key)];
1785ffe3c632Sopenharmony_ci  if (_autocreator) {
1786ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
1787ffe3c632Sopenharmony_ci  }
1788ffe3c632Sopenharmony_ci}
1789ffe3c632Sopenharmony_ci
1790ffe3c632Sopenharmony_ci- (void)removeInt32ForKey:(uint32_t)aKey {
1791ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:@(aKey)];
1792ffe3c632Sopenharmony_ci}
1793ffe3c632Sopenharmony_ci
1794ffe3c632Sopenharmony_ci- (void)removeAll {
1795ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
1796ffe3c632Sopenharmony_ci}
1797ffe3c632Sopenharmony_ci
1798ffe3c632Sopenharmony_ci@end
1799ffe3c632Sopenharmony_ci
1800ffe3c632Sopenharmony_ci#pragma mark - UInt32 -> UInt64
1801ffe3c632Sopenharmony_ci
1802ffe3c632Sopenharmony_ci@implementation GPBUInt32UInt64Dictionary {
1803ffe3c632Sopenharmony_ci @package
1804ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
1805ffe3c632Sopenharmony_ci}
1806ffe3c632Sopenharmony_ci
1807ffe3c632Sopenharmony_ci- (instancetype)init {
1808ffe3c632Sopenharmony_ci  return [self initWithUInt64s:NULL forKeys:NULL count:0];
1809ffe3c632Sopenharmony_ci}
1810ffe3c632Sopenharmony_ci
1811ffe3c632Sopenharmony_ci- (instancetype)initWithUInt64s:(const uint64_t [])values
1812ffe3c632Sopenharmony_ci                        forKeys:(const uint32_t [])keys
1813ffe3c632Sopenharmony_ci                          count:(NSUInteger)count {
1814ffe3c632Sopenharmony_ci  self = [super init];
1815ffe3c632Sopenharmony_ci  if (self) {
1816ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
1817ffe3c632Sopenharmony_ci    if (count && values && keys) {
1818ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
1819ffe3c632Sopenharmony_ci        [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
1820ffe3c632Sopenharmony_ci      }
1821ffe3c632Sopenharmony_ci    }
1822ffe3c632Sopenharmony_ci  }
1823ffe3c632Sopenharmony_ci  return self;
1824ffe3c632Sopenharmony_ci}
1825ffe3c632Sopenharmony_ci
1826ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBUInt32UInt64Dictionary *)dictionary {
1827ffe3c632Sopenharmony_ci  self = [self initWithUInt64s:NULL forKeys:NULL count:0];
1828ffe3c632Sopenharmony_ci  if (self) {
1829ffe3c632Sopenharmony_ci    if (dictionary) {
1830ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
1831ffe3c632Sopenharmony_ci    }
1832ffe3c632Sopenharmony_ci  }
1833ffe3c632Sopenharmony_ci  return self;
1834ffe3c632Sopenharmony_ci}
1835ffe3c632Sopenharmony_ci
1836ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
1837ffe3c632Sopenharmony_ci  #pragma unused(numItems)
1838ffe3c632Sopenharmony_ci  return [self initWithUInt64s:NULL forKeys:NULL count:0];
1839ffe3c632Sopenharmony_ci}
1840ffe3c632Sopenharmony_ci
1841ffe3c632Sopenharmony_ci- (void)dealloc {
1842ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
1843ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
1844ffe3c632Sopenharmony_ci           [self class], _autocreator);
1845ffe3c632Sopenharmony_ci  [_dictionary release];
1846ffe3c632Sopenharmony_ci  [super dealloc];
1847ffe3c632Sopenharmony_ci}
1848ffe3c632Sopenharmony_ci
1849ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
1850ffe3c632Sopenharmony_ci  return [[GPBUInt32UInt64Dictionary allocWithZone:zone] initWithDictionary:self];
1851ffe3c632Sopenharmony_ci}
1852ffe3c632Sopenharmony_ci
1853ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
1854ffe3c632Sopenharmony_ci  if (self == other) {
1855ffe3c632Sopenharmony_ci    return YES;
1856ffe3c632Sopenharmony_ci  }
1857ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBUInt32UInt64Dictionary class]]) {
1858ffe3c632Sopenharmony_ci    return NO;
1859ffe3c632Sopenharmony_ci  }
1860ffe3c632Sopenharmony_ci  GPBUInt32UInt64Dictionary *otherDictionary = other;
1861ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
1862ffe3c632Sopenharmony_ci}
1863ffe3c632Sopenharmony_ci
1864ffe3c632Sopenharmony_ci- (NSUInteger)hash {
1865ffe3c632Sopenharmony_ci  return _dictionary.count;
1866ffe3c632Sopenharmony_ci}
1867ffe3c632Sopenharmony_ci
1868ffe3c632Sopenharmony_ci- (NSString *)description {
1869ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
1870ffe3c632Sopenharmony_ci}
1871ffe3c632Sopenharmony_ci
1872ffe3c632Sopenharmony_ci- (NSUInteger)count {
1873ffe3c632Sopenharmony_ci  return _dictionary.count;
1874ffe3c632Sopenharmony_ci}
1875ffe3c632Sopenharmony_ci
1876ffe3c632Sopenharmony_ci- (void)enumerateKeysAndUInt64sUsingBlock:
1877ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(uint32_t key, uint64_t value, BOOL *stop))block {
1878ffe3c632Sopenharmony_ci  BOOL stop = NO;
1879ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
1880ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
1881ffe3c632Sopenharmony_ci  NSNumber *aKey;
1882ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
1883ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
1884ffe3c632Sopenharmony_ci    block([aKey unsignedIntValue], [aValue unsignedLongLongValue], &stop);
1885ffe3c632Sopenharmony_ci    if (stop) {
1886ffe3c632Sopenharmony_ci      break;
1887ffe3c632Sopenharmony_ci    }
1888ffe3c632Sopenharmony_ci  }
1889ffe3c632Sopenharmony_ci}
1890ffe3c632Sopenharmony_ci
1891ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
1892ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
1893ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
1894ffe3c632Sopenharmony_ci  if (count == 0) {
1895ffe3c632Sopenharmony_ci    return 0;
1896ffe3c632Sopenharmony_ci  }
1897ffe3c632Sopenharmony_ci
1898ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
1899ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
1900ffe3c632Sopenharmony_ci  size_t result = 0;
1901ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
1902ffe3c632Sopenharmony_ci  NSNumber *aKey;
1903ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
1904ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
1905ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
1906ffe3c632Sopenharmony_ci    msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
1907ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
1908ffe3c632Sopenharmony_ci  }
1909ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
1910ffe3c632Sopenharmony_ci  result += tagSize * count;
1911ffe3c632Sopenharmony_ci  return result;
1912ffe3c632Sopenharmony_ci}
1913ffe3c632Sopenharmony_ci
1914ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
1915ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
1916ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
1917ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
1918ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
1919ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
1920ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
1921ffe3c632Sopenharmony_ci  NSNumber *aKey;
1922ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
1923ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
1924ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
1925ffe3c632Sopenharmony_ci    // Write the size of the message.
1926ffe3c632Sopenharmony_ci    uint32_t unwrappedKey = [aKey unsignedIntValue];
1927ffe3c632Sopenharmony_ci    uint64_t unwrappedValue = [aValue unsignedLongLongValue];
1928ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
1929ffe3c632Sopenharmony_ci    msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
1930ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
1931ffe3c632Sopenharmony_ci    // Write the fields.
1932ffe3c632Sopenharmony_ci    WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
1933ffe3c632Sopenharmony_ci    WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
1934ffe3c632Sopenharmony_ci  }
1935ffe3c632Sopenharmony_ci}
1936ffe3c632Sopenharmony_ci
1937ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
1938ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
1939ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueUInt32)];
1940ffe3c632Sopenharmony_ci}
1941ffe3c632Sopenharmony_ci
1942ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
1943ffe3c632Sopenharmony_ci  [self enumerateKeysAndUInt64sUsingBlock:^(uint32_t key, uint64_t value, BOOL *stop) {
1944ffe3c632Sopenharmony_ci      #pragma unused(stop)
1945ffe3c632Sopenharmony_ci      block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%llu", value]);
1946ffe3c632Sopenharmony_ci  }];
1947ffe3c632Sopenharmony_ci}
1948ffe3c632Sopenharmony_ci
1949ffe3c632Sopenharmony_ci- (BOOL)getUInt64:(nullable uint64_t *)value forKey:(uint32_t)key {
1950ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:@(key)];
1951ffe3c632Sopenharmony_ci  if (wrapped && value) {
1952ffe3c632Sopenharmony_ci    *value = [wrapped unsignedLongLongValue];
1953ffe3c632Sopenharmony_ci  }
1954ffe3c632Sopenharmony_ci  return (wrapped != NULL);
1955ffe3c632Sopenharmony_ci}
1956ffe3c632Sopenharmony_ci
1957ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBUInt32UInt64Dictionary *)otherDictionary {
1958ffe3c632Sopenharmony_ci  if (otherDictionary) {
1959ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
1960ffe3c632Sopenharmony_ci    if (_autocreator) {
1961ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
1962ffe3c632Sopenharmony_ci    }
1963ffe3c632Sopenharmony_ci  }
1964ffe3c632Sopenharmony_ci}
1965ffe3c632Sopenharmony_ci
1966ffe3c632Sopenharmony_ci- (void)setUInt64:(uint64_t)value forKey:(uint32_t)key {
1967ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:@(key)];
1968ffe3c632Sopenharmony_ci  if (_autocreator) {
1969ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
1970ffe3c632Sopenharmony_ci  }
1971ffe3c632Sopenharmony_ci}
1972ffe3c632Sopenharmony_ci
1973ffe3c632Sopenharmony_ci- (void)removeUInt64ForKey:(uint32_t)aKey {
1974ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:@(aKey)];
1975ffe3c632Sopenharmony_ci}
1976ffe3c632Sopenharmony_ci
1977ffe3c632Sopenharmony_ci- (void)removeAll {
1978ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
1979ffe3c632Sopenharmony_ci}
1980ffe3c632Sopenharmony_ci
1981ffe3c632Sopenharmony_ci@end
1982ffe3c632Sopenharmony_ci
1983ffe3c632Sopenharmony_ci#pragma mark - UInt32 -> Int64
1984ffe3c632Sopenharmony_ci
1985ffe3c632Sopenharmony_ci@implementation GPBUInt32Int64Dictionary {
1986ffe3c632Sopenharmony_ci @package
1987ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
1988ffe3c632Sopenharmony_ci}
1989ffe3c632Sopenharmony_ci
1990ffe3c632Sopenharmony_ci- (instancetype)init {
1991ffe3c632Sopenharmony_ci  return [self initWithInt64s:NULL forKeys:NULL count:0];
1992ffe3c632Sopenharmony_ci}
1993ffe3c632Sopenharmony_ci
1994ffe3c632Sopenharmony_ci- (instancetype)initWithInt64s:(const int64_t [])values
1995ffe3c632Sopenharmony_ci                       forKeys:(const uint32_t [])keys
1996ffe3c632Sopenharmony_ci                         count:(NSUInteger)count {
1997ffe3c632Sopenharmony_ci  self = [super init];
1998ffe3c632Sopenharmony_ci  if (self) {
1999ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
2000ffe3c632Sopenharmony_ci    if (count && values && keys) {
2001ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
2002ffe3c632Sopenharmony_ci        [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
2003ffe3c632Sopenharmony_ci      }
2004ffe3c632Sopenharmony_ci    }
2005ffe3c632Sopenharmony_ci  }
2006ffe3c632Sopenharmony_ci  return self;
2007ffe3c632Sopenharmony_ci}
2008ffe3c632Sopenharmony_ci
2009ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBUInt32Int64Dictionary *)dictionary {
2010ffe3c632Sopenharmony_ci  self = [self initWithInt64s:NULL forKeys:NULL count:0];
2011ffe3c632Sopenharmony_ci  if (self) {
2012ffe3c632Sopenharmony_ci    if (dictionary) {
2013ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
2014ffe3c632Sopenharmony_ci    }
2015ffe3c632Sopenharmony_ci  }
2016ffe3c632Sopenharmony_ci  return self;
2017ffe3c632Sopenharmony_ci}
2018ffe3c632Sopenharmony_ci
2019ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
2020ffe3c632Sopenharmony_ci  #pragma unused(numItems)
2021ffe3c632Sopenharmony_ci  return [self initWithInt64s:NULL forKeys:NULL count:0];
2022ffe3c632Sopenharmony_ci}
2023ffe3c632Sopenharmony_ci
2024ffe3c632Sopenharmony_ci- (void)dealloc {
2025ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
2026ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
2027ffe3c632Sopenharmony_ci           [self class], _autocreator);
2028ffe3c632Sopenharmony_ci  [_dictionary release];
2029ffe3c632Sopenharmony_ci  [super dealloc];
2030ffe3c632Sopenharmony_ci}
2031ffe3c632Sopenharmony_ci
2032ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
2033ffe3c632Sopenharmony_ci  return [[GPBUInt32Int64Dictionary allocWithZone:zone] initWithDictionary:self];
2034ffe3c632Sopenharmony_ci}
2035ffe3c632Sopenharmony_ci
2036ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
2037ffe3c632Sopenharmony_ci  if (self == other) {
2038ffe3c632Sopenharmony_ci    return YES;
2039ffe3c632Sopenharmony_ci  }
2040ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBUInt32Int64Dictionary class]]) {
2041ffe3c632Sopenharmony_ci    return NO;
2042ffe3c632Sopenharmony_ci  }
2043ffe3c632Sopenharmony_ci  GPBUInt32Int64Dictionary *otherDictionary = other;
2044ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
2045ffe3c632Sopenharmony_ci}
2046ffe3c632Sopenharmony_ci
2047ffe3c632Sopenharmony_ci- (NSUInteger)hash {
2048ffe3c632Sopenharmony_ci  return _dictionary.count;
2049ffe3c632Sopenharmony_ci}
2050ffe3c632Sopenharmony_ci
2051ffe3c632Sopenharmony_ci- (NSString *)description {
2052ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
2053ffe3c632Sopenharmony_ci}
2054ffe3c632Sopenharmony_ci
2055ffe3c632Sopenharmony_ci- (NSUInteger)count {
2056ffe3c632Sopenharmony_ci  return _dictionary.count;
2057ffe3c632Sopenharmony_ci}
2058ffe3c632Sopenharmony_ci
2059ffe3c632Sopenharmony_ci- (void)enumerateKeysAndInt64sUsingBlock:
2060ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(uint32_t key, int64_t value, BOOL *stop))block {
2061ffe3c632Sopenharmony_ci  BOOL stop = NO;
2062ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
2063ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
2064ffe3c632Sopenharmony_ci  NSNumber *aKey;
2065ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
2066ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
2067ffe3c632Sopenharmony_ci    block([aKey unsignedIntValue], [aValue longLongValue], &stop);
2068ffe3c632Sopenharmony_ci    if (stop) {
2069ffe3c632Sopenharmony_ci      break;
2070ffe3c632Sopenharmony_ci    }
2071ffe3c632Sopenharmony_ci  }
2072ffe3c632Sopenharmony_ci}
2073ffe3c632Sopenharmony_ci
2074ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
2075ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
2076ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
2077ffe3c632Sopenharmony_ci  if (count == 0) {
2078ffe3c632Sopenharmony_ci    return 0;
2079ffe3c632Sopenharmony_ci  }
2080ffe3c632Sopenharmony_ci
2081ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
2082ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
2083ffe3c632Sopenharmony_ci  size_t result = 0;
2084ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
2085ffe3c632Sopenharmony_ci  NSNumber *aKey;
2086ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
2087ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
2088ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
2089ffe3c632Sopenharmony_ci    msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
2090ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
2091ffe3c632Sopenharmony_ci  }
2092ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
2093ffe3c632Sopenharmony_ci  result += tagSize * count;
2094ffe3c632Sopenharmony_ci  return result;
2095ffe3c632Sopenharmony_ci}
2096ffe3c632Sopenharmony_ci
2097ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
2098ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
2099ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
2100ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
2101ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
2102ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
2103ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
2104ffe3c632Sopenharmony_ci  NSNumber *aKey;
2105ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
2106ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
2107ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
2108ffe3c632Sopenharmony_ci    // Write the size of the message.
2109ffe3c632Sopenharmony_ci    uint32_t unwrappedKey = [aKey unsignedIntValue];
2110ffe3c632Sopenharmony_ci    int64_t unwrappedValue = [aValue longLongValue];
2111ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
2112ffe3c632Sopenharmony_ci    msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
2113ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
2114ffe3c632Sopenharmony_ci    // Write the fields.
2115ffe3c632Sopenharmony_ci    WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
2116ffe3c632Sopenharmony_ci    WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
2117ffe3c632Sopenharmony_ci  }
2118ffe3c632Sopenharmony_ci}
2119ffe3c632Sopenharmony_ci
2120ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
2121ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
2122ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueUInt32)];
2123ffe3c632Sopenharmony_ci}
2124ffe3c632Sopenharmony_ci
2125ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
2126ffe3c632Sopenharmony_ci  [self enumerateKeysAndInt64sUsingBlock:^(uint32_t key, int64_t value, BOOL *stop) {
2127ffe3c632Sopenharmony_ci      #pragma unused(stop)
2128ffe3c632Sopenharmony_ci      block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%lld", value]);
2129ffe3c632Sopenharmony_ci  }];
2130ffe3c632Sopenharmony_ci}
2131ffe3c632Sopenharmony_ci
2132ffe3c632Sopenharmony_ci- (BOOL)getInt64:(nullable int64_t *)value forKey:(uint32_t)key {
2133ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:@(key)];
2134ffe3c632Sopenharmony_ci  if (wrapped && value) {
2135ffe3c632Sopenharmony_ci    *value = [wrapped longLongValue];
2136ffe3c632Sopenharmony_ci  }
2137ffe3c632Sopenharmony_ci  return (wrapped != NULL);
2138ffe3c632Sopenharmony_ci}
2139ffe3c632Sopenharmony_ci
2140ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBUInt32Int64Dictionary *)otherDictionary {
2141ffe3c632Sopenharmony_ci  if (otherDictionary) {
2142ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
2143ffe3c632Sopenharmony_ci    if (_autocreator) {
2144ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
2145ffe3c632Sopenharmony_ci    }
2146ffe3c632Sopenharmony_ci  }
2147ffe3c632Sopenharmony_ci}
2148ffe3c632Sopenharmony_ci
2149ffe3c632Sopenharmony_ci- (void)setInt64:(int64_t)value forKey:(uint32_t)key {
2150ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:@(key)];
2151ffe3c632Sopenharmony_ci  if (_autocreator) {
2152ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
2153ffe3c632Sopenharmony_ci  }
2154ffe3c632Sopenharmony_ci}
2155ffe3c632Sopenharmony_ci
2156ffe3c632Sopenharmony_ci- (void)removeInt64ForKey:(uint32_t)aKey {
2157ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:@(aKey)];
2158ffe3c632Sopenharmony_ci}
2159ffe3c632Sopenharmony_ci
2160ffe3c632Sopenharmony_ci- (void)removeAll {
2161ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
2162ffe3c632Sopenharmony_ci}
2163ffe3c632Sopenharmony_ci
2164ffe3c632Sopenharmony_ci@end
2165ffe3c632Sopenharmony_ci
2166ffe3c632Sopenharmony_ci#pragma mark - UInt32 -> Bool
2167ffe3c632Sopenharmony_ci
2168ffe3c632Sopenharmony_ci@implementation GPBUInt32BoolDictionary {
2169ffe3c632Sopenharmony_ci @package
2170ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
2171ffe3c632Sopenharmony_ci}
2172ffe3c632Sopenharmony_ci
2173ffe3c632Sopenharmony_ci- (instancetype)init {
2174ffe3c632Sopenharmony_ci  return [self initWithBools:NULL forKeys:NULL count:0];
2175ffe3c632Sopenharmony_ci}
2176ffe3c632Sopenharmony_ci
2177ffe3c632Sopenharmony_ci- (instancetype)initWithBools:(const BOOL [])values
2178ffe3c632Sopenharmony_ci                      forKeys:(const uint32_t [])keys
2179ffe3c632Sopenharmony_ci                        count:(NSUInteger)count {
2180ffe3c632Sopenharmony_ci  self = [super init];
2181ffe3c632Sopenharmony_ci  if (self) {
2182ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
2183ffe3c632Sopenharmony_ci    if (count && values && keys) {
2184ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
2185ffe3c632Sopenharmony_ci        [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
2186ffe3c632Sopenharmony_ci      }
2187ffe3c632Sopenharmony_ci    }
2188ffe3c632Sopenharmony_ci  }
2189ffe3c632Sopenharmony_ci  return self;
2190ffe3c632Sopenharmony_ci}
2191ffe3c632Sopenharmony_ci
2192ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBUInt32BoolDictionary *)dictionary {
2193ffe3c632Sopenharmony_ci  self = [self initWithBools:NULL forKeys:NULL count:0];
2194ffe3c632Sopenharmony_ci  if (self) {
2195ffe3c632Sopenharmony_ci    if (dictionary) {
2196ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
2197ffe3c632Sopenharmony_ci    }
2198ffe3c632Sopenharmony_ci  }
2199ffe3c632Sopenharmony_ci  return self;
2200ffe3c632Sopenharmony_ci}
2201ffe3c632Sopenharmony_ci
2202ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
2203ffe3c632Sopenharmony_ci  #pragma unused(numItems)
2204ffe3c632Sopenharmony_ci  return [self initWithBools:NULL forKeys:NULL count:0];
2205ffe3c632Sopenharmony_ci}
2206ffe3c632Sopenharmony_ci
2207ffe3c632Sopenharmony_ci- (void)dealloc {
2208ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
2209ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
2210ffe3c632Sopenharmony_ci           [self class], _autocreator);
2211ffe3c632Sopenharmony_ci  [_dictionary release];
2212ffe3c632Sopenharmony_ci  [super dealloc];
2213ffe3c632Sopenharmony_ci}
2214ffe3c632Sopenharmony_ci
2215ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
2216ffe3c632Sopenharmony_ci  return [[GPBUInt32BoolDictionary allocWithZone:zone] initWithDictionary:self];
2217ffe3c632Sopenharmony_ci}
2218ffe3c632Sopenharmony_ci
2219ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
2220ffe3c632Sopenharmony_ci  if (self == other) {
2221ffe3c632Sopenharmony_ci    return YES;
2222ffe3c632Sopenharmony_ci  }
2223ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBUInt32BoolDictionary class]]) {
2224ffe3c632Sopenharmony_ci    return NO;
2225ffe3c632Sopenharmony_ci  }
2226ffe3c632Sopenharmony_ci  GPBUInt32BoolDictionary *otherDictionary = other;
2227ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
2228ffe3c632Sopenharmony_ci}
2229ffe3c632Sopenharmony_ci
2230ffe3c632Sopenharmony_ci- (NSUInteger)hash {
2231ffe3c632Sopenharmony_ci  return _dictionary.count;
2232ffe3c632Sopenharmony_ci}
2233ffe3c632Sopenharmony_ci
2234ffe3c632Sopenharmony_ci- (NSString *)description {
2235ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
2236ffe3c632Sopenharmony_ci}
2237ffe3c632Sopenharmony_ci
2238ffe3c632Sopenharmony_ci- (NSUInteger)count {
2239ffe3c632Sopenharmony_ci  return _dictionary.count;
2240ffe3c632Sopenharmony_ci}
2241ffe3c632Sopenharmony_ci
2242ffe3c632Sopenharmony_ci- (void)enumerateKeysAndBoolsUsingBlock:
2243ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(uint32_t key, BOOL value, BOOL *stop))block {
2244ffe3c632Sopenharmony_ci  BOOL stop = NO;
2245ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
2246ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
2247ffe3c632Sopenharmony_ci  NSNumber *aKey;
2248ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
2249ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
2250ffe3c632Sopenharmony_ci    block([aKey unsignedIntValue], [aValue boolValue], &stop);
2251ffe3c632Sopenharmony_ci    if (stop) {
2252ffe3c632Sopenharmony_ci      break;
2253ffe3c632Sopenharmony_ci    }
2254ffe3c632Sopenharmony_ci  }
2255ffe3c632Sopenharmony_ci}
2256ffe3c632Sopenharmony_ci
2257ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
2258ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
2259ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
2260ffe3c632Sopenharmony_ci  if (count == 0) {
2261ffe3c632Sopenharmony_ci    return 0;
2262ffe3c632Sopenharmony_ci  }
2263ffe3c632Sopenharmony_ci
2264ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
2265ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
2266ffe3c632Sopenharmony_ci  size_t result = 0;
2267ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
2268ffe3c632Sopenharmony_ci  NSNumber *aKey;
2269ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
2270ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
2271ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
2272ffe3c632Sopenharmony_ci    msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
2273ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
2274ffe3c632Sopenharmony_ci  }
2275ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
2276ffe3c632Sopenharmony_ci  result += tagSize * count;
2277ffe3c632Sopenharmony_ci  return result;
2278ffe3c632Sopenharmony_ci}
2279ffe3c632Sopenharmony_ci
2280ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
2281ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
2282ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
2283ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
2284ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
2285ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
2286ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
2287ffe3c632Sopenharmony_ci  NSNumber *aKey;
2288ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
2289ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
2290ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
2291ffe3c632Sopenharmony_ci    // Write the size of the message.
2292ffe3c632Sopenharmony_ci    uint32_t unwrappedKey = [aKey unsignedIntValue];
2293ffe3c632Sopenharmony_ci    BOOL unwrappedValue = [aValue boolValue];
2294ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
2295ffe3c632Sopenharmony_ci    msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
2296ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
2297ffe3c632Sopenharmony_ci    // Write the fields.
2298ffe3c632Sopenharmony_ci    WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
2299ffe3c632Sopenharmony_ci    WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
2300ffe3c632Sopenharmony_ci  }
2301ffe3c632Sopenharmony_ci}
2302ffe3c632Sopenharmony_ci
2303ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
2304ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
2305ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueBool) forKey:@(key->valueUInt32)];
2306ffe3c632Sopenharmony_ci}
2307ffe3c632Sopenharmony_ci
2308ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
2309ffe3c632Sopenharmony_ci  [self enumerateKeysAndBoolsUsingBlock:^(uint32_t key, BOOL value, BOOL *stop) {
2310ffe3c632Sopenharmony_ci      #pragma unused(stop)
2311ffe3c632Sopenharmony_ci      block([NSString stringWithFormat:@"%u", key], (value ? @"true" : @"false"));
2312ffe3c632Sopenharmony_ci  }];
2313ffe3c632Sopenharmony_ci}
2314ffe3c632Sopenharmony_ci
2315ffe3c632Sopenharmony_ci- (BOOL)getBool:(nullable BOOL *)value forKey:(uint32_t)key {
2316ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:@(key)];
2317ffe3c632Sopenharmony_ci  if (wrapped && value) {
2318ffe3c632Sopenharmony_ci    *value = [wrapped boolValue];
2319ffe3c632Sopenharmony_ci  }
2320ffe3c632Sopenharmony_ci  return (wrapped != NULL);
2321ffe3c632Sopenharmony_ci}
2322ffe3c632Sopenharmony_ci
2323ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBUInt32BoolDictionary *)otherDictionary {
2324ffe3c632Sopenharmony_ci  if (otherDictionary) {
2325ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
2326ffe3c632Sopenharmony_ci    if (_autocreator) {
2327ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
2328ffe3c632Sopenharmony_ci    }
2329ffe3c632Sopenharmony_ci  }
2330ffe3c632Sopenharmony_ci}
2331ffe3c632Sopenharmony_ci
2332ffe3c632Sopenharmony_ci- (void)setBool:(BOOL)value forKey:(uint32_t)key {
2333ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:@(key)];
2334ffe3c632Sopenharmony_ci  if (_autocreator) {
2335ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
2336ffe3c632Sopenharmony_ci  }
2337ffe3c632Sopenharmony_ci}
2338ffe3c632Sopenharmony_ci
2339ffe3c632Sopenharmony_ci- (void)removeBoolForKey:(uint32_t)aKey {
2340ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:@(aKey)];
2341ffe3c632Sopenharmony_ci}
2342ffe3c632Sopenharmony_ci
2343ffe3c632Sopenharmony_ci- (void)removeAll {
2344ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
2345ffe3c632Sopenharmony_ci}
2346ffe3c632Sopenharmony_ci
2347ffe3c632Sopenharmony_ci@end
2348ffe3c632Sopenharmony_ci
2349ffe3c632Sopenharmony_ci#pragma mark - UInt32 -> Float
2350ffe3c632Sopenharmony_ci
2351ffe3c632Sopenharmony_ci@implementation GPBUInt32FloatDictionary {
2352ffe3c632Sopenharmony_ci @package
2353ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
2354ffe3c632Sopenharmony_ci}
2355ffe3c632Sopenharmony_ci
2356ffe3c632Sopenharmony_ci- (instancetype)init {
2357ffe3c632Sopenharmony_ci  return [self initWithFloats:NULL forKeys:NULL count:0];
2358ffe3c632Sopenharmony_ci}
2359ffe3c632Sopenharmony_ci
2360ffe3c632Sopenharmony_ci- (instancetype)initWithFloats:(const float [])values
2361ffe3c632Sopenharmony_ci                       forKeys:(const uint32_t [])keys
2362ffe3c632Sopenharmony_ci                         count:(NSUInteger)count {
2363ffe3c632Sopenharmony_ci  self = [super init];
2364ffe3c632Sopenharmony_ci  if (self) {
2365ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
2366ffe3c632Sopenharmony_ci    if (count && values && keys) {
2367ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
2368ffe3c632Sopenharmony_ci        [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
2369ffe3c632Sopenharmony_ci      }
2370ffe3c632Sopenharmony_ci    }
2371ffe3c632Sopenharmony_ci  }
2372ffe3c632Sopenharmony_ci  return self;
2373ffe3c632Sopenharmony_ci}
2374ffe3c632Sopenharmony_ci
2375ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBUInt32FloatDictionary *)dictionary {
2376ffe3c632Sopenharmony_ci  self = [self initWithFloats:NULL forKeys:NULL count:0];
2377ffe3c632Sopenharmony_ci  if (self) {
2378ffe3c632Sopenharmony_ci    if (dictionary) {
2379ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
2380ffe3c632Sopenharmony_ci    }
2381ffe3c632Sopenharmony_ci  }
2382ffe3c632Sopenharmony_ci  return self;
2383ffe3c632Sopenharmony_ci}
2384ffe3c632Sopenharmony_ci
2385ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
2386ffe3c632Sopenharmony_ci  #pragma unused(numItems)
2387ffe3c632Sopenharmony_ci  return [self initWithFloats:NULL forKeys:NULL count:0];
2388ffe3c632Sopenharmony_ci}
2389ffe3c632Sopenharmony_ci
2390ffe3c632Sopenharmony_ci- (void)dealloc {
2391ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
2392ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
2393ffe3c632Sopenharmony_ci           [self class], _autocreator);
2394ffe3c632Sopenharmony_ci  [_dictionary release];
2395ffe3c632Sopenharmony_ci  [super dealloc];
2396ffe3c632Sopenharmony_ci}
2397ffe3c632Sopenharmony_ci
2398ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
2399ffe3c632Sopenharmony_ci  return [[GPBUInt32FloatDictionary allocWithZone:zone] initWithDictionary:self];
2400ffe3c632Sopenharmony_ci}
2401ffe3c632Sopenharmony_ci
2402ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
2403ffe3c632Sopenharmony_ci  if (self == other) {
2404ffe3c632Sopenharmony_ci    return YES;
2405ffe3c632Sopenharmony_ci  }
2406ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBUInt32FloatDictionary class]]) {
2407ffe3c632Sopenharmony_ci    return NO;
2408ffe3c632Sopenharmony_ci  }
2409ffe3c632Sopenharmony_ci  GPBUInt32FloatDictionary *otherDictionary = other;
2410ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
2411ffe3c632Sopenharmony_ci}
2412ffe3c632Sopenharmony_ci
2413ffe3c632Sopenharmony_ci- (NSUInteger)hash {
2414ffe3c632Sopenharmony_ci  return _dictionary.count;
2415ffe3c632Sopenharmony_ci}
2416ffe3c632Sopenharmony_ci
2417ffe3c632Sopenharmony_ci- (NSString *)description {
2418ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
2419ffe3c632Sopenharmony_ci}
2420ffe3c632Sopenharmony_ci
2421ffe3c632Sopenharmony_ci- (NSUInteger)count {
2422ffe3c632Sopenharmony_ci  return _dictionary.count;
2423ffe3c632Sopenharmony_ci}
2424ffe3c632Sopenharmony_ci
2425ffe3c632Sopenharmony_ci- (void)enumerateKeysAndFloatsUsingBlock:
2426ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(uint32_t key, float value, BOOL *stop))block {
2427ffe3c632Sopenharmony_ci  BOOL stop = NO;
2428ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
2429ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
2430ffe3c632Sopenharmony_ci  NSNumber *aKey;
2431ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
2432ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
2433ffe3c632Sopenharmony_ci    block([aKey unsignedIntValue], [aValue floatValue], &stop);
2434ffe3c632Sopenharmony_ci    if (stop) {
2435ffe3c632Sopenharmony_ci      break;
2436ffe3c632Sopenharmony_ci    }
2437ffe3c632Sopenharmony_ci  }
2438ffe3c632Sopenharmony_ci}
2439ffe3c632Sopenharmony_ci
2440ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
2441ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
2442ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
2443ffe3c632Sopenharmony_ci  if (count == 0) {
2444ffe3c632Sopenharmony_ci    return 0;
2445ffe3c632Sopenharmony_ci  }
2446ffe3c632Sopenharmony_ci
2447ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
2448ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
2449ffe3c632Sopenharmony_ci  size_t result = 0;
2450ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
2451ffe3c632Sopenharmony_ci  NSNumber *aKey;
2452ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
2453ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
2454ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
2455ffe3c632Sopenharmony_ci    msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
2456ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
2457ffe3c632Sopenharmony_ci  }
2458ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
2459ffe3c632Sopenharmony_ci  result += tagSize * count;
2460ffe3c632Sopenharmony_ci  return result;
2461ffe3c632Sopenharmony_ci}
2462ffe3c632Sopenharmony_ci
2463ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
2464ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
2465ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
2466ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
2467ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
2468ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
2469ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
2470ffe3c632Sopenharmony_ci  NSNumber *aKey;
2471ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
2472ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
2473ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
2474ffe3c632Sopenharmony_ci    // Write the size of the message.
2475ffe3c632Sopenharmony_ci    uint32_t unwrappedKey = [aKey unsignedIntValue];
2476ffe3c632Sopenharmony_ci    float unwrappedValue = [aValue floatValue];
2477ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
2478ffe3c632Sopenharmony_ci    msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
2479ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
2480ffe3c632Sopenharmony_ci    // Write the fields.
2481ffe3c632Sopenharmony_ci    WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
2482ffe3c632Sopenharmony_ci    WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
2483ffe3c632Sopenharmony_ci  }
2484ffe3c632Sopenharmony_ci}
2485ffe3c632Sopenharmony_ci
2486ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
2487ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
2488ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueUInt32)];
2489ffe3c632Sopenharmony_ci}
2490ffe3c632Sopenharmony_ci
2491ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
2492ffe3c632Sopenharmony_ci  [self enumerateKeysAndFloatsUsingBlock:^(uint32_t key, float value, BOOL *stop) {
2493ffe3c632Sopenharmony_ci      #pragma unused(stop)
2494ffe3c632Sopenharmony_ci      block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
2495ffe3c632Sopenharmony_ci  }];
2496ffe3c632Sopenharmony_ci}
2497ffe3c632Sopenharmony_ci
2498ffe3c632Sopenharmony_ci- (BOOL)getFloat:(nullable float *)value forKey:(uint32_t)key {
2499ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:@(key)];
2500ffe3c632Sopenharmony_ci  if (wrapped && value) {
2501ffe3c632Sopenharmony_ci    *value = [wrapped floatValue];
2502ffe3c632Sopenharmony_ci  }
2503ffe3c632Sopenharmony_ci  return (wrapped != NULL);
2504ffe3c632Sopenharmony_ci}
2505ffe3c632Sopenharmony_ci
2506ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBUInt32FloatDictionary *)otherDictionary {
2507ffe3c632Sopenharmony_ci  if (otherDictionary) {
2508ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
2509ffe3c632Sopenharmony_ci    if (_autocreator) {
2510ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
2511ffe3c632Sopenharmony_ci    }
2512ffe3c632Sopenharmony_ci  }
2513ffe3c632Sopenharmony_ci}
2514ffe3c632Sopenharmony_ci
2515ffe3c632Sopenharmony_ci- (void)setFloat:(float)value forKey:(uint32_t)key {
2516ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:@(key)];
2517ffe3c632Sopenharmony_ci  if (_autocreator) {
2518ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
2519ffe3c632Sopenharmony_ci  }
2520ffe3c632Sopenharmony_ci}
2521ffe3c632Sopenharmony_ci
2522ffe3c632Sopenharmony_ci- (void)removeFloatForKey:(uint32_t)aKey {
2523ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:@(aKey)];
2524ffe3c632Sopenharmony_ci}
2525ffe3c632Sopenharmony_ci
2526ffe3c632Sopenharmony_ci- (void)removeAll {
2527ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
2528ffe3c632Sopenharmony_ci}
2529ffe3c632Sopenharmony_ci
2530ffe3c632Sopenharmony_ci@end
2531ffe3c632Sopenharmony_ci
2532ffe3c632Sopenharmony_ci#pragma mark - UInt32 -> Double
2533ffe3c632Sopenharmony_ci
2534ffe3c632Sopenharmony_ci@implementation GPBUInt32DoubleDictionary {
2535ffe3c632Sopenharmony_ci @package
2536ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
2537ffe3c632Sopenharmony_ci}
2538ffe3c632Sopenharmony_ci
2539ffe3c632Sopenharmony_ci- (instancetype)init {
2540ffe3c632Sopenharmony_ci  return [self initWithDoubles:NULL forKeys:NULL count:0];
2541ffe3c632Sopenharmony_ci}
2542ffe3c632Sopenharmony_ci
2543ffe3c632Sopenharmony_ci- (instancetype)initWithDoubles:(const double [])values
2544ffe3c632Sopenharmony_ci                        forKeys:(const uint32_t [])keys
2545ffe3c632Sopenharmony_ci                          count:(NSUInteger)count {
2546ffe3c632Sopenharmony_ci  self = [super init];
2547ffe3c632Sopenharmony_ci  if (self) {
2548ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
2549ffe3c632Sopenharmony_ci    if (count && values && keys) {
2550ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
2551ffe3c632Sopenharmony_ci        [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
2552ffe3c632Sopenharmony_ci      }
2553ffe3c632Sopenharmony_ci    }
2554ffe3c632Sopenharmony_ci  }
2555ffe3c632Sopenharmony_ci  return self;
2556ffe3c632Sopenharmony_ci}
2557ffe3c632Sopenharmony_ci
2558ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBUInt32DoubleDictionary *)dictionary {
2559ffe3c632Sopenharmony_ci  self = [self initWithDoubles:NULL forKeys:NULL count:0];
2560ffe3c632Sopenharmony_ci  if (self) {
2561ffe3c632Sopenharmony_ci    if (dictionary) {
2562ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
2563ffe3c632Sopenharmony_ci    }
2564ffe3c632Sopenharmony_ci  }
2565ffe3c632Sopenharmony_ci  return self;
2566ffe3c632Sopenharmony_ci}
2567ffe3c632Sopenharmony_ci
2568ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
2569ffe3c632Sopenharmony_ci  #pragma unused(numItems)
2570ffe3c632Sopenharmony_ci  return [self initWithDoubles:NULL forKeys:NULL count:0];
2571ffe3c632Sopenharmony_ci}
2572ffe3c632Sopenharmony_ci
2573ffe3c632Sopenharmony_ci- (void)dealloc {
2574ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
2575ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
2576ffe3c632Sopenharmony_ci           [self class], _autocreator);
2577ffe3c632Sopenharmony_ci  [_dictionary release];
2578ffe3c632Sopenharmony_ci  [super dealloc];
2579ffe3c632Sopenharmony_ci}
2580ffe3c632Sopenharmony_ci
2581ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
2582ffe3c632Sopenharmony_ci  return [[GPBUInt32DoubleDictionary allocWithZone:zone] initWithDictionary:self];
2583ffe3c632Sopenharmony_ci}
2584ffe3c632Sopenharmony_ci
2585ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
2586ffe3c632Sopenharmony_ci  if (self == other) {
2587ffe3c632Sopenharmony_ci    return YES;
2588ffe3c632Sopenharmony_ci  }
2589ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBUInt32DoubleDictionary class]]) {
2590ffe3c632Sopenharmony_ci    return NO;
2591ffe3c632Sopenharmony_ci  }
2592ffe3c632Sopenharmony_ci  GPBUInt32DoubleDictionary *otherDictionary = other;
2593ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
2594ffe3c632Sopenharmony_ci}
2595ffe3c632Sopenharmony_ci
2596ffe3c632Sopenharmony_ci- (NSUInteger)hash {
2597ffe3c632Sopenharmony_ci  return _dictionary.count;
2598ffe3c632Sopenharmony_ci}
2599ffe3c632Sopenharmony_ci
2600ffe3c632Sopenharmony_ci- (NSString *)description {
2601ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
2602ffe3c632Sopenharmony_ci}
2603ffe3c632Sopenharmony_ci
2604ffe3c632Sopenharmony_ci- (NSUInteger)count {
2605ffe3c632Sopenharmony_ci  return _dictionary.count;
2606ffe3c632Sopenharmony_ci}
2607ffe3c632Sopenharmony_ci
2608ffe3c632Sopenharmony_ci- (void)enumerateKeysAndDoublesUsingBlock:
2609ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(uint32_t key, double value, BOOL *stop))block {
2610ffe3c632Sopenharmony_ci  BOOL stop = NO;
2611ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
2612ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
2613ffe3c632Sopenharmony_ci  NSNumber *aKey;
2614ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
2615ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
2616ffe3c632Sopenharmony_ci    block([aKey unsignedIntValue], [aValue doubleValue], &stop);
2617ffe3c632Sopenharmony_ci    if (stop) {
2618ffe3c632Sopenharmony_ci      break;
2619ffe3c632Sopenharmony_ci    }
2620ffe3c632Sopenharmony_ci  }
2621ffe3c632Sopenharmony_ci}
2622ffe3c632Sopenharmony_ci
2623ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
2624ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
2625ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
2626ffe3c632Sopenharmony_ci  if (count == 0) {
2627ffe3c632Sopenharmony_ci    return 0;
2628ffe3c632Sopenharmony_ci  }
2629ffe3c632Sopenharmony_ci
2630ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
2631ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
2632ffe3c632Sopenharmony_ci  size_t result = 0;
2633ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
2634ffe3c632Sopenharmony_ci  NSNumber *aKey;
2635ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
2636ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
2637ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
2638ffe3c632Sopenharmony_ci    msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
2639ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
2640ffe3c632Sopenharmony_ci  }
2641ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
2642ffe3c632Sopenharmony_ci  result += tagSize * count;
2643ffe3c632Sopenharmony_ci  return result;
2644ffe3c632Sopenharmony_ci}
2645ffe3c632Sopenharmony_ci
2646ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
2647ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
2648ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
2649ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
2650ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
2651ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
2652ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
2653ffe3c632Sopenharmony_ci  NSNumber *aKey;
2654ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
2655ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
2656ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
2657ffe3c632Sopenharmony_ci    // Write the size of the message.
2658ffe3c632Sopenharmony_ci    uint32_t unwrappedKey = [aKey unsignedIntValue];
2659ffe3c632Sopenharmony_ci    double unwrappedValue = [aValue doubleValue];
2660ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
2661ffe3c632Sopenharmony_ci    msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
2662ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
2663ffe3c632Sopenharmony_ci    // Write the fields.
2664ffe3c632Sopenharmony_ci    WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
2665ffe3c632Sopenharmony_ci    WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
2666ffe3c632Sopenharmony_ci  }
2667ffe3c632Sopenharmony_ci}
2668ffe3c632Sopenharmony_ci
2669ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
2670ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
2671ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueUInt32)];
2672ffe3c632Sopenharmony_ci}
2673ffe3c632Sopenharmony_ci
2674ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
2675ffe3c632Sopenharmony_ci  [self enumerateKeysAndDoublesUsingBlock:^(uint32_t key, double value, BOOL *stop) {
2676ffe3c632Sopenharmony_ci      #pragma unused(stop)
2677ffe3c632Sopenharmony_ci      block([NSString stringWithFormat:@"%u", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
2678ffe3c632Sopenharmony_ci  }];
2679ffe3c632Sopenharmony_ci}
2680ffe3c632Sopenharmony_ci
2681ffe3c632Sopenharmony_ci- (BOOL)getDouble:(nullable double *)value forKey:(uint32_t)key {
2682ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:@(key)];
2683ffe3c632Sopenharmony_ci  if (wrapped && value) {
2684ffe3c632Sopenharmony_ci    *value = [wrapped doubleValue];
2685ffe3c632Sopenharmony_ci  }
2686ffe3c632Sopenharmony_ci  return (wrapped != NULL);
2687ffe3c632Sopenharmony_ci}
2688ffe3c632Sopenharmony_ci
2689ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBUInt32DoubleDictionary *)otherDictionary {
2690ffe3c632Sopenharmony_ci  if (otherDictionary) {
2691ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
2692ffe3c632Sopenharmony_ci    if (_autocreator) {
2693ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
2694ffe3c632Sopenharmony_ci    }
2695ffe3c632Sopenharmony_ci  }
2696ffe3c632Sopenharmony_ci}
2697ffe3c632Sopenharmony_ci
2698ffe3c632Sopenharmony_ci- (void)setDouble:(double)value forKey:(uint32_t)key {
2699ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:@(key)];
2700ffe3c632Sopenharmony_ci  if (_autocreator) {
2701ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
2702ffe3c632Sopenharmony_ci  }
2703ffe3c632Sopenharmony_ci}
2704ffe3c632Sopenharmony_ci
2705ffe3c632Sopenharmony_ci- (void)removeDoubleForKey:(uint32_t)aKey {
2706ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:@(aKey)];
2707ffe3c632Sopenharmony_ci}
2708ffe3c632Sopenharmony_ci
2709ffe3c632Sopenharmony_ci- (void)removeAll {
2710ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
2711ffe3c632Sopenharmony_ci}
2712ffe3c632Sopenharmony_ci
2713ffe3c632Sopenharmony_ci@end
2714ffe3c632Sopenharmony_ci
2715ffe3c632Sopenharmony_ci#pragma mark - UInt32 -> Enum
2716ffe3c632Sopenharmony_ci
2717ffe3c632Sopenharmony_ci@implementation GPBUInt32EnumDictionary {
2718ffe3c632Sopenharmony_ci @package
2719ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
2720ffe3c632Sopenharmony_ci  GPBEnumValidationFunc _validationFunc;
2721ffe3c632Sopenharmony_ci}
2722ffe3c632Sopenharmony_ci
2723ffe3c632Sopenharmony_ci@synthesize validationFunc = _validationFunc;
2724ffe3c632Sopenharmony_ci
2725ffe3c632Sopenharmony_ci- (instancetype)init {
2726ffe3c632Sopenharmony_ci  return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
2727ffe3c632Sopenharmony_ci}
2728ffe3c632Sopenharmony_ci
2729ffe3c632Sopenharmony_ci- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
2730ffe3c632Sopenharmony_ci  return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
2731ffe3c632Sopenharmony_ci}
2732ffe3c632Sopenharmony_ci
2733ffe3c632Sopenharmony_ci- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
2734ffe3c632Sopenharmony_ci                                 rawValues:(const int32_t [])rawValues
2735ffe3c632Sopenharmony_ci                                   forKeys:(const uint32_t [])keys
2736ffe3c632Sopenharmony_ci                                     count:(NSUInteger)count {
2737ffe3c632Sopenharmony_ci  self = [super init];
2738ffe3c632Sopenharmony_ci  if (self) {
2739ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
2740ffe3c632Sopenharmony_ci    _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
2741ffe3c632Sopenharmony_ci    if (count && rawValues && keys) {
2742ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
2743ffe3c632Sopenharmony_ci        [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])];
2744ffe3c632Sopenharmony_ci      }
2745ffe3c632Sopenharmony_ci    }
2746ffe3c632Sopenharmony_ci  }
2747ffe3c632Sopenharmony_ci  return self;
2748ffe3c632Sopenharmony_ci}
2749ffe3c632Sopenharmony_ci
2750ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBUInt32EnumDictionary *)dictionary {
2751ffe3c632Sopenharmony_ci  self = [self initWithValidationFunction:dictionary.validationFunc
2752ffe3c632Sopenharmony_ci                                rawValues:NULL
2753ffe3c632Sopenharmony_ci                                  forKeys:NULL
2754ffe3c632Sopenharmony_ci                                    count:0];
2755ffe3c632Sopenharmony_ci  if (self) {
2756ffe3c632Sopenharmony_ci    if (dictionary) {
2757ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
2758ffe3c632Sopenharmony_ci    }
2759ffe3c632Sopenharmony_ci  }
2760ffe3c632Sopenharmony_ci  return self;
2761ffe3c632Sopenharmony_ci}
2762ffe3c632Sopenharmony_ci
2763ffe3c632Sopenharmony_ci- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
2764ffe3c632Sopenharmony_ci                                  capacity:(NSUInteger)numItems {
2765ffe3c632Sopenharmony_ci  #pragma unused(numItems)
2766ffe3c632Sopenharmony_ci  return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
2767ffe3c632Sopenharmony_ci}
2768ffe3c632Sopenharmony_ci
2769ffe3c632Sopenharmony_ci- (void)dealloc {
2770ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
2771ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
2772ffe3c632Sopenharmony_ci           [self class], _autocreator);
2773ffe3c632Sopenharmony_ci  [_dictionary release];
2774ffe3c632Sopenharmony_ci  [super dealloc];
2775ffe3c632Sopenharmony_ci}
2776ffe3c632Sopenharmony_ci
2777ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
2778ffe3c632Sopenharmony_ci  return [[GPBUInt32EnumDictionary allocWithZone:zone] initWithDictionary:self];
2779ffe3c632Sopenharmony_ci}
2780ffe3c632Sopenharmony_ci
2781ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
2782ffe3c632Sopenharmony_ci  if (self == other) {
2783ffe3c632Sopenharmony_ci    return YES;
2784ffe3c632Sopenharmony_ci  }
2785ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBUInt32EnumDictionary class]]) {
2786ffe3c632Sopenharmony_ci    return NO;
2787ffe3c632Sopenharmony_ci  }
2788ffe3c632Sopenharmony_ci  GPBUInt32EnumDictionary *otherDictionary = other;
2789ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
2790ffe3c632Sopenharmony_ci}
2791ffe3c632Sopenharmony_ci
2792ffe3c632Sopenharmony_ci- (NSUInteger)hash {
2793ffe3c632Sopenharmony_ci  return _dictionary.count;
2794ffe3c632Sopenharmony_ci}
2795ffe3c632Sopenharmony_ci
2796ffe3c632Sopenharmony_ci- (NSString *)description {
2797ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
2798ffe3c632Sopenharmony_ci}
2799ffe3c632Sopenharmony_ci
2800ffe3c632Sopenharmony_ci- (NSUInteger)count {
2801ffe3c632Sopenharmony_ci  return _dictionary.count;
2802ffe3c632Sopenharmony_ci}
2803ffe3c632Sopenharmony_ci
2804ffe3c632Sopenharmony_ci- (void)enumerateKeysAndRawValuesUsingBlock:
2805ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(uint32_t key, int32_t value, BOOL *stop))block {
2806ffe3c632Sopenharmony_ci  BOOL stop = NO;
2807ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
2808ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
2809ffe3c632Sopenharmony_ci  NSNumber *aKey;
2810ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
2811ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
2812ffe3c632Sopenharmony_ci    block([aKey unsignedIntValue], [aValue intValue], &stop);
2813ffe3c632Sopenharmony_ci    if (stop) {
2814ffe3c632Sopenharmony_ci      break;
2815ffe3c632Sopenharmony_ci    }
2816ffe3c632Sopenharmony_ci  }
2817ffe3c632Sopenharmony_ci}
2818ffe3c632Sopenharmony_ci
2819ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
2820ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
2821ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
2822ffe3c632Sopenharmony_ci  if (count == 0) {
2823ffe3c632Sopenharmony_ci    return 0;
2824ffe3c632Sopenharmony_ci  }
2825ffe3c632Sopenharmony_ci
2826ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
2827ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
2828ffe3c632Sopenharmony_ci  size_t result = 0;
2829ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
2830ffe3c632Sopenharmony_ci  NSNumber *aKey;
2831ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
2832ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
2833ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
2834ffe3c632Sopenharmony_ci    msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
2835ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
2836ffe3c632Sopenharmony_ci  }
2837ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
2838ffe3c632Sopenharmony_ci  result += tagSize * count;
2839ffe3c632Sopenharmony_ci  return result;
2840ffe3c632Sopenharmony_ci}
2841ffe3c632Sopenharmony_ci
2842ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
2843ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
2844ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
2845ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
2846ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
2847ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
2848ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
2849ffe3c632Sopenharmony_ci  NSNumber *aKey;
2850ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
2851ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
2852ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
2853ffe3c632Sopenharmony_ci    // Write the size of the message.
2854ffe3c632Sopenharmony_ci    uint32_t unwrappedKey = [aKey unsignedIntValue];
2855ffe3c632Sopenharmony_ci    int32_t unwrappedValue = [aValue intValue];
2856ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
2857ffe3c632Sopenharmony_ci    msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
2858ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
2859ffe3c632Sopenharmony_ci    // Write the fields.
2860ffe3c632Sopenharmony_ci    WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
2861ffe3c632Sopenharmony_ci    WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
2862ffe3c632Sopenharmony_ci  }
2863ffe3c632Sopenharmony_ci}
2864ffe3c632Sopenharmony_ci
2865ffe3c632Sopenharmony_ci- (NSData *)serializedDataForUnknownValue:(int32_t)value
2866ffe3c632Sopenharmony_ci                                   forKey:(GPBGenericValue *)key
2867ffe3c632Sopenharmony_ci                              keyDataType:(GPBDataType)keyDataType {
2868ffe3c632Sopenharmony_ci  size_t msgSize = ComputeDictUInt32FieldSize(key->valueUInt32, kMapKeyFieldNumber, keyDataType);
2869ffe3c632Sopenharmony_ci  msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
2870ffe3c632Sopenharmony_ci  NSMutableData *data = [NSMutableData dataWithLength:msgSize];
2871ffe3c632Sopenharmony_ci  GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
2872ffe3c632Sopenharmony_ci  WriteDictUInt32Field(outputStream, key->valueUInt32, kMapKeyFieldNumber, keyDataType);
2873ffe3c632Sopenharmony_ci  WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
2874ffe3c632Sopenharmony_ci  [outputStream release];
2875ffe3c632Sopenharmony_ci  return data;
2876ffe3c632Sopenharmony_ci}
2877ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
2878ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
2879ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueUInt32)];
2880ffe3c632Sopenharmony_ci}
2881ffe3c632Sopenharmony_ci
2882ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
2883ffe3c632Sopenharmony_ci  [self enumerateKeysAndRawValuesUsingBlock:^(uint32_t key, int32_t value, BOOL *stop) {
2884ffe3c632Sopenharmony_ci      #pragma unused(stop)
2885ffe3c632Sopenharmony_ci      block([NSString stringWithFormat:@"%u", key], @(value));
2886ffe3c632Sopenharmony_ci  }];
2887ffe3c632Sopenharmony_ci}
2888ffe3c632Sopenharmony_ci
2889ffe3c632Sopenharmony_ci- (BOOL)getEnum:(int32_t *)value forKey:(uint32_t)key {
2890ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:@(key)];
2891ffe3c632Sopenharmony_ci  if (wrapped && value) {
2892ffe3c632Sopenharmony_ci    int32_t result = [wrapped intValue];
2893ffe3c632Sopenharmony_ci    if (!_validationFunc(result)) {
2894ffe3c632Sopenharmony_ci      result = kGPBUnrecognizedEnumeratorValue;
2895ffe3c632Sopenharmony_ci    }
2896ffe3c632Sopenharmony_ci    *value = result;
2897ffe3c632Sopenharmony_ci  }
2898ffe3c632Sopenharmony_ci  return (wrapped != NULL);
2899ffe3c632Sopenharmony_ci}
2900ffe3c632Sopenharmony_ci
2901ffe3c632Sopenharmony_ci- (BOOL)getRawValue:(int32_t *)rawValue forKey:(uint32_t)key {
2902ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:@(key)];
2903ffe3c632Sopenharmony_ci  if (wrapped && rawValue) {
2904ffe3c632Sopenharmony_ci    *rawValue = [wrapped intValue];
2905ffe3c632Sopenharmony_ci  }
2906ffe3c632Sopenharmony_ci  return (wrapped != NULL);
2907ffe3c632Sopenharmony_ci}
2908ffe3c632Sopenharmony_ci
2909ffe3c632Sopenharmony_ci- (void)enumerateKeysAndEnumsUsingBlock:
2910ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(uint32_t key, int32_t value, BOOL *stop))block {
2911ffe3c632Sopenharmony_ci  GPBEnumValidationFunc func = _validationFunc;
2912ffe3c632Sopenharmony_ci  BOOL stop = NO;
2913ffe3c632Sopenharmony_ci  NSEnumerator *keys = [_dictionary keyEnumerator];
2914ffe3c632Sopenharmony_ci  NSNumber *aKey;
2915ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
2916ffe3c632Sopenharmony_ci    NSNumber *aValue = _dictionary[aKey];
2917ffe3c632Sopenharmony_ci      int32_t unwrapped = [aValue intValue];
2918ffe3c632Sopenharmony_ci      if (!func(unwrapped)) {
2919ffe3c632Sopenharmony_ci        unwrapped = kGPBUnrecognizedEnumeratorValue;
2920ffe3c632Sopenharmony_ci      }
2921ffe3c632Sopenharmony_ci    block([aKey unsignedIntValue], unwrapped, &stop);
2922ffe3c632Sopenharmony_ci    if (stop) {
2923ffe3c632Sopenharmony_ci      break;
2924ffe3c632Sopenharmony_ci    }
2925ffe3c632Sopenharmony_ci  }
2926ffe3c632Sopenharmony_ci}
2927ffe3c632Sopenharmony_ci
2928ffe3c632Sopenharmony_ci- (void)addRawEntriesFromDictionary:(GPBUInt32EnumDictionary *)otherDictionary {
2929ffe3c632Sopenharmony_ci  if (otherDictionary) {
2930ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
2931ffe3c632Sopenharmony_ci    if (_autocreator) {
2932ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
2933ffe3c632Sopenharmony_ci    }
2934ffe3c632Sopenharmony_ci  }
2935ffe3c632Sopenharmony_ci}
2936ffe3c632Sopenharmony_ci
2937ffe3c632Sopenharmony_ci- (void)setRawValue:(int32_t)value forKey:(uint32_t)key {
2938ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:@(key)];
2939ffe3c632Sopenharmony_ci  if (_autocreator) {
2940ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
2941ffe3c632Sopenharmony_ci  }
2942ffe3c632Sopenharmony_ci}
2943ffe3c632Sopenharmony_ci
2944ffe3c632Sopenharmony_ci- (void)removeEnumForKey:(uint32_t)aKey {
2945ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:@(aKey)];
2946ffe3c632Sopenharmony_ci}
2947ffe3c632Sopenharmony_ci
2948ffe3c632Sopenharmony_ci- (void)removeAll {
2949ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
2950ffe3c632Sopenharmony_ci}
2951ffe3c632Sopenharmony_ci
2952ffe3c632Sopenharmony_ci- (void)setEnum:(int32_t)value forKey:(uint32_t)key {
2953ffe3c632Sopenharmony_ci  if (!_validationFunc(value)) {
2954ffe3c632Sopenharmony_ci    [NSException raise:NSInvalidArgumentException
2955ffe3c632Sopenharmony_ci                format:@"GPBUInt32EnumDictionary: Attempt to set an unknown enum value (%d)",
2956ffe3c632Sopenharmony_ci                       value];
2957ffe3c632Sopenharmony_ci  }
2958ffe3c632Sopenharmony_ci
2959ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:@(key)];
2960ffe3c632Sopenharmony_ci  if (_autocreator) {
2961ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
2962ffe3c632Sopenharmony_ci  }
2963ffe3c632Sopenharmony_ci}
2964ffe3c632Sopenharmony_ci
2965ffe3c632Sopenharmony_ci@end
2966ffe3c632Sopenharmony_ci
2967ffe3c632Sopenharmony_ci#pragma mark - UInt32 -> Object
2968ffe3c632Sopenharmony_ci
2969ffe3c632Sopenharmony_ci@implementation GPBUInt32ObjectDictionary {
2970ffe3c632Sopenharmony_ci @package
2971ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
2972ffe3c632Sopenharmony_ci}
2973ffe3c632Sopenharmony_ci
2974ffe3c632Sopenharmony_ci- (instancetype)init {
2975ffe3c632Sopenharmony_ci  return [self initWithObjects:NULL forKeys:NULL count:0];
2976ffe3c632Sopenharmony_ci}
2977ffe3c632Sopenharmony_ci
2978ffe3c632Sopenharmony_ci- (instancetype)initWithObjects:(const id [])objects
2979ffe3c632Sopenharmony_ci                        forKeys:(const uint32_t [])keys
2980ffe3c632Sopenharmony_ci                          count:(NSUInteger)count {
2981ffe3c632Sopenharmony_ci  self = [super init];
2982ffe3c632Sopenharmony_ci  if (self) {
2983ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
2984ffe3c632Sopenharmony_ci    if (count && objects && keys) {
2985ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
2986ffe3c632Sopenharmony_ci        if (!objects[i]) {
2987ffe3c632Sopenharmony_ci          [NSException raise:NSInvalidArgumentException
2988ffe3c632Sopenharmony_ci                      format:@"Attempting to add nil object to a Dictionary"];
2989ffe3c632Sopenharmony_ci        }
2990ffe3c632Sopenharmony_ci        [_dictionary setObject:objects[i] forKey:@(keys[i])];
2991ffe3c632Sopenharmony_ci      }
2992ffe3c632Sopenharmony_ci    }
2993ffe3c632Sopenharmony_ci  }
2994ffe3c632Sopenharmony_ci  return self;
2995ffe3c632Sopenharmony_ci}
2996ffe3c632Sopenharmony_ci
2997ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBUInt32ObjectDictionary *)dictionary {
2998ffe3c632Sopenharmony_ci  self = [self initWithObjects:NULL forKeys:NULL count:0];
2999ffe3c632Sopenharmony_ci  if (self) {
3000ffe3c632Sopenharmony_ci    if (dictionary) {
3001ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
3002ffe3c632Sopenharmony_ci    }
3003ffe3c632Sopenharmony_ci  }
3004ffe3c632Sopenharmony_ci  return self;
3005ffe3c632Sopenharmony_ci}
3006ffe3c632Sopenharmony_ci
3007ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
3008ffe3c632Sopenharmony_ci  #pragma unused(numItems)
3009ffe3c632Sopenharmony_ci  return [self initWithObjects:NULL forKeys:NULL count:0];
3010ffe3c632Sopenharmony_ci}
3011ffe3c632Sopenharmony_ci
3012ffe3c632Sopenharmony_ci- (void)dealloc {
3013ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
3014ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
3015ffe3c632Sopenharmony_ci           [self class], _autocreator);
3016ffe3c632Sopenharmony_ci  [_dictionary release];
3017ffe3c632Sopenharmony_ci  [super dealloc];
3018ffe3c632Sopenharmony_ci}
3019ffe3c632Sopenharmony_ci
3020ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
3021ffe3c632Sopenharmony_ci  return [[GPBUInt32ObjectDictionary allocWithZone:zone] initWithDictionary:self];
3022ffe3c632Sopenharmony_ci}
3023ffe3c632Sopenharmony_ci
3024ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
3025ffe3c632Sopenharmony_ci  if (self == other) {
3026ffe3c632Sopenharmony_ci    return YES;
3027ffe3c632Sopenharmony_ci  }
3028ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBUInt32ObjectDictionary class]]) {
3029ffe3c632Sopenharmony_ci    return NO;
3030ffe3c632Sopenharmony_ci  }
3031ffe3c632Sopenharmony_ci  GPBUInt32ObjectDictionary *otherDictionary = other;
3032ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
3033ffe3c632Sopenharmony_ci}
3034ffe3c632Sopenharmony_ci
3035ffe3c632Sopenharmony_ci- (NSUInteger)hash {
3036ffe3c632Sopenharmony_ci  return _dictionary.count;
3037ffe3c632Sopenharmony_ci}
3038ffe3c632Sopenharmony_ci
3039ffe3c632Sopenharmony_ci- (NSString *)description {
3040ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
3041ffe3c632Sopenharmony_ci}
3042ffe3c632Sopenharmony_ci
3043ffe3c632Sopenharmony_ci- (NSUInteger)count {
3044ffe3c632Sopenharmony_ci  return _dictionary.count;
3045ffe3c632Sopenharmony_ci}
3046ffe3c632Sopenharmony_ci
3047ffe3c632Sopenharmony_ci- (void)enumerateKeysAndObjectsUsingBlock:
3048ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(uint32_t key, id object, BOOL *stop))block {
3049ffe3c632Sopenharmony_ci  BOOL stop = NO;
3050ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
3051ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
3052ffe3c632Sopenharmony_ci  NSNumber *aKey;
3053ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
3054ffe3c632Sopenharmony_ci    id aObject = internal[aKey];
3055ffe3c632Sopenharmony_ci    block([aKey unsignedIntValue], aObject, &stop);
3056ffe3c632Sopenharmony_ci    if (stop) {
3057ffe3c632Sopenharmony_ci      break;
3058ffe3c632Sopenharmony_ci    }
3059ffe3c632Sopenharmony_ci  }
3060ffe3c632Sopenharmony_ci}
3061ffe3c632Sopenharmony_ci
3062ffe3c632Sopenharmony_ci- (BOOL)isInitialized {
3063ffe3c632Sopenharmony_ci  for (GPBMessage *msg in [_dictionary objectEnumerator]) {
3064ffe3c632Sopenharmony_ci    if (!msg.initialized) {
3065ffe3c632Sopenharmony_ci      return NO;
3066ffe3c632Sopenharmony_ci    }
3067ffe3c632Sopenharmony_ci  }
3068ffe3c632Sopenharmony_ci  return YES;
3069ffe3c632Sopenharmony_ci}
3070ffe3c632Sopenharmony_ci
3071ffe3c632Sopenharmony_ci- (instancetype)deepCopyWithZone:(NSZone *)zone {
3072ffe3c632Sopenharmony_ci  GPBUInt32ObjectDictionary *newDict =
3073ffe3c632Sopenharmony_ci      [[GPBUInt32ObjectDictionary alloc] init];
3074ffe3c632Sopenharmony_ci  NSEnumerator *keys = [_dictionary keyEnumerator];
3075ffe3c632Sopenharmony_ci  id aKey;
3076ffe3c632Sopenharmony_ci  NSMutableDictionary *internalDict = newDict->_dictionary;
3077ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
3078ffe3c632Sopenharmony_ci    GPBMessage *msg = _dictionary[aKey];
3079ffe3c632Sopenharmony_ci    GPBMessage *copiedMsg = [msg copyWithZone:zone];
3080ffe3c632Sopenharmony_ci    [internalDict setObject:copiedMsg forKey:aKey];
3081ffe3c632Sopenharmony_ci    [copiedMsg release];
3082ffe3c632Sopenharmony_ci  }
3083ffe3c632Sopenharmony_ci  return newDict;
3084ffe3c632Sopenharmony_ci}
3085ffe3c632Sopenharmony_ci
3086ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
3087ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
3088ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
3089ffe3c632Sopenharmony_ci  if (count == 0) {
3090ffe3c632Sopenharmony_ci    return 0;
3091ffe3c632Sopenharmony_ci  }
3092ffe3c632Sopenharmony_ci
3093ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
3094ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
3095ffe3c632Sopenharmony_ci  size_t result = 0;
3096ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
3097ffe3c632Sopenharmony_ci  NSNumber *aKey;
3098ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
3099ffe3c632Sopenharmony_ci    id aObject = internal[aKey];
3100ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictUInt32FieldSize([aKey unsignedIntValue], kMapKeyFieldNumber, keyDataType);
3101ffe3c632Sopenharmony_ci    msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
3102ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
3103ffe3c632Sopenharmony_ci  }
3104ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
3105ffe3c632Sopenharmony_ci  result += tagSize * count;
3106ffe3c632Sopenharmony_ci  return result;
3107ffe3c632Sopenharmony_ci}
3108ffe3c632Sopenharmony_ci
3109ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
3110ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
3111ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
3112ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
3113ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
3114ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
3115ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
3116ffe3c632Sopenharmony_ci  NSNumber *aKey;
3117ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
3118ffe3c632Sopenharmony_ci    id aObject = internal[aKey];
3119ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
3120ffe3c632Sopenharmony_ci    // Write the size of the message.
3121ffe3c632Sopenharmony_ci    uint32_t unwrappedKey = [aKey unsignedIntValue];
3122ffe3c632Sopenharmony_ci    id unwrappedValue = aObject;
3123ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictUInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
3124ffe3c632Sopenharmony_ci    msgSize += ComputeDictObjectFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
3125ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
3126ffe3c632Sopenharmony_ci    // Write the fields.
3127ffe3c632Sopenharmony_ci    WriteDictUInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
3128ffe3c632Sopenharmony_ci    WriteDictObjectField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
3129ffe3c632Sopenharmony_ci  }
3130ffe3c632Sopenharmony_ci}
3131ffe3c632Sopenharmony_ci
3132ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
3133ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
3134ffe3c632Sopenharmony_ci  [_dictionary setObject:value->valueString forKey:@(key->valueUInt32)];
3135ffe3c632Sopenharmony_ci}
3136ffe3c632Sopenharmony_ci
3137ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
3138ffe3c632Sopenharmony_ci  [self enumerateKeysAndObjectsUsingBlock:^(uint32_t key, id object, BOOL *stop) {
3139ffe3c632Sopenharmony_ci      #pragma unused(stop)
3140ffe3c632Sopenharmony_ci      block([NSString stringWithFormat:@"%u", key], object);
3141ffe3c632Sopenharmony_ci  }];
3142ffe3c632Sopenharmony_ci}
3143ffe3c632Sopenharmony_ci
3144ffe3c632Sopenharmony_ci- (id)objectForKey:(uint32_t)key {
3145ffe3c632Sopenharmony_ci  id result = [_dictionary objectForKey:@(key)];
3146ffe3c632Sopenharmony_ci  return result;
3147ffe3c632Sopenharmony_ci}
3148ffe3c632Sopenharmony_ci
3149ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBUInt32ObjectDictionary *)otherDictionary {
3150ffe3c632Sopenharmony_ci  if (otherDictionary) {
3151ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
3152ffe3c632Sopenharmony_ci    if (_autocreator) {
3153ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
3154ffe3c632Sopenharmony_ci    }
3155ffe3c632Sopenharmony_ci  }
3156ffe3c632Sopenharmony_ci}
3157ffe3c632Sopenharmony_ci
3158ffe3c632Sopenharmony_ci- (void)setObject:(id)object forKey:(uint32_t)key {
3159ffe3c632Sopenharmony_ci  if (!object) {
3160ffe3c632Sopenharmony_ci    [NSException raise:NSInvalidArgumentException
3161ffe3c632Sopenharmony_ci                format:@"Attempting to add nil object to a Dictionary"];
3162ffe3c632Sopenharmony_ci  }
3163ffe3c632Sopenharmony_ci  [_dictionary setObject:object forKey:@(key)];
3164ffe3c632Sopenharmony_ci  if (_autocreator) {
3165ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
3166ffe3c632Sopenharmony_ci  }
3167ffe3c632Sopenharmony_ci}
3168ffe3c632Sopenharmony_ci
3169ffe3c632Sopenharmony_ci- (void)removeObjectForKey:(uint32_t)aKey {
3170ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:@(aKey)];
3171ffe3c632Sopenharmony_ci}
3172ffe3c632Sopenharmony_ci
3173ffe3c632Sopenharmony_ci- (void)removeAll {
3174ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
3175ffe3c632Sopenharmony_ci}
3176ffe3c632Sopenharmony_ci
3177ffe3c632Sopenharmony_ci@end
3178ffe3c632Sopenharmony_ci
3179ffe3c632Sopenharmony_ci// clang-format on
3180ffe3c632Sopenharmony_ci//%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(Int32, int32_t)
3181ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly.
3182ffe3c632Sopenharmony_ci// clang-format off
3183ffe3c632Sopenharmony_ci
3184ffe3c632Sopenharmony_ci#pragma mark - Int32 -> UInt32
3185ffe3c632Sopenharmony_ci
3186ffe3c632Sopenharmony_ci@implementation GPBInt32UInt32Dictionary {
3187ffe3c632Sopenharmony_ci @package
3188ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
3189ffe3c632Sopenharmony_ci}
3190ffe3c632Sopenharmony_ci
3191ffe3c632Sopenharmony_ci- (instancetype)init {
3192ffe3c632Sopenharmony_ci  return [self initWithUInt32s:NULL forKeys:NULL count:0];
3193ffe3c632Sopenharmony_ci}
3194ffe3c632Sopenharmony_ci
3195ffe3c632Sopenharmony_ci- (instancetype)initWithUInt32s:(const uint32_t [])values
3196ffe3c632Sopenharmony_ci                        forKeys:(const int32_t [])keys
3197ffe3c632Sopenharmony_ci                          count:(NSUInteger)count {
3198ffe3c632Sopenharmony_ci  self = [super init];
3199ffe3c632Sopenharmony_ci  if (self) {
3200ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
3201ffe3c632Sopenharmony_ci    if (count && values && keys) {
3202ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
3203ffe3c632Sopenharmony_ci        [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
3204ffe3c632Sopenharmony_ci      }
3205ffe3c632Sopenharmony_ci    }
3206ffe3c632Sopenharmony_ci  }
3207ffe3c632Sopenharmony_ci  return self;
3208ffe3c632Sopenharmony_ci}
3209ffe3c632Sopenharmony_ci
3210ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBInt32UInt32Dictionary *)dictionary {
3211ffe3c632Sopenharmony_ci  self = [self initWithUInt32s:NULL forKeys:NULL count:0];
3212ffe3c632Sopenharmony_ci  if (self) {
3213ffe3c632Sopenharmony_ci    if (dictionary) {
3214ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
3215ffe3c632Sopenharmony_ci    }
3216ffe3c632Sopenharmony_ci  }
3217ffe3c632Sopenharmony_ci  return self;
3218ffe3c632Sopenharmony_ci}
3219ffe3c632Sopenharmony_ci
3220ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
3221ffe3c632Sopenharmony_ci  #pragma unused(numItems)
3222ffe3c632Sopenharmony_ci  return [self initWithUInt32s:NULL forKeys:NULL count:0];
3223ffe3c632Sopenharmony_ci}
3224ffe3c632Sopenharmony_ci
3225ffe3c632Sopenharmony_ci- (void)dealloc {
3226ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
3227ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
3228ffe3c632Sopenharmony_ci           [self class], _autocreator);
3229ffe3c632Sopenharmony_ci  [_dictionary release];
3230ffe3c632Sopenharmony_ci  [super dealloc];
3231ffe3c632Sopenharmony_ci}
3232ffe3c632Sopenharmony_ci
3233ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
3234ffe3c632Sopenharmony_ci  return [[GPBInt32UInt32Dictionary allocWithZone:zone] initWithDictionary:self];
3235ffe3c632Sopenharmony_ci}
3236ffe3c632Sopenharmony_ci
3237ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
3238ffe3c632Sopenharmony_ci  if (self == other) {
3239ffe3c632Sopenharmony_ci    return YES;
3240ffe3c632Sopenharmony_ci  }
3241ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBInt32UInt32Dictionary class]]) {
3242ffe3c632Sopenharmony_ci    return NO;
3243ffe3c632Sopenharmony_ci  }
3244ffe3c632Sopenharmony_ci  GPBInt32UInt32Dictionary *otherDictionary = other;
3245ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
3246ffe3c632Sopenharmony_ci}
3247ffe3c632Sopenharmony_ci
3248ffe3c632Sopenharmony_ci- (NSUInteger)hash {
3249ffe3c632Sopenharmony_ci  return _dictionary.count;
3250ffe3c632Sopenharmony_ci}
3251ffe3c632Sopenharmony_ci
3252ffe3c632Sopenharmony_ci- (NSString *)description {
3253ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
3254ffe3c632Sopenharmony_ci}
3255ffe3c632Sopenharmony_ci
3256ffe3c632Sopenharmony_ci- (NSUInteger)count {
3257ffe3c632Sopenharmony_ci  return _dictionary.count;
3258ffe3c632Sopenharmony_ci}
3259ffe3c632Sopenharmony_ci
3260ffe3c632Sopenharmony_ci- (void)enumerateKeysAndUInt32sUsingBlock:
3261ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(int32_t key, uint32_t value, BOOL *stop))block {
3262ffe3c632Sopenharmony_ci  BOOL stop = NO;
3263ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
3264ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
3265ffe3c632Sopenharmony_ci  NSNumber *aKey;
3266ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
3267ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
3268ffe3c632Sopenharmony_ci    block([aKey intValue], [aValue unsignedIntValue], &stop);
3269ffe3c632Sopenharmony_ci    if (stop) {
3270ffe3c632Sopenharmony_ci      break;
3271ffe3c632Sopenharmony_ci    }
3272ffe3c632Sopenharmony_ci  }
3273ffe3c632Sopenharmony_ci}
3274ffe3c632Sopenharmony_ci
3275ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
3276ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
3277ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
3278ffe3c632Sopenharmony_ci  if (count == 0) {
3279ffe3c632Sopenharmony_ci    return 0;
3280ffe3c632Sopenharmony_ci  }
3281ffe3c632Sopenharmony_ci
3282ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
3283ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
3284ffe3c632Sopenharmony_ci  size_t result = 0;
3285ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
3286ffe3c632Sopenharmony_ci  NSNumber *aKey;
3287ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
3288ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
3289ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
3290ffe3c632Sopenharmony_ci    msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
3291ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
3292ffe3c632Sopenharmony_ci  }
3293ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
3294ffe3c632Sopenharmony_ci  result += tagSize * count;
3295ffe3c632Sopenharmony_ci  return result;
3296ffe3c632Sopenharmony_ci}
3297ffe3c632Sopenharmony_ci
3298ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
3299ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
3300ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
3301ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
3302ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
3303ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
3304ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
3305ffe3c632Sopenharmony_ci  NSNumber *aKey;
3306ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
3307ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
3308ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
3309ffe3c632Sopenharmony_ci    // Write the size of the message.
3310ffe3c632Sopenharmony_ci    int32_t unwrappedKey = [aKey intValue];
3311ffe3c632Sopenharmony_ci    uint32_t unwrappedValue = [aValue unsignedIntValue];
3312ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
3313ffe3c632Sopenharmony_ci    msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
3314ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
3315ffe3c632Sopenharmony_ci    // Write the fields.
3316ffe3c632Sopenharmony_ci    WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
3317ffe3c632Sopenharmony_ci    WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
3318ffe3c632Sopenharmony_ci  }
3319ffe3c632Sopenharmony_ci}
3320ffe3c632Sopenharmony_ci
3321ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
3322ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
3323ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueInt32)];
3324ffe3c632Sopenharmony_ci}
3325ffe3c632Sopenharmony_ci
3326ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
3327ffe3c632Sopenharmony_ci  [self enumerateKeysAndUInt32sUsingBlock:^(int32_t key, uint32_t value, BOOL *stop) {
3328ffe3c632Sopenharmony_ci      #pragma unused(stop)
3329ffe3c632Sopenharmony_ci      block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%u", value]);
3330ffe3c632Sopenharmony_ci  }];
3331ffe3c632Sopenharmony_ci}
3332ffe3c632Sopenharmony_ci
3333ffe3c632Sopenharmony_ci- (BOOL)getUInt32:(nullable uint32_t *)value forKey:(int32_t)key {
3334ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:@(key)];
3335ffe3c632Sopenharmony_ci  if (wrapped && value) {
3336ffe3c632Sopenharmony_ci    *value = [wrapped unsignedIntValue];
3337ffe3c632Sopenharmony_ci  }
3338ffe3c632Sopenharmony_ci  return (wrapped != NULL);
3339ffe3c632Sopenharmony_ci}
3340ffe3c632Sopenharmony_ci
3341ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBInt32UInt32Dictionary *)otherDictionary {
3342ffe3c632Sopenharmony_ci  if (otherDictionary) {
3343ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
3344ffe3c632Sopenharmony_ci    if (_autocreator) {
3345ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
3346ffe3c632Sopenharmony_ci    }
3347ffe3c632Sopenharmony_ci  }
3348ffe3c632Sopenharmony_ci}
3349ffe3c632Sopenharmony_ci
3350ffe3c632Sopenharmony_ci- (void)setUInt32:(uint32_t)value forKey:(int32_t)key {
3351ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:@(key)];
3352ffe3c632Sopenharmony_ci  if (_autocreator) {
3353ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
3354ffe3c632Sopenharmony_ci  }
3355ffe3c632Sopenharmony_ci}
3356ffe3c632Sopenharmony_ci
3357ffe3c632Sopenharmony_ci- (void)removeUInt32ForKey:(int32_t)aKey {
3358ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:@(aKey)];
3359ffe3c632Sopenharmony_ci}
3360ffe3c632Sopenharmony_ci
3361ffe3c632Sopenharmony_ci- (void)removeAll {
3362ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
3363ffe3c632Sopenharmony_ci}
3364ffe3c632Sopenharmony_ci
3365ffe3c632Sopenharmony_ci@end
3366ffe3c632Sopenharmony_ci
3367ffe3c632Sopenharmony_ci#pragma mark - Int32 -> Int32
3368ffe3c632Sopenharmony_ci
3369ffe3c632Sopenharmony_ci@implementation GPBInt32Int32Dictionary {
3370ffe3c632Sopenharmony_ci @package
3371ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
3372ffe3c632Sopenharmony_ci}
3373ffe3c632Sopenharmony_ci
3374ffe3c632Sopenharmony_ci- (instancetype)init {
3375ffe3c632Sopenharmony_ci  return [self initWithInt32s:NULL forKeys:NULL count:0];
3376ffe3c632Sopenharmony_ci}
3377ffe3c632Sopenharmony_ci
3378ffe3c632Sopenharmony_ci- (instancetype)initWithInt32s:(const int32_t [])values
3379ffe3c632Sopenharmony_ci                       forKeys:(const int32_t [])keys
3380ffe3c632Sopenharmony_ci                         count:(NSUInteger)count {
3381ffe3c632Sopenharmony_ci  self = [super init];
3382ffe3c632Sopenharmony_ci  if (self) {
3383ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
3384ffe3c632Sopenharmony_ci    if (count && values && keys) {
3385ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
3386ffe3c632Sopenharmony_ci        [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
3387ffe3c632Sopenharmony_ci      }
3388ffe3c632Sopenharmony_ci    }
3389ffe3c632Sopenharmony_ci  }
3390ffe3c632Sopenharmony_ci  return self;
3391ffe3c632Sopenharmony_ci}
3392ffe3c632Sopenharmony_ci
3393ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBInt32Int32Dictionary *)dictionary {
3394ffe3c632Sopenharmony_ci  self = [self initWithInt32s:NULL forKeys:NULL count:0];
3395ffe3c632Sopenharmony_ci  if (self) {
3396ffe3c632Sopenharmony_ci    if (dictionary) {
3397ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
3398ffe3c632Sopenharmony_ci    }
3399ffe3c632Sopenharmony_ci  }
3400ffe3c632Sopenharmony_ci  return self;
3401ffe3c632Sopenharmony_ci}
3402ffe3c632Sopenharmony_ci
3403ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
3404ffe3c632Sopenharmony_ci  #pragma unused(numItems)
3405ffe3c632Sopenharmony_ci  return [self initWithInt32s:NULL forKeys:NULL count:0];
3406ffe3c632Sopenharmony_ci}
3407ffe3c632Sopenharmony_ci
3408ffe3c632Sopenharmony_ci- (void)dealloc {
3409ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
3410ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
3411ffe3c632Sopenharmony_ci           [self class], _autocreator);
3412ffe3c632Sopenharmony_ci  [_dictionary release];
3413ffe3c632Sopenharmony_ci  [super dealloc];
3414ffe3c632Sopenharmony_ci}
3415ffe3c632Sopenharmony_ci
3416ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
3417ffe3c632Sopenharmony_ci  return [[GPBInt32Int32Dictionary allocWithZone:zone] initWithDictionary:self];
3418ffe3c632Sopenharmony_ci}
3419ffe3c632Sopenharmony_ci
3420ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
3421ffe3c632Sopenharmony_ci  if (self == other) {
3422ffe3c632Sopenharmony_ci    return YES;
3423ffe3c632Sopenharmony_ci  }
3424ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBInt32Int32Dictionary class]]) {
3425ffe3c632Sopenharmony_ci    return NO;
3426ffe3c632Sopenharmony_ci  }
3427ffe3c632Sopenharmony_ci  GPBInt32Int32Dictionary *otherDictionary = other;
3428ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
3429ffe3c632Sopenharmony_ci}
3430ffe3c632Sopenharmony_ci
3431ffe3c632Sopenharmony_ci- (NSUInteger)hash {
3432ffe3c632Sopenharmony_ci  return _dictionary.count;
3433ffe3c632Sopenharmony_ci}
3434ffe3c632Sopenharmony_ci
3435ffe3c632Sopenharmony_ci- (NSString *)description {
3436ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
3437ffe3c632Sopenharmony_ci}
3438ffe3c632Sopenharmony_ci
3439ffe3c632Sopenharmony_ci- (NSUInteger)count {
3440ffe3c632Sopenharmony_ci  return _dictionary.count;
3441ffe3c632Sopenharmony_ci}
3442ffe3c632Sopenharmony_ci
3443ffe3c632Sopenharmony_ci- (void)enumerateKeysAndInt32sUsingBlock:
3444ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(int32_t key, int32_t value, BOOL *stop))block {
3445ffe3c632Sopenharmony_ci  BOOL stop = NO;
3446ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
3447ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
3448ffe3c632Sopenharmony_ci  NSNumber *aKey;
3449ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
3450ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
3451ffe3c632Sopenharmony_ci    block([aKey intValue], [aValue intValue], &stop);
3452ffe3c632Sopenharmony_ci    if (stop) {
3453ffe3c632Sopenharmony_ci      break;
3454ffe3c632Sopenharmony_ci    }
3455ffe3c632Sopenharmony_ci  }
3456ffe3c632Sopenharmony_ci}
3457ffe3c632Sopenharmony_ci
3458ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
3459ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
3460ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
3461ffe3c632Sopenharmony_ci  if (count == 0) {
3462ffe3c632Sopenharmony_ci    return 0;
3463ffe3c632Sopenharmony_ci  }
3464ffe3c632Sopenharmony_ci
3465ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
3466ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
3467ffe3c632Sopenharmony_ci  size_t result = 0;
3468ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
3469ffe3c632Sopenharmony_ci  NSNumber *aKey;
3470ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
3471ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
3472ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
3473ffe3c632Sopenharmony_ci    msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
3474ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
3475ffe3c632Sopenharmony_ci  }
3476ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
3477ffe3c632Sopenharmony_ci  result += tagSize * count;
3478ffe3c632Sopenharmony_ci  return result;
3479ffe3c632Sopenharmony_ci}
3480ffe3c632Sopenharmony_ci
3481ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
3482ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
3483ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
3484ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
3485ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
3486ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
3487ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
3488ffe3c632Sopenharmony_ci  NSNumber *aKey;
3489ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
3490ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
3491ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
3492ffe3c632Sopenharmony_ci    // Write the size of the message.
3493ffe3c632Sopenharmony_ci    int32_t unwrappedKey = [aKey intValue];
3494ffe3c632Sopenharmony_ci    int32_t unwrappedValue = [aValue intValue];
3495ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
3496ffe3c632Sopenharmony_ci    msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
3497ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
3498ffe3c632Sopenharmony_ci    // Write the fields.
3499ffe3c632Sopenharmony_ci    WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
3500ffe3c632Sopenharmony_ci    WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
3501ffe3c632Sopenharmony_ci  }
3502ffe3c632Sopenharmony_ci}
3503ffe3c632Sopenharmony_ci
3504ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
3505ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
3506ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueInt32)];
3507ffe3c632Sopenharmony_ci}
3508ffe3c632Sopenharmony_ci
3509ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
3510ffe3c632Sopenharmony_ci  [self enumerateKeysAndInt32sUsingBlock:^(int32_t key, int32_t value, BOOL *stop) {
3511ffe3c632Sopenharmony_ci      #pragma unused(stop)
3512ffe3c632Sopenharmony_ci      block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%d", value]);
3513ffe3c632Sopenharmony_ci  }];
3514ffe3c632Sopenharmony_ci}
3515ffe3c632Sopenharmony_ci
3516ffe3c632Sopenharmony_ci- (BOOL)getInt32:(nullable int32_t *)value forKey:(int32_t)key {
3517ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:@(key)];
3518ffe3c632Sopenharmony_ci  if (wrapped && value) {
3519ffe3c632Sopenharmony_ci    *value = [wrapped intValue];
3520ffe3c632Sopenharmony_ci  }
3521ffe3c632Sopenharmony_ci  return (wrapped != NULL);
3522ffe3c632Sopenharmony_ci}
3523ffe3c632Sopenharmony_ci
3524ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBInt32Int32Dictionary *)otherDictionary {
3525ffe3c632Sopenharmony_ci  if (otherDictionary) {
3526ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
3527ffe3c632Sopenharmony_ci    if (_autocreator) {
3528ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
3529ffe3c632Sopenharmony_ci    }
3530ffe3c632Sopenharmony_ci  }
3531ffe3c632Sopenharmony_ci}
3532ffe3c632Sopenharmony_ci
3533ffe3c632Sopenharmony_ci- (void)setInt32:(int32_t)value forKey:(int32_t)key {
3534ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:@(key)];
3535ffe3c632Sopenharmony_ci  if (_autocreator) {
3536ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
3537ffe3c632Sopenharmony_ci  }
3538ffe3c632Sopenharmony_ci}
3539ffe3c632Sopenharmony_ci
3540ffe3c632Sopenharmony_ci- (void)removeInt32ForKey:(int32_t)aKey {
3541ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:@(aKey)];
3542ffe3c632Sopenharmony_ci}
3543ffe3c632Sopenharmony_ci
3544ffe3c632Sopenharmony_ci- (void)removeAll {
3545ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
3546ffe3c632Sopenharmony_ci}
3547ffe3c632Sopenharmony_ci
3548ffe3c632Sopenharmony_ci@end
3549ffe3c632Sopenharmony_ci
3550ffe3c632Sopenharmony_ci#pragma mark - Int32 -> UInt64
3551ffe3c632Sopenharmony_ci
3552ffe3c632Sopenharmony_ci@implementation GPBInt32UInt64Dictionary {
3553ffe3c632Sopenharmony_ci @package
3554ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
3555ffe3c632Sopenharmony_ci}
3556ffe3c632Sopenharmony_ci
3557ffe3c632Sopenharmony_ci- (instancetype)init {
3558ffe3c632Sopenharmony_ci  return [self initWithUInt64s:NULL forKeys:NULL count:0];
3559ffe3c632Sopenharmony_ci}
3560ffe3c632Sopenharmony_ci
3561ffe3c632Sopenharmony_ci- (instancetype)initWithUInt64s:(const uint64_t [])values
3562ffe3c632Sopenharmony_ci                        forKeys:(const int32_t [])keys
3563ffe3c632Sopenharmony_ci                          count:(NSUInteger)count {
3564ffe3c632Sopenharmony_ci  self = [super init];
3565ffe3c632Sopenharmony_ci  if (self) {
3566ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
3567ffe3c632Sopenharmony_ci    if (count && values && keys) {
3568ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
3569ffe3c632Sopenharmony_ci        [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
3570ffe3c632Sopenharmony_ci      }
3571ffe3c632Sopenharmony_ci    }
3572ffe3c632Sopenharmony_ci  }
3573ffe3c632Sopenharmony_ci  return self;
3574ffe3c632Sopenharmony_ci}
3575ffe3c632Sopenharmony_ci
3576ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBInt32UInt64Dictionary *)dictionary {
3577ffe3c632Sopenharmony_ci  self = [self initWithUInt64s:NULL forKeys:NULL count:0];
3578ffe3c632Sopenharmony_ci  if (self) {
3579ffe3c632Sopenharmony_ci    if (dictionary) {
3580ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
3581ffe3c632Sopenharmony_ci    }
3582ffe3c632Sopenharmony_ci  }
3583ffe3c632Sopenharmony_ci  return self;
3584ffe3c632Sopenharmony_ci}
3585ffe3c632Sopenharmony_ci
3586ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
3587ffe3c632Sopenharmony_ci  #pragma unused(numItems)
3588ffe3c632Sopenharmony_ci  return [self initWithUInt64s:NULL forKeys:NULL count:0];
3589ffe3c632Sopenharmony_ci}
3590ffe3c632Sopenharmony_ci
3591ffe3c632Sopenharmony_ci- (void)dealloc {
3592ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
3593ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
3594ffe3c632Sopenharmony_ci           [self class], _autocreator);
3595ffe3c632Sopenharmony_ci  [_dictionary release];
3596ffe3c632Sopenharmony_ci  [super dealloc];
3597ffe3c632Sopenharmony_ci}
3598ffe3c632Sopenharmony_ci
3599ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
3600ffe3c632Sopenharmony_ci  return [[GPBInt32UInt64Dictionary allocWithZone:zone] initWithDictionary:self];
3601ffe3c632Sopenharmony_ci}
3602ffe3c632Sopenharmony_ci
3603ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
3604ffe3c632Sopenharmony_ci  if (self == other) {
3605ffe3c632Sopenharmony_ci    return YES;
3606ffe3c632Sopenharmony_ci  }
3607ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBInt32UInt64Dictionary class]]) {
3608ffe3c632Sopenharmony_ci    return NO;
3609ffe3c632Sopenharmony_ci  }
3610ffe3c632Sopenharmony_ci  GPBInt32UInt64Dictionary *otherDictionary = other;
3611ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
3612ffe3c632Sopenharmony_ci}
3613ffe3c632Sopenharmony_ci
3614ffe3c632Sopenharmony_ci- (NSUInteger)hash {
3615ffe3c632Sopenharmony_ci  return _dictionary.count;
3616ffe3c632Sopenharmony_ci}
3617ffe3c632Sopenharmony_ci
3618ffe3c632Sopenharmony_ci- (NSString *)description {
3619ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
3620ffe3c632Sopenharmony_ci}
3621ffe3c632Sopenharmony_ci
3622ffe3c632Sopenharmony_ci- (NSUInteger)count {
3623ffe3c632Sopenharmony_ci  return _dictionary.count;
3624ffe3c632Sopenharmony_ci}
3625ffe3c632Sopenharmony_ci
3626ffe3c632Sopenharmony_ci- (void)enumerateKeysAndUInt64sUsingBlock:
3627ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(int32_t key, uint64_t value, BOOL *stop))block {
3628ffe3c632Sopenharmony_ci  BOOL stop = NO;
3629ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
3630ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
3631ffe3c632Sopenharmony_ci  NSNumber *aKey;
3632ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
3633ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
3634ffe3c632Sopenharmony_ci    block([aKey intValue], [aValue unsignedLongLongValue], &stop);
3635ffe3c632Sopenharmony_ci    if (stop) {
3636ffe3c632Sopenharmony_ci      break;
3637ffe3c632Sopenharmony_ci    }
3638ffe3c632Sopenharmony_ci  }
3639ffe3c632Sopenharmony_ci}
3640ffe3c632Sopenharmony_ci
3641ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
3642ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
3643ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
3644ffe3c632Sopenharmony_ci  if (count == 0) {
3645ffe3c632Sopenharmony_ci    return 0;
3646ffe3c632Sopenharmony_ci  }
3647ffe3c632Sopenharmony_ci
3648ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
3649ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
3650ffe3c632Sopenharmony_ci  size_t result = 0;
3651ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
3652ffe3c632Sopenharmony_ci  NSNumber *aKey;
3653ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
3654ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
3655ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
3656ffe3c632Sopenharmony_ci    msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
3657ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
3658ffe3c632Sopenharmony_ci  }
3659ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
3660ffe3c632Sopenharmony_ci  result += tagSize * count;
3661ffe3c632Sopenharmony_ci  return result;
3662ffe3c632Sopenharmony_ci}
3663ffe3c632Sopenharmony_ci
3664ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
3665ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
3666ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
3667ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
3668ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
3669ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
3670ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
3671ffe3c632Sopenharmony_ci  NSNumber *aKey;
3672ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
3673ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
3674ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
3675ffe3c632Sopenharmony_ci    // Write the size of the message.
3676ffe3c632Sopenharmony_ci    int32_t unwrappedKey = [aKey intValue];
3677ffe3c632Sopenharmony_ci    uint64_t unwrappedValue = [aValue unsignedLongLongValue];
3678ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
3679ffe3c632Sopenharmony_ci    msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
3680ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
3681ffe3c632Sopenharmony_ci    // Write the fields.
3682ffe3c632Sopenharmony_ci    WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
3683ffe3c632Sopenharmony_ci    WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
3684ffe3c632Sopenharmony_ci  }
3685ffe3c632Sopenharmony_ci}
3686ffe3c632Sopenharmony_ci
3687ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
3688ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
3689ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueInt32)];
3690ffe3c632Sopenharmony_ci}
3691ffe3c632Sopenharmony_ci
3692ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
3693ffe3c632Sopenharmony_ci  [self enumerateKeysAndUInt64sUsingBlock:^(int32_t key, uint64_t value, BOOL *stop) {
3694ffe3c632Sopenharmony_ci      #pragma unused(stop)
3695ffe3c632Sopenharmony_ci      block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%llu", value]);
3696ffe3c632Sopenharmony_ci  }];
3697ffe3c632Sopenharmony_ci}
3698ffe3c632Sopenharmony_ci
3699ffe3c632Sopenharmony_ci- (BOOL)getUInt64:(nullable uint64_t *)value forKey:(int32_t)key {
3700ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:@(key)];
3701ffe3c632Sopenharmony_ci  if (wrapped && value) {
3702ffe3c632Sopenharmony_ci    *value = [wrapped unsignedLongLongValue];
3703ffe3c632Sopenharmony_ci  }
3704ffe3c632Sopenharmony_ci  return (wrapped != NULL);
3705ffe3c632Sopenharmony_ci}
3706ffe3c632Sopenharmony_ci
3707ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBInt32UInt64Dictionary *)otherDictionary {
3708ffe3c632Sopenharmony_ci  if (otherDictionary) {
3709ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
3710ffe3c632Sopenharmony_ci    if (_autocreator) {
3711ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
3712ffe3c632Sopenharmony_ci    }
3713ffe3c632Sopenharmony_ci  }
3714ffe3c632Sopenharmony_ci}
3715ffe3c632Sopenharmony_ci
3716ffe3c632Sopenharmony_ci- (void)setUInt64:(uint64_t)value forKey:(int32_t)key {
3717ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:@(key)];
3718ffe3c632Sopenharmony_ci  if (_autocreator) {
3719ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
3720ffe3c632Sopenharmony_ci  }
3721ffe3c632Sopenharmony_ci}
3722ffe3c632Sopenharmony_ci
3723ffe3c632Sopenharmony_ci- (void)removeUInt64ForKey:(int32_t)aKey {
3724ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:@(aKey)];
3725ffe3c632Sopenharmony_ci}
3726ffe3c632Sopenharmony_ci
3727ffe3c632Sopenharmony_ci- (void)removeAll {
3728ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
3729ffe3c632Sopenharmony_ci}
3730ffe3c632Sopenharmony_ci
3731ffe3c632Sopenharmony_ci@end
3732ffe3c632Sopenharmony_ci
3733ffe3c632Sopenharmony_ci#pragma mark - Int32 -> Int64
3734ffe3c632Sopenharmony_ci
3735ffe3c632Sopenharmony_ci@implementation GPBInt32Int64Dictionary {
3736ffe3c632Sopenharmony_ci @package
3737ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
3738ffe3c632Sopenharmony_ci}
3739ffe3c632Sopenharmony_ci
3740ffe3c632Sopenharmony_ci- (instancetype)init {
3741ffe3c632Sopenharmony_ci  return [self initWithInt64s:NULL forKeys:NULL count:0];
3742ffe3c632Sopenharmony_ci}
3743ffe3c632Sopenharmony_ci
3744ffe3c632Sopenharmony_ci- (instancetype)initWithInt64s:(const int64_t [])values
3745ffe3c632Sopenharmony_ci                       forKeys:(const int32_t [])keys
3746ffe3c632Sopenharmony_ci                         count:(NSUInteger)count {
3747ffe3c632Sopenharmony_ci  self = [super init];
3748ffe3c632Sopenharmony_ci  if (self) {
3749ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
3750ffe3c632Sopenharmony_ci    if (count && values && keys) {
3751ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
3752ffe3c632Sopenharmony_ci        [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
3753ffe3c632Sopenharmony_ci      }
3754ffe3c632Sopenharmony_ci    }
3755ffe3c632Sopenharmony_ci  }
3756ffe3c632Sopenharmony_ci  return self;
3757ffe3c632Sopenharmony_ci}
3758ffe3c632Sopenharmony_ci
3759ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBInt32Int64Dictionary *)dictionary {
3760ffe3c632Sopenharmony_ci  self = [self initWithInt64s:NULL forKeys:NULL count:0];
3761ffe3c632Sopenharmony_ci  if (self) {
3762ffe3c632Sopenharmony_ci    if (dictionary) {
3763ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
3764ffe3c632Sopenharmony_ci    }
3765ffe3c632Sopenharmony_ci  }
3766ffe3c632Sopenharmony_ci  return self;
3767ffe3c632Sopenharmony_ci}
3768ffe3c632Sopenharmony_ci
3769ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
3770ffe3c632Sopenharmony_ci  #pragma unused(numItems)
3771ffe3c632Sopenharmony_ci  return [self initWithInt64s:NULL forKeys:NULL count:0];
3772ffe3c632Sopenharmony_ci}
3773ffe3c632Sopenharmony_ci
3774ffe3c632Sopenharmony_ci- (void)dealloc {
3775ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
3776ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
3777ffe3c632Sopenharmony_ci           [self class], _autocreator);
3778ffe3c632Sopenharmony_ci  [_dictionary release];
3779ffe3c632Sopenharmony_ci  [super dealloc];
3780ffe3c632Sopenharmony_ci}
3781ffe3c632Sopenharmony_ci
3782ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
3783ffe3c632Sopenharmony_ci  return [[GPBInt32Int64Dictionary allocWithZone:zone] initWithDictionary:self];
3784ffe3c632Sopenharmony_ci}
3785ffe3c632Sopenharmony_ci
3786ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
3787ffe3c632Sopenharmony_ci  if (self == other) {
3788ffe3c632Sopenharmony_ci    return YES;
3789ffe3c632Sopenharmony_ci  }
3790ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBInt32Int64Dictionary class]]) {
3791ffe3c632Sopenharmony_ci    return NO;
3792ffe3c632Sopenharmony_ci  }
3793ffe3c632Sopenharmony_ci  GPBInt32Int64Dictionary *otherDictionary = other;
3794ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
3795ffe3c632Sopenharmony_ci}
3796ffe3c632Sopenharmony_ci
3797ffe3c632Sopenharmony_ci- (NSUInteger)hash {
3798ffe3c632Sopenharmony_ci  return _dictionary.count;
3799ffe3c632Sopenharmony_ci}
3800ffe3c632Sopenharmony_ci
3801ffe3c632Sopenharmony_ci- (NSString *)description {
3802ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
3803ffe3c632Sopenharmony_ci}
3804ffe3c632Sopenharmony_ci
3805ffe3c632Sopenharmony_ci- (NSUInteger)count {
3806ffe3c632Sopenharmony_ci  return _dictionary.count;
3807ffe3c632Sopenharmony_ci}
3808ffe3c632Sopenharmony_ci
3809ffe3c632Sopenharmony_ci- (void)enumerateKeysAndInt64sUsingBlock:
3810ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(int32_t key, int64_t value, BOOL *stop))block {
3811ffe3c632Sopenharmony_ci  BOOL stop = NO;
3812ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
3813ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
3814ffe3c632Sopenharmony_ci  NSNumber *aKey;
3815ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
3816ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
3817ffe3c632Sopenharmony_ci    block([aKey intValue], [aValue longLongValue], &stop);
3818ffe3c632Sopenharmony_ci    if (stop) {
3819ffe3c632Sopenharmony_ci      break;
3820ffe3c632Sopenharmony_ci    }
3821ffe3c632Sopenharmony_ci  }
3822ffe3c632Sopenharmony_ci}
3823ffe3c632Sopenharmony_ci
3824ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
3825ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
3826ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
3827ffe3c632Sopenharmony_ci  if (count == 0) {
3828ffe3c632Sopenharmony_ci    return 0;
3829ffe3c632Sopenharmony_ci  }
3830ffe3c632Sopenharmony_ci
3831ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
3832ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
3833ffe3c632Sopenharmony_ci  size_t result = 0;
3834ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
3835ffe3c632Sopenharmony_ci  NSNumber *aKey;
3836ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
3837ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
3838ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
3839ffe3c632Sopenharmony_ci    msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
3840ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
3841ffe3c632Sopenharmony_ci  }
3842ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
3843ffe3c632Sopenharmony_ci  result += tagSize * count;
3844ffe3c632Sopenharmony_ci  return result;
3845ffe3c632Sopenharmony_ci}
3846ffe3c632Sopenharmony_ci
3847ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
3848ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
3849ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
3850ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
3851ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
3852ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
3853ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
3854ffe3c632Sopenharmony_ci  NSNumber *aKey;
3855ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
3856ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
3857ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
3858ffe3c632Sopenharmony_ci    // Write the size of the message.
3859ffe3c632Sopenharmony_ci    int32_t unwrappedKey = [aKey intValue];
3860ffe3c632Sopenharmony_ci    int64_t unwrappedValue = [aValue longLongValue];
3861ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
3862ffe3c632Sopenharmony_ci    msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
3863ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
3864ffe3c632Sopenharmony_ci    // Write the fields.
3865ffe3c632Sopenharmony_ci    WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
3866ffe3c632Sopenharmony_ci    WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
3867ffe3c632Sopenharmony_ci  }
3868ffe3c632Sopenharmony_ci}
3869ffe3c632Sopenharmony_ci
3870ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
3871ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
3872ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueInt32)];
3873ffe3c632Sopenharmony_ci}
3874ffe3c632Sopenharmony_ci
3875ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
3876ffe3c632Sopenharmony_ci  [self enumerateKeysAndInt64sUsingBlock:^(int32_t key, int64_t value, BOOL *stop) {
3877ffe3c632Sopenharmony_ci      #pragma unused(stop)
3878ffe3c632Sopenharmony_ci      block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%lld", value]);
3879ffe3c632Sopenharmony_ci  }];
3880ffe3c632Sopenharmony_ci}
3881ffe3c632Sopenharmony_ci
3882ffe3c632Sopenharmony_ci- (BOOL)getInt64:(nullable int64_t *)value forKey:(int32_t)key {
3883ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:@(key)];
3884ffe3c632Sopenharmony_ci  if (wrapped && value) {
3885ffe3c632Sopenharmony_ci    *value = [wrapped longLongValue];
3886ffe3c632Sopenharmony_ci  }
3887ffe3c632Sopenharmony_ci  return (wrapped != NULL);
3888ffe3c632Sopenharmony_ci}
3889ffe3c632Sopenharmony_ci
3890ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBInt32Int64Dictionary *)otherDictionary {
3891ffe3c632Sopenharmony_ci  if (otherDictionary) {
3892ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
3893ffe3c632Sopenharmony_ci    if (_autocreator) {
3894ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
3895ffe3c632Sopenharmony_ci    }
3896ffe3c632Sopenharmony_ci  }
3897ffe3c632Sopenharmony_ci}
3898ffe3c632Sopenharmony_ci
3899ffe3c632Sopenharmony_ci- (void)setInt64:(int64_t)value forKey:(int32_t)key {
3900ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:@(key)];
3901ffe3c632Sopenharmony_ci  if (_autocreator) {
3902ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
3903ffe3c632Sopenharmony_ci  }
3904ffe3c632Sopenharmony_ci}
3905ffe3c632Sopenharmony_ci
3906ffe3c632Sopenharmony_ci- (void)removeInt64ForKey:(int32_t)aKey {
3907ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:@(aKey)];
3908ffe3c632Sopenharmony_ci}
3909ffe3c632Sopenharmony_ci
3910ffe3c632Sopenharmony_ci- (void)removeAll {
3911ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
3912ffe3c632Sopenharmony_ci}
3913ffe3c632Sopenharmony_ci
3914ffe3c632Sopenharmony_ci@end
3915ffe3c632Sopenharmony_ci
3916ffe3c632Sopenharmony_ci#pragma mark - Int32 -> Bool
3917ffe3c632Sopenharmony_ci
3918ffe3c632Sopenharmony_ci@implementation GPBInt32BoolDictionary {
3919ffe3c632Sopenharmony_ci @package
3920ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
3921ffe3c632Sopenharmony_ci}
3922ffe3c632Sopenharmony_ci
3923ffe3c632Sopenharmony_ci- (instancetype)init {
3924ffe3c632Sopenharmony_ci  return [self initWithBools:NULL forKeys:NULL count:0];
3925ffe3c632Sopenharmony_ci}
3926ffe3c632Sopenharmony_ci
3927ffe3c632Sopenharmony_ci- (instancetype)initWithBools:(const BOOL [])values
3928ffe3c632Sopenharmony_ci                      forKeys:(const int32_t [])keys
3929ffe3c632Sopenharmony_ci                        count:(NSUInteger)count {
3930ffe3c632Sopenharmony_ci  self = [super init];
3931ffe3c632Sopenharmony_ci  if (self) {
3932ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
3933ffe3c632Sopenharmony_ci    if (count && values && keys) {
3934ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
3935ffe3c632Sopenharmony_ci        [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
3936ffe3c632Sopenharmony_ci      }
3937ffe3c632Sopenharmony_ci    }
3938ffe3c632Sopenharmony_ci  }
3939ffe3c632Sopenharmony_ci  return self;
3940ffe3c632Sopenharmony_ci}
3941ffe3c632Sopenharmony_ci
3942ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBInt32BoolDictionary *)dictionary {
3943ffe3c632Sopenharmony_ci  self = [self initWithBools:NULL forKeys:NULL count:0];
3944ffe3c632Sopenharmony_ci  if (self) {
3945ffe3c632Sopenharmony_ci    if (dictionary) {
3946ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
3947ffe3c632Sopenharmony_ci    }
3948ffe3c632Sopenharmony_ci  }
3949ffe3c632Sopenharmony_ci  return self;
3950ffe3c632Sopenharmony_ci}
3951ffe3c632Sopenharmony_ci
3952ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
3953ffe3c632Sopenharmony_ci  #pragma unused(numItems)
3954ffe3c632Sopenharmony_ci  return [self initWithBools:NULL forKeys:NULL count:0];
3955ffe3c632Sopenharmony_ci}
3956ffe3c632Sopenharmony_ci
3957ffe3c632Sopenharmony_ci- (void)dealloc {
3958ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
3959ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
3960ffe3c632Sopenharmony_ci           [self class], _autocreator);
3961ffe3c632Sopenharmony_ci  [_dictionary release];
3962ffe3c632Sopenharmony_ci  [super dealloc];
3963ffe3c632Sopenharmony_ci}
3964ffe3c632Sopenharmony_ci
3965ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
3966ffe3c632Sopenharmony_ci  return [[GPBInt32BoolDictionary allocWithZone:zone] initWithDictionary:self];
3967ffe3c632Sopenharmony_ci}
3968ffe3c632Sopenharmony_ci
3969ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
3970ffe3c632Sopenharmony_ci  if (self == other) {
3971ffe3c632Sopenharmony_ci    return YES;
3972ffe3c632Sopenharmony_ci  }
3973ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBInt32BoolDictionary class]]) {
3974ffe3c632Sopenharmony_ci    return NO;
3975ffe3c632Sopenharmony_ci  }
3976ffe3c632Sopenharmony_ci  GPBInt32BoolDictionary *otherDictionary = other;
3977ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
3978ffe3c632Sopenharmony_ci}
3979ffe3c632Sopenharmony_ci
3980ffe3c632Sopenharmony_ci- (NSUInteger)hash {
3981ffe3c632Sopenharmony_ci  return _dictionary.count;
3982ffe3c632Sopenharmony_ci}
3983ffe3c632Sopenharmony_ci
3984ffe3c632Sopenharmony_ci- (NSString *)description {
3985ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
3986ffe3c632Sopenharmony_ci}
3987ffe3c632Sopenharmony_ci
3988ffe3c632Sopenharmony_ci- (NSUInteger)count {
3989ffe3c632Sopenharmony_ci  return _dictionary.count;
3990ffe3c632Sopenharmony_ci}
3991ffe3c632Sopenharmony_ci
3992ffe3c632Sopenharmony_ci- (void)enumerateKeysAndBoolsUsingBlock:
3993ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(int32_t key, BOOL value, BOOL *stop))block {
3994ffe3c632Sopenharmony_ci  BOOL stop = NO;
3995ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
3996ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
3997ffe3c632Sopenharmony_ci  NSNumber *aKey;
3998ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
3999ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
4000ffe3c632Sopenharmony_ci    block([aKey intValue], [aValue boolValue], &stop);
4001ffe3c632Sopenharmony_ci    if (stop) {
4002ffe3c632Sopenharmony_ci      break;
4003ffe3c632Sopenharmony_ci    }
4004ffe3c632Sopenharmony_ci  }
4005ffe3c632Sopenharmony_ci}
4006ffe3c632Sopenharmony_ci
4007ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
4008ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
4009ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
4010ffe3c632Sopenharmony_ci  if (count == 0) {
4011ffe3c632Sopenharmony_ci    return 0;
4012ffe3c632Sopenharmony_ci  }
4013ffe3c632Sopenharmony_ci
4014ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
4015ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
4016ffe3c632Sopenharmony_ci  size_t result = 0;
4017ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
4018ffe3c632Sopenharmony_ci  NSNumber *aKey;
4019ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
4020ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
4021ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
4022ffe3c632Sopenharmony_ci    msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
4023ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
4024ffe3c632Sopenharmony_ci  }
4025ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
4026ffe3c632Sopenharmony_ci  result += tagSize * count;
4027ffe3c632Sopenharmony_ci  return result;
4028ffe3c632Sopenharmony_ci}
4029ffe3c632Sopenharmony_ci
4030ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
4031ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
4032ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
4033ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
4034ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
4035ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
4036ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
4037ffe3c632Sopenharmony_ci  NSNumber *aKey;
4038ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
4039ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
4040ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
4041ffe3c632Sopenharmony_ci    // Write the size of the message.
4042ffe3c632Sopenharmony_ci    int32_t unwrappedKey = [aKey intValue];
4043ffe3c632Sopenharmony_ci    BOOL unwrappedValue = [aValue boolValue];
4044ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
4045ffe3c632Sopenharmony_ci    msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
4046ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
4047ffe3c632Sopenharmony_ci    // Write the fields.
4048ffe3c632Sopenharmony_ci    WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
4049ffe3c632Sopenharmony_ci    WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
4050ffe3c632Sopenharmony_ci  }
4051ffe3c632Sopenharmony_ci}
4052ffe3c632Sopenharmony_ci
4053ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
4054ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
4055ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueBool) forKey:@(key->valueInt32)];
4056ffe3c632Sopenharmony_ci}
4057ffe3c632Sopenharmony_ci
4058ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
4059ffe3c632Sopenharmony_ci  [self enumerateKeysAndBoolsUsingBlock:^(int32_t key, BOOL value, BOOL *stop) {
4060ffe3c632Sopenharmony_ci      #pragma unused(stop)
4061ffe3c632Sopenharmony_ci      block([NSString stringWithFormat:@"%d", key], (value ? @"true" : @"false"));
4062ffe3c632Sopenharmony_ci  }];
4063ffe3c632Sopenharmony_ci}
4064ffe3c632Sopenharmony_ci
4065ffe3c632Sopenharmony_ci- (BOOL)getBool:(nullable BOOL *)value forKey:(int32_t)key {
4066ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:@(key)];
4067ffe3c632Sopenharmony_ci  if (wrapped && value) {
4068ffe3c632Sopenharmony_ci    *value = [wrapped boolValue];
4069ffe3c632Sopenharmony_ci  }
4070ffe3c632Sopenharmony_ci  return (wrapped != NULL);
4071ffe3c632Sopenharmony_ci}
4072ffe3c632Sopenharmony_ci
4073ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBInt32BoolDictionary *)otherDictionary {
4074ffe3c632Sopenharmony_ci  if (otherDictionary) {
4075ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
4076ffe3c632Sopenharmony_ci    if (_autocreator) {
4077ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
4078ffe3c632Sopenharmony_ci    }
4079ffe3c632Sopenharmony_ci  }
4080ffe3c632Sopenharmony_ci}
4081ffe3c632Sopenharmony_ci
4082ffe3c632Sopenharmony_ci- (void)setBool:(BOOL)value forKey:(int32_t)key {
4083ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:@(key)];
4084ffe3c632Sopenharmony_ci  if (_autocreator) {
4085ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
4086ffe3c632Sopenharmony_ci  }
4087ffe3c632Sopenharmony_ci}
4088ffe3c632Sopenharmony_ci
4089ffe3c632Sopenharmony_ci- (void)removeBoolForKey:(int32_t)aKey {
4090ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:@(aKey)];
4091ffe3c632Sopenharmony_ci}
4092ffe3c632Sopenharmony_ci
4093ffe3c632Sopenharmony_ci- (void)removeAll {
4094ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
4095ffe3c632Sopenharmony_ci}
4096ffe3c632Sopenharmony_ci
4097ffe3c632Sopenharmony_ci@end
4098ffe3c632Sopenharmony_ci
4099ffe3c632Sopenharmony_ci#pragma mark - Int32 -> Float
4100ffe3c632Sopenharmony_ci
4101ffe3c632Sopenharmony_ci@implementation GPBInt32FloatDictionary {
4102ffe3c632Sopenharmony_ci @package
4103ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
4104ffe3c632Sopenharmony_ci}
4105ffe3c632Sopenharmony_ci
4106ffe3c632Sopenharmony_ci- (instancetype)init {
4107ffe3c632Sopenharmony_ci  return [self initWithFloats:NULL forKeys:NULL count:0];
4108ffe3c632Sopenharmony_ci}
4109ffe3c632Sopenharmony_ci
4110ffe3c632Sopenharmony_ci- (instancetype)initWithFloats:(const float [])values
4111ffe3c632Sopenharmony_ci                       forKeys:(const int32_t [])keys
4112ffe3c632Sopenharmony_ci                         count:(NSUInteger)count {
4113ffe3c632Sopenharmony_ci  self = [super init];
4114ffe3c632Sopenharmony_ci  if (self) {
4115ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
4116ffe3c632Sopenharmony_ci    if (count && values && keys) {
4117ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
4118ffe3c632Sopenharmony_ci        [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
4119ffe3c632Sopenharmony_ci      }
4120ffe3c632Sopenharmony_ci    }
4121ffe3c632Sopenharmony_ci  }
4122ffe3c632Sopenharmony_ci  return self;
4123ffe3c632Sopenharmony_ci}
4124ffe3c632Sopenharmony_ci
4125ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBInt32FloatDictionary *)dictionary {
4126ffe3c632Sopenharmony_ci  self = [self initWithFloats:NULL forKeys:NULL count:0];
4127ffe3c632Sopenharmony_ci  if (self) {
4128ffe3c632Sopenharmony_ci    if (dictionary) {
4129ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
4130ffe3c632Sopenharmony_ci    }
4131ffe3c632Sopenharmony_ci  }
4132ffe3c632Sopenharmony_ci  return self;
4133ffe3c632Sopenharmony_ci}
4134ffe3c632Sopenharmony_ci
4135ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
4136ffe3c632Sopenharmony_ci  #pragma unused(numItems)
4137ffe3c632Sopenharmony_ci  return [self initWithFloats:NULL forKeys:NULL count:0];
4138ffe3c632Sopenharmony_ci}
4139ffe3c632Sopenharmony_ci
4140ffe3c632Sopenharmony_ci- (void)dealloc {
4141ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
4142ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
4143ffe3c632Sopenharmony_ci           [self class], _autocreator);
4144ffe3c632Sopenharmony_ci  [_dictionary release];
4145ffe3c632Sopenharmony_ci  [super dealloc];
4146ffe3c632Sopenharmony_ci}
4147ffe3c632Sopenharmony_ci
4148ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
4149ffe3c632Sopenharmony_ci  return [[GPBInt32FloatDictionary allocWithZone:zone] initWithDictionary:self];
4150ffe3c632Sopenharmony_ci}
4151ffe3c632Sopenharmony_ci
4152ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
4153ffe3c632Sopenharmony_ci  if (self == other) {
4154ffe3c632Sopenharmony_ci    return YES;
4155ffe3c632Sopenharmony_ci  }
4156ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBInt32FloatDictionary class]]) {
4157ffe3c632Sopenharmony_ci    return NO;
4158ffe3c632Sopenharmony_ci  }
4159ffe3c632Sopenharmony_ci  GPBInt32FloatDictionary *otherDictionary = other;
4160ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
4161ffe3c632Sopenharmony_ci}
4162ffe3c632Sopenharmony_ci
4163ffe3c632Sopenharmony_ci- (NSUInteger)hash {
4164ffe3c632Sopenharmony_ci  return _dictionary.count;
4165ffe3c632Sopenharmony_ci}
4166ffe3c632Sopenharmony_ci
4167ffe3c632Sopenharmony_ci- (NSString *)description {
4168ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
4169ffe3c632Sopenharmony_ci}
4170ffe3c632Sopenharmony_ci
4171ffe3c632Sopenharmony_ci- (NSUInteger)count {
4172ffe3c632Sopenharmony_ci  return _dictionary.count;
4173ffe3c632Sopenharmony_ci}
4174ffe3c632Sopenharmony_ci
4175ffe3c632Sopenharmony_ci- (void)enumerateKeysAndFloatsUsingBlock:
4176ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(int32_t key, float value, BOOL *stop))block {
4177ffe3c632Sopenharmony_ci  BOOL stop = NO;
4178ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
4179ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
4180ffe3c632Sopenharmony_ci  NSNumber *aKey;
4181ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
4182ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
4183ffe3c632Sopenharmony_ci    block([aKey intValue], [aValue floatValue], &stop);
4184ffe3c632Sopenharmony_ci    if (stop) {
4185ffe3c632Sopenharmony_ci      break;
4186ffe3c632Sopenharmony_ci    }
4187ffe3c632Sopenharmony_ci  }
4188ffe3c632Sopenharmony_ci}
4189ffe3c632Sopenharmony_ci
4190ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
4191ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
4192ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
4193ffe3c632Sopenharmony_ci  if (count == 0) {
4194ffe3c632Sopenharmony_ci    return 0;
4195ffe3c632Sopenharmony_ci  }
4196ffe3c632Sopenharmony_ci
4197ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
4198ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
4199ffe3c632Sopenharmony_ci  size_t result = 0;
4200ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
4201ffe3c632Sopenharmony_ci  NSNumber *aKey;
4202ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
4203ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
4204ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
4205ffe3c632Sopenharmony_ci    msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
4206ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
4207ffe3c632Sopenharmony_ci  }
4208ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
4209ffe3c632Sopenharmony_ci  result += tagSize * count;
4210ffe3c632Sopenharmony_ci  return result;
4211ffe3c632Sopenharmony_ci}
4212ffe3c632Sopenharmony_ci
4213ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
4214ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
4215ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
4216ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
4217ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
4218ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
4219ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
4220ffe3c632Sopenharmony_ci  NSNumber *aKey;
4221ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
4222ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
4223ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
4224ffe3c632Sopenharmony_ci    // Write the size of the message.
4225ffe3c632Sopenharmony_ci    int32_t unwrappedKey = [aKey intValue];
4226ffe3c632Sopenharmony_ci    float unwrappedValue = [aValue floatValue];
4227ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
4228ffe3c632Sopenharmony_ci    msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
4229ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
4230ffe3c632Sopenharmony_ci    // Write the fields.
4231ffe3c632Sopenharmony_ci    WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
4232ffe3c632Sopenharmony_ci    WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
4233ffe3c632Sopenharmony_ci  }
4234ffe3c632Sopenharmony_ci}
4235ffe3c632Sopenharmony_ci
4236ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
4237ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
4238ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueInt32)];
4239ffe3c632Sopenharmony_ci}
4240ffe3c632Sopenharmony_ci
4241ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
4242ffe3c632Sopenharmony_ci  [self enumerateKeysAndFloatsUsingBlock:^(int32_t key, float value, BOOL *stop) {
4243ffe3c632Sopenharmony_ci      #pragma unused(stop)
4244ffe3c632Sopenharmony_ci      block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
4245ffe3c632Sopenharmony_ci  }];
4246ffe3c632Sopenharmony_ci}
4247ffe3c632Sopenharmony_ci
4248ffe3c632Sopenharmony_ci- (BOOL)getFloat:(nullable float *)value forKey:(int32_t)key {
4249ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:@(key)];
4250ffe3c632Sopenharmony_ci  if (wrapped && value) {
4251ffe3c632Sopenharmony_ci    *value = [wrapped floatValue];
4252ffe3c632Sopenharmony_ci  }
4253ffe3c632Sopenharmony_ci  return (wrapped != NULL);
4254ffe3c632Sopenharmony_ci}
4255ffe3c632Sopenharmony_ci
4256ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBInt32FloatDictionary *)otherDictionary {
4257ffe3c632Sopenharmony_ci  if (otherDictionary) {
4258ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
4259ffe3c632Sopenharmony_ci    if (_autocreator) {
4260ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
4261ffe3c632Sopenharmony_ci    }
4262ffe3c632Sopenharmony_ci  }
4263ffe3c632Sopenharmony_ci}
4264ffe3c632Sopenharmony_ci
4265ffe3c632Sopenharmony_ci- (void)setFloat:(float)value forKey:(int32_t)key {
4266ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:@(key)];
4267ffe3c632Sopenharmony_ci  if (_autocreator) {
4268ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
4269ffe3c632Sopenharmony_ci  }
4270ffe3c632Sopenharmony_ci}
4271ffe3c632Sopenharmony_ci
4272ffe3c632Sopenharmony_ci- (void)removeFloatForKey:(int32_t)aKey {
4273ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:@(aKey)];
4274ffe3c632Sopenharmony_ci}
4275ffe3c632Sopenharmony_ci
4276ffe3c632Sopenharmony_ci- (void)removeAll {
4277ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
4278ffe3c632Sopenharmony_ci}
4279ffe3c632Sopenharmony_ci
4280ffe3c632Sopenharmony_ci@end
4281ffe3c632Sopenharmony_ci
4282ffe3c632Sopenharmony_ci#pragma mark - Int32 -> Double
4283ffe3c632Sopenharmony_ci
4284ffe3c632Sopenharmony_ci@implementation GPBInt32DoubleDictionary {
4285ffe3c632Sopenharmony_ci @package
4286ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
4287ffe3c632Sopenharmony_ci}
4288ffe3c632Sopenharmony_ci
4289ffe3c632Sopenharmony_ci- (instancetype)init {
4290ffe3c632Sopenharmony_ci  return [self initWithDoubles:NULL forKeys:NULL count:0];
4291ffe3c632Sopenharmony_ci}
4292ffe3c632Sopenharmony_ci
4293ffe3c632Sopenharmony_ci- (instancetype)initWithDoubles:(const double [])values
4294ffe3c632Sopenharmony_ci                        forKeys:(const int32_t [])keys
4295ffe3c632Sopenharmony_ci                          count:(NSUInteger)count {
4296ffe3c632Sopenharmony_ci  self = [super init];
4297ffe3c632Sopenharmony_ci  if (self) {
4298ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
4299ffe3c632Sopenharmony_ci    if (count && values && keys) {
4300ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
4301ffe3c632Sopenharmony_ci        [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
4302ffe3c632Sopenharmony_ci      }
4303ffe3c632Sopenharmony_ci    }
4304ffe3c632Sopenharmony_ci  }
4305ffe3c632Sopenharmony_ci  return self;
4306ffe3c632Sopenharmony_ci}
4307ffe3c632Sopenharmony_ci
4308ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBInt32DoubleDictionary *)dictionary {
4309ffe3c632Sopenharmony_ci  self = [self initWithDoubles:NULL forKeys:NULL count:0];
4310ffe3c632Sopenharmony_ci  if (self) {
4311ffe3c632Sopenharmony_ci    if (dictionary) {
4312ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
4313ffe3c632Sopenharmony_ci    }
4314ffe3c632Sopenharmony_ci  }
4315ffe3c632Sopenharmony_ci  return self;
4316ffe3c632Sopenharmony_ci}
4317ffe3c632Sopenharmony_ci
4318ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
4319ffe3c632Sopenharmony_ci  #pragma unused(numItems)
4320ffe3c632Sopenharmony_ci  return [self initWithDoubles:NULL forKeys:NULL count:0];
4321ffe3c632Sopenharmony_ci}
4322ffe3c632Sopenharmony_ci
4323ffe3c632Sopenharmony_ci- (void)dealloc {
4324ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
4325ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
4326ffe3c632Sopenharmony_ci           [self class], _autocreator);
4327ffe3c632Sopenharmony_ci  [_dictionary release];
4328ffe3c632Sopenharmony_ci  [super dealloc];
4329ffe3c632Sopenharmony_ci}
4330ffe3c632Sopenharmony_ci
4331ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
4332ffe3c632Sopenharmony_ci  return [[GPBInt32DoubleDictionary allocWithZone:zone] initWithDictionary:self];
4333ffe3c632Sopenharmony_ci}
4334ffe3c632Sopenharmony_ci
4335ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
4336ffe3c632Sopenharmony_ci  if (self == other) {
4337ffe3c632Sopenharmony_ci    return YES;
4338ffe3c632Sopenharmony_ci  }
4339ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBInt32DoubleDictionary class]]) {
4340ffe3c632Sopenharmony_ci    return NO;
4341ffe3c632Sopenharmony_ci  }
4342ffe3c632Sopenharmony_ci  GPBInt32DoubleDictionary *otherDictionary = other;
4343ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
4344ffe3c632Sopenharmony_ci}
4345ffe3c632Sopenharmony_ci
4346ffe3c632Sopenharmony_ci- (NSUInteger)hash {
4347ffe3c632Sopenharmony_ci  return _dictionary.count;
4348ffe3c632Sopenharmony_ci}
4349ffe3c632Sopenharmony_ci
4350ffe3c632Sopenharmony_ci- (NSString *)description {
4351ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
4352ffe3c632Sopenharmony_ci}
4353ffe3c632Sopenharmony_ci
4354ffe3c632Sopenharmony_ci- (NSUInteger)count {
4355ffe3c632Sopenharmony_ci  return _dictionary.count;
4356ffe3c632Sopenharmony_ci}
4357ffe3c632Sopenharmony_ci
4358ffe3c632Sopenharmony_ci- (void)enumerateKeysAndDoublesUsingBlock:
4359ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(int32_t key, double value, BOOL *stop))block {
4360ffe3c632Sopenharmony_ci  BOOL stop = NO;
4361ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
4362ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
4363ffe3c632Sopenharmony_ci  NSNumber *aKey;
4364ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
4365ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
4366ffe3c632Sopenharmony_ci    block([aKey intValue], [aValue doubleValue], &stop);
4367ffe3c632Sopenharmony_ci    if (stop) {
4368ffe3c632Sopenharmony_ci      break;
4369ffe3c632Sopenharmony_ci    }
4370ffe3c632Sopenharmony_ci  }
4371ffe3c632Sopenharmony_ci}
4372ffe3c632Sopenharmony_ci
4373ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
4374ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
4375ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
4376ffe3c632Sopenharmony_ci  if (count == 0) {
4377ffe3c632Sopenharmony_ci    return 0;
4378ffe3c632Sopenharmony_ci  }
4379ffe3c632Sopenharmony_ci
4380ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
4381ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
4382ffe3c632Sopenharmony_ci  size_t result = 0;
4383ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
4384ffe3c632Sopenharmony_ci  NSNumber *aKey;
4385ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
4386ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
4387ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
4388ffe3c632Sopenharmony_ci    msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
4389ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
4390ffe3c632Sopenharmony_ci  }
4391ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
4392ffe3c632Sopenharmony_ci  result += tagSize * count;
4393ffe3c632Sopenharmony_ci  return result;
4394ffe3c632Sopenharmony_ci}
4395ffe3c632Sopenharmony_ci
4396ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
4397ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
4398ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
4399ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
4400ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
4401ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
4402ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
4403ffe3c632Sopenharmony_ci  NSNumber *aKey;
4404ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
4405ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
4406ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
4407ffe3c632Sopenharmony_ci    // Write the size of the message.
4408ffe3c632Sopenharmony_ci    int32_t unwrappedKey = [aKey intValue];
4409ffe3c632Sopenharmony_ci    double unwrappedValue = [aValue doubleValue];
4410ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
4411ffe3c632Sopenharmony_ci    msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
4412ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
4413ffe3c632Sopenharmony_ci    // Write the fields.
4414ffe3c632Sopenharmony_ci    WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
4415ffe3c632Sopenharmony_ci    WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
4416ffe3c632Sopenharmony_ci  }
4417ffe3c632Sopenharmony_ci}
4418ffe3c632Sopenharmony_ci
4419ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
4420ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
4421ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueInt32)];
4422ffe3c632Sopenharmony_ci}
4423ffe3c632Sopenharmony_ci
4424ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
4425ffe3c632Sopenharmony_ci  [self enumerateKeysAndDoublesUsingBlock:^(int32_t key, double value, BOOL *stop) {
4426ffe3c632Sopenharmony_ci      #pragma unused(stop)
4427ffe3c632Sopenharmony_ci      block([NSString stringWithFormat:@"%d", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
4428ffe3c632Sopenharmony_ci  }];
4429ffe3c632Sopenharmony_ci}
4430ffe3c632Sopenharmony_ci
4431ffe3c632Sopenharmony_ci- (BOOL)getDouble:(nullable double *)value forKey:(int32_t)key {
4432ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:@(key)];
4433ffe3c632Sopenharmony_ci  if (wrapped && value) {
4434ffe3c632Sopenharmony_ci    *value = [wrapped doubleValue];
4435ffe3c632Sopenharmony_ci  }
4436ffe3c632Sopenharmony_ci  return (wrapped != NULL);
4437ffe3c632Sopenharmony_ci}
4438ffe3c632Sopenharmony_ci
4439ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBInt32DoubleDictionary *)otherDictionary {
4440ffe3c632Sopenharmony_ci  if (otherDictionary) {
4441ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
4442ffe3c632Sopenharmony_ci    if (_autocreator) {
4443ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
4444ffe3c632Sopenharmony_ci    }
4445ffe3c632Sopenharmony_ci  }
4446ffe3c632Sopenharmony_ci}
4447ffe3c632Sopenharmony_ci
4448ffe3c632Sopenharmony_ci- (void)setDouble:(double)value forKey:(int32_t)key {
4449ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:@(key)];
4450ffe3c632Sopenharmony_ci  if (_autocreator) {
4451ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
4452ffe3c632Sopenharmony_ci  }
4453ffe3c632Sopenharmony_ci}
4454ffe3c632Sopenharmony_ci
4455ffe3c632Sopenharmony_ci- (void)removeDoubleForKey:(int32_t)aKey {
4456ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:@(aKey)];
4457ffe3c632Sopenharmony_ci}
4458ffe3c632Sopenharmony_ci
4459ffe3c632Sopenharmony_ci- (void)removeAll {
4460ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
4461ffe3c632Sopenharmony_ci}
4462ffe3c632Sopenharmony_ci
4463ffe3c632Sopenharmony_ci@end
4464ffe3c632Sopenharmony_ci
4465ffe3c632Sopenharmony_ci#pragma mark - Int32 -> Enum
4466ffe3c632Sopenharmony_ci
4467ffe3c632Sopenharmony_ci@implementation GPBInt32EnumDictionary {
4468ffe3c632Sopenharmony_ci @package
4469ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
4470ffe3c632Sopenharmony_ci  GPBEnumValidationFunc _validationFunc;
4471ffe3c632Sopenharmony_ci}
4472ffe3c632Sopenharmony_ci
4473ffe3c632Sopenharmony_ci@synthesize validationFunc = _validationFunc;
4474ffe3c632Sopenharmony_ci
4475ffe3c632Sopenharmony_ci- (instancetype)init {
4476ffe3c632Sopenharmony_ci  return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
4477ffe3c632Sopenharmony_ci}
4478ffe3c632Sopenharmony_ci
4479ffe3c632Sopenharmony_ci- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
4480ffe3c632Sopenharmony_ci  return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
4481ffe3c632Sopenharmony_ci}
4482ffe3c632Sopenharmony_ci
4483ffe3c632Sopenharmony_ci- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
4484ffe3c632Sopenharmony_ci                                 rawValues:(const int32_t [])rawValues
4485ffe3c632Sopenharmony_ci                                   forKeys:(const int32_t [])keys
4486ffe3c632Sopenharmony_ci                                     count:(NSUInteger)count {
4487ffe3c632Sopenharmony_ci  self = [super init];
4488ffe3c632Sopenharmony_ci  if (self) {
4489ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
4490ffe3c632Sopenharmony_ci    _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
4491ffe3c632Sopenharmony_ci    if (count && rawValues && keys) {
4492ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
4493ffe3c632Sopenharmony_ci        [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])];
4494ffe3c632Sopenharmony_ci      }
4495ffe3c632Sopenharmony_ci    }
4496ffe3c632Sopenharmony_ci  }
4497ffe3c632Sopenharmony_ci  return self;
4498ffe3c632Sopenharmony_ci}
4499ffe3c632Sopenharmony_ci
4500ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBInt32EnumDictionary *)dictionary {
4501ffe3c632Sopenharmony_ci  self = [self initWithValidationFunction:dictionary.validationFunc
4502ffe3c632Sopenharmony_ci                                rawValues:NULL
4503ffe3c632Sopenharmony_ci                                  forKeys:NULL
4504ffe3c632Sopenharmony_ci                                    count:0];
4505ffe3c632Sopenharmony_ci  if (self) {
4506ffe3c632Sopenharmony_ci    if (dictionary) {
4507ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
4508ffe3c632Sopenharmony_ci    }
4509ffe3c632Sopenharmony_ci  }
4510ffe3c632Sopenharmony_ci  return self;
4511ffe3c632Sopenharmony_ci}
4512ffe3c632Sopenharmony_ci
4513ffe3c632Sopenharmony_ci- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
4514ffe3c632Sopenharmony_ci                                  capacity:(NSUInteger)numItems {
4515ffe3c632Sopenharmony_ci  #pragma unused(numItems)
4516ffe3c632Sopenharmony_ci  return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
4517ffe3c632Sopenharmony_ci}
4518ffe3c632Sopenharmony_ci
4519ffe3c632Sopenharmony_ci- (void)dealloc {
4520ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
4521ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
4522ffe3c632Sopenharmony_ci           [self class], _autocreator);
4523ffe3c632Sopenharmony_ci  [_dictionary release];
4524ffe3c632Sopenharmony_ci  [super dealloc];
4525ffe3c632Sopenharmony_ci}
4526ffe3c632Sopenharmony_ci
4527ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
4528ffe3c632Sopenharmony_ci  return [[GPBInt32EnumDictionary allocWithZone:zone] initWithDictionary:self];
4529ffe3c632Sopenharmony_ci}
4530ffe3c632Sopenharmony_ci
4531ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
4532ffe3c632Sopenharmony_ci  if (self == other) {
4533ffe3c632Sopenharmony_ci    return YES;
4534ffe3c632Sopenharmony_ci  }
4535ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBInt32EnumDictionary class]]) {
4536ffe3c632Sopenharmony_ci    return NO;
4537ffe3c632Sopenharmony_ci  }
4538ffe3c632Sopenharmony_ci  GPBInt32EnumDictionary *otherDictionary = other;
4539ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
4540ffe3c632Sopenharmony_ci}
4541ffe3c632Sopenharmony_ci
4542ffe3c632Sopenharmony_ci- (NSUInteger)hash {
4543ffe3c632Sopenharmony_ci  return _dictionary.count;
4544ffe3c632Sopenharmony_ci}
4545ffe3c632Sopenharmony_ci
4546ffe3c632Sopenharmony_ci- (NSString *)description {
4547ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
4548ffe3c632Sopenharmony_ci}
4549ffe3c632Sopenharmony_ci
4550ffe3c632Sopenharmony_ci- (NSUInteger)count {
4551ffe3c632Sopenharmony_ci  return _dictionary.count;
4552ffe3c632Sopenharmony_ci}
4553ffe3c632Sopenharmony_ci
4554ffe3c632Sopenharmony_ci- (void)enumerateKeysAndRawValuesUsingBlock:
4555ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(int32_t key, int32_t value, BOOL *stop))block {
4556ffe3c632Sopenharmony_ci  BOOL stop = NO;
4557ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
4558ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
4559ffe3c632Sopenharmony_ci  NSNumber *aKey;
4560ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
4561ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
4562ffe3c632Sopenharmony_ci    block([aKey intValue], [aValue intValue], &stop);
4563ffe3c632Sopenharmony_ci    if (stop) {
4564ffe3c632Sopenharmony_ci      break;
4565ffe3c632Sopenharmony_ci    }
4566ffe3c632Sopenharmony_ci  }
4567ffe3c632Sopenharmony_ci}
4568ffe3c632Sopenharmony_ci
4569ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
4570ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
4571ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
4572ffe3c632Sopenharmony_ci  if (count == 0) {
4573ffe3c632Sopenharmony_ci    return 0;
4574ffe3c632Sopenharmony_ci  }
4575ffe3c632Sopenharmony_ci
4576ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
4577ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
4578ffe3c632Sopenharmony_ci  size_t result = 0;
4579ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
4580ffe3c632Sopenharmony_ci  NSNumber *aKey;
4581ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
4582ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
4583ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
4584ffe3c632Sopenharmony_ci    msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
4585ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
4586ffe3c632Sopenharmony_ci  }
4587ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
4588ffe3c632Sopenharmony_ci  result += tagSize * count;
4589ffe3c632Sopenharmony_ci  return result;
4590ffe3c632Sopenharmony_ci}
4591ffe3c632Sopenharmony_ci
4592ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
4593ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
4594ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
4595ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
4596ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
4597ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
4598ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
4599ffe3c632Sopenharmony_ci  NSNumber *aKey;
4600ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
4601ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
4602ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
4603ffe3c632Sopenharmony_ci    // Write the size of the message.
4604ffe3c632Sopenharmony_ci    int32_t unwrappedKey = [aKey intValue];
4605ffe3c632Sopenharmony_ci    int32_t unwrappedValue = [aValue intValue];
4606ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
4607ffe3c632Sopenharmony_ci    msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
4608ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
4609ffe3c632Sopenharmony_ci    // Write the fields.
4610ffe3c632Sopenharmony_ci    WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
4611ffe3c632Sopenharmony_ci    WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
4612ffe3c632Sopenharmony_ci  }
4613ffe3c632Sopenharmony_ci}
4614ffe3c632Sopenharmony_ci
4615ffe3c632Sopenharmony_ci- (NSData *)serializedDataForUnknownValue:(int32_t)value
4616ffe3c632Sopenharmony_ci                                   forKey:(GPBGenericValue *)key
4617ffe3c632Sopenharmony_ci                              keyDataType:(GPBDataType)keyDataType {
4618ffe3c632Sopenharmony_ci  size_t msgSize = ComputeDictInt32FieldSize(key->valueInt32, kMapKeyFieldNumber, keyDataType);
4619ffe3c632Sopenharmony_ci  msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
4620ffe3c632Sopenharmony_ci  NSMutableData *data = [NSMutableData dataWithLength:msgSize];
4621ffe3c632Sopenharmony_ci  GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
4622ffe3c632Sopenharmony_ci  WriteDictInt32Field(outputStream, key->valueInt32, kMapKeyFieldNumber, keyDataType);
4623ffe3c632Sopenharmony_ci  WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
4624ffe3c632Sopenharmony_ci  [outputStream release];
4625ffe3c632Sopenharmony_ci  return data;
4626ffe3c632Sopenharmony_ci}
4627ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
4628ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
4629ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueInt32)];
4630ffe3c632Sopenharmony_ci}
4631ffe3c632Sopenharmony_ci
4632ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
4633ffe3c632Sopenharmony_ci  [self enumerateKeysAndRawValuesUsingBlock:^(int32_t key, int32_t value, BOOL *stop) {
4634ffe3c632Sopenharmony_ci      #pragma unused(stop)
4635ffe3c632Sopenharmony_ci      block([NSString stringWithFormat:@"%d", key], @(value));
4636ffe3c632Sopenharmony_ci  }];
4637ffe3c632Sopenharmony_ci}
4638ffe3c632Sopenharmony_ci
4639ffe3c632Sopenharmony_ci- (BOOL)getEnum:(int32_t *)value forKey:(int32_t)key {
4640ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:@(key)];
4641ffe3c632Sopenharmony_ci  if (wrapped && value) {
4642ffe3c632Sopenharmony_ci    int32_t result = [wrapped intValue];
4643ffe3c632Sopenharmony_ci    if (!_validationFunc(result)) {
4644ffe3c632Sopenharmony_ci      result = kGPBUnrecognizedEnumeratorValue;
4645ffe3c632Sopenharmony_ci    }
4646ffe3c632Sopenharmony_ci    *value = result;
4647ffe3c632Sopenharmony_ci  }
4648ffe3c632Sopenharmony_ci  return (wrapped != NULL);
4649ffe3c632Sopenharmony_ci}
4650ffe3c632Sopenharmony_ci
4651ffe3c632Sopenharmony_ci- (BOOL)getRawValue:(int32_t *)rawValue forKey:(int32_t)key {
4652ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:@(key)];
4653ffe3c632Sopenharmony_ci  if (wrapped && rawValue) {
4654ffe3c632Sopenharmony_ci    *rawValue = [wrapped intValue];
4655ffe3c632Sopenharmony_ci  }
4656ffe3c632Sopenharmony_ci  return (wrapped != NULL);
4657ffe3c632Sopenharmony_ci}
4658ffe3c632Sopenharmony_ci
4659ffe3c632Sopenharmony_ci- (void)enumerateKeysAndEnumsUsingBlock:
4660ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(int32_t key, int32_t value, BOOL *stop))block {
4661ffe3c632Sopenharmony_ci  GPBEnumValidationFunc func = _validationFunc;
4662ffe3c632Sopenharmony_ci  BOOL stop = NO;
4663ffe3c632Sopenharmony_ci  NSEnumerator *keys = [_dictionary keyEnumerator];
4664ffe3c632Sopenharmony_ci  NSNumber *aKey;
4665ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
4666ffe3c632Sopenharmony_ci    NSNumber *aValue = _dictionary[aKey];
4667ffe3c632Sopenharmony_ci      int32_t unwrapped = [aValue intValue];
4668ffe3c632Sopenharmony_ci      if (!func(unwrapped)) {
4669ffe3c632Sopenharmony_ci        unwrapped = kGPBUnrecognizedEnumeratorValue;
4670ffe3c632Sopenharmony_ci      }
4671ffe3c632Sopenharmony_ci    block([aKey intValue], unwrapped, &stop);
4672ffe3c632Sopenharmony_ci    if (stop) {
4673ffe3c632Sopenharmony_ci      break;
4674ffe3c632Sopenharmony_ci    }
4675ffe3c632Sopenharmony_ci  }
4676ffe3c632Sopenharmony_ci}
4677ffe3c632Sopenharmony_ci
4678ffe3c632Sopenharmony_ci- (void)addRawEntriesFromDictionary:(GPBInt32EnumDictionary *)otherDictionary {
4679ffe3c632Sopenharmony_ci  if (otherDictionary) {
4680ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
4681ffe3c632Sopenharmony_ci    if (_autocreator) {
4682ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
4683ffe3c632Sopenharmony_ci    }
4684ffe3c632Sopenharmony_ci  }
4685ffe3c632Sopenharmony_ci}
4686ffe3c632Sopenharmony_ci
4687ffe3c632Sopenharmony_ci- (void)setRawValue:(int32_t)value forKey:(int32_t)key {
4688ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:@(key)];
4689ffe3c632Sopenharmony_ci  if (_autocreator) {
4690ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
4691ffe3c632Sopenharmony_ci  }
4692ffe3c632Sopenharmony_ci}
4693ffe3c632Sopenharmony_ci
4694ffe3c632Sopenharmony_ci- (void)removeEnumForKey:(int32_t)aKey {
4695ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:@(aKey)];
4696ffe3c632Sopenharmony_ci}
4697ffe3c632Sopenharmony_ci
4698ffe3c632Sopenharmony_ci- (void)removeAll {
4699ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
4700ffe3c632Sopenharmony_ci}
4701ffe3c632Sopenharmony_ci
4702ffe3c632Sopenharmony_ci- (void)setEnum:(int32_t)value forKey:(int32_t)key {
4703ffe3c632Sopenharmony_ci  if (!_validationFunc(value)) {
4704ffe3c632Sopenharmony_ci    [NSException raise:NSInvalidArgumentException
4705ffe3c632Sopenharmony_ci                format:@"GPBInt32EnumDictionary: Attempt to set an unknown enum value (%d)",
4706ffe3c632Sopenharmony_ci                       value];
4707ffe3c632Sopenharmony_ci  }
4708ffe3c632Sopenharmony_ci
4709ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:@(key)];
4710ffe3c632Sopenharmony_ci  if (_autocreator) {
4711ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
4712ffe3c632Sopenharmony_ci  }
4713ffe3c632Sopenharmony_ci}
4714ffe3c632Sopenharmony_ci
4715ffe3c632Sopenharmony_ci@end
4716ffe3c632Sopenharmony_ci
4717ffe3c632Sopenharmony_ci#pragma mark - Int32 -> Object
4718ffe3c632Sopenharmony_ci
4719ffe3c632Sopenharmony_ci@implementation GPBInt32ObjectDictionary {
4720ffe3c632Sopenharmony_ci @package
4721ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
4722ffe3c632Sopenharmony_ci}
4723ffe3c632Sopenharmony_ci
4724ffe3c632Sopenharmony_ci- (instancetype)init {
4725ffe3c632Sopenharmony_ci  return [self initWithObjects:NULL forKeys:NULL count:0];
4726ffe3c632Sopenharmony_ci}
4727ffe3c632Sopenharmony_ci
4728ffe3c632Sopenharmony_ci- (instancetype)initWithObjects:(const id [])objects
4729ffe3c632Sopenharmony_ci                        forKeys:(const int32_t [])keys
4730ffe3c632Sopenharmony_ci                          count:(NSUInteger)count {
4731ffe3c632Sopenharmony_ci  self = [super init];
4732ffe3c632Sopenharmony_ci  if (self) {
4733ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
4734ffe3c632Sopenharmony_ci    if (count && objects && keys) {
4735ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
4736ffe3c632Sopenharmony_ci        if (!objects[i]) {
4737ffe3c632Sopenharmony_ci          [NSException raise:NSInvalidArgumentException
4738ffe3c632Sopenharmony_ci                      format:@"Attempting to add nil object to a Dictionary"];
4739ffe3c632Sopenharmony_ci        }
4740ffe3c632Sopenharmony_ci        [_dictionary setObject:objects[i] forKey:@(keys[i])];
4741ffe3c632Sopenharmony_ci      }
4742ffe3c632Sopenharmony_ci    }
4743ffe3c632Sopenharmony_ci  }
4744ffe3c632Sopenharmony_ci  return self;
4745ffe3c632Sopenharmony_ci}
4746ffe3c632Sopenharmony_ci
4747ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBInt32ObjectDictionary *)dictionary {
4748ffe3c632Sopenharmony_ci  self = [self initWithObjects:NULL forKeys:NULL count:0];
4749ffe3c632Sopenharmony_ci  if (self) {
4750ffe3c632Sopenharmony_ci    if (dictionary) {
4751ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
4752ffe3c632Sopenharmony_ci    }
4753ffe3c632Sopenharmony_ci  }
4754ffe3c632Sopenharmony_ci  return self;
4755ffe3c632Sopenharmony_ci}
4756ffe3c632Sopenharmony_ci
4757ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
4758ffe3c632Sopenharmony_ci  #pragma unused(numItems)
4759ffe3c632Sopenharmony_ci  return [self initWithObjects:NULL forKeys:NULL count:0];
4760ffe3c632Sopenharmony_ci}
4761ffe3c632Sopenharmony_ci
4762ffe3c632Sopenharmony_ci- (void)dealloc {
4763ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
4764ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
4765ffe3c632Sopenharmony_ci           [self class], _autocreator);
4766ffe3c632Sopenharmony_ci  [_dictionary release];
4767ffe3c632Sopenharmony_ci  [super dealloc];
4768ffe3c632Sopenharmony_ci}
4769ffe3c632Sopenharmony_ci
4770ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
4771ffe3c632Sopenharmony_ci  return [[GPBInt32ObjectDictionary allocWithZone:zone] initWithDictionary:self];
4772ffe3c632Sopenharmony_ci}
4773ffe3c632Sopenharmony_ci
4774ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
4775ffe3c632Sopenharmony_ci  if (self == other) {
4776ffe3c632Sopenharmony_ci    return YES;
4777ffe3c632Sopenharmony_ci  }
4778ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBInt32ObjectDictionary class]]) {
4779ffe3c632Sopenharmony_ci    return NO;
4780ffe3c632Sopenharmony_ci  }
4781ffe3c632Sopenharmony_ci  GPBInt32ObjectDictionary *otherDictionary = other;
4782ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
4783ffe3c632Sopenharmony_ci}
4784ffe3c632Sopenharmony_ci
4785ffe3c632Sopenharmony_ci- (NSUInteger)hash {
4786ffe3c632Sopenharmony_ci  return _dictionary.count;
4787ffe3c632Sopenharmony_ci}
4788ffe3c632Sopenharmony_ci
4789ffe3c632Sopenharmony_ci- (NSString *)description {
4790ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
4791ffe3c632Sopenharmony_ci}
4792ffe3c632Sopenharmony_ci
4793ffe3c632Sopenharmony_ci- (NSUInteger)count {
4794ffe3c632Sopenharmony_ci  return _dictionary.count;
4795ffe3c632Sopenharmony_ci}
4796ffe3c632Sopenharmony_ci
4797ffe3c632Sopenharmony_ci- (void)enumerateKeysAndObjectsUsingBlock:
4798ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(int32_t key, id object, BOOL *stop))block {
4799ffe3c632Sopenharmony_ci  BOOL stop = NO;
4800ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
4801ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
4802ffe3c632Sopenharmony_ci  NSNumber *aKey;
4803ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
4804ffe3c632Sopenharmony_ci    id aObject = internal[aKey];
4805ffe3c632Sopenharmony_ci    block([aKey intValue], aObject, &stop);
4806ffe3c632Sopenharmony_ci    if (stop) {
4807ffe3c632Sopenharmony_ci      break;
4808ffe3c632Sopenharmony_ci    }
4809ffe3c632Sopenharmony_ci  }
4810ffe3c632Sopenharmony_ci}
4811ffe3c632Sopenharmony_ci
4812ffe3c632Sopenharmony_ci- (BOOL)isInitialized {
4813ffe3c632Sopenharmony_ci  for (GPBMessage *msg in [_dictionary objectEnumerator]) {
4814ffe3c632Sopenharmony_ci    if (!msg.initialized) {
4815ffe3c632Sopenharmony_ci      return NO;
4816ffe3c632Sopenharmony_ci    }
4817ffe3c632Sopenharmony_ci  }
4818ffe3c632Sopenharmony_ci  return YES;
4819ffe3c632Sopenharmony_ci}
4820ffe3c632Sopenharmony_ci
4821ffe3c632Sopenharmony_ci- (instancetype)deepCopyWithZone:(NSZone *)zone {
4822ffe3c632Sopenharmony_ci  GPBInt32ObjectDictionary *newDict =
4823ffe3c632Sopenharmony_ci      [[GPBInt32ObjectDictionary alloc] init];
4824ffe3c632Sopenharmony_ci  NSEnumerator *keys = [_dictionary keyEnumerator];
4825ffe3c632Sopenharmony_ci  id aKey;
4826ffe3c632Sopenharmony_ci  NSMutableDictionary *internalDict = newDict->_dictionary;
4827ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
4828ffe3c632Sopenharmony_ci    GPBMessage *msg = _dictionary[aKey];
4829ffe3c632Sopenharmony_ci    GPBMessage *copiedMsg = [msg copyWithZone:zone];
4830ffe3c632Sopenharmony_ci    [internalDict setObject:copiedMsg forKey:aKey];
4831ffe3c632Sopenharmony_ci    [copiedMsg release];
4832ffe3c632Sopenharmony_ci  }
4833ffe3c632Sopenharmony_ci  return newDict;
4834ffe3c632Sopenharmony_ci}
4835ffe3c632Sopenharmony_ci
4836ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
4837ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
4838ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
4839ffe3c632Sopenharmony_ci  if (count == 0) {
4840ffe3c632Sopenharmony_ci    return 0;
4841ffe3c632Sopenharmony_ci  }
4842ffe3c632Sopenharmony_ci
4843ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
4844ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
4845ffe3c632Sopenharmony_ci  size_t result = 0;
4846ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
4847ffe3c632Sopenharmony_ci  NSNumber *aKey;
4848ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
4849ffe3c632Sopenharmony_ci    id aObject = internal[aKey];
4850ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictInt32FieldSize([aKey intValue], kMapKeyFieldNumber, keyDataType);
4851ffe3c632Sopenharmony_ci    msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
4852ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
4853ffe3c632Sopenharmony_ci  }
4854ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
4855ffe3c632Sopenharmony_ci  result += tagSize * count;
4856ffe3c632Sopenharmony_ci  return result;
4857ffe3c632Sopenharmony_ci}
4858ffe3c632Sopenharmony_ci
4859ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
4860ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
4861ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
4862ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
4863ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
4864ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
4865ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
4866ffe3c632Sopenharmony_ci  NSNumber *aKey;
4867ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
4868ffe3c632Sopenharmony_ci    id aObject = internal[aKey];
4869ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
4870ffe3c632Sopenharmony_ci    // Write the size of the message.
4871ffe3c632Sopenharmony_ci    int32_t unwrappedKey = [aKey intValue];
4872ffe3c632Sopenharmony_ci    id unwrappedValue = aObject;
4873ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictInt32FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
4874ffe3c632Sopenharmony_ci    msgSize += ComputeDictObjectFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
4875ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
4876ffe3c632Sopenharmony_ci    // Write the fields.
4877ffe3c632Sopenharmony_ci    WriteDictInt32Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
4878ffe3c632Sopenharmony_ci    WriteDictObjectField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
4879ffe3c632Sopenharmony_ci  }
4880ffe3c632Sopenharmony_ci}
4881ffe3c632Sopenharmony_ci
4882ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
4883ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
4884ffe3c632Sopenharmony_ci  [_dictionary setObject:value->valueString forKey:@(key->valueInt32)];
4885ffe3c632Sopenharmony_ci}
4886ffe3c632Sopenharmony_ci
4887ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
4888ffe3c632Sopenharmony_ci  [self enumerateKeysAndObjectsUsingBlock:^(int32_t key, id object, BOOL *stop) {
4889ffe3c632Sopenharmony_ci      #pragma unused(stop)
4890ffe3c632Sopenharmony_ci      block([NSString stringWithFormat:@"%d", key], object);
4891ffe3c632Sopenharmony_ci  }];
4892ffe3c632Sopenharmony_ci}
4893ffe3c632Sopenharmony_ci
4894ffe3c632Sopenharmony_ci- (id)objectForKey:(int32_t)key {
4895ffe3c632Sopenharmony_ci  id result = [_dictionary objectForKey:@(key)];
4896ffe3c632Sopenharmony_ci  return result;
4897ffe3c632Sopenharmony_ci}
4898ffe3c632Sopenharmony_ci
4899ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBInt32ObjectDictionary *)otherDictionary {
4900ffe3c632Sopenharmony_ci  if (otherDictionary) {
4901ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
4902ffe3c632Sopenharmony_ci    if (_autocreator) {
4903ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
4904ffe3c632Sopenharmony_ci    }
4905ffe3c632Sopenharmony_ci  }
4906ffe3c632Sopenharmony_ci}
4907ffe3c632Sopenharmony_ci
4908ffe3c632Sopenharmony_ci- (void)setObject:(id)object forKey:(int32_t)key {
4909ffe3c632Sopenharmony_ci  if (!object) {
4910ffe3c632Sopenharmony_ci    [NSException raise:NSInvalidArgumentException
4911ffe3c632Sopenharmony_ci                format:@"Attempting to add nil object to a Dictionary"];
4912ffe3c632Sopenharmony_ci  }
4913ffe3c632Sopenharmony_ci  [_dictionary setObject:object forKey:@(key)];
4914ffe3c632Sopenharmony_ci  if (_autocreator) {
4915ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
4916ffe3c632Sopenharmony_ci  }
4917ffe3c632Sopenharmony_ci}
4918ffe3c632Sopenharmony_ci
4919ffe3c632Sopenharmony_ci- (void)removeObjectForKey:(int32_t)aKey {
4920ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:@(aKey)];
4921ffe3c632Sopenharmony_ci}
4922ffe3c632Sopenharmony_ci
4923ffe3c632Sopenharmony_ci- (void)removeAll {
4924ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
4925ffe3c632Sopenharmony_ci}
4926ffe3c632Sopenharmony_ci
4927ffe3c632Sopenharmony_ci@end
4928ffe3c632Sopenharmony_ci
4929ffe3c632Sopenharmony_ci// clang-format on
4930ffe3c632Sopenharmony_ci//%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(UInt64, uint64_t)
4931ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly.
4932ffe3c632Sopenharmony_ci// clang-format off
4933ffe3c632Sopenharmony_ci
4934ffe3c632Sopenharmony_ci#pragma mark - UInt64 -> UInt32
4935ffe3c632Sopenharmony_ci
4936ffe3c632Sopenharmony_ci@implementation GPBUInt64UInt32Dictionary {
4937ffe3c632Sopenharmony_ci @package
4938ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
4939ffe3c632Sopenharmony_ci}
4940ffe3c632Sopenharmony_ci
4941ffe3c632Sopenharmony_ci- (instancetype)init {
4942ffe3c632Sopenharmony_ci  return [self initWithUInt32s:NULL forKeys:NULL count:0];
4943ffe3c632Sopenharmony_ci}
4944ffe3c632Sopenharmony_ci
4945ffe3c632Sopenharmony_ci- (instancetype)initWithUInt32s:(const uint32_t [])values
4946ffe3c632Sopenharmony_ci                        forKeys:(const uint64_t [])keys
4947ffe3c632Sopenharmony_ci                          count:(NSUInteger)count {
4948ffe3c632Sopenharmony_ci  self = [super init];
4949ffe3c632Sopenharmony_ci  if (self) {
4950ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
4951ffe3c632Sopenharmony_ci    if (count && values && keys) {
4952ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
4953ffe3c632Sopenharmony_ci        [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
4954ffe3c632Sopenharmony_ci      }
4955ffe3c632Sopenharmony_ci    }
4956ffe3c632Sopenharmony_ci  }
4957ffe3c632Sopenharmony_ci  return self;
4958ffe3c632Sopenharmony_ci}
4959ffe3c632Sopenharmony_ci
4960ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBUInt64UInt32Dictionary *)dictionary {
4961ffe3c632Sopenharmony_ci  self = [self initWithUInt32s:NULL forKeys:NULL count:0];
4962ffe3c632Sopenharmony_ci  if (self) {
4963ffe3c632Sopenharmony_ci    if (dictionary) {
4964ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
4965ffe3c632Sopenharmony_ci    }
4966ffe3c632Sopenharmony_ci  }
4967ffe3c632Sopenharmony_ci  return self;
4968ffe3c632Sopenharmony_ci}
4969ffe3c632Sopenharmony_ci
4970ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
4971ffe3c632Sopenharmony_ci  #pragma unused(numItems)
4972ffe3c632Sopenharmony_ci  return [self initWithUInt32s:NULL forKeys:NULL count:0];
4973ffe3c632Sopenharmony_ci}
4974ffe3c632Sopenharmony_ci
4975ffe3c632Sopenharmony_ci- (void)dealloc {
4976ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
4977ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
4978ffe3c632Sopenharmony_ci           [self class], _autocreator);
4979ffe3c632Sopenharmony_ci  [_dictionary release];
4980ffe3c632Sopenharmony_ci  [super dealloc];
4981ffe3c632Sopenharmony_ci}
4982ffe3c632Sopenharmony_ci
4983ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
4984ffe3c632Sopenharmony_ci  return [[GPBUInt64UInt32Dictionary allocWithZone:zone] initWithDictionary:self];
4985ffe3c632Sopenharmony_ci}
4986ffe3c632Sopenharmony_ci
4987ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
4988ffe3c632Sopenharmony_ci  if (self == other) {
4989ffe3c632Sopenharmony_ci    return YES;
4990ffe3c632Sopenharmony_ci  }
4991ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBUInt64UInt32Dictionary class]]) {
4992ffe3c632Sopenharmony_ci    return NO;
4993ffe3c632Sopenharmony_ci  }
4994ffe3c632Sopenharmony_ci  GPBUInt64UInt32Dictionary *otherDictionary = other;
4995ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
4996ffe3c632Sopenharmony_ci}
4997ffe3c632Sopenharmony_ci
4998ffe3c632Sopenharmony_ci- (NSUInteger)hash {
4999ffe3c632Sopenharmony_ci  return _dictionary.count;
5000ffe3c632Sopenharmony_ci}
5001ffe3c632Sopenharmony_ci
5002ffe3c632Sopenharmony_ci- (NSString *)description {
5003ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
5004ffe3c632Sopenharmony_ci}
5005ffe3c632Sopenharmony_ci
5006ffe3c632Sopenharmony_ci- (NSUInteger)count {
5007ffe3c632Sopenharmony_ci  return _dictionary.count;
5008ffe3c632Sopenharmony_ci}
5009ffe3c632Sopenharmony_ci
5010ffe3c632Sopenharmony_ci- (void)enumerateKeysAndUInt32sUsingBlock:
5011ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(uint64_t key, uint32_t value, BOOL *stop))block {
5012ffe3c632Sopenharmony_ci  BOOL stop = NO;
5013ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
5014ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
5015ffe3c632Sopenharmony_ci  NSNumber *aKey;
5016ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
5017ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
5018ffe3c632Sopenharmony_ci    block([aKey unsignedLongLongValue], [aValue unsignedIntValue], &stop);
5019ffe3c632Sopenharmony_ci    if (stop) {
5020ffe3c632Sopenharmony_ci      break;
5021ffe3c632Sopenharmony_ci    }
5022ffe3c632Sopenharmony_ci  }
5023ffe3c632Sopenharmony_ci}
5024ffe3c632Sopenharmony_ci
5025ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
5026ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
5027ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
5028ffe3c632Sopenharmony_ci  if (count == 0) {
5029ffe3c632Sopenharmony_ci    return 0;
5030ffe3c632Sopenharmony_ci  }
5031ffe3c632Sopenharmony_ci
5032ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
5033ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
5034ffe3c632Sopenharmony_ci  size_t result = 0;
5035ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
5036ffe3c632Sopenharmony_ci  NSNumber *aKey;
5037ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
5038ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
5039ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
5040ffe3c632Sopenharmony_ci    msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
5041ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
5042ffe3c632Sopenharmony_ci  }
5043ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
5044ffe3c632Sopenharmony_ci  result += tagSize * count;
5045ffe3c632Sopenharmony_ci  return result;
5046ffe3c632Sopenharmony_ci}
5047ffe3c632Sopenharmony_ci
5048ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
5049ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
5050ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
5051ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
5052ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
5053ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
5054ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
5055ffe3c632Sopenharmony_ci  NSNumber *aKey;
5056ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
5057ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
5058ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
5059ffe3c632Sopenharmony_ci    // Write the size of the message.
5060ffe3c632Sopenharmony_ci    uint64_t unwrappedKey = [aKey unsignedLongLongValue];
5061ffe3c632Sopenharmony_ci    uint32_t unwrappedValue = [aValue unsignedIntValue];
5062ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
5063ffe3c632Sopenharmony_ci    msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
5064ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
5065ffe3c632Sopenharmony_ci    // Write the fields.
5066ffe3c632Sopenharmony_ci    WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
5067ffe3c632Sopenharmony_ci    WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
5068ffe3c632Sopenharmony_ci  }
5069ffe3c632Sopenharmony_ci}
5070ffe3c632Sopenharmony_ci
5071ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
5072ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
5073ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueUInt64)];
5074ffe3c632Sopenharmony_ci}
5075ffe3c632Sopenharmony_ci
5076ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
5077ffe3c632Sopenharmony_ci  [self enumerateKeysAndUInt32sUsingBlock:^(uint64_t key, uint32_t value, BOOL *stop) {
5078ffe3c632Sopenharmony_ci      #pragma unused(stop)
5079ffe3c632Sopenharmony_ci      block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%u", value]);
5080ffe3c632Sopenharmony_ci  }];
5081ffe3c632Sopenharmony_ci}
5082ffe3c632Sopenharmony_ci
5083ffe3c632Sopenharmony_ci- (BOOL)getUInt32:(nullable uint32_t *)value forKey:(uint64_t)key {
5084ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:@(key)];
5085ffe3c632Sopenharmony_ci  if (wrapped && value) {
5086ffe3c632Sopenharmony_ci    *value = [wrapped unsignedIntValue];
5087ffe3c632Sopenharmony_ci  }
5088ffe3c632Sopenharmony_ci  return (wrapped != NULL);
5089ffe3c632Sopenharmony_ci}
5090ffe3c632Sopenharmony_ci
5091ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBUInt64UInt32Dictionary *)otherDictionary {
5092ffe3c632Sopenharmony_ci  if (otherDictionary) {
5093ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
5094ffe3c632Sopenharmony_ci    if (_autocreator) {
5095ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
5096ffe3c632Sopenharmony_ci    }
5097ffe3c632Sopenharmony_ci  }
5098ffe3c632Sopenharmony_ci}
5099ffe3c632Sopenharmony_ci
5100ffe3c632Sopenharmony_ci- (void)setUInt32:(uint32_t)value forKey:(uint64_t)key {
5101ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:@(key)];
5102ffe3c632Sopenharmony_ci  if (_autocreator) {
5103ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
5104ffe3c632Sopenharmony_ci  }
5105ffe3c632Sopenharmony_ci}
5106ffe3c632Sopenharmony_ci
5107ffe3c632Sopenharmony_ci- (void)removeUInt32ForKey:(uint64_t)aKey {
5108ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:@(aKey)];
5109ffe3c632Sopenharmony_ci}
5110ffe3c632Sopenharmony_ci
5111ffe3c632Sopenharmony_ci- (void)removeAll {
5112ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
5113ffe3c632Sopenharmony_ci}
5114ffe3c632Sopenharmony_ci
5115ffe3c632Sopenharmony_ci@end
5116ffe3c632Sopenharmony_ci
5117ffe3c632Sopenharmony_ci#pragma mark - UInt64 -> Int32
5118ffe3c632Sopenharmony_ci
5119ffe3c632Sopenharmony_ci@implementation GPBUInt64Int32Dictionary {
5120ffe3c632Sopenharmony_ci @package
5121ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
5122ffe3c632Sopenharmony_ci}
5123ffe3c632Sopenharmony_ci
5124ffe3c632Sopenharmony_ci- (instancetype)init {
5125ffe3c632Sopenharmony_ci  return [self initWithInt32s:NULL forKeys:NULL count:0];
5126ffe3c632Sopenharmony_ci}
5127ffe3c632Sopenharmony_ci
5128ffe3c632Sopenharmony_ci- (instancetype)initWithInt32s:(const int32_t [])values
5129ffe3c632Sopenharmony_ci                       forKeys:(const uint64_t [])keys
5130ffe3c632Sopenharmony_ci                         count:(NSUInteger)count {
5131ffe3c632Sopenharmony_ci  self = [super init];
5132ffe3c632Sopenharmony_ci  if (self) {
5133ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
5134ffe3c632Sopenharmony_ci    if (count && values && keys) {
5135ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
5136ffe3c632Sopenharmony_ci        [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
5137ffe3c632Sopenharmony_ci      }
5138ffe3c632Sopenharmony_ci    }
5139ffe3c632Sopenharmony_ci  }
5140ffe3c632Sopenharmony_ci  return self;
5141ffe3c632Sopenharmony_ci}
5142ffe3c632Sopenharmony_ci
5143ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBUInt64Int32Dictionary *)dictionary {
5144ffe3c632Sopenharmony_ci  self = [self initWithInt32s:NULL forKeys:NULL count:0];
5145ffe3c632Sopenharmony_ci  if (self) {
5146ffe3c632Sopenharmony_ci    if (dictionary) {
5147ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
5148ffe3c632Sopenharmony_ci    }
5149ffe3c632Sopenharmony_ci  }
5150ffe3c632Sopenharmony_ci  return self;
5151ffe3c632Sopenharmony_ci}
5152ffe3c632Sopenharmony_ci
5153ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
5154ffe3c632Sopenharmony_ci  #pragma unused(numItems)
5155ffe3c632Sopenharmony_ci  return [self initWithInt32s:NULL forKeys:NULL count:0];
5156ffe3c632Sopenharmony_ci}
5157ffe3c632Sopenharmony_ci
5158ffe3c632Sopenharmony_ci- (void)dealloc {
5159ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
5160ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
5161ffe3c632Sopenharmony_ci           [self class], _autocreator);
5162ffe3c632Sopenharmony_ci  [_dictionary release];
5163ffe3c632Sopenharmony_ci  [super dealloc];
5164ffe3c632Sopenharmony_ci}
5165ffe3c632Sopenharmony_ci
5166ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
5167ffe3c632Sopenharmony_ci  return [[GPBUInt64Int32Dictionary allocWithZone:zone] initWithDictionary:self];
5168ffe3c632Sopenharmony_ci}
5169ffe3c632Sopenharmony_ci
5170ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
5171ffe3c632Sopenharmony_ci  if (self == other) {
5172ffe3c632Sopenharmony_ci    return YES;
5173ffe3c632Sopenharmony_ci  }
5174ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBUInt64Int32Dictionary class]]) {
5175ffe3c632Sopenharmony_ci    return NO;
5176ffe3c632Sopenharmony_ci  }
5177ffe3c632Sopenharmony_ci  GPBUInt64Int32Dictionary *otherDictionary = other;
5178ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
5179ffe3c632Sopenharmony_ci}
5180ffe3c632Sopenharmony_ci
5181ffe3c632Sopenharmony_ci- (NSUInteger)hash {
5182ffe3c632Sopenharmony_ci  return _dictionary.count;
5183ffe3c632Sopenharmony_ci}
5184ffe3c632Sopenharmony_ci
5185ffe3c632Sopenharmony_ci- (NSString *)description {
5186ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
5187ffe3c632Sopenharmony_ci}
5188ffe3c632Sopenharmony_ci
5189ffe3c632Sopenharmony_ci- (NSUInteger)count {
5190ffe3c632Sopenharmony_ci  return _dictionary.count;
5191ffe3c632Sopenharmony_ci}
5192ffe3c632Sopenharmony_ci
5193ffe3c632Sopenharmony_ci- (void)enumerateKeysAndInt32sUsingBlock:
5194ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(uint64_t key, int32_t value, BOOL *stop))block {
5195ffe3c632Sopenharmony_ci  BOOL stop = NO;
5196ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
5197ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
5198ffe3c632Sopenharmony_ci  NSNumber *aKey;
5199ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
5200ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
5201ffe3c632Sopenharmony_ci    block([aKey unsignedLongLongValue], [aValue intValue], &stop);
5202ffe3c632Sopenharmony_ci    if (stop) {
5203ffe3c632Sopenharmony_ci      break;
5204ffe3c632Sopenharmony_ci    }
5205ffe3c632Sopenharmony_ci  }
5206ffe3c632Sopenharmony_ci}
5207ffe3c632Sopenharmony_ci
5208ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
5209ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
5210ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
5211ffe3c632Sopenharmony_ci  if (count == 0) {
5212ffe3c632Sopenharmony_ci    return 0;
5213ffe3c632Sopenharmony_ci  }
5214ffe3c632Sopenharmony_ci
5215ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
5216ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
5217ffe3c632Sopenharmony_ci  size_t result = 0;
5218ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
5219ffe3c632Sopenharmony_ci  NSNumber *aKey;
5220ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
5221ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
5222ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
5223ffe3c632Sopenharmony_ci    msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
5224ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
5225ffe3c632Sopenharmony_ci  }
5226ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
5227ffe3c632Sopenharmony_ci  result += tagSize * count;
5228ffe3c632Sopenharmony_ci  return result;
5229ffe3c632Sopenharmony_ci}
5230ffe3c632Sopenharmony_ci
5231ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
5232ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
5233ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
5234ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
5235ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
5236ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
5237ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
5238ffe3c632Sopenharmony_ci  NSNumber *aKey;
5239ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
5240ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
5241ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
5242ffe3c632Sopenharmony_ci    // Write the size of the message.
5243ffe3c632Sopenharmony_ci    uint64_t unwrappedKey = [aKey unsignedLongLongValue];
5244ffe3c632Sopenharmony_ci    int32_t unwrappedValue = [aValue intValue];
5245ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
5246ffe3c632Sopenharmony_ci    msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
5247ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
5248ffe3c632Sopenharmony_ci    // Write the fields.
5249ffe3c632Sopenharmony_ci    WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
5250ffe3c632Sopenharmony_ci    WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
5251ffe3c632Sopenharmony_ci  }
5252ffe3c632Sopenharmony_ci}
5253ffe3c632Sopenharmony_ci
5254ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
5255ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
5256ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueUInt64)];
5257ffe3c632Sopenharmony_ci}
5258ffe3c632Sopenharmony_ci
5259ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
5260ffe3c632Sopenharmony_ci  [self enumerateKeysAndInt32sUsingBlock:^(uint64_t key, int32_t value, BOOL *stop) {
5261ffe3c632Sopenharmony_ci      #pragma unused(stop)
5262ffe3c632Sopenharmony_ci      block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%d", value]);
5263ffe3c632Sopenharmony_ci  }];
5264ffe3c632Sopenharmony_ci}
5265ffe3c632Sopenharmony_ci
5266ffe3c632Sopenharmony_ci- (BOOL)getInt32:(nullable int32_t *)value forKey:(uint64_t)key {
5267ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:@(key)];
5268ffe3c632Sopenharmony_ci  if (wrapped && value) {
5269ffe3c632Sopenharmony_ci    *value = [wrapped intValue];
5270ffe3c632Sopenharmony_ci  }
5271ffe3c632Sopenharmony_ci  return (wrapped != NULL);
5272ffe3c632Sopenharmony_ci}
5273ffe3c632Sopenharmony_ci
5274ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBUInt64Int32Dictionary *)otherDictionary {
5275ffe3c632Sopenharmony_ci  if (otherDictionary) {
5276ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
5277ffe3c632Sopenharmony_ci    if (_autocreator) {
5278ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
5279ffe3c632Sopenharmony_ci    }
5280ffe3c632Sopenharmony_ci  }
5281ffe3c632Sopenharmony_ci}
5282ffe3c632Sopenharmony_ci
5283ffe3c632Sopenharmony_ci- (void)setInt32:(int32_t)value forKey:(uint64_t)key {
5284ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:@(key)];
5285ffe3c632Sopenharmony_ci  if (_autocreator) {
5286ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
5287ffe3c632Sopenharmony_ci  }
5288ffe3c632Sopenharmony_ci}
5289ffe3c632Sopenharmony_ci
5290ffe3c632Sopenharmony_ci- (void)removeInt32ForKey:(uint64_t)aKey {
5291ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:@(aKey)];
5292ffe3c632Sopenharmony_ci}
5293ffe3c632Sopenharmony_ci
5294ffe3c632Sopenharmony_ci- (void)removeAll {
5295ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
5296ffe3c632Sopenharmony_ci}
5297ffe3c632Sopenharmony_ci
5298ffe3c632Sopenharmony_ci@end
5299ffe3c632Sopenharmony_ci
5300ffe3c632Sopenharmony_ci#pragma mark - UInt64 -> UInt64
5301ffe3c632Sopenharmony_ci
5302ffe3c632Sopenharmony_ci@implementation GPBUInt64UInt64Dictionary {
5303ffe3c632Sopenharmony_ci @package
5304ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
5305ffe3c632Sopenharmony_ci}
5306ffe3c632Sopenharmony_ci
5307ffe3c632Sopenharmony_ci- (instancetype)init {
5308ffe3c632Sopenharmony_ci  return [self initWithUInt64s:NULL forKeys:NULL count:0];
5309ffe3c632Sopenharmony_ci}
5310ffe3c632Sopenharmony_ci
5311ffe3c632Sopenharmony_ci- (instancetype)initWithUInt64s:(const uint64_t [])values
5312ffe3c632Sopenharmony_ci                        forKeys:(const uint64_t [])keys
5313ffe3c632Sopenharmony_ci                          count:(NSUInteger)count {
5314ffe3c632Sopenharmony_ci  self = [super init];
5315ffe3c632Sopenharmony_ci  if (self) {
5316ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
5317ffe3c632Sopenharmony_ci    if (count && values && keys) {
5318ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
5319ffe3c632Sopenharmony_ci        [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
5320ffe3c632Sopenharmony_ci      }
5321ffe3c632Sopenharmony_ci    }
5322ffe3c632Sopenharmony_ci  }
5323ffe3c632Sopenharmony_ci  return self;
5324ffe3c632Sopenharmony_ci}
5325ffe3c632Sopenharmony_ci
5326ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBUInt64UInt64Dictionary *)dictionary {
5327ffe3c632Sopenharmony_ci  self = [self initWithUInt64s:NULL forKeys:NULL count:0];
5328ffe3c632Sopenharmony_ci  if (self) {
5329ffe3c632Sopenharmony_ci    if (dictionary) {
5330ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
5331ffe3c632Sopenharmony_ci    }
5332ffe3c632Sopenharmony_ci  }
5333ffe3c632Sopenharmony_ci  return self;
5334ffe3c632Sopenharmony_ci}
5335ffe3c632Sopenharmony_ci
5336ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
5337ffe3c632Sopenharmony_ci  #pragma unused(numItems)
5338ffe3c632Sopenharmony_ci  return [self initWithUInt64s:NULL forKeys:NULL count:0];
5339ffe3c632Sopenharmony_ci}
5340ffe3c632Sopenharmony_ci
5341ffe3c632Sopenharmony_ci- (void)dealloc {
5342ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
5343ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
5344ffe3c632Sopenharmony_ci           [self class], _autocreator);
5345ffe3c632Sopenharmony_ci  [_dictionary release];
5346ffe3c632Sopenharmony_ci  [super dealloc];
5347ffe3c632Sopenharmony_ci}
5348ffe3c632Sopenharmony_ci
5349ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
5350ffe3c632Sopenharmony_ci  return [[GPBUInt64UInt64Dictionary allocWithZone:zone] initWithDictionary:self];
5351ffe3c632Sopenharmony_ci}
5352ffe3c632Sopenharmony_ci
5353ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
5354ffe3c632Sopenharmony_ci  if (self == other) {
5355ffe3c632Sopenharmony_ci    return YES;
5356ffe3c632Sopenharmony_ci  }
5357ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBUInt64UInt64Dictionary class]]) {
5358ffe3c632Sopenharmony_ci    return NO;
5359ffe3c632Sopenharmony_ci  }
5360ffe3c632Sopenharmony_ci  GPBUInt64UInt64Dictionary *otherDictionary = other;
5361ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
5362ffe3c632Sopenharmony_ci}
5363ffe3c632Sopenharmony_ci
5364ffe3c632Sopenharmony_ci- (NSUInteger)hash {
5365ffe3c632Sopenharmony_ci  return _dictionary.count;
5366ffe3c632Sopenharmony_ci}
5367ffe3c632Sopenharmony_ci
5368ffe3c632Sopenharmony_ci- (NSString *)description {
5369ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
5370ffe3c632Sopenharmony_ci}
5371ffe3c632Sopenharmony_ci
5372ffe3c632Sopenharmony_ci- (NSUInteger)count {
5373ffe3c632Sopenharmony_ci  return _dictionary.count;
5374ffe3c632Sopenharmony_ci}
5375ffe3c632Sopenharmony_ci
5376ffe3c632Sopenharmony_ci- (void)enumerateKeysAndUInt64sUsingBlock:
5377ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(uint64_t key, uint64_t value, BOOL *stop))block {
5378ffe3c632Sopenharmony_ci  BOOL stop = NO;
5379ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
5380ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
5381ffe3c632Sopenharmony_ci  NSNumber *aKey;
5382ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
5383ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
5384ffe3c632Sopenharmony_ci    block([aKey unsignedLongLongValue], [aValue unsignedLongLongValue], &stop);
5385ffe3c632Sopenharmony_ci    if (stop) {
5386ffe3c632Sopenharmony_ci      break;
5387ffe3c632Sopenharmony_ci    }
5388ffe3c632Sopenharmony_ci  }
5389ffe3c632Sopenharmony_ci}
5390ffe3c632Sopenharmony_ci
5391ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
5392ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
5393ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
5394ffe3c632Sopenharmony_ci  if (count == 0) {
5395ffe3c632Sopenharmony_ci    return 0;
5396ffe3c632Sopenharmony_ci  }
5397ffe3c632Sopenharmony_ci
5398ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
5399ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
5400ffe3c632Sopenharmony_ci  size_t result = 0;
5401ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
5402ffe3c632Sopenharmony_ci  NSNumber *aKey;
5403ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
5404ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
5405ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
5406ffe3c632Sopenharmony_ci    msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
5407ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
5408ffe3c632Sopenharmony_ci  }
5409ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
5410ffe3c632Sopenharmony_ci  result += tagSize * count;
5411ffe3c632Sopenharmony_ci  return result;
5412ffe3c632Sopenharmony_ci}
5413ffe3c632Sopenharmony_ci
5414ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
5415ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
5416ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
5417ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
5418ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
5419ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
5420ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
5421ffe3c632Sopenharmony_ci  NSNumber *aKey;
5422ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
5423ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
5424ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
5425ffe3c632Sopenharmony_ci    // Write the size of the message.
5426ffe3c632Sopenharmony_ci    uint64_t unwrappedKey = [aKey unsignedLongLongValue];
5427ffe3c632Sopenharmony_ci    uint64_t unwrappedValue = [aValue unsignedLongLongValue];
5428ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
5429ffe3c632Sopenharmony_ci    msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
5430ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
5431ffe3c632Sopenharmony_ci    // Write the fields.
5432ffe3c632Sopenharmony_ci    WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
5433ffe3c632Sopenharmony_ci    WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
5434ffe3c632Sopenharmony_ci  }
5435ffe3c632Sopenharmony_ci}
5436ffe3c632Sopenharmony_ci
5437ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
5438ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
5439ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueUInt64)];
5440ffe3c632Sopenharmony_ci}
5441ffe3c632Sopenharmony_ci
5442ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
5443ffe3c632Sopenharmony_ci  [self enumerateKeysAndUInt64sUsingBlock:^(uint64_t key, uint64_t value, BOOL *stop) {
5444ffe3c632Sopenharmony_ci      #pragma unused(stop)
5445ffe3c632Sopenharmony_ci      block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%llu", value]);
5446ffe3c632Sopenharmony_ci  }];
5447ffe3c632Sopenharmony_ci}
5448ffe3c632Sopenharmony_ci
5449ffe3c632Sopenharmony_ci- (BOOL)getUInt64:(nullable uint64_t *)value forKey:(uint64_t)key {
5450ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:@(key)];
5451ffe3c632Sopenharmony_ci  if (wrapped && value) {
5452ffe3c632Sopenharmony_ci    *value = [wrapped unsignedLongLongValue];
5453ffe3c632Sopenharmony_ci  }
5454ffe3c632Sopenharmony_ci  return (wrapped != NULL);
5455ffe3c632Sopenharmony_ci}
5456ffe3c632Sopenharmony_ci
5457ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBUInt64UInt64Dictionary *)otherDictionary {
5458ffe3c632Sopenharmony_ci  if (otherDictionary) {
5459ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
5460ffe3c632Sopenharmony_ci    if (_autocreator) {
5461ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
5462ffe3c632Sopenharmony_ci    }
5463ffe3c632Sopenharmony_ci  }
5464ffe3c632Sopenharmony_ci}
5465ffe3c632Sopenharmony_ci
5466ffe3c632Sopenharmony_ci- (void)setUInt64:(uint64_t)value forKey:(uint64_t)key {
5467ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:@(key)];
5468ffe3c632Sopenharmony_ci  if (_autocreator) {
5469ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
5470ffe3c632Sopenharmony_ci  }
5471ffe3c632Sopenharmony_ci}
5472ffe3c632Sopenharmony_ci
5473ffe3c632Sopenharmony_ci- (void)removeUInt64ForKey:(uint64_t)aKey {
5474ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:@(aKey)];
5475ffe3c632Sopenharmony_ci}
5476ffe3c632Sopenharmony_ci
5477ffe3c632Sopenharmony_ci- (void)removeAll {
5478ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
5479ffe3c632Sopenharmony_ci}
5480ffe3c632Sopenharmony_ci
5481ffe3c632Sopenharmony_ci@end
5482ffe3c632Sopenharmony_ci
5483ffe3c632Sopenharmony_ci#pragma mark - UInt64 -> Int64
5484ffe3c632Sopenharmony_ci
5485ffe3c632Sopenharmony_ci@implementation GPBUInt64Int64Dictionary {
5486ffe3c632Sopenharmony_ci @package
5487ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
5488ffe3c632Sopenharmony_ci}
5489ffe3c632Sopenharmony_ci
5490ffe3c632Sopenharmony_ci- (instancetype)init {
5491ffe3c632Sopenharmony_ci  return [self initWithInt64s:NULL forKeys:NULL count:0];
5492ffe3c632Sopenharmony_ci}
5493ffe3c632Sopenharmony_ci
5494ffe3c632Sopenharmony_ci- (instancetype)initWithInt64s:(const int64_t [])values
5495ffe3c632Sopenharmony_ci                       forKeys:(const uint64_t [])keys
5496ffe3c632Sopenharmony_ci                         count:(NSUInteger)count {
5497ffe3c632Sopenharmony_ci  self = [super init];
5498ffe3c632Sopenharmony_ci  if (self) {
5499ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
5500ffe3c632Sopenharmony_ci    if (count && values && keys) {
5501ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
5502ffe3c632Sopenharmony_ci        [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
5503ffe3c632Sopenharmony_ci      }
5504ffe3c632Sopenharmony_ci    }
5505ffe3c632Sopenharmony_ci  }
5506ffe3c632Sopenharmony_ci  return self;
5507ffe3c632Sopenharmony_ci}
5508ffe3c632Sopenharmony_ci
5509ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBUInt64Int64Dictionary *)dictionary {
5510ffe3c632Sopenharmony_ci  self = [self initWithInt64s:NULL forKeys:NULL count:0];
5511ffe3c632Sopenharmony_ci  if (self) {
5512ffe3c632Sopenharmony_ci    if (dictionary) {
5513ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
5514ffe3c632Sopenharmony_ci    }
5515ffe3c632Sopenharmony_ci  }
5516ffe3c632Sopenharmony_ci  return self;
5517ffe3c632Sopenharmony_ci}
5518ffe3c632Sopenharmony_ci
5519ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
5520ffe3c632Sopenharmony_ci  #pragma unused(numItems)
5521ffe3c632Sopenharmony_ci  return [self initWithInt64s:NULL forKeys:NULL count:0];
5522ffe3c632Sopenharmony_ci}
5523ffe3c632Sopenharmony_ci
5524ffe3c632Sopenharmony_ci- (void)dealloc {
5525ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
5526ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
5527ffe3c632Sopenharmony_ci           [self class], _autocreator);
5528ffe3c632Sopenharmony_ci  [_dictionary release];
5529ffe3c632Sopenharmony_ci  [super dealloc];
5530ffe3c632Sopenharmony_ci}
5531ffe3c632Sopenharmony_ci
5532ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
5533ffe3c632Sopenharmony_ci  return [[GPBUInt64Int64Dictionary allocWithZone:zone] initWithDictionary:self];
5534ffe3c632Sopenharmony_ci}
5535ffe3c632Sopenharmony_ci
5536ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
5537ffe3c632Sopenharmony_ci  if (self == other) {
5538ffe3c632Sopenharmony_ci    return YES;
5539ffe3c632Sopenharmony_ci  }
5540ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBUInt64Int64Dictionary class]]) {
5541ffe3c632Sopenharmony_ci    return NO;
5542ffe3c632Sopenharmony_ci  }
5543ffe3c632Sopenharmony_ci  GPBUInt64Int64Dictionary *otherDictionary = other;
5544ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
5545ffe3c632Sopenharmony_ci}
5546ffe3c632Sopenharmony_ci
5547ffe3c632Sopenharmony_ci- (NSUInteger)hash {
5548ffe3c632Sopenharmony_ci  return _dictionary.count;
5549ffe3c632Sopenharmony_ci}
5550ffe3c632Sopenharmony_ci
5551ffe3c632Sopenharmony_ci- (NSString *)description {
5552ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
5553ffe3c632Sopenharmony_ci}
5554ffe3c632Sopenharmony_ci
5555ffe3c632Sopenharmony_ci- (NSUInteger)count {
5556ffe3c632Sopenharmony_ci  return _dictionary.count;
5557ffe3c632Sopenharmony_ci}
5558ffe3c632Sopenharmony_ci
5559ffe3c632Sopenharmony_ci- (void)enumerateKeysAndInt64sUsingBlock:
5560ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(uint64_t key, int64_t value, BOOL *stop))block {
5561ffe3c632Sopenharmony_ci  BOOL stop = NO;
5562ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
5563ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
5564ffe3c632Sopenharmony_ci  NSNumber *aKey;
5565ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
5566ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
5567ffe3c632Sopenharmony_ci    block([aKey unsignedLongLongValue], [aValue longLongValue], &stop);
5568ffe3c632Sopenharmony_ci    if (stop) {
5569ffe3c632Sopenharmony_ci      break;
5570ffe3c632Sopenharmony_ci    }
5571ffe3c632Sopenharmony_ci  }
5572ffe3c632Sopenharmony_ci}
5573ffe3c632Sopenharmony_ci
5574ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
5575ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
5576ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
5577ffe3c632Sopenharmony_ci  if (count == 0) {
5578ffe3c632Sopenharmony_ci    return 0;
5579ffe3c632Sopenharmony_ci  }
5580ffe3c632Sopenharmony_ci
5581ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
5582ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
5583ffe3c632Sopenharmony_ci  size_t result = 0;
5584ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
5585ffe3c632Sopenharmony_ci  NSNumber *aKey;
5586ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
5587ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
5588ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
5589ffe3c632Sopenharmony_ci    msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
5590ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
5591ffe3c632Sopenharmony_ci  }
5592ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
5593ffe3c632Sopenharmony_ci  result += tagSize * count;
5594ffe3c632Sopenharmony_ci  return result;
5595ffe3c632Sopenharmony_ci}
5596ffe3c632Sopenharmony_ci
5597ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
5598ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
5599ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
5600ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
5601ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
5602ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
5603ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
5604ffe3c632Sopenharmony_ci  NSNumber *aKey;
5605ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
5606ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
5607ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
5608ffe3c632Sopenharmony_ci    // Write the size of the message.
5609ffe3c632Sopenharmony_ci    uint64_t unwrappedKey = [aKey unsignedLongLongValue];
5610ffe3c632Sopenharmony_ci    int64_t unwrappedValue = [aValue longLongValue];
5611ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
5612ffe3c632Sopenharmony_ci    msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
5613ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
5614ffe3c632Sopenharmony_ci    // Write the fields.
5615ffe3c632Sopenharmony_ci    WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
5616ffe3c632Sopenharmony_ci    WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
5617ffe3c632Sopenharmony_ci  }
5618ffe3c632Sopenharmony_ci}
5619ffe3c632Sopenharmony_ci
5620ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
5621ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
5622ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueUInt64)];
5623ffe3c632Sopenharmony_ci}
5624ffe3c632Sopenharmony_ci
5625ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
5626ffe3c632Sopenharmony_ci  [self enumerateKeysAndInt64sUsingBlock:^(uint64_t key, int64_t value, BOOL *stop) {
5627ffe3c632Sopenharmony_ci      #pragma unused(stop)
5628ffe3c632Sopenharmony_ci      block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%lld", value]);
5629ffe3c632Sopenharmony_ci  }];
5630ffe3c632Sopenharmony_ci}
5631ffe3c632Sopenharmony_ci
5632ffe3c632Sopenharmony_ci- (BOOL)getInt64:(nullable int64_t *)value forKey:(uint64_t)key {
5633ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:@(key)];
5634ffe3c632Sopenharmony_ci  if (wrapped && value) {
5635ffe3c632Sopenharmony_ci    *value = [wrapped longLongValue];
5636ffe3c632Sopenharmony_ci  }
5637ffe3c632Sopenharmony_ci  return (wrapped != NULL);
5638ffe3c632Sopenharmony_ci}
5639ffe3c632Sopenharmony_ci
5640ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBUInt64Int64Dictionary *)otherDictionary {
5641ffe3c632Sopenharmony_ci  if (otherDictionary) {
5642ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
5643ffe3c632Sopenharmony_ci    if (_autocreator) {
5644ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
5645ffe3c632Sopenharmony_ci    }
5646ffe3c632Sopenharmony_ci  }
5647ffe3c632Sopenharmony_ci}
5648ffe3c632Sopenharmony_ci
5649ffe3c632Sopenharmony_ci- (void)setInt64:(int64_t)value forKey:(uint64_t)key {
5650ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:@(key)];
5651ffe3c632Sopenharmony_ci  if (_autocreator) {
5652ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
5653ffe3c632Sopenharmony_ci  }
5654ffe3c632Sopenharmony_ci}
5655ffe3c632Sopenharmony_ci
5656ffe3c632Sopenharmony_ci- (void)removeInt64ForKey:(uint64_t)aKey {
5657ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:@(aKey)];
5658ffe3c632Sopenharmony_ci}
5659ffe3c632Sopenharmony_ci
5660ffe3c632Sopenharmony_ci- (void)removeAll {
5661ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
5662ffe3c632Sopenharmony_ci}
5663ffe3c632Sopenharmony_ci
5664ffe3c632Sopenharmony_ci@end
5665ffe3c632Sopenharmony_ci
5666ffe3c632Sopenharmony_ci#pragma mark - UInt64 -> Bool
5667ffe3c632Sopenharmony_ci
5668ffe3c632Sopenharmony_ci@implementation GPBUInt64BoolDictionary {
5669ffe3c632Sopenharmony_ci @package
5670ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
5671ffe3c632Sopenharmony_ci}
5672ffe3c632Sopenharmony_ci
5673ffe3c632Sopenharmony_ci- (instancetype)init {
5674ffe3c632Sopenharmony_ci  return [self initWithBools:NULL forKeys:NULL count:0];
5675ffe3c632Sopenharmony_ci}
5676ffe3c632Sopenharmony_ci
5677ffe3c632Sopenharmony_ci- (instancetype)initWithBools:(const BOOL [])values
5678ffe3c632Sopenharmony_ci                      forKeys:(const uint64_t [])keys
5679ffe3c632Sopenharmony_ci                        count:(NSUInteger)count {
5680ffe3c632Sopenharmony_ci  self = [super init];
5681ffe3c632Sopenharmony_ci  if (self) {
5682ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
5683ffe3c632Sopenharmony_ci    if (count && values && keys) {
5684ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
5685ffe3c632Sopenharmony_ci        [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
5686ffe3c632Sopenharmony_ci      }
5687ffe3c632Sopenharmony_ci    }
5688ffe3c632Sopenharmony_ci  }
5689ffe3c632Sopenharmony_ci  return self;
5690ffe3c632Sopenharmony_ci}
5691ffe3c632Sopenharmony_ci
5692ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBUInt64BoolDictionary *)dictionary {
5693ffe3c632Sopenharmony_ci  self = [self initWithBools:NULL forKeys:NULL count:0];
5694ffe3c632Sopenharmony_ci  if (self) {
5695ffe3c632Sopenharmony_ci    if (dictionary) {
5696ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
5697ffe3c632Sopenharmony_ci    }
5698ffe3c632Sopenharmony_ci  }
5699ffe3c632Sopenharmony_ci  return self;
5700ffe3c632Sopenharmony_ci}
5701ffe3c632Sopenharmony_ci
5702ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
5703ffe3c632Sopenharmony_ci  #pragma unused(numItems)
5704ffe3c632Sopenharmony_ci  return [self initWithBools:NULL forKeys:NULL count:0];
5705ffe3c632Sopenharmony_ci}
5706ffe3c632Sopenharmony_ci
5707ffe3c632Sopenharmony_ci- (void)dealloc {
5708ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
5709ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
5710ffe3c632Sopenharmony_ci           [self class], _autocreator);
5711ffe3c632Sopenharmony_ci  [_dictionary release];
5712ffe3c632Sopenharmony_ci  [super dealloc];
5713ffe3c632Sopenharmony_ci}
5714ffe3c632Sopenharmony_ci
5715ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
5716ffe3c632Sopenharmony_ci  return [[GPBUInt64BoolDictionary allocWithZone:zone] initWithDictionary:self];
5717ffe3c632Sopenharmony_ci}
5718ffe3c632Sopenharmony_ci
5719ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
5720ffe3c632Sopenharmony_ci  if (self == other) {
5721ffe3c632Sopenharmony_ci    return YES;
5722ffe3c632Sopenharmony_ci  }
5723ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBUInt64BoolDictionary class]]) {
5724ffe3c632Sopenharmony_ci    return NO;
5725ffe3c632Sopenharmony_ci  }
5726ffe3c632Sopenharmony_ci  GPBUInt64BoolDictionary *otherDictionary = other;
5727ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
5728ffe3c632Sopenharmony_ci}
5729ffe3c632Sopenharmony_ci
5730ffe3c632Sopenharmony_ci- (NSUInteger)hash {
5731ffe3c632Sopenharmony_ci  return _dictionary.count;
5732ffe3c632Sopenharmony_ci}
5733ffe3c632Sopenharmony_ci
5734ffe3c632Sopenharmony_ci- (NSString *)description {
5735ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
5736ffe3c632Sopenharmony_ci}
5737ffe3c632Sopenharmony_ci
5738ffe3c632Sopenharmony_ci- (NSUInteger)count {
5739ffe3c632Sopenharmony_ci  return _dictionary.count;
5740ffe3c632Sopenharmony_ci}
5741ffe3c632Sopenharmony_ci
5742ffe3c632Sopenharmony_ci- (void)enumerateKeysAndBoolsUsingBlock:
5743ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(uint64_t key, BOOL value, BOOL *stop))block {
5744ffe3c632Sopenharmony_ci  BOOL stop = NO;
5745ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
5746ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
5747ffe3c632Sopenharmony_ci  NSNumber *aKey;
5748ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
5749ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
5750ffe3c632Sopenharmony_ci    block([aKey unsignedLongLongValue], [aValue boolValue], &stop);
5751ffe3c632Sopenharmony_ci    if (stop) {
5752ffe3c632Sopenharmony_ci      break;
5753ffe3c632Sopenharmony_ci    }
5754ffe3c632Sopenharmony_ci  }
5755ffe3c632Sopenharmony_ci}
5756ffe3c632Sopenharmony_ci
5757ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
5758ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
5759ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
5760ffe3c632Sopenharmony_ci  if (count == 0) {
5761ffe3c632Sopenharmony_ci    return 0;
5762ffe3c632Sopenharmony_ci  }
5763ffe3c632Sopenharmony_ci
5764ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
5765ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
5766ffe3c632Sopenharmony_ci  size_t result = 0;
5767ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
5768ffe3c632Sopenharmony_ci  NSNumber *aKey;
5769ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
5770ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
5771ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
5772ffe3c632Sopenharmony_ci    msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
5773ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
5774ffe3c632Sopenharmony_ci  }
5775ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
5776ffe3c632Sopenharmony_ci  result += tagSize * count;
5777ffe3c632Sopenharmony_ci  return result;
5778ffe3c632Sopenharmony_ci}
5779ffe3c632Sopenharmony_ci
5780ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
5781ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
5782ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
5783ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
5784ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
5785ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
5786ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
5787ffe3c632Sopenharmony_ci  NSNumber *aKey;
5788ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
5789ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
5790ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
5791ffe3c632Sopenharmony_ci    // Write the size of the message.
5792ffe3c632Sopenharmony_ci    uint64_t unwrappedKey = [aKey unsignedLongLongValue];
5793ffe3c632Sopenharmony_ci    BOOL unwrappedValue = [aValue boolValue];
5794ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
5795ffe3c632Sopenharmony_ci    msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
5796ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
5797ffe3c632Sopenharmony_ci    // Write the fields.
5798ffe3c632Sopenharmony_ci    WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
5799ffe3c632Sopenharmony_ci    WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
5800ffe3c632Sopenharmony_ci  }
5801ffe3c632Sopenharmony_ci}
5802ffe3c632Sopenharmony_ci
5803ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
5804ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
5805ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueBool) forKey:@(key->valueUInt64)];
5806ffe3c632Sopenharmony_ci}
5807ffe3c632Sopenharmony_ci
5808ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
5809ffe3c632Sopenharmony_ci  [self enumerateKeysAndBoolsUsingBlock:^(uint64_t key, BOOL value, BOOL *stop) {
5810ffe3c632Sopenharmony_ci      #pragma unused(stop)
5811ffe3c632Sopenharmony_ci      block([NSString stringWithFormat:@"%llu", key], (value ? @"true" : @"false"));
5812ffe3c632Sopenharmony_ci  }];
5813ffe3c632Sopenharmony_ci}
5814ffe3c632Sopenharmony_ci
5815ffe3c632Sopenharmony_ci- (BOOL)getBool:(nullable BOOL *)value forKey:(uint64_t)key {
5816ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:@(key)];
5817ffe3c632Sopenharmony_ci  if (wrapped && value) {
5818ffe3c632Sopenharmony_ci    *value = [wrapped boolValue];
5819ffe3c632Sopenharmony_ci  }
5820ffe3c632Sopenharmony_ci  return (wrapped != NULL);
5821ffe3c632Sopenharmony_ci}
5822ffe3c632Sopenharmony_ci
5823ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBUInt64BoolDictionary *)otherDictionary {
5824ffe3c632Sopenharmony_ci  if (otherDictionary) {
5825ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
5826ffe3c632Sopenharmony_ci    if (_autocreator) {
5827ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
5828ffe3c632Sopenharmony_ci    }
5829ffe3c632Sopenharmony_ci  }
5830ffe3c632Sopenharmony_ci}
5831ffe3c632Sopenharmony_ci
5832ffe3c632Sopenharmony_ci- (void)setBool:(BOOL)value forKey:(uint64_t)key {
5833ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:@(key)];
5834ffe3c632Sopenharmony_ci  if (_autocreator) {
5835ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
5836ffe3c632Sopenharmony_ci  }
5837ffe3c632Sopenharmony_ci}
5838ffe3c632Sopenharmony_ci
5839ffe3c632Sopenharmony_ci- (void)removeBoolForKey:(uint64_t)aKey {
5840ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:@(aKey)];
5841ffe3c632Sopenharmony_ci}
5842ffe3c632Sopenharmony_ci
5843ffe3c632Sopenharmony_ci- (void)removeAll {
5844ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
5845ffe3c632Sopenharmony_ci}
5846ffe3c632Sopenharmony_ci
5847ffe3c632Sopenharmony_ci@end
5848ffe3c632Sopenharmony_ci
5849ffe3c632Sopenharmony_ci#pragma mark - UInt64 -> Float
5850ffe3c632Sopenharmony_ci
5851ffe3c632Sopenharmony_ci@implementation GPBUInt64FloatDictionary {
5852ffe3c632Sopenharmony_ci @package
5853ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
5854ffe3c632Sopenharmony_ci}
5855ffe3c632Sopenharmony_ci
5856ffe3c632Sopenharmony_ci- (instancetype)init {
5857ffe3c632Sopenharmony_ci  return [self initWithFloats:NULL forKeys:NULL count:0];
5858ffe3c632Sopenharmony_ci}
5859ffe3c632Sopenharmony_ci
5860ffe3c632Sopenharmony_ci- (instancetype)initWithFloats:(const float [])values
5861ffe3c632Sopenharmony_ci                       forKeys:(const uint64_t [])keys
5862ffe3c632Sopenharmony_ci                         count:(NSUInteger)count {
5863ffe3c632Sopenharmony_ci  self = [super init];
5864ffe3c632Sopenharmony_ci  if (self) {
5865ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
5866ffe3c632Sopenharmony_ci    if (count && values && keys) {
5867ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
5868ffe3c632Sopenharmony_ci        [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
5869ffe3c632Sopenharmony_ci      }
5870ffe3c632Sopenharmony_ci    }
5871ffe3c632Sopenharmony_ci  }
5872ffe3c632Sopenharmony_ci  return self;
5873ffe3c632Sopenharmony_ci}
5874ffe3c632Sopenharmony_ci
5875ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBUInt64FloatDictionary *)dictionary {
5876ffe3c632Sopenharmony_ci  self = [self initWithFloats:NULL forKeys:NULL count:0];
5877ffe3c632Sopenharmony_ci  if (self) {
5878ffe3c632Sopenharmony_ci    if (dictionary) {
5879ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
5880ffe3c632Sopenharmony_ci    }
5881ffe3c632Sopenharmony_ci  }
5882ffe3c632Sopenharmony_ci  return self;
5883ffe3c632Sopenharmony_ci}
5884ffe3c632Sopenharmony_ci
5885ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
5886ffe3c632Sopenharmony_ci  #pragma unused(numItems)
5887ffe3c632Sopenharmony_ci  return [self initWithFloats:NULL forKeys:NULL count:0];
5888ffe3c632Sopenharmony_ci}
5889ffe3c632Sopenharmony_ci
5890ffe3c632Sopenharmony_ci- (void)dealloc {
5891ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
5892ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
5893ffe3c632Sopenharmony_ci           [self class], _autocreator);
5894ffe3c632Sopenharmony_ci  [_dictionary release];
5895ffe3c632Sopenharmony_ci  [super dealloc];
5896ffe3c632Sopenharmony_ci}
5897ffe3c632Sopenharmony_ci
5898ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
5899ffe3c632Sopenharmony_ci  return [[GPBUInt64FloatDictionary allocWithZone:zone] initWithDictionary:self];
5900ffe3c632Sopenharmony_ci}
5901ffe3c632Sopenharmony_ci
5902ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
5903ffe3c632Sopenharmony_ci  if (self == other) {
5904ffe3c632Sopenharmony_ci    return YES;
5905ffe3c632Sopenharmony_ci  }
5906ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBUInt64FloatDictionary class]]) {
5907ffe3c632Sopenharmony_ci    return NO;
5908ffe3c632Sopenharmony_ci  }
5909ffe3c632Sopenharmony_ci  GPBUInt64FloatDictionary *otherDictionary = other;
5910ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
5911ffe3c632Sopenharmony_ci}
5912ffe3c632Sopenharmony_ci
5913ffe3c632Sopenharmony_ci- (NSUInteger)hash {
5914ffe3c632Sopenharmony_ci  return _dictionary.count;
5915ffe3c632Sopenharmony_ci}
5916ffe3c632Sopenharmony_ci
5917ffe3c632Sopenharmony_ci- (NSString *)description {
5918ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
5919ffe3c632Sopenharmony_ci}
5920ffe3c632Sopenharmony_ci
5921ffe3c632Sopenharmony_ci- (NSUInteger)count {
5922ffe3c632Sopenharmony_ci  return _dictionary.count;
5923ffe3c632Sopenharmony_ci}
5924ffe3c632Sopenharmony_ci
5925ffe3c632Sopenharmony_ci- (void)enumerateKeysAndFloatsUsingBlock:
5926ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(uint64_t key, float value, BOOL *stop))block {
5927ffe3c632Sopenharmony_ci  BOOL stop = NO;
5928ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
5929ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
5930ffe3c632Sopenharmony_ci  NSNumber *aKey;
5931ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
5932ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
5933ffe3c632Sopenharmony_ci    block([aKey unsignedLongLongValue], [aValue floatValue], &stop);
5934ffe3c632Sopenharmony_ci    if (stop) {
5935ffe3c632Sopenharmony_ci      break;
5936ffe3c632Sopenharmony_ci    }
5937ffe3c632Sopenharmony_ci  }
5938ffe3c632Sopenharmony_ci}
5939ffe3c632Sopenharmony_ci
5940ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
5941ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
5942ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
5943ffe3c632Sopenharmony_ci  if (count == 0) {
5944ffe3c632Sopenharmony_ci    return 0;
5945ffe3c632Sopenharmony_ci  }
5946ffe3c632Sopenharmony_ci
5947ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
5948ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
5949ffe3c632Sopenharmony_ci  size_t result = 0;
5950ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
5951ffe3c632Sopenharmony_ci  NSNumber *aKey;
5952ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
5953ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
5954ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
5955ffe3c632Sopenharmony_ci    msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
5956ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
5957ffe3c632Sopenharmony_ci  }
5958ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
5959ffe3c632Sopenharmony_ci  result += tagSize * count;
5960ffe3c632Sopenharmony_ci  return result;
5961ffe3c632Sopenharmony_ci}
5962ffe3c632Sopenharmony_ci
5963ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
5964ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
5965ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
5966ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
5967ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
5968ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
5969ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
5970ffe3c632Sopenharmony_ci  NSNumber *aKey;
5971ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
5972ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
5973ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
5974ffe3c632Sopenharmony_ci    // Write the size of the message.
5975ffe3c632Sopenharmony_ci    uint64_t unwrappedKey = [aKey unsignedLongLongValue];
5976ffe3c632Sopenharmony_ci    float unwrappedValue = [aValue floatValue];
5977ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
5978ffe3c632Sopenharmony_ci    msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
5979ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
5980ffe3c632Sopenharmony_ci    // Write the fields.
5981ffe3c632Sopenharmony_ci    WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
5982ffe3c632Sopenharmony_ci    WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
5983ffe3c632Sopenharmony_ci  }
5984ffe3c632Sopenharmony_ci}
5985ffe3c632Sopenharmony_ci
5986ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
5987ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
5988ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueUInt64)];
5989ffe3c632Sopenharmony_ci}
5990ffe3c632Sopenharmony_ci
5991ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
5992ffe3c632Sopenharmony_ci  [self enumerateKeysAndFloatsUsingBlock:^(uint64_t key, float value, BOOL *stop) {
5993ffe3c632Sopenharmony_ci      #pragma unused(stop)
5994ffe3c632Sopenharmony_ci      block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
5995ffe3c632Sopenharmony_ci  }];
5996ffe3c632Sopenharmony_ci}
5997ffe3c632Sopenharmony_ci
5998ffe3c632Sopenharmony_ci- (BOOL)getFloat:(nullable float *)value forKey:(uint64_t)key {
5999ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:@(key)];
6000ffe3c632Sopenharmony_ci  if (wrapped && value) {
6001ffe3c632Sopenharmony_ci    *value = [wrapped floatValue];
6002ffe3c632Sopenharmony_ci  }
6003ffe3c632Sopenharmony_ci  return (wrapped != NULL);
6004ffe3c632Sopenharmony_ci}
6005ffe3c632Sopenharmony_ci
6006ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBUInt64FloatDictionary *)otherDictionary {
6007ffe3c632Sopenharmony_ci  if (otherDictionary) {
6008ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
6009ffe3c632Sopenharmony_ci    if (_autocreator) {
6010ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
6011ffe3c632Sopenharmony_ci    }
6012ffe3c632Sopenharmony_ci  }
6013ffe3c632Sopenharmony_ci}
6014ffe3c632Sopenharmony_ci
6015ffe3c632Sopenharmony_ci- (void)setFloat:(float)value forKey:(uint64_t)key {
6016ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:@(key)];
6017ffe3c632Sopenharmony_ci  if (_autocreator) {
6018ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
6019ffe3c632Sopenharmony_ci  }
6020ffe3c632Sopenharmony_ci}
6021ffe3c632Sopenharmony_ci
6022ffe3c632Sopenharmony_ci- (void)removeFloatForKey:(uint64_t)aKey {
6023ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:@(aKey)];
6024ffe3c632Sopenharmony_ci}
6025ffe3c632Sopenharmony_ci
6026ffe3c632Sopenharmony_ci- (void)removeAll {
6027ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
6028ffe3c632Sopenharmony_ci}
6029ffe3c632Sopenharmony_ci
6030ffe3c632Sopenharmony_ci@end
6031ffe3c632Sopenharmony_ci
6032ffe3c632Sopenharmony_ci#pragma mark - UInt64 -> Double
6033ffe3c632Sopenharmony_ci
6034ffe3c632Sopenharmony_ci@implementation GPBUInt64DoubleDictionary {
6035ffe3c632Sopenharmony_ci @package
6036ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
6037ffe3c632Sopenharmony_ci}
6038ffe3c632Sopenharmony_ci
6039ffe3c632Sopenharmony_ci- (instancetype)init {
6040ffe3c632Sopenharmony_ci  return [self initWithDoubles:NULL forKeys:NULL count:0];
6041ffe3c632Sopenharmony_ci}
6042ffe3c632Sopenharmony_ci
6043ffe3c632Sopenharmony_ci- (instancetype)initWithDoubles:(const double [])values
6044ffe3c632Sopenharmony_ci                        forKeys:(const uint64_t [])keys
6045ffe3c632Sopenharmony_ci                          count:(NSUInteger)count {
6046ffe3c632Sopenharmony_ci  self = [super init];
6047ffe3c632Sopenharmony_ci  if (self) {
6048ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
6049ffe3c632Sopenharmony_ci    if (count && values && keys) {
6050ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
6051ffe3c632Sopenharmony_ci        [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
6052ffe3c632Sopenharmony_ci      }
6053ffe3c632Sopenharmony_ci    }
6054ffe3c632Sopenharmony_ci  }
6055ffe3c632Sopenharmony_ci  return self;
6056ffe3c632Sopenharmony_ci}
6057ffe3c632Sopenharmony_ci
6058ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBUInt64DoubleDictionary *)dictionary {
6059ffe3c632Sopenharmony_ci  self = [self initWithDoubles:NULL forKeys:NULL count:0];
6060ffe3c632Sopenharmony_ci  if (self) {
6061ffe3c632Sopenharmony_ci    if (dictionary) {
6062ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
6063ffe3c632Sopenharmony_ci    }
6064ffe3c632Sopenharmony_ci  }
6065ffe3c632Sopenharmony_ci  return self;
6066ffe3c632Sopenharmony_ci}
6067ffe3c632Sopenharmony_ci
6068ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
6069ffe3c632Sopenharmony_ci  #pragma unused(numItems)
6070ffe3c632Sopenharmony_ci  return [self initWithDoubles:NULL forKeys:NULL count:0];
6071ffe3c632Sopenharmony_ci}
6072ffe3c632Sopenharmony_ci
6073ffe3c632Sopenharmony_ci- (void)dealloc {
6074ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
6075ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
6076ffe3c632Sopenharmony_ci           [self class], _autocreator);
6077ffe3c632Sopenharmony_ci  [_dictionary release];
6078ffe3c632Sopenharmony_ci  [super dealloc];
6079ffe3c632Sopenharmony_ci}
6080ffe3c632Sopenharmony_ci
6081ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
6082ffe3c632Sopenharmony_ci  return [[GPBUInt64DoubleDictionary allocWithZone:zone] initWithDictionary:self];
6083ffe3c632Sopenharmony_ci}
6084ffe3c632Sopenharmony_ci
6085ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
6086ffe3c632Sopenharmony_ci  if (self == other) {
6087ffe3c632Sopenharmony_ci    return YES;
6088ffe3c632Sopenharmony_ci  }
6089ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBUInt64DoubleDictionary class]]) {
6090ffe3c632Sopenharmony_ci    return NO;
6091ffe3c632Sopenharmony_ci  }
6092ffe3c632Sopenharmony_ci  GPBUInt64DoubleDictionary *otherDictionary = other;
6093ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
6094ffe3c632Sopenharmony_ci}
6095ffe3c632Sopenharmony_ci
6096ffe3c632Sopenharmony_ci- (NSUInteger)hash {
6097ffe3c632Sopenharmony_ci  return _dictionary.count;
6098ffe3c632Sopenharmony_ci}
6099ffe3c632Sopenharmony_ci
6100ffe3c632Sopenharmony_ci- (NSString *)description {
6101ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
6102ffe3c632Sopenharmony_ci}
6103ffe3c632Sopenharmony_ci
6104ffe3c632Sopenharmony_ci- (NSUInteger)count {
6105ffe3c632Sopenharmony_ci  return _dictionary.count;
6106ffe3c632Sopenharmony_ci}
6107ffe3c632Sopenharmony_ci
6108ffe3c632Sopenharmony_ci- (void)enumerateKeysAndDoublesUsingBlock:
6109ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(uint64_t key, double value, BOOL *stop))block {
6110ffe3c632Sopenharmony_ci  BOOL stop = NO;
6111ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
6112ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
6113ffe3c632Sopenharmony_ci  NSNumber *aKey;
6114ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
6115ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
6116ffe3c632Sopenharmony_ci    block([aKey unsignedLongLongValue], [aValue doubleValue], &stop);
6117ffe3c632Sopenharmony_ci    if (stop) {
6118ffe3c632Sopenharmony_ci      break;
6119ffe3c632Sopenharmony_ci    }
6120ffe3c632Sopenharmony_ci  }
6121ffe3c632Sopenharmony_ci}
6122ffe3c632Sopenharmony_ci
6123ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
6124ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
6125ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
6126ffe3c632Sopenharmony_ci  if (count == 0) {
6127ffe3c632Sopenharmony_ci    return 0;
6128ffe3c632Sopenharmony_ci  }
6129ffe3c632Sopenharmony_ci
6130ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
6131ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
6132ffe3c632Sopenharmony_ci  size_t result = 0;
6133ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
6134ffe3c632Sopenharmony_ci  NSNumber *aKey;
6135ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
6136ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
6137ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
6138ffe3c632Sopenharmony_ci    msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
6139ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
6140ffe3c632Sopenharmony_ci  }
6141ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
6142ffe3c632Sopenharmony_ci  result += tagSize * count;
6143ffe3c632Sopenharmony_ci  return result;
6144ffe3c632Sopenharmony_ci}
6145ffe3c632Sopenharmony_ci
6146ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
6147ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
6148ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
6149ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
6150ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
6151ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
6152ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
6153ffe3c632Sopenharmony_ci  NSNumber *aKey;
6154ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
6155ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
6156ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
6157ffe3c632Sopenharmony_ci    // Write the size of the message.
6158ffe3c632Sopenharmony_ci    uint64_t unwrappedKey = [aKey unsignedLongLongValue];
6159ffe3c632Sopenharmony_ci    double unwrappedValue = [aValue doubleValue];
6160ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
6161ffe3c632Sopenharmony_ci    msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
6162ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
6163ffe3c632Sopenharmony_ci    // Write the fields.
6164ffe3c632Sopenharmony_ci    WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
6165ffe3c632Sopenharmony_ci    WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
6166ffe3c632Sopenharmony_ci  }
6167ffe3c632Sopenharmony_ci}
6168ffe3c632Sopenharmony_ci
6169ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
6170ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
6171ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueUInt64)];
6172ffe3c632Sopenharmony_ci}
6173ffe3c632Sopenharmony_ci
6174ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
6175ffe3c632Sopenharmony_ci  [self enumerateKeysAndDoublesUsingBlock:^(uint64_t key, double value, BOOL *stop) {
6176ffe3c632Sopenharmony_ci      #pragma unused(stop)
6177ffe3c632Sopenharmony_ci      block([NSString stringWithFormat:@"%llu", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
6178ffe3c632Sopenharmony_ci  }];
6179ffe3c632Sopenharmony_ci}
6180ffe3c632Sopenharmony_ci
6181ffe3c632Sopenharmony_ci- (BOOL)getDouble:(nullable double *)value forKey:(uint64_t)key {
6182ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:@(key)];
6183ffe3c632Sopenharmony_ci  if (wrapped && value) {
6184ffe3c632Sopenharmony_ci    *value = [wrapped doubleValue];
6185ffe3c632Sopenharmony_ci  }
6186ffe3c632Sopenharmony_ci  return (wrapped != NULL);
6187ffe3c632Sopenharmony_ci}
6188ffe3c632Sopenharmony_ci
6189ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBUInt64DoubleDictionary *)otherDictionary {
6190ffe3c632Sopenharmony_ci  if (otherDictionary) {
6191ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
6192ffe3c632Sopenharmony_ci    if (_autocreator) {
6193ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
6194ffe3c632Sopenharmony_ci    }
6195ffe3c632Sopenharmony_ci  }
6196ffe3c632Sopenharmony_ci}
6197ffe3c632Sopenharmony_ci
6198ffe3c632Sopenharmony_ci- (void)setDouble:(double)value forKey:(uint64_t)key {
6199ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:@(key)];
6200ffe3c632Sopenharmony_ci  if (_autocreator) {
6201ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
6202ffe3c632Sopenharmony_ci  }
6203ffe3c632Sopenharmony_ci}
6204ffe3c632Sopenharmony_ci
6205ffe3c632Sopenharmony_ci- (void)removeDoubleForKey:(uint64_t)aKey {
6206ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:@(aKey)];
6207ffe3c632Sopenharmony_ci}
6208ffe3c632Sopenharmony_ci
6209ffe3c632Sopenharmony_ci- (void)removeAll {
6210ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
6211ffe3c632Sopenharmony_ci}
6212ffe3c632Sopenharmony_ci
6213ffe3c632Sopenharmony_ci@end
6214ffe3c632Sopenharmony_ci
6215ffe3c632Sopenharmony_ci#pragma mark - UInt64 -> Enum
6216ffe3c632Sopenharmony_ci
6217ffe3c632Sopenharmony_ci@implementation GPBUInt64EnumDictionary {
6218ffe3c632Sopenharmony_ci @package
6219ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
6220ffe3c632Sopenharmony_ci  GPBEnumValidationFunc _validationFunc;
6221ffe3c632Sopenharmony_ci}
6222ffe3c632Sopenharmony_ci
6223ffe3c632Sopenharmony_ci@synthesize validationFunc = _validationFunc;
6224ffe3c632Sopenharmony_ci
6225ffe3c632Sopenharmony_ci- (instancetype)init {
6226ffe3c632Sopenharmony_ci  return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
6227ffe3c632Sopenharmony_ci}
6228ffe3c632Sopenharmony_ci
6229ffe3c632Sopenharmony_ci- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
6230ffe3c632Sopenharmony_ci  return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
6231ffe3c632Sopenharmony_ci}
6232ffe3c632Sopenharmony_ci
6233ffe3c632Sopenharmony_ci- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
6234ffe3c632Sopenharmony_ci                                 rawValues:(const int32_t [])rawValues
6235ffe3c632Sopenharmony_ci                                   forKeys:(const uint64_t [])keys
6236ffe3c632Sopenharmony_ci                                     count:(NSUInteger)count {
6237ffe3c632Sopenharmony_ci  self = [super init];
6238ffe3c632Sopenharmony_ci  if (self) {
6239ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
6240ffe3c632Sopenharmony_ci    _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
6241ffe3c632Sopenharmony_ci    if (count && rawValues && keys) {
6242ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
6243ffe3c632Sopenharmony_ci        [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])];
6244ffe3c632Sopenharmony_ci      }
6245ffe3c632Sopenharmony_ci    }
6246ffe3c632Sopenharmony_ci  }
6247ffe3c632Sopenharmony_ci  return self;
6248ffe3c632Sopenharmony_ci}
6249ffe3c632Sopenharmony_ci
6250ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBUInt64EnumDictionary *)dictionary {
6251ffe3c632Sopenharmony_ci  self = [self initWithValidationFunction:dictionary.validationFunc
6252ffe3c632Sopenharmony_ci                                rawValues:NULL
6253ffe3c632Sopenharmony_ci                                  forKeys:NULL
6254ffe3c632Sopenharmony_ci                                    count:0];
6255ffe3c632Sopenharmony_ci  if (self) {
6256ffe3c632Sopenharmony_ci    if (dictionary) {
6257ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
6258ffe3c632Sopenharmony_ci    }
6259ffe3c632Sopenharmony_ci  }
6260ffe3c632Sopenharmony_ci  return self;
6261ffe3c632Sopenharmony_ci}
6262ffe3c632Sopenharmony_ci
6263ffe3c632Sopenharmony_ci- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
6264ffe3c632Sopenharmony_ci                                  capacity:(NSUInteger)numItems {
6265ffe3c632Sopenharmony_ci  #pragma unused(numItems)
6266ffe3c632Sopenharmony_ci  return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
6267ffe3c632Sopenharmony_ci}
6268ffe3c632Sopenharmony_ci
6269ffe3c632Sopenharmony_ci- (void)dealloc {
6270ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
6271ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
6272ffe3c632Sopenharmony_ci           [self class], _autocreator);
6273ffe3c632Sopenharmony_ci  [_dictionary release];
6274ffe3c632Sopenharmony_ci  [super dealloc];
6275ffe3c632Sopenharmony_ci}
6276ffe3c632Sopenharmony_ci
6277ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
6278ffe3c632Sopenharmony_ci  return [[GPBUInt64EnumDictionary allocWithZone:zone] initWithDictionary:self];
6279ffe3c632Sopenharmony_ci}
6280ffe3c632Sopenharmony_ci
6281ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
6282ffe3c632Sopenharmony_ci  if (self == other) {
6283ffe3c632Sopenharmony_ci    return YES;
6284ffe3c632Sopenharmony_ci  }
6285ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBUInt64EnumDictionary class]]) {
6286ffe3c632Sopenharmony_ci    return NO;
6287ffe3c632Sopenharmony_ci  }
6288ffe3c632Sopenharmony_ci  GPBUInt64EnumDictionary *otherDictionary = other;
6289ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
6290ffe3c632Sopenharmony_ci}
6291ffe3c632Sopenharmony_ci
6292ffe3c632Sopenharmony_ci- (NSUInteger)hash {
6293ffe3c632Sopenharmony_ci  return _dictionary.count;
6294ffe3c632Sopenharmony_ci}
6295ffe3c632Sopenharmony_ci
6296ffe3c632Sopenharmony_ci- (NSString *)description {
6297ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
6298ffe3c632Sopenharmony_ci}
6299ffe3c632Sopenharmony_ci
6300ffe3c632Sopenharmony_ci- (NSUInteger)count {
6301ffe3c632Sopenharmony_ci  return _dictionary.count;
6302ffe3c632Sopenharmony_ci}
6303ffe3c632Sopenharmony_ci
6304ffe3c632Sopenharmony_ci- (void)enumerateKeysAndRawValuesUsingBlock:
6305ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(uint64_t key, int32_t value, BOOL *stop))block {
6306ffe3c632Sopenharmony_ci  BOOL stop = NO;
6307ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
6308ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
6309ffe3c632Sopenharmony_ci  NSNumber *aKey;
6310ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
6311ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
6312ffe3c632Sopenharmony_ci    block([aKey unsignedLongLongValue], [aValue intValue], &stop);
6313ffe3c632Sopenharmony_ci    if (stop) {
6314ffe3c632Sopenharmony_ci      break;
6315ffe3c632Sopenharmony_ci    }
6316ffe3c632Sopenharmony_ci  }
6317ffe3c632Sopenharmony_ci}
6318ffe3c632Sopenharmony_ci
6319ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
6320ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
6321ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
6322ffe3c632Sopenharmony_ci  if (count == 0) {
6323ffe3c632Sopenharmony_ci    return 0;
6324ffe3c632Sopenharmony_ci  }
6325ffe3c632Sopenharmony_ci
6326ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
6327ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
6328ffe3c632Sopenharmony_ci  size_t result = 0;
6329ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
6330ffe3c632Sopenharmony_ci  NSNumber *aKey;
6331ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
6332ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
6333ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
6334ffe3c632Sopenharmony_ci    msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
6335ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
6336ffe3c632Sopenharmony_ci  }
6337ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
6338ffe3c632Sopenharmony_ci  result += tagSize * count;
6339ffe3c632Sopenharmony_ci  return result;
6340ffe3c632Sopenharmony_ci}
6341ffe3c632Sopenharmony_ci
6342ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
6343ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
6344ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
6345ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
6346ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
6347ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
6348ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
6349ffe3c632Sopenharmony_ci  NSNumber *aKey;
6350ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
6351ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
6352ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
6353ffe3c632Sopenharmony_ci    // Write the size of the message.
6354ffe3c632Sopenharmony_ci    uint64_t unwrappedKey = [aKey unsignedLongLongValue];
6355ffe3c632Sopenharmony_ci    int32_t unwrappedValue = [aValue intValue];
6356ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
6357ffe3c632Sopenharmony_ci    msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
6358ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
6359ffe3c632Sopenharmony_ci    // Write the fields.
6360ffe3c632Sopenharmony_ci    WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
6361ffe3c632Sopenharmony_ci    WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
6362ffe3c632Sopenharmony_ci  }
6363ffe3c632Sopenharmony_ci}
6364ffe3c632Sopenharmony_ci
6365ffe3c632Sopenharmony_ci- (NSData *)serializedDataForUnknownValue:(int32_t)value
6366ffe3c632Sopenharmony_ci                                   forKey:(GPBGenericValue *)key
6367ffe3c632Sopenharmony_ci                              keyDataType:(GPBDataType)keyDataType {
6368ffe3c632Sopenharmony_ci  size_t msgSize = ComputeDictUInt64FieldSize(key->valueUInt64, kMapKeyFieldNumber, keyDataType);
6369ffe3c632Sopenharmony_ci  msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
6370ffe3c632Sopenharmony_ci  NSMutableData *data = [NSMutableData dataWithLength:msgSize];
6371ffe3c632Sopenharmony_ci  GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
6372ffe3c632Sopenharmony_ci  WriteDictUInt64Field(outputStream, key->valueUInt64, kMapKeyFieldNumber, keyDataType);
6373ffe3c632Sopenharmony_ci  WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
6374ffe3c632Sopenharmony_ci  [outputStream release];
6375ffe3c632Sopenharmony_ci  return data;
6376ffe3c632Sopenharmony_ci}
6377ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
6378ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
6379ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueUInt64)];
6380ffe3c632Sopenharmony_ci}
6381ffe3c632Sopenharmony_ci
6382ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
6383ffe3c632Sopenharmony_ci  [self enumerateKeysAndRawValuesUsingBlock:^(uint64_t key, int32_t value, BOOL *stop) {
6384ffe3c632Sopenharmony_ci      #pragma unused(stop)
6385ffe3c632Sopenharmony_ci      block([NSString stringWithFormat:@"%llu", key], @(value));
6386ffe3c632Sopenharmony_ci  }];
6387ffe3c632Sopenharmony_ci}
6388ffe3c632Sopenharmony_ci
6389ffe3c632Sopenharmony_ci- (BOOL)getEnum:(int32_t *)value forKey:(uint64_t)key {
6390ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:@(key)];
6391ffe3c632Sopenharmony_ci  if (wrapped && value) {
6392ffe3c632Sopenharmony_ci    int32_t result = [wrapped intValue];
6393ffe3c632Sopenharmony_ci    if (!_validationFunc(result)) {
6394ffe3c632Sopenharmony_ci      result = kGPBUnrecognizedEnumeratorValue;
6395ffe3c632Sopenharmony_ci    }
6396ffe3c632Sopenharmony_ci    *value = result;
6397ffe3c632Sopenharmony_ci  }
6398ffe3c632Sopenharmony_ci  return (wrapped != NULL);
6399ffe3c632Sopenharmony_ci}
6400ffe3c632Sopenharmony_ci
6401ffe3c632Sopenharmony_ci- (BOOL)getRawValue:(int32_t *)rawValue forKey:(uint64_t)key {
6402ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:@(key)];
6403ffe3c632Sopenharmony_ci  if (wrapped && rawValue) {
6404ffe3c632Sopenharmony_ci    *rawValue = [wrapped intValue];
6405ffe3c632Sopenharmony_ci  }
6406ffe3c632Sopenharmony_ci  return (wrapped != NULL);
6407ffe3c632Sopenharmony_ci}
6408ffe3c632Sopenharmony_ci
6409ffe3c632Sopenharmony_ci- (void)enumerateKeysAndEnumsUsingBlock:
6410ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(uint64_t key, int32_t value, BOOL *stop))block {
6411ffe3c632Sopenharmony_ci  GPBEnumValidationFunc func = _validationFunc;
6412ffe3c632Sopenharmony_ci  BOOL stop = NO;
6413ffe3c632Sopenharmony_ci  NSEnumerator *keys = [_dictionary keyEnumerator];
6414ffe3c632Sopenharmony_ci  NSNumber *aKey;
6415ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
6416ffe3c632Sopenharmony_ci    NSNumber *aValue = _dictionary[aKey];
6417ffe3c632Sopenharmony_ci      int32_t unwrapped = [aValue intValue];
6418ffe3c632Sopenharmony_ci      if (!func(unwrapped)) {
6419ffe3c632Sopenharmony_ci        unwrapped = kGPBUnrecognizedEnumeratorValue;
6420ffe3c632Sopenharmony_ci      }
6421ffe3c632Sopenharmony_ci    block([aKey unsignedLongLongValue], unwrapped, &stop);
6422ffe3c632Sopenharmony_ci    if (stop) {
6423ffe3c632Sopenharmony_ci      break;
6424ffe3c632Sopenharmony_ci    }
6425ffe3c632Sopenharmony_ci  }
6426ffe3c632Sopenharmony_ci}
6427ffe3c632Sopenharmony_ci
6428ffe3c632Sopenharmony_ci- (void)addRawEntriesFromDictionary:(GPBUInt64EnumDictionary *)otherDictionary {
6429ffe3c632Sopenharmony_ci  if (otherDictionary) {
6430ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
6431ffe3c632Sopenharmony_ci    if (_autocreator) {
6432ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
6433ffe3c632Sopenharmony_ci    }
6434ffe3c632Sopenharmony_ci  }
6435ffe3c632Sopenharmony_ci}
6436ffe3c632Sopenharmony_ci
6437ffe3c632Sopenharmony_ci- (void)setRawValue:(int32_t)value forKey:(uint64_t)key {
6438ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:@(key)];
6439ffe3c632Sopenharmony_ci  if (_autocreator) {
6440ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
6441ffe3c632Sopenharmony_ci  }
6442ffe3c632Sopenharmony_ci}
6443ffe3c632Sopenharmony_ci
6444ffe3c632Sopenharmony_ci- (void)removeEnumForKey:(uint64_t)aKey {
6445ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:@(aKey)];
6446ffe3c632Sopenharmony_ci}
6447ffe3c632Sopenharmony_ci
6448ffe3c632Sopenharmony_ci- (void)removeAll {
6449ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
6450ffe3c632Sopenharmony_ci}
6451ffe3c632Sopenharmony_ci
6452ffe3c632Sopenharmony_ci- (void)setEnum:(int32_t)value forKey:(uint64_t)key {
6453ffe3c632Sopenharmony_ci  if (!_validationFunc(value)) {
6454ffe3c632Sopenharmony_ci    [NSException raise:NSInvalidArgumentException
6455ffe3c632Sopenharmony_ci                format:@"GPBUInt64EnumDictionary: Attempt to set an unknown enum value (%d)",
6456ffe3c632Sopenharmony_ci                       value];
6457ffe3c632Sopenharmony_ci  }
6458ffe3c632Sopenharmony_ci
6459ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:@(key)];
6460ffe3c632Sopenharmony_ci  if (_autocreator) {
6461ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
6462ffe3c632Sopenharmony_ci  }
6463ffe3c632Sopenharmony_ci}
6464ffe3c632Sopenharmony_ci
6465ffe3c632Sopenharmony_ci@end
6466ffe3c632Sopenharmony_ci
6467ffe3c632Sopenharmony_ci#pragma mark - UInt64 -> Object
6468ffe3c632Sopenharmony_ci
6469ffe3c632Sopenharmony_ci@implementation GPBUInt64ObjectDictionary {
6470ffe3c632Sopenharmony_ci @package
6471ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
6472ffe3c632Sopenharmony_ci}
6473ffe3c632Sopenharmony_ci
6474ffe3c632Sopenharmony_ci- (instancetype)init {
6475ffe3c632Sopenharmony_ci  return [self initWithObjects:NULL forKeys:NULL count:0];
6476ffe3c632Sopenharmony_ci}
6477ffe3c632Sopenharmony_ci
6478ffe3c632Sopenharmony_ci- (instancetype)initWithObjects:(const id [])objects
6479ffe3c632Sopenharmony_ci                        forKeys:(const uint64_t [])keys
6480ffe3c632Sopenharmony_ci                          count:(NSUInteger)count {
6481ffe3c632Sopenharmony_ci  self = [super init];
6482ffe3c632Sopenharmony_ci  if (self) {
6483ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
6484ffe3c632Sopenharmony_ci    if (count && objects && keys) {
6485ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
6486ffe3c632Sopenharmony_ci        if (!objects[i]) {
6487ffe3c632Sopenharmony_ci          [NSException raise:NSInvalidArgumentException
6488ffe3c632Sopenharmony_ci                      format:@"Attempting to add nil object to a Dictionary"];
6489ffe3c632Sopenharmony_ci        }
6490ffe3c632Sopenharmony_ci        [_dictionary setObject:objects[i] forKey:@(keys[i])];
6491ffe3c632Sopenharmony_ci      }
6492ffe3c632Sopenharmony_ci    }
6493ffe3c632Sopenharmony_ci  }
6494ffe3c632Sopenharmony_ci  return self;
6495ffe3c632Sopenharmony_ci}
6496ffe3c632Sopenharmony_ci
6497ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBUInt64ObjectDictionary *)dictionary {
6498ffe3c632Sopenharmony_ci  self = [self initWithObjects:NULL forKeys:NULL count:0];
6499ffe3c632Sopenharmony_ci  if (self) {
6500ffe3c632Sopenharmony_ci    if (dictionary) {
6501ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
6502ffe3c632Sopenharmony_ci    }
6503ffe3c632Sopenharmony_ci  }
6504ffe3c632Sopenharmony_ci  return self;
6505ffe3c632Sopenharmony_ci}
6506ffe3c632Sopenharmony_ci
6507ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
6508ffe3c632Sopenharmony_ci  #pragma unused(numItems)
6509ffe3c632Sopenharmony_ci  return [self initWithObjects:NULL forKeys:NULL count:0];
6510ffe3c632Sopenharmony_ci}
6511ffe3c632Sopenharmony_ci
6512ffe3c632Sopenharmony_ci- (void)dealloc {
6513ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
6514ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
6515ffe3c632Sopenharmony_ci           [self class], _autocreator);
6516ffe3c632Sopenharmony_ci  [_dictionary release];
6517ffe3c632Sopenharmony_ci  [super dealloc];
6518ffe3c632Sopenharmony_ci}
6519ffe3c632Sopenharmony_ci
6520ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
6521ffe3c632Sopenharmony_ci  return [[GPBUInt64ObjectDictionary allocWithZone:zone] initWithDictionary:self];
6522ffe3c632Sopenharmony_ci}
6523ffe3c632Sopenharmony_ci
6524ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
6525ffe3c632Sopenharmony_ci  if (self == other) {
6526ffe3c632Sopenharmony_ci    return YES;
6527ffe3c632Sopenharmony_ci  }
6528ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBUInt64ObjectDictionary class]]) {
6529ffe3c632Sopenharmony_ci    return NO;
6530ffe3c632Sopenharmony_ci  }
6531ffe3c632Sopenharmony_ci  GPBUInt64ObjectDictionary *otherDictionary = other;
6532ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
6533ffe3c632Sopenharmony_ci}
6534ffe3c632Sopenharmony_ci
6535ffe3c632Sopenharmony_ci- (NSUInteger)hash {
6536ffe3c632Sopenharmony_ci  return _dictionary.count;
6537ffe3c632Sopenharmony_ci}
6538ffe3c632Sopenharmony_ci
6539ffe3c632Sopenharmony_ci- (NSString *)description {
6540ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
6541ffe3c632Sopenharmony_ci}
6542ffe3c632Sopenharmony_ci
6543ffe3c632Sopenharmony_ci- (NSUInteger)count {
6544ffe3c632Sopenharmony_ci  return _dictionary.count;
6545ffe3c632Sopenharmony_ci}
6546ffe3c632Sopenharmony_ci
6547ffe3c632Sopenharmony_ci- (void)enumerateKeysAndObjectsUsingBlock:
6548ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(uint64_t key, id object, BOOL *stop))block {
6549ffe3c632Sopenharmony_ci  BOOL stop = NO;
6550ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
6551ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
6552ffe3c632Sopenharmony_ci  NSNumber *aKey;
6553ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
6554ffe3c632Sopenharmony_ci    id aObject = internal[aKey];
6555ffe3c632Sopenharmony_ci    block([aKey unsignedLongLongValue], aObject, &stop);
6556ffe3c632Sopenharmony_ci    if (stop) {
6557ffe3c632Sopenharmony_ci      break;
6558ffe3c632Sopenharmony_ci    }
6559ffe3c632Sopenharmony_ci  }
6560ffe3c632Sopenharmony_ci}
6561ffe3c632Sopenharmony_ci
6562ffe3c632Sopenharmony_ci- (BOOL)isInitialized {
6563ffe3c632Sopenharmony_ci  for (GPBMessage *msg in [_dictionary objectEnumerator]) {
6564ffe3c632Sopenharmony_ci    if (!msg.initialized) {
6565ffe3c632Sopenharmony_ci      return NO;
6566ffe3c632Sopenharmony_ci    }
6567ffe3c632Sopenharmony_ci  }
6568ffe3c632Sopenharmony_ci  return YES;
6569ffe3c632Sopenharmony_ci}
6570ffe3c632Sopenharmony_ci
6571ffe3c632Sopenharmony_ci- (instancetype)deepCopyWithZone:(NSZone *)zone {
6572ffe3c632Sopenharmony_ci  GPBUInt64ObjectDictionary *newDict =
6573ffe3c632Sopenharmony_ci      [[GPBUInt64ObjectDictionary alloc] init];
6574ffe3c632Sopenharmony_ci  NSEnumerator *keys = [_dictionary keyEnumerator];
6575ffe3c632Sopenharmony_ci  id aKey;
6576ffe3c632Sopenharmony_ci  NSMutableDictionary *internalDict = newDict->_dictionary;
6577ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
6578ffe3c632Sopenharmony_ci    GPBMessage *msg = _dictionary[aKey];
6579ffe3c632Sopenharmony_ci    GPBMessage *copiedMsg = [msg copyWithZone:zone];
6580ffe3c632Sopenharmony_ci    [internalDict setObject:copiedMsg forKey:aKey];
6581ffe3c632Sopenharmony_ci    [copiedMsg release];
6582ffe3c632Sopenharmony_ci  }
6583ffe3c632Sopenharmony_ci  return newDict;
6584ffe3c632Sopenharmony_ci}
6585ffe3c632Sopenharmony_ci
6586ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
6587ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
6588ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
6589ffe3c632Sopenharmony_ci  if (count == 0) {
6590ffe3c632Sopenharmony_ci    return 0;
6591ffe3c632Sopenharmony_ci  }
6592ffe3c632Sopenharmony_ci
6593ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
6594ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
6595ffe3c632Sopenharmony_ci  size_t result = 0;
6596ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
6597ffe3c632Sopenharmony_ci  NSNumber *aKey;
6598ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
6599ffe3c632Sopenharmony_ci    id aObject = internal[aKey];
6600ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictUInt64FieldSize([aKey unsignedLongLongValue], kMapKeyFieldNumber, keyDataType);
6601ffe3c632Sopenharmony_ci    msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
6602ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
6603ffe3c632Sopenharmony_ci  }
6604ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
6605ffe3c632Sopenharmony_ci  result += tagSize * count;
6606ffe3c632Sopenharmony_ci  return result;
6607ffe3c632Sopenharmony_ci}
6608ffe3c632Sopenharmony_ci
6609ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
6610ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
6611ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
6612ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
6613ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
6614ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
6615ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
6616ffe3c632Sopenharmony_ci  NSNumber *aKey;
6617ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
6618ffe3c632Sopenharmony_ci    id aObject = internal[aKey];
6619ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
6620ffe3c632Sopenharmony_ci    // Write the size of the message.
6621ffe3c632Sopenharmony_ci    uint64_t unwrappedKey = [aKey unsignedLongLongValue];
6622ffe3c632Sopenharmony_ci    id unwrappedValue = aObject;
6623ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictUInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
6624ffe3c632Sopenharmony_ci    msgSize += ComputeDictObjectFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
6625ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
6626ffe3c632Sopenharmony_ci    // Write the fields.
6627ffe3c632Sopenharmony_ci    WriteDictUInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
6628ffe3c632Sopenharmony_ci    WriteDictObjectField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
6629ffe3c632Sopenharmony_ci  }
6630ffe3c632Sopenharmony_ci}
6631ffe3c632Sopenharmony_ci
6632ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
6633ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
6634ffe3c632Sopenharmony_ci  [_dictionary setObject:value->valueString forKey:@(key->valueUInt64)];
6635ffe3c632Sopenharmony_ci}
6636ffe3c632Sopenharmony_ci
6637ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
6638ffe3c632Sopenharmony_ci  [self enumerateKeysAndObjectsUsingBlock:^(uint64_t key, id object, BOOL *stop) {
6639ffe3c632Sopenharmony_ci      #pragma unused(stop)
6640ffe3c632Sopenharmony_ci      block([NSString stringWithFormat:@"%llu", key], object);
6641ffe3c632Sopenharmony_ci  }];
6642ffe3c632Sopenharmony_ci}
6643ffe3c632Sopenharmony_ci
6644ffe3c632Sopenharmony_ci- (id)objectForKey:(uint64_t)key {
6645ffe3c632Sopenharmony_ci  id result = [_dictionary objectForKey:@(key)];
6646ffe3c632Sopenharmony_ci  return result;
6647ffe3c632Sopenharmony_ci}
6648ffe3c632Sopenharmony_ci
6649ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBUInt64ObjectDictionary *)otherDictionary {
6650ffe3c632Sopenharmony_ci  if (otherDictionary) {
6651ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
6652ffe3c632Sopenharmony_ci    if (_autocreator) {
6653ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
6654ffe3c632Sopenharmony_ci    }
6655ffe3c632Sopenharmony_ci  }
6656ffe3c632Sopenharmony_ci}
6657ffe3c632Sopenharmony_ci
6658ffe3c632Sopenharmony_ci- (void)setObject:(id)object forKey:(uint64_t)key {
6659ffe3c632Sopenharmony_ci  if (!object) {
6660ffe3c632Sopenharmony_ci    [NSException raise:NSInvalidArgumentException
6661ffe3c632Sopenharmony_ci                format:@"Attempting to add nil object to a Dictionary"];
6662ffe3c632Sopenharmony_ci  }
6663ffe3c632Sopenharmony_ci  [_dictionary setObject:object forKey:@(key)];
6664ffe3c632Sopenharmony_ci  if (_autocreator) {
6665ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
6666ffe3c632Sopenharmony_ci  }
6667ffe3c632Sopenharmony_ci}
6668ffe3c632Sopenharmony_ci
6669ffe3c632Sopenharmony_ci- (void)removeObjectForKey:(uint64_t)aKey {
6670ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:@(aKey)];
6671ffe3c632Sopenharmony_ci}
6672ffe3c632Sopenharmony_ci
6673ffe3c632Sopenharmony_ci- (void)removeAll {
6674ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
6675ffe3c632Sopenharmony_ci}
6676ffe3c632Sopenharmony_ci
6677ffe3c632Sopenharmony_ci@end
6678ffe3c632Sopenharmony_ci
6679ffe3c632Sopenharmony_ci// clang-format on
6680ffe3c632Sopenharmony_ci//%PDDM-EXPAND DICTIONARY_IMPL_FOR_POD_KEY(Int64, int64_t)
6681ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly.
6682ffe3c632Sopenharmony_ci// clang-format off
6683ffe3c632Sopenharmony_ci
6684ffe3c632Sopenharmony_ci#pragma mark - Int64 -> UInt32
6685ffe3c632Sopenharmony_ci
6686ffe3c632Sopenharmony_ci@implementation GPBInt64UInt32Dictionary {
6687ffe3c632Sopenharmony_ci @package
6688ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
6689ffe3c632Sopenharmony_ci}
6690ffe3c632Sopenharmony_ci
6691ffe3c632Sopenharmony_ci- (instancetype)init {
6692ffe3c632Sopenharmony_ci  return [self initWithUInt32s:NULL forKeys:NULL count:0];
6693ffe3c632Sopenharmony_ci}
6694ffe3c632Sopenharmony_ci
6695ffe3c632Sopenharmony_ci- (instancetype)initWithUInt32s:(const uint32_t [])values
6696ffe3c632Sopenharmony_ci                        forKeys:(const int64_t [])keys
6697ffe3c632Sopenharmony_ci                          count:(NSUInteger)count {
6698ffe3c632Sopenharmony_ci  self = [super init];
6699ffe3c632Sopenharmony_ci  if (self) {
6700ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
6701ffe3c632Sopenharmony_ci    if (count && values && keys) {
6702ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
6703ffe3c632Sopenharmony_ci        [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
6704ffe3c632Sopenharmony_ci      }
6705ffe3c632Sopenharmony_ci    }
6706ffe3c632Sopenharmony_ci  }
6707ffe3c632Sopenharmony_ci  return self;
6708ffe3c632Sopenharmony_ci}
6709ffe3c632Sopenharmony_ci
6710ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBInt64UInt32Dictionary *)dictionary {
6711ffe3c632Sopenharmony_ci  self = [self initWithUInt32s:NULL forKeys:NULL count:0];
6712ffe3c632Sopenharmony_ci  if (self) {
6713ffe3c632Sopenharmony_ci    if (dictionary) {
6714ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
6715ffe3c632Sopenharmony_ci    }
6716ffe3c632Sopenharmony_ci  }
6717ffe3c632Sopenharmony_ci  return self;
6718ffe3c632Sopenharmony_ci}
6719ffe3c632Sopenharmony_ci
6720ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
6721ffe3c632Sopenharmony_ci  #pragma unused(numItems)
6722ffe3c632Sopenharmony_ci  return [self initWithUInt32s:NULL forKeys:NULL count:0];
6723ffe3c632Sopenharmony_ci}
6724ffe3c632Sopenharmony_ci
6725ffe3c632Sopenharmony_ci- (void)dealloc {
6726ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
6727ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
6728ffe3c632Sopenharmony_ci           [self class], _autocreator);
6729ffe3c632Sopenharmony_ci  [_dictionary release];
6730ffe3c632Sopenharmony_ci  [super dealloc];
6731ffe3c632Sopenharmony_ci}
6732ffe3c632Sopenharmony_ci
6733ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
6734ffe3c632Sopenharmony_ci  return [[GPBInt64UInt32Dictionary allocWithZone:zone] initWithDictionary:self];
6735ffe3c632Sopenharmony_ci}
6736ffe3c632Sopenharmony_ci
6737ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
6738ffe3c632Sopenharmony_ci  if (self == other) {
6739ffe3c632Sopenharmony_ci    return YES;
6740ffe3c632Sopenharmony_ci  }
6741ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBInt64UInt32Dictionary class]]) {
6742ffe3c632Sopenharmony_ci    return NO;
6743ffe3c632Sopenharmony_ci  }
6744ffe3c632Sopenharmony_ci  GPBInt64UInt32Dictionary *otherDictionary = other;
6745ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
6746ffe3c632Sopenharmony_ci}
6747ffe3c632Sopenharmony_ci
6748ffe3c632Sopenharmony_ci- (NSUInteger)hash {
6749ffe3c632Sopenharmony_ci  return _dictionary.count;
6750ffe3c632Sopenharmony_ci}
6751ffe3c632Sopenharmony_ci
6752ffe3c632Sopenharmony_ci- (NSString *)description {
6753ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
6754ffe3c632Sopenharmony_ci}
6755ffe3c632Sopenharmony_ci
6756ffe3c632Sopenharmony_ci- (NSUInteger)count {
6757ffe3c632Sopenharmony_ci  return _dictionary.count;
6758ffe3c632Sopenharmony_ci}
6759ffe3c632Sopenharmony_ci
6760ffe3c632Sopenharmony_ci- (void)enumerateKeysAndUInt32sUsingBlock:
6761ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(int64_t key, uint32_t value, BOOL *stop))block {
6762ffe3c632Sopenharmony_ci  BOOL stop = NO;
6763ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
6764ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
6765ffe3c632Sopenharmony_ci  NSNumber *aKey;
6766ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
6767ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
6768ffe3c632Sopenharmony_ci    block([aKey longLongValue], [aValue unsignedIntValue], &stop);
6769ffe3c632Sopenharmony_ci    if (stop) {
6770ffe3c632Sopenharmony_ci      break;
6771ffe3c632Sopenharmony_ci    }
6772ffe3c632Sopenharmony_ci  }
6773ffe3c632Sopenharmony_ci}
6774ffe3c632Sopenharmony_ci
6775ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
6776ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
6777ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
6778ffe3c632Sopenharmony_ci  if (count == 0) {
6779ffe3c632Sopenharmony_ci    return 0;
6780ffe3c632Sopenharmony_ci  }
6781ffe3c632Sopenharmony_ci
6782ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
6783ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
6784ffe3c632Sopenharmony_ci  size_t result = 0;
6785ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
6786ffe3c632Sopenharmony_ci  NSNumber *aKey;
6787ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
6788ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
6789ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
6790ffe3c632Sopenharmony_ci    msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
6791ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
6792ffe3c632Sopenharmony_ci  }
6793ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
6794ffe3c632Sopenharmony_ci  result += tagSize * count;
6795ffe3c632Sopenharmony_ci  return result;
6796ffe3c632Sopenharmony_ci}
6797ffe3c632Sopenharmony_ci
6798ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
6799ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
6800ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
6801ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
6802ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
6803ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
6804ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
6805ffe3c632Sopenharmony_ci  NSNumber *aKey;
6806ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
6807ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
6808ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
6809ffe3c632Sopenharmony_ci    // Write the size of the message.
6810ffe3c632Sopenharmony_ci    int64_t unwrappedKey = [aKey longLongValue];
6811ffe3c632Sopenharmony_ci    uint32_t unwrappedValue = [aValue unsignedIntValue];
6812ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
6813ffe3c632Sopenharmony_ci    msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
6814ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
6815ffe3c632Sopenharmony_ci    // Write the fields.
6816ffe3c632Sopenharmony_ci    WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
6817ffe3c632Sopenharmony_ci    WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
6818ffe3c632Sopenharmony_ci  }
6819ffe3c632Sopenharmony_ci}
6820ffe3c632Sopenharmony_ci
6821ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
6822ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
6823ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueUInt32) forKey:@(key->valueInt64)];
6824ffe3c632Sopenharmony_ci}
6825ffe3c632Sopenharmony_ci
6826ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
6827ffe3c632Sopenharmony_ci  [self enumerateKeysAndUInt32sUsingBlock:^(int64_t key, uint32_t value, BOOL *stop) {
6828ffe3c632Sopenharmony_ci      #pragma unused(stop)
6829ffe3c632Sopenharmony_ci      block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%u", value]);
6830ffe3c632Sopenharmony_ci  }];
6831ffe3c632Sopenharmony_ci}
6832ffe3c632Sopenharmony_ci
6833ffe3c632Sopenharmony_ci- (BOOL)getUInt32:(nullable uint32_t *)value forKey:(int64_t)key {
6834ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:@(key)];
6835ffe3c632Sopenharmony_ci  if (wrapped && value) {
6836ffe3c632Sopenharmony_ci    *value = [wrapped unsignedIntValue];
6837ffe3c632Sopenharmony_ci  }
6838ffe3c632Sopenharmony_ci  return (wrapped != NULL);
6839ffe3c632Sopenharmony_ci}
6840ffe3c632Sopenharmony_ci
6841ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBInt64UInt32Dictionary *)otherDictionary {
6842ffe3c632Sopenharmony_ci  if (otherDictionary) {
6843ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
6844ffe3c632Sopenharmony_ci    if (_autocreator) {
6845ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
6846ffe3c632Sopenharmony_ci    }
6847ffe3c632Sopenharmony_ci  }
6848ffe3c632Sopenharmony_ci}
6849ffe3c632Sopenharmony_ci
6850ffe3c632Sopenharmony_ci- (void)setUInt32:(uint32_t)value forKey:(int64_t)key {
6851ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:@(key)];
6852ffe3c632Sopenharmony_ci  if (_autocreator) {
6853ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
6854ffe3c632Sopenharmony_ci  }
6855ffe3c632Sopenharmony_ci}
6856ffe3c632Sopenharmony_ci
6857ffe3c632Sopenharmony_ci- (void)removeUInt32ForKey:(int64_t)aKey {
6858ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:@(aKey)];
6859ffe3c632Sopenharmony_ci}
6860ffe3c632Sopenharmony_ci
6861ffe3c632Sopenharmony_ci- (void)removeAll {
6862ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
6863ffe3c632Sopenharmony_ci}
6864ffe3c632Sopenharmony_ci
6865ffe3c632Sopenharmony_ci@end
6866ffe3c632Sopenharmony_ci
6867ffe3c632Sopenharmony_ci#pragma mark - Int64 -> Int32
6868ffe3c632Sopenharmony_ci
6869ffe3c632Sopenharmony_ci@implementation GPBInt64Int32Dictionary {
6870ffe3c632Sopenharmony_ci @package
6871ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
6872ffe3c632Sopenharmony_ci}
6873ffe3c632Sopenharmony_ci
6874ffe3c632Sopenharmony_ci- (instancetype)init {
6875ffe3c632Sopenharmony_ci  return [self initWithInt32s:NULL forKeys:NULL count:0];
6876ffe3c632Sopenharmony_ci}
6877ffe3c632Sopenharmony_ci
6878ffe3c632Sopenharmony_ci- (instancetype)initWithInt32s:(const int32_t [])values
6879ffe3c632Sopenharmony_ci                       forKeys:(const int64_t [])keys
6880ffe3c632Sopenharmony_ci                         count:(NSUInteger)count {
6881ffe3c632Sopenharmony_ci  self = [super init];
6882ffe3c632Sopenharmony_ci  if (self) {
6883ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
6884ffe3c632Sopenharmony_ci    if (count && values && keys) {
6885ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
6886ffe3c632Sopenharmony_ci        [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
6887ffe3c632Sopenharmony_ci      }
6888ffe3c632Sopenharmony_ci    }
6889ffe3c632Sopenharmony_ci  }
6890ffe3c632Sopenharmony_ci  return self;
6891ffe3c632Sopenharmony_ci}
6892ffe3c632Sopenharmony_ci
6893ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBInt64Int32Dictionary *)dictionary {
6894ffe3c632Sopenharmony_ci  self = [self initWithInt32s:NULL forKeys:NULL count:0];
6895ffe3c632Sopenharmony_ci  if (self) {
6896ffe3c632Sopenharmony_ci    if (dictionary) {
6897ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
6898ffe3c632Sopenharmony_ci    }
6899ffe3c632Sopenharmony_ci  }
6900ffe3c632Sopenharmony_ci  return self;
6901ffe3c632Sopenharmony_ci}
6902ffe3c632Sopenharmony_ci
6903ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
6904ffe3c632Sopenharmony_ci  #pragma unused(numItems)
6905ffe3c632Sopenharmony_ci  return [self initWithInt32s:NULL forKeys:NULL count:0];
6906ffe3c632Sopenharmony_ci}
6907ffe3c632Sopenharmony_ci
6908ffe3c632Sopenharmony_ci- (void)dealloc {
6909ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
6910ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
6911ffe3c632Sopenharmony_ci           [self class], _autocreator);
6912ffe3c632Sopenharmony_ci  [_dictionary release];
6913ffe3c632Sopenharmony_ci  [super dealloc];
6914ffe3c632Sopenharmony_ci}
6915ffe3c632Sopenharmony_ci
6916ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
6917ffe3c632Sopenharmony_ci  return [[GPBInt64Int32Dictionary allocWithZone:zone] initWithDictionary:self];
6918ffe3c632Sopenharmony_ci}
6919ffe3c632Sopenharmony_ci
6920ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
6921ffe3c632Sopenharmony_ci  if (self == other) {
6922ffe3c632Sopenharmony_ci    return YES;
6923ffe3c632Sopenharmony_ci  }
6924ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBInt64Int32Dictionary class]]) {
6925ffe3c632Sopenharmony_ci    return NO;
6926ffe3c632Sopenharmony_ci  }
6927ffe3c632Sopenharmony_ci  GPBInt64Int32Dictionary *otherDictionary = other;
6928ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
6929ffe3c632Sopenharmony_ci}
6930ffe3c632Sopenharmony_ci
6931ffe3c632Sopenharmony_ci- (NSUInteger)hash {
6932ffe3c632Sopenharmony_ci  return _dictionary.count;
6933ffe3c632Sopenharmony_ci}
6934ffe3c632Sopenharmony_ci
6935ffe3c632Sopenharmony_ci- (NSString *)description {
6936ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
6937ffe3c632Sopenharmony_ci}
6938ffe3c632Sopenharmony_ci
6939ffe3c632Sopenharmony_ci- (NSUInteger)count {
6940ffe3c632Sopenharmony_ci  return _dictionary.count;
6941ffe3c632Sopenharmony_ci}
6942ffe3c632Sopenharmony_ci
6943ffe3c632Sopenharmony_ci- (void)enumerateKeysAndInt32sUsingBlock:
6944ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(int64_t key, int32_t value, BOOL *stop))block {
6945ffe3c632Sopenharmony_ci  BOOL stop = NO;
6946ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
6947ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
6948ffe3c632Sopenharmony_ci  NSNumber *aKey;
6949ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
6950ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
6951ffe3c632Sopenharmony_ci    block([aKey longLongValue], [aValue intValue], &stop);
6952ffe3c632Sopenharmony_ci    if (stop) {
6953ffe3c632Sopenharmony_ci      break;
6954ffe3c632Sopenharmony_ci    }
6955ffe3c632Sopenharmony_ci  }
6956ffe3c632Sopenharmony_ci}
6957ffe3c632Sopenharmony_ci
6958ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
6959ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
6960ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
6961ffe3c632Sopenharmony_ci  if (count == 0) {
6962ffe3c632Sopenharmony_ci    return 0;
6963ffe3c632Sopenharmony_ci  }
6964ffe3c632Sopenharmony_ci
6965ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
6966ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
6967ffe3c632Sopenharmony_ci  size_t result = 0;
6968ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
6969ffe3c632Sopenharmony_ci  NSNumber *aKey;
6970ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
6971ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
6972ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
6973ffe3c632Sopenharmony_ci    msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
6974ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
6975ffe3c632Sopenharmony_ci  }
6976ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
6977ffe3c632Sopenharmony_ci  result += tagSize * count;
6978ffe3c632Sopenharmony_ci  return result;
6979ffe3c632Sopenharmony_ci}
6980ffe3c632Sopenharmony_ci
6981ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
6982ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
6983ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
6984ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
6985ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
6986ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
6987ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
6988ffe3c632Sopenharmony_ci  NSNumber *aKey;
6989ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
6990ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
6991ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
6992ffe3c632Sopenharmony_ci    // Write the size of the message.
6993ffe3c632Sopenharmony_ci    int64_t unwrappedKey = [aKey longLongValue];
6994ffe3c632Sopenharmony_ci    int32_t unwrappedValue = [aValue intValue];
6995ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
6996ffe3c632Sopenharmony_ci    msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
6997ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
6998ffe3c632Sopenharmony_ci    // Write the fields.
6999ffe3c632Sopenharmony_ci    WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
7000ffe3c632Sopenharmony_ci    WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
7001ffe3c632Sopenharmony_ci  }
7002ffe3c632Sopenharmony_ci}
7003ffe3c632Sopenharmony_ci
7004ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
7005ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
7006ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueInt32) forKey:@(key->valueInt64)];
7007ffe3c632Sopenharmony_ci}
7008ffe3c632Sopenharmony_ci
7009ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
7010ffe3c632Sopenharmony_ci  [self enumerateKeysAndInt32sUsingBlock:^(int64_t key, int32_t value, BOOL *stop) {
7011ffe3c632Sopenharmony_ci      #pragma unused(stop)
7012ffe3c632Sopenharmony_ci      block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%d", value]);
7013ffe3c632Sopenharmony_ci  }];
7014ffe3c632Sopenharmony_ci}
7015ffe3c632Sopenharmony_ci
7016ffe3c632Sopenharmony_ci- (BOOL)getInt32:(nullable int32_t *)value forKey:(int64_t)key {
7017ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:@(key)];
7018ffe3c632Sopenharmony_ci  if (wrapped && value) {
7019ffe3c632Sopenharmony_ci    *value = [wrapped intValue];
7020ffe3c632Sopenharmony_ci  }
7021ffe3c632Sopenharmony_ci  return (wrapped != NULL);
7022ffe3c632Sopenharmony_ci}
7023ffe3c632Sopenharmony_ci
7024ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBInt64Int32Dictionary *)otherDictionary {
7025ffe3c632Sopenharmony_ci  if (otherDictionary) {
7026ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
7027ffe3c632Sopenharmony_ci    if (_autocreator) {
7028ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
7029ffe3c632Sopenharmony_ci    }
7030ffe3c632Sopenharmony_ci  }
7031ffe3c632Sopenharmony_ci}
7032ffe3c632Sopenharmony_ci
7033ffe3c632Sopenharmony_ci- (void)setInt32:(int32_t)value forKey:(int64_t)key {
7034ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:@(key)];
7035ffe3c632Sopenharmony_ci  if (_autocreator) {
7036ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
7037ffe3c632Sopenharmony_ci  }
7038ffe3c632Sopenharmony_ci}
7039ffe3c632Sopenharmony_ci
7040ffe3c632Sopenharmony_ci- (void)removeInt32ForKey:(int64_t)aKey {
7041ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:@(aKey)];
7042ffe3c632Sopenharmony_ci}
7043ffe3c632Sopenharmony_ci
7044ffe3c632Sopenharmony_ci- (void)removeAll {
7045ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
7046ffe3c632Sopenharmony_ci}
7047ffe3c632Sopenharmony_ci
7048ffe3c632Sopenharmony_ci@end
7049ffe3c632Sopenharmony_ci
7050ffe3c632Sopenharmony_ci#pragma mark - Int64 -> UInt64
7051ffe3c632Sopenharmony_ci
7052ffe3c632Sopenharmony_ci@implementation GPBInt64UInt64Dictionary {
7053ffe3c632Sopenharmony_ci @package
7054ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
7055ffe3c632Sopenharmony_ci}
7056ffe3c632Sopenharmony_ci
7057ffe3c632Sopenharmony_ci- (instancetype)init {
7058ffe3c632Sopenharmony_ci  return [self initWithUInt64s:NULL forKeys:NULL count:0];
7059ffe3c632Sopenharmony_ci}
7060ffe3c632Sopenharmony_ci
7061ffe3c632Sopenharmony_ci- (instancetype)initWithUInt64s:(const uint64_t [])values
7062ffe3c632Sopenharmony_ci                        forKeys:(const int64_t [])keys
7063ffe3c632Sopenharmony_ci                          count:(NSUInteger)count {
7064ffe3c632Sopenharmony_ci  self = [super init];
7065ffe3c632Sopenharmony_ci  if (self) {
7066ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
7067ffe3c632Sopenharmony_ci    if (count && values && keys) {
7068ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
7069ffe3c632Sopenharmony_ci        [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
7070ffe3c632Sopenharmony_ci      }
7071ffe3c632Sopenharmony_ci    }
7072ffe3c632Sopenharmony_ci  }
7073ffe3c632Sopenharmony_ci  return self;
7074ffe3c632Sopenharmony_ci}
7075ffe3c632Sopenharmony_ci
7076ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBInt64UInt64Dictionary *)dictionary {
7077ffe3c632Sopenharmony_ci  self = [self initWithUInt64s:NULL forKeys:NULL count:0];
7078ffe3c632Sopenharmony_ci  if (self) {
7079ffe3c632Sopenharmony_ci    if (dictionary) {
7080ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
7081ffe3c632Sopenharmony_ci    }
7082ffe3c632Sopenharmony_ci  }
7083ffe3c632Sopenharmony_ci  return self;
7084ffe3c632Sopenharmony_ci}
7085ffe3c632Sopenharmony_ci
7086ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
7087ffe3c632Sopenharmony_ci  #pragma unused(numItems)
7088ffe3c632Sopenharmony_ci  return [self initWithUInt64s:NULL forKeys:NULL count:0];
7089ffe3c632Sopenharmony_ci}
7090ffe3c632Sopenharmony_ci
7091ffe3c632Sopenharmony_ci- (void)dealloc {
7092ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
7093ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
7094ffe3c632Sopenharmony_ci           [self class], _autocreator);
7095ffe3c632Sopenharmony_ci  [_dictionary release];
7096ffe3c632Sopenharmony_ci  [super dealloc];
7097ffe3c632Sopenharmony_ci}
7098ffe3c632Sopenharmony_ci
7099ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
7100ffe3c632Sopenharmony_ci  return [[GPBInt64UInt64Dictionary allocWithZone:zone] initWithDictionary:self];
7101ffe3c632Sopenharmony_ci}
7102ffe3c632Sopenharmony_ci
7103ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
7104ffe3c632Sopenharmony_ci  if (self == other) {
7105ffe3c632Sopenharmony_ci    return YES;
7106ffe3c632Sopenharmony_ci  }
7107ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBInt64UInt64Dictionary class]]) {
7108ffe3c632Sopenharmony_ci    return NO;
7109ffe3c632Sopenharmony_ci  }
7110ffe3c632Sopenharmony_ci  GPBInt64UInt64Dictionary *otherDictionary = other;
7111ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
7112ffe3c632Sopenharmony_ci}
7113ffe3c632Sopenharmony_ci
7114ffe3c632Sopenharmony_ci- (NSUInteger)hash {
7115ffe3c632Sopenharmony_ci  return _dictionary.count;
7116ffe3c632Sopenharmony_ci}
7117ffe3c632Sopenharmony_ci
7118ffe3c632Sopenharmony_ci- (NSString *)description {
7119ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
7120ffe3c632Sopenharmony_ci}
7121ffe3c632Sopenharmony_ci
7122ffe3c632Sopenharmony_ci- (NSUInteger)count {
7123ffe3c632Sopenharmony_ci  return _dictionary.count;
7124ffe3c632Sopenharmony_ci}
7125ffe3c632Sopenharmony_ci
7126ffe3c632Sopenharmony_ci- (void)enumerateKeysAndUInt64sUsingBlock:
7127ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(int64_t key, uint64_t value, BOOL *stop))block {
7128ffe3c632Sopenharmony_ci  BOOL stop = NO;
7129ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
7130ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
7131ffe3c632Sopenharmony_ci  NSNumber *aKey;
7132ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
7133ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
7134ffe3c632Sopenharmony_ci    block([aKey longLongValue], [aValue unsignedLongLongValue], &stop);
7135ffe3c632Sopenharmony_ci    if (stop) {
7136ffe3c632Sopenharmony_ci      break;
7137ffe3c632Sopenharmony_ci    }
7138ffe3c632Sopenharmony_ci  }
7139ffe3c632Sopenharmony_ci}
7140ffe3c632Sopenharmony_ci
7141ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
7142ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
7143ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
7144ffe3c632Sopenharmony_ci  if (count == 0) {
7145ffe3c632Sopenharmony_ci    return 0;
7146ffe3c632Sopenharmony_ci  }
7147ffe3c632Sopenharmony_ci
7148ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
7149ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
7150ffe3c632Sopenharmony_ci  size_t result = 0;
7151ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
7152ffe3c632Sopenharmony_ci  NSNumber *aKey;
7153ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
7154ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
7155ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
7156ffe3c632Sopenharmony_ci    msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
7157ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
7158ffe3c632Sopenharmony_ci  }
7159ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
7160ffe3c632Sopenharmony_ci  result += tagSize * count;
7161ffe3c632Sopenharmony_ci  return result;
7162ffe3c632Sopenharmony_ci}
7163ffe3c632Sopenharmony_ci
7164ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
7165ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
7166ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
7167ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
7168ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
7169ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
7170ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
7171ffe3c632Sopenharmony_ci  NSNumber *aKey;
7172ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
7173ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
7174ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
7175ffe3c632Sopenharmony_ci    // Write the size of the message.
7176ffe3c632Sopenharmony_ci    int64_t unwrappedKey = [aKey longLongValue];
7177ffe3c632Sopenharmony_ci    uint64_t unwrappedValue = [aValue unsignedLongLongValue];
7178ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
7179ffe3c632Sopenharmony_ci    msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
7180ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
7181ffe3c632Sopenharmony_ci    // Write the fields.
7182ffe3c632Sopenharmony_ci    WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
7183ffe3c632Sopenharmony_ci    WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
7184ffe3c632Sopenharmony_ci  }
7185ffe3c632Sopenharmony_ci}
7186ffe3c632Sopenharmony_ci
7187ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
7188ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
7189ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueUInt64) forKey:@(key->valueInt64)];
7190ffe3c632Sopenharmony_ci}
7191ffe3c632Sopenharmony_ci
7192ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
7193ffe3c632Sopenharmony_ci  [self enumerateKeysAndUInt64sUsingBlock:^(int64_t key, uint64_t value, BOOL *stop) {
7194ffe3c632Sopenharmony_ci      #pragma unused(stop)
7195ffe3c632Sopenharmony_ci      block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%llu", value]);
7196ffe3c632Sopenharmony_ci  }];
7197ffe3c632Sopenharmony_ci}
7198ffe3c632Sopenharmony_ci
7199ffe3c632Sopenharmony_ci- (BOOL)getUInt64:(nullable uint64_t *)value forKey:(int64_t)key {
7200ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:@(key)];
7201ffe3c632Sopenharmony_ci  if (wrapped && value) {
7202ffe3c632Sopenharmony_ci    *value = [wrapped unsignedLongLongValue];
7203ffe3c632Sopenharmony_ci  }
7204ffe3c632Sopenharmony_ci  return (wrapped != NULL);
7205ffe3c632Sopenharmony_ci}
7206ffe3c632Sopenharmony_ci
7207ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBInt64UInt64Dictionary *)otherDictionary {
7208ffe3c632Sopenharmony_ci  if (otherDictionary) {
7209ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
7210ffe3c632Sopenharmony_ci    if (_autocreator) {
7211ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
7212ffe3c632Sopenharmony_ci    }
7213ffe3c632Sopenharmony_ci  }
7214ffe3c632Sopenharmony_ci}
7215ffe3c632Sopenharmony_ci
7216ffe3c632Sopenharmony_ci- (void)setUInt64:(uint64_t)value forKey:(int64_t)key {
7217ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:@(key)];
7218ffe3c632Sopenharmony_ci  if (_autocreator) {
7219ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
7220ffe3c632Sopenharmony_ci  }
7221ffe3c632Sopenharmony_ci}
7222ffe3c632Sopenharmony_ci
7223ffe3c632Sopenharmony_ci- (void)removeUInt64ForKey:(int64_t)aKey {
7224ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:@(aKey)];
7225ffe3c632Sopenharmony_ci}
7226ffe3c632Sopenharmony_ci
7227ffe3c632Sopenharmony_ci- (void)removeAll {
7228ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
7229ffe3c632Sopenharmony_ci}
7230ffe3c632Sopenharmony_ci
7231ffe3c632Sopenharmony_ci@end
7232ffe3c632Sopenharmony_ci
7233ffe3c632Sopenharmony_ci#pragma mark - Int64 -> Int64
7234ffe3c632Sopenharmony_ci
7235ffe3c632Sopenharmony_ci@implementation GPBInt64Int64Dictionary {
7236ffe3c632Sopenharmony_ci @package
7237ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
7238ffe3c632Sopenharmony_ci}
7239ffe3c632Sopenharmony_ci
7240ffe3c632Sopenharmony_ci- (instancetype)init {
7241ffe3c632Sopenharmony_ci  return [self initWithInt64s:NULL forKeys:NULL count:0];
7242ffe3c632Sopenharmony_ci}
7243ffe3c632Sopenharmony_ci
7244ffe3c632Sopenharmony_ci- (instancetype)initWithInt64s:(const int64_t [])values
7245ffe3c632Sopenharmony_ci                       forKeys:(const int64_t [])keys
7246ffe3c632Sopenharmony_ci                         count:(NSUInteger)count {
7247ffe3c632Sopenharmony_ci  self = [super init];
7248ffe3c632Sopenharmony_ci  if (self) {
7249ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
7250ffe3c632Sopenharmony_ci    if (count && values && keys) {
7251ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
7252ffe3c632Sopenharmony_ci        [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
7253ffe3c632Sopenharmony_ci      }
7254ffe3c632Sopenharmony_ci    }
7255ffe3c632Sopenharmony_ci  }
7256ffe3c632Sopenharmony_ci  return self;
7257ffe3c632Sopenharmony_ci}
7258ffe3c632Sopenharmony_ci
7259ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBInt64Int64Dictionary *)dictionary {
7260ffe3c632Sopenharmony_ci  self = [self initWithInt64s:NULL forKeys:NULL count:0];
7261ffe3c632Sopenharmony_ci  if (self) {
7262ffe3c632Sopenharmony_ci    if (dictionary) {
7263ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
7264ffe3c632Sopenharmony_ci    }
7265ffe3c632Sopenharmony_ci  }
7266ffe3c632Sopenharmony_ci  return self;
7267ffe3c632Sopenharmony_ci}
7268ffe3c632Sopenharmony_ci
7269ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
7270ffe3c632Sopenharmony_ci  #pragma unused(numItems)
7271ffe3c632Sopenharmony_ci  return [self initWithInt64s:NULL forKeys:NULL count:0];
7272ffe3c632Sopenharmony_ci}
7273ffe3c632Sopenharmony_ci
7274ffe3c632Sopenharmony_ci- (void)dealloc {
7275ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
7276ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
7277ffe3c632Sopenharmony_ci           [self class], _autocreator);
7278ffe3c632Sopenharmony_ci  [_dictionary release];
7279ffe3c632Sopenharmony_ci  [super dealloc];
7280ffe3c632Sopenharmony_ci}
7281ffe3c632Sopenharmony_ci
7282ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
7283ffe3c632Sopenharmony_ci  return [[GPBInt64Int64Dictionary allocWithZone:zone] initWithDictionary:self];
7284ffe3c632Sopenharmony_ci}
7285ffe3c632Sopenharmony_ci
7286ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
7287ffe3c632Sopenharmony_ci  if (self == other) {
7288ffe3c632Sopenharmony_ci    return YES;
7289ffe3c632Sopenharmony_ci  }
7290ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBInt64Int64Dictionary class]]) {
7291ffe3c632Sopenharmony_ci    return NO;
7292ffe3c632Sopenharmony_ci  }
7293ffe3c632Sopenharmony_ci  GPBInt64Int64Dictionary *otherDictionary = other;
7294ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
7295ffe3c632Sopenharmony_ci}
7296ffe3c632Sopenharmony_ci
7297ffe3c632Sopenharmony_ci- (NSUInteger)hash {
7298ffe3c632Sopenharmony_ci  return _dictionary.count;
7299ffe3c632Sopenharmony_ci}
7300ffe3c632Sopenharmony_ci
7301ffe3c632Sopenharmony_ci- (NSString *)description {
7302ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
7303ffe3c632Sopenharmony_ci}
7304ffe3c632Sopenharmony_ci
7305ffe3c632Sopenharmony_ci- (NSUInteger)count {
7306ffe3c632Sopenharmony_ci  return _dictionary.count;
7307ffe3c632Sopenharmony_ci}
7308ffe3c632Sopenharmony_ci
7309ffe3c632Sopenharmony_ci- (void)enumerateKeysAndInt64sUsingBlock:
7310ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(int64_t key, int64_t value, BOOL *stop))block {
7311ffe3c632Sopenharmony_ci  BOOL stop = NO;
7312ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
7313ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
7314ffe3c632Sopenharmony_ci  NSNumber *aKey;
7315ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
7316ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
7317ffe3c632Sopenharmony_ci    block([aKey longLongValue], [aValue longLongValue], &stop);
7318ffe3c632Sopenharmony_ci    if (stop) {
7319ffe3c632Sopenharmony_ci      break;
7320ffe3c632Sopenharmony_ci    }
7321ffe3c632Sopenharmony_ci  }
7322ffe3c632Sopenharmony_ci}
7323ffe3c632Sopenharmony_ci
7324ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
7325ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
7326ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
7327ffe3c632Sopenharmony_ci  if (count == 0) {
7328ffe3c632Sopenharmony_ci    return 0;
7329ffe3c632Sopenharmony_ci  }
7330ffe3c632Sopenharmony_ci
7331ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
7332ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
7333ffe3c632Sopenharmony_ci  size_t result = 0;
7334ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
7335ffe3c632Sopenharmony_ci  NSNumber *aKey;
7336ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
7337ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
7338ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
7339ffe3c632Sopenharmony_ci    msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
7340ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
7341ffe3c632Sopenharmony_ci  }
7342ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
7343ffe3c632Sopenharmony_ci  result += tagSize * count;
7344ffe3c632Sopenharmony_ci  return result;
7345ffe3c632Sopenharmony_ci}
7346ffe3c632Sopenharmony_ci
7347ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
7348ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
7349ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
7350ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
7351ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
7352ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
7353ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
7354ffe3c632Sopenharmony_ci  NSNumber *aKey;
7355ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
7356ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
7357ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
7358ffe3c632Sopenharmony_ci    // Write the size of the message.
7359ffe3c632Sopenharmony_ci    int64_t unwrappedKey = [aKey longLongValue];
7360ffe3c632Sopenharmony_ci    int64_t unwrappedValue = [aValue longLongValue];
7361ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
7362ffe3c632Sopenharmony_ci    msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
7363ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
7364ffe3c632Sopenharmony_ci    // Write the fields.
7365ffe3c632Sopenharmony_ci    WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
7366ffe3c632Sopenharmony_ci    WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
7367ffe3c632Sopenharmony_ci  }
7368ffe3c632Sopenharmony_ci}
7369ffe3c632Sopenharmony_ci
7370ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
7371ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
7372ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueInt64) forKey:@(key->valueInt64)];
7373ffe3c632Sopenharmony_ci}
7374ffe3c632Sopenharmony_ci
7375ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
7376ffe3c632Sopenharmony_ci  [self enumerateKeysAndInt64sUsingBlock:^(int64_t key, int64_t value, BOOL *stop) {
7377ffe3c632Sopenharmony_ci      #pragma unused(stop)
7378ffe3c632Sopenharmony_ci      block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%lld", value]);
7379ffe3c632Sopenharmony_ci  }];
7380ffe3c632Sopenharmony_ci}
7381ffe3c632Sopenharmony_ci
7382ffe3c632Sopenharmony_ci- (BOOL)getInt64:(nullable int64_t *)value forKey:(int64_t)key {
7383ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:@(key)];
7384ffe3c632Sopenharmony_ci  if (wrapped && value) {
7385ffe3c632Sopenharmony_ci    *value = [wrapped longLongValue];
7386ffe3c632Sopenharmony_ci  }
7387ffe3c632Sopenharmony_ci  return (wrapped != NULL);
7388ffe3c632Sopenharmony_ci}
7389ffe3c632Sopenharmony_ci
7390ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBInt64Int64Dictionary *)otherDictionary {
7391ffe3c632Sopenharmony_ci  if (otherDictionary) {
7392ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
7393ffe3c632Sopenharmony_ci    if (_autocreator) {
7394ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
7395ffe3c632Sopenharmony_ci    }
7396ffe3c632Sopenharmony_ci  }
7397ffe3c632Sopenharmony_ci}
7398ffe3c632Sopenharmony_ci
7399ffe3c632Sopenharmony_ci- (void)setInt64:(int64_t)value forKey:(int64_t)key {
7400ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:@(key)];
7401ffe3c632Sopenharmony_ci  if (_autocreator) {
7402ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
7403ffe3c632Sopenharmony_ci  }
7404ffe3c632Sopenharmony_ci}
7405ffe3c632Sopenharmony_ci
7406ffe3c632Sopenharmony_ci- (void)removeInt64ForKey:(int64_t)aKey {
7407ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:@(aKey)];
7408ffe3c632Sopenharmony_ci}
7409ffe3c632Sopenharmony_ci
7410ffe3c632Sopenharmony_ci- (void)removeAll {
7411ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
7412ffe3c632Sopenharmony_ci}
7413ffe3c632Sopenharmony_ci
7414ffe3c632Sopenharmony_ci@end
7415ffe3c632Sopenharmony_ci
7416ffe3c632Sopenharmony_ci#pragma mark - Int64 -> Bool
7417ffe3c632Sopenharmony_ci
7418ffe3c632Sopenharmony_ci@implementation GPBInt64BoolDictionary {
7419ffe3c632Sopenharmony_ci @package
7420ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
7421ffe3c632Sopenharmony_ci}
7422ffe3c632Sopenharmony_ci
7423ffe3c632Sopenharmony_ci- (instancetype)init {
7424ffe3c632Sopenharmony_ci  return [self initWithBools:NULL forKeys:NULL count:0];
7425ffe3c632Sopenharmony_ci}
7426ffe3c632Sopenharmony_ci
7427ffe3c632Sopenharmony_ci- (instancetype)initWithBools:(const BOOL [])values
7428ffe3c632Sopenharmony_ci                      forKeys:(const int64_t [])keys
7429ffe3c632Sopenharmony_ci                        count:(NSUInteger)count {
7430ffe3c632Sopenharmony_ci  self = [super init];
7431ffe3c632Sopenharmony_ci  if (self) {
7432ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
7433ffe3c632Sopenharmony_ci    if (count && values && keys) {
7434ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
7435ffe3c632Sopenharmony_ci        [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
7436ffe3c632Sopenharmony_ci      }
7437ffe3c632Sopenharmony_ci    }
7438ffe3c632Sopenharmony_ci  }
7439ffe3c632Sopenharmony_ci  return self;
7440ffe3c632Sopenharmony_ci}
7441ffe3c632Sopenharmony_ci
7442ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBInt64BoolDictionary *)dictionary {
7443ffe3c632Sopenharmony_ci  self = [self initWithBools:NULL forKeys:NULL count:0];
7444ffe3c632Sopenharmony_ci  if (self) {
7445ffe3c632Sopenharmony_ci    if (dictionary) {
7446ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
7447ffe3c632Sopenharmony_ci    }
7448ffe3c632Sopenharmony_ci  }
7449ffe3c632Sopenharmony_ci  return self;
7450ffe3c632Sopenharmony_ci}
7451ffe3c632Sopenharmony_ci
7452ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
7453ffe3c632Sopenharmony_ci  #pragma unused(numItems)
7454ffe3c632Sopenharmony_ci  return [self initWithBools:NULL forKeys:NULL count:0];
7455ffe3c632Sopenharmony_ci}
7456ffe3c632Sopenharmony_ci
7457ffe3c632Sopenharmony_ci- (void)dealloc {
7458ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
7459ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
7460ffe3c632Sopenharmony_ci           [self class], _autocreator);
7461ffe3c632Sopenharmony_ci  [_dictionary release];
7462ffe3c632Sopenharmony_ci  [super dealloc];
7463ffe3c632Sopenharmony_ci}
7464ffe3c632Sopenharmony_ci
7465ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
7466ffe3c632Sopenharmony_ci  return [[GPBInt64BoolDictionary allocWithZone:zone] initWithDictionary:self];
7467ffe3c632Sopenharmony_ci}
7468ffe3c632Sopenharmony_ci
7469ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
7470ffe3c632Sopenharmony_ci  if (self == other) {
7471ffe3c632Sopenharmony_ci    return YES;
7472ffe3c632Sopenharmony_ci  }
7473ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBInt64BoolDictionary class]]) {
7474ffe3c632Sopenharmony_ci    return NO;
7475ffe3c632Sopenharmony_ci  }
7476ffe3c632Sopenharmony_ci  GPBInt64BoolDictionary *otherDictionary = other;
7477ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
7478ffe3c632Sopenharmony_ci}
7479ffe3c632Sopenharmony_ci
7480ffe3c632Sopenharmony_ci- (NSUInteger)hash {
7481ffe3c632Sopenharmony_ci  return _dictionary.count;
7482ffe3c632Sopenharmony_ci}
7483ffe3c632Sopenharmony_ci
7484ffe3c632Sopenharmony_ci- (NSString *)description {
7485ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
7486ffe3c632Sopenharmony_ci}
7487ffe3c632Sopenharmony_ci
7488ffe3c632Sopenharmony_ci- (NSUInteger)count {
7489ffe3c632Sopenharmony_ci  return _dictionary.count;
7490ffe3c632Sopenharmony_ci}
7491ffe3c632Sopenharmony_ci
7492ffe3c632Sopenharmony_ci- (void)enumerateKeysAndBoolsUsingBlock:
7493ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(int64_t key, BOOL value, BOOL *stop))block {
7494ffe3c632Sopenharmony_ci  BOOL stop = NO;
7495ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
7496ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
7497ffe3c632Sopenharmony_ci  NSNumber *aKey;
7498ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
7499ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
7500ffe3c632Sopenharmony_ci    block([aKey longLongValue], [aValue boolValue], &stop);
7501ffe3c632Sopenharmony_ci    if (stop) {
7502ffe3c632Sopenharmony_ci      break;
7503ffe3c632Sopenharmony_ci    }
7504ffe3c632Sopenharmony_ci  }
7505ffe3c632Sopenharmony_ci}
7506ffe3c632Sopenharmony_ci
7507ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
7508ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
7509ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
7510ffe3c632Sopenharmony_ci  if (count == 0) {
7511ffe3c632Sopenharmony_ci    return 0;
7512ffe3c632Sopenharmony_ci  }
7513ffe3c632Sopenharmony_ci
7514ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
7515ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
7516ffe3c632Sopenharmony_ci  size_t result = 0;
7517ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
7518ffe3c632Sopenharmony_ci  NSNumber *aKey;
7519ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
7520ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
7521ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
7522ffe3c632Sopenharmony_ci    msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
7523ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
7524ffe3c632Sopenharmony_ci  }
7525ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
7526ffe3c632Sopenharmony_ci  result += tagSize * count;
7527ffe3c632Sopenharmony_ci  return result;
7528ffe3c632Sopenharmony_ci}
7529ffe3c632Sopenharmony_ci
7530ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
7531ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
7532ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
7533ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
7534ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
7535ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
7536ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
7537ffe3c632Sopenharmony_ci  NSNumber *aKey;
7538ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
7539ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
7540ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
7541ffe3c632Sopenharmony_ci    // Write the size of the message.
7542ffe3c632Sopenharmony_ci    int64_t unwrappedKey = [aKey longLongValue];
7543ffe3c632Sopenharmony_ci    BOOL unwrappedValue = [aValue boolValue];
7544ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
7545ffe3c632Sopenharmony_ci    msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
7546ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
7547ffe3c632Sopenharmony_ci    // Write the fields.
7548ffe3c632Sopenharmony_ci    WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
7549ffe3c632Sopenharmony_ci    WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
7550ffe3c632Sopenharmony_ci  }
7551ffe3c632Sopenharmony_ci}
7552ffe3c632Sopenharmony_ci
7553ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
7554ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
7555ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueBool) forKey:@(key->valueInt64)];
7556ffe3c632Sopenharmony_ci}
7557ffe3c632Sopenharmony_ci
7558ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
7559ffe3c632Sopenharmony_ci  [self enumerateKeysAndBoolsUsingBlock:^(int64_t key, BOOL value, BOOL *stop) {
7560ffe3c632Sopenharmony_ci      #pragma unused(stop)
7561ffe3c632Sopenharmony_ci      block([NSString stringWithFormat:@"%lld", key], (value ? @"true" : @"false"));
7562ffe3c632Sopenharmony_ci  }];
7563ffe3c632Sopenharmony_ci}
7564ffe3c632Sopenharmony_ci
7565ffe3c632Sopenharmony_ci- (BOOL)getBool:(nullable BOOL *)value forKey:(int64_t)key {
7566ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:@(key)];
7567ffe3c632Sopenharmony_ci  if (wrapped && value) {
7568ffe3c632Sopenharmony_ci    *value = [wrapped boolValue];
7569ffe3c632Sopenharmony_ci  }
7570ffe3c632Sopenharmony_ci  return (wrapped != NULL);
7571ffe3c632Sopenharmony_ci}
7572ffe3c632Sopenharmony_ci
7573ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBInt64BoolDictionary *)otherDictionary {
7574ffe3c632Sopenharmony_ci  if (otherDictionary) {
7575ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
7576ffe3c632Sopenharmony_ci    if (_autocreator) {
7577ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
7578ffe3c632Sopenharmony_ci    }
7579ffe3c632Sopenharmony_ci  }
7580ffe3c632Sopenharmony_ci}
7581ffe3c632Sopenharmony_ci
7582ffe3c632Sopenharmony_ci- (void)setBool:(BOOL)value forKey:(int64_t)key {
7583ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:@(key)];
7584ffe3c632Sopenharmony_ci  if (_autocreator) {
7585ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
7586ffe3c632Sopenharmony_ci  }
7587ffe3c632Sopenharmony_ci}
7588ffe3c632Sopenharmony_ci
7589ffe3c632Sopenharmony_ci- (void)removeBoolForKey:(int64_t)aKey {
7590ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:@(aKey)];
7591ffe3c632Sopenharmony_ci}
7592ffe3c632Sopenharmony_ci
7593ffe3c632Sopenharmony_ci- (void)removeAll {
7594ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
7595ffe3c632Sopenharmony_ci}
7596ffe3c632Sopenharmony_ci
7597ffe3c632Sopenharmony_ci@end
7598ffe3c632Sopenharmony_ci
7599ffe3c632Sopenharmony_ci#pragma mark - Int64 -> Float
7600ffe3c632Sopenharmony_ci
7601ffe3c632Sopenharmony_ci@implementation GPBInt64FloatDictionary {
7602ffe3c632Sopenharmony_ci @package
7603ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
7604ffe3c632Sopenharmony_ci}
7605ffe3c632Sopenharmony_ci
7606ffe3c632Sopenharmony_ci- (instancetype)init {
7607ffe3c632Sopenharmony_ci  return [self initWithFloats:NULL forKeys:NULL count:0];
7608ffe3c632Sopenharmony_ci}
7609ffe3c632Sopenharmony_ci
7610ffe3c632Sopenharmony_ci- (instancetype)initWithFloats:(const float [])values
7611ffe3c632Sopenharmony_ci                       forKeys:(const int64_t [])keys
7612ffe3c632Sopenharmony_ci                         count:(NSUInteger)count {
7613ffe3c632Sopenharmony_ci  self = [super init];
7614ffe3c632Sopenharmony_ci  if (self) {
7615ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
7616ffe3c632Sopenharmony_ci    if (count && values && keys) {
7617ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
7618ffe3c632Sopenharmony_ci        [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
7619ffe3c632Sopenharmony_ci      }
7620ffe3c632Sopenharmony_ci    }
7621ffe3c632Sopenharmony_ci  }
7622ffe3c632Sopenharmony_ci  return self;
7623ffe3c632Sopenharmony_ci}
7624ffe3c632Sopenharmony_ci
7625ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBInt64FloatDictionary *)dictionary {
7626ffe3c632Sopenharmony_ci  self = [self initWithFloats:NULL forKeys:NULL count:0];
7627ffe3c632Sopenharmony_ci  if (self) {
7628ffe3c632Sopenharmony_ci    if (dictionary) {
7629ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
7630ffe3c632Sopenharmony_ci    }
7631ffe3c632Sopenharmony_ci  }
7632ffe3c632Sopenharmony_ci  return self;
7633ffe3c632Sopenharmony_ci}
7634ffe3c632Sopenharmony_ci
7635ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
7636ffe3c632Sopenharmony_ci  #pragma unused(numItems)
7637ffe3c632Sopenharmony_ci  return [self initWithFloats:NULL forKeys:NULL count:0];
7638ffe3c632Sopenharmony_ci}
7639ffe3c632Sopenharmony_ci
7640ffe3c632Sopenharmony_ci- (void)dealloc {
7641ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
7642ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
7643ffe3c632Sopenharmony_ci           [self class], _autocreator);
7644ffe3c632Sopenharmony_ci  [_dictionary release];
7645ffe3c632Sopenharmony_ci  [super dealloc];
7646ffe3c632Sopenharmony_ci}
7647ffe3c632Sopenharmony_ci
7648ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
7649ffe3c632Sopenharmony_ci  return [[GPBInt64FloatDictionary allocWithZone:zone] initWithDictionary:self];
7650ffe3c632Sopenharmony_ci}
7651ffe3c632Sopenharmony_ci
7652ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
7653ffe3c632Sopenharmony_ci  if (self == other) {
7654ffe3c632Sopenharmony_ci    return YES;
7655ffe3c632Sopenharmony_ci  }
7656ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBInt64FloatDictionary class]]) {
7657ffe3c632Sopenharmony_ci    return NO;
7658ffe3c632Sopenharmony_ci  }
7659ffe3c632Sopenharmony_ci  GPBInt64FloatDictionary *otherDictionary = other;
7660ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
7661ffe3c632Sopenharmony_ci}
7662ffe3c632Sopenharmony_ci
7663ffe3c632Sopenharmony_ci- (NSUInteger)hash {
7664ffe3c632Sopenharmony_ci  return _dictionary.count;
7665ffe3c632Sopenharmony_ci}
7666ffe3c632Sopenharmony_ci
7667ffe3c632Sopenharmony_ci- (NSString *)description {
7668ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
7669ffe3c632Sopenharmony_ci}
7670ffe3c632Sopenharmony_ci
7671ffe3c632Sopenharmony_ci- (NSUInteger)count {
7672ffe3c632Sopenharmony_ci  return _dictionary.count;
7673ffe3c632Sopenharmony_ci}
7674ffe3c632Sopenharmony_ci
7675ffe3c632Sopenharmony_ci- (void)enumerateKeysAndFloatsUsingBlock:
7676ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(int64_t key, float value, BOOL *stop))block {
7677ffe3c632Sopenharmony_ci  BOOL stop = NO;
7678ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
7679ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
7680ffe3c632Sopenharmony_ci  NSNumber *aKey;
7681ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
7682ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
7683ffe3c632Sopenharmony_ci    block([aKey longLongValue], [aValue floatValue], &stop);
7684ffe3c632Sopenharmony_ci    if (stop) {
7685ffe3c632Sopenharmony_ci      break;
7686ffe3c632Sopenharmony_ci    }
7687ffe3c632Sopenharmony_ci  }
7688ffe3c632Sopenharmony_ci}
7689ffe3c632Sopenharmony_ci
7690ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
7691ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
7692ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
7693ffe3c632Sopenharmony_ci  if (count == 0) {
7694ffe3c632Sopenharmony_ci    return 0;
7695ffe3c632Sopenharmony_ci  }
7696ffe3c632Sopenharmony_ci
7697ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
7698ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
7699ffe3c632Sopenharmony_ci  size_t result = 0;
7700ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
7701ffe3c632Sopenharmony_ci  NSNumber *aKey;
7702ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
7703ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
7704ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
7705ffe3c632Sopenharmony_ci    msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
7706ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
7707ffe3c632Sopenharmony_ci  }
7708ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
7709ffe3c632Sopenharmony_ci  result += tagSize * count;
7710ffe3c632Sopenharmony_ci  return result;
7711ffe3c632Sopenharmony_ci}
7712ffe3c632Sopenharmony_ci
7713ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
7714ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
7715ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
7716ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
7717ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
7718ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
7719ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
7720ffe3c632Sopenharmony_ci  NSNumber *aKey;
7721ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
7722ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
7723ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
7724ffe3c632Sopenharmony_ci    // Write the size of the message.
7725ffe3c632Sopenharmony_ci    int64_t unwrappedKey = [aKey longLongValue];
7726ffe3c632Sopenharmony_ci    float unwrappedValue = [aValue floatValue];
7727ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
7728ffe3c632Sopenharmony_ci    msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
7729ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
7730ffe3c632Sopenharmony_ci    // Write the fields.
7731ffe3c632Sopenharmony_ci    WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
7732ffe3c632Sopenharmony_ci    WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
7733ffe3c632Sopenharmony_ci  }
7734ffe3c632Sopenharmony_ci}
7735ffe3c632Sopenharmony_ci
7736ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
7737ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
7738ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueFloat) forKey:@(key->valueInt64)];
7739ffe3c632Sopenharmony_ci}
7740ffe3c632Sopenharmony_ci
7741ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
7742ffe3c632Sopenharmony_ci  [self enumerateKeysAndFloatsUsingBlock:^(int64_t key, float value, BOOL *stop) {
7743ffe3c632Sopenharmony_ci      #pragma unused(stop)
7744ffe3c632Sopenharmony_ci      block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
7745ffe3c632Sopenharmony_ci  }];
7746ffe3c632Sopenharmony_ci}
7747ffe3c632Sopenharmony_ci
7748ffe3c632Sopenharmony_ci- (BOOL)getFloat:(nullable float *)value forKey:(int64_t)key {
7749ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:@(key)];
7750ffe3c632Sopenharmony_ci  if (wrapped && value) {
7751ffe3c632Sopenharmony_ci    *value = [wrapped floatValue];
7752ffe3c632Sopenharmony_ci  }
7753ffe3c632Sopenharmony_ci  return (wrapped != NULL);
7754ffe3c632Sopenharmony_ci}
7755ffe3c632Sopenharmony_ci
7756ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBInt64FloatDictionary *)otherDictionary {
7757ffe3c632Sopenharmony_ci  if (otherDictionary) {
7758ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
7759ffe3c632Sopenharmony_ci    if (_autocreator) {
7760ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
7761ffe3c632Sopenharmony_ci    }
7762ffe3c632Sopenharmony_ci  }
7763ffe3c632Sopenharmony_ci}
7764ffe3c632Sopenharmony_ci
7765ffe3c632Sopenharmony_ci- (void)setFloat:(float)value forKey:(int64_t)key {
7766ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:@(key)];
7767ffe3c632Sopenharmony_ci  if (_autocreator) {
7768ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
7769ffe3c632Sopenharmony_ci  }
7770ffe3c632Sopenharmony_ci}
7771ffe3c632Sopenharmony_ci
7772ffe3c632Sopenharmony_ci- (void)removeFloatForKey:(int64_t)aKey {
7773ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:@(aKey)];
7774ffe3c632Sopenharmony_ci}
7775ffe3c632Sopenharmony_ci
7776ffe3c632Sopenharmony_ci- (void)removeAll {
7777ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
7778ffe3c632Sopenharmony_ci}
7779ffe3c632Sopenharmony_ci
7780ffe3c632Sopenharmony_ci@end
7781ffe3c632Sopenharmony_ci
7782ffe3c632Sopenharmony_ci#pragma mark - Int64 -> Double
7783ffe3c632Sopenharmony_ci
7784ffe3c632Sopenharmony_ci@implementation GPBInt64DoubleDictionary {
7785ffe3c632Sopenharmony_ci @package
7786ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
7787ffe3c632Sopenharmony_ci}
7788ffe3c632Sopenharmony_ci
7789ffe3c632Sopenharmony_ci- (instancetype)init {
7790ffe3c632Sopenharmony_ci  return [self initWithDoubles:NULL forKeys:NULL count:0];
7791ffe3c632Sopenharmony_ci}
7792ffe3c632Sopenharmony_ci
7793ffe3c632Sopenharmony_ci- (instancetype)initWithDoubles:(const double [])values
7794ffe3c632Sopenharmony_ci                        forKeys:(const int64_t [])keys
7795ffe3c632Sopenharmony_ci                          count:(NSUInteger)count {
7796ffe3c632Sopenharmony_ci  self = [super init];
7797ffe3c632Sopenharmony_ci  if (self) {
7798ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
7799ffe3c632Sopenharmony_ci    if (count && values && keys) {
7800ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
7801ffe3c632Sopenharmony_ci        [_dictionary setObject:@(values[i]) forKey:@(keys[i])];
7802ffe3c632Sopenharmony_ci      }
7803ffe3c632Sopenharmony_ci    }
7804ffe3c632Sopenharmony_ci  }
7805ffe3c632Sopenharmony_ci  return self;
7806ffe3c632Sopenharmony_ci}
7807ffe3c632Sopenharmony_ci
7808ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBInt64DoubleDictionary *)dictionary {
7809ffe3c632Sopenharmony_ci  self = [self initWithDoubles:NULL forKeys:NULL count:0];
7810ffe3c632Sopenharmony_ci  if (self) {
7811ffe3c632Sopenharmony_ci    if (dictionary) {
7812ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
7813ffe3c632Sopenharmony_ci    }
7814ffe3c632Sopenharmony_ci  }
7815ffe3c632Sopenharmony_ci  return self;
7816ffe3c632Sopenharmony_ci}
7817ffe3c632Sopenharmony_ci
7818ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
7819ffe3c632Sopenharmony_ci  #pragma unused(numItems)
7820ffe3c632Sopenharmony_ci  return [self initWithDoubles:NULL forKeys:NULL count:0];
7821ffe3c632Sopenharmony_ci}
7822ffe3c632Sopenharmony_ci
7823ffe3c632Sopenharmony_ci- (void)dealloc {
7824ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
7825ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
7826ffe3c632Sopenharmony_ci           [self class], _autocreator);
7827ffe3c632Sopenharmony_ci  [_dictionary release];
7828ffe3c632Sopenharmony_ci  [super dealloc];
7829ffe3c632Sopenharmony_ci}
7830ffe3c632Sopenharmony_ci
7831ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
7832ffe3c632Sopenharmony_ci  return [[GPBInt64DoubleDictionary allocWithZone:zone] initWithDictionary:self];
7833ffe3c632Sopenharmony_ci}
7834ffe3c632Sopenharmony_ci
7835ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
7836ffe3c632Sopenharmony_ci  if (self == other) {
7837ffe3c632Sopenharmony_ci    return YES;
7838ffe3c632Sopenharmony_ci  }
7839ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBInt64DoubleDictionary class]]) {
7840ffe3c632Sopenharmony_ci    return NO;
7841ffe3c632Sopenharmony_ci  }
7842ffe3c632Sopenharmony_ci  GPBInt64DoubleDictionary *otherDictionary = other;
7843ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
7844ffe3c632Sopenharmony_ci}
7845ffe3c632Sopenharmony_ci
7846ffe3c632Sopenharmony_ci- (NSUInteger)hash {
7847ffe3c632Sopenharmony_ci  return _dictionary.count;
7848ffe3c632Sopenharmony_ci}
7849ffe3c632Sopenharmony_ci
7850ffe3c632Sopenharmony_ci- (NSString *)description {
7851ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
7852ffe3c632Sopenharmony_ci}
7853ffe3c632Sopenharmony_ci
7854ffe3c632Sopenharmony_ci- (NSUInteger)count {
7855ffe3c632Sopenharmony_ci  return _dictionary.count;
7856ffe3c632Sopenharmony_ci}
7857ffe3c632Sopenharmony_ci
7858ffe3c632Sopenharmony_ci- (void)enumerateKeysAndDoublesUsingBlock:
7859ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(int64_t key, double value, BOOL *stop))block {
7860ffe3c632Sopenharmony_ci  BOOL stop = NO;
7861ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
7862ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
7863ffe3c632Sopenharmony_ci  NSNumber *aKey;
7864ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
7865ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
7866ffe3c632Sopenharmony_ci    block([aKey longLongValue], [aValue doubleValue], &stop);
7867ffe3c632Sopenharmony_ci    if (stop) {
7868ffe3c632Sopenharmony_ci      break;
7869ffe3c632Sopenharmony_ci    }
7870ffe3c632Sopenharmony_ci  }
7871ffe3c632Sopenharmony_ci}
7872ffe3c632Sopenharmony_ci
7873ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
7874ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
7875ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
7876ffe3c632Sopenharmony_ci  if (count == 0) {
7877ffe3c632Sopenharmony_ci    return 0;
7878ffe3c632Sopenharmony_ci  }
7879ffe3c632Sopenharmony_ci
7880ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
7881ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
7882ffe3c632Sopenharmony_ci  size_t result = 0;
7883ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
7884ffe3c632Sopenharmony_ci  NSNumber *aKey;
7885ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
7886ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
7887ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
7888ffe3c632Sopenharmony_ci    msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
7889ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
7890ffe3c632Sopenharmony_ci  }
7891ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
7892ffe3c632Sopenharmony_ci  result += tagSize * count;
7893ffe3c632Sopenharmony_ci  return result;
7894ffe3c632Sopenharmony_ci}
7895ffe3c632Sopenharmony_ci
7896ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
7897ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
7898ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
7899ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
7900ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
7901ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
7902ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
7903ffe3c632Sopenharmony_ci  NSNumber *aKey;
7904ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
7905ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
7906ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
7907ffe3c632Sopenharmony_ci    // Write the size of the message.
7908ffe3c632Sopenharmony_ci    int64_t unwrappedKey = [aKey longLongValue];
7909ffe3c632Sopenharmony_ci    double unwrappedValue = [aValue doubleValue];
7910ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
7911ffe3c632Sopenharmony_ci    msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
7912ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
7913ffe3c632Sopenharmony_ci    // Write the fields.
7914ffe3c632Sopenharmony_ci    WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
7915ffe3c632Sopenharmony_ci    WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
7916ffe3c632Sopenharmony_ci  }
7917ffe3c632Sopenharmony_ci}
7918ffe3c632Sopenharmony_ci
7919ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
7920ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
7921ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueDouble) forKey:@(key->valueInt64)];
7922ffe3c632Sopenharmony_ci}
7923ffe3c632Sopenharmony_ci
7924ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
7925ffe3c632Sopenharmony_ci  [self enumerateKeysAndDoublesUsingBlock:^(int64_t key, double value, BOOL *stop) {
7926ffe3c632Sopenharmony_ci      #pragma unused(stop)
7927ffe3c632Sopenharmony_ci      block([NSString stringWithFormat:@"%lld", key], [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
7928ffe3c632Sopenharmony_ci  }];
7929ffe3c632Sopenharmony_ci}
7930ffe3c632Sopenharmony_ci
7931ffe3c632Sopenharmony_ci- (BOOL)getDouble:(nullable double *)value forKey:(int64_t)key {
7932ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:@(key)];
7933ffe3c632Sopenharmony_ci  if (wrapped && value) {
7934ffe3c632Sopenharmony_ci    *value = [wrapped doubleValue];
7935ffe3c632Sopenharmony_ci  }
7936ffe3c632Sopenharmony_ci  return (wrapped != NULL);
7937ffe3c632Sopenharmony_ci}
7938ffe3c632Sopenharmony_ci
7939ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBInt64DoubleDictionary *)otherDictionary {
7940ffe3c632Sopenharmony_ci  if (otherDictionary) {
7941ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
7942ffe3c632Sopenharmony_ci    if (_autocreator) {
7943ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
7944ffe3c632Sopenharmony_ci    }
7945ffe3c632Sopenharmony_ci  }
7946ffe3c632Sopenharmony_ci}
7947ffe3c632Sopenharmony_ci
7948ffe3c632Sopenharmony_ci- (void)setDouble:(double)value forKey:(int64_t)key {
7949ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:@(key)];
7950ffe3c632Sopenharmony_ci  if (_autocreator) {
7951ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
7952ffe3c632Sopenharmony_ci  }
7953ffe3c632Sopenharmony_ci}
7954ffe3c632Sopenharmony_ci
7955ffe3c632Sopenharmony_ci- (void)removeDoubleForKey:(int64_t)aKey {
7956ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:@(aKey)];
7957ffe3c632Sopenharmony_ci}
7958ffe3c632Sopenharmony_ci
7959ffe3c632Sopenharmony_ci- (void)removeAll {
7960ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
7961ffe3c632Sopenharmony_ci}
7962ffe3c632Sopenharmony_ci
7963ffe3c632Sopenharmony_ci@end
7964ffe3c632Sopenharmony_ci
7965ffe3c632Sopenharmony_ci#pragma mark - Int64 -> Enum
7966ffe3c632Sopenharmony_ci
7967ffe3c632Sopenharmony_ci@implementation GPBInt64EnumDictionary {
7968ffe3c632Sopenharmony_ci @package
7969ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
7970ffe3c632Sopenharmony_ci  GPBEnumValidationFunc _validationFunc;
7971ffe3c632Sopenharmony_ci}
7972ffe3c632Sopenharmony_ci
7973ffe3c632Sopenharmony_ci@synthesize validationFunc = _validationFunc;
7974ffe3c632Sopenharmony_ci
7975ffe3c632Sopenharmony_ci- (instancetype)init {
7976ffe3c632Sopenharmony_ci  return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
7977ffe3c632Sopenharmony_ci}
7978ffe3c632Sopenharmony_ci
7979ffe3c632Sopenharmony_ci- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
7980ffe3c632Sopenharmony_ci  return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
7981ffe3c632Sopenharmony_ci}
7982ffe3c632Sopenharmony_ci
7983ffe3c632Sopenharmony_ci- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
7984ffe3c632Sopenharmony_ci                                 rawValues:(const int32_t [])rawValues
7985ffe3c632Sopenharmony_ci                                   forKeys:(const int64_t [])keys
7986ffe3c632Sopenharmony_ci                                     count:(NSUInteger)count {
7987ffe3c632Sopenharmony_ci  self = [super init];
7988ffe3c632Sopenharmony_ci  if (self) {
7989ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
7990ffe3c632Sopenharmony_ci    _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
7991ffe3c632Sopenharmony_ci    if (count && rawValues && keys) {
7992ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
7993ffe3c632Sopenharmony_ci        [_dictionary setObject:@(rawValues[i]) forKey:@(keys[i])];
7994ffe3c632Sopenharmony_ci      }
7995ffe3c632Sopenharmony_ci    }
7996ffe3c632Sopenharmony_ci  }
7997ffe3c632Sopenharmony_ci  return self;
7998ffe3c632Sopenharmony_ci}
7999ffe3c632Sopenharmony_ci
8000ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBInt64EnumDictionary *)dictionary {
8001ffe3c632Sopenharmony_ci  self = [self initWithValidationFunction:dictionary.validationFunc
8002ffe3c632Sopenharmony_ci                                rawValues:NULL
8003ffe3c632Sopenharmony_ci                                  forKeys:NULL
8004ffe3c632Sopenharmony_ci                                    count:0];
8005ffe3c632Sopenharmony_ci  if (self) {
8006ffe3c632Sopenharmony_ci    if (dictionary) {
8007ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
8008ffe3c632Sopenharmony_ci    }
8009ffe3c632Sopenharmony_ci  }
8010ffe3c632Sopenharmony_ci  return self;
8011ffe3c632Sopenharmony_ci}
8012ffe3c632Sopenharmony_ci
8013ffe3c632Sopenharmony_ci- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
8014ffe3c632Sopenharmony_ci                                  capacity:(NSUInteger)numItems {
8015ffe3c632Sopenharmony_ci  #pragma unused(numItems)
8016ffe3c632Sopenharmony_ci  return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
8017ffe3c632Sopenharmony_ci}
8018ffe3c632Sopenharmony_ci
8019ffe3c632Sopenharmony_ci- (void)dealloc {
8020ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
8021ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
8022ffe3c632Sopenharmony_ci           [self class], _autocreator);
8023ffe3c632Sopenharmony_ci  [_dictionary release];
8024ffe3c632Sopenharmony_ci  [super dealloc];
8025ffe3c632Sopenharmony_ci}
8026ffe3c632Sopenharmony_ci
8027ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
8028ffe3c632Sopenharmony_ci  return [[GPBInt64EnumDictionary allocWithZone:zone] initWithDictionary:self];
8029ffe3c632Sopenharmony_ci}
8030ffe3c632Sopenharmony_ci
8031ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
8032ffe3c632Sopenharmony_ci  if (self == other) {
8033ffe3c632Sopenharmony_ci    return YES;
8034ffe3c632Sopenharmony_ci  }
8035ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBInt64EnumDictionary class]]) {
8036ffe3c632Sopenharmony_ci    return NO;
8037ffe3c632Sopenharmony_ci  }
8038ffe3c632Sopenharmony_ci  GPBInt64EnumDictionary *otherDictionary = other;
8039ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
8040ffe3c632Sopenharmony_ci}
8041ffe3c632Sopenharmony_ci
8042ffe3c632Sopenharmony_ci- (NSUInteger)hash {
8043ffe3c632Sopenharmony_ci  return _dictionary.count;
8044ffe3c632Sopenharmony_ci}
8045ffe3c632Sopenharmony_ci
8046ffe3c632Sopenharmony_ci- (NSString *)description {
8047ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
8048ffe3c632Sopenharmony_ci}
8049ffe3c632Sopenharmony_ci
8050ffe3c632Sopenharmony_ci- (NSUInteger)count {
8051ffe3c632Sopenharmony_ci  return _dictionary.count;
8052ffe3c632Sopenharmony_ci}
8053ffe3c632Sopenharmony_ci
8054ffe3c632Sopenharmony_ci- (void)enumerateKeysAndRawValuesUsingBlock:
8055ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(int64_t key, int32_t value, BOOL *stop))block {
8056ffe3c632Sopenharmony_ci  BOOL stop = NO;
8057ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
8058ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
8059ffe3c632Sopenharmony_ci  NSNumber *aKey;
8060ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
8061ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
8062ffe3c632Sopenharmony_ci    block([aKey longLongValue], [aValue intValue], &stop);
8063ffe3c632Sopenharmony_ci    if (stop) {
8064ffe3c632Sopenharmony_ci      break;
8065ffe3c632Sopenharmony_ci    }
8066ffe3c632Sopenharmony_ci  }
8067ffe3c632Sopenharmony_ci}
8068ffe3c632Sopenharmony_ci
8069ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
8070ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
8071ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
8072ffe3c632Sopenharmony_ci  if (count == 0) {
8073ffe3c632Sopenharmony_ci    return 0;
8074ffe3c632Sopenharmony_ci  }
8075ffe3c632Sopenharmony_ci
8076ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
8077ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
8078ffe3c632Sopenharmony_ci  size_t result = 0;
8079ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
8080ffe3c632Sopenharmony_ci  NSNumber *aKey;
8081ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
8082ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
8083ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
8084ffe3c632Sopenharmony_ci    msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
8085ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
8086ffe3c632Sopenharmony_ci  }
8087ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
8088ffe3c632Sopenharmony_ci  result += tagSize * count;
8089ffe3c632Sopenharmony_ci  return result;
8090ffe3c632Sopenharmony_ci}
8091ffe3c632Sopenharmony_ci
8092ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
8093ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
8094ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
8095ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
8096ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
8097ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
8098ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
8099ffe3c632Sopenharmony_ci  NSNumber *aKey;
8100ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
8101ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
8102ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
8103ffe3c632Sopenharmony_ci    // Write the size of the message.
8104ffe3c632Sopenharmony_ci    int64_t unwrappedKey = [aKey longLongValue];
8105ffe3c632Sopenharmony_ci    int32_t unwrappedValue = [aValue intValue];
8106ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
8107ffe3c632Sopenharmony_ci    msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
8108ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
8109ffe3c632Sopenharmony_ci    // Write the fields.
8110ffe3c632Sopenharmony_ci    WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
8111ffe3c632Sopenharmony_ci    WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
8112ffe3c632Sopenharmony_ci  }
8113ffe3c632Sopenharmony_ci}
8114ffe3c632Sopenharmony_ci
8115ffe3c632Sopenharmony_ci- (NSData *)serializedDataForUnknownValue:(int32_t)value
8116ffe3c632Sopenharmony_ci                                   forKey:(GPBGenericValue *)key
8117ffe3c632Sopenharmony_ci                              keyDataType:(GPBDataType)keyDataType {
8118ffe3c632Sopenharmony_ci  size_t msgSize = ComputeDictInt64FieldSize(key->valueInt64, kMapKeyFieldNumber, keyDataType);
8119ffe3c632Sopenharmony_ci  msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
8120ffe3c632Sopenharmony_ci  NSMutableData *data = [NSMutableData dataWithLength:msgSize];
8121ffe3c632Sopenharmony_ci  GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
8122ffe3c632Sopenharmony_ci  WriteDictInt64Field(outputStream, key->valueInt64, kMapKeyFieldNumber, keyDataType);
8123ffe3c632Sopenharmony_ci  WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
8124ffe3c632Sopenharmony_ci  [outputStream release];
8125ffe3c632Sopenharmony_ci  return data;
8126ffe3c632Sopenharmony_ci}
8127ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
8128ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
8129ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueEnum) forKey:@(key->valueInt64)];
8130ffe3c632Sopenharmony_ci}
8131ffe3c632Sopenharmony_ci
8132ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
8133ffe3c632Sopenharmony_ci  [self enumerateKeysAndRawValuesUsingBlock:^(int64_t key, int32_t value, BOOL *stop) {
8134ffe3c632Sopenharmony_ci      #pragma unused(stop)
8135ffe3c632Sopenharmony_ci      block([NSString stringWithFormat:@"%lld", key], @(value));
8136ffe3c632Sopenharmony_ci  }];
8137ffe3c632Sopenharmony_ci}
8138ffe3c632Sopenharmony_ci
8139ffe3c632Sopenharmony_ci- (BOOL)getEnum:(int32_t *)value forKey:(int64_t)key {
8140ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:@(key)];
8141ffe3c632Sopenharmony_ci  if (wrapped && value) {
8142ffe3c632Sopenharmony_ci    int32_t result = [wrapped intValue];
8143ffe3c632Sopenharmony_ci    if (!_validationFunc(result)) {
8144ffe3c632Sopenharmony_ci      result = kGPBUnrecognizedEnumeratorValue;
8145ffe3c632Sopenharmony_ci    }
8146ffe3c632Sopenharmony_ci    *value = result;
8147ffe3c632Sopenharmony_ci  }
8148ffe3c632Sopenharmony_ci  return (wrapped != NULL);
8149ffe3c632Sopenharmony_ci}
8150ffe3c632Sopenharmony_ci
8151ffe3c632Sopenharmony_ci- (BOOL)getRawValue:(int32_t *)rawValue forKey:(int64_t)key {
8152ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:@(key)];
8153ffe3c632Sopenharmony_ci  if (wrapped && rawValue) {
8154ffe3c632Sopenharmony_ci    *rawValue = [wrapped intValue];
8155ffe3c632Sopenharmony_ci  }
8156ffe3c632Sopenharmony_ci  return (wrapped != NULL);
8157ffe3c632Sopenharmony_ci}
8158ffe3c632Sopenharmony_ci
8159ffe3c632Sopenharmony_ci- (void)enumerateKeysAndEnumsUsingBlock:
8160ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(int64_t key, int32_t value, BOOL *stop))block {
8161ffe3c632Sopenharmony_ci  GPBEnumValidationFunc func = _validationFunc;
8162ffe3c632Sopenharmony_ci  BOOL stop = NO;
8163ffe3c632Sopenharmony_ci  NSEnumerator *keys = [_dictionary keyEnumerator];
8164ffe3c632Sopenharmony_ci  NSNumber *aKey;
8165ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
8166ffe3c632Sopenharmony_ci    NSNumber *aValue = _dictionary[aKey];
8167ffe3c632Sopenharmony_ci      int32_t unwrapped = [aValue intValue];
8168ffe3c632Sopenharmony_ci      if (!func(unwrapped)) {
8169ffe3c632Sopenharmony_ci        unwrapped = kGPBUnrecognizedEnumeratorValue;
8170ffe3c632Sopenharmony_ci      }
8171ffe3c632Sopenharmony_ci    block([aKey longLongValue], unwrapped, &stop);
8172ffe3c632Sopenharmony_ci    if (stop) {
8173ffe3c632Sopenharmony_ci      break;
8174ffe3c632Sopenharmony_ci    }
8175ffe3c632Sopenharmony_ci  }
8176ffe3c632Sopenharmony_ci}
8177ffe3c632Sopenharmony_ci
8178ffe3c632Sopenharmony_ci- (void)addRawEntriesFromDictionary:(GPBInt64EnumDictionary *)otherDictionary {
8179ffe3c632Sopenharmony_ci  if (otherDictionary) {
8180ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
8181ffe3c632Sopenharmony_ci    if (_autocreator) {
8182ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
8183ffe3c632Sopenharmony_ci    }
8184ffe3c632Sopenharmony_ci  }
8185ffe3c632Sopenharmony_ci}
8186ffe3c632Sopenharmony_ci
8187ffe3c632Sopenharmony_ci- (void)setRawValue:(int32_t)value forKey:(int64_t)key {
8188ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:@(key)];
8189ffe3c632Sopenharmony_ci  if (_autocreator) {
8190ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
8191ffe3c632Sopenharmony_ci  }
8192ffe3c632Sopenharmony_ci}
8193ffe3c632Sopenharmony_ci
8194ffe3c632Sopenharmony_ci- (void)removeEnumForKey:(int64_t)aKey {
8195ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:@(aKey)];
8196ffe3c632Sopenharmony_ci}
8197ffe3c632Sopenharmony_ci
8198ffe3c632Sopenharmony_ci- (void)removeAll {
8199ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
8200ffe3c632Sopenharmony_ci}
8201ffe3c632Sopenharmony_ci
8202ffe3c632Sopenharmony_ci- (void)setEnum:(int32_t)value forKey:(int64_t)key {
8203ffe3c632Sopenharmony_ci  if (!_validationFunc(value)) {
8204ffe3c632Sopenharmony_ci    [NSException raise:NSInvalidArgumentException
8205ffe3c632Sopenharmony_ci                format:@"GPBInt64EnumDictionary: Attempt to set an unknown enum value (%d)",
8206ffe3c632Sopenharmony_ci                       value];
8207ffe3c632Sopenharmony_ci  }
8208ffe3c632Sopenharmony_ci
8209ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:@(key)];
8210ffe3c632Sopenharmony_ci  if (_autocreator) {
8211ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
8212ffe3c632Sopenharmony_ci  }
8213ffe3c632Sopenharmony_ci}
8214ffe3c632Sopenharmony_ci
8215ffe3c632Sopenharmony_ci@end
8216ffe3c632Sopenharmony_ci
8217ffe3c632Sopenharmony_ci#pragma mark - Int64 -> Object
8218ffe3c632Sopenharmony_ci
8219ffe3c632Sopenharmony_ci@implementation GPBInt64ObjectDictionary {
8220ffe3c632Sopenharmony_ci @package
8221ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
8222ffe3c632Sopenharmony_ci}
8223ffe3c632Sopenharmony_ci
8224ffe3c632Sopenharmony_ci- (instancetype)init {
8225ffe3c632Sopenharmony_ci  return [self initWithObjects:NULL forKeys:NULL count:0];
8226ffe3c632Sopenharmony_ci}
8227ffe3c632Sopenharmony_ci
8228ffe3c632Sopenharmony_ci- (instancetype)initWithObjects:(const id [])objects
8229ffe3c632Sopenharmony_ci                        forKeys:(const int64_t [])keys
8230ffe3c632Sopenharmony_ci                          count:(NSUInteger)count {
8231ffe3c632Sopenharmony_ci  self = [super init];
8232ffe3c632Sopenharmony_ci  if (self) {
8233ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
8234ffe3c632Sopenharmony_ci    if (count && objects && keys) {
8235ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
8236ffe3c632Sopenharmony_ci        if (!objects[i]) {
8237ffe3c632Sopenharmony_ci          [NSException raise:NSInvalidArgumentException
8238ffe3c632Sopenharmony_ci                      format:@"Attempting to add nil object to a Dictionary"];
8239ffe3c632Sopenharmony_ci        }
8240ffe3c632Sopenharmony_ci        [_dictionary setObject:objects[i] forKey:@(keys[i])];
8241ffe3c632Sopenharmony_ci      }
8242ffe3c632Sopenharmony_ci    }
8243ffe3c632Sopenharmony_ci  }
8244ffe3c632Sopenharmony_ci  return self;
8245ffe3c632Sopenharmony_ci}
8246ffe3c632Sopenharmony_ci
8247ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBInt64ObjectDictionary *)dictionary {
8248ffe3c632Sopenharmony_ci  self = [self initWithObjects:NULL forKeys:NULL count:0];
8249ffe3c632Sopenharmony_ci  if (self) {
8250ffe3c632Sopenharmony_ci    if (dictionary) {
8251ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
8252ffe3c632Sopenharmony_ci    }
8253ffe3c632Sopenharmony_ci  }
8254ffe3c632Sopenharmony_ci  return self;
8255ffe3c632Sopenharmony_ci}
8256ffe3c632Sopenharmony_ci
8257ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
8258ffe3c632Sopenharmony_ci  #pragma unused(numItems)
8259ffe3c632Sopenharmony_ci  return [self initWithObjects:NULL forKeys:NULL count:0];
8260ffe3c632Sopenharmony_ci}
8261ffe3c632Sopenharmony_ci
8262ffe3c632Sopenharmony_ci- (void)dealloc {
8263ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
8264ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
8265ffe3c632Sopenharmony_ci           [self class], _autocreator);
8266ffe3c632Sopenharmony_ci  [_dictionary release];
8267ffe3c632Sopenharmony_ci  [super dealloc];
8268ffe3c632Sopenharmony_ci}
8269ffe3c632Sopenharmony_ci
8270ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
8271ffe3c632Sopenharmony_ci  return [[GPBInt64ObjectDictionary allocWithZone:zone] initWithDictionary:self];
8272ffe3c632Sopenharmony_ci}
8273ffe3c632Sopenharmony_ci
8274ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
8275ffe3c632Sopenharmony_ci  if (self == other) {
8276ffe3c632Sopenharmony_ci    return YES;
8277ffe3c632Sopenharmony_ci  }
8278ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBInt64ObjectDictionary class]]) {
8279ffe3c632Sopenharmony_ci    return NO;
8280ffe3c632Sopenharmony_ci  }
8281ffe3c632Sopenharmony_ci  GPBInt64ObjectDictionary *otherDictionary = other;
8282ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
8283ffe3c632Sopenharmony_ci}
8284ffe3c632Sopenharmony_ci
8285ffe3c632Sopenharmony_ci- (NSUInteger)hash {
8286ffe3c632Sopenharmony_ci  return _dictionary.count;
8287ffe3c632Sopenharmony_ci}
8288ffe3c632Sopenharmony_ci
8289ffe3c632Sopenharmony_ci- (NSString *)description {
8290ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
8291ffe3c632Sopenharmony_ci}
8292ffe3c632Sopenharmony_ci
8293ffe3c632Sopenharmony_ci- (NSUInteger)count {
8294ffe3c632Sopenharmony_ci  return _dictionary.count;
8295ffe3c632Sopenharmony_ci}
8296ffe3c632Sopenharmony_ci
8297ffe3c632Sopenharmony_ci- (void)enumerateKeysAndObjectsUsingBlock:
8298ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(int64_t key, id object, BOOL *stop))block {
8299ffe3c632Sopenharmony_ci  BOOL stop = NO;
8300ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
8301ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
8302ffe3c632Sopenharmony_ci  NSNumber *aKey;
8303ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
8304ffe3c632Sopenharmony_ci    id aObject = internal[aKey];
8305ffe3c632Sopenharmony_ci    block([aKey longLongValue], aObject, &stop);
8306ffe3c632Sopenharmony_ci    if (stop) {
8307ffe3c632Sopenharmony_ci      break;
8308ffe3c632Sopenharmony_ci    }
8309ffe3c632Sopenharmony_ci  }
8310ffe3c632Sopenharmony_ci}
8311ffe3c632Sopenharmony_ci
8312ffe3c632Sopenharmony_ci- (BOOL)isInitialized {
8313ffe3c632Sopenharmony_ci  for (GPBMessage *msg in [_dictionary objectEnumerator]) {
8314ffe3c632Sopenharmony_ci    if (!msg.initialized) {
8315ffe3c632Sopenharmony_ci      return NO;
8316ffe3c632Sopenharmony_ci    }
8317ffe3c632Sopenharmony_ci  }
8318ffe3c632Sopenharmony_ci  return YES;
8319ffe3c632Sopenharmony_ci}
8320ffe3c632Sopenharmony_ci
8321ffe3c632Sopenharmony_ci- (instancetype)deepCopyWithZone:(NSZone *)zone {
8322ffe3c632Sopenharmony_ci  GPBInt64ObjectDictionary *newDict =
8323ffe3c632Sopenharmony_ci      [[GPBInt64ObjectDictionary alloc] init];
8324ffe3c632Sopenharmony_ci  NSEnumerator *keys = [_dictionary keyEnumerator];
8325ffe3c632Sopenharmony_ci  id aKey;
8326ffe3c632Sopenharmony_ci  NSMutableDictionary *internalDict = newDict->_dictionary;
8327ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
8328ffe3c632Sopenharmony_ci    GPBMessage *msg = _dictionary[aKey];
8329ffe3c632Sopenharmony_ci    GPBMessage *copiedMsg = [msg copyWithZone:zone];
8330ffe3c632Sopenharmony_ci    [internalDict setObject:copiedMsg forKey:aKey];
8331ffe3c632Sopenharmony_ci    [copiedMsg release];
8332ffe3c632Sopenharmony_ci  }
8333ffe3c632Sopenharmony_ci  return newDict;
8334ffe3c632Sopenharmony_ci}
8335ffe3c632Sopenharmony_ci
8336ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
8337ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
8338ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
8339ffe3c632Sopenharmony_ci  if (count == 0) {
8340ffe3c632Sopenharmony_ci    return 0;
8341ffe3c632Sopenharmony_ci  }
8342ffe3c632Sopenharmony_ci
8343ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
8344ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
8345ffe3c632Sopenharmony_ci  size_t result = 0;
8346ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
8347ffe3c632Sopenharmony_ci  NSNumber *aKey;
8348ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
8349ffe3c632Sopenharmony_ci    id aObject = internal[aKey];
8350ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictInt64FieldSize([aKey longLongValue], kMapKeyFieldNumber, keyDataType);
8351ffe3c632Sopenharmony_ci    msgSize += ComputeDictObjectFieldSize(aObject, kMapValueFieldNumber, valueDataType);
8352ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
8353ffe3c632Sopenharmony_ci  }
8354ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
8355ffe3c632Sopenharmony_ci  result += tagSize * count;
8356ffe3c632Sopenharmony_ci  return result;
8357ffe3c632Sopenharmony_ci}
8358ffe3c632Sopenharmony_ci
8359ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
8360ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
8361ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
8362ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
8363ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
8364ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
8365ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
8366ffe3c632Sopenharmony_ci  NSNumber *aKey;
8367ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
8368ffe3c632Sopenharmony_ci    id aObject = internal[aKey];
8369ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
8370ffe3c632Sopenharmony_ci    // Write the size of the message.
8371ffe3c632Sopenharmony_ci    int64_t unwrappedKey = [aKey longLongValue];
8372ffe3c632Sopenharmony_ci    id unwrappedValue = aObject;
8373ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictInt64FieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
8374ffe3c632Sopenharmony_ci    msgSize += ComputeDictObjectFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
8375ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
8376ffe3c632Sopenharmony_ci    // Write the fields.
8377ffe3c632Sopenharmony_ci    WriteDictInt64Field(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
8378ffe3c632Sopenharmony_ci    WriteDictObjectField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
8379ffe3c632Sopenharmony_ci  }
8380ffe3c632Sopenharmony_ci}
8381ffe3c632Sopenharmony_ci
8382ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
8383ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
8384ffe3c632Sopenharmony_ci  [_dictionary setObject:value->valueString forKey:@(key->valueInt64)];
8385ffe3c632Sopenharmony_ci}
8386ffe3c632Sopenharmony_ci
8387ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
8388ffe3c632Sopenharmony_ci  [self enumerateKeysAndObjectsUsingBlock:^(int64_t key, id object, BOOL *stop) {
8389ffe3c632Sopenharmony_ci      #pragma unused(stop)
8390ffe3c632Sopenharmony_ci      block([NSString stringWithFormat:@"%lld", key], object);
8391ffe3c632Sopenharmony_ci  }];
8392ffe3c632Sopenharmony_ci}
8393ffe3c632Sopenharmony_ci
8394ffe3c632Sopenharmony_ci- (id)objectForKey:(int64_t)key {
8395ffe3c632Sopenharmony_ci  id result = [_dictionary objectForKey:@(key)];
8396ffe3c632Sopenharmony_ci  return result;
8397ffe3c632Sopenharmony_ci}
8398ffe3c632Sopenharmony_ci
8399ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBInt64ObjectDictionary *)otherDictionary {
8400ffe3c632Sopenharmony_ci  if (otherDictionary) {
8401ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
8402ffe3c632Sopenharmony_ci    if (_autocreator) {
8403ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
8404ffe3c632Sopenharmony_ci    }
8405ffe3c632Sopenharmony_ci  }
8406ffe3c632Sopenharmony_ci}
8407ffe3c632Sopenharmony_ci
8408ffe3c632Sopenharmony_ci- (void)setObject:(id)object forKey:(int64_t)key {
8409ffe3c632Sopenharmony_ci  if (!object) {
8410ffe3c632Sopenharmony_ci    [NSException raise:NSInvalidArgumentException
8411ffe3c632Sopenharmony_ci                format:@"Attempting to add nil object to a Dictionary"];
8412ffe3c632Sopenharmony_ci  }
8413ffe3c632Sopenharmony_ci  [_dictionary setObject:object forKey:@(key)];
8414ffe3c632Sopenharmony_ci  if (_autocreator) {
8415ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
8416ffe3c632Sopenharmony_ci  }
8417ffe3c632Sopenharmony_ci}
8418ffe3c632Sopenharmony_ci
8419ffe3c632Sopenharmony_ci- (void)removeObjectForKey:(int64_t)aKey {
8420ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:@(aKey)];
8421ffe3c632Sopenharmony_ci}
8422ffe3c632Sopenharmony_ci
8423ffe3c632Sopenharmony_ci- (void)removeAll {
8424ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
8425ffe3c632Sopenharmony_ci}
8426ffe3c632Sopenharmony_ci
8427ffe3c632Sopenharmony_ci@end
8428ffe3c632Sopenharmony_ci
8429ffe3c632Sopenharmony_ci// clang-format on
8430ffe3c632Sopenharmony_ci//%PDDM-EXPAND DICTIONARY_POD_IMPL_FOR_KEY(String, NSString, *, OBJECT)
8431ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly.
8432ffe3c632Sopenharmony_ci// clang-format off
8433ffe3c632Sopenharmony_ci
8434ffe3c632Sopenharmony_ci#pragma mark - String -> UInt32
8435ffe3c632Sopenharmony_ci
8436ffe3c632Sopenharmony_ci@implementation GPBStringUInt32Dictionary {
8437ffe3c632Sopenharmony_ci @package
8438ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
8439ffe3c632Sopenharmony_ci}
8440ffe3c632Sopenharmony_ci
8441ffe3c632Sopenharmony_ci- (instancetype)init {
8442ffe3c632Sopenharmony_ci  return [self initWithUInt32s:NULL forKeys:NULL count:0];
8443ffe3c632Sopenharmony_ci}
8444ffe3c632Sopenharmony_ci
8445ffe3c632Sopenharmony_ci- (instancetype)initWithUInt32s:(const uint32_t [])values
8446ffe3c632Sopenharmony_ci                        forKeys:(const NSString * [])keys
8447ffe3c632Sopenharmony_ci                          count:(NSUInteger)count {
8448ffe3c632Sopenharmony_ci  self = [super init];
8449ffe3c632Sopenharmony_ci  if (self) {
8450ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
8451ffe3c632Sopenharmony_ci    if (count && values && keys) {
8452ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
8453ffe3c632Sopenharmony_ci        if (!keys[i]) {
8454ffe3c632Sopenharmony_ci          [NSException raise:NSInvalidArgumentException
8455ffe3c632Sopenharmony_ci                      format:@"Attempting to add nil key to a Dictionary"];
8456ffe3c632Sopenharmony_ci        }
8457ffe3c632Sopenharmony_ci        [_dictionary setObject:@(values[i]) forKey:keys[i]];
8458ffe3c632Sopenharmony_ci      }
8459ffe3c632Sopenharmony_ci    }
8460ffe3c632Sopenharmony_ci  }
8461ffe3c632Sopenharmony_ci  return self;
8462ffe3c632Sopenharmony_ci}
8463ffe3c632Sopenharmony_ci
8464ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBStringUInt32Dictionary *)dictionary {
8465ffe3c632Sopenharmony_ci  self = [self initWithUInt32s:NULL forKeys:NULL count:0];
8466ffe3c632Sopenharmony_ci  if (self) {
8467ffe3c632Sopenharmony_ci    if (dictionary) {
8468ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
8469ffe3c632Sopenharmony_ci    }
8470ffe3c632Sopenharmony_ci  }
8471ffe3c632Sopenharmony_ci  return self;
8472ffe3c632Sopenharmony_ci}
8473ffe3c632Sopenharmony_ci
8474ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
8475ffe3c632Sopenharmony_ci  #pragma unused(numItems)
8476ffe3c632Sopenharmony_ci  return [self initWithUInt32s:NULL forKeys:NULL count:0];
8477ffe3c632Sopenharmony_ci}
8478ffe3c632Sopenharmony_ci
8479ffe3c632Sopenharmony_ci- (void)dealloc {
8480ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
8481ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
8482ffe3c632Sopenharmony_ci           [self class], _autocreator);
8483ffe3c632Sopenharmony_ci  [_dictionary release];
8484ffe3c632Sopenharmony_ci  [super dealloc];
8485ffe3c632Sopenharmony_ci}
8486ffe3c632Sopenharmony_ci
8487ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
8488ffe3c632Sopenharmony_ci  return [[GPBStringUInt32Dictionary allocWithZone:zone] initWithDictionary:self];
8489ffe3c632Sopenharmony_ci}
8490ffe3c632Sopenharmony_ci
8491ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
8492ffe3c632Sopenharmony_ci  if (self == other) {
8493ffe3c632Sopenharmony_ci    return YES;
8494ffe3c632Sopenharmony_ci  }
8495ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBStringUInt32Dictionary class]]) {
8496ffe3c632Sopenharmony_ci    return NO;
8497ffe3c632Sopenharmony_ci  }
8498ffe3c632Sopenharmony_ci  GPBStringUInt32Dictionary *otherDictionary = other;
8499ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
8500ffe3c632Sopenharmony_ci}
8501ffe3c632Sopenharmony_ci
8502ffe3c632Sopenharmony_ci- (NSUInteger)hash {
8503ffe3c632Sopenharmony_ci  return _dictionary.count;
8504ffe3c632Sopenharmony_ci}
8505ffe3c632Sopenharmony_ci
8506ffe3c632Sopenharmony_ci- (NSString *)description {
8507ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
8508ffe3c632Sopenharmony_ci}
8509ffe3c632Sopenharmony_ci
8510ffe3c632Sopenharmony_ci- (NSUInteger)count {
8511ffe3c632Sopenharmony_ci  return _dictionary.count;
8512ffe3c632Sopenharmony_ci}
8513ffe3c632Sopenharmony_ci
8514ffe3c632Sopenharmony_ci- (void)enumerateKeysAndUInt32sUsingBlock:
8515ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(NSString *key, uint32_t value, BOOL *stop))block {
8516ffe3c632Sopenharmony_ci  BOOL stop = NO;
8517ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
8518ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
8519ffe3c632Sopenharmony_ci  NSString *aKey;
8520ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
8521ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
8522ffe3c632Sopenharmony_ci    block(aKey, [aValue unsignedIntValue], &stop);
8523ffe3c632Sopenharmony_ci    if (stop) {
8524ffe3c632Sopenharmony_ci      break;
8525ffe3c632Sopenharmony_ci    }
8526ffe3c632Sopenharmony_ci  }
8527ffe3c632Sopenharmony_ci}
8528ffe3c632Sopenharmony_ci
8529ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
8530ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
8531ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
8532ffe3c632Sopenharmony_ci  if (count == 0) {
8533ffe3c632Sopenharmony_ci    return 0;
8534ffe3c632Sopenharmony_ci  }
8535ffe3c632Sopenharmony_ci
8536ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
8537ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
8538ffe3c632Sopenharmony_ci  size_t result = 0;
8539ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
8540ffe3c632Sopenharmony_ci  NSString *aKey;
8541ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
8542ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
8543ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
8544ffe3c632Sopenharmony_ci    msgSize += ComputeDictUInt32FieldSize([aValue unsignedIntValue], kMapValueFieldNumber, valueDataType);
8545ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
8546ffe3c632Sopenharmony_ci  }
8547ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
8548ffe3c632Sopenharmony_ci  result += tagSize * count;
8549ffe3c632Sopenharmony_ci  return result;
8550ffe3c632Sopenharmony_ci}
8551ffe3c632Sopenharmony_ci
8552ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
8553ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
8554ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
8555ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
8556ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
8557ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
8558ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
8559ffe3c632Sopenharmony_ci  NSString *aKey;
8560ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
8561ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
8562ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
8563ffe3c632Sopenharmony_ci    // Write the size of the message.
8564ffe3c632Sopenharmony_ci    NSString *unwrappedKey = aKey;
8565ffe3c632Sopenharmony_ci    uint32_t unwrappedValue = [aValue unsignedIntValue];
8566ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
8567ffe3c632Sopenharmony_ci    msgSize += ComputeDictUInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
8568ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
8569ffe3c632Sopenharmony_ci    // Write the fields.
8570ffe3c632Sopenharmony_ci    WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
8571ffe3c632Sopenharmony_ci    WriteDictUInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
8572ffe3c632Sopenharmony_ci  }
8573ffe3c632Sopenharmony_ci}
8574ffe3c632Sopenharmony_ci
8575ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
8576ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
8577ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueUInt32) forKey:key->valueString];
8578ffe3c632Sopenharmony_ci}
8579ffe3c632Sopenharmony_ci
8580ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
8581ffe3c632Sopenharmony_ci  [self enumerateKeysAndUInt32sUsingBlock:^(NSString *key, uint32_t value, BOOL *stop) {
8582ffe3c632Sopenharmony_ci      #pragma unused(stop)
8583ffe3c632Sopenharmony_ci      block(key, [NSString stringWithFormat:@"%u", value]);
8584ffe3c632Sopenharmony_ci  }];
8585ffe3c632Sopenharmony_ci}
8586ffe3c632Sopenharmony_ci
8587ffe3c632Sopenharmony_ci- (BOOL)getUInt32:(nullable uint32_t *)value forKey:(NSString *)key {
8588ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:key];
8589ffe3c632Sopenharmony_ci  if (wrapped && value) {
8590ffe3c632Sopenharmony_ci    *value = [wrapped unsignedIntValue];
8591ffe3c632Sopenharmony_ci  }
8592ffe3c632Sopenharmony_ci  return (wrapped != NULL);
8593ffe3c632Sopenharmony_ci}
8594ffe3c632Sopenharmony_ci
8595ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBStringUInt32Dictionary *)otherDictionary {
8596ffe3c632Sopenharmony_ci  if (otherDictionary) {
8597ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
8598ffe3c632Sopenharmony_ci    if (_autocreator) {
8599ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
8600ffe3c632Sopenharmony_ci    }
8601ffe3c632Sopenharmony_ci  }
8602ffe3c632Sopenharmony_ci}
8603ffe3c632Sopenharmony_ci
8604ffe3c632Sopenharmony_ci- (void)setUInt32:(uint32_t)value forKey:(NSString *)key {
8605ffe3c632Sopenharmony_ci  if (!key) {
8606ffe3c632Sopenharmony_ci    [NSException raise:NSInvalidArgumentException
8607ffe3c632Sopenharmony_ci                format:@"Attempting to add nil key to a Dictionary"];
8608ffe3c632Sopenharmony_ci  }
8609ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:key];
8610ffe3c632Sopenharmony_ci  if (_autocreator) {
8611ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
8612ffe3c632Sopenharmony_ci  }
8613ffe3c632Sopenharmony_ci}
8614ffe3c632Sopenharmony_ci
8615ffe3c632Sopenharmony_ci- (void)removeUInt32ForKey:(NSString *)aKey {
8616ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:aKey];
8617ffe3c632Sopenharmony_ci}
8618ffe3c632Sopenharmony_ci
8619ffe3c632Sopenharmony_ci- (void)removeAll {
8620ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
8621ffe3c632Sopenharmony_ci}
8622ffe3c632Sopenharmony_ci
8623ffe3c632Sopenharmony_ci@end
8624ffe3c632Sopenharmony_ci
8625ffe3c632Sopenharmony_ci#pragma mark - String -> Int32
8626ffe3c632Sopenharmony_ci
8627ffe3c632Sopenharmony_ci@implementation GPBStringInt32Dictionary {
8628ffe3c632Sopenharmony_ci @package
8629ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
8630ffe3c632Sopenharmony_ci}
8631ffe3c632Sopenharmony_ci
8632ffe3c632Sopenharmony_ci- (instancetype)init {
8633ffe3c632Sopenharmony_ci  return [self initWithInt32s:NULL forKeys:NULL count:0];
8634ffe3c632Sopenharmony_ci}
8635ffe3c632Sopenharmony_ci
8636ffe3c632Sopenharmony_ci- (instancetype)initWithInt32s:(const int32_t [])values
8637ffe3c632Sopenharmony_ci                       forKeys:(const NSString * [])keys
8638ffe3c632Sopenharmony_ci                         count:(NSUInteger)count {
8639ffe3c632Sopenharmony_ci  self = [super init];
8640ffe3c632Sopenharmony_ci  if (self) {
8641ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
8642ffe3c632Sopenharmony_ci    if (count && values && keys) {
8643ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
8644ffe3c632Sopenharmony_ci        if (!keys[i]) {
8645ffe3c632Sopenharmony_ci          [NSException raise:NSInvalidArgumentException
8646ffe3c632Sopenharmony_ci                      format:@"Attempting to add nil key to a Dictionary"];
8647ffe3c632Sopenharmony_ci        }
8648ffe3c632Sopenharmony_ci        [_dictionary setObject:@(values[i]) forKey:keys[i]];
8649ffe3c632Sopenharmony_ci      }
8650ffe3c632Sopenharmony_ci    }
8651ffe3c632Sopenharmony_ci  }
8652ffe3c632Sopenharmony_ci  return self;
8653ffe3c632Sopenharmony_ci}
8654ffe3c632Sopenharmony_ci
8655ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBStringInt32Dictionary *)dictionary {
8656ffe3c632Sopenharmony_ci  self = [self initWithInt32s:NULL forKeys:NULL count:0];
8657ffe3c632Sopenharmony_ci  if (self) {
8658ffe3c632Sopenharmony_ci    if (dictionary) {
8659ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
8660ffe3c632Sopenharmony_ci    }
8661ffe3c632Sopenharmony_ci  }
8662ffe3c632Sopenharmony_ci  return self;
8663ffe3c632Sopenharmony_ci}
8664ffe3c632Sopenharmony_ci
8665ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
8666ffe3c632Sopenharmony_ci  #pragma unused(numItems)
8667ffe3c632Sopenharmony_ci  return [self initWithInt32s:NULL forKeys:NULL count:0];
8668ffe3c632Sopenharmony_ci}
8669ffe3c632Sopenharmony_ci
8670ffe3c632Sopenharmony_ci- (void)dealloc {
8671ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
8672ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
8673ffe3c632Sopenharmony_ci           [self class], _autocreator);
8674ffe3c632Sopenharmony_ci  [_dictionary release];
8675ffe3c632Sopenharmony_ci  [super dealloc];
8676ffe3c632Sopenharmony_ci}
8677ffe3c632Sopenharmony_ci
8678ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
8679ffe3c632Sopenharmony_ci  return [[GPBStringInt32Dictionary allocWithZone:zone] initWithDictionary:self];
8680ffe3c632Sopenharmony_ci}
8681ffe3c632Sopenharmony_ci
8682ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
8683ffe3c632Sopenharmony_ci  if (self == other) {
8684ffe3c632Sopenharmony_ci    return YES;
8685ffe3c632Sopenharmony_ci  }
8686ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBStringInt32Dictionary class]]) {
8687ffe3c632Sopenharmony_ci    return NO;
8688ffe3c632Sopenharmony_ci  }
8689ffe3c632Sopenharmony_ci  GPBStringInt32Dictionary *otherDictionary = other;
8690ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
8691ffe3c632Sopenharmony_ci}
8692ffe3c632Sopenharmony_ci
8693ffe3c632Sopenharmony_ci- (NSUInteger)hash {
8694ffe3c632Sopenharmony_ci  return _dictionary.count;
8695ffe3c632Sopenharmony_ci}
8696ffe3c632Sopenharmony_ci
8697ffe3c632Sopenharmony_ci- (NSString *)description {
8698ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
8699ffe3c632Sopenharmony_ci}
8700ffe3c632Sopenharmony_ci
8701ffe3c632Sopenharmony_ci- (NSUInteger)count {
8702ffe3c632Sopenharmony_ci  return _dictionary.count;
8703ffe3c632Sopenharmony_ci}
8704ffe3c632Sopenharmony_ci
8705ffe3c632Sopenharmony_ci- (void)enumerateKeysAndInt32sUsingBlock:
8706ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(NSString *key, int32_t value, BOOL *stop))block {
8707ffe3c632Sopenharmony_ci  BOOL stop = NO;
8708ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
8709ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
8710ffe3c632Sopenharmony_ci  NSString *aKey;
8711ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
8712ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
8713ffe3c632Sopenharmony_ci    block(aKey, [aValue intValue], &stop);
8714ffe3c632Sopenharmony_ci    if (stop) {
8715ffe3c632Sopenharmony_ci      break;
8716ffe3c632Sopenharmony_ci    }
8717ffe3c632Sopenharmony_ci  }
8718ffe3c632Sopenharmony_ci}
8719ffe3c632Sopenharmony_ci
8720ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
8721ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
8722ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
8723ffe3c632Sopenharmony_ci  if (count == 0) {
8724ffe3c632Sopenharmony_ci    return 0;
8725ffe3c632Sopenharmony_ci  }
8726ffe3c632Sopenharmony_ci
8727ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
8728ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
8729ffe3c632Sopenharmony_ci  size_t result = 0;
8730ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
8731ffe3c632Sopenharmony_ci  NSString *aKey;
8732ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
8733ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
8734ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
8735ffe3c632Sopenharmony_ci    msgSize += ComputeDictInt32FieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
8736ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
8737ffe3c632Sopenharmony_ci  }
8738ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
8739ffe3c632Sopenharmony_ci  result += tagSize * count;
8740ffe3c632Sopenharmony_ci  return result;
8741ffe3c632Sopenharmony_ci}
8742ffe3c632Sopenharmony_ci
8743ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
8744ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
8745ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
8746ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
8747ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
8748ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
8749ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
8750ffe3c632Sopenharmony_ci  NSString *aKey;
8751ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
8752ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
8753ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
8754ffe3c632Sopenharmony_ci    // Write the size of the message.
8755ffe3c632Sopenharmony_ci    NSString *unwrappedKey = aKey;
8756ffe3c632Sopenharmony_ci    int32_t unwrappedValue = [aValue intValue];
8757ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
8758ffe3c632Sopenharmony_ci    msgSize += ComputeDictInt32FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
8759ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
8760ffe3c632Sopenharmony_ci    // Write the fields.
8761ffe3c632Sopenharmony_ci    WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
8762ffe3c632Sopenharmony_ci    WriteDictInt32Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
8763ffe3c632Sopenharmony_ci  }
8764ffe3c632Sopenharmony_ci}
8765ffe3c632Sopenharmony_ci
8766ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
8767ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
8768ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueInt32) forKey:key->valueString];
8769ffe3c632Sopenharmony_ci}
8770ffe3c632Sopenharmony_ci
8771ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
8772ffe3c632Sopenharmony_ci  [self enumerateKeysAndInt32sUsingBlock:^(NSString *key, int32_t value, BOOL *stop) {
8773ffe3c632Sopenharmony_ci      #pragma unused(stop)
8774ffe3c632Sopenharmony_ci      block(key, [NSString stringWithFormat:@"%d", value]);
8775ffe3c632Sopenharmony_ci  }];
8776ffe3c632Sopenharmony_ci}
8777ffe3c632Sopenharmony_ci
8778ffe3c632Sopenharmony_ci- (BOOL)getInt32:(nullable int32_t *)value forKey:(NSString *)key {
8779ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:key];
8780ffe3c632Sopenharmony_ci  if (wrapped && value) {
8781ffe3c632Sopenharmony_ci    *value = [wrapped intValue];
8782ffe3c632Sopenharmony_ci  }
8783ffe3c632Sopenharmony_ci  return (wrapped != NULL);
8784ffe3c632Sopenharmony_ci}
8785ffe3c632Sopenharmony_ci
8786ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBStringInt32Dictionary *)otherDictionary {
8787ffe3c632Sopenharmony_ci  if (otherDictionary) {
8788ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
8789ffe3c632Sopenharmony_ci    if (_autocreator) {
8790ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
8791ffe3c632Sopenharmony_ci    }
8792ffe3c632Sopenharmony_ci  }
8793ffe3c632Sopenharmony_ci}
8794ffe3c632Sopenharmony_ci
8795ffe3c632Sopenharmony_ci- (void)setInt32:(int32_t)value forKey:(NSString *)key {
8796ffe3c632Sopenharmony_ci  if (!key) {
8797ffe3c632Sopenharmony_ci    [NSException raise:NSInvalidArgumentException
8798ffe3c632Sopenharmony_ci                format:@"Attempting to add nil key to a Dictionary"];
8799ffe3c632Sopenharmony_ci  }
8800ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:key];
8801ffe3c632Sopenharmony_ci  if (_autocreator) {
8802ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
8803ffe3c632Sopenharmony_ci  }
8804ffe3c632Sopenharmony_ci}
8805ffe3c632Sopenharmony_ci
8806ffe3c632Sopenharmony_ci- (void)removeInt32ForKey:(NSString *)aKey {
8807ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:aKey];
8808ffe3c632Sopenharmony_ci}
8809ffe3c632Sopenharmony_ci
8810ffe3c632Sopenharmony_ci- (void)removeAll {
8811ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
8812ffe3c632Sopenharmony_ci}
8813ffe3c632Sopenharmony_ci
8814ffe3c632Sopenharmony_ci@end
8815ffe3c632Sopenharmony_ci
8816ffe3c632Sopenharmony_ci#pragma mark - String -> UInt64
8817ffe3c632Sopenharmony_ci
8818ffe3c632Sopenharmony_ci@implementation GPBStringUInt64Dictionary {
8819ffe3c632Sopenharmony_ci @package
8820ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
8821ffe3c632Sopenharmony_ci}
8822ffe3c632Sopenharmony_ci
8823ffe3c632Sopenharmony_ci- (instancetype)init {
8824ffe3c632Sopenharmony_ci  return [self initWithUInt64s:NULL forKeys:NULL count:0];
8825ffe3c632Sopenharmony_ci}
8826ffe3c632Sopenharmony_ci
8827ffe3c632Sopenharmony_ci- (instancetype)initWithUInt64s:(const uint64_t [])values
8828ffe3c632Sopenharmony_ci                        forKeys:(const NSString * [])keys
8829ffe3c632Sopenharmony_ci                          count:(NSUInteger)count {
8830ffe3c632Sopenharmony_ci  self = [super init];
8831ffe3c632Sopenharmony_ci  if (self) {
8832ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
8833ffe3c632Sopenharmony_ci    if (count && values && keys) {
8834ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
8835ffe3c632Sopenharmony_ci        if (!keys[i]) {
8836ffe3c632Sopenharmony_ci          [NSException raise:NSInvalidArgumentException
8837ffe3c632Sopenharmony_ci                      format:@"Attempting to add nil key to a Dictionary"];
8838ffe3c632Sopenharmony_ci        }
8839ffe3c632Sopenharmony_ci        [_dictionary setObject:@(values[i]) forKey:keys[i]];
8840ffe3c632Sopenharmony_ci      }
8841ffe3c632Sopenharmony_ci    }
8842ffe3c632Sopenharmony_ci  }
8843ffe3c632Sopenharmony_ci  return self;
8844ffe3c632Sopenharmony_ci}
8845ffe3c632Sopenharmony_ci
8846ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBStringUInt64Dictionary *)dictionary {
8847ffe3c632Sopenharmony_ci  self = [self initWithUInt64s:NULL forKeys:NULL count:0];
8848ffe3c632Sopenharmony_ci  if (self) {
8849ffe3c632Sopenharmony_ci    if (dictionary) {
8850ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
8851ffe3c632Sopenharmony_ci    }
8852ffe3c632Sopenharmony_ci  }
8853ffe3c632Sopenharmony_ci  return self;
8854ffe3c632Sopenharmony_ci}
8855ffe3c632Sopenharmony_ci
8856ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
8857ffe3c632Sopenharmony_ci  #pragma unused(numItems)
8858ffe3c632Sopenharmony_ci  return [self initWithUInt64s:NULL forKeys:NULL count:0];
8859ffe3c632Sopenharmony_ci}
8860ffe3c632Sopenharmony_ci
8861ffe3c632Sopenharmony_ci- (void)dealloc {
8862ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
8863ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
8864ffe3c632Sopenharmony_ci           [self class], _autocreator);
8865ffe3c632Sopenharmony_ci  [_dictionary release];
8866ffe3c632Sopenharmony_ci  [super dealloc];
8867ffe3c632Sopenharmony_ci}
8868ffe3c632Sopenharmony_ci
8869ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
8870ffe3c632Sopenharmony_ci  return [[GPBStringUInt64Dictionary allocWithZone:zone] initWithDictionary:self];
8871ffe3c632Sopenharmony_ci}
8872ffe3c632Sopenharmony_ci
8873ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
8874ffe3c632Sopenharmony_ci  if (self == other) {
8875ffe3c632Sopenharmony_ci    return YES;
8876ffe3c632Sopenharmony_ci  }
8877ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBStringUInt64Dictionary class]]) {
8878ffe3c632Sopenharmony_ci    return NO;
8879ffe3c632Sopenharmony_ci  }
8880ffe3c632Sopenharmony_ci  GPBStringUInt64Dictionary *otherDictionary = other;
8881ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
8882ffe3c632Sopenharmony_ci}
8883ffe3c632Sopenharmony_ci
8884ffe3c632Sopenharmony_ci- (NSUInteger)hash {
8885ffe3c632Sopenharmony_ci  return _dictionary.count;
8886ffe3c632Sopenharmony_ci}
8887ffe3c632Sopenharmony_ci
8888ffe3c632Sopenharmony_ci- (NSString *)description {
8889ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
8890ffe3c632Sopenharmony_ci}
8891ffe3c632Sopenharmony_ci
8892ffe3c632Sopenharmony_ci- (NSUInteger)count {
8893ffe3c632Sopenharmony_ci  return _dictionary.count;
8894ffe3c632Sopenharmony_ci}
8895ffe3c632Sopenharmony_ci
8896ffe3c632Sopenharmony_ci- (void)enumerateKeysAndUInt64sUsingBlock:
8897ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(NSString *key, uint64_t value, BOOL *stop))block {
8898ffe3c632Sopenharmony_ci  BOOL stop = NO;
8899ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
8900ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
8901ffe3c632Sopenharmony_ci  NSString *aKey;
8902ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
8903ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
8904ffe3c632Sopenharmony_ci    block(aKey, [aValue unsignedLongLongValue], &stop);
8905ffe3c632Sopenharmony_ci    if (stop) {
8906ffe3c632Sopenharmony_ci      break;
8907ffe3c632Sopenharmony_ci    }
8908ffe3c632Sopenharmony_ci  }
8909ffe3c632Sopenharmony_ci}
8910ffe3c632Sopenharmony_ci
8911ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
8912ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
8913ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
8914ffe3c632Sopenharmony_ci  if (count == 0) {
8915ffe3c632Sopenharmony_ci    return 0;
8916ffe3c632Sopenharmony_ci  }
8917ffe3c632Sopenharmony_ci
8918ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
8919ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
8920ffe3c632Sopenharmony_ci  size_t result = 0;
8921ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
8922ffe3c632Sopenharmony_ci  NSString *aKey;
8923ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
8924ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
8925ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
8926ffe3c632Sopenharmony_ci    msgSize += ComputeDictUInt64FieldSize([aValue unsignedLongLongValue], kMapValueFieldNumber, valueDataType);
8927ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
8928ffe3c632Sopenharmony_ci  }
8929ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
8930ffe3c632Sopenharmony_ci  result += tagSize * count;
8931ffe3c632Sopenharmony_ci  return result;
8932ffe3c632Sopenharmony_ci}
8933ffe3c632Sopenharmony_ci
8934ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
8935ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
8936ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
8937ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
8938ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
8939ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
8940ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
8941ffe3c632Sopenharmony_ci  NSString *aKey;
8942ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
8943ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
8944ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
8945ffe3c632Sopenharmony_ci    // Write the size of the message.
8946ffe3c632Sopenharmony_ci    NSString *unwrappedKey = aKey;
8947ffe3c632Sopenharmony_ci    uint64_t unwrappedValue = [aValue unsignedLongLongValue];
8948ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
8949ffe3c632Sopenharmony_ci    msgSize += ComputeDictUInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
8950ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
8951ffe3c632Sopenharmony_ci    // Write the fields.
8952ffe3c632Sopenharmony_ci    WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
8953ffe3c632Sopenharmony_ci    WriteDictUInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
8954ffe3c632Sopenharmony_ci  }
8955ffe3c632Sopenharmony_ci}
8956ffe3c632Sopenharmony_ci
8957ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
8958ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
8959ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueUInt64) forKey:key->valueString];
8960ffe3c632Sopenharmony_ci}
8961ffe3c632Sopenharmony_ci
8962ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
8963ffe3c632Sopenharmony_ci  [self enumerateKeysAndUInt64sUsingBlock:^(NSString *key, uint64_t value, BOOL *stop) {
8964ffe3c632Sopenharmony_ci      #pragma unused(stop)
8965ffe3c632Sopenharmony_ci      block(key, [NSString stringWithFormat:@"%llu", value]);
8966ffe3c632Sopenharmony_ci  }];
8967ffe3c632Sopenharmony_ci}
8968ffe3c632Sopenharmony_ci
8969ffe3c632Sopenharmony_ci- (BOOL)getUInt64:(nullable uint64_t *)value forKey:(NSString *)key {
8970ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:key];
8971ffe3c632Sopenharmony_ci  if (wrapped && value) {
8972ffe3c632Sopenharmony_ci    *value = [wrapped unsignedLongLongValue];
8973ffe3c632Sopenharmony_ci  }
8974ffe3c632Sopenharmony_ci  return (wrapped != NULL);
8975ffe3c632Sopenharmony_ci}
8976ffe3c632Sopenharmony_ci
8977ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBStringUInt64Dictionary *)otherDictionary {
8978ffe3c632Sopenharmony_ci  if (otherDictionary) {
8979ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
8980ffe3c632Sopenharmony_ci    if (_autocreator) {
8981ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
8982ffe3c632Sopenharmony_ci    }
8983ffe3c632Sopenharmony_ci  }
8984ffe3c632Sopenharmony_ci}
8985ffe3c632Sopenharmony_ci
8986ffe3c632Sopenharmony_ci- (void)setUInt64:(uint64_t)value forKey:(NSString *)key {
8987ffe3c632Sopenharmony_ci  if (!key) {
8988ffe3c632Sopenharmony_ci    [NSException raise:NSInvalidArgumentException
8989ffe3c632Sopenharmony_ci                format:@"Attempting to add nil key to a Dictionary"];
8990ffe3c632Sopenharmony_ci  }
8991ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:key];
8992ffe3c632Sopenharmony_ci  if (_autocreator) {
8993ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
8994ffe3c632Sopenharmony_ci  }
8995ffe3c632Sopenharmony_ci}
8996ffe3c632Sopenharmony_ci
8997ffe3c632Sopenharmony_ci- (void)removeUInt64ForKey:(NSString *)aKey {
8998ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:aKey];
8999ffe3c632Sopenharmony_ci}
9000ffe3c632Sopenharmony_ci
9001ffe3c632Sopenharmony_ci- (void)removeAll {
9002ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
9003ffe3c632Sopenharmony_ci}
9004ffe3c632Sopenharmony_ci
9005ffe3c632Sopenharmony_ci@end
9006ffe3c632Sopenharmony_ci
9007ffe3c632Sopenharmony_ci#pragma mark - String -> Int64
9008ffe3c632Sopenharmony_ci
9009ffe3c632Sopenharmony_ci@implementation GPBStringInt64Dictionary {
9010ffe3c632Sopenharmony_ci @package
9011ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
9012ffe3c632Sopenharmony_ci}
9013ffe3c632Sopenharmony_ci
9014ffe3c632Sopenharmony_ci- (instancetype)init {
9015ffe3c632Sopenharmony_ci  return [self initWithInt64s:NULL forKeys:NULL count:0];
9016ffe3c632Sopenharmony_ci}
9017ffe3c632Sopenharmony_ci
9018ffe3c632Sopenharmony_ci- (instancetype)initWithInt64s:(const int64_t [])values
9019ffe3c632Sopenharmony_ci                       forKeys:(const NSString * [])keys
9020ffe3c632Sopenharmony_ci                         count:(NSUInteger)count {
9021ffe3c632Sopenharmony_ci  self = [super init];
9022ffe3c632Sopenharmony_ci  if (self) {
9023ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
9024ffe3c632Sopenharmony_ci    if (count && values && keys) {
9025ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
9026ffe3c632Sopenharmony_ci        if (!keys[i]) {
9027ffe3c632Sopenharmony_ci          [NSException raise:NSInvalidArgumentException
9028ffe3c632Sopenharmony_ci                      format:@"Attempting to add nil key to a Dictionary"];
9029ffe3c632Sopenharmony_ci        }
9030ffe3c632Sopenharmony_ci        [_dictionary setObject:@(values[i]) forKey:keys[i]];
9031ffe3c632Sopenharmony_ci      }
9032ffe3c632Sopenharmony_ci    }
9033ffe3c632Sopenharmony_ci  }
9034ffe3c632Sopenharmony_ci  return self;
9035ffe3c632Sopenharmony_ci}
9036ffe3c632Sopenharmony_ci
9037ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBStringInt64Dictionary *)dictionary {
9038ffe3c632Sopenharmony_ci  self = [self initWithInt64s:NULL forKeys:NULL count:0];
9039ffe3c632Sopenharmony_ci  if (self) {
9040ffe3c632Sopenharmony_ci    if (dictionary) {
9041ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
9042ffe3c632Sopenharmony_ci    }
9043ffe3c632Sopenharmony_ci  }
9044ffe3c632Sopenharmony_ci  return self;
9045ffe3c632Sopenharmony_ci}
9046ffe3c632Sopenharmony_ci
9047ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
9048ffe3c632Sopenharmony_ci  #pragma unused(numItems)
9049ffe3c632Sopenharmony_ci  return [self initWithInt64s:NULL forKeys:NULL count:0];
9050ffe3c632Sopenharmony_ci}
9051ffe3c632Sopenharmony_ci
9052ffe3c632Sopenharmony_ci- (void)dealloc {
9053ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
9054ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
9055ffe3c632Sopenharmony_ci           [self class], _autocreator);
9056ffe3c632Sopenharmony_ci  [_dictionary release];
9057ffe3c632Sopenharmony_ci  [super dealloc];
9058ffe3c632Sopenharmony_ci}
9059ffe3c632Sopenharmony_ci
9060ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
9061ffe3c632Sopenharmony_ci  return [[GPBStringInt64Dictionary allocWithZone:zone] initWithDictionary:self];
9062ffe3c632Sopenharmony_ci}
9063ffe3c632Sopenharmony_ci
9064ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
9065ffe3c632Sopenharmony_ci  if (self == other) {
9066ffe3c632Sopenharmony_ci    return YES;
9067ffe3c632Sopenharmony_ci  }
9068ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBStringInt64Dictionary class]]) {
9069ffe3c632Sopenharmony_ci    return NO;
9070ffe3c632Sopenharmony_ci  }
9071ffe3c632Sopenharmony_ci  GPBStringInt64Dictionary *otherDictionary = other;
9072ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
9073ffe3c632Sopenharmony_ci}
9074ffe3c632Sopenharmony_ci
9075ffe3c632Sopenharmony_ci- (NSUInteger)hash {
9076ffe3c632Sopenharmony_ci  return _dictionary.count;
9077ffe3c632Sopenharmony_ci}
9078ffe3c632Sopenharmony_ci
9079ffe3c632Sopenharmony_ci- (NSString *)description {
9080ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
9081ffe3c632Sopenharmony_ci}
9082ffe3c632Sopenharmony_ci
9083ffe3c632Sopenharmony_ci- (NSUInteger)count {
9084ffe3c632Sopenharmony_ci  return _dictionary.count;
9085ffe3c632Sopenharmony_ci}
9086ffe3c632Sopenharmony_ci
9087ffe3c632Sopenharmony_ci- (void)enumerateKeysAndInt64sUsingBlock:
9088ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(NSString *key, int64_t value, BOOL *stop))block {
9089ffe3c632Sopenharmony_ci  BOOL stop = NO;
9090ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
9091ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
9092ffe3c632Sopenharmony_ci  NSString *aKey;
9093ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
9094ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
9095ffe3c632Sopenharmony_ci    block(aKey, [aValue longLongValue], &stop);
9096ffe3c632Sopenharmony_ci    if (stop) {
9097ffe3c632Sopenharmony_ci      break;
9098ffe3c632Sopenharmony_ci    }
9099ffe3c632Sopenharmony_ci  }
9100ffe3c632Sopenharmony_ci}
9101ffe3c632Sopenharmony_ci
9102ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
9103ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
9104ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
9105ffe3c632Sopenharmony_ci  if (count == 0) {
9106ffe3c632Sopenharmony_ci    return 0;
9107ffe3c632Sopenharmony_ci  }
9108ffe3c632Sopenharmony_ci
9109ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
9110ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
9111ffe3c632Sopenharmony_ci  size_t result = 0;
9112ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
9113ffe3c632Sopenharmony_ci  NSString *aKey;
9114ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
9115ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
9116ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
9117ffe3c632Sopenharmony_ci    msgSize += ComputeDictInt64FieldSize([aValue longLongValue], kMapValueFieldNumber, valueDataType);
9118ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
9119ffe3c632Sopenharmony_ci  }
9120ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
9121ffe3c632Sopenharmony_ci  result += tagSize * count;
9122ffe3c632Sopenharmony_ci  return result;
9123ffe3c632Sopenharmony_ci}
9124ffe3c632Sopenharmony_ci
9125ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
9126ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
9127ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
9128ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
9129ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
9130ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
9131ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
9132ffe3c632Sopenharmony_ci  NSString *aKey;
9133ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
9134ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
9135ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
9136ffe3c632Sopenharmony_ci    // Write the size of the message.
9137ffe3c632Sopenharmony_ci    NSString *unwrappedKey = aKey;
9138ffe3c632Sopenharmony_ci    int64_t unwrappedValue = [aValue longLongValue];
9139ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
9140ffe3c632Sopenharmony_ci    msgSize += ComputeDictInt64FieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
9141ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
9142ffe3c632Sopenharmony_ci    // Write the fields.
9143ffe3c632Sopenharmony_ci    WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
9144ffe3c632Sopenharmony_ci    WriteDictInt64Field(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
9145ffe3c632Sopenharmony_ci  }
9146ffe3c632Sopenharmony_ci}
9147ffe3c632Sopenharmony_ci
9148ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
9149ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
9150ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueInt64) forKey:key->valueString];
9151ffe3c632Sopenharmony_ci}
9152ffe3c632Sopenharmony_ci
9153ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
9154ffe3c632Sopenharmony_ci  [self enumerateKeysAndInt64sUsingBlock:^(NSString *key, int64_t value, BOOL *stop) {
9155ffe3c632Sopenharmony_ci      #pragma unused(stop)
9156ffe3c632Sopenharmony_ci      block(key, [NSString stringWithFormat:@"%lld", value]);
9157ffe3c632Sopenharmony_ci  }];
9158ffe3c632Sopenharmony_ci}
9159ffe3c632Sopenharmony_ci
9160ffe3c632Sopenharmony_ci- (BOOL)getInt64:(nullable int64_t *)value forKey:(NSString *)key {
9161ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:key];
9162ffe3c632Sopenharmony_ci  if (wrapped && value) {
9163ffe3c632Sopenharmony_ci    *value = [wrapped longLongValue];
9164ffe3c632Sopenharmony_ci  }
9165ffe3c632Sopenharmony_ci  return (wrapped != NULL);
9166ffe3c632Sopenharmony_ci}
9167ffe3c632Sopenharmony_ci
9168ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBStringInt64Dictionary *)otherDictionary {
9169ffe3c632Sopenharmony_ci  if (otherDictionary) {
9170ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
9171ffe3c632Sopenharmony_ci    if (_autocreator) {
9172ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
9173ffe3c632Sopenharmony_ci    }
9174ffe3c632Sopenharmony_ci  }
9175ffe3c632Sopenharmony_ci}
9176ffe3c632Sopenharmony_ci
9177ffe3c632Sopenharmony_ci- (void)setInt64:(int64_t)value forKey:(NSString *)key {
9178ffe3c632Sopenharmony_ci  if (!key) {
9179ffe3c632Sopenharmony_ci    [NSException raise:NSInvalidArgumentException
9180ffe3c632Sopenharmony_ci                format:@"Attempting to add nil key to a Dictionary"];
9181ffe3c632Sopenharmony_ci  }
9182ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:key];
9183ffe3c632Sopenharmony_ci  if (_autocreator) {
9184ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
9185ffe3c632Sopenharmony_ci  }
9186ffe3c632Sopenharmony_ci}
9187ffe3c632Sopenharmony_ci
9188ffe3c632Sopenharmony_ci- (void)removeInt64ForKey:(NSString *)aKey {
9189ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:aKey];
9190ffe3c632Sopenharmony_ci}
9191ffe3c632Sopenharmony_ci
9192ffe3c632Sopenharmony_ci- (void)removeAll {
9193ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
9194ffe3c632Sopenharmony_ci}
9195ffe3c632Sopenharmony_ci
9196ffe3c632Sopenharmony_ci@end
9197ffe3c632Sopenharmony_ci
9198ffe3c632Sopenharmony_ci#pragma mark - String -> Bool
9199ffe3c632Sopenharmony_ci
9200ffe3c632Sopenharmony_ci@implementation GPBStringBoolDictionary {
9201ffe3c632Sopenharmony_ci @package
9202ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
9203ffe3c632Sopenharmony_ci}
9204ffe3c632Sopenharmony_ci
9205ffe3c632Sopenharmony_ci- (instancetype)init {
9206ffe3c632Sopenharmony_ci  return [self initWithBools:NULL forKeys:NULL count:0];
9207ffe3c632Sopenharmony_ci}
9208ffe3c632Sopenharmony_ci
9209ffe3c632Sopenharmony_ci- (instancetype)initWithBools:(const BOOL [])values
9210ffe3c632Sopenharmony_ci                      forKeys:(const NSString * [])keys
9211ffe3c632Sopenharmony_ci                        count:(NSUInteger)count {
9212ffe3c632Sopenharmony_ci  self = [super init];
9213ffe3c632Sopenharmony_ci  if (self) {
9214ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
9215ffe3c632Sopenharmony_ci    if (count && values && keys) {
9216ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
9217ffe3c632Sopenharmony_ci        if (!keys[i]) {
9218ffe3c632Sopenharmony_ci          [NSException raise:NSInvalidArgumentException
9219ffe3c632Sopenharmony_ci                      format:@"Attempting to add nil key to a Dictionary"];
9220ffe3c632Sopenharmony_ci        }
9221ffe3c632Sopenharmony_ci        [_dictionary setObject:@(values[i]) forKey:keys[i]];
9222ffe3c632Sopenharmony_ci      }
9223ffe3c632Sopenharmony_ci    }
9224ffe3c632Sopenharmony_ci  }
9225ffe3c632Sopenharmony_ci  return self;
9226ffe3c632Sopenharmony_ci}
9227ffe3c632Sopenharmony_ci
9228ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBStringBoolDictionary *)dictionary {
9229ffe3c632Sopenharmony_ci  self = [self initWithBools:NULL forKeys:NULL count:0];
9230ffe3c632Sopenharmony_ci  if (self) {
9231ffe3c632Sopenharmony_ci    if (dictionary) {
9232ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
9233ffe3c632Sopenharmony_ci    }
9234ffe3c632Sopenharmony_ci  }
9235ffe3c632Sopenharmony_ci  return self;
9236ffe3c632Sopenharmony_ci}
9237ffe3c632Sopenharmony_ci
9238ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
9239ffe3c632Sopenharmony_ci  #pragma unused(numItems)
9240ffe3c632Sopenharmony_ci  return [self initWithBools:NULL forKeys:NULL count:0];
9241ffe3c632Sopenharmony_ci}
9242ffe3c632Sopenharmony_ci
9243ffe3c632Sopenharmony_ci- (void)dealloc {
9244ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
9245ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
9246ffe3c632Sopenharmony_ci           [self class], _autocreator);
9247ffe3c632Sopenharmony_ci  [_dictionary release];
9248ffe3c632Sopenharmony_ci  [super dealloc];
9249ffe3c632Sopenharmony_ci}
9250ffe3c632Sopenharmony_ci
9251ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
9252ffe3c632Sopenharmony_ci  return [[GPBStringBoolDictionary allocWithZone:zone] initWithDictionary:self];
9253ffe3c632Sopenharmony_ci}
9254ffe3c632Sopenharmony_ci
9255ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
9256ffe3c632Sopenharmony_ci  if (self == other) {
9257ffe3c632Sopenharmony_ci    return YES;
9258ffe3c632Sopenharmony_ci  }
9259ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBStringBoolDictionary class]]) {
9260ffe3c632Sopenharmony_ci    return NO;
9261ffe3c632Sopenharmony_ci  }
9262ffe3c632Sopenharmony_ci  GPBStringBoolDictionary *otherDictionary = other;
9263ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
9264ffe3c632Sopenharmony_ci}
9265ffe3c632Sopenharmony_ci
9266ffe3c632Sopenharmony_ci- (NSUInteger)hash {
9267ffe3c632Sopenharmony_ci  return _dictionary.count;
9268ffe3c632Sopenharmony_ci}
9269ffe3c632Sopenharmony_ci
9270ffe3c632Sopenharmony_ci- (NSString *)description {
9271ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
9272ffe3c632Sopenharmony_ci}
9273ffe3c632Sopenharmony_ci
9274ffe3c632Sopenharmony_ci- (NSUInteger)count {
9275ffe3c632Sopenharmony_ci  return _dictionary.count;
9276ffe3c632Sopenharmony_ci}
9277ffe3c632Sopenharmony_ci
9278ffe3c632Sopenharmony_ci- (void)enumerateKeysAndBoolsUsingBlock:
9279ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(NSString *key, BOOL value, BOOL *stop))block {
9280ffe3c632Sopenharmony_ci  BOOL stop = NO;
9281ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
9282ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
9283ffe3c632Sopenharmony_ci  NSString *aKey;
9284ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
9285ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
9286ffe3c632Sopenharmony_ci    block(aKey, [aValue boolValue], &stop);
9287ffe3c632Sopenharmony_ci    if (stop) {
9288ffe3c632Sopenharmony_ci      break;
9289ffe3c632Sopenharmony_ci    }
9290ffe3c632Sopenharmony_ci  }
9291ffe3c632Sopenharmony_ci}
9292ffe3c632Sopenharmony_ci
9293ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
9294ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
9295ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
9296ffe3c632Sopenharmony_ci  if (count == 0) {
9297ffe3c632Sopenharmony_ci    return 0;
9298ffe3c632Sopenharmony_ci  }
9299ffe3c632Sopenharmony_ci
9300ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
9301ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
9302ffe3c632Sopenharmony_ci  size_t result = 0;
9303ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
9304ffe3c632Sopenharmony_ci  NSString *aKey;
9305ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
9306ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
9307ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
9308ffe3c632Sopenharmony_ci    msgSize += ComputeDictBoolFieldSize([aValue boolValue], kMapValueFieldNumber, valueDataType);
9309ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
9310ffe3c632Sopenharmony_ci  }
9311ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
9312ffe3c632Sopenharmony_ci  result += tagSize * count;
9313ffe3c632Sopenharmony_ci  return result;
9314ffe3c632Sopenharmony_ci}
9315ffe3c632Sopenharmony_ci
9316ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
9317ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
9318ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
9319ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
9320ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
9321ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
9322ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
9323ffe3c632Sopenharmony_ci  NSString *aKey;
9324ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
9325ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
9326ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
9327ffe3c632Sopenharmony_ci    // Write the size of the message.
9328ffe3c632Sopenharmony_ci    NSString *unwrappedKey = aKey;
9329ffe3c632Sopenharmony_ci    BOOL unwrappedValue = [aValue boolValue];
9330ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
9331ffe3c632Sopenharmony_ci    msgSize += ComputeDictBoolFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
9332ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
9333ffe3c632Sopenharmony_ci    // Write the fields.
9334ffe3c632Sopenharmony_ci    WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
9335ffe3c632Sopenharmony_ci    WriteDictBoolField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
9336ffe3c632Sopenharmony_ci  }
9337ffe3c632Sopenharmony_ci}
9338ffe3c632Sopenharmony_ci
9339ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
9340ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
9341ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueBool) forKey:key->valueString];
9342ffe3c632Sopenharmony_ci}
9343ffe3c632Sopenharmony_ci
9344ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
9345ffe3c632Sopenharmony_ci  [self enumerateKeysAndBoolsUsingBlock:^(NSString *key, BOOL value, BOOL *stop) {
9346ffe3c632Sopenharmony_ci      #pragma unused(stop)
9347ffe3c632Sopenharmony_ci      block(key, (value ? @"true" : @"false"));
9348ffe3c632Sopenharmony_ci  }];
9349ffe3c632Sopenharmony_ci}
9350ffe3c632Sopenharmony_ci
9351ffe3c632Sopenharmony_ci- (BOOL)getBool:(nullable BOOL *)value forKey:(NSString *)key {
9352ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:key];
9353ffe3c632Sopenharmony_ci  if (wrapped && value) {
9354ffe3c632Sopenharmony_ci    *value = [wrapped boolValue];
9355ffe3c632Sopenharmony_ci  }
9356ffe3c632Sopenharmony_ci  return (wrapped != NULL);
9357ffe3c632Sopenharmony_ci}
9358ffe3c632Sopenharmony_ci
9359ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBStringBoolDictionary *)otherDictionary {
9360ffe3c632Sopenharmony_ci  if (otherDictionary) {
9361ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
9362ffe3c632Sopenharmony_ci    if (_autocreator) {
9363ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
9364ffe3c632Sopenharmony_ci    }
9365ffe3c632Sopenharmony_ci  }
9366ffe3c632Sopenharmony_ci}
9367ffe3c632Sopenharmony_ci
9368ffe3c632Sopenharmony_ci- (void)setBool:(BOOL)value forKey:(NSString *)key {
9369ffe3c632Sopenharmony_ci  if (!key) {
9370ffe3c632Sopenharmony_ci    [NSException raise:NSInvalidArgumentException
9371ffe3c632Sopenharmony_ci                format:@"Attempting to add nil key to a Dictionary"];
9372ffe3c632Sopenharmony_ci  }
9373ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:key];
9374ffe3c632Sopenharmony_ci  if (_autocreator) {
9375ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
9376ffe3c632Sopenharmony_ci  }
9377ffe3c632Sopenharmony_ci}
9378ffe3c632Sopenharmony_ci
9379ffe3c632Sopenharmony_ci- (void)removeBoolForKey:(NSString *)aKey {
9380ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:aKey];
9381ffe3c632Sopenharmony_ci}
9382ffe3c632Sopenharmony_ci
9383ffe3c632Sopenharmony_ci- (void)removeAll {
9384ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
9385ffe3c632Sopenharmony_ci}
9386ffe3c632Sopenharmony_ci
9387ffe3c632Sopenharmony_ci@end
9388ffe3c632Sopenharmony_ci
9389ffe3c632Sopenharmony_ci#pragma mark - String -> Float
9390ffe3c632Sopenharmony_ci
9391ffe3c632Sopenharmony_ci@implementation GPBStringFloatDictionary {
9392ffe3c632Sopenharmony_ci @package
9393ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
9394ffe3c632Sopenharmony_ci}
9395ffe3c632Sopenharmony_ci
9396ffe3c632Sopenharmony_ci- (instancetype)init {
9397ffe3c632Sopenharmony_ci  return [self initWithFloats:NULL forKeys:NULL count:0];
9398ffe3c632Sopenharmony_ci}
9399ffe3c632Sopenharmony_ci
9400ffe3c632Sopenharmony_ci- (instancetype)initWithFloats:(const float [])values
9401ffe3c632Sopenharmony_ci                       forKeys:(const NSString * [])keys
9402ffe3c632Sopenharmony_ci                         count:(NSUInteger)count {
9403ffe3c632Sopenharmony_ci  self = [super init];
9404ffe3c632Sopenharmony_ci  if (self) {
9405ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
9406ffe3c632Sopenharmony_ci    if (count && values && keys) {
9407ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
9408ffe3c632Sopenharmony_ci        if (!keys[i]) {
9409ffe3c632Sopenharmony_ci          [NSException raise:NSInvalidArgumentException
9410ffe3c632Sopenharmony_ci                      format:@"Attempting to add nil key to a Dictionary"];
9411ffe3c632Sopenharmony_ci        }
9412ffe3c632Sopenharmony_ci        [_dictionary setObject:@(values[i]) forKey:keys[i]];
9413ffe3c632Sopenharmony_ci      }
9414ffe3c632Sopenharmony_ci    }
9415ffe3c632Sopenharmony_ci  }
9416ffe3c632Sopenharmony_ci  return self;
9417ffe3c632Sopenharmony_ci}
9418ffe3c632Sopenharmony_ci
9419ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBStringFloatDictionary *)dictionary {
9420ffe3c632Sopenharmony_ci  self = [self initWithFloats:NULL forKeys:NULL count:0];
9421ffe3c632Sopenharmony_ci  if (self) {
9422ffe3c632Sopenharmony_ci    if (dictionary) {
9423ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
9424ffe3c632Sopenharmony_ci    }
9425ffe3c632Sopenharmony_ci  }
9426ffe3c632Sopenharmony_ci  return self;
9427ffe3c632Sopenharmony_ci}
9428ffe3c632Sopenharmony_ci
9429ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
9430ffe3c632Sopenharmony_ci  #pragma unused(numItems)
9431ffe3c632Sopenharmony_ci  return [self initWithFloats:NULL forKeys:NULL count:0];
9432ffe3c632Sopenharmony_ci}
9433ffe3c632Sopenharmony_ci
9434ffe3c632Sopenharmony_ci- (void)dealloc {
9435ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
9436ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
9437ffe3c632Sopenharmony_ci           [self class], _autocreator);
9438ffe3c632Sopenharmony_ci  [_dictionary release];
9439ffe3c632Sopenharmony_ci  [super dealloc];
9440ffe3c632Sopenharmony_ci}
9441ffe3c632Sopenharmony_ci
9442ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
9443ffe3c632Sopenharmony_ci  return [[GPBStringFloatDictionary allocWithZone:zone] initWithDictionary:self];
9444ffe3c632Sopenharmony_ci}
9445ffe3c632Sopenharmony_ci
9446ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
9447ffe3c632Sopenharmony_ci  if (self == other) {
9448ffe3c632Sopenharmony_ci    return YES;
9449ffe3c632Sopenharmony_ci  }
9450ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBStringFloatDictionary class]]) {
9451ffe3c632Sopenharmony_ci    return NO;
9452ffe3c632Sopenharmony_ci  }
9453ffe3c632Sopenharmony_ci  GPBStringFloatDictionary *otherDictionary = other;
9454ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
9455ffe3c632Sopenharmony_ci}
9456ffe3c632Sopenharmony_ci
9457ffe3c632Sopenharmony_ci- (NSUInteger)hash {
9458ffe3c632Sopenharmony_ci  return _dictionary.count;
9459ffe3c632Sopenharmony_ci}
9460ffe3c632Sopenharmony_ci
9461ffe3c632Sopenharmony_ci- (NSString *)description {
9462ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
9463ffe3c632Sopenharmony_ci}
9464ffe3c632Sopenharmony_ci
9465ffe3c632Sopenharmony_ci- (NSUInteger)count {
9466ffe3c632Sopenharmony_ci  return _dictionary.count;
9467ffe3c632Sopenharmony_ci}
9468ffe3c632Sopenharmony_ci
9469ffe3c632Sopenharmony_ci- (void)enumerateKeysAndFloatsUsingBlock:
9470ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(NSString *key, float value, BOOL *stop))block {
9471ffe3c632Sopenharmony_ci  BOOL stop = NO;
9472ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
9473ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
9474ffe3c632Sopenharmony_ci  NSString *aKey;
9475ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
9476ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
9477ffe3c632Sopenharmony_ci    block(aKey, [aValue floatValue], &stop);
9478ffe3c632Sopenharmony_ci    if (stop) {
9479ffe3c632Sopenharmony_ci      break;
9480ffe3c632Sopenharmony_ci    }
9481ffe3c632Sopenharmony_ci  }
9482ffe3c632Sopenharmony_ci}
9483ffe3c632Sopenharmony_ci
9484ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
9485ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
9486ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
9487ffe3c632Sopenharmony_ci  if (count == 0) {
9488ffe3c632Sopenharmony_ci    return 0;
9489ffe3c632Sopenharmony_ci  }
9490ffe3c632Sopenharmony_ci
9491ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
9492ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
9493ffe3c632Sopenharmony_ci  size_t result = 0;
9494ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
9495ffe3c632Sopenharmony_ci  NSString *aKey;
9496ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
9497ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
9498ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
9499ffe3c632Sopenharmony_ci    msgSize += ComputeDictFloatFieldSize([aValue floatValue], kMapValueFieldNumber, valueDataType);
9500ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
9501ffe3c632Sopenharmony_ci  }
9502ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
9503ffe3c632Sopenharmony_ci  result += tagSize * count;
9504ffe3c632Sopenharmony_ci  return result;
9505ffe3c632Sopenharmony_ci}
9506ffe3c632Sopenharmony_ci
9507ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
9508ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
9509ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
9510ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
9511ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
9512ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
9513ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
9514ffe3c632Sopenharmony_ci  NSString *aKey;
9515ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
9516ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
9517ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
9518ffe3c632Sopenharmony_ci    // Write the size of the message.
9519ffe3c632Sopenharmony_ci    NSString *unwrappedKey = aKey;
9520ffe3c632Sopenharmony_ci    float unwrappedValue = [aValue floatValue];
9521ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
9522ffe3c632Sopenharmony_ci    msgSize += ComputeDictFloatFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
9523ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
9524ffe3c632Sopenharmony_ci    // Write the fields.
9525ffe3c632Sopenharmony_ci    WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
9526ffe3c632Sopenharmony_ci    WriteDictFloatField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
9527ffe3c632Sopenharmony_ci  }
9528ffe3c632Sopenharmony_ci}
9529ffe3c632Sopenharmony_ci
9530ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
9531ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
9532ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueFloat) forKey:key->valueString];
9533ffe3c632Sopenharmony_ci}
9534ffe3c632Sopenharmony_ci
9535ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
9536ffe3c632Sopenharmony_ci  [self enumerateKeysAndFloatsUsingBlock:^(NSString *key, float value, BOOL *stop) {
9537ffe3c632Sopenharmony_ci      #pragma unused(stop)
9538ffe3c632Sopenharmony_ci      block(key, [NSString stringWithFormat:@"%.*g", FLT_DIG, value]);
9539ffe3c632Sopenharmony_ci  }];
9540ffe3c632Sopenharmony_ci}
9541ffe3c632Sopenharmony_ci
9542ffe3c632Sopenharmony_ci- (BOOL)getFloat:(nullable float *)value forKey:(NSString *)key {
9543ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:key];
9544ffe3c632Sopenharmony_ci  if (wrapped && value) {
9545ffe3c632Sopenharmony_ci    *value = [wrapped floatValue];
9546ffe3c632Sopenharmony_ci  }
9547ffe3c632Sopenharmony_ci  return (wrapped != NULL);
9548ffe3c632Sopenharmony_ci}
9549ffe3c632Sopenharmony_ci
9550ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBStringFloatDictionary *)otherDictionary {
9551ffe3c632Sopenharmony_ci  if (otherDictionary) {
9552ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
9553ffe3c632Sopenharmony_ci    if (_autocreator) {
9554ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
9555ffe3c632Sopenharmony_ci    }
9556ffe3c632Sopenharmony_ci  }
9557ffe3c632Sopenharmony_ci}
9558ffe3c632Sopenharmony_ci
9559ffe3c632Sopenharmony_ci- (void)setFloat:(float)value forKey:(NSString *)key {
9560ffe3c632Sopenharmony_ci  if (!key) {
9561ffe3c632Sopenharmony_ci    [NSException raise:NSInvalidArgumentException
9562ffe3c632Sopenharmony_ci                format:@"Attempting to add nil key to a Dictionary"];
9563ffe3c632Sopenharmony_ci  }
9564ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:key];
9565ffe3c632Sopenharmony_ci  if (_autocreator) {
9566ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
9567ffe3c632Sopenharmony_ci  }
9568ffe3c632Sopenharmony_ci}
9569ffe3c632Sopenharmony_ci
9570ffe3c632Sopenharmony_ci- (void)removeFloatForKey:(NSString *)aKey {
9571ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:aKey];
9572ffe3c632Sopenharmony_ci}
9573ffe3c632Sopenharmony_ci
9574ffe3c632Sopenharmony_ci- (void)removeAll {
9575ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
9576ffe3c632Sopenharmony_ci}
9577ffe3c632Sopenharmony_ci
9578ffe3c632Sopenharmony_ci@end
9579ffe3c632Sopenharmony_ci
9580ffe3c632Sopenharmony_ci#pragma mark - String -> Double
9581ffe3c632Sopenharmony_ci
9582ffe3c632Sopenharmony_ci@implementation GPBStringDoubleDictionary {
9583ffe3c632Sopenharmony_ci @package
9584ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
9585ffe3c632Sopenharmony_ci}
9586ffe3c632Sopenharmony_ci
9587ffe3c632Sopenharmony_ci- (instancetype)init {
9588ffe3c632Sopenharmony_ci  return [self initWithDoubles:NULL forKeys:NULL count:0];
9589ffe3c632Sopenharmony_ci}
9590ffe3c632Sopenharmony_ci
9591ffe3c632Sopenharmony_ci- (instancetype)initWithDoubles:(const double [])values
9592ffe3c632Sopenharmony_ci                        forKeys:(const NSString * [])keys
9593ffe3c632Sopenharmony_ci                          count:(NSUInteger)count {
9594ffe3c632Sopenharmony_ci  self = [super init];
9595ffe3c632Sopenharmony_ci  if (self) {
9596ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
9597ffe3c632Sopenharmony_ci    if (count && values && keys) {
9598ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
9599ffe3c632Sopenharmony_ci        if (!keys[i]) {
9600ffe3c632Sopenharmony_ci          [NSException raise:NSInvalidArgumentException
9601ffe3c632Sopenharmony_ci                      format:@"Attempting to add nil key to a Dictionary"];
9602ffe3c632Sopenharmony_ci        }
9603ffe3c632Sopenharmony_ci        [_dictionary setObject:@(values[i]) forKey:keys[i]];
9604ffe3c632Sopenharmony_ci      }
9605ffe3c632Sopenharmony_ci    }
9606ffe3c632Sopenharmony_ci  }
9607ffe3c632Sopenharmony_ci  return self;
9608ffe3c632Sopenharmony_ci}
9609ffe3c632Sopenharmony_ci
9610ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBStringDoubleDictionary *)dictionary {
9611ffe3c632Sopenharmony_ci  self = [self initWithDoubles:NULL forKeys:NULL count:0];
9612ffe3c632Sopenharmony_ci  if (self) {
9613ffe3c632Sopenharmony_ci    if (dictionary) {
9614ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
9615ffe3c632Sopenharmony_ci    }
9616ffe3c632Sopenharmony_ci  }
9617ffe3c632Sopenharmony_ci  return self;
9618ffe3c632Sopenharmony_ci}
9619ffe3c632Sopenharmony_ci
9620ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
9621ffe3c632Sopenharmony_ci  #pragma unused(numItems)
9622ffe3c632Sopenharmony_ci  return [self initWithDoubles:NULL forKeys:NULL count:0];
9623ffe3c632Sopenharmony_ci}
9624ffe3c632Sopenharmony_ci
9625ffe3c632Sopenharmony_ci- (void)dealloc {
9626ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
9627ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
9628ffe3c632Sopenharmony_ci           [self class], _autocreator);
9629ffe3c632Sopenharmony_ci  [_dictionary release];
9630ffe3c632Sopenharmony_ci  [super dealloc];
9631ffe3c632Sopenharmony_ci}
9632ffe3c632Sopenharmony_ci
9633ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
9634ffe3c632Sopenharmony_ci  return [[GPBStringDoubleDictionary allocWithZone:zone] initWithDictionary:self];
9635ffe3c632Sopenharmony_ci}
9636ffe3c632Sopenharmony_ci
9637ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
9638ffe3c632Sopenharmony_ci  if (self == other) {
9639ffe3c632Sopenharmony_ci    return YES;
9640ffe3c632Sopenharmony_ci  }
9641ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBStringDoubleDictionary class]]) {
9642ffe3c632Sopenharmony_ci    return NO;
9643ffe3c632Sopenharmony_ci  }
9644ffe3c632Sopenharmony_ci  GPBStringDoubleDictionary *otherDictionary = other;
9645ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
9646ffe3c632Sopenharmony_ci}
9647ffe3c632Sopenharmony_ci
9648ffe3c632Sopenharmony_ci- (NSUInteger)hash {
9649ffe3c632Sopenharmony_ci  return _dictionary.count;
9650ffe3c632Sopenharmony_ci}
9651ffe3c632Sopenharmony_ci
9652ffe3c632Sopenharmony_ci- (NSString *)description {
9653ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
9654ffe3c632Sopenharmony_ci}
9655ffe3c632Sopenharmony_ci
9656ffe3c632Sopenharmony_ci- (NSUInteger)count {
9657ffe3c632Sopenharmony_ci  return _dictionary.count;
9658ffe3c632Sopenharmony_ci}
9659ffe3c632Sopenharmony_ci
9660ffe3c632Sopenharmony_ci- (void)enumerateKeysAndDoublesUsingBlock:
9661ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(NSString *key, double value, BOOL *stop))block {
9662ffe3c632Sopenharmony_ci  BOOL stop = NO;
9663ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
9664ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
9665ffe3c632Sopenharmony_ci  NSString *aKey;
9666ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
9667ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
9668ffe3c632Sopenharmony_ci    block(aKey, [aValue doubleValue], &stop);
9669ffe3c632Sopenharmony_ci    if (stop) {
9670ffe3c632Sopenharmony_ci      break;
9671ffe3c632Sopenharmony_ci    }
9672ffe3c632Sopenharmony_ci  }
9673ffe3c632Sopenharmony_ci}
9674ffe3c632Sopenharmony_ci
9675ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
9676ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
9677ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
9678ffe3c632Sopenharmony_ci  if (count == 0) {
9679ffe3c632Sopenharmony_ci    return 0;
9680ffe3c632Sopenharmony_ci  }
9681ffe3c632Sopenharmony_ci
9682ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
9683ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
9684ffe3c632Sopenharmony_ci  size_t result = 0;
9685ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
9686ffe3c632Sopenharmony_ci  NSString *aKey;
9687ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
9688ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
9689ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
9690ffe3c632Sopenharmony_ci    msgSize += ComputeDictDoubleFieldSize([aValue doubleValue], kMapValueFieldNumber, valueDataType);
9691ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
9692ffe3c632Sopenharmony_ci  }
9693ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
9694ffe3c632Sopenharmony_ci  result += tagSize * count;
9695ffe3c632Sopenharmony_ci  return result;
9696ffe3c632Sopenharmony_ci}
9697ffe3c632Sopenharmony_ci
9698ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
9699ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
9700ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
9701ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
9702ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
9703ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
9704ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
9705ffe3c632Sopenharmony_ci  NSString *aKey;
9706ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
9707ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
9708ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
9709ffe3c632Sopenharmony_ci    // Write the size of the message.
9710ffe3c632Sopenharmony_ci    NSString *unwrappedKey = aKey;
9711ffe3c632Sopenharmony_ci    double unwrappedValue = [aValue doubleValue];
9712ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
9713ffe3c632Sopenharmony_ci    msgSize += ComputeDictDoubleFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
9714ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
9715ffe3c632Sopenharmony_ci    // Write the fields.
9716ffe3c632Sopenharmony_ci    WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
9717ffe3c632Sopenharmony_ci    WriteDictDoubleField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
9718ffe3c632Sopenharmony_ci  }
9719ffe3c632Sopenharmony_ci}
9720ffe3c632Sopenharmony_ci
9721ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
9722ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
9723ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueDouble) forKey:key->valueString];
9724ffe3c632Sopenharmony_ci}
9725ffe3c632Sopenharmony_ci
9726ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
9727ffe3c632Sopenharmony_ci  [self enumerateKeysAndDoublesUsingBlock:^(NSString *key, double value, BOOL *stop) {
9728ffe3c632Sopenharmony_ci      #pragma unused(stop)
9729ffe3c632Sopenharmony_ci      block(key, [NSString stringWithFormat:@"%.*lg", DBL_DIG, value]);
9730ffe3c632Sopenharmony_ci  }];
9731ffe3c632Sopenharmony_ci}
9732ffe3c632Sopenharmony_ci
9733ffe3c632Sopenharmony_ci- (BOOL)getDouble:(nullable double *)value forKey:(NSString *)key {
9734ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:key];
9735ffe3c632Sopenharmony_ci  if (wrapped && value) {
9736ffe3c632Sopenharmony_ci    *value = [wrapped doubleValue];
9737ffe3c632Sopenharmony_ci  }
9738ffe3c632Sopenharmony_ci  return (wrapped != NULL);
9739ffe3c632Sopenharmony_ci}
9740ffe3c632Sopenharmony_ci
9741ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBStringDoubleDictionary *)otherDictionary {
9742ffe3c632Sopenharmony_ci  if (otherDictionary) {
9743ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
9744ffe3c632Sopenharmony_ci    if (_autocreator) {
9745ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
9746ffe3c632Sopenharmony_ci    }
9747ffe3c632Sopenharmony_ci  }
9748ffe3c632Sopenharmony_ci}
9749ffe3c632Sopenharmony_ci
9750ffe3c632Sopenharmony_ci- (void)setDouble:(double)value forKey:(NSString *)key {
9751ffe3c632Sopenharmony_ci  if (!key) {
9752ffe3c632Sopenharmony_ci    [NSException raise:NSInvalidArgumentException
9753ffe3c632Sopenharmony_ci                format:@"Attempting to add nil key to a Dictionary"];
9754ffe3c632Sopenharmony_ci  }
9755ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:key];
9756ffe3c632Sopenharmony_ci  if (_autocreator) {
9757ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
9758ffe3c632Sopenharmony_ci  }
9759ffe3c632Sopenharmony_ci}
9760ffe3c632Sopenharmony_ci
9761ffe3c632Sopenharmony_ci- (void)removeDoubleForKey:(NSString *)aKey {
9762ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:aKey];
9763ffe3c632Sopenharmony_ci}
9764ffe3c632Sopenharmony_ci
9765ffe3c632Sopenharmony_ci- (void)removeAll {
9766ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
9767ffe3c632Sopenharmony_ci}
9768ffe3c632Sopenharmony_ci
9769ffe3c632Sopenharmony_ci@end
9770ffe3c632Sopenharmony_ci
9771ffe3c632Sopenharmony_ci#pragma mark - String -> Enum
9772ffe3c632Sopenharmony_ci
9773ffe3c632Sopenharmony_ci@implementation GPBStringEnumDictionary {
9774ffe3c632Sopenharmony_ci @package
9775ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
9776ffe3c632Sopenharmony_ci  GPBEnumValidationFunc _validationFunc;
9777ffe3c632Sopenharmony_ci}
9778ffe3c632Sopenharmony_ci
9779ffe3c632Sopenharmony_ci@synthesize validationFunc = _validationFunc;
9780ffe3c632Sopenharmony_ci
9781ffe3c632Sopenharmony_ci- (instancetype)init {
9782ffe3c632Sopenharmony_ci  return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
9783ffe3c632Sopenharmony_ci}
9784ffe3c632Sopenharmony_ci
9785ffe3c632Sopenharmony_ci- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
9786ffe3c632Sopenharmony_ci  return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
9787ffe3c632Sopenharmony_ci}
9788ffe3c632Sopenharmony_ci
9789ffe3c632Sopenharmony_ci- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
9790ffe3c632Sopenharmony_ci                                 rawValues:(const int32_t [])rawValues
9791ffe3c632Sopenharmony_ci                                   forKeys:(const NSString * [])keys
9792ffe3c632Sopenharmony_ci                                     count:(NSUInteger)count {
9793ffe3c632Sopenharmony_ci  self = [super init];
9794ffe3c632Sopenharmony_ci  if (self) {
9795ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
9796ffe3c632Sopenharmony_ci    _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
9797ffe3c632Sopenharmony_ci    if (count && rawValues && keys) {
9798ffe3c632Sopenharmony_ci      for (NSUInteger i = 0; i < count; ++i) {
9799ffe3c632Sopenharmony_ci        if (!keys[i]) {
9800ffe3c632Sopenharmony_ci          [NSException raise:NSInvalidArgumentException
9801ffe3c632Sopenharmony_ci                      format:@"Attempting to add nil key to a Dictionary"];
9802ffe3c632Sopenharmony_ci        }
9803ffe3c632Sopenharmony_ci        [_dictionary setObject:@(rawValues[i]) forKey:keys[i]];
9804ffe3c632Sopenharmony_ci      }
9805ffe3c632Sopenharmony_ci    }
9806ffe3c632Sopenharmony_ci  }
9807ffe3c632Sopenharmony_ci  return self;
9808ffe3c632Sopenharmony_ci}
9809ffe3c632Sopenharmony_ci
9810ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBStringEnumDictionary *)dictionary {
9811ffe3c632Sopenharmony_ci  self = [self initWithValidationFunction:dictionary.validationFunc
9812ffe3c632Sopenharmony_ci                                rawValues:NULL
9813ffe3c632Sopenharmony_ci                                  forKeys:NULL
9814ffe3c632Sopenharmony_ci                                    count:0];
9815ffe3c632Sopenharmony_ci  if (self) {
9816ffe3c632Sopenharmony_ci    if (dictionary) {
9817ffe3c632Sopenharmony_ci      [_dictionary addEntriesFromDictionary:dictionary->_dictionary];
9818ffe3c632Sopenharmony_ci    }
9819ffe3c632Sopenharmony_ci  }
9820ffe3c632Sopenharmony_ci  return self;
9821ffe3c632Sopenharmony_ci}
9822ffe3c632Sopenharmony_ci
9823ffe3c632Sopenharmony_ci- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
9824ffe3c632Sopenharmony_ci                                  capacity:(NSUInteger)numItems {
9825ffe3c632Sopenharmony_ci  #pragma unused(numItems)
9826ffe3c632Sopenharmony_ci  return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
9827ffe3c632Sopenharmony_ci}
9828ffe3c632Sopenharmony_ci
9829ffe3c632Sopenharmony_ci- (void)dealloc {
9830ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
9831ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
9832ffe3c632Sopenharmony_ci           [self class], _autocreator);
9833ffe3c632Sopenharmony_ci  [_dictionary release];
9834ffe3c632Sopenharmony_ci  [super dealloc];
9835ffe3c632Sopenharmony_ci}
9836ffe3c632Sopenharmony_ci
9837ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
9838ffe3c632Sopenharmony_ci  return [[GPBStringEnumDictionary allocWithZone:zone] initWithDictionary:self];
9839ffe3c632Sopenharmony_ci}
9840ffe3c632Sopenharmony_ci
9841ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
9842ffe3c632Sopenharmony_ci  if (self == other) {
9843ffe3c632Sopenharmony_ci    return YES;
9844ffe3c632Sopenharmony_ci  }
9845ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBStringEnumDictionary class]]) {
9846ffe3c632Sopenharmony_ci    return NO;
9847ffe3c632Sopenharmony_ci  }
9848ffe3c632Sopenharmony_ci  GPBStringEnumDictionary *otherDictionary = other;
9849ffe3c632Sopenharmony_ci  return [_dictionary isEqual:otherDictionary->_dictionary];
9850ffe3c632Sopenharmony_ci}
9851ffe3c632Sopenharmony_ci
9852ffe3c632Sopenharmony_ci- (NSUInteger)hash {
9853ffe3c632Sopenharmony_ci  return _dictionary.count;
9854ffe3c632Sopenharmony_ci}
9855ffe3c632Sopenharmony_ci
9856ffe3c632Sopenharmony_ci- (NSString *)description {
9857ffe3c632Sopenharmony_ci  return [NSString stringWithFormat:@"<%@ %p> { %@ }", [self class], self, _dictionary];
9858ffe3c632Sopenharmony_ci}
9859ffe3c632Sopenharmony_ci
9860ffe3c632Sopenharmony_ci- (NSUInteger)count {
9861ffe3c632Sopenharmony_ci  return _dictionary.count;
9862ffe3c632Sopenharmony_ci}
9863ffe3c632Sopenharmony_ci
9864ffe3c632Sopenharmony_ci- (void)enumerateKeysAndRawValuesUsingBlock:
9865ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(NSString *key, int32_t value, BOOL *stop))block {
9866ffe3c632Sopenharmony_ci  BOOL stop = NO;
9867ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
9868ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
9869ffe3c632Sopenharmony_ci  NSString *aKey;
9870ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
9871ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
9872ffe3c632Sopenharmony_ci    block(aKey, [aValue intValue], &stop);
9873ffe3c632Sopenharmony_ci    if (stop) {
9874ffe3c632Sopenharmony_ci      break;
9875ffe3c632Sopenharmony_ci    }
9876ffe3c632Sopenharmony_ci  }
9877ffe3c632Sopenharmony_ci}
9878ffe3c632Sopenharmony_ci
9879ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
9880ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
9881ffe3c632Sopenharmony_ci  NSUInteger count = internal.count;
9882ffe3c632Sopenharmony_ci  if (count == 0) {
9883ffe3c632Sopenharmony_ci    return 0;
9884ffe3c632Sopenharmony_ci  }
9885ffe3c632Sopenharmony_ci
9886ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
9887ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
9888ffe3c632Sopenharmony_ci  size_t result = 0;
9889ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
9890ffe3c632Sopenharmony_ci  NSString *aKey;
9891ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
9892ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
9893ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictStringFieldSize(aKey, kMapKeyFieldNumber, keyDataType);
9894ffe3c632Sopenharmony_ci    msgSize += ComputeDictEnumFieldSize([aValue intValue], kMapValueFieldNumber, valueDataType);
9895ffe3c632Sopenharmony_ci    result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
9896ffe3c632Sopenharmony_ci  }
9897ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
9898ffe3c632Sopenharmony_ci  result += tagSize * count;
9899ffe3c632Sopenharmony_ci  return result;
9900ffe3c632Sopenharmony_ci}
9901ffe3c632Sopenharmony_ci
9902ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
9903ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
9904ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
9905ffe3c632Sopenharmony_ci  GPBDataType keyDataType = field.mapKeyDataType;
9906ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
9907ffe3c632Sopenharmony_ci  NSDictionary *internal = _dictionary;
9908ffe3c632Sopenharmony_ci  NSEnumerator *keys = [internal keyEnumerator];
9909ffe3c632Sopenharmony_ci  NSString *aKey;
9910ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
9911ffe3c632Sopenharmony_ci    NSNumber *aValue = internal[aKey];
9912ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:tag];
9913ffe3c632Sopenharmony_ci    // Write the size of the message.
9914ffe3c632Sopenharmony_ci    NSString *unwrappedKey = aKey;
9915ffe3c632Sopenharmony_ci    int32_t unwrappedValue = [aValue intValue];
9916ffe3c632Sopenharmony_ci    size_t msgSize = ComputeDictStringFieldSize(unwrappedKey, kMapKeyFieldNumber, keyDataType);
9917ffe3c632Sopenharmony_ci    msgSize += ComputeDictEnumFieldSize(unwrappedValue, kMapValueFieldNumber, valueDataType);
9918ffe3c632Sopenharmony_ci    [outputStream writeInt32NoTag:(int32_t)msgSize];
9919ffe3c632Sopenharmony_ci    // Write the fields.
9920ffe3c632Sopenharmony_ci    WriteDictStringField(outputStream, unwrappedKey, kMapKeyFieldNumber, keyDataType);
9921ffe3c632Sopenharmony_ci    WriteDictEnumField(outputStream, unwrappedValue, kMapValueFieldNumber, valueDataType);
9922ffe3c632Sopenharmony_ci  }
9923ffe3c632Sopenharmony_ci}
9924ffe3c632Sopenharmony_ci
9925ffe3c632Sopenharmony_ci- (NSData *)serializedDataForUnknownValue:(int32_t)value
9926ffe3c632Sopenharmony_ci                                   forKey:(GPBGenericValue *)key
9927ffe3c632Sopenharmony_ci                              keyDataType:(GPBDataType)keyDataType {
9928ffe3c632Sopenharmony_ci  size_t msgSize = ComputeDictStringFieldSize(key->valueString, kMapKeyFieldNumber, keyDataType);
9929ffe3c632Sopenharmony_ci  msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
9930ffe3c632Sopenharmony_ci  NSMutableData *data = [NSMutableData dataWithLength:msgSize];
9931ffe3c632Sopenharmony_ci  GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
9932ffe3c632Sopenharmony_ci  WriteDictStringField(outputStream, key->valueString, kMapKeyFieldNumber, keyDataType);
9933ffe3c632Sopenharmony_ci  WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
9934ffe3c632Sopenharmony_ci  [outputStream release];
9935ffe3c632Sopenharmony_ci  return data;
9936ffe3c632Sopenharmony_ci}
9937ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
9938ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
9939ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value->valueEnum) forKey:key->valueString];
9940ffe3c632Sopenharmony_ci}
9941ffe3c632Sopenharmony_ci
9942ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
9943ffe3c632Sopenharmony_ci  [self enumerateKeysAndRawValuesUsingBlock:^(NSString *key, int32_t value, BOOL *stop) {
9944ffe3c632Sopenharmony_ci      #pragma unused(stop)
9945ffe3c632Sopenharmony_ci      block(key, @(value));
9946ffe3c632Sopenharmony_ci  }];
9947ffe3c632Sopenharmony_ci}
9948ffe3c632Sopenharmony_ci
9949ffe3c632Sopenharmony_ci- (BOOL)getEnum:(int32_t *)value forKey:(NSString *)key {
9950ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:key];
9951ffe3c632Sopenharmony_ci  if (wrapped && value) {
9952ffe3c632Sopenharmony_ci    int32_t result = [wrapped intValue];
9953ffe3c632Sopenharmony_ci    if (!_validationFunc(result)) {
9954ffe3c632Sopenharmony_ci      result = kGPBUnrecognizedEnumeratorValue;
9955ffe3c632Sopenharmony_ci    }
9956ffe3c632Sopenharmony_ci    *value = result;
9957ffe3c632Sopenharmony_ci  }
9958ffe3c632Sopenharmony_ci  return (wrapped != NULL);
9959ffe3c632Sopenharmony_ci}
9960ffe3c632Sopenharmony_ci
9961ffe3c632Sopenharmony_ci- (BOOL)getRawValue:(int32_t *)rawValue forKey:(NSString *)key {
9962ffe3c632Sopenharmony_ci  NSNumber *wrapped = [_dictionary objectForKey:key];
9963ffe3c632Sopenharmony_ci  if (wrapped && rawValue) {
9964ffe3c632Sopenharmony_ci    *rawValue = [wrapped intValue];
9965ffe3c632Sopenharmony_ci  }
9966ffe3c632Sopenharmony_ci  return (wrapped != NULL);
9967ffe3c632Sopenharmony_ci}
9968ffe3c632Sopenharmony_ci
9969ffe3c632Sopenharmony_ci- (void)enumerateKeysAndEnumsUsingBlock:
9970ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(NSString *key, int32_t value, BOOL *stop))block {
9971ffe3c632Sopenharmony_ci  GPBEnumValidationFunc func = _validationFunc;
9972ffe3c632Sopenharmony_ci  BOOL stop = NO;
9973ffe3c632Sopenharmony_ci  NSEnumerator *keys = [_dictionary keyEnumerator];
9974ffe3c632Sopenharmony_ci  NSString *aKey;
9975ffe3c632Sopenharmony_ci  while ((aKey = [keys nextObject])) {
9976ffe3c632Sopenharmony_ci    NSNumber *aValue = _dictionary[aKey];
9977ffe3c632Sopenharmony_ci      int32_t unwrapped = [aValue intValue];
9978ffe3c632Sopenharmony_ci      if (!func(unwrapped)) {
9979ffe3c632Sopenharmony_ci        unwrapped = kGPBUnrecognizedEnumeratorValue;
9980ffe3c632Sopenharmony_ci      }
9981ffe3c632Sopenharmony_ci    block(aKey, unwrapped, &stop);
9982ffe3c632Sopenharmony_ci    if (stop) {
9983ffe3c632Sopenharmony_ci      break;
9984ffe3c632Sopenharmony_ci    }
9985ffe3c632Sopenharmony_ci  }
9986ffe3c632Sopenharmony_ci}
9987ffe3c632Sopenharmony_ci
9988ffe3c632Sopenharmony_ci- (void)addRawEntriesFromDictionary:(GPBStringEnumDictionary *)otherDictionary {
9989ffe3c632Sopenharmony_ci  if (otherDictionary) {
9990ffe3c632Sopenharmony_ci    [_dictionary addEntriesFromDictionary:otherDictionary->_dictionary];
9991ffe3c632Sopenharmony_ci    if (_autocreator) {
9992ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
9993ffe3c632Sopenharmony_ci    }
9994ffe3c632Sopenharmony_ci  }
9995ffe3c632Sopenharmony_ci}
9996ffe3c632Sopenharmony_ci
9997ffe3c632Sopenharmony_ci- (void)setRawValue:(int32_t)value forKey:(NSString *)key {
9998ffe3c632Sopenharmony_ci  if (!key) {
9999ffe3c632Sopenharmony_ci    [NSException raise:NSInvalidArgumentException
10000ffe3c632Sopenharmony_ci                format:@"Attempting to add nil key to a Dictionary"];
10001ffe3c632Sopenharmony_ci  }
10002ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:key];
10003ffe3c632Sopenharmony_ci  if (_autocreator) {
10004ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
10005ffe3c632Sopenharmony_ci  }
10006ffe3c632Sopenharmony_ci}
10007ffe3c632Sopenharmony_ci
10008ffe3c632Sopenharmony_ci- (void)removeEnumForKey:(NSString *)aKey {
10009ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:aKey];
10010ffe3c632Sopenharmony_ci}
10011ffe3c632Sopenharmony_ci
10012ffe3c632Sopenharmony_ci- (void)removeAll {
10013ffe3c632Sopenharmony_ci  [_dictionary removeAllObjects];
10014ffe3c632Sopenharmony_ci}
10015ffe3c632Sopenharmony_ci
10016ffe3c632Sopenharmony_ci- (void)setEnum:(int32_t)value forKey:(NSString *)key {
10017ffe3c632Sopenharmony_ci  if (!key) {
10018ffe3c632Sopenharmony_ci    [NSException raise:NSInvalidArgumentException
10019ffe3c632Sopenharmony_ci                format:@"Attempting to add nil key to a Dictionary"];
10020ffe3c632Sopenharmony_ci  }
10021ffe3c632Sopenharmony_ci  if (!_validationFunc(value)) {
10022ffe3c632Sopenharmony_ci    [NSException raise:NSInvalidArgumentException
10023ffe3c632Sopenharmony_ci                format:@"GPBStringEnumDictionary: Attempt to set an unknown enum value (%d)",
10024ffe3c632Sopenharmony_ci                       value];
10025ffe3c632Sopenharmony_ci  }
10026ffe3c632Sopenharmony_ci
10027ffe3c632Sopenharmony_ci  [_dictionary setObject:@(value) forKey:key];
10028ffe3c632Sopenharmony_ci  if (_autocreator) {
10029ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
10030ffe3c632Sopenharmony_ci  }
10031ffe3c632Sopenharmony_ci}
10032ffe3c632Sopenharmony_ci
10033ffe3c632Sopenharmony_ci@end
10034ffe3c632Sopenharmony_ci
10035ffe3c632Sopenharmony_ci// clang-format on
10036ffe3c632Sopenharmony_ci//%PDDM-EXPAND-END (5 expansions)
10037ffe3c632Sopenharmony_ci
10038ffe3c632Sopenharmony_ci
10039ffe3c632Sopenharmony_ci//%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(UInt32, uint32_t)
10040ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly.
10041ffe3c632Sopenharmony_ci// clang-format off
10042ffe3c632Sopenharmony_ci
10043ffe3c632Sopenharmony_ci#pragma mark - Bool -> UInt32
10044ffe3c632Sopenharmony_ci
10045ffe3c632Sopenharmony_ci@implementation GPBBoolUInt32Dictionary {
10046ffe3c632Sopenharmony_ci @package
10047ffe3c632Sopenharmony_ci  uint32_t _values[2];
10048ffe3c632Sopenharmony_ci  BOOL _valueSet[2];
10049ffe3c632Sopenharmony_ci}
10050ffe3c632Sopenharmony_ci
10051ffe3c632Sopenharmony_ci- (instancetype)init {
10052ffe3c632Sopenharmony_ci  return [self initWithUInt32s:NULL forKeys:NULL count:0];
10053ffe3c632Sopenharmony_ci}
10054ffe3c632Sopenharmony_ci
10055ffe3c632Sopenharmony_ci- (instancetype)initWithUInt32s:(const uint32_t [])values
10056ffe3c632Sopenharmony_ci                        forKeys:(const BOOL [])keys
10057ffe3c632Sopenharmony_ci                          count:(NSUInteger)count {
10058ffe3c632Sopenharmony_ci  self = [super init];
10059ffe3c632Sopenharmony_ci  if (self) {
10060ffe3c632Sopenharmony_ci    for (NSUInteger i = 0; i < count; ++i) {
10061ffe3c632Sopenharmony_ci      int idx = keys[i] ? 1 : 0;
10062ffe3c632Sopenharmony_ci      _values[idx] = values[i];
10063ffe3c632Sopenharmony_ci      _valueSet[idx] = YES;
10064ffe3c632Sopenharmony_ci    }
10065ffe3c632Sopenharmony_ci  }
10066ffe3c632Sopenharmony_ci  return self;
10067ffe3c632Sopenharmony_ci}
10068ffe3c632Sopenharmony_ci
10069ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBBoolUInt32Dictionary *)dictionary {
10070ffe3c632Sopenharmony_ci  self = [self initWithUInt32s:NULL forKeys:NULL count:0];
10071ffe3c632Sopenharmony_ci  if (self) {
10072ffe3c632Sopenharmony_ci    if (dictionary) {
10073ffe3c632Sopenharmony_ci      for (int i = 0; i < 2; ++i) {
10074ffe3c632Sopenharmony_ci        if (dictionary->_valueSet[i]) {
10075ffe3c632Sopenharmony_ci          _values[i] = dictionary->_values[i];
10076ffe3c632Sopenharmony_ci          _valueSet[i] = YES;
10077ffe3c632Sopenharmony_ci        }
10078ffe3c632Sopenharmony_ci      }
10079ffe3c632Sopenharmony_ci    }
10080ffe3c632Sopenharmony_ci  }
10081ffe3c632Sopenharmony_ci  return self;
10082ffe3c632Sopenharmony_ci}
10083ffe3c632Sopenharmony_ci
10084ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
10085ffe3c632Sopenharmony_ci  #pragma unused(numItems)
10086ffe3c632Sopenharmony_ci  return [self initWithUInt32s:NULL forKeys:NULL count:0];
10087ffe3c632Sopenharmony_ci}
10088ffe3c632Sopenharmony_ci
10089ffe3c632Sopenharmony_ci#if !defined(NS_BLOCK_ASSERTIONS)
10090ffe3c632Sopenharmony_ci- (void)dealloc {
10091ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
10092ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
10093ffe3c632Sopenharmony_ci           [self class], _autocreator);
10094ffe3c632Sopenharmony_ci  [super dealloc];
10095ffe3c632Sopenharmony_ci}
10096ffe3c632Sopenharmony_ci#endif  // !defined(NS_BLOCK_ASSERTIONS)
10097ffe3c632Sopenharmony_ci
10098ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
10099ffe3c632Sopenharmony_ci  return [[GPBBoolUInt32Dictionary allocWithZone:zone] initWithDictionary:self];
10100ffe3c632Sopenharmony_ci}
10101ffe3c632Sopenharmony_ci
10102ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
10103ffe3c632Sopenharmony_ci  if (self == other) {
10104ffe3c632Sopenharmony_ci    return YES;
10105ffe3c632Sopenharmony_ci  }
10106ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBBoolUInt32Dictionary class]]) {
10107ffe3c632Sopenharmony_ci    return NO;
10108ffe3c632Sopenharmony_ci  }
10109ffe3c632Sopenharmony_ci  GPBBoolUInt32Dictionary *otherDictionary = other;
10110ffe3c632Sopenharmony_ci  if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
10111ffe3c632Sopenharmony_ci      (_valueSet[1] != otherDictionary->_valueSet[1])) {
10112ffe3c632Sopenharmony_ci    return NO;
10113ffe3c632Sopenharmony_ci  }
10114ffe3c632Sopenharmony_ci  if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
10115ffe3c632Sopenharmony_ci      (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
10116ffe3c632Sopenharmony_ci    return NO;
10117ffe3c632Sopenharmony_ci  }
10118ffe3c632Sopenharmony_ci  return YES;
10119ffe3c632Sopenharmony_ci}
10120ffe3c632Sopenharmony_ci
10121ffe3c632Sopenharmony_ci- (NSUInteger)hash {
10122ffe3c632Sopenharmony_ci  return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
10123ffe3c632Sopenharmony_ci}
10124ffe3c632Sopenharmony_ci
10125ffe3c632Sopenharmony_ci- (NSString *)description {
10126ffe3c632Sopenharmony_ci  NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
10127ffe3c632Sopenharmony_ci  if (_valueSet[0]) {
10128ffe3c632Sopenharmony_ci    [result appendFormat:@"NO: %u", _values[0]];
10129ffe3c632Sopenharmony_ci  }
10130ffe3c632Sopenharmony_ci  if (_valueSet[1]) {
10131ffe3c632Sopenharmony_ci    [result appendFormat:@"YES: %u", _values[1]];
10132ffe3c632Sopenharmony_ci  }
10133ffe3c632Sopenharmony_ci  [result appendString:@" }"];
10134ffe3c632Sopenharmony_ci  return result;
10135ffe3c632Sopenharmony_ci}
10136ffe3c632Sopenharmony_ci
10137ffe3c632Sopenharmony_ci- (NSUInteger)count {
10138ffe3c632Sopenharmony_ci  return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
10139ffe3c632Sopenharmony_ci}
10140ffe3c632Sopenharmony_ci
10141ffe3c632Sopenharmony_ci- (BOOL)getUInt32:(uint32_t *)value forKey:(BOOL)key {
10142ffe3c632Sopenharmony_ci  int idx = (key ? 1 : 0);
10143ffe3c632Sopenharmony_ci  if (_valueSet[idx]) {
10144ffe3c632Sopenharmony_ci    if (value) {
10145ffe3c632Sopenharmony_ci      *value = _values[idx];
10146ffe3c632Sopenharmony_ci    }
10147ffe3c632Sopenharmony_ci    return YES;
10148ffe3c632Sopenharmony_ci  }
10149ffe3c632Sopenharmony_ci  return NO;
10150ffe3c632Sopenharmony_ci}
10151ffe3c632Sopenharmony_ci
10152ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
10153ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
10154ffe3c632Sopenharmony_ci  int idx = (key->valueBool ? 1 : 0);
10155ffe3c632Sopenharmony_ci  _values[idx] = value->valueUInt32;
10156ffe3c632Sopenharmony_ci  _valueSet[idx] = YES;
10157ffe3c632Sopenharmony_ci}
10158ffe3c632Sopenharmony_ci
10159ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
10160ffe3c632Sopenharmony_ci  if (_valueSet[0]) {
10161ffe3c632Sopenharmony_ci    block(@"false", [NSString stringWithFormat:@"%u", _values[0]]);
10162ffe3c632Sopenharmony_ci  }
10163ffe3c632Sopenharmony_ci  if (_valueSet[1]) {
10164ffe3c632Sopenharmony_ci    block(@"true", [NSString stringWithFormat:@"%u", _values[1]]);
10165ffe3c632Sopenharmony_ci  }
10166ffe3c632Sopenharmony_ci}
10167ffe3c632Sopenharmony_ci
10168ffe3c632Sopenharmony_ci- (void)enumerateKeysAndUInt32sUsingBlock:
10169ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(BOOL key, uint32_t value, BOOL *stop))block {
10170ffe3c632Sopenharmony_ci  BOOL stop = NO;
10171ffe3c632Sopenharmony_ci  if (_valueSet[0]) {
10172ffe3c632Sopenharmony_ci    block(NO, _values[0], &stop);
10173ffe3c632Sopenharmony_ci  }
10174ffe3c632Sopenharmony_ci  if (!stop && _valueSet[1]) {
10175ffe3c632Sopenharmony_ci    block(YES, _values[1], &stop);
10176ffe3c632Sopenharmony_ci  }
10177ffe3c632Sopenharmony_ci}
10178ffe3c632Sopenharmony_ci
10179ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
10180ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
10181ffe3c632Sopenharmony_ci  NSUInteger count = 0;
10182ffe3c632Sopenharmony_ci  size_t result = 0;
10183ffe3c632Sopenharmony_ci  for (int i = 0; i < 2; ++i) {
10184ffe3c632Sopenharmony_ci    if (_valueSet[i]) {
10185ffe3c632Sopenharmony_ci      ++count;
10186ffe3c632Sopenharmony_ci      size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10187ffe3c632Sopenharmony_ci      msgSize += ComputeDictUInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
10188ffe3c632Sopenharmony_ci      result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
10189ffe3c632Sopenharmony_ci    }
10190ffe3c632Sopenharmony_ci  }
10191ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
10192ffe3c632Sopenharmony_ci  result += tagSize * count;
10193ffe3c632Sopenharmony_ci  return result;
10194ffe3c632Sopenharmony_ci}
10195ffe3c632Sopenharmony_ci
10196ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
10197ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
10198ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
10199ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
10200ffe3c632Sopenharmony_ci  for (int i = 0; i < 2; ++i) {
10201ffe3c632Sopenharmony_ci    if (_valueSet[i]) {
10202ffe3c632Sopenharmony_ci      // Write the tag.
10203ffe3c632Sopenharmony_ci      [outputStream writeInt32NoTag:tag];
10204ffe3c632Sopenharmony_ci      // Write the size of the message.
10205ffe3c632Sopenharmony_ci      size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10206ffe3c632Sopenharmony_ci      msgSize += ComputeDictUInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
10207ffe3c632Sopenharmony_ci      [outputStream writeInt32NoTag:(int32_t)msgSize];
10208ffe3c632Sopenharmony_ci      // Write the fields.
10209ffe3c632Sopenharmony_ci      WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10210ffe3c632Sopenharmony_ci      WriteDictUInt32Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
10211ffe3c632Sopenharmony_ci    }
10212ffe3c632Sopenharmony_ci  }
10213ffe3c632Sopenharmony_ci}
10214ffe3c632Sopenharmony_ci
10215ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBBoolUInt32Dictionary *)otherDictionary {
10216ffe3c632Sopenharmony_ci  if (otherDictionary) {
10217ffe3c632Sopenharmony_ci    for (int i = 0; i < 2; ++i) {
10218ffe3c632Sopenharmony_ci      if (otherDictionary->_valueSet[i]) {
10219ffe3c632Sopenharmony_ci        _valueSet[i] = YES;
10220ffe3c632Sopenharmony_ci        _values[i] = otherDictionary->_values[i];
10221ffe3c632Sopenharmony_ci      }
10222ffe3c632Sopenharmony_ci    }
10223ffe3c632Sopenharmony_ci    if (_autocreator) {
10224ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
10225ffe3c632Sopenharmony_ci    }
10226ffe3c632Sopenharmony_ci  }
10227ffe3c632Sopenharmony_ci}
10228ffe3c632Sopenharmony_ci
10229ffe3c632Sopenharmony_ci- (void)setUInt32:(uint32_t)value forKey:(BOOL)key {
10230ffe3c632Sopenharmony_ci  int idx = (key ? 1 : 0);
10231ffe3c632Sopenharmony_ci  _values[idx] = value;
10232ffe3c632Sopenharmony_ci  _valueSet[idx] = YES;
10233ffe3c632Sopenharmony_ci  if (_autocreator) {
10234ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
10235ffe3c632Sopenharmony_ci  }
10236ffe3c632Sopenharmony_ci}
10237ffe3c632Sopenharmony_ci
10238ffe3c632Sopenharmony_ci- (void)removeUInt32ForKey:(BOOL)aKey {
10239ffe3c632Sopenharmony_ci  _valueSet[aKey ? 1 : 0] = NO;
10240ffe3c632Sopenharmony_ci}
10241ffe3c632Sopenharmony_ci
10242ffe3c632Sopenharmony_ci- (void)removeAll {
10243ffe3c632Sopenharmony_ci  _valueSet[0] = NO;
10244ffe3c632Sopenharmony_ci  _valueSet[1] = NO;
10245ffe3c632Sopenharmony_ci}
10246ffe3c632Sopenharmony_ci
10247ffe3c632Sopenharmony_ci@end
10248ffe3c632Sopenharmony_ci
10249ffe3c632Sopenharmony_ci// clang-format on
10250ffe3c632Sopenharmony_ci//%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Int32, int32_t)
10251ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly.
10252ffe3c632Sopenharmony_ci// clang-format off
10253ffe3c632Sopenharmony_ci
10254ffe3c632Sopenharmony_ci#pragma mark - Bool -> Int32
10255ffe3c632Sopenharmony_ci
10256ffe3c632Sopenharmony_ci@implementation GPBBoolInt32Dictionary {
10257ffe3c632Sopenharmony_ci @package
10258ffe3c632Sopenharmony_ci  int32_t _values[2];
10259ffe3c632Sopenharmony_ci  BOOL _valueSet[2];
10260ffe3c632Sopenharmony_ci}
10261ffe3c632Sopenharmony_ci
10262ffe3c632Sopenharmony_ci- (instancetype)init {
10263ffe3c632Sopenharmony_ci  return [self initWithInt32s:NULL forKeys:NULL count:0];
10264ffe3c632Sopenharmony_ci}
10265ffe3c632Sopenharmony_ci
10266ffe3c632Sopenharmony_ci- (instancetype)initWithInt32s:(const int32_t [])values
10267ffe3c632Sopenharmony_ci                       forKeys:(const BOOL [])keys
10268ffe3c632Sopenharmony_ci                         count:(NSUInteger)count {
10269ffe3c632Sopenharmony_ci  self = [super init];
10270ffe3c632Sopenharmony_ci  if (self) {
10271ffe3c632Sopenharmony_ci    for (NSUInteger i = 0; i < count; ++i) {
10272ffe3c632Sopenharmony_ci      int idx = keys[i] ? 1 : 0;
10273ffe3c632Sopenharmony_ci      _values[idx] = values[i];
10274ffe3c632Sopenharmony_ci      _valueSet[idx] = YES;
10275ffe3c632Sopenharmony_ci    }
10276ffe3c632Sopenharmony_ci  }
10277ffe3c632Sopenharmony_ci  return self;
10278ffe3c632Sopenharmony_ci}
10279ffe3c632Sopenharmony_ci
10280ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBBoolInt32Dictionary *)dictionary {
10281ffe3c632Sopenharmony_ci  self = [self initWithInt32s:NULL forKeys:NULL count:0];
10282ffe3c632Sopenharmony_ci  if (self) {
10283ffe3c632Sopenharmony_ci    if (dictionary) {
10284ffe3c632Sopenharmony_ci      for (int i = 0; i < 2; ++i) {
10285ffe3c632Sopenharmony_ci        if (dictionary->_valueSet[i]) {
10286ffe3c632Sopenharmony_ci          _values[i] = dictionary->_values[i];
10287ffe3c632Sopenharmony_ci          _valueSet[i] = YES;
10288ffe3c632Sopenharmony_ci        }
10289ffe3c632Sopenharmony_ci      }
10290ffe3c632Sopenharmony_ci    }
10291ffe3c632Sopenharmony_ci  }
10292ffe3c632Sopenharmony_ci  return self;
10293ffe3c632Sopenharmony_ci}
10294ffe3c632Sopenharmony_ci
10295ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
10296ffe3c632Sopenharmony_ci  #pragma unused(numItems)
10297ffe3c632Sopenharmony_ci  return [self initWithInt32s:NULL forKeys:NULL count:0];
10298ffe3c632Sopenharmony_ci}
10299ffe3c632Sopenharmony_ci
10300ffe3c632Sopenharmony_ci#if !defined(NS_BLOCK_ASSERTIONS)
10301ffe3c632Sopenharmony_ci- (void)dealloc {
10302ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
10303ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
10304ffe3c632Sopenharmony_ci           [self class], _autocreator);
10305ffe3c632Sopenharmony_ci  [super dealloc];
10306ffe3c632Sopenharmony_ci}
10307ffe3c632Sopenharmony_ci#endif  // !defined(NS_BLOCK_ASSERTIONS)
10308ffe3c632Sopenharmony_ci
10309ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
10310ffe3c632Sopenharmony_ci  return [[GPBBoolInt32Dictionary allocWithZone:zone] initWithDictionary:self];
10311ffe3c632Sopenharmony_ci}
10312ffe3c632Sopenharmony_ci
10313ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
10314ffe3c632Sopenharmony_ci  if (self == other) {
10315ffe3c632Sopenharmony_ci    return YES;
10316ffe3c632Sopenharmony_ci  }
10317ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBBoolInt32Dictionary class]]) {
10318ffe3c632Sopenharmony_ci    return NO;
10319ffe3c632Sopenharmony_ci  }
10320ffe3c632Sopenharmony_ci  GPBBoolInt32Dictionary *otherDictionary = other;
10321ffe3c632Sopenharmony_ci  if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
10322ffe3c632Sopenharmony_ci      (_valueSet[1] != otherDictionary->_valueSet[1])) {
10323ffe3c632Sopenharmony_ci    return NO;
10324ffe3c632Sopenharmony_ci  }
10325ffe3c632Sopenharmony_ci  if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
10326ffe3c632Sopenharmony_ci      (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
10327ffe3c632Sopenharmony_ci    return NO;
10328ffe3c632Sopenharmony_ci  }
10329ffe3c632Sopenharmony_ci  return YES;
10330ffe3c632Sopenharmony_ci}
10331ffe3c632Sopenharmony_ci
10332ffe3c632Sopenharmony_ci- (NSUInteger)hash {
10333ffe3c632Sopenharmony_ci  return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
10334ffe3c632Sopenharmony_ci}
10335ffe3c632Sopenharmony_ci
10336ffe3c632Sopenharmony_ci- (NSString *)description {
10337ffe3c632Sopenharmony_ci  NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
10338ffe3c632Sopenharmony_ci  if (_valueSet[0]) {
10339ffe3c632Sopenharmony_ci    [result appendFormat:@"NO: %d", _values[0]];
10340ffe3c632Sopenharmony_ci  }
10341ffe3c632Sopenharmony_ci  if (_valueSet[1]) {
10342ffe3c632Sopenharmony_ci    [result appendFormat:@"YES: %d", _values[1]];
10343ffe3c632Sopenharmony_ci  }
10344ffe3c632Sopenharmony_ci  [result appendString:@" }"];
10345ffe3c632Sopenharmony_ci  return result;
10346ffe3c632Sopenharmony_ci}
10347ffe3c632Sopenharmony_ci
10348ffe3c632Sopenharmony_ci- (NSUInteger)count {
10349ffe3c632Sopenharmony_ci  return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
10350ffe3c632Sopenharmony_ci}
10351ffe3c632Sopenharmony_ci
10352ffe3c632Sopenharmony_ci- (BOOL)getInt32:(int32_t *)value forKey:(BOOL)key {
10353ffe3c632Sopenharmony_ci  int idx = (key ? 1 : 0);
10354ffe3c632Sopenharmony_ci  if (_valueSet[idx]) {
10355ffe3c632Sopenharmony_ci    if (value) {
10356ffe3c632Sopenharmony_ci      *value = _values[idx];
10357ffe3c632Sopenharmony_ci    }
10358ffe3c632Sopenharmony_ci    return YES;
10359ffe3c632Sopenharmony_ci  }
10360ffe3c632Sopenharmony_ci  return NO;
10361ffe3c632Sopenharmony_ci}
10362ffe3c632Sopenharmony_ci
10363ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
10364ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
10365ffe3c632Sopenharmony_ci  int idx = (key->valueBool ? 1 : 0);
10366ffe3c632Sopenharmony_ci  _values[idx] = value->valueInt32;
10367ffe3c632Sopenharmony_ci  _valueSet[idx] = YES;
10368ffe3c632Sopenharmony_ci}
10369ffe3c632Sopenharmony_ci
10370ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
10371ffe3c632Sopenharmony_ci  if (_valueSet[0]) {
10372ffe3c632Sopenharmony_ci    block(@"false", [NSString stringWithFormat:@"%d", _values[0]]);
10373ffe3c632Sopenharmony_ci  }
10374ffe3c632Sopenharmony_ci  if (_valueSet[1]) {
10375ffe3c632Sopenharmony_ci    block(@"true", [NSString stringWithFormat:@"%d", _values[1]]);
10376ffe3c632Sopenharmony_ci  }
10377ffe3c632Sopenharmony_ci}
10378ffe3c632Sopenharmony_ci
10379ffe3c632Sopenharmony_ci- (void)enumerateKeysAndInt32sUsingBlock:
10380ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(BOOL key, int32_t value, BOOL *stop))block {
10381ffe3c632Sopenharmony_ci  BOOL stop = NO;
10382ffe3c632Sopenharmony_ci  if (_valueSet[0]) {
10383ffe3c632Sopenharmony_ci    block(NO, _values[0], &stop);
10384ffe3c632Sopenharmony_ci  }
10385ffe3c632Sopenharmony_ci  if (!stop && _valueSet[1]) {
10386ffe3c632Sopenharmony_ci    block(YES, _values[1], &stop);
10387ffe3c632Sopenharmony_ci  }
10388ffe3c632Sopenharmony_ci}
10389ffe3c632Sopenharmony_ci
10390ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
10391ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
10392ffe3c632Sopenharmony_ci  NSUInteger count = 0;
10393ffe3c632Sopenharmony_ci  size_t result = 0;
10394ffe3c632Sopenharmony_ci  for (int i = 0; i < 2; ++i) {
10395ffe3c632Sopenharmony_ci    if (_valueSet[i]) {
10396ffe3c632Sopenharmony_ci      ++count;
10397ffe3c632Sopenharmony_ci      size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10398ffe3c632Sopenharmony_ci      msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
10399ffe3c632Sopenharmony_ci      result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
10400ffe3c632Sopenharmony_ci    }
10401ffe3c632Sopenharmony_ci  }
10402ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
10403ffe3c632Sopenharmony_ci  result += tagSize * count;
10404ffe3c632Sopenharmony_ci  return result;
10405ffe3c632Sopenharmony_ci}
10406ffe3c632Sopenharmony_ci
10407ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
10408ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
10409ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
10410ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
10411ffe3c632Sopenharmony_ci  for (int i = 0; i < 2; ++i) {
10412ffe3c632Sopenharmony_ci    if (_valueSet[i]) {
10413ffe3c632Sopenharmony_ci      // Write the tag.
10414ffe3c632Sopenharmony_ci      [outputStream writeInt32NoTag:tag];
10415ffe3c632Sopenharmony_ci      // Write the size of the message.
10416ffe3c632Sopenharmony_ci      size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10417ffe3c632Sopenharmony_ci      msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
10418ffe3c632Sopenharmony_ci      [outputStream writeInt32NoTag:(int32_t)msgSize];
10419ffe3c632Sopenharmony_ci      // Write the fields.
10420ffe3c632Sopenharmony_ci      WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10421ffe3c632Sopenharmony_ci      WriteDictInt32Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
10422ffe3c632Sopenharmony_ci    }
10423ffe3c632Sopenharmony_ci  }
10424ffe3c632Sopenharmony_ci}
10425ffe3c632Sopenharmony_ci
10426ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBBoolInt32Dictionary *)otherDictionary {
10427ffe3c632Sopenharmony_ci  if (otherDictionary) {
10428ffe3c632Sopenharmony_ci    for (int i = 0; i < 2; ++i) {
10429ffe3c632Sopenharmony_ci      if (otherDictionary->_valueSet[i]) {
10430ffe3c632Sopenharmony_ci        _valueSet[i] = YES;
10431ffe3c632Sopenharmony_ci        _values[i] = otherDictionary->_values[i];
10432ffe3c632Sopenharmony_ci      }
10433ffe3c632Sopenharmony_ci    }
10434ffe3c632Sopenharmony_ci    if (_autocreator) {
10435ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
10436ffe3c632Sopenharmony_ci    }
10437ffe3c632Sopenharmony_ci  }
10438ffe3c632Sopenharmony_ci}
10439ffe3c632Sopenharmony_ci
10440ffe3c632Sopenharmony_ci- (void)setInt32:(int32_t)value forKey:(BOOL)key {
10441ffe3c632Sopenharmony_ci  int idx = (key ? 1 : 0);
10442ffe3c632Sopenharmony_ci  _values[idx] = value;
10443ffe3c632Sopenharmony_ci  _valueSet[idx] = YES;
10444ffe3c632Sopenharmony_ci  if (_autocreator) {
10445ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
10446ffe3c632Sopenharmony_ci  }
10447ffe3c632Sopenharmony_ci}
10448ffe3c632Sopenharmony_ci
10449ffe3c632Sopenharmony_ci- (void)removeInt32ForKey:(BOOL)aKey {
10450ffe3c632Sopenharmony_ci  _valueSet[aKey ? 1 : 0] = NO;
10451ffe3c632Sopenharmony_ci}
10452ffe3c632Sopenharmony_ci
10453ffe3c632Sopenharmony_ci- (void)removeAll {
10454ffe3c632Sopenharmony_ci  _valueSet[0] = NO;
10455ffe3c632Sopenharmony_ci  _valueSet[1] = NO;
10456ffe3c632Sopenharmony_ci}
10457ffe3c632Sopenharmony_ci
10458ffe3c632Sopenharmony_ci@end
10459ffe3c632Sopenharmony_ci
10460ffe3c632Sopenharmony_ci// clang-format on
10461ffe3c632Sopenharmony_ci//%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(UInt64, uint64_t)
10462ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly.
10463ffe3c632Sopenharmony_ci// clang-format off
10464ffe3c632Sopenharmony_ci
10465ffe3c632Sopenharmony_ci#pragma mark - Bool -> UInt64
10466ffe3c632Sopenharmony_ci
10467ffe3c632Sopenharmony_ci@implementation GPBBoolUInt64Dictionary {
10468ffe3c632Sopenharmony_ci @package
10469ffe3c632Sopenharmony_ci  uint64_t _values[2];
10470ffe3c632Sopenharmony_ci  BOOL _valueSet[2];
10471ffe3c632Sopenharmony_ci}
10472ffe3c632Sopenharmony_ci
10473ffe3c632Sopenharmony_ci- (instancetype)init {
10474ffe3c632Sopenharmony_ci  return [self initWithUInt64s:NULL forKeys:NULL count:0];
10475ffe3c632Sopenharmony_ci}
10476ffe3c632Sopenharmony_ci
10477ffe3c632Sopenharmony_ci- (instancetype)initWithUInt64s:(const uint64_t [])values
10478ffe3c632Sopenharmony_ci                        forKeys:(const BOOL [])keys
10479ffe3c632Sopenharmony_ci                          count:(NSUInteger)count {
10480ffe3c632Sopenharmony_ci  self = [super init];
10481ffe3c632Sopenharmony_ci  if (self) {
10482ffe3c632Sopenharmony_ci    for (NSUInteger i = 0; i < count; ++i) {
10483ffe3c632Sopenharmony_ci      int idx = keys[i] ? 1 : 0;
10484ffe3c632Sopenharmony_ci      _values[idx] = values[i];
10485ffe3c632Sopenharmony_ci      _valueSet[idx] = YES;
10486ffe3c632Sopenharmony_ci    }
10487ffe3c632Sopenharmony_ci  }
10488ffe3c632Sopenharmony_ci  return self;
10489ffe3c632Sopenharmony_ci}
10490ffe3c632Sopenharmony_ci
10491ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBBoolUInt64Dictionary *)dictionary {
10492ffe3c632Sopenharmony_ci  self = [self initWithUInt64s:NULL forKeys:NULL count:0];
10493ffe3c632Sopenharmony_ci  if (self) {
10494ffe3c632Sopenharmony_ci    if (dictionary) {
10495ffe3c632Sopenharmony_ci      for (int i = 0; i < 2; ++i) {
10496ffe3c632Sopenharmony_ci        if (dictionary->_valueSet[i]) {
10497ffe3c632Sopenharmony_ci          _values[i] = dictionary->_values[i];
10498ffe3c632Sopenharmony_ci          _valueSet[i] = YES;
10499ffe3c632Sopenharmony_ci        }
10500ffe3c632Sopenharmony_ci      }
10501ffe3c632Sopenharmony_ci    }
10502ffe3c632Sopenharmony_ci  }
10503ffe3c632Sopenharmony_ci  return self;
10504ffe3c632Sopenharmony_ci}
10505ffe3c632Sopenharmony_ci
10506ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
10507ffe3c632Sopenharmony_ci  #pragma unused(numItems)
10508ffe3c632Sopenharmony_ci  return [self initWithUInt64s:NULL forKeys:NULL count:0];
10509ffe3c632Sopenharmony_ci}
10510ffe3c632Sopenharmony_ci
10511ffe3c632Sopenharmony_ci#if !defined(NS_BLOCK_ASSERTIONS)
10512ffe3c632Sopenharmony_ci- (void)dealloc {
10513ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
10514ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
10515ffe3c632Sopenharmony_ci           [self class], _autocreator);
10516ffe3c632Sopenharmony_ci  [super dealloc];
10517ffe3c632Sopenharmony_ci}
10518ffe3c632Sopenharmony_ci#endif  // !defined(NS_BLOCK_ASSERTIONS)
10519ffe3c632Sopenharmony_ci
10520ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
10521ffe3c632Sopenharmony_ci  return [[GPBBoolUInt64Dictionary allocWithZone:zone] initWithDictionary:self];
10522ffe3c632Sopenharmony_ci}
10523ffe3c632Sopenharmony_ci
10524ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
10525ffe3c632Sopenharmony_ci  if (self == other) {
10526ffe3c632Sopenharmony_ci    return YES;
10527ffe3c632Sopenharmony_ci  }
10528ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBBoolUInt64Dictionary class]]) {
10529ffe3c632Sopenharmony_ci    return NO;
10530ffe3c632Sopenharmony_ci  }
10531ffe3c632Sopenharmony_ci  GPBBoolUInt64Dictionary *otherDictionary = other;
10532ffe3c632Sopenharmony_ci  if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
10533ffe3c632Sopenharmony_ci      (_valueSet[1] != otherDictionary->_valueSet[1])) {
10534ffe3c632Sopenharmony_ci    return NO;
10535ffe3c632Sopenharmony_ci  }
10536ffe3c632Sopenharmony_ci  if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
10537ffe3c632Sopenharmony_ci      (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
10538ffe3c632Sopenharmony_ci    return NO;
10539ffe3c632Sopenharmony_ci  }
10540ffe3c632Sopenharmony_ci  return YES;
10541ffe3c632Sopenharmony_ci}
10542ffe3c632Sopenharmony_ci
10543ffe3c632Sopenharmony_ci- (NSUInteger)hash {
10544ffe3c632Sopenharmony_ci  return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
10545ffe3c632Sopenharmony_ci}
10546ffe3c632Sopenharmony_ci
10547ffe3c632Sopenharmony_ci- (NSString *)description {
10548ffe3c632Sopenharmony_ci  NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
10549ffe3c632Sopenharmony_ci  if (_valueSet[0]) {
10550ffe3c632Sopenharmony_ci    [result appendFormat:@"NO: %llu", _values[0]];
10551ffe3c632Sopenharmony_ci  }
10552ffe3c632Sopenharmony_ci  if (_valueSet[1]) {
10553ffe3c632Sopenharmony_ci    [result appendFormat:@"YES: %llu", _values[1]];
10554ffe3c632Sopenharmony_ci  }
10555ffe3c632Sopenharmony_ci  [result appendString:@" }"];
10556ffe3c632Sopenharmony_ci  return result;
10557ffe3c632Sopenharmony_ci}
10558ffe3c632Sopenharmony_ci
10559ffe3c632Sopenharmony_ci- (NSUInteger)count {
10560ffe3c632Sopenharmony_ci  return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
10561ffe3c632Sopenharmony_ci}
10562ffe3c632Sopenharmony_ci
10563ffe3c632Sopenharmony_ci- (BOOL)getUInt64:(uint64_t *)value forKey:(BOOL)key {
10564ffe3c632Sopenharmony_ci  int idx = (key ? 1 : 0);
10565ffe3c632Sopenharmony_ci  if (_valueSet[idx]) {
10566ffe3c632Sopenharmony_ci    if (value) {
10567ffe3c632Sopenharmony_ci      *value = _values[idx];
10568ffe3c632Sopenharmony_ci    }
10569ffe3c632Sopenharmony_ci    return YES;
10570ffe3c632Sopenharmony_ci  }
10571ffe3c632Sopenharmony_ci  return NO;
10572ffe3c632Sopenharmony_ci}
10573ffe3c632Sopenharmony_ci
10574ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
10575ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
10576ffe3c632Sopenharmony_ci  int idx = (key->valueBool ? 1 : 0);
10577ffe3c632Sopenharmony_ci  _values[idx] = value->valueUInt64;
10578ffe3c632Sopenharmony_ci  _valueSet[idx] = YES;
10579ffe3c632Sopenharmony_ci}
10580ffe3c632Sopenharmony_ci
10581ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
10582ffe3c632Sopenharmony_ci  if (_valueSet[0]) {
10583ffe3c632Sopenharmony_ci    block(@"false", [NSString stringWithFormat:@"%llu", _values[0]]);
10584ffe3c632Sopenharmony_ci  }
10585ffe3c632Sopenharmony_ci  if (_valueSet[1]) {
10586ffe3c632Sopenharmony_ci    block(@"true", [NSString stringWithFormat:@"%llu", _values[1]]);
10587ffe3c632Sopenharmony_ci  }
10588ffe3c632Sopenharmony_ci}
10589ffe3c632Sopenharmony_ci
10590ffe3c632Sopenharmony_ci- (void)enumerateKeysAndUInt64sUsingBlock:
10591ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(BOOL key, uint64_t value, BOOL *stop))block {
10592ffe3c632Sopenharmony_ci  BOOL stop = NO;
10593ffe3c632Sopenharmony_ci  if (_valueSet[0]) {
10594ffe3c632Sopenharmony_ci    block(NO, _values[0], &stop);
10595ffe3c632Sopenharmony_ci  }
10596ffe3c632Sopenharmony_ci  if (!stop && _valueSet[1]) {
10597ffe3c632Sopenharmony_ci    block(YES, _values[1], &stop);
10598ffe3c632Sopenharmony_ci  }
10599ffe3c632Sopenharmony_ci}
10600ffe3c632Sopenharmony_ci
10601ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
10602ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
10603ffe3c632Sopenharmony_ci  NSUInteger count = 0;
10604ffe3c632Sopenharmony_ci  size_t result = 0;
10605ffe3c632Sopenharmony_ci  for (int i = 0; i < 2; ++i) {
10606ffe3c632Sopenharmony_ci    if (_valueSet[i]) {
10607ffe3c632Sopenharmony_ci      ++count;
10608ffe3c632Sopenharmony_ci      size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10609ffe3c632Sopenharmony_ci      msgSize += ComputeDictUInt64FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
10610ffe3c632Sopenharmony_ci      result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
10611ffe3c632Sopenharmony_ci    }
10612ffe3c632Sopenharmony_ci  }
10613ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
10614ffe3c632Sopenharmony_ci  result += tagSize * count;
10615ffe3c632Sopenharmony_ci  return result;
10616ffe3c632Sopenharmony_ci}
10617ffe3c632Sopenharmony_ci
10618ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
10619ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
10620ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
10621ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
10622ffe3c632Sopenharmony_ci  for (int i = 0; i < 2; ++i) {
10623ffe3c632Sopenharmony_ci    if (_valueSet[i]) {
10624ffe3c632Sopenharmony_ci      // Write the tag.
10625ffe3c632Sopenharmony_ci      [outputStream writeInt32NoTag:tag];
10626ffe3c632Sopenharmony_ci      // Write the size of the message.
10627ffe3c632Sopenharmony_ci      size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10628ffe3c632Sopenharmony_ci      msgSize += ComputeDictUInt64FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
10629ffe3c632Sopenharmony_ci      [outputStream writeInt32NoTag:(int32_t)msgSize];
10630ffe3c632Sopenharmony_ci      // Write the fields.
10631ffe3c632Sopenharmony_ci      WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10632ffe3c632Sopenharmony_ci      WriteDictUInt64Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
10633ffe3c632Sopenharmony_ci    }
10634ffe3c632Sopenharmony_ci  }
10635ffe3c632Sopenharmony_ci}
10636ffe3c632Sopenharmony_ci
10637ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBBoolUInt64Dictionary *)otherDictionary {
10638ffe3c632Sopenharmony_ci  if (otherDictionary) {
10639ffe3c632Sopenharmony_ci    for (int i = 0; i < 2; ++i) {
10640ffe3c632Sopenharmony_ci      if (otherDictionary->_valueSet[i]) {
10641ffe3c632Sopenharmony_ci        _valueSet[i] = YES;
10642ffe3c632Sopenharmony_ci        _values[i] = otherDictionary->_values[i];
10643ffe3c632Sopenharmony_ci      }
10644ffe3c632Sopenharmony_ci    }
10645ffe3c632Sopenharmony_ci    if (_autocreator) {
10646ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
10647ffe3c632Sopenharmony_ci    }
10648ffe3c632Sopenharmony_ci  }
10649ffe3c632Sopenharmony_ci}
10650ffe3c632Sopenharmony_ci
10651ffe3c632Sopenharmony_ci- (void)setUInt64:(uint64_t)value forKey:(BOOL)key {
10652ffe3c632Sopenharmony_ci  int idx = (key ? 1 : 0);
10653ffe3c632Sopenharmony_ci  _values[idx] = value;
10654ffe3c632Sopenharmony_ci  _valueSet[idx] = YES;
10655ffe3c632Sopenharmony_ci  if (_autocreator) {
10656ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
10657ffe3c632Sopenharmony_ci  }
10658ffe3c632Sopenharmony_ci}
10659ffe3c632Sopenharmony_ci
10660ffe3c632Sopenharmony_ci- (void)removeUInt64ForKey:(BOOL)aKey {
10661ffe3c632Sopenharmony_ci  _valueSet[aKey ? 1 : 0] = NO;
10662ffe3c632Sopenharmony_ci}
10663ffe3c632Sopenharmony_ci
10664ffe3c632Sopenharmony_ci- (void)removeAll {
10665ffe3c632Sopenharmony_ci  _valueSet[0] = NO;
10666ffe3c632Sopenharmony_ci  _valueSet[1] = NO;
10667ffe3c632Sopenharmony_ci}
10668ffe3c632Sopenharmony_ci
10669ffe3c632Sopenharmony_ci@end
10670ffe3c632Sopenharmony_ci
10671ffe3c632Sopenharmony_ci// clang-format on
10672ffe3c632Sopenharmony_ci//%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Int64, int64_t)
10673ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly.
10674ffe3c632Sopenharmony_ci// clang-format off
10675ffe3c632Sopenharmony_ci
10676ffe3c632Sopenharmony_ci#pragma mark - Bool -> Int64
10677ffe3c632Sopenharmony_ci
10678ffe3c632Sopenharmony_ci@implementation GPBBoolInt64Dictionary {
10679ffe3c632Sopenharmony_ci @package
10680ffe3c632Sopenharmony_ci  int64_t _values[2];
10681ffe3c632Sopenharmony_ci  BOOL _valueSet[2];
10682ffe3c632Sopenharmony_ci}
10683ffe3c632Sopenharmony_ci
10684ffe3c632Sopenharmony_ci- (instancetype)init {
10685ffe3c632Sopenharmony_ci  return [self initWithInt64s:NULL forKeys:NULL count:0];
10686ffe3c632Sopenharmony_ci}
10687ffe3c632Sopenharmony_ci
10688ffe3c632Sopenharmony_ci- (instancetype)initWithInt64s:(const int64_t [])values
10689ffe3c632Sopenharmony_ci                       forKeys:(const BOOL [])keys
10690ffe3c632Sopenharmony_ci                         count:(NSUInteger)count {
10691ffe3c632Sopenharmony_ci  self = [super init];
10692ffe3c632Sopenharmony_ci  if (self) {
10693ffe3c632Sopenharmony_ci    for (NSUInteger i = 0; i < count; ++i) {
10694ffe3c632Sopenharmony_ci      int idx = keys[i] ? 1 : 0;
10695ffe3c632Sopenharmony_ci      _values[idx] = values[i];
10696ffe3c632Sopenharmony_ci      _valueSet[idx] = YES;
10697ffe3c632Sopenharmony_ci    }
10698ffe3c632Sopenharmony_ci  }
10699ffe3c632Sopenharmony_ci  return self;
10700ffe3c632Sopenharmony_ci}
10701ffe3c632Sopenharmony_ci
10702ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBBoolInt64Dictionary *)dictionary {
10703ffe3c632Sopenharmony_ci  self = [self initWithInt64s:NULL forKeys:NULL count:0];
10704ffe3c632Sopenharmony_ci  if (self) {
10705ffe3c632Sopenharmony_ci    if (dictionary) {
10706ffe3c632Sopenharmony_ci      for (int i = 0; i < 2; ++i) {
10707ffe3c632Sopenharmony_ci        if (dictionary->_valueSet[i]) {
10708ffe3c632Sopenharmony_ci          _values[i] = dictionary->_values[i];
10709ffe3c632Sopenharmony_ci          _valueSet[i] = YES;
10710ffe3c632Sopenharmony_ci        }
10711ffe3c632Sopenharmony_ci      }
10712ffe3c632Sopenharmony_ci    }
10713ffe3c632Sopenharmony_ci  }
10714ffe3c632Sopenharmony_ci  return self;
10715ffe3c632Sopenharmony_ci}
10716ffe3c632Sopenharmony_ci
10717ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
10718ffe3c632Sopenharmony_ci  #pragma unused(numItems)
10719ffe3c632Sopenharmony_ci  return [self initWithInt64s:NULL forKeys:NULL count:0];
10720ffe3c632Sopenharmony_ci}
10721ffe3c632Sopenharmony_ci
10722ffe3c632Sopenharmony_ci#if !defined(NS_BLOCK_ASSERTIONS)
10723ffe3c632Sopenharmony_ci- (void)dealloc {
10724ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
10725ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
10726ffe3c632Sopenharmony_ci           [self class], _autocreator);
10727ffe3c632Sopenharmony_ci  [super dealloc];
10728ffe3c632Sopenharmony_ci}
10729ffe3c632Sopenharmony_ci#endif  // !defined(NS_BLOCK_ASSERTIONS)
10730ffe3c632Sopenharmony_ci
10731ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
10732ffe3c632Sopenharmony_ci  return [[GPBBoolInt64Dictionary allocWithZone:zone] initWithDictionary:self];
10733ffe3c632Sopenharmony_ci}
10734ffe3c632Sopenharmony_ci
10735ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
10736ffe3c632Sopenharmony_ci  if (self == other) {
10737ffe3c632Sopenharmony_ci    return YES;
10738ffe3c632Sopenharmony_ci  }
10739ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBBoolInt64Dictionary class]]) {
10740ffe3c632Sopenharmony_ci    return NO;
10741ffe3c632Sopenharmony_ci  }
10742ffe3c632Sopenharmony_ci  GPBBoolInt64Dictionary *otherDictionary = other;
10743ffe3c632Sopenharmony_ci  if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
10744ffe3c632Sopenharmony_ci      (_valueSet[1] != otherDictionary->_valueSet[1])) {
10745ffe3c632Sopenharmony_ci    return NO;
10746ffe3c632Sopenharmony_ci  }
10747ffe3c632Sopenharmony_ci  if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
10748ffe3c632Sopenharmony_ci      (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
10749ffe3c632Sopenharmony_ci    return NO;
10750ffe3c632Sopenharmony_ci  }
10751ffe3c632Sopenharmony_ci  return YES;
10752ffe3c632Sopenharmony_ci}
10753ffe3c632Sopenharmony_ci
10754ffe3c632Sopenharmony_ci- (NSUInteger)hash {
10755ffe3c632Sopenharmony_ci  return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
10756ffe3c632Sopenharmony_ci}
10757ffe3c632Sopenharmony_ci
10758ffe3c632Sopenharmony_ci- (NSString *)description {
10759ffe3c632Sopenharmony_ci  NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
10760ffe3c632Sopenharmony_ci  if (_valueSet[0]) {
10761ffe3c632Sopenharmony_ci    [result appendFormat:@"NO: %lld", _values[0]];
10762ffe3c632Sopenharmony_ci  }
10763ffe3c632Sopenharmony_ci  if (_valueSet[1]) {
10764ffe3c632Sopenharmony_ci    [result appendFormat:@"YES: %lld", _values[1]];
10765ffe3c632Sopenharmony_ci  }
10766ffe3c632Sopenharmony_ci  [result appendString:@" }"];
10767ffe3c632Sopenharmony_ci  return result;
10768ffe3c632Sopenharmony_ci}
10769ffe3c632Sopenharmony_ci
10770ffe3c632Sopenharmony_ci- (NSUInteger)count {
10771ffe3c632Sopenharmony_ci  return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
10772ffe3c632Sopenharmony_ci}
10773ffe3c632Sopenharmony_ci
10774ffe3c632Sopenharmony_ci- (BOOL)getInt64:(int64_t *)value forKey:(BOOL)key {
10775ffe3c632Sopenharmony_ci  int idx = (key ? 1 : 0);
10776ffe3c632Sopenharmony_ci  if (_valueSet[idx]) {
10777ffe3c632Sopenharmony_ci    if (value) {
10778ffe3c632Sopenharmony_ci      *value = _values[idx];
10779ffe3c632Sopenharmony_ci    }
10780ffe3c632Sopenharmony_ci    return YES;
10781ffe3c632Sopenharmony_ci  }
10782ffe3c632Sopenharmony_ci  return NO;
10783ffe3c632Sopenharmony_ci}
10784ffe3c632Sopenharmony_ci
10785ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
10786ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
10787ffe3c632Sopenharmony_ci  int idx = (key->valueBool ? 1 : 0);
10788ffe3c632Sopenharmony_ci  _values[idx] = value->valueInt64;
10789ffe3c632Sopenharmony_ci  _valueSet[idx] = YES;
10790ffe3c632Sopenharmony_ci}
10791ffe3c632Sopenharmony_ci
10792ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
10793ffe3c632Sopenharmony_ci  if (_valueSet[0]) {
10794ffe3c632Sopenharmony_ci    block(@"false", [NSString stringWithFormat:@"%lld", _values[0]]);
10795ffe3c632Sopenharmony_ci  }
10796ffe3c632Sopenharmony_ci  if (_valueSet[1]) {
10797ffe3c632Sopenharmony_ci    block(@"true", [NSString stringWithFormat:@"%lld", _values[1]]);
10798ffe3c632Sopenharmony_ci  }
10799ffe3c632Sopenharmony_ci}
10800ffe3c632Sopenharmony_ci
10801ffe3c632Sopenharmony_ci- (void)enumerateKeysAndInt64sUsingBlock:
10802ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(BOOL key, int64_t value, BOOL *stop))block {
10803ffe3c632Sopenharmony_ci  BOOL stop = NO;
10804ffe3c632Sopenharmony_ci  if (_valueSet[0]) {
10805ffe3c632Sopenharmony_ci    block(NO, _values[0], &stop);
10806ffe3c632Sopenharmony_ci  }
10807ffe3c632Sopenharmony_ci  if (!stop && _valueSet[1]) {
10808ffe3c632Sopenharmony_ci    block(YES, _values[1], &stop);
10809ffe3c632Sopenharmony_ci  }
10810ffe3c632Sopenharmony_ci}
10811ffe3c632Sopenharmony_ci
10812ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
10813ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
10814ffe3c632Sopenharmony_ci  NSUInteger count = 0;
10815ffe3c632Sopenharmony_ci  size_t result = 0;
10816ffe3c632Sopenharmony_ci  for (int i = 0; i < 2; ++i) {
10817ffe3c632Sopenharmony_ci    if (_valueSet[i]) {
10818ffe3c632Sopenharmony_ci      ++count;
10819ffe3c632Sopenharmony_ci      size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10820ffe3c632Sopenharmony_ci      msgSize += ComputeDictInt64FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
10821ffe3c632Sopenharmony_ci      result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
10822ffe3c632Sopenharmony_ci    }
10823ffe3c632Sopenharmony_ci  }
10824ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
10825ffe3c632Sopenharmony_ci  result += tagSize * count;
10826ffe3c632Sopenharmony_ci  return result;
10827ffe3c632Sopenharmony_ci}
10828ffe3c632Sopenharmony_ci
10829ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
10830ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
10831ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
10832ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
10833ffe3c632Sopenharmony_ci  for (int i = 0; i < 2; ++i) {
10834ffe3c632Sopenharmony_ci    if (_valueSet[i]) {
10835ffe3c632Sopenharmony_ci      // Write the tag.
10836ffe3c632Sopenharmony_ci      [outputStream writeInt32NoTag:tag];
10837ffe3c632Sopenharmony_ci      // Write the size of the message.
10838ffe3c632Sopenharmony_ci      size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10839ffe3c632Sopenharmony_ci      msgSize += ComputeDictInt64FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
10840ffe3c632Sopenharmony_ci      [outputStream writeInt32NoTag:(int32_t)msgSize];
10841ffe3c632Sopenharmony_ci      // Write the fields.
10842ffe3c632Sopenharmony_ci      WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
10843ffe3c632Sopenharmony_ci      WriteDictInt64Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
10844ffe3c632Sopenharmony_ci    }
10845ffe3c632Sopenharmony_ci  }
10846ffe3c632Sopenharmony_ci}
10847ffe3c632Sopenharmony_ci
10848ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBBoolInt64Dictionary *)otherDictionary {
10849ffe3c632Sopenharmony_ci  if (otherDictionary) {
10850ffe3c632Sopenharmony_ci    for (int i = 0; i < 2; ++i) {
10851ffe3c632Sopenharmony_ci      if (otherDictionary->_valueSet[i]) {
10852ffe3c632Sopenharmony_ci        _valueSet[i] = YES;
10853ffe3c632Sopenharmony_ci        _values[i] = otherDictionary->_values[i];
10854ffe3c632Sopenharmony_ci      }
10855ffe3c632Sopenharmony_ci    }
10856ffe3c632Sopenharmony_ci    if (_autocreator) {
10857ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
10858ffe3c632Sopenharmony_ci    }
10859ffe3c632Sopenharmony_ci  }
10860ffe3c632Sopenharmony_ci}
10861ffe3c632Sopenharmony_ci
10862ffe3c632Sopenharmony_ci- (void)setInt64:(int64_t)value forKey:(BOOL)key {
10863ffe3c632Sopenharmony_ci  int idx = (key ? 1 : 0);
10864ffe3c632Sopenharmony_ci  _values[idx] = value;
10865ffe3c632Sopenharmony_ci  _valueSet[idx] = YES;
10866ffe3c632Sopenharmony_ci  if (_autocreator) {
10867ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
10868ffe3c632Sopenharmony_ci  }
10869ffe3c632Sopenharmony_ci}
10870ffe3c632Sopenharmony_ci
10871ffe3c632Sopenharmony_ci- (void)removeInt64ForKey:(BOOL)aKey {
10872ffe3c632Sopenharmony_ci  _valueSet[aKey ? 1 : 0] = NO;
10873ffe3c632Sopenharmony_ci}
10874ffe3c632Sopenharmony_ci
10875ffe3c632Sopenharmony_ci- (void)removeAll {
10876ffe3c632Sopenharmony_ci  _valueSet[0] = NO;
10877ffe3c632Sopenharmony_ci  _valueSet[1] = NO;
10878ffe3c632Sopenharmony_ci}
10879ffe3c632Sopenharmony_ci
10880ffe3c632Sopenharmony_ci@end
10881ffe3c632Sopenharmony_ci
10882ffe3c632Sopenharmony_ci// clang-format on
10883ffe3c632Sopenharmony_ci//%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Bool, BOOL)
10884ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly.
10885ffe3c632Sopenharmony_ci// clang-format off
10886ffe3c632Sopenharmony_ci
10887ffe3c632Sopenharmony_ci#pragma mark - Bool -> Bool
10888ffe3c632Sopenharmony_ci
10889ffe3c632Sopenharmony_ci@implementation GPBBoolBoolDictionary {
10890ffe3c632Sopenharmony_ci @package
10891ffe3c632Sopenharmony_ci  BOOL _values[2];
10892ffe3c632Sopenharmony_ci  BOOL _valueSet[2];
10893ffe3c632Sopenharmony_ci}
10894ffe3c632Sopenharmony_ci
10895ffe3c632Sopenharmony_ci- (instancetype)init {
10896ffe3c632Sopenharmony_ci  return [self initWithBools:NULL forKeys:NULL count:0];
10897ffe3c632Sopenharmony_ci}
10898ffe3c632Sopenharmony_ci
10899ffe3c632Sopenharmony_ci- (instancetype)initWithBools:(const BOOL [])values
10900ffe3c632Sopenharmony_ci                      forKeys:(const BOOL [])keys
10901ffe3c632Sopenharmony_ci                        count:(NSUInteger)count {
10902ffe3c632Sopenharmony_ci  self = [super init];
10903ffe3c632Sopenharmony_ci  if (self) {
10904ffe3c632Sopenharmony_ci    for (NSUInteger i = 0; i < count; ++i) {
10905ffe3c632Sopenharmony_ci      int idx = keys[i] ? 1 : 0;
10906ffe3c632Sopenharmony_ci      _values[idx] = values[i];
10907ffe3c632Sopenharmony_ci      _valueSet[idx] = YES;
10908ffe3c632Sopenharmony_ci    }
10909ffe3c632Sopenharmony_ci  }
10910ffe3c632Sopenharmony_ci  return self;
10911ffe3c632Sopenharmony_ci}
10912ffe3c632Sopenharmony_ci
10913ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBBoolBoolDictionary *)dictionary {
10914ffe3c632Sopenharmony_ci  self = [self initWithBools:NULL forKeys:NULL count:0];
10915ffe3c632Sopenharmony_ci  if (self) {
10916ffe3c632Sopenharmony_ci    if (dictionary) {
10917ffe3c632Sopenharmony_ci      for (int i = 0; i < 2; ++i) {
10918ffe3c632Sopenharmony_ci        if (dictionary->_valueSet[i]) {
10919ffe3c632Sopenharmony_ci          _values[i] = dictionary->_values[i];
10920ffe3c632Sopenharmony_ci          _valueSet[i] = YES;
10921ffe3c632Sopenharmony_ci        }
10922ffe3c632Sopenharmony_ci      }
10923ffe3c632Sopenharmony_ci    }
10924ffe3c632Sopenharmony_ci  }
10925ffe3c632Sopenharmony_ci  return self;
10926ffe3c632Sopenharmony_ci}
10927ffe3c632Sopenharmony_ci
10928ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
10929ffe3c632Sopenharmony_ci  #pragma unused(numItems)
10930ffe3c632Sopenharmony_ci  return [self initWithBools:NULL forKeys:NULL count:0];
10931ffe3c632Sopenharmony_ci}
10932ffe3c632Sopenharmony_ci
10933ffe3c632Sopenharmony_ci#if !defined(NS_BLOCK_ASSERTIONS)
10934ffe3c632Sopenharmony_ci- (void)dealloc {
10935ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
10936ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
10937ffe3c632Sopenharmony_ci           [self class], _autocreator);
10938ffe3c632Sopenharmony_ci  [super dealloc];
10939ffe3c632Sopenharmony_ci}
10940ffe3c632Sopenharmony_ci#endif  // !defined(NS_BLOCK_ASSERTIONS)
10941ffe3c632Sopenharmony_ci
10942ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
10943ffe3c632Sopenharmony_ci  return [[GPBBoolBoolDictionary allocWithZone:zone] initWithDictionary:self];
10944ffe3c632Sopenharmony_ci}
10945ffe3c632Sopenharmony_ci
10946ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
10947ffe3c632Sopenharmony_ci  if (self == other) {
10948ffe3c632Sopenharmony_ci    return YES;
10949ffe3c632Sopenharmony_ci  }
10950ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBBoolBoolDictionary class]]) {
10951ffe3c632Sopenharmony_ci    return NO;
10952ffe3c632Sopenharmony_ci  }
10953ffe3c632Sopenharmony_ci  GPBBoolBoolDictionary *otherDictionary = other;
10954ffe3c632Sopenharmony_ci  if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
10955ffe3c632Sopenharmony_ci      (_valueSet[1] != otherDictionary->_valueSet[1])) {
10956ffe3c632Sopenharmony_ci    return NO;
10957ffe3c632Sopenharmony_ci  }
10958ffe3c632Sopenharmony_ci  if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
10959ffe3c632Sopenharmony_ci      (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
10960ffe3c632Sopenharmony_ci    return NO;
10961ffe3c632Sopenharmony_ci  }
10962ffe3c632Sopenharmony_ci  return YES;
10963ffe3c632Sopenharmony_ci}
10964ffe3c632Sopenharmony_ci
10965ffe3c632Sopenharmony_ci- (NSUInteger)hash {
10966ffe3c632Sopenharmony_ci  return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
10967ffe3c632Sopenharmony_ci}
10968ffe3c632Sopenharmony_ci
10969ffe3c632Sopenharmony_ci- (NSString *)description {
10970ffe3c632Sopenharmony_ci  NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
10971ffe3c632Sopenharmony_ci  if (_valueSet[0]) {
10972ffe3c632Sopenharmony_ci    [result appendFormat:@"NO: %d", _values[0]];
10973ffe3c632Sopenharmony_ci  }
10974ffe3c632Sopenharmony_ci  if (_valueSet[1]) {
10975ffe3c632Sopenharmony_ci    [result appendFormat:@"YES: %d", _values[1]];
10976ffe3c632Sopenharmony_ci  }
10977ffe3c632Sopenharmony_ci  [result appendString:@" }"];
10978ffe3c632Sopenharmony_ci  return result;
10979ffe3c632Sopenharmony_ci}
10980ffe3c632Sopenharmony_ci
10981ffe3c632Sopenharmony_ci- (NSUInteger)count {
10982ffe3c632Sopenharmony_ci  return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
10983ffe3c632Sopenharmony_ci}
10984ffe3c632Sopenharmony_ci
10985ffe3c632Sopenharmony_ci- (BOOL)getBool:(BOOL *)value forKey:(BOOL)key {
10986ffe3c632Sopenharmony_ci  int idx = (key ? 1 : 0);
10987ffe3c632Sopenharmony_ci  if (_valueSet[idx]) {
10988ffe3c632Sopenharmony_ci    if (value) {
10989ffe3c632Sopenharmony_ci      *value = _values[idx];
10990ffe3c632Sopenharmony_ci    }
10991ffe3c632Sopenharmony_ci    return YES;
10992ffe3c632Sopenharmony_ci  }
10993ffe3c632Sopenharmony_ci  return NO;
10994ffe3c632Sopenharmony_ci}
10995ffe3c632Sopenharmony_ci
10996ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
10997ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
10998ffe3c632Sopenharmony_ci  int idx = (key->valueBool ? 1 : 0);
10999ffe3c632Sopenharmony_ci  _values[idx] = value->valueBool;
11000ffe3c632Sopenharmony_ci  _valueSet[idx] = YES;
11001ffe3c632Sopenharmony_ci}
11002ffe3c632Sopenharmony_ci
11003ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
11004ffe3c632Sopenharmony_ci  if (_valueSet[0]) {
11005ffe3c632Sopenharmony_ci    block(@"false", (_values[0] ? @"true" : @"false"));
11006ffe3c632Sopenharmony_ci  }
11007ffe3c632Sopenharmony_ci  if (_valueSet[1]) {
11008ffe3c632Sopenharmony_ci    block(@"true", (_values[1] ? @"true" : @"false"));
11009ffe3c632Sopenharmony_ci  }
11010ffe3c632Sopenharmony_ci}
11011ffe3c632Sopenharmony_ci
11012ffe3c632Sopenharmony_ci- (void)enumerateKeysAndBoolsUsingBlock:
11013ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(BOOL key, BOOL value, BOOL *stop))block {
11014ffe3c632Sopenharmony_ci  BOOL stop = NO;
11015ffe3c632Sopenharmony_ci  if (_valueSet[0]) {
11016ffe3c632Sopenharmony_ci    block(NO, _values[0], &stop);
11017ffe3c632Sopenharmony_ci  }
11018ffe3c632Sopenharmony_ci  if (!stop && _valueSet[1]) {
11019ffe3c632Sopenharmony_ci    block(YES, _values[1], &stop);
11020ffe3c632Sopenharmony_ci  }
11021ffe3c632Sopenharmony_ci}
11022ffe3c632Sopenharmony_ci
11023ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
11024ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
11025ffe3c632Sopenharmony_ci  NSUInteger count = 0;
11026ffe3c632Sopenharmony_ci  size_t result = 0;
11027ffe3c632Sopenharmony_ci  for (int i = 0; i < 2; ++i) {
11028ffe3c632Sopenharmony_ci    if (_valueSet[i]) {
11029ffe3c632Sopenharmony_ci      ++count;
11030ffe3c632Sopenharmony_ci      size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11031ffe3c632Sopenharmony_ci      msgSize += ComputeDictBoolFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
11032ffe3c632Sopenharmony_ci      result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
11033ffe3c632Sopenharmony_ci    }
11034ffe3c632Sopenharmony_ci  }
11035ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
11036ffe3c632Sopenharmony_ci  result += tagSize * count;
11037ffe3c632Sopenharmony_ci  return result;
11038ffe3c632Sopenharmony_ci}
11039ffe3c632Sopenharmony_ci
11040ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
11041ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
11042ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
11043ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
11044ffe3c632Sopenharmony_ci  for (int i = 0; i < 2; ++i) {
11045ffe3c632Sopenharmony_ci    if (_valueSet[i]) {
11046ffe3c632Sopenharmony_ci      // Write the tag.
11047ffe3c632Sopenharmony_ci      [outputStream writeInt32NoTag:tag];
11048ffe3c632Sopenharmony_ci      // Write the size of the message.
11049ffe3c632Sopenharmony_ci      size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11050ffe3c632Sopenharmony_ci      msgSize += ComputeDictBoolFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
11051ffe3c632Sopenharmony_ci      [outputStream writeInt32NoTag:(int32_t)msgSize];
11052ffe3c632Sopenharmony_ci      // Write the fields.
11053ffe3c632Sopenharmony_ci      WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11054ffe3c632Sopenharmony_ci      WriteDictBoolField(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
11055ffe3c632Sopenharmony_ci    }
11056ffe3c632Sopenharmony_ci  }
11057ffe3c632Sopenharmony_ci}
11058ffe3c632Sopenharmony_ci
11059ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBBoolBoolDictionary *)otherDictionary {
11060ffe3c632Sopenharmony_ci  if (otherDictionary) {
11061ffe3c632Sopenharmony_ci    for (int i = 0; i < 2; ++i) {
11062ffe3c632Sopenharmony_ci      if (otherDictionary->_valueSet[i]) {
11063ffe3c632Sopenharmony_ci        _valueSet[i] = YES;
11064ffe3c632Sopenharmony_ci        _values[i] = otherDictionary->_values[i];
11065ffe3c632Sopenharmony_ci      }
11066ffe3c632Sopenharmony_ci    }
11067ffe3c632Sopenharmony_ci    if (_autocreator) {
11068ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
11069ffe3c632Sopenharmony_ci    }
11070ffe3c632Sopenharmony_ci  }
11071ffe3c632Sopenharmony_ci}
11072ffe3c632Sopenharmony_ci
11073ffe3c632Sopenharmony_ci- (void)setBool:(BOOL)value forKey:(BOOL)key {
11074ffe3c632Sopenharmony_ci  int idx = (key ? 1 : 0);
11075ffe3c632Sopenharmony_ci  _values[idx] = value;
11076ffe3c632Sopenharmony_ci  _valueSet[idx] = YES;
11077ffe3c632Sopenharmony_ci  if (_autocreator) {
11078ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
11079ffe3c632Sopenharmony_ci  }
11080ffe3c632Sopenharmony_ci}
11081ffe3c632Sopenharmony_ci
11082ffe3c632Sopenharmony_ci- (void)removeBoolForKey:(BOOL)aKey {
11083ffe3c632Sopenharmony_ci  _valueSet[aKey ? 1 : 0] = NO;
11084ffe3c632Sopenharmony_ci}
11085ffe3c632Sopenharmony_ci
11086ffe3c632Sopenharmony_ci- (void)removeAll {
11087ffe3c632Sopenharmony_ci  _valueSet[0] = NO;
11088ffe3c632Sopenharmony_ci  _valueSet[1] = NO;
11089ffe3c632Sopenharmony_ci}
11090ffe3c632Sopenharmony_ci
11091ffe3c632Sopenharmony_ci@end
11092ffe3c632Sopenharmony_ci
11093ffe3c632Sopenharmony_ci// clang-format on
11094ffe3c632Sopenharmony_ci//%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Float, float)
11095ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly.
11096ffe3c632Sopenharmony_ci// clang-format off
11097ffe3c632Sopenharmony_ci
11098ffe3c632Sopenharmony_ci#pragma mark - Bool -> Float
11099ffe3c632Sopenharmony_ci
11100ffe3c632Sopenharmony_ci@implementation GPBBoolFloatDictionary {
11101ffe3c632Sopenharmony_ci @package
11102ffe3c632Sopenharmony_ci  float _values[2];
11103ffe3c632Sopenharmony_ci  BOOL _valueSet[2];
11104ffe3c632Sopenharmony_ci}
11105ffe3c632Sopenharmony_ci
11106ffe3c632Sopenharmony_ci- (instancetype)init {
11107ffe3c632Sopenharmony_ci  return [self initWithFloats:NULL forKeys:NULL count:0];
11108ffe3c632Sopenharmony_ci}
11109ffe3c632Sopenharmony_ci
11110ffe3c632Sopenharmony_ci- (instancetype)initWithFloats:(const float [])values
11111ffe3c632Sopenharmony_ci                       forKeys:(const BOOL [])keys
11112ffe3c632Sopenharmony_ci                         count:(NSUInteger)count {
11113ffe3c632Sopenharmony_ci  self = [super init];
11114ffe3c632Sopenharmony_ci  if (self) {
11115ffe3c632Sopenharmony_ci    for (NSUInteger i = 0; i < count; ++i) {
11116ffe3c632Sopenharmony_ci      int idx = keys[i] ? 1 : 0;
11117ffe3c632Sopenharmony_ci      _values[idx] = values[i];
11118ffe3c632Sopenharmony_ci      _valueSet[idx] = YES;
11119ffe3c632Sopenharmony_ci    }
11120ffe3c632Sopenharmony_ci  }
11121ffe3c632Sopenharmony_ci  return self;
11122ffe3c632Sopenharmony_ci}
11123ffe3c632Sopenharmony_ci
11124ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBBoolFloatDictionary *)dictionary {
11125ffe3c632Sopenharmony_ci  self = [self initWithFloats:NULL forKeys:NULL count:0];
11126ffe3c632Sopenharmony_ci  if (self) {
11127ffe3c632Sopenharmony_ci    if (dictionary) {
11128ffe3c632Sopenharmony_ci      for (int i = 0; i < 2; ++i) {
11129ffe3c632Sopenharmony_ci        if (dictionary->_valueSet[i]) {
11130ffe3c632Sopenharmony_ci          _values[i] = dictionary->_values[i];
11131ffe3c632Sopenharmony_ci          _valueSet[i] = YES;
11132ffe3c632Sopenharmony_ci        }
11133ffe3c632Sopenharmony_ci      }
11134ffe3c632Sopenharmony_ci    }
11135ffe3c632Sopenharmony_ci  }
11136ffe3c632Sopenharmony_ci  return self;
11137ffe3c632Sopenharmony_ci}
11138ffe3c632Sopenharmony_ci
11139ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
11140ffe3c632Sopenharmony_ci  #pragma unused(numItems)
11141ffe3c632Sopenharmony_ci  return [self initWithFloats:NULL forKeys:NULL count:0];
11142ffe3c632Sopenharmony_ci}
11143ffe3c632Sopenharmony_ci
11144ffe3c632Sopenharmony_ci#if !defined(NS_BLOCK_ASSERTIONS)
11145ffe3c632Sopenharmony_ci- (void)dealloc {
11146ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
11147ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
11148ffe3c632Sopenharmony_ci           [self class], _autocreator);
11149ffe3c632Sopenharmony_ci  [super dealloc];
11150ffe3c632Sopenharmony_ci}
11151ffe3c632Sopenharmony_ci#endif  // !defined(NS_BLOCK_ASSERTIONS)
11152ffe3c632Sopenharmony_ci
11153ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
11154ffe3c632Sopenharmony_ci  return [[GPBBoolFloatDictionary allocWithZone:zone] initWithDictionary:self];
11155ffe3c632Sopenharmony_ci}
11156ffe3c632Sopenharmony_ci
11157ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
11158ffe3c632Sopenharmony_ci  if (self == other) {
11159ffe3c632Sopenharmony_ci    return YES;
11160ffe3c632Sopenharmony_ci  }
11161ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBBoolFloatDictionary class]]) {
11162ffe3c632Sopenharmony_ci    return NO;
11163ffe3c632Sopenharmony_ci  }
11164ffe3c632Sopenharmony_ci  GPBBoolFloatDictionary *otherDictionary = other;
11165ffe3c632Sopenharmony_ci  if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
11166ffe3c632Sopenharmony_ci      (_valueSet[1] != otherDictionary->_valueSet[1])) {
11167ffe3c632Sopenharmony_ci    return NO;
11168ffe3c632Sopenharmony_ci  }
11169ffe3c632Sopenharmony_ci  if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
11170ffe3c632Sopenharmony_ci      (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
11171ffe3c632Sopenharmony_ci    return NO;
11172ffe3c632Sopenharmony_ci  }
11173ffe3c632Sopenharmony_ci  return YES;
11174ffe3c632Sopenharmony_ci}
11175ffe3c632Sopenharmony_ci
11176ffe3c632Sopenharmony_ci- (NSUInteger)hash {
11177ffe3c632Sopenharmony_ci  return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
11178ffe3c632Sopenharmony_ci}
11179ffe3c632Sopenharmony_ci
11180ffe3c632Sopenharmony_ci- (NSString *)description {
11181ffe3c632Sopenharmony_ci  NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
11182ffe3c632Sopenharmony_ci  if (_valueSet[0]) {
11183ffe3c632Sopenharmony_ci    [result appendFormat:@"NO: %f", _values[0]];
11184ffe3c632Sopenharmony_ci  }
11185ffe3c632Sopenharmony_ci  if (_valueSet[1]) {
11186ffe3c632Sopenharmony_ci    [result appendFormat:@"YES: %f", _values[1]];
11187ffe3c632Sopenharmony_ci  }
11188ffe3c632Sopenharmony_ci  [result appendString:@" }"];
11189ffe3c632Sopenharmony_ci  return result;
11190ffe3c632Sopenharmony_ci}
11191ffe3c632Sopenharmony_ci
11192ffe3c632Sopenharmony_ci- (NSUInteger)count {
11193ffe3c632Sopenharmony_ci  return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
11194ffe3c632Sopenharmony_ci}
11195ffe3c632Sopenharmony_ci
11196ffe3c632Sopenharmony_ci- (BOOL)getFloat:(float *)value forKey:(BOOL)key {
11197ffe3c632Sopenharmony_ci  int idx = (key ? 1 : 0);
11198ffe3c632Sopenharmony_ci  if (_valueSet[idx]) {
11199ffe3c632Sopenharmony_ci    if (value) {
11200ffe3c632Sopenharmony_ci      *value = _values[idx];
11201ffe3c632Sopenharmony_ci    }
11202ffe3c632Sopenharmony_ci    return YES;
11203ffe3c632Sopenharmony_ci  }
11204ffe3c632Sopenharmony_ci  return NO;
11205ffe3c632Sopenharmony_ci}
11206ffe3c632Sopenharmony_ci
11207ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
11208ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
11209ffe3c632Sopenharmony_ci  int idx = (key->valueBool ? 1 : 0);
11210ffe3c632Sopenharmony_ci  _values[idx] = value->valueFloat;
11211ffe3c632Sopenharmony_ci  _valueSet[idx] = YES;
11212ffe3c632Sopenharmony_ci}
11213ffe3c632Sopenharmony_ci
11214ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
11215ffe3c632Sopenharmony_ci  if (_valueSet[0]) {
11216ffe3c632Sopenharmony_ci    block(@"false", [NSString stringWithFormat:@"%.*g", FLT_DIG, _values[0]]);
11217ffe3c632Sopenharmony_ci  }
11218ffe3c632Sopenharmony_ci  if (_valueSet[1]) {
11219ffe3c632Sopenharmony_ci    block(@"true", [NSString stringWithFormat:@"%.*g", FLT_DIG, _values[1]]);
11220ffe3c632Sopenharmony_ci  }
11221ffe3c632Sopenharmony_ci}
11222ffe3c632Sopenharmony_ci
11223ffe3c632Sopenharmony_ci- (void)enumerateKeysAndFloatsUsingBlock:
11224ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(BOOL key, float value, BOOL *stop))block {
11225ffe3c632Sopenharmony_ci  BOOL stop = NO;
11226ffe3c632Sopenharmony_ci  if (_valueSet[0]) {
11227ffe3c632Sopenharmony_ci    block(NO, _values[0], &stop);
11228ffe3c632Sopenharmony_ci  }
11229ffe3c632Sopenharmony_ci  if (!stop && _valueSet[1]) {
11230ffe3c632Sopenharmony_ci    block(YES, _values[1], &stop);
11231ffe3c632Sopenharmony_ci  }
11232ffe3c632Sopenharmony_ci}
11233ffe3c632Sopenharmony_ci
11234ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
11235ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
11236ffe3c632Sopenharmony_ci  NSUInteger count = 0;
11237ffe3c632Sopenharmony_ci  size_t result = 0;
11238ffe3c632Sopenharmony_ci  for (int i = 0; i < 2; ++i) {
11239ffe3c632Sopenharmony_ci    if (_valueSet[i]) {
11240ffe3c632Sopenharmony_ci      ++count;
11241ffe3c632Sopenharmony_ci      size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11242ffe3c632Sopenharmony_ci      msgSize += ComputeDictFloatFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
11243ffe3c632Sopenharmony_ci      result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
11244ffe3c632Sopenharmony_ci    }
11245ffe3c632Sopenharmony_ci  }
11246ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
11247ffe3c632Sopenharmony_ci  result += tagSize * count;
11248ffe3c632Sopenharmony_ci  return result;
11249ffe3c632Sopenharmony_ci}
11250ffe3c632Sopenharmony_ci
11251ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
11252ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
11253ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
11254ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
11255ffe3c632Sopenharmony_ci  for (int i = 0; i < 2; ++i) {
11256ffe3c632Sopenharmony_ci    if (_valueSet[i]) {
11257ffe3c632Sopenharmony_ci      // Write the tag.
11258ffe3c632Sopenharmony_ci      [outputStream writeInt32NoTag:tag];
11259ffe3c632Sopenharmony_ci      // Write the size of the message.
11260ffe3c632Sopenharmony_ci      size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11261ffe3c632Sopenharmony_ci      msgSize += ComputeDictFloatFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
11262ffe3c632Sopenharmony_ci      [outputStream writeInt32NoTag:(int32_t)msgSize];
11263ffe3c632Sopenharmony_ci      // Write the fields.
11264ffe3c632Sopenharmony_ci      WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11265ffe3c632Sopenharmony_ci      WriteDictFloatField(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
11266ffe3c632Sopenharmony_ci    }
11267ffe3c632Sopenharmony_ci  }
11268ffe3c632Sopenharmony_ci}
11269ffe3c632Sopenharmony_ci
11270ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBBoolFloatDictionary *)otherDictionary {
11271ffe3c632Sopenharmony_ci  if (otherDictionary) {
11272ffe3c632Sopenharmony_ci    for (int i = 0; i < 2; ++i) {
11273ffe3c632Sopenharmony_ci      if (otherDictionary->_valueSet[i]) {
11274ffe3c632Sopenharmony_ci        _valueSet[i] = YES;
11275ffe3c632Sopenharmony_ci        _values[i] = otherDictionary->_values[i];
11276ffe3c632Sopenharmony_ci      }
11277ffe3c632Sopenharmony_ci    }
11278ffe3c632Sopenharmony_ci    if (_autocreator) {
11279ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
11280ffe3c632Sopenharmony_ci    }
11281ffe3c632Sopenharmony_ci  }
11282ffe3c632Sopenharmony_ci}
11283ffe3c632Sopenharmony_ci
11284ffe3c632Sopenharmony_ci- (void)setFloat:(float)value forKey:(BOOL)key {
11285ffe3c632Sopenharmony_ci  int idx = (key ? 1 : 0);
11286ffe3c632Sopenharmony_ci  _values[idx] = value;
11287ffe3c632Sopenharmony_ci  _valueSet[idx] = YES;
11288ffe3c632Sopenharmony_ci  if (_autocreator) {
11289ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
11290ffe3c632Sopenharmony_ci  }
11291ffe3c632Sopenharmony_ci}
11292ffe3c632Sopenharmony_ci
11293ffe3c632Sopenharmony_ci- (void)removeFloatForKey:(BOOL)aKey {
11294ffe3c632Sopenharmony_ci  _valueSet[aKey ? 1 : 0] = NO;
11295ffe3c632Sopenharmony_ci}
11296ffe3c632Sopenharmony_ci
11297ffe3c632Sopenharmony_ci- (void)removeAll {
11298ffe3c632Sopenharmony_ci  _valueSet[0] = NO;
11299ffe3c632Sopenharmony_ci  _valueSet[1] = NO;
11300ffe3c632Sopenharmony_ci}
11301ffe3c632Sopenharmony_ci
11302ffe3c632Sopenharmony_ci@end
11303ffe3c632Sopenharmony_ci
11304ffe3c632Sopenharmony_ci// clang-format on
11305ffe3c632Sopenharmony_ci//%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_POD_IMPL(Double, double)
11306ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly.
11307ffe3c632Sopenharmony_ci// clang-format off
11308ffe3c632Sopenharmony_ci
11309ffe3c632Sopenharmony_ci#pragma mark - Bool -> Double
11310ffe3c632Sopenharmony_ci
11311ffe3c632Sopenharmony_ci@implementation GPBBoolDoubleDictionary {
11312ffe3c632Sopenharmony_ci @package
11313ffe3c632Sopenharmony_ci  double _values[2];
11314ffe3c632Sopenharmony_ci  BOOL _valueSet[2];
11315ffe3c632Sopenharmony_ci}
11316ffe3c632Sopenharmony_ci
11317ffe3c632Sopenharmony_ci- (instancetype)init {
11318ffe3c632Sopenharmony_ci  return [self initWithDoubles:NULL forKeys:NULL count:0];
11319ffe3c632Sopenharmony_ci}
11320ffe3c632Sopenharmony_ci
11321ffe3c632Sopenharmony_ci- (instancetype)initWithDoubles:(const double [])values
11322ffe3c632Sopenharmony_ci                        forKeys:(const BOOL [])keys
11323ffe3c632Sopenharmony_ci                          count:(NSUInteger)count {
11324ffe3c632Sopenharmony_ci  self = [super init];
11325ffe3c632Sopenharmony_ci  if (self) {
11326ffe3c632Sopenharmony_ci    for (NSUInteger i = 0; i < count; ++i) {
11327ffe3c632Sopenharmony_ci      int idx = keys[i] ? 1 : 0;
11328ffe3c632Sopenharmony_ci      _values[idx] = values[i];
11329ffe3c632Sopenharmony_ci      _valueSet[idx] = YES;
11330ffe3c632Sopenharmony_ci    }
11331ffe3c632Sopenharmony_ci  }
11332ffe3c632Sopenharmony_ci  return self;
11333ffe3c632Sopenharmony_ci}
11334ffe3c632Sopenharmony_ci
11335ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBBoolDoubleDictionary *)dictionary {
11336ffe3c632Sopenharmony_ci  self = [self initWithDoubles:NULL forKeys:NULL count:0];
11337ffe3c632Sopenharmony_ci  if (self) {
11338ffe3c632Sopenharmony_ci    if (dictionary) {
11339ffe3c632Sopenharmony_ci      for (int i = 0; i < 2; ++i) {
11340ffe3c632Sopenharmony_ci        if (dictionary->_valueSet[i]) {
11341ffe3c632Sopenharmony_ci          _values[i] = dictionary->_values[i];
11342ffe3c632Sopenharmony_ci          _valueSet[i] = YES;
11343ffe3c632Sopenharmony_ci        }
11344ffe3c632Sopenharmony_ci      }
11345ffe3c632Sopenharmony_ci    }
11346ffe3c632Sopenharmony_ci  }
11347ffe3c632Sopenharmony_ci  return self;
11348ffe3c632Sopenharmony_ci}
11349ffe3c632Sopenharmony_ci
11350ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
11351ffe3c632Sopenharmony_ci  #pragma unused(numItems)
11352ffe3c632Sopenharmony_ci  return [self initWithDoubles:NULL forKeys:NULL count:0];
11353ffe3c632Sopenharmony_ci}
11354ffe3c632Sopenharmony_ci
11355ffe3c632Sopenharmony_ci#if !defined(NS_BLOCK_ASSERTIONS)
11356ffe3c632Sopenharmony_ci- (void)dealloc {
11357ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
11358ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
11359ffe3c632Sopenharmony_ci           [self class], _autocreator);
11360ffe3c632Sopenharmony_ci  [super dealloc];
11361ffe3c632Sopenharmony_ci}
11362ffe3c632Sopenharmony_ci#endif  // !defined(NS_BLOCK_ASSERTIONS)
11363ffe3c632Sopenharmony_ci
11364ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
11365ffe3c632Sopenharmony_ci  return [[GPBBoolDoubleDictionary allocWithZone:zone] initWithDictionary:self];
11366ffe3c632Sopenharmony_ci}
11367ffe3c632Sopenharmony_ci
11368ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
11369ffe3c632Sopenharmony_ci  if (self == other) {
11370ffe3c632Sopenharmony_ci    return YES;
11371ffe3c632Sopenharmony_ci  }
11372ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBBoolDoubleDictionary class]]) {
11373ffe3c632Sopenharmony_ci    return NO;
11374ffe3c632Sopenharmony_ci  }
11375ffe3c632Sopenharmony_ci  GPBBoolDoubleDictionary *otherDictionary = other;
11376ffe3c632Sopenharmony_ci  if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
11377ffe3c632Sopenharmony_ci      (_valueSet[1] != otherDictionary->_valueSet[1])) {
11378ffe3c632Sopenharmony_ci    return NO;
11379ffe3c632Sopenharmony_ci  }
11380ffe3c632Sopenharmony_ci  if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
11381ffe3c632Sopenharmony_ci      (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
11382ffe3c632Sopenharmony_ci    return NO;
11383ffe3c632Sopenharmony_ci  }
11384ffe3c632Sopenharmony_ci  return YES;
11385ffe3c632Sopenharmony_ci}
11386ffe3c632Sopenharmony_ci
11387ffe3c632Sopenharmony_ci- (NSUInteger)hash {
11388ffe3c632Sopenharmony_ci  return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
11389ffe3c632Sopenharmony_ci}
11390ffe3c632Sopenharmony_ci
11391ffe3c632Sopenharmony_ci- (NSString *)description {
11392ffe3c632Sopenharmony_ci  NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
11393ffe3c632Sopenharmony_ci  if (_valueSet[0]) {
11394ffe3c632Sopenharmony_ci    [result appendFormat:@"NO: %lf", _values[0]];
11395ffe3c632Sopenharmony_ci  }
11396ffe3c632Sopenharmony_ci  if (_valueSet[1]) {
11397ffe3c632Sopenharmony_ci    [result appendFormat:@"YES: %lf", _values[1]];
11398ffe3c632Sopenharmony_ci  }
11399ffe3c632Sopenharmony_ci  [result appendString:@" }"];
11400ffe3c632Sopenharmony_ci  return result;
11401ffe3c632Sopenharmony_ci}
11402ffe3c632Sopenharmony_ci
11403ffe3c632Sopenharmony_ci- (NSUInteger)count {
11404ffe3c632Sopenharmony_ci  return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
11405ffe3c632Sopenharmony_ci}
11406ffe3c632Sopenharmony_ci
11407ffe3c632Sopenharmony_ci- (BOOL)getDouble:(double *)value forKey:(BOOL)key {
11408ffe3c632Sopenharmony_ci  int idx = (key ? 1 : 0);
11409ffe3c632Sopenharmony_ci  if (_valueSet[idx]) {
11410ffe3c632Sopenharmony_ci    if (value) {
11411ffe3c632Sopenharmony_ci      *value = _values[idx];
11412ffe3c632Sopenharmony_ci    }
11413ffe3c632Sopenharmony_ci    return YES;
11414ffe3c632Sopenharmony_ci  }
11415ffe3c632Sopenharmony_ci  return NO;
11416ffe3c632Sopenharmony_ci}
11417ffe3c632Sopenharmony_ci
11418ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
11419ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
11420ffe3c632Sopenharmony_ci  int idx = (key->valueBool ? 1 : 0);
11421ffe3c632Sopenharmony_ci  _values[idx] = value->valueDouble;
11422ffe3c632Sopenharmony_ci  _valueSet[idx] = YES;
11423ffe3c632Sopenharmony_ci}
11424ffe3c632Sopenharmony_ci
11425ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
11426ffe3c632Sopenharmony_ci  if (_valueSet[0]) {
11427ffe3c632Sopenharmony_ci    block(@"false", [NSString stringWithFormat:@"%.*lg", DBL_DIG, _values[0]]);
11428ffe3c632Sopenharmony_ci  }
11429ffe3c632Sopenharmony_ci  if (_valueSet[1]) {
11430ffe3c632Sopenharmony_ci    block(@"true", [NSString stringWithFormat:@"%.*lg", DBL_DIG, _values[1]]);
11431ffe3c632Sopenharmony_ci  }
11432ffe3c632Sopenharmony_ci}
11433ffe3c632Sopenharmony_ci
11434ffe3c632Sopenharmony_ci- (void)enumerateKeysAndDoublesUsingBlock:
11435ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(BOOL key, double value, BOOL *stop))block {
11436ffe3c632Sopenharmony_ci  BOOL stop = NO;
11437ffe3c632Sopenharmony_ci  if (_valueSet[0]) {
11438ffe3c632Sopenharmony_ci    block(NO, _values[0], &stop);
11439ffe3c632Sopenharmony_ci  }
11440ffe3c632Sopenharmony_ci  if (!stop && _valueSet[1]) {
11441ffe3c632Sopenharmony_ci    block(YES, _values[1], &stop);
11442ffe3c632Sopenharmony_ci  }
11443ffe3c632Sopenharmony_ci}
11444ffe3c632Sopenharmony_ci
11445ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
11446ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
11447ffe3c632Sopenharmony_ci  NSUInteger count = 0;
11448ffe3c632Sopenharmony_ci  size_t result = 0;
11449ffe3c632Sopenharmony_ci  for (int i = 0; i < 2; ++i) {
11450ffe3c632Sopenharmony_ci    if (_valueSet[i]) {
11451ffe3c632Sopenharmony_ci      ++count;
11452ffe3c632Sopenharmony_ci      size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11453ffe3c632Sopenharmony_ci      msgSize += ComputeDictDoubleFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
11454ffe3c632Sopenharmony_ci      result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
11455ffe3c632Sopenharmony_ci    }
11456ffe3c632Sopenharmony_ci  }
11457ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
11458ffe3c632Sopenharmony_ci  result += tagSize * count;
11459ffe3c632Sopenharmony_ci  return result;
11460ffe3c632Sopenharmony_ci}
11461ffe3c632Sopenharmony_ci
11462ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
11463ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
11464ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
11465ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
11466ffe3c632Sopenharmony_ci  for (int i = 0; i < 2; ++i) {
11467ffe3c632Sopenharmony_ci    if (_valueSet[i]) {
11468ffe3c632Sopenharmony_ci      // Write the tag.
11469ffe3c632Sopenharmony_ci      [outputStream writeInt32NoTag:tag];
11470ffe3c632Sopenharmony_ci      // Write the size of the message.
11471ffe3c632Sopenharmony_ci      size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11472ffe3c632Sopenharmony_ci      msgSize += ComputeDictDoubleFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
11473ffe3c632Sopenharmony_ci      [outputStream writeInt32NoTag:(int32_t)msgSize];
11474ffe3c632Sopenharmony_ci      // Write the fields.
11475ffe3c632Sopenharmony_ci      WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11476ffe3c632Sopenharmony_ci      WriteDictDoubleField(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
11477ffe3c632Sopenharmony_ci    }
11478ffe3c632Sopenharmony_ci  }
11479ffe3c632Sopenharmony_ci}
11480ffe3c632Sopenharmony_ci
11481ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBBoolDoubleDictionary *)otherDictionary {
11482ffe3c632Sopenharmony_ci  if (otherDictionary) {
11483ffe3c632Sopenharmony_ci    for (int i = 0; i < 2; ++i) {
11484ffe3c632Sopenharmony_ci      if (otherDictionary->_valueSet[i]) {
11485ffe3c632Sopenharmony_ci        _valueSet[i] = YES;
11486ffe3c632Sopenharmony_ci        _values[i] = otherDictionary->_values[i];
11487ffe3c632Sopenharmony_ci      }
11488ffe3c632Sopenharmony_ci    }
11489ffe3c632Sopenharmony_ci    if (_autocreator) {
11490ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
11491ffe3c632Sopenharmony_ci    }
11492ffe3c632Sopenharmony_ci  }
11493ffe3c632Sopenharmony_ci}
11494ffe3c632Sopenharmony_ci
11495ffe3c632Sopenharmony_ci- (void)setDouble:(double)value forKey:(BOOL)key {
11496ffe3c632Sopenharmony_ci  int idx = (key ? 1 : 0);
11497ffe3c632Sopenharmony_ci  _values[idx] = value;
11498ffe3c632Sopenharmony_ci  _valueSet[idx] = YES;
11499ffe3c632Sopenharmony_ci  if (_autocreator) {
11500ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
11501ffe3c632Sopenharmony_ci  }
11502ffe3c632Sopenharmony_ci}
11503ffe3c632Sopenharmony_ci
11504ffe3c632Sopenharmony_ci- (void)removeDoubleForKey:(BOOL)aKey {
11505ffe3c632Sopenharmony_ci  _valueSet[aKey ? 1 : 0] = NO;
11506ffe3c632Sopenharmony_ci}
11507ffe3c632Sopenharmony_ci
11508ffe3c632Sopenharmony_ci- (void)removeAll {
11509ffe3c632Sopenharmony_ci  _valueSet[0] = NO;
11510ffe3c632Sopenharmony_ci  _valueSet[1] = NO;
11511ffe3c632Sopenharmony_ci}
11512ffe3c632Sopenharmony_ci
11513ffe3c632Sopenharmony_ci@end
11514ffe3c632Sopenharmony_ci
11515ffe3c632Sopenharmony_ci// clang-format on
11516ffe3c632Sopenharmony_ci//%PDDM-EXPAND DICTIONARY_BOOL_KEY_TO_OBJECT_IMPL(Object, id)
11517ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly.
11518ffe3c632Sopenharmony_ci// clang-format off
11519ffe3c632Sopenharmony_ci
11520ffe3c632Sopenharmony_ci#pragma mark - Bool -> Object
11521ffe3c632Sopenharmony_ci
11522ffe3c632Sopenharmony_ci@implementation GPBBoolObjectDictionary {
11523ffe3c632Sopenharmony_ci @package
11524ffe3c632Sopenharmony_ci  id _values[2];
11525ffe3c632Sopenharmony_ci}
11526ffe3c632Sopenharmony_ci
11527ffe3c632Sopenharmony_ci- (instancetype)init {
11528ffe3c632Sopenharmony_ci  return [self initWithObjects:NULL forKeys:NULL count:0];
11529ffe3c632Sopenharmony_ci}
11530ffe3c632Sopenharmony_ci
11531ffe3c632Sopenharmony_ci- (instancetype)initWithObjects:(const id [])objects
11532ffe3c632Sopenharmony_ci                        forKeys:(const BOOL [])keys
11533ffe3c632Sopenharmony_ci                          count:(NSUInteger)count {
11534ffe3c632Sopenharmony_ci  self = [super init];
11535ffe3c632Sopenharmony_ci  if (self) {
11536ffe3c632Sopenharmony_ci    for (NSUInteger i = 0; i < count; ++i) {
11537ffe3c632Sopenharmony_ci      if (!objects[i]) {
11538ffe3c632Sopenharmony_ci        [NSException raise:NSInvalidArgumentException
11539ffe3c632Sopenharmony_ci                    format:@"Attempting to add nil object to a Dictionary"];
11540ffe3c632Sopenharmony_ci      }
11541ffe3c632Sopenharmony_ci      int idx = keys[i] ? 1 : 0;
11542ffe3c632Sopenharmony_ci      [_values[idx] release];
11543ffe3c632Sopenharmony_ci      _values[idx] = (id)[objects[i] retain];
11544ffe3c632Sopenharmony_ci    }
11545ffe3c632Sopenharmony_ci  }
11546ffe3c632Sopenharmony_ci  return self;
11547ffe3c632Sopenharmony_ci}
11548ffe3c632Sopenharmony_ci
11549ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBBoolObjectDictionary *)dictionary {
11550ffe3c632Sopenharmony_ci  self = [self initWithObjects:NULL forKeys:NULL count:0];
11551ffe3c632Sopenharmony_ci  if (self) {
11552ffe3c632Sopenharmony_ci    if (dictionary) {
11553ffe3c632Sopenharmony_ci      _values[0] = [dictionary->_values[0] retain];
11554ffe3c632Sopenharmony_ci      _values[1] = [dictionary->_values[1] retain];
11555ffe3c632Sopenharmony_ci    }
11556ffe3c632Sopenharmony_ci  }
11557ffe3c632Sopenharmony_ci  return self;
11558ffe3c632Sopenharmony_ci}
11559ffe3c632Sopenharmony_ci
11560ffe3c632Sopenharmony_ci- (instancetype)initWithCapacity:(NSUInteger)numItems {
11561ffe3c632Sopenharmony_ci  #pragma unused(numItems)
11562ffe3c632Sopenharmony_ci  return [self initWithObjects:NULL forKeys:NULL count:0];
11563ffe3c632Sopenharmony_ci}
11564ffe3c632Sopenharmony_ci
11565ffe3c632Sopenharmony_ci- (void)dealloc {
11566ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
11567ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
11568ffe3c632Sopenharmony_ci           [self class], _autocreator);
11569ffe3c632Sopenharmony_ci  [_values[0] release];
11570ffe3c632Sopenharmony_ci  [_values[1] release];
11571ffe3c632Sopenharmony_ci  [super dealloc];
11572ffe3c632Sopenharmony_ci}
11573ffe3c632Sopenharmony_ci
11574ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
11575ffe3c632Sopenharmony_ci  return [[GPBBoolObjectDictionary allocWithZone:zone] initWithDictionary:self];
11576ffe3c632Sopenharmony_ci}
11577ffe3c632Sopenharmony_ci
11578ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
11579ffe3c632Sopenharmony_ci  if (self == other) {
11580ffe3c632Sopenharmony_ci    return YES;
11581ffe3c632Sopenharmony_ci  }
11582ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBBoolObjectDictionary class]]) {
11583ffe3c632Sopenharmony_ci    return NO;
11584ffe3c632Sopenharmony_ci  }
11585ffe3c632Sopenharmony_ci  GPBBoolObjectDictionary *otherDictionary = other;
11586ffe3c632Sopenharmony_ci  if (((_values[0] != nil) != (otherDictionary->_values[0] != nil)) ||
11587ffe3c632Sopenharmony_ci      ((_values[1] != nil) != (otherDictionary->_values[1] != nil))) {
11588ffe3c632Sopenharmony_ci    return NO;
11589ffe3c632Sopenharmony_ci  }
11590ffe3c632Sopenharmony_ci  if (((_values[0] != nil) && (![_values[0] isEqual:otherDictionary->_values[0]])) ||
11591ffe3c632Sopenharmony_ci      ((_values[1] != nil) && (![_values[1] isEqual:otherDictionary->_values[1]]))) {
11592ffe3c632Sopenharmony_ci    return NO;
11593ffe3c632Sopenharmony_ci  }
11594ffe3c632Sopenharmony_ci  return YES;
11595ffe3c632Sopenharmony_ci}
11596ffe3c632Sopenharmony_ci
11597ffe3c632Sopenharmony_ci- (NSUInteger)hash {
11598ffe3c632Sopenharmony_ci  return ((_values[0] != nil) ? 1 : 0) + ((_values[1] != nil) ? 1 : 0);
11599ffe3c632Sopenharmony_ci}
11600ffe3c632Sopenharmony_ci
11601ffe3c632Sopenharmony_ci- (NSString *)description {
11602ffe3c632Sopenharmony_ci  NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
11603ffe3c632Sopenharmony_ci  if ((_values[0] != nil)) {
11604ffe3c632Sopenharmony_ci    [result appendFormat:@"NO: %@", _values[0]];
11605ffe3c632Sopenharmony_ci  }
11606ffe3c632Sopenharmony_ci  if ((_values[1] != nil)) {
11607ffe3c632Sopenharmony_ci    [result appendFormat:@"YES: %@", _values[1]];
11608ffe3c632Sopenharmony_ci  }
11609ffe3c632Sopenharmony_ci  [result appendString:@" }"];
11610ffe3c632Sopenharmony_ci  return result;
11611ffe3c632Sopenharmony_ci}
11612ffe3c632Sopenharmony_ci
11613ffe3c632Sopenharmony_ci- (NSUInteger)count {
11614ffe3c632Sopenharmony_ci  return ((_values[0] != nil) ? 1 : 0) + ((_values[1] != nil) ? 1 : 0);
11615ffe3c632Sopenharmony_ci}
11616ffe3c632Sopenharmony_ci
11617ffe3c632Sopenharmony_ci- (id)objectForKey:(BOOL)key {
11618ffe3c632Sopenharmony_ci  return _values[key ? 1 : 0];
11619ffe3c632Sopenharmony_ci}
11620ffe3c632Sopenharmony_ci
11621ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
11622ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
11623ffe3c632Sopenharmony_ci  int idx = (key->valueBool ? 1 : 0);
11624ffe3c632Sopenharmony_ci  [_values[idx] release];
11625ffe3c632Sopenharmony_ci  _values[idx] = [value->valueString retain];
11626ffe3c632Sopenharmony_ci}
11627ffe3c632Sopenharmony_ci
11628ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
11629ffe3c632Sopenharmony_ci  if (_values[0] != nil) {
11630ffe3c632Sopenharmony_ci    block(@"false", _values[0]);
11631ffe3c632Sopenharmony_ci  }
11632ffe3c632Sopenharmony_ci  if ((_values[1] != nil)) {
11633ffe3c632Sopenharmony_ci    block(@"true", _values[1]);
11634ffe3c632Sopenharmony_ci  }
11635ffe3c632Sopenharmony_ci}
11636ffe3c632Sopenharmony_ci
11637ffe3c632Sopenharmony_ci- (void)enumerateKeysAndObjectsUsingBlock:
11638ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(BOOL key, id object, BOOL *stop))block {
11639ffe3c632Sopenharmony_ci  BOOL stop = NO;
11640ffe3c632Sopenharmony_ci  if (_values[0] != nil) {
11641ffe3c632Sopenharmony_ci    block(NO, _values[0], &stop);
11642ffe3c632Sopenharmony_ci  }
11643ffe3c632Sopenharmony_ci  if (!stop && (_values[1] != nil)) {
11644ffe3c632Sopenharmony_ci    block(YES, _values[1], &stop);
11645ffe3c632Sopenharmony_ci  }
11646ffe3c632Sopenharmony_ci}
11647ffe3c632Sopenharmony_ci
11648ffe3c632Sopenharmony_ci- (BOOL)isInitialized {
11649ffe3c632Sopenharmony_ci  if (_values[0] && ![_values[0] isInitialized]) {
11650ffe3c632Sopenharmony_ci    return NO;
11651ffe3c632Sopenharmony_ci  }
11652ffe3c632Sopenharmony_ci  if (_values[1] && ![_values[1] isInitialized]) {
11653ffe3c632Sopenharmony_ci    return NO;
11654ffe3c632Sopenharmony_ci  }
11655ffe3c632Sopenharmony_ci  return YES;
11656ffe3c632Sopenharmony_ci}
11657ffe3c632Sopenharmony_ci
11658ffe3c632Sopenharmony_ci- (instancetype)deepCopyWithZone:(NSZone *)zone {
11659ffe3c632Sopenharmony_ci  GPBBoolObjectDictionary *newDict =
11660ffe3c632Sopenharmony_ci      [[GPBBoolObjectDictionary alloc] init];
11661ffe3c632Sopenharmony_ci  for (int i = 0; i < 2; ++i) {
11662ffe3c632Sopenharmony_ci    if (_values[i] != nil) {
11663ffe3c632Sopenharmony_ci      newDict->_values[i] = [_values[i] copyWithZone:zone];
11664ffe3c632Sopenharmony_ci    }
11665ffe3c632Sopenharmony_ci  }
11666ffe3c632Sopenharmony_ci  return newDict;
11667ffe3c632Sopenharmony_ci}
11668ffe3c632Sopenharmony_ci
11669ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
11670ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
11671ffe3c632Sopenharmony_ci  NSUInteger count = 0;
11672ffe3c632Sopenharmony_ci  size_t result = 0;
11673ffe3c632Sopenharmony_ci  for (int i = 0; i < 2; ++i) {
11674ffe3c632Sopenharmony_ci    if (_values[i] != nil) {
11675ffe3c632Sopenharmony_ci      ++count;
11676ffe3c632Sopenharmony_ci      size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11677ffe3c632Sopenharmony_ci      msgSize += ComputeDictObjectFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
11678ffe3c632Sopenharmony_ci      result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
11679ffe3c632Sopenharmony_ci    }
11680ffe3c632Sopenharmony_ci  }
11681ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
11682ffe3c632Sopenharmony_ci  result += tagSize * count;
11683ffe3c632Sopenharmony_ci  return result;
11684ffe3c632Sopenharmony_ci}
11685ffe3c632Sopenharmony_ci
11686ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
11687ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
11688ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
11689ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
11690ffe3c632Sopenharmony_ci  for (int i = 0; i < 2; ++i) {
11691ffe3c632Sopenharmony_ci    if (_values[i] != nil) {
11692ffe3c632Sopenharmony_ci      // Write the tag.
11693ffe3c632Sopenharmony_ci      [outputStream writeInt32NoTag:tag];
11694ffe3c632Sopenharmony_ci      // Write the size of the message.
11695ffe3c632Sopenharmony_ci      size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11696ffe3c632Sopenharmony_ci      msgSize += ComputeDictObjectFieldSize(_values[i], kMapValueFieldNumber, valueDataType);
11697ffe3c632Sopenharmony_ci      [outputStream writeInt32NoTag:(int32_t)msgSize];
11698ffe3c632Sopenharmony_ci      // Write the fields.
11699ffe3c632Sopenharmony_ci      WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11700ffe3c632Sopenharmony_ci      WriteDictObjectField(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
11701ffe3c632Sopenharmony_ci    }
11702ffe3c632Sopenharmony_ci  }
11703ffe3c632Sopenharmony_ci}
11704ffe3c632Sopenharmony_ci
11705ffe3c632Sopenharmony_ci- (void)addEntriesFromDictionary:(GPBBoolObjectDictionary *)otherDictionary {
11706ffe3c632Sopenharmony_ci  if (otherDictionary) {
11707ffe3c632Sopenharmony_ci    for (int i = 0; i < 2; ++i) {
11708ffe3c632Sopenharmony_ci      if (otherDictionary->_values[i] != nil) {
11709ffe3c632Sopenharmony_ci        [_values[i] release];
11710ffe3c632Sopenharmony_ci        _values[i] = [otherDictionary->_values[i] retain];
11711ffe3c632Sopenharmony_ci      }
11712ffe3c632Sopenharmony_ci    }
11713ffe3c632Sopenharmony_ci    if (_autocreator) {
11714ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
11715ffe3c632Sopenharmony_ci    }
11716ffe3c632Sopenharmony_ci  }
11717ffe3c632Sopenharmony_ci}
11718ffe3c632Sopenharmony_ci
11719ffe3c632Sopenharmony_ci- (void)setObject:(id)object forKey:(BOOL)key {
11720ffe3c632Sopenharmony_ci  if (!object) {
11721ffe3c632Sopenharmony_ci    [NSException raise:NSInvalidArgumentException
11722ffe3c632Sopenharmony_ci                format:@"Attempting to add nil object to a Dictionary"];
11723ffe3c632Sopenharmony_ci  }
11724ffe3c632Sopenharmony_ci  int idx = (key ? 1 : 0);
11725ffe3c632Sopenharmony_ci  [_values[idx] release];
11726ffe3c632Sopenharmony_ci  _values[idx] = [object retain];
11727ffe3c632Sopenharmony_ci  if (_autocreator) {
11728ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
11729ffe3c632Sopenharmony_ci  }
11730ffe3c632Sopenharmony_ci}
11731ffe3c632Sopenharmony_ci
11732ffe3c632Sopenharmony_ci- (void)removeObjectForKey:(BOOL)aKey {
11733ffe3c632Sopenharmony_ci  int idx = (aKey ? 1 : 0);
11734ffe3c632Sopenharmony_ci  [_values[idx] release];
11735ffe3c632Sopenharmony_ci  _values[idx] = nil;
11736ffe3c632Sopenharmony_ci}
11737ffe3c632Sopenharmony_ci
11738ffe3c632Sopenharmony_ci- (void)removeAll {
11739ffe3c632Sopenharmony_ci  for (int i = 0; i < 2; ++i) {
11740ffe3c632Sopenharmony_ci    [_values[i] release];
11741ffe3c632Sopenharmony_ci    _values[i] = nil;
11742ffe3c632Sopenharmony_ci  }
11743ffe3c632Sopenharmony_ci}
11744ffe3c632Sopenharmony_ci
11745ffe3c632Sopenharmony_ci@end
11746ffe3c632Sopenharmony_ci
11747ffe3c632Sopenharmony_ci// clang-format on
11748ffe3c632Sopenharmony_ci//%PDDM-EXPAND-END (8 expansions)
11749ffe3c632Sopenharmony_ci
11750ffe3c632Sopenharmony_ci#pragma mark - Bool -> Enum
11751ffe3c632Sopenharmony_ci
11752ffe3c632Sopenharmony_ci@implementation GPBBoolEnumDictionary {
11753ffe3c632Sopenharmony_ci @package
11754ffe3c632Sopenharmony_ci  GPBEnumValidationFunc _validationFunc;
11755ffe3c632Sopenharmony_ci  int32_t _values[2];
11756ffe3c632Sopenharmony_ci  BOOL _valueSet[2];
11757ffe3c632Sopenharmony_ci}
11758ffe3c632Sopenharmony_ci
11759ffe3c632Sopenharmony_ci@synthesize validationFunc = _validationFunc;
11760ffe3c632Sopenharmony_ci
11761ffe3c632Sopenharmony_ci- (instancetype)init {
11762ffe3c632Sopenharmony_ci  return [self initWithValidationFunction:NULL rawValues:NULL forKeys:NULL count:0];
11763ffe3c632Sopenharmony_ci}
11764ffe3c632Sopenharmony_ci
11765ffe3c632Sopenharmony_ci- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func {
11766ffe3c632Sopenharmony_ci  return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
11767ffe3c632Sopenharmony_ci}
11768ffe3c632Sopenharmony_ci
11769ffe3c632Sopenharmony_ci- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
11770ffe3c632Sopenharmony_ci                                rawValues:(const int32_t [])rawValues
11771ffe3c632Sopenharmony_ci                                   forKeys:(const BOOL [])keys
11772ffe3c632Sopenharmony_ci                                     count:(NSUInteger)count {
11773ffe3c632Sopenharmony_ci  self = [super init];
11774ffe3c632Sopenharmony_ci  if (self) {
11775ffe3c632Sopenharmony_ci    _validationFunc = (func != NULL ? func : DictDefault_IsValidValue);
11776ffe3c632Sopenharmony_ci    for (NSUInteger i = 0; i < count; ++i) {
11777ffe3c632Sopenharmony_ci      int idx = keys[i] ? 1 : 0;
11778ffe3c632Sopenharmony_ci      _values[idx] = rawValues[i];
11779ffe3c632Sopenharmony_ci      _valueSet[idx] = YES;
11780ffe3c632Sopenharmony_ci    }
11781ffe3c632Sopenharmony_ci  }
11782ffe3c632Sopenharmony_ci  return self;
11783ffe3c632Sopenharmony_ci}
11784ffe3c632Sopenharmony_ci
11785ffe3c632Sopenharmony_ci- (instancetype)initWithDictionary:(GPBBoolEnumDictionary *)dictionary {
11786ffe3c632Sopenharmony_ci  self = [self initWithValidationFunction:dictionary.validationFunc
11787ffe3c632Sopenharmony_ci                                rawValues:NULL
11788ffe3c632Sopenharmony_ci                                  forKeys:NULL
11789ffe3c632Sopenharmony_ci                                    count:0];
11790ffe3c632Sopenharmony_ci  if (self) {
11791ffe3c632Sopenharmony_ci    if (dictionary) {
11792ffe3c632Sopenharmony_ci      for (int i = 0; i < 2; ++i) {
11793ffe3c632Sopenharmony_ci        if (dictionary->_valueSet[i]) {
11794ffe3c632Sopenharmony_ci          _values[i] = dictionary->_values[i];
11795ffe3c632Sopenharmony_ci          _valueSet[i] = YES;
11796ffe3c632Sopenharmony_ci        }
11797ffe3c632Sopenharmony_ci      }
11798ffe3c632Sopenharmony_ci    }
11799ffe3c632Sopenharmony_ci  }
11800ffe3c632Sopenharmony_ci  return self;
11801ffe3c632Sopenharmony_ci}
11802ffe3c632Sopenharmony_ci
11803ffe3c632Sopenharmony_ci- (instancetype)initWithValidationFunction:(GPBEnumValidationFunc)func
11804ffe3c632Sopenharmony_ci                                  capacity:(NSUInteger)numItems {
11805ffe3c632Sopenharmony_ci#pragma unused(numItems)
11806ffe3c632Sopenharmony_ci  return [self initWithValidationFunction:func rawValues:NULL forKeys:NULL count:0];
11807ffe3c632Sopenharmony_ci}
11808ffe3c632Sopenharmony_ci
11809ffe3c632Sopenharmony_ci#if !defined(NS_BLOCK_ASSERTIONS)
11810ffe3c632Sopenharmony_ci- (void)dealloc {
11811ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
11812ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
11813ffe3c632Sopenharmony_ci           [self class], _autocreator);
11814ffe3c632Sopenharmony_ci  [super dealloc];
11815ffe3c632Sopenharmony_ci}
11816ffe3c632Sopenharmony_ci#endif  // !defined(NS_BLOCK_ASSERTIONS)
11817ffe3c632Sopenharmony_ci
11818ffe3c632Sopenharmony_ci- (instancetype)copyWithZone:(NSZone *)zone {
11819ffe3c632Sopenharmony_ci  return [[GPBBoolEnumDictionary allocWithZone:zone] initWithDictionary:self];
11820ffe3c632Sopenharmony_ci}
11821ffe3c632Sopenharmony_ci
11822ffe3c632Sopenharmony_ci- (BOOL)isEqual:(id)other {
11823ffe3c632Sopenharmony_ci  if (self == other) {
11824ffe3c632Sopenharmony_ci    return YES;
11825ffe3c632Sopenharmony_ci  }
11826ffe3c632Sopenharmony_ci  if (![other isKindOfClass:[GPBBoolEnumDictionary class]]) {
11827ffe3c632Sopenharmony_ci    return NO;
11828ffe3c632Sopenharmony_ci  }
11829ffe3c632Sopenharmony_ci  GPBBoolEnumDictionary *otherDictionary = other;
11830ffe3c632Sopenharmony_ci  if ((_valueSet[0] != otherDictionary->_valueSet[0]) ||
11831ffe3c632Sopenharmony_ci      (_valueSet[1] != otherDictionary->_valueSet[1])) {
11832ffe3c632Sopenharmony_ci    return NO;
11833ffe3c632Sopenharmony_ci  }
11834ffe3c632Sopenharmony_ci  if ((_valueSet[0] && (_values[0] != otherDictionary->_values[0])) ||
11835ffe3c632Sopenharmony_ci      (_valueSet[1] && (_values[1] != otherDictionary->_values[1]))) {
11836ffe3c632Sopenharmony_ci    return NO;
11837ffe3c632Sopenharmony_ci  }
11838ffe3c632Sopenharmony_ci  return YES;
11839ffe3c632Sopenharmony_ci}
11840ffe3c632Sopenharmony_ci
11841ffe3c632Sopenharmony_ci- (NSUInteger)hash {
11842ffe3c632Sopenharmony_ci  return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
11843ffe3c632Sopenharmony_ci}
11844ffe3c632Sopenharmony_ci
11845ffe3c632Sopenharmony_ci- (NSString *)description {
11846ffe3c632Sopenharmony_ci  NSMutableString *result = [NSMutableString stringWithFormat:@"<%@ %p> {", [self class], self];
11847ffe3c632Sopenharmony_ci  if (_valueSet[0]) {
11848ffe3c632Sopenharmony_ci    [result appendFormat:@"NO: %d", _values[0]];
11849ffe3c632Sopenharmony_ci  }
11850ffe3c632Sopenharmony_ci  if (_valueSet[1]) {
11851ffe3c632Sopenharmony_ci    [result appendFormat:@"YES: %d", _values[1]];
11852ffe3c632Sopenharmony_ci  }
11853ffe3c632Sopenharmony_ci  [result appendString:@" }"];
11854ffe3c632Sopenharmony_ci  return result;
11855ffe3c632Sopenharmony_ci}
11856ffe3c632Sopenharmony_ci
11857ffe3c632Sopenharmony_ci- (NSUInteger)count {
11858ffe3c632Sopenharmony_ci  return (_valueSet[0] ? 1 : 0) + (_valueSet[1] ? 1 : 0);
11859ffe3c632Sopenharmony_ci}
11860ffe3c632Sopenharmony_ci
11861ffe3c632Sopenharmony_ci- (BOOL)getEnum:(int32_t*)value forKey:(BOOL)key {
11862ffe3c632Sopenharmony_ci  int idx = (key ? 1 : 0);
11863ffe3c632Sopenharmony_ci  if (_valueSet[idx]) {
11864ffe3c632Sopenharmony_ci    if (value) {
11865ffe3c632Sopenharmony_ci      int32_t result = _values[idx];
11866ffe3c632Sopenharmony_ci      if (!_validationFunc(result)) {
11867ffe3c632Sopenharmony_ci        result = kGPBUnrecognizedEnumeratorValue;
11868ffe3c632Sopenharmony_ci      }
11869ffe3c632Sopenharmony_ci      *value = result;
11870ffe3c632Sopenharmony_ci    }
11871ffe3c632Sopenharmony_ci    return YES;
11872ffe3c632Sopenharmony_ci  }
11873ffe3c632Sopenharmony_ci  return NO;
11874ffe3c632Sopenharmony_ci}
11875ffe3c632Sopenharmony_ci
11876ffe3c632Sopenharmony_ci- (BOOL)getRawValue:(int32_t*)rawValue forKey:(BOOL)key {
11877ffe3c632Sopenharmony_ci  int idx = (key ? 1 : 0);
11878ffe3c632Sopenharmony_ci  if (_valueSet[idx]) {
11879ffe3c632Sopenharmony_ci    if (rawValue) {
11880ffe3c632Sopenharmony_ci      *rawValue = _values[idx];
11881ffe3c632Sopenharmony_ci    }
11882ffe3c632Sopenharmony_ci    return YES;
11883ffe3c632Sopenharmony_ci  }
11884ffe3c632Sopenharmony_ci  return NO;
11885ffe3c632Sopenharmony_ci}
11886ffe3c632Sopenharmony_ci
11887ffe3c632Sopenharmony_ci- (void)enumerateKeysAndRawValuesUsingBlock:
11888ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(BOOL key, int32_t value, BOOL *stop))block {
11889ffe3c632Sopenharmony_ci  BOOL stop = NO;
11890ffe3c632Sopenharmony_ci  if (_valueSet[0]) {
11891ffe3c632Sopenharmony_ci    block(NO, _values[0], &stop);
11892ffe3c632Sopenharmony_ci  }
11893ffe3c632Sopenharmony_ci  if (!stop && _valueSet[1]) {
11894ffe3c632Sopenharmony_ci    block(YES, _values[1], &stop);
11895ffe3c632Sopenharmony_ci  }
11896ffe3c632Sopenharmony_ci}
11897ffe3c632Sopenharmony_ci
11898ffe3c632Sopenharmony_ci- (void)enumerateKeysAndEnumsUsingBlock:
11899ffe3c632Sopenharmony_ci    (void (NS_NOESCAPE ^)(BOOL key, int32_t rawValue, BOOL *stop))block {
11900ffe3c632Sopenharmony_ci  BOOL stop = NO;
11901ffe3c632Sopenharmony_ci  GPBEnumValidationFunc func = _validationFunc;
11902ffe3c632Sopenharmony_ci  int32_t validatedValue;
11903ffe3c632Sopenharmony_ci  if (_valueSet[0]) {
11904ffe3c632Sopenharmony_ci    validatedValue = _values[0];
11905ffe3c632Sopenharmony_ci    if (!func(validatedValue)) {
11906ffe3c632Sopenharmony_ci      validatedValue = kGPBUnrecognizedEnumeratorValue;
11907ffe3c632Sopenharmony_ci    }
11908ffe3c632Sopenharmony_ci    block(NO, validatedValue, &stop);
11909ffe3c632Sopenharmony_ci  }
11910ffe3c632Sopenharmony_ci  if (!stop && _valueSet[1]) {
11911ffe3c632Sopenharmony_ci    validatedValue = _values[1];
11912ffe3c632Sopenharmony_ci    if (!func(validatedValue)) {
11913ffe3c632Sopenharmony_ci      validatedValue = kGPBUnrecognizedEnumeratorValue;
11914ffe3c632Sopenharmony_ci    }
11915ffe3c632Sopenharmony_ci    block(YES, validatedValue, &stop);
11916ffe3c632Sopenharmony_ci  }
11917ffe3c632Sopenharmony_ci}
11918ffe3c632Sopenharmony_ci
11919ffe3c632Sopenharmony_ci//%PDDM-EXPAND SERIAL_DATA_FOR_ENTRY_POD_Enum(Bool)
11920ffe3c632Sopenharmony_ci// This block of code is generated, do not edit it directly.
11921ffe3c632Sopenharmony_ci// clang-format off
11922ffe3c632Sopenharmony_ci
11923ffe3c632Sopenharmony_ci- (NSData *)serializedDataForUnknownValue:(int32_t)value
11924ffe3c632Sopenharmony_ci                                   forKey:(GPBGenericValue *)key
11925ffe3c632Sopenharmony_ci                              keyDataType:(GPBDataType)keyDataType {
11926ffe3c632Sopenharmony_ci  size_t msgSize = ComputeDictBoolFieldSize(key->valueBool, kMapKeyFieldNumber, keyDataType);
11927ffe3c632Sopenharmony_ci  msgSize += ComputeDictEnumFieldSize(value, kMapValueFieldNumber, GPBDataTypeEnum);
11928ffe3c632Sopenharmony_ci  NSMutableData *data = [NSMutableData dataWithLength:msgSize];
11929ffe3c632Sopenharmony_ci  GPBCodedOutputStream *outputStream = [[GPBCodedOutputStream alloc] initWithData:data];
11930ffe3c632Sopenharmony_ci  WriteDictBoolField(outputStream, key->valueBool, kMapKeyFieldNumber, keyDataType);
11931ffe3c632Sopenharmony_ci  WriteDictEnumField(outputStream, value, kMapValueFieldNumber, GPBDataTypeEnum);
11932ffe3c632Sopenharmony_ci  [outputStream release];
11933ffe3c632Sopenharmony_ci  return data;
11934ffe3c632Sopenharmony_ci}
11935ffe3c632Sopenharmony_ci
11936ffe3c632Sopenharmony_ci// clang-format on
11937ffe3c632Sopenharmony_ci//%PDDM-EXPAND-END SERIAL_DATA_FOR_ENTRY_POD_Enum(Bool)
11938ffe3c632Sopenharmony_ci
11939ffe3c632Sopenharmony_ci- (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field {
11940ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
11941ffe3c632Sopenharmony_ci  NSUInteger count = 0;
11942ffe3c632Sopenharmony_ci  size_t result = 0;
11943ffe3c632Sopenharmony_ci  for (int i = 0; i < 2; ++i) {
11944ffe3c632Sopenharmony_ci    if (_valueSet[i]) {
11945ffe3c632Sopenharmony_ci      ++count;
11946ffe3c632Sopenharmony_ci      size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11947ffe3c632Sopenharmony_ci      msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
11948ffe3c632Sopenharmony_ci      result += GPBComputeRawVarint32SizeForInteger(msgSize) + msgSize;
11949ffe3c632Sopenharmony_ci    }
11950ffe3c632Sopenharmony_ci  }
11951ffe3c632Sopenharmony_ci  size_t tagSize = GPBComputeWireFormatTagSize(GPBFieldNumber(field), GPBDataTypeMessage);
11952ffe3c632Sopenharmony_ci  result += tagSize * count;
11953ffe3c632Sopenharmony_ci  return result;
11954ffe3c632Sopenharmony_ci}
11955ffe3c632Sopenharmony_ci
11956ffe3c632Sopenharmony_ci- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
11957ffe3c632Sopenharmony_ci                         asField:(GPBFieldDescriptor *)field {
11958ffe3c632Sopenharmony_ci  GPBDataType valueDataType = GPBGetFieldDataType(field);
11959ffe3c632Sopenharmony_ci  uint32_t tag = GPBWireFormatMakeTag(GPBFieldNumber(field), GPBWireFormatLengthDelimited);
11960ffe3c632Sopenharmony_ci  for (int i = 0; i < 2; ++i) {
11961ffe3c632Sopenharmony_ci    if (_valueSet[i]) {
11962ffe3c632Sopenharmony_ci      // Write the tag.
11963ffe3c632Sopenharmony_ci      [outputStream writeInt32NoTag:tag];
11964ffe3c632Sopenharmony_ci      // Write the size of the message.
11965ffe3c632Sopenharmony_ci      size_t msgSize = ComputeDictBoolFieldSize((i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11966ffe3c632Sopenharmony_ci      msgSize += ComputeDictInt32FieldSize(_values[i], kMapValueFieldNumber, valueDataType);
11967ffe3c632Sopenharmony_ci      [outputStream writeInt32NoTag:(int32_t)msgSize];
11968ffe3c632Sopenharmony_ci      // Write the fields.
11969ffe3c632Sopenharmony_ci      WriteDictBoolField(outputStream, (i == 1), kMapKeyFieldNumber, GPBDataTypeBool);
11970ffe3c632Sopenharmony_ci      WriteDictInt32Field(outputStream, _values[i], kMapValueFieldNumber, valueDataType);
11971ffe3c632Sopenharmony_ci    }
11972ffe3c632Sopenharmony_ci  }
11973ffe3c632Sopenharmony_ci}
11974ffe3c632Sopenharmony_ci
11975ffe3c632Sopenharmony_ci- (void)enumerateForTextFormat:(void (NS_NOESCAPE ^)(id keyObj, id valueObj))block {
11976ffe3c632Sopenharmony_ci  if (_valueSet[0]) {
11977ffe3c632Sopenharmony_ci    block(@"false", @(_values[0]));
11978ffe3c632Sopenharmony_ci  }
11979ffe3c632Sopenharmony_ci  if (_valueSet[1]) {
11980ffe3c632Sopenharmony_ci    block(@"true", @(_values[1]));
11981ffe3c632Sopenharmony_ci  }
11982ffe3c632Sopenharmony_ci}
11983ffe3c632Sopenharmony_ci
11984ffe3c632Sopenharmony_ci- (void)setGPBGenericValue:(GPBGenericValue *)value
11985ffe3c632Sopenharmony_ci     forGPBGenericValueKey:(GPBGenericValue *)key {
11986ffe3c632Sopenharmony_ci  int idx = (key->valueBool ? 1 : 0);
11987ffe3c632Sopenharmony_ci  _values[idx] = value->valueInt32;
11988ffe3c632Sopenharmony_ci  _valueSet[idx] = YES;
11989ffe3c632Sopenharmony_ci}
11990ffe3c632Sopenharmony_ci
11991ffe3c632Sopenharmony_ci- (void)addRawEntriesFromDictionary:(GPBBoolEnumDictionary *)otherDictionary {
11992ffe3c632Sopenharmony_ci  if (otherDictionary) {
11993ffe3c632Sopenharmony_ci    for (int i = 0; i < 2; ++i) {
11994ffe3c632Sopenharmony_ci      if (otherDictionary->_valueSet[i]) {
11995ffe3c632Sopenharmony_ci        _valueSet[i] = YES;
11996ffe3c632Sopenharmony_ci        _values[i] = otherDictionary->_values[i];
11997ffe3c632Sopenharmony_ci      }
11998ffe3c632Sopenharmony_ci    }
11999ffe3c632Sopenharmony_ci    if (_autocreator) {
12000ffe3c632Sopenharmony_ci      GPBAutocreatedDictionaryModified(_autocreator, self);
12001ffe3c632Sopenharmony_ci    }
12002ffe3c632Sopenharmony_ci  }
12003ffe3c632Sopenharmony_ci}
12004ffe3c632Sopenharmony_ci
12005ffe3c632Sopenharmony_ci- (void)setEnum:(int32_t)value forKey:(BOOL)key {
12006ffe3c632Sopenharmony_ci  if (!_validationFunc(value)) {
12007ffe3c632Sopenharmony_ci    [NSException raise:NSInvalidArgumentException
12008ffe3c632Sopenharmony_ci                format:@"GPBBoolEnumDictionary: Attempt to set an unknown enum value (%d)",
12009ffe3c632Sopenharmony_ci     value];
12010ffe3c632Sopenharmony_ci  }
12011ffe3c632Sopenharmony_ci  int idx = (key ? 1 : 0);
12012ffe3c632Sopenharmony_ci  _values[idx] = value;
12013ffe3c632Sopenharmony_ci  _valueSet[idx] = YES;
12014ffe3c632Sopenharmony_ci  if (_autocreator) {
12015ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
12016ffe3c632Sopenharmony_ci  }
12017ffe3c632Sopenharmony_ci}
12018ffe3c632Sopenharmony_ci
12019ffe3c632Sopenharmony_ci- (void)setRawValue:(int32_t)rawValue forKey:(BOOL)key {
12020ffe3c632Sopenharmony_ci  int idx = (key ? 1 : 0);
12021ffe3c632Sopenharmony_ci  _values[idx] = rawValue;
12022ffe3c632Sopenharmony_ci  _valueSet[idx] = YES;
12023ffe3c632Sopenharmony_ci  if (_autocreator) {
12024ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
12025ffe3c632Sopenharmony_ci  }
12026ffe3c632Sopenharmony_ci}
12027ffe3c632Sopenharmony_ci
12028ffe3c632Sopenharmony_ci- (void)removeEnumForKey:(BOOL)aKey {
12029ffe3c632Sopenharmony_ci  _valueSet[aKey ? 1 : 0] = NO;
12030ffe3c632Sopenharmony_ci}
12031ffe3c632Sopenharmony_ci
12032ffe3c632Sopenharmony_ci- (void)removeAll {
12033ffe3c632Sopenharmony_ci  _valueSet[0] = NO;
12034ffe3c632Sopenharmony_ci  _valueSet[1] = NO;
12035ffe3c632Sopenharmony_ci}
12036ffe3c632Sopenharmony_ci
12037ffe3c632Sopenharmony_ci@end
12038ffe3c632Sopenharmony_ci
12039ffe3c632Sopenharmony_ci#pragma mark - NSDictionary Subclass
12040ffe3c632Sopenharmony_ci
12041ffe3c632Sopenharmony_ci@implementation GPBAutocreatedDictionary {
12042ffe3c632Sopenharmony_ci  NSMutableDictionary *_dictionary;
12043ffe3c632Sopenharmony_ci}
12044ffe3c632Sopenharmony_ci
12045ffe3c632Sopenharmony_ci- (void)dealloc {
12046ffe3c632Sopenharmony_ci  NSAssert(!_autocreator,
12047ffe3c632Sopenharmony_ci           @"%@: Autocreator must be cleared before release, autocreator: %@",
12048ffe3c632Sopenharmony_ci           [self class], _autocreator);
12049ffe3c632Sopenharmony_ci  [_dictionary release];
12050ffe3c632Sopenharmony_ci  [super dealloc];
12051ffe3c632Sopenharmony_ci}
12052ffe3c632Sopenharmony_ci
12053ffe3c632Sopenharmony_ci#pragma mark Required NSDictionary overrides
12054ffe3c632Sopenharmony_ci
12055ffe3c632Sopenharmony_ci- (instancetype)initWithObjects:(const id [])objects
12056ffe3c632Sopenharmony_ci                        forKeys:(const id<NSCopying> [])keys
12057ffe3c632Sopenharmony_ci                          count:(NSUInteger)count {
12058ffe3c632Sopenharmony_ci  self = [super init];
12059ffe3c632Sopenharmony_ci  if (self) {
12060ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] initWithObjects:objects
12061ffe3c632Sopenharmony_ci                                                       forKeys:keys
12062ffe3c632Sopenharmony_ci                                                         count:count];
12063ffe3c632Sopenharmony_ci  }
12064ffe3c632Sopenharmony_ci  return self;
12065ffe3c632Sopenharmony_ci}
12066ffe3c632Sopenharmony_ci
12067ffe3c632Sopenharmony_ci- (NSUInteger)count {
12068ffe3c632Sopenharmony_ci  return [_dictionary count];
12069ffe3c632Sopenharmony_ci}
12070ffe3c632Sopenharmony_ci
12071ffe3c632Sopenharmony_ci- (id)objectForKey:(id)aKey {
12072ffe3c632Sopenharmony_ci  return [_dictionary objectForKey:aKey];
12073ffe3c632Sopenharmony_ci}
12074ffe3c632Sopenharmony_ci
12075ffe3c632Sopenharmony_ci- (NSEnumerator *)keyEnumerator {
12076ffe3c632Sopenharmony_ci  if (_dictionary == nil) {
12077ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
12078ffe3c632Sopenharmony_ci  }
12079ffe3c632Sopenharmony_ci  return [_dictionary keyEnumerator];
12080ffe3c632Sopenharmony_ci}
12081ffe3c632Sopenharmony_ci
12082ffe3c632Sopenharmony_ci#pragma mark Required NSMutableDictionary overrides
12083ffe3c632Sopenharmony_ci
12084ffe3c632Sopenharmony_ci// Only need to call GPBAutocreatedDictionaryModified() when adding things
12085ffe3c632Sopenharmony_ci// since we only autocreate empty dictionaries.
12086ffe3c632Sopenharmony_ci
12087ffe3c632Sopenharmony_ci- (void)setObject:(id)anObject forKey:(id<NSCopying>)aKey {
12088ffe3c632Sopenharmony_ci  if (_dictionary == nil) {
12089ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
12090ffe3c632Sopenharmony_ci  }
12091ffe3c632Sopenharmony_ci  [_dictionary setObject:anObject forKey:aKey];
12092ffe3c632Sopenharmony_ci  if (_autocreator) {
12093ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
12094ffe3c632Sopenharmony_ci  }
12095ffe3c632Sopenharmony_ci}
12096ffe3c632Sopenharmony_ci
12097ffe3c632Sopenharmony_ci- (void)removeObjectForKey:(id)aKey {
12098ffe3c632Sopenharmony_ci  [_dictionary removeObjectForKey:aKey];
12099ffe3c632Sopenharmony_ci}
12100ffe3c632Sopenharmony_ci
12101ffe3c632Sopenharmony_ci#pragma mark Extra things hooked
12102ffe3c632Sopenharmony_ci
12103ffe3c632Sopenharmony_ci- (id)copyWithZone:(NSZone *)zone {
12104ffe3c632Sopenharmony_ci  if (_dictionary == nil) {
12105ffe3c632Sopenharmony_ci    return [[NSMutableDictionary allocWithZone:zone] init];
12106ffe3c632Sopenharmony_ci  }
12107ffe3c632Sopenharmony_ci  return [_dictionary copyWithZone:zone];
12108ffe3c632Sopenharmony_ci}
12109ffe3c632Sopenharmony_ci
12110ffe3c632Sopenharmony_ci- (id)mutableCopyWithZone:(NSZone *)zone {
12111ffe3c632Sopenharmony_ci  if (_dictionary == nil) {
12112ffe3c632Sopenharmony_ci    return [[NSMutableDictionary allocWithZone:zone] init];
12113ffe3c632Sopenharmony_ci  }
12114ffe3c632Sopenharmony_ci  return [_dictionary mutableCopyWithZone:zone];
12115ffe3c632Sopenharmony_ci}
12116ffe3c632Sopenharmony_ci
12117ffe3c632Sopenharmony_ci// Not really needed, but subscripting is likely common enough it doesn't hurt
12118ffe3c632Sopenharmony_ci// to ensure it goes directly to the real NSMutableDictionary.
12119ffe3c632Sopenharmony_ci- (id)objectForKeyedSubscript:(id)key {
12120ffe3c632Sopenharmony_ci  return [_dictionary objectForKeyedSubscript:key];
12121ffe3c632Sopenharmony_ci}
12122ffe3c632Sopenharmony_ci
12123ffe3c632Sopenharmony_ci// Not really needed, but subscripting is likely common enough it doesn't hurt
12124ffe3c632Sopenharmony_ci// to ensure it goes directly to the real NSMutableDictionary.
12125ffe3c632Sopenharmony_ci- (void)setObject:(id)obj forKeyedSubscript:(id<NSCopying>)key {
12126ffe3c632Sopenharmony_ci  if (_dictionary == nil) {
12127ffe3c632Sopenharmony_ci    _dictionary = [[NSMutableDictionary alloc] init];
12128ffe3c632Sopenharmony_ci  }
12129ffe3c632Sopenharmony_ci  [_dictionary setObject:obj forKeyedSubscript:key];
12130ffe3c632Sopenharmony_ci  if (_autocreator) {
12131ffe3c632Sopenharmony_ci    GPBAutocreatedDictionaryModified(_autocreator, self);
12132ffe3c632Sopenharmony_ci  }
12133ffe3c632Sopenharmony_ci}
12134ffe3c632Sopenharmony_ci
12135ffe3c632Sopenharmony_ci- (void)enumerateKeysAndObjectsUsingBlock:(void (NS_NOESCAPE ^)(id key,
12136ffe3c632Sopenharmony_ci                                                    id obj,
12137ffe3c632Sopenharmony_ci                                                    BOOL *stop))block {
12138ffe3c632Sopenharmony_ci  [_dictionary enumerateKeysAndObjectsUsingBlock:block];
12139ffe3c632Sopenharmony_ci}
12140ffe3c632Sopenharmony_ci
12141ffe3c632Sopenharmony_ci- (void)enumerateKeysAndObjectsWithOptions:(NSEnumerationOptions)opts
12142ffe3c632Sopenharmony_ci                                usingBlock:(void (NS_NOESCAPE ^)(id key,
12143ffe3c632Sopenharmony_ci                                                     id obj,
12144ffe3c632Sopenharmony_ci                                                     BOOL *stop))block {
12145ffe3c632Sopenharmony_ci  [_dictionary enumerateKeysAndObjectsWithOptions:opts usingBlock:block];
12146ffe3c632Sopenharmony_ci}
12147ffe3c632Sopenharmony_ci
12148ffe3c632Sopenharmony_ci@end
12149ffe3c632Sopenharmony_ci
12150ffe3c632Sopenharmony_ci#pragma clang diagnostic pop
12151