Skip to content

Commit

Permalink
ObjC: Preserve unknown fields in proto3 syntax files.
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasvl committed Jun 6, 2017
1 parent 516a81a commit 1d0988b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 44 deletions.
4 changes: 0 additions & 4 deletions objectivec/GPBDescriptor_PackagePrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,6 @@ uint32_t GPBFieldTag(GPBFieldDescriptor *self);
// would be the wire type for packed.
uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self);

GPB_INLINE BOOL GPBPreserveUnknownFields(GPBFileSyntax syntax) {
return syntax != GPBFileSyntaxProto3;
}

GPB_INLINE BOOL GPBHasPreservingUnknownEnumSemantics(GPBFileSyntax syntax) {
return syntax == GPBFileSyntaxProto3;
}
Expand Down
16 changes: 5 additions & 11 deletions objectivec/GPBMessage.m
Original file line number Diff line number Diff line change
Expand Up @@ -2372,17 +2372,11 @@ - (void)mergeFromCodedInputStream:(GPBCodedInputStream *)input
// zero signals EOF / limit reached
return;
} else {
if (GPBPreserveUnknownFields(syntax)) {
if (![self parseUnknownField:input
extensionRegistry:extensionRegistry
tag:tag]) {
// it's an endgroup tag
return;
}
} else {
if (![input skipField:tag]) {
return;
}
if (![self parseUnknownField:input
extensionRegistry:extensionRegistry
tag:tag]) {
// it's an endgroup tag
return;
}
}
} // if(!merged)
Expand Down
29 changes: 0 additions & 29 deletions objectivec/Tests/GPBMessageTests+Serialization.m
Original file line number Diff line number Diff line change
Expand Up @@ -113,35 +113,6 @@ - (void)testProto3SerializationHandlingDefaults {
[msg release];
}

- (void)testProto3DroppingUnknownFields {
DropUnknownsFooWithExtraFields *fooWithExtras =
[[DropUnknownsFooWithExtraFields alloc] init];

fooWithExtras.int32Value = 1;
fooWithExtras.enumValue = DropUnknownsFooWithExtraFields_NestedEnum_Baz;
fooWithExtras.extraInt32Value = 2;

NSData *data = [fooWithExtras data];
XCTAssertNotNil(data);
DropUnknownsFoo *foo = [DropUnknownsFoo parseFromData:data error:NULL];

XCTAssertEqual(foo.int32Value, 1);
XCTAssertEqual(foo.enumValue, DropUnknownsFoo_NestedEnum_Baz);
// Nothing should end up in the unknowns.
XCTAssertEqual([foo.unknownFields countOfFields], 0U);

[fooWithExtras release];
data = [foo data];
fooWithExtras =
[DropUnknownsFooWithExtraFields parseFromData:data error:NULL];
XCTAssertEqual(fooWithExtras.int32Value, 1);
XCTAssertEqual(fooWithExtras.enumValue,
DropUnknownsFooWithExtraFields_NestedEnum_Baz);
// And the extra value is gone (back to the default).
XCTAssertEqual(fooWithExtras.extraInt32Value, 0);
XCTAssertEqual([foo.unknownFields countOfFields], 0U);
}

- (void)testProto2UnknownEnumToUnknownField {
Message3 *orig = [[Message3 alloc] init];

Expand Down

0 comments on commit 1d0988b

Please sign in to comment.