diff options
Diffstat (limited to 'conformance')
-rw-r--r-- | conformance/conformance_objc.m | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/conformance/conformance_objc.m b/conformance/conformance_objc.m index a5012ec4..6023fc78 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]; - Proto3TestAllTypesProto3 *testMessage = nil; + GPBMessage *testMessage = nil; switch (request.payloadOneOfCase) { case ConformanceRequest_Payload_OneOfCase_GPBUnsetOneOfCase: @@ -71,20 +72,21 @@ static ConformanceResponse *DoTest(ConformanceRequest *request) { break; case ConformanceRequest_Payload_OneOfCase_ProtobufPayload: { - if ([request.messageType isEqualToString:@"protobuf_test_messages.proto3.TestAllTypesProto3"]) { + 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"); + } + if (msgClass) { NSError *error = nil; - testMessage = [Proto3TestAllTypesProto3 parseFromData:request.protobufPayload - error:&error]; + testMessage = [msgClass 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; - } else { - Die(@"Protobuf request doesn't have specific payload type"); - break; } break; } |