1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc.  All rights reserved.
3 // https://developers.google.com/protocol-buffers/
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 //     * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //     * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
14 // distribution.
15 //     * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 #import <Foundation/Foundation.h>
32 
33 #import "GPBDictionary.h"
34 
35 @class GPBCodedInputStream;
36 @class GPBCodedOutputStream;
37 @class GPBExtensionRegistry;
38 @class GPBFieldDescriptor;
39 
40 @protocol GPBDictionaryInternalsProtocol
41 - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field;
42 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
43                          asField:(GPBFieldDescriptor *)field;
44 - (void)setGPBGenericValue:(GPBGenericValue *)value
45      forGPBGenericValueKey:(GPBGenericValue *)key;
46 - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block;
47 @end
48 
49 //%PDDM-DEFINE DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(KEY_NAME)
50 //%DICTIONARY_POD_PRIV_INTERFACES_FOR_KEY(KEY_NAME)
51 //%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, Object, Object)
52 //%PDDM-DEFINE DICTIONARY_POD_PRIV_INTERFACES_FOR_KEY(KEY_NAME)
53 //%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, UInt32, Basic)
54 //%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, Int32, Basic)
55 //%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, UInt64, Basic)
56 //%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, Int64, Basic)
57 //%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, Bool, Basic)
58 //%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, Float, Basic)
59 //%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, Double, Basic)
60 //%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, Enum, Enum)
61 
62 //%PDDM-DEFINE DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, VALUE_NAME, HELPER)
63 //%@interface GPB##KEY_NAME##VALUE_NAME##Dictionary () <GPBDictionaryInternalsProtocol> {
64 //% @package
65 //%  GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
66 //%}
67 //%EXTRA_DICTIONARY_PRIVATE_INTERFACES_##HELPER()@end
68 //%
69 
70 //%PDDM-DEFINE EXTRA_DICTIONARY_PRIVATE_INTERFACES_Basic()
71 // Empty
72 //%PDDM-DEFINE EXTRA_DICTIONARY_PRIVATE_INTERFACES_Object()
73 //%- (BOOL)isInitialized;
74 //%- (instancetype)deepCopyWithZone:(NSZone *)zone
75 //%    __attribute__((ns_returns_retained));
76 //%
77 //%PDDM-DEFINE EXTRA_DICTIONARY_PRIVATE_INTERFACES_Enum()
78 //%- (NSData *)serializedDataForUnknownValue:(int32_t)value
79 //%                                   forKey:(GPBGenericValue *)key
80 //%                              keyDataType:(GPBDataType)keyDataType;
81 //%
82 
83 //%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(UInt32)
84 // This block of code is generated, do not edit it directly.
85 
GPBUInt32UInt32Dictionary()86 @interface GPBUInt32UInt32Dictionary () <GPBDictionaryInternalsProtocol> {
87  @package
88   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
89 }
90 @end
91 
GPBUInt32Int32Dictionary()92 @interface GPBUInt32Int32Dictionary () <GPBDictionaryInternalsProtocol> {
93  @package
94   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
95 }
96 @end
97 
GPBUInt32UInt64Dictionary()98 @interface GPBUInt32UInt64Dictionary () <GPBDictionaryInternalsProtocol> {
99  @package
100   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
101 }
102 @end
103 
GPBUInt32Int64Dictionary()104 @interface GPBUInt32Int64Dictionary () <GPBDictionaryInternalsProtocol> {
105  @package
106   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
107 }
108 @end
109 
GPBUInt32BoolDictionary()110 @interface GPBUInt32BoolDictionary () <GPBDictionaryInternalsProtocol> {
111  @package
112   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
113 }
114 @end
115 
GPBUInt32FloatDictionary()116 @interface GPBUInt32FloatDictionary () <GPBDictionaryInternalsProtocol> {
117  @package
118   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
119 }
120 @end
121 
GPBUInt32DoubleDictionary()122 @interface GPBUInt32DoubleDictionary () <GPBDictionaryInternalsProtocol> {
123  @package
124   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
125 }
126 @end
127 
GPBUInt32EnumDictionary()128 @interface GPBUInt32EnumDictionary () <GPBDictionaryInternalsProtocol> {
129  @package
130   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
131 }
132 - (NSData *)serializedDataForUnknownValue:(int32_t)value
133                                    forKey:(GPBGenericValue *)key
134                               keyDataType:(GPBDataType)keyDataType;
135 @end
136 
GPBUInt32ObjectDictionary()137 @interface GPBUInt32ObjectDictionary () <GPBDictionaryInternalsProtocol> {
138  @package
139   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
140 }
141 - (BOOL)isInitialized;
142 - (instancetype)deepCopyWithZone:(NSZone *)zone
143     __attribute__((ns_returns_retained));
144 @end
145 
146 //%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(Int32)
147 // This block of code is generated, do not edit it directly.
148 
GPBInt32UInt32Dictionary()149 @interface GPBInt32UInt32Dictionary () <GPBDictionaryInternalsProtocol> {
150  @package
151   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
152 }
153 @end
154 
GPBInt32Int32Dictionary()155 @interface GPBInt32Int32Dictionary () <GPBDictionaryInternalsProtocol> {
156  @package
157   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
158 }
159 @end
160 
GPBInt32UInt64Dictionary()161 @interface GPBInt32UInt64Dictionary () <GPBDictionaryInternalsProtocol> {
162  @package
163   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
164 }
165 @end
166 
GPBInt32Int64Dictionary()167 @interface GPBInt32Int64Dictionary () <GPBDictionaryInternalsProtocol> {
168  @package
169   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
170 }
171 @end
172 
GPBInt32BoolDictionary()173 @interface GPBInt32BoolDictionary () <GPBDictionaryInternalsProtocol> {
174  @package
175   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
176 }
177 @end
178 
GPBInt32FloatDictionary()179 @interface GPBInt32FloatDictionary () <GPBDictionaryInternalsProtocol> {
180  @package
181   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
182 }
183 @end
184 
GPBInt32DoubleDictionary()185 @interface GPBInt32DoubleDictionary () <GPBDictionaryInternalsProtocol> {
186  @package
187   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
188 }
189 @end
190 
GPBInt32EnumDictionary()191 @interface GPBInt32EnumDictionary () <GPBDictionaryInternalsProtocol> {
192  @package
193   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
194 }
195 - (NSData *)serializedDataForUnknownValue:(int32_t)value
196                                    forKey:(GPBGenericValue *)key
197                               keyDataType:(GPBDataType)keyDataType;
198 @end
199 
GPBInt32ObjectDictionary()200 @interface GPBInt32ObjectDictionary () <GPBDictionaryInternalsProtocol> {
201  @package
202   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
203 }
204 - (BOOL)isInitialized;
205 - (instancetype)deepCopyWithZone:(NSZone *)zone
206     __attribute__((ns_returns_retained));
207 @end
208 
209 //%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(UInt64)
210 // This block of code is generated, do not edit it directly.
211 
GPBUInt64UInt32Dictionary()212 @interface GPBUInt64UInt32Dictionary () <GPBDictionaryInternalsProtocol> {
213  @package
214   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
215 }
216 @end
217 
GPBUInt64Int32Dictionary()218 @interface GPBUInt64Int32Dictionary () <GPBDictionaryInternalsProtocol> {
219  @package
220   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
221 }
222 @end
223 
GPBUInt64UInt64Dictionary()224 @interface GPBUInt64UInt64Dictionary () <GPBDictionaryInternalsProtocol> {
225  @package
226   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
227 }
228 @end
229 
GPBUInt64Int64Dictionary()230 @interface GPBUInt64Int64Dictionary () <GPBDictionaryInternalsProtocol> {
231  @package
232   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
233 }
234 @end
235 
GPBUInt64BoolDictionary()236 @interface GPBUInt64BoolDictionary () <GPBDictionaryInternalsProtocol> {
237  @package
238   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
239 }
240 @end
241 
GPBUInt64FloatDictionary()242 @interface GPBUInt64FloatDictionary () <GPBDictionaryInternalsProtocol> {
243  @package
244   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
245 }
246 @end
247 
GPBUInt64DoubleDictionary()248 @interface GPBUInt64DoubleDictionary () <GPBDictionaryInternalsProtocol> {
249  @package
250   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
251 }
252 @end
253 
GPBUInt64EnumDictionary()254 @interface GPBUInt64EnumDictionary () <GPBDictionaryInternalsProtocol> {
255  @package
256   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
257 }
258 - (NSData *)serializedDataForUnknownValue:(int32_t)value
259                                    forKey:(GPBGenericValue *)key
260                               keyDataType:(GPBDataType)keyDataType;
261 @end
262 
GPBUInt64ObjectDictionary()263 @interface GPBUInt64ObjectDictionary () <GPBDictionaryInternalsProtocol> {
264  @package
265   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
266 }
267 - (BOOL)isInitialized;
268 - (instancetype)deepCopyWithZone:(NSZone *)zone
269     __attribute__((ns_returns_retained));
270 @end
271 
272 //%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(Int64)
273 // This block of code is generated, do not edit it directly.
274 
GPBInt64UInt32Dictionary()275 @interface GPBInt64UInt32Dictionary () <GPBDictionaryInternalsProtocol> {
276  @package
277   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
278 }
279 @end
280 
GPBInt64Int32Dictionary()281 @interface GPBInt64Int32Dictionary () <GPBDictionaryInternalsProtocol> {
282  @package
283   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
284 }
285 @end
286 
GPBInt64UInt64Dictionary()287 @interface GPBInt64UInt64Dictionary () <GPBDictionaryInternalsProtocol> {
288  @package
289   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
290 }
291 @end
292 
GPBInt64Int64Dictionary()293 @interface GPBInt64Int64Dictionary () <GPBDictionaryInternalsProtocol> {
294  @package
295   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
296 }
297 @end
298 
GPBInt64BoolDictionary()299 @interface GPBInt64BoolDictionary () <GPBDictionaryInternalsProtocol> {
300  @package
301   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
302 }
303 @end
304 
GPBInt64FloatDictionary()305 @interface GPBInt64FloatDictionary () <GPBDictionaryInternalsProtocol> {
306  @package
307   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
308 }
309 @end
310 
GPBInt64DoubleDictionary()311 @interface GPBInt64DoubleDictionary () <GPBDictionaryInternalsProtocol> {
312  @package
313   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
314 }
315 @end
316 
GPBInt64EnumDictionary()317 @interface GPBInt64EnumDictionary () <GPBDictionaryInternalsProtocol> {
318  @package
319   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
320 }
321 - (NSData *)serializedDataForUnknownValue:(int32_t)value
322                                    forKey:(GPBGenericValue *)key
323                               keyDataType:(GPBDataType)keyDataType;
324 @end
325 
GPBInt64ObjectDictionary()326 @interface GPBInt64ObjectDictionary () <GPBDictionaryInternalsProtocol> {
327  @package
328   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
329 }
330 - (BOOL)isInitialized;
331 - (instancetype)deepCopyWithZone:(NSZone *)zone
332     __attribute__((ns_returns_retained));
333 @end
334 
335 //%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(Bool)
336 // This block of code is generated, do not edit it directly.
337 
GPBBoolUInt32Dictionary()338 @interface GPBBoolUInt32Dictionary () <GPBDictionaryInternalsProtocol> {
339  @package
340   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
341 }
342 @end
343 
GPBBoolInt32Dictionary()344 @interface GPBBoolInt32Dictionary () <GPBDictionaryInternalsProtocol> {
345  @package
346   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
347 }
348 @end
349 
GPBBoolUInt64Dictionary()350 @interface GPBBoolUInt64Dictionary () <GPBDictionaryInternalsProtocol> {
351  @package
352   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
353 }
354 @end
355 
GPBBoolInt64Dictionary()356 @interface GPBBoolInt64Dictionary () <GPBDictionaryInternalsProtocol> {
357  @package
358   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
359 }
360 @end
361 
GPBBoolBoolDictionary()362 @interface GPBBoolBoolDictionary () <GPBDictionaryInternalsProtocol> {
363  @package
364   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
365 }
366 @end
367 
GPBBoolFloatDictionary()368 @interface GPBBoolFloatDictionary () <GPBDictionaryInternalsProtocol> {
369  @package
370   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
371 }
372 @end
373 
GPBBoolDoubleDictionary()374 @interface GPBBoolDoubleDictionary () <GPBDictionaryInternalsProtocol> {
375  @package
376   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
377 }
378 @end
379 
GPBBoolEnumDictionary()380 @interface GPBBoolEnumDictionary () <GPBDictionaryInternalsProtocol> {
381  @package
382   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
383 }
384 - (NSData *)serializedDataForUnknownValue:(int32_t)value
385                                    forKey:(GPBGenericValue *)key
386                               keyDataType:(GPBDataType)keyDataType;
387 @end
388 
GPBBoolObjectDictionary()389 @interface GPBBoolObjectDictionary () <GPBDictionaryInternalsProtocol> {
390  @package
391   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
392 }
393 - (BOOL)isInitialized;
394 - (instancetype)deepCopyWithZone:(NSZone *)zone
395     __attribute__((ns_returns_retained));
396 @end
397 
398 //%PDDM-EXPAND DICTIONARY_POD_PRIV_INTERFACES_FOR_KEY(String)
399 // This block of code is generated, do not edit it directly.
400 
GPBStringUInt32Dictionary()401 @interface GPBStringUInt32Dictionary () <GPBDictionaryInternalsProtocol> {
402  @package
403   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
404 }
405 @end
406 
GPBStringInt32Dictionary()407 @interface GPBStringInt32Dictionary () <GPBDictionaryInternalsProtocol> {
408  @package
409   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
410 }
411 @end
412 
GPBStringUInt64Dictionary()413 @interface GPBStringUInt64Dictionary () <GPBDictionaryInternalsProtocol> {
414  @package
415   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
416 }
417 @end
418 
GPBStringInt64Dictionary()419 @interface GPBStringInt64Dictionary () <GPBDictionaryInternalsProtocol> {
420  @package
421   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
422 }
423 @end
424 
GPBStringBoolDictionary()425 @interface GPBStringBoolDictionary () <GPBDictionaryInternalsProtocol> {
426  @package
427   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
428 }
429 @end
430 
GPBStringFloatDictionary()431 @interface GPBStringFloatDictionary () <GPBDictionaryInternalsProtocol> {
432  @package
433   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
434 }
435 @end
436 
GPBStringDoubleDictionary()437 @interface GPBStringDoubleDictionary () <GPBDictionaryInternalsProtocol> {
438  @package
439   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
440 }
441 @end
442 
GPBStringEnumDictionary()443 @interface GPBStringEnumDictionary () <GPBDictionaryInternalsProtocol> {
444  @package
445   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
446 }
447 - (NSData *)serializedDataForUnknownValue:(int32_t)value
448                                    forKey:(GPBGenericValue *)key
449                               keyDataType:(GPBDataType)keyDataType;
450 @end
451 
452 //%PDDM-EXPAND-END (6 expansions)
453 
454 #pragma mark - NSDictionary Subclass
455 
456 @interface GPBAutocreatedDictionary : NSMutableDictionary {
457   @package
458   GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
459 }
460 @end
461 
462 #pragma mark - Helpers
463 
464 CF_EXTERN_C_BEGIN
465 
466 // Helper to compute size when an NSDictionary is used for the map instead
467 // of a custom type.
468 size_t GPBDictionaryComputeSizeInternalHelper(NSDictionary *dict,
469                                               GPBFieldDescriptor *field);
470 
471 // Helper to write out when an NSDictionary is used for the map instead
472 // of a custom type.
473 void GPBDictionaryWriteToStreamInternalHelper(
474     GPBCodedOutputStream *outputStream, NSDictionary *dict,
475     GPBFieldDescriptor *field);
476 
477 // Helper to check message initialization when an NSDictionary is used for
478 // the map instead of a custom type.
479 BOOL GPBDictionaryIsInitializedInternalHelper(NSDictionary *dict,
480                                               GPBFieldDescriptor *field);
481 
482 // Helper to read a map instead.
483 void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream,
484                             GPBExtensionRegistry *registry,
485                             GPBFieldDescriptor *field,
486                             GPBMessage *parentMessage);
487 
488 CF_EXTERN_C_END
489