GPBDictionary_PackagePrivate.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  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. #import <Foundation/Foundation.h>
  31. #import "GPBDictionary.h"
  32. @class GPBCodedInputStream;
  33. @class GPBCodedOutputStream;
  34. @class GPBExtensionRegistry;
  35. @class GPBFieldDescriptor;
  36. @protocol GPBDictionaryInternalsProtocol
  37. - (size_t)computeSerializedSizeAsField:(GPBFieldDescriptor *)field;
  38. - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)outputStream
  39. asField:(GPBFieldDescriptor *)field;
  40. - (void)setGPBGenericValue:(GPBGenericValue *)value
  41. forGPBGenericValueKey:(GPBGenericValue *)key;
  42. - (void)enumerateForTextFormat:(void (^)(id keyObj, id valueObj))block;
  43. @end
  44. //%PDDM-DEFINE DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(KEY_NAME)
  45. //%DICTIONARY_POD_PRIV_INTERFACES_FOR_KEY(KEY_NAME)
  46. //%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, Object, Object)
  47. //%PDDM-DEFINE DICTIONARY_POD_PRIV_INTERFACES_FOR_KEY(KEY_NAME)
  48. //%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, UInt32, Basic)
  49. //%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, Int32, Basic)
  50. //%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, UInt64, Basic)
  51. //%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, Int64, Basic)
  52. //%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, Bool, Basic)
  53. //%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, Float, Basic)
  54. //%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, Double, Basic)
  55. //%DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, Enum, Enum)
  56. //%PDDM-DEFINE DICTIONARY_PRIVATE_INTERFACES(KEY_NAME, VALUE_NAME, HELPER)
  57. //%@interface GPB##KEY_NAME##VALUE_NAME##Dictionary () <GPBDictionaryInternalsProtocol> {
  58. //% @package
  59. //% GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  60. //%}
  61. //%EXTRA_DICTIONARY_PRIVATE_INTERFACES_##HELPER()@end
  62. //%
  63. //%PDDM-DEFINE EXTRA_DICTIONARY_PRIVATE_INTERFACES_Basic()
  64. // Empty
  65. //%PDDM-DEFINE EXTRA_DICTIONARY_PRIVATE_INTERFACES_Object()
  66. //%- (BOOL)isInitialized;
  67. //%- (instancetype)deepCopyWithZone:(NSZone *)zone
  68. //% __attribute__((ns_returns_retained));
  69. //%
  70. //%PDDM-DEFINE EXTRA_DICTIONARY_PRIVATE_INTERFACES_Enum()
  71. //%- (NSData *)serializedDataForUnknownValue:(int32_t)value
  72. //% forKey:(GPBGenericValue *)key
  73. //% keyDataType:(GPBDataType)keyDataType;
  74. //%
  75. //%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(UInt32)
  76. // This block of code is generated, do not edit it directly.
  77. @interface GPBUInt32UInt32Dictionary () <GPBDictionaryInternalsProtocol> {
  78. @package
  79. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  80. }
  81. @end
  82. @interface GPBUInt32Int32Dictionary () <GPBDictionaryInternalsProtocol> {
  83. @package
  84. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  85. }
  86. @end
  87. @interface GPBUInt32UInt64Dictionary () <GPBDictionaryInternalsProtocol> {
  88. @package
  89. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  90. }
  91. @end
  92. @interface GPBUInt32Int64Dictionary () <GPBDictionaryInternalsProtocol> {
  93. @package
  94. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  95. }
  96. @end
  97. @interface GPBUInt32BoolDictionary () <GPBDictionaryInternalsProtocol> {
  98. @package
  99. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  100. }
  101. @end
  102. @interface GPBUInt32FloatDictionary () <GPBDictionaryInternalsProtocol> {
  103. @package
  104. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  105. }
  106. @end
  107. @interface GPBUInt32DoubleDictionary () <GPBDictionaryInternalsProtocol> {
  108. @package
  109. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  110. }
  111. @end
  112. @interface GPBUInt32EnumDictionary () <GPBDictionaryInternalsProtocol> {
  113. @package
  114. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  115. }
  116. - (NSData *)serializedDataForUnknownValue:(int32_t)value
  117. forKey:(GPBGenericValue *)key
  118. keyDataType:(GPBDataType)keyDataType;
  119. @end
  120. @interface GPBUInt32ObjectDictionary () <GPBDictionaryInternalsProtocol> {
  121. @package
  122. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  123. }
  124. - (BOOL)isInitialized;
  125. - (instancetype)deepCopyWithZone:(NSZone *)zone
  126. __attribute__((ns_returns_retained));
  127. @end
  128. //%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(Int32)
  129. // This block of code is generated, do not edit it directly.
  130. @interface GPBInt32UInt32Dictionary () <GPBDictionaryInternalsProtocol> {
  131. @package
  132. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  133. }
  134. @end
  135. @interface GPBInt32Int32Dictionary () <GPBDictionaryInternalsProtocol> {
  136. @package
  137. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  138. }
  139. @end
  140. @interface GPBInt32UInt64Dictionary () <GPBDictionaryInternalsProtocol> {
  141. @package
  142. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  143. }
  144. @end
  145. @interface GPBInt32Int64Dictionary () <GPBDictionaryInternalsProtocol> {
  146. @package
  147. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  148. }
  149. @end
  150. @interface GPBInt32BoolDictionary () <GPBDictionaryInternalsProtocol> {
  151. @package
  152. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  153. }
  154. @end
  155. @interface GPBInt32FloatDictionary () <GPBDictionaryInternalsProtocol> {
  156. @package
  157. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  158. }
  159. @end
  160. @interface GPBInt32DoubleDictionary () <GPBDictionaryInternalsProtocol> {
  161. @package
  162. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  163. }
  164. @end
  165. @interface GPBInt32EnumDictionary () <GPBDictionaryInternalsProtocol> {
  166. @package
  167. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  168. }
  169. - (NSData *)serializedDataForUnknownValue:(int32_t)value
  170. forKey:(GPBGenericValue *)key
  171. keyDataType:(GPBDataType)keyDataType;
  172. @end
  173. @interface GPBInt32ObjectDictionary () <GPBDictionaryInternalsProtocol> {
  174. @package
  175. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  176. }
  177. - (BOOL)isInitialized;
  178. - (instancetype)deepCopyWithZone:(NSZone *)zone
  179. __attribute__((ns_returns_retained));
  180. @end
  181. //%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(UInt64)
  182. // This block of code is generated, do not edit it directly.
  183. @interface GPBUInt64UInt32Dictionary () <GPBDictionaryInternalsProtocol> {
  184. @package
  185. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  186. }
  187. @end
  188. @interface GPBUInt64Int32Dictionary () <GPBDictionaryInternalsProtocol> {
  189. @package
  190. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  191. }
  192. @end
  193. @interface GPBUInt64UInt64Dictionary () <GPBDictionaryInternalsProtocol> {
  194. @package
  195. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  196. }
  197. @end
  198. @interface GPBUInt64Int64Dictionary () <GPBDictionaryInternalsProtocol> {
  199. @package
  200. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  201. }
  202. @end
  203. @interface GPBUInt64BoolDictionary () <GPBDictionaryInternalsProtocol> {
  204. @package
  205. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  206. }
  207. @end
  208. @interface GPBUInt64FloatDictionary () <GPBDictionaryInternalsProtocol> {
  209. @package
  210. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  211. }
  212. @end
  213. @interface GPBUInt64DoubleDictionary () <GPBDictionaryInternalsProtocol> {
  214. @package
  215. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  216. }
  217. @end
  218. @interface GPBUInt64EnumDictionary () <GPBDictionaryInternalsProtocol> {
  219. @package
  220. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  221. }
  222. - (NSData *)serializedDataForUnknownValue:(int32_t)value
  223. forKey:(GPBGenericValue *)key
  224. keyDataType:(GPBDataType)keyDataType;
  225. @end
  226. @interface GPBUInt64ObjectDictionary () <GPBDictionaryInternalsProtocol> {
  227. @package
  228. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  229. }
  230. - (BOOL)isInitialized;
  231. - (instancetype)deepCopyWithZone:(NSZone *)zone
  232. __attribute__((ns_returns_retained));
  233. @end
  234. //%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(Int64)
  235. // This block of code is generated, do not edit it directly.
  236. @interface GPBInt64UInt32Dictionary () <GPBDictionaryInternalsProtocol> {
  237. @package
  238. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  239. }
  240. @end
  241. @interface GPBInt64Int32Dictionary () <GPBDictionaryInternalsProtocol> {
  242. @package
  243. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  244. }
  245. @end
  246. @interface GPBInt64UInt64Dictionary () <GPBDictionaryInternalsProtocol> {
  247. @package
  248. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  249. }
  250. @end
  251. @interface GPBInt64Int64Dictionary () <GPBDictionaryInternalsProtocol> {
  252. @package
  253. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  254. }
  255. @end
  256. @interface GPBInt64BoolDictionary () <GPBDictionaryInternalsProtocol> {
  257. @package
  258. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  259. }
  260. @end
  261. @interface GPBInt64FloatDictionary () <GPBDictionaryInternalsProtocol> {
  262. @package
  263. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  264. }
  265. @end
  266. @interface GPBInt64DoubleDictionary () <GPBDictionaryInternalsProtocol> {
  267. @package
  268. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  269. }
  270. @end
  271. @interface GPBInt64EnumDictionary () <GPBDictionaryInternalsProtocol> {
  272. @package
  273. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  274. }
  275. - (NSData *)serializedDataForUnknownValue:(int32_t)value
  276. forKey:(GPBGenericValue *)key
  277. keyDataType:(GPBDataType)keyDataType;
  278. @end
  279. @interface GPBInt64ObjectDictionary () <GPBDictionaryInternalsProtocol> {
  280. @package
  281. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  282. }
  283. - (BOOL)isInitialized;
  284. - (instancetype)deepCopyWithZone:(NSZone *)zone
  285. __attribute__((ns_returns_retained));
  286. @end
  287. //%PDDM-EXPAND DICTIONARY_PRIV_INTERFACES_FOR_POD_KEY(Bool)
  288. // This block of code is generated, do not edit it directly.
  289. @interface GPBBoolUInt32Dictionary () <GPBDictionaryInternalsProtocol> {
  290. @package
  291. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  292. }
  293. @end
  294. @interface GPBBoolInt32Dictionary () <GPBDictionaryInternalsProtocol> {
  295. @package
  296. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  297. }
  298. @end
  299. @interface GPBBoolUInt64Dictionary () <GPBDictionaryInternalsProtocol> {
  300. @package
  301. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  302. }
  303. @end
  304. @interface GPBBoolInt64Dictionary () <GPBDictionaryInternalsProtocol> {
  305. @package
  306. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  307. }
  308. @end
  309. @interface GPBBoolBoolDictionary () <GPBDictionaryInternalsProtocol> {
  310. @package
  311. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  312. }
  313. @end
  314. @interface GPBBoolFloatDictionary () <GPBDictionaryInternalsProtocol> {
  315. @package
  316. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  317. }
  318. @end
  319. @interface GPBBoolDoubleDictionary () <GPBDictionaryInternalsProtocol> {
  320. @package
  321. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  322. }
  323. @end
  324. @interface GPBBoolEnumDictionary () <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. @interface GPBBoolObjectDictionary () <GPBDictionaryInternalsProtocol> {
  333. @package
  334. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  335. }
  336. - (BOOL)isInitialized;
  337. - (instancetype)deepCopyWithZone:(NSZone *)zone
  338. __attribute__((ns_returns_retained));
  339. @end
  340. //%PDDM-EXPAND DICTIONARY_POD_PRIV_INTERFACES_FOR_KEY(String)
  341. // This block of code is generated, do not edit it directly.
  342. @interface GPBStringUInt32Dictionary () <GPBDictionaryInternalsProtocol> {
  343. @package
  344. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  345. }
  346. @end
  347. @interface GPBStringInt32Dictionary () <GPBDictionaryInternalsProtocol> {
  348. @package
  349. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  350. }
  351. @end
  352. @interface GPBStringUInt64Dictionary () <GPBDictionaryInternalsProtocol> {
  353. @package
  354. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  355. }
  356. @end
  357. @interface GPBStringInt64Dictionary () <GPBDictionaryInternalsProtocol> {
  358. @package
  359. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  360. }
  361. @end
  362. @interface GPBStringBoolDictionary () <GPBDictionaryInternalsProtocol> {
  363. @package
  364. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  365. }
  366. @end
  367. @interface GPBStringFloatDictionary () <GPBDictionaryInternalsProtocol> {
  368. @package
  369. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  370. }
  371. @end
  372. @interface GPBStringDoubleDictionary () <GPBDictionaryInternalsProtocol> {
  373. @package
  374. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  375. }
  376. @end
  377. @interface GPBStringEnumDictionary () <GPBDictionaryInternalsProtocol> {
  378. @package
  379. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  380. }
  381. - (NSData *)serializedDataForUnknownValue:(int32_t)value
  382. forKey:(GPBGenericValue *)key
  383. keyDataType:(GPBDataType)keyDataType;
  384. @end
  385. //%PDDM-EXPAND-END (6 expansions)
  386. #pragma mark - NSDictionary Subclass
  387. @interface GPBAutocreatedDictionary : NSMutableDictionary {
  388. @package
  389. GPB_UNSAFE_UNRETAINED GPBMessage *_autocreator;
  390. }
  391. @end
  392. #pragma mark - Helpers
  393. CF_EXTERN_C_BEGIN
  394. // Helper to compute size when an NSDictionary is used for the map instead
  395. // of a custom type.
  396. size_t GPBDictionaryComputeSizeInternalHelper(NSDictionary *dict,
  397. GPBFieldDescriptor *field);
  398. // Helper to write out when an NSDictionary is used for the map instead
  399. // of a custom type.
  400. void GPBDictionaryWriteToStreamInternalHelper(
  401. GPBCodedOutputStream *outputStream, NSDictionary *dict,
  402. GPBFieldDescriptor *field);
  403. // Helper to check message initialization when an NSDictionary is used for
  404. // the map instead of a custom type.
  405. BOOL GPBDictionaryIsInitializedInternalHelper(NSDictionary *dict,
  406. GPBFieldDescriptor *field);
  407. // Helper to read a map instead.
  408. void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream,
  409. GPBExtensionRegistry *registry,
  410. GPBFieldDescriptor *field,
  411. GPBMessage *parentMessage);
  412. CF_EXTERN_C_END