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.
pull/10620/head
Thomas Van Lenten 2 years ago
parent e18aa2eda7
commit f191ab0f35
  1. 4
      objectivec/GPBCodedInputStream.h
  2. 6
      objectivec/GPBCodedInputStream.m
  3. 4
      objectivec/GPBCodedInputStream_PackagePrivate.h
  4. 4
      objectivec/GPBDictionary.m
  5. 4
      objectivec/GPBDictionary_PackagePrivate.h
  6. 4
      objectivec/GPBExtensionInternals.h
  7. 6
      objectivec/GPBExtensionInternals.m
  8. 32
      objectivec/GPBExtensionRegistry.h
  9. 14
      objectivec/GPBMessage.h
  10. 24
      objectivec/GPBMessage.m
  11. 4
      objectivec/GPBMessage_PackagePrivate.h

@ -31,7 +31,7 @@
#import <Foundation/Foundation.h>
@class GPBMessage;
@class GPBExtensionRegistry;
@protocol GPBExtensionRegistry;
NS_ASSUME_NONNULL_BEGIN
@ -184,7 +184,7 @@ CF_EXTERN_C_END
* 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.

@ -434,7 +434,7 @@ void GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state,
- (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 GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state,
}
- (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 GPBCodedInputStreamCheckLastTagWas(GPBCodedInputStreamState *state,
}
- (void)readMapEntry:(id)mapDictionary
extensionRegistry:(GPBExtensionRegistry *)extensionRegistry
extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry
field:(GPBFieldDescriptor *)field
parentMessage:(GPBMessage *)parentMessage {
CheckRecursionLimit(&state_);

@ -61,7 +61,7 @@ typedef struct GPBCodedInputStreamState {
// 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 @@ typedef struct GPBCodedInputStreamState {
// Reads a map entry.
- (void)readMapEntry:(id)mapDictionary
extensionRegistry:(GPBExtensionRegistry *)extensionRegistry
extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry
field:(GPBFieldDescriptor *)field
parentMessage:(GPBMessage *)parentMessage;
@end

@ -386,7 +386,7 @@ BOOL GPBDictionaryIsInitializedInternalHelper(NSDictionary *dict, GPBFieldDescri
static void ReadValue(GPBCodedInputStream *stream,
GPBGenericValue *valueToFill,
GPBDataType type,
GPBExtensionRegistry *registry,
id<GPBExtensionRegistry>registry,
GPBFieldDescriptor *field) {
switch (type) {
case GPBDataTypeBool:
@ -454,7 +454,7 @@ static void ReadValue(GPBCodedInputStream *stream,
void GPBDictionaryReadEntry(id mapDictionary,
GPBCodedInputStream *stream,
GPBExtensionRegistry *registry,
id<GPBExtensionRegistry>registry,
GPBFieldDescriptor *field,
GPBMessage *parentMessage) {
GPBDataType keyDataType = field.mapKeyDataType;

@ -34,7 +34,7 @@
@class GPBCodedInputStream;
@class GPBCodedOutputStream;
@class GPBExtensionRegistry;
@protocol GPBExtensionRegistry;
@class GPBFieldDescriptor;
@protocol GPBDictionaryInternalsProtocol
@ -493,7 +493,7 @@ BOOL GPBDictionaryIsInitializedInternalHelper(NSDictionary *dict,
// Helper to read a map instead.
void GPBDictionaryReadEntry(id mapDictionary, GPBCodedInputStream *stream,
GPBExtensionRegistry *registry,
id<GPBExtensionRegistry>registry,
GPBFieldDescriptor *field,
GPBMessage *parentMessage);

@ -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(

@ -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 @@ static void WriteArrayIncludingTagsToCodedOutputStream(
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 @@ size_t GPBComputeExtensionSerializedSizeIncludingTag(
// 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_;

@ -41,6 +41,24 @@ NS_ASSUME_NONNULL_BEGIN
* 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 @@ NS_ASSUME_NONNULL_BEGIN
* 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 @@ NS_ASSUME_NONNULL_BEGIN
**/
- (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

@ -36,7 +36,7 @@
@class GPBCodedInputStream;
@class GPBCodedOutputStream;
@class GPBExtensionDescriptor;
@class GPBExtensionRegistry;
@protocol GPBExtensionRegistry;
@class GPBFieldDescriptor;
@class GPBUnknownFieldSet;
@ -147,7 +147,7 @@ CF_EXTERN_C_END
* @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 @@ CF_EXTERN_C_END
**/
+ (nullable instancetype)parseFromCodedInputStream:(GPBCodedInputStream *)input
extensionRegistry:
(nullable GPBExtensionRegistry *)extensionRegistry
(nullable id<GPBExtensionRegistry>)extensionRegistry
error:(NSError **)errorPtr;
/**
@ -196,7 +196,7 @@ CF_EXTERN_C_END
**/
+ (nullable instancetype)parseDelimitedFromCodedInputStream:(GPBCodedInputStream *)input
extensionRegistry:
(nullable GPBExtensionRegistry *)extensionRegistry
(nullable id<GPBExtensionRegistry>)extensionRegistry
error:(NSError **)errorPtr;
/**
@ -239,7 +239,7 @@ CF_EXTERN_C_END
* @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 @@ CF_EXTERN_C_END
**/
- (nullable instancetype)initWithCodedInputStream:(GPBCodedInputStream *)input
extensionRegistry:
(nullable GPBExtensionRegistry *)extensionRegistry
(nullable id<GPBExtensionRegistry>)extensionRegistry
error:(NSError **)errorPtr;
/**
@ -278,7 +278,7 @@ CF_EXTERN_C_END
* 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

@ -881,7 +881,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) {
}
- (instancetype)initWithData:(NSData *)data
extensionRegistry:(GPBExtensionRegistry *)extensionRegistry
extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry
error:(NSError **)errorPtr {
if ((self = [self init])) {
@try {
@ -912,7 +912,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) {
- (instancetype)initWithCodedInputStream:(GPBCodedInputStream *)input
extensionRegistry:
(GPBExtensionRegistry *)extensionRegistry
(id<GPBExtensionRegistry>)extensionRegistry
error:(NSError **)errorPtr {
if ((self = [self init])) {
@try {
@ -1973,7 +1973,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) {
#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 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) {
#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 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) {
}
+ (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 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) {
}
+ (instancetype)parseFromCodedInputStream:(GPBCodedInputStream *)input
extensionRegistry:(GPBExtensionRegistry *)extensionRegistry
extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry
error:(NSError **)errorPtr {
return
[[[self alloc] initWithCodedInputStream:input
@ -2023,7 +2023,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) {
+ (instancetype)parseDelimitedFromCodedInputStream:(GPBCodedInputStream *)input
extensionRegistry:
(GPBExtensionRegistry *)extensionRegistry
(id<GPBExtensionRegistry>)extensionRegistry
error:(NSError **)errorPtr {
GPBMessage *message = [[[self alloc] init] autorelease];
@try {
@ -2065,7 +2065,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) {
}
- (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 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) {
}
- (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 GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) {
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 MergeRepeatedPackedFieldFromCodedInputStream(
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 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream(
}
- (void)mergeFromCodedInputStream:(GPBCodedInputStream *)input
extensionRegistry:(GPBExtensionRegistry *)extensionRegistry {
extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry {
GPBDescriptor *descriptor = [self descriptor];
GPBFileSyntax syntax = descriptor.file.syntax;
GPBCodedInputStreamState *state = &input->state_;

@ -78,13 +78,13 @@ typedef struct GPBMessage_Storage *GPBMessage_StoragePtr;
// 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;

Loading…
Cancel
Save