Sync from Piper @309848308

PROTOBUF_SYNC_PIPER
This commit is contained in:
Joshua Haberman 2020-05-04 17:10:15 -07:00
commit c05b55880f
39 changed files with 3640 additions and 3778 deletions

View File

@ -85,15 +85,15 @@ csharp_EXTRA_DIST= \
csharp/src/AddressBook/ListPeople.cs \
csharp/src/AddressBook/Program.cs \
csharp/src/AddressBook/SampleUsage.cs \
csharp/src/Google.Protobuf.Benchmarks/BenchmarkDatasetConfig.cs \
csharp/src/Google.Protobuf.Benchmarks/BenchmarkMessage1Proto3.cs \
csharp/src/Google.Protobuf.Benchmarks/Benchmarks.cs \
csharp/src/Google.Protobuf.Benchmarks/Google.Protobuf.Benchmarks.csproj \
csharp/src/Google.Protobuf.Benchmarks/GoogleMessageBenchmark.cs \
csharp/src/Google.Protobuf.Benchmarks/ParseRawPrimitivesBenchmark.cs \
csharp/src/Google.Protobuf.Benchmarks/ParseMessagesBenchmark.cs \
csharp/src/Google.Protobuf.Benchmarks/Program.cs \
csharp/src/Google.Protobuf.Benchmarks/SerializationBenchmark.cs \
csharp/src/Google.Protobuf.Benchmarks/SerializationConfig.cs \
csharp/src/Google.Protobuf.Benchmarks/wrapper_benchmark_messages.proto \
csharp/src/Google.Protobuf.Benchmarks/WrapperBenchmark.cs \
csharp/src/Google.Protobuf.Benchmarks/WrapperBenchmarkMessages.cs \
csharp/src/Google.Protobuf.Conformance/Conformance.cs \
csharp/src/Google.Protobuf.Conformance/Google.Protobuf.Conformance.csproj \
@ -122,6 +122,7 @@ csharp_EXTRA_DIST= \
csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs \
csharp/src/Google.Protobuf.Test/JsonParserTest.cs \
csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs \
csharp/src/Google.Protobuf.Test/Proto3OptionalTest.cs \
csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs \
csharp/src/Google.Protobuf.Test/Reflection/DescriptorDeclarationTest.cs \
csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs \
@ -148,6 +149,7 @@ csharp_EXTRA_DIST= \
csharp/src/Google.Protobuf.Test.TestProtos/UnittestImport.cs \
csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssues.cs \
csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3.cs \
csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3Optional.cs \
csharp/src/Google.Protobuf.Test.TestProtos/UnittestWellKnownTypes.cs \
csharp/src/Google.Protobuf.Test.TestProtos/Unittest.cs \
csharp/src/Google.Protobuf.Test/WellKnownTypes/AnyTest.cs \

View File

