Avoid recursive call to `Insert` in the flat case.
[google-protobuf.git] / objectivec / GPBDictionary_PackagePrivate.h
blob8d6ea16c95d7b2944d19f1d015d48ef1855f4b9b
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 //
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file or at
6 // https://developers.google.com/open-source/licenses/bsd
8 #import <Foundation/Foundation.h>
10 #import "GPBDictionary.h"
12 #import "GPBCodedInputStream.h"
13 #import "GPBCodedOutputStream.h"
14 #import "GPBDescriptor.h"
15 #import "GPBExtensionRegistry.h"
17 @protocol GPBDictionaryInternalsProtocol
18 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field;
19 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
20 asField:(GPBFieldDescriptor *)field;
21 - (void)setGPBGenericValue:(GPBGenericValue *)value forGPBGenericValueKey:(GPBGenericValue *)key;
22 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block;
23 @end
25 // Disable clang-format for the macros.
26 // clang-format off
28 //%PDDM-DEFINE DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(KEY_NAME)
29 //%DICTIONARY_POD_PRIV_INTERFACES_FOR_KEY(KEY_NAME)
30 //%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, Object, Object)
31 //%PDDM-DEFINE DICTIONARY_POD_PRIV_INTERFACES_FOR_KEY(KEY_NAME)
32 //%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, UInt32, Basic)
33 //%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, Int32, Basic)
34 //%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, UInt64, Basic)
35 //%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, Int64, Basic)
36 //%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, Bool, Basic)
37 //%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, Float, Basic)
38 //%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, Double, Basic)
39 //%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, Enum, Enum)
41 //%PDDM-DEFINE DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, VALUE_NAME, HELPER)
42 //%@interface GPB##KEY_NAME##VALUE_NAME##Dictionary () <GPBDictionaryInternalsProtocol> {
43 //% @package
44 //% GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
45 //%}
46 //%EXTRA_DICTIONARY_PRIVATE_INTERFACES_##HELPER()@end
47 //%
49 //%PDDM-DEFINE EXTRA_DICTIONARY_PRIVATE_INTERFACES_Basic()
50 // Empty
51 //%PDDM-DEFINE EXTRA_DICTIONARY_PRIVATE_INTERFACES_Object()
52 //%- (BOOL)isInitialized;
53 //%- (instancetype)deepCopyWithZone:(NSZone *)zone
54 //% __attribute__((ns_returns_retained));
55 //%
56 //%PDDM-DEFINE EXTRA_DICTIONARY_PRIVATE_INTERFACES_Enum()
57 //%- (NSData *)serializedDataForUnknownValue:(int32_t)value
58 //% forKey:(GPBGenericValue *)key
59 //% keyDataType:(GPBDataType)keyDataType;
60 //%
62 //%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(UInt32)
63 // This block of code is generated, do not edit it directly.
65 @interface GPBUInt32UInt32Dictionary () <GPBDictionaryInternalsProtocol> {
66 @package
67 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
69 @end
71 @interface GPBUInt32Int32Dictionary () <GPBDictionaryInternalsProtocol> {
72 @package
73 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
75 @end
77 @interface GPBUInt32UInt64Dictionary () <GPBDictionaryInternalsProtocol> {
78 @package
79 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
81 @end
83 @interface GPBUInt32Int64Dictionary () <GPBDictionaryInternalsProtocol> {
84 @package
85 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
87 @end
89 @interface GPBUInt32BoolDictionary () <GPBDictionaryInternalsProtocol> {
90 @package
91 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
93 @end
95 @interface GPBUInt32FloatDictionary () <GPBDictionaryInternalsProtocol> {
96 @package
97 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
99 @end
101 @interface GPBUInt32DoubleDictionary () <GPBDictionaryInternalsProtocol> {
102 @package
103 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
105 @end
107 @interface GPBUInt32EnumDictionary () <GPBDictionaryInternalsProtocol> {
108 @package
109 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
111 - (NSData *)serializedDataForUnknownValue:(int32_t)value
112 forKey:(GPBGenericValue *)key
113 keyDataType:(GPBDataType)keyDataType;
114 @end
116 @interface GPBUInt32ObjectDictionary () <GPBDictionaryInternalsProtocol> {
117 @package
118 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
120 - (BOOL)isInitialized;
121 - (instancetype)deepCopyWithZone:(NSZone *)zone
122 __attribute__((ns_returns_retained));
123 @end
125 //%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(Int32)
126 // This block of code is generated, do not edit it directly.
128 @interface GPBInt32UInt32Dictionary () <GPBDictionaryInternalsProtocol> {
129 @package
130 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
132 @end
134 @interface GPBInt32Int32Dictionary () <GPBDictionaryInternalsProtocol> {
135 @package
136 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
138 @end
140 @interface GPBInt32UInt64Dictionary () <GPBDictionaryInternalsProtocol> {
141 @package
142 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
144 @end
146 @interface GPBInt32Int64Dictionary () <GPBDictionaryInternalsProtocol> {
147 @package
148 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
150 @end
152 @interface GPBInt32BoolDictionary () <GPBDictionaryInternalsProtocol> {
153 @package
154 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
156 @end
158 @interface GPBInt32FloatDictionary () <GPBDictionaryInternalsProtocol> {
159 @package
160 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
162 @end
164 @interface GPBInt32DoubleDictionary () <GPBDictionaryInternalsProtocol> {
165 @package
166 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
168 @end
170 @interface GPBInt32EnumDictionary () <GPBDictionaryInternalsProtocol> {
171 @package
172 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
174 - (NSData *)serializedDataForUnknownValue:(int32_t)value
175 forKey:(GPBGenericValue *)key
176 keyDataType:(GPBDataType)keyDataType;
177 @end
179 @interface GPBInt32ObjectDictionary () <GPBDictionaryInternalsProtocol> {
180 @package
181 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
183 - (BOOL)isInitialized;
184 - (instancetype)deepCopyWithZone:(NSZone *)zone
185 __attribute__((ns_returns_retained));
186 @end
188 //%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(UInt64)
189 // This block of code is generated, do not edit it directly.
191 @interface GPBUInt64UInt32Dictionary () <GPBDictionaryInternalsProtocol> {
192 @package
193 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
195 @end
197 @interface GPBUInt64Int32Dictionary () <GPBDictionaryInternalsProtocol> {
198 @package
199 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
201 @end
203 @interface GPBUInt64UInt64Dictionary () <GPBDictionaryInternalsProtocol> {
204 @package
205 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
207 @end
209 @interface GPBUInt64Int64Dictionary () <GPBDictionaryInternalsProtocol> {
210 @package
211 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
213 @end
215 @interface GPBUInt64BoolDictionary () <GPBDictionaryInternalsProtocol> {
216 @package
217 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
219 @end
221 @interface GPBUInt64FloatDictionary () <GPBDictionaryInternalsProtocol> {
222 @package
223 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
225 @end
227 @interface GPBUInt64DoubleDictionary () <GPBDictionaryInternalsProtocol> {
228 @package
229 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
231 @end
233 @interface GPBUInt64EnumDictionary () <GPBDictionaryInternalsProtocol> {
234 @package
235 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
237 - (NSData *)serializedDataForUnknownValue:(int32_t)value
238 forKey:(GPBGenericValue *)key
239 keyDataType:(GPBDataType)keyDataType;
240 @end
242 @interface GPBUInt64ObjectDictionary () <GPBDictionaryInternalsProtocol> {
243 @package
244 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
246 - (BOOL)isInitialized;
247 - (instancetype)deepCopyWithZone:(NSZone *)zone
248 __attribute__((ns_returns_retained));
249 @end
251 //%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(Int64)
252 // This block of code is generated, do not edit it directly.
254 @interface GPBInt64UInt32Dictionary () <GPBDictionaryInternalsProtocol> {
255 @package
256 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
258 @end
260 @interface GPBInt64Int32Dictionary () <GPBDictionaryInternalsProtocol> {
261 @package
262 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
264 @end
266 @interface GPBInt64UInt64Dictionary () <GPBDictionaryInternalsProtocol> {
267 @package
268 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
270 @end
272 @interface GPBInt64Int64Dictionary () <GPBDictionaryInternalsProtocol> {
273 @package
274 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
276 @end
278 @interface GPBInt64BoolDictionary () <GPBDictionaryInternalsProtocol> {
279 @package
280 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
282 @end
284 @interface GPBInt64FloatDictionary () <GPBDictionaryInternalsProtocol> {
285 @package
286 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
288 @end
290 @interface GPBInt64DoubleDictionary () <GPBDictionaryInternalsProtocol> {
291 @package
292 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
294 @end
296 @interface GPBInt64EnumDictionary () <GPBDictionaryInternalsProtocol> {
297 @package
298 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
300 - (NSData *)serializedDataForUnknownValue:(int32_t)value
301 forKey:(GPBGenericValue *)key
302 keyDataType:(GPBDataType)keyDataType;
303 @end
305 @interface GPBInt64ObjectDictionary () <GPBDictionaryInternalsProtocol> {
306 @package
307 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
309 - (BOOL)isInitialized;
310 - (instancetype)deepCopyWithZone:(NSZone *)zone
311 __attribute__((ns_returns_retained));
312 @end
314 //%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(Bool)
315 // This block of code is generated, do not edit it directly.
317 @interface GPBBoolUInt32Dictionary () <GPBDictionaryInternalsProtocol> {
318 @package
319 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
321 @end
323 @interface GPBBoolInt32Dictionary () <GPBDictionaryInternalsProtocol> {
324 @package
325 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
327 @end
329 @interface GPBBoolUInt64Dictionary () <GPBDictionaryInternalsProtocol> {
330 @package
331 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
333 @end
335 @interface GPBBoolInt64Dictionary () <GPBDictionaryInternalsProtocol> {
336 @package
337 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
339 @end
341 @interface GPBBoolBoolDictionary () <GPBDictionaryInternalsProtocol> {
342 @package
343 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
345 @end
347 @interface GPBBoolFloatDictionary () <GPBDictionaryInternalsProtocol> {
348 @package
349 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
351 @end
353 @interface GPBBoolDoubleDictionary () <GPBDictionaryInternalsProtocol> {
354 @package
355 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
357 @end
359 @interface GPBBoolEnumDictionary () <GPBDictionaryInternalsProtocol> {
360 @package
361 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
363 - (NSData *)serializedDataForUnknownValue:(int32_t)value
364 forKey:(GPBGenericValue *)key
365 keyDataType:(GPBDataType)keyDataType;
366 @end
368 @interface GPBBoolObjectDictionary () <GPBDictionaryInternalsProtocol> {
369 @package
370 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
372 - (BOOL)isInitialized;
373 - (instancetype)deepCopyWithZone:(NSZone *)zone
374 __attribute__((ns_returns_retained));
375 @end
377 //%PDDM-EXPAND DICTIONARY_POD_PRIV_INTERFACES_FOR_KEY(String)
378 // This block of code is generated, do not edit it directly.
380 @interface GPBStringUInt32Dictionary () <GPBDictionaryInternalsProtocol> {
381 @package
382 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
384 @end
386 @interface GPBStringInt32Dictionary () <GPBDictionaryInternalsProtocol> {
387 @package
388 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
390 @end
392 @interface GPBStringUInt64Dictionary () <GPBDictionaryInternalsProtocol> {
393 @package
394 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
396 @end
398 @interface GPBStringInt64Dictionary () <GPBDictionaryInternalsProtocol> {
399 @package
400 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
402 @end
404 @interface GPBStringBoolDictionary () <GPBDictionaryInternalsProtocol> {
405 @package
406 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
408 @end
410 @interface GPBStringFloatDictionary () <GPBDictionaryInternalsProtocol> {
411 @package
412 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
414 @end
416 @interface GPBStringDoubleDictionary () <GPBDictionaryInternalsProtocol> {
417 @package
418 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
420 @end
422 @interface GPBStringEnumDictionary () <GPBDictionaryInternalsProtocol> {
423 @package
424 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
426 - (NSData *)serializedDataForUnknownValue:(int32_t)value
427 forKey:(GPBGenericValue *)key
428 keyDataType:(GPBDataType)keyDataType;
429 @end
431 //%PDDM-EXPAND-END (6 expansions)
433 // clang-format on
435 #pragma mark - NSDictionary Subclass
437 @interface GPBAutocreatedDictionary : NSMutableDictionary {
438 @package
439 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
441 @end
443 #pragma mark - Helpers
445 CF_EXTERN_C_BEGIN
447 // Helper to compute size when an NSDictionary is used for the map instead
448 // of a custom type.
449 size_t GPBDictionaryComputeSizeInternalHelper(NSDictionary *dict, GPBFieldDescriptor *field);
451 // Helper to write out when an NSDictionary is used for the map instead
452 // of a custom type.
453 void GPBDictionaryWriteToStreamInternalHelper(GPBCodedOutputStream *outputStream,
454 NSDictionary *dict, GPBFieldDescriptor *field);
456 // Helper to check message initialization when an NSDictionary is used for
457 // the map instead of a custom type.
458 BOOL GPBDictionaryIsInitializedInternalHelper(NSDictionary *dict, GPBFieldDescriptor *field);
460 // Helper to read a map instead.
461 void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream,
462 id<GPBExtensionRegistry> registry, GPBFieldDescriptor *field,
463 GPBMessage *parentMessage);
465 CF_EXTERN_C_END