blob: cca7dbcf354ea9bc7af009658031c411c9f00163 [file] [log] [blame]
Thomas Van Lenten30650d82015-05-01 08:57:16 -04001// Protocol Buffers - Google's data interchange format
2// Copyright 2008 Google Inc. All rights reserved.
Thomas Van Lenten30650d82015-05-01 08:57:16 -04003//
Joshua Haberman44bd65b2023-09-08 17:43:14 -07004// 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 Lenten30650d82015-05-01 08:57:16 -04007
Thomas Van Lenten1dcc3292015-05-21 17:14:52 -04008#import <Foundation/Foundation.h>
9
10#import "GPBBootstrap.h"
Thomas Van Lenten5392dc12022-09-19 16:06:12 -040011#import "GPBExtensionRegistry.h"
Thomas Van Lenten30650d82015-05-01 08:57:16 -040012
13@class GPBDescriptor;
14@class GPBCodedInputStream;
15@class GPBCodedOutputStream;
Thomas Van Lentend846b0b2015-06-08 16:24:57 -040016@class GPBExtensionDescriptor;
Thomas Van Lenten30650d82015-05-01 08:57:16 -040017@class GPBFieldDescriptor;
18@class GPBUnknownFieldSet;
19
Thomas Van Lenten8c889572015-06-16 16:45:14 -040020NS_ASSUME_NONNULL_BEGIN
21
Thomas Van Lenten1dcc3292015-05-21 17:14:52 -040022CF_EXTERN_C_BEGIN
23
Sergio Campamá32fadc02016-08-08 07:15:02 -070024/** NSError domain used for errors. */
Thomas Van Lenten1dcc3292015-05-21 17:14:52 -040025extern NSString *const GPBMessageErrorDomain;
26
Sergio Campamá32fadc02016-08-08 07:15:02 -070027/** Error codes for NSErrors originated in GPBMessage. */
Thomas Van Lenten1dcc3292015-05-21 17:14:52 -040028typedef NS_ENUM(NSInteger, GPBMessageErrorCode) {
Sergio Campamá32fadc02016-08-08 07:15:02 -070029 /** Uncategorized error. */
Sergio Campamáe34c0912016-06-02 11:14:26 -070030 GPBMessageErrorCodeOther = -100,
Sergio Campamá32fadc02016-08-08 07:15:02 -070031 /** Message couldn't be serialized because it is missing required fields. */
Thomas Van Lenten1dcc3292015-05-21 17:14:52 -040032 GPBMessageErrorCodeMissingRequiredField = -101,
33};
34
Sergio Campamá32fadc02016-08-08 07:15:02 -070035/**
36 * Key under which the GPBMessage error's reason is stored inside the userInfo
37 * dictionary.
38 **/
Sergio Campamáe34c0912016-06-02 11:14:26 -070039extern NSString *const GPBErrorReasonKey;
40
Protobuf Team Bote6d01b22023-02-22 05:54:19 -080041/**
42 * An exception name raised during serialization when the message would be
43 * larger than the 2GB limit.
44 **/
45extern NSString *const GPBMessageExceptionMessageTooLarge;
46
Thomas Van Lenten1dcc3292015-05-21 17:14:52 -040047CF_EXTERN_C_END
48
Sergio Campamá32fadc02016-08-08 07:15:02 -070049/**
50 * Base class that each generated message subclasses from.
Thomas Van Lenten98c01852016-10-31 10:43:46 -040051 *
Thomas Van Lenten5e4f14f2017-03-15 10:50:31 -040052 * @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 Lenten98c01852016-10-31 10:43:46 -040057 * @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á32fadc02016-08-08 07:15:02 -070065 **/
Thomas Van Lenten5d0b2172022-09-19 17:20:35 -040066@interface GPBMessage : NSObject <NSSecureCoding, NSCopying>
Thomas Van Lenten98c01852016-10-31 10:43:46 -040067
Sergio Campamá32fadc02016-08-08 07:15:02 -070068// 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 Lenten1dcc3292015-05-21 17:14:52 -040071
Sergio Campamá32fadc02016-08-08 07:15:02 -070072/**
73 * The set of unknown fields for this message.
Sergio Campamá32fadc02016-08-08 07:15:02 -070074 **/
Thomas Van Lenten8c889572015-06-16 16:45:14 -040075@property(nonatomic, copy, nullable) GPBUnknownFieldSet *unknownFields;
Thomas Van Lenten30650d82015-05-01 08:57:16 -040076
Sergio Campamá32fadc02016-08-08 07:15:02 -070077/**
78 * Whether the message, along with all submessages, have the required fields
Protobuf Team Botd4e13272022-11-14 07:46:23 -080079 * set.
Sergio Campamá32fadc02016-08-08 07:15:02 -070080 **/
Thomas Van Lenten30650d82015-05-01 08:57:16 -040081@property(nonatomic, readonly, getter=isInitialized) BOOL initialized;
82
Sergio Campamá32fadc02016-08-08 07:15:02 -070083/**
84 * @return An autoreleased message with the default values set.
85 **/
Thomas Van Lenten30650d82015-05-01 08:57:16 -040086+ (instancetype)message;
87
Sergio Campamá32fadc02016-08-08 07:15:02 -070088/**
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 Kharrat523bfd42016-06-24 00:05:02 -0700106+ (nullable instancetype)parseFromData:(NSData *)data error:(NSError **)errorPtr;
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500107
Sergio Campamá32fadc02016-08-08 07:15:02 -0700108/**
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 Kharrat523bfd42016-06-24 00:05:02 -0700127+ (nullable instancetype)parseFromData:(NSData *)data
Thomas Van Lentenf191ab02022-09-15 14:40:15 -0400128 extensionRegistry:(nullable id<GPBExtensionRegistry>)extensionRegistry
Dia Kharrat523bfd42016-06-24 00:05:02 -0700129 error:(NSError **)errorPtr;
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500130
Sergio Campamá32fadc02016-08-08 07:15:02 -0700131/**
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 Kharrat523bfd42016-06-24 00:05:02 -0700150+ (nullable instancetype)parseFromCodedInputStream:(GPBCodedInputStream *)input
151 extensionRegistry:
Thomas Van Lentenf191ab02022-09-15 14:40:15 -0400152 (nullable id<GPBExtensionRegistry>)extensionRegistry
Dia Kharrat523bfd42016-06-24 00:05:02 -0700153 error:(NSError **)errorPtr;
Thomas Van Lenten30650d82015-05-01 08:57:16 -0400154
Sergio Campamá32fadc02016-08-08 07:15:02 -0700155/**
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 Kharrat523bfd42016-06-24 00:05:02 -0700175+ (nullable instancetype)parseDelimitedFromCodedInputStream:(GPBCodedInputStream *)input
176 extensionRegistry:
Thomas Van Lentenf191ab02022-09-15 14:40:15 -0400177 (nullable id<GPBExtensionRegistry>)extensionRegistry
Dia Kharrat523bfd42016-06-24 00:05:02 -0700178 error:(NSError **)errorPtr;
Thomas Van Lenten30650d82015-05-01 08:57:16 -0400179
Sergio Campamá32fadc02016-08-08 07:15:02 -0700180/**
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 Kharrat523bfd42016-06-24 00:05:02 -0700198- (nullable instancetype)initWithData:(NSData *)data error:(NSError **)errorPtr;
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500199
Sergio Campamá32fadc02016-08-08 07:15:02 -0700200/**
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 Kharrat523bfd42016-06-24 00:05:02 -0700219- (nullable instancetype)initWithData:(NSData *)data
Thomas Van Lentenf191ab02022-09-15 14:40:15 -0400220 extensionRegistry:(nullable id<GPBExtensionRegistry>)extensionRegistry
Dia Kharrat523bfd42016-06-24 00:05:02 -0700221 error:(NSError **)errorPtr;
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500222
Sergio Campamá32fadc02016-08-08 07:15:02 -0700223/**
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 Kharrat523bfd42016-06-24 00:05:02 -0700243- (nullable instancetype)initWithCodedInputStream:(GPBCodedInputStream *)input
244 extensionRegistry:
Thomas Van Lentenf191ab02022-09-15 14:40:15 -0400245 (nullable id<GPBExtensionRegistry>)extensionRegistry
Dia Kharrat523bfd42016-06-24 00:05:02 -0700246 error:(NSError **)errorPtr;
Thomas Van Lenten30650d82015-05-01 08:57:16 -0400247
Sergio Campamá32fadc02016-08-08 07:15:02 -0700248/**
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 Bote3b00512023-02-21 11:45:16 -0800259 extensionRegistry:(nullable id<GPBExtensionRegistry>)extensionRegistry
260 __attribute__((deprecated(
261 "Use -mergeFromData:extensionRegistry:error: instead, especaily if calling from Swift.")));
Sergio Campamá32fadc02016-08-08 07:15:02 -0700262
263/**
Protobuf Team Botb4370b22023-02-17 12:10:22 -0800264 * 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á32fadc02016-08-08 07:15:02 -0700280 * 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 Lenten5fd71ce2017-06-19 10:21:33 -0400291 *
292 * @note This can raise the GPBCodedOutputStreamException_* exceptions.
293 *
Protobuf Team Bot4b1cd0d2023-02-15 13:24:29 -0800294 * @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á32fadc02016-08-08 07:15:02 -0700298 **/
Thomas Van Lenten30650d82015-05-01 08:57:16 -0400299- (void)writeToCodedOutputStream:(GPBCodedOutputStream *)output;
Sergio Campamá32fadc02016-08-08 07:15:02 -0700300
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 Lenten5fd71ce2017-06-19 10:21:33 -0400305 *
306 * @note This can raise the GPBCodedOutputStreamException_* exceptions.
Protobuf Team Bot4b1cd0d2023-02-15 13:24:29 -0800307 *
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á32fadc02016-08-08 07:15:02 -0700312 **/
Thomas Van Lenten30650d82015-05-01 08:57:16 -0400313- (void)writeToOutputStream:(NSOutputStream *)output;
314
Sergio Campamá32fadc02016-08-08 07:15:02 -0700315/**
Benjamin Peterson5939bc32019-03-21 12:31:41 -0700316 * Writes out a varint for the message size followed by the message to
Sergio Campamá32fadc02016-08-08 07:15:02 -0700317 * the given output stream.
318 *
319 * @param output The coded output stream into which to write the message.
Thomas Van Lenten5fd71ce2017-06-19 10:21:33 -0400320 *
321 * @note This can raise the GPBCodedOutputStreamException_* exceptions.
Protobuf Team Bot4b1cd0d2023-02-15 13:24:29 -0800322 *
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á32fadc02016-08-08 07:15:02 -0700327 **/
Thomas Van Lenten30650d82015-05-01 08:57:16 -0400328- (void)writeDelimitedToCodedOutputStream:(GPBCodedOutputStream *)output;
Sergio Campamá32fadc02016-08-08 07:15:02 -0700329
330/**
Benjamin Peterson5939bc32019-03-21 12:31:41 -0700331 * Writes out a varint for the message size followed by the message to
Sergio Campamá32fadc02016-08-08 07:15:02 -0700332 * the given output stream.
333 *
334 * @param output The output stream into which to write the message.
Thomas Van Lenten5fd71ce2017-06-19 10:21:33 -0400335 *
336 * @note This can raise the GPBCodedOutputStreamException_* exceptions.
Protobuf Team Bot4b1cd0d2023-02-15 13:24:29 -0800337 *
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á32fadc02016-08-08 07:15:02 -0700342 **/
Thomas Van Lenten30650d82015-05-01 08:57:16 -0400343- (void)writeDelimitedToOutputStream:(NSOutputStream *)output;
344
Sergio Campamá32fadc02016-08-08 07:15:02 -0700345/**
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 Bot4b1cd0d2023-02-15 13:24:29 -0800356 * @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á32fadc02016-08-08 07:15:02 -0700361 * @return The binary representation of the message.
362 **/
Thomas Van Lenten8c889572015-06-16 16:45:14 -0400363- (nullable NSData *)data;
Thomas Van Lenten30650d82015-05-01 08:57:16 -0400364
Sergio Campamá32fadc02016-08-08 07:15:02 -0700365/**
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 Bot4b1cd0d2023-02-15 13:24:29 -0800372 * @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á32fadc02016-08-08 07:15:02 -0700377 * @return The binary representation of the size along with the message.
378 **/
Thomas Van Lentenc27833b2015-12-07 10:49:30 -0500379- (NSData *)delimitedData;
Thomas Van Lenten30650d82015-05-01 08:57:16 -0400380
Sergio Campamá32fadc02016-08-08 07:15:02 -0700381/**
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 Lenten30650d82015-05-01 08:57:16 -0400405- (size_t)serializedSize;
406
Sergio Campamá32fadc02016-08-08 07:15:02 -0700407/**
408 * @return The descriptor for the message class.
409 **/
Thomas Van Lenten30650d82015-05-01 08:57:16 -0400410+ (GPBDescriptor *)descriptor;
Sergio Campamá32fadc02016-08-08 07:15:02 -0700411
412/**
413 * Return the descriptor for the message.
414 **/
Thomas Van Lenten30650d82015-05-01 08:57:16 -0400415- (GPBDescriptor *)descriptor;
416
Sergio Campamá32fadc02016-08-08 07:15:02 -0700417/**
418 * @return An array with the extension descriptors that are currently set on the
419 * message.
420 **/
Sergio Campamáb99577c2016-07-15 15:04:01 -0700421- (NSArray *)extensionsCurrentlySet;
422
Sergio Campamá32fadc02016-08-08 07:15:02 -0700423/**
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 Lentend846b0b2015-06-08 16:24:57 -0400431- (BOOL)hasExtension:(GPBExtensionDescriptor *)extension;
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500432
Sergio Campamá32fadc02016-08-08 07:15:02 -0700433/*
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 Bot903639c2022-11-28 08:51:36 -0800440 * 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á32fadc02016-08-08 07:15:02 -0700446 * @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 Lenten8c889572015-06-16 16:45:14 -0400450- (nullable id)getExtension:(GPBExtensionDescriptor *)extension;
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500451
Sergio Campamá32fadc02016-08-08 07:15:02 -0700452/**
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 Lenten5d0b2172022-09-19 17:20:35 -0400461- (void)setExtension:(GPBExtensionDescriptor *)extension value:(nullable id)value;
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500462
Sergio Campamá32fadc02016-08-08 07:15:02 -0700463/**
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 Lentend846b0b2015-06-08 16:24:57 -0400471- (void)addExtension:(GPBExtensionDescriptor *)extension value:(id)value;
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500472
Sergio Campamá32fadc02016-08-08 07:15:02 -0700473/**
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 Lenten5d0b2172022-09-19 17:20:35 -0400482- (void)setExtension:(GPBExtensionDescriptor *)extension index:(NSUInteger)index value:(id)value;
Thomas Van Lenten36650a02016-03-07 12:07:03 -0500483
Sergio Campamá32fadc02016-08-08 07:15:02 -0700484/**
485 * Clears the given extension for this message.
486 *
487 * @param extension The extension descriptor to be cleared from this message.
488 **/
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400489- (void)clearExtension:(GPBExtensionDescriptor *)extension;
Thomas Van Lenten30650d82015-05-01 08:57:16 -0400490
Sergio Campamá32fadc02016-08-08 07:15:02 -0700491/**
492 * Resets all of the fields of this message to their default values.
493 **/
Thomas Van Lenten30650d82015-05-01 08:57:16 -0400494- (void)clear;
495
Thomas Van Lenten30650d82015-05-01 08:57:16 -0400496@end
Thomas Van Lenten8c889572015-06-16 16:45:14 -0400497
498NS_ASSUME_NONNULL_END