Provide a protocol for GPBExtensionRegistry's lookup support.
This allows some to use an alternative registry if they have a different
implementation.
This is really just wiring though the change to use the GPBExtensionRegistry
protocol vs the concrete GPBExtensionRegistry through the other apis.
diff --git a/objectivec/GPBCodedInputStream.h b/objectivec/GPBCodedInputStream.h
index 1886ccf..73b6558 100644
--- a/objectivec/GPBCodedInputStream.h
+++ b/objectivec/GPBCodedInputStream.h
@@ -31,7 +31,7 @@
#import <Foundation/Foundation.h>
@class GPBMessage;
-@class GPBExtensionRegistry;
+@protocol GPBExtensionRegistry;
NS_ASSUME_NONNULL_BEGIN
@@ -184,7 +184,7 @@
* extensions for message.
**/
- (void)readMessage:(GPBMessage *)message
- extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry;
+ extensionRegistry:(nullable id<GPBExtensionRegistry>)extensionRegistry;
/**
* Reads and discards a single field, given its tag value.
diff --git a/objectivec/GPBCodedInputStream.m b/objectivec/GPBCodedInputStream.m
index c459391..25dde75 100644
--- a/objectivec/GPBCodedInputStream.m
+++ b/objectivec/GPBCodedInputStream.m
@@ -434,7 +434,7 @@
- (void)readGroup:(int32_t)fieldNumber
message:(GPBMessage *)message
- extensionRegistry:(GPBExtensionRegistry *)extensionRegistry {
+ extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry {
CheckRecursionLimit(&state_);
++state_.recursionDepth;
[message mergeFromCodedInputStream:self extensionRegistry:extensionRegistry];
@@ -454,7 +454,7 @@
}
- (void)readMessage:(GPBMessage *)message
- extensionRegistry:(GPBExtensionRegistry *)extensionRegistry {
+ extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry {
CheckRecursionLimit(&state_);
int32_t length = ReadRawVarint32(&state_);
size_t oldLimit = GPBCodedInputStreamPushLimit(&state_, length);
@@ -466,7 +466,7 @@
}
- (void)readMapEntry:(id)mapDictionary
- extensionRegistry:(GPBExtensionRegistry *)extensionRegistry
+ extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry
field:(GPBFieldDescriptor *)field
parentMessage:(GPBMessage *)parentMessage {
CheckRecursionLimit(&state_);
diff --git a/objectivec/GPBCodedInputStream_PackagePrivate.h b/objectivec/GPBCodedInputStream_PackagePrivate.h
index 43ec6e7..cdfb0dc 100644
--- a/objectivec/GPBCodedInputStream_PackagePrivate.h
+++ b/objectivec/GPBCodedInputStream_PackagePrivate.h
@@ -61,7 +61,7 @@
// support for older data.
- (void)readGroup:(int32_t)fieldNumber
message:(GPBMessage *)message
- extensionRegistry:(GPBExtensionRegistry *)extensionRegistry;
+ extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry;
// Reads a group field value from the stream and merges it into the given
// UnknownFieldSet.
@@ -70,7 +70,7 @@
// Reads a map entry.
- (void)readMapEntry:(id)mapDictionary
- extensionRegistry:(GPBExtensionRegistry *)extensionRegistry
+ extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry
field:(GPBFieldDescriptor *)field
parentMessage:(GPBMessage *)parentMessage;
@end
diff --git a/objectivec/GPBDictionary.m b/objectivec/GPBDictionary.m
index 187a970..77642c2 100644
--- a/objectivec/GPBDictionary.m
+++ b/objectivec/GPBDictionary.m
@@ -386,7 +386,7 @@
static void ReadValue(GPBCodedInputStream *stream,
GPBGenericValue *valueToFill,
GPBDataType type,
- GPBExtensionRegistry *registry,
+ id<GPBExtensionRegistry>registry,
GPBFieldDescriptor *field) {
switch (type) {
case GPBDataTypeBool:
@@ -454,7 +454,7 @@
void GPBDictionaryReadEntry(id mapDictionary,
GPBCodedInputStream *stream,
- GPBExtensionRegistry *registry,
+ id<GPBExtensionRegistry>registry,
GPBFieldDescriptor *field,
GPBMessage *parentMessage) {
GPBDataType keyDataType = field.mapKeyDataType;
diff --git a/objectivec/GPBDictionary_PackagePrivate.h b/objectivec/GPBDictionary_PackagePrivate.h
index 15e4283..d494b7e 100644
--- a/objectivec/GPBDictionary_PackagePrivate.h
+++ b/objectivec/GPBDictionary_PackagePrivate.h
@@ -34,7 +34,7 @@
@class GPBCodedInputStream;
@class GPBCodedOutputStream;
-@class GPBExtensionRegistry;
+@protocol GPBExtensionRegistry;
@class GPBFieldDescriptor;
@protocol GPBDictionaryInternalsProtocol
@@ -493,7 +493,7 @@
// Helper to read a map instead.
void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream,
- GPBExtensionRegistry *registry,
+ id<GPBExtensionRegistry>registry,
GPBFieldDescriptor *field,
GPBMessage *parentMessage);
diff --git a/objectivec/GPBExtensionInternals.h b/objectivec/GPBExtensionInternals.h
index 2b980ae..854b57f 100644
--- a/objectivec/GPBExtensionInternals.h
+++ b/objectivec/GPBExtensionInternals.h
@@ -34,12 +34,12 @@
@class GPBCodedInputStream;
@class GPBCodedOutputStream;
-@class GPBExtensionRegistry;
+@protocol GPBExtensionRegistry;
void GPBExtensionMergeFromInputStream(GPBExtensionDescriptor *extension,
BOOL isPackedOnStream,
GPBCodedInputStream *input,
- GPBExtensionRegistry *extensionRegistry,
+ id<GPBExtensionRegistry>extensionRegistry,
GPBMessage *message);
size_t GPBComputeExtensionSerializedSizeIncludingTag(
diff --git a/objectivec/GPBExtensionInternals.m b/objectivec/GPBExtensionInternals.m
index bacec57..b74591e 100644
--- a/objectivec/GPBExtensionInternals.m
+++ b/objectivec/GPBExtensionInternals.m
@@ -40,7 +40,7 @@
static id NewSingleValueFromInputStream(GPBExtensionDescriptor *extension,
GPBCodedInputStream *input,
- GPBExtensionRegistry *extensionRegistry,
+ id<GPBExtensionRegistry>extensionRegistry,
GPBMessage *existingValue)
__attribute__((ns_returns_retained));
@@ -273,7 +273,7 @@
void GPBExtensionMergeFromInputStream(GPBExtensionDescriptor *extension,
BOOL isPackedOnStream,
GPBCodedInputStream *input,
- GPBExtensionRegistry *extensionRegistry,
+ id<GPBExtensionRegistry>extensionRegistry,
GPBMessage *message) {
GPBExtensionDescription *description = extension->description_;
GPBCodedInputStreamState *state = &input->state_;
@@ -334,7 +334,7 @@
// Note that this returns a retained value intentionally.
static id NewSingleValueFromInputStream(GPBExtensionDescriptor *extension,
GPBCodedInputStream *input,
- GPBExtensionRegistry *extensionRegistry,
+ id<GPBExtensionRegistry>extensionRegistry,
GPBMessage *existingValue) {
GPBExtensionDescription *description = extension->description_;
GPBCodedInputStreamState *state = &input->state_;
diff --git a/objectivec/GPBExtensionRegistry.h b/objectivec/GPBExtensionRegistry.h
index d79632d..b185056 100644
--- a/objectivec/GPBExtensionRegistry.h
+++ b/objectivec/GPBExtensionRegistry.h
@@ -41,6 +41,24 @@
* GPBExtensionRegistry in which you have registered any extensions that you
* want to be able to parse. Otherwise, those extensions will just be treated
* like unknown fields.
+ **/
+@protocol GPBExtensionRegistry <NSObject>
+
+/**
+ * Looks for the extension registered for the given field number on a given
+ * GPBDescriptor.
+ *
+ * @param descriptor The descriptor to look for a registered extension on.
+ * @param fieldNumber The field number of the extension to look for.
+ *
+ * @return The registered GPBExtensionDescriptor or nil if none was found.
+ **/
+- (nullable GPBExtensionDescriptor *)extensionForDescriptor:(GPBDescriptor *)descriptor
+ fieldNumber:(NSInteger)fieldNumber;
+@end
+
+/**
+ * A concrete implementation of `GPBExtensionRegistry`.
*
* The *Root classes provide `+extensionRegistry` for the extensions defined
* in a given file *and* all files it imports. You can also create a
@@ -54,7 +72,7 @@
* MyMessage *msg = [MyMessage parseData:data extensionRegistry:registry error:&parseError];
* ```
**/
-@interface GPBExtensionRegistry : NSObject<NSCopying>
+@interface GPBExtensionRegistry : NSObject<NSCopying, GPBExtensionRegistry>
/**
* Adds the given GPBExtensionDescriptor to this registry.
@@ -70,18 +88,6 @@
**/
- (void)addExtensions:(GPBExtensionRegistry *)registry;
-/**
- * Looks for the extension registered for the given field number on a given
- * GPBDescriptor.
- *
- * @param descriptor The descriptor to look for a registered extension on.
- * @param fieldNumber The field number of the extension to look for.
- *
- * @return The registered GPBExtensionDescriptor or nil if none was found.
- **/
-- (nullable GPBExtensionDescriptor *)extensionForDescriptor:(GPBDescriptor *)descriptor
- fieldNumber:(NSInteger)fieldNumber;
-
@end
NS_ASSUME_NONNULL_END
diff --git a/objectivec/GPBMessage.h b/objectivec/GPBMessage.h
index 01253a4..990a796 100644
--- a/objectivec/GPBMessage.h
+++ b/objectivec/GPBMessage.h
@@ -36,7 +36,7 @@
@class GPBCodedInputStream;
@class GPBCodedOutputStream;
@class GPBExtensionDescriptor;
-@class GPBExtensionRegistry;
+@protocol GPBExtensionRegistry;
@class GPBFieldDescriptor;
@class GPBUnknownFieldSet;
@@ -147,7 +147,7 @@
* @return A new instance of the generated class.
**/
+ (nullable instancetype)parseFromData:(NSData *)data
- extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry
+ extensionRegistry:(nullable id<GPBExtensionRegistry>)extensionRegistry
error:(NSError **)errorPtr;
/**
@@ -171,7 +171,7 @@
**/
+ (nullable instancetype)parseFromCodedInputStream:(GPBCodedInputStream *)input
extensionRegistry:
- (nullable GPBExtensionRegistry *)extensionRegistry
+ (nullable id<GPBExtensionRegistry>)extensionRegistry
error:(NSError **)errorPtr;
/**
@@ -196,7 +196,7 @@
**/
+ (nullable instancetype)parseDelimitedFromCodedInputStream:(GPBCodedInputStream *)input
extensionRegistry:
- (nullable GPBExtensionRegistry *)extensionRegistry
+ (nullable id<GPBExtensionRegistry>)extensionRegistry
error:(NSError **)errorPtr;
/**
@@ -239,7 +239,7 @@
* @return An initialized instance of the generated class.
**/
- (nullable instancetype)initWithData:(NSData *)data
- extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry
+ extensionRegistry:(nullable id<GPBExtensionRegistry>)extensionRegistry
error:(NSError **)errorPtr;
/**
@@ -264,7 +264,7 @@
**/
- (nullable instancetype)initWithCodedInputStream:(GPBCodedInputStream *)input
extensionRegistry:
- (nullable GPBExtensionRegistry *)extensionRegistry
+ (nullable id<GPBExtensionRegistry>)extensionRegistry
error:(NSError **)errorPtr;
/**
@@ -278,7 +278,7 @@
* unsuccessful.
**/
- (void)mergeFromData:(NSData *)data
- extensionRegistry:(nullable GPBExtensionRegistry *)extensionRegistry;
+ extensionRegistry:(nullable id<GPBExtensionRegistry>)extensionRegistry;
/**
* Merges the fields from another message (of the same type) into this
diff --git a/objectivec/GPBMessage.m b/objectivec/GPBMessage.m
index ee94dee..b293604 100644
--- a/objectivec/GPBMessage.m
+++ b/objectivec/GPBMessage.m
@@ -881,7 +881,7 @@
}
- (instancetype)initWithData:(NSData *)data
- extensionRegistry:(GPBExtensionRegistry *)extensionRegistry
+ extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry
error:(NSError **)errorPtr {
if ((self = [self init])) {
@try {
@@ -912,7 +912,7 @@
- (instancetype)initWithCodedInputStream:(GPBCodedInputStream *)input
extensionRegistry:
- (GPBExtensionRegistry *)extensionRegistry
+ (id<GPBExtensionRegistry>)extensionRegistry
error:(NSError **)errorPtr {
if ((self = [self init])) {
@try {
@@ -1973,7 +1973,7 @@
#pragma mark - mergeFrom
- (void)mergeFromData:(NSData *)data
- extensionRegistry:(GPBExtensionRegistry *)extensionRegistry {
+ extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry {
GPBCodedInputStream *input = [[GPBCodedInputStream alloc] initWithData:data];
[self mergeFromCodedInputStream:input extensionRegistry:extensionRegistry];
[input checkLastTagWas:0];
@@ -1983,7 +1983,7 @@
#pragma mark - mergeDelimitedFrom
- (void)mergeDelimitedFromCodedInputStream:(GPBCodedInputStream *)input
- extensionRegistry:(GPBExtensionRegistry *)extensionRegistry {
+ extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry {
GPBCodedInputStreamState *state = &input->state_;
if (GPBCodedInputStreamIsAtEnd(state)) {
return;
@@ -2003,7 +2003,7 @@
}
+ (instancetype)parseFromData:(NSData *)data
- extensionRegistry:(GPBExtensionRegistry *)extensionRegistry
+ extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry
error:(NSError **)errorPtr {
return [[[self alloc] initWithData:data
extensionRegistry:extensionRegistry
@@ -2011,7 +2011,7 @@
}
+ (instancetype)parseFromCodedInputStream:(GPBCodedInputStream *)input
- extensionRegistry:(GPBExtensionRegistry *)extensionRegistry
+ extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry
error:(NSError **)errorPtr {
return
[[[self alloc] initWithCodedInputStream:input
@@ -2023,7 +2023,7 @@
+ (instancetype)parseDelimitedFromCodedInputStream:(GPBCodedInputStream *)input
extensionRegistry:
- (GPBExtensionRegistry *)extensionRegistry
+ (id<GPBExtensionRegistry>)extensionRegistry
error:(NSError **)errorPtr {
GPBMessage *message = [[[self alloc] init] autorelease];
@try {
@@ -2065,7 +2065,7 @@
}
- (void)parseMessageSet:(GPBCodedInputStream *)input
- extensionRegistry:(GPBExtensionRegistry *)extensionRegistry {
+ extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry {
uint32_t typeId = 0;
NSData *rawBytes = nil;
GPBExtensionDescriptor *extension = nil;
@@ -2117,7 +2117,7 @@
}
- (BOOL)parseUnknownField:(GPBCodedInputStream *)input
- extensionRegistry:(GPBExtensionRegistry *)extensionRegistry
+ extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry
tag:(uint32_t)tag {
GPBWireFormat wireType = GPBWireFormatGetTagWireType(tag);
int32_t fieldNumber = GPBWireFormatGetTagFieldNumber(tag);
@@ -2170,7 +2170,7 @@
static void MergeSingleFieldFromCodedInputStream(
GPBMessage *self, GPBFieldDescriptor *field, GPBFileSyntax syntax,
- GPBCodedInputStream *input, GPBExtensionRegistry *extensionRegistry) {
+ GPBCodedInputStream *input, id<GPBExtensionRegistry>extensionRegistry) {
GPBDataType fieldDataType = GPBGetFieldDataType(field);
switch (fieldDataType) {
#define CASE_SINGLE_POD(NAME, TYPE, FUNC_TYPE) \
@@ -2306,7 +2306,7 @@
static void MergeRepeatedNotPackedFieldFromCodedInputStream(
GPBMessage *self, GPBFieldDescriptor *field, GPBFileSyntax syntax,
- GPBCodedInputStream *input, GPBExtensionRegistry *extensionRegistry) {
+ GPBCodedInputStream *input, id<GPBExtensionRegistry>extensionRegistry) {
GPBCodedInputStreamState *state = &input->state_;
id genericArray = GetOrCreateArrayIvarWithField(self, field);
switch (GPBGetFieldDataType(field)) {
@@ -2371,7 +2371,7 @@
}
- (void)mergeFromCodedInputStream:(GPBCodedInputStream *)input
- extensionRegistry:(GPBExtensionRegistry *)extensionRegistry {
+ extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry {
GPBDescriptor *descriptor = [self descriptor];
GPBFileSyntax syntax = descriptor.file.syntax;
GPBCodedInputStreamState *state = &input->state_;
diff --git a/objectivec/GPBMessage_PackagePrivate.h b/objectivec/GPBMessage_PackagePrivate.h
index ca10983..a8755a2 100644
--- a/objectivec/GPBMessage_PackagePrivate.h
+++ b/objectivec/GPBMessage_PackagePrivate.h
@@ -78,13 +78,13 @@
// or zero for EOF.
// NOTE: This will throw if there is an error while parsing.
- (void)mergeFromCodedInputStream:(GPBCodedInputStream *)input
- extensionRegistry:(GPBExtensionRegistry *)extensionRegistry;
+ extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry;
// Parses the next delimited message of this type from the input and merges it
// with this message.
- (void)mergeDelimitedFromCodedInputStream:(GPBCodedInputStream *)input
extensionRegistry:
- (GPBExtensionRegistry *)extensionRegistry;
+ (id<GPBExtensionRegistry>)extensionRegistry;
- (void)addUnknownMapEntry:(int32_t)fieldNum value:(NSData *)data;