Commit c2831a34 authored by Thomas Van Lenten's avatar Thomas Van Lenten

Add the proto2 message conformance support for ObjC.

parent 9fd5e59c
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import "Conformance.pbobjc.h" #import "Conformance.pbobjc.h"
#import "google/protobuf/TestMessagesProto2.pbobjc.h"
#import "google/protobuf/TestMessagesProto3.pbobjc.h" #import "google/protobuf/TestMessagesProto3.pbobjc.h"
static void Die(NSString *format, ...) __dead2; static void Die(NSString *format, ...) __dead2;
...@@ -63,7 +64,7 @@ static NSData *CheckedReadDataOfLength(NSFileHandle *handle, NSUInteger numBytes ...@@ -63,7 +64,7 @@ static NSData *CheckedReadDataOfLength(NSFileHandle *handle, NSUInteger numBytes
static ConformanceResponse *DoTest(ConformanceRequest *request) { static ConformanceResponse *DoTest(ConformanceRequest *request) {
ConformanceResponse *response = [ConformanceResponse message]; ConformanceResponse *response = [ConformanceResponse message];
Proto3TestAllTypesProto3 *testMessage = nil; GPBMessage *testMessage = nil;
switch (request.payloadOneOfCase) { switch (request.payloadOneOfCase) {
case ConformanceRequest_Payload_OneOfCase_GPBUnsetOneOfCase: case ConformanceRequest_Payload_OneOfCase_GPBUnsetOneOfCase:
...@@ -71,20 +72,21 @@ static ConformanceResponse *DoTest(ConformanceRequest *request) { ...@@ -71,20 +72,21 @@ static ConformanceResponse *DoTest(ConformanceRequest *request) {
break; break;
case ConformanceRequest_Payload_OneOfCase_ProtobufPayload: { 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; NSError *error = nil;
testMessage = [Proto3TestAllTypesProto3 parseFromData:request.protobufPayload testMessage = [msgClass parseFromData:request.protobufPayload error:&error];
error:&error];
if (!testMessage) { if (!testMessage) {
response.parseError = response.parseError =
[NSString stringWithFormat:@"Parse error: %@", error]; [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; break;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment