Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 1 | // Protocol Buffers - Google's data interchange format |
| 2 | // Copyright 2008 Google Inc. All rights reserved. |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 3 | // |
Joshua Haberman | 44bd65b | 2023-09-08 17:43:14 -0700 | [diff] [blame] | 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 |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 7 | |
Thomas Van Lenten | 1dcc329 | 2015-05-21 17:14:52 -0400 | [diff] [blame] | 8 | #import <Foundation/Foundation.h> |
| 9 | |
| 10 | #import "GPBBootstrap.h" |
Thomas Van Lenten | 5392dc1 | 2022-09-19 16:06:12 -0400 | [diff] [blame] | 11 | #import "GPBExtensionRegistry.h" |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 12 | |
| 13 | @class GPBDescriptor; |
| 14 | @class GPBCodedInputStream; |
| 15 | @class GPBCodedOutputStream; |
Thomas Van Lenten | d846b0b | 2015-06-08 16:24:57 -0400 | [diff] [blame] | 16 | @class GPBExtensionDescriptor; |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 17 | @class GPBFieldDescriptor; |
| 18 | @class GPBUnknownFieldSet; |
| 19 | |
Thomas Van Lenten | 8c88957 | 2015-06-16 16:45:14 -0400 | [diff] [blame] | 20 | NS_ASSUME_NONNULL_BEGIN |
| 21 | |
Thomas Van Lenten | 1dcc329 | 2015-05-21 17:14:52 -0400 | [diff] [blame] | 22 | CF_EXTERN_C_BEGIN |
| 23 | |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 24 | /** NSError domain used for errors. */ |
Thomas Van Lenten | 1dcc329 | 2015-05-21 17:14:52 -0400 | [diff] [blame] | 25 | extern NSString *const GPBMessageErrorDomain; |
| 26 | |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 27 | /** Error codes for NSErrors originated in GPBMessage. */ |
Thomas Van Lenten | 1dcc329 | 2015-05-21 17:14:52 -0400 | [diff] [blame] | 28 | typedef NS_ENUM(NSInteger, GPBMessageErrorCode) { |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 29 | /** Uncategorized error. */ |
Sergio Campamá | e34c091 | 2016-06-02 11:14:26 -0700 | [diff] [blame] | 30 | GPBMessageErrorCodeOther = -100, |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 31 | /** Message couldn't be serialized because it is missing required fields. */ |
Thomas Van Lenten | 1dcc329 | 2015-05-21 17:14:52 -0400 | [diff] [blame] | 32 | GPBMessageErrorCodeMissingRequiredField = -101, |
| 33 | }; |
| 34 | |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 35 | /** |
| 36 | * Key under which the GPBMessage error's reason is stored inside the userInfo |
| 37 | * dictionary. |
| 38 | **/ |
Sergio Campamá | e34c091 | 2016-06-02 11:14:26 -0700 | [diff] [blame] | 39 | extern NSString *const GPBErrorReasonKey; |
| 40 | |
Protobuf Team Bot | e6d01b2 | 2023-02-22 05:54:19 -0800 | [diff] [blame] | 41 | /** |
| 42 | * An exception name raised during serialization when the message would be |
| 43 | * larger than the 2GB limit. |
| 44 | **/ |
| 45 | extern NSString *const GPBMessageExceptionMessageTooLarge; |
| 46 | |
Thomas Van Lenten | 1dcc329 | 2015-05-21 17:14:52 -0400 | [diff] [blame] | 47 | CF_EXTERN_C_END |
| 48 | |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 49 | /** |
| 50 | * Base class that each generated message subclasses from. |
Thomas Van Lenten | 98c0185 | 2016-10-31 10:43:46 -0400 | [diff] [blame] | 51 | * |
Thomas Van Lenten | 5e4f14f | 2017-03-15 10:50:31 -0400 | [diff] [blame] | 52 | * @note @c NSCopying support is a "deep copy", in that all sub objects are |
| 53 | * copied. Just like you wouldn't want a UIView/NSView trying to |
| 54 | * exist in two places, you don't want a sub message to be a property |
| 55 | * property of two other messages. |
| 56 | * |
Thomas Van Lenten | 98c0185 | 2016-10-31 10:43:46 -0400 | [diff] [blame] | 57 | * @note While the class support NSSecureCoding, if the message has any |
| 58 | * extensions, they will end up reloaded in @c unknownFields as there is |
| 59 | * no way for the @c NSCoding plumbing to pass through a |
| 60 | * @c GPBExtensionRegistry. To support extensions, instead of passing the |
| 61 | * calls off to the Message, simple store the result of @c data, and then |
| 62 | * when loading, fetch the data and use |
| 63 | * @c +parseFromData:extensionRegistry:error: to provide an extension |
| 64 | * registry. |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 65 | **/ |
Thomas Van Lenten | 5d0b217 | 2022-09-19 17:20:35 -0400 | [diff] [blame] | 66 | @interface GPBMessage : NSObject <NSSecureCoding, NSCopying> |
Thomas Van Lenten | 98c0185 | 2016-10-31 10:43:46 -0400 | [diff] [blame] | 67 | |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 68 | // If you add an instance method/property to this class that may conflict with |
| 69 | // fields declared in protos, you need to update objective_helpers.cc. The main |
| 70 | // cases are methods that take no arguments, or setFoo:/hasFoo: type methods. |
Thomas Van Lenten | 1dcc329 | 2015-05-21 17:14:52 -0400 | [diff] [blame] | 71 | |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 72 | /** |
| 73 | * The set of unknown fields for this message. |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 74 | **/ |
Thomas Van Lenten | 8c88957 | 2015-06-16 16:45:14 -0400 | [diff] [blame] | 75 | @property(nonatomic, copy, nullable) GPBUnknownFieldSet *unknownFields; |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 76 | |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 77 | /** |
| 78 | * Whether the message, along with all submessages, have the required fields |
Protobuf Team Bot | d4e1327 | 2022-11-14 07:46:23 -0800 | [diff] [blame] | 79 | * set. |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 80 | **/ |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 81 | @property(nonatomic, readonly, getter=isInitialized) BOOL initialized; |
| 82 | |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 83 | /** |
| 84 | * @return An autoreleased message with the default values set. |
| 85 | **/ |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 86 | + (instancetype)message; |
| 87 | |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 88 | /** |
| 89 | * Creates a new instance by parsing the provided data. This method should be |
| 90 | * sent to the generated message class that the data should be interpreted as. |
| 91 | * If there is an error the method returns nil and the error is returned in |
| 92 | * errorPtr (when provided). |
| 93 | * |
| 94 | * @note In DEBUG builds, the parsed message is checked to be sure all required |
| 95 | * fields were provided, and the parse will fail if some are missing. |
| 96 | * |
| 97 | * @note The errors returned are likely coming from the domain and codes listed |
| 98 | * at the top of this file and GPBCodedInputStream.h. |
| 99 | * |
| 100 | * @param data The data to parse. |
| 101 | * @param errorPtr An optional error pointer to fill in with a failure reason if |
| 102 | * the data can not be parsed. |
| 103 | * |
| 104 | * @return A new instance of the generated class. |
| 105 | **/ |
Dia Kharrat | 523bfd4 | 2016-06-24 00:05:02 -0700 | [diff] [blame] | 106 | + (nullable instancetype)parseFromData:(NSData *)data error:(NSError **)errorPtr; |
Thomas Van Lenten | 36650a0 | 2016-03-07 12:07:03 -0500 | [diff] [blame] | 107 | |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 108 | /** |
| 109 | * Creates a new instance by parsing the data. This method should be sent to |
| 110 | * the generated message class that the data should be interpreted as. If |
| 111 | * there is an error the method returns nil and the error is returned in |
| 112 | * errorPtr (when provided). |
| 113 | * |
| 114 | * @note In DEBUG builds, the parsed message is checked to be sure all required |
| 115 | * fields were provided, and the parse will fail if some are missing. |
| 116 | * |
| 117 | * @note The errors returned are likely coming from the domain and codes listed |
| 118 | * at the top of this file and GPBCodedInputStream.h. |
| 119 | * |
| 120 | * @param data The data to parse. |
| 121 | * @param extensionRegistry The extension registry to use to look up extensions. |
| 122 | * @param errorPtr An optional error pointer to fill in with a failure |
| 123 | * reason if the data can not be parsed. |
| 124 | * |
| 125 | * @return A new instance of the generated class. |
| 126 | **/ |
Dia Kharrat | 523bfd4 | 2016-06-24 00:05:02 -0700 | [diff] [blame] | 127 | + (nullable instancetype)parseFromData:(NSData *)data |
Thomas Van Lenten | f191ab0 | 2022-09-15 14:40:15 -0400 | [diff] [blame] | 128 | extensionRegistry:(nullable id<GPBExtensionRegistry>)extensionRegistry |
Dia Kharrat | 523bfd4 | 2016-06-24 00:05:02 -0700 | [diff] [blame] | 129 | error:(NSError **)errorPtr; |
Thomas Van Lenten | 36650a0 | 2016-03-07 12:07:03 -0500 | [diff] [blame] | 130 | |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 131 | /** |
| 132 | * Creates a new instance by parsing the data from the given input stream. This |
| 133 | * method should be sent to the generated message class that the data should |
| 134 | * be interpreted as. If there is an error the method returns nil and the error |
| 135 | * is returned in errorPtr (when provided). |
| 136 | * |
| 137 | * @note In DEBUG builds, the parsed message is checked to be sure all required |
| 138 | * fields were provided, and the parse will fail if some are missing. |
| 139 | * |
| 140 | * @note The errors returned are likely coming from the domain and codes listed |
| 141 | * at the top of this file and GPBCodedInputStream.h. |
| 142 | * |
| 143 | * @param input The stream to read data from. |
| 144 | * @param extensionRegistry The extension registry to use to look up extensions. |
| 145 | * @param errorPtr An optional error pointer to fill in with a failure |
| 146 | * reason if the data can not be parsed. |
| 147 | * |
| 148 | * @return A new instance of the generated class. |
| 149 | **/ |
Dia Kharrat | 523bfd4 | 2016-06-24 00:05:02 -0700 | [diff] [blame] | 150 | + (nullable instancetype)parseFromCodedInputStream:(GPBCodedInputStream *)input |
| 151 | extensionRegistry: |
Thomas Van Lenten | f191ab0 | 2022-09-15 14:40:15 -0400 | [diff] [blame] | 152 | (nullable id<GPBExtensionRegistry>)extensionRegistry |
Dia Kharrat | 523bfd4 | 2016-06-24 00:05:02 -0700 | [diff] [blame] | 153 | error:(NSError **)errorPtr; |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 154 | |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 155 | /** |
| 156 | * Creates a new instance by parsing the data from the given input stream. This |
| 157 | * method should be sent to the generated message class that the data should |
| 158 | * be interpreted as. If there is an error the method returns nil and the error |
| 159 | * is returned in errorPtr (when provided). |
| 160 | * |
| 161 | * @note Unlike the parseFrom... methods, this never checks to see if all of |
| 162 | * the required fields are set. So this method can be used to reload |
| 163 | * messages that may not be complete. |
| 164 | * |
| 165 | * @note The errors returned are likely coming from the domain and codes listed |
| 166 | * at the top of this file and GPBCodedInputStream.h. |
| 167 | * |
| 168 | * @param input The stream to read data from. |
| 169 | * @param extensionRegistry The extension registry to use to look up extensions. |
| 170 | * @param errorPtr An optional error pointer to fill in with a failure |
| 171 | * reason if the data can not be parsed. |
| 172 | * |
| 173 | * @return A new instance of the generated class. |
| 174 | **/ |
Dia Kharrat | 523bfd4 | 2016-06-24 00:05:02 -0700 | [diff] [blame] | 175 | + (nullable instancetype)parseDelimitedFromCodedInputStream:(GPBCodedInputStream *)input |
| 176 | extensionRegistry: |
Thomas Van Lenten | f191ab0 | 2022-09-15 14:40:15 -0400 | [diff] [blame] | 177 | (nullable id<GPBExtensionRegistry>)extensionRegistry |
Dia Kharrat | 523bfd4 | 2016-06-24 00:05:02 -0700 | [diff] [blame] | 178 | error:(NSError **)errorPtr; |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 179 | |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 180 | /** |
| 181 | * Initializes an instance by parsing the data. This method should be sent to |
| 182 | * the generated message class that the data should be interpreted as. If |
| 183 | * there is an error the method returns nil and the error is returned in |
| 184 | * errorPtr (when provided). |
| 185 | * |
| 186 | * @note In DEBUG builds, the parsed message is checked to be sure all required |
| 187 | * fields were provided, and the parse will fail if some are missing. |
| 188 | * |
| 189 | * @note The errors returned are likely coming from the domain and codes listed |
| 190 | * at the top of this file and GPBCodedInputStream.h. |
| 191 | * |
| 192 | * @param data The data to parse. |
| 193 | * @param errorPtr An optional error pointer to fill in with a failure reason if |
| 194 | * the data can not be parsed. |
| 195 | * |
| 196 | * @return An initialized instance of the generated class. |
| 197 | **/ |
Dia Kharrat | 523bfd4 | 2016-06-24 00:05:02 -0700 | [diff] [blame] | 198 | - (nullable instancetype)initWithData:(NSData *)data error:(NSError **)errorPtr; |
Thomas Van Lenten | 36650a0 | 2016-03-07 12:07:03 -0500 | [diff] [blame] | 199 | |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 200 | /** |
| 201 | * Initializes an instance by parsing the data. This method should be sent to |
| 202 | * the generated message class that the data should be interpreted as. If |
| 203 | * there is an error the method returns nil and the error is returned in |
| 204 | * errorPtr (when provided). |
| 205 | * |
| 206 | * @note In DEBUG builds, the parsed message is checked to be sure all required |
| 207 | * fields were provided, and the parse will fail if some are missing. |
| 208 | * |
| 209 | * @note The errors returned are likely coming from the domain and codes listed |
| 210 | * at the top of this file and GPBCodedInputStream.h. |
| 211 | * |
| 212 | * @param data The data to parse. |
| 213 | * @param extensionRegistry The extension registry to use to look up extensions. |
| 214 | * @param errorPtr An optional error pointer to fill in with a failure |
| 215 | * reason if the data can not be parsed. |
| 216 | * |
| 217 | * @return An initialized instance of the generated class. |
| 218 | **/ |
Dia Kharrat | 523bfd4 | 2016-06-24 00:05:02 -0700 | [diff] [blame] | 219 | - (nullable instancetype)initWithData:(NSData *)data |
Thomas Van Lenten | f191ab0 | 2022-09-15 14:40:15 -0400 | [diff] [blame] | 220 | extensionRegistry:(nullable id<GPBExtensionRegistry>)extensionRegistry |
Dia Kharrat | 523bfd4 | 2016-06-24 00:05:02 -0700 | [diff] [blame] | 221 | error:(NSError **)errorPtr; |
Thomas Van Lenten | 36650a0 | 2016-03-07 12:07:03 -0500 | [diff] [blame] | 222 | |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 223 | /** |
| 224 | * Initializes an instance by parsing the data from the given input stream. This |
| 225 | * method should be sent to the generated message class that the data should |
| 226 | * be interpreted as. If there is an error the method returns nil and the error |
| 227 | * is returned in errorPtr (when provided). |
| 228 | * |
| 229 | * @note Unlike the parseFrom... methods, this never checks to see if all of |
| 230 | * the required fields are set. So this method can be used to reload |
| 231 | * messages that may not be complete. |
| 232 | * |
| 233 | * @note The errors returned are likely coming from the domain and codes listed |
| 234 | * at the top of this file and GPBCodedInputStream.h. |
| 235 | * |
| 236 | * @param input The stream to read data from. |
| 237 | * @param extensionRegistry The extension registry to use to look up extensions. |
| 238 | * @param errorPtr An optional error pointer to fill in with a failure |
| 239 | * reason if the data can not be parsed. |
| 240 | * |
| 241 | * @return An initialized instance of the generated class. |
| 242 | **/ |
Dia Kharrat | 523bfd4 | 2016-06-24 00:05:02 -0700 | [diff] [blame] | 243 | - (nullable instancetype)initWithCodedInputStream:(GPBCodedInputStream *)input |
| 244 | extensionRegistry: |
Thomas Van Lenten | f191ab0 | 2022-09-15 14:40:15 -0400 | [diff] [blame] | 245 | (nullable id<GPBExtensionRegistry>)extensionRegistry |
Dia Kharrat | 523bfd4 | 2016-06-24 00:05:02 -0700 | [diff] [blame] | 246 | error:(NSError **)errorPtr; |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 247 | |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 248 | /** |
| 249 | * Parses the given data as this message's class, and merges those values into |
| 250 | * this message. |
| 251 | * |
| 252 | * @param data The binary representation of the message to merge. |
| 253 | * @param extensionRegistry The extension registry to use to look up extensions. |
| 254 | * |
| 255 | * @exception GPBCodedInputStreamException Exception thrown when parsing was |
| 256 | * unsuccessful. |
| 257 | **/ |
| 258 | - (void)mergeFromData:(NSData *)data |
Protobuf Team Bot | e3b0051 | 2023-02-21 11:45:16 -0800 | [diff] [blame] | 259 | extensionRegistry:(nullable id<GPBExtensionRegistry>)extensionRegistry |
| 260 | __attribute__((deprecated( |
| 261 | "Use -mergeFromData:extensionRegistry:error: instead, especaily if calling from Swift."))); |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 262 | |
| 263 | /** |
Protobuf Team Bot | b4370b2 | 2023-02-17 12:10:22 -0800 | [diff] [blame] | 264 | * Parses the given data as this message's class, and merges those values into |
| 265 | * this message. |
| 266 | * |
| 267 | * @param data The binary representation of the message to merge. |
| 268 | * @param extensionRegistry The extension registry to use to look up extensions. |
| 269 | * @param errorPtr An optional error pointer to fill in with a failure |
| 270 | * reason if the data can not be parsed. Will only be |
| 271 | * filled in if the data failed to be parsed. |
| 272 | * |
| 273 | * @return Boolean indicating success. errorPtr will only be fill in on failure. |
| 274 | **/ |
| 275 | - (BOOL)mergeFromData:(NSData *)data |
| 276 | extensionRegistry:(nullable id<GPBExtensionRegistry>)extensionRegistry |
| 277 | error:(NSError **)errorPtr; |
| 278 | |
| 279 | /** |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 280 | * Merges the fields from another message (of the same type) into this |
| 281 | * message. |
| 282 | * |
| 283 | * @param other Message to merge into this message. |
| 284 | **/ |
| 285 | - (void)mergeFrom:(GPBMessage *)other; |
| 286 | |
| 287 | /** |
| 288 | * Writes out the message to the given coded output stream. |
| 289 | * |
| 290 | * @param output The coded output stream into which to write the message. |
Thomas Van Lenten | 5fd71ce | 2017-06-19 10:21:33 -0400 | [diff] [blame] | 291 | * |
| 292 | * @note This can raise the GPBCodedOutputStreamException_* exceptions. |
| 293 | * |
Protobuf Team Bot | 4b1cd0d | 2023-02-15 13:24:29 -0800 | [diff] [blame] | 294 | * @note The most common cause of this failing is from one thread calling this |
| 295 | * while another thread has a reference to this message or a message used |
| 296 | * within a field and that other thread mutating the message while this |
| 297 | * serialization is taking place. |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 298 | **/ |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 299 | - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)output; |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 300 | |
| 301 | /** |
| 302 | * Writes out the message to the given output stream. |
| 303 | * |
| 304 | * @param output The output stream into which to write the message. |
Thomas Van Lenten | 5fd71ce | 2017-06-19 10:21:33 -0400 | [diff] [blame] | 305 | * |
| 306 | * @note This can raise the GPBCodedOutputStreamException_* exceptions. |
Protobuf Team Bot | 4b1cd0d | 2023-02-15 13:24:29 -0800 | [diff] [blame] | 307 | * |
| 308 | * @note The most common cause of this failing is from one thread calling this |
| 309 | * while another thread has a reference to this message or a message used |
| 310 | * within a field and that other thread mutating the message while this |
| 311 | * serialization is taking place. |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 312 | **/ |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 313 | - (void)writeToOutputStream:(NSOutputStream *)output; |
| 314 | |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 315 | /** |
Benjamin Peterson | 5939bc3 | 2019-03-21 12:31:41 -0700 | [diff] [blame] | 316 | * Writes out a varint for the message size followed by the message to |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 317 | * the given output stream. |
| 318 | * |
| 319 | * @param output The coded output stream into which to write the message. |
Thomas Van Lenten | 5fd71ce | 2017-06-19 10:21:33 -0400 | [diff] [blame] | 320 | * |
| 321 | * @note This can raise the GPBCodedOutputStreamException_* exceptions. |
Protobuf Team Bot | 4b1cd0d | 2023-02-15 13:24:29 -0800 | [diff] [blame] | 322 | * |
| 323 | * @note The most common cause of this failing is from one thread calling this |
| 324 | * while another thread has a reference to this message or a message used |
| 325 | * within a field and that other thread mutating the message while this |
| 326 | * serialization is taking place. |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 327 | **/ |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 328 | - (void)writeDelimitedToCodedOutputStream:(GPBCodedOutputStream *)output; |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 329 | |
| 330 | /** |
Benjamin Peterson | 5939bc3 | 2019-03-21 12:31:41 -0700 | [diff] [blame] | 331 | * Writes out a varint for the message size followed by the message to |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 332 | * the given output stream. |
| 333 | * |
| 334 | * @param output The output stream into which to write the message. |
Thomas Van Lenten | 5fd71ce | 2017-06-19 10:21:33 -0400 | [diff] [blame] | 335 | * |
| 336 | * @note This can raise the GPBCodedOutputStreamException_* exceptions. |
Protobuf Team Bot | 4b1cd0d | 2023-02-15 13:24:29 -0800 | [diff] [blame] | 337 | * |
| 338 | * @note The most common cause of this failing is from one thread calling this |
| 339 | * while another thread has a reference to this message or a message used |
| 340 | * within a field and that other thread mutating the message while this |
| 341 | * serialization is taking place. |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 342 | **/ |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 343 | - (void)writeDelimitedToOutputStream:(NSOutputStream *)output; |
| 344 | |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 345 | /** |
| 346 | * Serializes the message to an NSData. |
| 347 | * |
| 348 | * If there is an error while generating the data, nil is returned. |
| 349 | * |
| 350 | * @note This value is not cached, so if you are using it repeatedly, cache |
| 351 | * it yourself. |
| 352 | * |
| 353 | * @note In DEBUG ONLY, the message is also checked for all required field, |
| 354 | * if one is missing, nil will be returned. |
| 355 | * |
Protobuf Team Bot | 4b1cd0d | 2023-02-15 13:24:29 -0800 | [diff] [blame] | 356 | * @note The most common cause of this failing is from one thread calling this |
| 357 | * while another thread has a reference to this message or a message used |
| 358 | * within a field and that other thread mutating the message while this |
| 359 | * serialization is taking place. |
| 360 | * |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 361 | * @return The binary representation of the message. |
| 362 | **/ |
Thomas Van Lenten | 8c88957 | 2015-06-16 16:45:14 -0400 | [diff] [blame] | 363 | - (nullable NSData *)data; |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 364 | |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 365 | /** |
| 366 | * Serializes a varint with the message size followed by the message data, |
| 367 | * returning that as an NSData. |
| 368 | * |
| 369 | * @note This value is not cached, so if you are using it repeatedly, it is |
| 370 | * recommended to keep a local copy. |
| 371 | * |
Protobuf Team Bot | 4b1cd0d | 2023-02-15 13:24:29 -0800 | [diff] [blame] | 372 | * @note The most common cause of this failing is from one thread calling this |
| 373 | * while another thread has a reference to this message or a message used |
| 374 | * within a field and that other thread mutating the message while this |
| 375 | * serialization is taking place. |
| 376 | * |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 377 | * @return The binary representation of the size along with the message. |
| 378 | **/ |
Thomas Van Lenten | c27833b | 2015-12-07 10:49:30 -0500 | [diff] [blame] | 379 | - (NSData *)delimitedData; |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 380 | |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 381 | /** |
| 382 | * Calculates the size of the object if it were serialized. |
| 383 | * |
| 384 | * This is not a cached value. If you are following a pattern like this: |
| 385 | * |
| 386 | * ``` |
| 387 | * size_t size = [aMsg serializedSize]; |
| 388 | * NSMutableData *foo = [NSMutableData dataWithCapacity:size + sizeof(size)]; |
| 389 | * [foo writeSize:size]; |
| 390 | * [foo appendData:[aMsg data]]; |
| 391 | * ``` |
| 392 | * |
| 393 | * you would be better doing: |
| 394 | * |
| 395 | * ``` |
| 396 | * NSData *data = [aMsg data]; |
| 397 | * NSUInteger size = [aMsg length]; |
| 398 | * NSMutableData *foo = [NSMutableData dataWithCapacity:size + sizeof(size)]; |
| 399 | * [foo writeSize:size]; |
| 400 | * [foo appendData:data]; |
| 401 | * ``` |
| 402 | * |
| 403 | * @return The size of the message in it's binary representation. |
| 404 | **/ |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 405 | - (size_t)serializedSize; |
| 406 | |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 407 | /** |
| 408 | * @return The descriptor for the message class. |
| 409 | **/ |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 410 | + (GPBDescriptor *)descriptor; |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 411 | |
| 412 | /** |
| 413 | * Return the descriptor for the message. |
| 414 | **/ |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 415 | - (GPBDescriptor *)descriptor; |
| 416 | |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 417 | /** |
| 418 | * @return An array with the extension descriptors that are currently set on the |
| 419 | * message. |
| 420 | **/ |
Sergio Campamá | b99577c | 2016-07-15 15:04:01 -0700 | [diff] [blame] | 421 | - (NSArray *)extensionsCurrentlySet; |
| 422 | |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 423 | /** |
| 424 | * Checks whether there is an extension set on the message which matches the |
| 425 | * given extension descriptor. |
| 426 | * |
| 427 | * @param extension Extension descriptor to check if it's set on the message. |
| 428 | * |
| 429 | * @return Whether the extension is currently set on the message. |
| 430 | **/ |
Thomas Van Lenten | d846b0b | 2015-06-08 16:24:57 -0400 | [diff] [blame] | 431 | - (BOOL)hasExtension:(GPBExtensionDescriptor *)extension; |
Thomas Van Lenten | 36650a0 | 2016-03-07 12:07:03 -0500 | [diff] [blame] | 432 | |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 433 | /* |
| 434 | * Fetches the given extension's value for this message. |
| 435 | * |
| 436 | * Extensions use boxed values (NSNumbers) for PODs and NSMutableArrays for |
| 437 | * repeated fields. If the extension is a Message one will be auto created for |
| 438 | * you and returned similar to fields. |
| 439 | * |
Protobuf Team Bot | 903639c | 2022-11-28 08:51:36 -0800 | [diff] [blame] | 440 | * NOTE: For Enum extensions, if the enum was _closed_, then unknown values |
| 441 | * were parsed into the message's unknown fields instead of ending up in the |
| 442 | * extensions, just like what happens with singular/repeated fields. For open |
| 443 | * enums, the _raw_ value will be in the NSNumber, meaning if one does a |
| 444 | * `switch` on the values, a `default` case should also be included. |
| 445 | * |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 446 | * @param extension The extension descriptor of the extension to fetch. |
| 447 | * |
| 448 | * @return The extension matching the given descriptor, or nil if none found. |
| 449 | **/ |
Thomas Van Lenten | 8c88957 | 2015-06-16 16:45:14 -0400 | [diff] [blame] | 450 | - (nullable id)getExtension:(GPBExtensionDescriptor *)extension; |
Thomas Van Lenten | 36650a0 | 2016-03-07 12:07:03 -0500 | [diff] [blame] | 451 | |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 452 | /** |
| 453 | * Sets the given extension's value for this message. This only applies for |
| 454 | * single field extensions (i.e. - not repeated fields). |
| 455 | * |
| 456 | * Extensions use boxed values (NSNumbers). |
| 457 | * |
| 458 | * @param extension The extension descriptor under which to set the value. |
| 459 | * @param value The value to be set as the extension. |
| 460 | **/ |
Thomas Van Lenten | 5d0b217 | 2022-09-19 17:20:35 -0400 | [diff] [blame] | 461 | - (void)setExtension:(GPBExtensionDescriptor *)extension value:(nullable id)value; |
Thomas Van Lenten | 36650a0 | 2016-03-07 12:07:03 -0500 | [diff] [blame] | 462 | |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 463 | /** |
| 464 | * Adds the given value to the extension for this message. This only applies |
| 465 | * to repeated field extensions. If the field is a repeated POD type, the value |
| 466 | * should be an NSNumber. |
| 467 | * |
| 468 | * @param extension The extension descriptor under which to add the value. |
| 469 | * @param value The value to be added to the repeated extension. |
| 470 | **/ |
Thomas Van Lenten | d846b0b | 2015-06-08 16:24:57 -0400 | [diff] [blame] | 471 | - (void)addExtension:(GPBExtensionDescriptor *)extension value:(id)value; |
Thomas Van Lenten | 36650a0 | 2016-03-07 12:07:03 -0500 | [diff] [blame] | 472 | |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 473 | /** |
| 474 | * Replaces the value at the given index with the given value for the extension |
| 475 | * on this message. This only applies to repeated field extensions. If the field |
| 476 | * is a repeated POD type, the value is should be an NSNumber. |
| 477 | * |
| 478 | * @param extension The extension descriptor under which to replace the value. |
| 479 | * @param index The index of the extension to be replaced. |
| 480 | * @param value The value to be replaced in the repeated extension. |
| 481 | **/ |
Thomas Van Lenten | 5d0b217 | 2022-09-19 17:20:35 -0400 | [diff] [blame] | 482 | - (void)setExtension:(GPBExtensionDescriptor *)extension index:(NSUInteger)index value:(id)value; |
Thomas Van Lenten | 36650a0 | 2016-03-07 12:07:03 -0500 | [diff] [blame] | 483 | |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 484 | /** |
| 485 | * Clears the given extension for this message. |
| 486 | * |
| 487 | * @param extension The extension descriptor to be cleared from this message. |
| 488 | **/ |
Thomas Van Lenten | d846b0b | 2015-06-08 16:24:57 -0400 | [diff] [blame] | 489 | - (void)clearExtension:(GPBExtensionDescriptor *)extension; |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 490 | |
Sergio Campamá | 32fadc0 | 2016-08-08 07:15:02 -0700 | [diff] [blame] | 491 | /** |
| 492 | * Resets all of the fields of this message to their default values. |
| 493 | **/ |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 494 | - (void)clear; |
| 495 | |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 496 | @end |
Thomas Van Lenten | 8c88957 | 2015-06-16 16:45:14 -0400 | [diff] [blame] | 497 | |
| 498 | NS_ASSUME_NONNULL_END |