Skip to content

Commit

Permalink
[ObjC] mark mergeFromData:extensionRegistry: as deprecated.
Browse files Browse the repository at this point in the history
Since it really isn't safe in Swift, point folks at the new api that uses errors.

PiperOrigin-RevId: 511262228
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Feb 21, 2023
1 parent cffde99 commit e3b0051
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion objectivec/GPBMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,9 @@ CF_EXTERN_C_END
* unsuccessful.
**/
- (void)mergeFromData:(NSData *)data
extensionRegistry:(nullable id<GPBExtensionRegistry>)extensionRegistry;
extensionRegistry:(nullable id<GPBExtensionRegistry>)extensionRegistry
__attribute__((deprecated(
"Use -mergeFromData:extensionRegistry:error: instead, especaily if calling from Swift.")));

/**
* Parses the given data as this message's class, and merges those values into
Expand Down
3 changes: 3 additions & 0 deletions objectivec/GPBMessage.m
Original file line number Diff line number Diff line change
Expand Up @@ -3261,7 +3261,10 @@ - (instancetype)initWithCoder:(NSCoder *)aDecoder {
if (self) {
NSData *data = [aDecoder decodeObjectOfClass:[NSData class] forKey:kGPBDataCoderKey];
if (data.length) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[self mergeFromData:data extensionRegistry:nil];
#pragma clang diagnostic pop
}
}
return self;
Expand Down
6 changes: 5 additions & 1 deletion objectivec/Tests/GPBMessageTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,11 @@ - (void)testMergeFromWithExtensions {
result = [self mergeExtensionsDestination];
NSData *data = [[self mergeExtensionsSource] data];
XCTAssertNotNil(data);
[result mergeFromData:data extensionRegistry:[UnittestRoot extensionRegistry]];
NSError *error = nil;
XCTAssertTrue([result mergeFromData:data
extensionRegistry:[UnittestRoot extensionRegistry]
error:&error]);
XCTAssertNil(error);
resultData = [result data];
XCTAssertEqualObjects(resultData, mergeResultData);
XCTAssertEqualObjects(result, [self mergeExtensionsResult]);
Expand Down

0 comments on commit e3b0051

Please sign in to comment.