• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
7 
8 #import <Foundation/Foundation.h>
9 
10 #import "GPBDictionary.h"
11 
12 #import "GPBCodedInputStream.h"
13 #import "GPBCodedOutputStream.h"
14 #import "GPBDescriptor.h"
15 #import "GPBExtensionRegistry.h"
16 
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
24 
25 // Disable clang-format for the macros.
26 // clang-format off
27 
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)
40 
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 //%
48 
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 //%
61 
62 //%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(UInt32)
63 // This block of code is generated, do not edit it directly.
64 
GPBUInt32UInt32Dictionary()65 @interface GPBUInt32UInt32Dictionary () <GPBDictionaryInternalsProtocol> {
66  @package
67   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
68 }
69 @end
70 
GPBUInt32Int32Dictionary()71 @interface GPBUInt32Int32Dictionary () <GPBDictionaryInternalsProtocol> {
72  @package
73   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
74 }
75 @end
76 
GPBUInt32UInt64Dictionary()77 @interface GPBUInt32UInt64Dictionary () <GPBDictionaryInternalsProtocol> {
78  @package
79   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
80 }
81 @end
82 
GPBUInt32Int64Dictionary()83 @interface GPBUInt32Int64Dictionary () <GPBDictionaryInternalsProtocol> {
84  @package
85   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
86 }
87 @end
88 
GPBUInt32BoolDictionary()89 @interface GPBUInt32BoolDictionary () <GPBDictionaryInternalsProtocol> {
90  @package
91   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
92 }
93 @end
94 
GPBUInt32FloatDictionary()95 @interface GPBUInt32FloatDictionary () <GPBDictionaryInternalsProtocol> {
96  @package
97   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
98 }
99 @end
100 
GPBUInt32DoubleDictionary()101 @interface GPBUInt32DoubleDictionary () <GPBDictionaryInternalsProtocol> {
102  @package
103   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
104 }
105 @end
106 
GPBUInt32EnumDictionary()107 @interface GPBUInt32EnumDictionary () <GPBDictionaryInternalsProtocol> {
108  @package
109   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
110 }
111 - (NSData *)serializedDataForUnknownValue:(int32_t)value
112                                    forKey:(GPBGenericValue *)key
113                               keyDataType:(GPBDataType)keyDataType;
114 @end
115 
GPBUInt32ObjectDictionary()116 @interface GPBUInt32ObjectDictionary () <GPBDictionaryInternalsProtocol> {
117  @package
118   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
119 }
120 - (BOOL)isInitialized;
121 - (instancetype)deepCopyWithZone:(NSZone *)zone
122     __attribute__((ns_returns_retained));
123 @end
124 
125 //%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(Int32)
126 // This block of code is generated, do not edit it directly.
127 
GPBInt32UInt32Dictionary()128 @interface GPBInt32UInt32Dictionary () <GPBDictionaryInternalsProtocol> {
129  @package
130   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
131 }
132 @end
133 
GPBInt32Int32Dictionary()134 @interface GPBInt32Int32Dictionary () <GPBDictionaryInternalsProtocol> {
135  @package
136   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
137 }
138 @end
139 
GPBInt32UInt64Dictionary()140 @interface GPBInt32UInt64Dictionary () <GPBDictionaryInternalsProtocol> {
141  @package
142   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
143 }
144 @end
145 
GPBInt32Int64Dictionary()146 @interface GPBInt32Int64Dictionary () <GPBDictionaryInternalsProtocol> {
147  @package
148   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
149 }
150 @end
151 
GPBInt32BoolDictionary()152 @interface GPBInt32BoolDictionary () <GPBDictionaryInternalsProtocol> {
153  @package
154   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
155 }
156 @end
157 
GPBInt32FloatDictionary()158 @interface GPBInt32FloatDictionary () <GPBDictionaryInternalsProtocol> {
159  @package
160   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
161 }
162 @end
163 
GPBInt32DoubleDictionary()164 @interface GPBInt32DoubleDictionary () <GPBDictionaryInternalsProtocol> {
165  @package
166   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
167 }
168 @end
169 
GPBInt32EnumDictionary()170 @interface GPBInt32EnumDictionary () <GPBDictionaryInternalsProtocol> {
171  @package
172   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
173 }
174 - (NSData *)serializedDataForUnknownValue:(int32_t)value
175                                    forKey:(GPBGenericValue *)key
176                               keyDataType:(GPBDataType)keyDataType;
177 @end
178 
GPBInt32ObjectDictionary()179 @interface GPBInt32ObjectDictionary () <GPBDictionaryInternalsProtocol> {
180  @package
181   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
182 }
183 - (BOOL)isInitialized;
184 - (instancetype)deepCopyWithZone:(NSZone *)zone
185     __attribute__((ns_returns_retained));
186 @end
187 
188 //%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(UInt64)
189 // This block of code is generated, do not edit it directly.
190 
GPBUInt64UInt32Dictionary()191 @interface GPBUInt64UInt32Dictionary () <GPBDictionaryInternalsProtocol> {
192  @package
193   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
194 }
195 @end
196 
GPBUInt64Int32Dictionary()197 @interface GPBUInt64Int32Dictionary () <GPBDictionaryInternalsProtocol> {
198  @package
199   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
200 }
201 @end
202 
GPBUInt64UInt64Dictionary()203 @interface GPBUInt64UInt64Dictionary () <GPBDictionaryInternalsProtocol> {
204  @package
205   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
206 }
207 @end
208 
GPBUInt64Int64Dictionary()209 @interface GPBUInt64Int64Dictionary () <GPBDictionaryInternalsProtocol> {
210  @package
211   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
212 }
213 @end
214 
GPBUInt64BoolDictionary()215 @interface GPBUInt64BoolDictionary () <GPBDictionaryInternalsProtocol> {
216  @package
217   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
218 }
219 @end
220 
GPBUInt64FloatDictionary()221 @interface GPBUInt64FloatDictionary () <GPBDictionaryInternalsProtocol> {
222  @package
223   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
224 }
225 @end
226 
GPBUInt64DoubleDictionary()227 @interface GPBUInt64DoubleDictionary () <GPBDictionaryInternalsProtocol> {
228  @package
229   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
230 }
231 @end
232 
GPBUInt64EnumDictionary()233 @interface GPBUInt64EnumDictionary () <GPBDictionaryInternalsProtocol> {
234  @package
235   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
236 }
237 - (NSData *)serializedDataForUnknownValue:(int32_t)value
238                                    forKey:(GPBGenericValue *)key
239                               keyDataType:(GPBDataType)keyDataType;
240 @end
241 
GPBUInt64ObjectDictionary()242 @interface GPBUInt64ObjectDictionary () <GPBDictionaryInternalsProtocol> {
243  @package
244   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
245 }
246 - (BOOL)isInitialized;
247 - (instancetype)deepCopyWithZone:(NSZone *)zone
248     __attribute__((ns_returns_retained));
249 @end
250 
251 //%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(Int64)
252 // This block of code is generated, do not edit it directly.
253 
GPBInt64UInt32Dictionary()254 @interface GPBInt64UInt32Dictionary () <GPBDictionaryInternalsProtocol> {
255  @package
256   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
257 }
258 @end
259 
GPBInt64Int32Dictionary()260 @interface GPBInt64Int32Dictionary () <GPBDictionaryInternalsProtocol> {
261  @package
262   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
263 }
264 @end
265 
GPBInt64UInt64Dictionary()266 @interface GPBInt64UInt64Dictionary () <GPBDictionaryInternalsProtocol> {
267  @package
268   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
269 }
270 @end
271 
GPBInt64Int64Dictionary()272 @interface GPBInt64Int64Dictionary () <GPBDictionaryInternalsProtocol> {
273  @package
274   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
275 }
276 @end
277 
GPBInt64BoolDictionary()278 @interface GPBInt64BoolDictionary () <GPBDictionaryInternalsProtocol> {
279  @package
280   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
281 }
282 @end
283 
GPBInt64FloatDictionary()284 @interface GPBInt64FloatDictionary () <GPBDictionaryInternalsProtocol> {
285  @package
286   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
287 }
288 @end
289 
GPBInt64DoubleDictionary()290 @interface GPBInt64DoubleDictionary () <GPBDictionaryInternalsProtocol> {
291  @package
292   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
293 }
294 @end
295 
GPBInt64EnumDictionary()296 @interface GPBInt64EnumDictionary () <GPBDictionaryInternalsProtocol> {
297  @package
298   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
299 }
300 - (NSData *)serializedDataForUnknownValue:(int32_t)value
301                                    forKey:(GPBGenericValue *)key
302                               keyDataType:(GPBDataType)keyDataType;
303 @end
304 
GPBInt64ObjectDictionary()305 @interface GPBInt64ObjectDictionary () <GPBDictionaryInternalsProtocol> {
306  @package
307   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
308 }
309 - (BOOL)isInitialized;
310 - (instancetype)deepCopyWithZone:(NSZone *)zone
311     __attribute__((ns_returns_retained));
312 @end
313 
314 //%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(Bool)
315 // This block of code is generated, do not edit it directly.
316 
GPBBoolUInt32Dictionary()317 @interface GPBBoolUInt32Dictionary () <GPBDictionaryInternalsProtocol> {
318  @package
319   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
320 }
321 @end
322 
GPBBoolInt32Dictionary()323 @interface GPBBoolInt32Dictionary () <GPBDictionaryInternalsProtocol> {
324  @package
325   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
326 }
327 @end
328 
GPBBoolUInt64Dictionary()329 @interface GPBBoolUInt64Dictionary () <GPBDictionaryInternalsProtocol> {
330  @package
331   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
332 }
333 @end
334 
GPBBoolInt64Dictionary()335 @interface GPBBoolInt64Dictionary () <GPBDictionaryInternalsProtocol> {
336  @package
337   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
338 }
339 @end
340 
GPBBoolBoolDictionary()341 @interface GPBBoolBoolDictionary () <GPBDictionaryInternalsProtocol> {
342  @package
343   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
344 }
345 @end
346 
GPBBoolFloatDictionary()347 @interface GPBBoolFloatDictionary () <GPBDictionaryInternalsProtocol> {
348  @package
349   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
350 }
351 @end
352 
GPBBoolDoubleDictionary()353 @interface GPBBoolDoubleDictionary () <GPBDictionaryInternalsProtocol> {
354  @package
355   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
356 }
357 @end
358 
GPBBoolEnumDictionary()359 @interface GPBBoolEnumDictionary () <GPBDictionaryInternalsProtocol> {
360  @package
361   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
362 }
363 - (NSData *)serializedDataForUnknownValue:(int32_t)value
364                                    forKey:(GPBGenericValue *)key
365                               keyDataType:(GPBDataType)keyDataType;
366 @end
367 
GPBBoolObjectDictionary()368 @interface GPBBoolObjectDictionary () <GPBDictionaryInternalsProtocol> {
369  @package
370   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
371 }
372 - (BOOL)isInitialized;
373 - (instancetype)deepCopyWithZone:(NSZone *)zone
374     __attribute__((ns_returns_retained));
375 @end
376 
377 //%PDDM-EXPAND DICTIONARY_POD_PRIV_INTERFACES_FOR_KEY(String)
378 // This block of code is generated, do not edit it directly.
379 
GPBStringUInt32Dictionary()380 @interface GPBStringUInt32Dictionary () <GPBDictionaryInternalsProtocol> {
381  @package
382   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
383 }
384 @end
385 
GPBStringInt32Dictionary()386 @interface GPBStringInt32Dictionary () <GPBDictionaryInternalsProtocol> {
387  @package
388   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
389 }
390 @end
391 
GPBStringUInt64Dictionary()392 @interface GPBStringUInt64Dictionary () <GPBDictionaryInternalsProtocol> {
393  @package
394   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
395 }
396 @end
397 
GPBStringInt64Dictionary()398 @interface GPBStringInt64Dictionary () <GPBDictionaryInternalsProtocol> {
399  @package
400   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
401 }
402 @end
403 
GPBStringBoolDictionary()404 @interface GPBStringBoolDictionary () <GPBDictionaryInternalsProtocol> {
405  @package
406   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
407 }
408 @end
409 
GPBStringFloatDictionary()410 @interface GPBStringFloatDictionary () <GPBDictionaryInternalsProtocol> {
411  @package
412   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
413 }
414 @end
415 
GPBStringDoubleDictionary()416 @interface GPBStringDoubleDictionary () <GPBDictionaryInternalsProtocol> {
417  @package
418   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
419 }
420 @end
421 
GPBStringEnumDictionary()422 @interface GPBStringEnumDictionary () <GPBDictionaryInternalsProtocol> {
423  @package
424   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
425 }
426 - (NSData *)serializedDataForUnknownValue:(int32_t)value
427                                    forKey:(GPBGenericValue *)key
428                               keyDataType:(GPBDataType)keyDataType;
429 @end
430 
431 //%PDDM-EXPAND-END (6 expansions)
432 
433 // clang-format on
434 
435 #pragma mark - NSDictionary Subclass
436 
437 @interface GPBAutocreatedDictionary : NSMutableDictionary {
438  @package
439   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
440 }
441 @end
442 
443 #pragma mark - Helpers
444 
445 CF_EXTERN_C_BEGIN
446 
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);
450 
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);
455 
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);
459 
460 // Helper to read a map instead.
461 void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream,
462                             id<GPBExtensionRegistry> registry, GPBFieldDescriptor *field,
463                             GPBMessage *parentMessage);
464 
465 CF_EXTERN_C_END
466