1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file or at
6 // https://developers.google.com/open-source/licenses/bsd
8 #import <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
;
25 // Disable clang-format for the macros.
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> {
44 //% GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
46 //%EXTRA_DICTIONARY_PRIVATE_INTERFACES_##HELPER()@end
49 //%PDDM-DEFINE EXTRA_DICTIONARY_PRIVATE_INTERFACES_Basic()
51 //%PDDM-DEFINE EXTRA_DICTIONARY_PRIVATE_INTERFACES_Object()
52 //%- (BOOL)isInitialized;
53 //%- (instancetype)deepCopyWithZone:(NSZone *)zone
54 //% __attribute__((ns_returns_retained));
56 //%PDDM-DEFINE EXTRA_DICTIONARY_PRIVATE_INTERFACES_Enum()
57 //%- (NSData *)serializedDataForUnknownValue:(int32_t)value
58 //% forKey:(GPBGenericValue *)key
59 //% keyDataType:(GPBDataType)keyDataType;
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
> {
67 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
71 @interface
GPBUInt32Int32Dictionary () <GPBDictionaryInternalsProtocol
> {
73 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
77 @interface
GPBUInt32UInt64Dictionary () <GPBDictionaryInternalsProtocol
> {
79 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
83 @interface
GPBUInt32Int64Dictionary () <GPBDictionaryInternalsProtocol
> {
85 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
89 @interface
GPBUInt32BoolDictionary () <GPBDictionaryInternalsProtocol
> {
91 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
95 @interface
GPBUInt32FloatDictionary () <GPBDictionaryInternalsProtocol
> {
97 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
101 @interface
GPBUInt32DoubleDictionary () <GPBDictionaryInternalsProtocol
> {
103 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
107 @interface
GPBUInt32EnumDictionary () <GPBDictionaryInternalsProtocol
> {
109 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
111 - (NSData
*)serializedDataForUnknownValue
:(int32_t)value
112 forKey
:(GPBGenericValue
*)key
113 keyDataType
:(GPBDataType
)keyDataType
;
116 @interface
GPBUInt32ObjectDictionary () <GPBDictionaryInternalsProtocol
> {
118 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
120 - (BOOL
)isInitialized
;
121 - (instancetype
)deepCopyWithZone
:(NSZone
*)zone
122 __attribute__((ns_returns_retained
));
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
> {
130 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
134 @interface
GPBInt32Int32Dictionary () <GPBDictionaryInternalsProtocol
> {
136 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
140 @interface
GPBInt32UInt64Dictionary () <GPBDictionaryInternalsProtocol
> {
142 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
146 @interface
GPBInt32Int64Dictionary () <GPBDictionaryInternalsProtocol
> {
148 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
152 @interface
GPBInt32BoolDictionary () <GPBDictionaryInternalsProtocol
> {
154 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
158 @interface
GPBInt32FloatDictionary () <GPBDictionaryInternalsProtocol
> {
160 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
164 @interface
GPBInt32DoubleDictionary () <GPBDictionaryInternalsProtocol
> {
166 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
170 @interface
GPBInt32EnumDictionary () <GPBDictionaryInternalsProtocol
> {
172 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
174 - (NSData
*)serializedDataForUnknownValue
:(int32_t)value
175 forKey
:(GPBGenericValue
*)key
176 keyDataType
:(GPBDataType
)keyDataType
;
179 @interface
GPBInt32ObjectDictionary () <GPBDictionaryInternalsProtocol
> {
181 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
183 - (BOOL
)isInitialized
;
184 - (instancetype
)deepCopyWithZone
:(NSZone
*)zone
185 __attribute__((ns_returns_retained
));
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
> {
193 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
197 @interface
GPBUInt64Int32Dictionary () <GPBDictionaryInternalsProtocol
> {
199 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
203 @interface
GPBUInt64UInt64Dictionary () <GPBDictionaryInternalsProtocol
> {
205 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
209 @interface
GPBUInt64Int64Dictionary () <GPBDictionaryInternalsProtocol
> {
211 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
215 @interface
GPBUInt64BoolDictionary () <GPBDictionaryInternalsProtocol
> {
217 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
221 @interface
GPBUInt64FloatDictionary () <GPBDictionaryInternalsProtocol
> {
223 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
227 @interface
GPBUInt64DoubleDictionary () <GPBDictionaryInternalsProtocol
> {
229 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
233 @interface
GPBUInt64EnumDictionary () <GPBDictionaryInternalsProtocol
> {
235 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
237 - (NSData
*)serializedDataForUnknownValue
:(int32_t)value
238 forKey
:(GPBGenericValue
*)key
239 keyDataType
:(GPBDataType
)keyDataType
;
242 @interface
GPBUInt64ObjectDictionary () <GPBDictionaryInternalsProtocol
> {
244 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
246 - (BOOL
)isInitialized
;
247 - (instancetype
)deepCopyWithZone
:(NSZone
*)zone
248 __attribute__((ns_returns_retained
));
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
> {
256 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
260 @interface
GPBInt64Int32Dictionary () <GPBDictionaryInternalsProtocol
> {
262 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
266 @interface
GPBInt64UInt64Dictionary () <GPBDictionaryInternalsProtocol
> {
268 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
272 @interface
GPBInt64Int64Dictionary () <GPBDictionaryInternalsProtocol
> {
274 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
278 @interface
GPBInt64BoolDictionary () <GPBDictionaryInternalsProtocol
> {
280 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
284 @interface
GPBInt64FloatDictionary () <GPBDictionaryInternalsProtocol
> {
286 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
290 @interface
GPBInt64DoubleDictionary () <GPBDictionaryInternalsProtocol
> {
292 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
296 @interface
GPBInt64EnumDictionary () <GPBDictionaryInternalsProtocol
> {
298 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
300 - (NSData
*)serializedDataForUnknownValue
:(int32_t)value
301 forKey
:(GPBGenericValue
*)key
302 keyDataType
:(GPBDataType
)keyDataType
;
305 @interface
GPBInt64ObjectDictionary () <GPBDictionaryInternalsProtocol
> {
307 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
309 - (BOOL
)isInitialized
;
310 - (instancetype
)deepCopyWithZone
:(NSZone
*)zone
311 __attribute__((ns_returns_retained
));
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
> {
319 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
323 @interface
GPBBoolInt32Dictionary () <GPBDictionaryInternalsProtocol
> {
325 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
329 @interface
GPBBoolUInt64Dictionary () <GPBDictionaryInternalsProtocol
> {
331 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
335 @interface
GPBBoolInt64Dictionary () <GPBDictionaryInternalsProtocol
> {
337 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
341 @interface
GPBBoolBoolDictionary () <GPBDictionaryInternalsProtocol
> {
343 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
347 @interface
GPBBoolFloatDictionary () <GPBDictionaryInternalsProtocol
> {
349 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
353 @interface
GPBBoolDoubleDictionary () <GPBDictionaryInternalsProtocol
> {
355 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
359 @interface
GPBBoolEnumDictionary () <GPBDictionaryInternalsProtocol
> {
361 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
363 - (NSData
*)serializedDataForUnknownValue
:(int32_t)value
364 forKey
:(GPBGenericValue
*)key
365 keyDataType
:(GPBDataType
)keyDataType
;
368 @interface
GPBBoolObjectDictionary () <GPBDictionaryInternalsProtocol
> {
370 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
372 - (BOOL
)isInitialized
;
373 - (instancetype
)deepCopyWithZone
:(NSZone
*)zone
374 __attribute__((ns_returns_retained
));
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
> {
382 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
386 @interface
GPBStringInt32Dictionary () <GPBDictionaryInternalsProtocol
> {
388 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
392 @interface
GPBStringUInt64Dictionary () <GPBDictionaryInternalsProtocol
> {
394 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
398 @interface
GPBStringInt64Dictionary () <GPBDictionaryInternalsProtocol
> {
400 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
404 @interface
GPBStringBoolDictionary () <GPBDictionaryInternalsProtocol
> {
406 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
410 @interface
GPBStringFloatDictionary () <GPBDictionaryInternalsProtocol
> {
412 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
416 @interface
GPBStringDoubleDictionary () <GPBDictionaryInternalsProtocol
> {
418 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
422 @interface
GPBStringEnumDictionary () <GPBDictionaryInternalsProtocol
> {
424 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
426 - (NSData
*)serializedDataForUnknownValue
:(int32_t)value
427 forKey
:(GPBGenericValue
*)key
428 keyDataType
:(GPBDataType
)keyDataType
;
431 //%PDDM-EXPAND-END (6 expansions)
435 #pragma mark - NSDictionary Subclass
437 @interface GPBAutocreatedDictionary
: NSMutableDictionary
{
439 GPB_UNSAFE_UNRETAINED GPBMessage
*_autocreator
;
443 #pragma mark - Helpers
447 // Helper to compute size when an NSDictionary is used for the map instead
449 size_t GPBDictionaryComputeSizeInternalHelper(NSDictionary
*dict
, GPBFieldDescriptor
*field
);
451 // Helper to write out when an NSDictionary is used for the map instead
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
);