diff options
author | Bo Yang <paulyang1211@gmail.com> | 2017-08-05 10:42:29 -0700 |
---|---|---|
committer | Bo Yang <paulyang1211@gmail.com> | 2017-08-05 10:42:29 -0700 |
commit | 8f4b8e430a0cf087af423be434cf8d837027c651 (patch) | |
tree | a7a79a2ff33b31b9036eb378eb458928a0648481 /conformance/conformance_objc.m | |
parent | c2f69d6fa23a815948368fae0b8c1e56e50715c9 (diff) | |
parent | f14703c933d04a4aac285c482bf828269bd0a151 (diff) |
Merge branch 'master' into 3.4.x
Diffstat (limited to 'conformance/conformance_objc.m')
-rw-r--r-- | conformance/conformance_objc.m | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/conformance/conformance_objc.m b/conformance/conformance_objc.m index ba1c946f..84a43811 100644 --- a/conformance/conformance_objc.m +++ b/conformance/conformance_objc.m @@ -31,6 +31,7 @@ #import <Foundation/Foundation.h> #import "Conformance.pbobjc.h" +#import "google/protobuf/TestMessagesProto2.pbobjc.h" #import "google/protobuf/TestMessagesProto3.pbobjc.h" static void Die(NSString *format, ...) __dead2; @@ -63,7 +64,7 @@ static NSData *CheckedReadDataOfLength(NSFileHandle *handle, NSUInteger numBytes static ConformanceResponse *DoTest(ConformanceRequest *request) { ConformanceResponse *response = [ConformanceResponse message]; - TestAllTypesProto3 *testMessage = nil; + GPBMessage *testMessage = nil; switch (request.payloadOneOfCase) { case ConformanceRequest_Payload_OneOfCase_GPBUnsetOneOfCase: @@ -71,20 +72,19 @@ static ConformanceResponse *DoTest(ConformanceRequest *request) { break; case ConformanceRequest_Payload_OneOfCase_ProtobufPayload: { - if ([request.messageType isEqualToString:@"protobuf_test_messages.proto3.TestAllTypesProto3"]) { - NSError *error = nil; - testMessage = [TestAllTypesProto3 parseFromData:request.protobufPayload - error:&error]; - if (!testMessage) { - response.parseError = - [NSString stringWithFormat:@"Parse error: %@", error]; - } - } else if ([request.messageType isEqualToString:@"protobuf_test_messages.proto2.TestAllTypesProto2"]) { - response.skipped = @"ObjC doesn't support proto2"; - break; + Class msgClass = nil; + if ([request.messageType isEqual:@"protobuf_test_messages.proto3.TestAllTypesProto3"]) { + msgClass = [Proto3TestAllTypesProto3 class]; + } else if ([request.messageType isEqual:@"protobuf_test_messages.proto2.TestAllTypesProto2"]) { + msgClass = [TestAllTypesProto2 class]; } else { - Die(@"Protobuf request doesn't have specific payload type"); - break; + Die(@"Protobuf request had an unknown message_type: %@", request.messageType); + } + NSError *error = nil; + testMessage = [msgClass parseFromData:request.protobufPayload error:&error]; + if (!testMessage) { + response.parseError = + [NSString stringWithFormat:@"Parse error: %@", error]; } break; } |