GPBExtensionRegistry.h 2.4 KB

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