@ -290,13 +290,13 @@ namespace ProtobufTestMessages.Proto2 {
optionalBool_ = other.optionalBool_;
optionalString_ = other.optionalString_;
optionalBytes_ = other.optionalBytes_;
optionalNestedMessage_ = other.HasOptionalNestedMessage ? other.optionalNestedMessage_.Clone() : null;
optionalForeignMessage_ = other.HasOptionalForeignMessage ? other.optionalForeignMessage_.Clone() : null;
optionalNestedMessage_ = other.optionalNestedMessage_ != null ? other.optionalNestedMessage_.Clone() : null;
optionalForeignMessage_ = other.optionalForeignMessage_ != null ? other.optionalForeignMessage_.Clone() : null;
optionalNestedEnum_ = other.optionalNestedEnum_;
optionalForeignEnum_ = other.optionalForeignEnum_;
optionalStringPiece_ = other.optionalStringPiece_;
optionalCord_ = other.optionalCord_;
recursiveMessage_ = other.HasRecursiveMessage ? other.recursiveMessage_.Clone() : null;
recursiveMessage_ = other.recursiveMessage_ != null ? other.recursiveMessage_.Clone() : null;
repeatedInt32_ = other.repeatedInt32_.Clone();
repeatedInt64_ = other.repeatedInt64_.Clone();
repeatedUint32_ = other.repeatedUint32_.Clone();
@ -794,16 +794,6 @@ namespace ProtobufTestMessages.Proto2 {
optionalNestedMessage_ = value;
}
}
/// <summary>Gets whether the optional_nested_message field is set</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool HasOptionalNestedMessage {
get { return optionalNestedMessage_ != null; }
}
/// <summary>Clears the value of the optional_nested_message field</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void ClearOptionalNestedMessage() {
optionalNestedMessage_ = null;
}
/// <summary>Field number for the "optional_foreign_message" field.</summary>
public const int OptionalForeignMessageFieldNumber = 19;
@ -815,16 +805,6 @@ namespace ProtobufTestMessages.Proto2 {
optionalForeignMessage_ = value;
}
}
/// <summary>Gets whether the optional_foreign_message field is set</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool HasOptionalForeignMessage {
get { return optionalForeignMessage_ != null; }
}
/// <summary>Clears the value of the optional_foreign_message field</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void ClearOptionalForeignMessage() {
optionalForeignMessage_ = null;
}
/// <summary>Field number for the "optional_nested_enum" field.</summary>
public const int OptionalNestedEnumFieldNumber = 21;
@ -930,16 +910,6 @@ namespace ProtobufTestMessages.Proto2 {
recursiveMessage_ = value;
}
}
/// <summary>Gets whether the recursive_message field is set</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool HasRecursiveMessage {
get { return recursiveMessage_ != null; }
}
/// <summary>Clears the value of the recursive_message field</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void ClearRecursiveMessage() {
recursiveMessage_ = null;
}
/// <summary>Field number for the "repeated_int32" field.</summary>
public const int RepeatedInt32FieldNumber = 31;
@ -1660,24 +1630,12 @@ namespace ProtobufTestMessages.Proto2 {
public const int OneofNestedMessageFieldNumber = 112;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public global::ProtobufTestMessages.Proto2.TestAllTypesProto2.Types.NestedMessage OneofNestedMessage {
get { return HasOneofNestedMessage ? (global::ProtobufTestMessages.Proto2.TestAllTypesProto2.Types.NestedMessage) oneofField_ : null; }
get { return oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage ? (global::ProtobufTestMessages.Proto2.TestAllTypesProto2.Types.NestedMessage) oneofField_ : null; }
set {
oneofField_ = value;
oneofFieldCase_ = value == null ? OneofFieldOneofCase.None : OneofFieldOneofCase.OneofNestedMessage;
}
}
/// <summary>Gets whether the "oneof_nested_message" field is set</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool HasOneofNestedMessage {
get { return oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage; }
}
/// <summary> Clears the value of the oneof if it's currently set to "oneof_nested_message" </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void ClearOneofNestedMessage() {
if (HasOneofNestedMessage) {
ClearOneofField();
}
}
/// <summary>Field number for the "oneof_string" field.</summary>
public const int OneofStringFieldNumber = 113;
@ -2479,13 +2437,13 @@ namespace ProtobufTestMessages.Proto2 {
if (HasOptionalBool) hash ^= OptionalBool.GetHashCode();
if (HasOptionalString) hash ^= OptionalString.GetHashCode();
if (HasOptionalBytes) hash ^= OptionalBytes.GetHashCode();
if (HasOptionalNestedMessage) hash ^= OptionalNestedMessage.GetHashCode();
if (HasOptionalForeignMessage) hash ^= OptionalForeignMessage.GetHashCode();
if (optionalNestedMessage_ != null) hash ^= OptionalNestedMessage.GetHashCode();
if (optionalForeignMessage_ != null) hash ^= OptionalForeignMessage.GetHashCode();
if (HasOptionalNestedEnum) hash ^= OptionalNestedEnum.GetHashCode();
if (HasOptionalForeignEnum) hash ^= OptionalForeignEnum.GetHashCode();
if (HasOptionalStringPiece) hash ^= OptionalStringPiece.GetHashCode();
if (HasOptionalCord) hash ^= OptionalCord.GetHashCode();
if (HasRecursiveMessage) hash ^= RecursiveMessage.GetHashCode();
if (recursiveMessage_ != null) hash ^= RecursiveMessage.GetHashCode();
hash ^= repeatedInt32_.GetHashCode();
hash ^= repeatedInt64_.GetHashCode();
hash ^= repeatedUint32_.GetHashCode();
@ -2555,7 +2513,7 @@ namespace ProtobufTestMessages.Proto2 {
hash ^= MapStringNestedEnum.GetHashCode();
hash ^= MapStringForeignEnum.GetHashCode();
if (HasOneofUint32) hash ^= OneofUint32.GetHashCode();
if (HasOneofNestedMessage) hash ^= OneofNestedMessage.GetHashCode();
if (oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage) hash ^= OneofNestedMessage.GetHashCode();
if (HasOneofString) hash ^= OneofString.GetHashCode();
if (HasOneofBytes) hash ^= OneofBytes.GetHashCode();
if (HasOneofBool) hash ^= OneofBool.GetHashCode();
@ -2659,11 +2617,11 @@ namespace ProtobufTestMessages.Proto2 {
output.WriteRawTag(122);
output.WriteBytes(OptionalBytes);
}
if (HasOptionalNestedMessage) {
if (optionalNestedMessage_ != null) {
output.WriteRawTag(146, 1);
output.WriteMessage(OptionalNestedMessage);
}
if (HasOptionalForeignMessage) {
if (optionalForeignMessage_ != null) {
output.WriteRawTag(154, 1);
output.WriteMessage(OptionalForeignMessage);
}
@ -2683,7 +2641,7 @@ namespace ProtobufTestMessages.Proto2 {
output.WriteRawTag(202, 1);
output.WriteString(OptionalCord);
}
if (HasRecursiveMessage) {
if (recursiveMessage_ != null) {
output.WriteRawTag(218, 1);
output.WriteMessage(RecursiveMessage);
}
@ -2759,7 +2717,7 @@ namespace ProtobufTestMessages.Proto2 {
output.WriteRawTag(248, 6);
output.WriteUInt32(OneofUint32);
}
if (HasOneofNestedMessage) {
if (oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage) {
output.WriteRawTag(130, 7);
output.WriteMessage(OneofNestedMessage);
}
@ -2924,10 +2882,10 @@ namespace ProtobufTestMessages.Proto2 {
if (HasOptionalBytes) {
size += 1 + pb::CodedOutputStream.ComputeBytesSize(OptionalBytes);
}
if (HasOptionalNestedMessage) {
if (optionalNestedMessage_ != null) {
size += 2 + pb::CodedOutputStream.ComputeMessageSize(OptionalNestedMessage);
}
if (HasOptionalForeignMessage) {
if (optionalForeignMessage_ != null) {
size += 2 + pb::CodedOutputStream.ComputeMessageSize(OptionalForeignMessage);
}
if (HasOptionalNestedEnum) {
@ -2942,7 +2900,7 @@ namespace ProtobufTestMessages.Proto2 {
if (HasOptionalCord) {
size += 2 + pb::CodedOutputStream.ComputeStringSize(OptionalCord);
}
if (HasRecursiveMessage) {
if (recursiveMessage_ != null) {
size += 2 + pb::CodedOutputStream.ComputeMessageSize(RecursiveMessage);
}
size += repeatedInt32_.CalculateSize(_repeated_repeatedInt32_codec);
@ -3016,7 +2974,7 @@ namespace ProtobufTestMessages.Proto2 {
if (HasOneofUint32) {
size += 2 + pb::CodedOutputStream.ComputeUInt32Size(OneofUint32);
}
if (HasOneofNestedMessage) {
if (oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage) {
size += 2 + pb::CodedOutputStream.ComputeMessageSize(OneofNestedMessage);
}
if (HasOneofString) {
@ -3156,14 +3114,14 @@ namespace ProtobufTestMessages.Proto2 {
if (other.HasOptionalBytes) {
OptionalBytes = other.OptionalBytes;
}
if (other.HasOptionalNestedMessage) {
if (!HasOptionalNestedMessage) {
if (other.optionalNestedMessage_ != null) {
if (optionalNestedMessage_ == null) {
OptionalNestedMessage = new global::ProtobufTestMessages.Proto2.TestAllTypesProto2.Types.NestedMessage();
}
OptionalNestedMessage.MergeFrom(other.OptionalNestedMessage);
}
if (other.HasOptionalForeignMessage) {
if (!HasOptionalForeignMessage) {
if (other.optionalForeignMessage_ != null) {
if (optionalForeignMessage_ == null) {
OptionalForeignMessage = new global::ProtobufTestMessages.Proto2.ForeignMessageProto2();
}
OptionalForeignMessage.MergeFrom(other.OptionalForeignMessage);
@ -3180,8 +3138,8 @@ namespace ProtobufTestMessages.Proto2 {
if (other.HasOptionalCord) {
OptionalCord = other.OptionalCord;
}
if (other.HasRecursiveMessage) {
if (!HasRecursiveMessage) {
if (other.recursiveMessage_ != null) {
if (recursiveMessage_ == null) {
RecursiveMessage = new global::ProtobufTestMessages.Proto2.TestAllTypesProto2();
}
RecursiveMessage.MergeFrom(other.RecursiveMessage);
@ -3422,14 +3380,14 @@ namespace ProtobufTestMessages.Proto2 {
break;
}
case 146: {
if (!HasOptionalNestedMessage) {
if (optionalNestedMessage_ == null) {
OptionalNestedMessage = new global::ProtobufTestMessages.Proto2.TestAllTypesProto2.Types.NestedMessage();
}
input.ReadMessage(OptionalNestedMessage);
break;
}
case 154: {
if (!HasOptionalForeignMessage) {
if (optionalForeignMessage_ == null) {
OptionalForeignMessage = new global::ProtobufTestMessages.Proto2.ForeignMessageProto2();
}
input.ReadMessage(OptionalForeignMessage);
@ -3452,7 +3410,7 @@ namespace ProtobufTestMessages.Proto2 {
break;
}
case 218: {
if (!HasRecursiveMessage) {
if (recursiveMessage_ == null) {
RecursiveMessage = new global::ProtobufTestMessages.Proto2.TestAllTypesProto2();
}
input.ReadMessage(RecursiveMessage);
@ -3779,7 +3737,7 @@ namespace ProtobufTestMessages.Proto2 {
}
case 898: {
global::ProtobufTestMessages.Proto2.TestAllTypesProto2.Types.NestedMessage subBuilder = new global::ProtobufTestMessages.Proto2.TestAllTypesProto2.Types.NestedMessage();
if (HasOneofNestedMessage) {
if (oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage) {
subBuilder.MergeFrom(OneofNestedMessage);
}
input.ReadMessage(subBuilder);
@ -3962,7 +3920,7 @@ namespace ProtobufTestMessages.Proto2 {
public NestedMessage(NestedMessage other) : this() {
_hasBits0 = other._hasBits0;
a_ = other.a_;
corecursive_ = other.HasCorecursive ? other.corecursive_.Clone() : null;
corecursive_ = other.corecursive_ != null ? other.corecursive_.Clone() : null;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
@ -4005,16 +3963,6 @@ namespace ProtobufTestMessages.Proto2 {
corecursive_ = value;
}
}
/// <summary>Gets whether the corecursive field is set</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool HasCorecursive {
get { return corecursive_ != null; }
}
/// <summary>Clears the value of the corecursive field</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void ClearCorecursive() {
corecursive_ = null;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override bool Equals(object other) {
@ -4038,7 +3986,7 @@ namespace ProtobufTestMessages.Proto2 {
public override int GetHashCode() {
int hash = 1;
if (HasA) hash ^= A.GetHashCode();
if (HasCorecursive) hash ^= Corecursive.GetHashCode();
if (corecursive_ != null) hash ^= Corecursive.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
@ -4056,7 +4004,7 @@ namespace ProtobufTestMessages.Proto2 {
output.WriteRawTag(8);
output.WriteInt32(A);
}
if (HasCorecursive) {
if (corecursive_ != null) {
output.WriteRawTag(18);
output.WriteMessage(Corecursive);
}
@ -4071,7 +4019,7 @@ namespace ProtobufTestMessages.Proto2 {
if (HasA) {
size += 1 + pb::CodedOutputStream.ComputeInt32Size(A);
}
if (HasCorecursive) {
if (corecursive_ != null) {
size += 1 + pb::CodedOutputStream.ComputeMessageSize(Corecursive);
}
if (_unknownFields != null) {
@ -4088,8 +4036,8 @@ namespace ProtobufTestMessages.Proto2 {
if (other.HasA) {
A = other.A;
}
if (other.HasCorecursive) {
if (!HasCorecursive) {
if (other.corecursive_ != null) {
if (corecursive_ == null) {
Corecursive = new global::ProtobufTestMessages.Proto2.TestAllTypesProto2();
}
Corecursive.MergeFrom(other.Corecursive);
@ -4110,7 +4058,7 @@ namespace ProtobufTestMessages.Proto2 {
break;
}
case 18: {
if (!HasCorecursive) {
if (corecursive_ == null) {
Corecursive = new global::ProtobufTestMessages.Proto2.TestAllTypesProto2();
}
input.ReadMessage(Corecursive);
@ -4937,7 +4885,7 @@ namespace ProtobufTestMessages.Proto2 {
_hasBits0 = other._hasBits0;
optionalInt32_ = other.optionalInt32_;
optionalString_ = other.optionalString_;
nestedMessage_ = other.HasNestedMessage ? other.nestedMessage_.Clone() : null;
nestedMessage_ = other.nestedMessage_ != null ? other.nestedMessage_.Clone() : null;
optionalGroup_ = other.HasOptionalGroup ? other.optionalGroup_.Clone() : null;
optionalBool_ = other.optionalBool_;
repeatedInt32_ = other.repeatedInt32_.Clone();
@ -5006,16 +4954,6 @@ namespace ProtobufTestMessages.Proto2 {
nestedMessage_ = value;
}
}
/// <summary>Gets whether the nested_message field is set</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool HasNestedMessage {
get { return nestedMessage_ != null; }
}
/// <summary>Clears the value of the nested_message field</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void ClearNestedMessage() {
nestedMessage_ = null;
}
/// <summary>Field number for the "optionalgroup" field.</summary>
public const int OptionalGroupFieldNumber = 1004;
@ -5099,7 +5037,7 @@ namespace ProtobufTestMessages.Proto2 {
int hash = 1;
if (HasOptionalInt32) hash ^= OptionalInt32.GetHashCode();
if (HasOptionalString) hash ^= OptionalString.GetHashCode();
if (HasNestedMessage) hash ^= NestedMessage.GetHashCode();
if (nestedMessage_ != null) hash ^= NestedMessage.GetHashCode();
if (HasOptionalGroup) hash ^= OptionalGroup.GetHashCode();
if (HasOptionalBool) hash ^= OptionalBool.GetHashCode();
hash ^= repeatedInt32_.GetHashCode();
@ -5124,7 +5062,7 @@ namespace ProtobufTestMessages.Proto2 {
output.WriteRawTag(210, 62);
output.WriteString(OptionalString);
}
if (HasNestedMessage) {
if (nestedMessage_ != null) {
output.WriteRawTag(218, 62);
output.WriteMessage(NestedMessage);
}
@ -5152,7 +5090,7 @@ namespace ProtobufTestMessages.Proto2 {
if (HasOptionalString) {
size += 2 + pb::CodedOutputStream.ComputeStringSize(OptionalString);
}
if (HasNestedMessage) {
if (nestedMessage_ != null) {
size += 2 + pb::CodedOutputStream.ComputeMessageSize(NestedMessage);
}
if (HasOptionalGroup) {
@ -5179,8 +5117,8 @@ namespace ProtobufTestMessages.Proto2 {
if (other.HasOptionalString) {
OptionalString = other.OptionalString;
}
if (other.HasNestedMessage) {
if (!HasNestedMessage) {
if (other.nestedMessage_ != null) {
if (nestedMessage_ == null) {
NestedMessage = new global::ProtobufTestMessages.Proto2.ForeignMessageProto2();
}
NestedMessage.MergeFrom(other.NestedMessage);
@ -5215,7 +5153,7 @@ namespace ProtobufTestMessages.Proto2 {
break;
}
case 8026: {
if (!HasNestedMessage) {
if (nestedMessage_ == null) {
NestedMessage = new global::ProtobufTestMessages.Proto2.ForeignMessageProto2();
}
input.ReadMessage(NestedMessage);

File diff suppressed because it is too large Load Diff

View File

@ -352,8 +352,8 @@ namespace Google.Protobuf.Reflection {
enumType_ = other.enumType_.Clone();
service_ = other.service_.Clone();
extension_ = other.extension_.Clone();
options_ = other.HasOptions ? other.options_.Clone() : null;
sourceCodeInfo_ = other.HasSourceCodeInfo ? other.sourceCodeInfo_.Clone() : null;
options_ = other.options_ != null ? other.options_.Clone() : null;
sourceCodeInfo_ = other.sourceCodeInfo_ != null ? other.sourceCodeInfo_.Clone() : null;
syntax_ = other.syntax_;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
@ -508,16 +508,6 @@ namespace Google.Protobuf.Reflection {
options_ = value;
}
}
/// <summary>Gets whether the options field is set</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool HasOptions {
get { return options_ != null; }
}
/// <summary>Clears the value of the options field</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void ClearOptions() {
options_ = null;
}
/// <summary>Field number for the "source_code_info" field.</summary>
public const int SourceCodeInfoFieldNumber = 9;
@ -535,16 +525,6 @@ namespace Google.Protobuf.Reflection {
sourceCodeInfo_ = value;
}
}
/// <summary>Gets whether the source_code_info field is set</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool HasSourceCodeInfo {
get { return sourceCodeInfo_ != null; }
}
/// <summary>Clears the value of the source_code_info field</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void ClearSourceCodeInfo() {
sourceCodeInfo_ = null;
}
/// <summary>Field number for the "syntax" field.</summary>
public const int SyntaxFieldNumber = 12;
@ -613,8 +593,8 @@ namespace Google.Protobuf.Reflection {
hash ^= enumType_.GetHashCode();
hash ^= service_.GetHashCode();
hash ^= extension_.GetHashCode();
if (HasOptions) hash ^= Options.GetHashCode();
if (HasSourceCodeInfo) hash ^= SourceCodeInfo.GetHashCode();
if (options_ != null) hash ^= Options.GetHashCode();
if (sourceCodeInfo_ != null) hash ^= SourceCodeInfo.GetHashCode();
if (HasSyntax) hash ^= Syntax.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
@ -642,11 +622,11 @@ namespace Google.Protobuf.Reflection {
enumType_.WriteTo(output, _repeated_enumType_codec);
service_.WriteTo(output, _repeated_service_codec);
extension_.WriteTo(output, _repeated_extension_codec);
if (HasOptions) {
if (options_ != null) {
output.WriteRawTag(66);
output.WriteMessage(Options);
}
if (HasSourceCodeInfo) {
if (sourceCodeInfo_ != null) {
output.WriteRawTag(74);
output.WriteMessage(SourceCodeInfo);
}
@ -677,10 +657,10 @@ namespace Google.Protobuf.Reflection {
size += enumType_.CalculateSize(_repeated_enumType_codec);
size += service_.CalculateSize(_repeated_service_codec);
size += extension_.CalculateSize(_repeated_extension_codec);
if (HasOptions) {
if (options_ != null) {
size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options);
}
if (HasSourceCodeInfo) {
if (sourceCodeInfo_ != null) {
size += 1 + pb::CodedOutputStream.ComputeMessageSize(SourceCodeInfo);
}
if (HasSyntax) {
@ -710,14 +690,14 @@ namespace Google.Protobuf.Reflection {
enumType_.Add(other.enumType_);
service_.Add(other.service_);
extension_.Add(other.extension_);
if (other.HasOptions) {
if (!HasOptions) {
if (other.options_ != null) {
if (options_ == null) {
Options = new global::Google.Protobuf.Reflection.FileOptions();
}
Options.MergeFrom(other.Options);
}
if (other.HasSourceCodeInfo) {
if (!HasSourceCodeInfo) {
if (other.sourceCodeInfo_ != null) {
if (sourceCodeInfo_ == null) {
SourceCodeInfo = new global::Google.Protobuf.Reflection.SourceCodeInfo();
}
SourceCodeInfo.MergeFrom(other.SourceCodeInfo);
@ -765,14 +745,14 @@ namespace Google.Protobuf.Reflection {
break;
}
case 66: {
if (!HasOptions) {
if (options_ == null) {
Options = new global::Google.Protobuf.Reflection.FileOptions();
}
input.ReadMessage(Options);
break;
}
case 74: {
if (!HasSourceCodeInfo) {
if (sourceCodeInfo_ == null) {
SourceCodeInfo = new global::Google.Protobuf.Reflection.SourceCodeInfo();
}
input.ReadMessage(SourceCodeInfo);
@ -833,7 +813,7 @@ namespace Google.Protobuf.Reflection {
enumType_ = other.enumType_.Clone();
extensionRange_ = other.extensionRange_.Clone();
oneofDecl_ = other.oneofDecl_.Clone();
options_ = other.HasOptions ? other.options_.Clone() : null;
options_ = other.options_ != null ? other.options_.Clone() : null;
reservedRange_ = other.reservedRange_.Clone();
reservedName_ = other.reservedName_.Clone();
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
@ -937,16 +917,6 @@ namespace Google.Protobuf.Reflection {
options_ = value;
}
}
/// <summary>Gets whether the options field is set</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool HasOptions {
get { return options_ != null; }
}
/// <summary>Clears the value of the options field</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void ClearOptions() {
options_ = null;
}
/// <summary>Field number for the "reserved_range" field.</summary>
public const int ReservedRangeFieldNumber = 9;
@ -1008,7 +978,7 @@ namespace Google.Protobuf.Reflection {
hash ^= enumType_.GetHashCode();
hash ^= extensionRange_.GetHashCode();
hash ^= oneofDecl_.GetHashCode();
if (HasOptions) hash ^= Options.GetHashCode();
if (options_ != null) hash ^= Options.GetHashCode();
hash ^= reservedRange_.GetHashCode();
hash ^= reservedName_.GetHashCode();
if (_unknownFields != null) {
@ -1033,7 +1003,7 @@ namespace Google.Protobuf.Reflection {
enumType_.WriteTo(output, _repeated_enumType_codec);
extensionRange_.WriteTo(output, _repeated_extensionRange_codec);
extension_.WriteTo(output, _repeated_extension_codec);
if (HasOptions) {
if (options_ != null) {
output.WriteRawTag(58);
output.WriteMessage(Options);
}
@ -1057,7 +1027,7 @@ namespace Google.Protobuf.Reflection {
size += enumType_.CalculateSize(_repeated_enumType_codec);
size += extensionRange_.CalculateSize(_repeated_extensionRange_codec);
size += oneofDecl_.CalculateSize(_repeated_oneofDecl_codec);
if (HasOptions) {
if (options_ != null) {
size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options);
}
size += reservedRange_.CalculateSize(_repeated_reservedRange_codec);
@ -1082,8 +1052,8 @@ namespace Google.Protobuf.Reflection {
enumType_.Add(other.enumType_);
extensionRange_.Add(other.extensionRange_);
oneofDecl_.Add(other.oneofDecl_);
if (other.HasOptions) {
if (!HasOptions) {
if (other.options_ != null) {
if (options_ == null) {
Options = new global::Google.Protobuf.Reflection.MessageOptions();
}
Options.MergeFrom(other.Options);
@ -1126,7 +1096,7 @@ namespace Google.Protobuf.Reflection {
break;
}
case 58: {
if (!HasOptions) {
if (options_ == null) {
Options = new global::Google.Protobuf.Reflection.MessageOptions();
}
input.ReadMessage(Options);
@ -1181,7 +1151,7 @@ namespace Google.Protobuf.Reflection {
_hasBits0 = other._hasBits0;
start_ = other.start_;
end_ = other.end_;
options_ = other.HasOptions ? other.options_.Clone() : null;
options_ = other.options_ != null ? other.options_.Clone() : null;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
@ -1254,16 +1224,6 @@ namespace Google.Protobuf.Reflection {
options_ = value;
}
}
/// <summary>Gets whether the options field is set</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool HasOptions {
get { return options_ != null; }
}
/// <summary>Clears the value of the options field</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void ClearOptions() {
options_ = null;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override bool Equals(object other) {
@ -1289,7 +1249,7 @@ namespace Google.Protobuf.Reflection {
int hash = 1;
if (HasStart) hash ^= Start.GetHashCode();
if (HasEnd) hash ^= End.GetHashCode();
if (HasOptions) hash ^= Options.GetHashCode();
if (options_ != null) hash ^= Options.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
@ -1311,7 +1271,7 @@ namespace Google.Protobuf.Reflection {
output.WriteRawTag(16);
output.WriteInt32(End);
}
if (HasOptions) {
if (options_ != null) {
output.WriteRawTag(26);
output.WriteMessage(Options);
}
@ -1329,7 +1289,7 @@ namespace Google.Protobuf.Reflection {
if (HasEnd) {
size += 1 + pb::CodedOutputStream.ComputeInt32Size(End);
}
if (HasOptions) {
if (options_ != null) {
size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options);
}
if (_unknownFields != null) {
@ -1349,8 +1309,8 @@ namespace Google.Protobuf.Reflection {
if (other.HasEnd) {
End = other.End;
}
if (other.HasOptions) {
if (!HasOptions) {
if (other.options_ != null) {
if (options_ == null) {
Options = new global::Google.Protobuf.Reflection.ExtensionRangeOptions();
}
Options.MergeFrom(other.Options);
@ -1375,7 +1335,7 @@ namespace Google.Protobuf.Reflection {
break;
}
case 26: {
if (!HasOptions) {
if (options_ == null) {
Options = new global::Google.Protobuf.Reflection.ExtensionRangeOptions();
}
input.ReadMessage(Options);
@ -1791,7 +1751,7 @@ namespace Google.Protobuf.Reflection {
defaultValue_ = other.defaultValue_;
oneofIndex_ = other.oneofIndex_;
jsonName_ = other.jsonName_;
options_ = other.HasOptions ? other.options_.Clone() : null;
options_ = other.options_ != null ? other.options_.Clone() : null;
proto3Optional_ = other.proto3Optional_;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
@ -2054,16 +2014,6 @@ namespace Google.Protobuf.Reflection {
options_ = value;
}
}
/// <summary>Gets whether the options field is set</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool HasOptions {
get { return options_ != null; }
}
/// <summary>Clears the value of the options field</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void ClearOptions() {
options_ = null;
}
/// <summary>Field number for the "proto3_optional" field.</summary>
public const int Proto3OptionalFieldNumber = 17;
@ -2151,7 +2101,7 @@ namespace Google.Protobuf.Reflection {
if (HasDefaultValue) hash ^= DefaultValue.GetHashCode();
if (HasOneofIndex) hash ^= OneofIndex.GetHashCode();
if (HasJsonName) hash ^= JsonName.GetHashCode();
if (HasOptions) hash ^= Options.GetHashCode();
if (options_ != null) hash ^= Options.GetHashCode();
if (HasProto3Optional) hash ^= Proto3Optional.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
@ -2194,7 +2144,7 @@ namespace Google.Protobuf.Reflection {
output.WriteRawTag(58);
output.WriteString(DefaultValue);
}
if (HasOptions) {
if (options_ != null) {
output.WriteRawTag(66);
output.WriteMessage(Options);
}
@ -2245,7 +2195,7 @@ namespace Google.Protobuf.Reflection {
if (HasJsonName) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(JsonName);
}
if (HasOptions) {
if (options_ != null) {
size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options);
}
if (HasProto3Optional) {
@ -2289,8 +2239,8 @@ namespace Google.Protobuf.Reflection {
if (other.HasJsonName) {
JsonName = other.JsonName;
}
if (other.HasOptions) {
if (!HasOptions) {
if (other.options_ != null) {
if (options_ == null) {
Options = new global::Google.Protobuf.Reflection.FieldOptions();
}
Options.MergeFrom(other.Options);
@ -2338,7 +2288,7 @@ namespace Google.Protobuf.Reflection {
break;
}
case 66: {
if (!HasOptions) {
if (options_ == null) {
Options = new global::Google.Protobuf.Reflection.FieldOptions();
}
input.ReadMessage(Options);
@ -2458,7 +2408,7 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public OneofDescriptorProto(OneofDescriptorProto other) : this() {
name_ = other.name_;
options_ = other.HasOptions ? other.options_.Clone() : null;
options_ = other.options_ != null ? other.options_.Clone() : null;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
@ -2500,16 +2450,6 @@ namespace Google.Protobuf.Reflection {
options_ = value;
}
}
/// <summary>Gets whether the options field is set</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool HasOptions {
get { return options_ != null; }
}
/// <summary>Clears the value of the options field</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void ClearOptions() {
options_ = null;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override bool Equals(object other) {
@ -2533,7 +2473,7 @@ namespace Google.Protobuf.Reflection {
public override int GetHashCode() {
int hash = 1;
if (HasName) hash ^= Name.GetHashCode();
if (HasOptions) hash ^= Options.GetHashCode();
if (options_ != null) hash ^= Options.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
@ -2551,7 +2491,7 @@ namespace Google.Protobuf.Reflection {
output.WriteRawTag(10);
output.WriteString(Name);
}
if (HasOptions) {
if (options_ != null) {
output.WriteRawTag(18);
output.WriteMessage(Options);
}
@ -2566,7 +2506,7 @@ namespace Google.Protobuf.Reflection {
if (HasName) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(Name);
}
if (HasOptions) {
if (options_ != null) {
size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options);
}
if (_unknownFields != null) {
@ -2583,8 +2523,8 @@ namespace Google.Protobuf.Reflection {
if (other.HasName) {
Name = other.Name;
}
if (other.HasOptions) {
if (!HasOptions) {
if (other.options_ != null) {
if (options_ == null) {
Options = new global::Google.Protobuf.Reflection.OneofOptions();
}
Options.MergeFrom(other.Options);
@ -2605,7 +2545,7 @@ namespace Google.Protobuf.Reflection {
break;
}
case 18: {
if (!HasOptions) {
if (options_ == null) {
Options = new global::Google.Protobuf.Reflection.OneofOptions();
}
input.ReadMessage(Options);
@ -2647,7 +2587,7 @@ namespace Google.Protobuf.Reflection {
public EnumDescriptorProto(EnumDescriptorProto other) : this() {
name_ = other.name_;
value_ = other.value_.Clone();
options_ = other.HasOptions ? other.options_.Clone() : null;
options_ = other.options_ != null ? other.options_.Clone() : null;
reservedRange_ = other.reservedRange_.Clone();
reservedName_ = other.reservedName_.Clone();
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
@ -2701,16 +2641,6 @@ namespace Google.Protobuf.Reflection {
options_ = value;
}
}
/// <summary>Gets whether the options field is set</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool HasOptions {
get { return options_ != null; }
}
/// <summary>Clears the value of the options field</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void ClearOptions() {
options_ = null;
}
/// <summary>Field number for the "reserved_range" field.</summary>
public const int ReservedRangeFieldNumber = 4;
@ -2767,7 +2697,7 @@ namespace Google.Protobuf.Reflection {
int hash = 1;
if (HasName) hash ^= Name.GetHashCode();
hash ^= value_.GetHashCode();
if (HasOptions) hash ^= Options.GetHashCode();
if (options_ != null) hash ^= Options.GetHashCode();
hash ^= reservedRange_.GetHashCode();
hash ^= reservedName_.GetHashCode();
if (_unknownFields != null) {
@ -2788,7 +2718,7 @@ namespace Google.Protobuf.Reflection {
output.WriteString(Name);
}
value_.WriteTo(output, _repeated_value_codec);
if (HasOptions) {
if (options_ != null) {
output.WriteRawTag(26);
output.WriteMessage(Options);
}
@ -2806,7 +2736,7 @@ namespace Google.Protobuf.Reflection {
size += 1 + pb::CodedOutputStream.ComputeStringSize(Name);
}
size += value_.CalculateSize(_repeated_value_codec);
if (HasOptions) {
if (options_ != null) {
size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options);
}
size += reservedRange_.CalculateSize(_repeated_reservedRange_codec);
@ -2826,8 +2756,8 @@ namespace Google.Protobuf.Reflection {
Name = other.Name;
}
value_.Add(other.value_);
if (other.HasOptions) {
if (!HasOptions) {
if (other.options_ != null) {
if (options_ == null) {
Options = new global::Google.Protobuf.Reflection.EnumOptions();
}
Options.MergeFrom(other.Options);
@ -2854,7 +2784,7 @@ namespace Google.Protobuf.Reflection {
break;
}
case 26: {
if (!HasOptions) {
if (options_ == null) {
Options = new global::Google.Protobuf.Reflection.EnumOptions();
}
input.ReadMessage(Options);
@ -3112,7 +3042,7 @@ namespace Google.Protobuf.Reflection {
_hasBits0 = other._hasBits0;
name_ = other.name_;
number_ = other.number_;
options_ = other.HasOptions ? other.options_.Clone() : null;
options_ = other.options_ != null ? other.options_.Clone() : null;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
@ -3178,16 +3108,6 @@ namespace Google.Protobuf.Reflection {
options_ = value;
}
}
/// <summary>Gets whether the options field is set</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool HasOptions {
get { return options_ != null; }
}
/// <summary>Clears the value of the options field</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void ClearOptions() {
options_ = null;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override bool Equals(object other) {
@ -3213,7 +3133,7 @@ namespace Google.Protobuf.Reflection {
int hash = 1;
if (HasName) hash ^= Name.GetHashCode();
if (HasNumber) hash ^= Number.GetHashCode();
if (HasOptions) hash ^= Options.GetHashCode();
if (options_ != null) hash ^= Options.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
@ -3235,7 +3155,7 @@ namespace Google.Protobuf.Reflection {
output.WriteRawTag(16);
output.WriteInt32(Number);
}
if (HasOptions) {
if (options_ != null) {
output.WriteRawTag(26);
output.WriteMessage(Options);
}
@ -3253,7 +3173,7 @@ namespace Google.Protobuf.Reflection {
if (HasNumber) {
size += 1 + pb::CodedOutputStream.ComputeInt32Size(Number);
}
if (HasOptions) {
if (options_ != null) {
size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options);
}
if (_unknownFields != null) {
@ -3273,8 +3193,8 @@ namespace Google.Protobuf.Reflection {
if (other.HasNumber) {
Number = other.Number;
}
if (other.HasOptions) {
if (!HasOptions) {
if (other.options_ != null) {
if (options_ == null) {
Options = new global::Google.Protobuf.Reflection.EnumValueOptions();
}
Options.MergeFrom(other.Options);
@ -3299,7 +3219,7 @@ namespace Google.Protobuf.Reflection {
break;
}
case 26: {
if (!HasOptions) {
if (options_ == null) {
Options = new global::Google.Protobuf.Reflection.EnumValueOptions();
}
input.ReadMessage(Options);
@ -3341,7 +3261,7 @@ namespace Google.Protobuf.Reflection {
public ServiceDescriptorProto(ServiceDescriptorProto other) : this() {
name_ = other.name_;
method_ = other.method_.Clone();
options_ = other.HasOptions ? other.options_.Clone() : null;
options_ = other.options_ != null ? other.options_.Clone() : null;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
@ -3393,16 +3313,6 @@ namespace Google.Protobuf.Reflection {
options_ = value;
}
}
/// <summary>Gets whether the options field is set</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool HasOptions {
get { return options_ != null; }
}
/// <summary>Clears the value of the options field</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void ClearOptions() {
options_ = null;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override bool Equals(object other) {
@ -3428,7 +3338,7 @@ namespace Google.Protobuf.Reflection {
int hash = 1;
if (HasName) hash ^= Name.GetHashCode();
hash ^= method_.GetHashCode();
if (HasOptions) hash ^= Options.GetHashCode();
if (options_ != null) hash ^= Options.GetHashCode();
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();
}
@ -3447,7 +3357,7 @@ namespace Google.Protobuf.Reflection {
output.WriteString(Name);
}
method_.WriteTo(output, _repeated_method_codec);
if (HasOptions) {
if (options_ != null) {
output.WriteRawTag(26);
output.WriteMessage(Options);
}
@ -3463,7 +3373,7 @@ namespace Google.Protobuf.Reflection {
size += 1 + pb::CodedOutputStream.ComputeStringSize(Name);
}
size += method_.CalculateSize(_repeated_method_codec);
if (HasOptions) {
if (options_ != null) {
size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options);
}
if (_unknownFields != null) {
@ -3481,8 +3391,8 @@ namespace Google.Protobuf.Reflection {
Name = other.Name;
}
method_.Add(other.method_);
if (other.HasOptions) {
if (!HasOptions) {
if (other.options_ != null) {
if (options_ == null) {
Options = new global::Google.Protobuf.Reflection.ServiceOptions();
}
Options.MergeFrom(other.Options);
@ -3507,7 +3417,7 @@ namespace Google.Protobuf.Reflection {
break;
}
case 26: {
if (!HasOptions) {
if (options_ == null) {
Options = new global::Google.Protobuf.Reflection.ServiceOptions();
}
input.ReadMessage(Options);
@ -3552,7 +3462,7 @@ namespace Google.Protobuf.Reflection {
name_ = other.name_;
inputType_ = other.inputType_;
outputType_ = other.outputType_;
options_ = other.HasOptions ? other.options_.Clone() : null;
options_ = other.options_ != null ? other.options_.Clone() : null;
clientStreaming_ = other.clientStreaming_;
serverStreaming_ = other.serverStreaming_;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
@ -3646,16 +3556,6 @@ namespace Google.Protobuf.Reflection {
options_ = value;
}
}
/// <summary>Gets whether the options field is set</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool HasOptions {
get { return options_ != null; }
}
/// <summary>Clears the value of the options field</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void ClearOptions() {
options_ = null;
}
/// <summary>Field number for the "client_streaming" field.</summary>
public const int ClientStreamingFieldNumber = 5;
@ -3739,7 +3639,7 @@ namespace Google.Protobuf.Reflection {
if (HasName) hash ^= Name.GetHashCode();
if (HasInputType) hash ^= InputType.GetHashCode();
if (HasOutputType) hash ^= OutputType.GetHashCode();
if (HasOptions) hash ^= Options.GetHashCode();
if (options_ != null) hash ^= Options.GetHashCode();
if (HasClientStreaming) hash ^= ClientStreaming.GetHashCode();
if (HasServerStreaming) hash ^= ServerStreaming.GetHashCode();
if (_unknownFields != null) {
@ -3767,7 +3667,7 @@ namespace Google.Protobuf.Reflection {
output.WriteRawTag(26);
output.WriteString(OutputType);
}
if (HasOptions) {
if (options_ != null) {
output.WriteRawTag(34);
output.WriteMessage(Options);
}
@ -3796,7 +3696,7 @@ namespace Google.Protobuf.Reflection {
if (HasOutputType) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(OutputType);
}
if (HasOptions) {
if (options_ != null) {
size += 1 + pb::CodedOutputStream.ComputeMessageSize(Options);
}
if (HasClientStreaming) {
@ -3825,8 +3725,8 @@ namespace Google.Protobuf.Reflection {
if (other.HasOutputType) {
OutputType = other.OutputType;
}
if (other.HasOptions) {
if (!HasOptions) {
if (other.options_ != null) {
if (options_ == null) {
Options = new global::Google.Protobuf.Reflection.MethodOptions();
}
Options.MergeFrom(other.Options);
@ -3861,7 +3761,7 @@ namespace Google.Protobuf.Reflection {
break;
}
case 34: {
if (!HasOptions) {
if (options_ == null) {
Options = new global::Google.Protobuf.Reflection.MethodOptions();
}
input.ReadMessage(Options);

View File

@ -394,7 +394,7 @@ namespace Google.Protobuf.Reflection
File.DescriptorPool.AddFieldByNumber(this);
if (ContainingType != null && ContainingType.Proto.HasOptions && ContainingType.Proto.Options.MessageSetWireFormat)
if (ContainingType != null && ContainingType.Proto.Options != null && ContainingType.Proto.Options.MessageSetWireFormat)
{
throw new DescriptorValidationException(this, "MessageSet format is not supported.");
}

View File

@ -516,8 +516,8 @@ bool map_done(MapIter *iter) {
}
const char *map_iter_key(MapIter *iter, int *len) {
*len = upb_strtable_iter_keylength(&iter->it);
return upb_strtable_iter_key(&iter->it);
*len = upb_strtable_iter_key(&iter->it).size;
return upb_strtable_iter_key(&iter->it).data;
}
upb_value map_iter_value(MapIter *iter, int *len) {

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -773,10 +773,10 @@ class Message
* @return null.
* @throws \Exception Invalid data.
*/
public function mergeFromJsonString($data)
public function mergeFromJsonString($data, $ignore_unknown = false)
{
$input = new RawInputStream($data);
$this->parseFromJsonStream($input);
$this->parseFromJsonStream($input, $ignore_unknown);
}
/**
@ -801,6 +801,7 @@ class Message
private function convertJsonValueToProtoValue(
$value,
$field,
$ignore_unknown,
$is_map_key = false)
{
switch ($field->getType()) {
@ -849,7 +850,7 @@ class Message
} elseif (!is_object($value) && !is_array($value)) {
throw new GPBDecodeException("Expect message.");
}
$submsg->mergeFromJsonArray($value);
$submsg->mergeFromJsonArray($value, $ignore_unknown);
}
return $submsg;
case GPBType::ENUM:
@ -862,9 +863,12 @@ class Message
$enum_value = $field->getEnumType()->getValueByName($value);
if (!is_null($enum_value)) {
return $enum_value->getNumber();
} else if ($ignore_unknown) {
return $this->defaultValue($field);
} else {
throw new GPBDecodeException(
"Enum field only accepts integer or enum value name");
}
throw new GPBDecodeException(
"Enum field only accepts integer or enum value name");
case GPBType::STRING:
if (is_null($value)) {
return $this->defaultValue($field);
@ -1125,17 +1129,17 @@ class Message
}
}
protected function mergeFromJsonArray($array)
protected function mergeFromJsonArray($array, $ignore_unknown)
{
if (is_a($this, "Google\Protobuf\Any")) {
$this->clear();
$this->setTypeUrl($array["@type"]);
$msg = $this->unpack();
if (GPBUtil::hasSpecialJsonMapping($msg)) {
$msg->mergeFromJsonArray($array["value"]);
$msg->mergeFromJsonArray($array["value"], $ignore_unknown);
} else {
unset($array["@type"]);
$msg->mergeFromJsonArray($array);
$msg->mergeFromJsonArray($array, $ignore_unknown);
}
$this->setValue($msg->serializeToString());
return;
@ -1171,7 +1175,7 @@ class Message
$fields = $this->getFields();
foreach($array as $key => $value) {
$v = new Value();
$v->mergeFromJsonArray($value);
$v->mergeFromJsonArray($value, $ignore_unknown);
$fields[$key] = $v;
}
}
@ -1194,7 +1198,7 @@ class Message
}
foreach ($array as $key => $v) {
$value = new Value();
$value->mergeFromJsonArray($v);
$value->mergeFromJsonArray($v, $ignore_unknown);
$values = $struct_value->getFields();
$values[$key]= $value;
}
@ -1207,7 +1211,7 @@ class Message
}
foreach ($array as $v) {
$value = new Value();
$value->mergeFromJsonArray($v);
$value->mergeFromJsonArray($v, $ignore_unknown);
$values = $list_value->getValues();
$values[]= $value;
}
@ -1217,10 +1221,10 @@ class Message
}
return;
}
$this->mergeFromArrayJsonImpl($array);
$this->mergeFromArrayJsonImpl($array, $ignore_unknown);
}
private function mergeFromArrayJsonImpl($array)
private function mergeFromArrayJsonImpl($array, $ignore_unknown)
{
foreach ($array as $key => $value) {
$field = $this->desc->getFieldByJsonName($key);
@ -1244,10 +1248,12 @@ class Message
$proto_key = $this->convertJsonValueToProtoValue(
$tmp_key,
$key_field,
$ignore_unknown,
true);
$proto_value = $this->convertJsonValueToProtoValue(
$tmp_value,
$value_field);
$value_field,
$ignore_unknown);
self::kvUpdateHelper($field, $proto_key, $proto_value);
}
} else if ($field->isRepeated()) {
@ -1261,14 +1267,16 @@ class Message
}
$proto_value = $this->convertJsonValueToProtoValue(
$tmp,
$field);
$field,
$ignore_unknown);
self::appendHelper($field, $proto_value);
}
} else {
$setter = $field->getSetter();
$proto_value = $this->convertJsonValueToProtoValue(
$value,
$field);
$field,
$ignore_unknown);
if ($field->getType() === GPBType::MESSAGE) {
if (is_null($proto_value)) {
continue;
@ -1288,7 +1296,7 @@ class Message
/**
* @ignore
*/
public function parseFromJsonStream($input)
public function parseFromJsonStream($input, $ignore_unknown)
{
$array = json_decode($input->getData(), true, 512, JSON_BIGINT_AS_STRING);
if ($this instanceof \Google\Protobuf\ListValue) {
@ -1304,7 +1312,7 @@ class Message
}
}
try {
$this->mergeFromJsonArray($array);
$this->mergeFromJsonArray($array, $ignore_unknown);
} catch (\Exception $e) {
throw new GPBDecodeException($e->getMessage());
}

View File

@ -884,6 +884,11 @@ class EncodeDecodeTest extends TestBase
$m->mergeFromJsonString("{\"unknown\":{\"a\":1, \"b\":1},
\"optionalInt32\":1}", true);
$this->assertSame(1, $m->getOptionalInt32());
// Test unknown enum value
$m = new TestMessage();
$m->mergeFromJsonString("{\"optionalEnum\":\"UNKNOWN\"}", true);
$this->assertSame(0, $m->getOptionalEnum());
}
public function testJsonEncode()

View File

@ -239,16 +239,19 @@ class JsonFormatTest(JsonFormatBase):
golden_dict = {
'messageSet': {
'[protobuf_unittest.'
'TestMessageSetExtension1.messageSetExtension]': {
'TestMessageSetExtension1.message_set_extension]': {
'i': 23,
},
'[protobuf_unittest.'
'TestMessageSetExtension2.messageSetExtension]': {
'TestMessageSetExtension2.message_set_extension]': {
'str': u'foo',
},
},
}
self.assertEqual(golden_dict, message_dict)
parsed_msg = unittest_mset_pb2.TestMessageSetContainer()
json_format.ParseDict(golden_dict, parsed_msg)
self.assertEqual(message, parsed_msg)
def testExtensionSerializationDictMatchesProto3SpecMore(self):
"""See go/proto3-json-spec for spec.
@ -279,9 +282,9 @@ class JsonFormatTest(JsonFormatBase):
message
)
ext1_text = ('protobuf_unittest.TestMessageSetExtension1.'
'messageSetExtension')
'message_set_extension')
ext2_text = ('protobuf_unittest.TestMessageSetExtension2.'
'messageSetExtension')
'message_set_extension')
golden_text = ('{"messageSet": {'
' "[%s]": {'
' "i": 23'

View File

@ -246,8 +246,7 @@ class _Printer(object):
js[name] = [self._FieldToJsonObject(field, k)
for k in value]
elif field.is_extension:
full_qualifier = field.full_name[:-len(field.name)]
name = '[%s%s]' % (full_qualifier, name)
name = '[%s]' % field.full_name
js[name] = self._FieldToJsonObject(field, value)
else:
js[name] = self._FieldToJsonObject(field, value)

View File

@ -40,22 +40,21 @@ You can also get the source by "git clone" our git repository. Make sure you
have also cloned the submodules and generated the configure script (skip this
if you are using a release .tar.gz or .zip package):
```shell
git clone https://github.com/protocolbuffers/protobuf.git
cd protobuf
git submodule update --init --recursive
./autogen.sh
```
To build and install the C++ Protocol Buffer runtime and the Protocol
Buffer compiler (protoc) execute the following:
```shell
./configure
make
make check
sudo make install
sudo ldconfig # refresh shared library cache.
```
If "make check" fails, you can still install, but it is likely that
some features of this library will not work correctly on your system.
Proceed at your own risk.
@ -123,15 +122,15 @@ of "protobuf" in these examples.
For a Mac system, Unix tools are not available by default. You will first need
to install Xcode from the Mac AppStore and then run the following command from
a terminal:
```shell
sudo xcode-select --install
```shell
To install Unix tools, you can install "port" following the instructions at
https://www.macports.org . This will reside in /opt/local/bin/port for most
Mac installations.
```shell
sudo /opt/local/bin/port install autoconf automake libtool
```
Then follow the Unix instructions above.
**Note for cross-compiling**

View File

@ -59,11 +59,12 @@ ArenaImpl::ThreadCache& ArenaImpl::thread_cache() {
}
#elif defined(PROTOBUF_USE_DLLS)
ArenaImpl::ThreadCache& ArenaImpl::thread_cache() {
static GOOGLE_THREAD_LOCAL ThreadCache thread_cache_ = {-1, NULL};
static PROTOBUF_THREAD_LOCAL ThreadCache thread_cache_ = {-1, NULL};
return thread_cache_;
}
#else
GOOGLE_THREAD_LOCAL ArenaImpl::ThreadCache ArenaImpl::thread_cache_ = {-1, NULL};
PROTOBUF_THREAD_LOCAL ArenaImpl::ThreadCache ArenaImpl::thread_cache_ = {-1,
NULL};
#endif
void ArenaImpl::Init() {

View File

@ -288,16 +288,16 @@ class PROTOBUF_EXPORT ArenaImpl {
};
static std::atomic<LifecycleId> lifecycle_id_generator_;
#if defined(GOOGLE_PROTOBUF_NO_THREADLOCAL)
// Android ndk does not support GOOGLE_THREAD_LOCAL keyword so we use a custom thread
// Android ndk does not support __thread keyword so we use a custom thread
// local storage class we implemented.
// iOS also does not support the GOOGLE_THREAD_LOCAL keyword.
// iOS also does not support the __thread keyword.
static ThreadCache& thread_cache();
#elif defined(PROTOBUF_USE_DLLS)
// Thread local variables cannot be exposed through DLL interface but we can
// wrap them in static functions.
static ThreadCache& thread_cache();
#else
static GOOGLE_THREAD_LOCAL ThreadCache thread_cache_;
static PROTOBUF_THREAD_LOCAL ThreadCache thread_cache_;
static ThreadCache& thread_cache() { return thread_cache_; }
#endif

View File

@ -754,6 +754,10 @@ void StringOneofFieldGenerator::GenerateInlineAccessorDefinitions(
" if ($name$ != nullptr) {\n"
" set_has_$name$();\n"
" $field_member$.UnsafeSetDefault($name$);\n"
" ::$proto_ns$::Arena* arena = GetArena();\n"
" if (arena != nullptr) {\n"
" arena->Own($name$);\n"
" }\n"
" }\n"
" // @@protoc_insertion_point(field_set_allocated:$full_name$)\n"
"}\n");
@ -917,15 +921,6 @@ void StringOneofFieldGenerator::GenerateConstructorCode(
" $default_variable$);\n");
}
void StringOneofFieldGenerator::GenerateDestructorCode(
io::Printer* printer) const {
Formatter format(printer, variables_);
format(
"if (_internal_has_$name$()) {\n"
" $field_member$.DestroyNoArena($default_variable$);\n"
"}\n");
}
// ===================================================================
RepeatedStringFieldGenerator::RepeatedStringFieldGenerator(

View File

@ -95,7 +95,6 @@ class StringOneofFieldGenerator : public StringFieldGenerator {
void GenerateMessageClearingCode(io::Printer* printer) const;
void GenerateSwappingCode(io::Printer* printer) const;
void GenerateConstructorCode(io::Printer* printer) const;
void GenerateDestructorCode(io::Printer* printer) const;
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(StringOneofFieldGenerator);

View File

@ -1683,6 +1683,26 @@ TEST_F(OneofTest, SetAllocatedString) {
EXPECT_EQ(kHello, message.foo_string());
}
TEST_F(OneofTest, ArenaSetAllocatedString) {
// Check that set_allocated_foo() works for strings.
Arena arena;
UNITTEST::TestOneof2* message =
Arena::CreateMessage<UNITTEST::TestOneof2>(&arena);
EXPECT_FALSE(message->has_foo_string());
const std::string kHello("hello");
message->set_foo_string(kHello);
EXPECT_TRUE(message->has_foo_string());
message->set_allocated_foo_string(NULL);
EXPECT_FALSE(message->has_foo_string());
EXPECT_EQ("", message->foo_string());
message->set_allocated_foo_string(new std::string(kHello));
EXPECT_TRUE(message->has_foo_string());
EXPECT_EQ(kHello, message->foo_string());
}
TEST_F(OneofTest, SetMessage) {
// Check that setting a message field works

View File

@ -159,24 +159,23 @@ inline bool IsProto2(const FileDescriptor* descriptor) {
}
inline bool SupportsPresenceApi(const FieldDescriptor* descriptor) {
// We don't use descriptor->is_singular_with_presence() as C# has slightly
// different behavior to other languages.
if (IsProto2(descriptor->file())) {
// We generate Has/Clear for oneof fields in C#, as well as for messages.
// It's possible that we shouldn't, but stopping doing so would be a
// breaking change for proto2. Fortunately the decision is moot for
// onoeof in proto3: you can't use "optional" inside a oneof.
// Proto2: every singular field has presence. (Even fields in oneofs.)
return !descriptor->is_repeated();
} else {
// Proto3: only for explictly-optional fields that aren't messages.
// (Repeated fields can never be explicitly optional, so we don't need
// to check for that.) Currently we can't get at proto3_optional directly,
// but we can use has_optional_keyword() as a surrogate check.
return descriptor->has_optional_keyword() &&
descriptor->type() != FieldDescriptor::TYPE_MESSAGE;
// Unlike most languages, we don't generate Has/Clear members for message
// types, because they can always be set to null in C#. They're not really
// needed for oneof fields in proto2 either, as everything can be done via
// oneof case, but we follow the convention from other languages. Proto3
// oneof fields never have Has/Clear members - but will also never have
// the explicit optional keyword either.
//
// None of the built-in helpers (descriptor->has_presence() etc) describe
// quite the behavior we want, so the rules are explicit below.
if (descriptor->is_repeated() ||
descriptor->type() == FieldDescriptor::TYPE_MESSAGE) {
return false;
}
// has_optional_keyword() has more complex rules for proto2, but that
// doesn't matter given the first part of this condition.
return IsProto2(descriptor->file()) || descriptor->has_optional_keyword();
}
inline bool RequiresPresenceBit(const FieldDescriptor* descriptor) {

View File

@ -85,9 +85,9 @@ MapFieldGenerator::MapFieldGenerator(const FieldDescriptor* descriptor,
const Options& options)
: RepeatedFieldGenerator(descriptor, options) {
const FieldDescriptor* key_descriptor =
descriptor->message_type()->FindFieldByName("key");
descriptor->message_type()->map_key();
const FieldDescriptor* value_descriptor =
descriptor->message_type()->FindFieldByName("value");
descriptor->message_type()->map_value();
value_field_generator_.reset(FieldGenerator::Make(value_descriptor, options));
// Pull over some variables_ from the value.

View File

@ -3522,7 +3522,7 @@ class DescriptorBuilder {
return pool->enforce_weak_;
}
static inline bool get_is_placeholder(const Descriptor* descriptor) {
return descriptor->is_placeholder_;
return descriptor != nullptr && descriptor->is_placeholder_;
}
static inline void assert_mutex_held(const DescriptorPool* pool) {
if (pool->mutex_ != nullptr) {

View File

@ -2592,11 +2592,9 @@ TEST_F(MiscTest, DefaultValues) {
ASSERT_TRUE(message->field(10)->has_default_value());
EXPECT_EQ(-1, message->field(0)->default_value_int32());
EXPECT_EQ(-PROTOBUF_ULONGLONG(1000000000000),
message->field(1)->default_value_int64());
EXPECT_EQ(int64{-1000000000000}, message->field(1)->default_value_int64());
EXPECT_EQ(42, message->field(2)->default_value_uint32());
EXPECT_EQ(PROTOBUF_ULONGLONG(2000000000000),
message->field(3)->default_value_uint64());
EXPECT_EQ(uint64{2000000000000}, message->field(3)->default_value_uint64());
EXPECT_EQ(4.5, message->field(4)->default_value_float());
EXPECT_EQ(10e100, message->field(5)->default_value_double());
EXPECT_TRUE(message->field(6)->default_value_bool());
@ -3009,11 +3007,11 @@ TEST(CustomOptions, OptionLocations) {
file->FindServiceByName("TestServiceWithCustomOptions");
const MethodDescriptor* method = service->FindMethodByName("Foo");
EXPECT_EQ(PROTOBUF_LONGLONG(9876543210),
EXPECT_EQ(int64{9876543210},
file->options().GetExtension(protobuf_unittest::file_opt1));
EXPECT_EQ(-56,
message->options().GetExtension(protobuf_unittest::message_opt1));
EXPECT_EQ(PROTOBUF_LONGLONG(8765432109),
EXPECT_EQ(int64{8765432109},
field->options().GetExtension(protobuf_unittest::field_opt1));
EXPECT_EQ(42, // Check that we get the default for an option we don't set.
field->options().GetExtension(protobuf_unittest::field_opt2));
@ -3021,7 +3019,7 @@ TEST(CustomOptions, OptionLocations) {
EXPECT_EQ(-789, enm->options().GetExtension(protobuf_unittest::enum_opt1));
EXPECT_EQ(123, enm->value(1)->options().GetExtension(
protobuf_unittest::enum_value_opt1));
EXPECT_EQ(PROTOBUF_LONGLONG(-9876543210),
EXPECT_EQ(int64{-9876543210},
service->options().GetExtension(protobuf_unittest::service_opt1));
EXPECT_EQ(protobuf_unittest::METHODOPT1_VAL2,
method->options().GetExtension(protobuf_unittest::method_opt1));

View File

@ -37,6 +37,7 @@
#ifndef GOOGLE_PROTOBUF_MAP_H__
#define GOOGLE_PROTOBUF_MAP_H__
#include <functional>
#include <initializer_list>
#include <iterator>
#include <limits> // To support Visual Studio 2008
@ -268,7 +269,7 @@ class Map {
using const_reference = const value_type&;
using size_type = size_t;
using hasher = hash<Key>;
using hasher = std::hash<Key>;
Map() : arena_(nullptr), default_enum_value_(0) { Init(); }
explicit Map(Arena* arena) : arena_(arena), default_enum_value_(0) { Init(); }

View File

@ -32,6 +32,7 @@
#define GOOGLE_PROTOBUF_MAP_FIELD_H__
#include <atomic>
#include <functional>
#include <google/protobuf/arena.h>
#include <google/protobuf/descriptor.h>
@ -796,7 +797,7 @@ class PROTOBUF_EXPORT MapIterator {
} // namespace protobuf
} // namespace google
GOOGLE_PROTOBUF_HASH_NAMESPACE_DECLARATION_START
namespace std {
template <>
struct hash<::PROTOBUF_NAMESPACE_ID::MapKey> {
size_t operator()(const ::PROTOBUF_NAMESPACE_ID::MapKey& map_key) const {
@ -809,16 +810,25 @@ struct hash<::PROTOBUF_NAMESPACE_ID::MapKey> {
break;
case ::PROTOBUF_NAMESPACE_ID::FieldDescriptor::CPPTYPE_STRING:
return hash<std::string>()(map_key.GetStringValue());
case ::PROTOBUF_NAMESPACE_ID::FieldDescriptor::CPPTYPE_INT64:
return hash<int64>()(map_key.GetInt64Value());
case ::PROTOBUF_NAMESPACE_ID::FieldDescriptor::CPPTYPE_INT32:
return hash<int32>()(map_key.GetInt32Value());
case ::PROTOBUF_NAMESPACE_ID::FieldDescriptor::CPPTYPE_UINT64:
return hash<uint64>()(map_key.GetUInt64Value());
case ::PROTOBUF_NAMESPACE_ID::FieldDescriptor::CPPTYPE_UINT32:
return hash<uint32>()(map_key.GetUInt32Value());
case ::PROTOBUF_NAMESPACE_ID::FieldDescriptor::CPPTYPE_BOOL:
case ::PROTOBUF_NAMESPACE_ID::FieldDescriptor::CPPTYPE_INT64: {
auto value = map_key.GetInt64Value();
return hash<decltype(value)>()(value);
}
case ::PROTOBUF_NAMESPACE_ID::FieldDescriptor::CPPTYPE_INT32: {
auto value = map_key.GetInt32Value();
return hash<decltype(value)>()(map_key.GetInt32Value());
}
case ::PROTOBUF_NAMESPACE_ID::FieldDescriptor::CPPTYPE_UINT64: {
auto value = map_key.GetUInt64Value();
return hash<decltype(value)>()(map_key.GetUInt64Value());
}
case ::PROTOBUF_NAMESPACE_ID::FieldDescriptor::CPPTYPE_UINT32: {
auto value = map_key.GetUInt32Value();
return hash<decltype(value)>()(map_key.GetUInt32Value());
}
case ::PROTOBUF_NAMESPACE_ID::FieldDescriptor::CPPTYPE_BOOL: {
return hash<bool>()(map_key.GetBoolValue());
}
}
GOOGLE_LOG(FATAL) << "Can't get here.";
return 0;
@ -828,8 +838,7 @@ struct hash<::PROTOBUF_NAMESPACE_ID::MapKey> {
return map_key1 < map_key2;
}
};
GOOGLE_PROTOBUF_HASH_NAMESPACE_DECLARATION_END
} // namespace std
#include <google/protobuf/port_undef.inc>
#endif // GOOGLE_PROTOBUF_MAP_FIELD_H__

View File

@ -1011,8 +1011,10 @@ class PROTOBUF_EXPORT Reflection final {
const OneofDescriptor* oneof_descriptor) const;
inline uint32* MutableOneofCase(
Message* message, const OneofDescriptor* oneof_descriptor) const;
inline const internal::ExtensionSet& GetExtensionSet(
const Message& message) const;
inline bool HasExtensionSet(const Message& message) const {
return schema_.HasExtensionSet();
}
const internal::ExtensionSet& GetExtensionSet(const Message& message) const;
internal::ExtensionSet* MutableExtensionSet(Message* message) const;
inline Arena* GetArena(Message* message) const;

View File

@ -634,3 +634,9 @@ PROTOBUF_EXPORT_TEMPLATE_TEST(DEFAULT, __declspec(dllimport));
#endif
#define PROTOBUF_FINAL final
#if defined(_MSC_VER)
#define PROTOBUF_THREAD_LOCAL __declspec(thread)
#else
#define PROTOBUF_THREAD_LOCAL __thread
#endif

View File

@ -83,6 +83,7 @@
#undef PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_DECLSPEC_dllexport
#undef PROTOBUF_EXPORT_TEMPLATE_STYLE_MATCH_DECLSPEC_dllimport
#undef PROTOBUF_FINAL
#undef PROTOBUF_THREAD_LOCAL
// Restore macro that may have been #undef'd in port_def.inc.
#ifdef _MSC_VER

View File

@ -188,6 +188,68 @@ void ReflectionOps::Clear(Message* message) {
reflection->MutableUnknownFields(message)->Clear();
}
bool ReflectionOps::IsInitialized(const Message& message, bool check_fields,
bool check_descendants) {
const Descriptor* descriptor = message.GetDescriptor();
const Reflection* reflection = GetReflectionOrDie(message);
if (const int field_count = descriptor->field_count()) {
const FieldDescriptor* begin = descriptor->field(0);
const FieldDescriptor* end = begin + field_count;
GOOGLE_DCHECK_EQ(descriptor->field(field_count - 1), end - 1);
if (check_fields) {
// Check required fields of this message.
for (const FieldDescriptor* field = begin; field != end; ++field) {
if (field->is_required() && !reflection->HasField(message, field)) {
return false;
}
}
}
if (check_descendants) {
for (const FieldDescriptor* field = begin; field != end; ++field) {
if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
const Descriptor* message_type = field->message_type();
if (PROTOBUF_PREDICT_FALSE(message_type->options().map_entry())) {
if (message_type->field(1)->cpp_type() ==
FieldDescriptor::CPPTYPE_MESSAGE) {
const MapFieldBase* map_field =
reflection->GetMapData(message, field);
if (map_field->IsMapValid()) {
MapIterator it(const_cast<Message*>(&message), field);
MapIterator end(const_cast<Message*>(&message), field);
for (map_field->MapBegin(&it), map_field->MapEnd(&end);
it != end; ++it) {
if (!it.GetValueRef().GetMessageValue().IsInitialized()) {
return false;
}
}
}
}
} else if (field->is_repeated()) {
const int size = reflection->FieldSize(message, field);
for (int j = 0; j < size; j++) {
if (!reflection->GetRepeatedMessage(message, field, j)
.IsInitialized()) {
return false;
}
}
} else if (reflection->HasField(message, field)) {
if (!reflection->GetMessage(message, field).IsInitialized()) {
return false;
}
}
}
}
}
}
if (check_descendants && reflection->HasExtensionSet(message) &&
!reflection->GetExtensionSet(message).IsInitialized()) {
return false;
}
return true;
}
bool ReflectionOps::IsInitialized(const Message& message) {
const Descriptor* descriptor = message.GetDescriptor();
const Reflection* reflection = GetReflectionOrDie(message);

View File

@ -66,6 +66,8 @@ class PROTOBUF_EXPORT ReflectionOps {
static void Merge(const Message& from, Message* to);
static void Clear(Message* message);
static bool IsInitialized(const Message& message);
static bool IsInitialized(const Message& message, bool check_fields,
bool check_descendants);
static void DiscardUnknownFields(Message* message);
// Finds all unset required fields in the message and adds their full

View File

@ -340,12 +340,20 @@ TEST(ReflectionOpsTest, IsInitialized) {
unittest::TestRequired message;
EXPECT_FALSE(ReflectionOps::IsInitialized(message));
EXPECT_FALSE(ReflectionOps::IsInitialized(message, true, false));
EXPECT_TRUE(ReflectionOps::IsInitialized(message, false, true));
message.set_a(1);
EXPECT_FALSE(ReflectionOps::IsInitialized(message));
EXPECT_FALSE(ReflectionOps::IsInitialized(message, true, true));
EXPECT_TRUE(ReflectionOps::IsInitialized(message, false, true));
message.set_b(2);
EXPECT_FALSE(ReflectionOps::IsInitialized(message));
EXPECT_FALSE(ReflectionOps::IsInitialized(message, true, true));
EXPECT_TRUE(ReflectionOps::IsInitialized(message, false, true));
message.set_c(3);
EXPECT_TRUE(ReflectionOps::IsInitialized(message));
EXPECT_TRUE(ReflectionOps::IsInitialized(message, true, false));
EXPECT_TRUE(ReflectionOps::IsInitialized(message, false, true));
}
TEST(ReflectionOpsTest, ForeignIsInitialized) {
@ -354,26 +362,35 @@ TEST(ReflectionOpsTest, ForeignIsInitialized) {
// Starts out initialized because the foreign message is itself an optional
// field.
EXPECT_TRUE(ReflectionOps::IsInitialized(message));
EXPECT_TRUE(ReflectionOps::IsInitialized(message, false, true));
// Once we create that field, the message is no longer initialized.
message.mutable_optional_message();
EXPECT_FALSE(ReflectionOps::IsInitialized(message));
EXPECT_TRUE(ReflectionOps::IsInitialized(message, true, false));
EXPECT_FALSE(ReflectionOps::IsInitialized(message, false, true));
// Initialize it. Now we're initialized.
message.mutable_optional_message()->set_a(1);
message.mutable_optional_message()->set_b(2);
message.mutable_optional_message()->set_c(3);
EXPECT_TRUE(ReflectionOps::IsInitialized(message));
EXPECT_TRUE(ReflectionOps::IsInitialized(message, true, false));
EXPECT_TRUE(ReflectionOps::IsInitialized(message, false, true));
// Add a repeated version of the message. No longer initialized.
unittest::TestRequired* sub_message = message.add_repeated_message();
EXPECT_FALSE(ReflectionOps::IsInitialized(message));
EXPECT_TRUE(ReflectionOps::IsInitialized(message, true, false));
EXPECT_FALSE(ReflectionOps::IsInitialized(message, false, true));
// Initialize that repeated version.
sub_message->set_a(1);
sub_message->set_b(2);
sub_message->set_c(3);
EXPECT_TRUE(ReflectionOps::IsInitialized(message));
EXPECT_TRUE(ReflectionOps::IsInitialized(message, true, false));
EXPECT_TRUE(ReflectionOps::IsInitialized(message, false, true));
}
TEST(ReflectionOpsTest, ExtensionIsInitialized) {
@ -382,42 +399,62 @@ TEST(ReflectionOpsTest, ExtensionIsInitialized) {
// Starts out initialized because the foreign message is itself an optional
// field.
EXPECT_TRUE(ReflectionOps::IsInitialized(message));
EXPECT_TRUE(ReflectionOps::IsInitialized(message, true, false));
EXPECT_TRUE(ReflectionOps::IsInitialized(message, false, true));
// Once we create that field, the message is no longer initialized.
message.MutableExtension(unittest::TestRequired::single);
EXPECT_FALSE(ReflectionOps::IsInitialized(message));
EXPECT_TRUE(ReflectionOps::IsInitialized(message, true, false));
EXPECT_FALSE(ReflectionOps::IsInitialized(message, false, true));
// Initialize it. Now we're initialized.
message.MutableExtension(unittest::TestRequired::single)->set_a(1);
message.MutableExtension(unittest::TestRequired::single)->set_b(2);
message.MutableExtension(unittest::TestRequired::single)->set_c(3);
EXPECT_TRUE(ReflectionOps::IsInitialized(message));
EXPECT_TRUE(ReflectionOps::IsInitialized(message, true, false));
EXPECT_TRUE(ReflectionOps::IsInitialized(message, false, true));
// Add a repeated version of the message. No longer initialized.
message.AddExtension(unittest::TestRequired::multi);
EXPECT_FALSE(ReflectionOps::IsInitialized(message));
EXPECT_TRUE(ReflectionOps::IsInitialized(message, true, false));
EXPECT_FALSE(ReflectionOps::IsInitialized(message, false, true));
// Initialize that repeated version.
message.MutableExtension(unittest::TestRequired::multi, 0)->set_a(1);
message.MutableExtension(unittest::TestRequired::multi, 0)->set_b(2);
message.MutableExtension(unittest::TestRequired::multi, 0)->set_c(3);
EXPECT_TRUE(ReflectionOps::IsInitialized(message));
EXPECT_TRUE(ReflectionOps::IsInitialized(message, true, false));
EXPECT_TRUE(ReflectionOps::IsInitialized(message, false, true));
}
TEST(ReflectionOpsTest, OneofIsInitialized) {
unittest::TestRequiredOneof message;
EXPECT_TRUE(ReflectionOps::IsInitialized(message));
EXPECT_TRUE(ReflectionOps::IsInitialized(message, true, false));
EXPECT_TRUE(ReflectionOps::IsInitialized(message, false, true));
message.mutable_foo_message();
EXPECT_FALSE(ReflectionOps::IsInitialized(message));
EXPECT_TRUE(ReflectionOps::IsInitialized(message, true, false));
EXPECT_FALSE(ReflectionOps::IsInitialized(message, false, true));
message.set_foo_int(1);
EXPECT_TRUE(ReflectionOps::IsInitialized(message));
EXPECT_TRUE(ReflectionOps::IsInitialized(message, true, false));
EXPECT_TRUE(ReflectionOps::IsInitialized(message, false, true));
message.mutable_foo_message();
EXPECT_FALSE(ReflectionOps::IsInitialized(message));
EXPECT_TRUE(ReflectionOps::IsInitialized(message, true, false));
EXPECT_FALSE(ReflectionOps::IsInitialized(message, false, true));
message.mutable_foo_message()->set_required_double(0.1);
EXPECT_TRUE(ReflectionOps::IsInitialized(message));
EXPECT_TRUE(ReflectionOps::IsInitialized(message, true, false));
EXPECT_TRUE(ReflectionOps::IsInitialized(message, false, true));
}
static std::string FindInitializationErrors(const Message& message) {

View File

@ -911,6 +911,10 @@ inline void Value::set_allocated_string_value(std::string* string_value) {
if (string_value != nullptr) {
set_has_string_value();
kind_.string_value_.UnsafeSetDefault(string_value);
::PROTOBUF_NAMESPACE_ID::Arena* arena = GetArena();
if (arena != nullptr) {
arena->Own(string_value);
}
}
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Value.string_value)
}

View File

@ -225,12 +225,6 @@ inline void GOOGLE_UNALIGNED_STORE64(void *p, uint64 v) {
# define GOOGLE_PROTOBUF_USE_PORTABLE_LOG2
#endif
#if defined(_MSC_VER)
#define GOOGLE_THREAD_LOCAL __declspec(thread)
#else
#define GOOGLE_THREAD_LOCAL __thread
#endif
// The following guarantees declaration of the byte swap functions.
#ifdef _MSC_VER
#define bswap_16(x) _byteswap_ushort(x)

View File

@ -258,6 +258,7 @@ class TextFormat::Parser::ParserImpl {
allow_unknown_enum_(allow_unknown_enum),
allow_field_number_(allow_field_number),
allow_partial_(allow_partial),
initial_recursion_limit_(recursion_limit),
recursion_limit_(recursion_limit),
had_errors_(false) {
// For backwards-compatibility with proto1, we need to allow the 'f' suffix
@ -636,7 +637,10 @@ class TextFormat::Parser::ParserImpl {
bool ConsumeFieldMessage(Message* message, const Reflection* reflection,
const FieldDescriptor* field) {
if (--recursion_limit_ < 0) {
ReportError("Message is too deep");
ReportError(
StrCat("Message is too deep, the parser exceeded the "
"configured recursion limit of ",
initial_recursion_limit_, "."));
return false;
}
// If the parse information tree is not nullptr, create a nested one
@ -668,12 +672,22 @@ class TextFormat::Parser::ParserImpl {
// Skips the whole body of a message including the beginning delimiter and
// the ending delimiter.
bool SkipFieldMessage() {
if (--recursion_limit_ < 0) {
ReportError(
StrCat("Message is too deep, the parser exceeded the "
"configured recursion limit of ",
initial_recursion_limit_, "."));
return false;
}
std::string delimiter;
DO(ConsumeMessageDelimiter(&delimiter));
while (!LookingAt(">") && !LookingAt("}")) {
DO(SkipField());
}
DO(Consume(delimiter));
++recursion_limit_;
return true;
}
@ -1192,6 +1206,7 @@ class TextFormat::Parser::ParserImpl {
const bool allow_unknown_enum_;
const bool allow_field_number_;
const bool allow_partial_;
const int initial_recursion_limit_;
int recursion_limit_;
bool had_errors_;
};

View File

@ -55,9 +55,9 @@
#include <google/protobuf/io/tokenizer.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/stubs/strutil.h>
#include <google/protobuf/stubs/substitute.h>
#include <google/protobuf/testing/googletest.h>
#include <gtest/gtest.h>
#include <google/protobuf/stubs/substitute.h>
#include <google/protobuf/port_def.inc>
@ -1911,7 +1911,33 @@ TEST_F(TextFormatParserTest, SetRecursionLimit) {
input = strings::Substitute(format, input);
parser_.SetRecursionLimit(100);
ExpectMessage(input, "Message is too deep", 1, 908, &message, false);
ExpectMessage(input,
"Message is too deep, the parser exceeded the configured "
"recursion limit of 100.",
1, 908, &message, false);
parser_.SetRecursionLimit(101);
ExpectSuccessAndTree(input, &message, nullptr);
}
TEST_F(TextFormatParserTest, SetRecursionLimitUnknownField) {
const char* format = "unknown_child: { $0 }";
std::string input;
for (int i = 0; i < 100; ++i) input = strings::Substitute(format, input);
parser_.AllowUnknownField(true);
unittest::NestedTestAllTypes message;
ExpectSuccessAndTree(input, &message, nullptr);
input = strings::Substitute(format, input);
parser_.SetRecursionLimit(100);
ExpectMessage(
input,
"WARNING:Message type \"protobuf_unittest.NestedTestAllTypes\" has no "
"field named \"unknown_child\".\n1:1716: Message is too deep, the parser "
"exceeded the configured recursion limit of 100.",
1, 14, &message, false);
parser_.SetRecursionLimit(101);
ExpectSuccessAndTree(input, &message, nullptr);

View File

@ -201,7 +201,7 @@ class PROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter {
// Returns the Value Type of a map given the Type of the map entry and a
// TypeInfo instance.
const google::protobuf::Type* GetMapValueType(
const google::protobuf::Type& entry_type, const TypeInfo* typeinfo);
const google::protobuf::Type& found_type, const TypeInfo* typeinfo);
// Calls WriteTo() on every child in children_.
void WriteChildren(ObjectWriter* ow);

View File

@ -130,7 +130,7 @@ class PROTOBUF_EXPORT JsonStreamParser {
};
// Parses a single chunk of JSON, returning an error if the JSON was invalid.
util::Status ParseChunk(StringPiece json);
util::Status ParseChunk(StringPiece chunk);
// Runs the parser based on stack_ and p_, until the stack is empty or p_ runs
// out of data. If we unexpectedly run out of p_ we push the latest back onto

View File

@ -235,7 +235,7 @@ TEST_F(JsonStreamParserTest, SimpleInt) {
TEST_F(JsonStreamParserTest, SimpleNegativeInt) {
StringPiece str = "-79497823553162765";
for (int i = 0; i <= str.length(); ++i) {
ow_.RenderInt64("", -79497823553162765LL);
ow_.RenderInt64("", int64{-79497823553162765});
DoTest(str, i);
}
}
@ -243,7 +243,7 @@ TEST_F(JsonStreamParserTest, SimpleNegativeInt) {
TEST_F(JsonStreamParserTest, SimpleUnsignedInt) {
StringPiece str = "11779497823553162765";
for (int i = 0; i <= str.length(); ++i) {
ow_.RenderUint64("", 11779497823553162765ULL);
ow_.RenderUint64("", uint64{11779497823553162765u});
DoTest(str, i);
}
}
@ -378,7 +378,7 @@ TEST_F(JsonStreamParserTest, ArrayComplexValues) {
->RenderInt64("", -127)
->RenderDouble("", 45.3)
->RenderDouble("", -1056.4)
->RenderUint64("", 11779497823553162765ULL)
->RenderUint64("", uint64{11779497823553162765u})
->EndList()
->StartObject("")
->RenderBool("key", true)
@ -406,7 +406,7 @@ TEST_F(JsonStreamParserTest, ObjectValues) {
->RenderInt64("ni", -127)
->RenderDouble("pd", 45.3)
->RenderDouble("nd", -1056.4)
->RenderUint64("pl", 11779497823553162765ULL)
->RenderUint64("pl", uint64{11779497823553162765u})
->StartList("l")
->StartList("")
->EndList()

View File

@ -131,7 +131,7 @@ class PROTOBUF_EXPORT ProtoStreamObjectSource : public ObjectSource {
// nested messages (end with 0) and nested groups (end with group end tag).
// The include_start_and_end parameter allows this method to be called when
// already inside of an object, and skip calling StartObject and EndObject.
virtual util::Status WriteMessage(const google::protobuf::Type& descriptor,
virtual util::Status WriteMessage(const google::protobuf::Type& type,
StringPiece name,
const uint32 end_tag,
bool include_start_and_end,

View File

@ -152,13 +152,13 @@ class ProtostreamObjectSourceTest
->RenderInt32("", 3208)
->EndList()
->StartList("repFix64")
->RenderUint64("", bit_cast<uint64>(6401LL))
->RenderUint64("", bit_cast<uint64>(0LL))
->RenderUint64("", bit_cast<uint64>(int64{6401}))
->RenderUint64("", bit_cast<uint64>(int64{0}))
->EndList()
->StartList("repU64")
->RenderUint64("", bit_cast<uint64>(0LL))
->RenderUint64("", bit_cast<uint64>(6402LL))
->RenderUint64("", bit_cast<uint64>(6403LL))
->RenderUint64("", bit_cast<uint64>(int64{0}))
->RenderUint64("", bit_cast<uint64>(int64{6402}))
->RenderUint64("", bit_cast<uint64>(int64{6403}))
->EndList()
->StartList("repI64")
->RenderInt64("", 6404L)
@ -325,8 +325,8 @@ TEST_P(ProtostreamObjectSourceTest, Primitives) {
->RenderInt32("i32", 3203)
->RenderInt32("sf32", 3204)
->RenderInt32("s32", 3205)
->RenderUint64("fix64", bit_cast<uint64>(6401LL))
->RenderUint64("u64", bit_cast<uint64>(6402LL))
->RenderUint64("fix64", bit_cast<uint64>(int64{6401}))
->RenderUint64("u64", bit_cast<uint64>(int64{6402}))
->RenderInt64("i64", 6403L)
->RenderInt64("sf64", 6404L)
->RenderInt64("s64", 6405L)