1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
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
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.
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.
31 #import <Foundation/Foundation.h>
33 #import "GPBDictionary.h"
35 @class GPBCodedInputStream;
36 @class GPBCodedOutputStream;
37 @class GPBExtensionRegistry;
38 @class GPBFieldDescriptor;
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;
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)
62 //%PDDM-DEFINE DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, VALUE_NAME, HELPER)
63 //%@interface GPB##KEY_NAME##VALUE_NAME##Dictionary () <GPBDictionaryInternalsProtocol> {
65 //% GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
67 //%EXTRA_DICTIONARY_PRIVATE_INTERFACES_##HELPER()@end
70 //%PDDM-DEFINE EXTRA_DICTIONARY_PRIVATE_INTERFACES_Basic()
72 //%PDDM-DEFINE EXTRA_DICTIONARY_PRIVATE_INTERFACES_Object()
73 //%- (BOOL)isInitialized;
74 //%- (instancetype)deepCopyWithZone:(NSZone *)zone
75 //% __attribute__((ns_returns_retained));
77 //%PDDM-DEFINE EXTRA_DICTIONARY_PRIVATE_INTERFACES_Enum()
78 //%- (NSData *)serializedDataForUnknownValue:(int32_t)value
79 //% forKey:(GPBGenericValue *)key
80 //% keyDataType:(GPBDataType)keyDataType;
83 //%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(UInt32)
84 // This block of code is generated, do not edit it directly.
86 @interface GPBUInt32UInt32Dictionary () <GPBDictionaryInternalsProtocol> {
88 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
92 @interface GPBUInt32Int32Dictionary () <GPBDictionaryInternalsProtocol> {
94 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
98 @interface GPBUInt32UInt64Dictionary () <GPBDictionaryInternalsProtocol> {
100 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
104 @interface GPBUInt32Int64Dictionary () <GPBDictionaryInternalsProtocol> {
106 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
110 @interface GPBUInt32BoolDictionary () <GPBDictionaryInternalsProtocol> {
112 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
116 @interface GPBUInt32FloatDictionary () <GPBDictionaryInternalsProtocol> {
118 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
122 @interface GPBUInt32DoubleDictionary () <GPBDictionaryInternalsProtocol> {
124 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
128 @interface GPBUInt32EnumDictionary () <GPBDictionaryInternalsProtocol> {
130 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
132 - (NSData *)serializedDataForUnknownValue:(int32_t)value
133 forKey:(GPBGenericValue *)key
134 keyDataType:(GPBDataType)keyDataType;
137 @interface GPBUInt32ObjectDictionary () <GPBDictionaryInternalsProtocol> {
139 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
141 - (BOOL)isInitialized;
142 - (instancetype)deepCopyWithZone:(NSZone *)zone
143 __attribute__((ns_returns_retained));
146 //%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(Int32)
147 // This block of code is generated, do not edit it directly.
149 @interface GPBInt32UInt32Dictionary () <GPBDictionaryInternalsProtocol> {
151 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
155 @interface GPBInt32Int32Dictionary () <GPBDictionaryInternalsProtocol> {
157 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
161 @interface GPBInt32UInt64Dictionary () <GPBDictionaryInternalsProtocol> {
163 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
167 @interface GPBInt32Int64Dictionary () <GPBDictionaryInternalsProtocol> {
169 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
173 @interface GPBInt32BoolDictionary () <GPBDictionaryInternalsProtocol> {
175 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
179 @interface GPBInt32FloatDictionary () <GPBDictionaryInternalsProtocol> {
181 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
185 @interface GPBInt32DoubleDictionary () <GPBDictionaryInternalsProtocol> {
187 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
191 @interface GPBInt32EnumDictionary () <GPBDictionaryInternalsProtocol> {
193 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
195 - (NSData *)serializedDataForUnknownValue:(int32_t)value
196 forKey:(GPBGenericValue *)key
197 keyDataType:(GPBDataType)keyDataType;
200 @interface GPBInt32ObjectDictionary () <GPBDictionaryInternalsProtocol> {
202 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
204 - (BOOL)isInitialized;
205 - (instancetype)deepCopyWithZone:(NSZone *)zone
206 __attribute__((ns_returns_retained));
209 //%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(UInt64)
210 // This block of code is generated, do not edit it directly.
212 @interface GPBUInt64UInt32Dictionary () <GPBDictionaryInternalsProtocol> {
214 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
218 @interface GPBUInt64Int32Dictionary () <GPBDictionaryInternalsProtocol> {
220 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
224 @interface GPBUInt64UInt64Dictionary () <GPBDictionaryInternalsProtocol> {
226 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
230 @interface GPBUInt64Int64Dictionary () <GPBDictionaryInternalsProtocol> {
232 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
236 @interface GPBUInt64BoolDictionary () <GPBDictionaryInternalsProtocol> {
238 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
242 @interface GPBUInt64FloatDictionary () <GPBDictionaryInternalsProtocol> {
244 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
248 @interface GPBUInt64DoubleDictionary () <GPBDictionaryInternalsProtocol> {
250 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
254 @interface GPBUInt64EnumDictionary () <GPBDictionaryInternalsProtocol> {
256 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
258 - (NSData *)serializedDataForUnknownValue:(int32_t)value
259 forKey:(GPBGenericValue *)key
260 keyDataType:(GPBDataType)keyDataType;
263 @interface GPBUInt64ObjectDictionary () <GPBDictionaryInternalsProtocol> {
265 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
267 - (BOOL)isInitialized;
268 - (instancetype)deepCopyWithZone:(NSZone *)zone
269 __attribute__((ns_returns_retained));
272 //%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(Int64)
273 // This block of code is generated, do not edit it directly.
275 @interface GPBInt64UInt32Dictionary () <GPBDictionaryInternalsProtocol> {
277 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
281 @interface GPBInt64Int32Dictionary () <GPBDictionaryInternalsProtocol> {
283 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
287 @interface GPBInt64UInt64Dictionary () <GPBDictionaryInternalsProtocol> {
289 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
293 @interface GPBInt64Int64Dictionary () <GPBDictionaryInternalsProtocol> {
295 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
299 @interface GPBInt64BoolDictionary () <GPBDictionaryInternalsProtocol> {
301 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
305 @interface GPBInt64FloatDictionary () <GPBDictionaryInternalsProtocol> {
307 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
311 @interface GPBInt64DoubleDictionary () <GPBDictionaryInternalsProtocol> {
313 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
317 @interface GPBInt64EnumDictionary () <GPBDictionaryInternalsProtocol> {
319 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
321 - (NSData *)serializedDataForUnknownValue:(int32_t)value
322 forKey:(GPBGenericValue *)key
323 keyDataType:(GPBDataType)keyDataType;
326 @interface GPBInt64ObjectDictionary () <GPBDictionaryInternalsProtocol> {
328 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
330 - (BOOL)isInitialized;
331 - (instancetype)deepCopyWithZone:(NSZone *)zone
332 __attribute__((ns_returns_retained));
335 //%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(Bool)
336 // This block of code is generated, do not edit it directly.
338 @interface GPBBoolUInt32Dictionary () <GPBDictionaryInternalsProtocol> {
340 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
344 @interface GPBBoolInt32Dictionary () <GPBDictionaryInternalsProtocol> {
346 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
350 @interface GPBBoolUInt64Dictionary () <GPBDictionaryInternalsProtocol> {
352 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
356 @interface GPBBoolInt64Dictionary () <GPBDictionaryInternalsProtocol> {
358 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
362 @interface GPBBoolBoolDictionary () <GPBDictionaryInternalsProtocol> {
364 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
368 @interface GPBBoolFloatDictionary () <GPBDictionaryInternalsProtocol> {
370 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
374 @interface GPBBoolDoubleDictionary () <GPBDictionaryInternalsProtocol> {
376 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
380 @interface GPBBoolEnumDictionary () <GPBDictionaryInternalsProtocol> {
382 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
384 - (NSData *)serializedDataForUnknownValue:(int32_t)value
385 forKey:(GPBGenericValue *)key
386 keyDataType:(GPBDataType)keyDataType;
389 @interface GPBBoolObjectDictionary () <GPBDictionaryInternalsProtocol> {
391 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
393 - (BOOL)isInitialized;
394 - (instancetype)deepCopyWithZone:(NSZone *)zone
395 __attribute__((ns_returns_retained));
398 //%PDDM-EXPAND DICTIONARY_POD_PRIV_INTERFACES_FOR_KEY(String)
399 // This block of code is generated, do not edit it directly.
401 @interface GPBStringUInt32Dictionary () <GPBDictionaryInternalsProtocol> {
403 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
407 @interface GPBStringInt32Dictionary () <GPBDictionaryInternalsProtocol> {
409 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
413 @interface GPBStringUInt64Dictionary () <GPBDictionaryInternalsProtocol> {
415 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
419 @interface GPBStringInt64Dictionary () <GPBDictionaryInternalsProtocol> {
421 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
425 @interface GPBStringBoolDictionary () <GPBDictionaryInternalsProtocol> {
427 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
431 @interface GPBStringFloatDictionary () <GPBDictionaryInternalsProtocol> {
433 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
437 @interface GPBStringDoubleDictionary () <GPBDictionaryInternalsProtocol> {
439 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
443 @interface GPBStringEnumDictionary () <GPBDictionaryInternalsProtocol> {
445 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
447 - (NSData *)serializedDataForUnknownValue:(int32_t)value
448 forKey:(GPBGenericValue *)key
449 keyDataType:(GPBDataType)keyDataType;
452 //%PDDM-EXPAND-END (6 expansions)
454 #pragma mark - NSDictionary Subclass
456 @interface GPBAutocreatedDictionary : NSMutableDictionary {
458 GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
462 #pragma mark - Helpers
466 // Helper to compute size when an NSDictionary is used for the map instead
468 size_t GPBDictionaryComputeSizeInternalHelper(NSDictionary *dict,
469 GPBFieldDescriptor *field);
471 // Helper to write out when an NSDictionary is used for the map instead
473 void GPBDictionaryWriteToStreamInternalHelper(
474 GPBCodedOutputStream *outputStream, NSDictionary *dict,
475 GPBFieldDescriptor *field);
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);
482 // Helper to read a map instead.
483 void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream,
484 GPBExtensionRegistry *registry,
485 GPBFieldDescriptor *field,
486 GPBMessage *parentMessage);