1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
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
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.
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.
31 #import <Foundation/Foundation.h>
34 #import "GPBMessage.h"
35 #import "GPBRuntimeTypes.h"
39 NS_ASSUME_NONNULL_BEGIN
42 * Generates a string that should be a valid "TextFormat" for the C++ version
43 * of Protocol Buffers.
45 * @param message The message to generate from.
46 * @param lineIndent A string to use as the prefix for all lines generated. Can
47 * be nil if no extra indent is needed.
49 * @return An NSString with the TextFormat of the message.
51 NSString *GPBTextFormatForMessage(GPBMessage *message,
52 NSString * __nullable lineIndent);
55 * Generates a string that should be a valid "TextFormat" for the C++ version
56 * of Protocol Buffers.
58 * @param unknownSet The unknown field set to generate from.
59 * @param lineIndent A string to use as the prefix for all lines generated. Can
60 * be nil if no extra indent is needed.
62 * @return An NSString with the TextFormat of the unknown field set.
64 NSString *GPBTextFormatForUnknownFieldSet(GPBUnknownFieldSet * __nullable unknownSet,
65 NSString * __nullable lineIndent);
68 * Checks if the given field number is set on a message.
70 * @param self The message to check.
71 * @param fieldNumber The field number to check.
73 * @return YES if the field number is set on the given message.
75 BOOL GPBMessageHasFieldNumberSet(GPBMessage *self, uint32_t fieldNumber);
78 * Checks if the given field is set on a message.
80 * @param self The message to check.
81 * @param field The field to check.
83 * @return YES if the field is set on the given message.
85 BOOL GPBMessageHasFieldSet(GPBMessage *self, GPBFieldDescriptor *field);
88 * Clears the given field for the given message.
90 * @param self The message for which to clear the field.
91 * @param field The field to clear.
93 void GPBClearMessageField(GPBMessage *self, GPBFieldDescriptor *field);
95 //%PDDM-EXPAND GPB_ACCESSORS()
96 // This block of code is generated, do not edit it directly.
100 // Get/Set a given field from/to a message.
106 * Gets the value of a bytes field.
108 * @param self The message from which to get the field.
109 * @param field The field to get.
111 NSData *GPBGetMessageBytesField(GPBMessage *self, GPBFieldDescriptor *field);
114 * Sets the value of a bytes field.
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.
120 void GPBSetMessageBytesField(GPBMessage *self, GPBFieldDescriptor *field, NSData *value);
123 * Gets the value of a string field.
125 * @param self The message from which to get the field.
126 * @param field The field to get.
128 NSString *GPBGetMessageStringField(GPBMessage *self, GPBFieldDescriptor *field);
131 * Sets the value of a string field.
133 * @param self The message into which to set the field.
134 * @param field The field to set.
135 * @param value The to set in the field.
137 void GPBSetMessageStringField(GPBMessage *self, GPBFieldDescriptor *field, NSString *value);
140 * Gets the value of a message field.
142 * @param self The message from which to get the field.
143 * @param field The field to get.
145 GPBMessage *GPBGetMessageMessageField(GPBMessage *self, GPBFieldDescriptor *field);
148 * Sets the value of a message field.
150 * @param self The message into which to set the field.
151 * @param field The field to set.
152 * @param value The to set in the field.
154 void GPBSetMessageMessageField(GPBMessage *self, GPBFieldDescriptor *field, GPBMessage *value);
157 * Gets the value of a group field.
159 * @param self The message from which to get the field.
160 * @param field The field to get.
162 GPBMessage *GPBGetMessageGroupField(GPBMessage *self, GPBFieldDescriptor *field);
165 * Sets the value of a group field.
167 * @param self The message into which to set the field.
168 * @param field The field to set.
169 * @param value The to set in the field.
171 void GPBSetMessageGroupField(GPBMessage *self, GPBFieldDescriptor *field, GPBMessage *value);
174 * Gets the value of a bool field.
176 * @param self The message from which to get the field.
177 * @param field The field to get.
179 BOOL GPBGetMessageBoolField(GPBMessage *self, GPBFieldDescriptor *field);
182 * Sets the value of a bool field.
184 * @param self The message into which to set the field.
185 * @param field The field to set.
186 * @param value The to set in the field.
188 void GPBSetMessageBoolField(GPBMessage *self, GPBFieldDescriptor *field, BOOL value);
191 * Gets the value of an int32 field.
193 * @param self The message from which to get the field.
194 * @param field The field to get.
196 int32_t GPBGetMessageInt32Field(GPBMessage *self, GPBFieldDescriptor *field);
199 * Sets the value of an int32 field.
201 * @param self The message into which to set the field.
202 * @param field The field to set.
203 * @param value The to set in the field.
205 void GPBSetMessageInt32Field(GPBMessage *self, GPBFieldDescriptor *field, int32_t value);
208 * Gets the value of an uint32 field.
210 * @param self The message from which to get the field.
211 * @param field The field to get.
213 uint32_t GPBGetMessageUInt32Field(GPBMessage *self, GPBFieldDescriptor *field);
216 * Sets the value of an uint32 field.
218 * @param self The message into which to set the field.
219 * @param field The field to set.
220 * @param value The to set in the field.
222 void GPBSetMessageUInt32Field(GPBMessage *self, GPBFieldDescriptor *field, uint32_t value);
225 * Gets the value of an int64 field.
227 * @param self The message from which to get the field.
228 * @param field The field to get.
230 int64_t GPBGetMessageInt64Field(GPBMessage *self, GPBFieldDescriptor *field);
233 * Sets the value of an int64 field.
235 * @param self The message into which to set the field.
236 * @param field The field to set.
237 * @param value The to set in the field.
239 void GPBSetMessageInt64Field(GPBMessage *self, GPBFieldDescriptor *field, int64_t value);
242 * Gets the value of an uint64 field.
244 * @param self The message from which to get the field.
245 * @param field The field to get.
247 uint64_t GPBGetMessageUInt64Field(GPBMessage *self, GPBFieldDescriptor *field);
250 * Sets the value of an uint64 field.
252 * @param self The message into which to set the field.
253 * @param field The field to set.
254 * @param value The to set in the field.
256 void GPBSetMessageUInt64Field(GPBMessage *self, GPBFieldDescriptor *field, uint64_t value);
259 * Gets the value of a float field.
261 * @param self The message from which to get the field.
262 * @param field The field to get.
264 float GPBGetMessageFloatField(GPBMessage *self, GPBFieldDescriptor *field);
267 * Sets the value of a float field.
269 * @param self The message into which to set the field.
270 * @param field The field to set.
271 * @param value The to set in the field.
273 void GPBSetMessageFloatField(GPBMessage *self, GPBFieldDescriptor *field, float value);
276 * Gets the value of a double field.
278 * @param self The message from which to get the field.
279 * @param field The field to get.
281 double GPBGetMessageDoubleField(GPBMessage *self, GPBFieldDescriptor *field);
284 * Sets the value of a double field.
286 * @param self The message into which to set the field.
287 * @param field The field to set.
288 * @param value The to set in the field.
290 void GPBSetMessageDoubleField(GPBMessage *self, GPBFieldDescriptor *field, double value);
293 * Gets the given enum field of a message. For proto3, if the value isn't a
294 * member of the enum, @c kGPBUnrecognizedEnumeratorValue will be returned.
295 * GPBGetMessageRawEnumField will bypass the check and return whatever value
298 * @param self The message from which to get the field.
299 * @param field The field to get.
301 * @return The enum value for the given field.
303 int32_t GPBGetMessageEnumField(GPBMessage *self, GPBFieldDescriptor *field);
306 * Set the given enum field of a message. You can only set values that are
307 * members of the enum.
309 * @param self The message into which to set the field.
310 * @param field The field to set.
311 * @param value The enum value to set in the field.
313 void GPBSetMessageEnumField(GPBMessage *self,
314 GPBFieldDescriptor *field,
318 * Get the given enum field of a message. No check is done to ensure the value
319 * was defined in the enum.
321 * @param self The message from which to get the field.
322 * @param field The field to get.
324 * @return The raw enum value for the given field.
326 int32_t GPBGetMessageRawEnumField(GPBMessage *self, GPBFieldDescriptor *field);
329 * Set the given enum field of a message. You can set the value to anything,
330 * even a value that is not a member of the enum.
332 * @param self The message into which to set the field.
333 * @param field The field to set.
334 * @param value The raw enum value to set in the field.
336 void GPBSetMessageRawEnumField(GPBMessage *self,
337 GPBFieldDescriptor *field,
343 * Gets the value of a repeated field.
345 * @param self The message from which to get the field.
346 * @param field The repeated field to get.
348 * @return A GPB*Array or an NSMutableArray based on the field's type.
350 id GPBGetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field);
353 * Sets the value of a repeated field.
355 * @param self The message into which to set the field.
356 * @param field The field to set.
357 * @param array A GPB*Array or NSMutableArray based on the field's type.
359 void GPBSetMessageRepeatedField(GPBMessage *self,
360 GPBFieldDescriptor *field,
366 * Gets the value of a map<> field.
368 * @param self The message from which to get the field.
369 * @param field The repeated field to get.
371 * @return A GPB*Dictionary or NSMutableDictionary based on the field's type.
373 id GPBGetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field);
376 * Sets the value of a map<> field.
378 * @param self The message into which to set the field.
379 * @param field The field to set.
380 * @param dictionary A GPB*Dictionary or NSMutableDictionary based on the
383 void GPBSetMessageMapField(GPBMessage *self,
384 GPBFieldDescriptor *field,
387 //%PDDM-EXPAND-END GPB_ACCESSORS()
390 * Returns an empty NSData to assign to byte fields when you wish to assign them
391 * to empty. Prevents allocating a lot of little [NSData data] objects.
393 NSData *GPBEmptyNSData(void) __attribute__((pure));
396 * Drops the `unknownFields` from the given message and from all sub message.
398 void GPBMessageDropUnknownFieldsRecursively(GPBMessage *message);
400 NS_ASSUME_NONNULL_END
405 //%PDDM-DEFINE GPB_ACCESSORS()
408 //%// Get/Set a given field from/to a message.
413 //%GPB_ACCESSOR_SINGLE_FULL(Bytes, NSData, , *)
414 //%GPB_ACCESSOR_SINGLE_FULL(String, NSString, , *)
415 //%GPB_ACCESSOR_SINGLE_FULL(Message, GPBMessage, , *)
416 //%GPB_ACCESSOR_SINGLE_FULL(Group, GPBMessage, , *)
417 //%GPB_ACCESSOR_SINGLE(Bool, BOOL, )
418 //%GPB_ACCESSOR_SINGLE(Int32, int32_t, n)
419 //%GPB_ACCESSOR_SINGLE(UInt32, uint32_t, n)
420 //%GPB_ACCESSOR_SINGLE(Int64, int64_t, n)
421 //%GPB_ACCESSOR_SINGLE(UInt64, uint64_t, n)
422 //%GPB_ACCESSOR_SINGLE(Float, float, )
423 //%GPB_ACCESSOR_SINGLE(Double, double, )
425 //% * Gets the given enum field of a message. For proto3, if the value isn't a
426 //% * member of the enum, @c kGPBUnrecognizedEnumeratorValue will be returned.
427 //% * GPBGetMessageRawEnumField will bypass the check and return whatever value
430 //% * @param self The message from which to get the field.
431 //% * @param field The field to get.
433 //% * @return The enum value for the given field.
435 //%int32_t GPBGetMessageEnumField(GPBMessage *self, GPBFieldDescriptor *field);
438 //% * Set the given enum field of a message. You can only set values that are
439 //% * members of the enum.
441 //% * @param self The message into which to set the field.
442 //% * @param field The field to set.
443 //% * @param value The enum value to set in the field.
445 //%void GPBSetMessageEnumField(GPBMessage *self,
446 //% GPBFieldDescriptor *field,
450 //% * Get the given enum field of a message. No check is done to ensure the value
451 //% * was defined in the enum.
453 //% * @param self The message from which to get the field.
454 //% * @param field The field to get.
456 //% * @return The raw enum value for the given field.
458 //%int32_t GPBGetMessageRawEnumField(GPBMessage *self, GPBFieldDescriptor *field);
461 //% * Set the given enum field of a message. You can set the value to anything,
462 //% * even a value that is not a member of the enum.
464 //% * @param self The message into which to set the field.
465 //% * @param field The field to set.
466 //% * @param value The raw enum value to set in the field.
468 //%void GPBSetMessageRawEnumField(GPBMessage *self,
469 //% GPBFieldDescriptor *field,
472 //%// Repeated Fields
475 //% * Gets the value of a repeated field.
477 //% * @param self The message from which to get the field.
478 //% * @param field The repeated field to get.
480 //% * @return A GPB*Array or an NSMutableArray based on the field's type.
482 //%id GPBGetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field);
485 //% * Sets the value of a repeated field.
487 //% * @param self The message into which to set the field.
488 //% * @param field The field to set.
489 //% * @param array A GPB*Array or NSMutableArray based on the field's type.
491 //%void GPBSetMessageRepeatedField(GPBMessage *self,
492 //% GPBFieldDescriptor *field,
498 //% * Gets the value of a map<> field.
500 //% * @param self The message from which to get the field.
501 //% * @param field The repeated field to get.
503 //% * @return A GPB*Dictionary or NSMutableDictionary based on the field's type.
505 //%id GPBGetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field);
508 //% * Sets the value of a map<> field.
510 //% * @param self The message into which to set the field.
511 //% * @param field The field to set.
512 //% * @param dictionary A GPB*Dictionary or NSMutableDictionary based on the
515 //%void GPBSetMessageMapField(GPBMessage *self,
516 //% GPBFieldDescriptor *field,
520 //%PDDM-DEFINE GPB_ACCESSOR_SINGLE(NAME, TYPE, AN)
521 //%GPB_ACCESSOR_SINGLE_FULL(NAME, TYPE, AN, )
522 //%PDDM-DEFINE GPB_ACCESSOR_SINGLE_FULL(NAME, TYPE, AN, TisP)
524 //% * Gets the value of a##AN NAME$L field.
526 //% * @param self The message from which to get the field.
527 //% * @param field The field to get.
529 //%TYPE TisP##GPBGetMessage##NAME##Field(GPBMessage *self, GPBFieldDescriptor *field);
532 //% * Sets the value of a##AN NAME$L field.
534 //% * @param self The message into which to set the field.
535 //% * @param field The field to set.
536 //% * @param value The to set in the field.
538 //%void GPBSetMessage##NAME##Field(GPBMessage *self, GPBFieldDescriptor *field, TYPE TisP##value);