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