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