• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc.  All rights reserved.
3 //
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file or at
6 // https://developers.google.com/open-source/licenses/bsd
7 
8 #import <Foundation/Foundation.h>
9 
10 #import "GPBDescriptor.h"
11 
12 NS_ASSUME_NONNULL_BEGIN
13 
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>
22 
23 /**
24  * Looks for the extension registered for the given field number on a given
25  * GPBDescriptor.
26  *
27  * @param descriptor  The descriptor to look for a registered extension on.
28  * @param fieldNumber The field number of the extension to look for.
29  *
30  * @return The registered GPBExtensionDescriptor or nil if none was found.
31  **/
32 - (nullable GPBExtensionDescriptor *)extensionForDescriptor:(GPBDescriptor *)descriptor
33                                                 fieldNumber:(NSInteger)fieldNumber;
34 @end
35 
36 /**
37  * A concrete implementation of `GPBExtensionRegistry`.
38  *
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.
43  *
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>
53 
54 /**
55  * Adds the given GPBExtensionDescriptor to this registry.
56  *
57  * @param extension The extension description to add.
58  **/
59 - (void)addExtension:(GPBExtensionDescriptor *)extension;
60 
61 /**
62  * Adds all the extensions from another registry to this registry.
63  *
64  * @param registry The registry to merge into this registry.
65  **/
66 - (void)addExtensions:(GPBExtensionRegistry *)registry;
67 
68 @end
69 
70 NS_ASSUME_NONNULL_END
71