From 51f22eb3340f4a5c67aa85d243fc7f379d6ec558 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Tue, 7 Mar 2023 03:01:08 +0000 Subject: [PATCH] Auto-generate files after cl/514587333 --- .../Conformance.pb.cs | 312 ++++++++++++++---- .../TestMessagesProto3.pb.cs | 216 +++++++++--- .../UnittestCustomOptionsProto3.pb.cs | 24 +- .../UnittestIssues.pb.cs | 268 +++++++++++---- .../UnittestProto3.pb.cs | 120 +++++-- .../UnittestProto3Optional.pb.cs | 72 +++- .../WellKnownTypes/Struct.pb.cs | 96 ++++-- 7 files changed, 874 insertions(+), 234 deletions(-) diff --git a/csharp/src/Google.Protobuf.Conformance/Conformance.pb.cs b/csharp/src/Google.Protobuf.Conformance/Conformance.pb.cs index 664a17b636..3b4ff5362d 100644 --- a/csharp/src/Google.Protobuf.Conformance/Conformance.pb.cs +++ b/csharp/src/Google.Protobuf.Conformance/Conformance.pb.cs @@ -362,24 +362,52 @@ namespace Conformance { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public pb::ByteString ProtobufPayload { - get { return payloadCase_ == PayloadOneofCase.ProtobufPayload ? (pb::ByteString) payload_ : pb::ByteString.Empty; } + get { return HasProtobufPayload ? (pb::ByteString) payload_ : pb::ByteString.Empty; } set { payload_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); payloadCase_ = PayloadOneofCase.ProtobufPayload; } } + /// Gets whether the "protobuf_payload" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasProtobufPayload { + get { return payloadCase_ == PayloadOneofCase.ProtobufPayload; } + } + /// Clears the value of the oneof if it's currently set to "protobuf_payload" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearProtobufPayload() { + if (HasProtobufPayload) { + ClearPayload(); + } + } /// Field number for the "json_payload" field. public const int JsonPayloadFieldNumber = 2; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public string JsonPayload { - get { return payloadCase_ == PayloadOneofCase.JsonPayload ? (string) payload_ : ""; } + get { return HasJsonPayload ? (string) payload_ : ""; } set { payload_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); payloadCase_ = PayloadOneofCase.JsonPayload; } } + /// Gets whether the "json_payload" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasJsonPayload { + get { return payloadCase_ == PayloadOneofCase.JsonPayload; } + } + /// Clears the value of the oneof if it's currently set to "json_payload" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearJsonPayload() { + if (HasJsonPayload) { + ClearPayload(); + } + } /// Field number for the "jspb_payload" field. public const int JspbPayloadFieldNumber = 7; @@ -389,24 +417,52 @@ namespace Conformance { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public string JspbPayload { - get { return payloadCase_ == PayloadOneofCase.JspbPayload ? (string) payload_ : ""; } + get { return HasJspbPayload ? (string) payload_ : ""; } set { payload_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); payloadCase_ = PayloadOneofCase.JspbPayload; } } + /// Gets whether the "jspb_payload" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasJspbPayload { + get { return payloadCase_ == PayloadOneofCase.JspbPayload; } + } + /// Clears the value of the oneof if it's currently set to "jspb_payload" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearJspbPayload() { + if (HasJspbPayload) { + ClearPayload(); + } + } /// Field number for the "text_payload" field. public const int TextPayloadFieldNumber = 8; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public string TextPayload { - get { return payloadCase_ == PayloadOneofCase.TextPayload ? (string) payload_ : ""; } + get { return HasTextPayload ? (string) payload_ : ""; } set { payload_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); payloadCase_ = PayloadOneofCase.TextPayload; } } + /// Gets whether the "text_payload" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasTextPayload { + get { return payloadCase_ == PayloadOneofCase.TextPayload; } + } + /// Clears the value of the oneof if it's currently set to "text_payload" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearTextPayload() { + if (HasTextPayload) { + ClearPayload(); + } + } /// Field number for the "requested_output_format" field. public const int RequestedOutputFormatFieldNumber = 3; @@ -543,10 +599,10 @@ namespace Conformance { [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public override int GetHashCode() { int hash = 1; - if (payloadCase_ == PayloadOneofCase.ProtobufPayload) hash ^= ProtobufPayload.GetHashCode(); - if (payloadCase_ == PayloadOneofCase.JsonPayload) hash ^= JsonPayload.GetHashCode(); - if (payloadCase_ == PayloadOneofCase.JspbPayload) hash ^= JspbPayload.GetHashCode(); - if (payloadCase_ == PayloadOneofCase.TextPayload) hash ^= TextPayload.GetHashCode(); + if (HasProtobufPayload) hash ^= ProtobufPayload.GetHashCode(); + if (HasJsonPayload) hash ^= JsonPayload.GetHashCode(); + if (HasJspbPayload) hash ^= JspbPayload.GetHashCode(); + if (HasTextPayload) hash ^= TextPayload.GetHashCode(); if (RequestedOutputFormat != global::Conformance.WireFormat.Unspecified) hash ^= RequestedOutputFormat.GetHashCode(); if (MessageType.Length != 0) hash ^= MessageType.GetHashCode(); if (TestCategory != global::Conformance.TestCategory.UnspecifiedTest) hash ^= TestCategory.GetHashCode(); @@ -571,11 +627,11 @@ namespace Conformance { #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE output.WriteRawMessage(this); #else - if (payloadCase_ == PayloadOneofCase.ProtobufPayload) { + if (HasProtobufPayload) { output.WriteRawTag(10); output.WriteBytes(ProtobufPayload); } - if (payloadCase_ == PayloadOneofCase.JsonPayload) { + if (HasJsonPayload) { output.WriteRawTag(18); output.WriteString(JsonPayload); } @@ -595,11 +651,11 @@ namespace Conformance { output.WriteRawTag(50); output.WriteMessage(JspbEncodingOptions); } - if (payloadCase_ == PayloadOneofCase.JspbPayload) { + if (HasJspbPayload) { output.WriteRawTag(58); output.WriteString(JspbPayload); } - if (payloadCase_ == PayloadOneofCase.TextPayload) { + if (HasTextPayload) { output.WriteRawTag(66); output.WriteString(TextPayload); } @@ -617,11 +673,11 @@ namespace Conformance { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { - if (payloadCase_ == PayloadOneofCase.ProtobufPayload) { + if (HasProtobufPayload) { output.WriteRawTag(10); output.WriteBytes(ProtobufPayload); } - if (payloadCase_ == PayloadOneofCase.JsonPayload) { + if (HasJsonPayload) { output.WriteRawTag(18); output.WriteString(JsonPayload); } @@ -641,11 +697,11 @@ namespace Conformance { output.WriteRawTag(50); output.WriteMessage(JspbEncodingOptions); } - if (payloadCase_ == PayloadOneofCase.JspbPayload) { + if (HasJspbPayload) { output.WriteRawTag(58); output.WriteString(JspbPayload); } - if (payloadCase_ == PayloadOneofCase.TextPayload) { + if (HasTextPayload) { output.WriteRawTag(66); output.WriteString(TextPayload); } @@ -663,16 +719,16 @@ namespace Conformance { [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public int CalculateSize() { int size = 0; - if (payloadCase_ == PayloadOneofCase.ProtobufPayload) { + if (HasProtobufPayload) { size += 1 + pb::CodedOutputStream.ComputeBytesSize(ProtobufPayload); } - if (payloadCase_ == PayloadOneofCase.JsonPayload) { + if (HasJsonPayload) { size += 1 + pb::CodedOutputStream.ComputeStringSize(JsonPayload); } - if (payloadCase_ == PayloadOneofCase.JspbPayload) { + if (HasJspbPayload) { size += 1 + pb::CodedOutputStream.ComputeStringSize(JspbPayload); } - if (payloadCase_ == PayloadOneofCase.TextPayload) { + if (HasTextPayload) { size += 1 + pb::CodedOutputStream.ComputeStringSize(TextPayload); } if (RequestedOutputFormat != global::Conformance.WireFormat.Unspecified) { @@ -938,12 +994,26 @@ namespace Conformance { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public string ParseError { - get { return resultCase_ == ResultOneofCase.ParseError ? (string) result_ : ""; } + get { return HasParseError ? (string) result_ : ""; } set { result_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); resultCase_ = ResultOneofCase.ParseError; } } + /// Gets whether the "parse_error" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasParseError { + get { return resultCase_ == ResultOneofCase.ParseError; } + } + /// Clears the value of the oneof if it's currently set to "parse_error" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearParseError() { + if (HasParseError) { + ClearResult(); + } + } /// Field number for the "serialize_error" field. public const int SerializeErrorFieldNumber = 6; @@ -955,12 +1025,26 @@ namespace Conformance { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public string SerializeError { - get { return resultCase_ == ResultOneofCase.SerializeError ? (string) result_ : ""; } + get { return HasSerializeError ? (string) result_ : ""; } set { result_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); resultCase_ = ResultOneofCase.SerializeError; } } + /// Gets whether the "serialize_error" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasSerializeError { + get { return resultCase_ == ResultOneofCase.SerializeError; } + } + /// Clears the value of the oneof if it's currently set to "serialize_error" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearSerializeError() { + if (HasSerializeError) { + ClearResult(); + } + } /// Field number for the "timeout_error" field. public const int TimeoutErrorFieldNumber = 9; @@ -972,12 +1056,26 @@ namespace Conformance { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public string TimeoutError { - get { return resultCase_ == ResultOneofCase.TimeoutError ? (string) result_ : ""; } + get { return HasTimeoutError ? (string) result_ : ""; } set { result_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); resultCase_ = ResultOneofCase.TimeoutError; } } + /// Gets whether the "timeout_error" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasTimeoutError { + get { return resultCase_ == ResultOneofCase.TimeoutError; } + } + /// Clears the value of the oneof if it's currently set to "timeout_error" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearTimeoutError() { + if (HasTimeoutError) { + ClearResult(); + } + } /// Field number for the "runtime_error" field. public const int RuntimeErrorFieldNumber = 2; @@ -989,12 +1087,26 @@ namespace Conformance { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public string RuntimeError { - get { return resultCase_ == ResultOneofCase.RuntimeError ? (string) result_ : ""; } + get { return HasRuntimeError ? (string) result_ : ""; } set { result_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); resultCase_ = ResultOneofCase.RuntimeError; } } + /// Gets whether the "runtime_error" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasRuntimeError { + get { return resultCase_ == ResultOneofCase.RuntimeError; } + } + /// Clears the value of the oneof if it's currently set to "runtime_error" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearRuntimeError() { + if (HasRuntimeError) { + ClearResult(); + } + } /// Field number for the "protobuf_payload" field. public const int ProtobufPayloadFieldNumber = 3; @@ -1005,12 +1117,26 @@ namespace Conformance { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public pb::ByteString ProtobufPayload { - get { return resultCase_ == ResultOneofCase.ProtobufPayload ? (pb::ByteString) result_ : pb::ByteString.Empty; } + get { return HasProtobufPayload ? (pb::ByteString) result_ : pb::ByteString.Empty; } set { result_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); resultCase_ = ResultOneofCase.ProtobufPayload; } } + /// Gets whether the "protobuf_payload" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasProtobufPayload { + get { return resultCase_ == ResultOneofCase.ProtobufPayload; } + } + /// Clears the value of the oneof if it's currently set to "protobuf_payload" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearProtobufPayload() { + if (HasProtobufPayload) { + ClearResult(); + } + } /// Field number for the "json_payload" field. public const int JsonPayloadFieldNumber = 4; @@ -1021,12 +1147,26 @@ namespace Conformance { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public string JsonPayload { - get { return resultCase_ == ResultOneofCase.JsonPayload ? (string) result_ : ""; } + get { return HasJsonPayload ? (string) result_ : ""; } set { result_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); resultCase_ = ResultOneofCase.JsonPayload; } } + /// Gets whether the "json_payload" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasJsonPayload { + get { return resultCase_ == ResultOneofCase.JsonPayload; } + } + /// Clears the value of the oneof if it's currently set to "json_payload" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearJsonPayload() { + if (HasJsonPayload) { + ClearResult(); + } + } /// Field number for the "skipped" field. public const int SkippedFieldNumber = 5; @@ -1037,12 +1177,26 @@ namespace Conformance { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public string Skipped { - get { return resultCase_ == ResultOneofCase.Skipped ? (string) result_ : ""; } + get { return HasSkipped ? (string) result_ : ""; } set { result_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); resultCase_ = ResultOneofCase.Skipped; } } + /// Gets whether the "skipped" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasSkipped { + get { return resultCase_ == ResultOneofCase.Skipped; } + } + /// Clears the value of the oneof if it's currently set to "skipped" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearSkipped() { + if (HasSkipped) { + ClearResult(); + } + } /// Field number for the "jspb_payload" field. public const int JspbPayloadFieldNumber = 7; @@ -1054,12 +1208,26 @@ namespace Conformance { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public string JspbPayload { - get { return resultCase_ == ResultOneofCase.JspbPayload ? (string) result_ : ""; } + get { return HasJspbPayload ? (string) result_ : ""; } set { result_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); resultCase_ = ResultOneofCase.JspbPayload; } } + /// Gets whether the "jspb_payload" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasJspbPayload { + get { return resultCase_ == ResultOneofCase.JspbPayload; } + } + /// Clears the value of the oneof if it's currently set to "jspb_payload" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearJspbPayload() { + if (HasJspbPayload) { + ClearResult(); + } + } /// Field number for the "text_payload" field. public const int TextPayloadFieldNumber = 8; @@ -1070,12 +1238,26 @@ namespace Conformance { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public string TextPayload { - get { return resultCase_ == ResultOneofCase.TextPayload ? (string) result_ : ""; } + get { return HasTextPayload ? (string) result_ : ""; } set { result_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); resultCase_ = ResultOneofCase.TextPayload; } } + /// Gets whether the "text_payload" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasTextPayload { + get { return resultCase_ == ResultOneofCase.TextPayload; } + } + /// Clears the value of the oneof if it's currently set to "text_payload" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearTextPayload() { + if (HasTextPayload) { + ClearResult(); + } + } private object result_; /// Enum of possible cases for the "result" oneof. @@ -1137,15 +1319,15 @@ namespace Conformance { [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public override int GetHashCode() { int hash = 1; - if (resultCase_ == ResultOneofCase.ParseError) hash ^= ParseError.GetHashCode(); - if (resultCase_ == ResultOneofCase.SerializeError) hash ^= SerializeError.GetHashCode(); - if (resultCase_ == ResultOneofCase.TimeoutError) hash ^= TimeoutError.GetHashCode(); - if (resultCase_ == ResultOneofCase.RuntimeError) hash ^= RuntimeError.GetHashCode(); - if (resultCase_ == ResultOneofCase.ProtobufPayload) hash ^= ProtobufPayload.GetHashCode(); - if (resultCase_ == ResultOneofCase.JsonPayload) hash ^= JsonPayload.GetHashCode(); - if (resultCase_ == ResultOneofCase.Skipped) hash ^= Skipped.GetHashCode(); - if (resultCase_ == ResultOneofCase.JspbPayload) hash ^= JspbPayload.GetHashCode(); - if (resultCase_ == ResultOneofCase.TextPayload) hash ^= TextPayload.GetHashCode(); + if (HasParseError) hash ^= ParseError.GetHashCode(); + if (HasSerializeError) hash ^= SerializeError.GetHashCode(); + if (HasTimeoutError) hash ^= TimeoutError.GetHashCode(); + if (HasRuntimeError) hash ^= RuntimeError.GetHashCode(); + if (HasProtobufPayload) hash ^= ProtobufPayload.GetHashCode(); + if (HasJsonPayload) hash ^= JsonPayload.GetHashCode(); + if (HasSkipped) hash ^= Skipped.GetHashCode(); + if (HasJspbPayload) hash ^= JspbPayload.GetHashCode(); + if (HasTextPayload) hash ^= TextPayload.GetHashCode(); hash ^= (int) resultCase_; if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); @@ -1165,39 +1347,39 @@ namespace Conformance { #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE output.WriteRawMessage(this); #else - if (resultCase_ == ResultOneofCase.ParseError) { + if (HasParseError) { output.WriteRawTag(10); output.WriteString(ParseError); } - if (resultCase_ == ResultOneofCase.RuntimeError) { + if (HasRuntimeError) { output.WriteRawTag(18); output.WriteString(RuntimeError); } - if (resultCase_ == ResultOneofCase.ProtobufPayload) { + if (HasProtobufPayload) { output.WriteRawTag(26); output.WriteBytes(ProtobufPayload); } - if (resultCase_ == ResultOneofCase.JsonPayload) { + if (HasJsonPayload) { output.WriteRawTag(34); output.WriteString(JsonPayload); } - if (resultCase_ == ResultOneofCase.Skipped) { + if (HasSkipped) { output.WriteRawTag(42); output.WriteString(Skipped); } - if (resultCase_ == ResultOneofCase.SerializeError) { + if (HasSerializeError) { output.WriteRawTag(50); output.WriteString(SerializeError); } - if (resultCase_ == ResultOneofCase.JspbPayload) { + if (HasJspbPayload) { output.WriteRawTag(58); output.WriteString(JspbPayload); } - if (resultCase_ == ResultOneofCase.TextPayload) { + if (HasTextPayload) { output.WriteRawTag(66); output.WriteString(TextPayload); } - if (resultCase_ == ResultOneofCase.TimeoutError) { + if (HasTimeoutError) { output.WriteRawTag(74); output.WriteString(TimeoutError); } @@ -1211,39 +1393,39 @@ namespace Conformance { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { - if (resultCase_ == ResultOneofCase.ParseError) { + if (HasParseError) { output.WriteRawTag(10); output.WriteString(ParseError); } - if (resultCase_ == ResultOneofCase.RuntimeError) { + if (HasRuntimeError) { output.WriteRawTag(18); output.WriteString(RuntimeError); } - if (resultCase_ == ResultOneofCase.ProtobufPayload) { + if (HasProtobufPayload) { output.WriteRawTag(26); output.WriteBytes(ProtobufPayload); } - if (resultCase_ == ResultOneofCase.JsonPayload) { + if (HasJsonPayload) { output.WriteRawTag(34); output.WriteString(JsonPayload); } - if (resultCase_ == ResultOneofCase.Skipped) { + if (HasSkipped) { output.WriteRawTag(42); output.WriteString(Skipped); } - if (resultCase_ == ResultOneofCase.SerializeError) { + if (HasSerializeError) { output.WriteRawTag(50); output.WriteString(SerializeError); } - if (resultCase_ == ResultOneofCase.JspbPayload) { + if (HasJspbPayload) { output.WriteRawTag(58); output.WriteString(JspbPayload); } - if (resultCase_ == ResultOneofCase.TextPayload) { + if (HasTextPayload) { output.WriteRawTag(66); output.WriteString(TextPayload); } - if (resultCase_ == ResultOneofCase.TimeoutError) { + if (HasTimeoutError) { output.WriteRawTag(74); output.WriteString(TimeoutError); } @@ -1257,31 +1439,31 @@ namespace Conformance { [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public int CalculateSize() { int size = 0; - if (resultCase_ == ResultOneofCase.ParseError) { + if (HasParseError) { size += 1 + pb::CodedOutputStream.ComputeStringSize(ParseError); } - if (resultCase_ == ResultOneofCase.SerializeError) { + if (HasSerializeError) { size += 1 + pb::CodedOutputStream.ComputeStringSize(SerializeError); } - if (resultCase_ == ResultOneofCase.TimeoutError) { + if (HasTimeoutError) { size += 1 + pb::CodedOutputStream.ComputeStringSize(TimeoutError); } - if (resultCase_ == ResultOneofCase.RuntimeError) { + if (HasRuntimeError) { size += 1 + pb::CodedOutputStream.ComputeStringSize(RuntimeError); } - if (resultCase_ == ResultOneofCase.ProtobufPayload) { + if (HasProtobufPayload) { size += 1 + pb::CodedOutputStream.ComputeBytesSize(ProtobufPayload); } - if (resultCase_ == ResultOneofCase.JsonPayload) { + if (HasJsonPayload) { size += 1 + pb::CodedOutputStream.ComputeStringSize(JsonPayload); } - if (resultCase_ == ResultOneofCase.Skipped) { + if (HasSkipped) { size += 1 + pb::CodedOutputStream.ComputeStringSize(Skipped); } - if (resultCase_ == ResultOneofCase.JspbPayload) { + if (HasJspbPayload) { size += 1 + pb::CodedOutputStream.ComputeStringSize(JspbPayload); } - if (resultCase_ == ResultOneofCase.TextPayload) { + if (HasTextPayload) { size += 1 + pb::CodedOutputStream.ComputeStringSize(TextPayload); } if (_unknownFields != null) { diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto3.pb.cs b/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto3.pb.cs index 74e2a57680..47bb7d0111 100644 --- a/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto3.pb.cs +++ b/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto3.pb.cs @@ -1526,12 +1526,26 @@ namespace ProtobufTestMessages.Proto3 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public uint OneofUint32 { - get { return oneofFieldCase_ == OneofFieldOneofCase.OneofUint32 ? (uint) oneofField_ : 0; } + get { return HasOneofUint32 ? (uint) oneofField_ : 0; } set { oneofField_ = value; oneofFieldCase_ = OneofFieldOneofCase.OneofUint32; } } + /// Gets whether the "oneof_uint32" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasOneofUint32 { + get { return oneofFieldCase_ == OneofFieldOneofCase.OneofUint32; } + } + /// Clears the value of the oneof if it's currently set to "oneof_uint32" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearOneofUint32() { + if (HasOneofUint32) { + ClearOneofField(); + } + } /// Field number for the "oneof_nested_message" field. public const int OneofNestedMessageFieldNumber = 112; @@ -1550,96 +1564,208 @@ namespace ProtobufTestMessages.Proto3 { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public string OneofString { - get { return oneofFieldCase_ == OneofFieldOneofCase.OneofString ? (string) oneofField_ : ""; } + get { return HasOneofString ? (string) oneofField_ : ""; } set { oneofField_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); oneofFieldCase_ = OneofFieldOneofCase.OneofString; } } + /// Gets whether the "oneof_string" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasOneofString { + get { return oneofFieldCase_ == OneofFieldOneofCase.OneofString; } + } + /// Clears the value of the oneof if it's currently set to "oneof_string" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearOneofString() { + if (HasOneofString) { + ClearOneofField(); + } + } /// Field number for the "oneof_bytes" field. public const int OneofBytesFieldNumber = 114; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public pb::ByteString OneofBytes { - get { return oneofFieldCase_ == OneofFieldOneofCase.OneofBytes ? (pb::ByteString) oneofField_ : pb::ByteString.Empty; } + get { return HasOneofBytes ? (pb::ByteString) oneofField_ : pb::ByteString.Empty; } set { oneofField_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); oneofFieldCase_ = OneofFieldOneofCase.OneofBytes; } } + /// Gets whether the "oneof_bytes" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasOneofBytes { + get { return oneofFieldCase_ == OneofFieldOneofCase.OneofBytes; } + } + /// Clears the value of the oneof if it's currently set to "oneof_bytes" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearOneofBytes() { + if (HasOneofBytes) { + ClearOneofField(); + } + } /// Field number for the "oneof_bool" field. public const int OneofBoolFieldNumber = 115; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public bool OneofBool { - get { return oneofFieldCase_ == OneofFieldOneofCase.OneofBool ? (bool) oneofField_ : false; } + get { return HasOneofBool ? (bool) oneofField_ : false; } set { oneofField_ = value; oneofFieldCase_ = OneofFieldOneofCase.OneofBool; } } + /// Gets whether the "oneof_bool" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasOneofBool { + get { return oneofFieldCase_ == OneofFieldOneofCase.OneofBool; } + } + /// Clears the value of the oneof if it's currently set to "oneof_bool" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearOneofBool() { + if (HasOneofBool) { + ClearOneofField(); + } + } /// Field number for the "oneof_uint64" field. public const int OneofUint64FieldNumber = 116; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public ulong OneofUint64 { - get { return oneofFieldCase_ == OneofFieldOneofCase.OneofUint64 ? (ulong) oneofField_ : 0UL; } + get { return HasOneofUint64 ? (ulong) oneofField_ : 0UL; } set { oneofField_ = value; oneofFieldCase_ = OneofFieldOneofCase.OneofUint64; } } + /// Gets whether the "oneof_uint64" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasOneofUint64 { + get { return oneofFieldCase_ == OneofFieldOneofCase.OneofUint64; } + } + /// Clears the value of the oneof if it's currently set to "oneof_uint64" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearOneofUint64() { + if (HasOneofUint64) { + ClearOneofField(); + } + } /// Field number for the "oneof_float" field. public const int OneofFloatFieldNumber = 117; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public float OneofFloat { - get { return oneofFieldCase_ == OneofFieldOneofCase.OneofFloat ? (float) oneofField_ : 0F; } + get { return HasOneofFloat ? (float) oneofField_ : 0F; } set { oneofField_ = value; oneofFieldCase_ = OneofFieldOneofCase.OneofFloat; } } + /// Gets whether the "oneof_float" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasOneofFloat { + get { return oneofFieldCase_ == OneofFieldOneofCase.OneofFloat; } + } + /// Clears the value of the oneof if it's currently set to "oneof_float" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearOneofFloat() { + if (HasOneofFloat) { + ClearOneofField(); + } + } /// Field number for the "oneof_double" field. public const int OneofDoubleFieldNumber = 118; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public double OneofDouble { - get { return oneofFieldCase_ == OneofFieldOneofCase.OneofDouble ? (double) oneofField_ : 0D; } + get { return HasOneofDouble ? (double) oneofField_ : 0D; } set { oneofField_ = value; oneofFieldCase_ = OneofFieldOneofCase.OneofDouble; } } + /// Gets whether the "oneof_double" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasOneofDouble { + get { return oneofFieldCase_ == OneofFieldOneofCase.OneofDouble; } + } + /// Clears the value of the oneof if it's currently set to "oneof_double" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearOneofDouble() { + if (HasOneofDouble) { + ClearOneofField(); + } + } /// Field number for the "oneof_enum" field. public const int OneofEnumFieldNumber = 119; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public global::ProtobufTestMessages.Proto3.TestAllTypesProto3.Types.NestedEnum OneofEnum { - get { return oneofFieldCase_ == OneofFieldOneofCase.OneofEnum ? (global::ProtobufTestMessages.Proto3.TestAllTypesProto3.Types.NestedEnum) oneofField_ : global::ProtobufTestMessages.Proto3.TestAllTypesProto3.Types.NestedEnum.Foo; } + get { return HasOneofEnum ? (global::ProtobufTestMessages.Proto3.TestAllTypesProto3.Types.NestedEnum) oneofField_ : global::ProtobufTestMessages.Proto3.TestAllTypesProto3.Types.NestedEnum.Foo; } set { oneofField_ = value; oneofFieldCase_ = OneofFieldOneofCase.OneofEnum; } } + /// Gets whether the "oneof_enum" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasOneofEnum { + get { return oneofFieldCase_ == OneofFieldOneofCase.OneofEnum; } + } + /// Clears the value of the oneof if it's currently set to "oneof_enum" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearOneofEnum() { + if (HasOneofEnum) { + ClearOneofField(); + } + } /// Field number for the "oneof_null_value" field. public const int OneofNullValueFieldNumber = 120; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public global::Google.Protobuf.WellKnownTypes.NullValue OneofNullValue { - get { return oneofFieldCase_ == OneofFieldOneofCase.OneofNullValue ? (global::Google.Protobuf.WellKnownTypes.NullValue) oneofField_ : global::Google.Protobuf.WellKnownTypes.NullValue.NullValue; } + get { return HasOneofNullValue ? (global::Google.Protobuf.WellKnownTypes.NullValue) oneofField_ : global::Google.Protobuf.WellKnownTypes.NullValue.NullValue; } set { oneofField_ = value; oneofFieldCase_ = OneofFieldOneofCase.OneofNullValue; } } + /// Gets whether the "oneof_null_value" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasOneofNullValue { + get { return oneofFieldCase_ == OneofFieldOneofCase.OneofNullValue; } + } + /// Clears the value of the oneof if it's currently set to "oneof_null_value" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearOneofNullValue() { + if (HasOneofNullValue) { + ClearOneofField(); + } + } /// Field number for the "optional_bool_wrapper" field. public const int OptionalBoolWrapperFieldNumber = 201; @@ -2544,16 +2670,16 @@ namespace ProtobufTestMessages.Proto3 { hash ^= MapStringForeignMessage.GetHashCode(); hash ^= MapStringNestedEnum.GetHashCode(); hash ^= MapStringForeignEnum.GetHashCode(); - if (oneofFieldCase_ == OneofFieldOneofCase.OneofUint32) hash ^= OneofUint32.GetHashCode(); + if (HasOneofUint32) hash ^= OneofUint32.GetHashCode(); if (oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage) hash ^= OneofNestedMessage.GetHashCode(); - if (oneofFieldCase_ == OneofFieldOneofCase.OneofString) hash ^= OneofString.GetHashCode(); - if (oneofFieldCase_ == OneofFieldOneofCase.OneofBytes) hash ^= OneofBytes.GetHashCode(); - if (oneofFieldCase_ == OneofFieldOneofCase.OneofBool) hash ^= OneofBool.GetHashCode(); - if (oneofFieldCase_ == OneofFieldOneofCase.OneofUint64) hash ^= OneofUint64.GetHashCode(); - if (oneofFieldCase_ == OneofFieldOneofCase.OneofFloat) hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(OneofFloat); - if (oneofFieldCase_ == OneofFieldOneofCase.OneofDouble) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(OneofDouble); - if (oneofFieldCase_ == OneofFieldOneofCase.OneofEnum) hash ^= OneofEnum.GetHashCode(); - if (oneofFieldCase_ == OneofFieldOneofCase.OneofNullValue) hash ^= OneofNullValue.GetHashCode(); + if (HasOneofString) hash ^= OneofString.GetHashCode(); + if (HasOneofBytes) hash ^= OneofBytes.GetHashCode(); + if (HasOneofBool) hash ^= OneofBool.GetHashCode(); + if (HasOneofUint64) hash ^= OneofUint64.GetHashCode(); + if (HasOneofFloat) hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(OneofFloat); + if (HasOneofDouble) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(OneofDouble); + if (HasOneofEnum) hash ^= OneofEnum.GetHashCode(); + if (HasOneofNullValue) hash ^= OneofNullValue.GetHashCode(); if (optionalBoolWrapper_ != null) hash ^= OptionalBoolWrapper.GetHashCode(); if (optionalInt32Wrapper_ != null) hash ^= OptionalInt32Wrapper.GetHashCode(); if (optionalInt64Wrapper_ != null) hash ^= OptionalInt64Wrapper.GetHashCode(); @@ -2783,7 +2909,7 @@ namespace ProtobufTestMessages.Proto3 { unpackedDouble_.WriteTo(output, _repeated_unpackedDouble_codec); unpackedBool_.WriteTo(output, _repeated_unpackedBool_codec); unpackedNestedEnum_.WriteTo(output, _repeated_unpackedNestedEnum_codec); - if (oneofFieldCase_ == OneofFieldOneofCase.OneofUint32) { + if (HasOneofUint32) { output.WriteRawTag(248, 6); output.WriteUInt32(OneofUint32); } @@ -2791,35 +2917,35 @@ namespace ProtobufTestMessages.Proto3 { output.WriteRawTag(130, 7); output.WriteMessage(OneofNestedMessage); } - if (oneofFieldCase_ == OneofFieldOneofCase.OneofString) { + if (HasOneofString) { output.WriteRawTag(138, 7); output.WriteString(OneofString); } - if (oneofFieldCase_ == OneofFieldOneofCase.OneofBytes) { + if (HasOneofBytes) { output.WriteRawTag(146, 7); output.WriteBytes(OneofBytes); } - if (oneofFieldCase_ == OneofFieldOneofCase.OneofBool) { + if (HasOneofBool) { output.WriteRawTag(152, 7); output.WriteBool(OneofBool); } - if (oneofFieldCase_ == OneofFieldOneofCase.OneofUint64) { + if (HasOneofUint64) { output.WriteRawTag(160, 7); output.WriteUInt64(OneofUint64); } - if (oneofFieldCase_ == OneofFieldOneofCase.OneofFloat) { + if (HasOneofFloat) { output.WriteRawTag(173, 7); output.WriteFloat(OneofFloat); } - if (oneofFieldCase_ == OneofFieldOneofCase.OneofDouble) { + if (HasOneofDouble) { output.WriteRawTag(177, 7); output.WriteDouble(OneofDouble); } - if (oneofFieldCase_ == OneofFieldOneofCase.OneofEnum) { + if (HasOneofEnum) { output.WriteRawTag(184, 7); output.WriteEnum((int) OneofEnum); } - if (oneofFieldCase_ == OneofFieldOneofCase.OneofNullValue) { + if (HasOneofNullValue) { output.WriteRawTag(192, 7); output.WriteEnum((int) OneofNullValue); } @@ -3136,7 +3262,7 @@ namespace ProtobufTestMessages.Proto3 { unpackedDouble_.WriteTo(ref output, _repeated_unpackedDouble_codec); unpackedBool_.WriteTo(ref output, _repeated_unpackedBool_codec); unpackedNestedEnum_.WriteTo(ref output, _repeated_unpackedNestedEnum_codec); - if (oneofFieldCase_ == OneofFieldOneofCase.OneofUint32) { + if (HasOneofUint32) { output.WriteRawTag(248, 6); output.WriteUInt32(OneofUint32); } @@ -3144,35 +3270,35 @@ namespace ProtobufTestMessages.Proto3 { output.WriteRawTag(130, 7); output.WriteMessage(OneofNestedMessage); } - if (oneofFieldCase_ == OneofFieldOneofCase.OneofString) { + if (HasOneofString) { output.WriteRawTag(138, 7); output.WriteString(OneofString); } - if (oneofFieldCase_ == OneofFieldOneofCase.OneofBytes) { + if (HasOneofBytes) { output.WriteRawTag(146, 7); output.WriteBytes(OneofBytes); } - if (oneofFieldCase_ == OneofFieldOneofCase.OneofBool) { + if (HasOneofBool) { output.WriteRawTag(152, 7); output.WriteBool(OneofBool); } - if (oneofFieldCase_ == OneofFieldOneofCase.OneofUint64) { + if (HasOneofUint64) { output.WriteRawTag(160, 7); output.WriteUInt64(OneofUint64); } - if (oneofFieldCase_ == OneofFieldOneofCase.OneofFloat) { + if (HasOneofFloat) { output.WriteRawTag(173, 7); output.WriteFloat(OneofFloat); } - if (oneofFieldCase_ == OneofFieldOneofCase.OneofDouble) { + if (HasOneofDouble) { output.WriteRawTag(177, 7); output.WriteDouble(OneofDouble); } - if (oneofFieldCase_ == OneofFieldOneofCase.OneofEnum) { + if (HasOneofEnum) { output.WriteRawTag(184, 7); output.WriteEnum((int) OneofEnum); } - if (oneofFieldCase_ == OneofFieldOneofCase.OneofNullValue) { + if (HasOneofNullValue) { output.WriteRawTag(192, 7); output.WriteEnum((int) OneofNullValue); } @@ -3466,34 +3592,34 @@ namespace ProtobufTestMessages.Proto3 { size += mapStringForeignMessage_.CalculateSize(_map_mapStringForeignMessage_codec); size += mapStringNestedEnum_.CalculateSize(_map_mapStringNestedEnum_codec); size += mapStringForeignEnum_.CalculateSize(_map_mapStringForeignEnum_codec); - if (oneofFieldCase_ == OneofFieldOneofCase.OneofUint32) { + if (HasOneofUint32) { size += 2 + pb::CodedOutputStream.ComputeUInt32Size(OneofUint32); } if (oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage) { size += 2 + pb::CodedOutputStream.ComputeMessageSize(OneofNestedMessage); } - if (oneofFieldCase_ == OneofFieldOneofCase.OneofString) { + if (HasOneofString) { size += 2 + pb::CodedOutputStream.ComputeStringSize(OneofString); } - if (oneofFieldCase_ == OneofFieldOneofCase.OneofBytes) { + if (HasOneofBytes) { size += 2 + pb::CodedOutputStream.ComputeBytesSize(OneofBytes); } - if (oneofFieldCase_ == OneofFieldOneofCase.OneofBool) { + if (HasOneofBool) { size += 2 + 1; } - if (oneofFieldCase_ == OneofFieldOneofCase.OneofUint64) { + if (HasOneofUint64) { size += 2 + pb::CodedOutputStream.ComputeUInt64Size(OneofUint64); } - if (oneofFieldCase_ == OneofFieldOneofCase.OneofFloat) { + if (HasOneofFloat) { size += 2 + 4; } - if (oneofFieldCase_ == OneofFieldOneofCase.OneofDouble) { + if (HasOneofDouble) { size += 2 + 8; } - if (oneofFieldCase_ == OneofFieldOneofCase.OneofEnum) { + if (HasOneofEnum) { size += 2 + pb::CodedOutputStream.ComputeEnumSize((int) OneofEnum); } - if (oneofFieldCase_ == OneofFieldOneofCase.OneofNullValue) { + if (HasOneofNullValue) { size += 2 + pb::CodedOutputStream.ComputeEnumSize((int) OneofNullValue); } if (optionalBoolWrapper_ != null) { diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestCustomOptionsProto3.pb.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestCustomOptionsProto3.pb.cs index 42cac04d75..8b94027371 100644 --- a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestCustomOptionsProto3.pb.cs +++ b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestCustomOptionsProto3.pb.cs @@ -324,12 +324,26 @@ namespace UnitTest.Issues.TestProtos { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public int OneofField { - get { return anOneofCase_ == AnOneofOneofCase.OneofField ? (int) anOneof_ : 0; } + get { return HasOneofField ? (int) anOneof_ : 0; } set { anOneof_ = value; anOneofCase_ = AnOneofOneofCase.OneofField; } } + /// Gets whether the "oneof_field" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasOneofField { + get { return anOneofCase_ == AnOneofOneofCase.OneofField; } + } + /// Clears the value of the oneof if it's currently set to "oneof_field" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearOneofField() { + if (HasOneofField) { + ClearAnOneof(); + } + } private object anOneof_; /// Enum of possible cases for the "AnOneof" oneof. @@ -377,7 +391,7 @@ namespace UnitTest.Issues.TestProtos { public override int GetHashCode() { int hash = 1; if (Field1.Length != 0) hash ^= Field1.GetHashCode(); - if (anOneofCase_ == AnOneofOneofCase.OneofField) hash ^= OneofField.GetHashCode(); + if (HasOneofField) hash ^= OneofField.GetHashCode(); hash ^= (int) anOneofCase_; if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); @@ -401,7 +415,7 @@ namespace UnitTest.Issues.TestProtos { output.WriteRawTag(10); output.WriteString(Field1); } - if (anOneofCase_ == AnOneofOneofCase.OneofField) { + if (HasOneofField) { output.WriteRawTag(16); output.WriteInt32(OneofField); } @@ -419,7 +433,7 @@ namespace UnitTest.Issues.TestProtos { output.WriteRawTag(10); output.WriteString(Field1); } - if (anOneofCase_ == AnOneofOneofCase.OneofField) { + if (HasOneofField) { output.WriteRawTag(16); output.WriteInt32(OneofField); } @@ -436,7 +450,7 @@ namespace UnitTest.Issues.TestProtos { if (Field1.Length != 0) { size += 1 + pb::CodedOutputStream.ComputeStringSize(Field1); } - if (anOneofCase_ == AnOneofOneofCase.OneofField) { + if (HasOneofField) { size += 1 + pb::CodedOutputStream.ComputeInt32Size(OneofField); } if (_unknownFields != null) { diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssues.pb.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssues.pb.cs index b5a517a1e2..82e935e126 100644 --- a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssues.pb.cs +++ b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssues.pb.cs @@ -2015,24 +2015,52 @@ namespace UnitTest.Issues.TestProtos { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public string O1String { - get { return o1Case_ == O1OneofCase.O1String ? (string) o1_ : ""; } + get { return HasO1String ? (string) o1_ : ""; } set { o1_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); o1Case_ = O1OneofCase.O1String; } } + /// Gets whether the "o1_string" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasO1String { + get { return o1Case_ == O1OneofCase.O1String; } + } + /// Clears the value of the oneof if it's currently set to "o1_string" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearO1String() { + if (HasO1String) { + ClearO1(); + } + } /// Field number for the "o1_int32" field. public const int O1Int32FieldNumber = 5; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public int O1Int32 { - get { return o1Case_ == O1OneofCase.O1Int32 ? (int) o1_ : 0; } + get { return HasO1Int32 ? (int) o1_ : 0; } set { o1_ = value; o1Case_ = O1OneofCase.O1Int32; } } + /// Gets whether the "o1_int32" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasO1Int32 { + get { return o1Case_ == O1OneofCase.O1Int32; } + } + /// Clears the value of the oneof if it's currently set to "o1_int32" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearO1Int32() { + if (HasO1Int32) { + ClearO1(); + } + } /// Field number for the "plain_string" field. public const int PlainStringFieldNumber = 1; @@ -2051,24 +2079,52 @@ namespace UnitTest.Issues.TestProtos { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public int O2Int32 { - get { return o2Case_ == O2OneofCase.O2Int32 ? (int) o2_ : 0; } + get { return HasO2Int32 ? (int) o2_ : 0; } set { o2_ = value; o2Case_ = O2OneofCase.O2Int32; } } + /// Gets whether the "o2_int32" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasO2Int32 { + get { return o2Case_ == O2OneofCase.O2Int32; } + } + /// Clears the value of the oneof if it's currently set to "o2_int32" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearO2Int32() { + if (HasO2Int32) { + ClearO2(); + } + } /// Field number for the "o2_string" field. public const int O2StringFieldNumber = 3; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public string O2String { - get { return o2Case_ == O2OneofCase.O2String ? (string) o2_ : ""; } + get { return HasO2String ? (string) o2_ : ""; } set { o2_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); o2Case_ = O2OneofCase.O2String; } } + /// Gets whether the "o2_string" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasO2String { + get { return o2Case_ == O2OneofCase.O2String; } + } + /// Clears the value of the oneof if it's currently set to "o2_string" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearO2String() { + if (HasO2String) { + ClearO2(); + } + } private object o1_; /// Enum of possible cases for the "o1" oneof. @@ -2143,11 +2199,11 @@ namespace UnitTest.Issues.TestProtos { public override int GetHashCode() { int hash = 1; if (PlainInt32 != 0) hash ^= PlainInt32.GetHashCode(); - if (o1Case_ == O1OneofCase.O1String) hash ^= O1String.GetHashCode(); - if (o1Case_ == O1OneofCase.O1Int32) hash ^= O1Int32.GetHashCode(); + if (HasO1String) hash ^= O1String.GetHashCode(); + if (HasO1Int32) hash ^= O1Int32.GetHashCode(); if (PlainString.Length != 0) hash ^= PlainString.GetHashCode(); - if (o2Case_ == O2OneofCase.O2Int32) hash ^= O2Int32.GetHashCode(); - if (o2Case_ == O2OneofCase.O2String) hash ^= O2String.GetHashCode(); + if (HasO2Int32) hash ^= O2Int32.GetHashCode(); + if (HasO2String) hash ^= O2String.GetHashCode(); hash ^= (int) o1Case_; hash ^= (int) o2Case_; if (_unknownFields != null) { @@ -2172,11 +2228,11 @@ namespace UnitTest.Issues.TestProtos { output.WriteRawTag(10); output.WriteString(PlainString); } - if (o1Case_ == O1OneofCase.O1String) { + if (HasO1String) { output.WriteRawTag(18); output.WriteString(O1String); } - if (o2Case_ == O2OneofCase.O2String) { + if (HasO2String) { output.WriteRawTag(26); output.WriteString(O2String); } @@ -2184,11 +2240,11 @@ namespace UnitTest.Issues.TestProtos { output.WriteRawTag(32); output.WriteInt32(PlainInt32); } - if (o1Case_ == O1OneofCase.O1Int32) { + if (HasO1Int32) { output.WriteRawTag(40); output.WriteInt32(O1Int32); } - if (o2Case_ == O2OneofCase.O2Int32) { + if (HasO2Int32) { output.WriteRawTag(48); output.WriteInt32(O2Int32); } @@ -2206,11 +2262,11 @@ namespace UnitTest.Issues.TestProtos { output.WriteRawTag(10); output.WriteString(PlainString); } - if (o1Case_ == O1OneofCase.O1String) { + if (HasO1String) { output.WriteRawTag(18); output.WriteString(O1String); } - if (o2Case_ == O2OneofCase.O2String) { + if (HasO2String) { output.WriteRawTag(26); output.WriteString(O2String); } @@ -2218,11 +2274,11 @@ namespace UnitTest.Issues.TestProtos { output.WriteRawTag(32); output.WriteInt32(PlainInt32); } - if (o1Case_ == O1OneofCase.O1Int32) { + if (HasO1Int32) { output.WriteRawTag(40); output.WriteInt32(O1Int32); } - if (o2Case_ == O2OneofCase.O2Int32) { + if (HasO2Int32) { output.WriteRawTag(48); output.WriteInt32(O2Int32); } @@ -2239,19 +2295,19 @@ namespace UnitTest.Issues.TestProtos { if (PlainInt32 != 0) { size += 1 + pb::CodedOutputStream.ComputeInt32Size(PlainInt32); } - if (o1Case_ == O1OneofCase.O1String) { + if (HasO1String) { size += 1 + pb::CodedOutputStream.ComputeStringSize(O1String); } - if (o1Case_ == O1OneofCase.O1Int32) { + if (HasO1Int32) { size += 1 + pb::CodedOutputStream.ComputeInt32Size(O1Int32); } if (PlainString.Length != 0) { size += 1 + pb::CodedOutputStream.ComputeStringSize(PlainString); } - if (o2Case_ == O2OneofCase.O2Int32) { + if (HasO2Int32) { size += 1 + pb::CodedOutputStream.ComputeInt32Size(O2Int32); } - if (o2Case_ == O2OneofCase.O2String) { + if (HasO2String) { size += 1 + pb::CodedOutputStream.ComputeStringSize(O2String); } if (_unknownFields != null) { @@ -2703,12 +2759,26 @@ namespace UnitTest.Issues.TestProtos { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public string Text { - get { return valueCase_ == ValueOneofCase.Text ? (string) value_ : ""; } + get { return HasText ? (string) value_ : ""; } set { value_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); valueCase_ = ValueOneofCase.Text; } } + /// Gets whether the "text" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasText { + get { return valueCase_ == ValueOneofCase.Text; } + } + /// Clears the value of the oneof if it's currently set to "text" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearText() { + if (HasText) { + ClearValue(); + } + } /// Field number for the "nested" field. public const int NestedFieldNumber = 2; @@ -2768,7 +2838,7 @@ namespace UnitTest.Issues.TestProtos { [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public override int GetHashCode() { int hash = 1; - if (valueCase_ == ValueOneofCase.Text) hash ^= Text.GetHashCode(); + if (HasText) hash ^= Text.GetHashCode(); if (valueCase_ == ValueOneofCase.Nested) hash ^= Nested.GetHashCode(); hash ^= (int) valueCase_; if (_unknownFields != null) { @@ -2789,7 +2859,7 @@ namespace UnitTest.Issues.TestProtos { #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE output.WriteRawMessage(this); #else - if (valueCase_ == ValueOneofCase.Text) { + if (HasText) { output.WriteRawTag(10); output.WriteString(Text); } @@ -2807,7 +2877,7 @@ namespace UnitTest.Issues.TestProtos { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { - if (valueCase_ == ValueOneofCase.Text) { + if (HasText) { output.WriteRawTag(10); output.WriteString(Text); } @@ -2825,7 +2895,7 @@ namespace UnitTest.Issues.TestProtos { [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public int CalculateSize() { int size = 0; - if (valueCase_ == ValueOneofCase.Text) { + if (HasText) { size += 1 + pb::CodedOutputStream.ComputeStringSize(Text); } if (valueCase_ == ValueOneofCase.Nested) { @@ -3209,24 +3279,52 @@ namespace UnitTest.Issues.TestProtos { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public string StringValue { - get { return valueCase_ == ValueOneofCase.StringValue ? (string) value_ : ""; } + get { return HasStringValue ? (string) value_ : ""; } set { value_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); valueCase_ = ValueOneofCase.StringValue; } } + /// Gets whether the "string_value" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasStringValue { + get { return valueCase_ == ValueOneofCase.StringValue; } + } + /// Clears the value of the oneof if it's currently set to "string_value" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearStringValue() { + if (HasStringValue) { + ClearValue(); + } + } /// Field number for the "null_value" field. public const int NullValueFieldNumber = 2; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public global::Google.Protobuf.WellKnownTypes.NullValue NullValue { - get { return valueCase_ == ValueOneofCase.NullValue ? (global::Google.Protobuf.WellKnownTypes.NullValue) value_ : global::Google.Protobuf.WellKnownTypes.NullValue.NullValue; } + get { return HasNullValue ? (global::Google.Protobuf.WellKnownTypes.NullValue) value_ : global::Google.Protobuf.WellKnownTypes.NullValue.NullValue; } set { value_ = value; valueCase_ = ValueOneofCase.NullValue; } } + /// Gets whether the "null_value" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasNullValue { + get { return valueCase_ == ValueOneofCase.NullValue; } + } + /// Clears the value of the oneof if it's currently set to "null_value" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearNullValue() { + if (HasNullValue) { + ClearValue(); + } + } private object value_; /// Enum of possible cases for the "value" oneof. @@ -3274,8 +3372,8 @@ namespace UnitTest.Issues.TestProtos { [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public override int GetHashCode() { int hash = 1; - if (valueCase_ == ValueOneofCase.StringValue) hash ^= StringValue.GetHashCode(); - if (valueCase_ == ValueOneofCase.NullValue) hash ^= NullValue.GetHashCode(); + if (HasStringValue) hash ^= StringValue.GetHashCode(); + if (HasNullValue) hash ^= NullValue.GetHashCode(); hash ^= (int) valueCase_; if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); @@ -3295,11 +3393,11 @@ namespace UnitTest.Issues.TestProtos { #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE output.WriteRawMessage(this); #else - if (valueCase_ == ValueOneofCase.StringValue) { + if (HasStringValue) { output.WriteRawTag(10); output.WriteString(StringValue); } - if (valueCase_ == ValueOneofCase.NullValue) { + if (HasNullValue) { output.WriteRawTag(16); output.WriteEnum((int) NullValue); } @@ -3313,11 +3411,11 @@ namespace UnitTest.Issues.TestProtos { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { - if (valueCase_ == ValueOneofCase.StringValue) { + if (HasStringValue) { output.WriteRawTag(10); output.WriteString(StringValue); } - if (valueCase_ == ValueOneofCase.NullValue) { + if (HasNullValue) { output.WriteRawTag(16); output.WriteEnum((int) NullValue); } @@ -3331,10 +3429,10 @@ namespace UnitTest.Issues.TestProtos { [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public int CalculateSize() { int size = 0; - if (valueCase_ == ValueOneofCase.StringValue) { + if (HasStringValue) { size += 1 + pb::CodedOutputStream.ComputeStringSize(StringValue); } - if (valueCase_ == ValueOneofCase.NullValue) { + if (HasNullValue) { size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) NullValue); } if (_unknownFields != null) { @@ -3661,11 +3759,13 @@ namespace UnitTest.Issues.TestProtos { /// Field number for the "optional_field" field. public const int OptionalFieldFieldNumber = 2; + private readonly static string OptionalFieldDefaultValue = ""; + private string optionalField_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public string OptionalField { - get { return optionalField_ ?? ""; } + get { return optionalField_ ?? OptionalFieldDefaultValue; } set { optionalField_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); } @@ -3897,24 +3997,52 @@ namespace UnitTest.Issues.TestProtos { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public string X { - get { return testCase_ == TestOneofCase.X ? (string) test_ : ""; } + get { return HasX ? (string) test_ : ""; } set { test_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); testCase_ = TestOneofCase.X; } } + /// Gets whether the "x" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasX { + get { return testCase_ == TestOneofCase.X; } + } + /// Clears the value of the oneof if it's currently set to "x" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearX() { + if (HasX) { + ClearTest(); + } + } /// Field number for the "none" field. public const int NoneFieldNumber = 2; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public string None { - get { return testCase_ == TestOneofCase.None_ ? (string) test_ : ""; } + get { return HasNone ? (string) test_ : ""; } set { test_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); testCase_ = TestOneofCase.None_; } } + /// Gets whether the "none" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasNone { + get { return testCase_ == TestOneofCase.None_; } + } + /// Clears the value of the oneof if it's currently set to "none" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearNone() { + if (HasNone) { + ClearTest(); + } + } private object test_; /// Enum of possible cases for the "test" oneof. @@ -3962,8 +4090,8 @@ namespace UnitTest.Issues.TestProtos { [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public override int GetHashCode() { int hash = 1; - if (testCase_ == TestOneofCase.X) hash ^= X.GetHashCode(); - if (testCase_ == TestOneofCase.None_) hash ^= None.GetHashCode(); + if (HasX) hash ^= X.GetHashCode(); + if (HasNone) hash ^= None.GetHashCode(); hash ^= (int) testCase_; if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); @@ -3983,11 +4111,11 @@ namespace UnitTest.Issues.TestProtos { #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE output.WriteRawMessage(this); #else - if (testCase_ == TestOneofCase.X) { + if (HasX) { output.WriteRawTag(10); output.WriteString(X); } - if (testCase_ == TestOneofCase.None_) { + if (HasNone) { output.WriteRawTag(18); output.WriteString(None); } @@ -4001,11 +4129,11 @@ namespace UnitTest.Issues.TestProtos { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { - if (testCase_ == TestOneofCase.X) { + if (HasX) { output.WriteRawTag(10); output.WriteString(X); } - if (testCase_ == TestOneofCase.None_) { + if (HasNone) { output.WriteRawTag(18); output.WriteString(None); } @@ -4019,10 +4147,10 @@ namespace UnitTest.Issues.TestProtos { [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public int CalculateSize() { int size = 0; - if (testCase_ == TestOneofCase.X) { + if (HasX) { size += 1 + pb::CodedOutputStream.ComputeStringSize(X); } - if (testCase_ == TestOneofCase.None_) { + if (HasNone) { size += 1 + pb::CodedOutputStream.ComputeStringSize(None); } if (_unknownFields != null) { @@ -4156,24 +4284,52 @@ namespace UnitTest.Issues.TestProtos { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public string X { - get { return noneCase_ == NoneOneofCase.X ? (string) none_ : ""; } + get { return HasX ? (string) none_ : ""; } set { none_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); noneCase_ = NoneOneofCase.X; } } + /// Gets whether the "x" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasX { + get { return noneCase_ == NoneOneofCase.X; } + } + /// Clears the value of the oneof if it's currently set to "x" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearX() { + if (HasX) { + ClearNone(); + } + } /// Field number for the "y" field. public const int YFieldNumber = 2; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public string Y { - get { return noneCase_ == NoneOneofCase.Y ? (string) none_ : ""; } + get { return HasY ? (string) none_ : ""; } set { none_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); noneCase_ = NoneOneofCase.Y; } } + /// Gets whether the "y" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasY { + get { return noneCase_ == NoneOneofCase.Y; } + } + /// Clears the value of the oneof if it's currently set to "y" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearY() { + if (HasY) { + ClearNone(); + } + } private object none_; /// Enum of possible cases for the "none" oneof. @@ -4221,8 +4377,8 @@ namespace UnitTest.Issues.TestProtos { [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public override int GetHashCode() { int hash = 1; - if (noneCase_ == NoneOneofCase.X) hash ^= X.GetHashCode(); - if (noneCase_ == NoneOneofCase.Y) hash ^= Y.GetHashCode(); + if (HasX) hash ^= X.GetHashCode(); + if (HasY) hash ^= Y.GetHashCode(); hash ^= (int) noneCase_; if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); @@ -4242,11 +4398,11 @@ namespace UnitTest.Issues.TestProtos { #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE output.WriteRawMessage(this); #else - if (noneCase_ == NoneOneofCase.X) { + if (HasX) { output.WriteRawTag(10); output.WriteString(X); } - if (noneCase_ == NoneOneofCase.Y) { + if (HasY) { output.WriteRawTag(18); output.WriteString(Y); } @@ -4260,11 +4416,11 @@ namespace UnitTest.Issues.TestProtos { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { - if (noneCase_ == NoneOneofCase.X) { + if (HasX) { output.WriteRawTag(10); output.WriteString(X); } - if (noneCase_ == NoneOneofCase.Y) { + if (HasY) { output.WriteRawTag(18); output.WriteString(Y); } @@ -4278,10 +4434,10 @@ namespace UnitTest.Issues.TestProtos { [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public int CalculateSize() { int size = 0; - if (noneCase_ == NoneOneofCase.X) { + if (HasX) { size += 1 + pb::CodedOutputStream.ComputeStringSize(X); } - if (noneCase_ == NoneOneofCase.Y) { + if (HasY) { size += 1 + pb::CodedOutputStream.ComputeStringSize(Y); } if (_unknownFields != null) { diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3.pb.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3.pb.cs index 7236b1c8ab..209d37b60a 100644 --- a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3.pb.cs +++ b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3.pb.cs @@ -880,12 +880,26 @@ namespace Google.Protobuf.TestProtos { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public uint OneofUint32 { - get { return oneofFieldCase_ == OneofFieldOneofCase.OneofUint32 ? (uint) oneofField_ : 0; } + get { return HasOneofUint32 ? (uint) oneofField_ : 0; } set { oneofField_ = value; oneofFieldCase_ = OneofFieldOneofCase.OneofUint32; } } + /// Gets whether the "oneof_uint32" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasOneofUint32 { + get { return oneofFieldCase_ == OneofFieldOneofCase.OneofUint32; } + } + /// Clears the value of the oneof if it's currently set to "oneof_uint32" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearOneofUint32() { + if (HasOneofUint32) { + ClearOneofField(); + } + } /// Field number for the "oneof_nested_message" field. public const int OneofNestedMessageFieldNumber = 112; @@ -904,24 +918,52 @@ namespace Google.Protobuf.TestProtos { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public string OneofString { - get { return oneofFieldCase_ == OneofFieldOneofCase.OneofString ? (string) oneofField_ : ""; } + get { return HasOneofString ? (string) oneofField_ : ""; } set { oneofField_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); oneofFieldCase_ = OneofFieldOneofCase.OneofString; } } + /// Gets whether the "oneof_string" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasOneofString { + get { return oneofFieldCase_ == OneofFieldOneofCase.OneofString; } + } + /// Clears the value of the oneof if it's currently set to "oneof_string" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearOneofString() { + if (HasOneofString) { + ClearOneofField(); + } + } /// Field number for the "oneof_bytes" field. public const int OneofBytesFieldNumber = 114; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public pb::ByteString OneofBytes { - get { return oneofFieldCase_ == OneofFieldOneofCase.OneofBytes ? (pb::ByteString) oneofField_ : pb::ByteString.Empty; } + get { return HasOneofBytes ? (pb::ByteString) oneofField_ : pb::ByteString.Empty; } set { oneofField_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); oneofFieldCase_ = OneofFieldOneofCase.OneofBytes; } } + /// Gets whether the "oneof_bytes" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasOneofBytes { + get { return oneofFieldCase_ == OneofFieldOneofCase.OneofBytes; } + } + /// Clears the value of the oneof if it's currently set to "oneof_bytes" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearOneofBytes() { + if (HasOneofBytes) { + ClearOneofField(); + } + } private object oneofField_; /// Enum of possible cases for the "oneof_field" oneof. @@ -1061,10 +1103,10 @@ namespace Google.Protobuf.TestProtos { hash ^= repeatedForeignEnum_.GetHashCode(); hash ^= repeatedImportEnum_.GetHashCode(); hash ^= repeatedPublicImportMessage_.GetHashCode(); - if (oneofFieldCase_ == OneofFieldOneofCase.OneofUint32) hash ^= OneofUint32.GetHashCode(); + if (HasOneofUint32) hash ^= OneofUint32.GetHashCode(); if (oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage) hash ^= OneofNestedMessage.GetHashCode(); - if (oneofFieldCase_ == OneofFieldOneofCase.OneofString) hash ^= OneofString.GetHashCode(); - if (oneofFieldCase_ == OneofFieldOneofCase.OneofBytes) hash ^= OneofBytes.GetHashCode(); + if (HasOneofString) hash ^= OneofString.GetHashCode(); + if (HasOneofBytes) hash ^= OneofBytes.GetHashCode(); hash ^= (int) oneofFieldCase_; if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); @@ -1194,7 +1236,7 @@ namespace Google.Protobuf.TestProtos { repeatedForeignEnum_.WriteTo(output, _repeated_repeatedForeignEnum_codec); repeatedImportEnum_.WriteTo(output, _repeated_repeatedImportEnum_codec); repeatedPublicImportMessage_.WriteTo(output, _repeated_repeatedPublicImportMessage_codec); - if (oneofFieldCase_ == OneofFieldOneofCase.OneofUint32) { + if (HasOneofUint32) { output.WriteRawTag(248, 6); output.WriteUInt32(OneofUint32); } @@ -1202,11 +1244,11 @@ namespace Google.Protobuf.TestProtos { output.WriteRawTag(130, 7); output.WriteMessage(OneofNestedMessage); } - if (oneofFieldCase_ == OneofFieldOneofCase.OneofString) { + if (HasOneofString) { output.WriteRawTag(138, 7); output.WriteString(OneofString); } - if (oneofFieldCase_ == OneofFieldOneofCase.OneofBytes) { + if (HasOneofBytes) { output.WriteRawTag(146, 7); output.WriteBytes(OneofBytes); } @@ -1330,7 +1372,7 @@ namespace Google.Protobuf.TestProtos { repeatedForeignEnum_.WriteTo(ref output, _repeated_repeatedForeignEnum_codec); repeatedImportEnum_.WriteTo(ref output, _repeated_repeatedImportEnum_codec); repeatedPublicImportMessage_.WriteTo(ref output, _repeated_repeatedPublicImportMessage_codec); - if (oneofFieldCase_ == OneofFieldOneofCase.OneofUint32) { + if (HasOneofUint32) { output.WriteRawTag(248, 6); output.WriteUInt32(OneofUint32); } @@ -1338,11 +1380,11 @@ namespace Google.Protobuf.TestProtos { output.WriteRawTag(130, 7); output.WriteMessage(OneofNestedMessage); } - if (oneofFieldCase_ == OneofFieldOneofCase.OneofString) { + if (HasOneofString) { output.WriteRawTag(138, 7); output.WriteString(OneofString); } - if (oneofFieldCase_ == OneofFieldOneofCase.OneofBytes) { + if (HasOneofBytes) { output.WriteRawTag(146, 7); output.WriteBytes(OneofBytes); } @@ -1444,16 +1486,16 @@ namespace Google.Protobuf.TestProtos { size += repeatedForeignEnum_.CalculateSize(_repeated_repeatedForeignEnum_codec); size += repeatedImportEnum_.CalculateSize(_repeated_repeatedImportEnum_codec); size += repeatedPublicImportMessage_.CalculateSize(_repeated_repeatedPublicImportMessage_codec); - if (oneofFieldCase_ == OneofFieldOneofCase.OneofUint32) { + if (HasOneofUint32) { size += 2 + pb::CodedOutputStream.ComputeUInt32Size(OneofUint32); } if (oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage) { size += 2 + pb::CodedOutputStream.ComputeMessageSize(OneofNestedMessage); } - if (oneofFieldCase_ == OneofFieldOneofCase.OneofString) { + if (HasOneofString) { size += 2 + pb::CodedOutputStream.ComputeStringSize(OneofString); } - if (oneofFieldCase_ == OneofFieldOneofCase.OneofBytes) { + if (HasOneofBytes) { size += 2 + pb::CodedOutputStream.ComputeBytesSize(OneofBytes); } if (_unknownFields != null) { @@ -7309,24 +7351,52 @@ namespace Google.Protobuf.TestProtos { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public int FooInt { - get { return fooCase_ == FooOneofCase.FooInt ? (int) foo_ : 0; } + get { return HasFooInt ? (int) foo_ : 0; } set { foo_ = value; fooCase_ = FooOneofCase.FooInt; } } + /// Gets whether the "foo_int" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasFooInt { + get { return fooCase_ == FooOneofCase.FooInt; } + } + /// Clears the value of the oneof if it's currently set to "foo_int" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearFooInt() { + if (HasFooInt) { + ClearFoo(); + } + } /// Field number for the "foo_string" field. public const int FooStringFieldNumber = 2; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public string FooString { - get { return fooCase_ == FooOneofCase.FooString ? (string) foo_ : ""; } + get { return HasFooString ? (string) foo_ : ""; } set { foo_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); fooCase_ = FooOneofCase.FooString; } } + /// Gets whether the "foo_string" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasFooString { + get { return fooCase_ == FooOneofCase.FooString; } + } + /// Clears the value of the oneof if it's currently set to "foo_string" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearFooString() { + if (HasFooString) { + ClearFoo(); + } + } /// Field number for the "foo_message" field. public const int FooMessageFieldNumber = 3; @@ -7388,8 +7458,8 @@ namespace Google.Protobuf.TestProtos { [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public override int GetHashCode() { int hash = 1; - if (fooCase_ == FooOneofCase.FooInt) hash ^= FooInt.GetHashCode(); - if (fooCase_ == FooOneofCase.FooString) hash ^= FooString.GetHashCode(); + if (HasFooInt) hash ^= FooInt.GetHashCode(); + if (HasFooString) hash ^= FooString.GetHashCode(); if (fooCase_ == FooOneofCase.FooMessage) hash ^= FooMessage.GetHashCode(); hash ^= (int) fooCase_; if (_unknownFields != null) { @@ -7410,11 +7480,11 @@ namespace Google.Protobuf.TestProtos { #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE output.WriteRawMessage(this); #else - if (fooCase_ == FooOneofCase.FooInt) { + if (HasFooInt) { output.WriteRawTag(8); output.WriteInt32(FooInt); } - if (fooCase_ == FooOneofCase.FooString) { + if (HasFooString) { output.WriteRawTag(18); output.WriteString(FooString); } @@ -7432,11 +7502,11 @@ namespace Google.Protobuf.TestProtos { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { - if (fooCase_ == FooOneofCase.FooInt) { + if (HasFooInt) { output.WriteRawTag(8); output.WriteInt32(FooInt); } - if (fooCase_ == FooOneofCase.FooString) { + if (HasFooString) { output.WriteRawTag(18); output.WriteString(FooString); } @@ -7454,10 +7524,10 @@ namespace Google.Protobuf.TestProtos { [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public int CalculateSize() { int size = 0; - if (fooCase_ == FooOneofCase.FooInt) { + if (HasFooInt) { size += 1 + pb::CodedOutputStream.ComputeInt32Size(FooInt); } - if (fooCase_ == FooOneofCase.FooString) { + if (HasFooString) { size += 1 + pb::CodedOutputStream.ComputeStringSize(FooString); } if (fooCase_ == FooOneofCase.FooMessage) { diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3Optional.pb.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3Optional.pb.cs index b97d56f8d5..ff9c203faf 100644 --- a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3Optional.pb.cs +++ b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3Optional.pb.cs @@ -148,6 +148,8 @@ namespace ProtobufUnittest { /// Field number for the "optional_int32" field. public const int OptionalInt32FieldNumber = 1; + private readonly static int OptionalInt32DefaultValue = 0; + private int optionalInt32_; /// /// Singular @@ -155,7 +157,7 @@ namespace ProtobufUnittest { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public int OptionalInt32 { - get { if ((_hasBits0 & 1) != 0) { return optionalInt32_; } else { return 0; } } + get { if ((_hasBits0 & 1) != 0) { return optionalInt32_; } else { return OptionalInt32DefaultValue; } } set { _hasBits0 |= 1; optionalInt32_ = value; @@ -176,11 +178,13 @@ namespace ProtobufUnittest { /// Field number for the "optional_int64" field. public const int OptionalInt64FieldNumber = 2; + private readonly static long OptionalInt64DefaultValue = 0L; + private long optionalInt64_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public long OptionalInt64 { - get { if ((_hasBits0 & 2) != 0) { return optionalInt64_; } else { return 0L; } } + get { if ((_hasBits0 & 2) != 0) { return optionalInt64_; } else { return OptionalInt64DefaultValue; } } set { _hasBits0 |= 2; optionalInt64_ = value; @@ -201,11 +205,13 @@ namespace ProtobufUnittest { /// Field number for the "optional_uint32" field. public const int OptionalUint32FieldNumber = 3; + private readonly static uint OptionalUint32DefaultValue = 0; + private uint optionalUint32_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public uint OptionalUint32 { - get { if ((_hasBits0 & 4) != 0) { return optionalUint32_; } else { return 0; } } + get { if ((_hasBits0 & 4) != 0) { return optionalUint32_; } else { return OptionalUint32DefaultValue; } } set { _hasBits0 |= 4; optionalUint32_ = value; @@ -226,11 +232,13 @@ namespace ProtobufUnittest { /// Field number for the "optional_uint64" field. public const int OptionalUint64FieldNumber = 4; + private readonly static ulong OptionalUint64DefaultValue = 0UL; + private ulong optionalUint64_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public ulong OptionalUint64 { - get { if ((_hasBits0 & 8) != 0) { return optionalUint64_; } else { return 0UL; } } + get { if ((_hasBits0 & 8) != 0) { return optionalUint64_; } else { return OptionalUint64DefaultValue; } } set { _hasBits0 |= 8; optionalUint64_ = value; @@ -251,11 +259,13 @@ namespace ProtobufUnittest { /// Field number for the "optional_sint32" field. public const int OptionalSint32FieldNumber = 5; + private readonly static int OptionalSint32DefaultValue = 0; + private int optionalSint32_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public int OptionalSint32 { - get { if ((_hasBits0 & 16) != 0) { return optionalSint32_; } else { return 0; } } + get { if ((_hasBits0 & 16) != 0) { return optionalSint32_; } else { return OptionalSint32DefaultValue; } } set { _hasBits0 |= 16; optionalSint32_ = value; @@ -276,11 +286,13 @@ namespace ProtobufUnittest { /// Field number for the "optional_sint64" field. public const int OptionalSint64FieldNumber = 6; + private readonly static long OptionalSint64DefaultValue = 0L; + private long optionalSint64_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public long OptionalSint64 { - get { if ((_hasBits0 & 32) != 0) { return optionalSint64_; } else { return 0L; } } + get { if ((_hasBits0 & 32) != 0) { return optionalSint64_; } else { return OptionalSint64DefaultValue; } } set { _hasBits0 |= 32; optionalSint64_ = value; @@ -301,11 +313,13 @@ namespace ProtobufUnittest { /// Field number for the "optional_fixed32" field. public const int OptionalFixed32FieldNumber = 7; + private readonly static uint OptionalFixed32DefaultValue = 0; + private uint optionalFixed32_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public uint OptionalFixed32 { - get { if ((_hasBits0 & 64) != 0) { return optionalFixed32_; } else { return 0; } } + get { if ((_hasBits0 & 64) != 0) { return optionalFixed32_; } else { return OptionalFixed32DefaultValue; } } set { _hasBits0 |= 64; optionalFixed32_ = value; @@ -326,11 +340,13 @@ namespace ProtobufUnittest { /// Field number for the "optional_fixed64" field. public const int OptionalFixed64FieldNumber = 8; + private readonly static ulong OptionalFixed64DefaultValue = 0UL; + private ulong optionalFixed64_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public ulong OptionalFixed64 { - get { if ((_hasBits0 & 128) != 0) { return optionalFixed64_; } else { return 0UL; } } + get { if ((_hasBits0 & 128) != 0) { return optionalFixed64_; } else { return OptionalFixed64DefaultValue; } } set { _hasBits0 |= 128; optionalFixed64_ = value; @@ -351,11 +367,13 @@ namespace ProtobufUnittest { /// Field number for the "optional_sfixed32" field. public const int OptionalSfixed32FieldNumber = 9; + private readonly static int OptionalSfixed32DefaultValue = 0; + private int optionalSfixed32_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public int OptionalSfixed32 { - get { if ((_hasBits0 & 256) != 0) { return optionalSfixed32_; } else { return 0; } } + get { if ((_hasBits0 & 256) != 0) { return optionalSfixed32_; } else { return OptionalSfixed32DefaultValue; } } set { _hasBits0 |= 256; optionalSfixed32_ = value; @@ -376,11 +394,13 @@ namespace ProtobufUnittest { /// Field number for the "optional_sfixed64" field. public const int OptionalSfixed64FieldNumber = 10; + private readonly static long OptionalSfixed64DefaultValue = 0L; + private long optionalSfixed64_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public long OptionalSfixed64 { - get { if ((_hasBits0 & 512) != 0) { return optionalSfixed64_; } else { return 0L; } } + get { if ((_hasBits0 & 512) != 0) { return optionalSfixed64_; } else { return OptionalSfixed64DefaultValue; } } set { _hasBits0 |= 512; optionalSfixed64_ = value; @@ -401,11 +421,13 @@ namespace ProtobufUnittest { /// Field number for the "optional_float" field. public const int OptionalFloatFieldNumber = 11; + private readonly static float OptionalFloatDefaultValue = 0F; + private float optionalFloat_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public float OptionalFloat { - get { if ((_hasBits0 & 1024) != 0) { return optionalFloat_; } else { return 0F; } } + get { if ((_hasBits0 & 1024) != 0) { return optionalFloat_; } else { return OptionalFloatDefaultValue; } } set { _hasBits0 |= 1024; optionalFloat_ = value; @@ -426,11 +448,13 @@ namespace ProtobufUnittest { /// Field number for the "optional_double" field. public const int OptionalDoubleFieldNumber = 12; + private readonly static double OptionalDoubleDefaultValue = 0D; + private double optionalDouble_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public double OptionalDouble { - get { if ((_hasBits0 & 2048) != 0) { return optionalDouble_; } else { return 0D; } } + get { if ((_hasBits0 & 2048) != 0) { return optionalDouble_; } else { return OptionalDoubleDefaultValue; } } set { _hasBits0 |= 2048; optionalDouble_ = value; @@ -451,11 +475,13 @@ namespace ProtobufUnittest { /// Field number for the "optional_bool" field. public const int OptionalBoolFieldNumber = 13; + private readonly static bool OptionalBoolDefaultValue = false; + private bool optionalBool_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public bool OptionalBool { - get { if ((_hasBits0 & 4096) != 0) { return optionalBool_; } else { return false; } } + get { if ((_hasBits0 & 4096) != 0) { return optionalBool_; } else { return OptionalBoolDefaultValue; } } set { _hasBits0 |= 4096; optionalBool_ = value; @@ -476,11 +502,13 @@ namespace ProtobufUnittest { /// Field number for the "optional_string" field. public const int OptionalStringFieldNumber = 14; + private readonly static string OptionalStringDefaultValue = ""; + private string optionalString_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public string OptionalString { - get { return optionalString_ ?? ""; } + get { return optionalString_ ?? OptionalStringDefaultValue; } set { optionalString_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); } @@ -500,11 +528,13 @@ namespace ProtobufUnittest { /// Field number for the "optional_bytes" field. public const int OptionalBytesFieldNumber = 15; + private readonly static pb::ByteString OptionalBytesDefaultValue = pb::ByteString.Empty; + private pb::ByteString optionalBytes_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public pb::ByteString OptionalBytes { - get { return optionalBytes_ ?? pb::ByteString.Empty; } + get { return optionalBytes_ ?? OptionalBytesDefaultValue; } set { optionalBytes_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); } @@ -524,11 +554,13 @@ namespace ProtobufUnittest { /// Field number for the "optional_cord" field. public const int OptionalCordFieldNumber = 16; + private readonly static string OptionalCordDefaultValue = ""; + private string optionalCord_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public string OptionalCord { - get { return optionalCord_ ?? ""; } + get { return optionalCord_ ?? OptionalCordDefaultValue; } set { optionalCord_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); } @@ -572,11 +604,13 @@ namespace ProtobufUnittest { /// Field number for the "optional_nested_enum" field. public const int OptionalNestedEnumFieldNumber = 21; + private readonly static global::ProtobufUnittest.TestProto3Optional.Types.NestedEnum OptionalNestedEnumDefaultValue = global::ProtobufUnittest.TestProto3Optional.Types.NestedEnum.Unspecified; + private global::ProtobufUnittest.TestProto3Optional.Types.NestedEnum optionalNestedEnum_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public global::ProtobufUnittest.TestProto3Optional.Types.NestedEnum OptionalNestedEnum { - get { if ((_hasBits0 & 8192) != 0) { return optionalNestedEnum_; } else { return global::ProtobufUnittest.TestProto3Optional.Types.NestedEnum.Unspecified; } } + get { if ((_hasBits0 & 8192) != 0) { return optionalNestedEnum_; } else { return OptionalNestedEnumDefaultValue; } } set { _hasBits0 |= 8192; optionalNestedEnum_ = value; @@ -1315,6 +1349,8 @@ namespace ProtobufUnittest { /// Field number for the "bb" field. public const int BbFieldNumber = 1; + private readonly static int BbDefaultValue = 0; + private int bb_; /// /// The field name "b" fails to compile in proto1 because it conflicts with @@ -1324,7 +1360,7 @@ namespace ProtobufUnittest { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public int Bb { - get { if ((_hasBits0 & 1) != 0) { return bb_; } else { return 0; } } + get { if ((_hasBits0 & 1) != 0) { return bb_; } else { return BbDefaultValue; } } set { _hasBits0 |= 1; bb_ = value; diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Struct.pb.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Struct.pb.cs index b8c99c051c..38a49ac0ec 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/Struct.pb.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/Struct.pb.cs @@ -338,12 +338,26 @@ namespace Google.Protobuf.WellKnownTypes { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public global::Google.Protobuf.WellKnownTypes.NullValue NullValue { - get { return kindCase_ == KindOneofCase.NullValue ? (global::Google.Protobuf.WellKnownTypes.NullValue) kind_ : global::Google.Protobuf.WellKnownTypes.NullValue.NullValue; } + get { return HasNullValue ? (global::Google.Protobuf.WellKnownTypes.NullValue) kind_ : global::Google.Protobuf.WellKnownTypes.NullValue.NullValue; } set { kind_ = value; kindCase_ = KindOneofCase.NullValue; } } + /// Gets whether the "null_value" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasNullValue { + get { return kindCase_ == KindOneofCase.NullValue; } + } + /// Clears the value of the oneof if it's currently set to "null_value" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearNullValue() { + if (HasNullValue) { + ClearKind(); + } + } /// Field number for the "number_value" field. public const int NumberValueFieldNumber = 2; @@ -353,12 +367,26 @@ namespace Google.Protobuf.WellKnownTypes { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public double NumberValue { - get { return kindCase_ == KindOneofCase.NumberValue ? (double) kind_ : 0D; } + get { return HasNumberValue ? (double) kind_ : 0D; } set { kind_ = value; kindCase_ = KindOneofCase.NumberValue; } } + /// Gets whether the "number_value" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasNumberValue { + get { return kindCase_ == KindOneofCase.NumberValue; } + } + /// Clears the value of the oneof if it's currently set to "number_value" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearNumberValue() { + if (HasNumberValue) { + ClearKind(); + } + } /// Field number for the "string_value" field. public const int StringValueFieldNumber = 3; @@ -368,12 +396,26 @@ namespace Google.Protobuf.WellKnownTypes { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public string StringValue { - get { return kindCase_ == KindOneofCase.StringValue ? (string) kind_ : ""; } + get { return HasStringValue ? (string) kind_ : ""; } set { kind_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); kindCase_ = KindOneofCase.StringValue; } } + /// Gets whether the "string_value" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasStringValue { + get { return kindCase_ == KindOneofCase.StringValue; } + } + /// Clears the value of the oneof if it's currently set to "string_value" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearStringValue() { + if (HasStringValue) { + ClearKind(); + } + } /// Field number for the "bool_value" field. public const int BoolValueFieldNumber = 4; @@ -383,12 +425,26 @@ namespace Google.Protobuf.WellKnownTypes { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public bool BoolValue { - get { return kindCase_ == KindOneofCase.BoolValue ? (bool) kind_ : false; } + get { return HasBoolValue ? (bool) kind_ : false; } set { kind_ = value; kindCase_ = KindOneofCase.BoolValue; } } + /// Gets whether the "bool_value" field is set + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool HasBoolValue { + get { return kindCase_ == KindOneofCase.BoolValue; } + } + /// Clears the value of the oneof if it's currently set to "bool_value" + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void ClearBoolValue() { + if (HasBoolValue) { + ClearKind(); + } + } /// Field number for the "struct_value" field. public const int StructValueFieldNumber = 5; @@ -474,10 +530,10 @@ namespace Google.Protobuf.WellKnownTypes { [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public override int GetHashCode() { int hash = 1; - if (kindCase_ == KindOneofCase.NullValue) hash ^= NullValue.GetHashCode(); - if (kindCase_ == KindOneofCase.NumberValue) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(NumberValue); - if (kindCase_ == KindOneofCase.StringValue) hash ^= StringValue.GetHashCode(); - if (kindCase_ == KindOneofCase.BoolValue) hash ^= BoolValue.GetHashCode(); + if (HasNullValue) hash ^= NullValue.GetHashCode(); + if (HasNumberValue) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(NumberValue); + if (HasStringValue) hash ^= StringValue.GetHashCode(); + if (HasBoolValue) hash ^= BoolValue.GetHashCode(); if (kindCase_ == KindOneofCase.StructValue) hash ^= StructValue.GetHashCode(); if (kindCase_ == KindOneofCase.ListValue) hash ^= ListValue.GetHashCode(); hash ^= (int) kindCase_; @@ -499,19 +555,19 @@ namespace Google.Protobuf.WellKnownTypes { #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE output.WriteRawMessage(this); #else - if (kindCase_ == KindOneofCase.NullValue) { + if (HasNullValue) { output.WriteRawTag(8); output.WriteEnum((int) NullValue); } - if (kindCase_ == KindOneofCase.NumberValue) { + if (HasNumberValue) { output.WriteRawTag(17); output.WriteDouble(NumberValue); } - if (kindCase_ == KindOneofCase.StringValue) { + if (HasStringValue) { output.WriteRawTag(26); output.WriteString(StringValue); } - if (kindCase_ == KindOneofCase.BoolValue) { + if (HasBoolValue) { output.WriteRawTag(32); output.WriteBool(BoolValue); } @@ -533,19 +589,19 @@ namespace Google.Protobuf.WellKnownTypes { [global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { - if (kindCase_ == KindOneofCase.NullValue) { + if (HasNullValue) { output.WriteRawTag(8); output.WriteEnum((int) NullValue); } - if (kindCase_ == KindOneofCase.NumberValue) { + if (HasNumberValue) { output.WriteRawTag(17); output.WriteDouble(NumberValue); } - if (kindCase_ == KindOneofCase.StringValue) { + if (HasStringValue) { output.WriteRawTag(26); output.WriteString(StringValue); } - if (kindCase_ == KindOneofCase.BoolValue) { + if (HasBoolValue) { output.WriteRawTag(32); output.WriteBool(BoolValue); } @@ -567,16 +623,16 @@ namespace Google.Protobuf.WellKnownTypes { [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] public int CalculateSize() { int size = 0; - if (kindCase_ == KindOneofCase.NullValue) { + if (HasNullValue) { size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) NullValue); } - if (kindCase_ == KindOneofCase.NumberValue) { + if (HasNumberValue) { size += 1 + 8; } - if (kindCase_ == KindOneofCase.StringValue) { + if (HasStringValue) { size += 1 + pb::CodedOutputStream.ComputeStringSize(StringValue); } - if (kindCase_ == KindOneofCase.BoolValue) { + if (HasBoolValue) { size += 1 + 1; } if (kindCase_ == KindOneofCase.StructValue) {