GPBUtilities.h 8.1 KB

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