Auto-generate files after cl/721951543
[google-protobuf.git] / objectivec / GPBExtensionRegistry.h
blob9ca8ae53364083c2a367dee5e043ec68dbe1d61a
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
8 #import <Foundation/Foundation.h>
10 #import "GPBDescriptor.h"
12 NS_ASSUME_NONNULL_BEGIN
14 /**
15 * A table of known extensions, searchable by name or field number. When
16 * parsing a protocol message that might have extensions, you must provide a
17 * GPBExtensionRegistry in which you have registered any extensions that you
18 * want to be able to parse. Otherwise, those extensions will just be treated
19 * like unknown fields.
20 **/
21 @protocol GPBExtensionRegistry <NSObject>
23 /**
24 * Looks for the extension registered for the given field number on a given
25 * GPBDescriptor.
27 * @param descriptor The descriptor to look for a registered extension on.
28 * @param fieldNumber The field number of the extension to look for.
30 * @return The registered GPBExtensionDescriptor or nil if none was found.
31 **/
32 - (nullable GPBExtensionDescriptor *)extensionForDescriptor:(GPBDescriptor *)descriptor
33 fieldNumber:(NSInteger)fieldNumber;
34 @end
36 /**
37 * A concrete implementation of `GPBExtensionRegistry`.
39 * The *Root classes provide `+extensionRegistry` for the extensions defined
40 * in a given file *and* all files it imports. You can also create a
41 * GPBExtensionRegistry, and merge those registries to handle parsing
42 * extensions defined from non overlapping files.
44 * ```
45 * GPBExtensionRegistry *registry = [[MyProtoFileRoot extensionRegistry] copy];
46 * [registry addExtension:[OtherMessage neededExtension]]; // Not in MyProtoFile
47 * NSError *parseError;
48 * MyMessage *msg = [MyMessage parseData:data extensionRegistry:registry error:&parseError];
49 * ```
50 **/
51 __attribute__((objc_subclassing_restricted))
52 @interface GPBExtensionRegistry : NSObject<NSCopying, GPBExtensionRegistry>
54 /**
55 * Adds the given GPBExtensionDescriptor to this registry.
57 * @param extension The extension description to add.
58 **/
59 - (void)addExtension:(GPBExtensionDescriptor *)extension;
61 /**
62 * Adds all the extensions from another registry to this registry.
64 * @param registry The registry to merge into this registry.
65 **/
66 - (void)addExtensions:(GPBExtensionRegistry *)registry;
68 @end
70 NS_ASSUME_NONNULL_END