|
|
|
@ -1821,7 +1821,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { |
|
|
|
|
|
|
|
|
|
//%PDDM-EXPAND-END (18 expansions) |
|
|
|
|
|
|
|
|
|
// clang-format off |
|
|
|
|
// clang-format on |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1848,8 +1848,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { |
|
|
|
|
value = [autocreatedExtensionMap_ objectForKey:extension]; |
|
|
|
|
if (!value) { |
|
|
|
|
// Auto create the message extensions to match normal fields. |
|
|
|
|
value = CreateMessageWithAutocreatorForExtension(extension.msgClass, self, |
|
|
|
|
extension); |
|
|
|
|
value = CreateMessageWithAutocreatorForExtension(extension.msgClass, self, extension); |
|
|
|
|
|
|
|
|
|
if (autocreatedExtensionMap_ == nil) { |
|
|
|
|
autocreatedExtensionMap_ = [[NSMutableDictionary alloc] init]; |
|
|
|
@ -1926,8 +1925,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { |
|
|
|
|
GPBExtensionDescriptor *descriptor = extension; |
|
|
|
|
|
|
|
|
|
if (GPBExtensionIsMessage(descriptor) && !descriptor.isRepeated) { |
|
|
|
|
GPBMessage *autocreatedValue = |
|
|
|
|
[[autocreatedExtensionMap_ objectForKey:extension] retain]; |
|
|
|
|
GPBMessage *autocreatedValue = [[autocreatedExtensionMap_ objectForKey:extension] retain]; |
|
|
|
|
// Must remove from the map before calling GPBClearMessageAutocreator() so |
|
|
|
|
// that GPBClearMessageAutocreator() knows its safe to clear. |
|
|
|
|
[autocreatedExtensionMap_ removeObjectForKey:extension]; |
|
|
|
@ -1959,9 +1957,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { |
|
|
|
|
GPBBecomeVisibleToAutocreator(self); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
- (void)setExtension:(GPBExtensionDescriptor *)extension |
|
|
|
|
index:(NSUInteger)idx |
|
|
|
|
value:(id)value { |
|
|
|
|
- (void)setExtension:(GPBExtensionDescriptor *)extension index:(NSUInteger)idx value:(id)value { |
|
|
|
|
CheckExtension(self, extension); |
|
|
|
|
|
|
|
|
|
if (!extension.repeated) { |
|
|
|
@ -1991,8 +1987,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { |
|
|
|
|
|
|
|
|
|
#pragma mark - mergeFrom |
|
|
|
|
|
|
|
|
|
- (void)mergeFromData:(NSData *)data |
|
|
|
|
extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry { |
|
|
|
|
- (void)mergeFromData:(NSData *)data extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry { |
|
|
|
|
GPBCodedInputStream *input = [[GPBCodedInputStream alloc] initWithData:data]; |
|
|
|
|
[self mergeFromCodedInputStream:input extensionRegistry:extensionRegistry]; |
|
|
|
|
[input checkLastTagWas:0]; |
|
|
|
@ -2024,16 +2019,14 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { |
|
|
|
|
+ (instancetype)parseFromData:(NSData *)data |
|
|
|
|
extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry |
|
|
|
|
error:(NSError **)errorPtr { |
|
|
|
|
return [[[self alloc] initWithData:data |
|
|
|
|
extensionRegistry:extensionRegistry |
|
|
|
|
return [[[self alloc] initWithData:data extensionRegistry:extensionRegistry |
|
|
|
|
error:errorPtr] autorelease]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
+ (instancetype)parseFromCodedInputStream:(GPBCodedInputStream *)input |
|
|
|
|
extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry |
|
|
|
|
error:(NSError **)errorPtr { |
|
|
|
|
return |
|
|
|
|
[[[self alloc] initWithCodedInputStream:input |
|
|
|
|
return [[[self alloc] initWithCodedInputStream:input |
|
|
|
|
extensionRegistry:extensionRegistry |
|
|
|
|
error:errorPtr] autorelease]; |
|
|
|
|
} |
|
|
|
@ -2041,18 +2034,15 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { |
|
|
|
|
#pragma mark - Parse Delimited From Data Support |
|
|
|
|
|
|
|
|
|
+ (instancetype)parseDelimitedFromCodedInputStream:(GPBCodedInputStream *)input |
|
|
|
|
extensionRegistry: |
|
|
|
|
(id<GPBExtensionRegistry>)extensionRegistry |
|
|
|
|
extensionRegistry:(id<GPBExtensionRegistry>)extensionRegistry |
|
|
|
|
error:(NSError **)errorPtr { |
|
|
|
|
GPBMessage *message = [[[self alloc] init] autorelease]; |
|
|
|
|
@try { |
|
|
|
|
[message mergeDelimitedFromCodedInputStream:input |
|
|
|
|
extensionRegistry:extensionRegistry]; |
|
|
|
|
[message mergeDelimitedFromCodedInputStream:input extensionRegistry:extensionRegistry]; |
|
|
|
|
if (errorPtr) { |
|
|
|
|
*errorPtr = nil; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@catch (NSException *exception) { |
|
|
|
|
} @catch (NSException *exception) { |
|
|
|
|
message = nil; |
|
|
|
|
if (errorPtr) { |
|
|
|
|
*errorPtr = ErrorFromException(exception); |
|
|
|
@ -2098,12 +2088,10 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { |
|
|
|
|
if (tag == GPBWireFormatMessageSetTypeIdTag) { |
|
|
|
|
typeId = GPBCodedInputStreamReadUInt32(state); |
|
|
|
|
if (typeId != 0) { |
|
|
|
|
extension = [extensionRegistry extensionForDescriptor:[self descriptor] |
|
|
|
|
fieldNumber:typeId]; |
|
|
|
|
extension = [extensionRegistry extensionForDescriptor:[self descriptor] fieldNumber:typeId]; |
|
|
|
|
} |
|
|
|
|
} else if (tag == GPBWireFormatMessageSetMessageTag) { |
|
|
|
|
rawBytes = |
|
|
|
|
[GPBCodedInputStreamReadRetainedBytesNoCopy(state) autorelease]; |
|
|
|
|
rawBytes = [GPBCodedInputStreamReadRetainedBytesNoCopy(state) autorelease]; |
|
|
|
|
} else { |
|
|
|
|
if (![input skipField:tag]) { |
|
|
|
|
break; |
|
|
|
@ -2115,12 +2103,8 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { |
|
|
|
|
|
|
|
|
|
if (rawBytes != nil && typeId != 0) { |
|
|
|
|
if (extension != nil) { |
|
|
|
|
GPBCodedInputStream *newInput = |
|
|
|
|
[[GPBCodedInputStream alloc] initWithData:rawBytes]; |
|
|
|
|
ExtensionMergeFromInputStream(extension, |
|
|
|
|
extension.packable, |
|
|
|
|
newInput, |
|
|
|
|
extensionRegistry, |
|
|
|
|
GPBCodedInputStream *newInput = [[GPBCodedInputStream alloc] initWithData:rawBytes]; |
|
|
|
|
ExtensionMergeFromInputStream(extension, extension.packable, newInput, extensionRegistry, |
|
|
|
|
self); |
|
|
|
|
[newInput release]; |
|
|
|
|
} else { |
|
|
|
@ -2142,8 +2126,7 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { |
|
|
|
|
int32_t fieldNumber = GPBWireFormatGetTagFieldNumber(tag); |
|
|
|
|
|
|
|
|
|
GPBDescriptor *descriptor = [self descriptor]; |
|
|
|
|
GPBExtensionDescriptor *extension = |
|
|
|
|
[extensionRegistry extensionForDescriptor:descriptor |
|
|
|
|
GPBExtensionDescriptor *extension = [extensionRegistry extensionForDescriptor:descriptor |
|
|
|
|
fieldNumber:fieldNumber]; |
|
|
|
|
if (extension == nil) { |
|
|
|
|
if (descriptor.wireFormat && GPBWireFormatMessageSetItemTag == tag) { |
|
|
|
@ -2152,23 +2135,14 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
if (extension.wireType == wireType) { |
|
|
|
|
ExtensionMergeFromInputStream(extension, |
|
|
|
|
extension.packable, |
|
|
|
|
input, |
|
|
|
|
extensionRegistry, |
|
|
|
|
self); |
|
|
|
|
ExtensionMergeFromInputStream(extension, extension.packable, input, extensionRegistry, self); |
|
|
|
|
return YES; |
|
|
|
|
} |
|
|
|
|
// Primitive, repeated types can be packed on unpacked on the wire, and are |
|
|
|
|
// parsed either way. |
|
|
|
|
if ([extension isRepeated] && |
|
|
|
|
!GPBDataTypeIsObject(extension->description_->dataType) && |
|
|
|
|
if ([extension isRepeated] && !GPBDataTypeIsObject(extension->description_->dataType) && |
|
|
|
|
(extension.alternateWireType == wireType)) { |
|
|
|
|
ExtensionMergeFromInputStream(extension, |
|
|
|
|
!extension.packable, |
|
|
|
|
input, |
|
|
|
|
extensionRegistry, |
|
|
|
|
self); |
|
|
|
|
ExtensionMergeFromInputStream(extension, !extension.packable, input, extensionRegistry, self); |
|
|
|
|
return YES; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -2187,9 +2161,9 @@ static GPBUnknownFieldSet *GetOrMakeUnknownFields(GPBMessage *self) { |
|
|
|
|
|
|
|
|
|
#pragma mark - MergeFromCodedInputStream Support |
|
|
|
|
|
|
|
|
|
static void MergeSingleFieldFromCodedInputStream( |
|
|
|
|
GPBMessage *self, GPBFieldDescriptor *field, |
|
|
|
|
GPBCodedInputStream *input, id<GPBExtensionRegistry>extensionRegistry) { |
|
|
|
|
static void MergeSingleFieldFromCodedInputStream(GPBMessage *self, GPBFieldDescriptor *field, |
|
|
|
|
GPBCodedInputStream *input, |
|
|
|
|
id<GPBExtensionRegistry> extensionRegistry) { |
|
|
|
|
GPBDataType fieldDataType = GPBGetFieldDataType(field); |
|
|
|
|
switch (fieldDataType) { |
|
|
|
|
#define CASE_SINGLE_POD(NAME, TYPE, FUNC_TYPE) \ |
|
|
|
@ -2226,8 +2200,7 @@ static void MergeSingleFieldFromCodedInputStream( |
|
|
|
|
if (GPBGetHasIvarField(self, field)) { |
|
|
|
|
// GPBGetObjectIvarWithFieldNoAutocreate() avoids doing the has |
|
|
|
|
// check again. |
|
|
|
|
GPBMessage *message = |
|
|
|
|
GPBGetObjectIvarWithFieldNoAutocreate(self, field); |
|
|
|
|
GPBMessage *message = GPBGetObjectIvarWithFieldNoAutocreate(self, field); |
|
|
|
|
[input readMessage:message extensionRegistry:extensionRegistry]; |
|
|
|
|
} else { |
|
|
|
|
GPBMessage *message = [[field.msgClass alloc] init]; |
|
|
|
@ -2241,16 +2214,11 @@ static void MergeSingleFieldFromCodedInputStream( |
|
|
|
|
if (GPBGetHasIvarField(self, field)) { |
|
|
|
|
// GPBGetObjectIvarWithFieldNoAutocreate() avoids doing the has |
|
|
|
|
// check again. |
|
|
|
|
GPBMessage *message = |
|
|
|
|
GPBGetObjectIvarWithFieldNoAutocreate(self, field); |
|
|
|
|
[input readGroup:GPBFieldNumber(field) |
|
|
|
|
message:message |
|
|
|
|
extensionRegistry:extensionRegistry]; |
|
|
|
|
GPBMessage *message = GPBGetObjectIvarWithFieldNoAutocreate(self, field); |
|
|
|
|
[input readGroup:GPBFieldNumber(field) message:message extensionRegistry:extensionRegistry]; |
|
|
|
|
} else { |
|
|
|
|
GPBMessage *message = [[field.msgClass alloc] init]; |
|
|
|
|
[input readGroup:GPBFieldNumber(field) |
|
|
|
|
message:message |
|
|
|
|
extensionRegistry:extensionRegistry]; |
|
|
|
|
[input readGroup:GPBFieldNumber(field) message:message extensionRegistry:extensionRegistry]; |
|
|
|
|
GPBSetRetainedObjectIvarWithFieldPrivate(self, field, message); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
@ -2268,8 +2236,8 @@ static void MergeSingleFieldFromCodedInputStream( |
|
|
|
|
} // switch |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void MergeRepeatedPackedFieldFromCodedInputStream( |
|
|
|
|
GPBMessage *self, GPBFieldDescriptor *field, |
|
|
|
|
static void MergeRepeatedPackedFieldFromCodedInputStream(GPBMessage *self, |
|
|
|
|
GPBFieldDescriptor *field, |
|
|
|
|
GPBCodedInputStream *input) { |
|
|
|
|
GPBDataType fieldDataType = GPBGetFieldDataType(field); |
|
|
|
|
GPBCodedInputStreamState *state = &input->state_; |
|
|
|
@ -2322,8 +2290,8 @@ static void MergeRepeatedPackedFieldFromCodedInputStream( |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void MergeRepeatedNotPackedFieldFromCodedInputStream( |
|
|
|
|
GPBMessage *self, GPBFieldDescriptor *field, |
|
|
|
|
GPBCodedInputStream *input, id<GPBExtensionRegistry>extensionRegistry) { |
|
|
|
|
GPBMessage *self, GPBFieldDescriptor *field, GPBCodedInputStream *input, |
|
|
|
|
id<GPBExtensionRegistry> extensionRegistry) { |
|
|
|
|
GPBCodedInputStreamState *state = &input->state_; |
|
|
|
|
id genericArray = GetOrCreateArrayIvarWithField(self, field); |
|
|
|
|
switch (GPBGetFieldDataType(field)) { |
|
|
|
@ -2366,9 +2334,7 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream( |
|
|
|
|
} |
|
|
|
|
case GPBDataTypeGroup: { |
|
|
|
|
GPBMessage *message = [[field.msgClass alloc] init]; |
|
|
|
|
[input readGroup:GPBFieldNumber(field) |
|
|
|
|
message:message |
|
|
|
|
extensionRegistry:extensionRegistry]; |
|
|
|
|
[input readGroup:GPBFieldNumber(field) message:message extensionRegistry:extensionRegistry]; |
|
|
|
|
[(NSMutableArray *)genericArray addObject:message]; |
|
|
|
|
[message release]; |
|
|
|
|
break; |
|
|
|
@ -2406,21 +2372,19 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream( |
|
|
|
|
if (GPBFieldTag(fieldDescriptor) == tag) { |
|
|
|
|
GPBFieldType fieldType = fieldDescriptor.fieldType; |
|
|
|
|
if (fieldType == GPBFieldTypeSingle) { |
|
|
|
|
MergeSingleFieldFromCodedInputStream(self, fieldDescriptor, |
|
|
|
|
input, extensionRegistry); |
|
|
|
|
MergeSingleFieldFromCodedInputStream(self, fieldDescriptor, input, extensionRegistry); |
|
|
|
|
// Well formed protos will only have a single field once, advance |
|
|
|
|
// the starting index to the next field. |
|
|
|
|
startingIndex += 1; |
|
|
|
|
} else if (fieldType == GPBFieldTypeRepeated) { |
|
|
|
|
if (fieldDescriptor.isPackable) { |
|
|
|
|
MergeRepeatedPackedFieldFromCodedInputStream( |
|
|
|
|
self, fieldDescriptor, input); |
|
|
|
|
MergeRepeatedPackedFieldFromCodedInputStream(self, fieldDescriptor, input); |
|
|
|
|
// Well formed protos will only have a repeated field that is |
|
|
|
|
// packed once, advance the starting index to the next field. |
|
|
|
|
startingIndex += 1; |
|
|
|
|
} else { |
|
|
|
|
MergeRepeatedNotPackedFieldFromCodedInputStream( |
|
|
|
|
self, fieldDescriptor, input, extensionRegistry); |
|
|
|
|
MergeRepeatedNotPackedFieldFromCodedInputStream(self, fieldDescriptor, input, |
|
|
|
|
extensionRegistry); |
|
|
|
|
} |
|
|
|
|
} else { // fieldType == GPBFieldTypeMap |
|
|
|
|
// GPB*Dictionary or NSDictionary, exact type doesn't matter at this |
|
|
|
@ -2450,14 +2414,13 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream( |
|
|
|
|
(GPBFieldAlternateTag(fieldDescriptor) == tag)) { |
|
|
|
|
BOOL alternateIsPacked = !fieldDescriptor.isPackable; |
|
|
|
|
if (alternateIsPacked) { |
|
|
|
|
MergeRepeatedPackedFieldFromCodedInputStream( |
|
|
|
|
self, fieldDescriptor, input); |
|
|
|
|
MergeRepeatedPackedFieldFromCodedInputStream(self, fieldDescriptor, input); |
|
|
|
|
// Well formed protos will only have a repeated field that is |
|
|
|
|
// packed once, advance the starting index to the next field. |
|
|
|
|
startingIndex += 1; |
|
|
|
|
} else { |
|
|
|
|
MergeRepeatedNotPackedFieldFromCodedInputStream( |
|
|
|
|
self, fieldDescriptor, input, extensionRegistry); |
|
|
|
|
MergeRepeatedNotPackedFieldFromCodedInputStream(self, fieldDescriptor, input, |
|
|
|
|
extensionRegistry); |
|
|
|
|
} |
|
|
|
|
merged = YES; |
|
|
|
|
break; |
|
|
|
@ -2472,9 +2435,7 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream( |
|
|
|
|
// zero signals EOF / limit reached |
|
|
|
|
return; |
|
|
|
|
} else { |
|
|
|
|
if (![self parseUnknownField:input |
|
|
|
|
extensionRegistry:extensionRegistry |
|
|
|
|
tag:tag]) { |
|
|
|
|
if (![self parseUnknownField:input extensionRegistry:extensionRegistry tag:tag]) { |
|
|
|
|
// it's an endgroup tag |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
@ -2489,8 +2450,7 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream( |
|
|
|
|
- (void)mergeFrom:(GPBMessage *)other { |
|
|
|
|
Class selfClass = [self class]; |
|
|
|
|
Class otherClass = [other class]; |
|
|
|
|
if (!([selfClass isSubclassOfClass:otherClass] || |
|
|
|
|
[otherClass isSubclassOfClass:selfClass])) { |
|
|
|
|
if (!([selfClass isSubclassOfClass:otherClass] || [otherClass isSubclassOfClass:selfClass])) { |
|
|
|
|
[NSException raise:NSInvalidArgumentException |
|
|
|
|
format:@"Classes must match %@ != %@", selfClass, otherClass]; |
|
|
|
|
} |
|
|
|
@ -2512,39 +2472,32 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream( |
|
|
|
|
GPBDataType fieldDataType = GPBGetFieldDataType(field); |
|
|
|
|
switch (fieldDataType) { |
|
|
|
|
case GPBDataTypeBool: |
|
|
|
|
GPBSetBoolIvarWithFieldPrivate( |
|
|
|
|
self, field, GPBGetMessageBoolField(other, field)); |
|
|
|
|
GPBSetBoolIvarWithFieldPrivate(self, field, GPBGetMessageBoolField(other, field)); |
|
|
|
|
break; |
|
|
|
|
case GPBDataTypeSFixed32: |
|
|
|
|
case GPBDataTypeEnum: |
|
|
|
|
case GPBDataTypeInt32: |
|
|
|
|
case GPBDataTypeSInt32: |
|
|
|
|
GPBSetInt32IvarWithFieldPrivate( |
|
|
|
|
self, field, GPBGetMessageInt32Field(other, field)); |
|
|
|
|
GPBSetInt32IvarWithFieldPrivate(self, field, GPBGetMessageInt32Field(other, field)); |
|
|
|
|
break; |
|
|
|
|
case GPBDataTypeFixed32: |
|
|
|
|
case GPBDataTypeUInt32: |
|
|
|
|
GPBSetUInt32IvarWithFieldPrivate( |
|
|
|
|
self, field, GPBGetMessageUInt32Field(other, field)); |
|
|
|
|
GPBSetUInt32IvarWithFieldPrivate(self, field, GPBGetMessageUInt32Field(other, field)); |
|
|
|
|
break; |
|
|
|
|
case GPBDataTypeSFixed64: |
|
|
|
|
case GPBDataTypeInt64: |
|
|
|
|
case GPBDataTypeSInt64: |
|
|
|
|
GPBSetInt64IvarWithFieldPrivate( |
|
|
|
|
self, field, GPBGetMessageInt64Field(other, field)); |
|
|
|
|
GPBSetInt64IvarWithFieldPrivate(self, field, GPBGetMessageInt64Field(other, field)); |
|
|
|
|
break; |
|
|
|
|
case GPBDataTypeFixed64: |
|
|
|
|
case GPBDataTypeUInt64: |
|
|
|
|
GPBSetUInt64IvarWithFieldPrivate( |
|
|
|
|
self, field, GPBGetMessageUInt64Field(other, field)); |
|
|
|
|
GPBSetUInt64IvarWithFieldPrivate(self, field, GPBGetMessageUInt64Field(other, field)); |
|
|
|
|
break; |
|
|
|
|
case GPBDataTypeFloat: |
|
|
|
|
GPBSetFloatIvarWithFieldPrivate( |
|
|
|
|
self, field, GPBGetMessageFloatField(other, field)); |
|
|
|
|
GPBSetFloatIvarWithFieldPrivate(self, field, GPBGetMessageFloatField(other, field)); |
|
|
|
|
break; |
|
|
|
|
case GPBDataTypeDouble: |
|
|
|
|
GPBSetDoubleIvarWithFieldPrivate( |
|
|
|
|
self, field, GPBGetMessageDoubleField(other, field)); |
|
|
|
|
GPBSetDoubleIvarWithFieldPrivate(self, field, GPBGetMessageDoubleField(other, field)); |
|
|
|
|
break; |
|
|
|
|
case GPBDataTypeBytes: |
|
|
|
|
case GPBDataTypeString: { |
|
|
|
@ -2556,8 +2509,7 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream( |
|
|
|
|
case GPBDataTypeGroup: { |
|
|
|
|
id otherVal = GPBGetObjectIvarWithFieldNoAutocreate(other, field); |
|
|
|
|
if (GPBGetHasIvar(self, hasIndex, fieldNumber)) { |
|
|
|
|
GPBMessage *message = |
|
|
|
|
GPBGetObjectIvarWithFieldNoAutocreate(self, field); |
|
|
|
|
GPBMessage *message = GPBGetObjectIvarWithFieldNoAutocreate(self, field); |
|
|
|
|
[message mergeFrom:otherVal]; |
|
|
|
|
} else { |
|
|
|
|
GPBMessage *message = [otherVal copy]; |
|
|
|
@ -2569,23 +2521,19 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream( |
|
|
|
|
} else if (fieldType == GPBFieldTypeRepeated) { |
|
|
|
|
// In the case of a list, they need to be appended, and there is no |
|
|
|
|
// _hasIvar to worry about setting. |
|
|
|
|
id otherArray = |
|
|
|
|
GPBGetObjectIvarWithFieldNoAutocreate(other, field); |
|
|
|
|
id otherArray = GPBGetObjectIvarWithFieldNoAutocreate(other, field); |
|
|
|
|
if (otherArray) { |
|
|
|
|
GPBDataType fieldDataType = field->description_->dataType; |
|
|
|
|
if (GPBDataTypeIsObject(fieldDataType)) { |
|
|
|
|
NSMutableArray *resultArray = |
|
|
|
|
GetOrCreateArrayIvarWithField(self, field); |
|
|
|
|
NSMutableArray *resultArray = GetOrCreateArrayIvarWithField(self, field); |
|
|
|
|
[resultArray addObjectsFromArray:otherArray]; |
|
|
|
|
} else if (fieldDataType == GPBDataTypeEnum) { |
|
|
|
|
GPBEnumArray *resultArray = |
|
|
|
|
GetOrCreateArrayIvarWithField(self, field); |
|
|
|
|
GPBEnumArray *resultArray = GetOrCreateArrayIvarWithField(self, field); |
|
|
|
|
[resultArray addRawValuesFromArray:otherArray]; |
|
|
|
|
} else { |
|
|
|
|
// The array type doesn't matter, that all implement |
|
|
|
|
// -addValuesFromArray:. |
|
|
|
|
GPBInt32Array *resultArray = |
|
|
|
|
GetOrCreateArrayIvarWithField(self, field); |
|
|
|
|
GPBInt32Array *resultArray = GetOrCreateArrayIvarWithField(self, field); |
|
|
|
|
[resultArray addValuesFromArray:otherArray]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -2596,22 +2544,18 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream( |
|
|
|
|
if (otherDict) { |
|
|
|
|
GPBDataType keyDataType = field.mapKeyDataType; |
|
|
|
|
GPBDataType valueDataType = field->description_->dataType; |
|
|
|
|
if (GPBDataTypeIsObject(keyDataType) && |
|
|
|
|
GPBDataTypeIsObject(valueDataType)) { |
|
|
|
|
NSMutableDictionary *resultDict = |
|
|
|
|
GetOrCreateMapIvarWithField(self, field); |
|
|
|
|
if (GPBDataTypeIsObject(keyDataType) && GPBDataTypeIsObject(valueDataType)) { |
|
|
|
|
NSMutableDictionary *resultDict = GetOrCreateMapIvarWithField(self, field); |
|
|
|
|
[resultDict addEntriesFromDictionary:otherDict]; |
|
|
|
|
} else if (valueDataType == GPBDataTypeEnum) { |
|
|
|
|
// The exact type doesn't matter, just need to know it is a |
|
|
|
|
// GPB*EnumDictionary. |
|
|
|
|
GPBInt32EnumDictionary *resultDict = |
|
|
|
|
GetOrCreateMapIvarWithField(self, field); |
|
|
|
|
GPBInt32EnumDictionary *resultDict = GetOrCreateMapIvarWithField(self, field); |
|
|
|
|
[resultDict addRawEntriesFromDictionary:otherDict]; |
|
|
|
|
} else { |
|
|
|
|
// The exact type doesn't matter, they all implement |
|
|
|
|
// -addEntriesFromDictionary:. |
|
|
|
|
GPBInt32Int32Dictionary *resultDict = |
|
|
|
|
GetOrCreateMapIvarWithField(self, field); |
|
|
|
|
GPBInt32Int32Dictionary *resultDict = GetOrCreateMapIvarWithField(self, field); |
|
|
|
|
[resultDict addEntriesFromDictionary:otherDict]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -2632,8 +2576,7 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream( |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (extensionMap_ == nil) { |
|
|
|
|
extensionMap_ = |
|
|
|
|
CloneExtensionMap(other->extensionMap_, NSZoneFromPointer(self)); |
|
|
|
|
extensionMap_ = CloneExtensionMap(other->extensionMap_, NSZoneFromPointer(self)); |
|
|
|
|
} else { |
|
|
|
|
for (GPBExtensionDescriptor *extension in other->extensionMap_) { |
|
|
|
|
id otherValue = [other->extensionMap_ objectForKey:extension]; |
|
|
|
@ -2671,8 +2614,7 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream( |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (isMessageExtension && !extension.isRepeated) { |
|
|
|
|
GPBMessage *autocreatedValue = |
|
|
|
|
[[autocreatedExtensionMap_ objectForKey:extension] retain]; |
|
|
|
|
GPBMessage *autocreatedValue = [[autocreatedExtensionMap_ objectForKey:extension] retain]; |
|
|
|
|
// Must remove from the map before calling GPBClearMessageAutocreator() |
|
|
|
|
// so that GPBClearMessageAutocreator() knows its safe to clear. |
|
|
|
|
[autocreatedExtensionMap_ removeObjectForKey:extension]; |
|
|
|
@ -2706,10 +2648,8 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream( |
|
|
|
|
// NOTE: These are NSArray/GPB*Array or NSDictionary/GPB*Dictionary, but |
|
|
|
|
// the type doesn't really matter as the objects all support -count and |
|
|
|
|
// -isEqual:. |
|
|
|
|
NSArray *resultMapOrArray = |
|
|
|
|
GPBGetObjectIvarWithFieldNoAutocreate(self, field); |
|
|
|
|
NSArray *otherMapOrArray = |
|
|
|
|
GPBGetObjectIvarWithFieldNoAutocreate(other, field); |
|
|
|
|
NSArray *resultMapOrArray = GPBGetObjectIvarWithFieldNoAutocreate(self, field); |
|
|
|
|
NSArray *otherMapOrArray = GPBGetObjectIvarWithFieldNoAutocreate(other, field); |
|
|
|
|
// nil and empty are equal |
|
|
|
|
if (resultMapOrArray.count != 0 || otherMapOrArray.count != 0) { |
|
|
|
|
if (![resultMapOrArray isEqual:otherMapOrArray]) { |
|
|
|
@ -2800,8 +2740,7 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream( |
|
|
|
|
|
|
|
|
|
// nil and empty are equal |
|
|
|
|
GPBUnknownFieldSet *otherUnknowns = otherMsg->unknownFields_; |
|
|
|
|
if ([unknownFields_ countOfFields] != 0 || |
|
|
|
|
[otherUnknowns countOfFields] != 0) { |
|
|
|
|
if ([unknownFields_ countOfFields] != 0 || [otherUnknowns countOfFields] != 0) { |
|
|
|
|
if (![unknownFields_ isEqual:otherUnknowns]) { |
|
|
|
|
return NO; |
|
|
|
|
} |
|
|
|
@ -2917,8 +2856,8 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream( |
|
|
|
|
|
|
|
|
|
- (NSString *)description { |
|
|
|
|
NSString *textFormat = GPBTextFormatForMessage(self, @" "); |
|
|
|
|
NSString *description = [NSString |
|
|
|
|
stringWithFormat:@"<%@ %p>: {\n%@}", [self class], self, textFormat]; |
|
|
|
|
NSString *description = |
|
|
|
|
[NSString stringWithFormat:@"<%@ %p>: {\n%@}", [self class], self, textFormat]; |
|
|
|
|
return description; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -2992,8 +2931,7 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream( |
|
|
|
|
|
|
|
|
|
// Repeated Fields |
|
|
|
|
} else if (fieldType == GPBFieldTypeRepeated) { |
|
|
|
|
id genericArray = |
|
|
|
|
GPBGetObjectIvarWithFieldNoAutocreate(self, fieldDescriptor); |
|
|
|
|
id genericArray = GPBGetObjectIvarWithFieldNoAutocreate(self, fieldDescriptor); |
|
|
|
|
NSUInteger count = [genericArray count]; |
|
|
|
|
if (count == 0) { |
|
|
|
|
continue; // Nothing to add. |
|
|
|
@ -3001,12 +2939,12 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream( |
|
|
|
|
__block size_t dataSize = 0; |
|
|
|
|
|
|
|
|
|
switch (fieldDataType) { |
|
|
|
|
#define CASE_REPEATED_POD(NAME, TYPE, ARRAY_TYPE) \ |
|
|
|
|
CASE_REPEATED_POD_EXTRA(NAME, TYPE, ARRAY_TYPE, ) |
|
|
|
|
#define CASE_REPEATED_POD(NAME, TYPE, ARRAY_TYPE) CASE_REPEATED_POD_EXTRA(NAME, TYPE, ARRAY_TYPE, ) |
|
|
|
|
#define CASE_REPEATED_POD_EXTRA(NAME, TYPE, ARRAY_TYPE, ARRAY_ACCESSOR_NAME) \ |
|
|
|
|
case GPBDataType##NAME: { \ |
|
|
|
|
GPB##ARRAY_TYPE##Array *array = genericArray; \ |
|
|
|
|
[array enumerate##ARRAY_ACCESSOR_NAME##ValuesWithBlock:^(TYPE value, __unused NSUInteger idx, __unused BOOL *stop) { \ |
|
|
|
|
[array enumerate##ARRAY_ACCESSOR_NAME## \ |
|
|
|
|
ValuesWithBlock:^(TYPE value, __unused NSUInteger idx, __unused BOOL * stop) { \ |
|
|
|
|
dataSize += GPBCompute##NAME##SizeNoTag(value); \ |
|
|
|
|
}]; \ |
|
|
|
|
break; \ |
|
|
|
@ -3058,15 +2996,13 @@ static void MergeRepeatedNotPackedFieldFromCodedInputStream( |
|
|
|
|
if (GPBDataTypeIsObject(fieldDataType) && |
|
|
|
|
(fieldDescriptor.mapKeyDataType == GPBDataTypeString)) { |
|
|
|
|
// If key type was string, then the map is an NSDictionary. |
|
|
|
|
NSDictionary *map = |
|
|
|
|
GPBGetObjectIvarWithFieldNoAutocreate(self, fieldDescriptor); |
|
|
|
|
NSDictionary *map = GPBGetObjectIvarWithFieldNoAutocreate(self, fieldDescriptor); |
|
|
|
|
if (map) { |
|
|
|
|
result += GPBDictionaryComputeSizeInternalHelper(map, fieldDescriptor); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
// Type will be GPB*GroupDictionary, exact type doesn't matter. |
|
|
|
|
GPBInt32Int32Dictionary *map = |
|
|
|
|
GPBGetObjectIvarWithFieldNoAutocreate(self, fieldDescriptor); |
|
|
|
|
GPBInt32Int32Dictionary *map = GPBGetObjectIvarWithFieldNoAutocreate(self, fieldDescriptor); |
|
|
|
|
result += [map computeSerializedSizeAsField:fieldDescriptor]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -3217,8 +3153,7 @@ static void ResolveIvarSet(__unsafe_unretained GPBFieldDescriptor *field, |
|
|
|
|
result.impToAdd = imp_implementationWithBlock(^(id obj, BOOL value) { |
|
|
|
|
if (value) { |
|
|
|
|
[NSException raise:NSInvalidArgumentException |
|
|
|
|
format:@"%@: %@ can only be set to NO (to clear field).", |
|
|
|
|
[obj class], |
|
|
|
|
format:@"%@: %@ can only be set to NO (to clear field).", [obj class], |
|
|
|
|
NSStringFromSelector(field->setHasSel_)]; |
|
|
|
|
} |
|
|
|
|
GPBClearMessageField(obj, field); |
|
|
|
@ -3262,8 +3197,7 @@ static void ResolveIvarSet(__unsafe_unretained GPBFieldDescriptor *field, |
|
|
|
|
result.impToAdd = imp_implementationWithBlock(^(id obj) { |
|
|
|
|
// Type doesn't matter, all *Array and *Dictionary types support |
|
|
|
|
// -count. |
|
|
|
|
NSArray *arrayOrMap = |
|
|
|
|
GPBGetObjectIvarWithFieldNoAutocreate(obj, field); |
|
|
|
|
NSArray *arrayOrMap = GPBGetObjectIvarWithFieldNoAutocreate(obj, field); |
|
|
|
|
return [arrayOrMap count]; |
|
|
|
|
}); |
|
|
|
|
result.encodingSelector = @selector(getArrayCount); |
|
|
|
@ -3272,8 +3206,7 @@ static void ResolveIvarSet(__unsafe_unretained GPBFieldDescriptor *field, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (result.impToAdd) { |
|
|
|
|
const char *encoding = |
|
|
|
|
GPBMessageEncodingForSelector(result.encodingSelector, YES); |
|
|
|
|
const char *encoding = GPBMessageEncodingForSelector(result.encodingSelector, YES); |
|
|
|
|
Class msgClass = descriptor.messageClass; |
|
|
|
|
BOOL methodAdded = class_addMethod(msgClass, sel, result.impToAdd, encoding); |
|
|
|
|
// class_addMethod() is documented as also failing if the method was already |
|
|
|
@ -3307,8 +3240,7 @@ static void ResolveIvarSet(__unsafe_unretained GPBFieldDescriptor *field, |
|
|
|
|
- (instancetype)initWithCoder:(NSCoder *)aDecoder { |
|
|
|
|
self = [self init]; |
|
|
|
|
if (self) { |
|
|
|
|
NSData *data = |
|
|
|
|
[aDecoder decodeObjectOfClass:[NSData class] forKey:kGPBDataCoderKey]; |
|
|
|
|
NSData *data = [aDecoder decodeObjectOfClass:[NSData class] forKey:kGPBDataCoderKey]; |
|
|
|
|
if (data.length) { |
|
|
|
|
[self mergeFromData:data extensionRegistry:nil]; |
|
|
|
|
} |
|
|
|
@ -3355,8 +3287,7 @@ id GPBGetMessageRepeatedField(GPBMessage *self, GPBFieldDescriptor *field) { |
|
|
|
|
#if defined(DEBUG) && DEBUG |
|
|
|
|
if (field.fieldType != GPBFieldTypeRepeated) { |
|
|
|
|
[NSException raise:NSInvalidArgumentException |
|
|
|
|
format:@"%@.%@ is not a repeated field.", |
|
|
|
|
[self class], field.name]; |
|
|
|
|
format:@"%@.%@ is not a repeated field.", [self class], field.name]; |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
return GetOrCreateArrayIvarWithField(self, field); |
|
|
|
@ -3367,8 +3298,7 @@ id GPBGetMessageMapField(GPBMessage *self, GPBFieldDescriptor *field) { |
|
|
|
|
#if defined(DEBUG) && DEBUG |
|
|
|
|
if (field.fieldType != GPBFieldTypeMap) { |
|
|
|
|
[NSException raise:NSInvalidArgumentException |
|
|
|
|
format:@"%@.%@ is not a map<> field.", |
|
|
|
|
[self class], field.name]; |
|
|
|
|
format:@"%@.%@ is not a map<> field.", [self class], field.name]; |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
return GetOrCreateMapIvarWithField(self, field); |
|
|
|
|