GPBUtilities.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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. /// Generates a string that should be a valid "Text Format" for the C++ version
  37. /// of Protocol Buffers.
  38. ///
  39. /// @param message The message to generate from.
  40. /// @param lineIndent A string to use as the prefix for all lines generated. Can
  41. /// be nil if no extra indent is needed.
  42. ///
  43. /// @return A @c NSString with the Text Format of the message.
  44. NSString *GPBTextFormatForMessage(GPBMessage *message,
  45. NSString * __nullable lineIndent);
  46. /// Generates a string that should be a valid "Text Format" for the C++ version
  47. /// of Protocol Buffers.
  48. ///
  49. /// @param unknownSet The unknown field set to generate from.
  50. /// @param lineIndent A string to use as the prefix for all lines generated. Can
  51. /// be nil if no extra indent is needed.
  52. ///
  53. /// @return A @c NSString with the Text Format of the unknown field set.
  54. NSString *GPBTextFormatForUnknownFieldSet(GPBUnknownFieldSet * __nullable unknownSet,
  55. NSString * __nullable lineIndent);
  56. /// Test if the given field is set on a message.
  57. BOOL GPBMessageHasFieldNumberSet(GPBMessage *self, uint32_t fieldNumber);
  58. /// Test if the given field is set on a message.
  59. BOOL GPBMessageHasFieldSet(GPBMessage *self, GPBFieldDescriptor *field);
  60. /// Clear the given field of a message.
  61. void GPBClearMessageField(GPBMessage *self, GPBFieldDescriptor *field);
  62. //%PDDM-EXPAND GPB_ACCESSORS()
  63. // This block of code is generated, do not edit it directly.
  64. //
  65. // Get/Set the given field of a message.
  66. //
  67. // Single Fields
  68. /// Gets the value of a bytes field.
  69. NSData *GPBGetMessageBytesField(GPBMessage *self, GPBFieldDescriptor *field);
  70. /// Sets the value of a bytes field.
  71. void GPBSetMessageBytesField(GPBMessage *self, GPBFieldDescriptor *field, NSData *value);
  72. /// Gets the value of a string field.
  73. NSString *GPBGetMessageStringField(GPBMessage *self, GPBFieldDescriptor *field);
  74. /// Sets the value of a string field.
  75. void GPBSetMessageStringField(GPBMessage *self, GPBFieldDescriptor *field, NSString *value);
  76. /// Gets the value of a message field.
  77. GPBMessage *GPBGetMessageMessageField(GPBMessage *self, GPBFieldDescriptor *field);
  78. /// Sets the value of a message field.
  79. void GPBSetMessageMessageField(GPBMessage *self, GPBFieldDescriptor *field, GPBMessage *value);
  80. /// Gets the value of a group field.
  81. GPBMessage *GPBGetMessageGroupField(GPBMessage *self, GPBFieldDescriptor *field);
  82. /// Sets the value of a group field.
  83. void GPBSetMessageGroupField(GPBMessage *self, GPBFieldDescriptor *field, GPBMessage *value);
  84. /// Gets the value of a bool field.
  85. BOOL GPBGetMessageBoolField(GPBMessage *self, GPBFieldDescriptor *field);
  86. /// Sets the value of a bool field.
  87. void GPBSetMessageBoolField(GPBMessage *self, GPBFieldDescriptor *field, BOOL value);
  88. /// Gets the value of an int32 field.
  89. int32_t GPBGetMessageInt32Field(GPBMessage *self, GPBFieldDescriptor *field);
  90. /// Sets the value of an int32 field.
  91. void GPBSetMessageInt32Field(GPBMessage *self, GPBFieldDescriptor *field, int32_t value);
  92. /// Gets the value of an uint32 field.
  93. uint32_t GPBGetMessageUInt32Field(GPBMessage *self, GPBFieldDescriptor *field);
  94. /// Sets the value of an uint32 field.
  95. void GPBSetMessageUInt32Field(GPBMessage *self, GPBFieldDescriptor *field, uint32_t value);
  96. /// Gets the value of an int64 field.
  97. int64_t GPBGetMessageInt64Field(GPBMessage *self, GPBFieldDescriptor *field);
  98. /// Sets the value of an int64 field.
  99. void GPBSetMessageInt64Field(GPBMessage *self, GPBFieldDescriptor *field, int64_t value);
  100. /// Gets the value of an uint64 field.
  101. uint64_t GPBGetMessageUInt64Field(GPBMessage *self, GPBFieldDescriptor *field);
  102. /// Sets the value of an uint64 field.
  103. void GPBSetMessageUInt64Field(GPBMessage *self, GPBFieldDescriptor *field, uint64_t value);
  104. /// Gets the value of a float field.
  105. float GPBGetMessageFloatField(GPBMessage *self, GPBFieldDescriptor *field);
  106. /// Sets the value of a float field.
  107. void GPBSetMessageFloatField(GPBMessage *self, GPBFieldDescriptor *field, float value);
  108. /// Gets the value of a double field.
  109. double GPBGetMessageDoubleField(GPBMessage *self, GPBFieldDescriptor *field);
  110. /// Sets the value of a double field.
  111. void GPBSetMessageDoubleField(GPBMessage *self, GPBFieldDescriptor *field, double value);
  112. /// Get the given enum field of a message. For proto3, if the value isn't a
  113. /// member of the enum, @c kGPBUnrecognizedEnumeratorValue will be returned.
  114. /// GPBGetMessageRawEnumField will bypass the check and return whatever value
  115. /// was set.
  116. int32_t GPBGetMessageEnumField(GPBMessage *self, GPBFieldDescriptor *field);
  117. /// Set the given enum field of a message. You can only set values that are
  118. /// members of the enum.
  119. void GPBSetMessageEnumField(GPBMessage *self, GPBFieldDescriptor *field, int32_t value);
  120. /// Get the given enum field of a message. No check is done to ensure the value
  121. /// was defined in the enum.
  122. int32_t GPBGetMessageRawEnumField(GPBMessage *self, GPBFieldDescriptor *field);
  123. /// Set the given enum field of a message. You can set the value to anything,
  124. /// even a value that is not a member of the enum.
  125. void GPBSetMessageRawEnumField(GPBMessage *self, GPBFieldDescriptor *field, int32_t value);
  126. // Repeated Fields
  127. /// Gets the value of a repeated field.
  128. ///
  129. /// The result will be @c GPB*Array or @c NSMutableArray based on the
  130. /// field's type.
  131. id GPBGetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field);
  132. /// Sets the value of a repeated field.
  133. ///
  134. /// The value should be @c GPB*Array or @c NSMutableArray based on the
  135. /// field's type.
  136. void GPBSetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field, id array);
  137. // Map Fields
  138. /// Gets the value of a map<> field.
  139. ///
  140. /// The result will be @c GPB*Dictionary or @c NSMutableDictionary based on
  141. /// the field's type.
  142. id GPBGetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field);
  143. /// Sets the value of a map<> field.
  144. ///
  145. /// The object should be @c GPB*Dictionary or @c NSMutableDictionary based
  146. /// on the field's type.
  147. void GPBSetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field, id dictionary);
  148. //%PDDM-EXPAND-END GPB_ACCESSORS()
  149. // Returns an empty NSData to assign to byte fields when you wish
  150. // to assign them to empty. Prevents allocating a lot of little [NSData data]
  151. // objects.
  152. NSData *GPBEmptyNSData(void) __attribute__((pure));
  153. NS_ASSUME_NONNULL_END
  154. CF_EXTERN_C_END
  155. //%PDDM-DEFINE GPB_ACCESSORS()
  156. //%
  157. //%//
  158. //%// Get/Set the given field of a message.
  159. //%//
  160. //%
  161. //%// Single Fields
  162. //%
  163. //%GPB_ACCESSOR_SINGLE_FULL(Bytes, NSData, , *)
  164. //%GPB_ACCESSOR_SINGLE_FULL(String, NSString, , *)
  165. //%GPB_ACCESSOR_SINGLE_FULL(Message, GPBMessage, , *)
  166. //%GPB_ACCESSOR_SINGLE_FULL(Group, GPBMessage, , *)
  167. //%GPB_ACCESSOR_SINGLE(Bool, BOOL, )
  168. //%GPB_ACCESSOR_SINGLE(Int32, int32_t, n)
  169. //%GPB_ACCESSOR_SINGLE(UInt32, uint32_t, n)
  170. //%GPB_ACCESSOR_SINGLE(Int64, int64_t, n)
  171. //%GPB_ACCESSOR_SINGLE(UInt64, uint64_t, n)
  172. //%GPB_ACCESSOR_SINGLE(Float, float, )
  173. //%GPB_ACCESSOR_SINGLE(Double, double, )
  174. //%/// Get the given enum field of a message. For proto3, if the value isn't a
  175. //%/// member of the enum, @c kGPBUnrecognizedEnumeratorValue will be returned.
  176. //%/// GPBGetMessageRawEnumField will bypass the check and return whatever value
  177. //%/// was set.
  178. //%int32_t GPBGetMessageEnumField(GPBMessage *self, GPBFieldDescriptor *field);
  179. //%/// Set the given enum field of a message. You can only set values that are
  180. //%/// members of the enum.
  181. //%void GPBSetMessageEnumField(GPBMessage *self, GPBFieldDescriptor *field, int32_t value);
  182. //%/// Get the given enum field of a message. No check is done to ensure the value
  183. //%/// was defined in the enum.
  184. //%int32_t GPBGetMessageRawEnumField(GPBMessage *self, GPBFieldDescriptor *field);
  185. //%/// Set the given enum field of a message. You can set the value to anything,
  186. //%/// even a value that is not a member of the enum.
  187. //%void GPBSetMessageRawEnumField(GPBMessage *self, GPBFieldDescriptor *field, int32_t value);
  188. //%
  189. //%// Repeated Fields
  190. //%
  191. //%/// Gets the value of a repeated field.
  192. //%///
  193. //%/// The result will be @c GPB*Array or @c NSMutableArray based on the
  194. //%/// field's type.
  195. //%id GPBGetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field);
  196. //%/// Sets the value of a repeated field.
  197. //%///
  198. //%/// The value should be @c GPB*Array or @c NSMutableArray based on the
  199. //%/// field's type.
  200. //%void GPBSetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field, id array);
  201. //%
  202. //%// Map Fields
  203. //%
  204. //%/// Gets the value of a map<> field.
  205. //%///
  206. //%/// The result will be @c GPB*Dictionary or @c NSMutableDictionary based on
  207. //%/// the field's type.
  208. //%id GPBGetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field);
  209. //%/// Sets the value of a map<> field.
  210. //%///
  211. //%/// The object should be @c GPB*Dictionary or @c NSMutableDictionary based
  212. //%/// on the field's type.
  213. //%void GPBSetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field, id dictionary);
  214. //%
  215. //%PDDM-DEFINE GPB_ACCESSOR_SINGLE(NAME, TYPE, AN)
  216. //%GPB_ACCESSOR_SINGLE_FULL(NAME, TYPE, AN, )
  217. //%PDDM-DEFINE GPB_ACCESSOR_SINGLE_FULL(NAME, TYPE, AN, TisP)
  218. //%/// Gets the value of a##AN NAME$L field.
  219. //%TYPE TisP##GPBGetMessage##NAME##Field(GPBMessage *self, GPBFieldDescriptor *field);
  220. //%/// Sets the value of a##AN NAME$L field.
  221. //%void GPBSetMessage##NAME##Field(GPBMessage *self, GPBFieldDescriptor *field, TYPE TisP##value);
  222. //%