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