• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 @class GPBOneofDescriptor;
38 
39 CF_EXTERN_C_BEGIN
40 
41 NS_ASSUME_NONNULL_BEGIN
42 
43 /**
44  * Generates a string that should be a valid "TextFormat" for the C++ version
45  * of Protocol Buffers.
46  *
47  * @param message    The message to generate from.
48  * @param lineIndent A string to use as the prefix for all lines generated. Can
49  *                   be nil if no extra indent is needed.
50  *
51  * @return An NSString with the TextFormat of the message.
52  **/
53 NSString *GPBTextFormatForMessage(GPBMessage *message,
54                                   NSString * __nullable lineIndent);
55 
56 /**
57  * Generates a string that should be a valid "TextFormat" for the C++ version
58  * of Protocol Buffers.
59  *
60  * @param unknownSet The unknown field set to generate from.
61  * @param lineIndent A string to use as the prefix for all lines generated. Can
62  *                   be nil if no extra indent is needed.
63  *
64  * @return An NSString with the TextFormat of the unknown field set.
65  **/
66 NSString *GPBTextFormatForUnknownFieldSet(GPBUnknownFieldSet * __nullable unknownSet,
67                                           NSString * __nullable lineIndent);
68 
69 /**
70  * Checks if the given field number is set on a message.
71  *
72  * @param self        The message to check.
73  * @param fieldNumber The field number to check.
74  *
75  * @return YES if the field number is set on the given message.
76  **/
77 BOOL GPBMessageHasFieldNumberSet(GPBMessage *self, uint32_t fieldNumber);
78 
79 /**
80  * Checks if the given field is set on a message.
81  *
82  * @param self  The message to check.
83  * @param field The field to check.
84  *
85  * @return YES if the field is set on the given message.
86  **/
87 BOOL GPBMessageHasFieldSet(GPBMessage *self, GPBFieldDescriptor *field);
88 
89 /**
90  * Clears the given field for the given message.
91  *
92  * @param self  The message for which to clear the field.
93  * @param field The field to clear.
94  **/
95 void GPBClearMessageField(GPBMessage *self, GPBFieldDescriptor *field);
96 
97 /**
98  * Clears the given oneof field for the given message.
99  *
100  * @param self  The message for which to clear the field.
101  * @param oneof The oneof to clear.
102  **/
103 void GPBClearOneof(GPBMessage *self, GPBOneofDescriptor *oneof);
104 
105 //%PDDM-EXPAND GPB_ACCESSORS()
106 // This block of code is generated, do not edit it directly.
107 // clang-format off
108 
109 
110 //
111 // Get/Set a given field from/to a message.
112 //
113 
114 // Single Fields
115 
116 /**
117  * Gets the value of a bytes field.
118  *
119  * @param self  The message from which to get the field.
120  * @param field The field to get.
121  **/
122 NSData *GPBGetMessageBytesField(GPBMessage *self, GPBFieldDescriptor *field);
123 
124 /**
125  * Sets the value of a bytes field.
126  *
127  * @param self  The message into which to set the field.
128  * @param field The field to set.
129  * @param value The to set in the field.
130  **/
131 void GPBSetMessageBytesField(GPBMessage *self, GPBFieldDescriptor *field, NSData *value);
132 
133 /**
134  * Gets the value of a string field.
135  *
136  * @param self  The message from which to get the field.
137  * @param field The field to get.
138  **/
139 NSString *GPBGetMessageStringField(GPBMessage *self, GPBFieldDescriptor *field);
140 
141 /**
142  * Sets the value of a string field.
143  *
144  * @param self  The message into which to set the field.
145  * @param field The field to set.
146  * @param value The to set in the field.
147  **/
148 void GPBSetMessageStringField(GPBMessage *self, GPBFieldDescriptor *field, NSString *value);
149 
150 /**
151  * Gets the value of a message field.
152  *
153  * @param self  The message from which to get the field.
154  * @param field The field to get.
155  **/
156 GPBMessage *GPBGetMessageMessageField(GPBMessage *self, GPBFieldDescriptor *field);
157 
158 /**
159  * Sets the value of a message field.
160  *
161  * @param self  The message into which to set the field.
162  * @param field The field to set.
163  * @param value The to set in the field.
164  **/
165 void GPBSetMessageMessageField(GPBMessage *self, GPBFieldDescriptor *field, GPBMessage *value);
166 
167 /**
168  * Gets the value of a group field.
169  *
170  * @param self  The message from which to get the field.
171  * @param field The field to get.
172  **/
173 GPBMessage *GPBGetMessageGroupField(GPBMessage *self, GPBFieldDescriptor *field);
174 
175 /**
176  * Sets the value of a group field.
177  *
178  * @param self  The message into which to set the field.
179  * @param field The field to set.
180  * @param value The to set in the field.
181  **/
182 void GPBSetMessageGroupField(GPBMessage *self, GPBFieldDescriptor *field, GPBMessage *value);
183 
184 /**
185  * Gets the value of a bool field.
186  *
187  * @param self  The message from which to get the field.
188  * @param field The field to get.
189  **/
190 BOOL GPBGetMessageBoolField(GPBMessage *self, GPBFieldDescriptor *field);
191 
192 /**
193  * Sets the value of a bool field.
194  *
195  * @param self  The message into which to set the field.
196  * @param field The field to set.
197  * @param value The to set in the field.
198  **/
199 void GPBSetMessageBoolField(GPBMessage *self, GPBFieldDescriptor *field, BOOL value);
200 
201 /**
202  * Gets the value of an int32 field.
203  *
204  * @param self  The message from which to get the field.
205  * @param field The field to get.
206  **/
207 int32_t GPBGetMessageInt32Field(GPBMessage *self, GPBFieldDescriptor *field);
208 
209 /**
210  * Sets the value of an int32 field.
211  *
212  * @param self  The message into which to set the field.
213  * @param field The field to set.
214  * @param value The to set in the field.
215  **/
216 void GPBSetMessageInt32Field(GPBMessage *self, GPBFieldDescriptor *field, int32_t value);
217 
218 /**
219  * Gets the value of an uint32 field.
220  *
221  * @param self  The message from which to get the field.
222  * @param field The field to get.
223  **/
224 uint32_t GPBGetMessageUInt32Field(GPBMessage *self, GPBFieldDescriptor *field);
225 
226 /**
227  * Sets the value of an uint32 field.
228  *
229  * @param self  The message into which to set the field.
230  * @param field The field to set.
231  * @param value The to set in the field.
232  **/
233 void GPBSetMessageUInt32Field(GPBMessage *self, GPBFieldDescriptor *field, uint32_t value);
234 
235 /**
236  * Gets the value of an int64 field.
237  *
238  * @param self  The message from which to get the field.
239  * @param field The field to get.
240  **/
241 int64_t GPBGetMessageInt64Field(GPBMessage *self, GPBFieldDescriptor *field);
242 
243 /**
244  * Sets the value of an int64 field.
245  *
246  * @param self  The message into which to set the field.
247  * @param field The field to set.
248  * @param value The to set in the field.
249  **/
250 void GPBSetMessageInt64Field(GPBMessage *self, GPBFieldDescriptor *field, int64_t value);
251 
252 /**
253  * Gets the value of an uint64 field.
254  *
255  * @param self  The message from which to get the field.
256  * @param field The field to get.
257  **/
258 uint64_t GPBGetMessageUInt64Field(GPBMessage *self, GPBFieldDescriptor *field);
259 
260 /**
261  * Sets the value of an uint64 field.
262  *
263  * @param self  The message into which to set the field.
264  * @param field The field to set.
265  * @param value The to set in the field.
266  **/
267 void GPBSetMessageUInt64Field(GPBMessage *self, GPBFieldDescriptor *field, uint64_t value);
268 
269 /**
270  * Gets the value of a float field.
271  *
272  * @param self  The message from which to get the field.
273  * @param field The field to get.
274  **/
275 float GPBGetMessageFloatField(GPBMessage *self, GPBFieldDescriptor *field);
276 
277 /**
278  * Sets the value of a float field.
279  *
280  * @param self  The message into which to set the field.
281  * @param field The field to set.
282  * @param value The to set in the field.
283  **/
284 void GPBSetMessageFloatField(GPBMessage *self, GPBFieldDescriptor *field, float value);
285 
286 /**
287  * Gets the value of a double field.
288  *
289  * @param self  The message from which to get the field.
290  * @param field The field to get.
291  **/
292 double GPBGetMessageDoubleField(GPBMessage *self, GPBFieldDescriptor *field);
293 
294 /**
295  * Sets the value of a double field.
296  *
297  * @param self  The message into which to set the field.
298  * @param field The field to set.
299  * @param value The to set in the field.
300  **/
301 void GPBSetMessageDoubleField(GPBMessage *self, GPBFieldDescriptor *field, double value);
302 
303 /**
304  * Gets the given enum field of a message. For proto3, if the value isn't a
305  * member of the enum, @c kGPBUnrecognizedEnumeratorValue will be returned.
306  * GPBGetMessageRawEnumField will bypass the check and return whatever value
307  * was set.
308  *
309  * @param self  The message from which to get the field.
310  * @param field The field to get.
311  *
312  * @return The enum value for the given field.
313  **/
314 int32_t GPBGetMessageEnumField(GPBMessage *self, GPBFieldDescriptor *field);
315 
316 /**
317  * Set the given enum field of a message. You can only set values that are
318  * members of the enum.
319  *
320  * @param self  The message into which to set the field.
321  * @param field The field to set.
322  * @param value The enum value to set in the field.
323  **/
324 void GPBSetMessageEnumField(GPBMessage *self,
325                             GPBFieldDescriptor *field,
326                             int32_t value);
327 
328 /**
329  * Get the given enum field of a message. No check is done to ensure the value
330  * was defined in the enum.
331  *
332  * @param self  The message from which to get the field.
333  * @param field The field to get.
334  *
335  * @return The raw enum value for the given field.
336  **/
337 int32_t GPBGetMessageRawEnumField(GPBMessage *self, GPBFieldDescriptor *field);
338 
339 /**
340  * Set the given enum field of a message. You can set the value to anything,
341  * even a value that is not a member of the enum.
342  *
343  * @param self  The message into which to set the field.
344  * @param field The field to set.
345  * @param value The raw enum value to set in the field.
346  **/
347 void GPBSetMessageRawEnumField(GPBMessage *self,
348                                GPBFieldDescriptor *field,
349                                int32_t value);
350 
351 // Repeated Fields
352 
353 /**
354  * Gets the value of a repeated field.
355  *
356  * @param self  The message from which to get the field.
357  * @param field The repeated field to get.
358  *
359  * @return A GPB*Array or an NSMutableArray based on the field's type.
360  **/
361 id GPBGetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field);
362 
363 /**
364  * Sets the value of a repeated field.
365  *
366  * @param self  The message into which to set the field.
367  * @param field The field to set.
368  * @param array A GPB*Array or NSMutableArray based on the field's type.
369  **/
370 void GPBSetMessageRepeatedField(GPBMessage *self,
371                                 GPBFieldDescriptor *field,
372                                 id array);
373 
374 // Map Fields
375 
376 /**
377  * Gets the value of a map<> field.
378  *
379  * @param self  The message from which to get the field.
380  * @param field The repeated field to get.
381  *
382  * @return A GPB*Dictionary or NSMutableDictionary based on the field's type.
383  **/
384 id GPBGetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field);
385 
386 /**
387  * Sets the value of a map<> field.
388  *
389  * @param self       The message into which to set the field.
390  * @param field      The field to set.
391  * @param dictionary A GPB*Dictionary or NSMutableDictionary based on the
392  *                   field's type.
393  **/
394 void GPBSetMessageMapField(GPBMessage *self,
395                            GPBFieldDescriptor *field,
396                            id dictionary);
397 
398 // clang-format on
399 //%PDDM-EXPAND-END GPB_ACCESSORS()
400 
401 /**
402  * Returns an empty NSData to assign to byte fields when you wish to assign them
403  * to empty. Prevents allocating a lot of little [NSData data] objects.
404  **/
405 NSData *GPBEmptyNSData(void) __attribute__((pure));
406 
407 /**
408  * Drops the `unknownFields` from the given message and from all sub message.
409  **/
410 void GPBMessageDropUnknownFieldsRecursively(GPBMessage *message);
411 
412 NS_ASSUME_NONNULL_END
413 
414 CF_EXTERN_C_END
415 
416 
417 //%PDDM-DEFINE GPB_ACCESSORS()
418 //%
419 //%//
420 //%// Get/Set a given field from/to a message.
421 //%//
422 //%
423 //%// Single Fields
424 //%
425 //%GPB_ACCESSOR_SINGLE_FULL(Bytes, NSData, , *)
426 //%GPB_ACCESSOR_SINGLE_FULL(String, NSString, , *)
427 //%GPB_ACCESSOR_SINGLE_FULL(Message, GPBMessage, , *)
428 //%GPB_ACCESSOR_SINGLE_FULL(Group, GPBMessage, , *)
429 //%GPB_ACCESSOR_SINGLE(Bool, BOOL, )
430 //%GPB_ACCESSOR_SINGLE(Int32, int32_t, n)
431 //%GPB_ACCESSOR_SINGLE(UInt32, uint32_t, n)
432 //%GPB_ACCESSOR_SINGLE(Int64, int64_t, n)
433 //%GPB_ACCESSOR_SINGLE(UInt64, uint64_t, n)
434 //%GPB_ACCESSOR_SINGLE(Float, float, )
435 //%GPB_ACCESSOR_SINGLE(Double, double, )
436 //%/**
437 //% * Gets the given enum field of a message. For proto3, if the value isn't a
438 //% * member of the enum, @c kGPBUnrecognizedEnumeratorValue will be returned.
439 //% * GPBGetMessageRawEnumField will bypass the check and return whatever value
440 //% * was set.
441 //% *
442 //% * @param self  The message from which to get the field.
443 //% * @param field The field to get.
444 //% *
445 //% * @return The enum value for the given field.
446 //% **/
447 //%int32_t GPBGetMessageEnumField(GPBMessage *self, GPBFieldDescriptor *field);
448 //%
449 //%/**
450 //% * Set the given enum field of a message. You can only set values that are
451 //% * members of the enum.
452 //% *
453 //% * @param self  The message into which to set the field.
454 //% * @param field The field to set.
455 //% * @param value The enum value to set in the field.
456 //% **/
457 //%void GPBSetMessageEnumField(GPBMessage *self,
458 //%                            GPBFieldDescriptor *field,
459 //%                            int32_t value);
460 //%
461 //%/**
462 //% * Get the given enum field of a message. No check is done to ensure the value
463 //% * was defined in the enum.
464 //% *
465 //% * @param self  The message from which to get the field.
466 //% * @param field The field to get.
467 //% *
468 //% * @return The raw enum value for the given field.
469 //% **/
470 //%int32_t GPBGetMessageRawEnumField(GPBMessage *self, GPBFieldDescriptor *field);
471 //%
472 //%/**
473 //% * Set the given enum field of a message. You can set the value to anything,
474 //% * even a value that is not a member of the enum.
475 //% *
476 //% * @param self  The message into which to set the field.
477 //% * @param field The field to set.
478 //% * @param value The raw enum value to set in the field.
479 //% **/
480 //%void GPBSetMessageRawEnumField(GPBMessage *self,
481 //%                               GPBFieldDescriptor *field,
482 //%                               int32_t value);
483 //%
484 //%// Repeated Fields
485 //%
486 //%/**
487 //% * Gets the value of a repeated field.
488 //% *
489 //% * @param self  The message from which to get the field.
490 //% * @param field The repeated field to get.
491 //% *
492 //% * @return A GPB*Array or an NSMutableArray based on the field's type.
493 //% **/
494 //%id GPBGetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field);
495 //%
496 //%/**
497 //% * Sets the value of a repeated field.
498 //% *
499 //% * @param self  The message into which to set the field.
500 //% * @param field The field to set.
501 //% * @param array A GPB*Array or NSMutableArray based on the field's type.
502 //% **/
503 //%void GPBSetMessageRepeatedField(GPBMessage *self,
504 //%                                GPBFieldDescriptor *field,
505 //%                                id array);
506 //%
507 //%// Map Fields
508 //%
509 //%/**
510 //% * Gets the value of a map<> field.
511 //% *
512 //% * @param self  The message from which to get the field.
513 //% * @param field The repeated field to get.
514 //% *
515 //% * @return A GPB*Dictionary or NSMutableDictionary based on the field's type.
516 //% **/
517 //%id GPBGetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field);
518 //%
519 //%/**
520 //% * Sets the value of a map<> field.
521 //% *
522 //% * @param self       The message into which to set the field.
523 //% * @param field      The field to set.
524 //% * @param dictionary A GPB*Dictionary or NSMutableDictionary based on the
525 //% *                   field's type.
526 //% **/
527 //%void GPBSetMessageMapField(GPBMessage *self,
528 //%                           GPBFieldDescriptor *field,
529 //%                           id dictionary);
530 //%
531 
532 //%PDDM-DEFINE GPB_ACCESSOR_SINGLE(NAME, TYPE, AN)
533 //%GPB_ACCESSOR_SINGLE_FULL(NAME, TYPE, AN, )
534 //%PDDM-DEFINE GPB_ACCESSOR_SINGLE_FULL(NAME, TYPE, AN, TisP)
535 //%/**
536 //% * Gets the value of a##AN NAME$L field.
537 //% *
538 //% * @param self  The message from which to get the field.
539 //% * @param field The field to get.
540 //% **/
541 //%TYPE TisP##GPBGetMessage##NAME##Field(GPBMessage *self, GPBFieldDescriptor *field);
542 //%
543 //%/**
544 //% * Sets the value of a##AN NAME$L field.
545 //% *
546 //% * @param self  The message into which to set the field.
547 //% * @param field The field to set.
548 //% * @param value The to set in the field.
549 //% **/
550 //%void GPBSetMessage##NAME##Field(GPBMessage *self, GPBFieldDescriptor *field, TYPE TisP##value);
551 //%
552