Unverified Commit cb95a7f6 authored by Yilun Chong's avatar Yilun Chong Committed by GitHub

Down-integrate internal changes to github. (#5566)

* Down-integrate internal changes to github.

* fix csharp conformance test

* add comments in conformance.proto for text format

* fix comments

* fix comments, re-generated csharp file

* fix comments, re-generated csharp file
parent b1b9eaa6
import com.google.protobuf.ByteString;
import com.google.protobuf.AbstractMessage; import com.google.protobuf.AbstractMessage;
import com.google.protobuf.Parser; import com.google.protobuf.ByteString;
import com.google.protobuf.CodedInputStream; import com.google.protobuf.CodedInputStream;
import com.google.protobuf.conformance.Conformance;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf_test_messages.proto3.TestMessagesProto3;
import com.google.protobuf_test_messages.proto3.TestMessagesProto3.TestAllTypesProto3;
import com.google.protobuf_test_messages.proto2.TestMessagesProto2;
import com.google.protobuf_test_messages.proto2.TestMessagesProto2.TestAllTypesProto2;
import com.google.protobuf.ExtensionRegistry; import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.Parser;
import com.google.protobuf.TextFormat;
import com.google.protobuf.conformance.Conformance;
import com.google.protobuf.util.JsonFormat; import com.google.protobuf.util.JsonFormat;
import com.google.protobuf.util.JsonFormat.TypeRegistry; import com.google.protobuf.util.JsonFormat.TypeRegistry;
import com.google.protobuf_test_messages.proto2.TestMessagesProto2;
import com.google.protobuf_test_messages.proto2.TestMessagesProto2.TestAllTypesProto2;
import com.google.protobuf_test_messages.proto3.TestMessagesProto3;
import com.google.protobuf_test_messages.proto3.TestMessagesProto3.TestAllTypesProto3;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -247,6 +248,17 @@ class ConformanceJava { ...@@ -247,6 +248,17 @@ class ConformanceJava {
} }
break; break;
} }
case TEXT_PAYLOAD: {
try {
TestMessagesProto3.TestAllTypesProto3.Builder builder =
TestMessagesProto3.TestAllTypesProto3.newBuilder();
TextFormat.merge(request.getTextPayload(), builder);
testMessage = builder.build();
} catch (TextFormat.ParseException e) {
return Conformance.ConformanceResponse.newBuilder().setParseError(e.getMessage()).build();
}
break;
}
case PAYLOAD_NOT_SET: { case PAYLOAD_NOT_SET: {
throw new RuntimeException("Request didn't have payload."); throw new RuntimeException("Request didn't have payload.");
} }
...@@ -274,6 +286,10 @@ class ConformanceJava { ...@@ -274,6 +286,10 @@ class ConformanceJava {
e.getMessage()).build(); e.getMessage()).build();
} }
case TEXT_FORMAT:
return Conformance.ConformanceResponse.newBuilder().setTextPayload(
TextFormat.printToString(testMessage)).build();
default: { default: {
throw new RuntimeException("Unexpected request output."); throw new RuntimeException("Unexpected request output.");
} }
......
...@@ -56,6 +56,7 @@ enum WireFormat { ...@@ -56,6 +56,7 @@ enum WireFormat {
PROTOBUF = 1; PROTOBUF = 1;
JSON = 2; JSON = 2;
JSPB = 3; // Google internal only. Opensource testees just skip it. JSPB = 3; // Google internal only. Opensource testees just skip it.
TEXT_FORMAT = 4;
} }
enum TestCategory { enum TestCategory {
...@@ -70,8 +71,14 @@ enum TestCategory { ...@@ -70,8 +71,14 @@ enum TestCategory {
JSON_IGNORE_UNKNOWN_PARSING_TEST = 3; JSON_IGNORE_UNKNOWN_PARSING_TEST = 3;
// Test jspb wire format. Google internal only. Opensource testees just skip it. // Test jspb wire format. Google internal only. Opensource testees just skip it.
JSPB_TEST = 4; JSPB_TEST = 4;
// Test text format. For cpp, java and python, testees can already deal with
// this type. Testees of other languages can simply skip it.
TEXT_FORMAT_TEST = 5;
} }
// The conformance runner will request a list of failures as the first request.
// This will be known by message_type == "conformance.FailureSet", a conformance
// test should return a serialized FailureSet in protobuf_payload.
message FailureSet { message FailureSet {
repeated string failure = 1; repeated string failure = 1;
} }
...@@ -94,6 +101,7 @@ message ConformanceRequest { ...@@ -94,6 +101,7 @@ message ConformanceRequest {
string json_payload = 2; string json_payload = 2;
// Google internal only. Opensource testees just skip it. // Google internal only. Opensource testees just skip it.
string jspb_payload = 7; string jspb_payload = 7;
string text_payload = 8;
} }
// Which format should the testee serialize its message to? // Which format should the testee serialize its message to?
...@@ -149,6 +157,10 @@ message ConformanceResponse { ...@@ -149,6 +157,10 @@ message ConformanceResponse {
// serialize to JSPB and set it in this field. JSPB is google internal only // serialize to JSPB and set it in this field. JSPB is google internal only
// format. Opensource testees can just skip it. // format. Opensource testees can just skip it.
string jspb_payload = 7; string jspb_payload = 7;
// If the input was successfully parsed and the requested output was
// TEXT_FORMAT, serialize to TEXT_FORMAT and set it in this field.
string text_payload = 8;
} }
} }
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include <google/protobuf/test_messages_proto3.pb.h> #include <google/protobuf/test_messages_proto3.pb.h>
#include <google/protobuf/test_messages_proto2.pb.h> #include <google/protobuf/test_messages_proto2.pb.h>
#include <google/protobuf/message.h> #include <google/protobuf/message.h>
#include <google/protobuf/text_format.h>
#include <google/protobuf/util/json_util.h> #include <google/protobuf/util/json_util.h>
#include <google/protobuf/util/type_resolver_util.h> #include <google/protobuf/util/type_resolver_util.h>
...@@ -45,14 +46,15 @@ using google::protobuf::Descriptor; ...@@ -45,14 +46,15 @@ using google::protobuf::Descriptor;
using google::protobuf::DescriptorPool; using google::protobuf::DescriptorPool;
using google::protobuf::Message; using google::protobuf::Message;
using google::protobuf::MessageFactory; using google::protobuf::MessageFactory;
using google::protobuf::TextFormat;
using google::protobuf::util::BinaryToJsonString; using google::protobuf::util::BinaryToJsonString;
using google::protobuf::util::JsonParseOptions; using google::protobuf::util::JsonParseOptions;
using google::protobuf::util::JsonToBinaryString; using google::protobuf::util::JsonToBinaryString;
using google::protobuf::util::NewTypeResolverForDescriptorPool; using google::protobuf::util::NewTypeResolverForDescriptorPool;
using google::protobuf::util::Status; using google::protobuf::util::Status;
using google::protobuf::util::TypeResolver; using google::protobuf::util::TypeResolver;
using protobuf_test_messages::proto3::TestAllTypesProto3;
using protobuf_test_messages::proto2::TestAllTypesProto2; using protobuf_test_messages::proto2::TestAllTypesProto2;
using protobuf_test_messages::proto3::TestAllTypesProto3;
using std::string; using std::string;
static const char kTypeUrlPrefix[] = "type.googleapis.com"; static const char kTypeUrlPrefix[] = "type.googleapis.com";
...@@ -163,6 +165,14 @@ void DoTest(const ConformanceRequest& request, ConformanceResponse* response) { ...@@ -163,6 +165,14 @@ void DoTest(const ConformanceRequest& request, ConformanceResponse* response) {
break; break;
} }
case ConformanceRequest::kTextPayload: {
if (!TextFormat::ParseFromString(request.text_payload(), test_message)) {
response->set_parse_error("Parse error");
return;
}
break;
}
case ConformanceRequest::PAYLOAD_NOT_SET: case ConformanceRequest::PAYLOAD_NOT_SET:
GOOGLE_LOG(FATAL) << "Request didn't have payload."; GOOGLE_LOG(FATAL) << "Request didn't have payload.";
break; break;
...@@ -203,6 +213,12 @@ void DoTest(const ConformanceRequest& request, ConformanceResponse* response) { ...@@ -203,6 +213,12 @@ void DoTest(const ConformanceRequest& request, ConformanceResponse* response) {
break; break;
} }
case conformance::TEXT_FORMAT: {
GOOGLE_CHECK(TextFormat::PrintToString(*test_message,
response->mutable_text_payload()));
break;
}
default: default:
GOOGLE_LOG(FATAL) << "Unknown output format: " GOOGLE_LOG(FATAL) << "Unknown output format: "
<< request.requested_output_format(); << request.requested_output_format();
......
...@@ -44,6 +44,7 @@ from google.protobuf import json_format ...@@ -44,6 +44,7 @@ from google.protobuf import json_format
from google.protobuf import message from google.protobuf import message
from google.protobuf import test_messages_proto3_pb2 from google.protobuf import test_messages_proto3_pb2
from google.protobuf import test_messages_proto2_pb2 from google.protobuf import test_messages_proto2_pb2
from google.protobuf import text_format
import conformance_pb2 import conformance_pb2
sys.stdout = os.fdopen(sys.stdout.fileno(), 'wb', 0) sys.stdout = os.fdopen(sys.stdout.fileno(), 'wb', 0)
...@@ -136,6 +137,13 @@ def do_test(request): ...@@ -136,6 +137,13 @@ def do_test(request):
response.parse_error = str(e) response.parse_error = str(e)
return response return response
elif request.WhichOneof('payload') == 'text_payload':
try:
text_format.Parse(request.text_payload, test_message)
except Exception as e:
response.parse_error = str(e)
return response
else: else:
raise ProtocolError("Request didn't have payload.") raise ProtocolError("Request didn't have payload.")
...@@ -152,6 +160,9 @@ def do_test(request): ...@@ -152,6 +160,9 @@ def do_test(request):
response.serialize_error = str(e) response.serialize_error = str(e)
return response return response
elif request.requested_output_format == conformance_pb2.TEXT_FORMAT:
response.text_payload = text_format.MessageToString(test_message)
except Exception as e: except Exception as e:
response.runtime_error = str(e) response.runtime_error = str(e)
......
...@@ -85,6 +85,11 @@ ConformanceTestSuite::ConformanceRequestSetting::ConformanceRequestSetting( ...@@ -85,6 +85,11 @@ ConformanceTestSuite::ConformanceRequestSetting::ConformanceRequestSetting(
break; break;
} }
case conformance::TEXT_FORMAT: {
request_.set_text_payload(input);
break;
}
default: default:
GOOGLE_LOG(FATAL) << "Unspecified input format"; GOOGLE_LOG(FATAL) << "Unspecified input format";
} }
...@@ -131,6 +136,8 @@ string ConformanceTestSuite::ConformanceRequestSetting:: ...@@ -131,6 +136,8 @@ string ConformanceTestSuite::ConformanceRequestSetting::
return "ProtobufInput"; return "ProtobufInput";
case conformance::JSON: case conformance::JSON:
return "JsonInput"; return "JsonInput";
case conformance::TEXT_FORMAT:
return "TextFormatInput";
default: default:
GOOGLE_LOG(FATAL) << "Unspecified output format"; GOOGLE_LOG(FATAL) << "Unspecified output format";
} }
...@@ -144,6 +151,8 @@ string ConformanceTestSuite::ConformanceRequestSetting:: ...@@ -144,6 +151,8 @@ string ConformanceTestSuite::ConformanceRequestSetting::
return "ProtobufOutput"; return "ProtobufOutput";
case conformance::JSON: case conformance::JSON:
return "JsonOutput"; return "JsonOutput";
case conformance::TEXT_FORMAT:
return "TextFormatOutput";
default: default:
GOOGLE_LOG(FATAL) << "Unspecified output format"; GOOGLE_LOG(FATAL) << "Unspecified output format";
} }
...@@ -341,6 +350,8 @@ string ConformanceTestSuite::WireFormatToString( ...@@ -341,6 +350,8 @@ string ConformanceTestSuite::WireFormatToString(
return "JSON"; return "JSON";
case conformance::JSPB: case conformance::JSPB:
return "JSPB"; return "JSPB";
case conformance::TEXT_FORMAT:
return "TEXT_FORMAT";
case conformance::UNSPECIFIED: case conformance::UNSPECIFIED:
return "UNSPECIFIED"; return "UNSPECIFIED";
default: default:
......
...@@ -25,31 +25,33 @@ namespace Conformance { ...@@ -25,31 +25,33 @@ namespace Conformance {
byte[] descriptorData = global::System.Convert.FromBase64String( byte[] descriptorData = global::System.Convert.FromBase64String(
string.Concat( string.Concat(
"ChFjb25mb3JtYW5jZS5wcm90bxILY29uZm9ybWFuY2UiHQoKRmFpbHVyZVNl", "ChFjb25mb3JtYW5jZS5wcm90bxILY29uZm9ybWFuY2UiHQoKRmFpbHVyZVNl",
"dBIPCgdmYWlsdXJlGAEgAygJIq0CChJDb25mb3JtYW5jZVJlcXVlc3QSGgoQ", "dBIPCgdmYWlsdXJlGAEgAygJIsUCChJDb25mb3JtYW5jZVJlcXVlc3QSGgoQ",
"cHJvdG9idWZfcGF5bG9hZBgBIAEoDEgAEhYKDGpzb25fcGF5bG9hZBgCIAEo", "cHJvdG9idWZfcGF5bG9hZBgBIAEoDEgAEhYKDGpzb25fcGF5bG9hZBgCIAEo",
"CUgAEhYKDGpzcGJfcGF5bG9hZBgHIAEoCUgAEjgKF3JlcXVlc3RlZF9vdXRw", "CUgAEhYKDGpzcGJfcGF5bG9hZBgHIAEoCUgAEhYKDHRleHRfcGF5bG9hZBgI",
"dXRfZm9ybWF0GAMgASgOMhcuY29uZm9ybWFuY2UuV2lyZUZvcm1hdBIUCgxt", "IAEoCUgAEjgKF3JlcXVlc3RlZF9vdXRwdXRfZm9ybWF0GAMgASgOMhcuY29u",
"ZXNzYWdlX3R5cGUYBCABKAkSMAoNdGVzdF9jYXRlZ29yeRgFIAEoDjIZLmNv", "Zm9ybWFuY2UuV2lyZUZvcm1hdBIUCgxtZXNzYWdlX3R5cGUYBCABKAkSMAoN",
"bmZvcm1hbmNlLlRlc3RDYXRlZ29yeRI+ChVqc3BiX2VuY29kaW5nX29wdGlv", "dGVzdF9jYXRlZ29yeRgFIAEoDjIZLmNvbmZvcm1hbmNlLlRlc3RDYXRlZ29y",
"bnMYBiABKAsyHy5jb25mb3JtYW5jZS5Kc3BiRW5jb2RpbmdDb25maWdCCQoH", "eRI+ChVqc3BiX2VuY29kaW5nX29wdGlvbnMYBiABKAsyHy5jb25mb3JtYW5j",
"cGF5bG9hZCLJAQoTQ29uZm9ybWFuY2VSZXNwb25zZRIVCgtwYXJzZV9lcnJv", "ZS5Kc3BiRW5jb2RpbmdDb25maWdCCQoHcGF5bG9hZCLhAQoTQ29uZm9ybWFu",
"chgBIAEoCUgAEhkKD3NlcmlhbGl6ZV9lcnJvchgGIAEoCUgAEhcKDXJ1bnRp", "Y2VSZXNwb25zZRIVCgtwYXJzZV9lcnJvchgBIAEoCUgAEhkKD3NlcmlhbGl6",
"bWVfZXJyb3IYAiABKAlIABIaChBwcm90b2J1Zl9wYXlsb2FkGAMgASgMSAAS", "ZV9lcnJvchgGIAEoCUgAEhcKDXJ1bnRpbWVfZXJyb3IYAiABKAlIABIaChBw",
"FgoManNvbl9wYXlsb2FkGAQgASgJSAASEQoHc2tpcHBlZBgFIAEoCUgAEhYK", "cm90b2J1Zl9wYXlsb2FkGAMgASgMSAASFgoManNvbl9wYXlsb2FkGAQgASgJ",
"DGpzcGJfcGF5bG9hZBgHIAEoCUgAQggKBnJlc3VsdCI3ChJKc3BiRW5jb2Rp", "SAASEQoHc2tpcHBlZBgFIAEoCUgAEhYKDGpzcGJfcGF5bG9hZBgHIAEoCUgA",
"bmdDb25maWcSIQoZdXNlX2pzcGJfYXJyYXlfYW55X2Zvcm1hdBgBIAEoCCo/", "EhYKDHRleHRfcGF5bG9hZBgIIAEoCUgAQggKBnJlc3VsdCI3ChJKc3BiRW5j",
"CgpXaXJlRm9ybWF0Eg8KC1VOU1BFQ0lGSUVEEAASDAoIUFJPVE9CVUYQARII", "b2RpbmdDb25maWcSIQoZdXNlX2pzcGJfYXJyYXlfYW55X2Zvcm1hdBgBIAEo",
"CgRKU09OEAISCAoESlNQQhADKnkKDFRlc3RDYXRlZ29yeRIUChBVTlNQRUNJ", "CCpQCgpXaXJlRm9ybWF0Eg8KC1VOU1BFQ0lGSUVEEAASDAoIUFJPVE9CVUYQ",
"RklFRF9URVNUEAASDwoLQklOQVJZX1RFU1QQARINCglKU09OX1RFU1QQAhIk", "ARIICgRKU09OEAISCAoESlNQQhADEg8KC1RFWFRfRk9STUFUEAQqjwEKDFRl",
"CiBKU09OX0lHTk9SRV9VTktOT1dOX1BBUlNJTkdfVEVTVBADEg0KCUpTUEJf", "c3RDYXRlZ29yeRIUChBVTlNQRUNJRklFRF9URVNUEAASDwoLQklOQVJZX1RF",
"VEVTVBAEQiEKH2NvbS5nb29nbGUucHJvdG9idWYuY29uZm9ybWFuY2ViBnBy", "U1QQARINCglKU09OX1RFU1QQAhIkCiBKU09OX0lHTk9SRV9VTktOT1dOX1BB",
"b3RvMw==")); "UlNJTkdfVEVTVBADEg0KCUpTUEJfVEVTVBAEEhQKEFRFWFRfRk9STUFUX1RF",
"U1QQBUIhCh9jb20uZ29vZ2xlLnByb3RvYnVmLmNvbmZvcm1hbmNlYgZwcm90",
"bzM="));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { }, new pbr::FileDescriptor[] { },
new pbr::GeneratedClrTypeInfo(new[] {typeof(global::Conformance.WireFormat), typeof(global::Conformance.TestCategory), }, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(new[] {typeof(global::Conformance.WireFormat), typeof(global::Conformance.TestCategory), }, new pbr::GeneratedClrTypeInfo[] {
new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.FailureSet), global::Conformance.FailureSet.Parser, new[]{ "Failure" }, null, null, null), new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.FailureSet), global::Conformance.FailureSet.Parser, new[]{ "Failure" }, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.ConformanceRequest), global::Conformance.ConformanceRequest.Parser, new[]{ "ProtobufPayload", "JsonPayload", "JspbPayload", "RequestedOutputFormat", "MessageType", "TestCategory", "JspbEncodingOptions" }, new[]{ "Payload" }, null, null), new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.ConformanceRequest), global::Conformance.ConformanceRequest.Parser, new[]{ "ProtobufPayload", "JsonPayload", "JspbPayload", "TextPayload", "RequestedOutputFormat", "MessageType", "TestCategory", "JspbEncodingOptions" }, new[]{ "Payload" }, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.ConformanceResponse), global::Conformance.ConformanceResponse.Parser, new[]{ "ParseError", "SerializeError", "RuntimeError", "ProtobufPayload", "JsonPayload", "Skipped", "JspbPayload" }, new[]{ "Result" }, null, null), new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.ConformanceResponse), global::Conformance.ConformanceResponse.Parser, new[]{ "ParseError", "SerializeError", "RuntimeError", "ProtobufPayload", "JsonPayload", "Skipped", "JspbPayload", "TextPayload" }, new[]{ "Result" }, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.JspbEncodingConfig), global::Conformance.JspbEncodingConfig.Parser, new[]{ "UseJspbArrayAnyFormat" }, null, null, null) new pbr::GeneratedClrTypeInfo(typeof(global::Conformance.JspbEncodingConfig), global::Conformance.JspbEncodingConfig.Parser, new[]{ "UseJspbArrayAnyFormat" }, null, null, null)
})); }));
} }
...@@ -65,6 +67,7 @@ namespace Conformance { ...@@ -65,6 +67,7 @@ namespace Conformance {
/// Google internal only. Opensource testees just skip it. /// Google internal only. Opensource testees just skip it.
/// </summary> /// </summary>
[pbr::OriginalName("JSPB")] Jspb = 3, [pbr::OriginalName("JSPB")] Jspb = 3,
[pbr::OriginalName("TEXT_FORMAT")] TextFormat = 4,
} }
public enum TestCategory { public enum TestCategory {
...@@ -89,11 +92,21 @@ namespace Conformance { ...@@ -89,11 +92,21 @@ namespace Conformance {
/// Test jspb wire format. Google internal only. Opensource testees just skip it. /// Test jspb wire format. Google internal only. Opensource testees just skip it.
/// </summary> /// </summary>
[pbr::OriginalName("JSPB_TEST")] JspbTest = 4, [pbr::OriginalName("JSPB_TEST")] JspbTest = 4,
/// <summary>
/// Test text format. For cpp, java and python, testees can already deal with
/// this type. Testees of other languages can simply skip it.
/// </summary>
[pbr::OriginalName("TEXT_FORMAT_TEST")] TextFormatTest = 5,
} }
#endregion #endregion
#region Messages #region Messages
/// <summary>
/// The conformance runner will request a list of failures as the first request.
/// This will be known by message_type == "conformance.FailureSet", a conformance
/// test should return a serialized FailureSet in protobuf_payload.
/// </summary>
public sealed partial class FailureSet : pb::IMessage<FailureSet> { public sealed partial class FailureSet : pb::IMessage<FailureSet> {
private static readonly pb::MessageParser<FailureSet> _parser = new pb::MessageParser<FailureSet>(() => new FailureSet()); private static readonly pb::MessageParser<FailureSet> _parser = new pb::MessageParser<FailureSet>(() => new FailureSet());
private pb::UnknownFieldSet _unknownFields; private pb::UnknownFieldSet _unknownFields;
...@@ -263,6 +276,9 @@ namespace Conformance { ...@@ -263,6 +276,9 @@ namespace Conformance {
case PayloadOneofCase.JspbPayload: case PayloadOneofCase.JspbPayload:
JspbPayload = other.JspbPayload; JspbPayload = other.JspbPayload;
break; break;
case PayloadOneofCase.TextPayload:
TextPayload = other.TextPayload;
break;
} }
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
...@@ -309,6 +325,17 @@ namespace Conformance { ...@@ -309,6 +325,17 @@ namespace Conformance {
} }
} }
/// <summary>Field number for the "text_payload" field.</summary>
public const int TextPayloadFieldNumber = 8;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string TextPayload {
get { return payloadCase_ == PayloadOneofCase.TextPayload ? (string) payload_ : ""; }
set {
payload_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
payloadCase_ = PayloadOneofCase.TextPayload;
}
}
/// <summary>Field number for the "requested_output_format" field.</summary> /// <summary>Field number for the "requested_output_format" field.</summary>
public const int RequestedOutputFormatFieldNumber = 3; public const int RequestedOutputFormatFieldNumber = 3;
private global::Conformance.WireFormat requestedOutputFormat_ = 0; private global::Conformance.WireFormat requestedOutputFormat_ = 0;
...@@ -376,6 +403,7 @@ namespace Conformance { ...@@ -376,6 +403,7 @@ namespace Conformance {
ProtobufPayload = 1, ProtobufPayload = 1,
JsonPayload = 2, JsonPayload = 2,
JspbPayload = 7, JspbPayload = 7,
TextPayload = 8,
} }
private PayloadOneofCase payloadCase_ = PayloadOneofCase.None; private PayloadOneofCase payloadCase_ = PayloadOneofCase.None;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
...@@ -405,6 +433,7 @@ namespace Conformance { ...@@ -405,6 +433,7 @@ namespace Conformance {
if (ProtobufPayload != other.ProtobufPayload) return false; if (ProtobufPayload != other.ProtobufPayload) return false;
if (JsonPayload != other.JsonPayload) return false; if (JsonPayload != other.JsonPayload) return false;
if (JspbPayload != other.JspbPayload) return false; if (JspbPayload != other.JspbPayload) return false;
if (TextPayload != other.TextPayload) return false;
if (RequestedOutputFormat != other.RequestedOutputFormat) return false; if (RequestedOutputFormat != other.RequestedOutputFormat) return false;
if (MessageType != other.MessageType) return false; if (MessageType != other.MessageType) return false;
if (TestCategory != other.TestCategory) return false; if (TestCategory != other.TestCategory) return false;
...@@ -419,6 +448,7 @@ namespace Conformance { ...@@ -419,6 +448,7 @@ namespace Conformance {
if (payloadCase_ == PayloadOneofCase.ProtobufPayload) hash ^= ProtobufPayload.GetHashCode(); if (payloadCase_ == PayloadOneofCase.ProtobufPayload) hash ^= ProtobufPayload.GetHashCode();
if (payloadCase_ == PayloadOneofCase.JsonPayload) hash ^= JsonPayload.GetHashCode(); if (payloadCase_ == PayloadOneofCase.JsonPayload) hash ^= JsonPayload.GetHashCode();
if (payloadCase_ == PayloadOneofCase.JspbPayload) hash ^= JspbPayload.GetHashCode(); if (payloadCase_ == PayloadOneofCase.JspbPayload) hash ^= JspbPayload.GetHashCode();
if (payloadCase_ == PayloadOneofCase.TextPayload) hash ^= TextPayload.GetHashCode();
if (RequestedOutputFormat != 0) hash ^= RequestedOutputFormat.GetHashCode(); if (RequestedOutputFormat != 0) hash ^= RequestedOutputFormat.GetHashCode();
if (MessageType.Length != 0) hash ^= MessageType.GetHashCode(); if (MessageType.Length != 0) hash ^= MessageType.GetHashCode();
if (TestCategory != 0) hash ^= TestCategory.GetHashCode(); if (TestCategory != 0) hash ^= TestCategory.GetHashCode();
...@@ -465,6 +495,10 @@ namespace Conformance { ...@@ -465,6 +495,10 @@ namespace Conformance {
output.WriteRawTag(58); output.WriteRawTag(58);
output.WriteString(JspbPayload); output.WriteString(JspbPayload);
} }
if (payloadCase_ == PayloadOneofCase.TextPayload) {
output.WriteRawTag(66);
output.WriteString(TextPayload);
}
if (_unknownFields != null) { if (_unknownFields != null) {
_unknownFields.WriteTo(output); _unknownFields.WriteTo(output);
} }
...@@ -482,6 +516,9 @@ namespace Conformance { ...@@ -482,6 +516,9 @@ namespace Conformance {
if (payloadCase_ == PayloadOneofCase.JspbPayload) { if (payloadCase_ == PayloadOneofCase.JspbPayload) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(JspbPayload); size += 1 + pb::CodedOutputStream.ComputeStringSize(JspbPayload);
} }
if (payloadCase_ == PayloadOneofCase.TextPayload) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(TextPayload);
}
if (RequestedOutputFormat != 0) { if (RequestedOutputFormat != 0) {
size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) RequestedOutputFormat); size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) RequestedOutputFormat);
} }
...@@ -530,6 +567,9 @@ namespace Conformance { ...@@ -530,6 +567,9 @@ namespace Conformance {
case PayloadOneofCase.JspbPayload: case PayloadOneofCase.JspbPayload:
JspbPayload = other.JspbPayload; JspbPayload = other.JspbPayload;
break; break;
case PayloadOneofCase.TextPayload:
TextPayload = other.TextPayload;
break;
} }
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
...@@ -576,6 +616,10 @@ namespace Conformance { ...@@ -576,6 +616,10 @@ namespace Conformance {
JspbPayload = input.ReadString(); JspbPayload = input.ReadString();
break; break;
} }
case 66: {
TextPayload = input.ReadString();
break;
}
} }
} }
} }
...@@ -632,6 +676,9 @@ namespace Conformance { ...@@ -632,6 +676,9 @@ namespace Conformance {
case ResultOneofCase.JspbPayload: case ResultOneofCase.JspbPayload:
JspbPayload = other.JspbPayload; JspbPayload = other.JspbPayload;
break; break;
case ResultOneofCase.TextPayload:
TextPayload = other.TextPayload;
break;
} }
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
...@@ -753,6 +800,21 @@ namespace Conformance { ...@@ -753,6 +800,21 @@ namespace Conformance {
} }
} }
/// <summary>Field number for the "text_payload" field.</summary>
public const int TextPayloadFieldNumber = 8;
/// <summary>
/// If the input was successfully parsed and the requested output was
/// TEXT_FORMAT, serialize to TEXT_FORMAT and set it in this field.
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string TextPayload {
get { return resultCase_ == ResultOneofCase.TextPayload ? (string) result_ : ""; }
set {
result_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
resultCase_ = ResultOneofCase.TextPayload;
}
}
private object result_; private object result_;
/// <summary>Enum of possible cases for the "result" oneof.</summary> /// <summary>Enum of possible cases for the "result" oneof.</summary>
public enum ResultOneofCase { public enum ResultOneofCase {
...@@ -764,6 +826,7 @@ namespace Conformance { ...@@ -764,6 +826,7 @@ namespace Conformance {
JsonPayload = 4, JsonPayload = 4,
Skipped = 5, Skipped = 5,
JspbPayload = 7, JspbPayload = 7,
TextPayload = 8,
} }
private ResultOneofCase resultCase_ = ResultOneofCase.None; private ResultOneofCase resultCase_ = ResultOneofCase.None;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
...@@ -797,6 +860,7 @@ namespace Conformance { ...@@ -797,6 +860,7 @@ namespace Conformance {
if (JsonPayload != other.JsonPayload) return false; if (JsonPayload != other.JsonPayload) return false;
if (Skipped != other.Skipped) return false; if (Skipped != other.Skipped) return false;
if (JspbPayload != other.JspbPayload) return false; if (JspbPayload != other.JspbPayload) return false;
if (TextPayload != other.TextPayload) return false;
if (ResultCase != other.ResultCase) return false; if (ResultCase != other.ResultCase) return false;
return Equals(_unknownFields, other._unknownFields); return Equals(_unknownFields, other._unknownFields);
} }
...@@ -811,6 +875,7 @@ namespace Conformance { ...@@ -811,6 +875,7 @@ namespace Conformance {
if (resultCase_ == ResultOneofCase.JsonPayload) hash ^= JsonPayload.GetHashCode(); if (resultCase_ == ResultOneofCase.JsonPayload) hash ^= JsonPayload.GetHashCode();
if (resultCase_ == ResultOneofCase.Skipped) hash ^= Skipped.GetHashCode(); if (resultCase_ == ResultOneofCase.Skipped) hash ^= Skipped.GetHashCode();
if (resultCase_ == ResultOneofCase.JspbPayload) hash ^= JspbPayload.GetHashCode(); if (resultCase_ == ResultOneofCase.JspbPayload) hash ^= JspbPayload.GetHashCode();
if (resultCase_ == ResultOneofCase.TextPayload) hash ^= TextPayload.GetHashCode();
hash ^= (int) resultCase_; hash ^= (int) resultCase_;
if (_unknownFields != null) { if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode(); hash ^= _unknownFields.GetHashCode();
...@@ -853,6 +918,10 @@ namespace Conformance { ...@@ -853,6 +918,10 @@ namespace Conformance {
output.WriteRawTag(58); output.WriteRawTag(58);
output.WriteString(JspbPayload); output.WriteString(JspbPayload);
} }
if (resultCase_ == ResultOneofCase.TextPayload) {
output.WriteRawTag(66);
output.WriteString(TextPayload);
}
if (_unknownFields != null) { if (_unknownFields != null) {
_unknownFields.WriteTo(output); _unknownFields.WriteTo(output);
} }
...@@ -882,6 +951,9 @@ namespace Conformance { ...@@ -882,6 +951,9 @@ namespace Conformance {
if (resultCase_ == ResultOneofCase.JspbPayload) { if (resultCase_ == ResultOneofCase.JspbPayload) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(JspbPayload); size += 1 + pb::CodedOutputStream.ComputeStringSize(JspbPayload);
} }
if (resultCase_ == ResultOneofCase.TextPayload) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(TextPayload);
}
if (_unknownFields != null) { if (_unknownFields != null) {
size += _unknownFields.CalculateSize(); size += _unknownFields.CalculateSize();
} }
...@@ -915,6 +987,9 @@ namespace Conformance { ...@@ -915,6 +987,9 @@ namespace Conformance {
case ResultOneofCase.JspbPayload: case ResultOneofCase.JspbPayload:
JspbPayload = other.JspbPayload; JspbPayload = other.JspbPayload;
break; break;
case ResultOneofCase.TextPayload:
TextPayload = other.TextPayload;
break;
} }
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
...@@ -958,6 +1033,10 @@ namespace Conformance { ...@@ -958,6 +1033,10 @@ namespace Conformance {
JspbPayload = input.ReadString(); JspbPayload = input.ReadString();
break; break;
} }
case 66: {
TextPayload = input.ReadString();
break;
}
} }
} }
} }
......
...@@ -39,8 +39,7 @@ import "google/protobuf/descriptor.proto"; ...@@ -39,8 +39,7 @@ import "google/protobuf/descriptor.proto";
package jspb.test; package jspb.test;
message Empty { message Empty {}
}
enum OuterEnum { enum OuterEnum {
FOO = 1; FOO = 1;
...@@ -137,12 +136,13 @@ message DefaultValues { ...@@ -137,12 +136,13 @@ message DefaultValues {
E1 = 13; E1 = 13;
E2 = 77; E2 = 77;
} }
optional string string_field = 1 [default="default<>\'\"abc"]; optional string string_field = 1 [default = "default<>\'\"abc"];
optional bool bool_field = 2 [default=true]; optional bool bool_field = 2 [default = true];
optional int64 int_field = 3 [default=11]; optional int64 int_field = 3 [default = 11];
optional Enum enum_field = 4 [default=E1]; optional Enum enum_field = 4 [default = E1];
optional string empty_field = 6 [default=""]; optional string empty_field = 6 [default = ""];
optional bytes bytes_field = 8 [default="moo"]; // Base64 encoding is "bW9v" optional bytes bytes_field = 8
[default = "moo"]; // Base64 encoding is "bW9v"
} }
message FloatingPointFields { message FloatingPointFields {
...@@ -254,9 +254,9 @@ extend TestLastFieldBeforePivot { ...@@ -254,9 +254,9 @@ extend TestLastFieldBeforePivot {
message Int64Types { message Int64Types {
optional int64 int64_normal = 1 [jstype=JS_NORMAL]; optional int64 int64_normal = 1 [jstype = JS_NORMAL];
optional sint64 int64_string = 2 [jstype=JS_STRING]; optional sint64 int64_string = 2 [jstype = JS_STRING];
optional uint64 int64_number = 3 [jstype=JS_NUMBER]; optional uint64 int64_number = 3 [jstype = JS_NUMBER];
} }
...@@ -297,3 +297,4 @@ message Deeply { ...@@ -297,3 +297,4 @@ message Deeply {
} }
} }
...@@ -2847,52 +2847,69 @@ void Generator::GenerateClassField(const GeneratorOptions& options, ...@@ -2847,52 +2847,69 @@ void Generator::GenerateClassField(const GeneratorOptions& options,
// Generate clearFoo() method for map fields, repeated fields, and other // Generate clearFoo() method for map fields, repeated fields, and other
// fields with presence. // fields with presence.
if (field->is_map()) { if (field->is_map()) {
// clang-format off
printer->Print( printer->Print(
"/** Clears values from the map. The map will be non-null. */\n" "/**\n"
" * Clears values from the map. The map will be non-null."
"$returndoc$\n"
" */\n"
"$class$.prototype.$clearername$ = function() {\n" "$class$.prototype.$clearername$ = function() {\n"
" this.$gettername$().clear();$returnvalue$\n" " this.$gettername$().clear();$returnvalue$\n"
"};\n" "};\n"
"\n" "\n"
"\n", "\n",
"returndoc", JSReturnDoc(options, field),
"class", GetMessagePath(options, field->containing_type()), "class", GetMessagePath(options, field->containing_type()),
"clearername", "clear" + JSGetterName(options, field), "gettername", "clearername", "clear" + JSGetterName(options, field),
"get" + JSGetterName(options, field), "returnvalue", "gettername", "get" + JSGetterName(options, field),
JSReturnClause(field)); "returnvalue", JSReturnClause(field));
// clang-format on
printer->Annotate("clearername", field); printer->Annotate("clearername", field);
} else if (field->is_repeated() || } else if (field->is_repeated() ||
(field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE && (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE &&
!field->is_required())) { !field->is_required())) {
// Fields where we can delegate to the regular setter. // Fields where we can delegate to the regular setter.
// clang-format off
printer->Print( printer->Print(
"/** $jsdoc$ */\n" "/**\n"
" * $jsdoc$$returndoc$\n"
" */\n"
"$class$.prototype.$clearername$ = function() {\n" "$class$.prototype.$clearername$ = function() {\n"
" this.$settername$($clearedvalue$);$returnvalue$\n" " this.$settername$($clearedvalue$);$returnvalue$\n"
"};\n" "};\n"
"\n" "\n"
"\n", "\n",
"jsdoc", "jsdoc", field->is_repeated()
field->is_repeated() ? "Clears the list making it empty but non-null." ? "Clears the list making it empty but non-null."
: "Clears the message field making it undefined.", : "Clears the message field making it undefined.",
"returndoc", JSReturnDoc(options, field),
"class", GetMessagePath(options, field->containing_type()), "class", GetMessagePath(options, field->containing_type()),
"clearername", "clear" + JSGetterName(options, field), "settername", "clearername", "clear" + JSGetterName(options, field),
"set" + JSGetterName(options, field), "clearedvalue", "settername", "set" + JSGetterName(options, field),
(field->is_repeated() ? "[]" : "undefined"), "returnvalue", "clearedvalue", (field->is_repeated() ? "[]" : "undefined"),
JSReturnClause(field)); "returnvalue", JSReturnClause(field));
// clang-format on
printer->Annotate("clearername", field); printer->Annotate("clearername", field);
} else if (HasFieldPresence(options, field)) { } else if (HasFieldPresence(options, field)) {
// Fields where we can't delegate to the regular setter because it doesn't // Fields where we can't delegate to the regular setter because it doesn't
// accept "undefined" as an argument. // accept "undefined" as an argument.
// clang-format off
printer->Print( printer->Print(
"/** Clears the field making it undefined. */\n" "/**\n"
" * Clears the field making it undefined.$returndoc$\n"
" */\n"
"$class$.prototype.$clearername$ = function() {\n" "$class$.prototype.$clearername$ = function() {\n"
" jspb.Message.set$maybeoneof$Field(this, " " jspb.Message.set$maybeoneof$Field(this, "
"$index$$maybeoneofgroup$, ", "$index$$maybeoneofgroup$, ",
"returndoc", JSReturnDoc(options, field),
"class", GetMessagePath(options, field->containing_type()), "class", GetMessagePath(options, field->containing_type()),
"clearername", "clear" + JSGetterName(options, field), "maybeoneof", "clearername", "clear" + JSGetterName(options, field),
(field->containing_oneof() ? "Oneof" : ""), "maybeoneofgroup", "maybeoneof", (field->containing_oneof() ? "Oneof" : ""),
(field->containing_oneof() ? (", " + JSOneofArray(options, field)) "maybeoneofgroup", (field->containing_oneof()
: ""), ? (", " + JSOneofArray(options, field))
: ""),
"index", JSFieldIndex(field)); "index", JSFieldIndex(field));
// clang-format on
printer->Annotate("clearername", field); printer->Annotate("clearername", field);
printer->Print( printer->Print(
"$clearedvalue$);$returnvalue$\n" "$clearedvalue$);$returnvalue$\n"
......
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