GPBExtensionRegistry.h 2.4 KB

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