GPBDictionary_PackagePrivate.h 15 KB

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