GPBUtilities.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. lineIndent can be nil if no additional line indent is
  38. // needed. The comments provide the names according to the ObjC library, they
  39. // most likely won't exactly match the original .proto file.
  40. NSString *GPBTextFormatForMessage(GPBMessage *message,
  41. NSString * __nullable lineIndent);
  42. NSString *GPBTextFormatForUnknownFieldSet(GPBUnknownFieldSet *unknownSet,
  43. NSString * __nullable lineIndent);
  44. //
  45. // Test if the given field is set on a message.
  46. //
  47. BOOL GPBMessageHasFieldNumberSet(GPBMessage *self, uint32_t fieldNumber);
  48. BOOL GPBMessageHasFieldSet(GPBMessage *self, GPBFieldDescriptor *field);
  49. //
  50. // Clear the given field of a message.
  51. //
  52. void GPBClearMessageField(GPBMessage *self, GPBFieldDescriptor *field);
  53. //%PDDM-EXPAND GPB_ACCESSORS()
  54. // This block of code is generated, do not edit it directly.
  55. //
  56. // Get/Set the given field of a message.
  57. //
  58. // Single Fields
  59. NSData *GPBGetMessageBytesField(GPBMessage *self, GPBFieldDescriptor *field);
  60. void GPBSetMessageBytesField(GPBMessage *self, GPBFieldDescriptor *field, NSData *value);
  61. NSString *GPBGetMessageStringField(GPBMessage *self, GPBFieldDescriptor *field);
  62. void GPBSetMessageStringField(GPBMessage *self, GPBFieldDescriptor *field, NSString *value);
  63. GPBMessage *GPBGetMessageMessageField(GPBMessage *self, GPBFieldDescriptor *field);
  64. void GPBSetMessageMessageField(GPBMessage *self, GPBFieldDescriptor *field, GPBMessage *value);
  65. GPBMessage *GPBGetMessageGroupField(GPBMessage *self, GPBFieldDescriptor *field);
  66. void GPBSetMessageGroupField(GPBMessage *self, GPBFieldDescriptor *field, GPBMessage *value);
  67. BOOL GPBGetMessageBoolField(GPBMessage *self, GPBFieldDescriptor *field);
  68. void GPBSetMessageBoolField(GPBMessage *self, GPBFieldDescriptor *field, BOOL value);
  69. int32_t GPBGetMessageInt32Field(GPBMessage *self, GPBFieldDescriptor *field);
  70. void GPBSetMessageInt32Field(GPBMessage *self, GPBFieldDescriptor *field, int32_t value);
  71. uint32_t GPBGetMessageUInt32Field(GPBMessage *self, GPBFieldDescriptor *field);
  72. void GPBSetMessageUInt32Field(GPBMessage *self, GPBFieldDescriptor *field, uint32_t value);
  73. int64_t GPBGetMessageInt64Field(GPBMessage *self, GPBFieldDescriptor *field);
  74. void GPBSetMessageInt64Field(GPBMessage *self, GPBFieldDescriptor *field, int64_t value);
  75. uint64_t GPBGetMessageUInt64Field(GPBMessage *self, GPBFieldDescriptor *field);
  76. void GPBSetMessageUInt64Field(GPBMessage *self, GPBFieldDescriptor *field, uint64_t value);
  77. float GPBGetMessageFloatField(GPBMessage *self, GPBFieldDescriptor *field);
  78. void GPBSetMessageFloatField(GPBMessage *self, GPBFieldDescriptor *field, float value);
  79. double GPBGetMessageDoubleField(GPBMessage *self, GPBFieldDescriptor *field);
  80. void GPBSetMessageDoubleField(GPBMessage *self, GPBFieldDescriptor *field, double value);
  81. // Get/Set the given enum field of a message. You can only Set values that are
  82. // members of the enum. For proto3, when doing a Get, if the value isn't a
  83. // memeber of the enum, kGPBUnrecognizedEnumeratorValue will be returned. The
  84. // the functions with "Raw" in the will bypass all checks.
  85. int32_t GPBGetMessageEnumField(GPBMessage *self, GPBFieldDescriptor *field);
  86. void GPBSetMessageEnumField(GPBMessage *self, GPBFieldDescriptor *field, int32_t value);
  87. int32_t GPBGetMessageRawEnumField(GPBMessage *self, GPBFieldDescriptor *field);
  88. void GPBSetMessageRawEnumField(GPBMessage *self, GPBFieldDescriptor *field, int32_t value);
  89. // Repeated Fields
  90. // The object will/should be GPB*Array or NSMutableArray based on the field's
  91. // type.
  92. id GPBGetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field);
  93. void GPBSetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field, id array);
  94. // Map Fields
  95. // The object will/should be GPB*Dictionary or NSMutableDictionary based on the
  96. // field's type.
  97. id GPBGetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field);
  98. void GPBSetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field, id dictionary);
  99. //%PDDM-EXPAND-END GPB_ACCESSORS()
  100. // Returns an empty NSData to assign to byte fields when you wish
  101. // to assign them to empty. Prevents allocating a lot of little [NSData data]
  102. // objects.
  103. NSData *GPBEmptyNSData(void) __attribute__((pure));
  104. NS_ASSUME_NONNULL_END
  105. CF_EXTERN_C_END
  106. //%PDDM-DEFINE GPB_ACCESSORS()
  107. //%
  108. //%//
  109. //%// Get/Set the given field of a message.
  110. //%//
  111. //%
  112. //%// Single Fields
  113. //%
  114. //%GPB_ACCESSOR_SINGLE_FULL(Bytes, NSData, *)
  115. //%GPB_ACCESSOR_SINGLE_FULL(String, NSString, *)
  116. //%GPB_ACCESSOR_SINGLE_FULL(Message, GPBMessage, *)
  117. //%GPB_ACCESSOR_SINGLE_FULL(Group, GPBMessage, *)
  118. //%GPB_ACCESSOR_SINGLE(Bool, BOOL)
  119. //%GPB_ACCESSOR_SINGLE(Int32, int32_t)
  120. //%GPB_ACCESSOR_SINGLE(UInt32, uint32_t)
  121. //%GPB_ACCESSOR_SINGLE(Int64, int64_t)
  122. //%GPB_ACCESSOR_SINGLE(UInt64, uint64_t)
  123. //%GPB_ACCESSOR_SINGLE(Float, float)
  124. //%GPB_ACCESSOR_SINGLE(Double, double)
  125. //%// Get/Set the given enum field of a message. You can only Set values that are
  126. //%// members of the enum. For proto3, when doing a Get, if the value isn't a
  127. //%// memeber of the enum, kGPBUnrecognizedEnumeratorValue will be returned. The
  128. //%// the functions with "Raw" in the will bypass all checks.
  129. //%int32_t GPBGetMessageEnumField(GPBMessage *self, GPBFieldDescriptor *field);
  130. //%void GPBSetMessageEnumField(GPBMessage *self, GPBFieldDescriptor *field, int32_t value);
  131. //%int32_t GPBGetMessageRawEnumField(GPBMessage *self, GPBFieldDescriptor *field);
  132. //%void GPBSetMessageRawEnumField(GPBMessage *self, GPBFieldDescriptor *field, int32_t value);
  133. //%
  134. //%// Repeated Fields
  135. //%
  136. //%// The object will/should be GPB*Array or NSMutableArray based on the field's
  137. //%// type.
  138. //%id GPBGetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field);
  139. //%void GPBSetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field, id array);
  140. //%
  141. //%// Map Fields
  142. //%
  143. //%// The object will/should be GPB*Dictionary or NSMutableDictionary based on the
  144. //%// field's type.
  145. //%id GPBGetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field);
  146. //%void GPBSetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field, id dictionary);
  147. //%
  148. //%PDDM-DEFINE GPB_ACCESSOR_SINGLE(NAME, TYPE)
  149. //%GPB_ACCESSOR_SINGLE_FULL(NAME, TYPE, )
  150. //%PDDM-DEFINE GPB_ACCESSOR_SINGLE_FULL(NAME, TYPE, TisP)
  151. //%TYPE TisP##GPBGetMessage##NAME##Field(GPBMessage *self, GPBFieldDescriptor *field);
  152. //%void GPBSetMessage##NAME##Field(GPBMessage *self, GPBFieldDescriptor *field, TYPE TisP##value);
  153. //%