add proto2 supported for cpp,python,nodejs,ruby,php
diff --git a/conformance/conformance_python.py b/conformance/conformance_python.py
index 7ace9b1..846ccbc 100755
--- a/conformance/conformance_python.py
+++ b/conformance/conformance_python.py
@@ -41,6 +41,7 @@
from google.protobuf import json_format
from google.protobuf import message
from google.protobuf import test_messages_proto3_pb2
+from google.protobuf import test_messages_proto2_pb2
import conformance_pb2
sys.stdout = os.fdopen(sys.stdout.fileno(), 'wb', 0)
@@ -56,14 +57,26 @@
test_message = test_messages_proto3_pb2.TestAllTypes()
response = conformance_pb2.ConformanceResponse()
test_message = test_messages_proto3_pb2.TestAllTypes()
+ test_message_proto2 = test_messages_proto2_pb2.TestAllTypesProto2()
+ isProto3 = (request.message_type == "proto3")
+ isJson = (request.WhichOneof('payload') == 'json_payload')
try:
if request.WhichOneof('payload') == 'protobuf_payload':
- try:
- test_message.ParseFromString(request.protobuf_payload)
- except message.DecodeError as e:
- response.parse_error = str(e)
- return response
+ if isProto3:
+ try:
+ test_message.ParseFromString(request.protobuf_payload)
+ except message.DecodeError as e:
+ response.parse_error = str(e)
+ return response
+ elif request.message_type == "proto2":
+ try:
+ test_message_proto2.ParseFromString(request.protobuf_payload)
+ except message.DecodeError as e:
+ response.parse_error = str(e)
+ return response
+ else:
+ raise ProtocolError("Protobuf request doesn't have specific payload type")
elif request.WhichOneof('payload') == 'json_payload':
try:
@@ -79,11 +92,17 @@
raise ProtocolError("Unspecified output format")
elif request.requested_output_format == conformance_pb2.PROTOBUF:
- response.protobuf_payload = test_message.SerializeToString()
+ if isProto3 or isJson:
+ response.protobuf_payload = test_message.SerializeToString()
+ else:
+ response.protobuf_payload = test_message_proto2.SerializeToString()
elif request.requested_output_format == conformance_pb2.JSON:
try:
- response.json_payload = json_format.MessageToJson(test_message)
+ if isProto3 or isJson:
+ response.json_payload = json_format.MessageToJson(test_message)
+ else:
+ response.json_payload = json_format.MessageToJson(test_message_proto2)
except Exception as e:
response.serialize_error = str(e)
return response