OLD | NEW |
1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
4 // | 4 // |
5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
7 // met: | 7 // met: |
8 // | 8 // |
9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
(...skipping 26 matching lines...) Expand all Loading... |
37 @class GPBCodedOutputStream; | 37 @class GPBCodedOutputStream; |
38 @class GPBExtensionDescriptor; | 38 @class GPBExtensionDescriptor; |
39 @class GPBExtensionRegistry; | 39 @class GPBExtensionRegistry; |
40 @class GPBFieldDescriptor; | 40 @class GPBFieldDescriptor; |
41 @class GPBUnknownFieldSet; | 41 @class GPBUnknownFieldSet; |
42 | 42 |
43 NS_ASSUME_NONNULL_BEGIN | 43 NS_ASSUME_NONNULL_BEGIN |
44 | 44 |
45 CF_EXTERN_C_BEGIN | 45 CF_EXTERN_C_BEGIN |
46 | 46 |
47 /** NSError domain used for errors. */ | 47 /// NSError domain used for errors. |
48 extern NSString *const GPBMessageErrorDomain; | 48 extern NSString *const GPBMessageErrorDomain; |
49 | 49 |
50 /** Error codes for NSErrors originated in GPBMessage. */ | 50 /// Error code for NSError with GPBMessageErrorDomain. |
51 typedef NS_ENUM(NSInteger, GPBMessageErrorCode) { | 51 typedef NS_ENUM(NSInteger, GPBMessageErrorCode) { |
52 /** Uncategorized error. */ | 52 /// The data being parsed is bad and a message can not be created from it. |
53 GPBMessageErrorCodeOther = -100, | 53 GPBMessageErrorCodeMalformedData = -100, |
54 /** Message couldn't be serialized because it is missing required fields. */ | 54 /// A message can't be serialized because it is missing required fields. |
55 GPBMessageErrorCodeMissingRequiredField = -101, | 55 GPBMessageErrorCodeMissingRequiredField = -101, |
56 }; | 56 }; |
57 | 57 |
58 /** | 58 #ifdef DEBUG |
59 * Key under which the GPBMessage error's reason is stored inside the userInfo | 59 /// In DEBUG ONLY, an NSException is thrown when a parsed message doesn't |
60 * dictionary. | 60 /// contain required fields. This key allows you to retrieve the parsed message |
61 **/ | 61 /// from the exception's @c userInfo dictionary. |
62 extern NSString *const GPBErrorReasonKey; | 62 extern NSString *const GPBExceptionMessageKey; |
| 63 #endif // DEBUG |
63 | 64 |
64 CF_EXTERN_C_END | 65 CF_EXTERN_C_END |
65 | 66 |
66 /** | 67 /// Base class for all of the generated message classes. |
67 * Base class that each generated message subclasses from. | |
68 * | |
69 * @note While the class support NSSecureCoding, if the message has any | |
70 * extensions, they will end up reloaded in @c unknownFields as there is | |
71 * no way for the @c NSCoding plumbing to pass through a | |
72 * @c GPBExtensionRegistry. To support extensions, instead of passing the | |
73 * calls off to the Message, simple store the result of @c data, and then | |
74 * when loading, fetch the data and use | |
75 * @c +parseFromData:extensionRegistry:error: to provide an extension | |
76 * registry. | |
77 **/ | |
78 @interface GPBMessage : NSObject<NSSecureCoding, NSCopying> | 68 @interface GPBMessage : NSObject<NSSecureCoding, NSCopying> |
79 | 69 |
80 // If you add an instance method/property to this class that may conflict with | 70 // NOTE: If you add a instance method/property to this class that may conflict |
81 // fields declared in protos, you need to update objective_helpers.cc. The main | 71 // with methods declared in protos, you need to update objective_helpers.cc. |
82 // cases are methods that take no arguments, or setFoo:/hasFoo: type methods. | 72 // The main cases are methods that take no arguments, or setFoo:/hasFoo: type |
83 | 73 // methods. |
84 /** | 74 |
85 * The set of unknown fields for this message. | 75 /// The unknown fields for this message. |
86 * | 76 /// |
87 * Only messages from proto files declared with "proto2" syntax support unknown | 77 /// Only messages from proto files declared with "proto2" syntax support unknown |
88 * fields. For "proto3" syntax, any unknown fields found while parsing are | 78 /// fields. For "proto3" syntax, any unknown fields found while parsing are |
89 * dropped. | 79 /// dropped. |
90 **/ | |
91 @property(nonatomic, copy, nullable) GPBUnknownFieldSet *unknownFields; | 80 @property(nonatomic, copy, nullable) GPBUnknownFieldSet *unknownFields; |
92 | 81 |
93 /** | 82 /// Are all required fields set in the message and all embedded messages. |
94 * Whether the message, along with all submessages, have the required fields | |
95 * set. This is only applicable for files declared with "proto2" syntax, as | |
96 * there are no required fields for "proto3" syntax. | |
97 **/ | |
98 @property(nonatomic, readonly, getter=isInitialized) BOOL initialized; | 83 @property(nonatomic, readonly, getter=isInitialized) BOOL initialized; |
99 | 84 |
100 /** | 85 /// Returns an autoreleased instance. |
101 * @return An autoreleased message with the default values set. | |
102 **/ | |
103 + (instancetype)message; | 86 + (instancetype)message; |
104 | 87 |
105 /** | 88 /// Creates a new instance by parsing the data. This method should be sent to |
106 * Creates a new instance by parsing the provided data. This method should be | 89 /// the generated message class that the data should be interpreted as. If |
107 * sent to the generated message class that the data should be interpreted as. | 90 /// there is an error the method returns nil and the error is returned in |
108 * If there is an error the method returns nil and the error is returned in | 91 /// errorPtr (when provided). |
109 * errorPtr (when provided). | 92 /// |
110 * | 93 /// @note In DEBUG builds, the parsed message is checked to be sure all required |
111 * @note In DEBUG builds, the parsed message is checked to be sure all required | 94 /// fields were provided, and the parse will fail if some are missing. |
112 * fields were provided, and the parse will fail if some are missing. | 95 /// |
113 * | 96 /// @param data The data to parse. |
114 * @note The errors returned are likely coming from the domain and codes listed | 97 /// @param errorPtr An optional error pointer to fill in with a failure reason i
f |
115 * at the top of this file and GPBCodedInputStream.h. | 98 /// the data can not be parsed. |
116 * | 99 /// |
117 * @param data The data to parse. | 100 /// @return A new instance of the class messaged. |
118 * @param errorPtr An optional error pointer to fill in with a failure reason if | 101 + (instancetype)parseFromData:(NSData *)data error:(NSError **)errorPtr; |
119 * the data can not be parsed. | 102 |
120 * | 103 /// Creates a new instance by parsing the data. This method should be sent to |
121 * @return A new instance of the generated class. | 104 /// the generated message class that the data should be interpreted as. If |
122 **/ | 105 /// there is an error the method returns nil and the error is returned in |
123 + (nullable instancetype)parseFromData:(NSData *)data error:(NSError **)errorPtr
; | 106 /// errorPtr (when provided). |
124 | 107 /// |
125 /** | 108 /// @note In DEBUG builds, the parsed message is checked to be sure all required |
126 * Creates a new instance by parsing the data. This method should be sent to | 109 /// fields were provided, and the parse will fail if some are missing. |
127 * the generated message class that the data should be interpreted as. If | 110 /// |
128 * there is an error the method returns nil and the error is returned in | 111 /// @param data The data to parse. |
129 * errorPtr (when provided). | 112 /// @param extensionRegistry The extension registry to use to look up extensions
. |
130 * | 113 /// @param errorPtr An optional error pointer to fill in with a failure |
131 * @note In DEBUG builds, the parsed message is checked to be sure all required | 114 /// reason if the data can not be parsed. |
132 * fields were provided, and the parse will fail if some are missing. | 115 /// |
133 * | 116 /// @return A new instance of the class messaged. |
134 * @note The errors returned are likely coming from the domain and codes listed | 117 + (instancetype)parseFromData:(NSData *)data |
135 * at the top of this file and GPBCodedInputStream.h. | 118 extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry |
136 * | 119 error:(NSError **)errorPtr; |
137 * @param data The data to parse. | 120 |
138 * @param extensionRegistry The extension registry to use to look up extensions. | 121 /// Creates a new instance by parsing the data from the given input stream. This |
139 * @param errorPtr An optional error pointer to fill in with a failure | 122 /// method should be sent to the generated message class that the data should |
140 * reason if the data can not be parsed. | 123 /// be interpreted as. If there is an error the method returns nil and the error |
141 * | 124 /// is returned in errorPtr (when provided). |
142 * @return A new instance of the generated class. | 125 /// |
143 **/ | 126 /// @note In DEBUG builds, the parsed message is checked to be sure all required |
144 + (nullable instancetype)parseFromData:(NSData *)data | 127 /// fields were provided, and the parse will fail if some are missing. |
145 extensionRegistry:(nullable GPBExtensionRegistry *)extensio
nRegistry | 128 /// |
146 error:(NSError **)errorPtr; | 129 /// @param input The stream to read data from. |
147 | 130 /// @param extensionRegistry The extension registry to use to look up extensions
. |
148 /** | 131 /// @param errorPtr An optional error pointer to fill in with a failure |
149 * Creates a new instance by parsing the data from the given input stream. This | 132 /// reason if the data can not be parsed. |
150 * method should be sent to the generated message class that the data should | 133 /// |
151 * be interpreted as. If there is an error the method returns nil and the error | 134 /// @return A new instance of the class messaged. |
152 * is returned in errorPtr (when provided). | 135 + (instancetype)parseFromCodedInputStream:(GPBCodedInputStream *)input |
153 * | 136 extensionRegistry: |
154 * @note In DEBUG builds, the parsed message is checked to be sure all required | 137 (nullable GPBExtensionRegistry *)extensionRegistry |
155 * fields were provided, and the parse will fail if some are missing. | 138 error:(NSError **)errorPtr; |
156 * | 139 |
157 * @note The errors returned are likely coming from the domain and codes listed | 140 /// Creates a new instance by parsing the data from the given input stream. This |
158 * at the top of this file and GPBCodedInputStream.h. | 141 /// method should be sent to the generated message class that the data should |
159 * | 142 /// be interpreted as. If there is an error the method returns nil and the error |
160 * @param input The stream to read data from. | 143 /// is returned in errorPtr (when provided). |
161 * @param extensionRegistry The extension registry to use to look up extensions. | 144 /// |
162 * @param errorPtr An optional error pointer to fill in with a failure | 145 /// @note Unlike the parseFrom... methods, this never checks to see if all of |
163 * reason if the data can not be parsed. | 146 /// the required fields are set. So this method can be used to reload |
164 * | 147 /// messages that may not be complete. |
165 * @return A new instance of the generated class. | 148 /// |
166 **/ | 149 /// @param input The stream to read data from. |
167 + (nullable instancetype)parseFromCodedInputStream:(GPBCodedInputStream *)input | 150 /// @param extensionRegistry The extension registry to use to look up extensions
. |
| 151 /// @param errorPtr An optional error pointer to fill in with a failure |
| 152 /// reason if the data can not be parsed. |
| 153 /// |
| 154 /// @return A new instance of the class messaged. |
| 155 + (instancetype)parseDelimitedFromCodedInputStream:(GPBCodedInputStream *)input |
168 extensionRegistry: | 156 extensionRegistry: |
169 (nullable GPBExtensionRegistry *)extensionR
egistry | 157 (nullable GPBExtensionRegistry *)extensionR
egistry |
170 error:(NSError **)errorPtr; | 158 error:(NSError **)errorPtr; |
171 | 159 |
172 /** | 160 /// Initializes an instance by parsing the data. This method should be sent to |
173 * Creates a new instance by parsing the data from the given input stream. This | 161 /// the generated message class that the data should be interpreted as. If |
174 * method should be sent to the generated message class that the data should | 162 /// there is an error the method returns nil and the error is returned in |
175 * be interpreted as. If there is an error the method returns nil and the error | 163 /// errorPtr (when provided). |
176 * is returned in errorPtr (when provided). | 164 /// |
177 * | 165 /// @note In DEBUG builds, the parsed message is checked to be sure all required |
178 * @note Unlike the parseFrom... methods, this never checks to see if all of | 166 /// fields were provided, and the parse will fail if some are missing. |
179 * the required fields are set. So this method can be used to reload | 167 /// |
180 * messages that may not be complete. | 168 /// @param data The data to parse. |
181 * | 169 /// @param errorPtr An optional error pointer to fill in with a failure reason i
f |
182 * @note The errors returned are likely coming from the domain and codes listed | 170 /// the data can not be parsed. |
183 * at the top of this file and GPBCodedInputStream.h. | 171 - (instancetype)initWithData:(NSData *)data error:(NSError **)errorPtr; |
184 * | 172 |
185 * @param input The stream to read data from. | 173 /// Initializes an instance by parsing the data. This method should be sent to |
186 * @param extensionRegistry The extension registry to use to look up extensions. | 174 /// the generated message class that the data should be interpreted as. If |
187 * @param errorPtr An optional error pointer to fill in with a failure | 175 /// there is an error the method returns nil and the error is returned in |
188 * reason if the data can not be parsed. | 176 /// errorPtr (when provided). |
189 * | 177 /// |
190 * @return A new instance of the generated class. | 178 /// @note In DEBUG builds, the parsed message is checked to be sure all required |
191 **/ | 179 /// fields were provided, and the parse will fail if some are missing. |
192 + (nullable instancetype)parseDelimitedFromCodedInputStream:(GPBCodedInputStream
*)input | 180 /// |
193 extensionRegistry: | 181 /// @param data The data to parse. |
194 (nullable GPBExtensionRegistry *)e
xtensionRegistry | 182 /// @param extensionRegistry The extension registry to use to look up extensions
. |
195 error:(NSError **)errorPtr
; | 183 /// @param errorPtr An optional error pointer to fill in with a failure |
196 | 184 /// reason if the data can not be parsed. |
197 /** | 185 - (instancetype)initWithData:(NSData *)data |
198 * Initializes an instance by parsing the data. This method should be sent to | 186 extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry |
199 * the generated message class that the data should be interpreted as. If | 187 error:(NSError **)errorPtr; |
200 * there is an error the method returns nil and the error is returned in | 188 |
201 * errorPtr (when provided). | 189 /// Initializes an instance by parsing the data from the given input stream. Thi
s |
202 * | 190 /// method should be sent to the generated message class that the data should |
203 * @note In DEBUG builds, the parsed message is checked to be sure all required | 191 /// be interpreted as. If there is an error the method returns nil and the error |
204 * fields were provided, and the parse will fail if some are missing. | 192 /// is returned in errorPtr (when provided). |
205 * | 193 /// |
206 * @note The errors returned are likely coming from the domain and codes listed | 194 /// @note Unlike the parseFrom... methods, this never checks to see if all of |
207 * at the top of this file and GPBCodedInputStream.h. | 195 /// the required fields are set. So this method can be used to reload |
208 * | 196 /// messages that may not be complete. |
209 * @param data The data to parse. | 197 /// |
210 * @param errorPtr An optional error pointer to fill in with a failure reason if | 198 /// @param input The stream to read data from. |
211 * the data can not be parsed. | 199 /// @param extensionRegistry The extension registry to use to look up extensions
. |
212 * | 200 /// @param errorPtr An optional error pointer to fill in with a failure |
213 * @return An initialized instance of the generated class. | 201 /// reason if the data can not be parsed. |
214 **/ | 202 - (instancetype)initWithCodedInputStream:(GPBCodedInputStream *)input |
215 - (nullable instancetype)initWithData:(NSData *)data error:(NSError **)errorPtr; | 203 extensionRegistry: |
216 | 204 (nullable GPBExtensionRegistry *)extensionRegistry |
217 /** | 205 error:(NSError **)errorPtr; |
218 * Initializes an instance by parsing the data. This method should be sent to | 206 |
219 * the generated message class that the data should be interpreted as. If | 207 /// Writes out the message to the given output stream. |
220 * there is an error the method returns nil and the error is returned in | |
221 * errorPtr (when provided). | |
222 * | |
223 * @note In DEBUG builds, the parsed message is checked to be sure all required | |
224 * fields were provided, and the parse will fail if some are missing. | |
225 * | |
226 * @note The errors returned are likely coming from the domain and codes listed | |
227 * at the top of this file and GPBCodedInputStream.h. | |
228 * | |
229 * @param data The data to parse. | |
230 * @param extensionRegistry The extension registry to use to look up extensions. | |
231 * @param errorPtr An optional error pointer to fill in with a failure | |
232 * reason if the data can not be parsed. | |
233 * | |
234 * @return An initialized instance of the generated class. | |
235 **/ | |
236 - (nullable instancetype)initWithData:(NSData *)data | |
237 extensionRegistry:(nullable GPBExtensionRegistry *)extension
Registry | |
238 error:(NSError **)errorPtr; | |
239 | |
240 /** | |
241 * Initializes an instance by parsing the data from the given input stream. This | |
242 * method should be sent to the generated message class that the data should | |
243 * be interpreted as. If there is an error the method returns nil and the error | |
244 * is returned in errorPtr (when provided). | |
245 * | |
246 * @note Unlike the parseFrom... methods, this never checks to see if all of | |
247 * the required fields are set. So this method can be used to reload | |
248 * messages that may not be complete. | |
249 * | |
250 * @note The errors returned are likely coming from the domain and codes listed | |
251 * at the top of this file and GPBCodedInputStream.h. | |
252 * | |
253 * @param input The stream to read data from. | |
254 * @param extensionRegistry The extension registry to use to look up extensions. | |
255 * @param errorPtr An optional error pointer to fill in with a failure | |
256 * reason if the data can not be parsed. | |
257 * | |
258 * @return An initialized instance of the generated class. | |
259 **/ | |
260 - (nullable instancetype)initWithCodedInputStream:(GPBCodedInputStream *)input | |
261 extensionRegistry: | |
262 (nullable GPBExtensionRegistry *)extensionRe
gistry | |
263 error:(NSError **)errorPtr; | |
264 | |
265 /** | |
266 * Parses the given data as this message's class, and merges those values into | |
267 * this message. | |
268 * | |
269 * @param data The binary representation of the message to merge. | |
270 * @param extensionRegistry The extension registry to use to look up extensions. | |
271 * | |
272 * @exception GPBCodedInputStreamException Exception thrown when parsing was | |
273 * unsuccessful. | |
274 **/ | |
275 - (void)mergeFromData:(NSData *)data | |
276 extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry; | |
277 | |
278 /** | |
279 * Merges the fields from another message (of the same type) into this | |
280 * message. | |
281 * | |
282 * @param other Message to merge into this message. | |
283 **/ | |
284 - (void)mergeFrom:(GPBMessage *)other; | |
285 | |
286 /** | |
287 * Writes out the message to the given coded output stream. | |
288 * | |
289 * @param output The coded output stream into which to write the message. | |
290 **/ | |
291 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)output; | 208 - (void)writeToCodedOutputStream:(GPBCodedOutputStream *)output; |
292 | 209 /// Writes out the message to the given output stream. |
293 /** | |
294 * Writes out the message to the given output stream. | |
295 * | |
296 * @param output The output stream into which to write the message. | |
297 **/ | |
298 - (void)writeToOutputStream:(NSOutputStream *)output; | 210 - (void)writeToOutputStream:(NSOutputStream *)output; |
299 | 211 |
300 /** | 212 /// Writes out a varint for the message size followed by the the message to |
301 * Writes out a varint for the message size followed by the the message to | 213 /// the given output stream. |
302 * the given output stream. | |
303 * | |
304 * @param output The coded output stream into which to write the message. | |
305 **/ | |
306 - (void)writeDelimitedToCodedOutputStream:(GPBCodedOutputStream *)output; | 214 - (void)writeDelimitedToCodedOutputStream:(GPBCodedOutputStream *)output; |
307 | 215 /// Writes out a varint for the message size followed by the the message to |
308 /** | 216 /// the given output stream. |
309 * Writes out a varint for the message size followed by the the message to | |
310 * the given output stream. | |
311 * | |
312 * @param output The output stream into which to write the message. | |
313 **/ | |
314 - (void)writeDelimitedToOutputStream:(NSOutputStream *)output; | 217 - (void)writeDelimitedToOutputStream:(NSOutputStream *)output; |
315 | 218 |
316 /** | 219 /// Serializes the message to a @c NSData. |
317 * Serializes the message to an NSData. | 220 /// |
318 * | 221 /// If there is an error while generating the data, nil is returned. |
319 * If there is an error while generating the data, nil is returned. | 222 /// |
320 * | 223 /// @note This value is not cached, so if you are using it repeatedly, cache |
321 * @note This value is not cached, so if you are using it repeatedly, cache | 224 /// it yourself. |
322 * it yourself. | 225 /// |
323 * | 226 /// @note In DEBUG ONLY, the message is also checked for all required field, |
324 * @note In DEBUG ONLY, the message is also checked for all required field, | 227 /// if one is missing, nil will be returned. |
325 * if one is missing, nil will be returned. | |
326 * | |
327 * @return The binary representation of the message. | |
328 **/ | |
329 - (nullable NSData *)data; | 228 - (nullable NSData *)data; |
330 | 229 |
331 /** | 230 /// Serializes a varint with the message size followed by the message data, |
332 * Serializes a varint with the message size followed by the message data, | 231 /// returning that as a @c NSData. |
333 * returning that as an NSData. | 232 /// |
334 * | 233 /// @note This value is not cached, so if you are using it repeatedly, cache |
335 * @note This value is not cached, so if you are using it repeatedly, it is | 234 /// it yourself. |
336 * recommended to keep a local copy. | |
337 * | |
338 * @return The binary representation of the size along with the message. | |
339 **/ | |
340 - (NSData *)delimitedData; | 235 - (NSData *)delimitedData; |
341 | 236 |
342 /** | 237 /// Calculates the size of the object if it were serialized. |
343 * Calculates the size of the object if it were serialized. | 238 /// |
344 * | 239 /// This is not a cached value. If you are following a pattern like this: |
345 * This is not a cached value. If you are following a pattern like this: | 240 /// @code |
346 * | 241 /// size_t size = [aMsg serializedSize]; |
347 * ``` | 242 /// NSMutableData *foo = [NSMutableData dataWithCapacity:size + sizeof(size)]; |
348 * size_t size = [aMsg serializedSize]; | 243 /// [foo writeSize:size]; |
349 * NSMutableData *foo = [NSMutableData dataWithCapacity:size + sizeof(size)]; | 244 /// [foo appendData:[aMsg data]]; |
350 * [foo writeSize:size]; | 245 /// @endcode |
351 * [foo appendData:[aMsg data]]; | 246 /// you would be better doing: |
352 * ``` | 247 /// @code |
353 * | 248 /// NSData *data = [aMsg data]; |
354 * you would be better doing: | 249 /// NSUInteger size = [aMsg length]; |
355 * | 250 /// NSMutableData *foo = [NSMutableData dataWithCapacity:size + sizeof(size)]; |
356 * ``` | 251 /// [foo writeSize:size]; |
357 * NSData *data = [aMsg data]; | 252 /// [foo appendData:data]; |
358 * NSUInteger size = [aMsg length]; | 253 /// @endcode |
359 * NSMutableData *foo = [NSMutableData dataWithCapacity:size + sizeof(size)]; | |
360 * [foo writeSize:size]; | |
361 * [foo appendData:data]; | |
362 * ``` | |
363 * | |
364 * @return The size of the message in it's binary representation. | |
365 **/ | |
366 - (size_t)serializedSize; | 254 - (size_t)serializedSize; |
367 | 255 |
368 /** | 256 /// Return the descriptor for the message class. |
369 * @return The descriptor for the message class. | |
370 **/ | |
371 + (GPBDescriptor *)descriptor; | 257 + (GPBDescriptor *)descriptor; |
372 | 258 /// Return the descriptor for the message. |
373 /** | |
374 * Return the descriptor for the message. | |
375 **/ | |
376 - (GPBDescriptor *)descriptor; | 259 - (GPBDescriptor *)descriptor; |
377 | 260 |
378 /** | 261 /// Test to see if the given extension is set on the message. |
379 * @return An array with the extension descriptors that are currently set on the | |
380 * message. | |
381 **/ | |
382 - (NSArray *)extensionsCurrentlySet; | |
383 | |
384 /** | |
385 * Checks whether there is an extension set on the message which matches the | |
386 * given extension descriptor. | |
387 * | |
388 * @param extension Extension descriptor to check if it's set on the message. | |
389 * | |
390 * @return Whether the extension is currently set on the message. | |
391 **/ | |
392 - (BOOL)hasExtension:(GPBExtensionDescriptor *)extension; | 262 - (BOOL)hasExtension:(GPBExtensionDescriptor *)extension; |
393 | 263 |
394 /* | 264 /// Fetches the given extension's value for this message. |
395 * Fetches the given extension's value for this message. | 265 /// |
396 * | 266 /// Extensions use boxed values (NSNumbers) for PODs and NSMutableArrays for |
397 * Extensions use boxed values (NSNumbers) for PODs and NSMutableArrays for | 267 /// repeated fields. If the extension is a Message one will be auto created for
you |
398 * repeated fields. If the extension is a Message one will be auto created for | 268 /// and returned similar to fields. |
399 * you and returned similar to fields. | |
400 * | |
401 * @param extension The extension descriptor of the extension to fetch. | |
402 * | |
403 * @return The extension matching the given descriptor, or nil if none found. | |
404 **/ | |
405 - (nullable id)getExtension:(GPBExtensionDescriptor *)extension; | 269 - (nullable id)getExtension:(GPBExtensionDescriptor *)extension; |
406 | 270 |
407 /** | 271 /// Sets the given extension's value for this message. This is only for single |
408 * Sets the given extension's value for this message. This only applies for | 272 /// field extensions (i.e. - not repeated fields). |
409 * single field extensions (i.e. - not repeated fields). | 273 /// |
410 * | 274 /// Extensions use boxed values (@c NSNumbers). |
411 * Extensions use boxed values (NSNumbers). | 275 - (void)setExtension:(GPBExtensionDescriptor *)extension value:(nullable id)valu
e; |
412 * | 276 |
413 * @param extension The extension descriptor under which to set the value. | 277 /// Adds the given value to the extension for this message. This is only for |
414 * @param value The value to be set as the extension. | 278 /// repeated field extensions. If the field is a repeated POD type the @c value |
415 **/ | 279 /// is a @c NSNumber. |
416 - (void)setExtension:(GPBExtensionDescriptor *)extension | |
417 value:(nullable id)value; | |
418 | |
419 /** | |
420 * Adds the given value to the extension for this message. This only applies | |
421 * to repeated field extensions. If the field is a repeated POD type, the value | |
422 * should be an NSNumber. | |
423 * | |
424 * @param extension The extension descriptor under which to add the value. | |
425 * @param value The value to be added to the repeated extension. | |
426 **/ | |
427 - (void)addExtension:(GPBExtensionDescriptor *)extension value:(id)value; | 280 - (void)addExtension:(GPBExtensionDescriptor *)extension value:(id)value; |
428 | 281 |
429 /** | 282 /// Replaces the given value at an index for the extension on this message. This |
430 * Replaces the value at the given index with the given value for the extension | 283 /// is only for repeated field extensions. If the field is a repeated POD type |
431 * on this message. This only applies to repeated field extensions. If the field | 284 /// the @c value is a @c NSNumber. |
432 * is a repeated POD type, the value is should be an NSNumber. | |
433 * | |
434 * @param extension The extension descriptor under which to replace the value. | |
435 * @param index The index of the extension to be replaced. | |
436 * @param value The value to be replaced in the repeated extension. | |
437 **/ | |
438 - (void)setExtension:(GPBExtensionDescriptor *)extension | 285 - (void)setExtension:(GPBExtensionDescriptor *)extension |
439 index:(NSUInteger)index | 286 index:(NSUInteger)index |
440 value:(id)value; | 287 value:(id)value; |
441 | 288 |
442 /** | 289 /// Clears the given extension for this message. |
443 * Clears the given extension for this message. | |
444 * | |
445 * @param extension The extension descriptor to be cleared from this message. | |
446 **/ | |
447 - (void)clearExtension:(GPBExtensionDescriptor *)extension; | 290 - (void)clearExtension:(GPBExtensionDescriptor *)extension; |
448 | 291 |
449 /** | 292 /// Resets all of the fields of this message to their default values. |
450 * Resets all of the fields of this message to their default values. | |
451 **/ | |
452 - (void)clear; | 293 - (void)clear; |
453 | 294 |
| 295 /// Parses a message of this type from the input and merges it with this |
| 296 /// message. |
| 297 /// |
| 298 /// @note This will throw if there is an error parsing the data. |
| 299 - (void)mergeFromData:(NSData *)data |
| 300 extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry; |
| 301 |
| 302 /// Merges the fields from another message (of the same type) into this |
| 303 /// message. |
| 304 - (void)mergeFrom:(GPBMessage *)other; |
| 305 |
454 @end | 306 @end |
455 | 307 |
456 NS_ASSUME_NONNULL_END | 308 NS_ASSUME_NONNULL_END |
OLD | NEW |