1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
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
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.
21 @protocol GPBExtensionRegistry
<NSObject
>
24 * Looks for the extension registered for the given field number on a given
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.
32 - (nullable GPBExtensionDescriptor
*)extensionForDescriptor
:(GPBDescriptor
*)descriptor
33 fieldNumber
:(NSInteger
)fieldNumber
;
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.
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];
51 __attribute__((objc_subclassing_restricted
))
52 @interface GPBExtensionRegistry
: NSObject
<NSCopying
, GPBExtensionRegistry
>
55 * Adds the given GPBExtensionDescriptor to this registry.
57 * @param extension The extension description to add.
59 - (void)addExtension
:(GPBExtensionDescriptor
*)extension
;
62 * Adds all the extensions from another registry to this registry.
64 * @param registry The registry to merge into this registry.
66 - (void)addExtensions
:(GPBExtensionRegistry
*)registry
;