GPBUtilities.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  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 "GPBArray.h"
  32. #import "GPBMessage.h"
  33. #import "GPBRuntimeTypes.h"
  34. CF_EXTERN_C_BEGIN
  35. NS_ASSUME_NONNULL_BEGIN
  36. /**
  37. * Generates a string that should be a valid "TextFormat" for the C++ version
  38. * of Protocol Buffers.
  39. *
  40. * @param message The message to generate from.
  41. * @param lineIndent A string to use as the prefix for all lines generated. Can
  42. * be nil if no extra indent is needed.
  43. *
  44. * @return An NSString with the TextFormat of the message.
  45. **/
  46. NSString *GPBTextFormatForMessage(GPBMessage *message,
  47. NSString * __nullable lineIndent);
  48. /**
  49. * Generates a string that should be a valid "TextFormat" for the C++ version
  50. * of Protocol Buffers.
  51. *
  52. * @param unknownSet The unknown field set to generate from.
  53. * @param lineIndent A string to use as the prefix for all lines generated. Can
  54. * be nil if no extra indent is needed.
  55. *
  56. * @return An NSString with the TextFormat of the unknown field set.
  57. **/
  58. NSString *GPBTextFormatForUnknownFieldSet(GPBUnknownFieldSet * __nullable unknownSet,
  59. NSString * __nullable lineIndent);
  60. /**
  61. * Checks if the given field number is set on a message.
  62. *
  63. * @param self The message to check.
  64. * @param fieldNumber The field number to check.
  65. *
  66. * @return YES if the field number is set on the given message.
  67. **/
  68. BOOL GPBMessageHasFieldNumberSet(GPBMessage *self, uint32_t fieldNumber);
  69. /**
  70. * Checks if the given field is set on a message.
  71. *
  72. * @param self The message to check.
  73. * @param field The field to check.
  74. *
  75. * @return YES if the field is set on the given message.
  76. **/
  77. BOOL GPBMessageHasFieldSet(GPBMessage *self, GPBFieldDescriptor *field);
  78. /**
  79. * Clears the given field for the given message.
  80. *
  81. * @param self The message for which to clear the field.
  82. * @param field The field to clear.
  83. **/
  84. void GPBClearMessageField(GPBMessage *self, GPBFieldDescriptor *field);
  85. //%PDDM-EXPAND GPB_ACCESSORS()
  86. // This block of code is generated, do not edit it directly.
  87. //
  88. // Get/Set a given field from/to a message.
  89. //
  90. // Single Fields
  91. /**
  92. * Gets the value of a bytes field.
  93. *
  94. * @param self The message from which to get the field.
  95. * @param field The field to get.
  96. **/
  97. NSData *GPBGetMessageBytesField(GPBMessage *self, GPBFieldDescriptor *field);
  98. /**
  99. * Sets the value of a bytes field.
  100. *
  101. * @param self The message into which to set the field.
  102. * @param field The field to set.
  103. * @param value The to set in the field.
  104. **/
  105. void GPBSetMessageBytesField(GPBMessage *self, GPBFieldDescriptor *field, NSData *value);
  106. /**
  107. * Gets the value of a string field.
  108. *
  109. * @param self The message from which to get the field.
  110. * @param field The field to get.
  111. **/
  112. NSString *GPBGetMessageStringField(GPBMessage *self, GPBFieldDescriptor *field);
  113. /**
  114. * Sets the value of a string field.
  115. *
  116. * @param self The message into which to set the field.
  117. * @param field The field to set.
  118. * @param value The to set in the field.
  119. **/
  120. void GPBSetMessageStringField(GPBMessage *self, GPBFieldDescriptor *field, NSString *value);
  121. /**
  122. * Gets the value of a message field.
  123. *
  124. * @param self The message from which to get the field.
  125. * @param field The field to get.
  126. **/
  127. GPBMessage *GPBGetMessageMessageField(GPBMessage *self, GPBFieldDescriptor *field);
  128. /**
  129. * Sets the value of a message field.
  130. *
  131. * @param self The message into which to set the field.
  132. * @param field The field to set.
  133. * @param value The to set in the field.
  134. **/
  135. void GPBSetMessageMessageField(GPBMessage *self, GPBFieldDescriptor *field, GPBMessage *value);
  136. /**
  137. * Gets the value of a group field.
  138. *
  139. * @param self The message from which to get the field.
  140. * @param field The field to get.
  141. **/
  142. GPBMessage *GPBGetMessageGroupField(GPBMessage *self, GPBFieldDescriptor *field);
  143. /**
  144. * Sets the value of a group field.
  145. *
  146. * @param self The message into which to set the field.
  147. * @param field The field to set.
  148. * @param value The to set in the field.
  149. **/
  150. void GPBSetMessageGroupField(GPBMessage *self, GPBFieldDescriptor *field, GPBMessage *value);
  151. /**
  152. * Gets the value of a bool field.
  153. *
  154. * @param self The message from which to get the field.
  155. * @param field The field to get.
  156. **/
  157. BOOL GPBGetMessageBoolField(GPBMessage *self, GPBFieldDescriptor *field);
  158. /**
  159. * Sets the value of a bool field.
  160. *
  161. * @param self The message into which to set the field.
  162. * @param field The field to set.
  163. * @param value The to set in the field.
  164. **/
  165. void GPBSetMessageBoolField(GPBMessage *self, GPBFieldDescriptor *field, BOOL value);
  166. /**
  167. * Gets the value of an int32 field.
  168. *
  169. * @param self The message from which to get the field.
  170. * @param field The field to get.
  171. **/
  172. int32_t GPBGetMessageInt32Field(GPBMessage *self, GPBFieldDescriptor *field);
  173. /**
  174. * Sets the value of an int32 field.
  175. *
  176. * @param self The message into which to set the field.
  177. * @param field The field to set.
  178. * @param value The to set in the field.
  179. **/
  180. void GPBSetMessageInt32Field(GPBMessage *self, GPBFieldDescriptor *field, int32_t value);
  181. /**
  182. * Gets the value of an uint32 field.
  183. *
  184. * @param self The message from which to get the field.
  185. * @param field The field to get.
  186. **/
  187. uint32_t GPBGetMessageUInt32Field(GPBMessage *self, GPBFieldDescriptor *field);
  188. /**
  189. * Sets the value of an uint32 field.
  190. *
  191. * @param self The message into which to set the field.
  192. * @param field The field to set.
  193. * @param value The to set in the field.
  194. **/
  195. void GPBSetMessageUInt32Field(GPBMessage *self, GPBFieldDescriptor *field, uint32_t value);
  196. /**
  197. * Gets the value of an int64 field.
  198. *
  199. * @param self The message from which to get the field.
  200. * @param field The field to get.
  201. **/
  202. int64_t GPBGetMessageInt64Field(GPBMessage *self, GPBFieldDescriptor *field);
  203. /**
  204. * Sets the value of an int64 field.
  205. *
  206. * @param self The message into which to set the field.
  207. * @param field The field to set.
  208. * @param value The to set in the field.
  209. **/
  210. void GPBSetMessageInt64Field(GPBMessage *self, GPBFieldDescriptor *field, int64_t value);
  211. /**
  212. * Gets the value of an uint64 field.
  213. *
  214. * @param self The message from which to get the field.
  215. * @param field The field to get.
  216. **/
  217. uint64_t GPBGetMessageUInt64Field(GPBMessage *self, GPBFieldDescriptor *field);
  218. /**
  219. * Sets the value of an uint64 field.
  220. *
  221. * @param self The message into which to set the field.
  222. * @param field The field to set.
  223. * @param value The to set in the field.
  224. **/
  225. void GPBSetMessageUInt64Field(GPBMessage *self, GPBFieldDescriptor *field, uint64_t value);
  226. /**
  227. * Gets the value of a float field.
  228. *
  229. * @param self The message from which to get the field.
  230. * @param field The field to get.
  231. **/
  232. float GPBGetMessageFloatField(GPBMessage *self, GPBFieldDescriptor *field);
  233. /**
  234. * Sets the value of a float field.
  235. *
  236. * @param self The message into which to set the field.
  237. * @param field The field to set.
  238. * @param value The to set in the field.
  239. **/
  240. void GPBSetMessageFloatField(GPBMessage *self, GPBFieldDescriptor *field, float value);
  241. /**
  242. * Gets the value of a double field.
  243. *
  244. * @param self The message from which to get the field.
  245. * @param field The field to get.
  246. **/
  247. double GPBGetMessageDoubleField(GPBMessage *self, GPBFieldDescriptor *field);
  248. /**
  249. * Sets the value of a double field.
  250. *
  251. * @param self The message into which to set the field.
  252. * @param field The field to set.
  253. * @param value The to set in the field.
  254. **/
  255. void GPBSetMessageDoubleField(GPBMessage *self, GPBFieldDescriptor *field, double value);
  256. /**
  257. * Gets the given enum field of a message. For proto3, if the value isn't a
  258. * member of the enum, @c kGPBUnrecognizedEnumeratorValue will be returned.
  259. * GPBGetMessageRawEnumField will bypass the check and return whatever value
  260. * was set.
  261. *
  262. * @param self The message from which to get the field.
  263. * @param field The field to get.
  264. *
  265. * @return The enum value for the given field.
  266. **/
  267. int32_t GPBGetMessageEnumField(GPBMessage *self, GPBFieldDescriptor *field);
  268. /**
  269. * Set the given enum field of a message. You can only set values that are
  270. * members of the enum.
  271. *
  272. * @param self The message into which to set the field.
  273. * @param field The field to set.
  274. * @param value The enum value to set in the field.
  275. **/
  276. void GPBSetMessageEnumField(GPBMessage *self,
  277. GPBFieldDescriptor *field,
  278. int32_t value);
  279. /**
  280. * Get the given enum field of a message. No check is done to ensure the value
  281. * was defined in the enum.
  282. *
  283. * @param self The message from which to get the field.
  284. * @param field The field to get.
  285. *
  286. * @return The raw enum value for the given field.
  287. **/
  288. int32_t GPBGetMessageRawEnumField(GPBMessage *self, GPBFieldDescriptor *field);
  289. /**
  290. * Set the given enum field of a message. You can set the value to anything,
  291. * even a value that is not a member of the enum.
  292. *
  293. * @param self The message into which to set the field.
  294. * @param field The field to set.
  295. * @param value The raw enum value to set in the field.
  296. **/
  297. void GPBSetMessageRawEnumField(GPBMessage *self,
  298. GPBFieldDescriptor *field,
  299. int32_t value);
  300. // Repeated Fields
  301. /**
  302. * Gets the value of a repeated field.
  303. *
  304. * @param self The message from which to get the field.
  305. * @param field The repeated field to get.
  306. *
  307. * @return A GPB*Array or an NSMutableArray based on the field's type.
  308. **/
  309. id GPBGetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field);
  310. /**
  311. * Sets the value of a repeated field.
  312. *
  313. * @param self The message into which to set the field.
  314. * @param field The field to set.
  315. * @param array A GPB*Array or NSMutableArray based on the field's type.
  316. **/
  317. void GPBSetMessageRepeatedField(GPBMessage *self,
  318. GPBFieldDescriptor *field,
  319. id array);
  320. // Map Fields
  321. /**
  322. * Gets the value of a map<> field.
  323. *
  324. * @param self The message from which to get the field.
  325. * @param field The repeated field to get.
  326. *
  327. * @return A GPB*Dictionary or NSMutableDictionary based on the field's type.
  328. **/
  329. id GPBGetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field);
  330. /**
  331. * Sets the value of a map<> field.
  332. *
  333. * @param self The message into which to set the field.
  334. * @param field The field to set.
  335. * @param dictionary A GPB*Dictionary or NSMutableDictionary based on the
  336. * field's type.
  337. **/
  338. void GPBSetMessageMapField(GPBMessage *self,
  339. GPBFieldDescriptor *field,
  340. id dictionary);
  341. //%PDDM-EXPAND-END GPB_ACCESSORS()
  342. /**
  343. * Returns an empty NSData to assign to byte fields when you wish to assign them
  344. * to empty. Prevents allocating a lot of little [NSData data] objects.
  345. **/
  346. NSData *GPBEmptyNSData(void) __attribute__((pure));
  347. /**
  348. * Drops the `unknownFields` from the given message and from all sub message.
  349. **/
  350. void GPBMessageDropUnknownFieldsRecursively(GPBMessage *message);
  351. NS_ASSUME_NONNULL_END
  352. CF_EXTERN_C_END
  353. //%PDDM-DEFINE GPB_ACCESSORS()
  354. //%
  355. //%//
  356. //%// Get/Set a given field from/to a message.
  357. //%//
  358. //%
  359. //%// Single Fields
  360. //%
  361. //%GPB_ACCESSOR_SINGLE_FULL(Bytes, NSData, , *)
  362. //%GPB_ACCESSOR_SINGLE_FULL(String, NSString, , *)
  363. //%GPB_ACCESSOR_SINGLE_FULL(Message, GPBMessage, , *)
  364. //%GPB_ACCESSOR_SINGLE_FULL(Group, GPBMessage, , *)
  365. //%GPB_ACCESSOR_SINGLE(Bool, BOOL, )
  366. //%GPB_ACCESSOR_SINGLE(Int32, int32_t, n)
  367. //%GPB_ACCESSOR_SINGLE(UInt32, uint32_t, n)
  368. //%GPB_ACCESSOR_SINGLE(Int64, int64_t, n)
  369. //%GPB_ACCESSOR_SINGLE(UInt64, uint64_t, n)
  370. //%GPB_ACCESSOR_SINGLE(Float, float, )
  371. //%GPB_ACCESSOR_SINGLE(Double, double, )
  372. //%/**
  373. //% * Gets the given enum field of a message. For proto3, if the value isn't a
  374. //% * member of the enum, @c kGPBUnrecognizedEnumeratorValue will be returned.
  375. //% * GPBGetMessageRawEnumField will bypass the check and return whatever value
  376. //% * was set.
  377. //% *
  378. //% * @param self The message from which to get the field.
  379. //% * @param field The field to get.
  380. //% *
  381. //% * @return The enum value for the given field.
  382. //% **/
  383. //%int32_t GPBGetMessageEnumField(GPBMessage *self, GPBFieldDescriptor *field);
  384. //%
  385. //%/**
  386. //% * Set the given enum field of a message. You can only set values that are
  387. //% * members of the enum.
  388. //% *
  389. //% * @param self The message into which to set the field.
  390. //% * @param field The field to set.
  391. //% * @param value The enum value to set in the field.
  392. //% **/
  393. //%void GPBSetMessageEnumField(GPBMessage *self,
  394. //% GPBFieldDescriptor *field,
  395. //% int32_t value);
  396. //%
  397. //%/**
  398. //% * Get the given enum field of a message. No check is done to ensure the value
  399. //% * was defined in the enum.
  400. //% *
  401. //% * @param self The message from which to get the field.
  402. //% * @param field The field to get.
  403. //% *
  404. //% * @return The raw enum value for the given field.
  405. //% **/
  406. //%int32_t GPBGetMessageRawEnumField(GPBMessage *self, GPBFieldDescriptor *field);
  407. //%
  408. //%/**
  409. //% * Set the given enum field of a message. You can set the value to anything,
  410. //% * even a value that is not a member of the enum.
  411. //% *
  412. //% * @param self The message into which to set the field.
  413. //% * @param field The field to set.
  414. //% * @param value The raw enum value to set in the field.
  415. //% **/
  416. //%void GPBSetMessageRawEnumField(GPBMessage *self,
  417. //% GPBFieldDescriptor *field,
  418. //% int32_t value);
  419. //%
  420. //%// Repeated Fields
  421. //%
  422. //%/**
  423. //% * Gets the value of a repeated field.
  424. //% *
  425. //% * @param self The message from which to get the field.
  426. //% * @param field The repeated field to get.
  427. //% *
  428. //% * @return A GPB*Array or an NSMutableArray based on the field's type.
  429. //% **/
  430. //%id GPBGetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field);
  431. //%
  432. //%/**
  433. //% * Sets the value of a repeated field.
  434. //% *
  435. //% * @param self The message into which to set the field.
  436. //% * @param field The field to set.
  437. //% * @param array A GPB*Array or NSMutableArray based on the field's type.
  438. //% **/
  439. //%void GPBSetMessageRepeatedField(GPBMessage *self,
  440. //% GPBFieldDescriptor *field,
  441. //% id array);
  442. //%
  443. //%// Map Fields
  444. //%
  445. //%/**
  446. //% * Gets the value of a map<> field.
  447. //% *
  448. //% * @param self The message from which to get the field.
  449. //% * @param field The repeated field to get.
  450. //% *
  451. //% * @return A GPB*Dictionary or NSMutableDictionary based on the field's type.
  452. //% **/
  453. //%id GPBGetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field);
  454. //%
  455. //%/**
  456. //% * Sets the value of a map<> field.
  457. //% *
  458. //% * @param self The message into which to set the field.
  459. //% * @param field The field to set.
  460. //% * @param dictionary A GPB*Dictionary or NSMutableDictionary based on the
  461. //% * field's type.
  462. //% **/
  463. //%void GPBSetMessageMapField(GPBMessage *self,
  464. //% GPBFieldDescriptor *field,
  465. //% id dictionary);
  466. //%
  467. //%PDDM-DEFINE GPB_ACCESSOR_SINGLE(NAME, TYPE, AN)
  468. //%GPB_ACCESSOR_SINGLE_FULL(NAME, TYPE, AN, )
  469. //%PDDM-DEFINE GPB_ACCESSOR_SINGLE_FULL(NAME, TYPE, AN, TisP)
  470. //%/**
  471. //% * Gets the value of a##AN NAME$L field.
  472. //% *
  473. //% * @param self The message from which to get the field.
  474. //% * @param field The field to get.
  475. //% **/
  476. //%TYPE TisP##GPBGetMessage##NAME##Field(GPBMessage *self, GPBFieldDescriptor *field);
  477. //%
  478. //%/**
  479. //% * Sets the value of a##AN NAME$L field.
  480. //% *
  481. //% * @param self The message into which to set the field.
  482. //% * @param field The field to set.
  483. //% * @param value The to set in the field.
  484. //% **/
  485. //%void GPBSetMessage##NAME##Field(GPBMessage *self, GPBFieldDescriptor *field, TYPE TisP##value);
  486. //%