From bff00b1fe58012fbd06860e34085715d81fb1e52 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Sat, 9 Mar 2019 10:54:54 +1300 Subject: [PATCH 01/14] Add CodedInputReader and CodedOutputWriter --- .gitignore | 3 + Makefile.am | 15 +- conformance/Makefile.am | 1 + csharp/generate_protos.sh | 11 +- csharp/src/AddressBook/Addressbook.cs | 154 +- .../BenchmarkMessage1Proto3.cs | 597 +- .../Google.Protobuf.Benchmarks/Benchmarks.cs | 52 +- .../Google.Protobuf.Benchmarks.csproj | 9 +- .../GoogleMessageBenchmark.cs | 114 + .../src/Google.Protobuf.Benchmarks/Program.cs | 3 +- .../SerializationBenchmark.cs | 82 +- .../SerializationConfig.cs | 16 +- .../WrapperBenchmark.cs | 35 +- .../WrapperBenchmarkMessages.cs | 4900 ++++++++++---- .../Conformance.cs | 276 +- .../Google.Protobuf.Conformance.csproj | 5 + .../Google.Protobuf.Conformance/Program.cs | 89 +- .../Google.Protobuf.Test.TestProtos.csproj | 4 + .../MapUnittestProto3.cs | 413 +- .../TestMessagesProto2.cs | 1325 +++- .../TestMessagesProto3.cs | 1170 +++- .../Unittest.cs | 5948 ++++++++++++++++- .../UnittestCustomOptionsProto3.cs | 791 ++- .../UnittestImport.cs | 39 +- .../UnittestImportProto3.cs | 39 +- .../UnittestImportPublic.cs | 39 +- .../UnittestImportPublicProto3.cs | 39 +- .../UnittestIssue6936B.cs | 31 +- .../UnittestIssue6936C.cs | 42 +- .../UnittestIssues.cs | 600 +- .../UnittestProto3.cs | 2197 +++++- .../UnittestWellKnownTypes.cs | 698 +- .../Buffers/ArrayBufferWriter.cs | 215 + .../Buffers/MaxSizeHintBufferWriter.cs | 66 + .../Buffers/ReadOnlySequenceFactory.cs | 188 + ...mExtensions.cs => CodedInputExtensions.cs} | 18 +- .../CodedInputReaderTest.cs | 396 ++ .../CodedInputStreamTest.cs | 425 +- .../CodedInputTestBase.cs | 279 + .../CodedOutputStreamTest.cs | 387 +- .../CodedOutputTestBase.cs | 268 + .../CodedOutputWriterTest.cs | 282 + .../Collections/RepeatedFieldTest.cs | 55 +- .../Google.Protobuf.Test/ExtensionSetTest.cs | 14 +- .../GeneratedMessageTest.Proto2.cs | 20 +- .../GeneratedMessageTest.cs | 144 +- .../Google.Protobuf.Test.csproj | 4 + .../Google.Protobuf.Test/JsonParserTest.cs | 4 + .../Google.Protobuf.Test/JsonTokenizerTest.cs | 3 + .../MessageParsingHelpers.cs | 145 + .../UnknownFieldSetTest.cs | 24 +- .../WellKnownTypes/WrappersTest.cs | 150 +- csharp/src/Google.Protobuf/ByteString.cs | 7 +- .../src/Google.Protobuf/CodedInputReader.cs | 1198 ++++ .../src/Google.Protobuf/CodedOutputWriter.cs | 666 ++ .../Google.Protobuf/Collections/MapField.cs | 121 +- .../Collections/RepeatedField.cs | 87 +- .../src/Google.Protobuf/ExtensionRegistry.cs | 4 +- csharp/src/Google.Protobuf/ExtensionSet.cs | 48 +- csharp/src/Google.Protobuf/ExtensionValue.cs | 57 +- csharp/src/Google.Protobuf/FieldCodec.cs | 480 +- .../Google.Protobuf/Google.Protobuf.csproj | 21 +- csharp/src/Google.Protobuf/IBufferMessage.cs | 57 + csharp/src/Google.Protobuf/IMessage.cs | 2 +- .../src/Google.Protobuf/MessageExtensions.cs | 25 + csharp/src/Google.Protobuf/MessageParser.cs | 81 + .../Google.Protobuf/Reflection/Descriptor.cs | 1841 ++++- csharp/src/Google.Protobuf/SequenceReader.cs | 417 ++ csharp/src/Google.Protobuf/UnknownField.cs | 53 + csharp/src/Google.Protobuf/UnknownFieldSet.cs | 105 +- .../src/Google.Protobuf/WellKnownTypes/Any.cs | 47 +- .../src/Google.Protobuf/WellKnownTypes/Api.cs | 212 +- .../WellKnownTypes/Duration.cs | 47 +- .../Google.Protobuf/WellKnownTypes/Empty.cs | 31 +- .../WellKnownTypes/FieldMask.cs | 36 +- .../WellKnownTypes/SourceContext.cs | 39 +- .../Google.Protobuf/WellKnownTypes/Struct.cs | 162 +- .../WellKnownTypes/Timestamp.cs | 47 +- .../Google.Protobuf/WellKnownTypes/Type.cs | 351 +- .../WellKnownTypes/Wrappers.cs | 351 +- .../csharp/csharp_bootstrap_unittest.cc | 4 +- .../compiler/csharp/csharp_field_base.cc | 10 +- .../compiler/csharp/csharp_field_base.h | 2 + .../compiler/csharp/csharp_generator.cc | 2 + .../compiler/csharp/csharp_map_field.cc | 13 + .../compiler/csharp/csharp_map_field.h | 2 + .../compiler/csharp/csharp_message.cc | 159 +- .../protobuf/compiler/csharp/csharp_message.h | 3 + .../protobuf/compiler/csharp/csharp_options.h | 7 +- .../csharp/csharp_repeated_enum_field.cc | 13 + .../csharp/csharp_repeated_enum_field.h | 2 + .../csharp/csharp_repeated_message_field.cc | 13 + .../csharp/csharp_repeated_message_field.h | 2 + .../csharp/csharp_repeated_primitive_field.cc | 13 + .../csharp/csharp_repeated_primitive_field.h | 2 + .../compiler/csharp/csharp_wrapper_field.cc | 32 + .../compiler/csharp/csharp_wrapper_field.h | 4 + 97 files changed, 26902 insertions(+), 2798 deletions(-) create mode 100644 csharp/src/Google.Protobuf.Benchmarks/GoogleMessageBenchmark.cs create mode 100644 csharp/src/Google.Protobuf.Test/Buffers/ArrayBufferWriter.cs create mode 100644 csharp/src/Google.Protobuf.Test/Buffers/MaxSizeHintBufferWriter.cs create mode 100644 csharp/src/Google.Protobuf.Test/Buffers/ReadOnlySequenceFactory.cs rename csharp/src/Google.Protobuf.Test/{CodedInputStreamExtensions.cs => CodedInputExtensions.cs} (79%) create mode 100644 csharp/src/Google.Protobuf.Test/CodedInputReaderTest.cs create mode 100644 csharp/src/Google.Protobuf.Test/CodedInputTestBase.cs create mode 100644 csharp/src/Google.Protobuf.Test/CodedOutputTestBase.cs create mode 100644 csharp/src/Google.Protobuf.Test/CodedOutputWriterTest.cs create mode 100644 csharp/src/Google.Protobuf.Test/MessageParsingHelpers.cs create mode 100644 csharp/src/Google.Protobuf/CodedInputReader.cs create mode 100644 csharp/src/Google.Protobuf/CodedOutputWriter.cs create mode 100644 csharp/src/Google.Protobuf/IBufferMessage.cs create mode 100644 csharp/src/Google.Protobuf/SequenceReader.cs diff --git a/.gitignore b/.gitignore index 5e38bbf7c283..bf298f658b50 100644 --- a/.gitignore +++ b/.gitignore @@ -208,3 +208,6 @@ cmake/cmake-build-debug/ # IntelliJ .idea *.iml + +# Visual Studio test coverage +*.coverage diff --git a/Makefile.am b/Makefile.am index 079ac7062bd7..06450a23fc84 100644 --- a/Makefile.am +++ b/Makefile.am @@ -87,6 +87,7 @@ csharp_EXTRA_DIST= \ csharp/src/AddressBook/SampleUsage.cs \ csharp/src/Google.Protobuf.Benchmarks/BenchmarkMessage1Proto3.cs \ csharp/src/Google.Protobuf.Benchmarks/Benchmarks.cs \ + csharp/src/Google.Protobuf.Benchmarks/GoogleMessageBenchmark.cs \ csharp/src/Google.Protobuf.Benchmarks/Google.Protobuf.Benchmarks.csproj \ csharp/src/Google.Protobuf.Benchmarks/Program.cs \ csharp/src/Google.Protobuf.Benchmarks/SerializationBenchmark.cs \ @@ -100,9 +101,16 @@ csharp_EXTRA_DIST= \ csharp/src/Google.Protobuf.JsonDump/Google.Protobuf.JsonDump.csproj \ csharp/src/Google.Protobuf.JsonDump/Program.cs \ csharp/src/Google.Protobuf.Test/ByteStringTest.cs \ - csharp/src/Google.Protobuf.Test/CodedInputStreamExtensions.cs \ + csharp/src/Google.Protobuf.Test/CodedInputExtensions.cs \ + csharp/src/Google.Protobuf.Test/CodedInputReaderTest.cs \ csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs \ + csharp/src/Google.Protobuf.Test/CodedInputTestBase.cs \ csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs \ + csharp/src/Google.Protobuf.Test/CodedOutputWriterTest.cs \ + csharp/src/Google.Protobuf.Test/CodedOutputTestBase.cs \ + csharp/src/Google.Protobuf.Test/Buffers/ArrayBufferWriter.cs \ + csharp/src/Google.Protobuf.Test/Buffers/MaxSizeHintBufferWriter.cs \ + csharp/src/Google.Protobuf.Test/Buffers/ReadOnlySequenceFactory.cs \ csharp/src/Google.Protobuf.Test/Collections/MapFieldTest.cs \ csharp/src/Google.Protobuf.Test/Collections/ProtobufEqualityComparersTest.cs \ csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs \ @@ -121,6 +129,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/MessageParsingHelpers.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 \ @@ -160,8 +169,10 @@ csharp_EXTRA_DIST= \ csharp/src/Google.Protobuf/ByteArray.cs \ csharp/src/Google.Protobuf/ByteString.cs \ csharp/src/Google.Protobuf/CodedInputStream.cs \ + csharp/src/Google.Protobuf/CodedInputReader.cs \ csharp/src/Google.Protobuf/CodedOutputStream.ComputeSize.cs \ csharp/src/Google.Protobuf/CodedOutputStream.cs \ + csharp/src/Google.Protobuf/CodedOutputWriter.cs \ csharp/src/Google.Protobuf/Collections/Lists.cs \ csharp/src/Google.Protobuf/Collections/MapField.cs \ csharp/src/Google.Protobuf/Collections/ProtobufEqualityComparers.cs \ @@ -179,6 +190,7 @@ csharp_EXTRA_DIST= \ csharp/src/Google.Protobuf/FieldMaskTree.cs \ csharp/src/Google.Protobuf/FrameworkPortability.cs \ csharp/src/Google.Protobuf/Google.Protobuf.csproj \ + csharp/src/Google.Protobuf/IBufferMessage.cs \ csharp/src/Google.Protobuf/ICustomDiagnosticMessage.cs \ csharp/src/Google.Protobuf/IDeepCloneable.cs \ csharp/src/Google.Protobuf/IExtendableMessage.cs \ @@ -225,6 +237,7 @@ csharp_EXTRA_DIST= \ csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs \ csharp/src/Google.Protobuf/Reflection/SingleFieldAccessor.cs \ csharp/src/Google.Protobuf/Reflection/TypeRegistry.cs \ + csharp/src/Google.Protobuf/SequenceReader.cs \ csharp/src/Google.Protobuf/WellKnownTypes/Any.cs \ csharp/src/Google.Protobuf/WellKnownTypes/AnyPartial.cs \ csharp/src/Google.Protobuf/WellKnownTypes/Api.cs \ diff --git a/conformance/Makefile.am b/conformance/Makefile.am index 6815c733a522..6e0505b41355 100644 --- a/conformance/Makefile.am +++ b/conformance/Makefile.am @@ -343,6 +343,7 @@ test_java_lite: protoc_middleman conformance-test-runner conformance-java-lite test_csharp: protoc_middleman conformance-test-runner conformance-csharp ./conformance-test-runner --enforce_recommended --failure_list failure_list_csharp.txt --text_format_failure_list text_format_failure_list_csharp.txt ./conformance-csharp + ./conformance-test-runner --enforce_recommended --failure_list failure_list_csharp.txt --text_format_failure_list text_format_failure_list_csharp.txt ./conformance-csharp --use_buffer_serialization test_ruby: protoc_middleman conformance-test-runner $(other_language_protoc_outputs) RUBYLIB=../ruby/lib:. ./conformance-test-runner --enforce_recommended --failure_list failure_list_ruby.txt --text_format_failure_list text_format_failure_list_ruby.txt ./conformance_ruby.rb diff --git a/csharp/generate_protos.sh b/csharp/generate_protos.sh index e6687c308e47..c4285ce6e508 100755 --- a/csharp/generate_protos.sh +++ b/csharp/generate_protos.sh @@ -27,7 +27,7 @@ fi # descriptor.proto and well-known types $PROTOC -Isrc --csharp_out=csharp/src/Google.Protobuf \ - --csharp_opt=base_namespace=Google.Protobuf \ + --csharp_opt=base_namespace=Google.Protobuf,use_buffer_serialization \ src/google/protobuf/descriptor.proto \ src/google/protobuf/any.proto \ src/google/protobuf/api.proto \ @@ -46,6 +46,7 @@ $PROTOC -Isrc --csharp_out=csharp/src/Google.Protobuf \ # of protoc. $PROTOC -Isrc -Icsharp/protos \ --csharp_out=csharp/src/Google.Protobuf.Test.TestProtos \ + --csharp_opt=use_buffer_serialization \ --descriptor_set_out=csharp/src/Google.Protobuf.Test/testprotos.pb \ --include_source_info \ --include_imports \ @@ -67,18 +68,22 @@ $PROTOC -Isrc -Icsharp/protos \ # AddressBook sample protos $PROTOC -Iexamples -Isrc --csharp_out=csharp/src/AddressBook \ + --csharp_opt=use_buffer_serialization \ examples/addressbook.proto $PROTOC -Iconformance -Isrc --csharp_out=csharp/src/Google.Protobuf.Conformance \ + --csharp_opt=use_buffer_serialization \ conformance/conformance.proto # Benchmark protos $PROTOC -Ibenchmarks \ benchmarks/datasets/google_message1/proto3/*.proto \ benchmarks/benchmarks.proto \ - --csharp_out=csharp/src/Google.Protobuf.Benchmarks + --csharp_out=csharp/src/Google.Protobuf.Benchmarks \ + --csharp_opt=use_buffer_serialization # C# only benchmark protos $PROTOC -Isrc -Icsharp/src/Google.Protobuf.Benchmarks \ csharp/src/Google.Protobuf.Benchmarks/*.proto \ - --csharp_out=csharp/src/Google.Protobuf.Benchmarks + --csharp_out=csharp/src/Google.Protobuf.Benchmarks \ + --csharp_opt=use_buffer_serialization diff --git a/csharp/src/AddressBook/Addressbook.cs b/csharp/src/AddressBook/Addressbook.cs index cbd977269620..9e90930d2c9b 100644 --- a/csharp/src/AddressBook/Addressbook.cs +++ b/csharp/src/AddressBook/Addressbook.cs @@ -49,7 +49,11 @@ static AddressbookReflection() { /// /// [START messages] /// - public sealed partial class Person : pb::IMessage { + public sealed partial class Person : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Person()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -208,6 +212,33 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Name.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Name); + } + if (Id != 0) { + output.WriteRawTag(16); + output.WriteInt32(Id); + } + if (Email.Length != 0) { + output.WriteRawTag(26); + output.WriteString(Email); + } + phones_.WriteTo(ref output, _repeated_phones_codec); + if (lastUpdated_ != null) { + output.WriteRawTag(42); + output.WriteMessage(LastUpdated); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -289,6 +320,44 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 16: { + Id = input.ReadInt32(); + break; + } + case 26: { + Email = input.ReadString(); + break; + } + case 34: { + phones_.AddEntriesFrom(ref input, _repeated_phones_codec); + break; + } + case 42: { + if (lastUpdated_ == null) { + LastUpdated = new global::Google.Protobuf.WellKnownTypes.Timestamp(); + } + input.ReadMessage(LastUpdated); + break; + } + } + } + } + #endif + #region Nested types /// Container for nested types declared in the Person message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -299,7 +368,11 @@ public enum PhoneType { [pbr::OriginalName("WORK")] Work = 2, } - public sealed partial class PhoneNumber : pb::IMessage { + public sealed partial class PhoneNumber : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new PhoneNumber()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -405,6 +478,24 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Number.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Number); + } + if (Type != global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneType.Mobile) { + output.WriteRawTag(16); + output.WriteEnum((int) Type); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -454,6 +545,29 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Number = input.ReadString(); + break; + } + case 16: { + Type = (global::Google.Protobuf.Examples.AddressBook.Person.Types.PhoneType) input.ReadEnum(); + break; + } + } + } + } + #endif + } } @@ -464,7 +578,11 @@ public void MergeFrom(pb::CodedInputStream input) { /// /// Our address book file is just one of these. /// - public sealed partial class AddressBook : pb::IMessage { + public sealed partial class AddressBook : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new AddressBook()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -548,6 +666,17 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + people_.WriteTo(ref output, _repeated_people_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -583,6 +712,25 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + people_.AddEntriesFrom(ref input, _repeated_people_codec); + break; + } + } + } + } + #endif + } #endregion diff --git a/csharp/src/Google.Protobuf.Benchmarks/BenchmarkMessage1Proto3.cs b/csharp/src/Google.Protobuf.Benchmarks/BenchmarkMessage1Proto3.cs index 9e8c330a2b63..b1231c100269 100644 --- a/csharp/src/Google.Protobuf.Benchmarks/BenchmarkMessage1Proto3.cs +++ b/csharp/src/Google.Protobuf.Benchmarks/BenchmarkMessage1Proto3.cs @@ -64,7 +64,11 @@ static BenchmarkMessage1Proto3Reflection() { } #region Messages - public sealed partial class GoogleMessage1 : pb::IMessage { + public sealed partial class GoogleMessage1 : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new GoogleMessage1()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -868,6 +872,177 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Field1.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Field1); + } + if (Field2 != 0) { + output.WriteRawTag(16); + output.WriteInt32(Field2); + } + if (Field3 != 0) { + output.WriteRawTag(24); + output.WriteInt32(Field3); + } + if (Field4.Length != 0) { + output.WriteRawTag(34); + output.WriteString(Field4); + } + field5_.WriteTo(ref output, _repeated_field5_codec); + if (Field6 != 0) { + output.WriteRawTag(48); + output.WriteInt32(Field6); + } + if (Field7.Length != 0) { + output.WriteRawTag(58); + output.WriteString(Field7); + } + if (Field9.Length != 0) { + output.WriteRawTag(74); + output.WriteString(Field9); + } + if (Field12 != false) { + output.WriteRawTag(96); + output.WriteBool(Field12); + } + if (Field13 != false) { + output.WriteRawTag(104); + output.WriteBool(Field13); + } + if (Field14 != false) { + output.WriteRawTag(112); + output.WriteBool(Field14); + } + if (field15_ != null) { + output.WriteRawTag(122); + output.WriteMessage(Field15); + } + if (Field16 != 0) { + output.WriteRawTag(128, 1); + output.WriteInt32(Field16); + } + if (Field17 != false) { + output.WriteRawTag(136, 1); + output.WriteBool(Field17); + } + if (Field18.Length != 0) { + output.WriteRawTag(146, 1); + output.WriteString(Field18); + } + if (Field22 != 0L) { + output.WriteRawTag(176, 1); + output.WriteInt64(Field22); + } + if (Field23 != 0) { + output.WriteRawTag(184, 1); + output.WriteInt32(Field23); + } + if (Field24 != false) { + output.WriteRawTag(192, 1); + output.WriteBool(Field24); + } + if (Field25 != 0) { + output.WriteRawTag(200, 1); + output.WriteInt32(Field25); + } + if (Field29 != 0) { + output.WriteRawTag(232, 1); + output.WriteInt32(Field29); + } + if (Field30 != false) { + output.WriteRawTag(240, 1); + output.WriteBool(Field30); + } + if (Field59 != false) { + output.WriteRawTag(216, 3); + output.WriteBool(Field59); + } + if (Field60 != 0) { + output.WriteRawTag(224, 3); + output.WriteInt32(Field60); + } + if (Field67 != 0) { + output.WriteRawTag(152, 4); + output.WriteInt32(Field67); + } + if (Field68 != 0) { + output.WriteRawTag(160, 4); + output.WriteInt32(Field68); + } + if (Field78 != false) { + output.WriteRawTag(240, 4); + output.WriteBool(Field78); + } + if (Field80 != false) { + output.WriteRawTag(128, 5); + output.WriteBool(Field80); + } + if (Field81 != false) { + output.WriteRawTag(136, 5); + output.WriteBool(Field81); + } + if (Field100 != 0) { + output.WriteRawTag(160, 6); + output.WriteInt32(Field100); + } + if (Field101 != 0) { + output.WriteRawTag(168, 6); + output.WriteInt32(Field101); + } + if (Field102.Length != 0) { + output.WriteRawTag(178, 6); + output.WriteString(Field102); + } + if (Field103.Length != 0) { + output.WriteRawTag(186, 6); + output.WriteString(Field103); + } + if (Field104 != 0) { + output.WriteRawTag(192, 6); + output.WriteInt32(Field104); + } + if (Field128 != 0) { + output.WriteRawTag(128, 8); + output.WriteInt32(Field128); + } + if (Field129.Length != 0) { + output.WriteRawTag(138, 8); + output.WriteString(Field129); + } + if (Field130 != 0) { + output.WriteRawTag(144, 8); + output.WriteInt32(Field130); + } + if (Field131 != 0) { + output.WriteRawTag(152, 8); + output.WriteInt32(Field131); + } + if (Field150 != 0) { + output.WriteRawTag(176, 9); + output.WriteInt32(Field150); + } + if (Field271 != 0) { + output.WriteRawTag(248, 16); + output.WriteInt32(Field271); + } + if (Field272 != 0) { + output.WriteRawTag(128, 17); + output.WriteInt32(Field272); + } + if (Field280 != 0) { + output.WriteRawTag(192, 17); + output.WriteInt32(Field280); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -1107,36 +1282,218 @@ public void MergeFrom(GoogleMessage1 other) { if (field15_ == null) { Field15 = new global::Benchmarks.Proto3.GoogleMessage1SubMessage(); } - Field15.MergeFrom(other.Field15); - } - if (other.Field78 != false) { - Field78 = other.Field78; - } - if (other.Field67 != 0) { - Field67 = other.Field67; - } - if (other.Field68 != 0) { - Field68 = other.Field68; - } - if (other.Field128 != 0) { - Field128 = other.Field128; - } - if (other.Field129.Length != 0) { - Field129 = other.Field129; - } - if (other.Field131 != 0) { - Field131 = other.Field131; + Field15.MergeFrom(other.Field15); + } + if (other.Field78 != false) { + Field78 = other.Field78; + } + if (other.Field67 != 0) { + Field67 = other.Field67; + } + if (other.Field68 != 0) { + Field68 = other.Field68; + } + if (other.Field128 != 0) { + Field128 = other.Field128; + } + if (other.Field129.Length != 0) { + Field129 = other.Field129; + } + if (other.Field131 != 0) { + Field131 = other.Field131; + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + Field1 = input.ReadString(); + break; + } + case 16: { + Field2 = input.ReadInt32(); + break; + } + case 24: { + Field3 = input.ReadInt32(); + break; + } + case 34: { + Field4 = input.ReadString(); + break; + } + case 42: + case 41: { + field5_.AddEntriesFrom(input, _repeated_field5_codec); + break; + } + case 48: { + Field6 = input.ReadInt32(); + break; + } + case 58: { + Field7 = input.ReadString(); + break; + } + case 74: { + Field9 = input.ReadString(); + break; + } + case 96: { + Field12 = input.ReadBool(); + break; + } + case 104: { + Field13 = input.ReadBool(); + break; + } + case 112: { + Field14 = input.ReadBool(); + break; + } + case 122: { + if (field15_ == null) { + Field15 = new global::Benchmarks.Proto3.GoogleMessage1SubMessage(); + } + input.ReadMessage(Field15); + break; + } + case 128: { + Field16 = input.ReadInt32(); + break; + } + case 136: { + Field17 = input.ReadBool(); + break; + } + case 146: { + Field18 = input.ReadString(); + break; + } + case 176: { + Field22 = input.ReadInt64(); + break; + } + case 184: { + Field23 = input.ReadInt32(); + break; + } + case 192: { + Field24 = input.ReadBool(); + break; + } + case 200: { + Field25 = input.ReadInt32(); + break; + } + case 232: { + Field29 = input.ReadInt32(); + break; + } + case 240: { + Field30 = input.ReadBool(); + break; + } + case 472: { + Field59 = input.ReadBool(); + break; + } + case 480: { + Field60 = input.ReadInt32(); + break; + } + case 536: { + Field67 = input.ReadInt32(); + break; + } + case 544: { + Field68 = input.ReadInt32(); + break; + } + case 624: { + Field78 = input.ReadBool(); + break; + } + case 640: { + Field80 = input.ReadBool(); + break; + } + case 648: { + Field81 = input.ReadBool(); + break; + } + case 800: { + Field100 = input.ReadInt32(); + break; + } + case 808: { + Field101 = input.ReadInt32(); + break; + } + case 818: { + Field102 = input.ReadString(); + break; + } + case 826: { + Field103 = input.ReadString(); + break; + } + case 832: { + Field104 = input.ReadInt32(); + break; + } + case 1024: { + Field128 = input.ReadInt32(); + break; + } + case 1034: { + Field129 = input.ReadString(); + break; + } + case 1040: { + Field130 = input.ReadInt32(); + break; + } + case 1048: { + Field131 = input.ReadInt32(); + break; + } + case 1200: { + Field150 = input.ReadInt32(); + break; + } + case 2168: { + Field271 = input.ReadInt32(); + break; + } + case 2176: { + Field272 = input.ReadInt32(); + break; + } + case 2240: { + Field280 = input.ReadInt32(); + break; + } + } } - _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void MergeFrom(pb::CodedInputStream input) { + public void MergeFrom(ref pb::CodedInputReader input) { uint tag; while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); break; case 10: { Field1 = input.ReadString(); @@ -1156,7 +1513,7 @@ public void MergeFrom(pb::CodedInputStream input) { } case 42: case 41: { - field5_.AddEntriesFrom(input, _repeated_field5_codec); + field5_.AddEntriesFrom(ref input, _repeated_field5_codec); break; } case 48: { @@ -1309,10 +1666,15 @@ public void MergeFrom(pb::CodedInputStream input) { } } } + #endif } - public sealed partial class GoogleMessage1SubMessage : pb::IMessage { + public sealed partial class GoogleMessage1SubMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new GoogleMessage1SubMessage()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -1742,6 +2104,96 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Field1 != 0) { + output.WriteRawTag(8); + output.WriteInt32(Field1); + } + if (Field2 != 0) { + output.WriteRawTag(16); + output.WriteInt32(Field2); + } + if (Field3 != 0) { + output.WriteRawTag(24); + output.WriteInt32(Field3); + } + if (Field12 != false) { + output.WriteRawTag(96); + output.WriteBool(Field12); + } + if (Field13 != 0L) { + output.WriteRawTag(104); + output.WriteInt64(Field13); + } + if (Field14 != 0L) { + output.WriteRawTag(112); + output.WriteInt64(Field14); + } + if (Field15.Length != 0) { + output.WriteRawTag(122); + output.WriteString(Field15); + } + if (Field16 != 0) { + output.WriteRawTag(128, 1); + output.WriteInt32(Field16); + } + if (Field19 != 0) { + output.WriteRawTag(152, 1); + output.WriteInt32(Field19); + } + if (Field20 != false) { + output.WriteRawTag(160, 1); + output.WriteBool(Field20); + } + if (Field21 != 0UL) { + output.WriteRawTag(169, 1); + output.WriteFixed64(Field21); + } + if (Field22 != 0) { + output.WriteRawTag(176, 1); + output.WriteInt32(Field22); + } + if (Field23 != false) { + output.WriteRawTag(184, 1); + output.WriteBool(Field23); + } + if (Field28 != false) { + output.WriteRawTag(224, 1); + output.WriteBool(Field28); + } + if (Field203 != 0) { + output.WriteRawTag(221, 12); + output.WriteFixed32(Field203); + } + if (Field204 != 0) { + output.WriteRawTag(224, 12); + output.WriteInt32(Field204); + } + if (Field205.Length != 0) { + output.WriteRawTag(234, 12); + output.WriteString(Field205); + } + if (Field206 != false) { + output.WriteRawTag(240, 12); + output.WriteBool(Field206); + } + if (Field207 != 0UL) { + output.WriteRawTag(248, 12); + output.WriteUInt64(Field207); + } + if (Field300 != 0UL) { + output.WriteRawTag(224, 18); + output.WriteUInt64(Field300); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -1971,6 +2423,101 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Field1 = input.ReadInt32(); + break; + } + case 16: { + Field2 = input.ReadInt32(); + break; + } + case 24: { + Field3 = input.ReadInt32(); + break; + } + case 96: { + Field12 = input.ReadBool(); + break; + } + case 104: { + Field13 = input.ReadInt64(); + break; + } + case 112: { + Field14 = input.ReadInt64(); + break; + } + case 122: { + Field15 = input.ReadString(); + break; + } + case 128: { + Field16 = input.ReadInt32(); + break; + } + case 152: { + Field19 = input.ReadInt32(); + break; + } + case 160: { + Field20 = input.ReadBool(); + break; + } + case 169: { + Field21 = input.ReadFixed64(); + break; + } + case 176: { + Field22 = input.ReadInt32(); + break; + } + case 184: { + Field23 = input.ReadBool(); + break; + } + case 224: { + Field28 = input.ReadBool(); + break; + } + case 1629: { + Field203 = input.ReadFixed32(); + break; + } + case 1632: { + Field204 = input.ReadInt32(); + break; + } + case 1642: { + Field205 = input.ReadString(); + break; + } + case 1648: { + Field206 = input.ReadBool(); + break; + } + case 1656: { + Field207 = input.ReadUInt64(); + break; + } + case 2400: { + Field300 = input.ReadUInt64(); + break; + } + } + } + } + #endif + } #endregion diff --git a/csharp/src/Google.Protobuf.Benchmarks/Benchmarks.cs b/csharp/src/Google.Protobuf.Benchmarks/Benchmarks.cs index 01dfcd72dc6f..ada355df0d0e 100644 --- a/csharp/src/Google.Protobuf.Benchmarks/Benchmarks.cs +++ b/csharp/src/Google.Protobuf.Benchmarks/Benchmarks.cs @@ -38,7 +38,11 @@ static BenchmarksReflection() { } #region Messages - public sealed partial class BenchmarkDataset : pb::IMessage { + public sealed partial class BenchmarkDataset : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new BenchmarkDataset()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -186,6 +190,25 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Name.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Name); + } + if (MessageName.Length != 0) { + output.WriteRawTag(18); + output.WriteString(MessageName); + } + payload_.WriteTo(ref output, _repeated_payload_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -241,6 +264,33 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + MessageName = input.ReadString(); + break; + } + case 26: { + payload_.AddEntriesFrom(ref input, _repeated_payload_codec); + break; + } + } + } + } + #endif + } #endregion diff --git a/csharp/src/Google.Protobuf.Benchmarks/Google.Protobuf.Benchmarks.csproj b/csharp/src/Google.Protobuf.Benchmarks/Google.Protobuf.Benchmarks.csproj index ecc064ea7d09..ea39409f0817 100644 --- a/csharp/src/Google.Protobuf.Benchmarks/Google.Protobuf.Benchmarks.csproj +++ b/csharp/src/Google.Protobuf.Benchmarks/Google.Protobuf.Benchmarks.csproj @@ -2,15 +2,20 @@ Exe - netcoreapp2.1 + netcoreapp3.0 False + $(DefineConstants);GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY - + + + + + diff --git a/csharp/src/Google.Protobuf.Benchmarks/GoogleMessageBenchmark.cs b/csharp/src/Google.Protobuf.Benchmarks/GoogleMessageBenchmark.cs new file mode 100644 index 000000000000..2720f75ba2bc --- /dev/null +++ b/csharp/src/Google.Protobuf.Benchmarks/GoogleMessageBenchmark.cs @@ -0,0 +1,114 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2019 Google Inc. All rights reserved. +// https://github.com/protocolbuffers/protobuf +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + +using System; +using System.IO; +using Benchmarks; +using Benchmarks.Proto3; + +namespace Google.Protobuf.Benchmarks +{ + public static class GoogleMessageBenchmark + { + public static ByteString GetMessageData(MessageSize messageSize) + { + var ms = new MemoryStream(); + var output = new CodedOutputStream(ms); + + var googleMessage1 = new GoogleMessage1(); + switch (messageSize) + { + case MessageSize.Empty: + break; + case MessageSize.Small: + SetString(googleMessage1, 1); + AddRepeatingItems(googleMessage1, 1); + googleMessage1.Field2 = 2; + googleMessage1.Field15 = new GoogleMessage1SubMessage(); + googleMessage1.Field15.Field1 = 1; + break; + case MessageSize.Medium: + SetString(googleMessage1, 1024); + AddRepeatingItems(googleMessage1, 1024); + googleMessage1.Field2 = 2; + googleMessage1.Field15 = new GoogleMessage1SubMessage(); + googleMessage1.Field15.Field1 = 1; + break; + case MessageSize.Large: + SetString(googleMessage1, 1024 * 512); + AddRepeatingItems(googleMessage1, 1024 * 512); + googleMessage1.Field2 = 2; + googleMessage1.Field15 = new GoogleMessage1SubMessage(); + googleMessage1.Field15.Field1 = 1; + break; + default: + throw new ArgumentOutOfRangeException(nameof(MessageSize)); + } + + googleMessage1.WriteTo(output); + output.Flush(); + + return ByteString.CopyFrom(ms.ToArray()); + } + + private static void SetString(GoogleMessage1 googleMessage1, int count) + { + googleMessage1.Field1 = "Text" + new string('!', count); + } + + private static void AddRepeatingItems(GoogleMessage1 googleMessage1, ulong count) + { + for (var i = 0UL; i < count; i++) + { + googleMessage1.Field5.Add(i); + } + } + + public static SerializationConfig CreateGoogleMessageConfig(MessageSize messageSize) + { + return new SerializationConfig(new BenchmarkDataset + { + MessageName = "benchmarks.proto3.GoogleMessage1", + Name = "GoogleMessage1 " + messageSize, + Payload = { GoogleMessageBenchmark.GetMessageData(messageSize) } + }); + } + } + + public enum MessageSize + { + Empty, + Small, + Medium, + Large + } +} diff --git a/csharp/src/Google.Protobuf.Benchmarks/Program.cs b/csharp/src/Google.Protobuf.Benchmarks/Program.cs index 1f77a26135eb..7acdd38184bd 100644 --- a/csharp/src/Google.Protobuf.Benchmarks/Program.cs +++ b/csharp/src/Google.Protobuf.Benchmarks/Program.cs @@ -30,6 +30,7 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endregion +using System; using BenchmarkDotNet.Running; namespace Google.Protobuf.Benchmarks @@ -44,6 +45,4 @@ public static void Main(string[] args) BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args); } } - - } diff --git a/csharp/src/Google.Protobuf.Benchmarks/SerializationBenchmark.cs b/csharp/src/Google.Protobuf.Benchmarks/SerializationBenchmark.cs index d8c2ec11d73e..61edaf7c0fa4 100644 --- a/csharp/src/Google.Protobuf.Benchmarks/SerializationBenchmark.cs +++ b/csharp/src/Google.Protobuf.Benchmarks/SerializationBenchmark.cs @@ -31,6 +31,9 @@ #endregion using BenchmarkDotNet.Attributes; +using Benchmarks; +using Google.Protobuf.Buffers; +using System.Buffers; using System.Collections.Generic; using System.IO; using System.Linq; @@ -50,7 +53,11 @@ public class SerializationBenchmark /// public static SerializationConfig[] Configurations => new[] { - new SerializationConfig("dataset.google_message1_proto3.pb") + new SerializationConfig("dataset.google_message1_proto3.pb"), + GoogleMessageBenchmark.CreateGoogleMessageConfig(MessageSize.Empty), + GoogleMessageBenchmark.CreateGoogleMessageConfig(MessageSize.Small), + GoogleMessageBenchmark.CreateGoogleMessageConfig(MessageSize.Medium), + GoogleMessageBenchmark.CreateGoogleMessageConfig(MessageSize.Large) }; [ParamsSource(nameof(Configurations))] @@ -68,32 +75,78 @@ public class SerializationBenchmark public void GlobalSetup() { parser = Configuration.Parser; - subTests = Configuration.Payloads.Select(p => new SubTest(p, parser.ParseFrom(p))).ToList(); + subTests = Configuration.Payloads.Select(p => new SubTest(p, (IBufferMessage)parser.ParseFrom(p))).ToList(); } [Benchmark] - public void WriteToStream() => subTests.ForEach(item => item.WriteToStream()); + public void WriteToStream() + { + foreach (var subTest in subTests) + { + subTest.WriteToStream(); + } + } [Benchmark] - public void ToByteArray() => subTests.ForEach(item => item.ToByteArray()); + public void WriteToBufferWriter() + { + foreach (var subTest in subTests) + { + subTest.WriteToBufferWriter(); + } + } + + [Benchmark] + public void ToByteArray() + { + foreach (var subTest in subTests) + { + subTest.ToByteArray(); + } + } + + [Benchmark] + public void ParseFromByteString() + { + foreach (var subTest in subTests) + { + subTest.ParseFromByteString(parser); + } + } [Benchmark] - public void ParseFromByteString() => subTests.ForEach(item => item.ParseFromByteString(parser)); + public void ParseFromStream() + { + foreach (var subTest in subTests) + { + subTest.ParseFromStream(parser); + } + } [Benchmark] - public void ParseFromStream() => subTests.ForEach(item => item.ParseFromStream(parser)); + public void ParseFromReadOnlySequence() + { + foreach (var subTest in subTests) + { + subTest.ParseFromReadOnlySequence(parser); + } + } private class SubTest { private readonly Stream destinationStream; + private readonly Google.Protobuf.Buffers.ArrayBufferWriter bufferWriter; private readonly Stream sourceStream; + private readonly ReadOnlySequence readOnlySequence; private readonly ByteString data; - private readonly IMessage message; + private readonly IBufferMessage message; - public SubTest(ByteString data, IMessage message) + public SubTest(ByteString data, IBufferMessage message) { destinationStream = new MemoryStream(data.Length); + bufferWriter = new Google.Protobuf.Buffers.ArrayBufferWriter(); sourceStream = new MemoryStream(data.ToByteArray()); + readOnlySequence = new ReadOnlySequence(data.ToByteArray()); this.data = data; this.message = message; } @@ -106,6 +159,13 @@ public void WriteToStream() message.WriteTo(destinationStream); } + public void WriteToBufferWriter() + { + bufferWriter.Clear(); + var writer = new CodedOutputWriter(bufferWriter); + message.WriteTo(ref writer); + } + public void ToByteArray() => message.ToByteArray(); public void ParseFromByteString(MessageParser parser) => parser.ParseFrom(data); @@ -115,6 +175,12 @@ public void ParseFromStream(MessageParser parser) sourceStream.Position = 0; parser.ParseFrom(sourceStream); } + + public void ParseFromReadOnlySequence(MessageParser parser) + { + var reader = new CodedInputReader(readOnlySequence); + parser.ParseFrom(ref reader); + } } } } diff --git a/csharp/src/Google.Protobuf.Benchmarks/SerializationConfig.cs b/csharp/src/Google.Protobuf.Benchmarks/SerializationConfig.cs index 679f16cb9a87..6c3fe86c8aff 100644 --- a/csharp/src/Google.Protobuf.Benchmarks/SerializationConfig.cs +++ b/csharp/src/Google.Protobuf.Benchmarks/SerializationConfig.cs @@ -52,15 +52,25 @@ public class SerializationConfig t => ((MessageDescriptor) t.GetProperty("Descriptor", BindingFlags.Static | BindingFlags.Public).GetValue(null)).FullName, t => ((MessageParser) t.GetProperty("Parser", BindingFlags.Static | BindingFlags.Public).GetValue(null))); - public MessageParser Parser { get; } - public IEnumerable Payloads { get; } - public string Name { get; } + public MessageParser Parser { get; private set; } + public IEnumerable Payloads { get; private set; } + public string Name { get; private set; } public SerializationConfig(string resource) { var data = LoadData(resource); var dataset = BenchmarkDataset.Parser.ParseFrom(data); + Initialize(dataset); + } + + public SerializationConfig(BenchmarkDataset dataset) + { + Initialize(dataset); + } + + private void Initialize(BenchmarkDataset dataset) + { if (!parsersByMessageName.TryGetValue(dataset.MessageName, out var parser)) { throw new ArgumentException($"No parser for message {dataset.MessageName} in this assembly"); diff --git a/csharp/src/Google.Protobuf.Benchmarks/WrapperBenchmark.cs b/csharp/src/Google.Protobuf.Benchmarks/WrapperBenchmark.cs index ae17c1819af0..39256e24b37b 100644 --- a/csharp/src/Google.Protobuf.Benchmarks/WrapperBenchmark.cs +++ b/csharp/src/Google.Protobuf.Benchmarks/WrapperBenchmark.cs @@ -31,6 +31,7 @@ #endregion using BenchmarkDotNet.Attributes; +using System.Buffers; using System.Collections.Generic; using System.IO; using System.Linq; @@ -43,26 +44,44 @@ namespace Google.Protobuf.Benchmarks [MemoryDiagnoser] public class WrapperBenchmark { - byte[] manyWrapperFieldsData; - byte[] manyPrimitiveFieldsData; + byte[] manyWrapperFieldsByteArray; + ReadOnlySequence manyWrapperFieldsReadOnlySequence; + byte[] manyPrimitiveFieldsByteArray; + ReadOnlySequence manyPrimitiveFieldsReadOnlySequence; [GlobalSetup] public void GlobalSetup() { - manyWrapperFieldsData = CreateManyWrapperFieldsMessage().ToByteArray(); - manyPrimitiveFieldsData = CreateManyPrimitiveFieldsMessage().ToByteArray(); + manyWrapperFieldsByteArray = CreateManyWrapperFieldsMessage().ToByteArray(); + manyWrapperFieldsReadOnlySequence = new ReadOnlySequence(manyWrapperFieldsByteArray); + manyPrimitiveFieldsByteArray = CreateManyPrimitiveFieldsMessage().ToByteArray(); + manyPrimitiveFieldsReadOnlySequence = new ReadOnlySequence(manyPrimitiveFieldsByteArray); } [Benchmark] - public ManyWrapperFieldsMessage ParseWrapperFields() + public ManyWrapperFieldsMessage ParseWrapperFieldsFromByteArray() { - return ManyWrapperFieldsMessage.Parser.ParseFrom(manyWrapperFieldsData); + return ManyWrapperFieldsMessage.Parser.ParseFrom(manyWrapperFieldsByteArray); } [Benchmark] - public ManyPrimitiveFieldsMessage ParsePrimitiveFields() + public ManyWrapperFieldsMessage ParseWrapperFieldsFromReadOnlySequence() { - return ManyPrimitiveFieldsMessage.Parser.ParseFrom(manyPrimitiveFieldsData); + var input = new CodedInputReader(manyWrapperFieldsReadOnlySequence); + return ManyWrapperFieldsMessage.Parser.ParseFrom(ref input); + } + + [Benchmark] + public ManyPrimitiveFieldsMessage ParsePrimitiveFieldsFromByteArray() + { + return ManyPrimitiveFieldsMessage.Parser.ParseFrom(manyPrimitiveFieldsByteArray); + } + + [Benchmark] + public ManyPrimitiveFieldsMessage ParsePrimitiveFieldsFromReadOnlySequence() + { + var input = new CodedInputReader(manyPrimitiveFieldsReadOnlySequence); + return ManyPrimitiveFieldsMessage.Parser.ParseFrom(ref input); } private static ManyWrapperFieldsMessage CreateManyWrapperFieldsMessage() diff --git a/csharp/src/Google.Protobuf.Benchmarks/WrapperBenchmarkMessages.cs b/csharp/src/Google.Protobuf.Benchmarks/WrapperBenchmarkMessages.cs index 0cc86e2ad406..3b29e5a13be1 100644 --- a/csharp/src/Google.Protobuf.Benchmarks/WrapperBenchmarkMessages.cs +++ b/csharp/src/Google.Protobuf.Benchmarks/WrapperBenchmarkMessages.cs @@ -237,7 +237,11 @@ static WrapperBenchmarkMessagesReflection() { /// a message that has a large number of wrapper fields /// obfuscated version of an internal message /// - public sealed partial class ManyWrapperFieldsMessage : pb::IMessage { + public sealed partial class ManyWrapperFieldsMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ManyWrapperFieldsMessage()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -2408,6 +2412,350 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (doubleField1_ != null) { + _single_doubleField1_codec.WriteTagAndValue(ref output, DoubleField1); + } + if (int64Field2_ != null) { + _single_int64Field2_codec.WriteTagAndValue(ref output, Int64Field2); + } + if (int64Field3_ != null) { + _single_int64Field3_codec.WriteTagAndValue(ref output, Int64Field3); + } + if (int64Field4_ != null) { + _single_int64Field4_codec.WriteTagAndValue(ref output, Int64Field4); + } + if (doubleField7_ != null) { + _single_doubleField7_codec.WriteTagAndValue(ref output, DoubleField7); + } + if (doubleField8_ != null) { + _single_doubleField8_codec.WriteTagAndValue(ref output, DoubleField8); + } + if (doubleField9_ != null) { + _single_doubleField9_codec.WriteTagAndValue(ref output, DoubleField9); + } + if (doubleField10_ != null) { + _single_doubleField10_codec.WriteTagAndValue(ref output, DoubleField10); + } + if (doubleField11_ != null) { + _single_doubleField11_codec.WriteTagAndValue(ref output, DoubleField11); + } + if (doubleField14_ != null) { + _single_doubleField14_codec.WriteTagAndValue(ref output, DoubleField14); + } + if (doubleField15_ != null) { + _single_doubleField15_codec.WriteTagAndValue(ref output, DoubleField15); + } + if (int64Field19_ != null) { + _single_int64Field19_codec.WriteTagAndValue(ref output, Int64Field19); + } + if (doubleField20_ != null) { + _single_doubleField20_codec.WriteTagAndValue(ref output, DoubleField20); + } + if (doubleField21_ != null) { + _single_doubleField21_codec.WriteTagAndValue(ref output, DoubleField21); + } + if (doubleField22_ != null) { + _single_doubleField22_codec.WriteTagAndValue(ref output, DoubleField22); + } + if (doubleField25_ != null) { + _single_doubleField25_codec.WriteTagAndValue(ref output, DoubleField25); + } + if (int64Field26_ != null) { + _single_int64Field26_codec.WriteTagAndValue(ref output, Int64Field26); + } + if (doubleField28_ != null) { + _single_doubleField28_codec.WriteTagAndValue(ref output, DoubleField28); + } + if (doubleField29_ != null) { + _single_doubleField29_codec.WriteTagAndValue(ref output, DoubleField29); + } + if (doubleField30_ != null) { + _single_doubleField30_codec.WriteTagAndValue(ref output, DoubleField30); + } + if (doubleField31_ != null) { + _single_doubleField31_codec.WriteTagAndValue(ref output, DoubleField31); + } + if (int64Field32_ != null) { + _single_int64Field32_codec.WriteTagAndValue(ref output, Int64Field32); + } + if (int64Field37_ != null) { + _single_int64Field37_codec.WriteTagAndValue(ref output, Int64Field37); + } + if (doubleField38_ != null) { + _single_doubleField38_codec.WriteTagAndValue(ref output, DoubleField38); + } + if (interactions_ != null) { + _single_interactions_codec.WriteTagAndValue(ref output, Interactions); + } + if (doubleField40_ != null) { + _single_doubleField40_codec.WriteTagAndValue(ref output, DoubleField40); + } + if (int64Field41_ != null) { + _single_int64Field41_codec.WriteTagAndValue(ref output, Int64Field41); + } + if (doubleField42_ != null) { + _single_doubleField42_codec.WriteTagAndValue(ref output, DoubleField42); + } + if (int64Field43_ != null) { + _single_int64Field43_codec.WriteTagAndValue(ref output, Int64Field43); + } + if (int64Field44_ != null) { + _single_int64Field44_codec.WriteTagAndValue(ref output, Int64Field44); + } + if (doubleField45_ != null) { + _single_doubleField45_codec.WriteTagAndValue(ref output, DoubleField45); + } + if (doubleField46_ != null) { + _single_doubleField46_codec.WriteTagAndValue(ref output, DoubleField46); + } + if (doubleField47_ != null) { + _single_doubleField47_codec.WriteTagAndValue(ref output, DoubleField47); + } + if (doubleField48_ != null) { + _single_doubleField48_codec.WriteTagAndValue(ref output, DoubleField48); + } + if (doubleField49_ != null) { + _single_doubleField49_codec.WriteTagAndValue(ref output, DoubleField49); + } + if (doubleField50_ != null) { + _single_doubleField50_codec.WriteTagAndValue(ref output, DoubleField50); + } + if (doubleField51_ != null) { + _single_doubleField51_codec.WriteTagAndValue(ref output, DoubleField51); + } + if (doubleField52_ != null) { + _single_doubleField52_codec.WriteTagAndValue(ref output, DoubleField52); + } + if (doubleField53_ != null) { + _single_doubleField53_codec.WriteTagAndValue(ref output, DoubleField53); + } + if (doubleField54_ != null) { + _single_doubleField54_codec.WriteTagAndValue(ref output, DoubleField54); + } + if (doubleField55_ != null) { + _single_doubleField55_codec.WriteTagAndValue(ref output, DoubleField55); + } + if (doubleField56_ != null) { + _single_doubleField56_codec.WriteTagAndValue(ref output, DoubleField56); + } + if (doubleField57_ != null) { + _single_doubleField57_codec.WriteTagAndValue(ref output, DoubleField57); + } + if (doubleField58_ != null) { + _single_doubleField58_codec.WriteTagAndValue(ref output, DoubleField58); + } + if (int64Field59_ != null) { + _single_int64Field59_codec.WriteTagAndValue(ref output, Int64Field59); + } + if (int64Field60_ != null) { + _single_int64Field60_codec.WriteTagAndValue(ref output, Int64Field60); + } + if (doubleField62_ != null) { + _single_doubleField62_codec.WriteTagAndValue(ref output, DoubleField62); + } + if (doubleField65_ != null) { + _single_doubleField65_codec.WriteTagAndValue(ref output, DoubleField65); + } + if (doubleField66_ != null) { + _single_doubleField66_codec.WriteTagAndValue(ref output, DoubleField66); + } + if (doubleField67_ != null) { + _single_doubleField67_codec.WriteTagAndValue(ref output, DoubleField67); + } + if (doubleField68_ != null) { + _single_doubleField68_codec.WriteTagAndValue(ref output, DoubleField68); + } + if (doubleField69_ != null) { + _single_doubleField69_codec.WriteTagAndValue(ref output, DoubleField69); + } + if (doubleField70_ != null) { + _single_doubleField70_codec.WriteTagAndValue(ref output, DoubleField70); + } + if (doubleField71_ != null) { + _single_doubleField71_codec.WriteTagAndValue(ref output, DoubleField71); + } + if (doubleField72_ != null) { + _single_doubleField72_codec.WriteTagAndValue(ref output, DoubleField72); + } + if (stringField73_ != null) { + _single_stringField73_codec.WriteTagAndValue(ref output, StringField73); + } + if (stringField74_ != null) { + _single_stringField74_codec.WriteTagAndValue(ref output, StringField74); + } + if (doubleField75_ != null) { + _single_doubleField75_codec.WriteTagAndValue(ref output, DoubleField75); + } + if (doubleField77_ != null) { + _single_doubleField77_codec.WriteTagAndValue(ref output, DoubleField77); + } + if (doubleField78_ != null) { + _single_doubleField78_codec.WriteTagAndValue(ref output, DoubleField78); + } + if (doubleField79_ != null) { + _single_doubleField79_codec.WriteTagAndValue(ref output, DoubleField79); + } + if (EnumField80 != 0) { + output.WriteRawTag(128, 5); + output.WriteInt32(EnumField80); + } + if (EnumField81 != 0) { + output.WriteRawTag(136, 5); + output.WriteInt32(EnumField81); + } + if (int64Field82_ != null) { + _single_int64Field82_codec.WriteTagAndValue(ref output, Int64Field82); + } + if (EnumField83 != 0) { + output.WriteRawTag(152, 5); + output.WriteInt32(EnumField83); + } + if (doubleField84_ != null) { + _single_doubleField84_codec.WriteTagAndValue(ref output, DoubleField84); + } + if (int64Field85_ != null) { + _single_int64Field85_codec.WriteTagAndValue(ref output, Int64Field85); + } + if (int64Field86_ != null) { + _single_int64Field86_codec.WriteTagAndValue(ref output, Int64Field86); + } + if (int64Field87_ != null) { + _single_int64Field87_codec.WriteTagAndValue(ref output, Int64Field87); + } + if (doubleField88_ != null) { + _single_doubleField88_codec.WriteTagAndValue(ref output, DoubleField88); + } + if (doubleField89_ != null) { + _single_doubleField89_codec.WriteTagAndValue(ref output, DoubleField89); + } + if (doubleField90_ != null) { + _single_doubleField90_codec.WriteTagAndValue(ref output, DoubleField90); + } + if (doubleField91_ != null) { + _single_doubleField91_codec.WriteTagAndValue(ref output, DoubleField91); + } + if (doubleField92_ != null) { + _single_doubleField92_codec.WriteTagAndValue(ref output, DoubleField92); + } + if (doubleField93_ != null) { + _single_doubleField93_codec.WriteTagAndValue(ref output, DoubleField93); + } + if (doubleField94_ != null) { + _single_doubleField94_codec.WriteTagAndValue(ref output, DoubleField94); + } + if (doubleField95_ != null) { + _single_doubleField95_codec.WriteTagAndValue(ref output, DoubleField95); + } + if (doubleField96_ != null) { + _single_doubleField96_codec.WriteTagAndValue(ref output, DoubleField96); + } + if (doubleField97_ != null) { + _single_doubleField97_codec.WriteTagAndValue(ref output, DoubleField97); + } + if (doubleField98_ != null) { + _single_doubleField98_codec.WriteTagAndValue(ref output, DoubleField98); + } + if (doubleField99_ != null) { + _single_doubleField99_codec.WriteTagAndValue(ref output, DoubleField99); + } + repeatedIntField100_.WriteTo(ref output, _repeated_repeatedIntField100_codec); + if (doubleField101_ != null) { + _single_doubleField101_codec.WriteTagAndValue(ref output, DoubleField101); + } + if (doubleField102_ != null) { + _single_doubleField102_codec.WriteTagAndValue(ref output, DoubleField102); + } + if (doubleField103_ != null) { + _single_doubleField103_codec.WriteTagAndValue(ref output, DoubleField103); + } + if (doubleField104_ != null) { + _single_doubleField104_codec.WriteTagAndValue(ref output, DoubleField104); + } + if (doubleField105_ != null) { + _single_doubleField105_codec.WriteTagAndValue(ref output, DoubleField105); + } + if (doubleField106_ != null) { + _single_doubleField106_codec.WriteTagAndValue(ref output, DoubleField106); + } + if (int64Field107_ != null) { + _single_int64Field107_codec.WriteTagAndValue(ref output, Int64Field107); + } + if (doubleField108_ != null) { + _single_doubleField108_codec.WriteTagAndValue(ref output, DoubleField108); + } + if (doubleField109_ != null) { + _single_doubleField109_codec.WriteTagAndValue(ref output, DoubleField109); + } + if (int64Field110_ != null) { + _single_int64Field110_codec.WriteTagAndValue(ref output, Int64Field110); + } + if (doubleField111_ != null) { + _single_doubleField111_codec.WriteTagAndValue(ref output, DoubleField111); + } + if (int64Field112_ != null) { + _single_int64Field112_codec.WriteTagAndValue(ref output, Int64Field112); + } + if (doubleField113_ != null) { + _single_doubleField113_codec.WriteTagAndValue(ref output, DoubleField113); + } + if (int64Field114_ != null) { + _single_int64Field114_codec.WriteTagAndValue(ref output, Int64Field114); + } + if (int64Field115_ != null) { + _single_int64Field115_codec.WriteTagAndValue(ref output, Int64Field115); + } + if (doubleField116_ != null) { + _single_doubleField116_codec.WriteTagAndValue(ref output, DoubleField116); + } + if (int64Field117_ != null) { + _single_int64Field117_codec.WriteTagAndValue(ref output, Int64Field117); + } + if (doubleField118_ != null) { + _single_doubleField118_codec.WriteTagAndValue(ref output, DoubleField118); + } + if (doubleField119_ != null) { + _single_doubleField119_codec.WriteTagAndValue(ref output, DoubleField119); + } + if (doubleField120_ != null) { + _single_doubleField120_codec.WriteTagAndValue(ref output, DoubleField120); + } + if (doubleField121_ != null) { + _single_doubleField121_codec.WriteTagAndValue(ref output, DoubleField121); + } + if (doubleField122_ != null) { + _single_doubleField122_codec.WriteTagAndValue(ref output, DoubleField122); + } + if (doubleField123_ != null) { + _single_doubleField123_codec.WriteTagAndValue(ref output, DoubleField123); + } + if (doubleField124_ != null) { + _single_doubleField124_codec.WriteTagAndValue(ref output, DoubleField124); + } + if (int64Field125_ != null) { + _single_int64Field125_codec.WriteTagAndValue(ref output, Int64Field125); + } + if (int64Field126_ != null) { + _single_int64Field126_codec.WriteTagAndValue(ref output, Int64Field126); + } + if (int64Field127_ != null) { + _single_int64Field127_codec.WriteTagAndValue(ref output, Int64Field127); + } + if (doubleField128_ != null) { + _single_doubleField128_codec.WriteTagAndValue(ref output, DoubleField128); + } + if (doubleField129_ != null) { + _single_doubleField129_codec.WriteTagAndValue(ref output, DoubleField129); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -4079,1630 +4427,2865 @@ public void MergeFrom(pb::CodedInputStream input) { } } - } - - /// - /// same as ManyWrapperFieldsMessages, but with primitive fields - /// for comparison. - /// - public sealed partial class ManyPrimitiveFieldsMessage : pb::IMessage { - private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ManyPrimitiveFieldsMessage()); - private pb::UnknownFieldSet _unknownFields; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public static pb::MessageParser Parser { get { return _parser; } } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public static pbr::MessageDescriptor Descriptor { - get { return global::Google.Protobuf.Benchmarks.WrapperBenchmarkMessagesReflection.Descriptor.MessageTypes[1]; } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - pbr::MessageDescriptor pb::IMessage.Descriptor { - get { return Descriptor; } - } + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public ManyPrimitiveFieldsMessage() { - OnConstruction(); - } - + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + double? value = _single_doubleField1_codec.Read(ref input); + if (doubleField1_ == null || value != 0D) { + DoubleField1 = value; + } + break; + } + case 18: { + long? value = _single_int64Field2_codec.Read(ref input); + if (int64Field2_ == null || value != 0L) { + Int64Field2 = value; + } + break; + } + case 26: { + long? value = _single_int64Field3_codec.Read(ref input); + if (int64Field3_ == null || value != 0L) { + Int64Field3 = value; + } + break; + } + case 34: { + long? value = _single_int64Field4_codec.Read(ref input); + if (int64Field4_ == null || value != 0L) { + Int64Field4 = value; + } + break; + } + case 58: { + double? value = _single_doubleField7_codec.Read(ref input); + if (doubleField7_ == null || value != 0D) { + DoubleField7 = value; + } + break; + } + case 66: { + double? value = _single_doubleField8_codec.Read(ref input); + if (doubleField8_ == null || value != 0D) { + DoubleField8 = value; + } + break; + } + case 74: { + double? value = _single_doubleField9_codec.Read(ref input); + if (doubleField9_ == null || value != 0D) { + DoubleField9 = value; + } + break; + } + case 82: { + double? value = _single_doubleField10_codec.Read(ref input); + if (doubleField10_ == null || value != 0D) { + DoubleField10 = value; + } + break; + } + case 90: { + double? value = _single_doubleField11_codec.Read(ref input); + if (doubleField11_ == null || value != 0D) { + DoubleField11 = value; + } + break; + } + case 114: { + double? value = _single_doubleField14_codec.Read(ref input); + if (doubleField14_ == null || value != 0D) { + DoubleField14 = value; + } + break; + } + case 122: { + double? value = _single_doubleField15_codec.Read(ref input); + if (doubleField15_ == null || value != 0D) { + DoubleField15 = value; + } + break; + } + case 154: { + long? value = _single_int64Field19_codec.Read(ref input); + if (int64Field19_ == null || value != 0L) { + Int64Field19 = value; + } + break; + } + case 162: { + double? value = _single_doubleField20_codec.Read(ref input); + if (doubleField20_ == null || value != 0D) { + DoubleField20 = value; + } + break; + } + case 170: { + double? value = _single_doubleField21_codec.Read(ref input); + if (doubleField21_ == null || value != 0D) { + DoubleField21 = value; + } + break; + } + case 178: { + double? value = _single_doubleField22_codec.Read(ref input); + if (doubleField22_ == null || value != 0D) { + DoubleField22 = value; + } + break; + } + case 202: { + double? value = _single_doubleField25_codec.Read(ref input); + if (doubleField25_ == null || value != 0D) { + DoubleField25 = value; + } + break; + } + case 210: { + long? value = _single_int64Field26_codec.Read(ref input); + if (int64Field26_ == null || value != 0L) { + Int64Field26 = value; + } + break; + } + case 226: { + double? value = _single_doubleField28_codec.Read(ref input); + if (doubleField28_ == null || value != 0D) { + DoubleField28 = value; + } + break; + } + case 234: { + double? value = _single_doubleField29_codec.Read(ref input); + if (doubleField29_ == null || value != 0D) { + DoubleField29 = value; + } + break; + } + case 242: { + double? value = _single_doubleField30_codec.Read(ref input); + if (doubleField30_ == null || value != 0D) { + DoubleField30 = value; + } + break; + } + case 250: { + double? value = _single_doubleField31_codec.Read(ref input); + if (doubleField31_ == null || value != 0D) { + DoubleField31 = value; + } + break; + } + case 258: { + long? value = _single_int64Field32_codec.Read(ref input); + if (int64Field32_ == null || value != 0L) { + Int64Field32 = value; + } + break; + } + case 298: { + long? value = _single_int64Field37_codec.Read(ref input); + if (int64Field37_ == null || value != 0L) { + Int64Field37 = value; + } + break; + } + case 306: { + double? value = _single_doubleField38_codec.Read(ref input); + if (doubleField38_ == null || value != 0D) { + DoubleField38 = value; + } + break; + } + case 314: { + long? value = _single_interactions_codec.Read(ref input); + if (interactions_ == null || value != 0L) { + Interactions = value; + } + break; + } + case 322: { + double? value = _single_doubleField40_codec.Read(ref input); + if (doubleField40_ == null || value != 0D) { + DoubleField40 = value; + } + break; + } + case 330: { + long? value = _single_int64Field41_codec.Read(ref input); + if (int64Field41_ == null || value != 0L) { + Int64Field41 = value; + } + break; + } + case 338: { + double? value = _single_doubleField42_codec.Read(ref input); + if (doubleField42_ == null || value != 0D) { + DoubleField42 = value; + } + break; + } + case 346: { + long? value = _single_int64Field43_codec.Read(ref input); + if (int64Field43_ == null || value != 0L) { + Int64Field43 = value; + } + break; + } + case 354: { + long? value = _single_int64Field44_codec.Read(ref input); + if (int64Field44_ == null || value != 0L) { + Int64Field44 = value; + } + break; + } + case 362: { + double? value = _single_doubleField45_codec.Read(ref input); + if (doubleField45_ == null || value != 0D) { + DoubleField45 = value; + } + break; + } + case 370: { + double? value = _single_doubleField46_codec.Read(ref input); + if (doubleField46_ == null || value != 0D) { + DoubleField46 = value; + } + break; + } + case 378: { + double? value = _single_doubleField47_codec.Read(ref input); + if (doubleField47_ == null || value != 0D) { + DoubleField47 = value; + } + break; + } + case 386: { + double? value = _single_doubleField48_codec.Read(ref input); + if (doubleField48_ == null || value != 0D) { + DoubleField48 = value; + } + break; + } + case 394: { + double? value = _single_doubleField49_codec.Read(ref input); + if (doubleField49_ == null || value != 0D) { + DoubleField49 = value; + } + break; + } + case 402: { + double? value = _single_doubleField50_codec.Read(ref input); + if (doubleField50_ == null || value != 0D) { + DoubleField50 = value; + } + break; + } + case 410: { + double? value = _single_doubleField51_codec.Read(ref input); + if (doubleField51_ == null || value != 0D) { + DoubleField51 = value; + } + break; + } + case 418: { + double? value = _single_doubleField52_codec.Read(ref input); + if (doubleField52_ == null || value != 0D) { + DoubleField52 = value; + } + break; + } + case 426: { + double? value = _single_doubleField53_codec.Read(ref input); + if (doubleField53_ == null || value != 0D) { + DoubleField53 = value; + } + break; + } + case 434: { + double? value = _single_doubleField54_codec.Read(ref input); + if (doubleField54_ == null || value != 0D) { + DoubleField54 = value; + } + break; + } + case 442: { + double? value = _single_doubleField55_codec.Read(ref input); + if (doubleField55_ == null || value != 0D) { + DoubleField55 = value; + } + break; + } + case 450: { + double? value = _single_doubleField56_codec.Read(ref input); + if (doubleField56_ == null || value != 0D) { + DoubleField56 = value; + } + break; + } + case 458: { + double? value = _single_doubleField57_codec.Read(ref input); + if (doubleField57_ == null || value != 0D) { + DoubleField57 = value; + } + break; + } + case 466: { + double? value = _single_doubleField58_codec.Read(ref input); + if (doubleField58_ == null || value != 0D) { + DoubleField58 = value; + } + break; + } + case 474: { + long? value = _single_int64Field59_codec.Read(ref input); + if (int64Field59_ == null || value != 0L) { + Int64Field59 = value; + } + break; + } + case 482: { + long? value = _single_int64Field60_codec.Read(ref input); + if (int64Field60_ == null || value != 0L) { + Int64Field60 = value; + } + break; + } + case 498: { + double? value = _single_doubleField62_codec.Read(ref input); + if (doubleField62_ == null || value != 0D) { + DoubleField62 = value; + } + break; + } + case 522: { + double? value = _single_doubleField65_codec.Read(ref input); + if (doubleField65_ == null || value != 0D) { + DoubleField65 = value; + } + break; + } + case 530: { + double? value = _single_doubleField66_codec.Read(ref input); + if (doubleField66_ == null || value != 0D) { + DoubleField66 = value; + } + break; + } + case 538: { + double? value = _single_doubleField67_codec.Read(ref input); + if (doubleField67_ == null || value != 0D) { + DoubleField67 = value; + } + break; + } + case 546: { + double? value = _single_doubleField68_codec.Read(ref input); + if (doubleField68_ == null || value != 0D) { + DoubleField68 = value; + } + break; + } + case 554: { + double? value = _single_doubleField69_codec.Read(ref input); + if (doubleField69_ == null || value != 0D) { + DoubleField69 = value; + } + break; + } + case 562: { + double? value = _single_doubleField70_codec.Read(ref input); + if (doubleField70_ == null || value != 0D) { + DoubleField70 = value; + } + break; + } + case 570: { + double? value = _single_doubleField71_codec.Read(ref input); + if (doubleField71_ == null || value != 0D) { + DoubleField71 = value; + } + break; + } + case 578: { + double? value = _single_doubleField72_codec.Read(ref input); + if (doubleField72_ == null || value != 0D) { + DoubleField72 = value; + } + break; + } + case 586: { + string value = _single_stringField73_codec.Read(ref input); + if (stringField73_ == null || value != "") { + StringField73 = value; + } + break; + } + case 594: { + string value = _single_stringField74_codec.Read(ref input); + if (stringField74_ == null || value != "") { + StringField74 = value; + } + break; + } + case 602: { + double? value = _single_doubleField75_codec.Read(ref input); + if (doubleField75_ == null || value != 0D) { + DoubleField75 = value; + } + break; + } + case 618: { + double? value = _single_doubleField77_codec.Read(ref input); + if (doubleField77_ == null || value != 0D) { + DoubleField77 = value; + } + break; + } + case 626: { + double? value = _single_doubleField78_codec.Read(ref input); + if (doubleField78_ == null || value != 0D) { + DoubleField78 = value; + } + break; + } + case 634: { + double? value = _single_doubleField79_codec.Read(ref input); + if (doubleField79_ == null || value != 0D) { + DoubleField79 = value; + } + break; + } + case 640: { + EnumField80 = input.ReadInt32(); + break; + } + case 648: { + EnumField81 = input.ReadInt32(); + break; + } + case 658: { + long? value = _single_int64Field82_codec.Read(ref input); + if (int64Field82_ == null || value != 0L) { + Int64Field82 = value; + } + break; + } + case 664: { + EnumField83 = input.ReadInt32(); + break; + } + case 674: { + double? value = _single_doubleField84_codec.Read(ref input); + if (doubleField84_ == null || value != 0D) { + DoubleField84 = value; + } + break; + } + case 682: { + long? value = _single_int64Field85_codec.Read(ref input); + if (int64Field85_ == null || value != 0L) { + Int64Field85 = value; + } + break; + } + case 690: { + long? value = _single_int64Field86_codec.Read(ref input); + if (int64Field86_ == null || value != 0L) { + Int64Field86 = value; + } + break; + } + case 698: { + long? value = _single_int64Field87_codec.Read(ref input); + if (int64Field87_ == null || value != 0L) { + Int64Field87 = value; + } + break; + } + case 706: { + double? value = _single_doubleField88_codec.Read(ref input); + if (doubleField88_ == null || value != 0D) { + DoubleField88 = value; + } + break; + } + case 714: { + double? value = _single_doubleField89_codec.Read(ref input); + if (doubleField89_ == null || value != 0D) { + DoubleField89 = value; + } + break; + } + case 722: { + double? value = _single_doubleField90_codec.Read(ref input); + if (doubleField90_ == null || value != 0D) { + DoubleField90 = value; + } + break; + } + case 730: { + double? value = _single_doubleField91_codec.Read(ref input); + if (doubleField91_ == null || value != 0D) { + DoubleField91 = value; + } + break; + } + case 738: { + double? value = _single_doubleField92_codec.Read(ref input); + if (doubleField92_ == null || value != 0D) { + DoubleField92 = value; + } + break; + } + case 746: { + double? value = _single_doubleField93_codec.Read(ref input); + if (doubleField93_ == null || value != 0D) { + DoubleField93 = value; + } + break; + } + case 754: { + double? value = _single_doubleField94_codec.Read(ref input); + if (doubleField94_ == null || value != 0D) { + DoubleField94 = value; + } + break; + } + case 762: { + double? value = _single_doubleField95_codec.Read(ref input); + if (doubleField95_ == null || value != 0D) { + DoubleField95 = value; + } + break; + } + case 770: { + double? value = _single_doubleField96_codec.Read(ref input); + if (doubleField96_ == null || value != 0D) { + DoubleField96 = value; + } + break; + } + case 778: { + double? value = _single_doubleField97_codec.Read(ref input); + if (doubleField97_ == null || value != 0D) { + DoubleField97 = value; + } + break; + } + case 786: { + double? value = _single_doubleField98_codec.Read(ref input); + if (doubleField98_ == null || value != 0D) { + DoubleField98 = value; + } + break; + } + case 794: { + double? value = _single_doubleField99_codec.Read(ref input); + if (doubleField99_ == null || value != 0D) { + DoubleField99 = value; + } + break; + } + case 802: + case 800: { + repeatedIntField100_.AddEntriesFrom(ref input, _repeated_repeatedIntField100_codec); + break; + } + case 810: { + double? value = _single_doubleField101_codec.Read(ref input); + if (doubleField101_ == null || value != 0D) { + DoubleField101 = value; + } + break; + } + case 818: { + double? value = _single_doubleField102_codec.Read(ref input); + if (doubleField102_ == null || value != 0D) { + DoubleField102 = value; + } + break; + } + case 826: { + double? value = _single_doubleField103_codec.Read(ref input); + if (doubleField103_ == null || value != 0D) { + DoubleField103 = value; + } + break; + } + case 834: { + double? value = _single_doubleField104_codec.Read(ref input); + if (doubleField104_ == null || value != 0D) { + DoubleField104 = value; + } + break; + } + case 842: { + double? value = _single_doubleField105_codec.Read(ref input); + if (doubleField105_ == null || value != 0D) { + DoubleField105 = value; + } + break; + } + case 850: { + double? value = _single_doubleField106_codec.Read(ref input); + if (doubleField106_ == null || value != 0D) { + DoubleField106 = value; + } + break; + } + case 858: { + long? value = _single_int64Field107_codec.Read(ref input); + if (int64Field107_ == null || value != 0L) { + Int64Field107 = value; + } + break; + } + case 866: { + double? value = _single_doubleField108_codec.Read(ref input); + if (doubleField108_ == null || value != 0D) { + DoubleField108 = value; + } + break; + } + case 874: { + double? value = _single_doubleField109_codec.Read(ref input); + if (doubleField109_ == null || value != 0D) { + DoubleField109 = value; + } + break; + } + case 882: { + long? value = _single_int64Field110_codec.Read(ref input); + if (int64Field110_ == null || value != 0L) { + Int64Field110 = value; + } + break; + } + case 890: { + double? value = _single_doubleField111_codec.Read(ref input); + if (doubleField111_ == null || value != 0D) { + DoubleField111 = value; + } + break; + } + case 898: { + long? value = _single_int64Field112_codec.Read(ref input); + if (int64Field112_ == null || value != 0L) { + Int64Field112 = value; + } + break; + } + case 906: { + double? value = _single_doubleField113_codec.Read(ref input); + if (doubleField113_ == null || value != 0D) { + DoubleField113 = value; + } + break; + } + case 914: { + long? value = _single_int64Field114_codec.Read(ref input); + if (int64Field114_ == null || value != 0L) { + Int64Field114 = value; + } + break; + } + case 922: { + long? value = _single_int64Field115_codec.Read(ref input); + if (int64Field115_ == null || value != 0L) { + Int64Field115 = value; + } + break; + } + case 930: { + double? value = _single_doubleField116_codec.Read(ref input); + if (doubleField116_ == null || value != 0D) { + DoubleField116 = value; + } + break; + } + case 938: { + long? value = _single_int64Field117_codec.Read(ref input); + if (int64Field117_ == null || value != 0L) { + Int64Field117 = value; + } + break; + } + case 946: { + double? value = _single_doubleField118_codec.Read(ref input); + if (doubleField118_ == null || value != 0D) { + DoubleField118 = value; + } + break; + } + case 954: { + double? value = _single_doubleField119_codec.Read(ref input); + if (doubleField119_ == null || value != 0D) { + DoubleField119 = value; + } + break; + } + case 962: { + double? value = _single_doubleField120_codec.Read(ref input); + if (doubleField120_ == null || value != 0D) { + DoubleField120 = value; + } + break; + } + case 970: { + double? value = _single_doubleField121_codec.Read(ref input); + if (doubleField121_ == null || value != 0D) { + DoubleField121 = value; + } + break; + } + case 978: { + double? value = _single_doubleField122_codec.Read(ref input); + if (doubleField122_ == null || value != 0D) { + DoubleField122 = value; + } + break; + } + case 986: { + double? value = _single_doubleField123_codec.Read(ref input); + if (doubleField123_ == null || value != 0D) { + DoubleField123 = value; + } + break; + } + case 994: { + double? value = _single_doubleField124_codec.Read(ref input); + if (doubleField124_ == null || value != 0D) { + DoubleField124 = value; + } + break; + } + case 1002: { + long? value = _single_int64Field125_codec.Read(ref input); + if (int64Field125_ == null || value != 0L) { + Int64Field125 = value; + } + break; + } + case 1010: { + long? value = _single_int64Field126_codec.Read(ref input); + if (int64Field126_ == null || value != 0L) { + Int64Field126 = value; + } + break; + } + case 1018: { + long? value = _single_int64Field127_codec.Read(ref input); + if (int64Field127_ == null || value != 0L) { + Int64Field127 = value; + } + break; + } + case 1026: { + double? value = _single_doubleField128_codec.Read(ref input); + if (doubleField128_ == null || value != 0D) { + DoubleField128 = value; + } + break; + } + case 1034: { + double? value = _single_doubleField129_codec.Read(ref input); + if (doubleField129_ == null || value != 0D) { + DoubleField129 = value; + } + break; + } + } + } + } + #endif + + } + + /// + /// same as ManyWrapperFieldsMessages, but with primitive fields + /// for comparison. + /// + public sealed partial class ManyPrimitiveFieldsMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ManyPrimitiveFieldsMessage()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Google.Protobuf.Benchmarks.WrapperBenchmarkMessagesReflection.Descriptor.MessageTypes[1]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public ManyPrimitiveFieldsMessage() { + OnConstruction(); + } + partial void OnConstruction(); [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public ManyPrimitiveFieldsMessage(ManyPrimitiveFieldsMessage other) : this() { - doubleField95_ = other.doubleField95_; - doubleField1_ = other.doubleField1_; - doubleField79_ = other.doubleField79_; - int64Field2_ = other.int64Field2_; - doubleField96_ = other.doubleField96_; - int64Field3_ = other.int64Field3_; - int64Field4_ = other.int64Field4_; - doubleField97_ = other.doubleField97_; - doubleField65_ = other.doubleField65_; - doubleField66_ = other.doubleField66_; - doubleField7_ = other.doubleField7_; - doubleField62_ = other.doubleField62_; - doubleField118_ = other.doubleField118_; - doubleField119_ = other.doubleField119_; - doubleField67_ = other.doubleField67_; - doubleField120_ = other.doubleField120_; - doubleField121_ = other.doubleField121_; - doubleField122_ = other.doubleField122_; - doubleField123_ = other.doubleField123_; - doubleField124_ = other.doubleField124_; - doubleField8_ = other.doubleField8_; - doubleField9_ = other.doubleField9_; - doubleField98_ = other.doubleField98_; - doubleField10_ = other.doubleField10_; - doubleField11_ = other.doubleField11_; - doubleField99_ = other.doubleField99_; - doubleField84_ = other.doubleField84_; - doubleField14_ = other.doubleField14_; - doubleField77_ = other.doubleField77_; - doubleField15_ = other.doubleField15_; - int64Field19_ = other.int64Field19_; - int64Field115_ = other.int64Field115_; - doubleField116_ = other.doubleField116_; - int64Field117_ = other.int64Field117_; - doubleField20_ = other.doubleField20_; - doubleField21_ = other.doubleField21_; - stringField73_ = other.stringField73_; - stringField74_ = other.stringField74_; - doubleField22_ = other.doubleField22_; - doubleField69_ = other.doubleField69_; - doubleField70_ = other.doubleField70_; - doubleField71_ = other.doubleField71_; - doubleField72_ = other.doubleField72_; - doubleField25_ = other.doubleField25_; - int64Field26_ = other.int64Field26_; - doubleField68_ = other.doubleField68_; - doubleField28_ = other.doubleField28_; - doubleField106_ = other.doubleField106_; - doubleField29_ = other.doubleField29_; - doubleField30_ = other.doubleField30_; - doubleField101_ = other.doubleField101_; - doubleField102_ = other.doubleField102_; - doubleField103_ = other.doubleField103_; - doubleField104_ = other.doubleField104_; - doubleField105_ = other.doubleField105_; - doubleField31_ = other.doubleField31_; - int64Field32_ = other.int64Field32_; - doubleField75_ = other.doubleField75_; - doubleField129_ = other.doubleField129_; - enumField80_ = other.enumField80_; - enumField81_ = other.enumField81_; - int64Field82_ = other.int64Field82_; - enumField83_ = other.enumField83_; - int64Field85_ = other.int64Field85_; - int64Field86_ = other.int64Field86_; - int64Field87_ = other.int64Field87_; - int64Field125_ = other.int64Field125_; - int64Field37_ = other.int64Field37_; - doubleField38_ = other.doubleField38_; - interactions_ = other.interactions_; - repeatedIntField100_ = other.repeatedIntField100_.Clone(); - doubleField40_ = other.doubleField40_; - int64Field41_ = other.int64Field41_; - int64Field126_ = other.int64Field126_; - int64Field127_ = other.int64Field127_; - doubleField128_ = other.doubleField128_; - doubleField109_ = other.doubleField109_; - int64Field110_ = other.int64Field110_; - doubleField111_ = other.doubleField111_; - int64Field112_ = other.int64Field112_; - doubleField113_ = other.doubleField113_; - int64Field114_ = other.int64Field114_; - doubleField42_ = other.doubleField42_; - int64Field43_ = other.int64Field43_; - int64Field44_ = other.int64Field44_; - doubleField45_ = other.doubleField45_; - doubleField46_ = other.doubleField46_; - doubleField78_ = other.doubleField78_; - doubleField88_ = other.doubleField88_; - doubleField47_ = other.doubleField47_; - doubleField89_ = other.doubleField89_; - doubleField48_ = other.doubleField48_; - doubleField49_ = other.doubleField49_; - doubleField50_ = other.doubleField50_; - doubleField90_ = other.doubleField90_; - doubleField51_ = other.doubleField51_; - doubleField91_ = other.doubleField91_; - doubleField92_ = other.doubleField92_; - int64Field107_ = other.int64Field107_; - doubleField93_ = other.doubleField93_; - doubleField108_ = other.doubleField108_; - doubleField52_ = other.doubleField52_; - doubleField53_ = other.doubleField53_; - doubleField94_ = other.doubleField94_; - doubleField54_ = other.doubleField54_; - doubleField55_ = other.doubleField55_; - doubleField56_ = other.doubleField56_; - doubleField57_ = other.doubleField57_; - doubleField58_ = other.doubleField58_; - int64Field59_ = other.int64Field59_; - int64Field60_ = other.int64Field60_; - _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + public ManyPrimitiveFieldsMessage(ManyPrimitiveFieldsMessage other) : this() { + doubleField95_ = other.doubleField95_; + doubleField1_ = other.doubleField1_; + doubleField79_ = other.doubleField79_; + int64Field2_ = other.int64Field2_; + doubleField96_ = other.doubleField96_; + int64Field3_ = other.int64Field3_; + int64Field4_ = other.int64Field4_; + doubleField97_ = other.doubleField97_; + doubleField65_ = other.doubleField65_; + doubleField66_ = other.doubleField66_; + doubleField7_ = other.doubleField7_; + doubleField62_ = other.doubleField62_; + doubleField118_ = other.doubleField118_; + doubleField119_ = other.doubleField119_; + doubleField67_ = other.doubleField67_; + doubleField120_ = other.doubleField120_; + doubleField121_ = other.doubleField121_; + doubleField122_ = other.doubleField122_; + doubleField123_ = other.doubleField123_; + doubleField124_ = other.doubleField124_; + doubleField8_ = other.doubleField8_; + doubleField9_ = other.doubleField9_; + doubleField98_ = other.doubleField98_; + doubleField10_ = other.doubleField10_; + doubleField11_ = other.doubleField11_; + doubleField99_ = other.doubleField99_; + doubleField84_ = other.doubleField84_; + doubleField14_ = other.doubleField14_; + doubleField77_ = other.doubleField77_; + doubleField15_ = other.doubleField15_; + int64Field19_ = other.int64Field19_; + int64Field115_ = other.int64Field115_; + doubleField116_ = other.doubleField116_; + int64Field117_ = other.int64Field117_; + doubleField20_ = other.doubleField20_; + doubleField21_ = other.doubleField21_; + stringField73_ = other.stringField73_; + stringField74_ = other.stringField74_; + doubleField22_ = other.doubleField22_; + doubleField69_ = other.doubleField69_; + doubleField70_ = other.doubleField70_; + doubleField71_ = other.doubleField71_; + doubleField72_ = other.doubleField72_; + doubleField25_ = other.doubleField25_; + int64Field26_ = other.int64Field26_; + doubleField68_ = other.doubleField68_; + doubleField28_ = other.doubleField28_; + doubleField106_ = other.doubleField106_; + doubleField29_ = other.doubleField29_; + doubleField30_ = other.doubleField30_; + doubleField101_ = other.doubleField101_; + doubleField102_ = other.doubleField102_; + doubleField103_ = other.doubleField103_; + doubleField104_ = other.doubleField104_; + doubleField105_ = other.doubleField105_; + doubleField31_ = other.doubleField31_; + int64Field32_ = other.int64Field32_; + doubleField75_ = other.doubleField75_; + doubleField129_ = other.doubleField129_; + enumField80_ = other.enumField80_; + enumField81_ = other.enumField81_; + int64Field82_ = other.int64Field82_; + enumField83_ = other.enumField83_; + int64Field85_ = other.int64Field85_; + int64Field86_ = other.int64Field86_; + int64Field87_ = other.int64Field87_; + int64Field125_ = other.int64Field125_; + int64Field37_ = other.int64Field37_; + doubleField38_ = other.doubleField38_; + interactions_ = other.interactions_; + repeatedIntField100_ = other.repeatedIntField100_.Clone(); + doubleField40_ = other.doubleField40_; + int64Field41_ = other.int64Field41_; + int64Field126_ = other.int64Field126_; + int64Field127_ = other.int64Field127_; + doubleField128_ = other.doubleField128_; + doubleField109_ = other.doubleField109_; + int64Field110_ = other.int64Field110_; + doubleField111_ = other.doubleField111_; + int64Field112_ = other.int64Field112_; + doubleField113_ = other.doubleField113_; + int64Field114_ = other.int64Field114_; + doubleField42_ = other.doubleField42_; + int64Field43_ = other.int64Field43_; + int64Field44_ = other.int64Field44_; + doubleField45_ = other.doubleField45_; + doubleField46_ = other.doubleField46_; + doubleField78_ = other.doubleField78_; + doubleField88_ = other.doubleField88_; + doubleField47_ = other.doubleField47_; + doubleField89_ = other.doubleField89_; + doubleField48_ = other.doubleField48_; + doubleField49_ = other.doubleField49_; + doubleField50_ = other.doubleField50_; + doubleField90_ = other.doubleField90_; + doubleField51_ = other.doubleField51_; + doubleField91_ = other.doubleField91_; + doubleField92_ = other.doubleField92_; + int64Field107_ = other.int64Field107_; + doubleField93_ = other.doubleField93_; + doubleField108_ = other.doubleField108_; + doubleField52_ = other.doubleField52_; + doubleField53_ = other.doubleField53_; + doubleField94_ = other.doubleField94_; + doubleField54_ = other.doubleField54_; + doubleField55_ = other.doubleField55_; + doubleField56_ = other.doubleField56_; + doubleField57_ = other.doubleField57_; + doubleField58_ = other.doubleField58_; + int64Field59_ = other.int64Field59_; + int64Field60_ = other.int64Field60_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public ManyPrimitiveFieldsMessage Clone() { + return new ManyPrimitiveFieldsMessage(this); + } + + /// Field number for the "double_field_95" field. + public const int DoubleField95FieldNumber = 95; + private double doubleField95_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField95 { + get { return doubleField95_; } + set { + doubleField95_ = value; + } + } + + /// Field number for the "double_field_1" field. + public const int DoubleField1FieldNumber = 1; + private double doubleField1_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField1 { + get { return doubleField1_; } + set { + doubleField1_ = value; + } + } + + /// Field number for the "double_field_79" field. + public const int DoubleField79FieldNumber = 79; + private double doubleField79_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField79 { + get { return doubleField79_; } + set { + doubleField79_ = value; + } + } + + /// Field number for the "int64_field_2" field. + public const int Int64Field2FieldNumber = 2; + private long int64Field2_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long Int64Field2 { + get { return int64Field2_; } + set { + int64Field2_ = value; + } + } + + /// Field number for the "double_field_96" field. + public const int DoubleField96FieldNumber = 96; + private double doubleField96_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField96 { + get { return doubleField96_; } + set { + doubleField96_ = value; + } + } + + /// Field number for the "int64_field_3" field. + public const int Int64Field3FieldNumber = 3; + private long int64Field3_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long Int64Field3 { + get { return int64Field3_; } + set { + int64Field3_ = value; + } + } + + /// Field number for the "int64_field_4" field. + public const int Int64Field4FieldNumber = 4; + private long int64Field4_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long Int64Field4 { + get { return int64Field4_; } + set { + int64Field4_ = value; + } + } + + /// Field number for the "double_field_97" field. + public const int DoubleField97FieldNumber = 97; + private double doubleField97_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField97 { + get { return doubleField97_; } + set { + doubleField97_ = value; + } + } + + /// Field number for the "double_field_65" field. + public const int DoubleField65FieldNumber = 65; + private double doubleField65_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField65 { + get { return doubleField65_; } + set { + doubleField65_ = value; + } + } + + /// Field number for the "double_field_66" field. + public const int DoubleField66FieldNumber = 66; + private double doubleField66_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField66 { + get { return doubleField66_; } + set { + doubleField66_ = value; + } + } + + /// Field number for the "double_field_7" field. + public const int DoubleField7FieldNumber = 7; + private double doubleField7_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField7 { + get { return doubleField7_; } + set { + doubleField7_ = value; + } + } + + /// Field number for the "double_field_62" field. + public const int DoubleField62FieldNumber = 62; + private double doubleField62_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField62 { + get { return doubleField62_; } + set { + doubleField62_ = value; + } + } + + /// Field number for the "double_field_118" field. + public const int DoubleField118FieldNumber = 118; + private double doubleField118_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField118 { + get { return doubleField118_; } + set { + doubleField118_ = value; + } + } + + /// Field number for the "double_field_119" field. + public const int DoubleField119FieldNumber = 119; + private double doubleField119_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField119 { + get { return doubleField119_; } + set { + doubleField119_ = value; + } + } + + /// Field number for the "double_field_67" field. + public const int DoubleField67FieldNumber = 67; + private double doubleField67_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField67 { + get { return doubleField67_; } + set { + doubleField67_ = value; + } + } + + /// Field number for the "double_field_120" field. + public const int DoubleField120FieldNumber = 120; + private double doubleField120_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField120 { + get { return doubleField120_; } + set { + doubleField120_ = value; + } + } + + /// Field number for the "double_field_121" field. + public const int DoubleField121FieldNumber = 121; + private double doubleField121_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField121 { + get { return doubleField121_; } + set { + doubleField121_ = value; + } + } + + /// Field number for the "double_field_122" field. + public const int DoubleField122FieldNumber = 122; + private double doubleField122_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField122 { + get { return doubleField122_; } + set { + doubleField122_ = value; + } + } + + /// Field number for the "double_field_123" field. + public const int DoubleField123FieldNumber = 123; + private double doubleField123_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField123 { + get { return doubleField123_; } + set { + doubleField123_ = value; + } + } + + /// Field number for the "double_field_124" field. + public const int DoubleField124FieldNumber = 124; + private double doubleField124_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField124 { + get { return doubleField124_; } + set { + doubleField124_ = value; + } + } + + /// Field number for the "double_field_8" field. + public const int DoubleField8FieldNumber = 8; + private double doubleField8_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField8 { + get { return doubleField8_; } + set { + doubleField8_ = value; + } + } + + /// Field number for the "double_field_9" field. + public const int DoubleField9FieldNumber = 9; + private double doubleField9_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField9 { + get { return doubleField9_; } + set { + doubleField9_ = value; + } + } + + /// Field number for the "double_field_98" field. + public const int DoubleField98FieldNumber = 98; + private double doubleField98_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField98 { + get { return doubleField98_; } + set { + doubleField98_ = value; + } + } + + /// Field number for the "double_field_10" field. + public const int DoubleField10FieldNumber = 10; + private double doubleField10_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField10 { + get { return doubleField10_; } + set { + doubleField10_ = value; + } + } + + /// Field number for the "double_field_11" field. + public const int DoubleField11FieldNumber = 11; + private double doubleField11_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField11 { + get { return doubleField11_; } + set { + doubleField11_ = value; + } + } + + /// Field number for the "double_field_99" field. + public const int DoubleField99FieldNumber = 99; + private double doubleField99_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField99 { + get { return doubleField99_; } + set { + doubleField99_ = value; + } + } + + /// Field number for the "double_field_84" field. + public const int DoubleField84FieldNumber = 84; + private double doubleField84_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField84 { + get { return doubleField84_; } + set { + doubleField84_ = value; + } + } + + /// Field number for the "double_field_14" field. + public const int DoubleField14FieldNumber = 14; + private double doubleField14_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField14 { + get { return doubleField14_; } + set { + doubleField14_ = value; + } + } + + /// Field number for the "double_field_77" field. + public const int DoubleField77FieldNumber = 77; + private double doubleField77_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField77 { + get { return doubleField77_; } + set { + doubleField77_ = value; + } + } + + /// Field number for the "double_field_15" field. + public const int DoubleField15FieldNumber = 15; + private double doubleField15_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField15 { + get { return doubleField15_; } + set { + doubleField15_ = value; + } + } + + /// Field number for the "int64_field_19" field. + public const int Int64Field19FieldNumber = 19; + private long int64Field19_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long Int64Field19 { + get { return int64Field19_; } + set { + int64Field19_ = value; + } + } + + /// Field number for the "int64_field_115" field. + public const int Int64Field115FieldNumber = 115; + private long int64Field115_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long Int64Field115 { + get { return int64Field115_; } + set { + int64Field115_ = value; + } + } + + /// Field number for the "double_field_116" field. + public const int DoubleField116FieldNumber = 116; + private double doubleField116_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField116 { + get { return doubleField116_; } + set { + doubleField116_ = value; + } + } + + /// Field number for the "int64_field_117" field. + public const int Int64Field117FieldNumber = 117; + private long int64Field117_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long Int64Field117 { + get { return int64Field117_; } + set { + int64Field117_ = value; + } + } + + /// Field number for the "double_field_20" field. + public const int DoubleField20FieldNumber = 20; + private double doubleField20_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField20 { + get { return doubleField20_; } + set { + doubleField20_ = value; + } + } + + /// Field number for the "double_field_21" field. + public const int DoubleField21FieldNumber = 21; + private double doubleField21_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField21 { + get { return doubleField21_; } + set { + doubleField21_ = value; + } + } + + /// Field number for the "string_field_73" field. + public const int StringField73FieldNumber = 73; + private string stringField73_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string StringField73 { + get { return stringField73_; } + set { + stringField73_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "string_field_74" field. + public const int StringField74FieldNumber = 74; + private string stringField74_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string StringField74 { + get { return stringField74_; } + set { + stringField74_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "double_field_22" field. + public const int DoubleField22FieldNumber = 22; + private double doubleField22_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField22 { + get { return doubleField22_; } + set { + doubleField22_ = value; + } + } + + /// Field number for the "double_field_69" field. + public const int DoubleField69FieldNumber = 69; + private double doubleField69_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField69 { + get { return doubleField69_; } + set { + doubleField69_ = value; + } + } + + /// Field number for the "double_field_70" field. + public const int DoubleField70FieldNumber = 70; + private double doubleField70_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField70 { + get { return doubleField70_; } + set { + doubleField70_ = value; + } + } + + /// Field number for the "double_field_71" field. + public const int DoubleField71FieldNumber = 71; + private double doubleField71_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField71 { + get { return doubleField71_; } + set { + doubleField71_ = value; + } + } + + /// Field number for the "double_field_72" field. + public const int DoubleField72FieldNumber = 72; + private double doubleField72_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField72 { + get { return doubleField72_; } + set { + doubleField72_ = value; + } + } + + /// Field number for the "double_field_25" field. + public const int DoubleField25FieldNumber = 25; + private double doubleField25_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField25 { + get { return doubleField25_; } + set { + doubleField25_ = value; + } + } + + /// Field number for the "int64_field_26" field. + public const int Int64Field26FieldNumber = 26; + private long int64Field26_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long Int64Field26 { + get { return int64Field26_; } + set { + int64Field26_ = value; + } + } + + /// Field number for the "double_field_68" field. + public const int DoubleField68FieldNumber = 68; + private double doubleField68_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField68 { + get { return doubleField68_; } + set { + doubleField68_ = value; + } + } + + /// Field number for the "double_field_28" field. + public const int DoubleField28FieldNumber = 28; + private double doubleField28_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField28 { + get { return doubleField28_; } + set { + doubleField28_ = value; + } + } + + /// Field number for the "double_field_106" field. + public const int DoubleField106FieldNumber = 106; + private double doubleField106_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField106 { + get { return doubleField106_; } + set { + doubleField106_ = value; + } + } + + /// Field number for the "double_field_29" field. + public const int DoubleField29FieldNumber = 29; + private double doubleField29_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField29 { + get { return doubleField29_; } + set { + doubleField29_ = value; + } + } + + /// Field number for the "double_field_30" field. + public const int DoubleField30FieldNumber = 30; + private double doubleField30_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField30 { + get { return doubleField30_; } + set { + doubleField30_ = value; + } + } + + /// Field number for the "double_field_101" field. + public const int DoubleField101FieldNumber = 101; + private double doubleField101_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField101 { + get { return doubleField101_; } + set { + doubleField101_ = value; + } + } + + /// Field number for the "double_field_102" field. + public const int DoubleField102FieldNumber = 102; + private double doubleField102_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField102 { + get { return doubleField102_; } + set { + doubleField102_ = value; + } + } + + /// Field number for the "double_field_103" field. + public const int DoubleField103FieldNumber = 103; + private double doubleField103_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField103 { + get { return doubleField103_; } + set { + doubleField103_ = value; + } + } + + /// Field number for the "double_field_104" field. + public const int DoubleField104FieldNumber = 104; + private double doubleField104_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField104 { + get { return doubleField104_; } + set { + doubleField104_ = value; + } + } + + /// Field number for the "double_field_105" field. + public const int DoubleField105FieldNumber = 105; + private double doubleField105_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField105 { + get { return doubleField105_; } + set { + doubleField105_ = value; + } + } + + /// Field number for the "double_field_31" field. + public const int DoubleField31FieldNumber = 31; + private double doubleField31_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField31 { + get { return doubleField31_; } + set { + doubleField31_ = value; + } + } + + /// Field number for the "int64_field_32" field. + public const int Int64Field32FieldNumber = 32; + private long int64Field32_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long Int64Field32 { + get { return int64Field32_; } + set { + int64Field32_ = value; + } + } + + /// Field number for the "double_field_75" field. + public const int DoubleField75FieldNumber = 75; + private double doubleField75_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField75 { + get { return doubleField75_; } + set { + doubleField75_ = value; + } + } + + /// Field number for the "double_field_129" field. + public const int DoubleField129FieldNumber = 129; + private double doubleField129_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField129 { + get { return doubleField129_; } + set { + doubleField129_ = value; + } + } + + /// Field number for the "enum_field_80" field. + public const int EnumField80FieldNumber = 80; + private int enumField80_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int EnumField80 { + get { return enumField80_; } + set { + enumField80_ = value; + } + } + + /// Field number for the "enum_field_81" field. + public const int EnumField81FieldNumber = 81; + private int enumField81_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int EnumField81 { + get { return enumField81_; } + set { + enumField81_ = value; + } + } + + /// Field number for the "int64_field_82" field. + public const int Int64Field82FieldNumber = 82; + private long int64Field82_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long Int64Field82 { + get { return int64Field82_; } + set { + int64Field82_ = value; + } + } + + /// Field number for the "enum_field_83" field. + public const int EnumField83FieldNumber = 83; + private int enumField83_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int EnumField83 { + get { return enumField83_; } + set { + enumField83_ = value; + } + } + + /// Field number for the "int64_field_85" field. + public const int Int64Field85FieldNumber = 85; + private long int64Field85_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long Int64Field85 { + get { return int64Field85_; } + set { + int64Field85_ = value; + } + } + + /// Field number for the "int64_field_86" field. + public const int Int64Field86FieldNumber = 86; + private long int64Field86_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long Int64Field86 { + get { return int64Field86_; } + set { + int64Field86_ = value; + } + } + + /// Field number for the "int64_field_87" field. + public const int Int64Field87FieldNumber = 87; + private long int64Field87_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long Int64Field87 { + get { return int64Field87_; } + set { + int64Field87_ = value; + } + } + + /// Field number for the "int64_field_125" field. + public const int Int64Field125FieldNumber = 125; + private long int64Field125_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long Int64Field125 { + get { return int64Field125_; } + set { + int64Field125_ = value; + } + } + + /// Field number for the "int64_field_37" field. + public const int Int64Field37FieldNumber = 37; + private long int64Field37_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long Int64Field37 { + get { return int64Field37_; } + set { + int64Field37_ = value; + } + } + + /// Field number for the "double_field_38" field. + public const int DoubleField38FieldNumber = 38; + private double doubleField38_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField38 { + get { return doubleField38_; } + set { + doubleField38_ = value; + } + } + + /// Field number for the "interactions" field. + public const int InteractionsFieldNumber = 39; + private long interactions_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long Interactions { + get { return interactions_; } + set { + interactions_ = value; + } + } + + /// Field number for the "repeated_int_field_100" field. + public const int RepeatedIntField100FieldNumber = 100; + private static readonly pb::FieldCodec _repeated_repeatedIntField100_codec + = pb::FieldCodec.ForInt32(802); + private readonly pbc::RepeatedField repeatedIntField100_ = new pbc::RepeatedField(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField RepeatedIntField100 { + get { return repeatedIntField100_; } + } + + /// Field number for the "double_field_40" field. + public const int DoubleField40FieldNumber = 40; + private double doubleField40_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField40 { + get { return doubleField40_; } + set { + doubleField40_ = value; + } + } + + /// Field number for the "int64_field_41" field. + public const int Int64Field41FieldNumber = 41; + private long int64Field41_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long Int64Field41 { + get { return int64Field41_; } + set { + int64Field41_ = value; + } + } + + /// Field number for the "int64_field_126" field. + public const int Int64Field126FieldNumber = 126; + private long int64Field126_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long Int64Field126 { + get { return int64Field126_; } + set { + int64Field126_ = value; + } + } + + /// Field number for the "int64_field_127" field. + public const int Int64Field127FieldNumber = 127; + private long int64Field127_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long Int64Field127 { + get { return int64Field127_; } + set { + int64Field127_ = value; + } + } + + /// Field number for the "double_field_128" field. + public const int DoubleField128FieldNumber = 128; + private double doubleField128_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField128 { + get { return doubleField128_; } + set { + doubleField128_ = value; + } + } + + /// Field number for the "double_field_109" field. + public const int DoubleField109FieldNumber = 109; + private double doubleField109_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField109 { + get { return doubleField109_; } + set { + doubleField109_ = value; + } + } + + /// Field number for the "int64_field_110" field. + public const int Int64Field110FieldNumber = 110; + private long int64Field110_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long Int64Field110 { + get { return int64Field110_; } + set { + int64Field110_ = value; + } + } + + /// Field number for the "double_field_111" field. + public const int DoubleField111FieldNumber = 111; + private double doubleField111_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField111 { + get { return doubleField111_; } + set { + doubleField111_ = value; + } + } + + /// Field number for the "int64_field_112" field. + public const int Int64Field112FieldNumber = 112; + private long int64Field112_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long Int64Field112 { + get { return int64Field112_; } + set { + int64Field112_ = value; + } + } + + /// Field number for the "double_field_113" field. + public const int DoubleField113FieldNumber = 113; + private double doubleField113_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField113 { + get { return doubleField113_; } + set { + doubleField113_ = value; + } + } + + /// Field number for the "int64_field_114" field. + public const int Int64Field114FieldNumber = 114; + private long int64Field114_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long Int64Field114 { + get { return int64Field114_; } + set { + int64Field114_ = value; + } + } + + /// Field number for the "double_field_42" field. + public const int DoubleField42FieldNumber = 42; + private double doubleField42_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField42 { + get { return doubleField42_; } + set { + doubleField42_ = value; + } + } + + /// Field number for the "int64_field_43" field. + public const int Int64Field43FieldNumber = 43; + private long int64Field43_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long Int64Field43 { + get { return int64Field43_; } + set { + int64Field43_ = value; + } } + /// Field number for the "int64_field_44" field. + public const int Int64Field44FieldNumber = 44; + private long int64Field44_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public ManyPrimitiveFieldsMessage Clone() { - return new ManyPrimitiveFieldsMessage(this); + public long Int64Field44 { + get { return int64Field44_; } + set { + int64Field44_ = value; + } } - /// Field number for the "double_field_95" field. - public const int DoubleField95FieldNumber = 95; - private double doubleField95_; + /// Field number for the "double_field_45" field. + public const int DoubleField45FieldNumber = 45; + private double doubleField45_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField95 { - get { return doubleField95_; } + public double DoubleField45 { + get { return doubleField45_; } set { - doubleField95_ = value; + doubleField45_ = value; } } - /// Field number for the "double_field_1" field. - public const int DoubleField1FieldNumber = 1; - private double doubleField1_; + /// Field number for the "double_field_46" field. + public const int DoubleField46FieldNumber = 46; + private double doubleField46_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField1 { - get { return doubleField1_; } + public double DoubleField46 { + get { return doubleField46_; } set { - doubleField1_ = value; + doubleField46_ = value; } } - /// Field number for the "double_field_79" field. - public const int DoubleField79FieldNumber = 79; - private double doubleField79_; + /// Field number for the "double_field_78" field. + public const int DoubleField78FieldNumber = 78; + private double doubleField78_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField79 { - get { return doubleField79_; } + public double DoubleField78 { + get { return doubleField78_; } set { - doubleField79_ = value; + doubleField78_ = value; } } - /// Field number for the "int64_field_2" field. - public const int Int64Field2FieldNumber = 2; - private long int64Field2_; + /// Field number for the "double_field_88" field. + public const int DoubleField88FieldNumber = 88; + private double doubleField88_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public long Int64Field2 { - get { return int64Field2_; } + public double DoubleField88 { + get { return doubleField88_; } set { - int64Field2_ = value; + doubleField88_ = value; } } - /// Field number for the "double_field_96" field. - public const int DoubleField96FieldNumber = 96; - private double doubleField96_; + /// Field number for the "double_field_47" field. + public const int DoubleField47FieldNumber = 47; + private double doubleField47_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField96 { - get { return doubleField96_; } + public double DoubleField47 { + get { return doubleField47_; } set { - doubleField96_ = value; + doubleField47_ = value; } } - /// Field number for the "int64_field_3" field. - public const int Int64Field3FieldNumber = 3; - private long int64Field3_; + /// Field number for the "double_field_89" field. + public const int DoubleField89FieldNumber = 89; + private double doubleField89_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public long Int64Field3 { - get { return int64Field3_; } + public double DoubleField89 { + get { return doubleField89_; } set { - int64Field3_ = value; + doubleField89_ = value; } } - /// Field number for the "int64_field_4" field. - public const int Int64Field4FieldNumber = 4; - private long int64Field4_; + /// Field number for the "double_field_48" field. + public const int DoubleField48FieldNumber = 48; + private double doubleField48_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public long Int64Field4 { - get { return int64Field4_; } + public double DoubleField48 { + get { return doubleField48_; } set { - int64Field4_ = value; + doubleField48_ = value; } } - /// Field number for the "double_field_97" field. - public const int DoubleField97FieldNumber = 97; - private double doubleField97_; + /// Field number for the "double_field_49" field. + public const int DoubleField49FieldNumber = 49; + private double doubleField49_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField97 { - get { return doubleField97_; } + public double DoubleField49 { + get { return doubleField49_; } set { - doubleField97_ = value; + doubleField49_ = value; } } - /// Field number for the "double_field_65" field. - public const int DoubleField65FieldNumber = 65; - private double doubleField65_; + /// Field number for the "double_field_50" field. + public const int DoubleField50FieldNumber = 50; + private double doubleField50_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField65 { - get { return doubleField65_; } + public double DoubleField50 { + get { return doubleField50_; } set { - doubleField65_ = value; + doubleField50_ = value; } } - /// Field number for the "double_field_66" field. - public const int DoubleField66FieldNumber = 66; - private double doubleField66_; + /// Field number for the "double_field_90" field. + public const int DoubleField90FieldNumber = 90; + private double doubleField90_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField66 { - get { return doubleField66_; } + public double DoubleField90 { + get { return doubleField90_; } set { - doubleField66_ = value; + doubleField90_ = value; } } - /// Field number for the "double_field_7" field. - public const int DoubleField7FieldNumber = 7; - private double doubleField7_; + /// Field number for the "double_field_51" field. + public const int DoubleField51FieldNumber = 51; + private double doubleField51_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField7 { - get { return doubleField7_; } + public double DoubleField51 { + get { return doubleField51_; } + set { + doubleField51_ = value; + } + } + + /// Field number for the "double_field_91" field. + public const int DoubleField91FieldNumber = 91; + private double doubleField91_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField91 { + get { return doubleField91_; } + set { + doubleField91_ = value; + } + } + + /// Field number for the "double_field_92" field. + public const int DoubleField92FieldNumber = 92; + private double doubleField92_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField92 { + get { return doubleField92_; } + set { + doubleField92_ = value; + } + } + + /// Field number for the "int64_field_107" field. + public const int Int64Field107FieldNumber = 107; + private long int64Field107_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long Int64Field107 { + get { return int64Field107_; } + set { + int64Field107_ = value; + } + } + + /// Field number for the "double_field_93" field. + public const int DoubleField93FieldNumber = 93; + private double doubleField93_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField93 { + get { return doubleField93_; } + set { + doubleField93_ = value; + } + } + + /// Field number for the "double_field_108" field. + public const int DoubleField108FieldNumber = 108; + private double doubleField108_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField108 { + get { return doubleField108_; } + set { + doubleField108_ = value; + } + } + + /// Field number for the "double_field_52" field. + public const int DoubleField52FieldNumber = 52; + private double doubleField52_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField52 { + get { return doubleField52_; } + set { + doubleField52_ = value; + } + } + + /// Field number for the "double_field_53" field. + public const int DoubleField53FieldNumber = 53; + private double doubleField53_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField53 { + get { return doubleField53_; } + set { + doubleField53_ = value; + } + } + + /// Field number for the "double_field_94" field. + public const int DoubleField94FieldNumber = 94; + private double doubleField94_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField94 { + get { return doubleField94_; } + set { + doubleField94_ = value; + } + } + + /// Field number for the "double_field_54" field. + public const int DoubleField54FieldNumber = 54; + private double doubleField54_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField54 { + get { return doubleField54_; } + set { + doubleField54_ = value; + } + } + + /// Field number for the "double_field_55" field. + public const int DoubleField55FieldNumber = 55; + private double doubleField55_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public double DoubleField55 { + get { return doubleField55_; } set { - doubleField7_ = value; + doubleField55_ = value; } } - /// Field number for the "double_field_62" field. - public const int DoubleField62FieldNumber = 62; - private double doubleField62_; + /// Field number for the "double_field_56" field. + public const int DoubleField56FieldNumber = 56; + private double doubleField56_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField62 { - get { return doubleField62_; } + public double DoubleField56 { + get { return doubleField56_; } set { - doubleField62_ = value; + doubleField56_ = value; } } - /// Field number for the "double_field_118" field. - public const int DoubleField118FieldNumber = 118; - private double doubleField118_; + /// Field number for the "double_field_57" field. + public const int DoubleField57FieldNumber = 57; + private double doubleField57_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField118 { - get { return doubleField118_; } + public double DoubleField57 { + get { return doubleField57_; } set { - doubleField118_ = value; + doubleField57_ = value; } } - /// Field number for the "double_field_119" field. - public const int DoubleField119FieldNumber = 119; - private double doubleField119_; + /// Field number for the "double_field_58" field. + public const int DoubleField58FieldNumber = 58; + private double doubleField58_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField119 { - get { return doubleField119_; } + public double DoubleField58 { + get { return doubleField58_; } set { - doubleField119_ = value; + doubleField58_ = value; } } - /// Field number for the "double_field_67" field. - public const int DoubleField67FieldNumber = 67; - private double doubleField67_; + /// Field number for the "int64_field_59" field. + public const int Int64Field59FieldNumber = 59; + private long int64Field59_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField67 { - get { return doubleField67_; } + public long Int64Field59 { + get { return int64Field59_; } set { - doubleField67_ = value; + int64Field59_ = value; } } - /// Field number for the "double_field_120" field. - public const int DoubleField120FieldNumber = 120; - private double doubleField120_; + /// Field number for the "int64_field_60" field. + public const int Int64Field60FieldNumber = 60; + private long int64Field60_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField120 { - get { return doubleField120_; } + public long Int64Field60 { + get { return int64Field60_; } set { - doubleField120_ = value; + int64Field60_ = value; } } - /// Field number for the "double_field_121" field. - public const int DoubleField121FieldNumber = 121; - private double doubleField121_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField121 { - get { return doubleField121_; } - set { - doubleField121_ = value; - } + public override bool Equals(object other) { + return Equals(other as ManyPrimitiveFieldsMessage); } - /// Field number for the "double_field_122" field. - public const int DoubleField122FieldNumber = 122; - private double doubleField122_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField122 { - get { return doubleField122_; } - set { - doubleField122_ = value; + public bool Equals(ManyPrimitiveFieldsMessage other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; } + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField95, other.DoubleField95)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField1, other.DoubleField1)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField79, other.DoubleField79)) return false; + if (Int64Field2 != other.Int64Field2) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField96, other.DoubleField96)) return false; + if (Int64Field3 != other.Int64Field3) return false; + if (Int64Field4 != other.Int64Field4) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField97, other.DoubleField97)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField65, other.DoubleField65)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField66, other.DoubleField66)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField7, other.DoubleField7)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField62, other.DoubleField62)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField118, other.DoubleField118)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField119, other.DoubleField119)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField67, other.DoubleField67)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField120, other.DoubleField120)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField121, other.DoubleField121)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField122, other.DoubleField122)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField123, other.DoubleField123)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField124, other.DoubleField124)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField8, other.DoubleField8)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField9, other.DoubleField9)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField98, other.DoubleField98)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField10, other.DoubleField10)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField11, other.DoubleField11)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField99, other.DoubleField99)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField84, other.DoubleField84)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField14, other.DoubleField14)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField77, other.DoubleField77)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField15, other.DoubleField15)) return false; + if (Int64Field19 != other.Int64Field19) return false; + if (Int64Field115 != other.Int64Field115) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField116, other.DoubleField116)) return false; + if (Int64Field117 != other.Int64Field117) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField20, other.DoubleField20)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField21, other.DoubleField21)) return false; + if (StringField73 != other.StringField73) return false; + if (StringField74 != other.StringField74) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField22, other.DoubleField22)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField69, other.DoubleField69)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField70, other.DoubleField70)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField71, other.DoubleField71)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField72, other.DoubleField72)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField25, other.DoubleField25)) return false; + if (Int64Field26 != other.Int64Field26) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField68, other.DoubleField68)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField28, other.DoubleField28)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField106, other.DoubleField106)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField29, other.DoubleField29)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField30, other.DoubleField30)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField101, other.DoubleField101)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField102, other.DoubleField102)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField103, other.DoubleField103)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField104, other.DoubleField104)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField105, other.DoubleField105)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField31, other.DoubleField31)) return false; + if (Int64Field32 != other.Int64Field32) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField75, other.DoubleField75)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField129, other.DoubleField129)) return false; + if (EnumField80 != other.EnumField80) return false; + if (EnumField81 != other.EnumField81) return false; + if (Int64Field82 != other.Int64Field82) return false; + if (EnumField83 != other.EnumField83) return false; + if (Int64Field85 != other.Int64Field85) return false; + if (Int64Field86 != other.Int64Field86) return false; + if (Int64Field87 != other.Int64Field87) return false; + if (Int64Field125 != other.Int64Field125) return false; + if (Int64Field37 != other.Int64Field37) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField38, other.DoubleField38)) return false; + if (Interactions != other.Interactions) return false; + if(!repeatedIntField100_.Equals(other.repeatedIntField100_)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField40, other.DoubleField40)) return false; + if (Int64Field41 != other.Int64Field41) return false; + if (Int64Field126 != other.Int64Field126) return false; + if (Int64Field127 != other.Int64Field127) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField128, other.DoubleField128)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField109, other.DoubleField109)) return false; + if (Int64Field110 != other.Int64Field110) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField111, other.DoubleField111)) return false; + if (Int64Field112 != other.Int64Field112) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField113, other.DoubleField113)) return false; + if (Int64Field114 != other.Int64Field114) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField42, other.DoubleField42)) return false; + if (Int64Field43 != other.Int64Field43) return false; + if (Int64Field44 != other.Int64Field44) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField45, other.DoubleField45)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField46, other.DoubleField46)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField78, other.DoubleField78)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField88, other.DoubleField88)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField47, other.DoubleField47)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField89, other.DoubleField89)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField48, other.DoubleField48)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField49, other.DoubleField49)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField50, other.DoubleField50)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField90, other.DoubleField90)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField51, other.DoubleField51)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField91, other.DoubleField91)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField92, other.DoubleField92)) return false; + if (Int64Field107 != other.Int64Field107) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField93, other.DoubleField93)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField108, other.DoubleField108)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField52, other.DoubleField52)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField53, other.DoubleField53)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField94, other.DoubleField94)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField54, other.DoubleField54)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField55, other.DoubleField55)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField56, other.DoubleField56)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField57, other.DoubleField57)) return false; + if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField58, other.DoubleField58)) return false; + if (Int64Field59 != other.Int64Field59) return false; + if (Int64Field60 != other.Int64Field60) return false; + return Equals(_unknownFields, other._unknownFields); } - /// Field number for the "double_field_123" field. - public const int DoubleField123FieldNumber = 123; - private double doubleField123_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField123 { - get { return doubleField123_; } - set { - doubleField123_ = value; + public override int GetHashCode() { + int hash = 1; + if (DoubleField95 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField95); + if (DoubleField1 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField1); + if (DoubleField79 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField79); + if (Int64Field2 != 0L) hash ^= Int64Field2.GetHashCode(); + if (DoubleField96 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField96); + if (Int64Field3 != 0L) hash ^= Int64Field3.GetHashCode(); + if (Int64Field4 != 0L) hash ^= Int64Field4.GetHashCode(); + if (DoubleField97 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField97); + if (DoubleField65 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField65); + if (DoubleField66 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField66); + if (DoubleField7 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField7); + if (DoubleField62 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField62); + if (DoubleField118 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField118); + if (DoubleField119 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField119); + if (DoubleField67 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField67); + if (DoubleField120 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField120); + if (DoubleField121 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField121); + if (DoubleField122 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField122); + if (DoubleField123 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField123); + if (DoubleField124 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField124); + if (DoubleField8 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField8); + if (DoubleField9 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField9); + if (DoubleField98 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField98); + if (DoubleField10 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField10); + if (DoubleField11 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField11); + if (DoubleField99 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField99); + if (DoubleField84 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField84); + if (DoubleField14 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField14); + if (DoubleField77 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField77); + if (DoubleField15 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField15); + if (Int64Field19 != 0L) hash ^= Int64Field19.GetHashCode(); + if (Int64Field115 != 0L) hash ^= Int64Field115.GetHashCode(); + if (DoubleField116 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField116); + if (Int64Field117 != 0L) hash ^= Int64Field117.GetHashCode(); + if (DoubleField20 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField20); + if (DoubleField21 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField21); + if (StringField73.Length != 0) hash ^= StringField73.GetHashCode(); + if (StringField74.Length != 0) hash ^= StringField74.GetHashCode(); + if (DoubleField22 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField22); + if (DoubleField69 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField69); + if (DoubleField70 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField70); + if (DoubleField71 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField71); + if (DoubleField72 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField72); + if (DoubleField25 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField25); + if (Int64Field26 != 0L) hash ^= Int64Field26.GetHashCode(); + if (DoubleField68 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField68); + if (DoubleField28 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField28); + if (DoubleField106 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField106); + if (DoubleField29 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField29); + if (DoubleField30 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField30); + if (DoubleField101 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField101); + if (DoubleField102 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField102); + if (DoubleField103 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField103); + if (DoubleField104 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField104); + if (DoubleField105 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField105); + if (DoubleField31 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField31); + if (Int64Field32 != 0L) hash ^= Int64Field32.GetHashCode(); + if (DoubleField75 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField75); + if (DoubleField129 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField129); + if (EnumField80 != 0) hash ^= EnumField80.GetHashCode(); + if (EnumField81 != 0) hash ^= EnumField81.GetHashCode(); + if (Int64Field82 != 0L) hash ^= Int64Field82.GetHashCode(); + if (EnumField83 != 0) hash ^= EnumField83.GetHashCode(); + if (Int64Field85 != 0L) hash ^= Int64Field85.GetHashCode(); + if (Int64Field86 != 0L) hash ^= Int64Field86.GetHashCode(); + if (Int64Field87 != 0L) hash ^= Int64Field87.GetHashCode(); + if (Int64Field125 != 0L) hash ^= Int64Field125.GetHashCode(); + if (Int64Field37 != 0L) hash ^= Int64Field37.GetHashCode(); + if (DoubleField38 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField38); + if (Interactions != 0L) hash ^= Interactions.GetHashCode(); + hash ^= repeatedIntField100_.GetHashCode(); + if (DoubleField40 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField40); + if (Int64Field41 != 0L) hash ^= Int64Field41.GetHashCode(); + if (Int64Field126 != 0L) hash ^= Int64Field126.GetHashCode(); + if (Int64Field127 != 0L) hash ^= Int64Field127.GetHashCode(); + if (DoubleField128 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField128); + if (DoubleField109 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField109); + if (Int64Field110 != 0L) hash ^= Int64Field110.GetHashCode(); + if (DoubleField111 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField111); + if (Int64Field112 != 0L) hash ^= Int64Field112.GetHashCode(); + if (DoubleField113 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField113); + if (Int64Field114 != 0L) hash ^= Int64Field114.GetHashCode(); + if (DoubleField42 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField42); + if (Int64Field43 != 0L) hash ^= Int64Field43.GetHashCode(); + if (Int64Field44 != 0L) hash ^= Int64Field44.GetHashCode(); + if (DoubleField45 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField45); + if (DoubleField46 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField46); + if (DoubleField78 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField78); + if (DoubleField88 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField88); + if (DoubleField47 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField47); + if (DoubleField89 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField89); + if (DoubleField48 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField48); + if (DoubleField49 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField49); + if (DoubleField50 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField50); + if (DoubleField90 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField90); + if (DoubleField51 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField51); + if (DoubleField91 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField91); + if (DoubleField92 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField92); + if (Int64Field107 != 0L) hash ^= Int64Field107.GetHashCode(); + if (DoubleField93 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField93); + if (DoubleField108 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField108); + if (DoubleField52 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField52); + if (DoubleField53 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField53); + if (DoubleField94 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField94); + if (DoubleField54 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField54); + if (DoubleField55 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField55); + if (DoubleField56 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField56); + if (DoubleField57 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField57); + if (DoubleField58 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField58); + if (Int64Field59 != 0L) hash ^= Int64Field59.GetHashCode(); + if (Int64Field60 != 0L) hash ^= Int64Field60.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); } + return hash; } - /// Field number for the "double_field_124" field. - public const int DoubleField124FieldNumber = 124; - private double doubleField124_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField124 { - get { return doubleField124_; } - set { - doubleField124_ = value; - } + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); } - /// Field number for the "double_field_8" field. - public const int DoubleField8FieldNumber = 8; - private double doubleField8_; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField8 { - get { return doubleField8_; } - set { - doubleField8_ = value; + public void WriteTo(pb::CodedOutputStream output) { + if (DoubleField1 != 0D) { + output.WriteRawTag(9); + output.WriteDouble(DoubleField1); } - } - - /// Field number for the "double_field_9" field. - public const int DoubleField9FieldNumber = 9; - private double doubleField9_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField9 { - get { return doubleField9_; } - set { - doubleField9_ = value; + if (Int64Field2 != 0L) { + output.WriteRawTag(16); + output.WriteInt64(Int64Field2); } - } - - /// Field number for the "double_field_98" field. - public const int DoubleField98FieldNumber = 98; - private double doubleField98_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField98 { - get { return doubleField98_; } - set { - doubleField98_ = value; + if (Int64Field3 != 0L) { + output.WriteRawTag(24); + output.WriteInt64(Int64Field3); } - } - - /// Field number for the "double_field_10" field. - public const int DoubleField10FieldNumber = 10; - private double doubleField10_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField10 { - get { return doubleField10_; } - set { - doubleField10_ = value; + if (Int64Field4 != 0L) { + output.WriteRawTag(32); + output.WriteInt64(Int64Field4); } - } - - /// Field number for the "double_field_11" field. - public const int DoubleField11FieldNumber = 11; - private double doubleField11_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField11 { - get { return doubleField11_; } - set { - doubleField11_ = value; + if (DoubleField7 != 0D) { + output.WriteRawTag(57); + output.WriteDouble(DoubleField7); } - } - - /// Field number for the "double_field_99" field. - public const int DoubleField99FieldNumber = 99; - private double doubleField99_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField99 { - get { return doubleField99_; } - set { - doubleField99_ = value; + if (DoubleField8 != 0D) { + output.WriteRawTag(65); + output.WriteDouble(DoubleField8); } - } - - /// Field number for the "double_field_84" field. - public const int DoubleField84FieldNumber = 84; - private double doubleField84_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField84 { - get { return doubleField84_; } - set { - doubleField84_ = value; + if (DoubleField9 != 0D) { + output.WriteRawTag(73); + output.WriteDouble(DoubleField9); } - } - - /// Field number for the "double_field_14" field. - public const int DoubleField14FieldNumber = 14; - private double doubleField14_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField14 { - get { return doubleField14_; } - set { - doubleField14_ = value; + if (DoubleField10 != 0D) { + output.WriteRawTag(81); + output.WriteDouble(DoubleField10); } - } - - /// Field number for the "double_field_77" field. - public const int DoubleField77FieldNumber = 77; - private double doubleField77_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField77 { - get { return doubleField77_; } - set { - doubleField77_ = value; + if (DoubleField11 != 0D) { + output.WriteRawTag(89); + output.WriteDouble(DoubleField11); } - } - - /// Field number for the "double_field_15" field. - public const int DoubleField15FieldNumber = 15; - private double doubleField15_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField15 { - get { return doubleField15_; } - set { - doubleField15_ = value; + if (DoubleField14 != 0D) { + output.WriteRawTag(113); + output.WriteDouble(DoubleField14); } - } - - /// Field number for the "int64_field_19" field. - public const int Int64Field19FieldNumber = 19; - private long int64Field19_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public long Int64Field19 { - get { return int64Field19_; } - set { - int64Field19_ = value; + if (DoubleField15 != 0D) { + output.WriteRawTag(121); + output.WriteDouble(DoubleField15); } - } - - /// Field number for the "int64_field_115" field. - public const int Int64Field115FieldNumber = 115; - private long int64Field115_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public long Int64Field115 { - get { return int64Field115_; } - set { - int64Field115_ = value; + if (Int64Field19 != 0L) { + output.WriteRawTag(152, 1); + output.WriteInt64(Int64Field19); } - } - - /// Field number for the "double_field_116" field. - public const int DoubleField116FieldNumber = 116; - private double doubleField116_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField116 { - get { return doubleField116_; } - set { - doubleField116_ = value; + if (DoubleField20 != 0D) { + output.WriteRawTag(161, 1); + output.WriteDouble(DoubleField20); } - } - - /// Field number for the "int64_field_117" field. - public const int Int64Field117FieldNumber = 117; - private long int64Field117_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public long Int64Field117 { - get { return int64Field117_; } - set { - int64Field117_ = value; + if (DoubleField21 != 0D) { + output.WriteRawTag(169, 1); + output.WriteDouble(DoubleField21); } - } - - /// Field number for the "double_field_20" field. - public const int DoubleField20FieldNumber = 20; - private double doubleField20_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField20 { - get { return doubleField20_; } - set { - doubleField20_ = value; + if (DoubleField22 != 0D) { + output.WriteRawTag(177, 1); + output.WriteDouble(DoubleField22); } - } - - /// Field number for the "double_field_21" field. - public const int DoubleField21FieldNumber = 21; - private double doubleField21_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField21 { - get { return doubleField21_; } - set { - doubleField21_ = value; + if (DoubleField25 != 0D) { + output.WriteRawTag(201, 1); + output.WriteDouble(DoubleField25); } - } - - /// Field number for the "string_field_73" field. - public const int StringField73FieldNumber = 73; - private string stringField73_ = ""; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public string StringField73 { - get { return stringField73_; } - set { - stringField73_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + if (Int64Field26 != 0L) { + output.WriteRawTag(208, 1); + output.WriteInt64(Int64Field26); } - } - - /// Field number for the "string_field_74" field. - public const int StringField74FieldNumber = 74; - private string stringField74_ = ""; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public string StringField74 { - get { return stringField74_; } - set { - stringField74_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + if (DoubleField28 != 0D) { + output.WriteRawTag(225, 1); + output.WriteDouble(DoubleField28); } - } - - /// Field number for the "double_field_22" field. - public const int DoubleField22FieldNumber = 22; - private double doubleField22_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField22 { - get { return doubleField22_; } - set { - doubleField22_ = value; + if (DoubleField29 != 0D) { + output.WriteRawTag(233, 1); + output.WriteDouble(DoubleField29); } - } - - /// Field number for the "double_field_69" field. - public const int DoubleField69FieldNumber = 69; - private double doubleField69_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField69 { - get { return doubleField69_; } - set { - doubleField69_ = value; + if (DoubleField30 != 0D) { + output.WriteRawTag(241, 1); + output.WriteDouble(DoubleField30); } - } - - /// Field number for the "double_field_70" field. - public const int DoubleField70FieldNumber = 70; - private double doubleField70_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField70 { - get { return doubleField70_; } - set { - doubleField70_ = value; + if (DoubleField31 != 0D) { + output.WriteRawTag(249, 1); + output.WriteDouble(DoubleField31); } - } - - /// Field number for the "double_field_71" field. - public const int DoubleField71FieldNumber = 71; - private double doubleField71_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField71 { - get { return doubleField71_; } - set { - doubleField71_ = value; + if (Int64Field32 != 0L) { + output.WriteRawTag(128, 2); + output.WriteInt64(Int64Field32); } - } - - /// Field number for the "double_field_72" field. - public const int DoubleField72FieldNumber = 72; - private double doubleField72_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField72 { - get { return doubleField72_; } - set { - doubleField72_ = value; + if (Int64Field37 != 0L) { + output.WriteRawTag(168, 2); + output.WriteInt64(Int64Field37); } - } - - /// Field number for the "double_field_25" field. - public const int DoubleField25FieldNumber = 25; - private double doubleField25_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField25 { - get { return doubleField25_; } - set { - doubleField25_ = value; + if (DoubleField38 != 0D) { + output.WriteRawTag(177, 2); + output.WriteDouble(DoubleField38); } - } - - /// Field number for the "int64_field_26" field. - public const int Int64Field26FieldNumber = 26; - private long int64Field26_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public long Int64Field26 { - get { return int64Field26_; } - set { - int64Field26_ = value; + if (Interactions != 0L) { + output.WriteRawTag(184, 2); + output.WriteInt64(Interactions); } - } - - /// Field number for the "double_field_68" field. - public const int DoubleField68FieldNumber = 68; - private double doubleField68_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField68 { - get { return doubleField68_; } - set { - doubleField68_ = value; + if (DoubleField40 != 0D) { + output.WriteRawTag(193, 2); + output.WriteDouble(DoubleField40); } - } - - /// Field number for the "double_field_28" field. - public const int DoubleField28FieldNumber = 28; - private double doubleField28_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField28 { - get { return doubleField28_; } - set { - doubleField28_ = value; + if (Int64Field41 != 0L) { + output.WriteRawTag(200, 2); + output.WriteInt64(Int64Field41); } - } - - /// Field number for the "double_field_106" field. - public const int DoubleField106FieldNumber = 106; - private double doubleField106_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField106 { - get { return doubleField106_; } - set { - doubleField106_ = value; + if (DoubleField42 != 0D) { + output.WriteRawTag(209, 2); + output.WriteDouble(DoubleField42); } - } - - /// Field number for the "double_field_29" field. - public const int DoubleField29FieldNumber = 29; - private double doubleField29_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField29 { - get { return doubleField29_; } - set { - doubleField29_ = value; + if (Int64Field43 != 0L) { + output.WriteRawTag(216, 2); + output.WriteInt64(Int64Field43); } - } - - /// Field number for the "double_field_30" field. - public const int DoubleField30FieldNumber = 30; - private double doubleField30_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField30 { - get { return doubleField30_; } - set { - doubleField30_ = value; + if (Int64Field44 != 0L) { + output.WriteRawTag(224, 2); + output.WriteInt64(Int64Field44); } - } - - /// Field number for the "double_field_101" field. - public const int DoubleField101FieldNumber = 101; - private double doubleField101_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField101 { - get { return doubleField101_; } - set { - doubleField101_ = value; + if (DoubleField45 != 0D) { + output.WriteRawTag(233, 2); + output.WriteDouble(DoubleField45); } - } - - /// Field number for the "double_field_102" field. - public const int DoubleField102FieldNumber = 102; - private double doubleField102_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField102 { - get { return doubleField102_; } - set { - doubleField102_ = value; + if (DoubleField46 != 0D) { + output.WriteRawTag(241, 2); + output.WriteDouble(DoubleField46); } - } - - /// Field number for the "double_field_103" field. - public const int DoubleField103FieldNumber = 103; - private double doubleField103_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField103 { - get { return doubleField103_; } - set { - doubleField103_ = value; + if (DoubleField47 != 0D) { + output.WriteRawTag(249, 2); + output.WriteDouble(DoubleField47); + } + if (DoubleField48 != 0D) { + output.WriteRawTag(129, 3); + output.WriteDouble(DoubleField48); + } + if (DoubleField49 != 0D) { + output.WriteRawTag(137, 3); + output.WriteDouble(DoubleField49); } - } - - /// Field number for the "double_field_104" field. - public const int DoubleField104FieldNumber = 104; - private double doubleField104_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField104 { - get { return doubleField104_; } - set { - doubleField104_ = value; + if (DoubleField50 != 0D) { + output.WriteRawTag(145, 3); + output.WriteDouble(DoubleField50); } - } - - /// Field number for the "double_field_105" field. - public const int DoubleField105FieldNumber = 105; - private double doubleField105_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField105 { - get { return doubleField105_; } - set { - doubleField105_ = value; + if (DoubleField51 != 0D) { + output.WriteRawTag(153, 3); + output.WriteDouble(DoubleField51); } - } - - /// Field number for the "double_field_31" field. - public const int DoubleField31FieldNumber = 31; - private double doubleField31_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField31 { - get { return doubleField31_; } - set { - doubleField31_ = value; + if (DoubleField52 != 0D) { + output.WriteRawTag(161, 3); + output.WriteDouble(DoubleField52); } - } - - /// Field number for the "int64_field_32" field. - public const int Int64Field32FieldNumber = 32; - private long int64Field32_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public long Int64Field32 { - get { return int64Field32_; } - set { - int64Field32_ = value; + if (DoubleField53 != 0D) { + output.WriteRawTag(169, 3); + output.WriteDouble(DoubleField53); } - } - - /// Field number for the "double_field_75" field. - public const int DoubleField75FieldNumber = 75; - private double doubleField75_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField75 { - get { return doubleField75_; } - set { - doubleField75_ = value; + if (DoubleField54 != 0D) { + output.WriteRawTag(177, 3); + output.WriteDouble(DoubleField54); } - } - - /// Field number for the "double_field_129" field. - public const int DoubleField129FieldNumber = 129; - private double doubleField129_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField129 { - get { return doubleField129_; } - set { - doubleField129_ = value; + if (DoubleField55 != 0D) { + output.WriteRawTag(185, 3); + output.WriteDouble(DoubleField55); } - } - - /// Field number for the "enum_field_80" field. - public const int EnumField80FieldNumber = 80; - private int enumField80_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public int EnumField80 { - get { return enumField80_; } - set { - enumField80_ = value; + if (DoubleField56 != 0D) { + output.WriteRawTag(193, 3); + output.WriteDouble(DoubleField56); } - } - - /// Field number for the "enum_field_81" field. - public const int EnumField81FieldNumber = 81; - private int enumField81_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public int EnumField81 { - get { return enumField81_; } - set { - enumField81_ = value; + if (DoubleField57 != 0D) { + output.WriteRawTag(201, 3); + output.WriteDouble(DoubleField57); } - } - - /// Field number for the "int64_field_82" field. - public const int Int64Field82FieldNumber = 82; - private long int64Field82_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public long Int64Field82 { - get { return int64Field82_; } - set { - int64Field82_ = value; + if (DoubleField58 != 0D) { + output.WriteRawTag(209, 3); + output.WriteDouble(DoubleField58); } - } - - /// Field number for the "enum_field_83" field. - public const int EnumField83FieldNumber = 83; - private int enumField83_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public int EnumField83 { - get { return enumField83_; } - set { - enumField83_ = value; + if (Int64Field59 != 0L) { + output.WriteRawTag(216, 3); + output.WriteInt64(Int64Field59); } - } - - /// Field number for the "int64_field_85" field. - public const int Int64Field85FieldNumber = 85; - private long int64Field85_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public long Int64Field85 { - get { return int64Field85_; } - set { - int64Field85_ = value; + if (Int64Field60 != 0L) { + output.WriteRawTag(224, 3); + output.WriteInt64(Int64Field60); } - } - - /// Field number for the "int64_field_86" field. - public const int Int64Field86FieldNumber = 86; - private long int64Field86_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public long Int64Field86 { - get { return int64Field86_; } - set { - int64Field86_ = value; + if (DoubleField62 != 0D) { + output.WriteRawTag(241, 3); + output.WriteDouble(DoubleField62); } - } - - /// Field number for the "int64_field_87" field. - public const int Int64Field87FieldNumber = 87; - private long int64Field87_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public long Int64Field87 { - get { return int64Field87_; } - set { - int64Field87_ = value; + if (DoubleField65 != 0D) { + output.WriteRawTag(137, 4); + output.WriteDouble(DoubleField65); } - } - - /// Field number for the "int64_field_125" field. - public const int Int64Field125FieldNumber = 125; - private long int64Field125_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public long Int64Field125 { - get { return int64Field125_; } - set { - int64Field125_ = value; + if (DoubleField66 != 0D) { + output.WriteRawTag(145, 4); + output.WriteDouble(DoubleField66); } - } - - /// Field number for the "int64_field_37" field. - public const int Int64Field37FieldNumber = 37; - private long int64Field37_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public long Int64Field37 { - get { return int64Field37_; } - set { - int64Field37_ = value; + if (DoubleField67 != 0D) { + output.WriteRawTag(153, 4); + output.WriteDouble(DoubleField67); } - } - - /// Field number for the "double_field_38" field. - public const int DoubleField38FieldNumber = 38; - private double doubleField38_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField38 { - get { return doubleField38_; } - set { - doubleField38_ = value; + if (DoubleField68 != 0D) { + output.WriteRawTag(161, 4); + output.WriteDouble(DoubleField68); } - } - - /// Field number for the "interactions" field. - public const int InteractionsFieldNumber = 39; - private long interactions_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public long Interactions { - get { return interactions_; } - set { - interactions_ = value; + if (DoubleField69 != 0D) { + output.WriteRawTag(169, 4); + output.WriteDouble(DoubleField69); } - } - - /// Field number for the "repeated_int_field_100" field. - public const int RepeatedIntField100FieldNumber = 100; - private static readonly pb::FieldCodec _repeated_repeatedIntField100_codec - = pb::FieldCodec.ForInt32(802); - private readonly pbc::RepeatedField repeatedIntField100_ = new pbc::RepeatedField(); - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public pbc::RepeatedField RepeatedIntField100 { - get { return repeatedIntField100_; } - } - - /// Field number for the "double_field_40" field. - public const int DoubleField40FieldNumber = 40; - private double doubleField40_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField40 { - get { return doubleField40_; } - set { - doubleField40_ = value; + if (DoubleField70 != 0D) { + output.WriteRawTag(177, 4); + output.WriteDouble(DoubleField70); } - } - - /// Field number for the "int64_field_41" field. - public const int Int64Field41FieldNumber = 41; - private long int64Field41_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public long Int64Field41 { - get { return int64Field41_; } - set { - int64Field41_ = value; + if (DoubleField71 != 0D) { + output.WriteRawTag(185, 4); + output.WriteDouble(DoubleField71); } - } - - /// Field number for the "int64_field_126" field. - public const int Int64Field126FieldNumber = 126; - private long int64Field126_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public long Int64Field126 { - get { return int64Field126_; } - set { - int64Field126_ = value; + if (DoubleField72 != 0D) { + output.WriteRawTag(193, 4); + output.WriteDouble(DoubleField72); } - } - - /// Field number for the "int64_field_127" field. - public const int Int64Field127FieldNumber = 127; - private long int64Field127_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public long Int64Field127 { - get { return int64Field127_; } - set { - int64Field127_ = value; + if (StringField73.Length != 0) { + output.WriteRawTag(202, 4); + output.WriteString(StringField73); } - } - - /// Field number for the "double_field_128" field. - public const int DoubleField128FieldNumber = 128; - private double doubleField128_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField128 { - get { return doubleField128_; } - set { - doubleField128_ = value; + if (StringField74.Length != 0) { + output.WriteRawTag(210, 4); + output.WriteString(StringField74); } - } - - /// Field number for the "double_field_109" field. - public const int DoubleField109FieldNumber = 109; - private double doubleField109_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField109 { - get { return doubleField109_; } - set { - doubleField109_ = value; + if (DoubleField75 != 0D) { + output.WriteRawTag(217, 4); + output.WriteDouble(DoubleField75); } - } - - /// Field number for the "int64_field_110" field. - public const int Int64Field110FieldNumber = 110; - private long int64Field110_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public long Int64Field110 { - get { return int64Field110_; } - set { - int64Field110_ = value; + if (DoubleField77 != 0D) { + output.WriteRawTag(233, 4); + output.WriteDouble(DoubleField77); } - } - - /// Field number for the "double_field_111" field. - public const int DoubleField111FieldNumber = 111; - private double doubleField111_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField111 { - get { return doubleField111_; } - set { - doubleField111_ = value; + if (DoubleField78 != 0D) { + output.WriteRawTag(241, 4); + output.WriteDouble(DoubleField78); } - } - - /// Field number for the "int64_field_112" field. - public const int Int64Field112FieldNumber = 112; - private long int64Field112_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public long Int64Field112 { - get { return int64Field112_; } - set { - int64Field112_ = value; + if (DoubleField79 != 0D) { + output.WriteRawTag(249, 4); + output.WriteDouble(DoubleField79); } - } - - /// Field number for the "double_field_113" field. - public const int DoubleField113FieldNumber = 113; - private double doubleField113_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField113 { - get { return doubleField113_; } - set { - doubleField113_ = value; + if (EnumField80 != 0) { + output.WriteRawTag(128, 5); + output.WriteInt32(EnumField80); } - } - - /// Field number for the "int64_field_114" field. - public const int Int64Field114FieldNumber = 114; - private long int64Field114_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public long Int64Field114 { - get { return int64Field114_; } - set { - int64Field114_ = value; + if (EnumField81 != 0) { + output.WriteRawTag(136, 5); + output.WriteInt32(EnumField81); } - } - - /// Field number for the "double_field_42" field. - public const int DoubleField42FieldNumber = 42; - private double doubleField42_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField42 { - get { return doubleField42_; } - set { - doubleField42_ = value; + if (Int64Field82 != 0L) { + output.WriteRawTag(144, 5); + output.WriteInt64(Int64Field82); } - } - - /// Field number for the "int64_field_43" field. - public const int Int64Field43FieldNumber = 43; - private long int64Field43_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public long Int64Field43 { - get { return int64Field43_; } - set { - int64Field43_ = value; + if (EnumField83 != 0) { + output.WriteRawTag(152, 5); + output.WriteInt32(EnumField83); } - } - - /// Field number for the "int64_field_44" field. - public const int Int64Field44FieldNumber = 44; - private long int64Field44_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public long Int64Field44 { - get { return int64Field44_; } - set { - int64Field44_ = value; + if (DoubleField84 != 0D) { + output.WriteRawTag(161, 5); + output.WriteDouble(DoubleField84); } - } - - /// Field number for the "double_field_45" field. - public const int DoubleField45FieldNumber = 45; - private double doubleField45_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField45 { - get { return doubleField45_; } - set { - doubleField45_ = value; + if (Int64Field85 != 0L) { + output.WriteRawTag(168, 5); + output.WriteInt64(Int64Field85); } - } - - /// Field number for the "double_field_46" field. - public const int DoubleField46FieldNumber = 46; - private double doubleField46_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField46 { - get { return doubleField46_; } - set { - doubleField46_ = value; + if (Int64Field86 != 0L) { + output.WriteRawTag(176, 5); + output.WriteInt64(Int64Field86); } - } - - /// Field number for the "double_field_78" field. - public const int DoubleField78FieldNumber = 78; - private double doubleField78_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField78 { - get { return doubleField78_; } - set { - doubleField78_ = value; + if (Int64Field87 != 0L) { + output.WriteRawTag(184, 5); + output.WriteInt64(Int64Field87); } - } - - /// Field number for the "double_field_88" field. - public const int DoubleField88FieldNumber = 88; - private double doubleField88_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField88 { - get { return doubleField88_; } - set { - doubleField88_ = value; + if (DoubleField88 != 0D) { + output.WriteRawTag(193, 5); + output.WriteDouble(DoubleField88); } - } - - /// Field number for the "double_field_47" field. - public const int DoubleField47FieldNumber = 47; - private double doubleField47_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField47 { - get { return doubleField47_; } - set { - doubleField47_ = value; + if (DoubleField89 != 0D) { + output.WriteRawTag(201, 5); + output.WriteDouble(DoubleField89); } - } - - /// Field number for the "double_field_89" field. - public const int DoubleField89FieldNumber = 89; - private double doubleField89_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField89 { - get { return doubleField89_; } - set { - doubleField89_ = value; + if (DoubleField90 != 0D) { + output.WriteRawTag(209, 5); + output.WriteDouble(DoubleField90); } - } - - /// Field number for the "double_field_48" field. - public const int DoubleField48FieldNumber = 48; - private double doubleField48_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField48 { - get { return doubleField48_; } - set { - doubleField48_ = value; + if (DoubleField91 != 0D) { + output.WriteRawTag(217, 5); + output.WriteDouble(DoubleField91); + } + if (DoubleField92 != 0D) { + output.WriteRawTag(225, 5); + output.WriteDouble(DoubleField92); + } + if (DoubleField93 != 0D) { + output.WriteRawTag(233, 5); + output.WriteDouble(DoubleField93); } - } - - /// Field number for the "double_field_49" field. - public const int DoubleField49FieldNumber = 49; - private double doubleField49_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField49 { - get { return doubleField49_; } - set { - doubleField49_ = value; + if (DoubleField94 != 0D) { + output.WriteRawTag(241, 5); + output.WriteDouble(DoubleField94); } - } - - /// Field number for the "double_field_50" field. - public const int DoubleField50FieldNumber = 50; - private double doubleField50_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField50 { - get { return doubleField50_; } - set { - doubleField50_ = value; + if (DoubleField95 != 0D) { + output.WriteRawTag(249, 5); + output.WriteDouble(DoubleField95); } - } - - /// Field number for the "double_field_90" field. - public const int DoubleField90FieldNumber = 90; - private double doubleField90_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField90 { - get { return doubleField90_; } - set { - doubleField90_ = value; + if (DoubleField96 != 0D) { + output.WriteRawTag(129, 6); + output.WriteDouble(DoubleField96); } - } - - /// Field number for the "double_field_51" field. - public const int DoubleField51FieldNumber = 51; - private double doubleField51_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField51 { - get { return doubleField51_; } - set { - doubleField51_ = value; + if (DoubleField97 != 0D) { + output.WriteRawTag(137, 6); + output.WriteDouble(DoubleField97); } - } - - /// Field number for the "double_field_91" field. - public const int DoubleField91FieldNumber = 91; - private double doubleField91_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField91 { - get { return doubleField91_; } - set { - doubleField91_ = value; + if (DoubleField98 != 0D) { + output.WriteRawTag(145, 6); + output.WriteDouble(DoubleField98); } - } - - /// Field number for the "double_field_92" field. - public const int DoubleField92FieldNumber = 92; - private double doubleField92_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField92 { - get { return doubleField92_; } - set { - doubleField92_ = value; + if (DoubleField99 != 0D) { + output.WriteRawTag(153, 6); + output.WriteDouble(DoubleField99); } - } - - /// Field number for the "int64_field_107" field. - public const int Int64Field107FieldNumber = 107; - private long int64Field107_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public long Int64Field107 { - get { return int64Field107_; } - set { - int64Field107_ = value; + repeatedIntField100_.WriteTo(output, _repeated_repeatedIntField100_codec); + if (DoubleField101 != 0D) { + output.WriteRawTag(169, 6); + output.WriteDouble(DoubleField101); } - } - - /// Field number for the "double_field_93" field. - public const int DoubleField93FieldNumber = 93; - private double doubleField93_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField93 { - get { return doubleField93_; } - set { - doubleField93_ = value; + if (DoubleField102 != 0D) { + output.WriteRawTag(177, 6); + output.WriteDouble(DoubleField102); } - } - - /// Field number for the "double_field_108" field. - public const int DoubleField108FieldNumber = 108; - private double doubleField108_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField108 { - get { return doubleField108_; } - set { - doubleField108_ = value; + if (DoubleField103 != 0D) { + output.WriteRawTag(185, 6); + output.WriteDouble(DoubleField103); } - } - - /// Field number for the "double_field_52" field. - public const int DoubleField52FieldNumber = 52; - private double doubleField52_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField52 { - get { return doubleField52_; } - set { - doubleField52_ = value; + if (DoubleField104 != 0D) { + output.WriteRawTag(193, 6); + output.WriteDouble(DoubleField104); } - } - - /// Field number for the "double_field_53" field. - public const int DoubleField53FieldNumber = 53; - private double doubleField53_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField53 { - get { return doubleField53_; } - set { - doubleField53_ = value; + if (DoubleField105 != 0D) { + output.WriteRawTag(201, 6); + output.WriteDouble(DoubleField105); } - } - - /// Field number for the "double_field_94" field. - public const int DoubleField94FieldNumber = 94; - private double doubleField94_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField94 { - get { return doubleField94_; } - set { - doubleField94_ = value; + if (DoubleField106 != 0D) { + output.WriteRawTag(209, 6); + output.WriteDouble(DoubleField106); } - } - - /// Field number for the "double_field_54" field. - public const int DoubleField54FieldNumber = 54; - private double doubleField54_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField54 { - get { return doubleField54_; } - set { - doubleField54_ = value; + if (Int64Field107 != 0L) { + output.WriteRawTag(216, 6); + output.WriteInt64(Int64Field107); } - } - - /// Field number for the "double_field_55" field. - public const int DoubleField55FieldNumber = 55; - private double doubleField55_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField55 { - get { return doubleField55_; } - set { - doubleField55_ = value; + if (DoubleField108 != 0D) { + output.WriteRawTag(225, 6); + output.WriteDouble(DoubleField108); } - } - - /// Field number for the "double_field_56" field. - public const int DoubleField56FieldNumber = 56; - private double doubleField56_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField56 { - get { return doubleField56_; } - set { - doubleField56_ = value; + if (DoubleField109 != 0D) { + output.WriteRawTag(233, 6); + output.WriteDouble(DoubleField109); } - } - - /// Field number for the "double_field_57" field. - public const int DoubleField57FieldNumber = 57; - private double doubleField57_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField57 { - get { return doubleField57_; } - set { - doubleField57_ = value; + if (Int64Field110 != 0L) { + output.WriteRawTag(240, 6); + output.WriteInt64(Int64Field110); } - } - - /// Field number for the "double_field_58" field. - public const int DoubleField58FieldNumber = 58; - private double doubleField58_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public double DoubleField58 { - get { return doubleField58_; } - set { - doubleField58_ = value; + if (DoubleField111 != 0D) { + output.WriteRawTag(249, 6); + output.WriteDouble(DoubleField111); } - } - - /// Field number for the "int64_field_59" field. - public const int Int64Field59FieldNumber = 59; - private long int64Field59_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public long Int64Field59 { - get { return int64Field59_; } - set { - int64Field59_ = value; + if (Int64Field112 != 0L) { + output.WriteRawTag(128, 7); + output.WriteInt64(Int64Field112); } - } - - /// Field number for the "int64_field_60" field. - public const int Int64Field60FieldNumber = 60; - private long int64Field60_; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public long Int64Field60 { - get { return int64Field60_; } - set { - int64Field60_ = value; + if (DoubleField113 != 0D) { + output.WriteRawTag(137, 7); + output.WriteDouble(DoubleField113); + } + if (Int64Field114 != 0L) { + output.WriteRawTag(144, 7); + output.WriteInt64(Int64Field114); + } + if (Int64Field115 != 0L) { + output.WriteRawTag(152, 7); + output.WriteInt64(Int64Field115); } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public override bool Equals(object other) { - return Equals(other as ManyPrimitiveFieldsMessage); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public bool Equals(ManyPrimitiveFieldsMessage other) { - if (ReferenceEquals(other, null)) { - return false; + if (DoubleField116 != 0D) { + output.WriteRawTag(161, 7); + output.WriteDouble(DoubleField116); } - if (ReferenceEquals(other, this)) { - return true; + if (Int64Field117 != 0L) { + output.WriteRawTag(168, 7); + output.WriteInt64(Int64Field117); + } + if (DoubleField118 != 0D) { + output.WriteRawTag(177, 7); + output.WriteDouble(DoubleField118); + } + if (DoubleField119 != 0D) { + output.WriteRawTag(185, 7); + output.WriteDouble(DoubleField119); + } + if (DoubleField120 != 0D) { + output.WriteRawTag(193, 7); + output.WriteDouble(DoubleField120); + } + if (DoubleField121 != 0D) { + output.WriteRawTag(201, 7); + output.WriteDouble(DoubleField121); + } + if (DoubleField122 != 0D) { + output.WriteRawTag(209, 7); + output.WriteDouble(DoubleField122); + } + if (DoubleField123 != 0D) { + output.WriteRawTag(217, 7); + output.WriteDouble(DoubleField123); + } + if (DoubleField124 != 0D) { + output.WriteRawTag(225, 7); + output.WriteDouble(DoubleField124); + } + if (Int64Field125 != 0L) { + output.WriteRawTag(232, 7); + output.WriteInt64(Int64Field125); + } + if (Int64Field126 != 0L) { + output.WriteRawTag(240, 7); + output.WriteInt64(Int64Field126); + } + if (Int64Field127 != 0L) { + output.WriteRawTag(248, 7); + output.WriteInt64(Int64Field127); + } + if (DoubleField128 != 0D) { + output.WriteRawTag(129, 8); + output.WriteDouble(DoubleField128); + } + if (DoubleField129 != 0D) { + output.WriteRawTag(137, 8); + output.WriteDouble(DoubleField129); } - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField95, other.DoubleField95)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField1, other.DoubleField1)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField79, other.DoubleField79)) return false; - if (Int64Field2 != other.Int64Field2) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField96, other.DoubleField96)) return false; - if (Int64Field3 != other.Int64Field3) return false; - if (Int64Field4 != other.Int64Field4) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField97, other.DoubleField97)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField65, other.DoubleField65)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField66, other.DoubleField66)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField7, other.DoubleField7)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField62, other.DoubleField62)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField118, other.DoubleField118)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField119, other.DoubleField119)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField67, other.DoubleField67)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField120, other.DoubleField120)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField121, other.DoubleField121)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField122, other.DoubleField122)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField123, other.DoubleField123)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField124, other.DoubleField124)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField8, other.DoubleField8)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField9, other.DoubleField9)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField98, other.DoubleField98)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField10, other.DoubleField10)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField11, other.DoubleField11)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField99, other.DoubleField99)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField84, other.DoubleField84)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField14, other.DoubleField14)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField77, other.DoubleField77)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField15, other.DoubleField15)) return false; - if (Int64Field19 != other.Int64Field19) return false; - if (Int64Field115 != other.Int64Field115) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField116, other.DoubleField116)) return false; - if (Int64Field117 != other.Int64Field117) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField20, other.DoubleField20)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField21, other.DoubleField21)) return false; - if (StringField73 != other.StringField73) return false; - if (StringField74 != other.StringField74) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField22, other.DoubleField22)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField69, other.DoubleField69)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField70, other.DoubleField70)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField71, other.DoubleField71)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField72, other.DoubleField72)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField25, other.DoubleField25)) return false; - if (Int64Field26 != other.Int64Field26) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField68, other.DoubleField68)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField28, other.DoubleField28)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField106, other.DoubleField106)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField29, other.DoubleField29)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField30, other.DoubleField30)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField101, other.DoubleField101)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField102, other.DoubleField102)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField103, other.DoubleField103)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField104, other.DoubleField104)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField105, other.DoubleField105)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField31, other.DoubleField31)) return false; - if (Int64Field32 != other.Int64Field32) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField75, other.DoubleField75)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField129, other.DoubleField129)) return false; - if (EnumField80 != other.EnumField80) return false; - if (EnumField81 != other.EnumField81) return false; - if (Int64Field82 != other.Int64Field82) return false; - if (EnumField83 != other.EnumField83) return false; - if (Int64Field85 != other.Int64Field85) return false; - if (Int64Field86 != other.Int64Field86) return false; - if (Int64Field87 != other.Int64Field87) return false; - if (Int64Field125 != other.Int64Field125) return false; - if (Int64Field37 != other.Int64Field37) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField38, other.DoubleField38)) return false; - if (Interactions != other.Interactions) return false; - if(!repeatedIntField100_.Equals(other.repeatedIntField100_)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField40, other.DoubleField40)) return false; - if (Int64Field41 != other.Int64Field41) return false; - if (Int64Field126 != other.Int64Field126) return false; - if (Int64Field127 != other.Int64Field127) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField128, other.DoubleField128)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField109, other.DoubleField109)) return false; - if (Int64Field110 != other.Int64Field110) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField111, other.DoubleField111)) return false; - if (Int64Field112 != other.Int64Field112) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField113, other.DoubleField113)) return false; - if (Int64Field114 != other.Int64Field114) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField42, other.DoubleField42)) return false; - if (Int64Field43 != other.Int64Field43) return false; - if (Int64Field44 != other.Int64Field44) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField45, other.DoubleField45)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField46, other.DoubleField46)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField78, other.DoubleField78)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField88, other.DoubleField88)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField47, other.DoubleField47)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField89, other.DoubleField89)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField48, other.DoubleField48)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField49, other.DoubleField49)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField50, other.DoubleField50)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField90, other.DoubleField90)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField51, other.DoubleField51)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField91, other.DoubleField91)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField92, other.DoubleField92)) return false; - if (Int64Field107 != other.Int64Field107) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField93, other.DoubleField93)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField108, other.DoubleField108)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField52, other.DoubleField52)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField53, other.DoubleField53)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField94, other.DoubleField94)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField54, other.DoubleField54)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField55, other.DoubleField55)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField56, other.DoubleField56)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField57, other.DoubleField57)) return false; - if (!pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.Equals(DoubleField58, other.DoubleField58)) return false; - if (Int64Field59 != other.Int64Field59) return false; - if (Int64Field60 != other.Int64Field60) return false; - return Equals(_unknownFields, other._unknownFields); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public override int GetHashCode() { - int hash = 1; - if (DoubleField95 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField95); - if (DoubleField1 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField1); - if (DoubleField79 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField79); - if (Int64Field2 != 0L) hash ^= Int64Field2.GetHashCode(); - if (DoubleField96 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField96); - if (Int64Field3 != 0L) hash ^= Int64Field3.GetHashCode(); - if (Int64Field4 != 0L) hash ^= Int64Field4.GetHashCode(); - if (DoubleField97 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField97); - if (DoubleField65 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField65); - if (DoubleField66 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField66); - if (DoubleField7 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField7); - if (DoubleField62 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField62); - if (DoubleField118 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField118); - if (DoubleField119 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField119); - if (DoubleField67 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField67); - if (DoubleField120 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField120); - if (DoubleField121 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField121); - if (DoubleField122 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField122); - if (DoubleField123 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField123); - if (DoubleField124 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField124); - if (DoubleField8 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField8); - if (DoubleField9 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField9); - if (DoubleField98 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField98); - if (DoubleField10 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField10); - if (DoubleField11 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField11); - if (DoubleField99 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField99); - if (DoubleField84 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField84); - if (DoubleField14 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField14); - if (DoubleField77 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField77); - if (DoubleField15 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField15); - if (Int64Field19 != 0L) hash ^= Int64Field19.GetHashCode(); - if (Int64Field115 != 0L) hash ^= Int64Field115.GetHashCode(); - if (DoubleField116 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField116); - if (Int64Field117 != 0L) hash ^= Int64Field117.GetHashCode(); - if (DoubleField20 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField20); - if (DoubleField21 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField21); - if (StringField73.Length != 0) hash ^= StringField73.GetHashCode(); - if (StringField74.Length != 0) hash ^= StringField74.GetHashCode(); - if (DoubleField22 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField22); - if (DoubleField69 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField69); - if (DoubleField70 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField70); - if (DoubleField71 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField71); - if (DoubleField72 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField72); - if (DoubleField25 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField25); - if (Int64Field26 != 0L) hash ^= Int64Field26.GetHashCode(); - if (DoubleField68 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField68); - if (DoubleField28 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField28); - if (DoubleField106 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField106); - if (DoubleField29 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField29); - if (DoubleField30 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField30); - if (DoubleField101 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField101); - if (DoubleField102 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField102); - if (DoubleField103 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField103); - if (DoubleField104 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField104); - if (DoubleField105 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField105); - if (DoubleField31 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField31); - if (Int64Field32 != 0L) hash ^= Int64Field32.GetHashCode(); - if (DoubleField75 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField75); - if (DoubleField129 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField129); - if (EnumField80 != 0) hash ^= EnumField80.GetHashCode(); - if (EnumField81 != 0) hash ^= EnumField81.GetHashCode(); - if (Int64Field82 != 0L) hash ^= Int64Field82.GetHashCode(); - if (EnumField83 != 0) hash ^= EnumField83.GetHashCode(); - if (Int64Field85 != 0L) hash ^= Int64Field85.GetHashCode(); - if (Int64Field86 != 0L) hash ^= Int64Field86.GetHashCode(); - if (Int64Field87 != 0L) hash ^= Int64Field87.GetHashCode(); - if (Int64Field125 != 0L) hash ^= Int64Field125.GetHashCode(); - if (Int64Field37 != 0L) hash ^= Int64Field37.GetHashCode(); - if (DoubleField38 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField38); - if (Interactions != 0L) hash ^= Interactions.GetHashCode(); - hash ^= repeatedIntField100_.GetHashCode(); - if (DoubleField40 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField40); - if (Int64Field41 != 0L) hash ^= Int64Field41.GetHashCode(); - if (Int64Field126 != 0L) hash ^= Int64Field126.GetHashCode(); - if (Int64Field127 != 0L) hash ^= Int64Field127.GetHashCode(); - if (DoubleField128 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField128); - if (DoubleField109 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField109); - if (Int64Field110 != 0L) hash ^= Int64Field110.GetHashCode(); - if (DoubleField111 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField111); - if (Int64Field112 != 0L) hash ^= Int64Field112.GetHashCode(); - if (DoubleField113 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField113); - if (Int64Field114 != 0L) hash ^= Int64Field114.GetHashCode(); - if (DoubleField42 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField42); - if (Int64Field43 != 0L) hash ^= Int64Field43.GetHashCode(); - if (Int64Field44 != 0L) hash ^= Int64Field44.GetHashCode(); - if (DoubleField45 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField45); - if (DoubleField46 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField46); - if (DoubleField78 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField78); - if (DoubleField88 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField88); - if (DoubleField47 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField47); - if (DoubleField89 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField89); - if (DoubleField48 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField48); - if (DoubleField49 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField49); - if (DoubleField50 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField50); - if (DoubleField90 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField90); - if (DoubleField51 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField51); - if (DoubleField91 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField91); - if (DoubleField92 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField92); - if (Int64Field107 != 0L) hash ^= Int64Field107.GetHashCode(); - if (DoubleField93 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField93); - if (DoubleField108 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField108); - if (DoubleField52 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField52); - if (DoubleField53 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField53); - if (DoubleField94 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField94); - if (DoubleField54 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField54); - if (DoubleField55 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField55); - if (DoubleField56 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField56); - if (DoubleField57 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField57); - if (DoubleField58 != 0D) hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(DoubleField58); - if (Int64Field59 != 0L) hash ^= Int64Field59.GetHashCode(); - if (Int64Field60 != 0L) hash ^= Int64Field60.GetHashCode(); if (_unknownFields != null) { - hash ^= _unknownFields.GetHashCode(); + _unknownFields.WriteTo(output); } - return hash; } - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public override string ToString() { - return pb::JsonFormatter.ToDiagnosticString(this); - } + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void WriteTo(pb::CodedOutputStream output) { + public void WriteTo(ref pb::CodedOutputWriter output) { if (DoubleField1 != 0D) { output.WriteRawTag(9); output.WriteDouble(DoubleField1); @@ -6027,7 +7610,7 @@ public void WriteTo(pb::CodedOutputStream output) { output.WriteRawTag(153, 6); output.WriteDouble(DoubleField99); } - repeatedIntField100_.WriteTo(output, _repeated_repeatedIntField100_codec); + repeatedIntField100_.WriteTo(ref output, _repeated_repeatedIntField100_codec); if (DoubleField101 != 0D) { output.WriteRawTag(169, 6); output.WriteDouble(DoubleField101); @@ -6145,9 +7728,10 @@ public void WriteTo(pb::CodedOutputStream output) { output.WriteDouble(DoubleField129); } if (_unknownFields != null) { - _unknownFields.WriteTo(output); + _unknownFields.WriteTo(ref output); } } + #endif [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { @@ -6825,16 +8409,475 @@ public void MergeFrom(ManyPrimitiveFieldsMessage other) { if (other.Int64Field60 != 0L) { Int64Field60 = other.Int64Field60; } - _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 9: { + DoubleField1 = input.ReadDouble(); + break; + } + case 16: { + Int64Field2 = input.ReadInt64(); + break; + } + case 24: { + Int64Field3 = input.ReadInt64(); + break; + } + case 32: { + Int64Field4 = input.ReadInt64(); + break; + } + case 57: { + DoubleField7 = input.ReadDouble(); + break; + } + case 65: { + DoubleField8 = input.ReadDouble(); + break; + } + case 73: { + DoubleField9 = input.ReadDouble(); + break; + } + case 81: { + DoubleField10 = input.ReadDouble(); + break; + } + case 89: { + DoubleField11 = input.ReadDouble(); + break; + } + case 113: { + DoubleField14 = input.ReadDouble(); + break; + } + case 121: { + DoubleField15 = input.ReadDouble(); + break; + } + case 152: { + Int64Field19 = input.ReadInt64(); + break; + } + case 161: { + DoubleField20 = input.ReadDouble(); + break; + } + case 169: { + DoubleField21 = input.ReadDouble(); + break; + } + case 177: { + DoubleField22 = input.ReadDouble(); + break; + } + case 201: { + DoubleField25 = input.ReadDouble(); + break; + } + case 208: { + Int64Field26 = input.ReadInt64(); + break; + } + case 225: { + DoubleField28 = input.ReadDouble(); + break; + } + case 233: { + DoubleField29 = input.ReadDouble(); + break; + } + case 241: { + DoubleField30 = input.ReadDouble(); + break; + } + case 249: { + DoubleField31 = input.ReadDouble(); + break; + } + case 256: { + Int64Field32 = input.ReadInt64(); + break; + } + case 296: { + Int64Field37 = input.ReadInt64(); + break; + } + case 305: { + DoubleField38 = input.ReadDouble(); + break; + } + case 312: { + Interactions = input.ReadInt64(); + break; + } + case 321: { + DoubleField40 = input.ReadDouble(); + break; + } + case 328: { + Int64Field41 = input.ReadInt64(); + break; + } + case 337: { + DoubleField42 = input.ReadDouble(); + break; + } + case 344: { + Int64Field43 = input.ReadInt64(); + break; + } + case 352: { + Int64Field44 = input.ReadInt64(); + break; + } + case 361: { + DoubleField45 = input.ReadDouble(); + break; + } + case 369: { + DoubleField46 = input.ReadDouble(); + break; + } + case 377: { + DoubleField47 = input.ReadDouble(); + break; + } + case 385: { + DoubleField48 = input.ReadDouble(); + break; + } + case 393: { + DoubleField49 = input.ReadDouble(); + break; + } + case 401: { + DoubleField50 = input.ReadDouble(); + break; + } + case 409: { + DoubleField51 = input.ReadDouble(); + break; + } + case 417: { + DoubleField52 = input.ReadDouble(); + break; + } + case 425: { + DoubleField53 = input.ReadDouble(); + break; + } + case 433: { + DoubleField54 = input.ReadDouble(); + break; + } + case 441: { + DoubleField55 = input.ReadDouble(); + break; + } + case 449: { + DoubleField56 = input.ReadDouble(); + break; + } + case 457: { + DoubleField57 = input.ReadDouble(); + break; + } + case 465: { + DoubleField58 = input.ReadDouble(); + break; + } + case 472: { + Int64Field59 = input.ReadInt64(); + break; + } + case 480: { + Int64Field60 = input.ReadInt64(); + break; + } + case 497: { + DoubleField62 = input.ReadDouble(); + break; + } + case 521: { + DoubleField65 = input.ReadDouble(); + break; + } + case 529: { + DoubleField66 = input.ReadDouble(); + break; + } + case 537: { + DoubleField67 = input.ReadDouble(); + break; + } + case 545: { + DoubleField68 = input.ReadDouble(); + break; + } + case 553: { + DoubleField69 = input.ReadDouble(); + break; + } + case 561: { + DoubleField70 = input.ReadDouble(); + break; + } + case 569: { + DoubleField71 = input.ReadDouble(); + break; + } + case 577: { + DoubleField72 = input.ReadDouble(); + break; + } + case 586: { + StringField73 = input.ReadString(); + break; + } + case 594: { + StringField74 = input.ReadString(); + break; + } + case 601: { + DoubleField75 = input.ReadDouble(); + break; + } + case 617: { + DoubleField77 = input.ReadDouble(); + break; + } + case 625: { + DoubleField78 = input.ReadDouble(); + break; + } + case 633: { + DoubleField79 = input.ReadDouble(); + break; + } + case 640: { + EnumField80 = input.ReadInt32(); + break; + } + case 648: { + EnumField81 = input.ReadInt32(); + break; + } + case 656: { + Int64Field82 = input.ReadInt64(); + break; + } + case 664: { + EnumField83 = input.ReadInt32(); + break; + } + case 673: { + DoubleField84 = input.ReadDouble(); + break; + } + case 680: { + Int64Field85 = input.ReadInt64(); + break; + } + case 688: { + Int64Field86 = input.ReadInt64(); + break; + } + case 696: { + Int64Field87 = input.ReadInt64(); + break; + } + case 705: { + DoubleField88 = input.ReadDouble(); + break; + } + case 713: { + DoubleField89 = input.ReadDouble(); + break; + } + case 721: { + DoubleField90 = input.ReadDouble(); + break; + } + case 729: { + DoubleField91 = input.ReadDouble(); + break; + } + case 737: { + DoubleField92 = input.ReadDouble(); + break; + } + case 745: { + DoubleField93 = input.ReadDouble(); + break; + } + case 753: { + DoubleField94 = input.ReadDouble(); + break; + } + case 761: { + DoubleField95 = input.ReadDouble(); + break; + } + case 769: { + DoubleField96 = input.ReadDouble(); + break; + } + case 777: { + DoubleField97 = input.ReadDouble(); + break; + } + case 785: { + DoubleField98 = input.ReadDouble(); + break; + } + case 793: { + DoubleField99 = input.ReadDouble(); + break; + } + case 802: + case 800: { + repeatedIntField100_.AddEntriesFrom(input, _repeated_repeatedIntField100_codec); + break; + } + case 809: { + DoubleField101 = input.ReadDouble(); + break; + } + case 817: { + DoubleField102 = input.ReadDouble(); + break; + } + case 825: { + DoubleField103 = input.ReadDouble(); + break; + } + case 833: { + DoubleField104 = input.ReadDouble(); + break; + } + case 841: { + DoubleField105 = input.ReadDouble(); + break; + } + case 849: { + DoubleField106 = input.ReadDouble(); + break; + } + case 856: { + Int64Field107 = input.ReadInt64(); + break; + } + case 865: { + DoubleField108 = input.ReadDouble(); + break; + } + case 873: { + DoubleField109 = input.ReadDouble(); + break; + } + case 880: { + Int64Field110 = input.ReadInt64(); + break; + } + case 889: { + DoubleField111 = input.ReadDouble(); + break; + } + case 896: { + Int64Field112 = input.ReadInt64(); + break; + } + case 905: { + DoubleField113 = input.ReadDouble(); + break; + } + case 912: { + Int64Field114 = input.ReadInt64(); + break; + } + case 920: { + Int64Field115 = input.ReadInt64(); + break; + } + case 929: { + DoubleField116 = input.ReadDouble(); + break; + } + case 936: { + Int64Field117 = input.ReadInt64(); + break; + } + case 945: { + DoubleField118 = input.ReadDouble(); + break; + } + case 953: { + DoubleField119 = input.ReadDouble(); + break; + } + case 961: { + DoubleField120 = input.ReadDouble(); + break; + } + case 969: { + DoubleField121 = input.ReadDouble(); + break; + } + case 977: { + DoubleField122 = input.ReadDouble(); + break; + } + case 985: { + DoubleField123 = input.ReadDouble(); + break; + } + case 993: { + DoubleField124 = input.ReadDouble(); + break; + } + case 1000: { + Int64Field125 = input.ReadInt64(); + break; + } + case 1008: { + Int64Field126 = input.ReadInt64(); + break; + } + case 1016: { + Int64Field127 = input.ReadInt64(); + break; + } + case 1025: { + DoubleField128 = input.ReadDouble(); + break; + } + case 1033: { + DoubleField129 = input.ReadDouble(); + break; + } + } + } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void MergeFrom(pb::CodedInputStream input) { + public void MergeFrom(ref pb::CodedInputReader input) { uint tag; while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); break; case 9: { DoubleField1 = input.ReadDouble(); @@ -7162,7 +9205,7 @@ public void MergeFrom(pb::CodedInputStream input) { } case 802: case 800: { - repeatedIntField100_.AddEntriesFrom(input, _repeated_repeatedIntField100_codec); + repeatedIntField100_.AddEntriesFrom(ref input, _repeated_repeatedIntField100_codec); break; } case 809: { @@ -7284,6 +9327,7 @@ public void MergeFrom(pb::CodedInputStream input) { } } } + #endif } diff --git a/csharp/src/Google.Protobuf.Conformance/Conformance.cs b/csharp/src/Google.Protobuf.Conformance/Conformance.cs index 23894ad3ba4c..a8c5e310d484 100644 --- a/csharp/src/Google.Protobuf.Conformance/Conformance.cs +++ b/csharp/src/Google.Protobuf.Conformance/Conformance.cs @@ -107,7 +107,11 @@ public enum TestCategory { /// This will be known by message_type == "conformance.FailureSet", a conformance /// test should return a serialized FailureSet in protobuf_payload. /// - public sealed partial class FailureSet : pb::IMessage { + public sealed partial class FailureSet : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new FailureSet()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -191,6 +195,17 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + failure_.WriteTo(ref output, _repeated_failure_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -226,6 +241,25 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + failure_.AddEntriesFrom(ref input, _repeated_failure_codec); + break; + } + } + } + } + #endif + } /// @@ -235,7 +269,11 @@ public void MergeFrom(pb::CodedInputStream input) { /// 2. parse the protobuf or JSON payload in "payload" (which may fail) /// 3. if the parse succeeded, serialize the message in the requested format. /// - public sealed partial class ConformanceRequest : pb::IMessage { + public sealed partial class ConformanceRequest : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ConformanceRequest()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -524,6 +562,52 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (payloadCase_ == PayloadOneofCase.ProtobufPayload) { + output.WriteRawTag(10); + output.WriteBytes(ProtobufPayload); + } + if (payloadCase_ == PayloadOneofCase.JsonPayload) { + output.WriteRawTag(18); + output.WriteString(JsonPayload); + } + if (RequestedOutputFormat != global::Conformance.WireFormat.Unspecified) { + output.WriteRawTag(24); + output.WriteEnum((int) RequestedOutputFormat); + } + if (MessageType.Length != 0) { + output.WriteRawTag(34); + output.WriteString(MessageType); + } + if (TestCategory != global::Conformance.TestCategory.UnspecifiedTest) { + output.WriteRawTag(40); + output.WriteEnum((int) TestCategory); + } + if (jspbEncodingOptions_ != null) { + output.WriteRawTag(50); + output.WriteMessage(JspbEncodingOptions); + } + if (payloadCase_ == PayloadOneofCase.JspbPayload) { + output.WriteRawTag(58); + output.WriteString(JspbPayload); + } + if (payloadCase_ == PayloadOneofCase.TextPayload) { + output.WriteRawTag(66); + output.WriteString(TextPayload); + } + if (PrintUnknownFields != false) { + output.WriteRawTag(72); + output.WriteBool(PrintUnknownFields); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -652,12 +736,70 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + ProtobufPayload = input.ReadBytes(); + break; + } + case 18: { + JsonPayload = input.ReadString(); + break; + } + case 24: { + RequestedOutputFormat = (global::Conformance.WireFormat) input.ReadEnum(); + break; + } + case 34: { + MessageType = input.ReadString(); + break; + } + case 40: { + TestCategory = (global::Conformance.TestCategory) input.ReadEnum(); + break; + } + case 50: { + if (jspbEncodingOptions_ == null) { + JspbEncodingOptions = new global::Conformance.JspbEncodingConfig(); + } + input.ReadMessage(JspbEncodingOptions); + break; + } + case 58: { + JspbPayload = input.ReadString(); + break; + } + case 66: { + TextPayload = input.ReadString(); + break; + } + case 72: { + PrintUnknownFields = input.ReadBool(); + break; + } + } + } + } + #endif + } /// /// Represents a single test case's output. /// - public sealed partial class ConformanceResponse : pb::IMessage { + public sealed partial class ConformanceResponse : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ConformanceResponse()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -955,6 +1097,48 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (resultCase_ == ResultOneofCase.ParseError) { + output.WriteRawTag(10); + output.WriteString(ParseError); + } + if (resultCase_ == ResultOneofCase.RuntimeError) { + output.WriteRawTag(18); + output.WriteString(RuntimeError); + } + if (resultCase_ == ResultOneofCase.ProtobufPayload) { + output.WriteRawTag(26); + output.WriteBytes(ProtobufPayload); + } + if (resultCase_ == ResultOneofCase.JsonPayload) { + output.WriteRawTag(34); + output.WriteString(JsonPayload); + } + if (resultCase_ == ResultOneofCase.Skipped) { + output.WriteRawTag(42); + output.WriteString(Skipped); + } + if (resultCase_ == ResultOneofCase.SerializeError) { + output.WriteRawTag(50); + output.WriteString(SerializeError); + } + if (resultCase_ == ResultOneofCase.JspbPayload) { + output.WriteRawTag(58); + output.WriteString(JspbPayload); + } + if (resultCase_ == ResultOneofCase.TextPayload) { + output.WriteRawTag(66); + output.WriteString(TextPayload); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -1067,12 +1251,63 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + ParseError = input.ReadString(); + break; + } + case 18: { + RuntimeError = input.ReadString(); + break; + } + case 26: { + ProtobufPayload = input.ReadBytes(); + break; + } + case 34: { + JsonPayload = input.ReadString(); + break; + } + case 42: { + Skipped = input.ReadString(); + break; + } + case 50: { + SerializeError = input.ReadString(); + break; + } + case 58: { + JspbPayload = input.ReadString(); + break; + } + case 66: { + TextPayload = input.ReadString(); + break; + } + } + } + } + #endif + } /// /// Encoding options for jspb format. /// - public sealed partial class JspbEncodingConfig : pb::IMessage { + public sealed partial class JspbEncodingConfig : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new JspbEncodingConfig()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -1163,6 +1398,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (UseJspbArrayAnyFormat != false) { + output.WriteRawTag(8); + output.WriteBool(UseJspbArrayAnyFormat); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -1202,6 +1451,25 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + UseJspbArrayAnyFormat = input.ReadBool(); + break; + } + } + } + } + #endif + } #endregion diff --git a/csharp/src/Google.Protobuf.Conformance/Google.Protobuf.Conformance.csproj b/csharp/src/Google.Protobuf.Conformance/Google.Protobuf.Conformance.csproj index ec8fb9138947..8c9122750070 100644 --- a/csharp/src/Google.Protobuf.Conformance/Google.Protobuf.Conformance.csproj +++ b/csharp/src/Google.Protobuf.Conformance/Google.Protobuf.Conformance.csproj @@ -4,8 +4,13 @@ netcoreapp2.1 Exe False + $(DefineConstants);GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + + + + diff --git a/csharp/src/Google.Protobuf.Conformance/Program.cs b/csharp/src/Google.Protobuf.Conformance/Program.cs index d1093abee1f3..8ee58691274b 100644 --- a/csharp/src/Google.Protobuf.Conformance/Program.cs +++ b/csharp/src/Google.Protobuf.Conformance/Program.cs @@ -31,9 +31,12 @@ #endregion using Conformance; +using Google.Protobuf.Buffers; using Google.Protobuf.Reflection; using System; +using System.Buffers; using System.IO; +using System.Linq; namespace Google.Protobuf.Conformance { @@ -45,6 +48,8 @@ class Program { private static void Main(string[] args) { + var mode = ParseCmdline(args); + // This way we get the binary streams instead of readers/writers. var input = new BinaryReader(Console.OpenStandardInput()); var output = new BinaryWriter(Console.OpenStandardOutput()); @@ -53,14 +58,31 @@ private static void Main(string[] args) ProtobufTestMessages.Proto2.TestAllTypesProto2.Descriptor); int count = 0; - while (RunTest(input, output, typeRegistry)) + while (RunTest(input, output, typeRegistry, mode)) { count++; } Console.Error.WriteLine("Received EOF after {0} tests", count); } - private static bool RunTest(BinaryReader input, BinaryWriter output, TypeRegistry typeRegistry) + private static SerializationMode ParseCmdline(string[] args) + { + var mode = SerializationMode.Stream; + foreach (var arg in args.Skip(1)) + { + switch (arg) + { + case "--use_buffer_serialization": + mode = SerializationMode.Buffer; + break; + default: + throw new Exception($"Unknown command line argument: {arg}"); + } + } + return mode; + } + + private static bool RunTest(BinaryReader input, BinaryWriter output, TypeRegistry typeRegistry, SerializationMode mode) { int? size = ReadInt32(input); if (size == null) @@ -72,8 +94,9 @@ private static bool RunTest(BinaryReader input, BinaryWriter output, TypeRegistr { throw new EndOfStreamException("Read " + inputData.Length + " bytes of data when expecting " + size); } + // It doesn't matter what parser mode we use for ConformanceRequest, it isn't being tested ConformanceRequest request = ConformanceRequest.Parser.ParseFrom(inputData); - ConformanceResponse response = PerformRequest(request, typeRegistry); + ConformanceResponse response = PerformRequest(request, typeRegistry, mode); byte[] outputData = response.ToByteArray(); output.Write(outputData.Length); output.Write(outputData); @@ -81,7 +104,7 @@ private static bool RunTest(BinaryReader input, BinaryWriter output, TypeRegistr return true; } - private static ConformanceResponse PerformRequest(ConformanceRequest request, TypeRegistry typeRegistry) + private static ConformanceResponse PerformRequest(ConformanceRequest request, TypeRegistry typeRegistry, SerializationMode mode) { IMessage message; try @@ -89,17 +112,30 @@ private static ConformanceResponse PerformRequest(ConformanceRequest request, Ty switch (request.PayloadCase) { case ConformanceRequest.PayloadOneofCase.JsonPayload: - if (request.TestCategory == global::Conformance.TestCategory.JsonIgnoreUnknownParsingTest) { + { + // There is no buffer implementation of JSON. Use standard implementation + if (request.TestCategory == global::Conformance.TestCategory.JsonIgnoreUnknownParsingTest) + { return new ConformanceResponse { Skipped = "CSharp doesn't support skipping unknown fields in json parsing." }; } var parser = new JsonParser(new JsonParser.Settings(20, typeRegistry)); message = parser.Parse(request.JsonPayload); break; + } case ConformanceRequest.PayloadOneofCase.ProtobufPayload: { if (request.MessageType.Equals("protobuf_test_messages.proto3.TestAllTypesProto3")) { - message = ProtobufTestMessages.Proto3.TestAllTypesProto3.Parser.ParseFrom(request.ProtobufPayload); + var messageParser = ProtobufTestMessages.Proto3.TestAllTypesProto3.Parser; + + if (mode == SerializationMode.Stream) + { + message = messageParser.ParseFrom(request.ProtobufPayload); + } + else + { + message = messageParser.ParseFrom(new ReadOnlySequence(request.ProtobufPayload.ToByteArray())); + } } else if (request.MessageType.Equals("protobuf_test_messages.proto2.TestAllTypesProto2")) { @@ -109,18 +145,27 @@ private static ConformanceResponse PerformRequest(ConformanceRequest request, Ty ProtobufTestMessages.Proto2.TestAllTypesProto2.Types.MessageSetCorrectExtension1.Extensions.MessageSetExtension, ProtobufTestMessages.Proto2.TestAllTypesProto2.Types.MessageSetCorrectExtension2.Extensions.MessageSetExtension }; - message = ProtobufTestMessages.Proto2.TestAllTypesProto2.Parser.WithExtensionRegistry(registry).ParseFrom(request.ProtobufPayload); + var messageParser = ProtobufTestMessages.Proto2.TestAllTypesProto2.Parser.WithExtensionRegistry(registry); + + if (mode == SerializationMode.Stream) + { + message = messageParser.ParseFrom(request.ProtobufPayload); + } + else + { + message = messageParser.ParseFrom(new ReadOnlySequence(request.ProtobufPayload.ToByteArray())); + } } else { - throw new Exception(" Protobuf request doesn't have specific payload type"); + throw new Exception("Protobuf request doesn't have specific payload type"); } break; } - case ConformanceRequest.PayloadOneofCase.TextPayload: - { - return new ConformanceResponse { Skipped = "CSharp doesn't support text format" }; - } + case ConformanceRequest.PayloadOneofCase.TextPayload: + { + return new ConformanceResponse { Skipped = "CSharp doesn't support text format" }; + } default: throw new Exception("Unsupported request payload: " + request.PayloadCase); } @@ -141,7 +186,19 @@ private static ConformanceResponse PerformRequest(ConformanceRequest request, Ty var formatter = new JsonFormatter(new JsonFormatter.Settings(false, typeRegistry)); return new ConformanceResponse { JsonPayload = formatter.Format(message) }; case global::Conformance.WireFormat.Protobuf: - return new ConformanceResponse { ProtobufPayload = message.ToByteString() }; + if (mode == SerializationMode.Stream) + { + return new ConformanceResponse { ProtobufPayload = message.ToByteString() }; + } + else + { + var bufferMessage = (IBufferMessage)message; + var byteArrayWriter = new ArrayBufferWriter(); + var codedOutputWriter = new CodedOutputWriter(byteArrayWriter); + bufferMessage.WriteTo(ref codedOutputWriter); + codedOutputWriter.Flush(); + return new ConformanceResponse { ProtobufPayload = ByteString.CopyFrom(byteArrayWriter.WrittenSpan.ToArray()) }; + } default: throw new Exception("Unsupported request output format: " + request.RequestedOutputFormat); } @@ -166,5 +223,11 @@ private static ConformanceResponse PerformRequest(ConformanceRequest request, Ty } return bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24); } + + private enum SerializationMode + { + Stream, + Buffer + } } } diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/Google.Protobuf.Test.TestProtos.csproj b/csharp/src/Google.Protobuf.Test.TestProtos/Google.Protobuf.Test.TestProtos.csproj index 5b705804aa27..b3a2393fce2d 100644 --- a/csharp/src/Google.Protobuf.Test.TestProtos/Google.Protobuf.Test.TestProtos.csproj +++ b/csharp/src/Google.Protobuf.Test.TestProtos/Google.Protobuf.Test.TestProtos.csproj @@ -14,6 +14,10 @@ False + + $(DefineConstants);GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + + diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/MapUnittestProto3.cs b/csharp/src/Google.Protobuf.Test.TestProtos/MapUnittestProto3.cs index 197b197d0ea4..9349119c668a 100644 --- a/csharp/src/Google.Protobuf.Test.TestProtos/MapUnittestProto3.cs +++ b/csharp/src/Google.Protobuf.Test.TestProtos/MapUnittestProto3.cs @@ -176,7 +176,11 @@ public enum MapEnum { /// /// Tests maps. /// - public sealed partial class TestMap : pb::IMessage { + public sealed partial class TestMap : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestMap()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -484,6 +488,33 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + mapInt32Int32_.WriteTo(ref output, _map_mapInt32Int32_codec); + mapInt64Int64_.WriteTo(ref output, _map_mapInt64Int64_codec); + mapUint32Uint32_.WriteTo(ref output, _map_mapUint32Uint32_codec); + mapUint64Uint64_.WriteTo(ref output, _map_mapUint64Uint64_codec); + mapSint32Sint32_.WriteTo(ref output, _map_mapSint32Sint32_codec); + mapSint64Sint64_.WriteTo(ref output, _map_mapSint64Sint64_codec); + mapFixed32Fixed32_.WriteTo(ref output, _map_mapFixed32Fixed32_codec); + mapFixed64Fixed64_.WriteTo(ref output, _map_mapFixed64Fixed64_codec); + mapSfixed32Sfixed32_.WriteTo(ref output, _map_mapSfixed32Sfixed32_codec); + mapSfixed64Sfixed64_.WriteTo(ref output, _map_mapSfixed64Sfixed64_codec); + mapInt32Float_.WriteTo(ref output, _map_mapInt32Float_codec); + mapInt32Double_.WriteTo(ref output, _map_mapInt32Double_codec); + mapBoolBool_.WriteTo(ref output, _map_mapBoolBool_codec); + mapStringString_.WriteTo(ref output, _map_mapStringString_codec); + mapInt32Bytes_.WriteTo(ref output, _map_mapInt32Bytes_codec); + mapInt32Enum_.WriteTo(ref output, _map_mapInt32Enum_codec); + mapInt32ForeignMessage_.WriteTo(ref output, _map_mapInt32ForeignMessage_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -615,9 +646,96 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + mapInt32Int32_.AddEntriesFrom(ref input, _map_mapInt32Int32_codec); + break; + } + case 18: { + mapInt64Int64_.AddEntriesFrom(ref input, _map_mapInt64Int64_codec); + break; + } + case 26: { + mapUint32Uint32_.AddEntriesFrom(ref input, _map_mapUint32Uint32_codec); + break; + } + case 34: { + mapUint64Uint64_.AddEntriesFrom(ref input, _map_mapUint64Uint64_codec); + break; + } + case 42: { + mapSint32Sint32_.AddEntriesFrom(ref input, _map_mapSint32Sint32_codec); + break; + } + case 50: { + mapSint64Sint64_.AddEntriesFrom(ref input, _map_mapSint64Sint64_codec); + break; + } + case 58: { + mapFixed32Fixed32_.AddEntriesFrom(ref input, _map_mapFixed32Fixed32_codec); + break; + } + case 66: { + mapFixed64Fixed64_.AddEntriesFrom(ref input, _map_mapFixed64Fixed64_codec); + break; + } + case 74: { + mapSfixed32Sfixed32_.AddEntriesFrom(ref input, _map_mapSfixed32Sfixed32_codec); + break; + } + case 82: { + mapSfixed64Sfixed64_.AddEntriesFrom(ref input, _map_mapSfixed64Sfixed64_codec); + break; + } + case 90: { + mapInt32Float_.AddEntriesFrom(ref input, _map_mapInt32Float_codec); + break; + } + case 98: { + mapInt32Double_.AddEntriesFrom(ref input, _map_mapInt32Double_codec); + break; + } + case 106: { + mapBoolBool_.AddEntriesFrom(ref input, _map_mapBoolBool_codec); + break; + } + case 114: { + mapStringString_.AddEntriesFrom(ref input, _map_mapStringString_codec); + break; + } + case 122: { + mapInt32Bytes_.AddEntriesFrom(ref input, _map_mapInt32Bytes_codec); + break; + } + case 130: { + mapInt32Enum_.AddEntriesFrom(ref input, _map_mapInt32Enum_codec); + break; + } + case 138: { + mapInt32ForeignMessage_.AddEntriesFrom(ref input, _map_mapInt32ForeignMessage_codec); + break; + } + } + } + } + #endif + } - public sealed partial class TestMapSubmessage : pb::IMessage { + public sealed partial class TestMapSubmessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestMapSubmessage()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -705,6 +823,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (testMap_ != null) { + output.WriteRawTag(10); + output.WriteMessage(TestMap); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -750,9 +882,35 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + if (testMap_ == null) { + TestMap = new global::Google.Protobuf.TestProtos.TestMap(); + } + input.ReadMessage(TestMap); + break; + } + } + } + } + #endif + } - public sealed partial class TestMessageMap : pb::IMessage { + public sealed partial class TestMessageMap : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestMessageMap()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -836,6 +994,17 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + mapInt32Message_.WriteTo(ref output, _map_mapInt32Message_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -871,12 +1040,35 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + mapInt32Message_.AddEntriesFrom(ref input, _map_mapInt32Message_codec); + break; + } + } + } + } + #endif + } /// /// Two map fields share the same entry default instance. /// - public sealed partial class TestSameTypeMap : pb::IMessage { + public sealed partial class TestSameTypeMap : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestSameTypeMap()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -974,6 +1166,18 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + map1_.WriteTo(ref output, _map_map1_codec); + map2_.WriteTo(ref output, _map_map2_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -1015,9 +1219,36 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + map1_.AddEntriesFrom(ref input, _map_map1_codec); + break; + } + case 18: { + map2_.AddEntriesFrom(ref input, _map_map2_codec); + break; + } + } + } + } + #endif + } - public sealed partial class TestArenaMap : pb::IMessage { + public sealed partial class TestArenaMap : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestArenaMap()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -1297,6 +1528,31 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + mapInt32Int32_.WriteTo(ref output, _map_mapInt32Int32_codec); + mapInt64Int64_.WriteTo(ref output, _map_mapInt64Int64_codec); + mapUint32Uint32_.WriteTo(ref output, _map_mapUint32Uint32_codec); + mapUint64Uint64_.WriteTo(ref output, _map_mapUint64Uint64_codec); + mapSint32Sint32_.WriteTo(ref output, _map_mapSint32Sint32_codec); + mapSint64Sint64_.WriteTo(ref output, _map_mapSint64Sint64_codec); + mapFixed32Fixed32_.WriteTo(ref output, _map_mapFixed32Fixed32_codec); + mapFixed64Fixed64_.WriteTo(ref output, _map_mapFixed64Fixed64_codec); + mapSfixed32Sfixed32_.WriteTo(ref output, _map_mapSfixed32Sfixed32_codec); + mapSfixed64Sfixed64_.WriteTo(ref output, _map_mapSfixed64Sfixed64_codec); + mapInt32Float_.WriteTo(ref output, _map_mapInt32Float_codec); + mapInt32Double_.WriteTo(ref output, _map_mapInt32Double_codec); + mapBoolBool_.WriteTo(ref output, _map_mapBoolBool_codec); + mapInt32Enum_.WriteTo(ref output, _map_mapInt32Enum_codec); + mapInt32ForeignMessage_.WriteTo(ref output, _map_mapInt32ForeignMessage_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -1416,13 +1672,92 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + mapInt32Int32_.AddEntriesFrom(ref input, _map_mapInt32Int32_codec); + break; + } + case 18: { + mapInt64Int64_.AddEntriesFrom(ref input, _map_mapInt64Int64_codec); + break; + } + case 26: { + mapUint32Uint32_.AddEntriesFrom(ref input, _map_mapUint32Uint32_codec); + break; + } + case 34: { + mapUint64Uint64_.AddEntriesFrom(ref input, _map_mapUint64Uint64_codec); + break; + } + case 42: { + mapSint32Sint32_.AddEntriesFrom(ref input, _map_mapSint32Sint32_codec); + break; + } + case 50: { + mapSint64Sint64_.AddEntriesFrom(ref input, _map_mapSint64Sint64_codec); + break; + } + case 58: { + mapFixed32Fixed32_.AddEntriesFrom(ref input, _map_mapFixed32Fixed32_codec); + break; + } + case 66: { + mapFixed64Fixed64_.AddEntriesFrom(ref input, _map_mapFixed64Fixed64_codec); + break; + } + case 74: { + mapSfixed32Sfixed32_.AddEntriesFrom(ref input, _map_mapSfixed32Sfixed32_codec); + break; + } + case 82: { + mapSfixed64Sfixed64_.AddEntriesFrom(ref input, _map_mapSfixed64Sfixed64_codec); + break; + } + case 90: { + mapInt32Float_.AddEntriesFrom(ref input, _map_mapInt32Float_codec); + break; + } + case 98: { + mapInt32Double_.AddEntriesFrom(ref input, _map_mapInt32Double_codec); + break; + } + case 106: { + mapBoolBool_.AddEntriesFrom(ref input, _map_mapBoolBool_codec); + break; + } + case 114: { + mapInt32Enum_.AddEntriesFrom(ref input, _map_mapInt32Enum_codec); + break; + } + case 122: { + mapInt32ForeignMessage_.AddEntriesFrom(ref input, _map_mapInt32ForeignMessage_codec); + break; + } + } + } + } + #endif + } /// /// Previously, message containing enum called Type cannot be used as value of /// map field. /// - public sealed partial class MessageContainingEnumCalledType : pb::IMessage { + public sealed partial class MessageContainingEnumCalledType : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new MessageContainingEnumCalledType()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -1506,6 +1841,17 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + type_.WriteTo(ref output, _map_type_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -1541,6 +1887,25 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + type_.AddEntriesFrom(ref input, _map_type_codec); + break; + } + } + } + } + #endif + #region Nested types /// Container for nested types declared in the MessageContainingEnumCalledType message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -1557,7 +1922,11 @@ public enum Type { /// /// Previously, message cannot contain map field called "entry". /// - public sealed partial class MessageContainingMapCalledEntry : pb::IMessage { + public sealed partial class MessageContainingMapCalledEntry : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new MessageContainingMapCalledEntry()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -1641,6 +2010,17 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + entry_.WriteTo(ref output, _map_entry_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -1676,6 +2056,25 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + entry_.AddEntriesFrom(ref input, _map_entry_codec); + break; + } + } + } + } + #endif + } #endregion diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto2.cs b/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto2.cs index 350fb7cde714..71bdb895597f 100644 --- a/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto2.cs +++ b/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto2.cs @@ -244,7 +244,11 @@ public enum ForeignEnumProto2 { /// could trigger bugs that occur in any message type in this file. We verify /// this stays true in a unit test. /// - public sealed partial class TestAllTypesProto2 : pb::IExtendableMessage { + public sealed partial class TestAllTypesProto2 : pb::IExtendableMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestAllTypesProto2()); private pb::UnknownFieldSet _unknownFields; private pb::ExtensionSet _extensions; @@ -2876,6 +2880,288 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasOptionalInt32) { + output.WriteRawTag(8); + output.WriteInt32(OptionalInt32); + } + if (HasOptionalInt64) { + output.WriteRawTag(16); + output.WriteInt64(OptionalInt64); + } + if (HasOptionalUint32) { + output.WriteRawTag(24); + output.WriteUInt32(OptionalUint32); + } + if (HasOptionalUint64) { + output.WriteRawTag(32); + output.WriteUInt64(OptionalUint64); + } + if (HasOptionalSint32) { + output.WriteRawTag(40); + output.WriteSInt32(OptionalSint32); + } + if (HasOptionalSint64) { + output.WriteRawTag(48); + output.WriteSInt64(OptionalSint64); + } + if (HasOptionalFixed32) { + output.WriteRawTag(61); + output.WriteFixed32(OptionalFixed32); + } + if (HasOptionalFixed64) { + output.WriteRawTag(65); + output.WriteFixed64(OptionalFixed64); + } + if (HasOptionalSfixed32) { + output.WriteRawTag(77); + output.WriteSFixed32(OptionalSfixed32); + } + if (HasOptionalSfixed64) { + output.WriteRawTag(81); + output.WriteSFixed64(OptionalSfixed64); + } + if (HasOptionalFloat) { + output.WriteRawTag(93); + output.WriteFloat(OptionalFloat); + } + if (HasOptionalDouble) { + output.WriteRawTag(97); + output.WriteDouble(OptionalDouble); + } + if (HasOptionalBool) { + output.WriteRawTag(104); + output.WriteBool(OptionalBool); + } + if (HasOptionalString) { + output.WriteRawTag(114); + output.WriteString(OptionalString); + } + if (HasOptionalBytes) { + output.WriteRawTag(122); + output.WriteBytes(OptionalBytes); + } + if (HasOptionalNestedMessage) { + output.WriteRawTag(146, 1); + output.WriteMessage(OptionalNestedMessage); + } + if (HasOptionalForeignMessage) { + output.WriteRawTag(154, 1); + output.WriteMessage(OptionalForeignMessage); + } + if (HasOptionalNestedEnum) { + output.WriteRawTag(168, 1); + output.WriteEnum((int) OptionalNestedEnum); + } + if (HasOptionalForeignEnum) { + output.WriteRawTag(176, 1); + output.WriteEnum((int) OptionalForeignEnum); + } + if (HasOptionalStringPiece) { + output.WriteRawTag(194, 1); + output.WriteString(OptionalStringPiece); + } + if (HasOptionalCord) { + output.WriteRawTag(202, 1); + output.WriteString(OptionalCord); + } + if (HasRecursiveMessage) { + output.WriteRawTag(218, 1); + output.WriteMessage(RecursiveMessage); + } + repeatedInt32_.WriteTo(ref output, _repeated_repeatedInt32_codec); + repeatedInt64_.WriteTo(ref output, _repeated_repeatedInt64_codec); + repeatedUint32_.WriteTo(ref output, _repeated_repeatedUint32_codec); + repeatedUint64_.WriteTo(ref output, _repeated_repeatedUint64_codec); + repeatedSint32_.WriteTo(ref output, _repeated_repeatedSint32_codec); + repeatedSint64_.WriteTo(ref output, _repeated_repeatedSint64_codec); + repeatedFixed32_.WriteTo(ref output, _repeated_repeatedFixed32_codec); + repeatedFixed64_.WriteTo(ref output, _repeated_repeatedFixed64_codec); + repeatedSfixed32_.WriteTo(ref output, _repeated_repeatedSfixed32_codec); + repeatedSfixed64_.WriteTo(ref output, _repeated_repeatedSfixed64_codec); + repeatedFloat_.WriteTo(ref output, _repeated_repeatedFloat_codec); + repeatedDouble_.WriteTo(ref output, _repeated_repeatedDouble_codec); + repeatedBool_.WriteTo(ref output, _repeated_repeatedBool_codec); + repeatedString_.WriteTo(ref output, _repeated_repeatedString_codec); + repeatedBytes_.WriteTo(ref output, _repeated_repeatedBytes_codec); + repeatedNestedMessage_.WriteTo(ref output, _repeated_repeatedNestedMessage_codec); + repeatedForeignMessage_.WriteTo(ref output, _repeated_repeatedForeignMessage_codec); + repeatedNestedEnum_.WriteTo(ref output, _repeated_repeatedNestedEnum_codec); + repeatedForeignEnum_.WriteTo(ref output, _repeated_repeatedForeignEnum_codec); + repeatedStringPiece_.WriteTo(ref output, _repeated_repeatedStringPiece_codec); + repeatedCord_.WriteTo(ref output, _repeated_repeatedCord_codec); + mapInt32Int32_.WriteTo(ref output, _map_mapInt32Int32_codec); + mapInt64Int64_.WriteTo(ref output, _map_mapInt64Int64_codec); + mapUint32Uint32_.WriteTo(ref output, _map_mapUint32Uint32_codec); + mapUint64Uint64_.WriteTo(ref output, _map_mapUint64Uint64_codec); + mapSint32Sint32_.WriteTo(ref output, _map_mapSint32Sint32_codec); + mapSint64Sint64_.WriteTo(ref output, _map_mapSint64Sint64_codec); + mapFixed32Fixed32_.WriteTo(ref output, _map_mapFixed32Fixed32_codec); + mapFixed64Fixed64_.WriteTo(ref output, _map_mapFixed64Fixed64_codec); + mapSfixed32Sfixed32_.WriteTo(ref output, _map_mapSfixed32Sfixed32_codec); + mapSfixed64Sfixed64_.WriteTo(ref output, _map_mapSfixed64Sfixed64_codec); + mapInt32Float_.WriteTo(ref output, _map_mapInt32Float_codec); + mapInt32Double_.WriteTo(ref output, _map_mapInt32Double_codec); + mapBoolBool_.WriteTo(ref output, _map_mapBoolBool_codec); + mapStringString_.WriteTo(ref output, _map_mapStringString_codec); + mapStringBytes_.WriteTo(ref output, _map_mapStringBytes_codec); + mapStringNestedMessage_.WriteTo(ref output, _map_mapStringNestedMessage_codec); + mapStringForeignMessage_.WriteTo(ref output, _map_mapStringForeignMessage_codec); + mapStringNestedEnum_.WriteTo(ref output, _map_mapStringNestedEnum_codec); + mapStringForeignEnum_.WriteTo(ref output, _map_mapStringForeignEnum_codec); + packedInt32_.WriteTo(ref output, _repeated_packedInt32_codec); + packedInt64_.WriteTo(ref output, _repeated_packedInt64_codec); + packedUint32_.WriteTo(ref output, _repeated_packedUint32_codec); + packedUint64_.WriteTo(ref output, _repeated_packedUint64_codec); + packedSint32_.WriteTo(ref output, _repeated_packedSint32_codec); + packedSint64_.WriteTo(ref output, _repeated_packedSint64_codec); + packedFixed32_.WriteTo(ref output, _repeated_packedFixed32_codec); + packedFixed64_.WriteTo(ref output, _repeated_packedFixed64_codec); + packedSfixed32_.WriteTo(ref output, _repeated_packedSfixed32_codec); + packedSfixed64_.WriteTo(ref output, _repeated_packedSfixed64_codec); + packedFloat_.WriteTo(ref output, _repeated_packedFloat_codec); + packedDouble_.WriteTo(ref output, _repeated_packedDouble_codec); + packedBool_.WriteTo(ref output, _repeated_packedBool_codec); + packedNestedEnum_.WriteTo(ref output, _repeated_packedNestedEnum_codec); + unpackedInt32_.WriteTo(ref output, _repeated_unpackedInt32_codec); + unpackedInt64_.WriteTo(ref output, _repeated_unpackedInt64_codec); + unpackedUint32_.WriteTo(ref output, _repeated_unpackedUint32_codec); + unpackedUint64_.WriteTo(ref output, _repeated_unpackedUint64_codec); + unpackedSint32_.WriteTo(ref output, _repeated_unpackedSint32_codec); + unpackedSint64_.WriteTo(ref output, _repeated_unpackedSint64_codec); + unpackedFixed32_.WriteTo(ref output, _repeated_unpackedFixed32_codec); + unpackedFixed64_.WriteTo(ref output, _repeated_unpackedFixed64_codec); + unpackedSfixed32_.WriteTo(ref output, _repeated_unpackedSfixed32_codec); + unpackedSfixed64_.WriteTo(ref output, _repeated_unpackedSfixed64_codec); + unpackedFloat_.WriteTo(ref output, _repeated_unpackedFloat_codec); + unpackedDouble_.WriteTo(ref output, _repeated_unpackedDouble_codec); + unpackedBool_.WriteTo(ref output, _repeated_unpackedBool_codec); + unpackedNestedEnum_.WriteTo(ref output, _repeated_unpackedNestedEnum_codec); + if (HasOneofUint32) { + output.WriteRawTag(248, 6); + output.WriteUInt32(OneofUint32); + } + if (HasOneofNestedMessage) { + output.WriteRawTag(130, 7); + output.WriteMessage(OneofNestedMessage); + } + if (HasOneofString) { + output.WriteRawTag(138, 7); + output.WriteString(OneofString); + } + if (HasOneofBytes) { + output.WriteRawTag(146, 7); + output.WriteBytes(OneofBytes); + } + if (HasOneofBool) { + output.WriteRawTag(152, 7); + output.WriteBool(OneofBool); + } + if (HasOneofUint64) { + output.WriteRawTag(160, 7); + output.WriteUInt64(OneofUint64); + } + if (HasOneofFloat) { + output.WriteRawTag(173, 7); + output.WriteFloat(OneofFloat); + } + if (HasOneofDouble) { + output.WriteRawTag(177, 7); + output.WriteDouble(OneofDouble); + } + if (HasOneofEnum) { + output.WriteRawTag(184, 7); + output.WriteEnum((int) OneofEnum); + } + if (HasData) { + output.WriteRawTag(203, 12); + output.WriteGroup(Data); + output.WriteRawTag(204, 12); + } + if (HasFieldname1) { + output.WriteRawTag(136, 25); + output.WriteInt32(Fieldname1); + } + if (HasFieldName2) { + output.WriteRawTag(144, 25); + output.WriteInt32(FieldName2); + } + if (HasFieldName3) { + output.WriteRawTag(152, 25); + output.WriteInt32(FieldName3); + } + if (HasFieldName4) { + output.WriteRawTag(160, 25); + output.WriteInt32(FieldName4); + } + if (HasField0Name5) { + output.WriteRawTag(168, 25); + output.WriteInt32(Field0Name5); + } + if (HasField0Name6) { + output.WriteRawTag(176, 25); + output.WriteInt32(Field0Name6); + } + if (HasFieldName7) { + output.WriteRawTag(184, 25); + output.WriteInt32(FieldName7); + } + if (HasFieldName8) { + output.WriteRawTag(192, 25); + output.WriteInt32(FieldName8); + } + if (HasFieldName9) { + output.WriteRawTag(200, 25); + output.WriteInt32(FieldName9); + } + if (HasFieldName10) { + output.WriteRawTag(208, 25); + output.WriteInt32(FieldName10); + } + if (HasFIELDNAME11) { + output.WriteRawTag(216, 25); + output.WriteInt32(FIELDNAME11); + } + if (HasFIELDName12) { + output.WriteRawTag(224, 25); + output.WriteInt32(FIELDName12); + } + if (HasFieldName13) { + output.WriteRawTag(232, 25); + output.WriteInt32(FieldName13); + } + if (HasFieldName14) { + output.WriteRawTag(240, 25); + output.WriteInt32(FieldName14); + } + if (HasFieldName15) { + output.WriteRawTag(248, 25); + output.WriteInt32(FieldName15); + } + if (HasFieldName16) { + output.WriteRawTag(128, 26); + output.WriteInt32(FieldName16); + } + if (HasFieldName17) { + output.WriteRawTag(136, 26); + output.WriteInt32(FieldName17); + } + if (HasFieldName18) { + output.WriteRawTag(144, 26); + output.WriteInt32(FieldName18); + } + if (_extensions != null) { + _extensions.WriteTo(ref output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -3898,56 +4184,610 @@ public void MergeFrom(pb::CodedInputStream input) { } } - public TValue GetExtension(pb::Extension extension) { - return pb::ExtensionSet.Get(ref _extensions, extension); - } - public pbc::RepeatedField GetExtension(pb::RepeatedExtension extension) { - return pb::ExtensionSet.Get(ref _extensions, extension); - } - public pbc::RepeatedField GetOrInitializeExtension(pb::RepeatedExtension extension) { - return pb::ExtensionSet.GetOrInitialize(ref _extensions, extension); - } - public void SetExtension(pb::Extension extension, TValue value) { - pb::ExtensionSet.Set(ref _extensions, extension, value); - } - public bool HasExtension(pb::Extension extension) { - return pb::ExtensionSet.Has(ref _extensions, extension); - } - public void ClearExtension(pb::Extension extension) { - pb::ExtensionSet.Clear(ref _extensions, extension); - } - public void ClearExtension(pb::RepeatedExtension extension) { - pb::ExtensionSet.Clear(ref _extensions, extension); - } - #region Nested types - /// Container for nested types declared in the TestAllTypesProto2 message type. + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public static partial class Types { - public enum NestedEnum { - [pbr::OriginalName("FOO")] Foo = 0, - [pbr::OriginalName("BAR")] Bar = 1, - [pbr::OriginalName("BAZ")] Baz = 2, - /// - /// Intentionally negative. - /// - [pbr::OriginalName("NEG")] Neg = -1, - } - - public sealed partial class NestedMessage : pb::IMessage { - private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new NestedMessage()); - private pb::UnknownFieldSet _unknownFields; - private int _hasBits0; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public static pb::MessageParser Parser { get { return _parser; } } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public static pbr::MessageDescriptor Descriptor { - get { return global::ProtobufTestMessages.Proto2.TestAllTypesProto2.Descriptor.NestedTypes[0]; } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - pbr::MessageDescriptor pb::IMessage.Descriptor { + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + } + break; + case 8: { + OptionalInt32 = input.ReadInt32(); + break; + } + case 16: { + OptionalInt64 = input.ReadInt64(); + break; + } + case 24: { + OptionalUint32 = input.ReadUInt32(); + break; + } + case 32: { + OptionalUint64 = input.ReadUInt64(); + break; + } + case 40: { + OptionalSint32 = input.ReadSInt32(); + break; + } + case 48: { + OptionalSint64 = input.ReadSInt64(); + break; + } + case 61: { + OptionalFixed32 = input.ReadFixed32(); + break; + } + case 65: { + OptionalFixed64 = input.ReadFixed64(); + break; + } + case 77: { + OptionalSfixed32 = input.ReadSFixed32(); + break; + } + case 81: { + OptionalSfixed64 = input.ReadSFixed64(); + break; + } + case 93: { + OptionalFloat = input.ReadFloat(); + break; + } + case 97: { + OptionalDouble = input.ReadDouble(); + break; + } + case 104: { + OptionalBool = input.ReadBool(); + break; + } + case 114: { + OptionalString = input.ReadString(); + break; + } + case 122: { + OptionalBytes = input.ReadBytes(); + break; + } + case 146: { + if (!HasOptionalNestedMessage) { + OptionalNestedMessage = new global::ProtobufTestMessages.Proto2.TestAllTypesProto2.Types.NestedMessage(); + } + input.ReadMessage(OptionalNestedMessage); + break; + } + case 154: { + if (!HasOptionalForeignMessage) { + OptionalForeignMessage = new global::ProtobufTestMessages.Proto2.ForeignMessageProto2(); + } + input.ReadMessage(OptionalForeignMessage); + break; + } + case 168: { + OptionalNestedEnum = (global::ProtobufTestMessages.Proto2.TestAllTypesProto2.Types.NestedEnum) input.ReadEnum(); + break; + } + case 176: { + OptionalForeignEnum = (global::ProtobufTestMessages.Proto2.ForeignEnumProto2) input.ReadEnum(); + break; + } + case 194: { + OptionalStringPiece = input.ReadString(); + break; + } + case 202: { + OptionalCord = input.ReadString(); + break; + } + case 218: { + if (!HasRecursiveMessage) { + RecursiveMessage = new global::ProtobufTestMessages.Proto2.TestAllTypesProto2(); + } + input.ReadMessage(RecursiveMessage); + break; + } + case 250: + case 248: { + repeatedInt32_.AddEntriesFrom(ref input, _repeated_repeatedInt32_codec); + break; + } + case 258: + case 256: { + repeatedInt64_.AddEntriesFrom(ref input, _repeated_repeatedInt64_codec); + break; + } + case 266: + case 264: { + repeatedUint32_.AddEntriesFrom(ref input, _repeated_repeatedUint32_codec); + break; + } + case 274: + case 272: { + repeatedUint64_.AddEntriesFrom(ref input, _repeated_repeatedUint64_codec); + break; + } + case 282: + case 280: { + repeatedSint32_.AddEntriesFrom(ref input, _repeated_repeatedSint32_codec); + break; + } + case 290: + case 288: { + repeatedSint64_.AddEntriesFrom(ref input, _repeated_repeatedSint64_codec); + break; + } + case 298: + case 301: { + repeatedFixed32_.AddEntriesFrom(ref input, _repeated_repeatedFixed32_codec); + break; + } + case 306: + case 305: { + repeatedFixed64_.AddEntriesFrom(ref input, _repeated_repeatedFixed64_codec); + break; + } + case 314: + case 317: { + repeatedSfixed32_.AddEntriesFrom(ref input, _repeated_repeatedSfixed32_codec); + break; + } + case 322: + case 321: { + repeatedSfixed64_.AddEntriesFrom(ref input, _repeated_repeatedSfixed64_codec); + break; + } + case 330: + case 333: { + repeatedFloat_.AddEntriesFrom(ref input, _repeated_repeatedFloat_codec); + break; + } + case 338: + case 337: { + repeatedDouble_.AddEntriesFrom(ref input, _repeated_repeatedDouble_codec); + break; + } + case 346: + case 344: { + repeatedBool_.AddEntriesFrom(ref input, _repeated_repeatedBool_codec); + break; + } + case 354: { + repeatedString_.AddEntriesFrom(ref input, _repeated_repeatedString_codec); + break; + } + case 362: { + repeatedBytes_.AddEntriesFrom(ref input, _repeated_repeatedBytes_codec); + break; + } + case 386: { + repeatedNestedMessage_.AddEntriesFrom(ref input, _repeated_repeatedNestedMessage_codec); + break; + } + case 394: { + repeatedForeignMessage_.AddEntriesFrom(ref input, _repeated_repeatedForeignMessage_codec); + break; + } + case 410: + case 408: { + repeatedNestedEnum_.AddEntriesFrom(ref input, _repeated_repeatedNestedEnum_codec); + break; + } + case 418: + case 416: { + repeatedForeignEnum_.AddEntriesFrom(ref input, _repeated_repeatedForeignEnum_codec); + break; + } + case 434: { + repeatedStringPiece_.AddEntriesFrom(ref input, _repeated_repeatedStringPiece_codec); + break; + } + case 442: { + repeatedCord_.AddEntriesFrom(ref input, _repeated_repeatedCord_codec); + break; + } + case 450: { + mapInt32Int32_.AddEntriesFrom(ref input, _map_mapInt32Int32_codec); + break; + } + case 458: { + mapInt64Int64_.AddEntriesFrom(ref input, _map_mapInt64Int64_codec); + break; + } + case 466: { + mapUint32Uint32_.AddEntriesFrom(ref input, _map_mapUint32Uint32_codec); + break; + } + case 474: { + mapUint64Uint64_.AddEntriesFrom(ref input, _map_mapUint64Uint64_codec); + break; + } + case 482: { + mapSint32Sint32_.AddEntriesFrom(ref input, _map_mapSint32Sint32_codec); + break; + } + case 490: { + mapSint64Sint64_.AddEntriesFrom(ref input, _map_mapSint64Sint64_codec); + break; + } + case 498: { + mapFixed32Fixed32_.AddEntriesFrom(ref input, _map_mapFixed32Fixed32_codec); + break; + } + case 506: { + mapFixed64Fixed64_.AddEntriesFrom(ref input, _map_mapFixed64Fixed64_codec); + break; + } + case 514: { + mapSfixed32Sfixed32_.AddEntriesFrom(ref input, _map_mapSfixed32Sfixed32_codec); + break; + } + case 522: { + mapSfixed64Sfixed64_.AddEntriesFrom(ref input, _map_mapSfixed64Sfixed64_codec); + break; + } + case 530: { + mapInt32Float_.AddEntriesFrom(ref input, _map_mapInt32Float_codec); + break; + } + case 538: { + mapInt32Double_.AddEntriesFrom(ref input, _map_mapInt32Double_codec); + break; + } + case 546: { + mapBoolBool_.AddEntriesFrom(ref input, _map_mapBoolBool_codec); + break; + } + case 554: { + mapStringString_.AddEntriesFrom(ref input, _map_mapStringString_codec); + break; + } + case 562: { + mapStringBytes_.AddEntriesFrom(ref input, _map_mapStringBytes_codec); + break; + } + case 570: { + mapStringNestedMessage_.AddEntriesFrom(ref input, _map_mapStringNestedMessage_codec); + break; + } + case 578: { + mapStringForeignMessage_.AddEntriesFrom(ref input, _map_mapStringForeignMessage_codec); + break; + } + case 586: { + mapStringNestedEnum_.AddEntriesFrom(ref input, _map_mapStringNestedEnum_codec); + break; + } + case 594: { + mapStringForeignEnum_.AddEntriesFrom(ref input, _map_mapStringForeignEnum_codec); + break; + } + case 602: + case 600: { + packedInt32_.AddEntriesFrom(ref input, _repeated_packedInt32_codec); + break; + } + case 610: + case 608: { + packedInt64_.AddEntriesFrom(ref input, _repeated_packedInt64_codec); + break; + } + case 618: + case 616: { + packedUint32_.AddEntriesFrom(ref input, _repeated_packedUint32_codec); + break; + } + case 626: + case 624: { + packedUint64_.AddEntriesFrom(ref input, _repeated_packedUint64_codec); + break; + } + case 634: + case 632: { + packedSint32_.AddEntriesFrom(ref input, _repeated_packedSint32_codec); + break; + } + case 642: + case 640: { + packedSint64_.AddEntriesFrom(ref input, _repeated_packedSint64_codec); + break; + } + case 650: + case 653: { + packedFixed32_.AddEntriesFrom(ref input, _repeated_packedFixed32_codec); + break; + } + case 658: + case 657: { + packedFixed64_.AddEntriesFrom(ref input, _repeated_packedFixed64_codec); + break; + } + case 666: + case 669: { + packedSfixed32_.AddEntriesFrom(ref input, _repeated_packedSfixed32_codec); + break; + } + case 674: + case 673: { + packedSfixed64_.AddEntriesFrom(ref input, _repeated_packedSfixed64_codec); + break; + } + case 682: + case 685: { + packedFloat_.AddEntriesFrom(ref input, _repeated_packedFloat_codec); + break; + } + case 690: + case 689: { + packedDouble_.AddEntriesFrom(ref input, _repeated_packedDouble_codec); + break; + } + case 698: + case 696: { + packedBool_.AddEntriesFrom(ref input, _repeated_packedBool_codec); + break; + } + case 706: + case 704: { + packedNestedEnum_.AddEntriesFrom(ref input, _repeated_packedNestedEnum_codec); + break; + } + case 714: + case 712: { + unpackedInt32_.AddEntriesFrom(ref input, _repeated_unpackedInt32_codec); + break; + } + case 722: + case 720: { + unpackedInt64_.AddEntriesFrom(ref input, _repeated_unpackedInt64_codec); + break; + } + case 730: + case 728: { + unpackedUint32_.AddEntriesFrom(ref input, _repeated_unpackedUint32_codec); + break; + } + case 738: + case 736: { + unpackedUint64_.AddEntriesFrom(ref input, _repeated_unpackedUint64_codec); + break; + } + case 746: + case 744: { + unpackedSint32_.AddEntriesFrom(ref input, _repeated_unpackedSint32_codec); + break; + } + case 754: + case 752: { + unpackedSint64_.AddEntriesFrom(ref input, _repeated_unpackedSint64_codec); + break; + } + case 762: + case 765: { + unpackedFixed32_.AddEntriesFrom(ref input, _repeated_unpackedFixed32_codec); + break; + } + case 770: + case 769: { + unpackedFixed64_.AddEntriesFrom(ref input, _repeated_unpackedFixed64_codec); + break; + } + case 778: + case 781: { + unpackedSfixed32_.AddEntriesFrom(ref input, _repeated_unpackedSfixed32_codec); + break; + } + case 786: + case 785: { + unpackedSfixed64_.AddEntriesFrom(ref input, _repeated_unpackedSfixed64_codec); + break; + } + case 794: + case 797: { + unpackedFloat_.AddEntriesFrom(ref input, _repeated_unpackedFloat_codec); + break; + } + case 802: + case 801: { + unpackedDouble_.AddEntriesFrom(ref input, _repeated_unpackedDouble_codec); + break; + } + case 810: + case 808: { + unpackedBool_.AddEntriesFrom(ref input, _repeated_unpackedBool_codec); + break; + } + case 818: + case 816: { + unpackedNestedEnum_.AddEntriesFrom(ref input, _repeated_unpackedNestedEnum_codec); + break; + } + case 888: { + OneofUint32 = input.ReadUInt32(); + break; + } + case 898: { + global::ProtobufTestMessages.Proto2.TestAllTypesProto2.Types.NestedMessage subBuilder = new global::ProtobufTestMessages.Proto2.TestAllTypesProto2.Types.NestedMessage(); + if (HasOneofNestedMessage) { + subBuilder.MergeFrom(OneofNestedMessage); + } + input.ReadMessage(subBuilder); + OneofNestedMessage = subBuilder; + break; + } + case 906: { + OneofString = input.ReadString(); + break; + } + case 914: { + OneofBytes = input.ReadBytes(); + break; + } + case 920: { + OneofBool = input.ReadBool(); + break; + } + case 928: { + OneofUint64 = input.ReadUInt64(); + break; + } + case 941: { + OneofFloat = input.ReadFloat(); + break; + } + case 945: { + OneofDouble = input.ReadDouble(); + break; + } + case 952: { + oneofField_ = input.ReadEnum(); + oneofFieldCase_ = OneofFieldOneofCase.OneofEnum; + break; + } + case 1611: { + if (!HasData) { + Data = new global::ProtobufTestMessages.Proto2.TestAllTypesProto2.Types.Data(); + } + input.ReadGroup(Data); + break; + } + case 3208: { + Fieldname1 = input.ReadInt32(); + break; + } + case 3216: { + FieldName2 = input.ReadInt32(); + break; + } + case 3224: { + FieldName3 = input.ReadInt32(); + break; + } + case 3232: { + FieldName4 = input.ReadInt32(); + break; + } + case 3240: { + Field0Name5 = input.ReadInt32(); + break; + } + case 3248: { + Field0Name6 = input.ReadInt32(); + break; + } + case 3256: { + FieldName7 = input.ReadInt32(); + break; + } + case 3264: { + FieldName8 = input.ReadInt32(); + break; + } + case 3272: { + FieldName9 = input.ReadInt32(); + break; + } + case 3280: { + FieldName10 = input.ReadInt32(); + break; + } + case 3288: { + FIELDNAME11 = input.ReadInt32(); + break; + } + case 3296: { + FIELDName12 = input.ReadInt32(); + break; + } + case 3304: { + FieldName13 = input.ReadInt32(); + break; + } + case 3312: { + FieldName14 = input.ReadInt32(); + break; + } + case 3320: { + FieldName15 = input.ReadInt32(); + break; + } + case 3328: { + FieldName16 = input.ReadInt32(); + break; + } + case 3336: { + FieldName17 = input.ReadInt32(); + break; + } + case 3344: { + FieldName18 = input.ReadInt32(); + break; + } + } + } + } + #endif + + public TValue GetExtension(pb::Extension extension) { + return pb::ExtensionSet.Get(ref _extensions, extension); + } + public pbc::RepeatedField GetExtension(pb::RepeatedExtension extension) { + return pb::ExtensionSet.Get(ref _extensions, extension); + } + public pbc::RepeatedField GetOrInitializeExtension(pb::RepeatedExtension extension) { + return pb::ExtensionSet.GetOrInitialize(ref _extensions, extension); + } + public void SetExtension(pb::Extension extension, TValue value) { + pb::ExtensionSet.Set(ref _extensions, extension, value); + } + public bool HasExtension(pb::Extension extension) { + return pb::ExtensionSet.Has(ref _extensions, extension); + } + public void ClearExtension(pb::Extension extension) { + pb::ExtensionSet.Clear(ref _extensions, extension); + } + public void ClearExtension(pb::RepeatedExtension extension) { + pb::ExtensionSet.Clear(ref _extensions, extension); + } + + #region Nested types + /// Container for nested types declared in the TestAllTypesProto2 message type. + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static partial class Types { + public enum NestedEnum { + [pbr::OriginalName("FOO")] Foo = 0, + [pbr::OriginalName("BAR")] Bar = 1, + [pbr::OriginalName("BAZ")] Baz = 2, + /// + /// Intentionally negative. + /// + [pbr::OriginalName("NEG")] Neg = -1, + } + + public sealed partial class NestedMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new NestedMessage()); + private pb::UnknownFieldSet _unknownFields; + private int _hasBits0; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::ProtobufTestMessages.Proto2.TestAllTypesProto2.Descriptor.NestedTypes[0]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { get { return Descriptor; } } @@ -4040,18 +4880,35 @@ public override int GetHashCode() { if (HasA) hash ^= A.GetHashCode(); if (HasCorecursive) hash ^= Corecursive.GetHashCode(); if (_unknownFields != null) { - hash ^= _unknownFields.GetHashCode(); + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + if (HasA) { + output.WriteRawTag(8); + output.WriteInt32(A); + } + if (HasCorecursive) { + output.WriteRawTag(18); + output.WriteMessage(Corecursive); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); } - return hash; } - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public override string ToString() { - return pb::JsonFormatter.ToDiagnosticString(this); - } + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void WriteTo(pb::CodedOutputStream output) { + public void WriteTo(ref pb::CodedOutputWriter output) { if (HasA) { output.WriteRawTag(8); output.WriteInt32(A); @@ -4061,9 +4918,10 @@ public void WriteTo(pb::CodedOutputStream output) { output.WriteMessage(Corecursive); } if (_unknownFields != null) { - _unknownFields.WriteTo(output); + _unknownFields.WriteTo(ref output); } } + #endif [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { @@ -4120,12 +4978,42 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + A = input.ReadInt32(); + break; + } + case 18: { + if (!HasCorecursive) { + Corecursive = new global::ProtobufTestMessages.Proto2.TestAllTypesProto2(); + } + input.ReadMessage(Corecursive); + break; + } + } + } + } + #endif + } /// /// groups /// - public sealed partial class Data : pb::IMessage { + public sealed partial class Data : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Data()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -4259,6 +5147,24 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasGroupInt32) { + output.WriteRawTag(208, 12); + output.WriteInt32(GroupInt32); + } + if (HasGroupUint32) { + output.WriteRawTag(216, 12); + output.WriteUInt32(GroupUint32); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -4310,12 +5216,41 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + case 1612: + return; + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 1616: { + GroupInt32 = input.ReadInt32(); + break; + } + case 1624: { + GroupUint32 = input.ReadUInt32(); + break; + } + } + } + } + #endif + } /// /// message_set test case. /// - public sealed partial class MessageSetCorrect : pb::IExtendableMessage { + public sealed partial class MessageSetCorrect : pb::IExtendableMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new MessageSetCorrect()); private pb::UnknownFieldSet _unknownFields; private pb::ExtensionSet _extensions; @@ -4397,6 +5332,19 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_extensions != null) { + _extensions.WriteTo(ref output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -4432,6 +5380,23 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + } + break; + } + } + } + #endif + public TValue GetExtension(pb::Extension extension) { return pb::ExtensionSet.Get(ref _extensions, extension); } @@ -4456,7 +5421,11 @@ public void ClearExtension(pb::RepeatedExtension { + public sealed partial class MessageSetCorrectExtension1 : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new MessageSetCorrectExtension1()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -4556,6 +5525,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasStr) { + output.WriteRawTag(202, 1); + output.WriteString(Str); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -4595,6 +5578,25 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 202: { + Str = input.ReadString(); + break; + } + } + } + } + #endif + #region Extensions /// Container for extensions for other messages declared in the MessageSetCorrectExtension1 message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -4606,7 +5608,11 @@ public static partial class Extensions { } - public sealed partial class MessageSetCorrectExtension2 : pb::IMessage { + public sealed partial class MessageSetCorrectExtension2 : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new MessageSetCorrectExtension2()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -4709,6 +5715,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasI) { + output.WriteRawTag(72); + output.WriteInt32(I); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -4748,6 +5768,25 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 72: { + I = input.ReadInt32(); + break; + } + } + } + } + #endif + #region Extensions /// Container for extensions for other messages declared in the MessageSetCorrectExtension2 message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -4764,7 +5803,11 @@ public static partial class Extensions { } - public sealed partial class ForeignMessageProto2 : pb::IMessage { + public sealed partial class ForeignMessageProto2 : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ForeignMessageProto2()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -4867,6 +5910,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasC) { + output.WriteRawTag(8); + output.WriteInt32(C); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -4906,9 +5963,32 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + C = input.ReadInt32(); + break; + } + } + } + } + #endif + } - public sealed partial class UnknownToTestAllTypes : pb::IMessage { + public sealed partial class UnknownToTestAllTypes : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new UnknownToTestAllTypes()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -5143,6 +6223,38 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasOptionalInt32) { + output.WriteRawTag(200, 62); + output.WriteInt32(OptionalInt32); + } + if (HasOptionalString) { + output.WriteRawTag(210, 62); + output.WriteString(OptionalString); + } + if (HasNestedMessage) { + output.WriteRawTag(218, 62); + output.WriteMessage(NestedMessage); + } + if (HasOptionalGroup) { + output.WriteRawTag(227, 62); + output.WriteGroup(OptionalGroup); + output.WriteRawTag(228, 62); + } + if (HasOptionalBool) { + output.WriteRawTag(240, 62); + output.WriteBool(OptionalBool); + } + repeatedInt32_.WriteTo(ref output, _repeated_repeatedInt32_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -5241,11 +6353,61 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8008: { + OptionalInt32 = input.ReadInt32(); + break; + } + case 8018: { + OptionalString = input.ReadString(); + break; + } + case 8026: { + if (!HasNestedMessage) { + NestedMessage = new global::ProtobufTestMessages.Proto2.ForeignMessageProto2(); + } + input.ReadMessage(NestedMessage); + break; + } + case 8035: { + if (!HasOptionalGroup) { + OptionalGroup = new global::ProtobufTestMessages.Proto2.UnknownToTestAllTypes.Types.OptionalGroup(); + } + input.ReadGroup(OptionalGroup); + break; + } + case 8048: { + OptionalBool = input.ReadBool(); + break; + } + case 8090: + case 8088: { + repeatedInt32_.AddEntriesFrom(ref input, _repeated_repeatedInt32_codec); + break; + } + } + } + } + #endif + #region Nested types /// Container for nested types declared in the UnknownToTestAllTypes message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static partial class Types { - public sealed partial class OptionalGroup : pb::IMessage { + public sealed partial class OptionalGroup : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new OptionalGroup()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -5348,6 +6510,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasA) { + output.WriteRawTag(8); + output.WriteInt32(A); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -5389,6 +6565,27 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + case 8036: + return; + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + A = input.ReadInt32(); + break; + } + } + } + } + #endif + } } diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto3.cs b/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto3.cs index 064d0c0acec0..b1859a8292f6 100644 --- a/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto3.cs +++ b/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto3.cs @@ -259,7 +259,11 @@ public enum ForeignEnum { /// could trigger bugs that occur in any message type in this file. We verify /// this stays true in a unit test. /// - public sealed partial class TestAllTypesProto3 : pb::IMessage { + public sealed partial class TestAllTypesProto3 : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestAllTypesProto3()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -2755,6 +2759,351 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (OptionalInt32 != 0) { + output.WriteRawTag(8); + output.WriteInt32(OptionalInt32); + } + if (OptionalInt64 != 0L) { + output.WriteRawTag(16); + output.WriteInt64(OptionalInt64); + } + if (OptionalUint32 != 0) { + output.WriteRawTag(24); + output.WriteUInt32(OptionalUint32); + } + if (OptionalUint64 != 0UL) { + output.WriteRawTag(32); + output.WriteUInt64(OptionalUint64); + } + if (OptionalSint32 != 0) { + output.WriteRawTag(40); + output.WriteSInt32(OptionalSint32); + } + if (OptionalSint64 != 0L) { + output.WriteRawTag(48); + output.WriteSInt64(OptionalSint64); + } + if (OptionalFixed32 != 0) { + output.WriteRawTag(61); + output.WriteFixed32(OptionalFixed32); + } + if (OptionalFixed64 != 0UL) { + output.WriteRawTag(65); + output.WriteFixed64(OptionalFixed64); + } + if (OptionalSfixed32 != 0) { + output.WriteRawTag(77); + output.WriteSFixed32(OptionalSfixed32); + } + if (OptionalSfixed64 != 0L) { + output.WriteRawTag(81); + output.WriteSFixed64(OptionalSfixed64); + } + if (OptionalFloat != 0F) { + output.WriteRawTag(93); + output.WriteFloat(OptionalFloat); + } + if (OptionalDouble != 0D) { + output.WriteRawTag(97); + output.WriteDouble(OptionalDouble); + } + if (OptionalBool != false) { + output.WriteRawTag(104); + output.WriteBool(OptionalBool); + } + if (OptionalString.Length != 0) { + output.WriteRawTag(114); + output.WriteString(OptionalString); + } + if (OptionalBytes.Length != 0) { + output.WriteRawTag(122); + output.WriteBytes(OptionalBytes); + } + if (optionalNestedMessage_ != null) { + output.WriteRawTag(146, 1); + output.WriteMessage(OptionalNestedMessage); + } + if (optionalForeignMessage_ != null) { + output.WriteRawTag(154, 1); + output.WriteMessage(OptionalForeignMessage); + } + if (OptionalNestedEnum != global::ProtobufTestMessages.Proto3.TestAllTypesProto3.Types.NestedEnum.Foo) { + output.WriteRawTag(168, 1); + output.WriteEnum((int) OptionalNestedEnum); + } + if (OptionalForeignEnum != global::ProtobufTestMessages.Proto3.ForeignEnum.ForeignFoo) { + output.WriteRawTag(176, 1); + output.WriteEnum((int) OptionalForeignEnum); + } + if (OptionalAliasedEnum != global::ProtobufTestMessages.Proto3.TestAllTypesProto3.Types.AliasedEnum.AliasFoo) { + output.WriteRawTag(184, 1); + output.WriteEnum((int) OptionalAliasedEnum); + } + if (OptionalStringPiece.Length != 0) { + output.WriteRawTag(194, 1); + output.WriteString(OptionalStringPiece); + } + if (OptionalCord.Length != 0) { + output.WriteRawTag(202, 1); + output.WriteString(OptionalCord); + } + if (recursiveMessage_ != null) { + output.WriteRawTag(218, 1); + output.WriteMessage(RecursiveMessage); + } + repeatedInt32_.WriteTo(ref output, _repeated_repeatedInt32_codec); + repeatedInt64_.WriteTo(ref output, _repeated_repeatedInt64_codec); + repeatedUint32_.WriteTo(ref output, _repeated_repeatedUint32_codec); + repeatedUint64_.WriteTo(ref output, _repeated_repeatedUint64_codec); + repeatedSint32_.WriteTo(ref output, _repeated_repeatedSint32_codec); + repeatedSint64_.WriteTo(ref output, _repeated_repeatedSint64_codec); + repeatedFixed32_.WriteTo(ref output, _repeated_repeatedFixed32_codec); + repeatedFixed64_.WriteTo(ref output, _repeated_repeatedFixed64_codec); + repeatedSfixed32_.WriteTo(ref output, _repeated_repeatedSfixed32_codec); + repeatedSfixed64_.WriteTo(ref output, _repeated_repeatedSfixed64_codec); + repeatedFloat_.WriteTo(ref output, _repeated_repeatedFloat_codec); + repeatedDouble_.WriteTo(ref output, _repeated_repeatedDouble_codec); + repeatedBool_.WriteTo(ref output, _repeated_repeatedBool_codec); + repeatedString_.WriteTo(ref output, _repeated_repeatedString_codec); + repeatedBytes_.WriteTo(ref output, _repeated_repeatedBytes_codec); + repeatedNestedMessage_.WriteTo(ref output, _repeated_repeatedNestedMessage_codec); + repeatedForeignMessage_.WriteTo(ref output, _repeated_repeatedForeignMessage_codec); + repeatedNestedEnum_.WriteTo(ref output, _repeated_repeatedNestedEnum_codec); + repeatedForeignEnum_.WriteTo(ref output, _repeated_repeatedForeignEnum_codec); + repeatedStringPiece_.WriteTo(ref output, _repeated_repeatedStringPiece_codec); + repeatedCord_.WriteTo(ref output, _repeated_repeatedCord_codec); + mapInt32Int32_.WriteTo(ref output, _map_mapInt32Int32_codec); + mapInt64Int64_.WriteTo(ref output, _map_mapInt64Int64_codec); + mapUint32Uint32_.WriteTo(ref output, _map_mapUint32Uint32_codec); + mapUint64Uint64_.WriteTo(ref output, _map_mapUint64Uint64_codec); + mapSint32Sint32_.WriteTo(ref output, _map_mapSint32Sint32_codec); + mapSint64Sint64_.WriteTo(ref output, _map_mapSint64Sint64_codec); + mapFixed32Fixed32_.WriteTo(ref output, _map_mapFixed32Fixed32_codec); + mapFixed64Fixed64_.WriteTo(ref output, _map_mapFixed64Fixed64_codec); + mapSfixed32Sfixed32_.WriteTo(ref output, _map_mapSfixed32Sfixed32_codec); + mapSfixed64Sfixed64_.WriteTo(ref output, _map_mapSfixed64Sfixed64_codec); + mapInt32Float_.WriteTo(ref output, _map_mapInt32Float_codec); + mapInt32Double_.WriteTo(ref output, _map_mapInt32Double_codec); + mapBoolBool_.WriteTo(ref output, _map_mapBoolBool_codec); + mapStringString_.WriteTo(ref output, _map_mapStringString_codec); + mapStringBytes_.WriteTo(ref output, _map_mapStringBytes_codec); + mapStringNestedMessage_.WriteTo(ref output, _map_mapStringNestedMessage_codec); + mapStringForeignMessage_.WriteTo(ref output, _map_mapStringForeignMessage_codec); + mapStringNestedEnum_.WriteTo(ref output, _map_mapStringNestedEnum_codec); + mapStringForeignEnum_.WriteTo(ref output, _map_mapStringForeignEnum_codec); + packedInt32_.WriteTo(ref output, _repeated_packedInt32_codec); + packedInt64_.WriteTo(ref output, _repeated_packedInt64_codec); + packedUint32_.WriteTo(ref output, _repeated_packedUint32_codec); + packedUint64_.WriteTo(ref output, _repeated_packedUint64_codec); + packedSint32_.WriteTo(ref output, _repeated_packedSint32_codec); + packedSint64_.WriteTo(ref output, _repeated_packedSint64_codec); + packedFixed32_.WriteTo(ref output, _repeated_packedFixed32_codec); + packedFixed64_.WriteTo(ref output, _repeated_packedFixed64_codec); + packedSfixed32_.WriteTo(ref output, _repeated_packedSfixed32_codec); + packedSfixed64_.WriteTo(ref output, _repeated_packedSfixed64_codec); + packedFloat_.WriteTo(ref output, _repeated_packedFloat_codec); + packedDouble_.WriteTo(ref output, _repeated_packedDouble_codec); + packedBool_.WriteTo(ref output, _repeated_packedBool_codec); + packedNestedEnum_.WriteTo(ref output, _repeated_packedNestedEnum_codec); + unpackedInt32_.WriteTo(ref output, _repeated_unpackedInt32_codec); + unpackedInt64_.WriteTo(ref output, _repeated_unpackedInt64_codec); + unpackedUint32_.WriteTo(ref output, _repeated_unpackedUint32_codec); + unpackedUint64_.WriteTo(ref output, _repeated_unpackedUint64_codec); + unpackedSint32_.WriteTo(ref output, _repeated_unpackedSint32_codec); + unpackedSint64_.WriteTo(ref output, _repeated_unpackedSint64_codec); + unpackedFixed32_.WriteTo(ref output, _repeated_unpackedFixed32_codec); + unpackedFixed64_.WriteTo(ref output, _repeated_unpackedFixed64_codec); + unpackedSfixed32_.WriteTo(ref output, _repeated_unpackedSfixed32_codec); + unpackedSfixed64_.WriteTo(ref output, _repeated_unpackedSfixed64_codec); + unpackedFloat_.WriteTo(ref output, _repeated_unpackedFloat_codec); + 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) { + output.WriteRawTag(248, 6); + output.WriteUInt32(OneofUint32); + } + if (oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage) { + output.WriteRawTag(130, 7); + output.WriteMessage(OneofNestedMessage); + } + if (oneofFieldCase_ == OneofFieldOneofCase.OneofString) { + output.WriteRawTag(138, 7); + output.WriteString(OneofString); + } + if (oneofFieldCase_ == OneofFieldOneofCase.OneofBytes) { + output.WriteRawTag(146, 7); + output.WriteBytes(OneofBytes); + } + if (oneofFieldCase_ == OneofFieldOneofCase.OneofBool) { + output.WriteRawTag(152, 7); + output.WriteBool(OneofBool); + } + if (oneofFieldCase_ == OneofFieldOneofCase.OneofUint64) { + output.WriteRawTag(160, 7); + output.WriteUInt64(OneofUint64); + } + if (oneofFieldCase_ == OneofFieldOneofCase.OneofFloat) { + output.WriteRawTag(173, 7); + output.WriteFloat(OneofFloat); + } + if (oneofFieldCase_ == OneofFieldOneofCase.OneofDouble) { + output.WriteRawTag(177, 7); + output.WriteDouble(OneofDouble); + } + if (oneofFieldCase_ == OneofFieldOneofCase.OneofEnum) { + output.WriteRawTag(184, 7); + output.WriteEnum((int) OneofEnum); + } + if (optionalBoolWrapper_ != null) { + _single_optionalBoolWrapper_codec.WriteTagAndValue(ref output, OptionalBoolWrapper); + } + if (optionalInt32Wrapper_ != null) { + _single_optionalInt32Wrapper_codec.WriteTagAndValue(ref output, OptionalInt32Wrapper); + } + if (optionalInt64Wrapper_ != null) { + _single_optionalInt64Wrapper_codec.WriteTagAndValue(ref output, OptionalInt64Wrapper); + } + if (optionalUint32Wrapper_ != null) { + _single_optionalUint32Wrapper_codec.WriteTagAndValue(ref output, OptionalUint32Wrapper); + } + if (optionalUint64Wrapper_ != null) { + _single_optionalUint64Wrapper_codec.WriteTagAndValue(ref output, OptionalUint64Wrapper); + } + if (optionalFloatWrapper_ != null) { + _single_optionalFloatWrapper_codec.WriteTagAndValue(ref output, OptionalFloatWrapper); + } + if (optionalDoubleWrapper_ != null) { + _single_optionalDoubleWrapper_codec.WriteTagAndValue(ref output, OptionalDoubleWrapper); + } + if (optionalStringWrapper_ != null) { + _single_optionalStringWrapper_codec.WriteTagAndValue(ref output, OptionalStringWrapper); + } + if (optionalBytesWrapper_ != null) { + _single_optionalBytesWrapper_codec.WriteTagAndValue(ref output, OptionalBytesWrapper); + } + repeatedBoolWrapper_.WriteTo(ref output, _repeated_repeatedBoolWrapper_codec); + repeatedInt32Wrapper_.WriteTo(ref output, _repeated_repeatedInt32Wrapper_codec); + repeatedInt64Wrapper_.WriteTo(ref output, _repeated_repeatedInt64Wrapper_codec); + repeatedUint32Wrapper_.WriteTo(ref output, _repeated_repeatedUint32Wrapper_codec); + repeatedUint64Wrapper_.WriteTo(ref output, _repeated_repeatedUint64Wrapper_codec); + repeatedFloatWrapper_.WriteTo(ref output, _repeated_repeatedFloatWrapper_codec); + repeatedDoubleWrapper_.WriteTo(ref output, _repeated_repeatedDoubleWrapper_codec); + repeatedStringWrapper_.WriteTo(ref output, _repeated_repeatedStringWrapper_codec); + repeatedBytesWrapper_.WriteTo(ref output, _repeated_repeatedBytesWrapper_codec); + if (optionalDuration_ != null) { + output.WriteRawTag(234, 18); + output.WriteMessage(OptionalDuration); + } + if (optionalTimestamp_ != null) { + output.WriteRawTag(242, 18); + output.WriteMessage(OptionalTimestamp); + } + if (optionalFieldMask_ != null) { + output.WriteRawTag(250, 18); + output.WriteMessage(OptionalFieldMask); + } + if (optionalStruct_ != null) { + output.WriteRawTag(130, 19); + output.WriteMessage(OptionalStruct); + } + if (optionalAny_ != null) { + output.WriteRawTag(138, 19); + output.WriteMessage(OptionalAny); + } + if (optionalValue_ != null) { + output.WriteRawTag(146, 19); + output.WriteMessage(OptionalValue); + } + repeatedDuration_.WriteTo(ref output, _repeated_repeatedDuration_codec); + repeatedTimestamp_.WriteTo(ref output, _repeated_repeatedTimestamp_codec); + repeatedFieldmask_.WriteTo(ref output, _repeated_repeatedFieldmask_codec); + repeatedAny_.WriteTo(ref output, _repeated_repeatedAny_codec); + repeatedValue_.WriteTo(ref output, _repeated_repeatedValue_codec); + repeatedListValue_.WriteTo(ref output, _repeated_repeatedListValue_codec); + repeatedStruct_.WriteTo(ref output, _repeated_repeatedStruct_codec); + if (Fieldname1 != 0) { + output.WriteRawTag(136, 25); + output.WriteInt32(Fieldname1); + } + if (FieldName2 != 0) { + output.WriteRawTag(144, 25); + output.WriteInt32(FieldName2); + } + if (FieldName3 != 0) { + output.WriteRawTag(152, 25); + output.WriteInt32(FieldName3); + } + if (FieldName4 != 0) { + output.WriteRawTag(160, 25); + output.WriteInt32(FieldName4); + } + if (Field0Name5 != 0) { + output.WriteRawTag(168, 25); + output.WriteInt32(Field0Name5); + } + if (Field0Name6 != 0) { + output.WriteRawTag(176, 25); + output.WriteInt32(Field0Name6); + } + if (FieldName7 != 0) { + output.WriteRawTag(184, 25); + output.WriteInt32(FieldName7); + } + if (FieldName8 != 0) { + output.WriteRawTag(192, 25); + output.WriteInt32(FieldName8); + } + if (FieldName9 != 0) { + output.WriteRawTag(200, 25); + output.WriteInt32(FieldName9); + } + if (FieldName10 != 0) { + output.WriteRawTag(208, 25); + output.WriteInt32(FieldName10); + } + if (FIELDNAME11 != 0) { + output.WriteRawTag(216, 25); + output.WriteInt32(FIELDNAME11); + } + if (FIELDName12 != 0) { + output.WriteRawTag(224, 25); + output.WriteInt32(FIELDName12); + } + if (FieldName13 != 0) { + output.WriteRawTag(232, 25); + output.WriteInt32(FieldName13); + } + if (FieldName14 != 0) { + output.WriteRawTag(240, 25); + output.WriteInt32(FieldName14); + } + if (FieldName15 != 0) { + output.WriteRawTag(248, 25); + output.WriteInt32(FieldName15); + } + if (FieldName16 != 0) { + output.WriteRawTag(128, 26); + output.WriteInt32(FieldName16); + } + if (FieldName17 != 0) { + output.WriteRawTag(136, 26); + output.WriteInt32(FieldName17); + } + if (FieldName18 != 0) { + output.WriteRawTag(144, 26); + output.WriteInt32(FieldName18); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -4092,15 +4441,729 @@ public void MergeFrom(pb::CodedInputStream input) { } } - #region Nested types - /// Container for nested types declared in the TestAllTypesProto3 message type. + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public static partial class Types { - public enum NestedEnum { - [pbr::OriginalName("FOO")] Foo = 0, - [pbr::OriginalName("BAR")] Bar = 1, - [pbr::OriginalName("BAZ")] Baz = 2, - /// + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + OptionalInt32 = input.ReadInt32(); + break; + } + case 16: { + OptionalInt64 = input.ReadInt64(); + break; + } + case 24: { + OptionalUint32 = input.ReadUInt32(); + break; + } + case 32: { + OptionalUint64 = input.ReadUInt64(); + break; + } + case 40: { + OptionalSint32 = input.ReadSInt32(); + break; + } + case 48: { + OptionalSint64 = input.ReadSInt64(); + break; + } + case 61: { + OptionalFixed32 = input.ReadFixed32(); + break; + } + case 65: { + OptionalFixed64 = input.ReadFixed64(); + break; + } + case 77: { + OptionalSfixed32 = input.ReadSFixed32(); + break; + } + case 81: { + OptionalSfixed64 = input.ReadSFixed64(); + break; + } + case 93: { + OptionalFloat = input.ReadFloat(); + break; + } + case 97: { + OptionalDouble = input.ReadDouble(); + break; + } + case 104: { + OptionalBool = input.ReadBool(); + break; + } + case 114: { + OptionalString = input.ReadString(); + break; + } + case 122: { + OptionalBytes = input.ReadBytes(); + break; + } + case 146: { + if (optionalNestedMessage_ == null) { + OptionalNestedMessage = new global::ProtobufTestMessages.Proto3.TestAllTypesProto3.Types.NestedMessage(); + } + input.ReadMessage(OptionalNestedMessage); + break; + } + case 154: { + if (optionalForeignMessage_ == null) { + OptionalForeignMessage = new global::ProtobufTestMessages.Proto3.ForeignMessage(); + } + input.ReadMessage(OptionalForeignMessage); + break; + } + case 168: { + OptionalNestedEnum = (global::ProtobufTestMessages.Proto3.TestAllTypesProto3.Types.NestedEnum) input.ReadEnum(); + break; + } + case 176: { + OptionalForeignEnum = (global::ProtobufTestMessages.Proto3.ForeignEnum) input.ReadEnum(); + break; + } + case 184: { + OptionalAliasedEnum = (global::ProtobufTestMessages.Proto3.TestAllTypesProto3.Types.AliasedEnum) input.ReadEnum(); + break; + } + case 194: { + OptionalStringPiece = input.ReadString(); + break; + } + case 202: { + OptionalCord = input.ReadString(); + break; + } + case 218: { + if (recursiveMessage_ == null) { + RecursiveMessage = new global::ProtobufTestMessages.Proto3.TestAllTypesProto3(); + } + input.ReadMessage(RecursiveMessage); + break; + } + case 250: + case 248: { + repeatedInt32_.AddEntriesFrom(ref input, _repeated_repeatedInt32_codec); + break; + } + case 258: + case 256: { + repeatedInt64_.AddEntriesFrom(ref input, _repeated_repeatedInt64_codec); + break; + } + case 266: + case 264: { + repeatedUint32_.AddEntriesFrom(ref input, _repeated_repeatedUint32_codec); + break; + } + case 274: + case 272: { + repeatedUint64_.AddEntriesFrom(ref input, _repeated_repeatedUint64_codec); + break; + } + case 282: + case 280: { + repeatedSint32_.AddEntriesFrom(ref input, _repeated_repeatedSint32_codec); + break; + } + case 290: + case 288: { + repeatedSint64_.AddEntriesFrom(ref input, _repeated_repeatedSint64_codec); + break; + } + case 298: + case 301: { + repeatedFixed32_.AddEntriesFrom(ref input, _repeated_repeatedFixed32_codec); + break; + } + case 306: + case 305: { + repeatedFixed64_.AddEntriesFrom(ref input, _repeated_repeatedFixed64_codec); + break; + } + case 314: + case 317: { + repeatedSfixed32_.AddEntriesFrom(ref input, _repeated_repeatedSfixed32_codec); + break; + } + case 322: + case 321: { + repeatedSfixed64_.AddEntriesFrom(ref input, _repeated_repeatedSfixed64_codec); + break; + } + case 330: + case 333: { + repeatedFloat_.AddEntriesFrom(ref input, _repeated_repeatedFloat_codec); + break; + } + case 338: + case 337: { + repeatedDouble_.AddEntriesFrom(ref input, _repeated_repeatedDouble_codec); + break; + } + case 346: + case 344: { + repeatedBool_.AddEntriesFrom(ref input, _repeated_repeatedBool_codec); + break; + } + case 354: { + repeatedString_.AddEntriesFrom(ref input, _repeated_repeatedString_codec); + break; + } + case 362: { + repeatedBytes_.AddEntriesFrom(ref input, _repeated_repeatedBytes_codec); + break; + } + case 386: { + repeatedNestedMessage_.AddEntriesFrom(ref input, _repeated_repeatedNestedMessage_codec); + break; + } + case 394: { + repeatedForeignMessage_.AddEntriesFrom(ref input, _repeated_repeatedForeignMessage_codec); + break; + } + case 410: + case 408: { + repeatedNestedEnum_.AddEntriesFrom(ref input, _repeated_repeatedNestedEnum_codec); + break; + } + case 418: + case 416: { + repeatedForeignEnum_.AddEntriesFrom(ref input, _repeated_repeatedForeignEnum_codec); + break; + } + case 434: { + repeatedStringPiece_.AddEntriesFrom(ref input, _repeated_repeatedStringPiece_codec); + break; + } + case 442: { + repeatedCord_.AddEntriesFrom(ref input, _repeated_repeatedCord_codec); + break; + } + case 450: { + mapInt32Int32_.AddEntriesFrom(ref input, _map_mapInt32Int32_codec); + break; + } + case 458: { + mapInt64Int64_.AddEntriesFrom(ref input, _map_mapInt64Int64_codec); + break; + } + case 466: { + mapUint32Uint32_.AddEntriesFrom(ref input, _map_mapUint32Uint32_codec); + break; + } + case 474: { + mapUint64Uint64_.AddEntriesFrom(ref input, _map_mapUint64Uint64_codec); + break; + } + case 482: { + mapSint32Sint32_.AddEntriesFrom(ref input, _map_mapSint32Sint32_codec); + break; + } + case 490: { + mapSint64Sint64_.AddEntriesFrom(ref input, _map_mapSint64Sint64_codec); + break; + } + case 498: { + mapFixed32Fixed32_.AddEntriesFrom(ref input, _map_mapFixed32Fixed32_codec); + break; + } + case 506: { + mapFixed64Fixed64_.AddEntriesFrom(ref input, _map_mapFixed64Fixed64_codec); + break; + } + case 514: { + mapSfixed32Sfixed32_.AddEntriesFrom(ref input, _map_mapSfixed32Sfixed32_codec); + break; + } + case 522: { + mapSfixed64Sfixed64_.AddEntriesFrom(ref input, _map_mapSfixed64Sfixed64_codec); + break; + } + case 530: { + mapInt32Float_.AddEntriesFrom(ref input, _map_mapInt32Float_codec); + break; + } + case 538: { + mapInt32Double_.AddEntriesFrom(ref input, _map_mapInt32Double_codec); + break; + } + case 546: { + mapBoolBool_.AddEntriesFrom(ref input, _map_mapBoolBool_codec); + break; + } + case 554: { + mapStringString_.AddEntriesFrom(ref input, _map_mapStringString_codec); + break; + } + case 562: { + mapStringBytes_.AddEntriesFrom(ref input, _map_mapStringBytes_codec); + break; + } + case 570: { + mapStringNestedMessage_.AddEntriesFrom(ref input, _map_mapStringNestedMessage_codec); + break; + } + case 578: { + mapStringForeignMessage_.AddEntriesFrom(ref input, _map_mapStringForeignMessage_codec); + break; + } + case 586: { + mapStringNestedEnum_.AddEntriesFrom(ref input, _map_mapStringNestedEnum_codec); + break; + } + case 594: { + mapStringForeignEnum_.AddEntriesFrom(ref input, _map_mapStringForeignEnum_codec); + break; + } + case 602: + case 600: { + packedInt32_.AddEntriesFrom(ref input, _repeated_packedInt32_codec); + break; + } + case 610: + case 608: { + packedInt64_.AddEntriesFrom(ref input, _repeated_packedInt64_codec); + break; + } + case 618: + case 616: { + packedUint32_.AddEntriesFrom(ref input, _repeated_packedUint32_codec); + break; + } + case 626: + case 624: { + packedUint64_.AddEntriesFrom(ref input, _repeated_packedUint64_codec); + break; + } + case 634: + case 632: { + packedSint32_.AddEntriesFrom(ref input, _repeated_packedSint32_codec); + break; + } + case 642: + case 640: { + packedSint64_.AddEntriesFrom(ref input, _repeated_packedSint64_codec); + break; + } + case 650: + case 653: { + packedFixed32_.AddEntriesFrom(ref input, _repeated_packedFixed32_codec); + break; + } + case 658: + case 657: { + packedFixed64_.AddEntriesFrom(ref input, _repeated_packedFixed64_codec); + break; + } + case 666: + case 669: { + packedSfixed32_.AddEntriesFrom(ref input, _repeated_packedSfixed32_codec); + break; + } + case 674: + case 673: { + packedSfixed64_.AddEntriesFrom(ref input, _repeated_packedSfixed64_codec); + break; + } + case 682: + case 685: { + packedFloat_.AddEntriesFrom(ref input, _repeated_packedFloat_codec); + break; + } + case 690: + case 689: { + packedDouble_.AddEntriesFrom(ref input, _repeated_packedDouble_codec); + break; + } + case 698: + case 696: { + packedBool_.AddEntriesFrom(ref input, _repeated_packedBool_codec); + break; + } + case 706: + case 704: { + packedNestedEnum_.AddEntriesFrom(ref input, _repeated_packedNestedEnum_codec); + break; + } + case 714: + case 712: { + unpackedInt32_.AddEntriesFrom(ref input, _repeated_unpackedInt32_codec); + break; + } + case 722: + case 720: { + unpackedInt64_.AddEntriesFrom(ref input, _repeated_unpackedInt64_codec); + break; + } + case 730: + case 728: { + unpackedUint32_.AddEntriesFrom(ref input, _repeated_unpackedUint32_codec); + break; + } + case 738: + case 736: { + unpackedUint64_.AddEntriesFrom(ref input, _repeated_unpackedUint64_codec); + break; + } + case 746: + case 744: { + unpackedSint32_.AddEntriesFrom(ref input, _repeated_unpackedSint32_codec); + break; + } + case 754: + case 752: { + unpackedSint64_.AddEntriesFrom(ref input, _repeated_unpackedSint64_codec); + break; + } + case 762: + case 765: { + unpackedFixed32_.AddEntriesFrom(ref input, _repeated_unpackedFixed32_codec); + break; + } + case 770: + case 769: { + unpackedFixed64_.AddEntriesFrom(ref input, _repeated_unpackedFixed64_codec); + break; + } + case 778: + case 781: { + unpackedSfixed32_.AddEntriesFrom(ref input, _repeated_unpackedSfixed32_codec); + break; + } + case 786: + case 785: { + unpackedSfixed64_.AddEntriesFrom(ref input, _repeated_unpackedSfixed64_codec); + break; + } + case 794: + case 797: { + unpackedFloat_.AddEntriesFrom(ref input, _repeated_unpackedFloat_codec); + break; + } + case 802: + case 801: { + unpackedDouble_.AddEntriesFrom(ref input, _repeated_unpackedDouble_codec); + break; + } + case 810: + case 808: { + unpackedBool_.AddEntriesFrom(ref input, _repeated_unpackedBool_codec); + break; + } + case 818: + case 816: { + unpackedNestedEnum_.AddEntriesFrom(ref input, _repeated_unpackedNestedEnum_codec); + break; + } + case 888: { + OneofUint32 = input.ReadUInt32(); + break; + } + case 898: { + global::ProtobufTestMessages.Proto3.TestAllTypesProto3.Types.NestedMessage subBuilder = new global::ProtobufTestMessages.Proto3.TestAllTypesProto3.Types.NestedMessage(); + if (oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage) { + subBuilder.MergeFrom(OneofNestedMessage); + } + input.ReadMessage(subBuilder); + OneofNestedMessage = subBuilder; + break; + } + case 906: { + OneofString = input.ReadString(); + break; + } + case 914: { + OneofBytes = input.ReadBytes(); + break; + } + case 920: { + OneofBool = input.ReadBool(); + break; + } + case 928: { + OneofUint64 = input.ReadUInt64(); + break; + } + case 941: { + OneofFloat = input.ReadFloat(); + break; + } + case 945: { + OneofDouble = input.ReadDouble(); + break; + } + case 952: { + oneofField_ = input.ReadEnum(); + oneofFieldCase_ = OneofFieldOneofCase.OneofEnum; + break; + } + case 1610: { + bool? value = _single_optionalBoolWrapper_codec.Read(ref input); + if (optionalBoolWrapper_ == null || value != false) { + OptionalBoolWrapper = value; + } + break; + } + case 1618: { + int? value = _single_optionalInt32Wrapper_codec.Read(ref input); + if (optionalInt32Wrapper_ == null || value != 0) { + OptionalInt32Wrapper = value; + } + break; + } + case 1626: { + long? value = _single_optionalInt64Wrapper_codec.Read(ref input); + if (optionalInt64Wrapper_ == null || value != 0L) { + OptionalInt64Wrapper = value; + } + break; + } + case 1634: { + uint? value = _single_optionalUint32Wrapper_codec.Read(ref input); + if (optionalUint32Wrapper_ == null || value != 0) { + OptionalUint32Wrapper = value; + } + break; + } + case 1642: { + ulong? value = _single_optionalUint64Wrapper_codec.Read(ref input); + if (optionalUint64Wrapper_ == null || value != 0UL) { + OptionalUint64Wrapper = value; + } + break; + } + case 1650: { + float? value = _single_optionalFloatWrapper_codec.Read(ref input); + if (optionalFloatWrapper_ == null || value != 0F) { + OptionalFloatWrapper = value; + } + break; + } + case 1658: { + double? value = _single_optionalDoubleWrapper_codec.Read(ref input); + if (optionalDoubleWrapper_ == null || value != 0D) { + OptionalDoubleWrapper = value; + } + break; + } + case 1666: { + string value = _single_optionalStringWrapper_codec.Read(ref input); + if (optionalStringWrapper_ == null || value != "") { + OptionalStringWrapper = value; + } + break; + } + case 1674: { + pb::ByteString value = _single_optionalBytesWrapper_codec.Read(ref input); + if (optionalBytesWrapper_ == null || value != pb::ByteString.Empty) { + OptionalBytesWrapper = value; + } + break; + } + case 1690: { + repeatedBoolWrapper_.AddEntriesFrom(ref input, _repeated_repeatedBoolWrapper_codec); + break; + } + case 1698: { + repeatedInt32Wrapper_.AddEntriesFrom(ref input, _repeated_repeatedInt32Wrapper_codec); + break; + } + case 1706: { + repeatedInt64Wrapper_.AddEntriesFrom(ref input, _repeated_repeatedInt64Wrapper_codec); + break; + } + case 1714: { + repeatedUint32Wrapper_.AddEntriesFrom(ref input, _repeated_repeatedUint32Wrapper_codec); + break; + } + case 1722: { + repeatedUint64Wrapper_.AddEntriesFrom(ref input, _repeated_repeatedUint64Wrapper_codec); + break; + } + case 1730: { + repeatedFloatWrapper_.AddEntriesFrom(ref input, _repeated_repeatedFloatWrapper_codec); + break; + } + case 1738: { + repeatedDoubleWrapper_.AddEntriesFrom(ref input, _repeated_repeatedDoubleWrapper_codec); + break; + } + case 1746: { + repeatedStringWrapper_.AddEntriesFrom(ref input, _repeated_repeatedStringWrapper_codec); + break; + } + case 1754: { + repeatedBytesWrapper_.AddEntriesFrom(ref input, _repeated_repeatedBytesWrapper_codec); + break; + } + case 2410: { + if (optionalDuration_ == null) { + OptionalDuration = new global::Google.Protobuf.WellKnownTypes.Duration(); + } + input.ReadMessage(OptionalDuration); + break; + } + case 2418: { + if (optionalTimestamp_ == null) { + OptionalTimestamp = new global::Google.Protobuf.WellKnownTypes.Timestamp(); + } + input.ReadMessage(OptionalTimestamp); + break; + } + case 2426: { + if (optionalFieldMask_ == null) { + OptionalFieldMask = new global::Google.Protobuf.WellKnownTypes.FieldMask(); + } + input.ReadMessage(OptionalFieldMask); + break; + } + case 2434: { + if (optionalStruct_ == null) { + OptionalStruct = new global::Google.Protobuf.WellKnownTypes.Struct(); + } + input.ReadMessage(OptionalStruct); + break; + } + case 2442: { + if (optionalAny_ == null) { + OptionalAny = new global::Google.Protobuf.WellKnownTypes.Any(); + } + input.ReadMessage(OptionalAny); + break; + } + case 2450: { + if (optionalValue_ == null) { + OptionalValue = new global::Google.Protobuf.WellKnownTypes.Value(); + } + input.ReadMessage(OptionalValue); + break; + } + case 2490: { + repeatedDuration_.AddEntriesFrom(ref input, _repeated_repeatedDuration_codec); + break; + } + case 2498: { + repeatedTimestamp_.AddEntriesFrom(ref input, _repeated_repeatedTimestamp_codec); + break; + } + case 2506: { + repeatedFieldmask_.AddEntriesFrom(ref input, _repeated_repeatedFieldmask_codec); + break; + } + case 2522: { + repeatedAny_.AddEntriesFrom(ref input, _repeated_repeatedAny_codec); + break; + } + case 2530: { + repeatedValue_.AddEntriesFrom(ref input, _repeated_repeatedValue_codec); + break; + } + case 2538: { + repeatedListValue_.AddEntriesFrom(ref input, _repeated_repeatedListValue_codec); + break; + } + case 2594: { + repeatedStruct_.AddEntriesFrom(ref input, _repeated_repeatedStruct_codec); + break; + } + case 3208: { + Fieldname1 = input.ReadInt32(); + break; + } + case 3216: { + FieldName2 = input.ReadInt32(); + break; + } + case 3224: { + FieldName3 = input.ReadInt32(); + break; + } + case 3232: { + FieldName4 = input.ReadInt32(); + break; + } + case 3240: { + Field0Name5 = input.ReadInt32(); + break; + } + case 3248: { + Field0Name6 = input.ReadInt32(); + break; + } + case 3256: { + FieldName7 = input.ReadInt32(); + break; + } + case 3264: { + FieldName8 = input.ReadInt32(); + break; + } + case 3272: { + FieldName9 = input.ReadInt32(); + break; + } + case 3280: { + FieldName10 = input.ReadInt32(); + break; + } + case 3288: { + FIELDNAME11 = input.ReadInt32(); + break; + } + case 3296: { + FIELDName12 = input.ReadInt32(); + break; + } + case 3304: { + FieldName13 = input.ReadInt32(); + break; + } + case 3312: { + FieldName14 = input.ReadInt32(); + break; + } + case 3320: { + FieldName15 = input.ReadInt32(); + break; + } + case 3328: { + FieldName16 = input.ReadInt32(); + break; + } + case 3336: { + FieldName17 = input.ReadInt32(); + break; + } + case 3344: { + FieldName18 = input.ReadInt32(); + break; + } + } + } + } + #endif + + #region Nested types + /// Container for nested types declared in the TestAllTypesProto3 message type. + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static partial class Types { + public enum NestedEnum { + [pbr::OriginalName("FOO")] Foo = 0, + [pbr::OriginalName("BAR")] Bar = 1, + [pbr::OriginalName("BAZ")] Baz = 2, + /// /// Intentionally negative. /// [pbr::OriginalName("NEG")] Neg = -1, @@ -4115,7 +5178,11 @@ public enum AliasedEnum { [pbr::OriginalName("bAz", PreferredAlias = false)] BAz = 2, } - public sealed partial class NestedMessage : pb::IMessage { + public sealed partial class NestedMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new NestedMessage()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -4221,6 +5288,24 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (A != 0) { + output.WriteRawTag(8); + output.WriteInt32(A); + } + if (corecursive_ != null) { + output.WriteRawTag(18); + output.WriteMessage(Corecursive); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -4276,6 +5361,32 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + A = input.ReadInt32(); + break; + } + case 18: { + if (corecursive_ == null) { + Corecursive = new global::ProtobufTestMessages.Proto3.TestAllTypesProto3(); + } + input.ReadMessage(Corecursive); + break; + } + } + } + } + #endif + } } @@ -4283,7 +5394,11 @@ public void MergeFrom(pb::CodedInputStream input) { } - public sealed partial class ForeignMessage : pb::IMessage { + public sealed partial class ForeignMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ForeignMessage()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -4371,6 +5486,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (C != 0) { + output.WriteRawTag(8); + output.WriteInt32(C); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -4410,6 +5539,25 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + C = input.ReadInt32(); + break; + } + } + } + } + #endif + } #endregion diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/Unittest.cs b/csharp/src/Google.Protobuf.Test.TestProtos/Unittest.cs index e55df12f2ec8..0cccc1c976ad 100644 --- a/csharp/src/Google.Protobuf.Test.TestProtos/Unittest.cs +++ b/csharp/src/Google.Protobuf.Test.TestProtos/Unittest.cs @@ -1120,7 +1120,11 @@ public enum VeryLargeEnum { /// This proto includes every type of field in both singular and repeated /// forms. /// - public sealed partial class TestAllTypes : pb::IMessage { + public sealed partial class TestAllTypes : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestAllTypes()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -3111,6 +3115,242 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasOptionalInt32) { + output.WriteRawTag(8); + output.WriteInt32(OptionalInt32); + } + if (HasOptionalInt64) { + output.WriteRawTag(16); + output.WriteInt64(OptionalInt64); + } + if (HasOptionalUint32) { + output.WriteRawTag(24); + output.WriteUInt32(OptionalUint32); + } + if (HasOptionalUint64) { + output.WriteRawTag(32); + output.WriteUInt64(OptionalUint64); + } + if (HasOptionalSint32) { + output.WriteRawTag(40); + output.WriteSInt32(OptionalSint32); + } + if (HasOptionalSint64) { + output.WriteRawTag(48); + output.WriteSInt64(OptionalSint64); + } + if (HasOptionalFixed32) { + output.WriteRawTag(61); + output.WriteFixed32(OptionalFixed32); + } + if (HasOptionalFixed64) { + output.WriteRawTag(65); + output.WriteFixed64(OptionalFixed64); + } + if (HasOptionalSfixed32) { + output.WriteRawTag(77); + output.WriteSFixed32(OptionalSfixed32); + } + if (HasOptionalSfixed64) { + output.WriteRawTag(81); + output.WriteSFixed64(OptionalSfixed64); + } + if (HasOptionalFloat) { + output.WriteRawTag(93); + output.WriteFloat(OptionalFloat); + } + if (HasOptionalDouble) { + output.WriteRawTag(97); + output.WriteDouble(OptionalDouble); + } + if (HasOptionalBool) { + output.WriteRawTag(104); + output.WriteBool(OptionalBool); + } + if (HasOptionalString) { + output.WriteRawTag(114); + output.WriteString(OptionalString); + } + if (HasOptionalBytes) { + output.WriteRawTag(122); + output.WriteBytes(OptionalBytes); + } + if (HasOptionalGroup) { + output.WriteRawTag(131, 1); + output.WriteGroup(OptionalGroup); + output.WriteRawTag(132, 1); + } + if (HasOptionalNestedMessage) { + output.WriteRawTag(146, 1); + output.WriteMessage(OptionalNestedMessage); + } + if (HasOptionalForeignMessage) { + output.WriteRawTag(154, 1); + output.WriteMessage(OptionalForeignMessage); + } + if (HasOptionalImportMessage) { + output.WriteRawTag(162, 1); + output.WriteMessage(OptionalImportMessage); + } + if (HasOptionalNestedEnum) { + output.WriteRawTag(168, 1); + output.WriteEnum((int) OptionalNestedEnum); + } + if (HasOptionalForeignEnum) { + output.WriteRawTag(176, 1); + output.WriteEnum((int) OptionalForeignEnum); + } + if (HasOptionalImportEnum) { + output.WriteRawTag(184, 1); + output.WriteEnum((int) OptionalImportEnum); + } + if (HasOptionalStringPiece) { + output.WriteRawTag(194, 1); + output.WriteString(OptionalStringPiece); + } + if (HasOptionalCord) { + output.WriteRawTag(202, 1); + output.WriteString(OptionalCord); + } + if (HasOptionalPublicImportMessage) { + output.WriteRawTag(210, 1); + output.WriteMessage(OptionalPublicImportMessage); + } + if (HasOptionalLazyMessage) { + output.WriteRawTag(218, 1); + output.WriteMessage(OptionalLazyMessage); + } + repeatedInt32_.WriteTo(ref output, _repeated_repeatedInt32_codec); + repeatedInt64_.WriteTo(ref output, _repeated_repeatedInt64_codec); + repeatedUint32_.WriteTo(ref output, _repeated_repeatedUint32_codec); + repeatedUint64_.WriteTo(ref output, _repeated_repeatedUint64_codec); + repeatedSint32_.WriteTo(ref output, _repeated_repeatedSint32_codec); + repeatedSint64_.WriteTo(ref output, _repeated_repeatedSint64_codec); + repeatedFixed32_.WriteTo(ref output, _repeated_repeatedFixed32_codec); + repeatedFixed64_.WriteTo(ref output, _repeated_repeatedFixed64_codec); + repeatedSfixed32_.WriteTo(ref output, _repeated_repeatedSfixed32_codec); + repeatedSfixed64_.WriteTo(ref output, _repeated_repeatedSfixed64_codec); + repeatedFloat_.WriteTo(ref output, _repeated_repeatedFloat_codec); + repeatedDouble_.WriteTo(ref output, _repeated_repeatedDouble_codec); + repeatedBool_.WriteTo(ref output, _repeated_repeatedBool_codec); + repeatedString_.WriteTo(ref output, _repeated_repeatedString_codec); + repeatedBytes_.WriteTo(ref output, _repeated_repeatedBytes_codec); + repeatedGroup_.WriteTo(ref output, _repeated_repeatedGroup_codec); + repeatedNestedMessage_.WriteTo(ref output, _repeated_repeatedNestedMessage_codec); + repeatedForeignMessage_.WriteTo(ref output, _repeated_repeatedForeignMessage_codec); + repeatedImportMessage_.WriteTo(ref output, _repeated_repeatedImportMessage_codec); + repeatedNestedEnum_.WriteTo(ref output, _repeated_repeatedNestedEnum_codec); + repeatedForeignEnum_.WriteTo(ref output, _repeated_repeatedForeignEnum_codec); + repeatedImportEnum_.WriteTo(ref output, _repeated_repeatedImportEnum_codec); + repeatedStringPiece_.WriteTo(ref output, _repeated_repeatedStringPiece_codec); + repeatedCord_.WriteTo(ref output, _repeated_repeatedCord_codec); + repeatedLazyMessage_.WriteTo(ref output, _repeated_repeatedLazyMessage_codec); + if (HasDefaultInt32) { + output.WriteRawTag(232, 3); + output.WriteInt32(DefaultInt32); + } + if (HasDefaultInt64) { + output.WriteRawTag(240, 3); + output.WriteInt64(DefaultInt64); + } + if (HasDefaultUint32) { + output.WriteRawTag(248, 3); + output.WriteUInt32(DefaultUint32); + } + if (HasDefaultUint64) { + output.WriteRawTag(128, 4); + output.WriteUInt64(DefaultUint64); + } + if (HasDefaultSint32) { + output.WriteRawTag(136, 4); + output.WriteSInt32(DefaultSint32); + } + if (HasDefaultSint64) { + output.WriteRawTag(144, 4); + output.WriteSInt64(DefaultSint64); + } + if (HasDefaultFixed32) { + output.WriteRawTag(157, 4); + output.WriteFixed32(DefaultFixed32); + } + if (HasDefaultFixed64) { + output.WriteRawTag(161, 4); + output.WriteFixed64(DefaultFixed64); + } + if (HasDefaultSfixed32) { + output.WriteRawTag(173, 4); + output.WriteSFixed32(DefaultSfixed32); + } + if (HasDefaultSfixed64) { + output.WriteRawTag(177, 4); + output.WriteSFixed64(DefaultSfixed64); + } + if (HasDefaultFloat) { + output.WriteRawTag(189, 4); + output.WriteFloat(DefaultFloat); + } + if (HasDefaultDouble) { + output.WriteRawTag(193, 4); + output.WriteDouble(DefaultDouble); + } + if (HasDefaultBool) { + output.WriteRawTag(200, 4); + output.WriteBool(DefaultBool); + } + if (HasDefaultString) { + output.WriteRawTag(210, 4); + output.WriteString(DefaultString); + } + if (HasDefaultBytes) { + output.WriteRawTag(218, 4); + output.WriteBytes(DefaultBytes); + } + if (HasDefaultNestedEnum) { + output.WriteRawTag(136, 5); + output.WriteEnum((int) DefaultNestedEnum); + } + if (HasDefaultForeignEnum) { + output.WriteRawTag(144, 5); + output.WriteEnum((int) DefaultForeignEnum); + } + if (HasDefaultImportEnum) { + output.WriteRawTag(152, 5); + output.WriteEnum((int) DefaultImportEnum); + } + if (HasDefaultStringPiece) { + output.WriteRawTag(162, 5); + output.WriteString(DefaultStringPiece); + } + if (HasDefaultCord) { + output.WriteRawTag(170, 5); + output.WriteString(DefaultCord); + } + if (HasOneofUint32) { + output.WriteRawTag(248, 6); + output.WriteUInt32(OneofUint32); + } + if (HasOneofNestedMessage) { + output.WriteRawTag(130, 7); + output.WriteMessage(OneofNestedMessage); + } + if (HasOneofString) { + output.WriteRawTag(138, 7); + output.WriteString(OneofString); + } + if (HasOneofBytes) { + output.WriteRawTag(146, 7); + output.WriteBytes(OneofBytes); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -3853,57 +4093,415 @@ public void MergeFrom(pb::CodedInputStream input) { } } - #region Nested types - /// Container for nested types declared in the TestAllTypes message type. - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public static partial class Types { - public enum NestedEnum { - [pbr::OriginalName("FOO")] Foo = 1, - [pbr::OriginalName("BAR")] Bar = 2, - [pbr::OriginalName("BAZ")] Baz = 3, - /// - /// Intentionally negative. - /// - [pbr::OriginalName("NEG")] Neg = -1, - } - - public sealed partial class NestedMessage : pb::IMessage { - private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new NestedMessage()); - private pb::UnknownFieldSet _unknownFields; - private int _hasBits0; - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public static pb::MessageParser Parser { get { return _parser; } } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public static pbr::MessageDescriptor Descriptor { - get { return global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Descriptor.NestedTypes[0]; } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - pbr::MessageDescriptor pb::IMessage.Descriptor { - get { return Descriptor; } - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public NestedMessage() { - OnConstruction(); - } - - partial void OnConstruction(); - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public NestedMessage(NestedMessage other) : this() { - _hasBits0 = other._hasBits0; - bb_ = other.bb_; - _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); - } - - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public NestedMessage Clone() { - return new NestedMessage(this); - } - /// Field number for the "bb" field. + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + OptionalInt32 = input.ReadInt32(); + break; + } + case 16: { + OptionalInt64 = input.ReadInt64(); + break; + } + case 24: { + OptionalUint32 = input.ReadUInt32(); + break; + } + case 32: { + OptionalUint64 = input.ReadUInt64(); + break; + } + case 40: { + OptionalSint32 = input.ReadSInt32(); + break; + } + case 48: { + OptionalSint64 = input.ReadSInt64(); + break; + } + case 61: { + OptionalFixed32 = input.ReadFixed32(); + break; + } + case 65: { + OptionalFixed64 = input.ReadFixed64(); + break; + } + case 77: { + OptionalSfixed32 = input.ReadSFixed32(); + break; + } + case 81: { + OptionalSfixed64 = input.ReadSFixed64(); + break; + } + case 93: { + OptionalFloat = input.ReadFloat(); + break; + } + case 97: { + OptionalDouble = input.ReadDouble(); + break; + } + case 104: { + OptionalBool = input.ReadBool(); + break; + } + case 114: { + OptionalString = input.ReadString(); + break; + } + case 122: { + OptionalBytes = input.ReadBytes(); + break; + } + case 131: { + if (!HasOptionalGroup) { + OptionalGroup = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.OptionalGroup(); + } + input.ReadGroup(OptionalGroup); + break; + } + case 146: { + if (!HasOptionalNestedMessage) { + OptionalNestedMessage = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage(); + } + input.ReadMessage(OptionalNestedMessage); + break; + } + case 154: { + if (!HasOptionalForeignMessage) { + OptionalForeignMessage = new global::Google.Protobuf.TestProtos.Proto2.ForeignMessage(); + } + input.ReadMessage(OptionalForeignMessage); + break; + } + case 162: { + if (!HasOptionalImportMessage) { + OptionalImportMessage = new global::Google.Protobuf.TestProtos.Proto2.ImportMessage(); + } + input.ReadMessage(OptionalImportMessage); + break; + } + case 168: { + OptionalNestedEnum = (global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedEnum) input.ReadEnum(); + break; + } + case 176: { + OptionalForeignEnum = (global::Google.Protobuf.TestProtos.Proto2.ForeignEnum) input.ReadEnum(); + break; + } + case 184: { + OptionalImportEnum = (global::Google.Protobuf.TestProtos.Proto2.ImportEnum) input.ReadEnum(); + break; + } + case 194: { + OptionalStringPiece = input.ReadString(); + break; + } + case 202: { + OptionalCord = input.ReadString(); + break; + } + case 210: { + if (!HasOptionalPublicImportMessage) { + OptionalPublicImportMessage = new global::Google.Protobuf.TestProtos.Proto2.PublicImportMessage(); + } + input.ReadMessage(OptionalPublicImportMessage); + break; + } + case 218: { + if (!HasOptionalLazyMessage) { + OptionalLazyMessage = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage(); + } + input.ReadMessage(OptionalLazyMessage); + break; + } + case 250: + case 248: { + repeatedInt32_.AddEntriesFrom(ref input, _repeated_repeatedInt32_codec); + break; + } + case 258: + case 256: { + repeatedInt64_.AddEntriesFrom(ref input, _repeated_repeatedInt64_codec); + break; + } + case 266: + case 264: { + repeatedUint32_.AddEntriesFrom(ref input, _repeated_repeatedUint32_codec); + break; + } + case 274: + case 272: { + repeatedUint64_.AddEntriesFrom(ref input, _repeated_repeatedUint64_codec); + break; + } + case 282: + case 280: { + repeatedSint32_.AddEntriesFrom(ref input, _repeated_repeatedSint32_codec); + break; + } + case 290: + case 288: { + repeatedSint64_.AddEntriesFrom(ref input, _repeated_repeatedSint64_codec); + break; + } + case 298: + case 301: { + repeatedFixed32_.AddEntriesFrom(ref input, _repeated_repeatedFixed32_codec); + break; + } + case 306: + case 305: { + repeatedFixed64_.AddEntriesFrom(ref input, _repeated_repeatedFixed64_codec); + break; + } + case 314: + case 317: { + repeatedSfixed32_.AddEntriesFrom(ref input, _repeated_repeatedSfixed32_codec); + break; + } + case 322: + case 321: { + repeatedSfixed64_.AddEntriesFrom(ref input, _repeated_repeatedSfixed64_codec); + break; + } + case 330: + case 333: { + repeatedFloat_.AddEntriesFrom(ref input, _repeated_repeatedFloat_codec); + break; + } + case 338: + case 337: { + repeatedDouble_.AddEntriesFrom(ref input, _repeated_repeatedDouble_codec); + break; + } + case 346: + case 344: { + repeatedBool_.AddEntriesFrom(ref input, _repeated_repeatedBool_codec); + break; + } + case 354: { + repeatedString_.AddEntriesFrom(ref input, _repeated_repeatedString_codec); + break; + } + case 362: { + repeatedBytes_.AddEntriesFrom(ref input, _repeated_repeatedBytes_codec); + break; + } + case 371: { + repeatedGroup_.AddEntriesFrom(ref input, _repeated_repeatedGroup_codec); + break; + } + case 386: { + repeatedNestedMessage_.AddEntriesFrom(ref input, _repeated_repeatedNestedMessage_codec); + break; + } + case 394: { + repeatedForeignMessage_.AddEntriesFrom(ref input, _repeated_repeatedForeignMessage_codec); + break; + } + case 402: { + repeatedImportMessage_.AddEntriesFrom(ref input, _repeated_repeatedImportMessage_codec); + break; + } + case 410: + case 408: { + repeatedNestedEnum_.AddEntriesFrom(ref input, _repeated_repeatedNestedEnum_codec); + break; + } + case 418: + case 416: { + repeatedForeignEnum_.AddEntriesFrom(ref input, _repeated_repeatedForeignEnum_codec); + break; + } + case 426: + case 424: { + repeatedImportEnum_.AddEntriesFrom(ref input, _repeated_repeatedImportEnum_codec); + break; + } + case 434: { + repeatedStringPiece_.AddEntriesFrom(ref input, _repeated_repeatedStringPiece_codec); + break; + } + case 442: { + repeatedCord_.AddEntriesFrom(ref input, _repeated_repeatedCord_codec); + break; + } + case 458: { + repeatedLazyMessage_.AddEntriesFrom(ref input, _repeated_repeatedLazyMessage_codec); + break; + } + case 488: { + DefaultInt32 = input.ReadInt32(); + break; + } + case 496: { + DefaultInt64 = input.ReadInt64(); + break; + } + case 504: { + DefaultUint32 = input.ReadUInt32(); + break; + } + case 512: { + DefaultUint64 = input.ReadUInt64(); + break; + } + case 520: { + DefaultSint32 = input.ReadSInt32(); + break; + } + case 528: { + DefaultSint64 = input.ReadSInt64(); + break; + } + case 541: { + DefaultFixed32 = input.ReadFixed32(); + break; + } + case 545: { + DefaultFixed64 = input.ReadFixed64(); + break; + } + case 557: { + DefaultSfixed32 = input.ReadSFixed32(); + break; + } + case 561: { + DefaultSfixed64 = input.ReadSFixed64(); + break; + } + case 573: { + DefaultFloat = input.ReadFloat(); + break; + } + case 577: { + DefaultDouble = input.ReadDouble(); + break; + } + case 584: { + DefaultBool = input.ReadBool(); + break; + } + case 594: { + DefaultString = input.ReadString(); + break; + } + case 602: { + DefaultBytes = input.ReadBytes(); + break; + } + case 648: { + DefaultNestedEnum = (global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedEnum) input.ReadEnum(); + break; + } + case 656: { + DefaultForeignEnum = (global::Google.Protobuf.TestProtos.Proto2.ForeignEnum) input.ReadEnum(); + break; + } + case 664: { + DefaultImportEnum = (global::Google.Protobuf.TestProtos.Proto2.ImportEnum) input.ReadEnum(); + break; + } + case 674: { + DefaultStringPiece = input.ReadString(); + break; + } + case 682: { + DefaultCord = input.ReadString(); + break; + } + case 888: { + OneofUint32 = input.ReadUInt32(); + break; + } + case 898: { + global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage subBuilder = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage(); + if (HasOneofNestedMessage) { + subBuilder.MergeFrom(OneofNestedMessage); + } + input.ReadMessage(subBuilder); + OneofNestedMessage = subBuilder; + break; + } + case 906: { + OneofString = input.ReadString(); + break; + } + case 914: { + OneofBytes = input.ReadBytes(); + break; + } + } + } + } + #endif + + #region Nested types + /// Container for nested types declared in the TestAllTypes message type. + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static partial class Types { + public enum NestedEnum { + [pbr::OriginalName("FOO")] Foo = 1, + [pbr::OriginalName("BAR")] Bar = 2, + [pbr::OriginalName("BAZ")] Baz = 3, + /// + /// Intentionally negative. + /// + [pbr::OriginalName("NEG")] Neg = -1, + } + + public sealed partial class NestedMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new NestedMessage()); + private pb::UnknownFieldSet _unknownFields; + private int _hasBits0; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Descriptor.NestedTypes[0]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public NestedMessage() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public NestedMessage(NestedMessage other) : this() { + _hasBits0 = other._hasBits0; + bb_ = other.bb_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public NestedMessage Clone() { + return new NestedMessage(this); + } + + /// Field number for the "bb" field. public const int BbFieldNumber = 1; private readonly static int BbDefaultValue = 0; @@ -3975,6 +4573,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasBb) { + output.WriteRawTag(8); + output.WriteInt32(Bb); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -4014,9 +4626,32 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Bb = input.ReadInt32(); + break; + } + } + } + } + #endif + } - public sealed partial class OptionalGroup : pb::IMessage { + public sealed partial class OptionalGroup : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new OptionalGroup()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -4119,6 +4754,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasA) { + output.WriteRawTag(136, 1); + output.WriteInt32(A); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -4160,9 +4809,34 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + case 132: + return; + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 136: { + A = input.ReadInt32(); + break; + } + } + } + } + #endif + } - public sealed partial class RepeatedGroup : pb::IMessage { + public sealed partial class RepeatedGroup : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new RepeatedGroup()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -4265,6 +4939,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasA) { + output.WriteRawTag(248, 2); + output.WriteInt32(A); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -4306,6 +4994,27 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + case 372: + return; + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 376: { + A = input.ReadInt32(); + break; + } + } + } + } + #endif + } } @@ -4316,7 +5025,11 @@ public void MergeFrom(pb::CodedInputStream input) { /// /// This proto includes a recusively nested message. /// - public sealed partial class NestedTestAllTypes : pb::IMessage { + public sealed partial class NestedTestAllTypes : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new NestedTestAllTypes()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -4456,6 +5169,25 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasChild) { + output.WriteRawTag(10); + output.WriteMessage(Child); + } + if (HasPayload) { + output.WriteRawTag(18); + output.WriteMessage(Payload); + } + repeatedChild_.WriteTo(ref output, _repeated_repeatedChild_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -4523,9 +5255,46 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + if (!HasChild) { + Child = new global::Google.Protobuf.TestProtos.Proto2.NestedTestAllTypes(); + } + input.ReadMessage(Child); + break; + } + case 18: { + if (!HasPayload) { + Payload = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes(); + } + input.ReadMessage(Payload); + break; + } + case 26: { + repeatedChild_.AddEntriesFrom(ref input, _repeated_repeatedChild_codec); + break; + } + } + } + } + #endif + } - public sealed partial class TestDeprecatedFields : pb::IMessage { + public sealed partial class TestDeprecatedFields : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestDeprecatedFields()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -4689,6 +5458,24 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasDeprecatedInt32) { + output.WriteRawTag(8); + output.WriteInt32(DeprecatedInt32); + } + if (HasDeprecatedInt32InOneof) { + output.WriteRawTag(16); + output.WriteInt32(DeprecatedInt32InOneof); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -4741,10 +5528,37 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + DeprecatedInt32 = input.ReadInt32(); + break; + } + case 16: { + DeprecatedInt32InOneof = input.ReadInt32(); + break; + } + } + } + } + #endif + } [global::System.ObsoleteAttribute] - public sealed partial class TestDeprecatedMessage : pb::IMessage { + public sealed partial class TestDeprecatedMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestDeprecatedMessage()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -4814,6 +5628,16 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -4843,13 +5667,32 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + } /// /// Define these after TestAllTypes to make sure the compiler can handle /// that. /// - public sealed partial class ForeignMessage : pb::IMessage { + public sealed partial class ForeignMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ForeignMessage()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -4983,6 +5826,24 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasC) { + output.WriteRawTag(8); + output.WriteInt32(C); + } + if (HasD) { + output.WriteRawTag(16); + output.WriteInt32(D); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -5032,9 +5893,36 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + C = input.ReadInt32(); + break; + } + case 16: { + D = input.ReadInt32(); + break; + } + } + } + } + #endif + } - public sealed partial class TestReservedFields : pb::IMessage { + public sealed partial class TestReservedFields : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestReservedFields()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -5104,6 +5992,16 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -5133,9 +6031,28 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + } - public sealed partial class TestAllExtensions : pb::IExtendableMessage { + public sealed partial class TestAllExtensions : pb::IExtendableMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestAllExtensions()); private pb::UnknownFieldSet _unknownFields; private pb::ExtensionSet _extensions; @@ -5217,6 +6134,19 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_extensions != null) { + _extensions.WriteTo(ref output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -5252,6 +6182,23 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + } + break; + } + } + } + #endif + public TValue GetExtension(pb::Extension extension) { return pb::ExtensionSet.Get(ref _extensions, extension); } @@ -5276,7 +6223,11 @@ public void ClearExtension(pb::RepeatedExtension { + public sealed partial class OptionalGroup_extension : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new OptionalGroup_extension()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -5369,15 +6320,29 @@ public override string ToString() { } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void WriteTo(pb::CodedOutputStream output) { + public void WriteTo(pb::CodedOutputStream output) { + if (HasA) { + output.WriteRawTag(136, 1); + output.WriteInt32(A); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + } + + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { if (HasA) { output.WriteRawTag(136, 1); output.WriteInt32(A); } if (_unknownFields != null) { - _unknownFields.WriteTo(output); + _unknownFields.WriteTo(ref output); } } + #endif [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { @@ -5420,9 +6385,34 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + case 132: + return; + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 136: { + A = input.ReadInt32(); + break; + } + } + } + } + #endif + } - public sealed partial class RepeatedGroup_extension : pb::IMessage { + public sealed partial class RepeatedGroup_extension : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new RepeatedGroup_extension()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -5525,6 +6515,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasA) { + output.WriteRawTag(248, 2); + output.WriteInt32(A); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -5566,9 +6570,34 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + case 372: + return; + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 376: { + A = input.ReadInt32(); + break; + } + } + } + } + #endif + } - public sealed partial class TestGroup : pb::IMessage { + public sealed partial class TestGroup : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestGroup()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -5700,6 +6729,25 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasOptionalGroup) { + output.WriteRawTag(131, 1); + output.WriteGroup(OptionalGroup); + output.WriteRawTag(132, 1); + } + if (HasOptionalForeignEnum) { + output.WriteRawTag(176, 1); + output.WriteEnum((int) OptionalForeignEnum); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -5755,11 +6803,41 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 131: { + if (!HasOptionalGroup) { + OptionalGroup = new global::Google.Protobuf.TestProtos.Proto2.TestGroup.Types.OptionalGroup(); + } + input.ReadGroup(OptionalGroup); + break; + } + case 176: { + OptionalForeignEnum = (global::Google.Protobuf.TestProtos.Proto2.ForeignEnum) input.ReadEnum(); + break; + } + } + } + } + #endif + #region Nested types /// Container for nested types declared in the TestGroup message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static partial class Types { - public sealed partial class OptionalGroup : pb::IMessage { + public sealed partial class OptionalGroup : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new OptionalGroup()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -5862,6 +6940,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasA) { + output.WriteRawTag(136, 1); + output.WriteInt32(A); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -5903,6 +6995,27 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + case 132: + return; + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 136: { + A = input.ReadInt32(); + break; + } + } + } + } + #endif + } } @@ -5910,7 +7023,11 @@ public void MergeFrom(pb::CodedInputStream input) { } - public sealed partial class TestGroupExtension : pb::IExtendableMessage { + public sealed partial class TestGroupExtension : pb::IExtendableMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestGroupExtension()); private pb::UnknownFieldSet _unknownFields; private pb::ExtensionSet _extensions; @@ -5992,6 +7109,19 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_extensions != null) { + _extensions.WriteTo(ref output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -6027,6 +7157,23 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + } + break; + } + } + } + #endif + public TValue GetExtension(pb::Extension extension) { return pb::ExtensionSet.Get(ref _extensions, extension); } @@ -6051,7 +7198,11 @@ public void ClearExtension(pb::RepeatedExtension { + public sealed partial class TestNestedExtension : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestNestedExtension()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -6121,6 +7272,16 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -6150,11 +7311,30 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + #region Nested types /// Container for nested types declared in the TestNestedExtension message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static partial class Types { - public sealed partial class OptionalGroup_extension : pb::IMessage { + public sealed partial class OptionalGroup_extension : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new OptionalGroup_extension()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -6257,6 +7437,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasA) { + output.WriteRawTag(136, 1); + output.WriteInt32(A); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -6298,6 +7492,27 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + case 132: + return; + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 136: { + A = input.ReadInt32(); + break; + } + } + } + } + #endif + } } @@ -6335,7 +7550,11 @@ public static partial class Extensions { /// required filed because the code output is basically identical to /// optional fields for all types. /// - public sealed partial class TestRequired : pb::IMessage { + public sealed partial class TestRequired : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestRequired()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -7287,18 +8506,159 @@ public override int GetHashCode() { if (HasDummy32) hash ^= Dummy32.GetHashCode(); if (HasC) hash ^= C.GetHashCode(); if (_unknownFields != null) { - hash ^= _unknownFields.GetHashCode(); + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + if (HasA) { + output.WriteRawTag(8); + output.WriteInt32(A); + } + if (HasDummy2) { + output.WriteRawTag(16); + output.WriteInt32(Dummy2); + } + if (HasB) { + output.WriteRawTag(24); + output.WriteInt32(B); + } + if (HasDummy4) { + output.WriteRawTag(32); + output.WriteInt32(Dummy4); + } + if (HasDummy5) { + output.WriteRawTag(40); + output.WriteInt32(Dummy5); + } + if (HasDummy6) { + output.WriteRawTag(48); + output.WriteInt32(Dummy6); + } + if (HasDummy7) { + output.WriteRawTag(56); + output.WriteInt32(Dummy7); + } + if (HasDummy8) { + output.WriteRawTag(64); + output.WriteInt32(Dummy8); + } + if (HasDummy9) { + output.WriteRawTag(72); + output.WriteInt32(Dummy9); + } + if (HasDummy10) { + output.WriteRawTag(80); + output.WriteInt32(Dummy10); + } + if (HasDummy11) { + output.WriteRawTag(88); + output.WriteInt32(Dummy11); + } + if (HasDummy12) { + output.WriteRawTag(96); + output.WriteInt32(Dummy12); + } + if (HasDummy13) { + output.WriteRawTag(104); + output.WriteInt32(Dummy13); + } + if (HasDummy14) { + output.WriteRawTag(112); + output.WriteInt32(Dummy14); + } + if (HasDummy15) { + output.WriteRawTag(120); + output.WriteInt32(Dummy15); + } + if (HasDummy16) { + output.WriteRawTag(128, 1); + output.WriteInt32(Dummy16); + } + if (HasDummy17) { + output.WriteRawTag(136, 1); + output.WriteInt32(Dummy17); + } + if (HasDummy18) { + output.WriteRawTag(144, 1); + output.WriteInt32(Dummy18); + } + if (HasDummy19) { + output.WriteRawTag(152, 1); + output.WriteInt32(Dummy19); + } + if (HasDummy20) { + output.WriteRawTag(160, 1); + output.WriteInt32(Dummy20); + } + if (HasDummy21) { + output.WriteRawTag(168, 1); + output.WriteInt32(Dummy21); + } + if (HasDummy22) { + output.WriteRawTag(176, 1); + output.WriteInt32(Dummy22); + } + if (HasDummy23) { + output.WriteRawTag(184, 1); + output.WriteInt32(Dummy23); + } + if (HasDummy24) { + output.WriteRawTag(192, 1); + output.WriteInt32(Dummy24); + } + if (HasDummy25) { + output.WriteRawTag(200, 1); + output.WriteInt32(Dummy25); + } + if (HasDummy26) { + output.WriteRawTag(208, 1); + output.WriteInt32(Dummy26); + } + if (HasDummy27) { + output.WriteRawTag(216, 1); + output.WriteInt32(Dummy27); + } + if (HasDummy28) { + output.WriteRawTag(224, 1); + output.WriteInt32(Dummy28); + } + if (HasDummy29) { + output.WriteRawTag(232, 1); + output.WriteInt32(Dummy29); + } + if (HasDummy30) { + output.WriteRawTag(240, 1); + output.WriteInt32(Dummy30); + } + if (HasDummy31) { + output.WriteRawTag(248, 1); + output.WriteInt32(Dummy31); + } + if (HasDummy32) { + output.WriteRawTag(128, 2); + output.WriteInt32(Dummy32); + } + if (HasC) { + output.WriteRawTag(136, 2); + output.WriteInt32(C); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); } - return hash; } - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public override string ToString() { - return pb::JsonFormatter.ToDiagnosticString(this); - } + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void WriteTo(pb::CodedOutputStream output) { + public void WriteTo(ref pb::CodedOutputWriter output) { if (HasA) { output.WriteRawTag(8); output.WriteInt32(A); @@ -7432,9 +8792,10 @@ public void WriteTo(pb::CodedOutputStream output) { output.WriteInt32(C); } if (_unknownFields != null) { - _unknownFields.WriteTo(output); + _unknownFields.WriteTo(ref output); } } + #endif [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { @@ -7795,6 +9156,153 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + A = input.ReadInt32(); + break; + } + case 16: { + Dummy2 = input.ReadInt32(); + break; + } + case 24: { + B = input.ReadInt32(); + break; + } + case 32: { + Dummy4 = input.ReadInt32(); + break; + } + case 40: { + Dummy5 = input.ReadInt32(); + break; + } + case 48: { + Dummy6 = input.ReadInt32(); + break; + } + case 56: { + Dummy7 = input.ReadInt32(); + break; + } + case 64: { + Dummy8 = input.ReadInt32(); + break; + } + case 72: { + Dummy9 = input.ReadInt32(); + break; + } + case 80: { + Dummy10 = input.ReadInt32(); + break; + } + case 88: { + Dummy11 = input.ReadInt32(); + break; + } + case 96: { + Dummy12 = input.ReadInt32(); + break; + } + case 104: { + Dummy13 = input.ReadInt32(); + break; + } + case 112: { + Dummy14 = input.ReadInt32(); + break; + } + case 120: { + Dummy15 = input.ReadInt32(); + break; + } + case 128: { + Dummy16 = input.ReadInt32(); + break; + } + case 136: { + Dummy17 = input.ReadInt32(); + break; + } + case 144: { + Dummy18 = input.ReadInt32(); + break; + } + case 152: { + Dummy19 = input.ReadInt32(); + break; + } + case 160: { + Dummy20 = input.ReadInt32(); + break; + } + case 168: { + Dummy21 = input.ReadInt32(); + break; + } + case 176: { + Dummy22 = input.ReadInt32(); + break; + } + case 184: { + Dummy23 = input.ReadInt32(); + break; + } + case 192: { + Dummy24 = input.ReadInt32(); + break; + } + case 200: { + Dummy25 = input.ReadInt32(); + break; + } + case 208: { + Dummy26 = input.ReadInt32(); + break; + } + case 216: { + Dummy27 = input.ReadInt32(); + break; + } + case 224: { + Dummy28 = input.ReadInt32(); + break; + } + case 232: { + Dummy29 = input.ReadInt32(); + break; + } + case 240: { + Dummy30 = input.ReadInt32(); + break; + } + case 248: { + Dummy31 = input.ReadInt32(); + break; + } + case 256: { + Dummy32 = input.ReadInt32(); + break; + } + case 264: { + C = input.ReadInt32(); + break; + } + } + } + } + #endif + #region Extensions /// Container for extensions for other messages declared in the TestRequired message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -7808,7 +9316,11 @@ public static partial class Extensions { } - public sealed partial class TestRequiredForeign : pb::IMessage { + public sealed partial class TestRequiredForeign : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestRequiredForeign()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -7953,6 +9465,25 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasOptionalMessage) { + output.WriteRawTag(10); + output.WriteMessage(OptionalMessage); + } + repeatedMessage_.WriteTo(ref output, _repeated_repeatedMessage_codec); + if (HasDummy) { + output.WriteRawTag(24); + output.WriteInt32(Dummy); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -7984,16 +9515,45 @@ public void MergeFrom(TestRequiredForeign other) { if (other.HasDummy) { Dummy = other.Dummy; } - _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + if (!HasOptionalMessage) { + OptionalMessage = new global::Google.Protobuf.TestProtos.Proto2.TestRequired(); + } + input.ReadMessage(OptionalMessage); + break; + } + case 18: { + repeatedMessage_.AddEntriesFrom(input, _repeated_repeatedMessage_codec); + break; + } + case 24: { + Dummy = input.ReadInt32(); + break; + } + } + } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void MergeFrom(pb::CodedInputStream input) { + public void MergeFrom(ref pb::CodedInputReader input) { uint tag; while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); break; case 10: { if (!HasOptionalMessage) { @@ -8003,7 +9563,7 @@ public void MergeFrom(pb::CodedInputStream input) { break; } case 18: { - repeatedMessage_.AddEntriesFrom(input, _repeated_repeatedMessage_codec); + repeatedMessage_.AddEntriesFrom(ref input, _repeated_repeatedMessage_codec); break; } case 24: { @@ -8013,10 +9573,15 @@ public void MergeFrom(pb::CodedInputStream input) { } } } + #endif } - public sealed partial class TestRequiredMessage : pb::IMessage { + public sealed partial class TestRequiredMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestRequiredMessage()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -8156,6 +9721,25 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasOptionalMessage) { + output.WriteRawTag(10); + output.WriteMessage(OptionalMessage); + } + repeatedMessage_.WriteTo(ref output, _repeated_repeatedMessage_codec); + if (HasRequiredMessage) { + output.WriteRawTag(26); + output.WriteMessage(RequiredMessage); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -8223,12 +9807,49 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + if (!HasOptionalMessage) { + OptionalMessage = new global::Google.Protobuf.TestProtos.Proto2.TestRequired(); + } + input.ReadMessage(OptionalMessage); + break; + } + case 18: { + repeatedMessage_.AddEntriesFrom(ref input, _repeated_repeatedMessage_codec); + break; + } + case 26: { + if (!HasRequiredMessage) { + RequiredMessage = new global::Google.Protobuf.TestProtos.Proto2.TestRequired(); + } + input.ReadMessage(RequiredMessage); + break; + } + } + } + } + #endif + } /// /// Test that we can use NestedMessage from outside TestAllTypes. /// - public sealed partial class TestForeignNested : pb::IMessage { + public sealed partial class TestForeignNested : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestForeignNested()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -8326,6 +9947,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasForeignNested) { + output.WriteRawTag(10); + output.WriteMessage(ForeignNested); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -8371,12 +10006,38 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + if (!HasForeignNested) { + ForeignNested = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedMessage(); + } + input.ReadMessage(ForeignNested); + break; + } + } + } + } + #endif + } /// /// TestEmptyMessage is used to test unknown field support. /// - public sealed partial class TestEmptyMessage : pb::IMessage { + public sealed partial class TestEmptyMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestEmptyMessage()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -8446,6 +10107,16 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -8475,13 +10146,32 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + } /// /// Like above, but declare all field numbers as potential extensions. No /// actual extensions should ever be defined for this type. /// - public sealed partial class TestEmptyMessageWithExtensions : pb::IExtendableMessage { + public sealed partial class TestEmptyMessageWithExtensions : pb::IExtendableMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestEmptyMessageWithExtensions()); private pb::UnknownFieldSet _unknownFields; private pb::ExtensionSet _extensions; @@ -8563,6 +10253,19 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_extensions != null) { + _extensions.WriteTo(ref output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -8598,6 +10301,23 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + } + break; + } + } + } + #endif + public TValue GetExtension(pb::Extension extension) { return pb::ExtensionSet.Get(ref _extensions, extension); } @@ -8622,7 +10342,11 @@ public void ClearExtension(pb::RepeatedExtension { + public sealed partial class TestMultipleExtensionRanges : pb::IExtendableMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestMultipleExtensionRanges()); private pb::UnknownFieldSet _unknownFields; private pb::ExtensionSet _extensions; @@ -8704,6 +10428,19 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_extensions != null) { + _extensions.WriteTo(ref output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -8739,6 +10476,23 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + } + break; + } + } + } + #endif + public TValue GetExtension(pb::Extension extension) { return pb::ExtensionSet.Get(ref _extensions, extension); } @@ -8766,7 +10520,11 @@ public void ClearExtension(pb::RepeatedExtension /// Test that really large tag numbers don't break anything. /// - public sealed partial class TestReallyLargeTagNumber : pb::IMessage { + public sealed partial class TestReallyLargeTagNumber : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestReallyLargeTagNumber()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -8904,6 +10662,24 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasA) { + output.WriteRawTag(8); + output.WriteInt32(A); + } + if (HasBb) { + output.WriteRawTag(248, 255, 255, 255, 7); + output.WriteInt32(Bb); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -8953,9 +10729,36 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + A = input.ReadInt32(); + break; + } + case 2147483640: { + Bb = input.ReadInt32(); + break; + } + } + } + } + #endif + } - public sealed partial class TestRecursiveMessage : pb::IMessage { + public sealed partial class TestRecursiveMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestRecursiveMessage()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -9086,6 +10889,24 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasA) { + output.WriteRawTag(10); + output.WriteMessage(A); + } + if (HasI) { + output.WriteRawTag(16); + output.WriteInt32(I); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -9141,12 +10962,42 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + if (!HasA) { + A = new global::Google.Protobuf.TestProtos.Proto2.TestRecursiveMessage(); + } + input.ReadMessage(A); + break; + } + case 16: { + I = input.ReadInt32(); + break; + } + } + } + } + #endif + } /// /// Test that mutual recursion works. /// - public sealed partial class TestMutualRecursionA : pb::IMessage { + public sealed partial class TestMutualRecursionA : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestMutualRecursionA()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -9273,6 +11124,25 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasBb) { + output.WriteRawTag(10); + output.WriteMessage(Bb); + } + if (HasSubGroup) { + output.WriteRawTag(19); + output.WriteGroup(SubGroup); + output.WriteRawTag(20); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -9334,11 +11204,44 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + if (!HasBb) { + Bb = new global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionB(); + } + input.ReadMessage(Bb); + break; + } + case 19: { + if (!HasSubGroup) { + SubGroup = new global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionA.Types.SubGroup(); + } + input.ReadGroup(SubGroup); + break; + } + } + } + } + #endif + #region Nested types /// Container for nested types declared in the TestMutualRecursionA message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static partial class Types { - public sealed partial class SubMessage : pb::IMessage { + public sealed partial class SubMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new SubMessage()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -9426,15 +11329,29 @@ public override string ToString() { } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void WriteTo(pb::CodedOutputStream output) { + public void WriteTo(pb::CodedOutputStream output) { + if (HasB) { + output.WriteRawTag(10); + output.WriteMessage(B); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + } + + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { if (HasB) { output.WriteRawTag(10); output.WriteMessage(B); } if (_unknownFields != null) { - _unknownFields.WriteTo(output); + _unknownFields.WriteTo(ref output); } } + #endif [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { @@ -9481,9 +11398,35 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + if (!HasB) { + B = new global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionB(); + } + input.ReadMessage(B); + break; + } + } + } + } + #endif + } - public sealed partial class SubGroup : pb::IMessage { + public sealed partial class SubGroup : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new SubGroup()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -9612,6 +11555,24 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasSubMessage) { + output.WriteRawTag(26); + output.WriteMessage(SubMessage); + } + if (HasNotInThisScc) { + output.WriteRawTag(34); + output.WriteMessage(NotInThisScc); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -9675,6 +11636,37 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + case 20: + return; + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 26: { + if (!HasSubMessage) { + SubMessage = new global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionA.Types.SubMessage(); + } + input.ReadMessage(SubMessage); + break; + } + case 34: { + if (!HasNotInThisScc) { + NotInThisScc = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes(); + } + input.ReadMessage(NotInThisScc); + break; + } + } + } + } + #endif + } } @@ -9682,7 +11674,11 @@ public void MergeFrom(pb::CodedInputStream input) { } - public sealed partial class TestMutualRecursionB : pb::IMessage { + public sealed partial class TestMutualRecursionB : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestMutualRecursionB()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -9813,6 +11809,24 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasA) { + output.WriteRawTag(10); + output.WriteMessage(A); + } + if (HasOptionalInt32) { + output.WriteRawTag(16); + output.WriteInt32(OptionalInt32); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -9868,9 +11882,39 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + if (!HasA) { + A = new global::Google.Protobuf.TestProtos.Proto2.TestMutualRecursionA(); + } + input.ReadMessage(A); + break; + } + case 16: { + OptionalInt32 = input.ReadInt32(); + break; + } + } + } + } + #endif + } - public sealed partial class TestIsInitialized : pb::IMessage { + public sealed partial class TestIsInitialized : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestIsInitialized()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -9968,6 +12012,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasSubMessage) { + output.WriteRawTag(10); + output.WriteMessage(SubMessage); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -10013,11 +12071,37 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + if (!HasSubMessage) { + SubMessage = new global::Google.Protobuf.TestProtos.Proto2.TestIsInitialized.Types.SubMessage(); + } + input.ReadMessage(SubMessage); + break; + } + } + } + } + #endif + #region Nested types /// Container for nested types declared in the TestIsInitialized message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static partial class Types { - public sealed partial class SubMessage : pb::IMessage { + public sealed partial class SubMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new SubMessage()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -10116,6 +12200,21 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasSubGroup) { + output.WriteRawTag(11); + output.WriteGroup(SubGroup); + output.WriteRawTag(12); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -10161,11 +12260,37 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 11: { + if (!HasSubGroup) { + SubGroup = new global::Google.Protobuf.TestProtos.Proto2.TestIsInitialized.Types.SubMessage.Types.SubGroup(); + } + input.ReadGroup(SubGroup); + break; + } + } + } + } + #endif + #region Nested types /// Container for nested types declared in the SubMessage message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static partial class Types { - public sealed partial class SubGroup : pb::IMessage { + public sealed partial class SubGroup : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new SubGroup()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -10268,6 +12393,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasI) { + output.WriteRawTag(16); + output.WriteInt32(I); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -10309,6 +12448,27 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + case 12: + return; + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 16: { + I = input.ReadInt32(); + break; + } + } + } + } + #endif + } } @@ -10327,7 +12487,11 @@ public void MergeFrom(pb::CodedInputStream input) { /// to compile with proto1, this will emit an error; so we only include it /// in protobuf_unittest_proto. /// - public sealed partial class TestDupFieldNumber : pb::IMessage { + public sealed partial class TestDupFieldNumber : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestDupFieldNumber()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -10491,6 +12655,30 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasA) { + output.WriteRawTag(8); + output.WriteInt32(A); + } + if (HasFoo) { + output.WriteRawTag(19); + output.WriteGroup(Foo); + output.WriteRawTag(20); + } + if (HasBar) { + output.WriteRawTag(27); + output.WriteGroup(Bar); + output.WriteRawTag(28); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -10562,11 +12750,48 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + A = input.ReadInt32(); + break; + } + case 19: { + if (!HasFoo) { + Foo = new global::Google.Protobuf.TestProtos.Proto2.TestDupFieldNumber.Types.Foo(); + } + input.ReadGroup(Foo); + break; + } + case 27: { + if (!HasBar) { + Bar = new global::Google.Protobuf.TestProtos.Proto2.TestDupFieldNumber.Types.Bar(); + } + input.ReadGroup(Bar); + break; + } + } + } + } + #endif + #region Nested types /// Container for nested types declared in the TestDupFieldNumber message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static partial class Types { - public sealed partial class Foo : pb::IMessage { + public sealed partial class Foo : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Foo()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -10669,6 +12894,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasA) { + output.WriteRawTag(8); + output.WriteInt32(A); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -10689,18 +12928,38 @@ public void MergeFrom(Foo other) { if (other.HasA) { A = other.A; } - _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + case 20: + return; + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 8: { + A = input.ReadInt32(); + break; + } + } + } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void MergeFrom(pb::CodedInputStream input) { + public void MergeFrom(ref pb::CodedInputReader input) { uint tag; while ((tag = input.ReadTag()) != 0) { switch(tag) { case 20: return; default: - _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); break; case 8: { A = input.ReadInt32(); @@ -10709,10 +12968,15 @@ public void MergeFrom(pb::CodedInputStream input) { } } } + #endif } - public sealed partial class Bar : pb::IMessage { + public sealed partial class Bar : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Bar()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -10815,6 +13079,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasA) { + output.WriteRawTag(8); + output.WriteInt32(A); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -10856,6 +13134,27 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + case 28: + return; + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + A = input.ReadInt32(); + break; + } + } + } + } + #endif + } } @@ -10866,7 +13165,11 @@ public void MergeFrom(pb::CodedInputStream input) { /// /// Additional messages for testing lazy fields. /// - public sealed partial class TestEagerMessage : pb::IMessage { + public sealed partial class TestEagerMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestEagerMessage()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -10964,6 +13267,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasSubMessage) { + output.WriteRawTag(10); + output.WriteMessage(SubMessage); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -11009,9 +13326,35 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + if (!HasSubMessage) { + SubMessage = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes(); + } + input.ReadMessage(SubMessage); + break; + } + } + } + } + #endif + } - public sealed partial class TestLazyMessage : pb::IMessage { + public sealed partial class TestLazyMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestLazyMessage()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -11109,6 +13452,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasSubMessage) { + output.WriteRawTag(10); + output.WriteMessage(SubMessage); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -11154,12 +13511,38 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + if (!HasSubMessage) { + SubMessage = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes(); + } + input.ReadMessage(SubMessage); + break; + } + } + } + } + #endif + } /// /// Needed for a Python test. /// - public sealed partial class TestNestedMessageHasBits : pb::IMessage { + public sealed partial class TestNestedMessageHasBits : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestNestedMessageHasBits()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -11257,6 +13640,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasOptionalNestedMessage) { + output.WriteRawTag(10); + output.WriteMessage(OptionalNestedMessage); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -11302,11 +13699,37 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + if (!HasOptionalNestedMessage) { + OptionalNestedMessage = new global::Google.Protobuf.TestProtos.Proto2.TestNestedMessageHasBits.Types.NestedMessage(); + } + input.ReadMessage(OptionalNestedMessage); + break; + } + } + } + } + #endif + #region Nested types /// Container for nested types declared in the TestNestedMessageHasBits message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static partial class Types { - public sealed partial class NestedMessage : pb::IMessage { + public sealed partial class NestedMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new NestedMessage()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -11404,6 +13827,18 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + nestedmessageRepeatedInt32_.WriteTo(ref output, _repeated_nestedmessageRepeatedInt32_codec); + nestedmessageRepeatedForeignmessage_.WriteTo(ref output, _repeated_nestedmessageRepeatedForeignmessage_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -11446,6 +13881,30 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: + case 8: { + nestedmessageRepeatedInt32_.AddEntriesFrom(ref input, _repeated_nestedmessageRepeatedInt32_codec); + break; + } + case 18: { + nestedmessageRepeatedForeignmessage_.AddEntriesFrom(ref input, _repeated_nestedmessageRepeatedForeignmessage_codec); + break; + } + } + } + } + #endif + } } @@ -11457,7 +13916,11 @@ public void MergeFrom(pb::CodedInputStream input) { /// Test message with CamelCase field names. This violates Protocol Buffer /// standard style. /// - public sealed partial class TestCamelCaseFieldNames : pb::IMessage { + public sealed partial class TestCamelCaseFieldNames : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestCamelCaseFieldNames()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -11793,6 +14256,46 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasPrimitiveField) { + output.WriteRawTag(8); + output.WriteInt32(PrimitiveField); + } + if (HasStringField) { + output.WriteRawTag(18); + output.WriteString(StringField); + } + if (HasEnumField) { + output.WriteRawTag(24); + output.WriteEnum((int) EnumField); + } + if (HasMessageField) { + output.WriteRawTag(34); + output.WriteMessage(MessageField); + } + if (HasStringPieceField) { + output.WriteRawTag(42); + output.WriteString(StringPieceField); + } + if (HasCordField) { + output.WriteRawTag(50); + output.WriteString(CordField); + } + repeatedPrimitiveField_.WriteTo(ref output, _repeated_repeatedPrimitiveField_codec); + repeatedStringField_.WriteTo(ref output, _repeated_repeatedStringField_codec); + repeatedEnumField_.WriteTo(ref output, _repeated_repeatedEnumField_codec); + repeatedMessageField_.WriteTo(ref output, _repeated_repeatedMessageField_codec); + repeatedStringPieceField_.WriteTo(ref output, _repeated_repeatedStringPieceField_codec); + repeatedCordField_.WriteTo(ref output, _repeated_repeatedCordField_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -11926,13 +14429,85 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + PrimitiveField = input.ReadInt32(); + break; + } + case 18: { + StringField = input.ReadString(); + break; + } + case 24: { + EnumField = (global::Google.Protobuf.TestProtos.Proto2.ForeignEnum) input.ReadEnum(); + break; + } + case 34: { + if (!HasMessageField) { + MessageField = new global::Google.Protobuf.TestProtos.Proto2.ForeignMessage(); + } + input.ReadMessage(MessageField); + break; + } + case 42: { + StringPieceField = input.ReadString(); + break; + } + case 50: { + CordField = input.ReadString(); + break; + } + case 58: + case 56: { + repeatedPrimitiveField_.AddEntriesFrom(ref input, _repeated_repeatedPrimitiveField_codec); + break; + } + case 66: { + repeatedStringField_.AddEntriesFrom(ref input, _repeated_repeatedStringField_codec); + break; + } + case 74: + case 72: { + repeatedEnumField_.AddEntriesFrom(ref input, _repeated_repeatedEnumField_codec); + break; + } + case 82: { + repeatedMessageField_.AddEntriesFrom(ref input, _repeated_repeatedMessageField_codec); + break; + } + case 90: { + repeatedStringPieceField_.AddEntriesFrom(ref input, _repeated_repeatedStringPieceField_codec); + break; + } + case 98: { + repeatedCordField_.AddEntriesFrom(ref input, _repeated_repeatedCordField_codec); + break; + } + } + } + } + #endif + } /// /// We list fields out of order, to ensure that we're using field number and not /// field index to determine serialization order. /// - public sealed partial class TestFieldOrderings : pb::IExtendableMessage { + public sealed partial class TestFieldOrderings : pb::IExtendableMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestFieldOrderings()); private pb::UnknownFieldSet _unknownFields; private pb::ExtensionSet _extensions; @@ -12111,7 +14686,35 @@ public override string ToString() { } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void WriteTo(pb::CodedOutputStream output) { + public void WriteTo(pb::CodedOutputStream output) { + if (HasMyInt) { + output.WriteRawTag(8); + output.WriteInt64(MyInt); + } + if (HasMyString) { + output.WriteRawTag(90); + output.WriteString(MyString); + } + if (HasMyFloat) { + output.WriteRawTag(173, 6); + output.WriteFloat(MyFloat); + } + if (HasOptionalNestedMessage) { + output.WriteRawTag(194, 12); + output.WriteMessage(OptionalNestedMessage); + } + if (_extensions != null) { + _extensions.WriteTo(output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + } + + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { if (HasMyInt) { output.WriteRawTag(8); output.WriteInt64(MyInt); @@ -12129,12 +14732,13 @@ public void WriteTo(pb::CodedOutputStream output) { output.WriteMessage(OptionalNestedMessage); } if (_extensions != null) { - _extensions.WriteTo(output); + _extensions.WriteTo(ref output); } if (_unknownFields != null) { - _unknownFields.WriteTo(output); + _unknownFields.WriteTo(ref output); } } + #endif [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { @@ -12217,6 +14821,42 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + } + break; + case 8: { + MyInt = input.ReadInt64(); + break; + } + case 90: { + MyString = input.ReadString(); + break; + } + case 813: { + MyFloat = input.ReadFloat(); + break; + } + case 1602: { + if (!HasOptionalNestedMessage) { + OptionalNestedMessage = new global::Google.Protobuf.TestProtos.Proto2.TestFieldOrderings.Types.NestedMessage(); + } + input.ReadMessage(OptionalNestedMessage); + break; + } + } + } + } + #endif + public TValue GetExtension(pb::Extension extension) { return pb::ExtensionSet.Get(ref _extensions, extension); } @@ -12243,7 +14883,11 @@ public void ClearExtension(pb::RepeatedExtensionContainer for nested types declared in the TestFieldOrderings message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static partial class Types { - public sealed partial class NestedMessage : pb::IMessage { + public sealed partial class NestedMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new NestedMessage()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -12382,6 +15026,24 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasBb) { + output.WriteRawTag(8); + output.WriteInt32(Bb); + } + if (HasOo) { + output.WriteRawTag(16); + output.WriteInt64(Oo); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -12431,6 +15093,29 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Bb = input.ReadInt32(); + break; + } + case 16: { + Oo = input.ReadInt64(); + break; + } + } + } + } + #endif + } } @@ -12438,7 +15123,11 @@ public void MergeFrom(pb::CodedInputStream input) { } - public sealed partial class TestExtensionOrderings1 : pb::IMessage { + public sealed partial class TestExtensionOrderings1 : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestExtensionOrderings1()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -12538,6 +15227,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasMyString) { + output.WriteRawTag(10); + output.WriteString(MyString); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -12577,6 +15280,25 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + MyString = input.ReadString(); + break; + } + } + } + } + #endif + #region Extensions /// Container for extensions for other messages declared in the TestExtensionOrderings1 message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -12588,7 +15310,11 @@ public static partial class Extensions { } - public sealed partial class TestExtensionOrderings2 : pb::IMessage { + public sealed partial class TestExtensionOrderings2 : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestExtensionOrderings2()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -12688,6 +15414,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasMyString) { + output.WriteRawTag(10); + output.WriteString(MyString); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -12727,11 +15467,34 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + MyString = input.ReadString(); + break; + } + } + } + } + #endif + #region Nested types /// Container for nested types declared in the TestExtensionOrderings2 message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static partial class Types { - public sealed partial class TestExtensionOrderings3 : pb::IMessage { + public sealed partial class TestExtensionOrderings3 : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestExtensionOrderings3()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -12831,6 +15594,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasMyString) { + output.WriteRawTag(10); + output.WriteString(MyString); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -12870,6 +15647,25 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + MyString = input.ReadString(); + break; + } + } + } + } + #endif + #region Extensions /// Container for extensions for other messages declared in the TestExtensionOrderings3 message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -12895,7 +15691,11 @@ public static partial class Extensions { } - public sealed partial class TestExtremeDefaultValues : pb::IMessage { + public sealed partial class TestExtremeDefaultValues : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestExtremeDefaultValues()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -13695,18 +16495,135 @@ public override int GetHashCode() { if (HasCordWithZero) hash ^= CordWithZero.GetHashCode(); if (HasReplacementString) hash ^= ReplacementString.GetHashCode(); if (_unknownFields != null) { - hash ^= _unknownFields.GetHashCode(); + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + if (HasEscapedBytes) { + output.WriteRawTag(10); + output.WriteBytes(EscapedBytes); + } + if (HasLargeUint32) { + output.WriteRawTag(16); + output.WriteUInt32(LargeUint32); + } + if (HasLargeUint64) { + output.WriteRawTag(24); + output.WriteUInt64(LargeUint64); + } + if (HasSmallInt32) { + output.WriteRawTag(32); + output.WriteInt32(SmallInt32); + } + if (HasSmallInt64) { + output.WriteRawTag(40); + output.WriteInt64(SmallInt64); + } + if (HasUtf8String) { + output.WriteRawTag(50); + output.WriteString(Utf8String); + } + if (HasZeroFloat) { + output.WriteRawTag(61); + output.WriteFloat(ZeroFloat); + } + if (HasOneFloat) { + output.WriteRawTag(69); + output.WriteFloat(OneFloat); + } + if (HasSmallFloat) { + output.WriteRawTag(77); + output.WriteFloat(SmallFloat); + } + if (HasNegativeOneFloat) { + output.WriteRawTag(85); + output.WriteFloat(NegativeOneFloat); + } + if (HasNegativeFloat) { + output.WriteRawTag(93); + output.WriteFloat(NegativeFloat); + } + if (HasLargeFloat) { + output.WriteRawTag(101); + output.WriteFloat(LargeFloat); + } + if (HasSmallNegativeFloat) { + output.WriteRawTag(109); + output.WriteFloat(SmallNegativeFloat); + } + if (HasInfDouble) { + output.WriteRawTag(113); + output.WriteDouble(InfDouble); + } + if (HasNegInfDouble) { + output.WriteRawTag(121); + output.WriteDouble(NegInfDouble); + } + if (HasNanDouble) { + output.WriteRawTag(129, 1); + output.WriteDouble(NanDouble); + } + if (HasInfFloat) { + output.WriteRawTag(141, 1); + output.WriteFloat(InfFloat); + } + if (HasNegInfFloat) { + output.WriteRawTag(149, 1); + output.WriteFloat(NegInfFloat); + } + if (HasNanFloat) { + output.WriteRawTag(157, 1); + output.WriteFloat(NanFloat); + } + if (HasCppTrigraph) { + output.WriteRawTag(162, 1); + output.WriteString(CppTrigraph); + } + if (HasReallySmallInt32) { + output.WriteRawTag(168, 1); + output.WriteInt32(ReallySmallInt32); + } + if (HasReallySmallInt64) { + output.WriteRawTag(176, 1); + output.WriteInt64(ReallySmallInt64); + } + if (HasStringWithZero) { + output.WriteRawTag(186, 1); + output.WriteString(StringWithZero); + } + if (HasBytesWithZero) { + output.WriteRawTag(194, 1); + output.WriteBytes(BytesWithZero); + } + if (HasStringPieceWithZero) { + output.WriteRawTag(202, 1); + output.WriteString(StringPieceWithZero); + } + if (HasCordWithZero) { + output.WriteRawTag(210, 1); + output.WriteString(CordWithZero); + } + if (HasReplacementString) { + output.WriteRawTag(218, 1); + output.WriteString(ReplacementString); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); } - return hash; } - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public override string ToString() { - return pb::JsonFormatter.ToDiagnosticString(this); - } + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void WriteTo(pb::CodedOutputStream output) { + public void WriteTo(ref pb::CodedOutputWriter output) { if (HasEscapedBytes) { output.WriteRawTag(10); output.WriteBytes(EscapedBytes); @@ -13816,9 +16733,10 @@ public void WriteTo(pb::CodedOutputStream output) { output.WriteString(ReplacementString); } if (_unknownFields != null) { - _unknownFields.WriteTo(output); + _unknownFields.WriteTo(ref output); } } + #endif [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { @@ -14119,9 +17037,136 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + EscapedBytes = input.ReadBytes(); + break; + } + case 16: { + LargeUint32 = input.ReadUInt32(); + break; + } + case 24: { + LargeUint64 = input.ReadUInt64(); + break; + } + case 32: { + SmallInt32 = input.ReadInt32(); + break; + } + case 40: { + SmallInt64 = input.ReadInt64(); + break; + } + case 50: { + Utf8String = input.ReadString(); + break; + } + case 61: { + ZeroFloat = input.ReadFloat(); + break; + } + case 69: { + OneFloat = input.ReadFloat(); + break; + } + case 77: { + SmallFloat = input.ReadFloat(); + break; + } + case 85: { + NegativeOneFloat = input.ReadFloat(); + break; + } + case 93: { + NegativeFloat = input.ReadFloat(); + break; + } + case 101: { + LargeFloat = input.ReadFloat(); + break; + } + case 109: { + SmallNegativeFloat = input.ReadFloat(); + break; + } + case 113: { + InfDouble = input.ReadDouble(); + break; + } + case 121: { + NegInfDouble = input.ReadDouble(); + break; + } + case 129: { + NanDouble = input.ReadDouble(); + break; + } + case 141: { + InfFloat = input.ReadFloat(); + break; + } + case 149: { + NegInfFloat = input.ReadFloat(); + break; + } + case 157: { + NanFloat = input.ReadFloat(); + break; + } + case 162: { + CppTrigraph = input.ReadString(); + break; + } + case 168: { + ReallySmallInt32 = input.ReadInt32(); + break; + } + case 176: { + ReallySmallInt64 = input.ReadInt64(); + break; + } + case 186: { + StringWithZero = input.ReadString(); + break; + } + case 194: { + BytesWithZero = input.ReadBytes(); + break; + } + case 202: { + StringPieceWithZero = input.ReadString(); + break; + } + case 210: { + CordWithZero = input.ReadString(); + break; + } + case 218: { + ReplacementString = input.ReadString(); + break; + } + } + } + } + #endif + } - public sealed partial class SparseEnumMessage : pb::IMessage { + public sealed partial class SparseEnumMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new SparseEnumMessage()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -14224,6 +17269,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasSparseEnum) { + output.WriteRawTag(8); + output.WriteEnum((int) SparseEnum); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -14263,12 +17322,35 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + SparseEnum = (global::Google.Protobuf.TestProtos.Proto2.TestSparseEnum) input.ReadEnum(); + break; + } + } + } + } + #endif + } /// /// Test String and Bytes: string is for valid UTF-8 strings /// - public sealed partial class OneString : pb::IMessage { + public sealed partial class OneString : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new OneString()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -14368,6 +17450,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasData) { + output.WriteRawTag(10); + output.WriteString(Data); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -14407,9 +17503,32 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Data = input.ReadString(); + break; + } + } + } + } + #endif + } - public sealed partial class MoreString : pb::IMessage { + public sealed partial class MoreString : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new MoreString()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -14493,6 +17612,17 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + data_.WriteTo(ref output, _repeated_data_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -14528,9 +17658,32 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + data_.AddEntriesFrom(ref input, _repeated_data_codec); + break; + } + } + } + } + #endif + } - public sealed partial class OneBytes : pb::IMessage { + public sealed partial class OneBytes : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new OneBytes()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -14630,6 +17783,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasData) { + output.WriteRawTag(10); + output.WriteBytes(Data); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -14669,9 +17836,32 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Data = input.ReadBytes(); + break; + } + } + } + } + #endif + } - public sealed partial class MoreBytes : pb::IMessage { + public sealed partial class MoreBytes : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new MoreBytes()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -14755,6 +17945,17 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + data_.WriteTo(ref output, _repeated_data_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -14770,32 +17971,55 @@ public void MergeFrom(MoreBytes other) { if (other == null) { return; } - data_.Add(other.data_); - _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + data_.Add(other.data_); + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + data_.AddEntriesFrom(input, _repeated_data_codec); + break; + } + } + } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void MergeFrom(pb::CodedInputStream input) { + public void MergeFrom(ref pb::CodedInputReader input) { uint tag; while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); break; case 10: { - data_.AddEntriesFrom(input, _repeated_data_codec); + data_.AddEntriesFrom(ref input, _repeated_data_codec); break; } } } } + #endif } /// /// Test int32, uint32, int64, uint64, and bool are all compatible /// - public sealed partial class Int32Message : pb::IMessage { + public sealed partial class Int32Message : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Int32Message()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -14898,6 +18122,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasData) { + output.WriteRawTag(8); + output.WriteInt32(Data); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -14937,9 +18175,32 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Data = input.ReadInt32(); + break; + } + } + } + } + #endif + } - public sealed partial class Uint32Message : pb::IMessage { + public sealed partial class Uint32Message : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Uint32Message()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -15042,6 +18303,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasData) { + output.WriteRawTag(8); + output.WriteUInt32(Data); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -15081,9 +18356,32 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Data = input.ReadUInt32(); + break; + } + } + } + } + #endif + } - public sealed partial class Int64Message : pb::IMessage { + public sealed partial class Int64Message : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Int64Message()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -15186,6 +18484,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasData) { + output.WriteRawTag(8); + output.WriteInt64(Data); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -15225,9 +18537,32 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Data = input.ReadInt64(); + break; + } + } + } + } + #endif + } - public sealed partial class Uint64Message : pb::IMessage { + public sealed partial class Uint64Message : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Uint64Message()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -15330,6 +18665,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasData) { + output.WriteRawTag(8); + output.WriteUInt64(Data); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -15369,9 +18718,32 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Data = input.ReadUInt64(); + break; + } + } + } + } + #endif + } - public sealed partial class BoolMessage : pb::IMessage { + public sealed partial class BoolMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new BoolMessage()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -15474,6 +18846,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasData) { + output.WriteRawTag(8); + output.WriteBool(Data); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -15513,12 +18899,35 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Data = input.ReadBool(); + break; + } + } + } + } + #endif + } /// /// Test oneofs. /// - public sealed partial class TestOneof : pb::IMessage { + public sealed partial class TestOneof : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestOneof()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -15745,6 +19154,33 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasFooInt) { + output.WriteRawTag(8); + output.WriteInt32(FooInt); + } + if (HasFooString) { + output.WriteRawTag(18); + output.WriteString(FooString); + } + if (HasFooMessage) { + output.WriteRawTag(26); + output.WriteMessage(FooMessage); + } + if (HasFooGroup) { + output.WriteRawTag(35); + output.WriteGroup(FooGroup); + output.WriteRawTag(36); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -15833,11 +19269,56 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + FooInt = input.ReadInt32(); + break; + } + case 18: { + FooString = input.ReadString(); + break; + } + case 26: { + global::Google.Protobuf.TestProtos.Proto2.TestAllTypes subBuilder = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes(); + if (HasFooMessage) { + subBuilder.MergeFrom(FooMessage); + } + input.ReadMessage(subBuilder); + FooMessage = subBuilder; + break; + } + case 35: { + global::Google.Protobuf.TestProtos.Proto2.TestOneof.Types.FooGroup subBuilder = new global::Google.Protobuf.TestProtos.Proto2.TestOneof.Types.FooGroup(); + if (HasFooGroup) { + subBuilder.MergeFrom(FooGroup); + } + input.ReadGroup(subBuilder); + FooGroup = subBuilder; + break; + } + } + } + } + #endif + #region Nested types /// Container for nested types declared in the TestOneof message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static partial class Types { - public sealed partial class FooGroup : pb::IMessage { + public sealed partial class FooGroup : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new FooGroup()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -15970,6 +19451,24 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasA) { + output.WriteRawTag(40); + output.WriteInt32(A); + } + if (HasB) { + output.WriteRawTag(50); + output.WriteString(B); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -16021,6 +19520,31 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + case 36: + return; + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 40: { + A = input.ReadInt32(); + break; + } + case 50: { + B = input.ReadString(); + break; + } + } + } + } + #endif + } } @@ -16028,7 +19552,11 @@ public void MergeFrom(pb::CodedInputStream input) { } - public sealed partial class TestOneofBackwardsCompatible : pb::IMessage { + public sealed partial class TestOneofBackwardsCompatible : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestOneofBackwardsCompatible()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -16186,16 +19714,42 @@ public override int GetHashCode() { if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } - return hash; + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + if (HasFooInt) { + output.WriteRawTag(8); + output.WriteInt32(FooInt); + } + if (HasFooString) { + output.WriteRawTag(18); + output.WriteString(FooString); + } + if (HasFooMessage) { + output.WriteRawTag(26); + output.WriteMessage(FooMessage); + } + if (HasFooGroup) { + output.WriteRawTag(35); + output.WriteGroup(FooGroup); + output.WriteRawTag(36); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } } - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public override string ToString() { - return pb::JsonFormatter.ToDiagnosticString(this); - } + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void WriteTo(pb::CodedOutputStream output) { + public void WriteTo(ref pb::CodedOutputWriter output) { if (HasFooInt) { output.WriteRawTag(8); output.WriteInt32(FooInt); @@ -16214,9 +19768,10 @@ public void WriteTo(pb::CodedOutputStream output) { output.WriteRawTag(36); } if (_unknownFields != null) { - _unknownFields.WriteTo(output); + _unknownFields.WriteTo(ref output); } } + #endif [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { @@ -16299,11 +19854,52 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + FooInt = input.ReadInt32(); + break; + } + case 18: { + FooString = input.ReadString(); + break; + } + case 26: { + if (!HasFooMessage) { + FooMessage = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes(); + } + input.ReadMessage(FooMessage); + break; + } + case 35: { + if (!HasFooGroup) { + FooGroup = new global::Google.Protobuf.TestProtos.Proto2.TestOneofBackwardsCompatible.Types.FooGroup(); + } + input.ReadGroup(FooGroup); + break; + } + } + } + } + #endif + #region Nested types /// Container for nested types declared in the TestOneofBackwardsCompatible message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static partial class Types { - public sealed partial class FooGroup : pb::IMessage { + public sealed partial class FooGroup : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new FooGroup()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -16436,6 +20032,24 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasA) { + output.WriteRawTag(40); + output.WriteInt32(A); + } + if (HasB) { + output.WriteRawTag(50); + output.WriteString(B); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -16487,6 +20101,31 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + case 36: + return; + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 40: { + A = input.ReadInt32(); + break; + } + case 50: { + B = input.ReadString(); + break; + } + } + } + } + #endif + } } @@ -16494,7 +20133,11 @@ public void MergeFrom(pb::CodedInputStream input) { } - public sealed partial class TestOneof2 : pb::IMessage { + public sealed partial class TestOneof2 : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestOneof2()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -17167,6 +20810,85 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasFooInt) { + output.WriteRawTag(8); + output.WriteInt32(FooInt); + } + if (HasFooString) { + output.WriteRawTag(18); + output.WriteString(FooString); + } + if (HasFooCord) { + output.WriteRawTag(26); + output.WriteString(FooCord); + } + if (HasFooStringPiece) { + output.WriteRawTag(34); + output.WriteString(FooStringPiece); + } + if (HasFooBytes) { + output.WriteRawTag(42); + output.WriteBytes(FooBytes); + } + if (HasFooEnum) { + output.WriteRawTag(48); + output.WriteEnum((int) FooEnum); + } + if (HasFooMessage) { + output.WriteRawTag(58); + output.WriteMessage(FooMessage); + } + if (HasFooGroup) { + output.WriteRawTag(67); + output.WriteGroup(FooGroup); + output.WriteRawTag(68); + } + if (HasFooLazyMessage) { + output.WriteRawTag(90); + output.WriteMessage(FooLazyMessage); + } + if (HasBarInt) { + output.WriteRawTag(96); + output.WriteInt32(BarInt); + } + if (HasBarString) { + output.WriteRawTag(106); + output.WriteString(BarString); + } + if (HasBarCord) { + output.WriteRawTag(114); + output.WriteString(BarCord); + } + if (HasBarStringPiece) { + output.WriteRawTag(122); + output.WriteString(BarStringPiece); + } + if (HasBarBytes) { + output.WriteRawTag(130, 1); + output.WriteBytes(BarBytes); + } + if (HasBarEnum) { + output.WriteRawTag(136, 1); + output.WriteEnum((int) BarEnum); + } + if (HasBazInt) { + output.WriteRawTag(144, 1); + output.WriteInt32(BazInt); + } + if (HasBazString) { + output.WriteRawTag(154, 1); + output.WriteString(BazString); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -17261,53 +20983,152 @@ public void MergeFrom(TestOneof2 other) { if (FooMessage == null) { FooMessage = new global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedMessage(); } - FooMessage.MergeFrom(other.FooMessage); - break; - case FooOneofCase.FooGroup: - if (FooGroup == null) { - FooGroup = new global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.FooGroup(); + FooMessage.MergeFrom(other.FooMessage); + break; + case FooOneofCase.FooGroup: + if (FooGroup == null) { + FooGroup = new global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.FooGroup(); + } + FooGroup.MergeFrom(other.FooGroup); + break; + case FooOneofCase.FooLazyMessage: + if (FooLazyMessage == null) { + FooLazyMessage = new global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedMessage(); + } + FooLazyMessage.MergeFrom(other.FooLazyMessage); + break; + } + + switch (other.BarCase) { + case BarOneofCase.BarInt: + BarInt = other.BarInt; + break; + case BarOneofCase.BarString: + BarString = other.BarString; + break; + case BarOneofCase.BarCord: + BarCord = other.BarCord; + break; + case BarOneofCase.BarStringPiece: + BarStringPiece = other.BarStringPiece; + break; + case BarOneofCase.BarBytes: + BarBytes = other.BarBytes; + break; + case BarOneofCase.BarEnum: + BarEnum = other.BarEnum; + break; + } + + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 8: { + FooInt = input.ReadInt32(); + break; + } + case 18: { + FooString = input.ReadString(); + break; + } + case 26: { + FooCord = input.ReadString(); + break; + } + case 34: { + FooStringPiece = input.ReadString(); + break; + } + case 42: { + FooBytes = input.ReadBytes(); + break; + } + case 48: { + foo_ = input.ReadEnum(); + fooCase_ = FooOneofCase.FooEnum; + break; + } + case 58: { + global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedMessage subBuilder = new global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedMessage(); + if (HasFooMessage) { + subBuilder.MergeFrom(FooMessage); + } + input.ReadMessage(subBuilder); + FooMessage = subBuilder; + break; + } + case 67: { + global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.FooGroup subBuilder = new global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.FooGroup(); + if (HasFooGroup) { + subBuilder.MergeFrom(FooGroup); + } + input.ReadGroup(subBuilder); + FooGroup = subBuilder; + break; + } + case 90: { + global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedMessage subBuilder = new global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedMessage(); + if (HasFooLazyMessage) { + subBuilder.MergeFrom(FooLazyMessage); + } + input.ReadMessage(subBuilder); + FooLazyMessage = subBuilder; + break; + } + case 96: { + BarInt = input.ReadInt32(); + break; + } + case 106: { + BarString = input.ReadString(); + break; + } + case 114: { + BarCord = input.ReadString(); + break; } - FooGroup.MergeFrom(other.FooGroup); - break; - case FooOneofCase.FooLazyMessage: - if (FooLazyMessage == null) { - FooLazyMessage = new global::Google.Protobuf.TestProtos.Proto2.TestOneof2.Types.NestedMessage(); + case 122: { + BarStringPiece = input.ReadString(); + break; } - FooLazyMessage.MergeFrom(other.FooLazyMessage); - break; - } - - switch (other.BarCase) { - case BarOneofCase.BarInt: - BarInt = other.BarInt; - break; - case BarOneofCase.BarString: - BarString = other.BarString; - break; - case BarOneofCase.BarCord: - BarCord = other.BarCord; - break; - case BarOneofCase.BarStringPiece: - BarStringPiece = other.BarStringPiece; - break; - case BarOneofCase.BarBytes: - BarBytes = other.BarBytes; - break; - case BarOneofCase.BarEnum: - BarEnum = other.BarEnum; - break; + case 130: { + BarBytes = input.ReadBytes(); + break; + } + case 136: { + bar_ = input.ReadEnum(); + barCase_ = BarOneofCase.BarEnum; + break; + } + case 144: { + BazInt = input.ReadInt32(); + break; + } + case 154: { + BazString = input.ReadString(); + break; + } + } } - - _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void MergeFrom(pb::CodedInputStream input) { + public void MergeFrom(ref pb::CodedInputReader input) { uint tag; while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); break; case 8: { FooInt = input.ReadInt32(); @@ -17397,6 +21218,7 @@ public void MergeFrom(pb::CodedInputStream input) { } } } + #endif #region Nested types /// Container for nested types declared in the TestOneof2 message type. @@ -17408,7 +21230,11 @@ public enum NestedEnum { [pbr::OriginalName("BAZ")] Baz = 3, } - public sealed partial class FooGroup : pb::IMessage { + public sealed partial class FooGroup : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new FooGroup()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -17541,6 +21367,24 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasA) { + output.WriteRawTag(72); + output.WriteInt32(A); + } + if (HasB) { + output.WriteRawTag(82); + output.WriteString(B); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -17592,9 +21436,38 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + case 68: + return; + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 72: { + A = input.ReadInt32(); + break; + } + case 82: { + B = input.ReadString(); + break; + } + } + } + } + #endif + } - public sealed partial class NestedMessage : pb::IMessage { + public sealed partial class NestedMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new NestedMessage()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -17711,6 +21584,21 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasQuxInt) { + output.WriteRawTag(8); + output.WriteInt64(QuxInt); + } + corgeInt_.WriteTo(ref output, _repeated_corgeInt_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -17757,6 +21645,30 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + QuxInt = input.ReadInt64(); + break; + } + case 18: + case 16: { + corgeInt_.AddEntriesFrom(ref input, _repeated_corgeInt_codec); + break; + } + } + } + } + #endif + } } @@ -17764,7 +21676,11 @@ public void MergeFrom(pb::CodedInputStream input) { } - public sealed partial class TestRequiredOneof : pb::IMessage { + public sealed partial class TestRequiredOneof : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestRequiredOneof()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -17957,6 +21873,28 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasFooInt) { + output.WriteRawTag(8); + output.WriteInt32(FooInt); + } + if (HasFooString) { + output.WriteRawTag(18); + output.WriteString(FooString); + } + if (HasFooMessage) { + output.WriteRawTag(26); + output.WriteMessage(FooMessage); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -18027,11 +21965,47 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + FooInt = input.ReadInt32(); + break; + } + case 18: { + FooString = input.ReadString(); + break; + } + case 26: { + global::Google.Protobuf.TestProtos.Proto2.TestRequiredOneof.Types.NestedMessage subBuilder = new global::Google.Protobuf.TestProtos.Proto2.TestRequiredOneof.Types.NestedMessage(); + if (HasFooMessage) { + subBuilder.MergeFrom(FooMessage); + } + input.ReadMessage(subBuilder); + FooMessage = subBuilder; + break; + } + } + } + } + #endif + #region Nested types /// Container for nested types declared in the TestRequiredOneof message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static partial class Types { - public sealed partial class NestedMessage : pb::IMessage { + public sealed partial class NestedMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new NestedMessage()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -18134,6 +22108,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasRequiredDouble) { + output.WriteRawTag(9); + output.WriteDouble(RequiredDouble); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -18173,6 +22161,25 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 9: { + RequiredDouble = input.ReadDouble(); + break; + } + } + } + } + #endif + } } @@ -18180,7 +22187,11 @@ public void MergeFrom(pb::CodedInputStream input) { } - public sealed partial class TestRequiredMap : pb::IMessage { + public sealed partial class TestRequiredMap : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestRequiredMap()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -18264,6 +22275,17 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + foo_.WriteTo(ref output, _map_foo_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -18299,11 +22321,34 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + foo_.AddEntriesFrom(ref input, _map_foo_codec); + break; + } + } + } + } + #endif + #region Nested types /// Container for nested types declared in the TestRequiredMap message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static partial class Types { - public sealed partial class NestedMessage : pb::IMessage { + public sealed partial class NestedMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new NestedMessage()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -18406,6 +22451,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasRequiredInt32) { + output.WriteRawTag(8); + output.WriteInt32(RequiredInt32); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -18415,27 +22474,45 @@ public int CalculateSize() { if (_unknownFields != null) { size += _unknownFields.CalculateSize(); } - return size; + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(NestedMessage other) { + if (other == null) { + return; + } + if (other.HasRequiredInt32) { + RequiredInt32 = other.RequiredInt32; + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 8: { + RequiredInt32 = input.ReadInt32(); + break; + } + } + } } - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void MergeFrom(NestedMessage other) { - if (other == null) { - return; - } - if (other.HasRequiredInt32) { - RequiredInt32 = other.RequiredInt32; - } - _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); - } + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void MergeFrom(pb::CodedInputStream input) { + public void MergeFrom(ref pb::CodedInputReader input) { uint tag; while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); break; case 8: { RequiredInt32 = input.ReadInt32(); @@ -18444,6 +22521,7 @@ public void MergeFrom(pb::CodedInputStream input) { } } } + #endif } @@ -18452,7 +22530,11 @@ public void MergeFrom(pb::CodedInputStream input) { } - public sealed partial class TestPackedTypes : pb::IMessage { + public sealed partial class TestPackedTypes : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestPackedTypes()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -18718,6 +22800,30 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + packedInt32_.WriteTo(ref output, _repeated_packedInt32_codec); + packedInt64_.WriteTo(ref output, _repeated_packedInt64_codec); + packedUint32_.WriteTo(ref output, _repeated_packedUint32_codec); + packedUint64_.WriteTo(ref output, _repeated_packedUint64_codec); + packedSint32_.WriteTo(ref output, _repeated_packedSint32_codec); + packedSint64_.WriteTo(ref output, _repeated_packedSint64_codec); + packedFixed32_.WriteTo(ref output, _repeated_packedFixed32_codec); + packedFixed64_.WriteTo(ref output, _repeated_packedFixed64_codec); + packedSfixed32_.WriteTo(ref output, _repeated_packedSfixed32_codec); + packedSfixed64_.WriteTo(ref output, _repeated_packedSfixed64_codec); + packedFloat_.WriteTo(ref output, _repeated_packedFloat_codec); + packedDouble_.WriteTo(ref output, _repeated_packedDouble_codec); + packedBool_.WriteTo(ref output, _repeated_packedBool_codec); + packedEnum_.WriteTo(ref output, _repeated_packedEnum_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -18845,13 +22951,102 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 722: + case 720: { + packedInt32_.AddEntriesFrom(ref input, _repeated_packedInt32_codec); + break; + } + case 730: + case 728: { + packedInt64_.AddEntriesFrom(ref input, _repeated_packedInt64_codec); + break; + } + case 738: + case 736: { + packedUint32_.AddEntriesFrom(ref input, _repeated_packedUint32_codec); + break; + } + case 746: + case 744: { + packedUint64_.AddEntriesFrom(ref input, _repeated_packedUint64_codec); + break; + } + case 754: + case 752: { + packedSint32_.AddEntriesFrom(ref input, _repeated_packedSint32_codec); + break; + } + case 762: + case 760: { + packedSint64_.AddEntriesFrom(ref input, _repeated_packedSint64_codec); + break; + } + case 770: + case 773: { + packedFixed32_.AddEntriesFrom(ref input, _repeated_packedFixed32_codec); + break; + } + case 778: + case 777: { + packedFixed64_.AddEntriesFrom(ref input, _repeated_packedFixed64_codec); + break; + } + case 786: + case 789: { + packedSfixed32_.AddEntriesFrom(ref input, _repeated_packedSfixed32_codec); + break; + } + case 794: + case 793: { + packedSfixed64_.AddEntriesFrom(ref input, _repeated_packedSfixed64_codec); + break; + } + case 802: + case 805: { + packedFloat_.AddEntriesFrom(ref input, _repeated_packedFloat_codec); + break; + } + case 810: + case 809: { + packedDouble_.AddEntriesFrom(ref input, _repeated_packedDouble_codec); + break; + } + case 818: + case 816: { + packedBool_.AddEntriesFrom(ref input, _repeated_packedBool_codec); + break; + } + case 826: + case 824: { + packedEnum_.AddEntriesFrom(ref input, _repeated_packedEnum_codec); + break; + } + } + } + } + #endif + } /// /// A message with the same fields as TestPackedTypes, but without packing. Used /// to test packed <-> unpacked wire compatibility. /// - public sealed partial class TestUnpackedTypes : pb::IMessage { + public sealed partial class TestUnpackedTypes : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestUnpackedTypes()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -19117,6 +23312,30 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + unpackedInt32_.WriteTo(ref output, _repeated_unpackedInt32_codec); + unpackedInt64_.WriteTo(ref output, _repeated_unpackedInt64_codec); + unpackedUint32_.WriteTo(ref output, _repeated_unpackedUint32_codec); + unpackedUint64_.WriteTo(ref output, _repeated_unpackedUint64_codec); + unpackedSint32_.WriteTo(ref output, _repeated_unpackedSint32_codec); + unpackedSint64_.WriteTo(ref output, _repeated_unpackedSint64_codec); + unpackedFixed32_.WriteTo(ref output, _repeated_unpackedFixed32_codec); + unpackedFixed64_.WriteTo(ref output, _repeated_unpackedFixed64_codec); + unpackedSfixed32_.WriteTo(ref output, _repeated_unpackedSfixed32_codec); + unpackedSfixed64_.WriteTo(ref output, _repeated_unpackedSfixed64_codec); + unpackedFloat_.WriteTo(ref output, _repeated_unpackedFloat_codec); + unpackedDouble_.WriteTo(ref output, _repeated_unpackedDouble_codec); + unpackedBool_.WriteTo(ref output, _repeated_unpackedBool_codec); + unpackedEnum_.WriteTo(ref output, _repeated_unpackedEnum_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -19244,9 +23463,98 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 722: + case 720: { + unpackedInt32_.AddEntriesFrom(ref input, _repeated_unpackedInt32_codec); + break; + } + case 730: + case 728: { + unpackedInt64_.AddEntriesFrom(ref input, _repeated_unpackedInt64_codec); + break; + } + case 738: + case 736: { + unpackedUint32_.AddEntriesFrom(ref input, _repeated_unpackedUint32_codec); + break; + } + case 746: + case 744: { + unpackedUint64_.AddEntriesFrom(ref input, _repeated_unpackedUint64_codec); + break; + } + case 754: + case 752: { + unpackedSint32_.AddEntriesFrom(ref input, _repeated_unpackedSint32_codec); + break; + } + case 762: + case 760: { + unpackedSint64_.AddEntriesFrom(ref input, _repeated_unpackedSint64_codec); + break; + } + case 770: + case 773: { + unpackedFixed32_.AddEntriesFrom(ref input, _repeated_unpackedFixed32_codec); + break; + } + case 778: + case 777: { + unpackedFixed64_.AddEntriesFrom(ref input, _repeated_unpackedFixed64_codec); + break; + } + case 786: + case 789: { + unpackedSfixed32_.AddEntriesFrom(ref input, _repeated_unpackedSfixed32_codec); + break; + } + case 794: + case 793: { + unpackedSfixed64_.AddEntriesFrom(ref input, _repeated_unpackedSfixed64_codec); + break; + } + case 802: + case 805: { + unpackedFloat_.AddEntriesFrom(ref input, _repeated_unpackedFloat_codec); + break; + } + case 810: + case 809: { + unpackedDouble_.AddEntriesFrom(ref input, _repeated_unpackedDouble_codec); + break; + } + case 818: + case 816: { + unpackedBool_.AddEntriesFrom(ref input, _repeated_unpackedBool_codec); + break; + } + case 826: + case 824: { + unpackedEnum_.AddEntriesFrom(ref input, _repeated_unpackedEnum_codec); + break; + } + } + } + } + #endif + } - public sealed partial class TestPackedExtensions : pb::IExtendableMessage { + public sealed partial class TestPackedExtensions : pb::IExtendableMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestPackedExtensions()); private pb::UnknownFieldSet _unknownFields; private pb::ExtensionSet _extensions; @@ -19328,6 +23636,19 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_extensions != null) { + _extensions.WriteTo(ref output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -19363,6 +23684,23 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + } + break; + } + } + } + #endif + public TValue GetExtension(pb::Extension extension) { return pb::ExtensionSet.Get(ref _extensions, extension); } @@ -19387,7 +23725,11 @@ public void ClearExtension(pb::RepeatedExtension { + public sealed partial class TestUnpackedExtensions : pb::IExtendableMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestUnpackedExtensions()); private pb::UnknownFieldSet _unknownFields; private pb::ExtensionSet _extensions; @@ -19469,6 +23811,19 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_extensions != null) { + _extensions.WriteTo(ref output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -19504,6 +23859,23 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + } + break; + } + } + } + #endif + public TValue GetExtension(pb::Extension extension) { return pb::ExtensionSet.Get(ref _extensions, extension); } @@ -19533,7 +23905,11 @@ public void ClearExtension(pb::RepeatedExtension - public sealed partial class TestDynamicExtensions : pb::IMessage { + public sealed partial class TestDynamicExtensions : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestDynamicExtensions()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -19782,6 +24158,38 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasScalarExtension) { + output.WriteRawTag(133, 125); + output.WriteFixed32(ScalarExtension); + } + if (HasEnumExtension) { + output.WriteRawTag(136, 125); + output.WriteEnum((int) EnumExtension); + } + if (HasDynamicEnumExtension) { + output.WriteRawTag(144, 125); + output.WriteEnum((int) DynamicEnumExtension); + } + if (HasMessageExtension) { + output.WriteRawTag(154, 125); + output.WriteMessage(MessageExtension); + } + if (HasDynamicMessageExtension) { + output.WriteRawTag(162, 125); + output.WriteMessage(DynamicMessageExtension); + } + repeatedExtension_.WriteTo(ref output, _repeated_repeatedExtension_codec); + packedExtension_.WriteTo(ref output, _repeated_packedExtension_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -19832,20 +24240,69 @@ public void MergeFrom(TestDynamicExtensions other) { if (!HasDynamicMessageExtension) { DynamicMessageExtension = new global::Google.Protobuf.TestProtos.Proto2.TestDynamicExtensions.Types.DynamicMessageType(); } - DynamicMessageExtension.MergeFrom(other.DynamicMessageExtension); + DynamicMessageExtension.MergeFrom(other.DynamicMessageExtension); + } + repeatedExtension_.Add(other.repeatedExtension_); + packedExtension_.Add(other.packedExtension_); + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 16005: { + ScalarExtension = input.ReadFixed32(); + break; + } + case 16008: { + EnumExtension = (global::Google.Protobuf.TestProtos.Proto2.ForeignEnum) input.ReadEnum(); + break; + } + case 16016: { + DynamicEnumExtension = (global::Google.Protobuf.TestProtos.Proto2.TestDynamicExtensions.Types.DynamicEnumType) input.ReadEnum(); + break; + } + case 16026: { + if (!HasMessageExtension) { + MessageExtension = new global::Google.Protobuf.TestProtos.Proto2.ForeignMessage(); + } + input.ReadMessage(MessageExtension); + break; + } + case 16034: { + if (!HasDynamicMessageExtension) { + DynamicMessageExtension = new global::Google.Protobuf.TestProtos.Proto2.TestDynamicExtensions.Types.DynamicMessageType(); + } + input.ReadMessage(DynamicMessageExtension); + break; + } + case 16042: { + repeatedExtension_.AddEntriesFrom(input, _repeated_repeatedExtension_codec); + break; + } + case 16050: + case 16048: { + packedExtension_.AddEntriesFrom(input, _repeated_packedExtension_codec); + break; + } + } } - repeatedExtension_.Add(other.repeatedExtension_); - packedExtension_.Add(other.packedExtension_); - _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void MergeFrom(pb::CodedInputStream input) { + public void MergeFrom(ref pb::CodedInputReader input) { uint tag; while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); break; case 16005: { ScalarExtension = input.ReadFixed32(); @@ -19874,17 +24331,18 @@ public void MergeFrom(pb::CodedInputStream input) { break; } case 16042: { - repeatedExtension_.AddEntriesFrom(input, _repeated_repeatedExtension_codec); + repeatedExtension_.AddEntriesFrom(ref input, _repeated_repeatedExtension_codec); break; } case 16050: case 16048: { - packedExtension_.AddEntriesFrom(input, _repeated_packedExtension_codec); + packedExtension_.AddEntriesFrom(ref input, _repeated_packedExtension_codec); break; } } } } + #endif #region Nested types /// Container for nested types declared in the TestDynamicExtensions message type. @@ -19896,7 +24354,11 @@ public enum DynamicEnumType { [pbr::OriginalName("DYNAMIC_BAZ")] DynamicBaz = 2202, } - public sealed partial class DynamicMessageType : pb::IMessage { + public sealed partial class DynamicMessageType : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new DynamicMessageType()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -19999,6 +24461,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasDynamicField) { + output.WriteRawTag(160, 131, 1); + output.WriteInt32(DynamicField); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -20038,6 +24514,25 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 16800: { + DynamicField = input.ReadInt32(); + break; + } + } + } + } + #endif + } } @@ -20045,7 +24540,11 @@ public void MergeFrom(pb::CodedInputStream input) { } - public sealed partial class TestRepeatedScalarDifferentTagSizes : pb::IMessage { + public sealed partial class TestRepeatedScalarDifferentTagSizes : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestRepeatedScalarDifferentTagSizes()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -20213,6 +24712,22 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + repeatedFixed32_.WriteTo(ref output, _repeated_repeatedFixed32_codec); + repeatedInt32_.WriteTo(ref output, _repeated_repeatedInt32_codec); + repeatedFixed64_.WriteTo(ref output, _repeated_repeatedFixed64_codec); + repeatedInt64_.WriteTo(ref output, _repeated_repeatedInt64_codec); + repeatedFloat_.WriteTo(ref output, _repeated_repeatedFloat_codec); + repeatedUint64_.WriteTo(ref output, _repeated_repeatedUint64_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -20284,13 +24799,62 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 98: + case 101: { + repeatedFixed32_.AddEntriesFrom(ref input, _repeated_repeatedFixed32_codec); + break; + } + case 106: + case 104: { + repeatedInt32_.AddEntriesFrom(ref input, _repeated_repeatedInt32_codec); + break; + } + case 16370: + case 16369: { + repeatedFixed64_.AddEntriesFrom(ref input, _repeated_repeatedFixed64_codec); + break; + } + case 16378: + case 16376: { + repeatedInt64_.AddEntriesFrom(ref input, _repeated_repeatedInt64_codec); + break; + } + case 2097138: + case 2097141: { + repeatedFloat_.AddEntriesFrom(ref input, _repeated_repeatedFloat_codec); + break; + } + case 2097146: + case 2097144: { + repeatedUint64_.AddEntriesFrom(ref input, _repeated_repeatedUint64_codec); + break; + } + } + } + } + #endif + } /// /// Test that if an optional or required message/group field appears multiple /// times in the input, they need to be merged. /// - public sealed partial class TestParsingMerge : pb::IExtendableMessage { + public sealed partial class TestParsingMerge : pb::IExtendableMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestParsingMerge()); private pb::UnknownFieldSet _unknownFields; private pb::ExtensionSet _extensions; @@ -20485,6 +25049,34 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasRequiredAllTypes) { + output.WriteRawTag(10); + output.WriteMessage(RequiredAllTypes); + } + if (HasOptionalAllTypes) { + output.WriteRawTag(18); + output.WriteMessage(OptionalAllTypes); + } + repeatedAllTypes_.WriteTo(ref output, _repeated_repeatedAllTypes_codec); + if (HasOptionalGroup) { + output.WriteRawTag(83); + output.WriteGroup(OptionalGroup); + output.WriteRawTag(84); + } + repeatedGroup_.WriteTo(ref output, _repeated_repeatedGroup_codec); + if (_extensions != null) { + _extensions.WriteTo(ref output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -20580,6 +25172,52 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + } + break; + case 10: { + if (!HasRequiredAllTypes) { + RequiredAllTypes = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes(); + } + input.ReadMessage(RequiredAllTypes); + break; + } + case 18: { + if (!HasOptionalAllTypes) { + OptionalAllTypes = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes(); + } + input.ReadMessage(OptionalAllTypes); + break; + } + case 26: { + repeatedAllTypes_.AddEntriesFrom(ref input, _repeated_repeatedAllTypes_codec); + break; + } + case 83: { + if (!HasOptionalGroup) { + OptionalGroup = new global::Google.Protobuf.TestProtos.Proto2.TestParsingMerge.Types.OptionalGroup(); + } + input.ReadGroup(OptionalGroup); + break; + } + case 163: { + repeatedGroup_.AddEntriesFrom(ref input, _repeated_repeatedGroup_codec); + break; + } + } + } + } + #endif + public TValue GetExtension(pb::Extension extension) { return pb::ExtensionSet.Get(ref _extensions, extension); } @@ -20613,7 +25251,11 @@ public static partial class Types { /// Repeated fields in RepeatedFieldsGenerator are expected to be merged into /// the corresponding required/optional fields in TestParsingMerge. /// - public sealed partial class RepeatedFieldsGenerator : pb::IMessage { + public sealed partial class RepeatedFieldsGenerator : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new RepeatedFieldsGenerator()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -20781,6 +25423,23 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + field1_.WriteTo(ref output, _repeated_field1_codec); + field2_.WriteTo(ref output, _repeated_field2_codec); + field3_.WriteTo(ref output, _repeated_field3_codec); + group1_.WriteTo(ref output, _repeated_group1_codec); + group2_.WriteTo(ref output, _repeated_group2_codec); + ext1_.WriteTo(ref output, _repeated_ext1_codec); + ext2_.WriteTo(ref output, _repeated_ext2_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -20852,11 +25511,58 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + field1_.AddEntriesFrom(ref input, _repeated_field1_codec); + break; + } + case 18: { + field2_.AddEntriesFrom(ref input, _repeated_field2_codec); + break; + } + case 26: { + field3_.AddEntriesFrom(ref input, _repeated_field3_codec); + break; + } + case 83: { + group1_.AddEntriesFrom(ref input, _repeated_group1_codec); + break; + } + case 163: { + group2_.AddEntriesFrom(ref input, _repeated_group2_codec); + break; + } + case 8002: { + ext1_.AddEntriesFrom(ref input, _repeated_ext1_codec); + break; + } + case 8010: { + ext2_.AddEntriesFrom(ref input, _repeated_ext2_codec); + break; + } + } + } + } + #endif + #region Nested types /// Container for nested types declared in the RepeatedFieldsGenerator message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static partial class Types { - public sealed partial class Group1 : pb::IMessage { + public sealed partial class Group1 : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Group1()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -20954,6 +25660,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasField1) { + output.WriteRawTag(90); + output.WriteMessage(Field1); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -21001,9 +25721,37 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + case 84: + return; + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 90: { + if (!HasField1) { + Field1 = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes(); + } + input.ReadMessage(Field1); + break; + } + } + } + } + #endif + } - public sealed partial class Group2 : pb::IMessage { + public sealed partial class Group2 : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Group2()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -21101,6 +25849,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasField1) { + output.WriteRawTag(170, 1); + output.WriteMessage(Field1); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -21124,18 +25886,41 @@ public void MergeFrom(Group2 other) { } Field1.MergeFrom(other.Field1); } - _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + case 164: + return; + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 170: { + if (!HasField1) { + Field1 = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes(); + } + input.ReadMessage(Field1); + break; + } + } + } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void MergeFrom(pb::CodedInputStream input) { + public void MergeFrom(ref pb::CodedInputReader input) { uint tag; while ((tag = input.ReadTag()) != 0) { switch(tag) { case 164: return; default: - _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); break; case 170: { if (!HasField1) { @@ -21147,6 +25932,7 @@ public void MergeFrom(pb::CodedInputStream input) { } } } + #endif } @@ -21155,7 +25941,11 @@ public void MergeFrom(pb::CodedInputStream input) { } - public sealed partial class OptionalGroup : pb::IMessage { + public sealed partial class OptionalGroup : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new OptionalGroup()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -21253,6 +26043,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasOptionalGroupAllTypes) { + output.WriteRawTag(90); + output.WriteMessage(OptionalGroupAllTypes); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -21300,9 +26104,37 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + case 84: + return; + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 90: { + if (!HasOptionalGroupAllTypes) { + OptionalGroupAllTypes = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes(); + } + input.ReadMessage(OptionalGroupAllTypes); + break; + } + } + } + } + #endif + } - public sealed partial class RepeatedGroup : pb::IMessage { + public sealed partial class RepeatedGroup : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new RepeatedGroup()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -21400,6 +26232,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasRepeatedGroupAllTypes) { + output.WriteRawTag(170, 1); + output.WriteMessage(RepeatedGroupAllTypes); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -21447,6 +26293,30 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + case 164: + return; + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 170: { + if (!HasRepeatedGroupAllTypes) { + RepeatedGroupAllTypes = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes(); + } + input.ReadMessage(RepeatedGroupAllTypes); + break; + } + } + } + } + #endif + } } @@ -21465,7 +26335,11 @@ public static partial class Extensions { } - public sealed partial class TestCommentInjectionMessage : pb::IMessage { + public sealed partial class TestCommentInjectionMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestCommentInjectionMessage()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -21568,6 +26442,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasA) { + output.WriteRawTag(10); + output.WriteString(A); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -21607,12 +26495,35 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + A = input.ReadString(); + break; + } + } + } + } + #endif + } /// /// Test that RPC services work. /// - public sealed partial class FooRequest : pb::IMessage { + public sealed partial class FooRequest : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new FooRequest()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -21682,6 +26593,16 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -21711,9 +26632,28 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + } - public sealed partial class FooResponse : pb::IMessage { + public sealed partial class FooResponse : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new FooResponse()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -21783,6 +26723,16 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -21812,9 +26762,28 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + } - public sealed partial class FooClientMessage : pb::IMessage { + public sealed partial class FooClientMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new FooClientMessage()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -21884,6 +26853,16 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -21913,9 +26892,28 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + } - public sealed partial class FooServerMessage : pb::IMessage { + public sealed partial class FooServerMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new FooServerMessage()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -21985,6 +26983,16 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -22014,9 +27022,28 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + } - public sealed partial class BarRequest : pb::IMessage { + public sealed partial class BarRequest : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new BarRequest()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -22086,6 +27113,16 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -22115,9 +27152,28 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + } - public sealed partial class BarResponse : pb::IMessage { + public sealed partial class BarResponse : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new BarResponse()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -22187,6 +27243,16 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -22216,9 +27282,28 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + } - public sealed partial class TestJsonName : pb::IMessage { + public sealed partial class TestJsonName : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestJsonName()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -22476,6 +27561,40 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasFieldName1) { + output.WriteRawTag(8); + output.WriteInt32(FieldName1); + } + if (HasFieldName2) { + output.WriteRawTag(16); + output.WriteInt32(FieldName2); + } + if (HasFieldName3) { + output.WriteRawTag(24); + output.WriteInt32(FieldName3); + } + if (HasFieldName4) { + output.WriteRawTag(32); + output.WriteInt32(FieldName4); + } + if (HasFIELDNAME5) { + output.WriteRawTag(40); + output.WriteInt32(FIELDNAME5); + } + if (HasFieldName6) { + output.WriteRawTag(48); + output.WriteInt32(FieldName6); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -22526,16 +27645,54 @@ public void MergeFrom(TestJsonName other) { if (other.HasFieldName6) { FieldName6 = other.FieldName6; } - _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 8: { + FieldName1 = input.ReadInt32(); + break; + } + case 16: { + FieldName2 = input.ReadInt32(); + break; + } + case 24: { + FieldName3 = input.ReadInt32(); + break; + } + case 32: { + FieldName4 = input.ReadInt32(); + break; + } + case 40: { + FIELDNAME5 = input.ReadInt32(); + break; + } + case 48: { + FieldName6 = input.ReadInt32(); + break; + } + } + } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void MergeFrom(pb::CodedInputStream input) { + public void MergeFrom(ref pb::CodedInputReader input) { uint tag; while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); break; case 8: { FieldName1 = input.ReadInt32(); @@ -22564,10 +27721,15 @@ public void MergeFrom(pb::CodedInputStream input) { } } } + #endif } - public sealed partial class TestHugeFieldNumbers : pb::IExtendableMessage { + public sealed partial class TestHugeFieldNumbers : pb::IExtendableMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestHugeFieldNumbers()); private pb::UnknownFieldSet _unknownFields; private pb::ExtensionSet _extensions; @@ -23057,6 +28219,67 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasOptionalInt32) { + output.WriteRawTag(128, 199, 255, 255, 15); + output.WriteInt32(OptionalInt32); + } + if (HasFixed32) { + output.WriteRawTag(136, 199, 255, 255, 15); + output.WriteInt32(Fixed32); + } + repeatedInt32_.WriteTo(ref output, _repeated_repeatedInt32_codec); + packedInt32_.WriteTo(ref output, _repeated_packedInt32_codec); + if (HasOptionalEnum) { + output.WriteRawTag(160, 199, 255, 255, 15); + output.WriteEnum((int) OptionalEnum); + } + if (HasOptionalString) { + output.WriteRawTag(170, 199, 255, 255, 15); + output.WriteString(OptionalString); + } + if (HasOptionalBytes) { + output.WriteRawTag(178, 199, 255, 255, 15); + output.WriteBytes(OptionalBytes); + } + if (HasOptionalMessage) { + output.WriteRawTag(186, 199, 255, 255, 15); + output.WriteMessage(OptionalMessage); + } + if (HasOptionalGroup) { + output.WriteRawTag(195, 199, 255, 255, 15); + output.WriteGroup(OptionalGroup); + output.WriteRawTag(196, 199, 255, 255, 15); + } + stringStringMap_.WriteTo(ref output, _map_stringStringMap_codec); + if (HasOneofUint32) { + output.WriteRawTag(216, 199, 255, 255, 15); + output.WriteUInt32(OneofUint32); + } + if (HasOneofTestAllTypes) { + output.WriteRawTag(226, 199, 255, 255, 15); + output.WriteMessage(OneofTestAllTypes); + } + if (HasOneofString) { + output.WriteRawTag(234, 199, 255, 255, 15); + output.WriteString(OneofString); + } + if (HasOneofBytes) { + output.WriteRawTag(242, 199, 255, 255, 15); + output.WriteBytes(OneofBytes); + } + if (_extensions != null) { + _extensions.WriteTo(ref output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -23245,6 +28468,92 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + } + break; + case 4294960000: { + OptionalInt32 = input.ReadInt32(); + break; + } + case 4294960008: { + Fixed32 = input.ReadInt32(); + break; + } + case 4294960018: + case 4294960016: { + repeatedInt32_.AddEntriesFrom(ref input, _repeated_repeatedInt32_codec); + break; + } + case 4294960026: + case 4294960024: { + packedInt32_.AddEntriesFrom(ref input, _repeated_packedInt32_codec); + break; + } + case 4294960032: { + OptionalEnum = (global::Google.Protobuf.TestProtos.Proto2.ForeignEnum) input.ReadEnum(); + break; + } + case 4294960042: { + OptionalString = input.ReadString(); + break; + } + case 4294960050: { + OptionalBytes = input.ReadBytes(); + break; + } + case 4294960058: { + if (!HasOptionalMessage) { + OptionalMessage = new global::Google.Protobuf.TestProtos.Proto2.ForeignMessage(); + } + input.ReadMessage(OptionalMessage); + break; + } + case 4294960067: { + if (!HasOptionalGroup) { + OptionalGroup = new global::Google.Protobuf.TestProtos.Proto2.TestHugeFieldNumbers.Types.OptionalGroup(); + } + input.ReadGroup(OptionalGroup); + break; + } + case 4294960082: { + stringStringMap_.AddEntriesFrom(ref input, _map_stringStringMap_codec); + break; + } + case 4294960088: { + OneofUint32 = input.ReadUInt32(); + break; + } + case 4294960098: { + global::Google.Protobuf.TestProtos.Proto2.TestAllTypes subBuilder = new global::Google.Protobuf.TestProtos.Proto2.TestAllTypes(); + if (HasOneofTestAllTypes) { + subBuilder.MergeFrom(OneofTestAllTypes); + } + input.ReadMessage(subBuilder); + OneofTestAllTypes = subBuilder; + break; + } + case 4294960106: { + OneofString = input.ReadString(); + break; + } + case 4294960114: { + OneofBytes = input.ReadBytes(); + break; + } + } + } + } + #endif + public TValue GetExtension(pb::Extension extension) { return pb::ExtensionSet.Get(ref _extensions, extension); } @@ -23271,7 +28580,11 @@ public void ClearExtension(pb::RepeatedExtensionContainer for nested types declared in the TestHugeFieldNumbers message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static partial class Types { - public sealed partial class OptionalGroup : pb::IMessage { + public sealed partial class OptionalGroup : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new OptionalGroup()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -23374,6 +28687,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasGroupA) { + output.WriteRawTag(200, 199, 255, 255, 15); + output.WriteInt32(GroupA); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -23415,6 +28742,27 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + case 4294960068: + return; + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 4294960072: { + GroupA = input.ReadInt32(); + break; + } + } + } + } + #endif + } } @@ -23422,7 +28770,11 @@ public void MergeFrom(pb::CodedInputStream input) { } - public sealed partial class TestExtensionInsideTable : pb::IExtendableMessage { + public sealed partial class TestExtensionInsideTable : pb::IExtendableMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestExtensionInsideTable()); private pb::UnknownFieldSet _unknownFields; private pb::ExtensionSet _extensions; @@ -23785,6 +29137,55 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasField1) { + output.WriteRawTag(8); + output.WriteInt32(Field1); + } + if (HasField2) { + output.WriteRawTag(16); + output.WriteInt32(Field2); + } + if (HasField3) { + output.WriteRawTag(24); + output.WriteInt32(Field3); + } + if (HasField4) { + output.WriteRawTag(32); + output.WriteInt32(Field4); + } + if (HasField6) { + output.WriteRawTag(48); + output.WriteInt32(Field6); + } + if (HasField7) { + output.WriteRawTag(56); + output.WriteInt32(Field7); + } + if (HasField8) { + output.WriteRawTag(64); + output.WriteInt32(Field8); + } + if (HasField9) { + output.WriteRawTag(72); + output.WriteInt32(Field9); + } + if (HasField10) { + output.WriteRawTag(80); + output.WriteInt32(Field10); + } + if (_extensions != null) { + _extensions.WriteTo(ref output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -23910,6 +29311,59 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + } + break; + case 8: { + Field1 = input.ReadInt32(); + break; + } + case 16: { + Field2 = input.ReadInt32(); + break; + } + case 24: { + Field3 = input.ReadInt32(); + break; + } + case 32: { + Field4 = input.ReadInt32(); + break; + } + case 48: { + Field6 = input.ReadInt32(); + break; + } + case 56: { + Field7 = input.ReadInt32(); + break; + } + case 64: { + Field8 = input.ReadInt32(); + break; + } + case 72: { + Field9 = input.ReadInt32(); + break; + } + case 80: { + Field10 = input.ReadInt32(); + break; + } + } + } + } + #endif + public TValue GetExtension(pb::Extension extension) { return pb::ExtensionSet.Get(ref _extensions, extension); } diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestCustomOptionsProto3.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestCustomOptionsProto3.cs index cb5edf75472d..3b48aa8b6574 100644 --- a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestCustomOptionsProto3.cs +++ b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestCustomOptionsProto3.cs @@ -257,7 +257,11 @@ public enum AggregateEnum { /// A test message with custom options at all possible locations (and also some /// regular options, to make sure they interact nicely). /// - public sealed partial class TestMessageWithCustomOptions : pb::IMessage { + public sealed partial class TestMessageWithCustomOptions : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestMessageWithCustomOptions()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -388,6 +392,24 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Field1.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Field1); + } + if (anOneofCase_ == AnOneofOneofCase.OneofField) { + output.WriteRawTag(16); + output.WriteInt32(OneofField); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -440,6 +462,29 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Field1 = input.ReadString(); + break; + } + case 16: { + OneofField = input.ReadInt32(); + break; + } + } + } + } + #endif + #region Nested types /// Container for nested types declared in the TestMessageWithCustomOptions message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -459,7 +504,11 @@ public enum AnEnum { /// A test RPC service with custom options at all possible locations (and also /// some regular options, to make sure they interact nicely). /// - public sealed partial class CustomOptionFooRequest : pb::IMessage { + public sealed partial class CustomOptionFooRequest : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new CustomOptionFooRequest()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -529,6 +578,16 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -558,9 +617,28 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + } - public sealed partial class CustomOptionFooResponse : pb::IMessage { + public sealed partial class CustomOptionFooResponse : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new CustomOptionFooResponse()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -630,6 +708,16 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -659,9 +747,28 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + } - public sealed partial class CustomOptionFooClientMessage : pb::IMessage { + public sealed partial class CustomOptionFooClientMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new CustomOptionFooClientMessage()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -731,6 +838,16 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -760,9 +877,28 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + } - public sealed partial class CustomOptionFooServerMessage : pb::IMessage { + public sealed partial class CustomOptionFooServerMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new CustomOptionFooServerMessage()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -832,6 +968,16 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -861,9 +1007,28 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + } - public sealed partial class DummyMessageContainingEnum : pb::IMessage { + public sealed partial class DummyMessageContainingEnum : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new DummyMessageContainingEnum()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -933,6 +1098,16 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -962,6 +1137,21 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + #region Nested types /// Container for nested types declared in the DummyMessageContainingEnum message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -977,7 +1167,11 @@ public enum TestEnumType { } - public sealed partial class DummyMessageInvalidAsOptionType : pb::IMessage { + public sealed partial class DummyMessageInvalidAsOptionType : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new DummyMessageInvalidAsOptionType()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -1047,6 +1241,16 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -1076,9 +1280,28 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + } - public sealed partial class CustomOptionMinIntegerValues : pb::IMessage { + public sealed partial class CustomOptionMinIntegerValues : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new CustomOptionMinIntegerValues()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -1148,6 +1371,16 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -1177,9 +1410,28 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + } - public sealed partial class CustomOptionMaxIntegerValues : pb::IMessage { + public sealed partial class CustomOptionMaxIntegerValues : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new CustomOptionMaxIntegerValues()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -1249,6 +1501,16 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -1278,9 +1540,28 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + } - public sealed partial class CustomOptionOtherValues : pb::IMessage { + public sealed partial class CustomOptionOtherValues : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new CustomOptionOtherValues()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -1350,6 +1631,16 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -1379,9 +1670,28 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + } - public sealed partial class SettingRealsFromPositiveInts : pb::IMessage { + public sealed partial class SettingRealsFromPositiveInts : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new SettingRealsFromPositiveInts()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -1451,6 +1761,16 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -1480,9 +1800,28 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + } - public sealed partial class SettingRealsFromNegativeInts : pb::IMessage { + public sealed partial class SettingRealsFromNegativeInts : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new SettingRealsFromNegativeInts()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -1552,6 +1891,16 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -1581,9 +1930,28 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + } - public sealed partial class ComplexOptionType1 : pb::IMessage { + public sealed partial class ComplexOptionType1 : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ComplexOptionType1()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -1721,6 +2089,29 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Foo != 0) { + output.WriteRawTag(8); + output.WriteInt32(Foo); + } + if (Foo2 != 0) { + output.WriteRawTag(16); + output.WriteInt32(Foo2); + } + if (Foo3 != 0) { + output.WriteRawTag(24); + output.WriteInt32(Foo3); + } + foo4_.WriteTo(ref output, _repeated_foo4_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -1787,9 +2178,45 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Foo = input.ReadInt32(); + break; + } + case 16: { + Foo2 = input.ReadInt32(); + break; + } + case 24: { + Foo3 = input.ReadInt32(); + break; + } + case 34: + case 32: { + foo4_.AddEntriesFrom(ref input, _repeated_foo4_codec); + break; + } + } + } + } + #endif + } - public sealed partial class ComplexOptionType2 : pb::IMessage { + public sealed partial class ComplexOptionType2 : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ComplexOptionType2()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -1927,6 +2354,29 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (bar_ != null) { + output.WriteRawTag(10); + output.WriteMessage(Bar); + } + if (Baz != 0) { + output.WriteRawTag(16); + output.WriteInt32(Baz); + } + if (fred_ != null) { + output.WriteRawTag(26); + output.WriteMessage(Fred); + } + barney_.WriteTo(ref output, _repeated_barney_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -2004,11 +2454,52 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + if (bar_ == null) { + Bar = new global::UnitTest.Issues.TestProtos.ComplexOptionType1(); + } + input.ReadMessage(Bar); + break; + } + case 16: { + Baz = input.ReadInt32(); + break; + } + case 26: { + if (fred_ == null) { + Fred = new global::UnitTest.Issues.TestProtos.ComplexOptionType2.Types.ComplexOptionType4(); + } + input.ReadMessage(Fred); + break; + } + case 34: { + barney_.AddEntriesFrom(ref input, _repeated_barney_codec); + break; + } + } + } + } + #endif + #region Nested types /// Container for nested types declared in the ComplexOptionType2 message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static partial class Types { - public sealed partial class ComplexOptionType4 : pb::IMessage { + public sealed partial class ComplexOptionType4 : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ComplexOptionType4()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -2096,6 +2587,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Waldo != 0) { + output.WriteRawTag(8); + output.WriteInt32(Waldo); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -2135,6 +2640,25 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Waldo = input.ReadInt32(); + break; + } + } + } + } + #endif + #region Extensions /// Container for extensions for other messages declared in the ComplexOptionType4 message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -2151,7 +2675,11 @@ public static partial class Extensions { } - public sealed partial class ComplexOptionType3 : pb::IMessage { + public sealed partial class ComplexOptionType3 : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ComplexOptionType3()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -2239,6 +2767,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Qux != 0) { + output.WriteRawTag(8); + output.WriteInt32(Qux); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -2278,12 +2820,35 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Qux = input.ReadInt32(); + break; + } + } + } + } + #endif + } /// /// Note that we try various different ways of naming the same extension. /// - public sealed partial class VariousComplexOptions : pb::IMessage { + public sealed partial class VariousComplexOptions : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new VariousComplexOptions()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -2353,6 +2918,16 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -2382,12 +2957,31 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + } /// /// A helper type used to test aggregate option parsing /// - public sealed partial class Aggregate : pb::IMessage { + public sealed partial class Aggregate : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Aggregate()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -2514,6 +3108,28 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (I != 0) { + output.WriteRawTag(8); + output.WriteInt32(I); + } + if (S.Length != 0) { + output.WriteRawTag(18); + output.WriteString(S); + } + if (sub_ != null) { + output.WriteRawTag(26); + output.WriteMessage(Sub); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -2579,9 +3195,43 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + I = input.ReadInt32(); + break; + } + case 18: { + S = input.ReadString(); + break; + } + case 26: { + if (sub_ == null) { + Sub = new global::UnitTest.Issues.TestProtos.Aggregate(); + } + input.ReadMessage(Sub); + break; + } + } + } + } + #endif + } - public sealed partial class AggregateMessage : pb::IMessage { + public sealed partial class AggregateMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new AggregateMessage()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -2669,6 +3319,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Fieldname != 0) { + output.WriteRawTag(8); + output.WriteInt32(Fieldname); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -2708,12 +3372,35 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Fieldname = input.ReadInt32(); + break; + } + } + } + } + #endif + } /// /// Test custom options for nested type. /// - public sealed partial class NestedOptionType : pb::IMessage { + public sealed partial class NestedOptionType : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new NestedOptionType()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -2783,6 +3470,16 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -2812,6 +3509,21 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + #region Nested types /// Container for nested types declared in the NestedOptionType message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -2821,7 +3533,11 @@ public enum NestedEnum { [pbr::OriginalName("NESTED_ENUM_VALUE")] Value = 1, } - public sealed partial class NestedMessage : pb::IMessage { + public sealed partial class NestedMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new NestedMessage()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -2909,6 +3625,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (NestedField != 0) { + output.WriteRawTag(8); + output.WriteInt32(NestedField); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -2948,6 +3678,25 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + NestedField = input.ReadInt32(); + break; + } + } + } + } + #endif + } } diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImport.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImport.cs index d5f8589315e3..86e406127a32 100644 --- a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImport.cs +++ b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImport.cs @@ -59,7 +59,11 @@ public enum ImportEnumForMap { #endregion #region Messages - public sealed partial class ImportMessage : pb::IMessage { + public sealed partial class ImportMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ImportMessage()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -162,6 +166,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasD) { + output.WriteRawTag(8); + output.WriteInt32(D); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -201,6 +219,25 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + D = input.ReadInt32(); + break; + } + } + } + } + #endif + } #endregion diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportProto3.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportProto3.cs index 19a1a34634f9..778984ad40b5 100644 --- a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportProto3.cs +++ b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportProto3.cs @@ -50,7 +50,11 @@ public enum ImportEnum { #endregion #region Messages - public sealed partial class ImportMessage : pb::IMessage { + public sealed partial class ImportMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ImportMessage()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -138,6 +142,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (D != 0) { + output.WriteRawTag(8); + output.WriteInt32(D); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -177,6 +195,25 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + D = input.ReadInt32(); + break; + } + } + } + } + #endif + } #endregion diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportPublic.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportPublic.cs index 77f212176035..5d67d9a04a25 100644 --- a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportPublic.cs +++ b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportPublic.cs @@ -37,7 +37,11 @@ static UnittestImportPublicReflection() { } #region Messages - public sealed partial class PublicImportMessage : pb::IMessage { + public sealed partial class PublicImportMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new PublicImportMessage()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -140,6 +144,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasE) { + output.WriteRawTag(8); + output.WriteInt32(E); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -179,6 +197,25 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + E = input.ReadInt32(); + break; + } + } + } + } + #endif + } #endregion diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportPublicProto3.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportPublicProto3.cs index a45565546989..1ee7766435e0 100644 --- a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportPublicProto3.cs +++ b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportPublicProto3.cs @@ -38,7 +38,11 @@ static UnittestImportPublicProto3Reflection() { } #region Messages - public sealed partial class PublicImportMessage : pb::IMessage { + public sealed partial class PublicImportMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new PublicImportMessage()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -126,6 +130,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (E != 0) { + output.WriteRawTag(8); + output.WriteInt32(E); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -165,6 +183,25 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + E = input.ReadInt32(); + break; + } + } + } + } + #endif + } #endregion diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936B.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936B.cs index 6b816f739b82..f9c3c06f08bd 100644 --- a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936B.cs +++ b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936B.cs @@ -37,7 +37,11 @@ static UnittestIssue6936BReflection() { } #region Messages - public sealed partial class Foo : pb::IMessage { + public sealed partial class Foo : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Foo()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -107,6 +111,16 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -136,6 +150,21 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + } #endregion diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936C.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936C.cs index a8a73f6cb6ec..947857f58d4a 100644 --- a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936C.cs +++ b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936C.cs @@ -39,7 +39,11 @@ static UnittestIssue6936CReflection() { } #region Messages - public sealed partial class Bar : pb::IMessage { + public sealed partial class Bar : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Bar()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -127,6 +131,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (foo_ != null) { + output.WriteRawTag(10); + output.WriteMessage(Foo); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -172,6 +190,28 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + if (foo_ == null) { + Foo = new global::UnitTest.Issues.TestProtos.Foo(); + } + input.ReadMessage(Foo); + break; + } + } + } + } + #endif + } #endregion diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssues.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssues.cs index f3f40c6a70cf..cea81be2fe7d 100644 --- a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssues.cs +++ b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssues.cs @@ -88,7 +88,11 @@ public enum DeprecatedEnum { /// Issue 307: when generating doubly-nested types, any references /// should be of the form A.Types.B.Types.C. /// - public sealed partial class Issue307 : pb::IMessage { + public sealed partial class Issue307 : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Issue307()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -158,6 +162,16 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -187,11 +201,30 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + #region Nested types /// Container for nested types declared in the Issue307 message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static partial class Types { - public sealed partial class NestedOnce : pb::IMessage { + public sealed partial class NestedOnce : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new NestedOnce()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -261,6 +294,16 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -290,11 +333,30 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + #region Nested types /// Container for nested types declared in the NestedOnce message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static partial class Types { - public sealed partial class NestedTwice : pb::IMessage { + public sealed partial class NestedTwice : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new NestedTwice()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -364,6 +426,16 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -393,6 +465,21 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + } } @@ -405,7 +492,11 @@ public void MergeFrom(pb::CodedInputStream input) { } - public sealed partial class NegativeEnumMessage : pb::IMessage { + public sealed partial class NegativeEnumMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new NegativeEnumMessage()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -521,6 +612,22 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Value != global::UnitTest.Issues.TestProtos.NegativeEnum.Zero) { + output.WriteRawTag(8); + output.WriteEnum((int) Value); + } + values_.WriteTo(ref output, _repeated_values_codec); + packedValues_.WriteTo(ref output, _repeated_packedValues_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -574,9 +681,42 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Value = (global::UnitTest.Issues.TestProtos.NegativeEnum) input.ReadEnum(); + break; + } + case 18: + case 16: { + values_.AddEntriesFrom(ref input, _repeated_values_codec); + break; + } + case 26: + case 24: { + packedValues_.AddEntriesFrom(ref input, _repeated_packedValues_codec); + break; + } + } + } + } + #endif + } - public sealed partial class DeprecatedChild : pb::IMessage { + public sealed partial class DeprecatedChild : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new DeprecatedChild()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -646,6 +786,16 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -675,9 +825,28 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + } - public sealed partial class DeprecatedFieldsMessage : pb::IMessage { + public sealed partial class DeprecatedFieldsMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new DeprecatedFieldsMessage()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -849,6 +1018,31 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (PrimitiveValue != 0) { + output.WriteRawTag(8); + output.WriteInt32(PrimitiveValue); + } + primitiveArray_.WriteTo(ref output, _repeated_primitiveArray_codec); + if (messageValue_ != null) { + output.WriteRawTag(26); + output.WriteMessage(MessageValue); + } + messageArray_.WriteTo(ref output, _repeated_messageArray_codec); + if (EnumValue != global::UnitTest.Issues.TestProtos.DeprecatedEnum.DeprecatedZero) { + output.WriteRawTag(40); + output.WriteEnum((int) EnumValue); + } + enumArray_.WriteTo(ref output, _repeated_enumArray_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -934,12 +1128,60 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + PrimitiveValue = input.ReadInt32(); + break; + } + case 18: + case 16: { + primitiveArray_.AddEntriesFrom(ref input, _repeated_primitiveArray_codec); + break; + } + case 26: { + if (messageValue_ == null) { + MessageValue = new global::UnitTest.Issues.TestProtos.DeprecatedChild(); + } + input.ReadMessage(MessageValue); + break; + } + case 34: { + messageArray_.AddEntriesFrom(ref input, _repeated_messageArray_codec); + break; + } + case 40: { + EnumValue = (global::UnitTest.Issues.TestProtos.DeprecatedEnum) input.ReadEnum(); + break; + } + case 50: + case 48: { + enumArray_.AddEntriesFrom(ref input, _repeated_enumArray_codec); + break; + } + } + } + } + #endif + } /// /// Issue 45: http://code.google.com/p/protobuf-csharp-port/issues/detail?id=45 /// - public sealed partial class ItemField : pb::IMessage { + public sealed partial class ItemField : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ItemField()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -1027,6 +1269,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Item != 0) { + output.WriteRawTag(8); + output.WriteInt32(Item); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -1066,9 +1322,32 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Item = input.ReadInt32(); + break; + } + } + } + } + #endif + } - public sealed partial class ReservedNames : pb::IMessage { + public sealed partial class ReservedNames : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ReservedNames()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -1174,6 +1453,24 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Types_ != 0) { + output.WriteRawTag(8); + output.WriteInt32(Types_); + } + if (Descriptor_ != 0) { + output.WriteRawTag(16); + output.WriteInt32(Descriptor_); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -1223,6 +1520,29 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Types_ = input.ReadInt32(); + break; + } + case 16: { + Descriptor_ = input.ReadInt32(); + break; + } + } + } + } + #endif + #region Nested types /// Container for nested types declared in the ReservedNames message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -1230,7 +1550,11 @@ public static partial class Types { /// /// Force a nested type called Types /// - public sealed partial class SomeNestedType : pb::IMessage { + public sealed partial class SomeNestedType : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new SomeNestedType()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -1300,6 +1624,16 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -1329,6 +1663,21 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + } } @@ -1348,7 +1697,11 @@ public void MergeFrom(pb::CodedInputStream input) { /// Alternatively, consider just adding this to /// unittest_proto3.proto if multiple platforms want it. /// - public sealed partial class TestJsonFieldOrdering : pb::IMessage { + public sealed partial class TestJsonFieldOrdering : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestJsonFieldOrdering()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -1582,6 +1935,40 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (PlainString.Length != 0) { + output.WriteRawTag(10); + output.WriteString(PlainString); + } + if (o1Case_ == O1OneofCase.O1String) { + output.WriteRawTag(18); + output.WriteString(O1String); + } + if (o2Case_ == O2OneofCase.O2String) { + output.WriteRawTag(26); + output.WriteString(O2String); + } + if (PlainInt32 != 0) { + output.WriteRawTag(32); + output.WriteInt32(PlainInt32); + } + if (o1Case_ == O1OneofCase.O1Int32) { + output.WriteRawTag(40); + output.WriteInt32(O1Int32); + } + if (o2Case_ == O2OneofCase.O2Int32) { + output.WriteRawTag(48); + output.WriteInt32(O2Int32); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -1677,9 +2064,52 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + PlainString = input.ReadString(); + break; + } + case 18: { + O1String = input.ReadString(); + break; + } + case 26: { + O2String = input.ReadString(); + break; + } + case 32: { + PlainInt32 = input.ReadInt32(); + break; + } + case 40: { + O1Int32 = input.ReadInt32(); + break; + } + case 48: { + O2Int32 = input.ReadInt32(); + break; + } + } + } + } + #endif + } - public sealed partial class TestJsonName : pb::IMessage { + public sealed partial class TestJsonName : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestJsonName()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -1806,6 +2236,28 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Name.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Name); + } + if (Description.Length != 0) { + output.WriteRawTag(18); + output.WriteString(Description); + } + if (Guid.Length != 0) { + output.WriteRawTag(26); + output.WriteString(Guid); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -1865,6 +2317,33 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + Description = input.ReadString(); + break; + } + case 26: { + Guid = input.ReadString(); + break; + } + } + } + } + #endif + } /// @@ -1872,7 +2351,11 @@ public void MergeFrom(pb::CodedInputStream input) { /// oneof case, which is itself a message type, the submessages should /// be merged. /// - public sealed partial class OneofMerging : pb::IMessage { + public sealed partial class OneofMerging : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new OneofMerging()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -2006,6 +2489,24 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (valueCase_ == ValueOneofCase.Text) { + output.WriteRawTag(10); + output.WriteString(Text); + } + if (valueCase_ == ValueOneofCase.Nested) { + output.WriteRawTag(18); + output.WriteMessage(Nested); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -2066,11 +2567,43 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Text = input.ReadString(); + break; + } + case 18: { + global::UnitTest.Issues.TestProtos.OneofMerging.Types.Nested subBuilder = new global::UnitTest.Issues.TestProtos.OneofMerging.Types.Nested(); + if (valueCase_ == ValueOneofCase.Nested) { + subBuilder.MergeFrom(Nested); + } + input.ReadMessage(subBuilder); + Nested = subBuilder; + break; + } + } + } + } + #endif + #region Nested types /// Container for nested types declared in the OneofMerging message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static partial class Types { - public sealed partial class Nested : pb::IMessage { + public sealed partial class Nested : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Nested()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -2176,6 +2709,24 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (X != 0) { + output.WriteRawTag(8); + output.WriteInt32(X); + } + if (Y != 0) { + output.WriteRawTag(16); + output.WriteInt32(Y); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -2225,6 +2776,29 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + X = input.ReadInt32(); + break; + } + case 16: { + Y = input.ReadInt32(); + break; + } + } + } + } + #endif + } } diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3.cs index 3f01e38bb973..c3a238528ad6 100644 --- a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3.cs +++ b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3.cs @@ -254,7 +254,11 @@ public enum CommentEnum { /// This proto includes every type of field in both singular and repeated /// forms. /// - public sealed partial class TestAllTypes : pb::IMessage { + public sealed partial class TestAllTypes : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestAllTypes()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -1146,6 +1150,142 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (SingleInt32 != 0) { + output.WriteRawTag(8); + output.WriteInt32(SingleInt32); + } + if (SingleInt64 != 0L) { + output.WriteRawTag(16); + output.WriteInt64(SingleInt64); + } + if (SingleUint32 != 0) { + output.WriteRawTag(24); + output.WriteUInt32(SingleUint32); + } + if (SingleUint64 != 0UL) { + output.WriteRawTag(32); + output.WriteUInt64(SingleUint64); + } + if (SingleSint32 != 0) { + output.WriteRawTag(40); + output.WriteSInt32(SingleSint32); + } + if (SingleSint64 != 0L) { + output.WriteRawTag(48); + output.WriteSInt64(SingleSint64); + } + if (SingleFixed32 != 0) { + output.WriteRawTag(61); + output.WriteFixed32(SingleFixed32); + } + if (SingleFixed64 != 0UL) { + output.WriteRawTag(65); + output.WriteFixed64(SingleFixed64); + } + if (SingleSfixed32 != 0) { + output.WriteRawTag(77); + output.WriteSFixed32(SingleSfixed32); + } + if (SingleSfixed64 != 0L) { + output.WriteRawTag(81); + output.WriteSFixed64(SingleSfixed64); + } + if (SingleFloat != 0F) { + output.WriteRawTag(93); + output.WriteFloat(SingleFloat); + } + if (SingleDouble != 0D) { + output.WriteRawTag(97); + output.WriteDouble(SingleDouble); + } + if (SingleBool != false) { + output.WriteRawTag(104); + output.WriteBool(SingleBool); + } + if (SingleString.Length != 0) { + output.WriteRawTag(114); + output.WriteString(SingleString); + } + if (SingleBytes.Length != 0) { + output.WriteRawTag(122); + output.WriteBytes(SingleBytes); + } + if (singleNestedMessage_ != null) { + output.WriteRawTag(146, 1); + output.WriteMessage(SingleNestedMessage); + } + if (singleForeignMessage_ != null) { + output.WriteRawTag(154, 1); + output.WriteMessage(SingleForeignMessage); + } + if (singleImportMessage_ != null) { + output.WriteRawTag(162, 1); + output.WriteMessage(SingleImportMessage); + } + if (SingleNestedEnum != global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedEnum.Unspecified) { + output.WriteRawTag(168, 1); + output.WriteEnum((int) SingleNestedEnum); + } + if (SingleForeignEnum != global::Google.Protobuf.TestProtos.ForeignEnum.ForeignUnspecified) { + output.WriteRawTag(176, 1); + output.WriteEnum((int) SingleForeignEnum); + } + if (SingleImportEnum != global::Google.Protobuf.TestProtos.ImportEnum.Unspecified) { + output.WriteRawTag(184, 1); + output.WriteEnum((int) SingleImportEnum); + } + if (singlePublicImportMessage_ != null) { + output.WriteRawTag(210, 1); + output.WriteMessage(SinglePublicImportMessage); + } + repeatedInt32_.WriteTo(ref output, _repeated_repeatedInt32_codec); + repeatedInt64_.WriteTo(ref output, _repeated_repeatedInt64_codec); + repeatedUint32_.WriteTo(ref output, _repeated_repeatedUint32_codec); + repeatedUint64_.WriteTo(ref output, _repeated_repeatedUint64_codec); + repeatedSint32_.WriteTo(ref output, _repeated_repeatedSint32_codec); + repeatedSint64_.WriteTo(ref output, _repeated_repeatedSint64_codec); + repeatedFixed32_.WriteTo(ref output, _repeated_repeatedFixed32_codec); + repeatedFixed64_.WriteTo(ref output, _repeated_repeatedFixed64_codec); + repeatedSfixed32_.WriteTo(ref output, _repeated_repeatedSfixed32_codec); + repeatedSfixed64_.WriteTo(ref output, _repeated_repeatedSfixed64_codec); + repeatedFloat_.WriteTo(ref output, _repeated_repeatedFloat_codec); + repeatedDouble_.WriteTo(ref output, _repeated_repeatedDouble_codec); + repeatedBool_.WriteTo(ref output, _repeated_repeatedBool_codec); + repeatedString_.WriteTo(ref output, _repeated_repeatedString_codec); + repeatedBytes_.WriteTo(ref output, _repeated_repeatedBytes_codec); + repeatedNestedMessage_.WriteTo(ref output, _repeated_repeatedNestedMessage_codec); + repeatedForeignMessage_.WriteTo(ref output, _repeated_repeatedForeignMessage_codec); + repeatedImportMessage_.WriteTo(ref output, _repeated_repeatedImportMessage_codec); + repeatedNestedEnum_.WriteTo(ref output, _repeated_repeatedNestedEnum_codec); + 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) { + output.WriteRawTag(248, 6); + output.WriteUInt32(OneofUint32); + } + if (oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage) { + output.WriteRawTag(130, 7); + output.WriteMessage(OneofNestedMessage); + } + if (oneofFieldCase_ == OneofFieldOneofCase.OneofString) { + output.WriteRawTag(138, 7); + output.WriteString(OneofString); + } + if (oneofFieldCase_ == OneofFieldOneofCase.OneofBytes) { + output.WriteRawTag(146, 7); + output.WriteBytes(OneofBytes); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -1618,6 +1758,246 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + SingleInt32 = input.ReadInt32(); + break; + } + case 16: { + SingleInt64 = input.ReadInt64(); + break; + } + case 24: { + SingleUint32 = input.ReadUInt32(); + break; + } + case 32: { + SingleUint64 = input.ReadUInt64(); + break; + } + case 40: { + SingleSint32 = input.ReadSInt32(); + break; + } + case 48: { + SingleSint64 = input.ReadSInt64(); + break; + } + case 61: { + SingleFixed32 = input.ReadFixed32(); + break; + } + case 65: { + SingleFixed64 = input.ReadFixed64(); + break; + } + case 77: { + SingleSfixed32 = input.ReadSFixed32(); + break; + } + case 81: { + SingleSfixed64 = input.ReadSFixed64(); + break; + } + case 93: { + SingleFloat = input.ReadFloat(); + break; + } + case 97: { + SingleDouble = input.ReadDouble(); + break; + } + case 104: { + SingleBool = input.ReadBool(); + break; + } + case 114: { + SingleString = input.ReadString(); + break; + } + case 122: { + SingleBytes = input.ReadBytes(); + break; + } + case 146: { + if (singleNestedMessage_ == null) { + SingleNestedMessage = new global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedMessage(); + } + input.ReadMessage(SingleNestedMessage); + break; + } + case 154: { + if (singleForeignMessage_ == null) { + SingleForeignMessage = new global::Google.Protobuf.TestProtos.ForeignMessage(); + } + input.ReadMessage(SingleForeignMessage); + break; + } + case 162: { + if (singleImportMessage_ == null) { + SingleImportMessage = new global::Google.Protobuf.TestProtos.ImportMessage(); + } + input.ReadMessage(SingleImportMessage); + break; + } + case 168: { + SingleNestedEnum = (global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedEnum) input.ReadEnum(); + break; + } + case 176: { + SingleForeignEnum = (global::Google.Protobuf.TestProtos.ForeignEnum) input.ReadEnum(); + break; + } + case 184: { + SingleImportEnum = (global::Google.Protobuf.TestProtos.ImportEnum) input.ReadEnum(); + break; + } + case 210: { + if (singlePublicImportMessage_ == null) { + SinglePublicImportMessage = new global::Google.Protobuf.TestProtos.PublicImportMessage(); + } + input.ReadMessage(SinglePublicImportMessage); + break; + } + case 250: + case 248: { + repeatedInt32_.AddEntriesFrom(ref input, _repeated_repeatedInt32_codec); + break; + } + case 258: + case 256: { + repeatedInt64_.AddEntriesFrom(ref input, _repeated_repeatedInt64_codec); + break; + } + case 266: + case 264: { + repeatedUint32_.AddEntriesFrom(ref input, _repeated_repeatedUint32_codec); + break; + } + case 274: + case 272: { + repeatedUint64_.AddEntriesFrom(ref input, _repeated_repeatedUint64_codec); + break; + } + case 282: + case 280: { + repeatedSint32_.AddEntriesFrom(ref input, _repeated_repeatedSint32_codec); + break; + } + case 290: + case 288: { + repeatedSint64_.AddEntriesFrom(ref input, _repeated_repeatedSint64_codec); + break; + } + case 298: + case 301: { + repeatedFixed32_.AddEntriesFrom(ref input, _repeated_repeatedFixed32_codec); + break; + } + case 306: + case 305: { + repeatedFixed64_.AddEntriesFrom(ref input, _repeated_repeatedFixed64_codec); + break; + } + case 314: + case 317: { + repeatedSfixed32_.AddEntriesFrom(ref input, _repeated_repeatedSfixed32_codec); + break; + } + case 322: + case 321: { + repeatedSfixed64_.AddEntriesFrom(ref input, _repeated_repeatedSfixed64_codec); + break; + } + case 330: + case 333: { + repeatedFloat_.AddEntriesFrom(ref input, _repeated_repeatedFloat_codec); + break; + } + case 338: + case 337: { + repeatedDouble_.AddEntriesFrom(ref input, _repeated_repeatedDouble_codec); + break; + } + case 346: + case 344: { + repeatedBool_.AddEntriesFrom(ref input, _repeated_repeatedBool_codec); + break; + } + case 354: { + repeatedString_.AddEntriesFrom(ref input, _repeated_repeatedString_codec); + break; + } + case 362: { + repeatedBytes_.AddEntriesFrom(ref input, _repeated_repeatedBytes_codec); + break; + } + case 386: { + repeatedNestedMessage_.AddEntriesFrom(ref input, _repeated_repeatedNestedMessage_codec); + break; + } + case 394: { + repeatedForeignMessage_.AddEntriesFrom(ref input, _repeated_repeatedForeignMessage_codec); + break; + } + case 402: { + repeatedImportMessage_.AddEntriesFrom(ref input, _repeated_repeatedImportMessage_codec); + break; + } + case 410: + case 408: { + repeatedNestedEnum_.AddEntriesFrom(ref input, _repeated_repeatedNestedEnum_codec); + break; + } + case 418: + case 416: { + repeatedForeignEnum_.AddEntriesFrom(ref input, _repeated_repeatedForeignEnum_codec); + break; + } + case 426: + case 424: { + repeatedImportEnum_.AddEntriesFrom(ref input, _repeated_repeatedImportEnum_codec); + break; + } + case 434: { + repeatedPublicImportMessage_.AddEntriesFrom(ref input, _repeated_repeatedPublicImportMessage_codec); + break; + } + case 888: { + OneofUint32 = input.ReadUInt32(); + break; + } + case 898: { + global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedMessage subBuilder = new global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedMessage(); + if (oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage) { + subBuilder.MergeFrom(OneofNestedMessage); + } + input.ReadMessage(subBuilder); + OneofNestedMessage = subBuilder; + break; + } + case 906: { + OneofString = input.ReadString(); + break; + } + case 914: { + OneofBytes = input.ReadBytes(); + break; + } + } + } + } + #endif + #region Nested types /// Container for nested types declared in the TestAllTypes message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -1633,7 +2013,11 @@ public enum NestedEnum { [pbr::OriginalName("NEG")] Neg = -1, } - public sealed partial class NestedMessage : pb::IMessage { + public sealed partial class NestedMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new NestedMessage()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -1726,6 +2110,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Bb != 0) { + output.WriteRawTag(8); + output.WriteInt32(Bb); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -1765,6 +2163,25 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Bb = input.ReadInt32(); + break; + } + } + } + } + #endif + } } @@ -1775,7 +2192,11 @@ public void MergeFrom(pb::CodedInputStream input) { /// /// This proto includes a recursively nested message. /// - public sealed partial class NestedTestAllTypes : pb::IMessage { + public sealed partial class NestedTestAllTypes : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new NestedTestAllTypes()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -1895,6 +2316,25 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (child_ != null) { + output.WriteRawTag(10); + output.WriteMessage(Child); + } + if (payload_ != null) { + output.WriteRawTag(18); + output.WriteMessage(Payload); + } + repeatedChild_.WriteTo(ref output, _repeated_repeatedChild_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -1962,9 +2402,46 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + if (child_ == null) { + Child = new global::Google.Protobuf.TestProtos.NestedTestAllTypes(); + } + input.ReadMessage(Child); + break; + } + case 18: { + if (payload_ == null) { + Payload = new global::Google.Protobuf.TestProtos.TestAllTypes(); + } + input.ReadMessage(Payload); + break; + } + case 26: { + repeatedChild_.AddEntriesFrom(ref input, _repeated_repeatedChild_codec); + break; + } + } + } + } + #endif + } - public sealed partial class TestDeprecatedFields : pb::IMessage { + public sealed partial class TestDeprecatedFields : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestDeprecatedFields()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -2053,6 +2530,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (DeprecatedInt32 != 0) { + output.WriteRawTag(8); + output.WriteInt32(DeprecatedInt32); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -2092,13 +2583,36 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + DeprecatedInt32 = input.ReadInt32(); + break; + } + } + } + } + #endif + } /// /// Define these after TestAllTypes to make sure the compiler can handle /// that. /// - public sealed partial class ForeignMessage : pb::IMessage { + public sealed partial class ForeignMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ForeignMessage()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -2186,6 +2700,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (C != 0) { + output.WriteRawTag(8); + output.WriteInt32(C); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -2225,9 +2753,32 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + C = input.ReadInt32(); + break; + } + } + } + } + #endif + } - public sealed partial class TestReservedFields : pb::IMessage { + public sealed partial class TestReservedFields : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestReservedFields()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -2297,6 +2848,16 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -2326,12 +2887,31 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + } /// /// Test that we can use NestedMessage from outside TestAllTypes. /// - public sealed partial class TestForeignNested : pb::IMessage { + public sealed partial class TestForeignNested : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestForeignNested()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -2419,6 +2999,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (foreignNested_ != null) { + output.WriteRawTag(10); + output.WriteMessage(ForeignNested); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -2464,12 +3058,38 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + if (foreignNested_ == null) { + ForeignNested = new global::Google.Protobuf.TestProtos.TestAllTypes.Types.NestedMessage(); + } + input.ReadMessage(ForeignNested); + break; + } + } + } + } + #endif + } /// /// Test that really large tag numbers don't break anything. /// - public sealed partial class TestReallyLargeTagNumber : pb::IMessage { + public sealed partial class TestReallyLargeTagNumber : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestReallyLargeTagNumber()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -2554,18 +3174,35 @@ public override int GetHashCode() { if (A != 0) hash ^= A.GetHashCode(); if (Bb != 0) hash ^= Bb.GetHashCode(); if (_unknownFields != null) { - hash ^= _unknownFields.GetHashCode(); + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + if (A != 0) { + output.WriteRawTag(8); + output.WriteInt32(A); + } + if (Bb != 0) { + output.WriteRawTag(248, 255, 255, 255, 7); + output.WriteInt32(Bb); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); } - return hash; } - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public override string ToString() { - return pb::JsonFormatter.ToDiagnosticString(this); - } + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void WriteTo(pb::CodedOutputStream output) { + public void WriteTo(ref pb::CodedOutputWriter output) { if (A != 0) { output.WriteRawTag(8); output.WriteInt32(A); @@ -2575,9 +3212,10 @@ public void WriteTo(pb::CodedOutputStream output) { output.WriteInt32(Bb); } if (_unknownFields != null) { - _unknownFields.WriteTo(output); + _unknownFields.WriteTo(ref output); } } + #endif [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { @@ -2628,9 +3266,36 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + A = input.ReadInt32(); + break; + } + case 2147483640: { + Bb = input.ReadInt32(); + break; + } + } + } + } + #endif + } - public sealed partial class TestRecursiveMessage : pb::IMessage { + public sealed partial class TestRecursiveMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestRecursiveMessage()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -2736,6 +3401,24 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (a_ != null) { + output.WriteRawTag(10); + output.WriteMessage(A); + } + if (I != 0) { + output.WriteRawTag(16); + output.WriteInt32(I); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -2791,12 +3474,42 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + if (a_ == null) { + A = new global::Google.Protobuf.TestProtos.TestRecursiveMessage(); + } + input.ReadMessage(A); + break; + } + case 16: { + I = input.ReadInt32(); + break; + } + } + } + } + #endif + } /// /// Test that mutual recursion works. /// - public sealed partial class TestMutualRecursionA : pb::IMessage { + public sealed partial class TestMutualRecursionA : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestMutualRecursionA()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -2884,6 +3597,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (bb_ != null) { + output.WriteRawTag(10); + output.WriteMessage(Bb); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -2929,9 +3656,35 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + if (bb_ == null) { + Bb = new global::Google.Protobuf.TestProtos.TestMutualRecursionB(); + } + input.ReadMessage(Bb); + break; + } + } + } + } + #endif + } - public sealed partial class TestMutualRecursionB : pb::IMessage { + public sealed partial class TestMutualRecursionB : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestMutualRecursionB()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -3037,6 +3790,24 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (a_ != null) { + output.WriteRawTag(10); + output.WriteMessage(A); + } + if (OptionalInt32 != 0) { + output.WriteRawTag(16); + output.WriteInt32(OptionalInt32); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -3092,9 +3863,39 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + if (a_ == null) { + A = new global::Google.Protobuf.TestProtos.TestMutualRecursionA(); + } + input.ReadMessage(A); + break; + } + case 16: { + OptionalInt32 = input.ReadInt32(); + break; + } + } + } + } + #endif + } - public sealed partial class TestEnumAllowAlias : pb::IMessage { + public sealed partial class TestEnumAllowAlias : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestEnumAllowAlias()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -3182,6 +3983,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Value != global::Google.Protobuf.TestProtos.TestEnumWithDupValue.Unspecified) { + output.WriteRawTag(8); + output.WriteEnum((int) Value); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -3221,13 +4036,36 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Value = (global::Google.Protobuf.TestProtos.TestEnumWithDupValue) input.ReadEnum(); + break; + } + } + } + } + #endif + } /// /// Test message with CamelCase field names. This violates Protocol Buffer /// standard style. /// - public sealed partial class TestCamelCaseFieldNames : pb::IMessage { + public sealed partial class TestCamelCaseFieldNames : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestCamelCaseFieldNames()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -3425,6 +4263,36 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (PrimitiveField != 0) { + output.WriteRawTag(8); + output.WriteInt32(PrimitiveField); + } + if (StringField.Length != 0) { + output.WriteRawTag(18); + output.WriteString(StringField); + } + if (EnumField != global::Google.Protobuf.TestProtos.ForeignEnum.ForeignUnspecified) { + output.WriteRawTag(24); + output.WriteEnum((int) EnumField); + } + if (messageField_ != null) { + output.WriteRawTag(34); + output.WriteMessage(MessageField); + } + repeatedPrimitiveField_.WriteTo(ref output, _repeated_repeatedPrimitiveField_codec); + repeatedStringField_.WriteTo(ref output, _repeated_repeatedStringField_codec); + repeatedEnumField_.WriteTo(ref output, _repeated_repeatedEnumField_codec); + repeatedMessageField_.WriteTo(ref output, _repeated_repeatedMessageField_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -3526,13 +4394,69 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + PrimitiveField = input.ReadInt32(); + break; + } + case 18: { + StringField = input.ReadString(); + break; + } + case 24: { + EnumField = (global::Google.Protobuf.TestProtos.ForeignEnum) input.ReadEnum(); + break; + } + case 34: { + if (messageField_ == null) { + MessageField = new global::Google.Protobuf.TestProtos.ForeignMessage(); + } + input.ReadMessage(MessageField); + break; + } + case 58: + case 56: { + repeatedPrimitiveField_.AddEntriesFrom(ref input, _repeated_repeatedPrimitiveField_codec); + break; + } + case 66: { + repeatedStringField_.AddEntriesFrom(ref input, _repeated_repeatedStringField_codec); + break; + } + case 74: + case 72: { + repeatedEnumField_.AddEntriesFrom(ref input, _repeated_repeatedEnumField_codec); + break; + } + case 82: { + repeatedMessageField_.AddEntriesFrom(ref input, _repeated_repeatedMessageField_codec); + break; + } + } + } + } + #endif + } /// /// We list fields out of order, to ensure that we're using field number and not /// field index to determine serialization order. /// - public sealed partial class TestFieldOrderings : pb::IMessage { + public sealed partial class TestFieldOrderings : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestFieldOrderings()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -3674,6 +4598,32 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (MyInt != 0L) { + output.WriteRawTag(8); + output.WriteInt64(MyInt); + } + if (MyString.Length != 0) { + output.WriteRawTag(90); + output.WriteString(MyString); + } + if (MyFloat != 0F) { + output.WriteRawTag(173, 6); + output.WriteFloat(MyFloat); + } + if (singleNestedMessage_ != null) { + output.WriteRawTag(194, 12); + output.WriteMessage(SingleNestedMessage); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -3713,18 +4663,51 @@ public void MergeFrom(TestFieldOrderings other) { if (singleNestedMessage_ == null) { SingleNestedMessage = new global::Google.Protobuf.TestProtos.TestFieldOrderings.Types.NestedMessage(); } - SingleNestedMessage.MergeFrom(other.SingleNestedMessage); + SingleNestedMessage.MergeFrom(other.SingleNestedMessage); + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 8: { + MyInt = input.ReadInt64(); + break; + } + case 90: { + MyString = input.ReadString(); + break; + } + case 813: { + MyFloat = input.ReadFloat(); + break; + } + case 1602: { + if (singleNestedMessage_ == null) { + SingleNestedMessage = new global::Google.Protobuf.TestProtos.TestFieldOrderings.Types.NestedMessage(); + } + input.ReadMessage(SingleNestedMessage); + break; + } + } } - _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void MergeFrom(pb::CodedInputStream input) { + public void MergeFrom(ref pb::CodedInputReader input) { uint tag; while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); break; case 8: { MyInt = input.ReadInt64(); @@ -3748,12 +4731,17 @@ public void MergeFrom(pb::CodedInputStream input) { } } } + #endif #region Nested types /// Container for nested types declared in the TestFieldOrderings message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static partial class Types { - public sealed partial class NestedMessage : pb::IMessage { + public sealed partial class NestedMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new NestedMessage()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -3864,6 +4852,24 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Bb != 0) { + output.WriteRawTag(8); + output.WriteInt32(Bb); + } + if (Oo != 0L) { + output.WriteRawTag(16); + output.WriteInt64(Oo); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -3913,6 +4919,29 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Bb = input.ReadInt32(); + break; + } + case 16: { + Oo = input.ReadInt64(); + break; + } + } + } + } + #endif + } } @@ -3920,7 +4949,11 @@ public void MergeFrom(pb::CodedInputStream input) { } - public sealed partial class SparseEnumMessage : pb::IMessage { + public sealed partial class SparseEnumMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new SparseEnumMessage()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -4008,6 +5041,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (SparseEnum != global::Google.Protobuf.TestProtos.TestSparseEnum.Unspecified) { + output.WriteRawTag(8); + output.WriteEnum((int) SparseEnum); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -4047,12 +5094,35 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + SparseEnum = (global::Google.Protobuf.TestProtos.TestSparseEnum) input.ReadEnum(); + break; + } + } + } + } + #endif + } /// /// Test String and Bytes: string is for valid UTF-8 strings /// - public sealed partial class OneString : pb::IMessage { + public sealed partial class OneString : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new OneString()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -4140,6 +5210,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Data.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Data); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -4179,9 +5263,32 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Data = input.ReadString(); + break; + } + } + } + } + #endif + } - public sealed partial class MoreString : pb::IMessage { + public sealed partial class MoreString : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new MoreString()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -4265,6 +5372,17 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + data_.WriteTo(ref output, _repeated_data_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -4300,9 +5418,32 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + data_.AddEntriesFrom(ref input, _repeated_data_codec); + break; + } + } + } + } + #endif + } - public sealed partial class OneBytes : pb::IMessage { + public sealed partial class OneBytes : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new OneBytes()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -4390,6 +5531,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Data.Length != 0) { + output.WriteRawTag(10); + output.WriteBytes(Data); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -4429,9 +5584,32 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Data = input.ReadBytes(); + break; + } + } + } + } + #endif + } - public sealed partial class MoreBytes : pb::IMessage { + public sealed partial class MoreBytes : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new MoreBytes()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -4519,6 +5697,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Data.Length != 0) { + output.WriteRawTag(10); + output.WriteBytes(Data); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -4558,12 +5750,35 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Data = input.ReadBytes(); + break; + } + } + } + } + #endif + } /// /// Test int32, uint32, int64, uint64, and bool are all compatible /// - public sealed partial class Int32Message : pb::IMessage { + public sealed partial class Int32Message : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Int32Message()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -4651,6 +5866,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Data != 0) { + output.WriteRawTag(8); + output.WriteInt32(Data); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -4690,9 +5919,32 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Data = input.ReadInt32(); + break; + } + } + } + } + #endif + } - public sealed partial class Uint32Message : pb::IMessage { + public sealed partial class Uint32Message : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Uint32Message()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -4780,6 +6032,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Data != 0) { + output.WriteRawTag(8); + output.WriteUInt32(Data); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -4819,9 +6085,32 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Data = input.ReadUInt32(); + break; + } + } + } + } + #endif + } - public sealed partial class Int64Message : pb::IMessage { + public sealed partial class Int64Message : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Int64Message()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -4909,6 +6198,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Data != 0L) { + output.WriteRawTag(8); + output.WriteInt64(Data); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -4933,12 +6236,30 @@ public void MergeFrom(Int64Message other) { } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void MergeFrom(pb::CodedInputStream input) { + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 8: { + Data = input.ReadInt64(); + break; + } + } + } + } + + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { uint tag; while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); break; case 8: { Data = input.ReadInt64(); @@ -4947,10 +6268,15 @@ public void MergeFrom(pb::CodedInputStream input) { } } } + #endif } - public sealed partial class Uint64Message : pb::IMessage { + public sealed partial class Uint64Message : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Uint64Message()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -5038,6 +6364,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Data != 0UL) { + output.WriteRawTag(8); + output.WriteUInt64(Data); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -5077,9 +6417,32 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Data = input.ReadUInt64(); + break; + } + } + } + } + #endif + } - public sealed partial class BoolMessage : pb::IMessage { + public sealed partial class BoolMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new BoolMessage()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -5167,6 +6530,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Data != false) { + output.WriteRawTag(8); + output.WriteBool(Data); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -5206,12 +6583,35 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Data = input.ReadBool(); + break; + } + } + } + } + #endif + } /// /// Test oneofs. /// - public sealed partial class TestOneof : pb::IMessage { + public sealed partial class TestOneof : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestOneof()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -5366,6 +6766,28 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (fooCase_ == FooOneofCase.FooInt) { + output.WriteRawTag(8); + output.WriteInt32(FooInt); + } + if (fooCase_ == FooOneofCase.FooString) { + output.WriteRawTag(18); + output.WriteString(FooString); + } + if (fooCase_ == FooOneofCase.FooMessage) { + output.WriteRawTag(26); + output.WriteMessage(FooMessage); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -5436,9 +6858,45 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + FooInt = input.ReadInt32(); + break; + } + case 18: { + FooString = input.ReadString(); + break; + } + case 26: { + global::Google.Protobuf.TestProtos.TestAllTypes subBuilder = new global::Google.Protobuf.TestProtos.TestAllTypes(); + if (fooCase_ == FooOneofCase.FooMessage) { + subBuilder.MergeFrom(FooMessage); + } + input.ReadMessage(subBuilder); + FooMessage = subBuilder; + break; + } + } + } + } + #endif + } - public sealed partial class TestPackedTypes : pb::IMessage { + public sealed partial class TestPackedTypes : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestPackedTypes()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -5704,6 +7162,30 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + packedInt32_.WriteTo(ref output, _repeated_packedInt32_codec); + packedInt64_.WriteTo(ref output, _repeated_packedInt64_codec); + packedUint32_.WriteTo(ref output, _repeated_packedUint32_codec); + packedUint64_.WriteTo(ref output, _repeated_packedUint64_codec); + packedSint32_.WriteTo(ref output, _repeated_packedSint32_codec); + packedSint64_.WriteTo(ref output, _repeated_packedSint64_codec); + packedFixed32_.WriteTo(ref output, _repeated_packedFixed32_codec); + packedFixed64_.WriteTo(ref output, _repeated_packedFixed64_codec); + packedSfixed32_.WriteTo(ref output, _repeated_packedSfixed32_codec); + packedSfixed64_.WriteTo(ref output, _repeated_packedSfixed64_codec); + packedFloat_.WriteTo(ref output, _repeated_packedFloat_codec); + packedDouble_.WriteTo(ref output, _repeated_packedDouble_codec); + packedBool_.WriteTo(ref output, _repeated_packedBool_codec); + packedEnum_.WriteTo(ref output, _repeated_packedEnum_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -5831,13 +7313,102 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 722: + case 720: { + packedInt32_.AddEntriesFrom(ref input, _repeated_packedInt32_codec); + break; + } + case 730: + case 728: { + packedInt64_.AddEntriesFrom(ref input, _repeated_packedInt64_codec); + break; + } + case 738: + case 736: { + packedUint32_.AddEntriesFrom(ref input, _repeated_packedUint32_codec); + break; + } + case 746: + case 744: { + packedUint64_.AddEntriesFrom(ref input, _repeated_packedUint64_codec); + break; + } + case 754: + case 752: { + packedSint32_.AddEntriesFrom(ref input, _repeated_packedSint32_codec); + break; + } + case 762: + case 760: { + packedSint64_.AddEntriesFrom(ref input, _repeated_packedSint64_codec); + break; + } + case 770: + case 773: { + packedFixed32_.AddEntriesFrom(ref input, _repeated_packedFixed32_codec); + break; + } + case 778: + case 777: { + packedFixed64_.AddEntriesFrom(ref input, _repeated_packedFixed64_codec); + break; + } + case 786: + case 789: { + packedSfixed32_.AddEntriesFrom(ref input, _repeated_packedSfixed32_codec); + break; + } + case 794: + case 793: { + packedSfixed64_.AddEntriesFrom(ref input, _repeated_packedSfixed64_codec); + break; + } + case 802: + case 805: { + packedFloat_.AddEntriesFrom(ref input, _repeated_packedFloat_codec); + break; + } + case 810: + case 809: { + packedDouble_.AddEntriesFrom(ref input, _repeated_packedDouble_codec); + break; + } + case 818: + case 816: { + packedBool_.AddEntriesFrom(ref input, _repeated_packedBool_codec); + break; + } + case 826: + case 824: { + packedEnum_.AddEntriesFrom(ref input, _repeated_packedEnum_codec); + break; + } + } + } + } + #endif + } /// /// A message with the same fields as TestPackedTypes, but without packing. Used /// to test packed <-> unpacked wire compatibility. /// - public sealed partial class TestUnpackedTypes : pb::IMessage { + public sealed partial class TestUnpackedTypes : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestUnpackedTypes()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -6103,6 +7674,30 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + unpackedInt32_.WriteTo(ref output, _repeated_unpackedInt32_codec); + unpackedInt64_.WriteTo(ref output, _repeated_unpackedInt64_codec); + unpackedUint32_.WriteTo(ref output, _repeated_unpackedUint32_codec); + unpackedUint64_.WriteTo(ref output, _repeated_unpackedUint64_codec); + unpackedSint32_.WriteTo(ref output, _repeated_unpackedSint32_codec); + unpackedSint64_.WriteTo(ref output, _repeated_unpackedSint64_codec); + unpackedFixed32_.WriteTo(ref output, _repeated_unpackedFixed32_codec); + unpackedFixed64_.WriteTo(ref output, _repeated_unpackedFixed64_codec); + unpackedSfixed32_.WriteTo(ref output, _repeated_unpackedSfixed32_codec); + unpackedSfixed64_.WriteTo(ref output, _repeated_unpackedSfixed64_codec); + unpackedFloat_.WriteTo(ref output, _repeated_unpackedFloat_codec); + unpackedDouble_.WriteTo(ref output, _repeated_unpackedDouble_codec); + unpackedBool_.WriteTo(ref output, _repeated_unpackedBool_codec); + unpackedEnum_.WriteTo(ref output, _repeated_unpackedEnum_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -6149,90 +7744,179 @@ public void MergeFrom(TestUnpackedTypes other) { } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void MergeFrom(pb::CodedInputStream input) { + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 722: + case 720: { + unpackedInt32_.AddEntriesFrom(input, _repeated_unpackedInt32_codec); + break; + } + case 730: + case 728: { + unpackedInt64_.AddEntriesFrom(input, _repeated_unpackedInt64_codec); + break; + } + case 738: + case 736: { + unpackedUint32_.AddEntriesFrom(input, _repeated_unpackedUint32_codec); + break; + } + case 746: + case 744: { + unpackedUint64_.AddEntriesFrom(input, _repeated_unpackedUint64_codec); + break; + } + case 754: + case 752: { + unpackedSint32_.AddEntriesFrom(input, _repeated_unpackedSint32_codec); + break; + } + case 762: + case 760: { + unpackedSint64_.AddEntriesFrom(input, _repeated_unpackedSint64_codec); + break; + } + case 770: + case 773: { + unpackedFixed32_.AddEntriesFrom(input, _repeated_unpackedFixed32_codec); + break; + } + case 778: + case 777: { + unpackedFixed64_.AddEntriesFrom(input, _repeated_unpackedFixed64_codec); + break; + } + case 786: + case 789: { + unpackedSfixed32_.AddEntriesFrom(input, _repeated_unpackedSfixed32_codec); + break; + } + case 794: + case 793: { + unpackedSfixed64_.AddEntriesFrom(input, _repeated_unpackedSfixed64_codec); + break; + } + case 802: + case 805: { + unpackedFloat_.AddEntriesFrom(input, _repeated_unpackedFloat_codec); + break; + } + case 810: + case 809: { + unpackedDouble_.AddEntriesFrom(input, _repeated_unpackedDouble_codec); + break; + } + case 818: + case 816: { + unpackedBool_.AddEntriesFrom(input, _repeated_unpackedBool_codec); + break; + } + case 826: + case 824: { + unpackedEnum_.AddEntriesFrom(input, _repeated_unpackedEnum_codec); + break; + } + } + } + } + + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { uint tag; while ((tag = input.ReadTag()) != 0) { switch(tag) { default: - _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); break; case 722: case 720: { - unpackedInt32_.AddEntriesFrom(input, _repeated_unpackedInt32_codec); + unpackedInt32_.AddEntriesFrom(ref input, _repeated_unpackedInt32_codec); break; } case 730: case 728: { - unpackedInt64_.AddEntriesFrom(input, _repeated_unpackedInt64_codec); + unpackedInt64_.AddEntriesFrom(ref input, _repeated_unpackedInt64_codec); break; } case 738: case 736: { - unpackedUint32_.AddEntriesFrom(input, _repeated_unpackedUint32_codec); + unpackedUint32_.AddEntriesFrom(ref input, _repeated_unpackedUint32_codec); break; } case 746: case 744: { - unpackedUint64_.AddEntriesFrom(input, _repeated_unpackedUint64_codec); + unpackedUint64_.AddEntriesFrom(ref input, _repeated_unpackedUint64_codec); break; } case 754: case 752: { - unpackedSint32_.AddEntriesFrom(input, _repeated_unpackedSint32_codec); + unpackedSint32_.AddEntriesFrom(ref input, _repeated_unpackedSint32_codec); break; } case 762: case 760: { - unpackedSint64_.AddEntriesFrom(input, _repeated_unpackedSint64_codec); + unpackedSint64_.AddEntriesFrom(ref input, _repeated_unpackedSint64_codec); break; } case 770: case 773: { - unpackedFixed32_.AddEntriesFrom(input, _repeated_unpackedFixed32_codec); + unpackedFixed32_.AddEntriesFrom(ref input, _repeated_unpackedFixed32_codec); break; } case 778: case 777: { - unpackedFixed64_.AddEntriesFrom(input, _repeated_unpackedFixed64_codec); + unpackedFixed64_.AddEntriesFrom(ref input, _repeated_unpackedFixed64_codec); break; } case 786: case 789: { - unpackedSfixed32_.AddEntriesFrom(input, _repeated_unpackedSfixed32_codec); + unpackedSfixed32_.AddEntriesFrom(ref input, _repeated_unpackedSfixed32_codec); break; } case 794: case 793: { - unpackedSfixed64_.AddEntriesFrom(input, _repeated_unpackedSfixed64_codec); + unpackedSfixed64_.AddEntriesFrom(ref input, _repeated_unpackedSfixed64_codec); break; } case 802: case 805: { - unpackedFloat_.AddEntriesFrom(input, _repeated_unpackedFloat_codec); + unpackedFloat_.AddEntriesFrom(ref input, _repeated_unpackedFloat_codec); break; } case 810: case 809: { - unpackedDouble_.AddEntriesFrom(input, _repeated_unpackedDouble_codec); + unpackedDouble_.AddEntriesFrom(ref input, _repeated_unpackedDouble_codec); break; } case 818: case 816: { - unpackedBool_.AddEntriesFrom(input, _repeated_unpackedBool_codec); + unpackedBool_.AddEntriesFrom(ref input, _repeated_unpackedBool_codec); break; } case 826: case 824: { - unpackedEnum_.AddEntriesFrom(input, _repeated_unpackedEnum_codec); + unpackedEnum_.AddEntriesFrom(ref input, _repeated_unpackedEnum_codec); break; } } } } + #endif } - public sealed partial class TestRepeatedScalarDifferentTagSizes : pb::IMessage { + public sealed partial class TestRepeatedScalarDifferentTagSizes : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestRepeatedScalarDifferentTagSizes()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -6400,6 +8084,22 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + repeatedFixed32_.WriteTo(ref output, _repeated_repeatedFixed32_codec); + repeatedInt32_.WriteTo(ref output, _repeated_repeatedInt32_codec); + repeatedFixed64_.WriteTo(ref output, _repeated_repeatedFixed64_codec); + repeatedInt64_.WriteTo(ref output, _repeated_repeatedInt64_codec); + repeatedFloat_.WriteTo(ref output, _repeated_repeatedFloat_codec); + repeatedUint64_.WriteTo(ref output, _repeated_repeatedUint64_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -6471,9 +8171,58 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 98: + case 101: { + repeatedFixed32_.AddEntriesFrom(ref input, _repeated_repeatedFixed32_codec); + break; + } + case 106: + case 104: { + repeatedInt32_.AddEntriesFrom(ref input, _repeated_repeatedInt32_codec); + break; + } + case 16370: + case 16369: { + repeatedFixed64_.AddEntriesFrom(ref input, _repeated_repeatedFixed64_codec); + break; + } + case 16378: + case 16376: { + repeatedInt64_.AddEntriesFrom(ref input, _repeated_repeatedInt64_codec); + break; + } + case 2097138: + case 2097141: { + repeatedFloat_.AddEntriesFrom(ref input, _repeated_repeatedFloat_codec); + break; + } + case 2097146: + case 2097144: { + repeatedUint64_.AddEntriesFrom(ref input, _repeated_repeatedUint64_codec); + break; + } + } + } + } + #endif + } - public sealed partial class TestCommentInjectionMessage : pb::IMessage { + public sealed partial class TestCommentInjectionMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestCommentInjectionMessage()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -6564,6 +8313,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (A.Length != 0) { + output.WriteRawTag(10); + output.WriteString(A); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -6603,12 +8366,35 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + A = input.ReadString(); + break; + } + } + } + } + #endif + } /// /// Test that RPC services work. /// - public sealed partial class FooRequest : pb::IMessage { + public sealed partial class FooRequest : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new FooRequest()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -6678,6 +8464,16 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -6707,9 +8503,28 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + } - public sealed partial class FooResponse : pb::IMessage { + public sealed partial class FooResponse : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new FooResponse()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -6779,6 +8594,16 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -6808,9 +8633,28 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + } - public sealed partial class FooClientMessage : pb::IMessage { + public sealed partial class FooClientMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new FooClientMessage()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -6880,6 +8724,16 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -6909,9 +8763,28 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + } - public sealed partial class FooServerMessage : pb::IMessage { + public sealed partial class FooServerMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new FooServerMessage()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -6981,6 +8854,16 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -7010,9 +8893,28 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + } - public sealed partial class BarRequest : pb::IMessage { + public sealed partial class BarRequest : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new BarRequest()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -7082,6 +8984,16 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -7111,9 +9023,28 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + } - public sealed partial class BarResponse : pb::IMessage { + public sealed partial class BarResponse : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new BarResponse()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -7183,6 +9114,16 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -7212,9 +9153,28 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + } - public sealed partial class TestEmptyMessage : pb::IMessage { + public sealed partial class TestEmptyMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestEmptyMessage()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -7284,6 +9244,16 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -7313,12 +9283,31 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + } /// /// This is a leading comment /// - public sealed partial class CommentMessage : pb::IMessage { + public sealed partial class CommentMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new CommentMessage()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -7409,6 +9398,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Text.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Text); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -7448,6 +9451,25 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Text = input.ReadString(); + break; + } + } + } + } + #endif + #region Nested types /// Container for nested types declared in the CommentMessage message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -7465,7 +9487,11 @@ public enum NestedCommentEnum { /// /// Leading nested message comment /// - public sealed partial class NestedCommentMessage : pb::IMessage { + public sealed partial class NestedCommentMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new NestedCommentMessage()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -7556,6 +9582,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (NestedText.Length != 0) { + output.WriteRawTag(10); + output.WriteString(NestedText); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -7595,6 +9635,25 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + NestedText = input.ReadString(); + break; + } + } + } + } + #endif + } } diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestWellKnownTypes.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestWellKnownTypes.cs index 90b338436bc9..3acd3b355850 100644 --- a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestWellKnownTypes.cs +++ b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestWellKnownTypes.cs @@ -179,7 +179,11 @@ static UnittestWellKnownTypesReflection() { /// Each wrapper type is included separately, as languages /// map handle different wrappers in different ways. /// - public sealed partial class TestWellKnownTypes : pb::IMessage { + public sealed partial class TestWellKnownTypes : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestWellKnownTypes()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -603,6 +607,83 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (anyField_ != null) { + output.WriteRawTag(10); + output.WriteMessage(AnyField); + } + if (apiField_ != null) { + output.WriteRawTag(18); + output.WriteMessage(ApiField); + } + if (durationField_ != null) { + output.WriteRawTag(26); + output.WriteMessage(DurationField); + } + if (emptyField_ != null) { + output.WriteRawTag(34); + output.WriteMessage(EmptyField); + } + if (fieldMaskField_ != null) { + output.WriteRawTag(42); + output.WriteMessage(FieldMaskField); + } + if (sourceContextField_ != null) { + output.WriteRawTag(50); + output.WriteMessage(SourceContextField); + } + if (structField_ != null) { + output.WriteRawTag(58); + output.WriteMessage(StructField); + } + if (timestampField_ != null) { + output.WriteRawTag(66); + output.WriteMessage(TimestampField); + } + if (typeField_ != null) { + output.WriteRawTag(74); + output.WriteMessage(TypeField); + } + if (doubleField_ != null) { + _single_doubleField_codec.WriteTagAndValue(ref output, DoubleField); + } + if (floatField_ != null) { + _single_floatField_codec.WriteTagAndValue(ref output, FloatField); + } + if (int64Field_ != null) { + _single_int64Field_codec.WriteTagAndValue(ref output, Int64Field); + } + if (uint64Field_ != null) { + _single_uint64Field_codec.WriteTagAndValue(ref output, Uint64Field); + } + if (int32Field_ != null) { + _single_int32Field_codec.WriteTagAndValue(ref output, Int32Field); + } + if (uint32Field_ != null) { + _single_uint32Field_codec.WriteTagAndValue(ref output, Uint32Field); + } + if (boolField_ != null) { + _single_boolField_codec.WriteTagAndValue(ref output, BoolField); + } + if (stringField_ != null) { + _single_stringField_codec.WriteTagAndValue(ref output, StringField); + } + if (bytesField_ != null) { + _single_bytesField_codec.WriteTagAndValue(ref output, BytesField); + } + if (valueField_ != null) { + output.WriteRawTag(154, 1); + output.WriteMessage(ValueField); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -927,12 +1008,164 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + if (anyField_ == null) { + AnyField = new global::Google.Protobuf.WellKnownTypes.Any(); + } + input.ReadMessage(AnyField); + break; + } + case 18: { + if (apiField_ == null) { + ApiField = new global::Google.Protobuf.WellKnownTypes.Api(); + } + input.ReadMessage(ApiField); + break; + } + case 26: { + if (durationField_ == null) { + DurationField = new global::Google.Protobuf.WellKnownTypes.Duration(); + } + input.ReadMessage(DurationField); + break; + } + case 34: { + if (emptyField_ == null) { + EmptyField = new global::Google.Protobuf.WellKnownTypes.Empty(); + } + input.ReadMessage(EmptyField); + break; + } + case 42: { + if (fieldMaskField_ == null) { + FieldMaskField = new global::Google.Protobuf.WellKnownTypes.FieldMask(); + } + input.ReadMessage(FieldMaskField); + break; + } + case 50: { + if (sourceContextField_ == null) { + SourceContextField = new global::Google.Protobuf.WellKnownTypes.SourceContext(); + } + input.ReadMessage(SourceContextField); + break; + } + case 58: { + if (structField_ == null) { + StructField = new global::Google.Protobuf.WellKnownTypes.Struct(); + } + input.ReadMessage(StructField); + break; + } + case 66: { + if (timestampField_ == null) { + TimestampField = new global::Google.Protobuf.WellKnownTypes.Timestamp(); + } + input.ReadMessage(TimestampField); + break; + } + case 74: { + if (typeField_ == null) { + TypeField = new global::Google.Protobuf.WellKnownTypes.Type(); + } + input.ReadMessage(TypeField); + break; + } + case 82: { + double? value = _single_doubleField_codec.Read(ref input); + if (doubleField_ == null || value != 0D) { + DoubleField = value; + } + break; + } + case 90: { + float? value = _single_floatField_codec.Read(ref input); + if (floatField_ == null || value != 0F) { + FloatField = value; + } + break; + } + case 98: { + long? value = _single_int64Field_codec.Read(ref input); + if (int64Field_ == null || value != 0L) { + Int64Field = value; + } + break; + } + case 106: { + ulong? value = _single_uint64Field_codec.Read(ref input); + if (uint64Field_ == null || value != 0UL) { + Uint64Field = value; + } + break; + } + case 114: { + int? value = _single_int32Field_codec.Read(ref input); + if (int32Field_ == null || value != 0) { + Int32Field = value; + } + break; + } + case 122: { + uint? value = _single_uint32Field_codec.Read(ref input); + if (uint32Field_ == null || value != 0) { + Uint32Field = value; + } + break; + } + case 130: { + bool? value = _single_boolField_codec.Read(ref input); + if (boolField_ == null || value != false) { + BoolField = value; + } + break; + } + case 138: { + string value = _single_stringField_codec.Read(ref input); + if (stringField_ == null || value != "") { + StringField = value; + } + break; + } + case 146: { + pb::ByteString value = _single_bytesField_codec.Read(ref input); + if (bytesField_ == null || value != pb::ByteString.Empty) { + BytesField = value; + } + break; + } + case 154: { + if (valueField_ == null) { + ValueField = new global::Google.Protobuf.WellKnownTypes.Value(); + } + input.ReadMessage(ValueField); + break; + } + } + } + } + #endif + } /// /// A repeated field for each well-known type. /// - public sealed partial class RepeatedWellKnownTypes : pb::IMessage { + public sealed partial class RepeatedWellKnownTypes : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new RepeatedWellKnownTypes()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -1257,6 +1490,34 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + anyField_.WriteTo(ref output, _repeated_anyField_codec); + apiField_.WriteTo(ref output, _repeated_apiField_codec); + durationField_.WriteTo(ref output, _repeated_durationField_codec); + emptyField_.WriteTo(ref output, _repeated_emptyField_codec); + fieldMaskField_.WriteTo(ref output, _repeated_fieldMaskField_codec); + sourceContextField_.WriteTo(ref output, _repeated_sourceContextField_codec); + structField_.WriteTo(ref output, _repeated_structField_codec); + timestampField_.WriteTo(ref output, _repeated_timestampField_codec); + typeField_.WriteTo(ref output, _repeated_typeField_codec); + doubleField_.WriteTo(ref output, _repeated_doubleField_codec); + floatField_.WriteTo(ref output, _repeated_floatField_codec); + int64Field_.WriteTo(ref output, _repeated_int64Field_codec); + uint64Field_.WriteTo(ref output, _repeated_uint64Field_codec); + int32Field_.WriteTo(ref output, _repeated_int32Field_codec); + uint32Field_.WriteTo(ref output, _repeated_uint32Field_codec); + boolField_.WriteTo(ref output, _repeated_boolField_codec); + stringField_.WriteTo(ref output, _repeated_stringField_codec); + bytesField_.WriteTo(ref output, _repeated_bytesField_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -1363,40 +1624,131 @@ public void MergeFrom(pb::CodedInputStream input) { break; } case 98: { - int64Field_.AddEntriesFrom(input, _repeated_int64Field_codec); + int64Field_.AddEntriesFrom(input, _repeated_int64Field_codec); + break; + } + case 106: { + uint64Field_.AddEntriesFrom(input, _repeated_uint64Field_codec); + break; + } + case 114: { + int32Field_.AddEntriesFrom(input, _repeated_int32Field_codec); + break; + } + case 122: { + uint32Field_.AddEntriesFrom(input, _repeated_uint32Field_codec); + break; + } + case 130: { + boolField_.AddEntriesFrom(input, _repeated_boolField_codec); + break; + } + case 138: { + stringField_.AddEntriesFrom(input, _repeated_stringField_codec); + break; + } + case 146: { + bytesField_.AddEntriesFrom(input, _repeated_bytesField_codec); + break; + } + } + } + } + + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + anyField_.AddEntriesFrom(ref input, _repeated_anyField_codec); + break; + } + case 18: { + apiField_.AddEntriesFrom(ref input, _repeated_apiField_codec); + break; + } + case 26: { + durationField_.AddEntriesFrom(ref input, _repeated_durationField_codec); + break; + } + case 34: { + emptyField_.AddEntriesFrom(ref input, _repeated_emptyField_codec); + break; + } + case 42: { + fieldMaskField_.AddEntriesFrom(ref input, _repeated_fieldMaskField_codec); + break; + } + case 50: { + sourceContextField_.AddEntriesFrom(ref input, _repeated_sourceContextField_codec); + break; + } + case 58: { + structField_.AddEntriesFrom(ref input, _repeated_structField_codec); + break; + } + case 66: { + timestampField_.AddEntriesFrom(ref input, _repeated_timestampField_codec); + break; + } + case 74: { + typeField_.AddEntriesFrom(ref input, _repeated_typeField_codec); + break; + } + case 82: { + doubleField_.AddEntriesFrom(ref input, _repeated_doubleField_codec); + break; + } + case 90: { + floatField_.AddEntriesFrom(ref input, _repeated_floatField_codec); + break; + } + case 98: { + int64Field_.AddEntriesFrom(ref input, _repeated_int64Field_codec); break; } case 106: { - uint64Field_.AddEntriesFrom(input, _repeated_uint64Field_codec); + uint64Field_.AddEntriesFrom(ref input, _repeated_uint64Field_codec); break; } case 114: { - int32Field_.AddEntriesFrom(input, _repeated_int32Field_codec); + int32Field_.AddEntriesFrom(ref input, _repeated_int32Field_codec); break; } case 122: { - uint32Field_.AddEntriesFrom(input, _repeated_uint32Field_codec); + uint32Field_.AddEntriesFrom(ref input, _repeated_uint32Field_codec); break; } case 130: { - boolField_.AddEntriesFrom(input, _repeated_boolField_codec); + boolField_.AddEntriesFrom(ref input, _repeated_boolField_codec); break; } case 138: { - stringField_.AddEntriesFrom(input, _repeated_stringField_codec); + stringField_.AddEntriesFrom(ref input, _repeated_stringField_codec); break; } case 146: { - bytesField_.AddEntriesFrom(input, _repeated_bytesField_codec); + bytesField_.AddEntriesFrom(ref input, _repeated_bytesField_codec); break; } } } } + #endif } - public sealed partial class OneofWellKnownTypes : pb::IMessage { + public sealed partial class OneofWellKnownTypes : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new OneofWellKnownTypes()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -1866,6 +2218,79 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (oneofFieldCase_ == OneofFieldOneofCase.AnyField) { + output.WriteRawTag(10); + output.WriteMessage(AnyField); + } + if (oneofFieldCase_ == OneofFieldOneofCase.ApiField) { + output.WriteRawTag(18); + output.WriteMessage(ApiField); + } + if (oneofFieldCase_ == OneofFieldOneofCase.DurationField) { + output.WriteRawTag(26); + output.WriteMessage(DurationField); + } + if (oneofFieldCase_ == OneofFieldOneofCase.EmptyField) { + output.WriteRawTag(34); + output.WriteMessage(EmptyField); + } + if (oneofFieldCase_ == OneofFieldOneofCase.FieldMaskField) { + output.WriteRawTag(42); + output.WriteMessage(FieldMaskField); + } + if (oneofFieldCase_ == OneofFieldOneofCase.SourceContextField) { + output.WriteRawTag(50); + output.WriteMessage(SourceContextField); + } + if (oneofFieldCase_ == OneofFieldOneofCase.StructField) { + output.WriteRawTag(58); + output.WriteMessage(StructField); + } + if (oneofFieldCase_ == OneofFieldOneofCase.TimestampField) { + output.WriteRawTag(66); + output.WriteMessage(TimestampField); + } + if (oneofFieldCase_ == OneofFieldOneofCase.TypeField) { + output.WriteRawTag(74); + output.WriteMessage(TypeField); + } + if (oneofFieldCase_ == OneofFieldOneofCase.DoubleField) { + _oneof_doubleField_codec.WriteTagAndValue(ref output, (double?) oneofField_); + } + if (oneofFieldCase_ == OneofFieldOneofCase.FloatField) { + _oneof_floatField_codec.WriteTagAndValue(ref output, (float?) oneofField_); + } + if (oneofFieldCase_ == OneofFieldOneofCase.Int64Field) { + _oneof_int64Field_codec.WriteTagAndValue(ref output, (long?) oneofField_); + } + if (oneofFieldCase_ == OneofFieldOneofCase.Uint64Field) { + _oneof_uint64Field_codec.WriteTagAndValue(ref output, (ulong?) oneofField_); + } + if (oneofFieldCase_ == OneofFieldOneofCase.Int32Field) { + _oneof_int32Field_codec.WriteTagAndValue(ref output, (int?) oneofField_); + } + if (oneofFieldCase_ == OneofFieldOneofCase.Uint32Field) { + _oneof_uint32Field_codec.WriteTagAndValue(ref output, (uint?) oneofField_); + } + if (oneofFieldCase_ == OneofFieldOneofCase.BoolField) { + _oneof_boolField_codec.WriteTagAndValue(ref output, (bool?) oneofField_); + } + if (oneofFieldCase_ == OneofFieldOneofCase.StringField) { + _oneof_stringField_codec.WriteTagAndValue(ref output, (string) oneofField_); + } + if (oneofFieldCase_ == OneofFieldOneofCase.BytesField) { + _oneof_bytesField_codec.WriteTagAndValue(ref output, (pb::ByteString) oneofField_); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -2150,6 +2575,138 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + global::Google.Protobuf.WellKnownTypes.Any subBuilder = new global::Google.Protobuf.WellKnownTypes.Any(); + if (oneofFieldCase_ == OneofFieldOneofCase.AnyField) { + subBuilder.MergeFrom(AnyField); + } + input.ReadMessage(subBuilder); + AnyField = subBuilder; + break; + } + case 18: { + global::Google.Protobuf.WellKnownTypes.Api subBuilder = new global::Google.Protobuf.WellKnownTypes.Api(); + if (oneofFieldCase_ == OneofFieldOneofCase.ApiField) { + subBuilder.MergeFrom(ApiField); + } + input.ReadMessage(subBuilder); + ApiField = subBuilder; + break; + } + case 26: { + global::Google.Protobuf.WellKnownTypes.Duration subBuilder = new global::Google.Protobuf.WellKnownTypes.Duration(); + if (oneofFieldCase_ == OneofFieldOneofCase.DurationField) { + subBuilder.MergeFrom(DurationField); + } + input.ReadMessage(subBuilder); + DurationField = subBuilder; + break; + } + case 34: { + global::Google.Protobuf.WellKnownTypes.Empty subBuilder = new global::Google.Protobuf.WellKnownTypes.Empty(); + if (oneofFieldCase_ == OneofFieldOneofCase.EmptyField) { + subBuilder.MergeFrom(EmptyField); + } + input.ReadMessage(subBuilder); + EmptyField = subBuilder; + break; + } + case 42: { + global::Google.Protobuf.WellKnownTypes.FieldMask subBuilder = new global::Google.Protobuf.WellKnownTypes.FieldMask(); + if (oneofFieldCase_ == OneofFieldOneofCase.FieldMaskField) { + subBuilder.MergeFrom(FieldMaskField); + } + input.ReadMessage(subBuilder); + FieldMaskField = subBuilder; + break; + } + case 50: { + global::Google.Protobuf.WellKnownTypes.SourceContext subBuilder = new global::Google.Protobuf.WellKnownTypes.SourceContext(); + if (oneofFieldCase_ == OneofFieldOneofCase.SourceContextField) { + subBuilder.MergeFrom(SourceContextField); + } + input.ReadMessage(subBuilder); + SourceContextField = subBuilder; + break; + } + case 58: { + global::Google.Protobuf.WellKnownTypes.Struct subBuilder = new global::Google.Protobuf.WellKnownTypes.Struct(); + if (oneofFieldCase_ == OneofFieldOneofCase.StructField) { + subBuilder.MergeFrom(StructField); + } + input.ReadMessage(subBuilder); + StructField = subBuilder; + break; + } + case 66: { + global::Google.Protobuf.WellKnownTypes.Timestamp subBuilder = new global::Google.Protobuf.WellKnownTypes.Timestamp(); + if (oneofFieldCase_ == OneofFieldOneofCase.TimestampField) { + subBuilder.MergeFrom(TimestampField); + } + input.ReadMessage(subBuilder); + TimestampField = subBuilder; + break; + } + case 74: { + global::Google.Protobuf.WellKnownTypes.Type subBuilder = new global::Google.Protobuf.WellKnownTypes.Type(); + if (oneofFieldCase_ == OneofFieldOneofCase.TypeField) { + subBuilder.MergeFrom(TypeField); + } + input.ReadMessage(subBuilder); + TypeField = subBuilder; + break; + } + case 82: { + DoubleField = _oneof_doubleField_codec.Read(ref input); + break; + } + case 90: { + FloatField = _oneof_floatField_codec.Read(ref input); + break; + } + case 98: { + Int64Field = _oneof_int64Field_codec.Read(ref input); + break; + } + case 106: { + Uint64Field = _oneof_uint64Field_codec.Read(ref input); + break; + } + case 114: { + Int32Field = _oneof_int32Field_codec.Read(ref input); + break; + } + case 122: { + Uint32Field = _oneof_uint32Field_codec.Read(ref input); + break; + } + case 130: { + BoolField = _oneof_boolField_codec.Read(ref input); + break; + } + case 138: { + StringField = _oneof_stringField_codec.Read(ref input); + break; + } + case 146: { + BytesField = _oneof_bytesField_codec.Read(ref input); + break; + } + } + } + } + #endif + } /// @@ -2157,7 +2714,11 @@ public void MergeFrom(pb::CodedInputStream input) { /// need to worry about the value part of the map being the /// well-known types, as messages can't be map keys. /// - public sealed partial class MapWellKnownTypes : pb::IMessage { + public sealed partial class MapWellKnownTypes : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new MapWellKnownTypes()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -2479,6 +3040,34 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + anyField_.WriteTo(ref output, _map_anyField_codec); + apiField_.WriteTo(ref output, _map_apiField_codec); + durationField_.WriteTo(ref output, _map_durationField_codec); + emptyField_.WriteTo(ref output, _map_emptyField_codec); + fieldMaskField_.WriteTo(ref output, _map_fieldMaskField_codec); + sourceContextField_.WriteTo(ref output, _map_sourceContextField_codec); + structField_.WriteTo(ref output, _map_structField_codec); + timestampField_.WriteTo(ref output, _map_timestampField_codec); + typeField_.WriteTo(ref output, _map_typeField_codec); + doubleField_.WriteTo(ref output, _map_doubleField_codec); + floatField_.WriteTo(ref output, _map_floatField_codec); + int64Field_.WriteTo(ref output, _map_int64Field_codec); + uint64Field_.WriteTo(ref output, _map_uint64Field_codec); + int32Field_.WriteTo(ref output, _map_int32Field_codec); + uint32Field_.WriteTo(ref output, _map_uint32Field_codec); + boolField_.WriteTo(ref output, _map_boolField_codec); + stringField_.WriteTo(ref output, _map_stringField_codec); + bytesField_.WriteTo(ref output, _map_bytesField_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -2616,6 +3205,93 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + anyField_.AddEntriesFrom(ref input, _map_anyField_codec); + break; + } + case 18: { + apiField_.AddEntriesFrom(ref input, _map_apiField_codec); + break; + } + case 26: { + durationField_.AddEntriesFrom(ref input, _map_durationField_codec); + break; + } + case 34: { + emptyField_.AddEntriesFrom(ref input, _map_emptyField_codec); + break; + } + case 42: { + fieldMaskField_.AddEntriesFrom(ref input, _map_fieldMaskField_codec); + break; + } + case 50: { + sourceContextField_.AddEntriesFrom(ref input, _map_sourceContextField_codec); + break; + } + case 58: { + structField_.AddEntriesFrom(ref input, _map_structField_codec); + break; + } + case 66: { + timestampField_.AddEntriesFrom(ref input, _map_timestampField_codec); + break; + } + case 74: { + typeField_.AddEntriesFrom(ref input, _map_typeField_codec); + break; + } + case 82: { + doubleField_.AddEntriesFrom(ref input, _map_doubleField_codec); + break; + } + case 90: { + floatField_.AddEntriesFrom(ref input, _map_floatField_codec); + break; + } + case 98: { + int64Field_.AddEntriesFrom(ref input, _map_int64Field_codec); + break; + } + case 106: { + uint64Field_.AddEntriesFrom(ref input, _map_uint64Field_codec); + break; + } + case 114: { + int32Field_.AddEntriesFrom(ref input, _map_int32Field_codec); + break; + } + case 122: { + uint32Field_.AddEntriesFrom(ref input, _map_uint32Field_codec); + break; + } + case 130: { + boolField_.AddEntriesFrom(ref input, _map_boolField_codec); + break; + } + case 138: { + stringField_.AddEntriesFrom(ref input, _map_stringField_codec); + break; + } + case 146: { + bytesField_.AddEntriesFrom(ref input, _map_bytesField_codec); + break; + } + } + } + } + #endif + } #endregion diff --git a/csharp/src/Google.Protobuf.Test/Buffers/ArrayBufferWriter.cs b/csharp/src/Google.Protobuf.Test/Buffers/ArrayBufferWriter.cs new file mode 100644 index 000000000000..8166fe12f090 --- /dev/null +++ b/csharp/src/Google.Protobuf.Test/Buffers/ArrayBufferWriter.cs @@ -0,0 +1,215 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY +using System; +using System.Buffers; +using System.Diagnostics; + +namespace Google.Protobuf.Buffers +{ + /// + /// Represents a heap-based, array-backed output sink into which data can be written. + /// + /// ArrayBufferWriter is originally from corefx, and has been contributed to Protobuf + /// https://github.com/dotnet/runtime/blob/071da4c41aa808c949a773b92dca6f88de9d11f3/src/libraries/Common/src/System/Buffers/ArrayBufferWriter.cs + /// + internal sealed class ArrayBufferWriter : IBufferWriter + { + private T[] _buffer; + private int _index; + + private const int DefaultInitialBufferSize = 256; + + /// + /// Creates an instance of an , in which data can be written to, + /// with the default initial capacity. + /// + public ArrayBufferWriter() + { + _buffer = new T[0]; + _index = 0; + } + + /// + /// Creates an instance of an , in which data can be written to, + /// with an initial capacity specified. + /// + /// The minimum capacity with which to initialize the underlying buffer. + /// + /// Thrown when is not positive (i.e. less than or equal to 0). + /// + public ArrayBufferWriter(int initialCapacity) + { + if (initialCapacity <= 0) + throw new ArgumentException(nameof(initialCapacity)); + + _buffer = new T[initialCapacity]; + _index = 0; + } + + /// + /// Returns the data written to the underlying buffer so far, as a . + /// + public ReadOnlyMemory WrittenMemory => _buffer.AsMemory(0, _index); + + /// + /// Returns the data written to the underlying buffer so far, as a . + /// + public ReadOnlySpan WrittenSpan => _buffer.AsSpan(0, _index); + + /// + /// Returns the amount of data written to the underlying buffer so far. + /// + public int WrittenCount => _index; + + /// + /// Returns the total amount of space within the underlying buffer. + /// + public int Capacity => _buffer.Length; + + /// + /// Returns the amount of space available that can still be written into without forcing the underlying buffer to grow. + /// + public int FreeCapacity => _buffer.Length - _index; + + /// + /// Clears the data written to the underlying buffer. + /// + /// + /// You must clear the before trying to re-use it. + /// + public void Clear() + { + Debug.Assert(_buffer.Length >= _index); + _buffer.AsSpan(0, _index).Clear(); + _index = 0; + } + + /// + /// Notifies that amount of data was written to the output / + /// + /// + /// Thrown when is negative. + /// + /// + /// Thrown when attempting to advance past the end of the underlying buffer. + /// + /// + /// You must request a new buffer after calling Advance to continue writing more data and cannot write to a previously acquired buffer. + /// + public void Advance(int count) + { + if (count < 0) + throw new ArgumentException(nameof(count)); + + if (_index > _buffer.Length - count) + throw new InvalidOperationException("Advanced past capacity."); + + _index += count; + } + + /// + /// Returns a to write to that is at least the requested length (specified by ). + /// If no is provided (or it's equal to 0), some non-empty buffer is returned. + /// + /// + /// Thrown when is negative. + /// + /// + /// This will never return an empty . + /// + /// + /// There is no guarantee that successive calls will return the same buffer or the same-sized buffer. + /// + /// + /// You must request a new buffer after calling Advance to continue writing more data and cannot write to a previously acquired buffer. + /// + public Memory GetMemory(int sizeHint = 0) + { + CheckAndResizeBuffer(sizeHint); + Debug.Assert(_buffer.Length > _index); + return _buffer.AsMemory(_index); + } + + /// + /// Returns a to write to that is at least the requested length (specified by ). + /// If no is provided (or it's equal to 0), some non-empty buffer is returned. + /// + /// + /// Thrown when is negative. + /// + /// + /// This will never return an empty . + /// + /// + /// There is no guarantee that successive calls will return the same buffer or the same-sized buffer. + /// + /// + /// You must request a new buffer after calling Advance to continue writing more data and cannot write to a previously acquired buffer. + /// + public Span GetSpan(int sizeHint = 0) + { + CheckAndResizeBuffer(sizeHint); + Debug.Assert(_buffer.Length > _index); + return _buffer.AsSpan(_index); + } + + private void CheckAndResizeBuffer(int sizeHint) + { + if (sizeHint < 0) + throw new ArgumentException(nameof(sizeHint)); + + if (sizeHint == 0) + { + sizeHint = 1; + } + + if (sizeHint > FreeCapacity) + { + int growBy = Math.Max(sizeHint, _buffer.Length); + + if (_buffer.Length == 0) + { + growBy = Math.Max(growBy, DefaultInitialBufferSize); + } + + int newSize = checked(_buffer.Length + growBy); + + Array.Resize(ref _buffer, newSize); + } + + Debug.Assert(FreeCapacity > 0 && FreeCapacity >= sizeHint); + } + } +} +#endif \ No newline at end of file diff --git a/csharp/src/Google.Protobuf.Test/Buffers/MaxSizeHintBufferWriter.cs b/csharp/src/Google.Protobuf.Test/Buffers/MaxSizeHintBufferWriter.cs new file mode 100644 index 000000000000..5c13d8110ec5 --- /dev/null +++ b/csharp/src/Google.Protobuf.Test/Buffers/MaxSizeHintBufferWriter.cs @@ -0,0 +1,66 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY +using System; +using System.Buffers; + +namespace Google.Protobuf.Buffers +{ + internal class MaxSizeHintBufferWriter : IBufferWriter + { + private readonly IBufferWriter bufferWriter; + private readonly int maxSizeHint; + + public MaxSizeHintBufferWriter(IBufferWriter bufferWriter, int maxSizeHint) + { + this.bufferWriter = bufferWriter; + this.maxSizeHint = maxSizeHint; + } + + public void Advance(int count) + { + bufferWriter.Advance(count); + } + + public Memory GetMemory(int sizeHint = 0) + { + return bufferWriter.GetMemory(Math.Min(sizeHint, maxSizeHint)); + } + + public Span GetSpan(int sizeHint = 0) + { + return bufferWriter.GetSpan(Math.Min(sizeHint, maxSizeHint)); + } + } +} +#endif \ No newline at end of file diff --git a/csharp/src/Google.Protobuf.Test/Buffers/ReadOnlySequenceFactory.cs b/csharp/src/Google.Protobuf.Test/Buffers/ReadOnlySequenceFactory.cs new file mode 100644 index 000000000000..0ca15e16c997 --- /dev/null +++ b/csharp/src/Google.Protobuf.Test/Buffers/ReadOnlySequenceFactory.cs @@ -0,0 +1,188 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Google.Protobuf.Buffers +{ + /// + /// ReadOnlySequenceFactory is originally from corefx, and has been contributed to Protobuf + /// https://github.com/dotnet/corefx/blob/e99ec129cfd594d53f4390bf97d1d736cff6f860/src/System.Memory/tests/ReadOnlyBuffer/ReadOnlySequenceFactory.byte.cs + /// + internal abstract class ReadOnlySequenceFactory + { + public static ReadOnlySequenceFactory ArrayFactory { get; } = new ArrayTestSequenceFactory(); + public static ReadOnlySequenceFactory MemoryFactory { get; } = new MemoryTestSequenceFactory(); + public static ReadOnlySequenceFactory SingleSegmentFactory { get; } = new SingleSegmentTestSequenceFactory(); + public static ReadOnlySequenceFactory SegmentPerByteFactory { get; } = new BytePerSegmentTestSequenceFactory(); + + public abstract ReadOnlySequence CreateOfSize(int size); + public abstract ReadOnlySequence CreateWithContent(byte[] data); + + public ReadOnlySequence CreateWithContent(string data) + { + return CreateWithContent(Encoding.ASCII.GetBytes(data)); + } + + internal class ArrayTestSequenceFactory : ReadOnlySequenceFactory + { + public override ReadOnlySequence CreateOfSize(int size) + { + return new ReadOnlySequence(new byte[size + 20], 10, size); + } + + public override ReadOnlySequence CreateWithContent(byte[] data) + { + var startSegment = new byte[data.Length + 20]; + Array.Copy(data, 0, startSegment, 10, data.Length); + return new ReadOnlySequence(startSegment, 10, data.Length); + } + } + + internal class MemoryTestSequenceFactory : ReadOnlySequenceFactory + { + public override ReadOnlySequence CreateOfSize(int size) + { + return CreateWithContent(new byte[size]); + } + + public override ReadOnlySequence CreateWithContent(byte[] data) + { + var startSegment = new byte[data.Length + 20]; + Array.Copy(data, 0, startSegment, 10, data.Length); + return new ReadOnlySequence(new Memory(startSegment, 10, data.Length)); + } + } + + internal class SingleSegmentTestSequenceFactory : ReadOnlySequenceFactory + { + public override ReadOnlySequence CreateOfSize(int size) + { + return CreateWithContent(new byte[size]); + } + + public override ReadOnlySequence CreateWithContent(byte[] data) + { + return CreateSegments(data); + } + } + + internal class BytePerSegmentTestSequenceFactory : ReadOnlySequenceFactory + { + public override ReadOnlySequence CreateOfSize(int size) + { + return CreateWithContent(new byte[size]); + } + + public override ReadOnlySequence CreateWithContent(byte[] data) + { + var segments = new List(); + + segments.Add(new byte[0]); + foreach (var b in data) + { + segments.Add(new[] { b }); + segments.Add(new byte[0]); + } + + return CreateSegments(segments.ToArray()); + } + } + + public static ReadOnlySequence CreateSegments(params byte[][] inputs) + { + if (inputs == null || inputs.Length == 0) + { + throw new InvalidOperationException(); + } + + int i = 0; + + BufferSegment last = null; + BufferSegment first = null; + + do + { + byte[] s = inputs[i]; + int length = s.Length; + int dataOffset = length; + var chars = new byte[length * 2]; + + for (int j = 0; j < length; j++) + { + chars[dataOffset + j] = s[j]; + } + + // Create a segment that has offset relative to the OwnedMemory and OwnedMemory itself has offset relative to array + var memory = new Memory(chars).Slice(length, length); + + if (first == null) + { + first = new BufferSegment(memory); + last = first; + } + else + { + last = last.Append(memory); + } + i++; + } while (i < inputs.Length); + + return new ReadOnlySequence(first, 0, last, last.Memory.Length); + } + + private class BufferSegment : ReadOnlySequenceSegment + { + public BufferSegment(Memory memory) + { + Memory = memory; + } + + public BufferSegment Append(Memory memory) + { + var segment = new BufferSegment(memory) + { + RunningIndex = RunningIndex + Memory.Length + }; + Next = segment; + return segment; + } + } + } +} +#endif diff --git a/csharp/src/Google.Protobuf.Test/CodedInputStreamExtensions.cs b/csharp/src/Google.Protobuf.Test/CodedInputExtensions.cs similarity index 79% rename from csharp/src/Google.Protobuf.Test/CodedInputStreamExtensions.cs rename to csharp/src/Google.Protobuf.Test/CodedInputExtensions.cs index 23af28870ab4..ab962b6d9db3 100644 --- a/csharp/src/Google.Protobuf.Test/CodedInputStreamExtensions.cs +++ b/csharp/src/Google.Protobuf.Test/CodedInputExtensions.cs @@ -34,7 +34,7 @@ namespace Google.Protobuf { - internal static class CodedInputStreamExtensions + internal static class CodedInputExtensions { public static void AssertNextTag(this CodedInputStream input, uint expectedTag) { @@ -49,5 +49,21 @@ public static T ReadMessage(this CodedInputStream stream, MessageParser pa stream.ReadMessage(message); return message; } + +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + public static void AssertNextTag(this ref CodedInputReader input, uint expectedTag) + { + uint tag = input.ReadTag(); + Assert.AreEqual(expectedTag, tag); + } + + public static T ReadMessage(this ref CodedInputReader input, MessageParser parser) + where T : IMessage + { + var message = parser.CreateTemplate(); + input.ReadMessage((IBufferMessage)message); + return message; + } +#endif } } diff --git a/csharp/src/Google.Protobuf.Test/CodedInputReaderTest.cs b/csharp/src/Google.Protobuf.Test/CodedInputReaderTest.cs new file mode 100644 index 000000000000..dd797831c1bd --- /dev/null +++ b/csharp/src/Google.Protobuf.Test/CodedInputReaderTest.cs @@ -0,0 +1,396 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY +using System; +using System.Buffers; +using System.IO; +using Google.Protobuf.TestProtos; +using NUnit.Framework; + +namespace Google.Protobuf +{ + public class CodedInputReaderTest : CodedInputTestBase + { + [Test] + public void ReadMaliciouslyLargeBlob() + { + MemoryStream ms = new MemoryStream(); + CodedOutputStream output = new CodedOutputStream(ms); + + uint tag = WireFormat.MakeTag(1, WireFormat.WireType.LengthDelimited); + output.WriteRawVarint32(tag); + output.WriteRawVarint32(0x7FFFFFFF); + output.WriteRawBytes(new byte[32]); // Pad with a few random bytes. + output.Flush(); + ms.Position = 0; + + CodedInputReader input = new CodedInputReader(new ReadOnlySequence(ms.ToArray())); + Assert.AreEqual(tag, input.ReadTag()); + + try + { + input.ReadBytes(); + Assert.Fail(); + } + catch (InvalidProtocolBufferException) + { + } + } + + /// + /// Tests that if we read an string that contains invalid UTF-8, no exception + /// is thrown. Instead, the invalid bytes are replaced with the Unicode + /// "replacement character" U+FFFD. + /// + [Test] + public void ReadInvalidUtf8() + { + MemoryStream ms = new MemoryStream(); + CodedOutputStream output = new CodedOutputStream(ms); + + uint tag = WireFormat.MakeTag(1, WireFormat.WireType.LengthDelimited); + output.WriteRawVarint32(tag); + output.WriteRawVarint32(1); + output.WriteRawBytes(new byte[] {0x80}); + output.Flush(); + ms.Position = 0; + + CodedInputReader input = new CodedInputReader(new ReadOnlySequence(ms.ToArray())); + + Assert.AreEqual(tag, input.ReadTag()); + string text = input.ReadString(); + Assert.AreEqual('\ufffd', text[0]); + } + + [Test] + public void ReadNegativeSizedStringThrowsInvalidProtocolBufferException() + { + MemoryStream ms = new MemoryStream(); + CodedOutputStream output = new CodedOutputStream(ms); + + uint tag = WireFormat.MakeTag(1, WireFormat.WireType.LengthDelimited); + output.WriteRawVarint32(tag); + output.WriteLength(-1); + output.Flush(); + ms.Position = 0; + + CodedInputReader input = new CodedInputReader(new ReadOnlySequence(ms.ToArray())); + + Assert.AreEqual(tag, input.ReadTag()); + try + { + input.ReadString(); + Assert.Fail(); + } + catch (InvalidProtocolBufferException) + { + } + } + + [Test] + public void ReadNegativeSizedBytesThrowsInvalidProtocolBufferException() + { + MemoryStream ms = new MemoryStream(); + CodedOutputStream output = new CodedOutputStream(ms); + + uint tag = WireFormat.MakeTag(1, WireFormat.WireType.LengthDelimited); + output.WriteRawVarint32(tag); + output.WriteLength(-1); + output.Flush(); + ms.Position = 0; + + CodedInputReader input = new CodedInputReader(new ReadOnlySequence(ms.ToArray())); + + Assert.AreEqual(tag, input.ReadTag()); + try + { + input.ReadBytes(); + Assert.Fail(); + } + catch (InvalidProtocolBufferException) + { + } + } + + [Test] + public void SkipGroup() + { + // Create an output stream with a group in: + // Field 1: string "field 1" + // Field 2: group containing: + // Field 1: fixed int32 value 100 + // Field 2: string "ignore me" + // Field 3: nested group containing + // Field 1: fixed int64 value 1000 + // Field 3: string "field 3" + var stream = new MemoryStream(); + var output = new CodedOutputStream(stream); + output.WriteTag(1, WireFormat.WireType.LengthDelimited); + output.WriteString("field 1"); + + // The outer group... + output.WriteTag(2, WireFormat.WireType.StartGroup); + output.WriteTag(1, WireFormat.WireType.Fixed32); + output.WriteFixed32(100); + output.WriteTag(2, WireFormat.WireType.LengthDelimited); + output.WriteString("ignore me"); + // The nested group... + output.WriteTag(3, WireFormat.WireType.StartGroup); + output.WriteTag(1, WireFormat.WireType.Fixed64); + output.WriteFixed64(1000); + // Note: Not sure the field number is relevant for end group... + output.WriteTag(3, WireFormat.WireType.EndGroup); + + // End the outer group + output.WriteTag(2, WireFormat.WireType.EndGroup); + + output.WriteTag(3, WireFormat.WireType.LengthDelimited); + output.WriteString("field 3"); + output.Flush(); + stream.Position = 0; + + // Now act like a generated client + var input = new CodedInputReader(new ReadOnlySequence(stream.ToArray())); + Assert.AreEqual(WireFormat.MakeTag(1, WireFormat.WireType.LengthDelimited), input.ReadTag()); + Assert.AreEqual("field 1", input.ReadString()); + Assert.AreEqual(WireFormat.MakeTag(2, WireFormat.WireType.StartGroup), input.ReadTag()); + input.SkipLastField(); // Should consume the whole group, including the nested one. + Assert.AreEqual(WireFormat.MakeTag(3, WireFormat.WireType.LengthDelimited), input.ReadTag()); + Assert.AreEqual("field 3", input.ReadString()); + } + + [Test] + public void SkipGroup_WrongEndGroupTag() + { + // Create an output stream with: + // Field 1: string "field 1" + // Start group 2 + // Field 3: fixed int32 + // End group 4 (should give an error) + var stream = new MemoryStream(); + var output = new CodedOutputStream(stream); + output.WriteTag(1, WireFormat.WireType.LengthDelimited); + output.WriteString("field 1"); + + // The outer group... + output.WriteTag(2, WireFormat.WireType.StartGroup); + output.WriteTag(3, WireFormat.WireType.Fixed32); + output.WriteFixed32(100); + output.WriteTag(4, WireFormat.WireType.EndGroup); + output.Flush(); + stream.Position = 0; + + // Now act like a generated client + var input = new CodedInputReader(new ReadOnlySequence(stream.ToArray())); + Assert.AreEqual(WireFormat.MakeTag(1, WireFormat.WireType.LengthDelimited), input.ReadTag()); + Assert.AreEqual("field 1", input.ReadString()); + Assert.AreEqual(WireFormat.MakeTag(2, WireFormat.WireType.StartGroup), input.ReadTag()); + + try + { + input.SkipLastField(); + Assert.Fail(); + } + catch (InvalidProtocolBufferException) + { + } + } + + [Test] + public void RogueEndGroupTag() + { + // If we have an end-group tag without a leading start-group tag, generated + // code will just call SkipLastField... so that should fail. + + var stream = new MemoryStream(); + var output = new CodedOutputStream(stream); + output.WriteTag(1, WireFormat.WireType.EndGroup); + output.Flush(); + stream.Position = 0; + + var input = new CodedInputReader(new ReadOnlySequence(stream.ToArray())); + Assert.AreEqual(WireFormat.MakeTag(1, WireFormat.WireType.EndGroup), input.ReadTag()); + + try + { + input.SkipLastField(); + Assert.Fail(); + } + catch (InvalidProtocolBufferException) + { + } + } + + [Test] + public void EndOfStreamReachedWhileSkippingGroup() + { + var stream = new MemoryStream(); + var output = new CodedOutputStream(stream); + output.WriteTag(1, WireFormat.WireType.StartGroup); + output.WriteTag(2, WireFormat.WireType.StartGroup); + output.WriteTag(2, WireFormat.WireType.EndGroup); + + output.Flush(); + stream.Position = 0; + + // Now act like a generated client + var input = new CodedInputReader(new ReadOnlySequence(stream.ToArray())); + input.ReadTag(); + + try + { + input.SkipLastField(); + Assert.Fail(); + } + catch (InvalidProtocolBufferException) + { + } + } + + [Test] + public void RecursionLimitAppliedWhileSkippingGroup() + { + var stream = new MemoryStream(); + var output = new CodedOutputStream(stream); + for (int i = 0; i < CodedInputStream.DefaultRecursionLimit + 1; i++) + { + output.WriteTag(1, WireFormat.WireType.StartGroup); + } + for (int i = 0; i < CodedInputStream.DefaultRecursionLimit + 1; i++) + { + output.WriteTag(1, WireFormat.WireType.EndGroup); + } + output.Flush(); + stream.Position = 0; + + // Now act like a generated client + var input = new CodedInputReader(new ReadOnlySequence(stream.ToArray())); + Assert.AreEqual(WireFormat.MakeTag(1, WireFormat.WireType.StartGroup), input.ReadTag()); + + try + { + input.SkipLastField(); + Assert.Fail(); + } + catch (InvalidProtocolBufferException) + { + } + } + + protected override void AssertReadVarint(byte[] data, ulong value) + { + CodedInputReader input = new CodedInputReader(new ReadOnlySequence(data)); + Assert.AreEqual((uint)value, input.ReadRawVarint32()); + + Assert.AreEqual(true, input.IsAtEnd); + + input = new CodedInputReader(new ReadOnlySequence(data)); + Assert.AreEqual(value, input.ReadRawVarint64()); + + Assert.AreEqual(true, input.IsAtEnd); + } + + protected override void AssertReadVarintFailure(InvalidProtocolBufferException expected, byte[] data) + { + var exception = Assert.Throws(() => + { + CodedInputReader input = new CodedInputReader(new ReadOnlySequence(data)); + input.ReadRawVarint32(); + }); + Assert.AreEqual(expected.Message, exception.Message); + + exception = Assert.Throws(() => + { + CodedInputReader input = new CodedInputReader(new ReadOnlySequence(data)); + input.ReadRawVarint64(); + }); + Assert.AreEqual(expected.Message, exception.Message); + } + + protected override void AssertReadLittleEndian32(byte[] data, uint value) + { + CodedInputReader input = new CodedInputReader(new ReadOnlySequence(data)); + Assert.AreEqual(value, input.ReadRawLittleEndian32()); + Assert.IsTrue(input.IsAtEnd); + } + + protected override void AssertReadLittleEndian64(byte[] data, ulong value) + { + CodedInputReader input = new CodedInputReader(new ReadOnlySequence(data)); + Assert.AreEqual(value, input.ReadRawLittleEndian64()); + Assert.IsTrue(input.IsAtEnd); + } + + protected override void ReadTag(byte[] data) + { + CodedInputReader input = new CodedInputReader(new ReadOnlySequence(data)); + input.ReadTag(); + } + + protected override void AssertEnum(byte[] data, int value) + { + CodedInputReader input = new CodedInputReader(new ReadOnlySequence(data)); + Assert.AreEqual(value, input.ReadEnum()); + Assert.IsTrue(input.IsAtEnd); + } + + protected override void AssertReadFloat(byte[] data, float value) + { + CodedInputReader input = new CodedInputReader(new ReadOnlySequence(data)); + + Assert.AreEqual(value, input.ReadFloat()); + Assert.IsTrue(input.IsAtEnd); + } + + protected override void AssertReadDouble(byte[] data, double value) + { + CodedInputReader input = new CodedInputReader(new ReadOnlySequence(data)); + + Assert.AreEqual(value, input.ReadDouble()); + Assert.IsTrue(input.IsAtEnd); + } + + protected override T ParseFrom(MessageParser messageParser, ByteString bytes) + { + CodedInputReader input = new CodedInputReader(new ReadOnlySequence(bytes.ToByteArray())); + return messageParser.ParseFrom(ref input); + } + + protected override T ParseFromWithLimits(MessageParser messageParser, ByteString bytes, int sizeLimit, int resursionLimits) + { + CodedInputReader input = CodedInputReader.CreateWithLimits(new ReadOnlySequence(bytes.ToByteArray()), resursionLimits); + return messageParser.ParseFrom(ref input); + } + } +} +#endif \ No newline at end of file diff --git a/csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs b/csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs index ba65b328e806..30762dc927b6 100644 --- a/csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs +++ b/csharp/src/Google.Protobuf.Test/CodedInputStreamTest.cs @@ -37,195 +37,8 @@ namespace Google.Protobuf { - public class CodedInputStreamTest + public class CodedInputStreamTest : CodedInputTestBase { - /// - /// Helper to construct a byte array from a bunch of bytes. The inputs are - /// actually ints so that I can use hex notation and not get stupid errors - /// about precision. - /// - private static byte[] Bytes(params int[] bytesAsInts) - { - byte[] bytes = new byte[bytesAsInts.Length]; - for (int i = 0; i < bytesAsInts.Length; i++) - { - bytes[i] = (byte) bytesAsInts[i]; - } - return bytes; - } - - /// - /// Parses the given bytes using ReadRawVarint32() and ReadRawVarint64() - /// - private static void AssertReadVarint(byte[] data, ulong value) - { - CodedInputStream input = new CodedInputStream(data); - Assert.AreEqual((uint) value, input.ReadRawVarint32()); - - input = new CodedInputStream(data); - Assert.AreEqual(value, input.ReadRawVarint64()); - Assert.IsTrue(input.IsAtEnd); - - // Try different block sizes. - for (int bufferSize = 1; bufferSize <= 16; bufferSize *= 2) - { - input = new CodedInputStream(new SmallBlockInputStream(data, bufferSize)); - Assert.AreEqual((uint) value, input.ReadRawVarint32()); - - input = new CodedInputStream(new SmallBlockInputStream(data, bufferSize)); - Assert.AreEqual(value, input.ReadRawVarint64()); - Assert.IsTrue(input.IsAtEnd); - } - - // Try reading directly from a MemoryStream. We want to verify that it - // doesn't read past the end of the input, so write an extra byte - this - // lets us test the position at the end. - MemoryStream memoryStream = new MemoryStream(); - memoryStream.Write(data, 0, data.Length); - memoryStream.WriteByte(0); - memoryStream.Position = 0; - Assert.AreEqual((uint) value, CodedInputStream.ReadRawVarint32(memoryStream)); - Assert.AreEqual(data.Length, memoryStream.Position); - } - - /// - /// Parses the given bytes using ReadRawVarint32() and ReadRawVarint64() and - /// expects them to fail with an InvalidProtocolBufferException whose - /// description matches the given one. - /// - private static void AssertReadVarintFailure(InvalidProtocolBufferException expected, byte[] data) - { - CodedInputStream input = new CodedInputStream(data); - var exception = Assert.Throws(() => input.ReadRawVarint32()); - Assert.AreEqual(expected.Message, exception.Message); - - input = new CodedInputStream(data); - exception = Assert.Throws(() => input.ReadRawVarint64()); - Assert.AreEqual(expected.Message, exception.Message); - - // Make sure we get the same error when reading directly from a Stream. - exception = Assert.Throws(() => CodedInputStream.ReadRawVarint32(new MemoryStream(data))); - Assert.AreEqual(expected.Message, exception.Message); - } - - [Test] - public void ReadVarint() - { - AssertReadVarint(Bytes(0x00), 0); - AssertReadVarint(Bytes(0x01), 1); - AssertReadVarint(Bytes(0x7f), 127); - // 14882 - AssertReadVarint(Bytes(0xa2, 0x74), (0x22 << 0) | (0x74 << 7)); - // 2961488830 - AssertReadVarint(Bytes(0xbe, 0xf7, 0x92, 0x84, 0x0b), - (0x3e << 0) | (0x77 << 7) | (0x12 << 14) | (0x04 << 21) | - (0x0bL << 28)); - - // 64-bit - // 7256456126 - AssertReadVarint(Bytes(0xbe, 0xf7, 0x92, 0x84, 0x1b), - (0x3e << 0) | (0x77 << 7) | (0x12 << 14) | (0x04 << 21) | - (0x1bL << 28)); - // 41256202580718336 - AssertReadVarint(Bytes(0x80, 0xe6, 0xeb, 0x9c, 0xc3, 0xc9, 0xa4, 0x49), - (0x00 << 0) | (0x66 << 7) | (0x6b << 14) | (0x1c << 21) | - (0x43L << 28) | (0x49L << 35) | (0x24L << 42) | (0x49L << 49)); - // 11964378330978735131 - AssertReadVarint(Bytes(0x9b, 0xa8, 0xf9, 0xc2, 0xbb, 0xd6, 0x80, 0x85, 0xa6, 0x01), - (0x1b << 0) | (0x28 << 7) | (0x79 << 14) | (0x42 << 21) | - (0x3bUL << 28) | (0x56UL << 35) | (0x00UL << 42) | - (0x05UL << 49) | (0x26UL << 56) | (0x01UL << 63)); - - // Failures - AssertReadVarintFailure( - InvalidProtocolBufferException.MalformedVarint(), - Bytes(0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, - 0x00)); - AssertReadVarintFailure( - InvalidProtocolBufferException.TruncatedMessage(), - Bytes(0x80)); - } - - /// - /// Parses the given bytes using ReadRawLittleEndian32() and checks - /// that the result matches the given value. - /// - private static void AssertReadLittleEndian32(byte[] data, uint value) - { - CodedInputStream input = new CodedInputStream(data); - Assert.AreEqual(value, input.ReadRawLittleEndian32()); - Assert.IsTrue(input.IsAtEnd); - - // Try different block sizes. - for (int blockSize = 1; blockSize <= 16; blockSize *= 2) - { - input = new CodedInputStream( - new SmallBlockInputStream(data, blockSize)); - Assert.AreEqual(value, input.ReadRawLittleEndian32()); - Assert.IsTrue(input.IsAtEnd); - } - } - - /// - /// Parses the given bytes using ReadRawLittleEndian64() and checks - /// that the result matches the given value. - /// - private static void AssertReadLittleEndian64(byte[] data, ulong value) - { - CodedInputStream input = new CodedInputStream(data); - Assert.AreEqual(value, input.ReadRawLittleEndian64()); - Assert.IsTrue(input.IsAtEnd); - - // Try different block sizes. - for (int blockSize = 1; blockSize <= 16; blockSize *= 2) - { - input = new CodedInputStream( - new SmallBlockInputStream(data, blockSize)); - Assert.AreEqual(value, input.ReadRawLittleEndian64()); - Assert.IsTrue(input.IsAtEnd); - } - } - - [Test] - public void ReadLittleEndian() - { - AssertReadLittleEndian32(Bytes(0x78, 0x56, 0x34, 0x12), 0x12345678); - AssertReadLittleEndian32(Bytes(0xf0, 0xde, 0xbc, 0x9a), 0x9abcdef0); - - AssertReadLittleEndian64(Bytes(0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12), - 0x123456789abcdef0L); - AssertReadLittleEndian64( - Bytes(0x78, 0x56, 0x34, 0x12, 0xf0, 0xde, 0xbc, 0x9a), 0x9abcdef012345678UL); - } - - [Test] - public void DecodeZigZag32() - { - Assert.AreEqual(0, CodedInputStream.DecodeZigZag32(0)); - Assert.AreEqual(-1, CodedInputStream.DecodeZigZag32(1)); - Assert.AreEqual(1, CodedInputStream.DecodeZigZag32(2)); - Assert.AreEqual(-2, CodedInputStream.DecodeZigZag32(3)); - Assert.AreEqual(0x3FFFFFFF, CodedInputStream.DecodeZigZag32(0x7FFFFFFE)); - Assert.AreEqual(unchecked((int) 0xC0000000), CodedInputStream.DecodeZigZag32(0x7FFFFFFF)); - Assert.AreEqual(0x7FFFFFFF, CodedInputStream.DecodeZigZag32(0xFFFFFFFE)); - Assert.AreEqual(unchecked((int) 0x80000000), CodedInputStream.DecodeZigZag32(0xFFFFFFFF)); - } - - [Test] - public void DecodeZigZag64() - { - Assert.AreEqual(0, CodedInputStream.DecodeZigZag64(0)); - Assert.AreEqual(-1, CodedInputStream.DecodeZigZag64(1)); - Assert.AreEqual(1, CodedInputStream.DecodeZigZag64(2)); - Assert.AreEqual(-2, CodedInputStream.DecodeZigZag64(3)); - Assert.AreEqual(0x000000003FFFFFFFL, CodedInputStream.DecodeZigZag64(0x000000007FFFFFFEL)); - Assert.AreEqual(unchecked((long) 0xFFFFFFFFC0000000L), CodedInputStream.DecodeZigZag64(0x000000007FFFFFFFL)); - Assert.AreEqual(0x000000007FFFFFFFL, CodedInputStream.DecodeZigZag64(0x00000000FFFFFFFEL)); - Assert.AreEqual(unchecked((long) 0xFFFFFFFF80000000L), CodedInputStream.DecodeZigZag64(0x00000000FFFFFFFFL)); - Assert.AreEqual(0x7FFFFFFFFFFFFFFFL, CodedInputStream.DecodeZigZag64(0xFFFFFFFFFFFFFFFEL)); - Assert.AreEqual(unchecked((long) 0x8000000000000000L), CodedInputStream.DecodeZigZag64(0xFFFFFFFFFFFFFFFFL)); - } - [Test] public void ReadWholeMessage_VaryingBlockSizes() { @@ -243,109 +56,13 @@ public void ReadWholeMessage_VaryingBlockSizes() Assert.AreEqual(message, message2); } } - - [Test] - public void ReadHugeBlob() - { - // Allocate and initialize a 1MB blob. - byte[] blob = new byte[1 << 20]; - for (int i = 0; i < blob.Length; i++) - { - blob[i] = (byte) i; - } - - // Make a message containing it. - var message = new TestAllTypes { SingleBytes = ByteString.CopyFrom(blob) }; - - // Serialize and parse it. Make sure to parse from an InputStream, not - // directly from a ByteString, so that CodedInputStream uses buffered - // reading. - TestAllTypes message2 = TestAllTypes.Parser.ParseFrom(message.ToByteString()); - - Assert.AreEqual(message, message2); - } - - [Test] - public void ReadMaliciouslyLargeBlob() - { - MemoryStream ms = new MemoryStream(); - CodedOutputStream output = new CodedOutputStream(ms); - - uint tag = WireFormat.MakeTag(1, WireFormat.WireType.LengthDelimited); - output.WriteRawVarint32(tag); - output.WriteRawVarint32(0x7FFFFFFF); - output.WriteRawBytes(new byte[32]); // Pad with a few random bytes. - output.Flush(); - ms.Position = 0; - - CodedInputStream input = new CodedInputStream(ms); - Assert.AreEqual(tag, input.ReadTag()); - - Assert.Throws(() => input.ReadBytes()); - } - - // Representations of a tag for field 0 with various wire types - [Test] - [TestCase(0)] - [TestCase(1)] - [TestCase(2)] - [TestCase(3)] - [TestCase(4)] - [TestCase(5)] - public void ReadTag_ZeroFieldRejected(byte tag) - { - CodedInputStream cis = new CodedInputStream(new byte[] { tag }); - Assert.Throws(() => cis.ReadTag()); - } - - internal static TestRecursiveMessage MakeRecursiveMessage(int depth) - { - if (depth == 0) - { - return new TestRecursiveMessage { I = 5 }; - } - else - { - return new TestRecursiveMessage { A = MakeRecursiveMessage(depth - 1) }; - } - } - - internal static void AssertMessageDepth(TestRecursiveMessage message, int depth) - { - if (depth == 0) - { - Assert.IsNull(message.A); - Assert.AreEqual(5, message.I); - } - else - { - Assert.IsNotNull(message.A); - AssertMessageDepth(message.A, depth - 1); - } - } - - [Test] - public void MaliciousRecursion() - { - ByteString atRecursiveLimit = MakeRecursiveMessage(CodedInputStream.DefaultRecursionLimit).ToByteString(); - ByteString beyondRecursiveLimit = MakeRecursiveMessage(CodedInputStream.DefaultRecursionLimit + 1).ToByteString(); - - AssertMessageDepth(TestRecursiveMessage.Parser.ParseFrom(atRecursiveLimit), CodedInputStream.DefaultRecursionLimit); - - Assert.Throws(() => TestRecursiveMessage.Parser.ParseFrom(beyondRecursiveLimit)); - - CodedInputStream input = CodedInputStream.CreateWithLimits(new MemoryStream(atRecursiveLimit.ToByteArray()), 1000000, CodedInputStream.DefaultRecursionLimit - 1); - Assert.Throws(() => TestRecursiveMessage.Parser.ParseFrom(input)); - } [Test] public void SizeLimit() { - // Have to use a Stream rather than ByteString.CreateCodedInput as SizeLimit doesn't - // apply to the latter case. - MemoryStream ms = new MemoryStream(SampleMessages.CreateFullTestAllTypes().ToByteArray()); - CodedInputStream input = CodedInputStream.CreateWithLimits(ms, 16, 100); - Assert.Throws(() => TestAllTypes.Parser.ParseFrom(input)); + var data = ByteString.CopyFrom(SampleMessages.CreateFullTestAllTypes().ToByteArray()); + + Assert.Throws(() => ParseFromWithLimits(TestAllTypes.Parser, data, sizeLimit: 16, resursionLimits: 100)); } /// @@ -430,15 +147,6 @@ public override int Read(byte[] buffer, int offset, int count) } } - [Test] - public void TestNegativeEnum() - { - byte[] bytes = { 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01 }; - CodedInputStream input = new CodedInputStream(bytes); - Assert.AreEqual((int)SampleEnum.NegativeValue, input.ReadEnum()); - Assert.IsTrue(input.IsAtEnd); - } - //Issue 71: CodedInputStream.ReadBytes go to slow path unnecessarily [Test] public void TestSlowPathAvoidance() @@ -465,13 +173,6 @@ public void TestSlowPathAvoidance() } } - [Test] - public void Tag0Throws() - { - var input = new CodedInputStream(new byte[] { 0 }); - Assert.Throws(() => input.ReadTag()); - } - [Test] public void SkipGroup() { @@ -693,6 +394,124 @@ private static byte[] GenerateBigSerializedMessage() return message.ToByteArray(); } + protected override void AssertReadVarint(byte[] data, ulong value) + { + CodedInputStream input = new CodedInputStream(data); + Assert.AreEqual((uint)value, input.ReadRawVarint32()); + + input = new CodedInputStream(data); + Assert.AreEqual(value, input.ReadRawVarint64()); + Assert.IsTrue(input.IsAtEnd); + + // Try different block sizes. + for (int bufferSize = 1; bufferSize <= 16; bufferSize *= 2) + { + input = new CodedInputStream(new SmallBlockInputStream(data, bufferSize)); + Assert.AreEqual((uint)value, input.ReadRawVarint32()); + + input = new CodedInputStream(new SmallBlockInputStream(data, bufferSize)); + Assert.AreEqual(value, input.ReadRawVarint64()); + Assert.IsTrue(input.IsAtEnd); + } + + // Try reading directly from a MemoryStream. We want to verify that it + // doesn't read past the end of the input, so write an extra byte - this + // lets us test the position at the end. + MemoryStream memoryStream = new MemoryStream(); + memoryStream.Write(data, 0, data.Length); + memoryStream.WriteByte(0); + memoryStream.Position = 0; + Assert.AreEqual((uint)value, CodedInputStream.ReadRawVarint32(memoryStream)); + Assert.AreEqual(data.Length, memoryStream.Position); + } + + protected override void AssertReadVarintFailure(InvalidProtocolBufferException expected, byte[] data) + { + CodedInputStream input = new CodedInputStream(data); + var exception = Assert.Throws(() => input.ReadRawVarint32()); + Assert.AreEqual(expected.Message, exception.Message); + + input = new CodedInputStream(data); + exception = Assert.Throws(() => input.ReadRawVarint64()); + Assert.AreEqual(expected.Message, exception.Message); + + // Make sure we get the same error when reading directly from a Stream. + exception = Assert.Throws(() => CodedInputStream.ReadRawVarint32(new MemoryStream(data))); + Assert.AreEqual(expected.Message, exception.Message); + } + + protected override void AssertReadLittleEndian32(byte[] data, uint value) + { + CodedInputStream input = new CodedInputStream(data); + Assert.AreEqual(value, input.ReadRawLittleEndian32()); + Assert.IsTrue(input.IsAtEnd); + + // Try different block sizes. + for (int blockSize = 1; blockSize <= 16; blockSize *= 2) + { + input = new CodedInputStream( + new SmallBlockInputStream(data, blockSize)); + Assert.AreEqual(value, input.ReadRawLittleEndian32()); + Assert.IsTrue(input.IsAtEnd); + } + } + + protected override void AssertReadLittleEndian64(byte[] data, ulong value) + { + CodedInputStream input = new CodedInputStream(data); + Assert.AreEqual(value, input.ReadRawLittleEndian64()); + Assert.IsTrue(input.IsAtEnd); + + // Try different block sizes. + for (int blockSize = 1; blockSize <= 16; blockSize *= 2) + { + input = new CodedInputStream( + new SmallBlockInputStream(data, blockSize)); + Assert.AreEqual(value, input.ReadRawLittleEndian64()); + Assert.IsTrue(input.IsAtEnd); + } + } + + protected override void AssertEnum(byte[] data, int value) + { + CodedInputStream input = new CodedInputStream(data); + Assert.AreEqual(value, input.ReadEnum()); + Assert.IsTrue(input.IsAtEnd); + } + + protected override void ReadTag(byte[] data) + { + CodedInputStream input = new CodedInputStream(data); + input.ReadTag(); + } + + protected override void AssertReadFloat(byte[] data, float value) + { + CodedInputStream input = new CodedInputStream(data); + + Assert.AreEqual(value, input.ReadFloat()); + Assert.IsTrue(input.IsAtEnd); + } + + protected override void AssertReadDouble(byte[] data, double value) + { + CodedInputStream input = new CodedInputStream(data); + + Assert.AreEqual(value, input.ReadDouble()); + Assert.IsTrue(input.IsAtEnd); + } + + protected override T ParseFrom(MessageParser messageParser, ByteString bytes) + { + return messageParser.ParseFrom(bytes); + } + + protected override T ParseFromWithLimits(MessageParser messageParser, ByteString bytes, int sizeLimit, int resursionLimits) + { + CodedInputStream input = CodedInputStream.CreateWithLimits(new MemoryStream(bytes.ToByteArray()), sizeLimit, resursionLimits); + return messageParser.ParseFrom(input); + } + /// /// A MemoryStream that repeats a byte arrays' content a number of times. /// Simulates really large input without consuming loads of memory. Used above diff --git a/csharp/src/Google.Protobuf.Test/CodedInputTestBase.cs b/csharp/src/Google.Protobuf.Test/CodedInputTestBase.cs new file mode 100644 index 000000000000..3bc6eb3ff90d --- /dev/null +++ b/csharp/src/Google.Protobuf.Test/CodedInputTestBase.cs @@ -0,0 +1,279 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + +using System.IO; +using Google.Protobuf.TestProtos; +using NUnit.Framework; + +namespace Google.Protobuf +{ + public abstract class CodedInputTestBase + { + /// + /// Helper to construct a byte array from a bunch of bytes. The inputs are + /// actually ints so that I can use hex notation and not get stupid errors + /// about precision. + /// + protected static byte[] Bytes(params int[] bytesAsInts) + { + byte[] bytes = new byte[bytesAsInts.Length]; + for (int i = 0; i < bytesAsInts.Length; i++) + { + bytes[i] = (byte) bytesAsInts[i]; + } + return bytes; + } + + /// + /// Parses the given bytes using ReadRawVarint32() and ReadRawVarint64() + /// + protected abstract void AssertReadVarint(byte[] data, ulong value); + + /// + /// Parses the given bytes using ReadRawVarint32() and ReadRawVarint64() and + /// expects them to fail with an InvalidProtocolBufferException whose + /// description matches the given one. + /// + protected abstract void AssertReadVarintFailure(InvalidProtocolBufferException expected, byte[] data); + + /// + /// Parses the given bytes using ReadRawLittleEndian32() and checks + /// that the result matches the given value. + /// + protected abstract void AssertReadLittleEndian32(byte[] data, uint value); + + /// + /// Parses the given bytes using ReadRawLittleEndian64() and checks + /// that the result matches the given value. + /// + protected abstract void AssertReadLittleEndian64(byte[] data, ulong value); + + protected abstract void AssertEnum(byte[] data, int value); + + protected abstract void ReadTag(byte[] data); + + protected abstract void AssertReadFloat(byte[] data, float value); + + protected abstract void AssertReadDouble(byte[] data, double value); + + protected abstract T ParseFrom(MessageParser messageParser, ByteString bytes) where T : IMessage; + + protected abstract T ParseFromWithLimits(MessageParser messageParser, ByteString bytes, int sizeLimit, int resursionLimits) where T : IMessage; + + internal static TestRecursiveMessage MakeRecursiveMessage(int depth) + { + if (depth == 0) + { + return new TestRecursiveMessage { I = 5 }; + } + else + { + return new TestRecursiveMessage { A = MakeRecursiveMessage(depth - 1) }; + } + } + + internal static void AssertMessageDepth(TestRecursiveMessage message, int depth) + { + if (depth == 0) + { + Assert.IsNull(message.A); + Assert.AreEqual(5, message.I); + } + else + { + Assert.IsNotNull(message.A); + AssertMessageDepth(message.A, depth - 1); + } + } + + [Test] + public void MaliciousRecursion() + { + ByteString atRecursiveLimit = MakeRecursiveMessage(CodedInputStream.DefaultRecursionLimit).ToByteString(); + ByteString beyondRecursiveLimit = MakeRecursiveMessage(CodedInputStream.DefaultRecursionLimit + 1).ToByteString(); + + AssertMessageDepth(ParseFrom(TestRecursiveMessage.Parser, atRecursiveLimit), CodedInputStream.DefaultRecursionLimit); + + Assert.Throws(() => ParseFrom(TestRecursiveMessage.Parser, beyondRecursiveLimit)); + + CodedInputStream input = CodedInputStream.CreateWithLimits(new MemoryStream(atRecursiveLimit.ToByteArray()), 1000000, CodedInputStream.DefaultRecursionLimit - 1); + Assert.Throws(() => TestRecursiveMessage.Parser.ParseFrom(input)); + + Assert.Throws(() => ParseFromWithLimits(TestRecursiveMessage.Parser, atRecursiveLimit, sizeLimit: 1000000, resursionLimits: CodedInputStream.DefaultRecursionLimit - 1)); + } + + [Test] + public void ReadHugeBlob() + { + // Allocate and initialize a 1MB blob. + byte[] blob = new byte[1 << 20]; + for (int i = 0; i < blob.Length; i++) + { + blob[i] = (byte)i; + } + + // Make a message containing it. + var message = new TestAllTypes { SingleBytes = ByteString.CopyFrom(blob) }; + + // Serialize and parse it. Make sure to parse from an InputStream, not + // directly from a ByteString, so that CodedInputStream uses buffered + // reading. + TestAllTypes message2 = ParseFrom(TestAllTypes.Parser, message.ToByteString()); + + Assert.AreEqual(message, message2); + } + + [Test] + public void ReadLittleEndian() + { + AssertReadLittleEndian32(Bytes(0x78, 0x56, 0x34, 0x12), 0x12345678); + AssertReadLittleEndian32(Bytes(0xf0, 0xde, 0xbc, 0x9a), 0x9abcdef0); + + AssertReadLittleEndian64(Bytes(0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12), + 0x123456789abcdef0L); + AssertReadLittleEndian64( + Bytes(0x78, 0x56, 0x34, 0x12, 0xf0, 0xde, 0xbc, 0x9a), 0x9abcdef012345678UL); + } + + [Test] + public void ReadVarint() + { + AssertReadVarint(Bytes(0x00), 0); + AssertReadVarint(Bytes(0x01), 1); + AssertReadVarint(Bytes(0x7f), 127); + // 14882 + AssertReadVarint(Bytes(0xa2, 0x74), (0x22 << 0) | (0x74 << 7)); + // 2961488830 + AssertReadVarint(Bytes(0xbe, 0xf7, 0x92, 0x84, 0x0b), + (0x3e << 0) | (0x77 << 7) | (0x12 << 14) | (0x04 << 21) | + (0x0bL << 28)); + + // 64-bit + // 7256456126 + AssertReadVarint(Bytes(0xbe, 0xf7, 0x92, 0x84, 0x1b), + (0x3e << 0) | (0x77 << 7) | (0x12 << 14) | (0x04 << 21) | + (0x1bL << 28)); + // 41256202580718336 + AssertReadVarint(Bytes(0x80, 0xe6, 0xeb, 0x9c, 0xc3, 0xc9, 0xa4, 0x49), + (0x00 << 0) | (0x66 << 7) | (0x6b << 14) | (0x1c << 21) | + (0x43L << 28) | (0x49L << 35) | (0x24L << 42) | (0x49L << 49)); + // 11964378330978735131 + AssertReadVarint(Bytes(0x9b, 0xa8, 0xf9, 0xc2, 0xbb, 0xd6, 0x80, 0x85, 0xa6, 0x01), + (0x1b << 0) | (0x28 << 7) | (0x79 << 14) | (0x42 << 21) | + (0x3bUL << 28) | (0x56UL << 35) | (0x00UL << 42) | + (0x05UL << 49) | (0x26UL << 56) | (0x01UL << 63)); + + // Failures + AssertReadVarintFailure( + InvalidProtocolBufferException.MalformedVarint(), + Bytes(0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, + 0x00)); + AssertReadVarintFailure( + InvalidProtocolBufferException.TruncatedMessage(), + Bytes(0x80)); + } + + // Representations of a tag for field 0 with various wire types + [Test] + [TestCase(0)] + [TestCase(1)] + [TestCase(2)] + [TestCase(3)] + [TestCase(4)] + [TestCase(5)] + public void ReadTag_ZeroFieldRejected(byte tag) + { + try + { + ReadTag(new byte[] { tag }); + Assert.Fail(); + } + catch (InvalidProtocolBufferException) + { + } + } + + [Test] + public void TestNegativeEnum() + { + byte[] bytes = { 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01 }; + + AssertEnum(bytes, (int)SampleEnum.NegativeValue); + } + + [Test] + public void DecodeZigZag32() + { + Assert.AreEqual(0, CodedInputStream.DecodeZigZag32(0)); + Assert.AreEqual(-1, CodedInputStream.DecodeZigZag32(1)); + Assert.AreEqual(1, CodedInputStream.DecodeZigZag32(2)); + Assert.AreEqual(-2, CodedInputStream.DecodeZigZag32(3)); + Assert.AreEqual(0x3FFFFFFF, CodedInputStream.DecodeZigZag32(0x7FFFFFFE)); + Assert.AreEqual(unchecked((int)0xC0000000), CodedInputStream.DecodeZigZag32(0x7FFFFFFF)); + Assert.AreEqual(0x7FFFFFFF, CodedInputStream.DecodeZigZag32(0xFFFFFFFE)); + Assert.AreEqual(unchecked((int)0x80000000), CodedInputStream.DecodeZigZag32(0xFFFFFFFF)); + } + + [Test] + public void DecodeZigZag64() + { + Assert.AreEqual(0, CodedInputStream.DecodeZigZag64(0)); + Assert.AreEqual(-1, CodedInputStream.DecodeZigZag64(1)); + Assert.AreEqual(1, CodedInputStream.DecodeZigZag64(2)); + Assert.AreEqual(-2, CodedInputStream.DecodeZigZag64(3)); + Assert.AreEqual(0x000000003FFFFFFFL, CodedInputStream.DecodeZigZag64(0x000000007FFFFFFEL)); + Assert.AreEqual(unchecked((long)0xFFFFFFFFC0000000L), CodedInputStream.DecodeZigZag64(0x000000007FFFFFFFL)); + Assert.AreEqual(0x000000007FFFFFFFL, CodedInputStream.DecodeZigZag64(0x00000000FFFFFFFEL)); + Assert.AreEqual(unchecked((long)0xFFFFFFFF80000000L), CodedInputStream.DecodeZigZag64(0x00000000FFFFFFFFL)); + Assert.AreEqual(0x7FFFFFFFFFFFFFFFL, CodedInputStream.DecodeZigZag64(0xFFFFFFFFFFFFFFFEL)); + Assert.AreEqual(unchecked((long)0x8000000000000000L), CodedInputStream.DecodeZigZag64(0xFFFFFFFFFFFFFFFFL)); + } + + [Test] + public void ReadFloat() + { + AssertReadFloat(new byte[] { 0, 0, 0, 0 }, 0f); + AssertReadFloat(new byte[] { 205, 204, 140, 63 }, 1.1f); + AssertReadFloat(new byte[] { 255, 255, 127, 127 }, float.MaxValue); + AssertReadFloat(new byte[] { 255, 255, 127, 255 }, float.MinValue); + } + + [Test] + public void ReadDouble() + { + AssertReadDouble(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }, 0f); + AssertReadDouble(new byte[] { 0, 0, 0, 160, 153, 153, 241, 63 }, 1.1f); + AssertReadDouble(new byte[] { 255, 255, 255, 255, 255, 255, 239, 127 }, double.MaxValue); + AssertReadDouble(new byte[] { 255, 255, 255, 255, 255, 255, 239, 255 }, double.MinValue); + } + } +} diff --git a/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs b/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs index 98cabd55adc4..a56b40704583 100644 --- a/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs +++ b/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs @@ -32,164 +32,14 @@ using System; using System.IO; +using System.Text; using Google.Protobuf.TestProtos; using NUnit.Framework; namespace Google.Protobuf { - public class CodedOutputStreamTest + public class CodedOutputStreamTest : CodedOutputTestBase { - /// - /// Writes the given value using WriteRawVarint32() and WriteRawVarint64() and - /// checks that the result matches the given bytes - /// - private static void AssertWriteVarint(byte[] data, ulong value) - { - // Only do 32-bit write if the value fits in 32 bits. - if ((value >> 32) == 0) - { - MemoryStream rawOutput = new MemoryStream(); - CodedOutputStream output = new CodedOutputStream(rawOutput); - output.WriteRawVarint32((uint) value); - output.Flush(); - Assert.AreEqual(data, rawOutput.ToArray()); - // Also try computing size. - Assert.AreEqual(data.Length, CodedOutputStream.ComputeRawVarint32Size((uint) value)); - } - - { - MemoryStream rawOutput = new MemoryStream(); - CodedOutputStream output = new CodedOutputStream(rawOutput); - output.WriteRawVarint64(value); - output.Flush(); - Assert.AreEqual(data, rawOutput.ToArray()); - - // Also try computing size. - Assert.AreEqual(data.Length, CodedOutputStream.ComputeRawVarint64Size(value)); - } - - // Try different buffer sizes. - for (int bufferSize = 1; bufferSize <= 16; bufferSize *= 2) - { - // Only do 32-bit write if the value fits in 32 bits. - if ((value >> 32) == 0) - { - MemoryStream rawOutput = new MemoryStream(); - CodedOutputStream output = - new CodedOutputStream(rawOutput, bufferSize); - output.WriteRawVarint32((uint) value); - output.Flush(); - Assert.AreEqual(data, rawOutput.ToArray()); - } - - { - MemoryStream rawOutput = new MemoryStream(); - CodedOutputStream output = new CodedOutputStream(rawOutput, bufferSize); - output.WriteRawVarint64(value); - output.Flush(); - Assert.AreEqual(data, rawOutput.ToArray()); - } - } - } - - /// - /// Tests WriteRawVarint32() and WriteRawVarint64() - /// - [Test] - public void WriteVarint() - { - AssertWriteVarint(new byte[] {0x00}, 0); - AssertWriteVarint(new byte[] {0x01}, 1); - AssertWriteVarint(new byte[] {0x7f}, 127); - // 14882 - AssertWriteVarint(new byte[] {0xa2, 0x74}, (0x22 << 0) | (0x74 << 7)); - // 2961488830 - AssertWriteVarint(new byte[] {0xbe, 0xf7, 0x92, 0x84, 0x0b}, - (0x3e << 0) | (0x77 << 7) | (0x12 << 14) | (0x04 << 21) | - (0x0bL << 28)); - - // 64-bit - // 7256456126 - AssertWriteVarint(new byte[] {0xbe, 0xf7, 0x92, 0x84, 0x1b}, - (0x3e << 0) | (0x77 << 7) | (0x12 << 14) | (0x04 << 21) | - (0x1bL << 28)); - // 41256202580718336 - AssertWriteVarint( - new byte[] {0x80, 0xe6, 0xeb, 0x9c, 0xc3, 0xc9, 0xa4, 0x49}, - (0x00 << 0) | (0x66 << 7) | (0x6b << 14) | (0x1c << 21) | - (0x43UL << 28) | (0x49L << 35) | (0x24UL << 42) | (0x49UL << 49)); - // 11964378330978735131 - AssertWriteVarint( - new byte[] {0x9b, 0xa8, 0xf9, 0xc2, 0xbb, 0xd6, 0x80, 0x85, 0xa6, 0x01}, - unchecked((ulong) - ((0x1b << 0) | (0x28 << 7) | (0x79 << 14) | (0x42 << 21) | - (0x3bL << 28) | (0x56L << 35) | (0x00L << 42) | - (0x05L << 49) | (0x26L << 56) | (0x01L << 63)))); - } - - /// - /// Parses the given bytes using WriteRawLittleEndian32() and checks - /// that the result matches the given value. - /// - private static void AssertWriteLittleEndian32(byte[] data, uint value) - { - MemoryStream rawOutput = new MemoryStream(); - CodedOutputStream output = new CodedOutputStream(rawOutput); - output.WriteRawLittleEndian32(value); - output.Flush(); - Assert.AreEqual(data, rawOutput.ToArray()); - - // Try different buffer sizes. - for (int bufferSize = 1; bufferSize <= 16; bufferSize *= 2) - { - rawOutput = new MemoryStream(); - output = new CodedOutputStream(rawOutput, bufferSize); - output.WriteRawLittleEndian32(value); - output.Flush(); - Assert.AreEqual(data, rawOutput.ToArray()); - } - } - - /// - /// Parses the given bytes using WriteRawLittleEndian64() and checks - /// that the result matches the given value. - /// - private static void AssertWriteLittleEndian64(byte[] data, ulong value) - { - MemoryStream rawOutput = new MemoryStream(); - CodedOutputStream output = new CodedOutputStream(rawOutput); - output.WriteRawLittleEndian64(value); - output.Flush(); - Assert.AreEqual(data, rawOutput.ToArray()); - - // Try different block sizes. - for (int blockSize = 1; blockSize <= 16; blockSize *= 2) - { - rawOutput = new MemoryStream(); - output = new CodedOutputStream(rawOutput, blockSize); - output.WriteRawLittleEndian64(value); - output.Flush(); - Assert.AreEqual(data, rawOutput.ToArray()); - } - } - - /// - /// Tests writeRawLittleEndian32() and writeRawLittleEndian64(). - /// - [Test] - public void WriteLittleEndian() - { - AssertWriteLittleEndian32(new byte[] {0x78, 0x56, 0x34, 0x12}, 0x12345678); - AssertWriteLittleEndian32(new byte[] {0xf0, 0xde, 0xbc, 0x9a}, 0x9abcdef0); - - AssertWriteLittleEndian64( - new byte[] {0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12}, - 0x123456789abcdef0L); - AssertWriteLittleEndian64( - new byte[] {0x78, 0x56, 0x34, 0x12, 0xf0, 0xde, 0xbc, 0x9a}, - 0x9abcdef012345678UL); - } - [Test] public void WriteWholeMessage_VaryingBlockSizes() { @@ -207,81 +57,6 @@ public void WriteWholeMessage_VaryingBlockSizes() Assert.AreEqual(rawBytes, rawOutput.ToArray()); } } - - [Test] - public void EncodeZigZag32() - { - Assert.AreEqual(0u, CodedOutputStream.EncodeZigZag32(0)); - Assert.AreEqual(1u, CodedOutputStream.EncodeZigZag32(-1)); - Assert.AreEqual(2u, CodedOutputStream.EncodeZigZag32(1)); - Assert.AreEqual(3u, CodedOutputStream.EncodeZigZag32(-2)); - Assert.AreEqual(0x7FFFFFFEu, CodedOutputStream.EncodeZigZag32(0x3FFFFFFF)); - Assert.AreEqual(0x7FFFFFFFu, CodedOutputStream.EncodeZigZag32(unchecked((int) 0xC0000000))); - Assert.AreEqual(0xFFFFFFFEu, CodedOutputStream.EncodeZigZag32(0x7FFFFFFF)); - Assert.AreEqual(0xFFFFFFFFu, CodedOutputStream.EncodeZigZag32(unchecked((int) 0x80000000))); - } - - [Test] - public void EncodeZigZag64() - { - Assert.AreEqual(0u, CodedOutputStream.EncodeZigZag64(0)); - Assert.AreEqual(1u, CodedOutputStream.EncodeZigZag64(-1)); - Assert.AreEqual(2u, CodedOutputStream.EncodeZigZag64(1)); - Assert.AreEqual(3u, CodedOutputStream.EncodeZigZag64(-2)); - Assert.AreEqual(0x000000007FFFFFFEuL, - CodedOutputStream.EncodeZigZag64(unchecked((long) 0x000000003FFFFFFFUL))); - Assert.AreEqual(0x000000007FFFFFFFuL, - CodedOutputStream.EncodeZigZag64(unchecked((long) 0xFFFFFFFFC0000000UL))); - Assert.AreEqual(0x00000000FFFFFFFEuL, - CodedOutputStream.EncodeZigZag64(unchecked((long) 0x000000007FFFFFFFUL))); - Assert.AreEqual(0x00000000FFFFFFFFuL, - CodedOutputStream.EncodeZigZag64(unchecked((long) 0xFFFFFFFF80000000UL))); - Assert.AreEqual(0xFFFFFFFFFFFFFFFEL, - CodedOutputStream.EncodeZigZag64(unchecked((long) 0x7FFFFFFFFFFFFFFFUL))); - Assert.AreEqual(0xFFFFFFFFFFFFFFFFL, - CodedOutputStream.EncodeZigZag64(unchecked((long) 0x8000000000000000UL))); - } - - [Test] - public void RoundTripZigZag32() - { - // Some easier-to-verify round-trip tests. The inputs (other than 0, 1, -1) - // were chosen semi-randomly via keyboard bashing. - Assert.AreEqual(0, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(0))); - Assert.AreEqual(1, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(1))); - Assert.AreEqual(-1, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(-1))); - Assert.AreEqual(14927, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(14927))); - Assert.AreEqual(-3612, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(-3612))); - } - - [Test] - public void RoundTripZigZag64() - { - Assert.AreEqual(0, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(0))); - Assert.AreEqual(1, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(1))); - Assert.AreEqual(-1, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(-1))); - Assert.AreEqual(14927, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(14927))); - Assert.AreEqual(-3612, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(-3612))); - - Assert.AreEqual(856912304801416L, - CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(856912304801416L))); - Assert.AreEqual(-75123905439571256L, - CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(-75123905439571256L))); - } - - [Test] - public void TestNegativeEnumNoTag() - { - Assert.AreEqual(10, CodedOutputStream.ComputeInt32Size(-2)); - Assert.AreEqual(10, CodedOutputStream.ComputeEnumSize((int) SampleEnum.NegativeValue)); - - byte[] bytes = new byte[10]; - CodedOutputStream output = new CodedOutputStream(bytes); - output.WriteEnum((int) SampleEnum.NegativeValue); - - Assert.AreEqual(0, output.SpaceLeft); - Assert.AreEqual("FE-FF-FF-FF-FF-FF-FF-FF-FF-01", BitConverter.ToString(bytes)); - } [Test] public void TestCodedInputOutputPosition() @@ -422,5 +197,163 @@ public void Dispose_FromByteArray() var stream = new CodedOutputStream(new byte[10]); stream.Dispose(); } + + protected override void AssertWriteVarint(byte[] data, ulong value) + { + // Only do 32-bit write if the value fits in 32 bits. + if ((value >> 32) == 0) + { + MemoryStream rawOutput = new MemoryStream(); + CodedOutputStream output = new CodedOutputStream(rawOutput); + output.WriteRawVarint32((uint)value); + output.Flush(); + Assert.AreEqual(data, rawOutput.ToArray()); + // Also try computing size. + Assert.AreEqual(data.Length, CodedOutputStream.ComputeRawVarint32Size((uint)value)); + } + + { + MemoryStream rawOutput = new MemoryStream(); + CodedOutputStream output = new CodedOutputStream(rawOutput); + output.WriteRawVarint64(value); + output.Flush(); + Assert.AreEqual(data, rawOutput.ToArray()); + + // Also try computing size. + Assert.AreEqual(data.Length, CodedOutputStream.ComputeRawVarint64Size(value)); + } + + // Try different buffer sizes. + for (int bufferSize = 1; bufferSize <= 16; bufferSize *= 2) + { + // Only do 32-bit write if the value fits in 32 bits. + if ((value >> 32) == 0) + { + MemoryStream rawOutput = new MemoryStream(); + CodedOutputStream output = + new CodedOutputStream(rawOutput, bufferSize); + output.WriteRawVarint32((uint)value); + output.Flush(); + Assert.AreEqual(data, rawOutput.ToArray()); + } + + { + MemoryStream rawOutput = new MemoryStream(); + CodedOutputStream output = new CodedOutputStream(rawOutput, bufferSize); + output.WriteRawVarint64(value); + output.Flush(); + Assert.AreEqual(data, rawOutput.ToArray()); + } + } + } + + protected override void AssertWriteLittleEndian32(byte[] data, uint value) + { + MemoryStream rawOutput = new MemoryStream(); + CodedOutputStream output = new CodedOutputStream(rawOutput); + output.WriteRawLittleEndian32(value); + output.Flush(); + Assert.AreEqual(data, rawOutput.ToArray()); + + // Try different buffer sizes. + for (int bufferSize = 1; bufferSize <= 16; bufferSize *= 2) + { + rawOutput = new MemoryStream(); + output = new CodedOutputStream(rawOutput, bufferSize); + output.WriteRawLittleEndian32(value); + output.Flush(); + Assert.AreEqual(data, rawOutput.ToArray()); + } + } + + protected override void AssertWriteLittleEndian64(byte[] data, ulong value) + { + MemoryStream rawOutput = new MemoryStream(); + CodedOutputStream output = new CodedOutputStream(rawOutput); + output.WriteRawLittleEndian64(value); + output.Flush(); + Assert.AreEqual(data, rawOutput.ToArray()); + + // Try different block sizes. + for (int blockSize = 1; blockSize <= 16; blockSize *= 2) + { + rawOutput = new MemoryStream(); + output = new CodedOutputStream(rawOutput, blockSize); + output.WriteRawLittleEndian64(value); + output.Flush(); + Assert.AreEqual(data, rawOutput.ToArray()); + } + } + + protected override void AssertWriteEnum(byte[] data, int value) + { + MemoryStream rawOutput = new MemoryStream(); + CodedOutputStream output = new CodedOutputStream(rawOutput); + output.WriteEnum(value); + output.Flush(); + + Assert.AreEqual(data, rawOutput.ToArray()); + } + + protected override void AssertWriteString(string value) + { + MemoryStream rawOutput = new MemoryStream(); + CodedOutputStream output = new CodedOutputStream(rawOutput); + output.WriteString(value); + output.Flush(); + + CodedInputStream input = new CodedInputStream(rawOutput.ToArray()); + Assert.AreEqual(value, input.ReadString()); + } + + protected override void AssertWriteFloat(byte[] data, float value) + { + MemoryStream rawOutput = new MemoryStream(); + CodedOutputStream output = new CodedOutputStream(rawOutput); + output.WriteFloat(value); + output.Flush(); + Assert.AreEqual(data, rawOutput.ToArray()); + } + + protected override void AssertWriteDouble(byte[] data, double value) + { + MemoryStream rawOutput = new MemoryStream(); + CodedOutputStream output = new CodedOutputStream(rawOutput); + output.WriteDouble(value); + output.Flush(); + Assert.AreEqual(data, rawOutput.ToArray()); + } + + protected override void AssertWriteRawTag(byte[] data, int value) + { + MemoryStream rawOutput = new MemoryStream(); + CodedOutputStream output = new CodedOutputStream(rawOutput); + + switch (data.Length) + { + case 1: + output.WriteRawTag(data[0]); + break; + case 2: + output.WriteRawTag(data[0], data[1]); + break; + case 3: + output.WriteRawTag(data[0], data[1], data[2]); + break; + case 4: + output.WriteRawTag(data[0], data[1], data[2], data[3]); + break; + case 5: + output.WriteRawTag(data[0], data[1], data[2], data[3], data[4]); + break; + default: + throw new ArgumentException(); + } + + output.Flush(); + + CodedInputStream input = new CodedInputStream(rawOutput.ToArray()); + Assert.AreEqual(value, input.ReadTag()); + } } } \ No newline at end of file diff --git a/csharp/src/Google.Protobuf.Test/CodedOutputTestBase.cs b/csharp/src/Google.Protobuf.Test/CodedOutputTestBase.cs new file mode 100644 index 000000000000..d18611dc2489 --- /dev/null +++ b/csharp/src/Google.Protobuf.Test/CodedOutputTestBase.cs @@ -0,0 +1,268 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + +using System.Text; +using NUnit.Framework; + +namespace Google.Protobuf +{ + public abstract class CodedOutputTestBase + { + /// + /// Writes the given value using WriteRawVarint32() and WriteRawVarint64() and + /// checks that the result matches the given bytes + /// + protected abstract void AssertWriteVarint(byte[] data, ulong value); + + /// + /// Parses the given bytes using WriteRawLittleEndian32() and checks + /// that the result matches the given value. + /// + protected abstract void AssertWriteLittleEndian32(byte[] data, uint value); + + /// + /// Parses the given bytes using WriteRawLittleEndian64() and checks + /// that the result matches the given value. + /// + protected abstract void AssertWriteLittleEndian64(byte[] data, ulong value); + + protected abstract void AssertWriteEnum(byte[] data, int value); + + protected abstract void AssertWriteString(string value); + + protected abstract void AssertWriteFloat(byte[] data, float value); + + protected abstract void AssertWriteDouble(byte[] data, double value); + + protected abstract void AssertWriteRawTag(byte[] data, int value); + + /// + /// Tests WriteRawVarint32() and WriteRawVarint64() + /// + [Test] + public void WriteVarint() + { + AssertWriteVarint(new byte[] {0x00}, 0); + AssertWriteVarint(new byte[] {0x01}, 1); + AssertWriteVarint(new byte[] {0x7f}, 127); + // 14882 + AssertWriteVarint(new byte[] {0xa2, 0x74}, (0x22 << 0) | (0x74 << 7)); + // 2961488830 + AssertWriteVarint(new byte[] {0xbe, 0xf7, 0x92, 0x84, 0x0b}, + (0x3e << 0) | (0x77 << 7) | (0x12 << 14) | (0x04 << 21) | + (0x0bL << 28)); + + // 64-bit + // 7256456126 + AssertWriteVarint(new byte[] {0xbe, 0xf7, 0x92, 0x84, 0x1b}, + (0x3e << 0) | (0x77 << 7) | (0x12 << 14) | (0x04 << 21) | + (0x1bL << 28)); + // 41256202580718336 + AssertWriteVarint( + new byte[] {0x80, 0xe6, 0xeb, 0x9c, 0xc3, 0xc9, 0xa4, 0x49}, + (0x00 << 0) | (0x66 << 7) | (0x6b << 14) | (0x1c << 21) | + (0x43UL << 28) | (0x49L << 35) | (0x24UL << 42) | (0x49UL << 49)); + // 11964378330978735131 + AssertWriteVarint( + new byte[] {0x9b, 0xa8, 0xf9, 0xc2, 0xbb, 0xd6, 0x80, 0x85, 0xa6, 0x01}, + unchecked((ulong) + ((0x1b << 0) | (0x28 << 7) | (0x79 << 14) | (0x42 << 21) | + (0x3bL << 28) | (0x56L << 35) | (0x00L << 42) | + (0x05L << 49) | (0x26L << 56) | (0x01L << 63)))); + } + + /// + /// Tests writeRawLittleEndian32() and writeRawLittleEndian64(). + /// + [Test] + public void WriteLittleEndian() + { + AssertWriteLittleEndian32(new byte[] {0x78, 0x56, 0x34, 0x12}, 0x12345678); + AssertWriteLittleEndian32(new byte[] {0xf0, 0xde, 0xbc, 0x9a}, 0x9abcdef0); + + AssertWriteLittleEndian64( + new byte[] {0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12}, + 0x123456789abcdef0L); + AssertWriteLittleEndian64( + new byte[] {0x78, 0x56, 0x34, 0x12, 0xf0, 0xde, 0xbc, 0x9a}, + 0x9abcdef012345678UL); + } + + [Test] + public void EncodeZigZag32() + { + Assert.AreEqual(0u, CodedOutputStream.EncodeZigZag32(0)); + Assert.AreEqual(1u, CodedOutputStream.EncodeZigZag32(-1)); + Assert.AreEqual(2u, CodedOutputStream.EncodeZigZag32(1)); + Assert.AreEqual(3u, CodedOutputStream.EncodeZigZag32(-2)); + Assert.AreEqual(0x7FFFFFFEu, CodedOutputStream.EncodeZigZag32(0x3FFFFFFF)); + Assert.AreEqual(0x7FFFFFFFu, CodedOutputStream.EncodeZigZag32(unchecked((int) 0xC0000000))); + Assert.AreEqual(0xFFFFFFFEu, CodedOutputStream.EncodeZigZag32(0x7FFFFFFF)); + Assert.AreEqual(0xFFFFFFFFu, CodedOutputStream.EncodeZigZag32(unchecked((int) 0x80000000))); + } + + [Test] + public void EncodeZigZag64() + { + Assert.AreEqual(0u, CodedOutputStream.EncodeZigZag64(0)); + Assert.AreEqual(1u, CodedOutputStream.EncodeZigZag64(-1)); + Assert.AreEqual(2u, CodedOutputStream.EncodeZigZag64(1)); + Assert.AreEqual(3u, CodedOutputStream.EncodeZigZag64(-2)); + Assert.AreEqual(0x000000007FFFFFFEuL, + CodedOutputStream.EncodeZigZag64(unchecked((long) 0x000000003FFFFFFFUL))); + Assert.AreEqual(0x000000007FFFFFFFuL, + CodedOutputStream.EncodeZigZag64(unchecked((long) 0xFFFFFFFFC0000000UL))); + Assert.AreEqual(0x00000000FFFFFFFEuL, + CodedOutputStream.EncodeZigZag64(unchecked((long) 0x000000007FFFFFFFUL))); + Assert.AreEqual(0x00000000FFFFFFFFuL, + CodedOutputStream.EncodeZigZag64(unchecked((long) 0xFFFFFFFF80000000UL))); + Assert.AreEqual(0xFFFFFFFFFFFFFFFEL, + CodedOutputStream.EncodeZigZag64(unchecked((long) 0x7FFFFFFFFFFFFFFFUL))); + Assert.AreEqual(0xFFFFFFFFFFFFFFFFL, + CodedOutputStream.EncodeZigZag64(unchecked((long) 0x8000000000000000UL))); + } + + [Test] + public void RoundTripZigZag32() + { + // Some easier-to-verify round-trip tests. The inputs (other than 0, 1, -1) + // were chosen semi-randomly via keyboard bashing. + Assert.AreEqual(0, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(0))); + Assert.AreEqual(1, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(1))); + Assert.AreEqual(-1, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(-1))); + Assert.AreEqual(14927, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(14927))); + Assert.AreEqual(-3612, CodedInputStream.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(-3612))); + } + + [Test] + public void RoundTripZigZag64() + { + Assert.AreEqual(0, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(0))); + Assert.AreEqual(1, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(1))); + Assert.AreEqual(-1, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(-1))); + Assert.AreEqual(14927, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(14927))); + Assert.AreEqual(-3612, CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(-3612))); + + Assert.AreEqual(856912304801416L, + CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(856912304801416L))); + Assert.AreEqual(-75123905439571256L, + CodedInputStream.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(-75123905439571256L))); + } + + [Test] + public void TestNegativeEnumNoTag() + { + Assert.AreEqual(10, CodedOutputStream.ComputeInt32Size(-2)); + Assert.AreEqual(10, CodedOutputStream.ComputeEnumSize((int) SampleEnum.NegativeValue)); + + byte[] bytes = { 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01 }; + + AssertWriteEnum(bytes, (int)SampleEnum.NegativeValue); + } + + [Test] + public void WriteAsciiSmallString() + { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < 32; i++) + { + sb.AppendLine(i.ToString()); + } + + AssertWriteString(sb.ToString()); + } + + [Test] + public void WriteUnicodeSmallString() + { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < 32; i++) + { + sb.AppendLine(i.ToString().Replace("0", "\x1369")); + } + + AssertWriteString(sb.ToString()); + } + + [Test] + public void WriteAsciiLargeString() + { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < 2048; i++) + { + sb.AppendLine(i.ToString()); + } + + AssertWriteString(sb.ToString()); + } + + [Test] + public void WriteUnicodeLargeString() + { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < 2048; i++) + { + sb.AppendLine(i.ToString().Replace("0", "\x1369")); + } + + AssertWriteString(sb.ToString()); + } + + [Test] + public void WriteFloat() + { + AssertWriteFloat(new byte[] { 0, 0, 0, 0 }, 0f); + AssertWriteFloat(new byte[] { 205, 204, 140, 63 }, 1.1f); + AssertWriteFloat(new byte[] { 255, 255, 127, 127 }, float.MaxValue); + AssertWriteFloat(new byte[] { 255, 255, 127, 255 }, float.MinValue); + } + + [Test] + public void WriteDouble() + { + AssertWriteDouble(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }, 0f); + AssertWriteDouble(new byte[] { 0, 0, 0, 160, 153, 153, 241, 63 }, 1.1f); + AssertWriteDouble(new byte[] { 255, 255, 255, 255, 255, 255, 239, 127 }, double.MaxValue); + AssertWriteDouble(new byte[] { 255, 255, 255, 255, 255, 255, 239, 255 }, double.MinValue); + } + + [Test] + public void WriteTag() + { + AssertWriteRawTag(new byte[] { 128, 128, 128, 128, 1 }, 268435456); + AssertWriteRawTag(new byte[] { 128, 128, 128, 1 }, 2097152); + AssertWriteRawTag(new byte[] { 128, 128, 1 }, 16384); + AssertWriteRawTag(new byte[] { 128, 1 }, 128); + AssertWriteRawTag(new byte[] { 127 }, 127); + } + } +} diff --git a/csharp/src/Google.Protobuf.Test/CodedOutputWriterTest.cs b/csharp/src/Google.Protobuf.Test/CodedOutputWriterTest.cs new file mode 100644 index 000000000000..55b05b515443 --- /dev/null +++ b/csharp/src/Google.Protobuf.Test/CodedOutputWriterTest.cs @@ -0,0 +1,282 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY +using System; +using System.Buffers; +using System.IO; +using System.Text; +using Google.Protobuf.Buffers; +using NUnit.Framework; + +namespace Google.Protobuf +{ + public class CodedOutputWriterTest : CodedOutputTestBase + { + [Test] + public void TestCodedInputOutputPosition() + { + byte[] content = new byte[110]; + for (int i = 0; i < content.Length; i++) + content[i] = (byte)i; + + byte[] child; + { + ArrayBufferWriter rawOutput = new ArrayBufferWriter(1024); + CodedOutputWriter cout = new CodedOutputWriter(rawOutput); + // Field 11: numeric value: 500 + cout.WriteTag(11, WireFormat.WireType.Varint); + cout.Flush(); + Assert.AreEqual(1, rawOutput.WrittenCount); + cout.WriteInt32(500); + cout.Flush(); + Assert.AreEqual(3, rawOutput.WrittenCount); + //Field 12: length delimited 120 bytes + cout.WriteTag(12, WireFormat.WireType.LengthDelimited); + cout.Flush(); + Assert.AreEqual(4, rawOutput.WrittenCount); + cout.WriteBytes(ByteString.CopyFrom(content)); + cout.Flush(); + Assert.AreEqual(115, rawOutput.WrittenCount); + // Field 13: fixed numeric value: 501 + cout.WriteTag(13, WireFormat.WireType.Fixed32); + cout.Flush(); + Assert.AreEqual(116, rawOutput.WrittenCount); + cout.WriteSFixed32(501); + cout.Flush(); + Assert.AreEqual(120, rawOutput.WrittenCount); + + child = rawOutput.WrittenSpan.ToArray(); + } + + byte[] bytes; + { + ArrayBufferWriter rawOutput = new ArrayBufferWriter(1024); + CodedOutputWriter cout = new CodedOutputWriter(rawOutput); + // Field 1: numeric value: 500 + cout.WriteTag(1, WireFormat.WireType.Varint); + cout.Flush(); + Assert.AreEqual(1, rawOutput.WrittenCount); + cout.WriteInt32(500); + cout.Flush(); + Assert.AreEqual(3, rawOutput.WrittenCount); + //Field 2: length delimited 120 bytes + cout.WriteTag(2, WireFormat.WireType.LengthDelimited); + cout.Flush(); + Assert.AreEqual(4, rawOutput.WrittenCount); + cout.WriteBytes(ByteString.CopyFrom(child)); + cout.Flush(); + Assert.AreEqual(125, rawOutput.WrittenCount); + // Field 3: fixed numeric value: 500 + cout.WriteTag(3, WireFormat.WireType.Fixed32); + cout.Flush(); + Assert.AreEqual(126, rawOutput.WrittenCount); + cout.WriteSFixed32(501); + cout.Flush(); + Assert.AreEqual(130, rawOutput.WrittenCount); + + bytes = rawOutput.WrittenSpan.ToArray(); + } + + // Now test Input stream: + { + CodedInputReader cin = new CodedInputReader(new ReadOnlySequence(bytes)); + Assert.AreEqual(0, cin.Position); + // Field 1: + uint tag = cin.ReadTag(); + Assert.AreEqual(1, tag >> 3); + Assert.AreEqual(1, cin.Position); + Assert.AreEqual(500, cin.ReadInt32()); + Assert.AreEqual(3, cin.Position); + //Field 2: + tag = cin.ReadTag(); + Assert.AreEqual(2, tag >> 3); + Assert.AreEqual(4, cin.Position); + int childlen = cin.ReadLength(); + Assert.AreEqual(120, childlen); + Assert.AreEqual(5, cin.Position); + Assert.AreEqual(5, cin.Position); + // Now we are reading child message + { + // Field 11: numeric value: 500 + tag = cin.ReadTag(); + Assert.AreEqual(11, tag >> 3); + Assert.AreEqual(6, cin.Position); + Assert.AreEqual(500, cin.ReadInt32()); + Assert.AreEqual(8, cin.Position); + //Field 12: length delimited 120 bytes + tag = cin.ReadTag(); + Assert.AreEqual(12, tag >> 3); + Assert.AreEqual(9, cin.Position); + ByteString bstr = cin.ReadBytes(); + Assert.AreEqual(110, bstr.Length); + Assert.AreEqual((byte) 109, bstr[109]); + Assert.AreEqual(120, cin.Position); + // Field 13: fixed numeric value: 501 + tag = cin.ReadTag(); + Assert.AreEqual(13, tag >> 3); + // ROK - Previously broken here, this returned 126 failing to account for bufferSizeAfterLimit + Assert.AreEqual(121, cin.Position); + Assert.AreEqual(501, cin.ReadSFixed32()); + Assert.AreEqual(125, cin.Position); + } + Assert.AreEqual(125, cin.Position); + // Field 3: fixed numeric value: 501 + tag = cin.ReadTag(); + Assert.AreEqual(3, tag >> 3); + Assert.AreEqual(126, cin.Position); + Assert.AreEqual(501, cin.ReadSFixed32()); + Assert.AreEqual(130, cin.Position); + Assert.IsTrue(cin.IsAtEnd); + } + } + + protected override void AssertWriteVarint(byte[] data, ulong value) + { + // Only do 32-bit write if the value fits in 32 bits. + if ((value >> 32) == 0) + { + ArrayBufferWriter rawOutput = new ArrayBufferWriter(1024); + CodedOutputWriter output = new CodedOutputWriter(rawOutput); + output.WriteRawVarint32((uint)value); + output.Flush(); + Assert.AreEqual(data, rawOutput.WrittenSpan.ToArray()); + // Also try computing size. + Assert.AreEqual(data.Length, CodedOutputStream.ComputeRawVarint32Size((uint)value)); + } + + { + ArrayBufferWriter rawOutput = new ArrayBufferWriter(1024); + CodedOutputWriter output = new CodedOutputWriter(rawOutput); + output.WriteRawVarint64(value); + output.Flush(); + Assert.AreEqual(data, rawOutput.WrittenSpan.ToArray()); + + // Also try computing size. + Assert.AreEqual(data.Length, CodedOutputStream.ComputeRawVarint64Size(value)); + } + } + + protected override void AssertWriteLittleEndian32(byte[] data, uint value) + { + ArrayBufferWriter rawOutput = new ArrayBufferWriter(1024); + CodedOutputWriter output = new CodedOutputWriter(rawOutput); + output.WriteRawLittleEndian32(value); + output.Flush(); + Assert.AreEqual(data, rawOutput.WrittenSpan.ToArray()); + } + + protected override void AssertWriteLittleEndian64(byte[] data, ulong value) + { + ArrayBufferWriter rawOutput = new ArrayBufferWriter(1024); + CodedOutputWriter output = new CodedOutputWriter(rawOutput); + output.WriteRawLittleEndian64(value); + output.Flush(); + Assert.AreEqual(data, rawOutput.WrittenSpan.ToArray()); + } + + protected override void AssertWriteEnum(byte[] data, int value) + { + ArrayBufferWriter rawOutput = new ArrayBufferWriter(10); + CodedOutputWriter output = new CodedOutputWriter(rawOutput); + output.WriteEnum(value); + output.Flush(); + + Assert.AreEqual(data, rawOutput.WrittenSpan.ToArray()); + } + + protected override void AssertWriteString(string value) + { + ArrayBufferWriter rawOutput = new ArrayBufferWriter(1024); + // Limit the max span size to force string to be written in multiple parts + CodedOutputWriter output = new CodedOutputWriter(new MaxSizeHintBufferWriter(rawOutput, 1024)); + output.WriteString(value); + output.Flush(); + + CodedInputReader input = new CodedInputReader(ReadOnlySequenceFactory.SegmentPerByteFactory.CreateWithContent(rawOutput.WrittenSpan.ToArray())); + Assert.AreEqual(value, input.ReadString()); + } + + protected override void AssertWriteFloat(byte[] data, float value) + { + ArrayBufferWriter rawOutput = new ArrayBufferWriter(1024); + CodedOutputWriter output = new CodedOutputWriter(rawOutput); + output.WriteFloat(value); + output.Flush(); + + Assert.AreEqual(data, rawOutput.WrittenSpan.ToArray()); + } + + protected override void AssertWriteDouble(byte[] data, double value) + { + ArrayBufferWriter rawOutput = new ArrayBufferWriter(1024); + CodedOutputWriter output = new CodedOutputWriter(rawOutput); + output.WriteDouble(value); + output.Flush(); + + Assert.AreEqual(data, rawOutput.WrittenSpan.ToArray()); + } + + protected override void AssertWriteRawTag(byte[] data, int value) + { + ArrayBufferWriter rawOutput = new ArrayBufferWriter(1024); + CodedOutputWriter output = new CodedOutputWriter(rawOutput); + + switch (data.Length) + { + case 1: + output.WriteRawTag(data[0]); + break; + case 2: + output.WriteRawTag(data[0], data[1]); + break; + case 3: + output.WriteRawTag(data[0], data[1], data[2]); + break; + case 4: + output.WriteRawTag(data[0], data[1], data[2], data[3]); + break; + case 5: + output.WriteRawTag(data[0], data[1], data[2], data[3], data[4]); + break; + default: + throw new ArgumentException(); + } + + output.Flush(); + + CodedInputReader input = new CodedInputReader(new ReadOnlySequence(rawOutput.WrittenSpan.ToArray())); + Assert.AreEqual(value, input.ReadTag()); + } + } +} +#endif \ No newline at end of file diff --git a/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs b/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs index 527c7d404c46..fb337b1619c6 100644 --- a/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs +++ b/csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs @@ -31,12 +31,16 @@ #endregion using System; +using System.Buffers; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; using System.Linq; using System.Text; +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY +using Google.Protobuf.Buffers; +#endif using Google.Protobuf.TestProtos; using Google.Protobuf.WellKnownTypes; using NUnit.Framework; @@ -382,7 +386,7 @@ public void AddEntriesFrom_String() } [Test] - public void AddEntriesFrom_Message() + public void AddEntriesFrom_CodedInputStream_Message() { var message1 = new ForeignMessage { C = 2000 }; var message2 = new ForeignMessage { C = -250 }; @@ -405,6 +409,31 @@ public void AddEntriesFrom_Message() Assert.IsTrue(input.IsAtEnd); } +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + [Test] + public void AddEntriesFrom_CodedInputReader_Message() + { + var message1 = new ForeignMessage { C = 2000 }; + var message2 = new ForeignMessage { C = -250 }; + + uint tag = WireFormat.MakeTag(10, WireFormat.WireType.LengthDelimited); + var bufferWriter = new ArrayBufferWriter(); + var output = new CodedOutputWriter(bufferWriter); + output.WriteTag(tag); + output.WriteMessage(message1); + output.WriteTag(tag); + output.WriteMessage(message2); + output.Flush(); + + var field = new RepeatedField(); + var input = new CodedInputReader(new ReadOnlySequence(bufferWriter.WrittenSpan.ToArray())); + input.AssertNextTag(tag); + field.AddEntriesFrom(ref input, FieldCodec.ForMessage(tag, ForeignMessage.Parser)); + CollectionAssert.AreEqual(new[] { message1, message2 }, field); + Assert.IsTrue(input.IsAtEnd); + } +#endif + [Test] public void WriteTo_PackedInt32() { @@ -469,7 +498,7 @@ public void WriteTo_String() } [Test] - public void WriteTo_Message() + public void WriteTo_CodedInputStream_Message() { var message1 = new ForeignMessage { C = 20 }; var message2 = new ForeignMessage { C = 25 }; @@ -489,6 +518,28 @@ public void WriteTo_Message() Assert.IsTrue(input.IsAtEnd); } +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + [Test] + public void WriteTo_CodedInputReader_Message() + { + var message1 = new ForeignMessage { C = 20 }; + var message2 = new ForeignMessage { C = 25 }; + uint tag = WireFormat.MakeTag(10, WireFormat.WireType.LengthDelimited); + var field = new RepeatedField { message1, message2 }; + var bufferWriter = new ArrayBufferWriter(); + var output = new CodedOutputWriter(bufferWriter); + field.WriteTo(ref output, FieldCodec.ForMessage(tag, ForeignMessage.Parser)); + output.Flush(); + + var input = new CodedInputReader(new ReadOnlySequence(bufferWriter.WrittenSpan.ToArray())); + input.AssertNextTag(tag); + Assert.AreEqual(message1, input.ReadMessage(ForeignMessage.Parser)); + input.AssertNextTag(tag); + Assert.AreEqual(message2, input.ReadMessage(ForeignMessage.Parser)); + Assert.IsTrue(input.IsAtEnd); + } +#endif + [Test] public void CalculateSize_VariableSizeNonPacked() { diff --git a/csharp/src/Google.Protobuf.Test/ExtensionSetTest.cs b/csharp/src/Google.Protobuf.Test/ExtensionSetTest.cs index 33dc50430d07..3f15b9743858 100644 --- a/csharp/src/Google.Protobuf.Test/ExtensionSetTest.cs +++ b/csharp/src/Google.Protobuf.Test/ExtensionSetTest.cs @@ -34,12 +34,14 @@ public void TestMergeCodedInput() message.SetExtension(OptionalBoolExtension, true); var serialized = message.ToByteArray(); - var other = TestAllExtensions.Parser - .WithExtensionRegistry(new ExtensionRegistry() { OptionalBoolExtension }) - .ParseFrom(serialized); - - Assert.AreEqual(message, other); - Assert.AreEqual(message.CalculateSize(), other.CalculateSize()); + MessageParsingHelpers.AssertReadingMessage( + TestAllExtensions.Parser.WithExtensionRegistry(new ExtensionRegistry() { OptionalBoolExtension }), + serialized, + other => + { + Assert.AreEqual(message, other); + Assert.AreEqual(message.CalculateSize(), other.CalculateSize()); + }); } [Test] diff --git a/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.Proto2.cs b/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.Proto2.cs index 718c3edcb80e..5f90c94cce6d 100644 --- a/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.Proto2.cs +++ b/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.Proto2.cs @@ -269,8 +269,8 @@ public void RequiredFields() [Test] public void RequiredFieldsNoThrow() { - Assert.DoesNotThrow(() => TestRequired.Parser.ParseFrom(new byte[0])); - Assert.DoesNotThrow(() => (TestRequired.Parser as MessageParser).ParseFrom(new byte[0])); + Assert.DoesNotThrow(() => MessageParsingHelpers.AssertReadingMessage(TestRequired.Parser, new byte[0], m => { })); + Assert.DoesNotThrow(() => MessageParsingHelpers.AssertReadingMessage(TestRequired.Parser as MessageParser, new byte[0], m => { })); } [Test] @@ -344,9 +344,7 @@ public void RoundTrip_Groups() } }; - byte[] bytes = message.ToByteArray(); - TestAllTypes parsed = Proto2.TestAllTypes.Parser.ParseFrom(bytes); - Assert.AreEqual(message, parsed); + MessageParsingHelpers.AssertRoundtrip(Proto2.TestAllTypes.Parser, message); } [Test] @@ -361,9 +359,9 @@ public void RoundTrip_ExtensionGroups() new RepeatedGroup_extension { A = 30 } }); - byte[] bytes = message.ToByteArray(); - TestAllExtensions extendable_parsed = TestAllExtensions.Parser.WithExtensionRegistry(new ExtensionRegistry() { UnittestExtensions.OptionalGroupExtension, UnittestExtensions.RepeatedGroupExtension }).ParseFrom(bytes); - Assert.AreEqual(message, extendable_parsed); + MessageParsingHelpers.AssertRoundtrip( + TestAllExtensions.Parser.WithExtensionRegistry(new ExtensionRegistry() { UnittestExtensions.OptionalGroupExtension, UnittestExtensions.RepeatedGroupExtension }), + message); } [Test] @@ -372,9 +370,9 @@ public void RoundTrip_NestedExtensionGroup() var message = new TestGroupExtension(); message.SetExtension(TestNestedExtension.Extensions.OptionalGroupExtension, new TestNestedExtension.Types.OptionalGroup_extension { A = 10 }); - byte[] bytes = message.ToByteArray(); - TestGroupExtension extendable_parsed = TestGroupExtension.Parser.WithExtensionRegistry(new ExtensionRegistry() { TestNestedExtension.Extensions.OptionalGroupExtension }).ParseFrom(bytes); - Assert.AreEqual(message, extendable_parsed); + MessageParsingHelpers.AssertRoundtrip( + TestGroupExtension.Parser.WithExtensionRegistry(new ExtensionRegistry() { TestNestedExtension.Extensions.OptionalGroupExtension }), + message); } } } diff --git a/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs b/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs index 103df7dd2fef..71867e3e4414 100644 --- a/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs +++ b/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs @@ -131,8 +131,8 @@ public void RoundTrip_Empty() // Without setting any values, there's nothing to write. byte[] bytes = message.ToByteArray(); Assert.AreEqual(0, bytes.Length); - TestAllTypes parsed = TestAllTypes.Parser.ParseFrom(bytes); - Assert.AreEqual(message, parsed); + + MessageParsingHelpers.AssertRoundtrip(TestAllTypes.Parser, message); } [Test] @@ -164,9 +164,7 @@ public void RoundTrip_SingleValues() SingleUint64 = ulong.MaxValue }; - byte[] bytes = message.ToByteArray(); - TestAllTypes parsed = TestAllTypes.Parser.ParseFrom(bytes); - Assert.AreEqual(message, parsed); + MessageParsingHelpers.AssertRoundtrip(TestAllTypes.Parser, message); } [Test] @@ -198,9 +196,7 @@ public void RoundTrip_RepeatedValues() RepeatedUint64 = { ulong.MaxValue, uint.MinValue } }; - byte[] bytes = message.ToByteArray(); - TestAllTypes parsed = TestAllTypes.Parser.ParseFrom(bytes); - Assert.AreEqual(message, parsed); + MessageParsingHelpers.AssertRoundtrip(TestAllTypes.Parser, message); } // Note that not every map within map_unittest_proto3 is used. They all go through very @@ -230,9 +226,7 @@ public void RoundTrip_Maps() } }; - byte[] bytes = message.ToByteArray(); - TestMap parsed = TestMap.Parser.ParseFrom(bytes); - Assert.AreEqual(message, parsed); + MessageParsingHelpers.AssertRoundtrip(TestMap.Parser, message); } [Test] @@ -246,9 +240,14 @@ public void MapWithEmptyEntry() byte[] bytes = message.ToByteArray(); Assert.AreEqual(2, bytes.Length); // Tag for field entry (1 byte), length of entry (0; 1 byte) - var parsed = TestMap.Parser.ParseFrom(bytes); - Assert.AreEqual(1, parsed.MapInt32Bytes.Count); - Assert.AreEqual(ByteString.Empty, parsed.MapInt32Bytes[0]); + MessageParsingHelpers.AssertReadingMessage( + TestMap.Parser, + bytes, + parsed=> + { + Assert.AreEqual(1, parsed.MapInt32Bytes.Count); + Assert.AreEqual(ByteString.Empty, parsed.MapInt32Bytes[0]); + }); } [Test] @@ -265,8 +264,13 @@ public void MapWithOnlyValue() output.WriteMessage(nestedMessage); output.Flush(); - var parsed = TestMap.Parser.ParseFrom(memoryStream.ToArray()); - Assert.AreEqual(nestedMessage, parsed.MapInt32ForeignMessage[0]); + MessageParsingHelpers.AssertReadingMessage( + TestMap.Parser, + memoryStream.ToArray(), + parsed => + { + Assert.AreEqual(nestedMessage, parsed.MapInt32ForeignMessage[0]); + }); } [Test] @@ -282,8 +286,13 @@ public void MapWithOnlyKey_PrimitiveValue() output.WriteInt32(key); output.Flush(); - var parsed = TestMap.Parser.ParseFrom(memoryStream.ToArray()); - Assert.AreEqual(0.0, parsed.MapInt32Double[key]); + MessageParsingHelpers.AssertReadingMessage( + TestMap.Parser, + memoryStream.ToArray(), + parsed => + { + Assert.AreEqual(0.0, parsed.MapInt32Double[key]); + }); } [Test] @@ -299,8 +308,13 @@ public void MapWithOnlyKey_MessageValue() output.WriteInt32(key); output.Flush(); - var parsed = TestMap.Parser.ParseFrom(memoryStream.ToArray()); - Assert.AreEqual(new ForeignMessage(), parsed.MapInt32ForeignMessage[key]); + MessageParsingHelpers.AssertReadingMessage( + TestMap.Parser, + memoryStream.ToArray(), + parsed => + { + Assert.AreEqual(new ForeignMessage(), parsed.MapInt32ForeignMessage[key]); + }); } [Test] @@ -327,8 +341,13 @@ public void MapIgnoresExtraFieldsWithinEntryMessages() output.WriteInt32(extra); output.Flush(); - var parsed = TestMap.Parser.ParseFrom(memoryStream.ToArray()); - Assert.AreEqual(value, parsed.MapInt32Int32[key]); + MessageParsingHelpers.AssertReadingMessage( + TestMap.Parser, + memoryStream.ToArray(), + parsed => + { + Assert.AreEqual(value, parsed.MapInt32Int32[key]); + }); } [Test] @@ -351,8 +370,13 @@ public void MapFieldOrderIsIrrelevant() output.WriteInt32(key); output.Flush(); - var parsed = TestMap.Parser.ParseFrom(memoryStream.ToArray()); - Assert.AreEqual(value, parsed.MapInt32Int32[key]); + MessageParsingHelpers.AssertReadingMessage( + TestMap.Parser, + memoryStream.ToArray(), + parsed => + { + Assert.AreEqual(value, parsed.MapInt32Int32[key]); + }); } [Test] @@ -397,13 +421,19 @@ public void MapNonContiguousEntries() output.WriteInt32(value3); output.Flush(); - var parsed = TestMap.Parser.ParseFrom(memoryStream.ToArray()); - var expected = new TestMap - { - MapInt32Int32 = { { key1, value1 }, { key3, value3 } }, - MapStringString = { { key2, value2 } } - }; - Assert.AreEqual(expected, parsed); + + MessageParsingHelpers.AssertReadingMessage( + TestMap.Parser, + memoryStream.ToArray(), + parsed => + { + var expected = new TestMap + { + MapInt32Int32 = { { key1, value1 }, { key3, value3 } }, + MapStringString = { { key2, value2 } } + }; + Assert.AreEqual(expected, parsed); + }); } [Test] @@ -433,8 +463,13 @@ public void DuplicateKeys_LastEntryWins() output.WriteInt32(value2); output.Flush(); - var parsed = TestMap.Parser.ParseFrom(memoryStream.ToArray()); - Assert.AreEqual(value2, parsed.MapInt32Int32[key]); + MessageParsingHelpers.AssertReadingMessage( + TestMap.Parser, + memoryStream.ToArray(), + parsed => + { + Assert.AreEqual(value2, parsed.MapInt32Int32[key]); + }); } [Test] @@ -619,9 +654,10 @@ public void OneofSerialization_NonDefaultValue() var bytes = message.ToByteArray(); Assert.AreEqual(3, bytes.Length); // 2 bytes for the tag + 1 for the value - no string! - var message2 = TestAllTypes.Parser.ParseFrom(bytes); - Assert.AreEqual(message, message2); - Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.OneofUint32, message2.OneofFieldCase); + MessageParsingHelpers.AssertRoundtrip(TestAllTypes.Parser, message, parsedMessage => + { + Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.OneofUint32, parsedMessage.OneofFieldCase); + }); } [Test] @@ -633,9 +669,10 @@ public void OneofSerialization_DefaultValue() var bytes = message.ToByteArray(); Assert.AreEqual(3, bytes.Length); // 2 bytes for the tag + 1 for the value - it's still serialized - var message2 = TestAllTypes.Parser.ParseFrom(bytes); - Assert.AreEqual(message, message2); - Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.OneofUint32, message2.OneofFieldCase); + MessageParsingHelpers.AssertRoundtrip(TestAllTypes.Parser, message, parsedMessage => + { + Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.OneofUint32, parsedMessage.OneofFieldCase); + }); } [Test] @@ -651,10 +688,14 @@ public void DiscardUnknownFields_RealDataStillRead() message.WriteTo(output); output.Flush(); - stream.Position = 0; - var parsed = TestAllTypes.Parser.ParseFrom(stream); - // TODO(jieluo): Add test back when DiscardUnknownFields API is supported. - // Assert.AreEqual(message, parsed); + MessageParsingHelpers.AssertReadingMessage( + TestAllTypes.Parser, + stream.ToArray(), + parsed => + { + // TODO(jieluo): Add test back when DiscardUnknownFields API is supported. + // Assert.AreEqual(message, parsed); + }); } [Test] @@ -662,9 +703,15 @@ public void DiscardUnknownFields_AllTypes() { // Simple way of ensuring we can skip all kinds of fields. var data = SampleMessages.CreateFullTestAllTypes().ToByteArray(); - var empty = Empty.Parser.ParseFrom(data); - // TODO(jieluo): Add test back when DiscardUnknownFields API is supported. - // Assert.AreNotEqual(new Empty(), empty); + + MessageParsingHelpers.AssertReadingMessage( + Empty.Parser, + data, + parsed => + { + // TODO(jieluo): Add test back when DiscardUnknownFields API is supported. + // Assert.AreNotEqual(new Empty(), empty); + }); } // This was originally seen as a conformance test failure. @@ -674,7 +721,7 @@ public void TruncatedMessageFieldThrows() // 130, 3 is the message tag // 1 is the data length - but there's no data. var data = new byte[] { 130, 3, 1 }; - Assert.Throws(() => TestAllTypes.Parser.ParseFrom(data)); + MessageParsingHelpers.AssertReadingMessageThrows(TestAllTypes.Parser, data); } /// @@ -694,8 +741,7 @@ public void ExtraEndGroupThrows() output.Flush(); - stream.Position = 0; - Assert.Throws(() => TestAllTypes.Parser.ParseFrom(stream)); + MessageParsingHelpers.AssertReadingMessageThrows(TestAllTypes.Parser, stream.ToArray()); } [Test] diff --git a/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj b/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj index 1a7953d6b786..900bd7738d85 100644 --- a/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj +++ b/csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj @@ -19,6 +19,10 @@ + + $(DefineConstants);GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + + diff --git a/csharp/src/Google.Protobuf.Test/JsonParserTest.cs b/csharp/src/Google.Protobuf.Test/JsonParserTest.cs index a6cf04ab7af2..b8d94ed8be99 100644 --- a/csharp/src/Google.Protobuf.Test/JsonParserTest.cs +++ b/csharp/src/Google.Protobuf.Test/JsonParserTest.cs @@ -549,9 +549,13 @@ public void NumberToDouble_Valid(string jsonValue, double expectedParsedValue) } [Test] +#if !NETCOREAPP3_0 + // .NET Core 3.0 returns infinity + // https://github.com/dotnet/docs/issues/14705 [TestCase("1.7977e308")] [TestCase("-1.7977e308")] [TestCase("1e309")] +#endif [TestCase("1,0")] [TestCase("1.0.0")] [TestCase("+1")] diff --git a/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs b/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs index df43effd4ff0..2d8b30fd7d24 100644 --- a/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs +++ b/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs @@ -199,8 +199,11 @@ public void NumberValue(string json, double expectedValue) [TestCase("1e-")] [TestCase("--")] [TestCase("--1")] +#if !NETCOREAPP3_0 + // .NET Core 3.0 returns infinity [TestCase("-1.7977e308")] [TestCase("1.7977e308")] +#endif public void InvalidNumberValue(string json) { AssertThrowsAfter(json); diff --git a/csharp/src/Google.Protobuf.Test/MessageParsingHelpers.cs b/csharp/src/Google.Protobuf.Test/MessageParsingHelpers.cs new file mode 100644 index 000000000000..53c9dfb602ea --- /dev/null +++ b/csharp/src/Google.Protobuf.Test/MessageParsingHelpers.cs @@ -0,0 +1,145 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2015 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + +using NUnit.Framework; +using System; +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY +using Google.Protobuf.Buffers; +#endif +using System.Buffers; + +namespace Google.Protobuf +{ + public static class MessageParsingHelpers + { + public static void AssertWritingMessage(MessageParser parser, T message, byte[] expectedData) where T : IMessage + { + var bytes = message.ToByteArray(); + +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + var bufferMessage = (IBufferMessage)message; + var bufferWriter = new ArrayBufferWriter(); + var output = new CodedOutputWriter(bufferWriter); + bufferMessage.WriteTo(ref output); + output.Flush(); + + Assert.AreEqual(expectedData, bufferWriter.WrittenMemory.ToArray()); +#endif + Assert.AreEqual(expectedData, bytes); + } + + public static void AssertReadingMessage(MessageParser parser, byte[] bytes, Action assert) where T : IMessage + { + var parsedStream = parser.ParseFrom(bytes); + +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + // Load content as single segment + var parsedBuffer = parser.ParseFrom(new ReadOnlySequence(bytes)); + assert(parsedBuffer); + + // Load content as multiple segments + parsedBuffer = parser.ParseFrom(ReadOnlySequenceFactory.SegmentPerByteFactory.CreateWithContent(bytes)); + assert(parsedBuffer); +#endif + assert(parsedStream); + } + + public static void AssertReadingMessage(MessageParser parser, byte[] bytes, Action assert) + { + var parsedStream = parser.ParseFrom(bytes); + +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + // Load content as single segment + var parsedBuffer = parser.ParseFrom(new ReadOnlySequence(bytes)); + assert(parsedBuffer); + + // Load content as multiple segments + parsedBuffer = parser.ParseFrom(ReadOnlySequenceFactory.SegmentPerByteFactory.CreateWithContent(bytes)); + assert(parsedBuffer); +#endif + assert(parsedStream); + } + + public static void AssertReadingMessageThrows(MessageParser parser, byte[] bytes) + where TMessage : IMessage + where TException : Exception + { + Assert.Throws(() => parser.ParseFrom(bytes)); + +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + Assert.Throws(() => parser.ParseFrom(new ReadOnlySequence(bytes))); +#endif + } + + public static void AssertMergingMessage(MessageParser parser, Func prepareMessage, byte[] bytes, Action assert) where T : IMessage + { + var streamMergeMessage = prepareMessage(); + streamMergeMessage.MergeFrom(bytes); + +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + var bufferMergeMessage = (IBufferMessage)prepareMessage(); + var reader = new CodedInputReader(new ReadOnlySequence(bytes)); + bufferMergeMessage.MergeFrom(ref reader); + assert((T)bufferMergeMessage); +#endif + assert(streamMergeMessage); + } + + public static void AssertRoundtrip(MessageParser parser, T message, Action additionalAssert = null) where T : IMessage + { + var bytes = message.ToByteArray(); + +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + var bufferMessage = (IBufferMessage)message; + var bufferWriter = new ArrayBufferWriter(); + var output = new CodedOutputWriter(bufferWriter); + bufferMessage.WriteTo(ref output); + output.Flush(); + + // Load content as single segment + var parsedBuffer = parser.ParseFrom(new ReadOnlySequence(bufferWriter.WrittenMemory)); + Assert.AreEqual(message, parsedBuffer); + additionalAssert?.Invoke(parsedBuffer); + + // Load content as multiple segments + parsedBuffer = parser.ParseFrom(ReadOnlySequenceFactory.SegmentPerByteFactory.CreateWithContent(bufferWriter.WrittenMemory.ToArray())); + Assert.AreEqual(message, parsedBuffer); + additionalAssert?.Invoke(parsedBuffer); +#endif + + var parsedStream = parser.ParseFrom(bytes); + + Assert.AreEqual(message, parsedStream); + additionalAssert?.Invoke(parsedStream); + } + } +} diff --git a/csharp/src/Google.Protobuf.Test/UnknownFieldSetTest.cs b/csharp/src/Google.Protobuf.Test/UnknownFieldSetTest.cs index 886937d70620..17de0d8f1283 100644 --- a/csharp/src/Google.Protobuf.Test/UnknownFieldSetTest.cs +++ b/csharp/src/Google.Protobuf.Test/UnknownFieldSetTest.cs @@ -161,10 +161,10 @@ public void TestDiscardUnknownFields(IMessage message) MessageParser discardingParser2 = retainingParser2.WithDiscardUnknownFields(true); // Test parse from byte[] - assertFull(retainingParser1.ParseFrom(data)); - assertFull(retainingParser2.ParseFrom(data)); - assertEmpty(discardingParser1.ParseFrom(data)); - assertEmpty(discardingParser2.ParseFrom(data)); + MessageParsingHelpers.AssertReadingMessage(retainingParser1, data, m => assertFull(m)); + MessageParsingHelpers.AssertReadingMessage(retainingParser2, data, m => assertFull(m)); + MessageParsingHelpers.AssertReadingMessage(discardingParser1, data, m => assertEmpty(m)); + MessageParsingHelpers.AssertReadingMessage(discardingParser2, data, m => assertEmpty(m)); // Test parse from byte[] with offset assertFull(retainingParser1.ParseFrom(data, 0, data.Length)); @@ -197,10 +197,20 @@ public void TestReadInvalidWireTypeThrowsInvalidProtocolBufferException() output.Flush(); ms.Position = 0; - CodedInputStream input = new CodedInputStream(ms); - Assert.AreEqual(tag, input.ReadTag()); + CodedInputStream inputStream = new CodedInputStream(ms); + Assert.AreEqual(tag, inputStream.ReadTag()); + Assert.Throws(() => UnknownFieldSet.MergeFieldFrom(null, inputStream)); - Assert.Throws(() => UnknownFieldSet.MergeFieldFrom(null, input)); +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + ms.Position = 0; + + Assert.Throws(() => + { + CodedInputReader inputReader = new CodedInputReader(new System.Buffers.ReadOnlySequence(ms.ToArray())); + Assert.AreEqual(tag, inputReader.ReadTag()); + UnknownFieldSet.MergeFieldFrom(null, ref inputReader); + }); +#endif } } } diff --git a/csharp/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs b/csharp/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs index 4a425f79aa84..7802066830bc 100644 --- a/csharp/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs +++ b/csharp/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs @@ -71,18 +71,18 @@ public void NonDefaultSingleValues() Uint64Field = 4 }; - var bytes = message.ToByteArray(); - var parsed = TestWellKnownTypes.Parser.ParseFrom(bytes); - - Assert.AreEqual("x", parsed.StringField); - Assert.AreEqual(ByteString.CopyFrom(1, 2, 3), parsed.BytesField); - Assert.AreEqual(true, parsed.BoolField); - Assert.AreEqual(12.5f, parsed.FloatField); - Assert.AreEqual(12.25d, parsed.DoubleField); - Assert.AreEqual(1, parsed.Int32Field); - Assert.AreEqual(2L, parsed.Int64Field); - Assert.AreEqual(3U, parsed.Uint32Field); - Assert.AreEqual(4UL, parsed.Uint64Field); + MessageParsingHelpers.AssertRoundtrip(TestWellKnownTypes.Parser, message, parsed => + { + Assert.AreEqual("x", parsed.StringField); + Assert.AreEqual(ByteString.CopyFrom(1, 2, 3), parsed.BytesField); + Assert.AreEqual(true, parsed.BoolField); + Assert.AreEqual(12.5f, parsed.FloatField); + Assert.AreEqual(12.25d, parsed.DoubleField); + Assert.AreEqual(1, parsed.Int32Field); + Assert.AreEqual(2L, parsed.Int64Field); + Assert.AreEqual(3U, parsed.Uint32Field); + Assert.AreEqual(4UL, parsed.Uint64Field); + }); } [Test] @@ -101,18 +101,18 @@ public void NonNullDefaultIsPreservedThroughSerialization() Uint64Field = 0 }; - var bytes = message.ToByteArray(); - var parsed = TestWellKnownTypes.Parser.ParseFrom(bytes); - - Assert.AreEqual("", parsed.StringField); - Assert.AreEqual(ByteString.Empty, parsed.BytesField); - Assert.AreEqual(false, parsed.BoolField); - Assert.AreEqual(0f, parsed.FloatField); - Assert.AreEqual(0d, parsed.DoubleField); - Assert.AreEqual(0, parsed.Int32Field); - Assert.AreEqual(0L, parsed.Int64Field); - Assert.AreEqual(0U, parsed.Uint32Field); - Assert.AreEqual(0UL, parsed.Uint64Field); + MessageParsingHelpers.AssertRoundtrip(TestWellKnownTypes.Parser, message, parsed => + { + Assert.AreEqual("", parsed.StringField); + Assert.AreEqual(ByteString.Empty, parsed.BytesField); + Assert.AreEqual(false, parsed.BoolField); + Assert.AreEqual(0f, parsed.FloatField); + Assert.AreEqual(0d, parsed.DoubleField); + Assert.AreEqual(0, parsed.Int32Field); + Assert.AreEqual(0L, parsed.Int64Field); + Assert.AreEqual(0U, parsed.Uint32Field); + Assert.AreEqual(0UL, parsed.Uint64Field); + }); } [Test] @@ -140,12 +140,11 @@ public void RepeatedWrappersSerializeDeserialize() Uint32Field = { uint.MaxValue, uint.MinValue, 0U }, Uint64Field = { ulong.MaxValue, ulong.MinValue, 0UL }, }; - var bytes = message.ToByteArray(); - var parsed = RepeatedWellKnownTypes.Parser.ParseFrom(bytes); - Assert.AreEqual(message, parsed); // Just to test a single value for sanity... Assert.AreEqual("Second", message.StringField[1]); + + MessageParsingHelpers.AssertRoundtrip(RepeatedWellKnownTypes.Parser, message); } [Test] @@ -168,8 +167,7 @@ public void RepeatedWrappersBinaryFormat() var expectedBytes = rawOutput.ToArray(); var message = new RepeatedWellKnownTypes { Int32Field = { 5, 0 } }; - var actualBytes = message.ToByteArray(); - Assert.AreEqual(expectedBytes, actualBytes); + MessageParsingHelpers.AssertWritingMessage(RepeatedWellKnownTypes.Parser, message, expectedBytes); } [Test] @@ -194,12 +192,10 @@ public void MapWrappersSerializeDeserialize() Uint64Field = { { 18, ulong.MaxValue }, { 19, ulong.MinValue }, { 20, 0UL } }, }; - var bytes = message.ToByteArray(); - var parsed = MapWellKnownTypes.Parser.ParseFrom(bytes); - - Assert.AreEqual(message, parsed); // Just to test a single value for sanity... Assert.AreEqual("Second", message.StringField[12]); + + MessageParsingHelpers.AssertRoundtrip(MapWellKnownTypes.Parser, message); } [Test] @@ -288,10 +284,10 @@ public void Oneof() private void AssertOneofRoundTrip(OneofWellKnownTypes message) { // Normal roundtrip, but explicitly checking the case... - var bytes = message.ToByteArray(); - var parsed = OneofWellKnownTypes.Parser.ParseFrom(bytes); - Assert.AreEqual(message, parsed); - Assert.AreEqual(message.OneofFieldCase, parsed.OneofFieldCase); + MessageParsingHelpers.AssertRoundtrip(OneofWellKnownTypes.Parser, message, parsed => + { + Assert.AreEqual(message.OneofFieldCase, parsed.OneofFieldCase); + }); } [Test] @@ -306,15 +302,25 @@ private void AssertOneofRoundTrip(OneofWellKnownTypes message) [TestCase(null, null, null)] public void Merging(string original, string merged, string expected) { - var originalMessage = new TestWellKnownTypes { StringField = original }; var mergingMessage = new TestWellKnownTypes { StringField = merged }; - originalMessage.MergeFrom(mergingMessage); - Assert.AreEqual(expected, originalMessage.StringField); - // Try it using MergeFrom(CodedInputStream) too... - originalMessage = new TestWellKnownTypes { StringField = original }; - originalMessage.MergeFrom(mergingMessage.ToByteArray()); - Assert.AreEqual(expected, originalMessage.StringField); + MessageParsingHelpers.AssertMergingMessage( + TestWellKnownTypes.Parser, + () => + { + var originalMessage = new TestWellKnownTypes { StringField = original }; + originalMessage.MergeFrom(mergingMessage); + Assert.AreEqual(expected, originalMessage.StringField); + + // Try it using MergeFrom(CodedInputStream) too... + originalMessage = new TestWellKnownTypes { StringField = original }; + originalMessage.MergeFrom(mergingMessage.ToByteArray()); + Assert.AreEqual(expected, originalMessage.StringField); + + return originalMessage; + }, + mergingMessage.ToByteArray(), + mergedMessage => Assert.AreEqual(expected, mergedMessage.StringField)); } // Merging is odd with wrapper types, due to the way that default values aren't emitted in @@ -324,8 +330,6 @@ public void Merging(string original, string merged, string expected) [Test] public void MergingStreamExplicitValue() { - var message = new TestWellKnownTypes { Int32Field = 5 }; - // Create a byte array which has the data of an Int32Value explicitly containing a value of 0. // This wouldn't normally happen. byte[] bytes; @@ -342,25 +346,35 @@ public void MergingStreamExplicitValue() bytes = stream.ToArray(); } - message.MergeFrom(bytes); - // A normal implementation would have 0 now, as the explicit default would have been overwritten the 5. - // With the FieldCodec for Nullable, we can't tell the difference between an implicit 0 and an explicit 0. - Assert.AreEqual(5, message.Int32Field); + MessageParsingHelpers.AssertMergingMessage( + TestWellKnownTypes.Parser, + () => new TestWellKnownTypes { Int32Field = 5 }, + bytes, + mergedMessage => + { + // A normal implementation would have 0 now, as the explicit default would have been overwritten the 5. + // With the FieldCodec for Nullable, we can't tell the difference between an implicit 0 and an explicit 0. + Assert.AreEqual(5, mergedMessage.Int32Field); + }); } [Test] public void MergingStreamNoValue() { - var message = new TestWellKnownTypes { Int32Field = 5 }; - // Create a byte array which an Int32 field, but with no value. var bytes = new TestWellKnownTypes { Int32Field = 0 }.ToByteArray(); Assert.AreEqual(2, bytes.Length); // The tag for Int32Field is a single byte, then a byte indicating a 0-length message. - message.MergeFrom(bytes); - // The "implicit" 0 did *not* overwrite the value. - // (This is the correct behaviour.) - Assert.AreEqual(5, message.Int32Field); + MessageParsingHelpers.AssertMergingMessage( + TestWellKnownTypes.Parser, + () => new TestWellKnownTypes { Int32Field = 5 }, + bytes, + mergedMessage => + { + // The "implicit" 0 did *not* overwrite the value. + // (This is the correct behaviour.) + Assert.AreEqual(5, mergedMessage.Int32Field); + }); } // All permutations of origin/merging value being null, zero (default) or non-default. @@ -406,8 +420,10 @@ public void UnknownFieldInWrapperInt32FastPath() Assert.AreEqual(8, stream.Length); // tag (1 byte) + length (1 byte) + message (6 bytes) stream.Position = 0; - var message = TestWellKnownTypes.Parser.ParseFrom(stream); - Assert.AreEqual(65536, message.Int32Field); + MessageParsingHelpers.AssertReadingMessage( + TestWellKnownTypes.Parser, + stream.ToArray(), + message => Assert.AreEqual(65536, message.Int32Field)); } [Test] @@ -431,8 +447,10 @@ public void UnknownFieldInWrapperInt32SlowPath() Assert.Less(stream.Length, 8); // tag (1 byte) + length (1 byte) + message stream.Position = 0; - var message = TestWellKnownTypes.Parser.ParseFrom(stream); - Assert.AreEqual(6, message.Int32Field); + MessageParsingHelpers.AssertReadingMessage( + TestWellKnownTypes.Parser, + stream.ToArray(), + message => Assert.AreEqual(6, message.Int32Field)); } [Test] @@ -456,8 +474,10 @@ public void UnknownFieldInWrapperInt64FastPath() Assert.AreEqual(13, stream.Length); // tag (1 byte) + length (1 byte) + message (11 bytes) stream.Position = 0; - var message = TestWellKnownTypes.Parser.ParseFrom(stream); - Assert.AreEqual(0xfffffffffffffL, message.Int64Field); + MessageParsingHelpers.AssertReadingMessage( + TestWellKnownTypes.Parser, + stream.ToArray(), + message => Assert.AreEqual(0xfffffffffffffL, message.Int64Field)); } [Test] @@ -481,8 +501,10 @@ public void UnknownFieldInWrapperInt64SlowPath() Assert.Less(stream.Length, 12); // tag (1 byte) + length (1 byte) + message stream.Position = 0; - var message = TestWellKnownTypes.Parser.ParseFrom(stream); - Assert.AreEqual(6L, message.Int64Field); + MessageParsingHelpers.AssertReadingMessage( + TestWellKnownTypes.Parser, + stream.ToArray(), + message => Assert.AreEqual(6L, message.Int64Field)); } [Test] diff --git a/csharp/src/Google.Protobuf/ByteString.cs b/csharp/src/Google.Protobuf/ByteString.cs index 3eb00e5bb5c7..56a1e5cd5485 100644 --- a/csharp/src/Google.Protobuf/ByteString.cs +++ b/csharp/src/Google.Protobuf/ByteString.cs @@ -34,6 +34,7 @@ using System.Collections; using System.Collections.Generic; using System.IO; +using System.Security; using System.Text; #if !NET35 using System.Threading; @@ -115,7 +116,11 @@ public bool IsEmpty /// Provides read-only access to the data of this . /// No data is copied so this is the most efficient way of accessing. /// - public ReadOnlySpan Span => new ReadOnlySpan(bytes); + public ReadOnlySpan Span + { + [SecuritySafeCritical] + get { return new ReadOnlySpan(bytes); } + } #endif /// diff --git a/csharp/src/Google.Protobuf/CodedInputReader.cs b/csharp/src/Google.Protobuf/CodedInputReader.cs new file mode 100644 index 000000000000..82194e058c4d --- /dev/null +++ b/csharp/src/Google.Protobuf/CodedInputReader.cs @@ -0,0 +1,1198 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY +using System; +using System.Buffers; +using System.Buffers.Binary; +using System.Collections.Generic; +using System.IO; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security; +using System.Text; +using Google.Protobuf.Collections; + +namespace Google.Protobuf +{ + /// + /// Reads and decodes protocol message fields. + /// Note: experimental API that can change or be removed without any prior notice. + /// + /// + /// + /// This class is generally used by generated code to read appropriate + /// primitives from the input. It effectively encapsulates the lowest + /// levels of protocol buffer format. + /// + /// + /// Repeated fields and map fields are not handled by this class; use + /// and to serialize such fields. + /// + /// + [SecuritySafeCritical] + public ref struct CodedInputReader + { + internal const int DefaultRecursionLimit = 100; + + private SequenceReader reader; + private uint lastTag; + private int recursionDepth; + private long currentLimit; + private Decoder decoder; + + private readonly int recursionLimit; + + + /// + /// Creates a new CodedInputReader reading data from the given . + /// + public CodedInputReader(ReadOnlySequence input) : this(input, DefaultRecursionLimit) + { + } + + internal CodedInputReader(ReadOnlySequence input, int recursionLimit) + { + this.reader = new SequenceReader(input); + this.lastTag = 0; + this.recursionDepth = 0; + this.recursionLimit = recursionLimit; + this.currentLimit = long.MaxValue; + this.decoder = null; + this.DiscardUnknownFields = false; + this.ExtensionRegistry = null; + } + + /// + /// The total number of bytes processed by the reader. + /// + public long Position => reader.Consumed; + + /// + /// Returns true if the reader has reached the end of the input. This is the + /// case if either the end of the underlying input source has been reached or + /// the reader has reached a limit created using PushLimit. + /// + public bool IsAtEnd => reader.End; + + /// + /// Returns the last tag read, or 0 if no tags have been read or we've read beyond + /// the end of the input. + /// + internal uint LastTag { get { return lastTag; } } + + /// + /// Internal-only property; when set to true, unknown fields will be discarded while parsing. + /// + internal bool DiscardUnknownFields { get; set; } + + /// + /// Internal-only property; provides extension identifiers to compatible messages while parsing. + /// + internal ExtensionRegistry ExtensionRegistry { get; set; } + + /// + /// Creates a with the specified recursion limits, reading + /// from the input. + /// + /// + /// This method exists separately from the constructor to reduce the number of constructor overloads. + /// It is likely to be used considerably less frequently than the constructors, as the default limits + /// are suitable for most use cases. + /// + /// The input to read from + /// The maximum recursion depth to allow while reading. + /// A CodedInputReader reading from with the specified limits. + public static CodedInputReader CreateWithLimits(ReadOnlySequence input, int recursionLimit) + { + return new CodedInputReader(input, recursionLimit); + } + + #region Reading of tags etc + + /// + /// Peeks at the next field tag. This is like calling , but the + /// tag is not consumed. (So a subsequent call to will return the + /// same value.) + /// + public uint PeekTag() + { + uint previousTag = lastTag; + long consumed = reader.Consumed; + + uint tag = ReadTag(); + + long rewindCount = reader.Consumed - consumed; + if (rewindCount > 0) + { + reader.Rewind(rewindCount); + } + lastTag = previousTag; + + return tag; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private void ThrowEndOfInputIfFalse(bool condition) + { + if (!condition) + { + ThrowEndOfInput(); + return; + } + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static void ThrowEndOfInput() + { + throw InvalidProtocolBufferException.TruncatedMessage(); + } + + /// + /// Reads a field tag, returning the tag of 0 for "end of input". + /// + /// + /// If this method returns 0, it doesn't necessarily mean the end of all + /// the data in this CodedInputReader; it may be the end of the logical input + /// for an embedded message, for example. + /// + /// The next field tag, or 0 for end of input. (0 is never a valid tag.) + public uint ReadTag() + { + if (ReachedLimit) + { + lastTag = 0; + return 0; + } + + byte value; + + bool hasValue = reader.TryRead(out value); + if (!hasValue) + { + ThrowEndOfInputIfFalse(IsAtEnd); + + // End of input + lastTag = 0; + return 0; + } + + // Optimize for the incredibly common case of having at least two bytes left in the buffer, + // and those two bytes being enough to get the tag. This will be true for fields up to 4095. + if (value < 128) + { + lastTag = value; + } + else + { + int result = value & 0x7f; + ThrowEndOfInputIfFalse(reader.TryRead(out value)); + if (value < 128) + { + result |= value << 7; + lastTag = (uint)result; + } + else + { + // Nope, rewind and go the potentially slow route. + reader.Rewind(2); + lastTag = ReadRawVarint32(); + } + } + + if (WireFormat.GetTagFieldNumber(lastTag) == 0) + { + // If we actually read a tag with a field of 0, that's not a valid tag. + throw InvalidProtocolBufferException.InvalidTag(); + } + if (ReachedLimit) + { + return 0; + } + return lastTag; + } + + /// + /// Skips the data for the field with the tag we've just read. + /// This should be called directly after , when + /// the caller wishes to skip an unknown field. + /// + /// + /// This method throws if the last-read tag was an end-group tag. + /// If a caller wishes to skip a group, they should skip the whole group, by calling this method after reading the + /// start-group tag. This behavior allows callers to call this method on any field they don't understand, correctly + /// resulting in an error if an end-group tag has not been paired with an earlier start-group tag. + /// + /// The last tag was an end-group tag + /// The last read operation read to the end of the logical input + public void SkipLastField() + { + if (lastTag == 0) + { + throw new InvalidOperationException("SkipLastField cannot be called at the end of a input"); + } + switch (WireFormat.GetTagWireType(lastTag)) + { + case WireFormat.WireType.StartGroup: + SkipGroup(lastTag); + break; + case WireFormat.WireType.EndGroup: + throw new InvalidProtocolBufferException( + "SkipLastField called on an end-group tag, indicating that the corresponding start-group was missing"); + case WireFormat.WireType.Fixed32: + ReadFixed32(); + break; + case WireFormat.WireType.Fixed64: + ReadFixed64(); + break; + case WireFormat.WireType.LengthDelimited: + var length = ReadLength(); + SkipRawBytes(length); + break; + case WireFormat.WireType.Varint: + ReadRawVarint32(); + break; + } + } + + private void SkipRawBytes(int length) + { + if (length < 0) + { + throw InvalidProtocolBufferException.NegativeSize(); + } + + if (length + reader.Consumed > currentLimit) + { + // Read to the end of the limit. + reader.Advance(currentLimit); + // Then fail. + throw InvalidProtocolBufferException.TruncatedMessage(); + } + if (reader.Remaining < length) + { + reader.Advance(reader.Remaining); + ThrowEndOfInput(); + } + + reader.Advance(length); + } + + /// + /// Skip a group. + /// + internal void SkipGroup(uint startGroupTag) + { + // Note: Currently we expect this to be the way that groups are read. We could put the recursion + // depth changes into the ReadTag method instead, potentially... + recursionDepth++; + if (recursionDepth >= recursionLimit) + { + throw InvalidProtocolBufferException.RecursionLimitExceeded(); + } + uint tag; + while (true) + { + tag = ReadTag(); + if (tag == 0) + { + throw InvalidProtocolBufferException.TruncatedMessage(); + } + // Can't call SkipLastField for this case- that would throw. + if (WireFormat.GetTagWireType(tag) == WireFormat.WireType.EndGroup) + { + break; + } + // This recursion will allow us to handle nested groups. + SkipLastField(); + } + int startField = WireFormat.GetTagFieldNumber(startGroupTag); + int endField = WireFormat.GetTagFieldNumber(tag); + if (startField != endField) + { + throw new InvalidProtocolBufferException( + $"Mismatched end-group tag. Started with field {startField}; ended with field {endField}"); + } + recursionDepth--; + } + + /// + /// Reads a double field from the input. + /// + public double ReadDouble() + { + return BitConverter.Int64BitsToDouble((long)ReadRawLittleEndian64()); + } + + /// + /// Reads a float field from the input. + /// + public float ReadFloat() + { + const int length = sizeof(float); + + if (BitConverter.IsLittleEndian && reader.CurrentSpan.Length - reader.CurrentSpanIndex >= length) + { + // Fast path. All data is in the current span and we're little endian architecture. + ReadOnlySpan data = reader.CurrentSpan.Slice(reader.CurrentSpanIndex, length); + reader.Advance(length); + + // ReadUnaligned uses processor architecture for endianness. Content is little endian and + // IsLittleEndian has been checked so this is safe to call. + return Unsafe.ReadUnaligned(ref MemoryMarshal.GetReference(data)); + } + else + { + return ReadFloatSlow(); + } + } + + private unsafe float ReadFloatSlow() + { + const int length = sizeof(float); + + byte* buffer = stackalloc byte[length]; + Span tempSpan = new Span(buffer, length); + + ThrowEndOfInputIfFalse(reader.TryCopyTo(tempSpan)); + reader.Advance(length); + + // Content is little endian. Reverse if needed to match endianness of architecture. + if (!BitConverter.IsLittleEndian) + { + tempSpan.Reverse(); + } + + // ReadUnaligned uses processor architecture for endianness. Content is little endian and + // IsLittleEndian has been checked so this is safe to call. + return Unsafe.ReadUnaligned(ref MemoryMarshal.GetReference(tempSpan)); + } + + /// + /// Reads a uint64 field from the input. + /// + public ulong ReadUInt64() + { + return ReadRawVarint64(); + } + + /// + /// Reads an int64 field from the input. + /// + public long ReadInt64() + { + return (long)ReadRawVarint64(); + } + + /// + /// Reads an int32 field from the input. + /// + public int ReadInt32() + { + return (int)ReadRawVarint32(); + } + + /// + /// Reads a fixed64 field from the input. + /// + public ulong ReadFixed64() + { + return ReadRawLittleEndian64(); + } + + /// + /// Reads a fixed32 field from the input. + /// + public uint ReadFixed32() + { + return ReadRawLittleEndian32(); + } + + /// + /// Reads a bool field from the input. + /// + public bool ReadBool() + { + return ReadRawVarint64() != 0; + } + + /// + /// Reads a string field from the input. + /// + public string ReadString() + { + int length = ReadLength(); + + if (length == 0) + { + return string.Empty; + } + + if (length < 0) + { + throw InvalidProtocolBufferException.NegativeSize(); + } + +#if GOOGLE_PROTOBUF_SUPPORT_FAST_STRING + ReadOnlySpan unreadSpan = reader.UnreadSpan; + if (unreadSpan.Length >= length) + { + // Fast path: all bytes to decode appear in the same span. + ReadOnlySpan data = unreadSpan.Slice(0, length); + + string value; + unsafe + { + fixed (byte* sourceBytes = &MemoryMarshal.GetReference(data)) + { + value = CodedOutputStream.Utf8Encoding.GetString(sourceBytes, length); + } + } + + reader.Advance(length); + return value; + } +#endif + + return ReadStringSlow(length); + } + + /// + /// Reads a string assuming that it is spread across multiple spans in the . + /// + /// The length of the string to be decoded, in bytes. + /// The decoded string. + private string ReadStringSlow(int byteLength) + { + ThrowEndOfInputIfFalse(reader.Remaining >= byteLength); + + if (decoder == null) + { + decoder = CodedOutputStream.Utf8Encoding.GetDecoder(); + } + + // We need to decode bytes incrementally across multiple spans. + int maxCharLength = CodedOutputStream.Utf8Encoding.GetMaxCharCount(byteLength); + char[] charArray = ArrayPool.Shared.Rent(maxCharLength); + + try + { + int remainingByteLength = byteLength; + int initializedChars = 0; + while (remainingByteLength > 0) + { + int bytesRead = Math.Min(remainingByteLength, reader.UnreadSpan.Length); + remainingByteLength -= bytesRead; + bool flush = remainingByteLength == 0; + + unsafe + { + fixed (byte* pUnreadSpan = &MemoryMarshal.GetReference(reader.UnreadSpan)) + fixed (char* pCharArray = &charArray[initializedChars]) + { + initializedChars += decoder.GetChars(pUnreadSpan, bytesRead, pCharArray, charArray.Length - initializedChars, flush); + } + + reader.Advance(bytesRead); + } + } + + string value = new string(charArray, 0, initializedChars); + return value; + } + finally + { + ArrayPool.Shared.Return(charArray); + } + } + + /// + /// Reads an embedded message field value from the input. + /// + public void ReadMessage(IBufferMessage builder) + { + int length = ReadLength(); + if (recursionDepth >= recursionLimit) + { + throw InvalidProtocolBufferException.RecursionLimitExceeded(); + } + long oldLimit = PushLimit(length); + ++recursionDepth; + builder.MergeFrom(ref this); + CheckReadEndOfInputTag(); + // Check that we've read exactly as much data as expected. + if (!ReachedLimit) + { + throw InvalidProtocolBufferException.TruncatedMessage(); + } + --recursionDepth; + PopLimit(oldLimit); + } + + /// + /// Reads an embedded group field from the input. + /// + public void ReadGroup(IBufferMessage builder) + { + if (recursionDepth >= recursionLimit) + { + throw InvalidProtocolBufferException.RecursionLimitExceeded(); + } + ++recursionDepth; + builder.MergeFrom(ref this); + --recursionDepth; + } + + /// + /// Reads a bytes field value from the input. + /// + public ByteString ReadBytes() + { + int length = ReadLength(); + + if (length == 0) + { + return ByteString.Empty; + } + + ThrowEndOfInputIfFalse(reader.Remaining >= length); + + if (length < 0) + { + throw InvalidProtocolBufferException.NegativeSize(); + } + + if (length + reader.Consumed > currentLimit) + { + // Read to the end of the limit. + reader.Advance(currentLimit); + // Then fail. + throw InvalidProtocolBufferException.TruncatedMessage(); + } + + // Avoid creating a copy of Sequence if data is on current span + var data = (reader.UnreadSpan.Length >= length) + ? reader.UnreadSpan.Slice(0, length).ToArray() + : reader.Sequence.Slice(reader.Position, length).ToArray(); + + reader.Advance(length); + + return ByteString.AttachBytes(data); + } + + /// + /// Reads a uint32 field value from the input. + /// + public uint ReadUInt32() + { + return ReadRawVarint32(); + } + + /// + /// Reads an enum field value from the input. + /// + public int ReadEnum() + { + // Currently just a pass-through, but it's nice to separate it logically from WriteInt32. + return (int)ReadRawVarint32(); + } + + /// + /// Reads an sfixed32 field value from the input. + /// + public int ReadSFixed32() + { + return (int)ReadRawLittleEndian32(); + } + + /// + /// Reads an sfixed64 field value from the input. + /// + public long ReadSFixed64() + { + return (long)ReadRawLittleEndian64(); + } + + /// + /// Reads an sint32 field value from the input. + /// + public int ReadSInt32() + { + return CodedInputStream.DecodeZigZag32(ReadRawVarint32()); + } + + /// + /// Reads an sint64 field value from the input. + /// + public long ReadSInt64() + { + return CodedInputStream.DecodeZigZag64(ReadRawVarint64()); + } + + /// + /// Reads a length for length-delimited data. + /// + /// + /// This is internally just reading a varint, but this method exists + /// to make the calling code clearer. + /// + public int ReadLength() + { + return (int)ReadRawVarint32(); + } + + /// + /// Peeks at the next tag in the input. If it matches , + /// the tag is consumed and the method returns true; otherwise, the + /// input is left in the original position and the method returns false. + /// + public bool MaybeConsumeTag(uint tag) + { + uint previousTag = lastTag; + long consumed = reader.Consumed; + + uint newTag = ReadTag(); + if (newTag == tag) + { + // Match so consume tag + return true; + } + + // No match so rewind + long rewindCount = reader.Consumed - consumed; + if (rewindCount > 0) + { + reader.Rewind(rewindCount); + } + lastTag = previousTag; + + return false; + } + + internal static float? ReadFloatWrapperLittleEndian(ref CodedInputReader input) + { + // length:1 + tag:1 + value:4 = 6 bytes + const int wrapperLength = 6; + + var remaining = input.reader.UnreadSpan; + if (remaining.Length >= wrapperLength) + { + // The entire wrapper message is already contained in `buffer`. + int length = remaining[0]; + if (length == 0) + { + input.reader.Advance(1); + return 0F; + } + // tag:1 + value:4 = length of 5 bytes + // field=1, type=32-bit = tag of 13 + if (length != wrapperLength - 1 || remaining[1] != 13) + { + return ReadFloatWrapperSlow(ref input); + } + // ReadUnaligned uses processor architecture for endianness. Content is little endian and + // IsLittleEndian has been checked so this is safe to call. + var result = Unsafe.ReadUnaligned(ref MemoryMarshal.GetReference(remaining.Slice(2))); + input.reader.Advance(wrapperLength); + return result; + } + else + { + return ReadFloatWrapperSlow(ref input); + } + } + + internal static float? ReadFloatWrapperSlow(ref CodedInputReader input) + { + int length = input.ReadLength(); + if (length == 0) + { + return 0F; + } + long finalBufferPos = input.reader.Consumed + length; + float result = 0F; + do + { + // field=1, type=32-bit = tag of 13 + if (input.ReadTag() == 13) + { + result = input.ReadFloat(); + } + else + { + input.SkipLastField(); + } + } + while (input.reader.Consumed < finalBufferPos); + return result; + } + + internal static double? ReadDoubleWrapperLittleEndian(ref CodedInputReader input) + { + // length:1 + tag:1 + value:8 = 10 bytes + const int wrapperLength = 10; + + var remaining = input.reader.UnreadSpan; + if (remaining.Length >= wrapperLength) + { + // The entire wrapper message is already contained in `buffer`. + int length = remaining[0]; + if (length == 0) + { + input.reader.Advance(1); + return 0D; + } + // tag:1 + value:8 = length of 9 bytes + // field=1, type=64-bit = tag of 9 + if (length != wrapperLength - 1 || remaining[1] != 9) + { + return ReadDoubleWrapperSlow(ref input); + } + // ReadUnaligned uses processor architecture for endianness. Content is little endian and + // IsLittleEndian has been checked so this is safe to call. + var result = Unsafe.ReadUnaligned(ref MemoryMarshal.GetReference(remaining.Slice(2))); + input.reader.Advance(wrapperLength); + return result; + } + else + { + return ReadDoubleWrapperSlow(ref input); + } + } + + internal static double? ReadDoubleWrapperSlow(ref CodedInputReader input) + { + int length = input.ReadLength(); + if (length == 0) + { + return 0D; + } + long finalBufferPos = input.reader.Consumed + length; + double result = 0D; + do + { + // field=1, type=64-bit = tag of 9 + if (input.ReadTag() == 9) + { + result = input.ReadDouble(); + } + else + { + input.SkipLastField(); + } + } + while (input.reader.Consumed < finalBufferPos); + return result; + } + + internal static bool? ReadBoolWrapper(ref CodedInputReader input) + { + return ReadUInt64Wrapper(ref input) != 0; + } + + internal static uint? ReadUInt32Wrapper(ref CodedInputReader input) + { + // length:1 + tag:1 + value:5(varint32-max) = 7 bytes + const int wrapperLength = 7; + + var remaining = input.reader.UnreadSpan; + if (remaining.Length >= wrapperLength) + { + // The entire wrapper message is already contained in `buffer`. + int length = remaining[0]; + if (length == 0) + { + input.reader.Advance(1); + return 0; + } + // Length will always fit in a single byte. + if (length >= 128) + { + return ReadUInt32WrapperSlow(ref input); + } + long finalBufferPos = input.reader.Consumed + length; + // field=1, type=varint = tag of 8 + if (remaining[2] != 8) + { + return ReadUInt32WrapperSlow(ref input); + } + long pos0 = input.reader.Consumed; + input.reader.Advance(2); + var result = input.ReadUInt32(); + // Verify this message only contained a single field. + if (input.reader.Consumed != finalBufferPos) + { + input.reader.Rewind(input.reader.Consumed - pos0); + return ReadUInt32WrapperSlow(ref input); + } + return result; + } + else + { + return ReadUInt32WrapperSlow(ref input); + } + } + + private static uint? ReadUInt32WrapperSlow(ref CodedInputReader input) + { + int length = input.ReadLength(); + if (length == 0) + { + return 0; + } + long finalBufferPos = input.reader.Consumed + length; + uint result = 0; + do + { + // field=1, type=varint = tag of 8 + if (input.ReadTag() == 8) + { + result = input.ReadUInt32(); + } + else + { + input.SkipLastField(); + } + } + while (input.reader.Consumed < finalBufferPos); + return result; + } + + internal static int? ReadInt32Wrapper(ref CodedInputReader input) + { + return (int?)ReadUInt32Wrapper(ref input); + } + + internal static ulong? ReadUInt64Wrapper(ref CodedInputReader input) + { + // field=1, type=varint = tag of 8 + const int expectedTag = 8; + // length:1 + tag:1 + value:10(varint64-max) = 12 bytes + const int wrapperLength = 12; + + var remaining = input.reader.UnreadSpan; + if (remaining.Length >= wrapperLength) + { + // The entire wrapper message is already contained in `buffer`. + int length = remaining[0]; + if (length == 0) + { + input.reader.Advance(1); + return 0; + } + // Length will always fit in a single byte. + if (length >= 128) + { + return ReadUInt64WrapperSlow(ref input); + } + long finalBufferPos = input.reader.Consumed + length; + if (remaining[2] != expectedTag) + { + return ReadUInt64WrapperSlow(ref input); + } + long pos0 = input.reader.Consumed; + input.reader.Advance(2); + var result = input.ReadUInt64(); + // Verify this message only contained a single field. + if (input.reader.Consumed != finalBufferPos) + { + input.reader.Rewind(input.reader.Consumed - pos0); + return ReadUInt64WrapperSlow(ref input); + } + return result; + } + else + { + return ReadUInt64WrapperSlow(ref input); + } + } + + internal static ulong? ReadUInt64WrapperSlow(ref CodedInputReader input) + { + // field=1, type=varint = tag of 8 + const int expectedTag = 8; + + int length = input.ReadLength(); + if (length == 0) + { + return 0L; + } + long finalBufferPos = input.reader.Consumed + length; + ulong result = 0L; + do + { + if (input.ReadTag() == expectedTag) + { + result = input.ReadUInt64(); + } + else + { + input.SkipLastField(); + } + } + while (input.reader.Consumed < finalBufferPos); + return result; + } + + internal static long? ReadInt64Wrapper(ref CodedInputReader input) + { + return (long?)ReadUInt64Wrapper(ref input); + } + + #endregion + + #region Underlying reading primitives + + /// + /// Reads a raw Varint from the input. If larger than 32 bits, discard the upper bits. + /// This method is optimised for the case where we've got lots of data in the buffer. + /// That means we can check the size just once, then just read directly from the buffer + /// without constant rechecking of the buffer length. + /// + internal uint ReadRawVarint32() + { + byte value; + + ThrowEndOfInputIfFalse(reader.TryRead(out value)); + int tmp = value; + if (tmp < 128) + { + return (uint)tmp; + } + int result = tmp & 0x7f; + ThrowEndOfInputIfFalse(reader.TryRead(out value)); + tmp = value; + if (tmp < 128) + { + result |= tmp << 7; + } + else + { + result |= (tmp & 0x7f) << 7; + ThrowEndOfInputIfFalse(reader.TryRead(out value)); + tmp = value; + if (tmp < 128) + { + result |= tmp << 14; + } + else + { + result |= (tmp & 0x7f) << 14; + ThrowEndOfInputIfFalse(reader.TryRead(out value)); + tmp = value; + if (tmp < 128) + { + result |= tmp << 21; + } + else + { + result |= (tmp & 0x7f) << 21; + ThrowEndOfInputIfFalse(reader.TryRead(out value)); + tmp = value; + result |= tmp << 28; + if (tmp >= 128) + { + // Discard upper 32 bits. + // Note that this has to use ReadRawByte() as we only ensure we've + // got at least 5 bytes at the start of the method. This lets us + // use the fast path in more cases, and we rarely hit this section of code. + for (int i = 0; i < 5; i++) + { + ThrowEndOfInputIfFalse(reader.TryRead(out value)); + tmp = value; + if (tmp < 128) + { + return (uint)result; + } + } + throw InvalidProtocolBufferException.MalformedVarint(); + } + } + } + } + return (uint)result; + } + + /// + /// Reads a raw varint from the input. + /// + internal ulong ReadRawVarint64() + { + int shift = 0; + ulong result = 0; + while (shift < 64) + { + ThrowEndOfInputIfFalse(reader.TryRead(out byte b)); + result |= (ulong)(b & 0x7F) << shift; + if ((b & 0x80) == 0) + { + return result; + } + shift += 7; + } + throw InvalidProtocolBufferException.MalformedVarint(); + } + + /// + /// Reads a 32-bit little-endian integer from the input. + /// + internal uint ReadRawLittleEndian32() + { + const int length = 4; + + if (reader.CurrentSpan.Length - reader.CurrentSpanIndex >= length) + { + // Fast path. All data is in the current span. + ReadOnlySpan data = reader.CurrentSpan.Slice(reader.CurrentSpanIndex, length); + reader.Advance(length); + + return BinaryPrimitives.ReadUInt32LittleEndian(data); + } + else + { + return ReadRawLittleEndian32Slow(); + } + } + + private unsafe uint ReadRawLittleEndian32Slow() + { + const int length = 4; + + byte* buffer = stackalloc byte[length]; + Span tempSpan = new Span(buffer, length); + + ThrowEndOfInputIfFalse(reader.TryCopyTo(tempSpan)); + reader.Advance(length); + + return BinaryPrimitives.ReadUInt32LittleEndian(tempSpan); + } + + /// + /// Reads a 64-bit little-endian integer from the input. + /// + internal unsafe ulong ReadRawLittleEndian64() + { + const int length = 8; + + if (reader.CurrentSpan.Length - reader.CurrentSpanIndex >= length) + { + // Fast path. All data is in the current span. + ReadOnlySpan data = reader.CurrentSpan.Slice(reader.CurrentSpanIndex, length); + reader.Advance(length); + + return BinaryPrimitives.ReadUInt64LittleEndian(data); + } + else + { + return ReadRawLittleEndian64Slow(); + } + } + + private unsafe ulong ReadRawLittleEndian64Slow() + { + const int length = 8; + + byte* buffer = stackalloc byte[length]; + Span tempSpan = new Span(buffer, length); + + ThrowEndOfInputIfFalse(reader.TryCopyTo(tempSpan)); + reader.Advance(length); + + return BinaryPrimitives.ReadUInt64LittleEndian(tempSpan); + } + #endregion + + /// + /// Sets currentLimit to (current position) + byteLimit. This is called + /// when descending into a length-delimited embedded message. The previous + /// limit is returned. + /// + /// The old limit. + internal long PushLimit(long byteLimit) + { + if (byteLimit < 0) + { + throw InvalidProtocolBufferException.NegativeSize(); + } + + byteLimit += reader.Consumed; + long oldLimit = currentLimit; + if (byteLimit > oldLimit) + { + throw InvalidProtocolBufferException.TruncatedMessage(); + } + currentLimit = byteLimit; + + return oldLimit; + } + + /// + /// Discards the current limit, returning the previous limit. + /// + internal void PopLimit(long oldLimit) + { + currentLimit = oldLimit; + } + + /// + /// Returns whether or not all the data before the limit has been read. + /// + /// + internal bool ReachedLimit + { + get + { + if (currentLimit == long.MaxValue) + { + return false; + } + + return reader.Consumed >= currentLimit; + } + } + + /// + /// Verifies that the last call to ReadTag() returned tag 0 - in other words, + /// we've reached the end of the input when we expected to. + /// + /// The + /// tag read was not the one specified + internal void CheckReadEndOfInputTag() + { + if (lastTag != 0) + { + throw InvalidProtocolBufferException.MoreDataAvailable(); + } + } + } +} +#endif \ No newline at end of file diff --git a/csharp/src/Google.Protobuf/CodedOutputWriter.cs b/csharp/src/Google.Protobuf/CodedOutputWriter.cs new file mode 100644 index 000000000000..4b1f6f311159 --- /dev/null +++ b/csharp/src/Google.Protobuf/CodedOutputWriter.cs @@ -0,0 +1,666 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY +using System; +using System.Buffers; +using System.Buffers.Binary; +using System.IO; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security; +using System.Text; + +namespace Google.Protobuf +{ + /// + /// Encodes and writes protocol message fields. + /// Note: experimental API that can change or be removed without any prior notice. + /// + /// + /// + /// This class is generally used by generated code to write appropriate + /// primitives to the stream. It effectively encapsulates the lowest + /// levels of protocol buffer format. Unlike some other implementations, + /// this does not include combined "write tag and value" methods. Generated + /// code knows the exact byte representations of the tags they're going to write, + /// so there's no need to re-encode them each time. Manually-written code calling + /// this class should just call one of the WriteTag overloads before each value. + /// + /// + /// Repeated fields and map fields are not handled by this class; use RepeatedField<T> + /// and MapField<TKey, TValue> to serialize such fields. + /// + /// + [SecuritySafeCritical] + public ref struct CodedOutputWriter + { + private Encoder encoder; + + /// + /// The underlying . + /// + private IBufferWriter output; + + /// + /// The cached span. + /// + private Span span; + + /// + /// The number of uncommitted bytes in the cached span. + /// + private int buffered; + + /// + /// Creates a new CodedOutputWriter that writes to the given + /// . + /// + /// The to write to. + public CodedOutputWriter(IBufferWriter writer) + { + buffered = 0; + + span = writer.GetSpan(); + + this.output = writer; + this.encoder = null; + } + + #region Writing of values (not including tags) + + /// + /// Writes a double field value, without a tag, to the stream. + /// + /// The value to write + public void WriteDouble(double value) + { + WriteRawLittleEndian64((ulong) BitConverter.DoubleToInt64Bits(value)); + } + + /// + /// Writes a float field value, without a tag, to the stream. + /// + /// The value to write + public void WriteFloat(float value) + { + const int length = sizeof(float); + + Ensure(length); + + var floatSpan = span.Slice(buffered, length); + + Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(floatSpan), value); + + if (!BitConverter.IsLittleEndian) + { + floatSpan.Reverse(); + } + + buffered += length; + } + + /// + /// Writes a uint64 field value, without a tag, to the stream. + /// + /// The value to write + public void WriteUInt64(ulong value) + { + WriteRawVarint64(value); + } + + /// + /// Writes an int64 field value, without a tag, to the stream. + /// + /// The value to write + public void WriteInt64(long value) + { + WriteRawVarint64((ulong) value); + } + + /// + /// Writes an int32 field value, without a tag, to the stream. + /// + /// The value to write + public void WriteInt32(int value) + { + if (value >= 0) + { + WriteRawVarint32((uint) value); + } + else + { + // Must sign-extend. + WriteRawVarint64((ulong) value); + } + } + + /// + /// Writes a fixed64 field value, without a tag, to the stream. + /// + /// The value to write + public void WriteFixed64(ulong value) + { + WriteRawLittleEndian64(value); + } + + /// + /// Writes a fixed32 field value, without a tag, to the stream. + /// + /// The value to write + public void WriteFixed32(uint value) + { + WriteRawLittleEndian32(value); + } + + /// + /// Writes a bool field value, without a tag, to the stream. + /// + /// The value to write + public void WriteBool(bool value) + { + WriteRawByte(value ? (byte) 1 : (byte) 0); + } + + /// + /// Writes a string field value, without a tag, to the stream. + /// The data is length-prefixed. + /// + /// The value to write + public void WriteString(string value) + { + int length = Encoding.UTF8.GetByteCount(value); + WriteLength(length); + + Ensure(length); + Span buffer = span.Slice(buffered); + + if (buffer.Length >= length) + { + // Can write string to a single buffer + + if (length == value.Length) // Must be all ASCII... + { + for (int i = 0; i < length; i++) + { + buffer[i] = (byte)value[i]; + } + + buffered += length; + } + else + { + ReadOnlySpan source = value.AsSpan(); + + int bytesUsed; + + unsafe + { + fixed (char* sourceChars = &MemoryMarshal.GetReference(source)) + fixed (byte* destinationBytes = &MemoryMarshal.GetReference(buffer)) + { + bytesUsed = Encoding.UTF8.GetBytes(sourceChars, source.Length, destinationBytes, buffer.Length); + } + } + + buffered += bytesUsed; + } + } + else + { + // The destination byte array might not be large enough so multiple writes are sometimes required + if (encoder == null) + { + encoder = Encoding.UTF8.GetEncoder(); + } + + ReadOnlySpan source = value.AsSpan(); + int written = 0; + + while (true) + { + int bytesUsed; + int charsUsed; + + unsafe + { + fixed (char* sourceChars = &MemoryMarshal.GetReference(source)) + fixed (byte* destinationBytes = &MemoryMarshal.GetReference(buffer)) + { + encoder.Convert(sourceChars, source.Length, destinationBytes, buffer.Length, false, out charsUsed, out bytesUsed, out _); + } + } + + source = source.Slice(charsUsed); + written += bytesUsed; + + buffered += bytesUsed; + + if (source.Length == 0) + { + break; + } + + Ensure(length - written); + buffer = span.Slice(buffered); + } + } + } + + /// + /// Writes a message, without a tag, to the stream. + /// The data is length-prefixed. + /// + /// The value to write + public void WriteMessage(IBufferMessage value) + { + WriteLength(value.CalculateSize()); + value.WriteTo(ref this); + } + + /// + /// Writes a group, without a tag, to the stream. + /// + /// The value to write + public void WriteGroup(IBufferMessage value) + { + value.WriteTo(ref this); + } + + /// + /// Write a byte string, without a tag, to the stream. + /// The data is length-prefixed. + /// + /// The value to write + public void WriteBytes(ByteString value) + { + WriteLength(value.Length); + + Write(value.Span); + } + + /// + /// Writes a uint32 value, without a tag, to the stream. + /// + /// The value to write + public void WriteUInt32(uint value) + { + WriteRawVarint32(value); + } + + /// + /// Writes an enum value, without a tag, to the stream. + /// + /// The value to write + public void WriteEnum(int value) + { + WriteInt32(value); + } + + /// + /// Writes an sfixed32 value, without a tag, to the stream. + /// + /// The value to write. + public void WriteSFixed32(int value) + { + WriteRawLittleEndian32((uint) value); + } + + /// + /// Writes an sfixed64 value, without a tag, to the stream. + /// + /// The value to write + public void WriteSFixed64(long value) + { + WriteRawLittleEndian64((ulong) value); + } + + /// + /// Writes an sint32 value, without a tag, to the stream. + /// + /// The value to write + public void WriteSInt32(int value) + { + WriteRawVarint32(CodedOutputStream.EncodeZigZag32(value)); + } + + /// + /// Writes an sint64 value, without a tag, to the stream. + /// + /// The value to write + public void WriteSInt64(long value) + { + WriteRawVarint64(CodedOutputStream.EncodeZigZag64(value)); + } + + /// + /// Writes a length (in bytes) for length-delimited data. + /// + /// + /// This method simply writes a rawint, but exists for clarity in calling code. + /// + /// Length value, in bytes. + public void WriteLength(int length) + { + WriteRawVarint32((uint) length); + } + + #endregion + + #region Raw tag writing + /// + /// Encodes and writes a tag. + /// + /// The number of the field to write the tag for + /// The wire format type of the tag to write + public void WriteTag(int fieldNumber, WireFormat.WireType type) + { + WriteRawVarint32(WireFormat.MakeTag(fieldNumber, type)); + } + + /// + /// Writes an already-encoded tag. + /// + /// The encoded tag + public void WriteTag(uint tag) + { + WriteRawVarint32(tag); + } + + /// + /// Writes the given single-byte tag directly to the stream. + /// + /// The encoded tag + public void WriteRawTag(byte b1) + { + if (buffered > span.Length) + { + EnsureMore(1); + } + + span[buffered++] = b1; + } + + /// + /// Writes the given two-byte tag directly to the stream. + /// + /// The first byte of the encoded tag + /// The second byte of the encoded tag + public void WriteRawTag(byte b1, byte b2) + { + if (buffered + 1 > span.Length) + { + EnsureMore(2); + } + + span[buffered++] = b1; + span[buffered++] = b2; + } + + /// + /// Writes the given three-byte tag directly to the stream. + /// + /// The first byte of the encoded tag + /// The second byte of the encoded tag + /// The third byte of the encoded tag + public void WriteRawTag(byte b1, byte b2, byte b3) + { + if (buffered + 2 > span.Length) + { + EnsureMore(3); + } + + span[buffered++] = b1; + span[buffered++] = b2; + span[buffered++] = b3; + } + + /// + /// Writes the given four-byte tag directly to the stream. + /// + /// The first byte of the encoded tag + /// The second byte of the encoded tag + /// The third byte of the encoded tag + /// The fourth byte of the encoded tag + public void WriteRawTag(byte b1, byte b2, byte b3, byte b4) + { + if (buffered + 3 > span.Length) + { + EnsureMore(4); + } + + span[buffered++] = b1; + span[buffered++] = b2; + span[buffered++] = b3; + span[buffered++] = b4; + } + + /// + /// Writes the given five-byte tag directly to the stream. + /// + /// The first byte of the encoded tag + /// The second byte of the encoded tag + /// The third byte of the encoded tag + /// The fourth byte of the encoded tag + /// The fifth byte of the encoded tag + public void WriteRawTag(byte b1, byte b2, byte b3, byte b4, byte b5) + { + if (buffered + 4 > span.Length) + { + EnsureMore(5); + } + + span[buffered++] = b1; + span[buffered++] = b2; + span[buffered++] = b3; + span[buffered++] = b4; + span[buffered++] = b5; + } + #endregion + + #region Underlying writing primitives + internal void WriteRawVarint32(uint value) + { + // Optimize for the common case of a single byte value + if (value < 128 && buffered < span.Length) + { + span[buffered++] = (byte)value; + } + else + { + while (value > 127) + { + Ensure(1); + span[buffered++] = (byte)((value & 0x7F) | 0x80); + value >>= 7; + } + + Ensure(1); + span[buffered++] = (byte)value; + } + } + + internal void WriteRawVarint64(ulong value) + { + // Optimize for the common case of a single byte value + if (value < 128 && buffered < span.Length) + { + span[buffered++] = (byte)value; + } + else + { + while (value > 127) + { + Ensure(1); + span[buffered++] = (byte)((value & 0x7F) | 0x80); + value >>= 7; + } + + Ensure(1); + span[buffered++] = (byte)value; + } + } + + internal void WriteRawLittleEndian32(uint value) + { + const int length = 4; + + Ensure(length); + + BinaryPrimitives.WriteUInt32LittleEndian(span.Slice(buffered), value); + + buffered += length; + } + + internal void WriteRawLittleEndian64(ulong value) + { + const int length = 8; + + Ensure(length); + + BinaryPrimitives.WriteUInt64LittleEndian(span.Slice(buffered), value); + + buffered += length; + } + + internal void WriteRawByte(byte value) + { + if (buffered > span.Length) + { + EnsureMore(1); + } + + span[buffered++] = value; + } + + /// + /// Writes out an array of bytes. + /// + internal void WriteRawBytes(byte[] value) + { + WriteRawBytes(value, 0, value.Length); + } + + /// + /// Writes out part of an array of bytes. + /// + internal void WriteRawBytes(byte[] value, int offset, int length) + { + Write(value.AsSpan(offset, length)); + } + + #endregion + + #region Buffer + /// + /// Copies the caller's buffer into the writer. + /// + /// The buffer to copy in. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private void Write(ReadOnlySpan source) + { + if (span.Length - buffered >= source.Length) + { + source.CopyTo(span.Slice(buffered)); + buffered += source.Length; + } + else + { + WriteMultiBuffer(source); + } + } + + /// + /// Acquires a new buffer if necessary to ensure that some given number of bytes can be written to a single buffer. + /// + /// The number of bytes that must be allocated in a single buffer. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private void Ensure(int count = 1) + { + if (span.Length < count + buffered) + { + EnsureMore(count); + } + } + + /// + /// Gets a fresh span to write to, with an optional minimum size. + /// + /// The minimum size for the next requested buffer. + [MethodImpl(MethodImplOptions.NoInlining)] + private void EnsureMore(int count = 0) + { + // This method should only be called when the end of the current span is reached. + // We don't want it inlined because it is called infrequently and it is used by + // methods that we want to be as inlinable as possible. + if (buffered > 0) + { + Flush(); + } + + span = output.GetSpan(count); + } + + /// + /// Copies the caller's buffer into this writer, potentially across multiple buffers from the underlying writer. + /// + /// The buffer to copy into this writer. + private void WriteMultiBuffer(ReadOnlySpan source) + { + while (source.Length > 0) + { + Ensure(source.Length); + + var writable = Math.Min(source.Length, span.Length); + source.Slice(0, writable).CopyTo(span.Slice(buffered)); + source = source.Slice(writable); + buffered += writable; + } + } + + /// + /// Flush uncommited data to the output writer. + /// + public void Flush() + { + var buffered = this.buffered; + if (buffered > 0) + { + this.buffered = 0; + output.Advance(buffered); + span = default; + } + } + #endregion + } +} +#endif \ No newline at end of file diff --git a/csharp/src/Google.Protobuf/Collections/MapField.cs b/csharp/src/Google.Protobuf/Collections/MapField.cs index 1924439e5cad..ae4b5155088d 100644 --- a/csharp/src/Google.Protobuf/Collections/MapField.cs +++ b/csharp/src/Google.Protobuf/Collections/MapField.cs @@ -1,4 +1,4 @@ -#region Copyright notice and license +#region Copyright notice and license // Protocol Buffers - Google's data interchange format // Copyright 2015 Google Inc. All rights reserved. // https://developers.google.com/protocol-buffers/ @@ -33,10 +33,14 @@ using Google.Protobuf.Compatibility; using Google.Protobuf.Reflection; using System; +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY +using System.Buffers; +#endif using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Security; namespace Google.Protobuf.Collections { @@ -51,7 +55,7 @@ namespace Google.Protobuf.Collections /// /// /// Null values are not permitted in the map, either for wrapper types or regular messages. - /// If a map is deserialized from a data stream and the value is missing from an entry, a default value + /// If a map is deserialized from a data input and the value is missing from an entry, a default value /// is created instead. For primitive types, that is the regular default value (0, the empty string and so /// on); for message types, an empty instance of the message is created, as if the map entry contained a 0-length /// encoded value for the field. @@ -411,14 +415,14 @@ public bool Equals(MapField other) } /// - /// Adds entries to the map from the given stream. + /// Adds entries to the map from the given input. /// /// - /// It is assumed that the stream is initially positioned after the tag specified by the codec. - /// This method will continue reading entries from the stream until the end is reached, or + /// It is assumed that the input is initially positioned after the tag specified by the codec. + /// This method will continue reading entries from the input until the end is reached, or /// a different tag is encountered. /// - /// Stream to read from + /// Input to read from /// Codec describing how the key/value pairs are encoded public void AddEntriesFrom(CodedInputStream input, Codec codec) { @@ -431,11 +435,34 @@ public void AddEntriesFrom(CodedInputStream input, Codec codec) } while (input.MaybeConsumeTag(codec.MapTag)); } +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY /// - /// Writes the contents of this map to the given coded output stream, using the specified codec + /// Adds entries to the map from the given input. + /// + /// + /// It is assumed that the input is initially positioned after the tag specified by the codec. + /// This method will continue reading entries from the input until the end is reached, or + /// a different tag is encountered. + /// + /// Input to read from + /// Codec describing how the key/value pairs are encoded + public void AddEntriesFrom(ref CodedInputReader input, Codec codec) + { + var adapter = new Codec.MessageAdapter(codec); + do + { + adapter.Reset(); + input.ReadMessage(adapter); + this[adapter.Key] = adapter.Value; + } while (input.MaybeConsumeTag(codec.MapTag)); + } +#endif + + /// + /// Writes the contents of this map to the given coded output, using the specified codec /// to encode each entry. /// - /// The output stream to write to. + /// The output to write to. /// The codec to use for each entry. public void WriteTo(CodedOutputStream output, Codec codec) { @@ -449,6 +476,26 @@ public void WriteTo(CodedOutputStream output, Codec codec) } } +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + /// + /// Writes the contents of this map to the given coded output, using the specified codec + /// to encode each entry. + /// + /// The output to write to. + /// The codec to use for each entry. + public void WriteTo(ref CodedOutputWriter output, Codec codec) + { + var message = new Codec.MessageAdapter(codec); + foreach (var entry in list) + { + message.Key = entry.Key; + message.Value = entry.Value; + output.WriteTag(codec.MapTag); + output.WriteMessage(message); + } + } +#endif + /// /// Calculates the size of this map based on the given entry codec. /// @@ -621,8 +668,23 @@ public Codec(FieldCodec keyCodec, FieldCodec valueCodec, uint mapT /// and it's simpler if it has direct access to all its fields. /// internal class MessageAdapter : IMessage +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + , IBufferMessage +#endif { - private static readonly byte[] ZeroLengthMessageStreamData = new byte[] { 0 }; + private static readonly byte[] ZeroLengthMessageStreamData; +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + private static readonly ReadOnlySequence ZeroLengthMessageSequence; +#endif + + [SecuritySafeCritical] + static MessageAdapter() + { + ZeroLengthMessageStreamData = new byte[] { 0 }; +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + ZeroLengthMessageSequence = new ReadOnlySequence(ZeroLengthMessageStreamData); +#endif + } private readonly Codec codec; internal TKey Key { get; set; } @@ -659,19 +721,58 @@ public void MergeFrom(CodedInputStream input) } // Corner case: a map entry with a key but no value, where the value type is a message. - // Read it as if we'd seen an input stream with no data (i.e. create a "default" message). + // Read it as if we'd seen input with no data (i.e. create a "default" message). if (Value == null) { Value = codec.valueCodec.Read(new CodedInputStream(ZeroLengthMessageStreamData)); } } +#if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [SecuritySafeCritical] + public void MergeFrom(ref CodedInputReader input) + { + uint tag; + while ((tag = input.ReadTag()) != 0) + { + if (tag == codec.keyCodec.Tag) + { + Key = codec.keyCodec.Read(ref input); + } + else if (tag == codec.valueCodec.Tag) + { + Value = codec.valueCodec.Read(ref input); + } + else + { + input.SkipLastField(); + } + } + + // Corner case: a map entry with a key but no value, where the value type is a message. + // Read it as if we'd seen input with no data (i.e. create a "default" message). + if (Value == null) + { + var reader = new CodedInputReader(ZeroLengthMessageSequence); + Value = codec.valueCodec.Read(ref reader); + } + } +#endif + public void WriteTo(CodedOutputStream output) { codec.keyCodec.WriteTagAndValue(output, Key); codec.valueCodec.WriteTagAndValue(output, Value); } +#if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + public void WriteTo(ref CodedOutputWriter output) + { + codec.keyCodec.WriteTagAndValue(ref output, Key); + codec.valueCodec.WriteTagAndValue(ref output, Value); + } +#endif + public int CalculateSize() { return codec.keyCodec.CalculateSizeWithTag(Key) + codec.valueCodec.CalculateSizeWithTag(Value); diff --git a/csharp/src/Google.Protobuf/Collections/RepeatedField.cs b/csharp/src/Google.Protobuf/Collections/RepeatedField.cs index 0e8bb617647b..392b5f4beb4a 100644 --- a/csharp/src/Google.Protobuf/Collections/RepeatedField.cs +++ b/csharp/src/Google.Protobuf/Collections/RepeatedField.cs @@ -124,11 +124,49 @@ public void AddEntriesFrom(CodedInputStream input, FieldCodec codec) } } +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + /// + /// Adds the entries from the given input stream, decoding them with the specified codec. + /// + /// The input stream to read from. + /// The codec to use in order to read each entry. + public void AddEntriesFrom(ref CodedInputReader input, FieldCodec codec) + { + // TODO: Inline some of the Add code, so we can avoid checking the size on every + // iteration. + uint tag = input.LastTag; + var reader = codec.BufferValueReader; + // Non-nullable value types can be packed or not. + if (FieldCodec.IsPackedRepeatedField(tag)) + { + int length = input.ReadLength(); + if (length > 0) + { + long oldLimit = input.PushLimit(length); + while (!input.ReachedLimit) + { + Add(reader(ref input)); + } + input.PopLimit(oldLimit); + } + // Empty packed field. Odd, but valid - just ignore. + } + else + { + // Not packed... (possibly not packable) + do + { + Add(reader(ref input)); + } while (input.MaybeConsumeTag(tag)); + } + } +#endif + /// /// Calculates the size of this collection based on the given codec. /// /// The codec to use when encoding each field. - /// The number of bytes that would be written to a by , + /// The number of bytes that would be written to output, /// using the same codec. public int CalculateSize(FieldCodec codec) { @@ -220,6 +258,49 @@ public void WriteTo(CodedOutputStream output, FieldCodec codec) } } +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + /// + /// Writes the contents of this collection to the given , + /// encoding each value using the specified codec. + /// + /// The output stream to write to. + /// The codec to use when encoding each value. + public void WriteTo(ref CodedOutputWriter output, FieldCodec codec) + { + if (count == 0) + { + return; + } + var writer = codec.BufferValueWriter; + var tag = codec.Tag; + if (codec.PackedRepeatedField) + { + // Packed primitive type + uint size = (uint)CalculatePackedDataSize(codec); + output.WriteTag(tag); + output.WriteRawVarint32(size); + for (int i = 0; i < count; i++) + { + writer(ref output, array[i]); + } + } + else + { + // Not packed: a simple tag/value pair for each value. + // Can't use codec.WriteTagAndValue, as that omits default values. + for (int i = 0; i < count; i++) + { + output.WriteTag(tag); + writer(ref output, array[i]); + if (codec.EndTag != 0) + { + output.WriteTag(codec.EndTag); + } + } + } + } +#endif + /// /// Gets and sets the capacity of the RepeatedField's internal array. WHen set, the internal array is reallocated to the given capacity. /// The new value is less than Count -or- when Count is less than 0. @@ -579,7 +660,7 @@ public T this[int index] } } - #region Explicit interface implementation for IList and ICollection. +#region Explicit interface implementation for IList and ICollection. bool IList.IsFixedSize => false; void ICollection.CopyTo(Array array, int index) @@ -630,6 +711,6 @@ void IList.Remove(object value) } Remove((T)value); } - #endregion +#endregion } } diff --git a/csharp/src/Google.Protobuf/ExtensionRegistry.cs b/csharp/src/Google.Protobuf/ExtensionRegistry.cs index d3d7ebdc5dd6..e72314b22c29 100644 --- a/csharp/src/Google.Protobuf/ExtensionRegistry.cs +++ b/csharp/src/Google.Protobuf/ExtensionRegistry.cs @@ -80,9 +80,9 @@ private ExtensionRegistry(IDictionary, Extension> collection /// bool ICollection.IsReadOnly => false; - internal bool ContainsInputField(CodedInputStream stream, Type target, out Extension extension) + internal bool ContainsInputField(uint lastTag, Type target, out Extension extension) { - return extensions.TryGetValue(new ObjectIntPair(target, WireFormat.GetTagFieldNumber(stream.LastTag)), out extension); + return extensions.TryGetValue(new ObjectIntPair(target, WireFormat.GetTagFieldNumber(lastTag)), out extension); } /// diff --git a/csharp/src/Google.Protobuf/ExtensionSet.cs b/csharp/src/Google.Protobuf/ExtensionSet.cs index d1bbf6910247..09f70419d98f 100644 --- a/csharp/src/Google.Protobuf/ExtensionSet.cs +++ b/csharp/src/Google.Protobuf/ExtensionSet.cs @@ -1,4 +1,4 @@ -#region Copyright notice and license +#region Copyright notice and license // Protocol Buffers - Google's data interchange format // Copyright 2008 Google Inc. All rights reserved. // https://developers.google.com/protocol-buffers/ @@ -192,7 +192,7 @@ public static bool TryMergeFieldFrom(ref ExtensionSet set, Cod extensionValue.MergeFrom(stream); return true; } - else if (stream.ExtensionRegistry != null && stream.ExtensionRegistry.ContainsInputField(stream, typeof(TTarget), out extension)) + else if (stream.ExtensionRegistry != null && stream.ExtensionRegistry.ContainsInputField(stream.LastTag, typeof(TTarget), out extension)) { IExtensionValue value = extension.CreateValue(); value.MergeFrom(stream); @@ -206,6 +206,37 @@ public static bool TryMergeFieldFrom(ref ExtensionSet set, Cod } } +#if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + /// + /// Tries to merge a field from the coded input, returning true if the field was merged. + /// If the set is null or the field was not otherwise merged, this returns false. + /// + public static bool TryMergeFieldFrom(ref ExtensionSet set, ref CodedInputReader input) where TTarget : IExtendableMessage + { + Extension extension; + int lastFieldNumber = WireFormat.GetTagFieldNumber(input.LastTag); + + IExtensionValue extensionValue; + if (set != null && set.ValuesByNumber.TryGetValue(lastFieldNumber, out extensionValue)) + { + extensionValue.MergeFrom(ref input); + return true; + } + else if (input.ExtensionRegistry != null && input.ExtensionRegistry.ContainsInputField(input.LastTag, typeof(TTarget), out extension)) + { + IExtensionValue value = extension.CreateValue(); + value.MergeFrom(ref input); + set = (set ?? new ExtensionSet()); + set.ValuesByNumber.Add(extension.FieldNumber, value); + return true; + } + else + { + return false; + } + } +#endif + /// /// Merges the second set into the first set, creating a new instance if first is null /// @@ -333,6 +364,19 @@ public void WriteTo(CodedOutputStream stream) } } +#if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + /// + /// Writes the extension values in this set to the output stream + /// + public void WriteTo(ref CodedOutputWriter output) + { + foreach (var value in ValuesByNumber.Values) + { + value.WriteTo(ref output); + } + } +#endif + internal bool IsInitialized() { return ValuesByNumber.Values.All(v => v.IsInitialized()); diff --git a/csharp/src/Google.Protobuf/ExtensionValue.cs b/csharp/src/Google.Protobuf/ExtensionValue.cs index 6ee737a7b0c9..550bea3aeaf7 100644 --- a/csharp/src/Google.Protobuf/ExtensionValue.cs +++ b/csharp/src/Google.Protobuf/ExtensionValue.cs @@ -38,9 +38,15 @@ namespace Google.Protobuf { internal interface IExtensionValue : IEquatable, IDeepCloneable { - void MergeFrom(CodedInputStream input); + void MergeFrom(CodedInputStream input); +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + void MergeFrom(ref CodedInputReader input); +#endif void MergeFrom(IExtensionValue value); - void WriteTo(CodedOutputStream output); + void WriteTo(CodedOutputStream output); +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + void WriteTo(ref CodedOutputWriter output); +#endif int CalculateSize(); bool IsInitialized(); } @@ -94,8 +100,15 @@ public override int GetHashCode() public void MergeFrom(CodedInputStream input) { codec.ValueMerger(input, ref field); - } - + } + +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + public void MergeFrom(ref CodedInputReader input) + { + codec.BufferValueMerger(ref input, ref field); + } +#endif + public void MergeFrom(IExtensionValue value) { if (value is ExtensionValue) @@ -113,8 +126,20 @@ public void WriteTo(CodedOutputStream output) { output.WriteTag(codec.EndTag); } - } - + } + +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + public void WriteTo(ref CodedOutputWriter output) + { + output.WriteTag(codec.Tag); + codec.BufferValueWriter(ref output, field); + if (codec.EndTag != 0) + { + output.WriteTag(codec.EndTag); + } + } +#endif + public T GetValue() => field; public void SetValue(T value) @@ -132,7 +157,7 @@ public bool IsInitialized() { return true; } - } + } } internal sealed class RepeatedExtensionValue : IExtensionValue @@ -183,7 +208,14 @@ public override int GetHashCode() public void MergeFrom(CodedInputStream input) { field.AddEntriesFrom(input, codec); - } + } + +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + public void MergeFrom(ref CodedInputReader input) + { + field.AddEntriesFrom(ref input, codec); + } +#endif public void MergeFrom(IExtensionValue value) { @@ -196,7 +228,14 @@ public void MergeFrom(IExtensionValue value) public void WriteTo(CodedOutputStream output) { field.WriteTo(output, codec); + } + +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + public void WriteTo(ref CodedOutputWriter output) + { + field.WriteTo(ref output, codec); } +#endif public RepeatedField GetValue() => field; @@ -219,6 +258,6 @@ public bool IsInitialized() } return true; - } + } } } diff --git a/csharp/src/Google.Protobuf/FieldCodec.cs b/csharp/src/Google.Protobuf/FieldCodec.cs index 1971261649a0..e292824d5a8a 100644 --- a/csharp/src/Google.Protobuf/FieldCodec.cs +++ b/csharp/src/Google.Protobuf/FieldCodec.cs @@ -218,7 +218,16 @@ public static FieldCodec ForEnum(uint tag, Func toInt32, FuncA codec for the given tag. public static FieldCodec ForString(uint tag, string defaultValue) { - return new FieldCodec(input => input.ReadString(), (output, value) => output.WriteString(value), CodedOutputStream.ComputeStringSize, tag, defaultValue); + return new FieldCodec( + input => input.ReadString(), + (output, value) => output.WriteString(value), +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + (ref CodedInputReader input) => input.ReadString(), + (ref CodedOutputWriter output, string value) => output.WriteString(value), +#endif + CodedOutputStream.ComputeStringSize, + tag, + defaultValue); } /// @@ -229,7 +238,16 @@ public static FieldCodec ForString(uint tag, string defaultValue) /// A codec for the given tag. public static FieldCodec ForBytes(uint tag, ByteString defaultValue) { - return new FieldCodec(input => input.ReadBytes(), (output, value) => output.WriteBytes(value), CodedOutputStream.ComputeBytesSize, tag, defaultValue); + return new FieldCodec( + input => input.ReadBytes(), + (output, value) => output.WriteBytes(value), +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + (ref CodedInputReader input) => input.ReadBytes(), + (ref CodedOutputWriter output, ByteString value) => output.WriteBytes(value), +#endif + CodedOutputStream.ComputeBytesSize, + tag, + defaultValue); } /// @@ -240,7 +258,16 @@ public static FieldCodec ForBytes(uint tag, ByteString defaultValue) /// A codec for the given tag. public static FieldCodec ForBool(uint tag, bool defaultValue) { - return new FieldCodec(input => input.ReadBool(), (output, value) => output.WriteBool(value), CodedOutputStream.BoolSize, tag, defaultValue); + return new FieldCodec( + input => input.ReadBool(), + (output, value) => output.WriteBool(value), +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + (ref CodedInputReader input) => input.ReadBool(), + (ref CodedOutputWriter output, bool value) => output.WriteBool(value), +#endif + CodedOutputStream.BoolSize, + tag, + defaultValue); } /// @@ -251,7 +278,16 @@ public static FieldCodec ForBool(uint tag, bool defaultValue) /// A codec for the given tag. public static FieldCodec ForInt32(uint tag, int defaultValue) { - return new FieldCodec(input => input.ReadInt32(), (output, value) => output.WriteInt32(value), CodedOutputStream.ComputeInt32Size, tag, defaultValue); + return new FieldCodec( + input => input.ReadInt32(), + (output, value) => output.WriteInt32(value), +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + (ref CodedInputReader input) => input.ReadInt32(), + (ref CodedOutputWriter output, int value) => output.WriteInt32(value), +#endif + CodedOutputStream.ComputeInt32Size, + tag, + defaultValue); } /// @@ -262,7 +298,16 @@ public static FieldCodec ForInt32(uint tag, int defaultValue) /// A codec for the given tag. public static FieldCodec ForSInt32(uint tag, int defaultValue) { - return new FieldCodec(input => input.ReadSInt32(), (output, value) => output.WriteSInt32(value), CodedOutputStream.ComputeSInt32Size, tag, defaultValue); + return new FieldCodec( + input => input.ReadSInt32(), + (output, value) => output.WriteSInt32(value), +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + (ref CodedInputReader input) => input.ReadSInt32(), + (ref CodedOutputWriter output, int value) => output.WriteSInt32(value), +#endif + CodedOutputStream.ComputeSInt32Size, + tag, + defaultValue); } /// @@ -273,7 +318,16 @@ public static FieldCodec ForSInt32(uint tag, int defaultValue) /// A codec for the given tag. public static FieldCodec ForFixed32(uint tag, uint defaultValue) { - return new FieldCodec(input => input.ReadFixed32(), (output, value) => output.WriteFixed32(value), 4, tag, defaultValue); + return new FieldCodec( + input => input.ReadFixed32(), + (output, value) => output.WriteFixed32(value), +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + (ref CodedInputReader input) => input.ReadFixed32(), + (ref CodedOutputWriter output, uint value) => output.WriteFixed32(value), +#endif + 4, + tag, + defaultValue); } /// @@ -284,7 +338,16 @@ public static FieldCodec ForFixed32(uint tag, uint defaultValue) /// A codec for the given tag. public static FieldCodec ForSFixed32(uint tag, int defaultValue) { - return new FieldCodec(input => input.ReadSFixed32(), (output, value) => output.WriteSFixed32(value), 4, tag, defaultValue); + return new FieldCodec( + input => input.ReadSFixed32(), + (output, value) => output.WriteSFixed32(value), +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + (ref CodedInputReader input) => input.ReadSFixed32(), + (ref CodedOutputWriter output, int value) => output.WriteSFixed32(value), +#endif + 4, + tag, + defaultValue); } /// @@ -295,7 +358,16 @@ public static FieldCodec ForSFixed32(uint tag, int defaultValue) /// A codec for the given tag. public static FieldCodec ForUInt32(uint tag, uint defaultValue) { - return new FieldCodec(input => input.ReadUInt32(), (output, value) => output.WriteUInt32(value), CodedOutputStream.ComputeUInt32Size, tag, defaultValue); + return new FieldCodec( + input => input.ReadUInt32(), + (output, value) => output.WriteUInt32(value), +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + (ref CodedInputReader input) => input.ReadUInt32(), + (ref CodedOutputWriter output, uint value) => output.WriteUInt32(value), +#endif + CodedOutputStream.ComputeUInt32Size, + tag, + defaultValue); } /// @@ -306,7 +378,16 @@ public static FieldCodec ForUInt32(uint tag, uint defaultValue) /// A codec for the given tag. public static FieldCodec ForInt64(uint tag, long defaultValue) { - return new FieldCodec(input => input.ReadInt64(), (output, value) => output.WriteInt64(value), CodedOutputStream.ComputeInt64Size, tag, defaultValue); + return new FieldCodec( + input => input.ReadInt64(), + (output, value) => output.WriteInt64(value), +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + (ref CodedInputReader input) => input.ReadInt64(), + (ref CodedOutputWriter output, long value) => output.WriteInt64(value), +#endif + CodedOutputStream.ComputeInt64Size, + tag, + defaultValue); } /// @@ -317,7 +398,16 @@ public static FieldCodec ForInt64(uint tag, long defaultValue) /// A codec for the given tag. public static FieldCodec ForSInt64(uint tag, long defaultValue) { - return new FieldCodec(input => input.ReadSInt64(), (output, value) => output.WriteSInt64(value), CodedOutputStream.ComputeSInt64Size, tag, defaultValue); + return new FieldCodec( + input => input.ReadSInt64(), + (output, value) => output.WriteSInt64(value), +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + (ref CodedInputReader input) => input.ReadSInt64(), + (ref CodedOutputWriter output, long value) => output.WriteSInt64(value), +#endif + CodedOutputStream.ComputeSInt64Size, + tag, + defaultValue); } /// @@ -328,7 +418,16 @@ public static FieldCodec ForSInt64(uint tag, long defaultValue) /// A codec for the given tag. public static FieldCodec ForFixed64(uint tag, ulong defaultValue) { - return new FieldCodec(input => input.ReadFixed64(), (output, value) => output.WriteFixed64(value), 8, tag, defaultValue); + return new FieldCodec( + input => input.ReadFixed64(), + (output, value) => output.WriteFixed64(value), +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + (ref CodedInputReader input) => input.ReadFixed64(), + (ref CodedOutputWriter output, ulong value) => output.WriteFixed64(value), +#endif + 8, + tag, + defaultValue); } /// @@ -339,7 +438,16 @@ public static FieldCodec ForFixed64(uint tag, ulong defaultValue) /// A codec for the given tag. public static FieldCodec ForSFixed64(uint tag, long defaultValue) { - return new FieldCodec(input => input.ReadSFixed64(), (output, value) => output.WriteSFixed64(value), 8, tag, defaultValue); + return new FieldCodec( + input => input.ReadSFixed64(), + (output, value) => output.WriteSFixed64(value), +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + (ref CodedInputReader input) => input.ReadSFixed64(), + (ref CodedOutputWriter output, long value) => output.WriteSFixed64(value), +#endif + 8, + tag, + defaultValue); } /// @@ -350,7 +458,16 @@ public static FieldCodec ForSFixed64(uint tag, long defaultValue) /// A codec for the given tag. public static FieldCodec ForUInt64(uint tag, ulong defaultValue) { - return new FieldCodec(input => input.ReadUInt64(), (output, value) => output.WriteUInt64(value), CodedOutputStream.ComputeUInt64Size, tag, defaultValue); + return new FieldCodec( + input => input.ReadUInt64(), + (output, value) => output.WriteUInt64(value), +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + (ref CodedInputReader input) => input.ReadUInt64(), + (ref CodedOutputWriter output, ulong value) => output.WriteUInt64(value), +#endif + CodedOutputStream.ComputeUInt64Size, + tag, + defaultValue); } /// @@ -361,7 +478,16 @@ public static FieldCodec ForUInt64(uint tag, ulong defaultValue) /// A codec for the given tag. public static FieldCodec ForFloat(uint tag, float defaultValue) { - return new FieldCodec(input => input.ReadFloat(), (output, value) => output.WriteFloat(value), CodedOutputStream.FloatSize, tag, defaultValue); + return new FieldCodec( + input => input.ReadFloat(), + (output, value) => output.WriteFloat(value), +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + (ref CodedInputReader input) => input.ReadFloat(), + (ref CodedOutputWriter output, float value) => output.WriteFloat(value), +#endif + CodedOutputStream.FloatSize, + tag, + defaultValue); } /// @@ -372,7 +498,16 @@ public static FieldCodec ForFloat(uint tag, float defaultValue) /// A codec for the given tag. public static FieldCodec ForDouble(uint tag, double defaultValue) { - return new FieldCodec(input => input.ReadDouble(), (output, value) => output.WriteDouble(value), CodedOutputStream.DoubleSize, tag, defaultValue); + return new FieldCodec( + input => input.ReadDouble(), + (output, value) => output.WriteDouble(value), +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + (ref CodedInputReader input) => input.ReadDouble(), + (ref CodedOutputWriter output, double value) => output.WriteDouble(value), +#endif + CodedOutputStream.DoubleSize, + tag, + defaultValue); } // Enums are tricky. We can probably use expression trees to build these delegates automatically, @@ -388,9 +523,13 @@ public static FieldCodec ForDouble(uint tag, double defaultValue) /// A codec for the given tag. public static FieldCodec ForEnum(uint tag, Func toInt32, Func fromInt32, T defaultValue) { - return new FieldCodec(input => fromInt32( - input.ReadEnum()), + return new FieldCodec( + input => fromInt32(input.ReadEnum()), (output, value) => output.WriteEnum(toInt32(value)), +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + (ref CodedInputReader input) => fromInt32(input.ReadEnum()), + (ref CodedOutputWriter output, T value) => output.WriteEnum(toInt32(value)), +#endif value => CodedOutputStream.ComputeEnumSize(toInt32(value)), tag, defaultValue); } @@ -403,14 +542,14 @@ public static FieldCodec ForEnum(uint tag, Func toInt32, Func ForMessage(uint tag, MessageParser parser) where T : class, IMessage { return new FieldCodec( - input => - { - T message = parser.CreateTemplate(); - input.ReadMessage(message); - return message; + input => + { + T message = parser.CreateTemplate(); + input.ReadMessage(message); + return message; }, (output, value) => output.WriteMessage(value), - (CodedInputStream i, ref T v) => + (CodedInputStream i, ref T v) => { if (v == null) { @@ -434,7 +573,46 @@ public static FieldCodec ForMessage(uint tag, MessageParser parser) whe v.MergeFrom(v2); } return true; - }, + }, +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + (ref CodedInputReader input) => + { + T message = parser.CreateTemplate(); + + if (message is IBufferMessage m) + { + input.ReadMessage(m); + return message; + } + + throw new NotSupportedException(nameof(T) + " doesn't implement " + nameof(IBufferMessage)); + }, + (ref CodedOutputWriter output, T value) => + { + if (value is IBufferMessage m) + { + output.WriteMessage(m); + return; + } + + throw new NotSupportedException(nameof(T) + " doesn't implement " + nameof(IBufferMessage)); + }, + (ref CodedInputReader i, ref T v) => + { + if (v == null) + { + v = parser.CreateTemplate(); + } + + if (v is IBufferMessage m) + { + i.ReadMessage(m); + return; + } + + throw new NotSupportedException(nameof(T) + " doesn't implement " + nameof(IBufferMessage)); + }, +#endif message => CodedOutputStream.ComputeMessageSize(message), tag); } @@ -454,8 +632,8 @@ public static FieldCodec ForGroup(uint startTag, uint endTag, MessageParse input.ReadGroup(message); return message; }, - (output, value) => output.WriteGroup(value), - (CodedInputStream i, ref T v) => + (output, value) => output.WriteGroup(value), + (CodedInputStream i, ref T v) => { if (v == null) { @@ -480,6 +658,45 @@ public static FieldCodec ForGroup(uint startTag, uint endTag, MessageParse } return true; }, +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + (ref CodedInputReader input) => + { + T message = parser.CreateTemplate(); + + if (message is IBufferMessage m) + { + input.ReadGroup(m); + return message; + } + + throw new NotSupportedException(nameof(T) + " doesn't implement " + nameof(IBufferMessage)); + }, + (ref CodedOutputWriter output, T value) => + { + if (value is IBufferMessage m) + { + output.WriteGroup(m); + return; + } + + throw new NotSupportedException(nameof(T) + " doesn't implement " + nameof(IBufferMessage)); + }, + (ref CodedInputReader i, ref T v) => + { + if (v == null) + { + v = parser.CreateTemplate(); + } + + if (v is IBufferMessage m) + { + i.ReadGroup(m); + return; + } + + throw new NotSupportedException(nameof(T) + " doesn't implement " + nameof(IBufferMessage)); + }, +#endif message => CodedOutputStream.ComputeGroupSize(message), startTag, endTag); } @@ -494,6 +711,11 @@ public static FieldCodec ForClassWrapper(uint tag) where T : class (output, value) => WrapperCodecs.Write(output, value, nestedCodec), (CodedInputStream i, ref T v) => v = WrapperCodecs.Read(i, nestedCodec), (ref T v, T v2) => { v = v2; return v == null; }, +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + (ref CodedInputReader input) => WrapperCodecs.Read(ref input, nestedCodec), + (ref CodedOutputWriter output, T value) => WrapperCodecs.Write(ref output, value, nestedCodec), + (ref CodedInputReader i, ref T v) => v = WrapperCodecs.Read(ref i, nestedCodec), +#endif value => WrapperCodecs.CalculateSize(value, nestedCodec), tag, 0, null); // Default value for the wrapper @@ -507,10 +729,15 @@ public static FieldCodec ForClassWrapper(uint tag) where T : class { var nestedCodec = WrapperCodecs.GetCodec(); return new FieldCodec( - WrapperCodecs.GetReader(), + WrapperCodecs.GetStreamReader(), (output, value) => WrapperCodecs.Write(output, value.Value, nestedCodec), (CodedInputStream i, ref T? v) => v = WrapperCodecs.Read(i, nestedCodec), (ref T? v, T? v2) => { if (v2.HasValue) { v = v2; } return v.HasValue; }, +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + WrapperCodecs.GetBufferReader(), + (ref CodedOutputWriter output, T? value) => WrapperCodecs.Write(ref output, value.Value, nestedCodec), + (ref CodedInputReader i, ref T? v) => v = WrapperCodecs.Read(ref i, nestedCodec), +#endif value => value == null ? 0 : WrapperCodecs.CalculateSize(value.Value, nestedCodec), tag, 0, null); // Default value for the wrapper @@ -539,7 +766,7 @@ private static class WrapperCodecs { typeof(ByteString), ForBytes(WireFormat.MakeTag(WrappersReflection.WrapperValueFieldNumber, WireFormat.WireType.LengthDelimited)) } }; - private static readonly Dictionary Readers = new Dictionary + private static readonly Dictionary StreamReaders = new Dictionary { // TODO: Provide more optimized readers. { typeof(bool), (Func)CodedInputStream.ReadBoolWrapper }, @@ -558,6 +785,27 @@ private static class WrapperCodecs { typeof(ByteString), null }, }; +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + private static readonly Dictionary BufferReaders = new Dictionary + { + // TODO: Provide more optimized readers. + { typeof(bool), (BufferReader)CodedInputReader.ReadBoolWrapper }, + { typeof(int), (BufferReader)CodedInputReader.ReadInt32Wrapper }, + { typeof(long), (BufferReader)CodedInputReader.ReadInt64Wrapper }, + { typeof(uint), (BufferReader)CodedInputReader.ReadUInt32Wrapper }, + { typeof(ulong), (BufferReader)CodedInputReader.ReadUInt64Wrapper }, + { typeof(float), BitConverter.IsLittleEndian ? + (BufferReader)CodedInputReader.ReadFloatWrapperLittleEndian : + (BufferReader)CodedInputReader.ReadFloatWrapperSlow }, + { typeof(double), BitConverter.IsLittleEndian ? + (BufferReader)CodedInputReader.ReadDoubleWrapperLittleEndian : + (BufferReader)CodedInputReader.ReadDoubleWrapperSlow }, + // `string` and `ByteString` less performance-sensitive. Do not implement for now. + { typeof(string), null }, + { typeof(ByteString), null }, + }; +#endif + /// /// Returns a field codec which effectively wraps a value of type T in a message. /// @@ -572,10 +820,10 @@ internal static FieldCodec GetCodec() return (FieldCodec) value; } - internal static Func GetReader() where T : struct + internal static Func GetStreamReader() where T : struct { object value; - if (!Readers.TryGetValue(typeof(T), out value)) + if (!StreamReaders.TryGetValue(typeof(T), out value)) { throw new InvalidOperationException("Invalid type argument requested for wrapper reader: " + typeof(T)); } @@ -589,6 +837,25 @@ internal static FieldCodec GetCodec() return (Func)value; } +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + internal static BufferReader GetBufferReader() where T : struct + { + object value; + if (!BufferReaders.TryGetValue(typeof(T), out value)) + { + throw new InvalidOperationException("Invalid type argument requested for wrapper reader: " + typeof(T)); + } + if (value == null) + { + // Return default unoptimized reader for the wrapper type. + var nestedCoded = GetCodec(); + return (ref CodedInputReader input) => Read(ref input, nestedCoded); + } + // Return optimized read for the wrapper type. + return (BufferReader)value; + } +#endif + internal static T Read(CodedInputStream input, FieldCodec codec) { int length = input.ReadLength(); @@ -620,6 +887,39 @@ internal static void Write(CodedOutputStream output, T value, FieldCodec c codec.WriteTagAndValue(output, value); } +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + internal static T Read(ref CodedInputReader input, FieldCodec codec) + { + int length = input.ReadLength(); + long oldLimit = input.PushLimit(length); + + uint tag; + T value = codec.DefaultValue; + while ((tag = input.ReadTag()) != 0) + { + if (tag == codec.Tag) + { + value = codec.Read(ref input); + } + else + { + input.SkipLastField(); + } + + } + input.CheckReadEndOfInputTag(); + input.PopLimit(oldLimit); + + return value; + } + + internal static void Write(ref CodedOutputWriter output, T value, FieldCodec codec) + { + output.WriteLength(codec.CalculateSizeWithTag(value)); + codec.WriteTagAndValue(ref output, value); + } +#endif + internal static int CalculateSize(T value, FieldCodec codec) { int fieldLength = codec.CalculateSizeWithTag(value); @@ -628,6 +928,12 @@ internal static int CalculateSize(T value, FieldCodec codec) } } +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + internal delegate void BufferWriter(ref CodedOutputWriter writer, TValue value); + internal delegate TValue BufferReader(ref CodedInputReader reader); + internal delegate void BufferInputMerger(ref CodedInputReader input, ref TValue value); +#endif + /// /// /// An encode/decode pair for a single field. This effectively encapsulates @@ -683,6 +989,13 @@ internal static bool IsPackedRepeatedField(uint tag) => /// internal Action ValueWriter { get; } +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + /// + /// Returns a delegate to write a value (unconditionally) to a coded output writer. + /// + internal BufferWriter BufferValueWriter { get; } +#endif + /// /// Returns the size calculator for just a value. /// @@ -694,12 +1007,28 @@ internal static bool IsPackedRepeatedField(uint tag) => /// internal Func ValueReader { get; } +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + /// + /// Returns a delegate to read a value from a coded input reader. It is assumed that + /// the reader is already positioned on the appropriate tag. + /// + internal BufferReader BufferValueReader { get; } +#endif + /// /// Returns a delegate to merge a value from a coded input stream. /// It is assumed that the stream is already positioned on the appropriate tag /// internal InputMerger ValueMerger { get; } +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + /// + /// Returns a delegate to merge a value from a coded input stream. + /// It is assumed that the stream is already positioned on the appropriate tag + /// + internal BufferInputMerger BufferValueMerger { get; } +#endif + /// /// Returns a delegate to merge two values together. /// @@ -741,9 +1070,22 @@ internal static bool IsPackedRepeatedField(uint tag) => internal FieldCodec( Func reader, Action writer, +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + BufferReader bufferReader, + BufferWriter bufferWriter, +#endif int fixedSize, uint tag, - T defaultValue) : this(reader, writer, _ => fixedSize, tag, defaultValue) + T defaultValue) : this( + reader, + writer, +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + bufferReader, + bufferWriter, +#endif + _ => fixedSize, + tag, + defaultValue) { FixedSize = fixedSize; } @@ -751,9 +1093,26 @@ internal FieldCodec( internal FieldCodec( Func reader, Action writer, +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + BufferReader bufferReader, + BufferWriter bufferWriter, +#endif Func sizeCalculator, uint tag, - T defaultValue) : this(reader, writer, (CodedInputStream i, ref T v) => v = reader(i), (ref T v, T v2) => { v = v2; return true; }, sizeCalculator, tag, 0, defaultValue) + T defaultValue) : this( + reader, + writer, + (CodedInputStream i, ref T v) => v = reader(i), + (ref T v, T v2) => { v = v2; return true; }, +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + bufferReader, + bufferWriter, + (ref CodedInputReader i, ref T v) => v = bufferReader(ref i), +#endif + sizeCalculator, + tag, + 0, + defaultValue) { } @@ -762,9 +1121,27 @@ internal FieldCodec( Action writer, InputMerger inputMerger, ValuesMerger valuesMerger, +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + BufferReader bufferReader, + BufferWriter bufferWriter, + BufferInputMerger bufferInputMerger, +#endif Func sizeCalculator, uint tag, - uint endTag = 0) : this(reader, writer, inputMerger, valuesMerger, sizeCalculator, tag, endTag, DefaultDefault) + uint endTag = 0) : this( + reader, + writer, + inputMerger, + valuesMerger, +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + bufferReader, + bufferWriter, + bufferInputMerger, +#endif + sizeCalculator, + tag, + endTag, + DefaultDefault) { } @@ -773,6 +1150,11 @@ internal FieldCodec( Action writer, InputMerger inputMerger, ValuesMerger valuesMerger, +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + BufferReader bufferReader, + BufferWriter bufferWriter, + BufferInputMerger bufferInputMerger, +#endif Func sizeCalculator, uint tag, uint endTag, @@ -782,6 +1164,11 @@ internal FieldCodec( ValueWriter = writer; ValueMerger = inputMerger; FieldMerger = valuesMerger; +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + BufferValueReader = bufferReader; + BufferValueWriter = bufferWriter; + BufferValueMerger = bufferInputMerger; +#endif ValueSizeCalculator = sizeCalculator; FixedSize = 0; Tag = tag; @@ -810,6 +1197,24 @@ public void WriteTagAndValue(CodedOutputStream output, T value) } } +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + /// + /// Write a tag and the given value, *if* the value is not the default. + /// + public void WriteTagAndValue(ref CodedOutputWriter output, T value) + { + if (!IsDefault(value)) + { + output.WriteTag(Tag); + BufferValueWriter(ref output, value); + if (EndTag != 0) + { + output.WriteTag(EndTag); + } + } + } +#endif + /// /// Reads a value of the codec type from the given . /// @@ -817,6 +1222,15 @@ public void WriteTagAndValue(CodedOutputStream output, T value) /// The value read from the stream. public T Read(CodedInputStream input) => ValueReader(input); +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + /// + /// Reads a value of the codec type from the given . + /// + /// The input stream to read from. + /// The value read from the stream. + public T Read(ref CodedInputReader input) => BufferValueReader(ref input); +#endif + /// /// Calculates the size required to write the given value, with a tag, /// if the value is not the default. diff --git a/csharp/src/Google.Protobuf/Google.Protobuf.csproj b/csharp/src/Google.Protobuf/Google.Protobuf.csproj index e8e33e27e6ff..90393ff7941b 100644 --- a/csharp/src/Google.Protobuf/Google.Protobuf.csproj +++ b/csharp/src/Google.Protobuf/Google.Protobuf.csproj @@ -22,8 +22,22 @@ $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb - + $(DefineConstants);GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + + 7.2 + True + + + + $(DefineConstants);GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + + + + $(DefineConstants);GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY;GOOGLE_PROTOBUF_SUPPORT_FAST_STRING + + 7.2 + True @@ -31,6 +45,11 @@ + + + + + diff --git a/csharp/src/Google.Protobuf/IBufferMessage.cs b/csharp/src/Google.Protobuf/IBufferMessage.cs new file mode 100644 index 000000000000..0fd9973fcb47 --- /dev/null +++ b/csharp/src/Google.Protobuf/IBufferMessage.cs @@ -0,0 +1,57 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + +namespace Google.Protobuf +{ +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + /// + /// Interface for a Protocol Buffers message, supporting + /// and + /// serialization operations. + /// + public interface IBufferMessage : IMessage + { + /// + /// Merges the data from the specified with the current message. + /// + /// See the user guide for precise merge semantics. + /// to read data from. Must not be null. + void MergeFrom(ref CodedInputReader input); + + /// + /// Writes the data to the given . + /// + /// to write the data to. Must not be null. + void WriteTo(ref CodedOutputWriter output); + } +#endif +} diff --git a/csharp/src/Google.Protobuf/IMessage.cs b/csharp/src/Google.Protobuf/IMessage.cs index d089f9463985..cf22872121ab 100644 --- a/csharp/src/Google.Protobuf/IMessage.cs +++ b/csharp/src/Google.Protobuf/IMessage.cs @@ -45,7 +45,7 @@ public interface IMessage /// Merges the data from the specified coded input stream with the current message. /// /// See the user guide for precise merge semantics. - /// + /// Coded input stream to read data from. Must not be null. void MergeFrom(CodedInputStream input); /// diff --git a/csharp/src/Google.Protobuf/MessageExtensions.cs b/csharp/src/Google.Protobuf/MessageExtensions.cs index 06e0980ec2b1..5fa93d2de8c9 100644 --- a/csharp/src/Google.Protobuf/MessageExtensions.cs +++ b/csharp/src/Google.Protobuf/MessageExtensions.cs @@ -31,9 +31,13 @@ #endregion using Google.Protobuf.Reflection; +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY +using System.Buffers; +#endif using System.Collections; using System.IO; using System.Linq; +using System.Security; namespace Google.Protobuf { @@ -237,6 +241,27 @@ internal static void MergeFrom(this IMessage message, ByteString data, bool disc input.CheckReadEndOfStreamTag(); } +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + [SecuritySafeCritical] + internal static void MergeFrom(this IMessage message, ReadOnlySequence data, bool discardUnknownFields, ExtensionRegistry registry) + { + ProtoPreconditions.CheckNotNull(message, "message"); + + if (message is IBufferMessage bufferMessage) + { + CodedInputReader input = new CodedInputReader(data); + input.DiscardUnknownFields = discardUnknownFields; + input.ExtensionRegistry = registry; + bufferMessage.MergeFrom(ref input); + input.CheckReadEndOfInputTag(); + } + else + { + message.MergeFrom(data.ToArray(), discardUnknownFields, registry); + } + } +#endif + internal static void MergeFrom(this IMessage message, Stream input, bool discardUnknownFields, ExtensionRegistry registry) { ProtoPreconditions.CheckNotNull(message, "message"); diff --git a/csharp/src/Google.Protobuf/MessageParser.cs b/csharp/src/Google.Protobuf/MessageParser.cs index 06d0f1059c7a..ed8a5db4ea76 100644 --- a/csharp/src/Google.Protobuf/MessageParser.cs +++ b/csharp/src/Google.Protobuf/MessageParser.cs @@ -31,7 +31,11 @@ #endregion using System; +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY +using System.Buffers; +#endif using System.IO; +using System.Security; namespace Google.Protobuf { @@ -155,6 +159,33 @@ public IMessage ParseJson(string json) return message; } +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + /// + /// Parses a message from the given sequence. + /// + /// The data to parse. + /// The parsed message. + [SecuritySafeCritical] + public IMessage ParseFrom(ReadOnlySequence data) + { + IMessage message = factory(); + message.MergeFrom(data, DiscardUnknownFields, Extensions); + return message; + } + + /// + /// Parses a message from the given coded input stream. + /// + /// The stream to parse. + /// The parsed message. + public IMessage ParseFrom(ref CodedInputReader input) + { + IMessage message = factory(); + MergeFrom(message, ref input); + return message; + } +#endif + // TODO: When we're using a C# 7.1 compiler, make this private protected. internal void MergeFrom(IMessage message, CodedInputStream codedInput) { @@ -170,6 +201,29 @@ internal void MergeFrom(IMessage message, CodedInputStream codedInput) } } +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + // TODO: When we're using a C# 7.1 compiler, make this private protected. + internal void MergeFrom(IMessage message, ref CodedInputReader codedInput) + { + IBufferMessage bufferMessage = message as IBufferMessage; + if (bufferMessage == null) + { + throw new InvalidOperationException("Message does not support CodedInputReader."); + } + + bool originalDiscard = codedInput.DiscardUnknownFields; + try + { + codedInput.DiscardUnknownFields = DiscardUnknownFields; + bufferMessage.MergeFrom(ref codedInput); + } + finally + { + codedInput.DiscardUnknownFields = originalDiscard; + } + } +#endif + /// /// Creates a new message parser which optionally discards unknown fields when parsing. /// @@ -315,6 +369,33 @@ internal MessageParser(Func factory, bool discardUnknownFields, ExtensionRegi return message; } +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + /// + /// Parses a message from the given sequence. + /// + /// The data to parse. + /// The parsed message. + [SecuritySafeCritical] + public new T ParseFrom(ReadOnlySequence data) + { + T message = factory(); + message.MergeFrom(data, DiscardUnknownFields, Extensions); + return message; + } + + /// + /// Parses a message from the given coded input stream. + /// + /// The stream to parse. + /// The parsed message. + public new T ParseFrom(ref CodedInputReader input) + { + T message = factory(); + MergeFrom(message, ref input); + return message; + } +#endif + /// /// Parses a message from the given JSON. /// diff --git a/csharp/src/Google.Protobuf/Reflection/Descriptor.cs b/csharp/src/Google.Protobuf/Reflection/Descriptor.cs index 59c260018c04..9d94b4146fa8 100644 --- a/csharp/src/Google.Protobuf/Reflection/Descriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/Descriptor.cs @@ -193,7 +193,11 @@ static DescriptorReflection() { /// The protocol compiler can output a FileDescriptorSet containing the .proto /// files it parses. /// - public sealed partial class FileDescriptorSet : pb::IMessage { + public sealed partial class FileDescriptorSet : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new FileDescriptorSet()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -277,6 +281,17 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + file_.WriteTo(ref output, _repeated_file_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -312,12 +327,35 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + file_.AddEntriesFrom(ref input, _repeated_file_codec); + break; + } + } + } + } + #endif + } /// /// Describes a complete .proto file. /// - public sealed partial class FileDescriptorProto : pb::IMessage { + public sealed partial class FileDescriptorProto : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new FileDescriptorProto()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -660,6 +698,43 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasName) { + output.WriteRawTag(10); + output.WriteString(Name); + } + if (HasPackage) { + output.WriteRawTag(18); + output.WriteString(Package); + } + dependency_.WriteTo(ref output, _repeated_dependency_codec); + messageType_.WriteTo(ref output, _repeated_messageType_codec); + enumType_.WriteTo(ref output, _repeated_enumType_codec); + service_.WriteTo(ref output, _repeated_service_codec); + extension_.WriteTo(ref output, _repeated_extension_codec); + if (HasOptions) { + output.WriteRawTag(66); + output.WriteMessage(Options); + } + if (HasSourceCodeInfo) { + output.WriteRawTag(74); + output.WriteMessage(SourceCodeInfo); + } + publicDependency_.WriteTo(ref output, _repeated_publicDependency_codec); + weakDependency_.WriteTo(ref output, _repeated_weakDependency_codec); + if (HasSyntax) { + output.WriteRawTag(98); + output.WriteString(Syntax); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -795,12 +870,87 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + Package = input.ReadString(); + break; + } + case 26: { + dependency_.AddEntriesFrom(ref input, _repeated_dependency_codec); + break; + } + case 34: { + messageType_.AddEntriesFrom(ref input, _repeated_messageType_codec); + break; + } + case 42: { + enumType_.AddEntriesFrom(ref input, _repeated_enumType_codec); + break; + } + case 50: { + service_.AddEntriesFrom(ref input, _repeated_service_codec); + break; + } + case 58: { + extension_.AddEntriesFrom(ref input, _repeated_extension_codec); + break; + } + case 66: { + if (!HasOptions) { + Options = new global::Google.Protobuf.Reflection.FileOptions(); + } + input.ReadMessage(Options); + break; + } + case 74: { + if (!HasSourceCodeInfo) { + SourceCodeInfo = new global::Google.Protobuf.Reflection.SourceCodeInfo(); + } + input.ReadMessage(SourceCodeInfo); + break; + } + case 82: + case 80: { + publicDependency_.AddEntriesFrom(ref input, _repeated_publicDependency_codec); + break; + } + case 90: + case 88: { + weakDependency_.AddEntriesFrom(ref input, _repeated_weakDependency_codec); + break; + } + case 98: { + Syntax = input.ReadString(); + break; + } + } + } + } + #endif + } /// /// Describes a message type. /// - public sealed partial class DescriptorProto : pb::IMessage { + public sealed partial class DescriptorProto : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new DescriptorProto()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -1044,6 +1194,32 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasName) { + output.WriteRawTag(10); + output.WriteString(Name); + } + field_.WriteTo(ref output, _repeated_field_codec); + nestedType_.WriteTo(ref output, _repeated_nestedType_codec); + enumType_.WriteTo(ref output, _repeated_enumType_codec); + extensionRange_.WriteTo(ref output, _repeated_extensionRange_codec); + extension_.WriteTo(ref output, _repeated_extension_codec); + if (HasOptions) { + output.WriteRawTag(58); + output.WriteMessage(Options); + } + oneofDecl_.WriteTo(ref output, _repeated_oneofDecl_codec); + reservedRange_.WriteTo(ref output, _repeated_reservedRange_codec); + reservedName_.WriteTo(ref output, _repeated_reservedName_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -1147,11 +1323,73 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + field_.AddEntriesFrom(ref input, _repeated_field_codec); + break; + } + case 26: { + nestedType_.AddEntriesFrom(ref input, _repeated_nestedType_codec); + break; + } + case 34: { + enumType_.AddEntriesFrom(ref input, _repeated_enumType_codec); + break; + } + case 42: { + extensionRange_.AddEntriesFrom(ref input, _repeated_extensionRange_codec); + break; + } + case 50: { + extension_.AddEntriesFrom(ref input, _repeated_extension_codec); + break; + } + case 58: { + if (!HasOptions) { + Options = new global::Google.Protobuf.Reflection.MessageOptions(); + } + input.ReadMessage(Options); + break; + } + case 66: { + oneofDecl_.AddEntriesFrom(ref input, _repeated_oneofDecl_codec); + break; + } + case 74: { + reservedRange_.AddEntriesFrom(ref input, _repeated_reservedRange_codec); + break; + } + case 82: { + reservedName_.AddEntriesFrom(ref input, _repeated_reservedName_codec); + break; + } + } + } + } + #endif + #region Nested types /// Container for nested types declared in the DescriptorProto message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static partial class Types { - public sealed partial class ExtensionRange : pb::IMessage { + public sealed partial class ExtensionRange : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ExtensionRange()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -1319,6 +1557,28 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasStart) { + output.WriteRawTag(8); + output.WriteInt32(Start); + } + if (HasEnd) { + output.WriteRawTag(16); + output.WriteInt32(End); + } + if (HasOptions) { + output.WriteRawTag(26); + output.WriteMessage(Options); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -1384,6 +1644,36 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Start = input.ReadInt32(); + break; + } + case 16: { + End = input.ReadInt32(); + break; + } + case 26: { + if (!HasOptions) { + Options = new global::Google.Protobuf.Reflection.ExtensionRangeOptions(); + } + input.ReadMessage(Options); + break; + } + } + } + } + #endif + } /// @@ -1391,7 +1681,11 @@ public void MergeFrom(pb::CodedInputStream input) { /// fields or extension ranges in the same message. Reserved ranges may /// not overlap. /// - public sealed partial class ReservedRange : pb::IMessage { + public sealed partial class ReservedRange : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ReservedRange()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -1531,6 +1825,24 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasStart) { + output.WriteRawTag(8); + output.WriteInt32(Start); + } + if (HasEnd) { + output.WriteRawTag(16); + output.WriteInt32(End); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -1580,6 +1892,29 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Start = input.ReadInt32(); + break; + } + case 16: { + End = input.ReadInt32(); + break; + } + } + } + } + #endif + } } @@ -1587,7 +1922,11 @@ public void MergeFrom(pb::CodedInputStream input) { } - public sealed partial class ExtensionRangeOptions : pb::IExtendableMessage { + public sealed partial class ExtensionRangeOptions : pb::IExtendableMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ExtensionRangeOptions()); private pb::UnknownFieldSet _unknownFields; internal pb::ExtensionSet _extensions; @@ -1686,6 +2025,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + uninterpretedOption_.WriteTo(ref output, _repeated_uninterpretedOption_codec); + if (_extensions != null) { + _extensions.WriteTo(ref output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -1727,11 +2080,32 @@ public void MergeFrom(pb::CodedInputStream input) { } } - public TValue GetExtension(pb::Extension extension) { - return pb::ExtensionSet.Get(ref _extensions, extension); - } - public pbc::RepeatedField GetExtension(pb::RepeatedExtension extension) { - return pb::ExtensionSet.Get(ref _extensions, extension); + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + } + break; + case 7994: { + uninterpretedOption_.AddEntriesFrom(ref input, _repeated_uninterpretedOption_codec); + break; + } + } + } + } + #endif + + public TValue GetExtension(pb::Extension extension) { + return pb::ExtensionSet.Get(ref _extensions, extension); + } + public pbc::RepeatedField GetExtension(pb::RepeatedExtension extension) { + return pb::ExtensionSet.Get(ref _extensions, extension); } public pbc::RepeatedField GetOrInitializeExtension(pb::RepeatedExtension extension) { return pb::ExtensionSet.GetOrInitialize(ref _extensions, extension); @@ -1754,7 +2128,11 @@ public void ClearExtension(pb::RepeatedExtension /// Describes a field within a message. /// - public sealed partial class FieldDescriptorProto : pb::IMessage { + public sealed partial class FieldDescriptorProto : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new FieldDescriptorProto()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -2160,6 +2538,56 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasName) { + output.WriteRawTag(10); + output.WriteString(Name); + } + if (HasExtendee) { + output.WriteRawTag(18); + output.WriteString(Extendee); + } + if (HasNumber) { + output.WriteRawTag(24); + output.WriteInt32(Number); + } + if (HasLabel) { + output.WriteRawTag(32); + output.WriteEnum((int) Label); + } + if (HasType) { + output.WriteRawTag(40); + output.WriteEnum((int) Type); + } + if (HasTypeName) { + output.WriteRawTag(50); + output.WriteString(TypeName); + } + if (HasDefaultValue) { + output.WriteRawTag(58); + output.WriteString(DefaultValue); + } + if (HasOptions) { + output.WriteRawTag(66); + output.WriteMessage(Options); + } + if (HasOneofIndex) { + output.WriteRawTag(72); + output.WriteInt32(OneofIndex); + } + if (HasJsonName) { + output.WriteRawTag(82); + output.WriteString(JsonName); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -2295,6 +2723,64 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + Extendee = input.ReadString(); + break; + } + case 24: { + Number = input.ReadInt32(); + break; + } + case 32: { + Label = (global::Google.Protobuf.Reflection.FieldDescriptorProto.Types.Label) input.ReadEnum(); + break; + } + case 40: { + Type = (global::Google.Protobuf.Reflection.FieldDescriptorProto.Types.Type) input.ReadEnum(); + break; + } + case 50: { + TypeName = input.ReadString(); + break; + } + case 58: { + DefaultValue = input.ReadString(); + break; + } + case 66: { + if (!HasOptions) { + Options = new global::Google.Protobuf.Reflection.FieldOptions(); + } + input.ReadMessage(Options); + break; + } + case 72: { + OneofIndex = input.ReadInt32(); + break; + } + case 82: { + JsonName = input.ReadString(); + break; + } + } + } + } + #endif + #region Nested types /// Container for nested types declared in the FieldDescriptorProto message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -2367,7 +2853,11 @@ public enum Label { /// /// Describes a oneof. /// - public sealed partial class OneofDescriptorProto : pb::IMessage { + public sealed partial class OneofDescriptorProto : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new OneofDescriptorProto()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -2495,6 +2985,24 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasName) { + output.WriteRawTag(10); + output.WriteString(Name); + } + if (HasOptions) { + output.WriteRawTag(18); + output.WriteMessage(Options); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -2550,12 +3058,42 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + if (!HasOptions) { + Options = new global::Google.Protobuf.Reflection.OneofOptions(); + } + input.ReadMessage(Options); + break; + } + } + } + } + #endif + } /// /// Describes an enum type. /// - public sealed partial class EnumDescriptorProto : pb::IMessage { + public sealed partial class EnumDescriptorProto : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new EnumDescriptorProto()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -2734,6 +3272,27 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasName) { + output.WriteRawTag(10); + output.WriteString(Name); + } + value_.WriteTo(ref output, _repeated_value_codec); + if (HasOptions) { + output.WriteRawTag(26); + output.WriteMessage(Options); + } + reservedRange_.WriteTo(ref output, _repeated_reservedRange_codec); + reservedName_.WriteTo(ref output, _repeated_reservedName_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -2807,6 +3366,44 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + value_.AddEntriesFrom(ref input, _repeated_value_codec); + break; + } + case 26: { + if (!HasOptions) { + Options = new global::Google.Protobuf.Reflection.EnumOptions(); + } + input.ReadMessage(Options); + break; + } + case 34: { + reservedRange_.AddEntriesFrom(ref input, _repeated_reservedRange_codec); + break; + } + case 42: { + reservedName_.AddEntriesFrom(ref input, _repeated_reservedName_codec); + break; + } + } + } + } + #endif + #region Nested types /// Container for nested types declared in the EnumDescriptorProto message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -2819,7 +3416,11 @@ public static partial class Types { /// is inclusive such that it can appropriately represent the entire int32 /// domain. /// - public sealed partial class EnumReservedRange : pb::IMessage { + public sealed partial class EnumReservedRange : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new EnumReservedRange()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -2959,6 +3560,24 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasStart) { + output.WriteRawTag(8); + output.WriteInt32(Start); + } + if (HasEnd) { + output.WriteRawTag(16); + output.WriteInt32(End); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -3008,6 +3627,29 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Start = input.ReadInt32(); + break; + } + case 16: { + End = input.ReadInt32(); + break; + } + } + } + } + #endif + } } @@ -3018,7 +3660,11 @@ public void MergeFrom(pb::CodedInputStream input) { /// /// Describes a value within an enum. /// - public sealed partial class EnumValueDescriptorProto : pb::IMessage { + public sealed partial class EnumValueDescriptorProto : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new EnumValueDescriptorProto()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -3179,6 +3825,28 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasName) { + output.WriteRawTag(10); + output.WriteString(Name); + } + if (HasNumber) { + output.WriteRawTag(16); + output.WriteInt32(Number); + } + if (HasOptions) { + output.WriteRawTag(26); + output.WriteMessage(Options); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -3244,12 +3912,46 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 16: { + Number = input.ReadInt32(); + break; + } + case 26: { + if (!HasOptions) { + Options = new global::Google.Protobuf.Reflection.EnumValueOptions(); + } + input.ReadMessage(Options); + break; + } + } + } + } + #endif + } /// /// Describes a service. /// - public sealed partial class ServiceDescriptorProto : pb::IMessage { + public sealed partial class ServiceDescriptorProto : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ServiceDescriptorProto()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -3391,6 +4093,25 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasName) { + output.WriteRawTag(10); + output.WriteString(Name); + } + method_.WriteTo(ref output, _repeated_method_codec); + if (HasOptions) { + output.WriteRawTag(26); + output.WriteMessage(Options); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -3452,12 +4173,46 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + method_.AddEntriesFrom(ref input, _repeated_method_codec); + break; + } + case 26: { + if (!HasOptions) { + Options = new global::Google.Protobuf.Reflection.ServiceOptions(); + } + input.ReadMessage(Options); + break; + } + } + } + } + #endif + } /// /// Describes a method of a service. /// - public sealed partial class MethodDescriptorProto : pb::IMessage { + public sealed partial class MethodDescriptorProto : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new MethodDescriptorProto()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -3689,7 +4444,40 @@ public override string ToString() { } [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void WriteTo(pb::CodedOutputStream output) { + public void WriteTo(pb::CodedOutputStream output) { + if (HasName) { + output.WriteRawTag(10); + output.WriteString(Name); + } + if (HasInputType) { + output.WriteRawTag(18); + output.WriteString(InputType); + } + if (HasOutputType) { + output.WriteRawTag(26); + output.WriteString(OutputType); + } + if (HasOptions) { + output.WriteRawTag(34); + output.WriteMessage(Options); + } + if (HasClientStreaming) { + output.WriteRawTag(40); + output.WriteBool(ClientStreaming); + } + if (HasServerStreaming) { + output.WriteRawTag(48); + output.WriteBool(ServerStreaming); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + } + + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { if (HasName) { output.WriteRawTag(10); output.WriteString(Name); @@ -3715,9 +4503,10 @@ public void WriteTo(pb::CodedOutputStream output) { output.WriteBool(ServerStreaming); } if (_unknownFields != null) { - _unknownFields.WriteTo(output); + _unknownFields.WriteTo(ref output); } } + #endif [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { @@ -3814,9 +4603,55 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + InputType = input.ReadString(); + break; + } + case 26: { + OutputType = input.ReadString(); + break; + } + case 34: { + if (!HasOptions) { + Options = new global::Google.Protobuf.Reflection.MethodOptions(); + } + input.ReadMessage(Options); + break; + } + case 40: { + ClientStreaming = input.ReadBool(); + break; + } + case 48: { + ServerStreaming = input.ReadBool(); + break; + } + } + } + } + #endif + } - public sealed partial class FileOptions : pb::IExtendableMessage { + public sealed partial class FileOptions : pb::IExtendableMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new FileOptions()); private pb::UnknownFieldSet _unknownFields; internal pb::ExtensionSet _extensions; @@ -4624,6 +5459,100 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasJavaPackage) { + output.WriteRawTag(10); + output.WriteString(JavaPackage); + } + if (HasJavaOuterClassname) { + output.WriteRawTag(66); + output.WriteString(JavaOuterClassname); + } + if (HasOptimizeFor) { + output.WriteRawTag(72); + output.WriteEnum((int) OptimizeFor); + } + if (HasJavaMultipleFiles) { + output.WriteRawTag(80); + output.WriteBool(JavaMultipleFiles); + } + if (HasGoPackage) { + output.WriteRawTag(90); + output.WriteString(GoPackage); + } + if (HasCcGenericServices) { + output.WriteRawTag(128, 1); + output.WriteBool(CcGenericServices); + } + if (HasJavaGenericServices) { + output.WriteRawTag(136, 1); + output.WriteBool(JavaGenericServices); + } + if (HasPyGenericServices) { + output.WriteRawTag(144, 1); + output.WriteBool(PyGenericServices); + } + if (HasJavaGenerateEqualsAndHash) { + output.WriteRawTag(160, 1); + output.WriteBool(JavaGenerateEqualsAndHash); + } + if (HasDeprecated) { + output.WriteRawTag(184, 1); + output.WriteBool(Deprecated); + } + if (HasJavaStringCheckUtf8) { + output.WriteRawTag(216, 1); + output.WriteBool(JavaStringCheckUtf8); + } + if (HasCcEnableArenas) { + output.WriteRawTag(248, 1); + output.WriteBool(CcEnableArenas); + } + if (HasObjcClassPrefix) { + output.WriteRawTag(162, 2); + output.WriteString(ObjcClassPrefix); + } + if (HasCsharpNamespace) { + output.WriteRawTag(170, 2); + output.WriteString(CsharpNamespace); + } + if (HasSwiftPrefix) { + output.WriteRawTag(186, 2); + output.WriteString(SwiftPrefix); + } + if (HasPhpClassPrefix) { + output.WriteRawTag(194, 2); + output.WriteString(PhpClassPrefix); + } + if (HasPhpNamespace) { + output.WriteRawTag(202, 2); + output.WriteString(PhpNamespace); + } + if (HasPhpGenericServices) { + output.WriteRawTag(208, 2); + output.WriteBool(PhpGenericServices); + } + if (HasPhpMetadataNamespace) { + output.WriteRawTag(226, 2); + output.WriteString(PhpMetadataNamespace); + } + if (HasRubyPackage) { + output.WriteRawTag(234, 2); + output.WriteString(RubyPackage); + } + uninterpretedOption_.WriteTo(ref output, _repeated_uninterpretedOption_codec); + if (_extensions != null) { + _extensions.WriteTo(ref output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -4865,6 +5794,107 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + } + break; + case 10: { + JavaPackage = input.ReadString(); + break; + } + case 66: { + JavaOuterClassname = input.ReadString(); + break; + } + case 72: { + OptimizeFor = (global::Google.Protobuf.Reflection.FileOptions.Types.OptimizeMode) input.ReadEnum(); + break; + } + case 80: { + JavaMultipleFiles = input.ReadBool(); + break; + } + case 90: { + GoPackage = input.ReadString(); + break; + } + case 128: { + CcGenericServices = input.ReadBool(); + break; + } + case 136: { + JavaGenericServices = input.ReadBool(); + break; + } + case 144: { + PyGenericServices = input.ReadBool(); + break; + } + case 160: { + JavaGenerateEqualsAndHash = input.ReadBool(); + break; + } + case 184: { + Deprecated = input.ReadBool(); + break; + } + case 216: { + JavaStringCheckUtf8 = input.ReadBool(); + break; + } + case 248: { + CcEnableArenas = input.ReadBool(); + break; + } + case 290: { + ObjcClassPrefix = input.ReadString(); + break; + } + case 298: { + CsharpNamespace = input.ReadString(); + break; + } + case 314: { + SwiftPrefix = input.ReadString(); + break; + } + case 322: { + PhpClassPrefix = input.ReadString(); + break; + } + case 330: { + PhpNamespace = input.ReadString(); + break; + } + case 336: { + PhpGenericServices = input.ReadBool(); + break; + } + case 354: { + PhpMetadataNamespace = input.ReadString(); + break; + } + case 362: { + RubyPackage = input.ReadString(); + break; + } + case 7994: { + uninterpretedOption_.AddEntriesFrom(ref input, _repeated_uninterpretedOption_codec); + break; + } + } + } + } + #endif + public TValue GetExtension(pb::Extension extension) { return pb::ExtensionSet.Get(ref _extensions, extension); } @@ -4914,7 +5944,11 @@ public enum OptimizeMode { } - public sealed partial class MessageOptions : pb::IExtendableMessage { + public sealed partial class MessageOptions : pb::IExtendableMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new MessageOptions()); private pb::UnknownFieldSet _unknownFields; internal pb::ExtensionSet _extensions; @@ -5156,18 +6190,47 @@ public override int GetHashCode() { hash ^= _extensions.GetHashCode(); } if (_unknownFields != null) { - hash ^= _unknownFields.GetHashCode(); + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + if (HasMessageSetWireFormat) { + output.WriteRawTag(8); + output.WriteBool(MessageSetWireFormat); + } + if (HasNoStandardDescriptorAccessor) { + output.WriteRawTag(16); + output.WriteBool(NoStandardDescriptorAccessor); + } + if (HasDeprecated) { + output.WriteRawTag(24); + output.WriteBool(Deprecated); + } + if (HasMapEntry) { + output.WriteRawTag(56); + output.WriteBool(MapEntry); + } + uninterpretedOption_.WriteTo(output, _repeated_uninterpretedOption_codec); + if (_extensions != null) { + _extensions.WriteTo(output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); } - return hash; } - [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public override string ToString() { - return pb::JsonFormatter.ToDiagnosticString(this); - } + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public void WriteTo(pb::CodedOutputStream output) { + public void WriteTo(ref pb::CodedOutputWriter output) { if (HasMessageSetWireFormat) { output.WriteRawTag(8); output.WriteBool(MessageSetWireFormat); @@ -5184,14 +6247,15 @@ public void WriteTo(pb::CodedOutputStream output) { output.WriteRawTag(56); output.WriteBool(MapEntry); } - uninterpretedOption_.WriteTo(output, _repeated_uninterpretedOption_codec); + uninterpretedOption_.WriteTo(ref output, _repeated_uninterpretedOption_codec); if (_extensions != null) { - _extensions.WriteTo(output); + _extensions.WriteTo(ref output); } if (_unknownFields != null) { - _unknownFields.WriteTo(output); + _unknownFields.WriteTo(ref output); } } + #endif [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { @@ -5274,6 +6338,43 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + } + break; + case 8: { + MessageSetWireFormat = input.ReadBool(); + break; + } + case 16: { + NoStandardDescriptorAccessor = input.ReadBool(); + break; + } + case 24: { + Deprecated = input.ReadBool(); + break; + } + case 56: { + MapEntry = input.ReadBool(); + break; + } + case 7994: { + uninterpretedOption_.AddEntriesFrom(ref input, _repeated_uninterpretedOption_codec); + break; + } + } + } + } + #endif + public TValue GetExtension(pb::Extension extension) { return pb::ExtensionSet.Get(ref _extensions, extension); } @@ -5298,7 +6399,11 @@ public void ClearExtension(pb::RepeatedExtension } - public sealed partial class FieldOptions : pb::IExtendableMessage { + public sealed partial class FieldOptions : pb::IExtendableMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new FieldOptions()); private pb::UnknownFieldSet _unknownFields; internal pb::ExtensionSet _extensions; @@ -5649,6 +6754,44 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasCtype) { + output.WriteRawTag(8); + output.WriteEnum((int) Ctype); + } + if (HasPacked) { + output.WriteRawTag(16); + output.WriteBool(Packed); + } + if (HasDeprecated) { + output.WriteRawTag(24); + output.WriteBool(Deprecated); + } + if (HasLazy) { + output.WriteRawTag(40); + output.WriteBool(Lazy); + } + if (HasJstype) { + output.WriteRawTag(48); + output.WriteEnum((int) Jstype); + } + if (HasWeak) { + output.WriteRawTag(80); + output.WriteBool(Weak); + } + uninterpretedOption_.WriteTo(ref output, _repeated_uninterpretedOption_codec); + if (_extensions != null) { + _extensions.WriteTo(ref output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -5750,6 +6893,51 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + } + break; + case 8: { + Ctype = (global::Google.Protobuf.Reflection.FieldOptions.Types.CType) input.ReadEnum(); + break; + } + case 16: { + Packed = input.ReadBool(); + break; + } + case 24: { + Deprecated = input.ReadBool(); + break; + } + case 40: { + Lazy = input.ReadBool(); + break; + } + case 48: { + Jstype = (global::Google.Protobuf.Reflection.FieldOptions.Types.JSType) input.ReadEnum(); + break; + } + case 80: { + Weak = input.ReadBool(); + break; + } + case 7994: { + uninterpretedOption_.AddEntriesFrom(ref input, _repeated_uninterpretedOption_codec); + break; + } + } + } + } + #endif + public TValue GetExtension(pb::Extension extension) { return pb::ExtensionSet.Get(ref _extensions, extension); } @@ -5805,7 +6993,11 @@ public enum JSType { } - public sealed partial class OneofOptions : pb::IExtendableMessage { + public sealed partial class OneofOptions : pb::IExtendableMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new OneofOptions()); private pb::UnknownFieldSet _unknownFields; internal pb::ExtensionSet _extensions; @@ -5904,6 +7096,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + uninterpretedOption_.WriteTo(ref output, _repeated_uninterpretedOption_codec); + if (_extensions != null) { + _extensions.WriteTo(ref output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -5945,6 +7151,27 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + } + break; + case 7994: { + uninterpretedOption_.AddEntriesFrom(ref input, _repeated_uninterpretedOption_codec); + break; + } + } + } + } + #endif + public TValue GetExtension(pb::Extension extension) { return pb::ExtensionSet.Get(ref _extensions, extension); } @@ -5969,7 +7196,11 @@ public void ClearExtension(pb::RepeatedExtension e } - public sealed partial class EnumOptions : pb::IExtendableMessage { + public sealed partial class EnumOptions : pb::IExtendableMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new EnumOptions()); private pb::UnknownFieldSet _unknownFields; internal pb::ExtensionSet _extensions; @@ -6142,6 +7373,28 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasAllowAlias) { + output.WriteRawTag(16); + output.WriteBool(AllowAlias); + } + if (HasDeprecated) { + output.WriteRawTag(24); + output.WriteBool(Deprecated); + } + uninterpretedOption_.WriteTo(ref output, _repeated_uninterpretedOption_codec); + if (_extensions != null) { + _extensions.WriteTo(ref output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -6203,6 +7456,35 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + } + break; + case 16: { + AllowAlias = input.ReadBool(); + break; + } + case 24: { + Deprecated = input.ReadBool(); + break; + } + case 7994: { + uninterpretedOption_.AddEntriesFrom(ref input, _repeated_uninterpretedOption_codec); + break; + } + } + } + } + #endif + public TValue GetExtension(pb::Extension extension) { return pb::ExtensionSet.Get(ref _extensions, extension); } @@ -6227,7 +7509,11 @@ public void ClearExtension(pb::RepeatedExtension ex } - public sealed partial class EnumValueOptions : pb::IExtendableMessage { + public sealed partial class EnumValueOptions : pb::IExtendableMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new EnumValueOptions()); private pb::UnknownFieldSet _unknownFields; internal pb::ExtensionSet _extensions; @@ -6365,6 +7651,24 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasDeprecated) { + output.WriteRawTag(8); + output.WriteBool(Deprecated); + } + uninterpretedOption_.WriteTo(ref output, _repeated_uninterpretedOption_codec); + if (_extensions != null) { + _extensions.WriteTo(ref output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -6416,6 +7720,31 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + } + break; + case 8: { + Deprecated = input.ReadBool(); + break; + } + case 7994: { + uninterpretedOption_.AddEntriesFrom(ref input, _repeated_uninterpretedOption_codec); + break; + } + } + } + } + #endif + public TValue GetExtension(pb::Extension extension) { return pb::ExtensionSet.Get(ref _extensions, extension); } @@ -6440,7 +7769,11 @@ public void ClearExtension(pb::RepeatedExtension { + public sealed partial class ServiceOptions : pb::IExtendableMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ServiceOptions()); private pb::UnknownFieldSet _unknownFields; internal pb::ExtensionSet _extensions; @@ -6578,6 +7911,24 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasDeprecated) { + output.WriteRawTag(136, 2); + output.WriteBool(Deprecated); + } + uninterpretedOption_.WriteTo(ref output, _repeated_uninterpretedOption_codec); + if (_extensions != null) { + _extensions.WriteTo(ref output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -6629,6 +7980,31 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + } + break; + case 264: { + Deprecated = input.ReadBool(); + break; + } + case 7994: { + uninterpretedOption_.AddEntriesFrom(ref input, _repeated_uninterpretedOption_codec); + break; + } + } + } + } + #endif + public TValue GetExtension(pb::Extension extension) { return pb::ExtensionSet.Get(ref _extensions, extension); } @@ -6653,7 +8029,11 @@ public void ClearExtension(pb::RepeatedExtension } - public sealed partial class MethodOptions : pb::IExtendableMessage { + public sealed partial class MethodOptions : pb::IExtendableMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new MethodOptions()); private pb::UnknownFieldSet _unknownFields; internal pb::ExtensionSet _extensions; @@ -6813,14 +8193,36 @@ public void WriteTo(pb::CodedOutputStream output) { output.WriteRawTag(144, 2); output.WriteEnum((int) IdempotencyLevel); } - uninterpretedOption_.WriteTo(output, _repeated_uninterpretedOption_codec); + uninterpretedOption_.WriteTo(output, _repeated_uninterpretedOption_codec); + if (_extensions != null) { + _extensions.WriteTo(output); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + } + + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasDeprecated) { + output.WriteRawTag(136, 2); + output.WriteBool(Deprecated); + } + if (HasIdempotencyLevel) { + output.WriteRawTag(144, 2); + output.WriteEnum((int) IdempotencyLevel); + } + uninterpretedOption_.WriteTo(ref output, _repeated_uninterpretedOption_codec); if (_extensions != null) { - _extensions.WriteTo(output); + _extensions.WriteTo(ref output); } if (_unknownFields != null) { - _unknownFields.WriteTo(output); + _unknownFields.WriteTo(ref output); } } + #endif [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { @@ -6883,6 +8285,35 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) { + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + } + break; + case 264: { + Deprecated = input.ReadBool(); + break; + } + case 272: { + IdempotencyLevel = (global::Google.Protobuf.Reflection.MethodOptions.Types.IdempotencyLevel) input.ReadEnum(); + break; + } + case 7994: { + uninterpretedOption_.AddEntriesFrom(ref input, _repeated_uninterpretedOption_codec); + break; + } + } + } + } + #endif + public TValue GetExtension(pb::Extension extension) { return pb::ExtensionSet.Get(ref _extensions, extension); } @@ -6939,7 +8370,11 @@ public enum IdempotencyLevel { /// or produced by Descriptor::CopyTo()) will never have UninterpretedOptions /// in them. /// - public sealed partial class UninterpretedOption : pb::IMessage { + public sealed partial class UninterpretedOption : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new UninterpretedOption()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -7212,6 +8647,41 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + name_.WriteTo(ref output, _repeated_name_codec); + if (HasIdentifierValue) { + output.WriteRawTag(26); + output.WriteString(IdentifierValue); + } + if (HasPositiveIntValue) { + output.WriteRawTag(32); + output.WriteUInt64(PositiveIntValue); + } + if (HasNegativeIntValue) { + output.WriteRawTag(40); + output.WriteInt64(NegativeIntValue); + } + if (HasDoubleValue) { + output.WriteRawTag(49); + output.WriteDouble(DoubleValue); + } + if (HasStringValue) { + output.WriteRawTag(58); + output.WriteBytes(StringValue); + } + if (HasAggregateValue) { + output.WriteRawTag(66); + output.WriteString(AggregateValue); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -7307,6 +8777,49 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 18: { + name_.AddEntriesFrom(ref input, _repeated_name_codec); + break; + } + case 26: { + IdentifierValue = input.ReadString(); + break; + } + case 32: { + PositiveIntValue = input.ReadUInt64(); + break; + } + case 40: { + NegativeIntValue = input.ReadInt64(); + break; + } + case 49: { + DoubleValue = input.ReadDouble(); + break; + } + case 58: { + StringValue = input.ReadBytes(); + break; + } + case 66: { + AggregateValue = input.ReadString(); + break; + } + } + } + } + #endif + #region Nested types /// Container for nested types declared in the UninterpretedOption message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -7318,7 +8831,11 @@ public static partial class Types { /// E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents /// "foo.(bar.baz).qux". /// - public sealed partial class NamePart : pb::IMessage { + public sealed partial class NamePart : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new NamePart()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -7451,6 +8968,24 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (HasNamePart_) { + output.WriteRawTag(10); + output.WriteString(NamePart_); + } + if (HasIsExtension) { + output.WriteRawTag(16); + output.WriteBool(IsExtension); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -7500,6 +9035,29 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + NamePart_ = input.ReadString(); + break; + } + case 16: { + IsExtension = input.ReadBool(); + break; + } + } + } + } + #endif + } } @@ -7511,7 +9069,11 @@ public void MergeFrom(pb::CodedInputStream input) { /// Encapsulates information about the original source file from which a /// FileDescriptorProto was generated. /// - public sealed partial class SourceCodeInfo : pb::IMessage { + public sealed partial class SourceCodeInfo : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new SourceCodeInfo()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -7640,6 +9202,17 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + location_.WriteTo(ref output, _repeated_location_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -7675,11 +9248,34 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + location_.AddEntriesFrom(ref input, _repeated_location_codec); + break; + } + } + } + } + #endif + #region Nested types /// Container for nested types declared in the SourceCodeInfo message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static partial class Types { - public sealed partial class Location : pb::IMessage { + public sealed partial class Location : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Location()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -7932,6 +9528,27 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + path_.WriteTo(ref output, _repeated_path_codec); + span_.WriteTo(ref output, _repeated_span_codec); + if (HasLeadingComments) { + output.WriteRawTag(26); + output.WriteString(LeadingComments); + } + if (HasTrailingComments) { + output.WriteRawTag(34); + output.WriteString(TrailingComments); + } + leadingDetachedComments_.WriteTo(ref output, _repeated_leadingDetachedComments_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -8001,6 +9618,43 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: + case 8: { + path_.AddEntriesFrom(ref input, _repeated_path_codec); + break; + } + case 18: + case 16: { + span_.AddEntriesFrom(ref input, _repeated_span_codec); + break; + } + case 26: { + LeadingComments = input.ReadString(); + break; + } + case 34: { + TrailingComments = input.ReadString(); + break; + } + case 50: { + leadingDetachedComments_.AddEntriesFrom(ref input, _repeated_leadingDetachedComments_codec); + break; + } + } + } + } + #endif + } } @@ -8013,7 +9667,11 @@ public void MergeFrom(pb::CodedInputStream input) { /// file. A GeneratedCodeInfo message is associated with only one generated /// source file, but may contain references to different source .proto files. /// - public sealed partial class GeneratedCodeInfo : pb::IMessage { + public sealed partial class GeneratedCodeInfo : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new GeneratedCodeInfo()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -8101,6 +9759,17 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + annotation_.WriteTo(ref output, _repeated_annotation_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -8136,11 +9805,34 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + annotation_.AddEntriesFrom(ref input, _repeated_annotation_codec); + break; + } + } + } + } + #endif + #region Nested types /// Container for nested types declared in the GeneratedCodeInfo message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static partial class Types { - public sealed partial class Annotation : pb::IMessage { + public sealed partial class Annotation : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Annotation()); private pb::UnknownFieldSet _unknownFields; private int _hasBits0; @@ -8334,6 +10026,29 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + path_.WriteTo(ref output, _repeated_path_codec); + if (HasSourceFile) { + output.WriteRawTag(18); + output.WriteString(SourceFile); + } + if (HasBegin) { + output.WriteRawTag(24); + output.WriteInt32(Begin); + } + if (HasEnd) { + output.WriteRawTag(32); + output.WriteInt32(End); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -8400,6 +10115,38 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: + case 8: { + path_.AddEntriesFrom(ref input, _repeated_path_codec); + break; + } + case 18: { + SourceFile = input.ReadString(); + break; + } + case 24: { + Begin = input.ReadInt32(); + break; + } + case 32: { + End = input.ReadInt32(); + break; + } + } + } + } + #endif + } } diff --git a/csharp/src/Google.Protobuf/SequenceReader.cs b/csharp/src/Google.Protobuf/SequenceReader.cs new file mode 100644 index 000000000000..55f386794091 --- /dev/null +++ b/csharp/src/Google.Protobuf/SequenceReader.cs @@ -0,0 +1,417 @@ +#region Copyright notice and license +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#endregion + +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY +using System; +using System.Buffers; +using System.Collections.Generic; +using System.Diagnostics; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Security; +using System.Text; +using System.Threading; + +namespace Google.Protobuf +{ + /// + /// SequenceReader is originally from corefx, and has been contributed to Protobuf + /// https://github.com/dotnet/runtime/blob/071da4c41aa808c949a773b92dca6f88de9d11f3/src/libraries/System.Memory/src/System/Buffers/SequenceReader.cs + /// + [SecuritySafeCritical] + internal ref partial struct SequenceReader where T : IEquatable + { + private SequencePosition _currentPosition; + private SequencePosition _nextPosition; + private bool _moreData; + private long _length; + + /// + /// Create a over the given . + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public SequenceReader(ReadOnlySequence sequence) + { + CurrentSpanIndex = 0; + Consumed = 0; + Sequence = sequence; + _currentPosition = sequence.Start; + _length = -1; + + var first = sequence.First.Span; + _nextPosition = sequence.GetPosition(first.Length); + CurrentSpan = first; + _moreData = first.Length > 0; + + if (!_moreData && !sequence.IsSingleSegment) + { + _moreData = true; + GetNextSpan(); + } + } + + /// + /// True when there is no more data in the . + /// + public bool End => !_moreData; + + /// + /// The underlying for the reader. + /// + public ReadOnlySequence Sequence { get; } + + /// + /// The current position in the . + /// + public SequencePosition Position + => Sequence.GetPosition(CurrentSpanIndex, _currentPosition); + + /// + /// The current segment in the as a span. + /// + public ReadOnlySpan CurrentSpan { get; private set; } + + /// + /// The index in the . + /// + public int CurrentSpanIndex { get; private set; } + + /// + /// The unread portion of the . + /// + public ReadOnlySpan UnreadSpan + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => CurrentSpan.Slice(CurrentSpanIndex); + } + + /// + /// The total number of 's processed by the reader. + /// + public long Consumed { get; private set; } + + /// + /// Remaining 's in the reader's . + /// + public long Remaining => Length - Consumed; + + /// + /// Count of in the reader's . + /// + public long Length + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { + if (_length < 0) + { + // Cache the length + _length = Sequence.Length; + } + return _length; + } + } + + /// + /// Peeks at the next value without advancing the reader. + /// + /// The next value or default if at the end. + /// False if at the end of the reader. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool TryPeek(out T value) + { + if (_moreData) + { + value = CurrentSpan[CurrentSpanIndex]; + return true; + } + else + { + value = default; + return false; + } + } + + /// + /// Read the next value and advance the reader. + /// + /// The next value or default if at the end. + /// False if at the end of the reader. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool TryRead(out T value) + { + if (End) + { + value = default; + return false; + } + + value = CurrentSpan[CurrentSpanIndex]; + CurrentSpanIndex++; + Consumed++; + + if (CurrentSpanIndex >= CurrentSpan.Length) + { + GetNextSpan(); + } + + return true; + } + + /// + /// Move the reader back the specified number of items. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Rewind(long count) + { + if (count < 0) + { + throw new ArgumentOutOfRangeException(nameof(count)); + } + + Consumed -= count; + + if (CurrentSpanIndex >= count) + { + CurrentSpanIndex -= (int)count; + _moreData = true; + } + else + { + // Current segment doesn't have enough data, scan backward through segments + RetreatToPreviousSpan(Consumed); + } + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private void RetreatToPreviousSpan(long consumed) + { + ResetReader(); + Advance(consumed); + } + + private void ResetReader() + { + CurrentSpanIndex = 0; + Consumed = 0; + _currentPosition = Sequence.Start; + _nextPosition = _currentPosition; + + if (Sequence.TryGet(ref _nextPosition, out ReadOnlyMemory memory, advance: true)) + { + _moreData = true; + + if (memory.Length == 0) + { + CurrentSpan = default; + // No data in the first span, move to one with data + GetNextSpan(); + } + else + { + CurrentSpan = memory.Span; + } + } + else + { + // No data in any spans and at end of sequence + _moreData = false; + CurrentSpan = default; + } + } + + /// + /// Get the next segment with available data, if any. + /// + private void GetNextSpan() + { + if (!Sequence.IsSingleSegment) + { + SequencePosition previousNextPosition = _nextPosition; + while (Sequence.TryGet(ref _nextPosition, out ReadOnlyMemory memory, advance: true)) + { + _currentPosition = previousNextPosition; + if (memory.Length > 0) + { + CurrentSpan = memory.Span; + CurrentSpanIndex = 0; + return; + } + else + { + CurrentSpan = default; + CurrentSpanIndex = 0; + previousNextPosition = _nextPosition; + } + } + } + _moreData = false; + } + + /// + /// Move the reader ahead the specified number of items. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Advance(long count) + { + const long TooBigOrNegative = unchecked((long)0xFFFFFFFF80000000); + if ((count & TooBigOrNegative) == 0 && CurrentSpan.Length - CurrentSpanIndex > (int)count) + { + CurrentSpanIndex += (int)count; + Consumed += count; + } + else + { + // Can't satisfy from the current span + AdvanceToNextSpan(count); + } + } + + /// + /// Unchecked helper to avoid unnecessary checks where you know count is valid. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal void AdvanceCurrentSpan(long count) + { + Debug.Assert(count >= 0); + + Consumed += count; + CurrentSpanIndex += (int)count; + if (CurrentSpanIndex >= CurrentSpan.Length) + GetNextSpan(); + } + + /// + /// Only call this helper if you know that you are advancing in the current span + /// with valid count and there is no need to fetch the next one. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal void AdvanceWithinSpan(long count) + { + Debug.Assert(count >= 0); + + Consumed += count; + CurrentSpanIndex += (int)count; + + Debug.Assert(CurrentSpanIndex < CurrentSpan.Length); + } + + private void AdvanceToNextSpan(long count) + { + if (count < 0) + { + throw new ArgumentOutOfRangeException(nameof(count)); + } + + Consumed += count; + while (_moreData) + { + int remaining = CurrentSpan.Length - CurrentSpanIndex; + + if (remaining > count) + { + CurrentSpanIndex += (int)count; + count = 0; + break; + } + + // As there may not be any further segments we need to + // push the current index to the end of the span. + CurrentSpanIndex += remaining; + count -= remaining; + Debug.Assert(count >= 0); + + GetNextSpan(); + + if (count == 0) + { + break; + } + } + + if (count != 0) + { + // Not enough data left- adjust for where we actually ended and throw + Consumed -= count; + throw new ArgumentOutOfRangeException(nameof(count)); + } + } + + /// + /// Copies data from the current to the given span. + /// + /// Destination to copy to. + /// True if there is enough data to copy to the . + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool TryCopyTo(Span destination) + { + ReadOnlySpan firstSpan = UnreadSpan; + if (firstSpan.Length >= destination.Length) + { + firstSpan.Slice(0, destination.Length).CopyTo(destination); + return true; + } + + return TryCopyMultisegment(destination); + } + + internal bool TryCopyMultisegment(Span destination) + { + if (Remaining < destination.Length) + return false; + + ReadOnlySpan firstSpan = UnreadSpan; + Debug.Assert(firstSpan.Length < destination.Length); + firstSpan.CopyTo(destination); + int copied = firstSpan.Length; + + SequencePosition next = _nextPosition; + while (Sequence.TryGet(ref next, out ReadOnlyMemory nextSegment, true)) + { + if (nextSegment.Length > 0) + { + ReadOnlySpan nextSpan = nextSegment.Span; + int toCopy = Math.Min(nextSpan.Length, destination.Length - copied); + nextSpan.Slice(0, toCopy).CopyTo(destination.Slice(copied)); + copied += toCopy; + if (copied >= destination.Length) + { + break; + } + } + } + + return true; + } + } +} +#endif \ No newline at end of file diff --git a/csharp/src/Google.Protobuf/UnknownField.cs b/csharp/src/Google.Protobuf/UnknownField.cs index e3ce0e86efce..e206f472e16a 100644 --- a/csharp/src/Google.Protobuf/UnknownField.cs +++ b/csharp/src/Google.Protobuf/UnknownField.cs @@ -147,6 +147,59 @@ internal void WriteTo(int fieldNumber, CodedOutputStream output) } } +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + /// + /// Serializes the field, including the field number, and writes it to + /// + /// + /// The unknown field number. + /// The CodedOutputWriter to write to. + internal void WriteTo(int fieldNumber, ref CodedOutputWriter output) + { + if (varintList != null) + { + foreach (ulong value in varintList) + { + output.WriteTag(fieldNumber, WireFormat.WireType.Varint); + output.WriteUInt64(value); + } + } + if (fixed32List != null) + { + foreach (uint value in fixed32List) + { + output.WriteTag(fieldNumber, WireFormat.WireType.Fixed32); + output.WriteFixed32(value); + } + } + if (fixed64List != null) + { + foreach (ulong value in fixed64List) + { + output.WriteTag(fieldNumber, WireFormat.WireType.Fixed64); + output.WriteFixed64(value); + } + } + if (lengthDelimitedList != null) + { + foreach (ByteString value in lengthDelimitedList) + { + output.WriteTag(fieldNumber, WireFormat.WireType.LengthDelimited); + output.WriteBytes(value); + } + } + if (groupList != null) + { + foreach (UnknownFieldSet value in groupList) + { + output.WriteTag(fieldNumber, WireFormat.WireType.StartGroup); + value.WriteTo(ref output); + output.WriteTag(fieldNumber, WireFormat.WireType.EndGroup); + } + } + } +#endif + /// /// Computes the number of bytes required to encode this field, including field /// number. diff --git a/csharp/src/Google.Protobuf/UnknownFieldSet.cs b/csharp/src/Google.Protobuf/UnknownFieldSet.cs index d136cf1e6572..97bd1d1c4306 100644 --- a/csharp/src/Google.Protobuf/UnknownFieldSet.cs +++ b/csharp/src/Google.Protobuf/UnknownFieldSet.cs @@ -75,7 +75,20 @@ public void WriteTo(CodedOutputStream output) { entry.Value.WriteTo(entry.Key, output); } - } + } + +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + /// + /// Serializes the set and writes it to . + /// + public void WriteTo(ref CodedOutputWriter output) + { + foreach (KeyValuePair entry in fields) + { + entry.Value.WriteTo(entry.Key, ref output); + } + } +#endif /// /// Gets the number of bytes required to encode this set. @@ -231,7 +244,65 @@ private bool MergeFieldFrom(CodedInputStream input) default: throw InvalidProtocolBufferException.InvalidWireType(); } - } + } + +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + /// + /// Parse a single field from and merge it + /// into this set. + /// + /// The coded input reader containing the field + /// false if the tag is an "end group" tag, true otherwise + private bool MergeFieldFrom(ref CodedInputReader input) + { + uint tag = input.LastTag; + int number = WireFormat.GetTagFieldNumber(tag); + switch (WireFormat.GetTagWireType(tag)) + { + case WireFormat.WireType.Varint: + { + ulong uint64 = input.ReadUInt64(); + GetOrAddField(number).AddVarint(uint64); + return true; + } + case WireFormat.WireType.Fixed32: + { + uint uint32 = input.ReadFixed32(); + GetOrAddField(number).AddFixed32(uint32); + return true; + } + case WireFormat.WireType.Fixed64: + { + ulong uint64 = input.ReadFixed64(); + GetOrAddField(number).AddFixed64(uint64); + return true; + } + case WireFormat.WireType.LengthDelimited: + { + ByteString bytes = input.ReadBytes(); + GetOrAddField(number).AddLengthDelimited(bytes); + return true; + } + case WireFormat.WireType.StartGroup: + { + uint endTag = WireFormat.MakeTag(number, WireFormat.WireType.EndGroup); + UnknownFieldSet set = new UnknownFieldSet(); + while (input.ReadTag() != endTag) + { + set.MergeFieldFrom(ref input); + } + GetOrAddField(number).AddGroup(set); + return true; + } + case WireFormat.WireType.EndGroup: + { + return false; + } + default: + throw InvalidProtocolBufferException.InvalidWireType(); + } + } +#endif /// /// Create a new UnknownFieldSet if unknownFields is null. @@ -260,6 +331,36 @@ public static UnknownFieldSet MergeFieldFrom(UnknownFieldSet unknownFields, } return unknownFields; } + +#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY + /// + /// Create a new UnknownFieldSet if unknownFields is null. + /// Parse a single field from and merge it + /// into unknownFields. If is configured to discard unknown fields, + /// will be returned as-is and the field will be skipped. + /// + /// The UnknownFieldSet which need to be merged + /// The coded input reader containing the field + /// The merged UnknownFieldSet + public static UnknownFieldSet MergeFieldFrom(UnknownFieldSet unknownFields, + ref CodedInputReader input) + { + if (input.DiscardUnknownFields) + { + input.SkipLastField(); + return unknownFields; + } + if (unknownFields == null) + { + unknownFields = new UnknownFieldSet(); + } + if (!unknownFields.MergeFieldFrom(ref input)) + { + throw new InvalidProtocolBufferException("Merge an unknown field of end-group tag, indicating that the corresponding start-group was missing."); // match the old code-gen + } + return unknownFields; + } +#endif /// /// Merges the fields from into this set. diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Any.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Any.cs index 09e0e29f0de9..01c49939d1ce 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/Any.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/Any.cs @@ -119,7 +119,11 @@ static AnyReflection() { /// "value": "1.212s" /// } /// - public sealed partial class Any : pb::IMessage { + public sealed partial class Any : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Any()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -257,6 +261,24 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (TypeUrl.Length != 0) { + output.WriteRawTag(10); + output.WriteString(TypeUrl); + } + if (Value.Length != 0) { + output.WriteRawTag(18); + output.WriteBytes(Value); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -306,6 +328,29 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + TypeUrl = input.ReadString(); + break; + } + case 18: { + Value = input.ReadBytes(); + break; + } + } + } + } + #endif + } #endregion diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Api.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Api.cs index 06a990591940..de0f0b947407 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/Api.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/Api.cs @@ -64,7 +64,11 @@ static ApiReflection() { /// this message itself. See https://cloud.google.com/apis/design/glossary for /// detailed terminology. /// - public sealed partial class Api : pb::IMessage { + public sealed partial class Api : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Api()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -289,6 +293,35 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Name.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Name); + } + methods_.WriteTo(ref output, _repeated_methods_codec); + options_.WriteTo(ref output, _repeated_options_codec); + if (Version.Length != 0) { + output.WriteRawTag(34); + output.WriteString(Version); + } + if (sourceContext_ != null) { + output.WriteRawTag(42); + output.WriteMessage(SourceContext); + } + mixins_.WriteTo(ref output, _repeated_mixins_codec); + if (Syntax != global::Google.Protobuf.WellKnownTypes.Syntax.Proto2) { + output.WriteRawTag(56); + output.WriteEnum((int) Syntax); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -382,12 +415,62 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + methods_.AddEntriesFrom(ref input, _repeated_methods_codec); + break; + } + case 26: { + options_.AddEntriesFrom(ref input, _repeated_options_codec); + break; + } + case 34: { + Version = input.ReadString(); + break; + } + case 42: { + if (sourceContext_ == null) { + SourceContext = new global::Google.Protobuf.WellKnownTypes.SourceContext(); + } + input.ReadMessage(SourceContext); + break; + } + case 50: { + mixins_.AddEntriesFrom(ref input, _repeated_mixins_codec); + break; + } + case 56: { + Syntax = (global::Google.Protobuf.WellKnownTypes.Syntax) input.ReadEnum(); + break; + } + } + } + } + #endif + } /// /// Method represents a method of an API interface. /// - public sealed partial class Method : pb::IMessage { + public sealed partial class Method : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Method()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -600,6 +683,41 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Name.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Name); + } + if (RequestTypeUrl.Length != 0) { + output.WriteRawTag(18); + output.WriteString(RequestTypeUrl); + } + if (RequestStreaming != false) { + output.WriteRawTag(24); + output.WriteBool(RequestStreaming); + } + if (ResponseTypeUrl.Length != 0) { + output.WriteRawTag(34); + output.WriteString(ResponseTypeUrl); + } + if (ResponseStreaming != false) { + output.WriteRawTag(40); + output.WriteBool(ResponseStreaming); + } + options_.WriteTo(ref output, _repeated_options_codec); + if (Syntax != global::Google.Protobuf.WellKnownTypes.Syntax.Proto2) { + output.WriteRawTag(56); + output.WriteEnum((int) Syntax); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -695,6 +813,49 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + RequestTypeUrl = input.ReadString(); + break; + } + case 24: { + RequestStreaming = input.ReadBool(); + break; + } + case 34: { + ResponseTypeUrl = input.ReadString(); + break; + } + case 40: { + ResponseStreaming = input.ReadBool(); + break; + } + case 50: { + options_.AddEntriesFrom(ref input, _repeated_options_codec); + break; + } + case 56: { + Syntax = (global::Google.Protobuf.WellKnownTypes.Syntax) input.ReadEnum(); + break; + } + } + } + } + #endif + } /// @@ -777,7 +938,11 @@ public void MergeFrom(pb::CodedInputStream input) { /// ... /// } /// - public sealed partial class Mixin : pb::IMessage { + public sealed partial class Mixin : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Mixin()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -890,6 +1055,24 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Name.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Name); + } + if (Root.Length != 0) { + output.WriteRawTag(18); + output.WriteString(Root); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -939,6 +1122,29 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + Root = input.ReadString(); + break; + } + } + } + } + #endif + } #endregion diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs index f0078c4dd4e0..f5afe09d9300 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs @@ -100,7 +100,11 @@ static DurationReflection() { /// be expressed in JSON format as "3.000000001s", and 3 seconds and 1 /// microsecond should be expressed in JSON format as "3.000001s". /// - public sealed partial class Duration : pb::IMessage { + public sealed partial class Duration : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Duration()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -219,6 +223,24 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Seconds != 0L) { + output.WriteRawTag(8); + output.WriteInt64(Seconds); + } + if (Nanos != 0) { + output.WriteRawTag(16); + output.WriteInt32(Nanos); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -268,6 +290,29 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Seconds = input.ReadInt64(); + break; + } + case 16: { + Nanos = input.ReadInt32(); + break; + } + } + } + } + #endif + } #endregion diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs index fa435cd23edf..d2c70e3d07fb 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs @@ -50,7 +50,11 @@ static EmptyReflection() { /// /// The JSON representation for `Empty` is empty JSON object `{}`. /// - public sealed partial class Empty : pb::IMessage { + public sealed partial class Empty : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Empty()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -120,6 +124,16 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -149,6 +163,21 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + } + } + } + #endif + } #endregion diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs b/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs index 00e1e9faa453..9f096d2208f6 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs @@ -240,7 +240,11 @@ static FieldMaskReflection() { /// request should verify the included field paths, and return an /// `INVALID_ARGUMENT` error if any path is unmappable. /// - public sealed partial class FieldMask : pb::IMessage { + public sealed partial class FieldMask : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new FieldMask()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -327,6 +331,17 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + paths_.WriteTo(ref output, _repeated_paths_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -362,6 +377,25 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + paths_.AddEntriesFrom(ref input, _repeated_paths_codec); + break; + } + } + } + } + #endif + } #endregion diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs b/csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs index d7076196e0fd..7db9b941c33d 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs @@ -44,7 +44,11 @@ static SourceContextReflection() { /// `SourceContext` represents information about the source of a /// protobuf element, like the file in which it is defined. /// - public sealed partial class SourceContext : pb::IMessage { + public sealed partial class SourceContext : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new SourceContext()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -136,6 +140,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (FileName.Length != 0) { + output.WriteRawTag(10); + output.WriteString(FileName); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -175,6 +193,25 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + FileName = input.ReadString(); + break; + } + } + } + } + #endif + } #endregion diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs index b1dbe239cc9c..4d3b9cd3c2c5 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs @@ -77,7 +77,11 @@ public enum NullValue { /// /// The JSON representation for `Struct` is JSON object. /// - public sealed partial class Struct : pb::IMessage { + public sealed partial class Struct : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Struct()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -164,6 +168,17 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + fields_.WriteTo(ref output, _map_fields_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -199,6 +214,25 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + fields_.AddEntriesFrom(ref input, _map_fields_codec); + break; + } + } + } + } + #endif + } /// @@ -209,7 +243,11 @@ public void MergeFrom(pb::CodedInputStream input) { /// /// The JSON representation for `Value` is JSON value. /// - public sealed partial class Value : pb::IMessage { + public sealed partial class Value : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Value()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -445,6 +483,40 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (kindCase_ == KindOneofCase.NullValue) { + output.WriteRawTag(8); + output.WriteEnum((int) NullValue); + } + if (kindCase_ == KindOneofCase.NumberValue) { + output.WriteRawTag(17); + output.WriteDouble(NumberValue); + } + if (kindCase_ == KindOneofCase.StringValue) { + output.WriteRawTag(26); + output.WriteString(StringValue); + } + if (kindCase_ == KindOneofCase.BoolValue) { + output.WriteRawTag(32); + output.WriteBool(BoolValue); + } + if (kindCase_ == KindOneofCase.StructValue) { + output.WriteRawTag(42); + output.WriteMessage(StructValue); + } + if (kindCase_ == KindOneofCase.ListValue) { + output.WriteRawTag(50); + output.WriteMessage(ListValue); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -554,6 +626,56 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + kind_ = input.ReadEnum(); + kindCase_ = KindOneofCase.NullValue; + break; + } + case 17: { + NumberValue = input.ReadDouble(); + break; + } + case 26: { + StringValue = input.ReadString(); + break; + } + case 32: { + BoolValue = input.ReadBool(); + break; + } + case 42: { + global::Google.Protobuf.WellKnownTypes.Struct subBuilder = new global::Google.Protobuf.WellKnownTypes.Struct(); + if (kindCase_ == KindOneofCase.StructValue) { + subBuilder.MergeFrom(StructValue); + } + input.ReadMessage(subBuilder); + StructValue = subBuilder; + break; + } + case 50: { + global::Google.Protobuf.WellKnownTypes.ListValue subBuilder = new global::Google.Protobuf.WellKnownTypes.ListValue(); + if (kindCase_ == KindOneofCase.ListValue) { + subBuilder.MergeFrom(ListValue); + } + input.ReadMessage(subBuilder); + ListValue = subBuilder; + break; + } + } + } + } + #endif + } /// @@ -561,7 +683,11 @@ public void MergeFrom(pb::CodedInputStream input) { /// /// The JSON representation for `ListValue` is JSON array. /// - public sealed partial class ListValue : pb::IMessage { + public sealed partial class ListValue : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ListValue()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -648,6 +774,17 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + values_.WriteTo(ref output, _repeated_values_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -683,6 +820,25 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + values_.AddEntriesFrom(ref input, _repeated_values_codec); + break; + } + } + } + } + #endif + } #endregion diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs index 12f4812af37f..27a9c960fe5f 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs @@ -123,7 +123,11 @@ static TimestampReflection() { /// http://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D /// ) to obtain a formatter capable of generating timestamps in this format. /// - public sealed partial class Timestamp : pb::IMessage { + public sealed partial class Timestamp : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Timestamp()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -240,6 +244,24 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Seconds != 0L) { + output.WriteRawTag(8); + output.WriteInt64(Seconds); + } + if (Nanos != 0) { + output.WriteRawTag(16); + output.WriteInt32(Nanos); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -289,6 +311,29 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Seconds = input.ReadInt64(); + break; + } + case 16: { + Nanos = input.ReadInt32(); + break; + } + } + } + } + #endif + } #endregion diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Type.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Type.cs index bfd4b8ec8221..4e6ce45ebf45 100644 --- a/csharp/src/Google.Protobuf/WellKnownTypes/Type.cs +++ b/csharp/src/Google.Protobuf/WellKnownTypes/Type.cs @@ -94,7 +94,11 @@ public enum Syntax { /// /// A protocol buffer message type. /// - public sealed partial class Type : pb::IMessage { + public sealed partial class Type : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Type()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -278,6 +282,31 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Name.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Name); + } + fields_.WriteTo(ref output, _repeated_fields_codec); + oneofs_.WriteTo(ref output, _repeated_oneofs_codec); + options_.WriteTo(ref output, _repeated_options_codec); + if (sourceContext_ != null) { + output.WriteRawTag(42); + output.WriteMessage(SourceContext); + } + if (Syntax != global::Google.Protobuf.WellKnownTypes.Syntax.Proto2) { + output.WriteRawTag(48); + output.WriteEnum((int) Syntax); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -361,12 +390,58 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + fields_.AddEntriesFrom(ref input, _repeated_fields_codec); + break; + } + case 26: { + oneofs_.AddEntriesFrom(ref input, _repeated_oneofs_codec); + break; + } + case 34: { + options_.AddEntriesFrom(ref input, _repeated_options_codec); + break; + } + case 42: { + if (sourceContext_ == null) { + SourceContext = new global::Google.Protobuf.WellKnownTypes.SourceContext(); + } + input.ReadMessage(SourceContext); + break; + } + case 48: { + Syntax = (global::Google.Protobuf.WellKnownTypes.Syntax) input.ReadEnum(); + break; + } + } + } + } + #endif + } /// /// A single field of a message type. /// - public sealed partial class Field : pb::IMessage { + public sealed partial class Field : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Field()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -644,6 +719,53 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Kind != global::Google.Protobuf.WellKnownTypes.Field.Types.Kind.TypeUnknown) { + output.WriteRawTag(8); + output.WriteEnum((int) Kind); + } + if (Cardinality != global::Google.Protobuf.WellKnownTypes.Field.Types.Cardinality.Unknown) { + output.WriteRawTag(16); + output.WriteEnum((int) Cardinality); + } + if (Number != 0) { + output.WriteRawTag(24); + output.WriteInt32(Number); + } + if (Name.Length != 0) { + output.WriteRawTag(34); + output.WriteString(Name); + } + if (TypeUrl.Length != 0) { + output.WriteRawTag(50); + output.WriteString(TypeUrl); + } + if (OneofIndex != 0) { + output.WriteRawTag(56); + output.WriteInt32(OneofIndex); + } + if (Packed != false) { + output.WriteRawTag(64); + output.WriteBool(Packed); + } + options_.WriteTo(ref output, _repeated_options_codec); + if (JsonName.Length != 0) { + output.WriteRawTag(82); + output.WriteString(JsonName); + } + if (DefaultValue.Length != 0) { + output.WriteRawTag(90); + output.WriteString(DefaultValue); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -769,6 +891,61 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Kind = (global::Google.Protobuf.WellKnownTypes.Field.Types.Kind) input.ReadEnum(); + break; + } + case 16: { + Cardinality = (global::Google.Protobuf.WellKnownTypes.Field.Types.Cardinality) input.ReadEnum(); + break; + } + case 24: { + Number = input.ReadInt32(); + break; + } + case 34: { + Name = input.ReadString(); + break; + } + case 50: { + TypeUrl = input.ReadString(); + break; + } + case 56: { + OneofIndex = input.ReadInt32(); + break; + } + case 64: { + Packed = input.ReadBool(); + break; + } + case 74: { + options_.AddEntriesFrom(ref input, _repeated_options_codec); + break; + } + case 82: { + JsonName = input.ReadString(); + break; + } + case 90: { + DefaultValue = input.ReadString(); + break; + } + } + } + } + #endif + #region Nested types /// Container for nested types declared in the Field message type. [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -885,7 +1062,11 @@ public enum Cardinality { /// /// Enum type definition. /// - public sealed partial class Enum : pb::IMessage { + public sealed partial class Enum : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Enum()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -1052,6 +1233,30 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Name.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Name); + } + enumvalue_.WriteTo(ref output, _repeated_enumvalue_codec); + options_.WriteTo(ref output, _repeated_options_codec); + if (sourceContext_ != null) { + output.WriteRawTag(34); + output.WriteMessage(SourceContext); + } + if (Syntax != global::Google.Protobuf.WellKnownTypes.Syntax.Proto2) { + output.WriteRawTag(40); + output.WriteEnum((int) Syntax); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -1129,12 +1334,54 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 18: { + enumvalue_.AddEntriesFrom(ref input, _repeated_enumvalue_codec); + break; + } + case 26: { + options_.AddEntriesFrom(ref input, _repeated_options_codec); + break; + } + case 34: { + if (sourceContext_ == null) { + SourceContext = new global::Google.Protobuf.WellKnownTypes.SourceContext(); + } + input.ReadMessage(SourceContext); + break; + } + case 40: { + Syntax = (global::Google.Protobuf.WellKnownTypes.Syntax) input.ReadEnum(); + break; + } + } + } + } + #endif + } /// /// Enum value definition. /// - public sealed partial class EnumValue : pb::IMessage { + public sealed partial class EnumValue : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new EnumValue()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -1263,6 +1510,25 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Name.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Name); + } + if (Number != 0) { + output.WriteRawTag(16); + output.WriteInt32(Number); + } + options_.WriteTo(ref output, _repeated_options_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -1318,13 +1584,44 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Name = input.ReadString(); + break; + } + case 16: { + Number = input.ReadInt32(); + break; + } + case 26: { + options_.AddEntriesFrom(ref input, _repeated_options_codec); + break; + } + } + } + } + #endif + } /// /// A protocol buffer option, which can be attached to a message, field, /// enumeration, etc. /// - public sealed partial class Option : pb::IMessage - public sealed partial class DoubleValue : pb::IMessage { + public sealed partial class DoubleValue : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new DoubleValue()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -148,6 +152,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Value != 0D) { + output.WriteRawTag(9); + output.WriteDouble(Value); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -187,6 +205,25 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 9: { + Value = input.ReadDouble(); + break; + } + } + } + } + #endif + } /// @@ -194,7 +231,11 @@ public void MergeFrom(pb::CodedInputStream input) { /// /// The JSON representation for `FloatValue` is JSON number. /// - public sealed partial class FloatValue : pb::IMessage { + public sealed partial class FloatValue : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new FloatValue()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -285,6 +326,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Value != 0F) { + output.WriteRawTag(13); + output.WriteFloat(Value); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -324,6 +379,25 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 13: { + Value = input.ReadFloat(); + break; + } + } + } + } + #endif + } /// @@ -331,7 +405,11 @@ public void MergeFrom(pb::CodedInputStream input) { /// /// The JSON representation for `Int64Value` is JSON string. /// - public sealed partial class Int64Value : pb::IMessage { + public sealed partial class Int64Value : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Int64Value()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -422,6 +500,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Value != 0L) { + output.WriteRawTag(8); + output.WriteInt64(Value); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -461,6 +553,25 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Value = input.ReadInt64(); + break; + } + } + } + } + #endif + } /// @@ -468,7 +579,11 @@ public void MergeFrom(pb::CodedInputStream input) { /// /// The JSON representation for `UInt64Value` is JSON string. /// - public sealed partial class UInt64Value : pb::IMessage { + public sealed partial class UInt64Value : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new UInt64Value()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -559,6 +674,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Value != 0UL) { + output.WriteRawTag(8); + output.WriteUInt64(Value); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -598,6 +727,25 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Value = input.ReadUInt64(); + break; + } + } + } + } + #endif + } /// @@ -605,7 +753,11 @@ public void MergeFrom(pb::CodedInputStream input) { /// /// The JSON representation for `Int32Value` is JSON number. /// - public sealed partial class Int32Value : pb::IMessage { + public sealed partial class Int32Value : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Int32Value()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -696,6 +848,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Value != 0) { + output.WriteRawTag(8); + output.WriteInt32(Value); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -735,6 +901,25 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Value = input.ReadInt32(); + break; + } + } + } + } + #endif + } /// @@ -742,7 +927,11 @@ public void MergeFrom(pb::CodedInputStream input) { /// /// The JSON representation for `UInt32Value` is JSON number. /// - public sealed partial class UInt32Value : pb::IMessage { + public sealed partial class UInt32Value : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new UInt32Value()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -833,6 +1022,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Value != 0) { + output.WriteRawTag(8); + output.WriteUInt32(Value); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -872,6 +1075,25 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Value = input.ReadUInt32(); + break; + } + } + } + } + #endif + } /// @@ -879,7 +1101,11 @@ public void MergeFrom(pb::CodedInputStream input) { /// /// The JSON representation for `BoolValue` is JSON `true` and `false`. /// - public sealed partial class BoolValue : pb::IMessage { + public sealed partial class BoolValue : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new BoolValue()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -970,6 +1196,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Value != false) { + output.WriteRawTag(8); + output.WriteBool(Value); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -1009,6 +1249,25 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Value = input.ReadBool(); + break; + } + } + } + } + #endif + } /// @@ -1016,7 +1275,11 @@ public void MergeFrom(pb::CodedInputStream input) { /// /// The JSON representation for `StringValue` is JSON string. /// - public sealed partial class StringValue : pb::IMessage { + public sealed partial class StringValue : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new StringValue()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -1107,6 +1370,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Value.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Value); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -1146,6 +1423,25 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Value = input.ReadString(); + break; + } + } + } + } + #endif + } /// @@ -1153,7 +1449,11 @@ public void MergeFrom(pb::CodedInputStream input) { /// /// The JSON representation for `BytesValue` is JSON string. /// - public sealed partial class BytesValue : pb::IMessage { + public sealed partial class BytesValue : pb::IMessage + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + , pb::IBufferMessage + #endif + { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new BytesValue()); private pb::UnknownFieldSet _unknownFields; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -1244,6 +1544,20 @@ public void WriteTo(pb::CodedOutputStream output) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(ref pb::CodedOutputWriter output) { + if (Value.Length != 0) { + output.WriteRawTag(10); + output.WriteBytes(Value); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize() { int size = 0; @@ -1283,6 +1597,25 @@ public void MergeFrom(pb::CodedInputStream input) { } } + + #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ref pb::CodedInputReader input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 10: { + Value = input.ReadBytes(); + break; + } + } + } + } + #endif + } #endregion diff --git a/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc b/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc index 978fdf02b6fb..200ce75d4c0a 100644 --- a/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc +++ b/src/google/protobuf/compiler/csharp/csharp_bootstrap_unittest.cc @@ -141,7 +141,7 @@ TEST(CsharpBootstrapTest, GeneratedCsharpDescriptorMatches) { Importer importer(&source_tree, &error_collector); GenerateAndTest generate_test; - generate_test.SetParameter("base_namespace=Google.Protobuf"); + generate_test.SetParameter("base_namespace=Google.Protobuf,use_buffer_serialization"); source_tree.MapPath("", TestSourceDir()); generate_test.Run(importer.Import("google/protobuf/descriptor.proto"), "Reflection/Descriptor.cs", @@ -177,7 +177,7 @@ TEST(CsharpBootstrapTest, GeneratedCsharpDescriptorMatches) { "WellKnownTypes/Wrappers.cs", "../csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs"); - generate_test.SetParameter(""); + generate_test.SetParameter("use_buffer_serialization"); source_tree.MapPath("", TestSourceDir() + "/../conformance"); generate_test.Run(importer.Import("conformance.proto"), "Conformance.cs", diff --git a/src/google/protobuf/compiler/csharp/csharp_field_base.cc b/src/google/protobuf/compiler/csharp/csharp_field_base.cc index 454f4cb14413..f315560906d2 100644 --- a/src/google/protobuf/compiler/csharp/csharp_field_base.cc +++ b/src/google/protobuf/compiler/csharp/csharp_field_base.cc @@ -157,10 +157,18 @@ void FieldGeneratorBase::GenerateCodecCode(io::Printer* printer) { } void FieldGeneratorBase::GenerateExtensionCode(io::Printer* printer) { - // No-op: only message fields, enum fields, primitives, + // No-op: only message fields, enum fields, primitives, // and repeated fields need this default is to not generate any code } +void FieldGeneratorBase::GenerateBufferParsingCode(io::Printer* printer) { + GenerateParsingCode(printer); +} + +void FieldGeneratorBase::GenerateBufferSerializationCode(io::Printer* printer) { + GenerateSerializationCode(printer); +} + void FieldGeneratorBase::AddDeprecatedFlag(io::Printer* printer) { if (descriptor_->options().deprecated()) { printer->Print("[global::System.ObsoleteAttribute]\n"); diff --git a/src/google/protobuf/compiler/csharp/csharp_field_base.h b/src/google/protobuf/compiler/csharp/csharp_field_base.h index 594461da7845..8a28f45acebf 100644 --- a/src/google/protobuf/compiler/csharp/csharp_field_base.h +++ b/src/google/protobuf/compiler/csharp/csharp_field_base.h @@ -61,7 +61,9 @@ class FieldGeneratorBase : public SourceGeneratorBase { virtual void GenerateMembers(io::Printer* printer) = 0; virtual void GenerateMergingCode(io::Printer* printer) = 0; virtual void GenerateParsingCode(io::Printer* printer) = 0; + virtual void GenerateBufferParsingCode(io::Printer* printer); virtual void GenerateSerializationCode(io::Printer* printer) = 0; + virtual void GenerateBufferSerializationCode(io::Printer* printer); virtual void GenerateSerializedSizeCode(io::Printer* printer) = 0; virtual void WriteHash(io::Printer* printer) = 0; diff --git a/src/google/protobuf/compiler/csharp/csharp_generator.cc b/src/google/protobuf/compiler/csharp/csharp_generator.cc index b335522032f3..fe1e53c5cce5 100644 --- a/src/google/protobuf/compiler/csharp/csharp_generator.cc +++ b/src/google/protobuf/compiler/csharp/csharp_generator.cc @@ -75,6 +75,8 @@ bool Generator::Generate( cli_options.internal_access = true; } else if (options[i].first == "serializable") { cli_options.serializable = true; + } else if (options[i].first == "use_buffer_serialization") { + cli_options.use_buffer_serialization = true; } else { *error = "Unknown generator option: " + options[i].first; return false; diff --git a/src/google/protobuf/compiler/csharp/csharp_map_field.cc b/src/google/protobuf/compiler/csharp/csharp_map_field.cc index f3f09ea4546b..47aece117a10 100644 --- a/src/google/protobuf/compiler/csharp/csharp_map_field.cc +++ b/src/google/protobuf/compiler/csharp/csharp_map_field.cc @@ -40,6 +40,7 @@ #include #include #include +#include namespace google { namespace protobuf { @@ -99,12 +100,24 @@ void MapFieldGenerator::GenerateParsingCode(io::Printer* printer) { "$name$_.AddEntriesFrom(input, _map_$name$_codec);\n"); } +void MapFieldGenerator::GenerateBufferParsingCode(io::Printer* printer) { + printer->Print( + variables_, + "$name$_.AddEntriesFrom(ref input, _map_$name$_codec);\n"); +} + void MapFieldGenerator::GenerateSerializationCode(io::Printer* printer) { printer->Print( variables_, "$name$_.WriteTo(output, _map_$name$_codec);\n"); } +void MapFieldGenerator::GenerateBufferSerializationCode(io::Printer* printer) { + printer->Print( + variables_, + "$name$_.WriteTo(ref output, _map_$name$_codec);\n"); +} + void MapFieldGenerator::GenerateSerializedSizeCode(io::Printer* printer) { printer->Print( variables_, diff --git a/src/google/protobuf/compiler/csharp/csharp_map_field.h b/src/google/protobuf/compiler/csharp/csharp_map_field.h index b920b9f2257b..380703c489b6 100644 --- a/src/google/protobuf/compiler/csharp/csharp_map_field.h +++ b/src/google/protobuf/compiler/csharp/csharp_map_field.h @@ -56,7 +56,9 @@ class MapFieldGenerator : public FieldGeneratorBase { virtual void GenerateMembers(io::Printer* printer); virtual void GenerateMergingCode(io::Printer* printer); virtual void GenerateParsingCode(io::Printer* printer); + virtual void GenerateBufferParsingCode(io::Printer* printer); virtual void GenerateSerializationCode(io::Printer* printer); + virtual void GenerateBufferSerializationCode(io::Printer* printer); virtual void GenerateSerializedSizeCode(io::Printer* printer); virtual void WriteHash(io::Printer* printer); diff --git a/src/google/protobuf/compiler/csharp/csharp_message.cc b/src/google/protobuf/compiler/csharp/csharp_message.cc index 67f28929196c..ec20c8c11fa4 100644 --- a/src/google/protobuf/compiler/csharp/csharp_message.cc +++ b/src/google/protobuf/compiler/csharp/csharp_message.cc @@ -132,6 +132,20 @@ void MessageGenerator::Generate(io::Printer* printer) { else { printer->Print(vars, "pb::IMessage<$class_name$>"); } + + if (this->options()->use_buffer_serialization) + { + printer->Print( + "\n" + "#if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION\n"); + printer->Indent(); + printer->Print( + ", pb::IBufferMessage\n"); + printer->Outdent(); + printer->Print( + "#endif\n"); + } + printer->Print(" {\n"); printer->Indent(); @@ -514,63 +528,100 @@ void MessageGenerator::GenerateFrameworkMethods(io::Printer* printer) { } void MessageGenerator::GenerateMessageSerializationMethods(io::Printer* printer) { + GenerateWriteToOutputMethod(printer, false); + if (this->options()->use_buffer_serialization) { + GenerateWriteToOutputMethod(printer, true); + } + WriteGeneratedCodeAttributes(printer); printer->Print( - "public void WriteTo(pb::CodedOutputStream output) {\n"); + "public int CalculateSize() {\n"); printer->Indent(); - - // Serialize all the fields - for (int i = 0; i < fields_by_number().size(); i++) { + printer->Print("int size = 0;\n"); + for (int i = 0; i < descriptor_->field_count(); i++) { std::unique_ptr generator( - CreateFieldGeneratorInternal(fields_by_number()[i])); - generator->GenerateSerializationCode(printer); + CreateFieldGeneratorInternal(descriptor_->field(i))); + generator->GenerateSerializedSizeCode(printer); } if (has_extension_ranges_) { - // Serialize extensions printer->Print( "if (_extensions != null) {\n" - " _extensions.WriteTo(output);\n" + " size += _extensions.CalculateSize();\n" "}\n"); } - // Serialize unknown fields printer->Print( "if (_unknownFields != null) {\n" - " _unknownFields.WriteTo(output);\n" + " size += _unknownFields.CalculateSize();\n" "}\n"); - // TODO(jonskeet): Memoize size of frozen messages? + printer->Print("return size;\n"); printer->Outdent(); - printer->Print( - "}\n" - "\n"); + printer->Print("}\n\n"); +} + +void MessageGenerator::GenerateWriteToOutputMethod(io::Printer* printer, bool use_buffer_serialization) { + if (use_buffer_serialization) { + printer->Print("\n#if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION\n"); + } WriteGeneratedCodeAttributes(printer); - printer->Print( - "public int CalculateSize() {\n"); + if (use_buffer_serialization) { + printer->Print( + "public void WriteTo(ref pb::CodedOutputWriter output) {\n"); + } else { + printer->Print( + "public void WriteTo(pb::CodedOutputStream output) {\n"); + } printer->Indent(); - printer->Print("int size = 0;\n"); - for (int i = 0; i < descriptor_->field_count(); i++) { + + // Serialize all the fields + for (int i = 0; i < fields_by_number().size(); i++) { std::unique_ptr generator( - CreateFieldGeneratorInternal(descriptor_->field(i))); - generator->GenerateSerializedSizeCode(printer); + CreateFieldGeneratorInternal(fields_by_number()[i])); + if (use_buffer_serialization) { + generator->GenerateBufferSerializationCode(printer); + } else { + generator->GenerateSerializationCode(printer); + } } if (has_extension_ranges_) { + // Serialize extensions printer->Print( - "if (_extensions != null) {\n" - " size += _extensions.CalculateSize();\n" - "}\n"); + "if (_extensions != null) {\n"); + if (use_buffer_serialization) { + printer->Print( + " _extensions.WriteTo(ref output);\n"); + } else { + printer->Print( + " _extensions.WriteTo(output);\n"); + } + printer->Print( + "}\n"); } + // Serialize unknown fields printer->Print( - "if (_unknownFields != null) {\n" - " size += _unknownFields.CalculateSize();\n" - "}\n"); + "if (_unknownFields != null) {\n"); + if (use_buffer_serialization) { + printer->Print( + " _unknownFields.WriteTo(ref output);\n"); + } else { + printer->Print( + " _unknownFields.WriteTo(output);\n"); + } + printer->Print( + "}\n"); - printer->Print("return size;\n"); + // TODO(jonskeet): Memoize size of frozen messages? printer->Outdent(); - printer->Print("}\n\n"); + printer->Print( + "}\n"); + if (use_buffer_serialization) { + printer->Print("#endif\n"); + } + printer->Print("\n"); } void MessageGenerator::GenerateMergingMethods(io::Printer* printer) { @@ -622,17 +673,28 @@ void MessageGenerator::GenerateMergingMethods(io::Printer* printer) { if (has_extension_ranges_) { printer->Print("pb::ExtensionSet.MergeFrom(ref _extensions, other._extensions);\n"); } - // Merge unknown fields. printer->Print( "_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);\n"); - printer->Outdent(); printer->Print("}\n\n"); + GenerateMergeFromInput(printer, false); + if (this->options()->use_buffer_serialization) { + GenerateMergeFromInput(printer, true); + } +} +void MessageGenerator::GenerateMergeFromInput(io::Printer* printer, bool use_buffer_serialization) { + if (use_buffer_serialization) { + printer->Print("\n#if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION\n"); + } WriteGeneratedCodeAttributes(printer); - printer->Print("public void MergeFrom(pb::CodedInputStream input) {\n"); + if (use_buffer_serialization) { + printer->Print("public void MergeFrom(ref pb::CodedInputReader input) {\n"); + } else { + printer->Print("public void MergeFrom(pb::CodedInputStream input) {\n"); + } printer->Indent(); printer->Print( "uint tag;\n" @@ -648,15 +710,30 @@ void MessageGenerator::GenerateMergingMethods(io::Printer* printer) { } if (has_extension_ranges_) { printer->Print( - "default:\n" + "default:\n"); + if (use_buffer_serialization) { + printer->Print( + " if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, ref input)) {\n" + " _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);\n"); + } else { + printer->Print( " if (!pb::ExtensionSet.TryMergeFieldFrom(ref _extensions, input)) {\n" - " _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);\n" + " _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);\n"); + } + printer->Print( " }\n" " break;\n"); } else { printer->Print( - "default:\n" - " _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);\n" + "default:\n"); + if (use_buffer_serialization) { + printer->Print( + " _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);\n"); + } else { + printer->Print( + " _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);\n"); + } + printer->Print( " break;\n"); } for (int i = 0; i < fields_by_number().size(); i++) { @@ -683,7 +760,11 @@ void MessageGenerator::GenerateMergingMethods(io::Printer* printer) { printer->Indent(); std::unique_ptr generator( CreateFieldGeneratorInternal(field)); - generator->GenerateParsingCode(printer); + if (use_buffer_serialization) { + generator->GenerateBufferParsingCode(printer); + } else { + generator->GenerateParsingCode(printer); + } printer->Print("break;\n"); printer->Outdent(); printer->Print("}\n"); @@ -693,7 +774,11 @@ void MessageGenerator::GenerateMergingMethods(io::Printer* printer) { printer->Outdent(); printer->Print("}\n"); // while printer->Outdent(); - printer->Print("}\n\n"); // method + printer->Print("}\n"); // method + if (use_buffer_serialization) { + printer->Print("#endif\n"); + } + printer->Print("\n"); } // it's a waste of space to track presence for all values, so we only track them if they're not nullable diff --git a/src/google/protobuf/compiler/csharp/csharp_message.h b/src/google/protobuf/compiler/csharp/csharp_message.h index 5642dc88120c..b2e4ecf59998 100644 --- a/src/google/protobuf/compiler/csharp/csharp_message.h +++ b/src/google/protobuf/compiler/csharp/csharp_message.h @@ -77,6 +77,9 @@ class MessageGenerator : public SourceGeneratorBase { void AddDeprecatedFlag(io::Printer* printer); void AddSerializableAttribute(io::Printer* printer); + void GenerateWriteToOutputMethod(io::Printer* printer, bool use_buffer_serialization); + void GenerateMergeFromInput(io::Printer* printer, bool use_buffer_serialization); + std::string class_name(); std::string full_class_name(); diff --git a/src/google/protobuf/compiler/csharp/csharp_options.h b/src/google/protobuf/compiler/csharp/csharp_options.h index 42ff6d866277..57690260c929 100644 --- a/src/google/protobuf/compiler/csharp/csharp_options.h +++ b/src/google/protobuf/compiler/csharp/csharp_options.h @@ -45,7 +45,8 @@ struct Options { base_namespace(""), base_namespace_specified(false), internal_access(false), - serializable(false) { + serializable(false), + use_buffer_serialization(false) { } // Extension of the generated file. Defaults to ".cs" std::string file_extension; @@ -71,6 +72,10 @@ struct Options { // Whether the generated classes should have a global::System.Serializable attribute added // Defaults to false bool serializable; + // Whether the generated classes should use CodedInputReader and CodedOutputWriter + // Defaults to false + // Note: experimental API that can change or be removed without any prior notice. + bool use_buffer_serialization; }; } // namespace csharp diff --git a/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc b/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc index 73309a7edd1e..6fb00462f32f 100644 --- a/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc +++ b/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.cc @@ -39,6 +39,7 @@ #include #include +#include #include namespace google { @@ -83,12 +84,24 @@ void RepeatedEnumFieldGenerator::GenerateParsingCode(io::Printer* printer) { "$name$_.AddEntriesFrom(input, _repeated_$name$_codec);\n"); } +void RepeatedEnumFieldGenerator::GenerateBufferParsingCode(io::Printer* printer) { + printer->Print( + variables_, + "$name$_.AddEntriesFrom(ref input, _repeated_$name$_codec);\n"); +} + void RepeatedEnumFieldGenerator::GenerateSerializationCode(io::Printer* printer) { printer->Print( variables_, "$name$_.WriteTo(output, _repeated_$name$_codec);\n"); } +void RepeatedEnumFieldGenerator::GenerateBufferSerializationCode(io::Printer* printer) { + printer->Print( + variables_, + "$name$_.WriteTo(ref output, _repeated_$name$_codec);\n"); +} + void RepeatedEnumFieldGenerator::GenerateSerializedSizeCode(io::Printer* printer) { printer->Print( variables_, diff --git a/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.h b/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.h index c7a632a17d4f..f06479b20fc8 100644 --- a/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.h +++ b/src/google/protobuf/compiler/csharp/csharp_repeated_enum_field.h @@ -59,7 +59,9 @@ class RepeatedEnumFieldGenerator : public FieldGeneratorBase { virtual void GenerateMembers(io::Printer* printer); virtual void GenerateMergingCode(io::Printer* printer); virtual void GenerateParsingCode(io::Printer* printer); + virtual void GenerateBufferParsingCode(io::Printer* printer); virtual void GenerateSerializationCode(io::Printer* printer); + virtual void GenerateBufferSerializationCode(io::Printer* printer); virtual void GenerateSerializedSizeCode(io::Printer* printer); virtual void GenerateExtensionCode(io::Printer* printer); diff --git a/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc b/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc index 4b4b37de1bb4..069f1dc58cd9 100644 --- a/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc +++ b/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.cc @@ -40,6 +40,7 @@ #include #include #include +#include #include namespace google { @@ -98,12 +99,24 @@ void RepeatedMessageFieldGenerator::GenerateParsingCode(io::Printer* printer) { "$name$_.AddEntriesFrom(input, _repeated_$name$_codec);\n"); } +void RepeatedMessageFieldGenerator::GenerateBufferParsingCode(io::Printer* printer) { + printer->Print( + variables_, + "$name$_.AddEntriesFrom(ref input, _repeated_$name$_codec);\n"); +} + void RepeatedMessageFieldGenerator::GenerateSerializationCode(io::Printer* printer) { printer->Print( variables_, "$name$_.WriteTo(output, _repeated_$name$_codec);\n"); } +void RepeatedMessageFieldGenerator::GenerateBufferSerializationCode(io::Printer* printer) { + printer->Print( + variables_, + "$name$_.WriteTo(ref output, _repeated_$name$_codec);\n"); +} + void RepeatedMessageFieldGenerator::GenerateSerializedSizeCode(io::Printer* printer) { printer->Print( variables_, diff --git a/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.h b/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.h index 74f6874df263..d9ade71aebc5 100644 --- a/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.h +++ b/src/google/protobuf/compiler/csharp/csharp_repeated_message_field.h @@ -59,7 +59,9 @@ class RepeatedMessageFieldGenerator : public FieldGeneratorBase { virtual void GenerateMembers(io::Printer* printer); virtual void GenerateMergingCode(io::Printer* printer); virtual void GenerateParsingCode(io::Printer* printer); + virtual void GenerateBufferParsingCode(io::Printer* printer); virtual void GenerateSerializationCode(io::Printer* printer); + virtual void GenerateBufferSerializationCode(io::Printer* printer); virtual void GenerateSerializedSizeCode(io::Printer* printer); virtual void GenerateExtensionCode(io::Printer* printer); diff --git a/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc b/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc index c1444ea124aa..e757f5d27db1 100644 --- a/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc +++ b/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.cc @@ -39,6 +39,7 @@ #include #include +#include #include namespace google { @@ -83,12 +84,24 @@ void RepeatedPrimitiveFieldGenerator::GenerateParsingCode(io::Printer* printer) "$name$_.AddEntriesFrom(input, _repeated_$name$_codec);\n"); } +void RepeatedPrimitiveFieldGenerator::GenerateBufferParsingCode(io::Printer* printer) { + printer->Print( + variables_, + "$name$_.AddEntriesFrom(ref input, _repeated_$name$_codec);\n"); +} + void RepeatedPrimitiveFieldGenerator::GenerateSerializationCode(io::Printer* printer) { printer->Print( variables_, "$name$_.WriteTo(output, _repeated_$name$_codec);\n"); } +void RepeatedPrimitiveFieldGenerator::GenerateBufferSerializationCode(io::Printer* printer) { + printer->Print( + variables_, + "$name$_.WriteTo(ref output, _repeated_$name$_codec);\n"); +} + void RepeatedPrimitiveFieldGenerator::GenerateSerializedSizeCode(io::Printer* printer) { printer->Print( variables_, diff --git a/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h b/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h index 2a3be4816809..f25fcd1734fe 100644 --- a/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h +++ b/src/google/protobuf/compiler/csharp/csharp_repeated_primitive_field.h @@ -55,7 +55,9 @@ class RepeatedPrimitiveFieldGenerator : public FieldGeneratorBase { virtual void GenerateMembers(io::Printer* printer); virtual void GenerateMergingCode(io::Printer* printer); virtual void GenerateParsingCode(io::Printer* printer); + virtual void GenerateBufferParsingCode(io::Printer* printer); virtual void GenerateSerializationCode(io::Printer* printer); + virtual void GenerateBufferSerializationCode(io::Printer* printer); virtual void GenerateSerializedSizeCode(io::Printer* printer); virtual void GenerateExtensionCode(io::Printer* printer); diff --git a/src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc b/src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc index add20ab9fe63..95d3d465fdb2 100644 --- a/src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc +++ b/src/google/protobuf/compiler/csharp/csharp_wrapper_field.cc @@ -122,6 +122,15 @@ void WrapperFieldGenerator::GenerateParsingCode(io::Printer* printer) { "}\n"); } +void WrapperFieldGenerator::GenerateBufferParsingCode(io::Printer* printer) { + printer->Print( + variables_, + "$type_name$ value = _single_$name$_codec.Read(ref input);\n" + "if ($has_not_property_check$ || value != $default_value$) {\n" + " $property_name$ = value;\n" + "}\n"); +} + void WrapperFieldGenerator::GenerateSerializationCode(io::Printer* printer) { printer->Print( variables_, @@ -130,6 +139,14 @@ void WrapperFieldGenerator::GenerateSerializationCode(io::Printer* printer) { "}\n"); } +void WrapperFieldGenerator::GenerateBufferSerializationCode(io::Printer* printer) { + printer->Print( + variables_, + "if ($has_property_check$) {\n" + " _single_$name$_codec.WriteTagAndValue(ref output, $property_name$);\n" + "}\n"); +} + void WrapperFieldGenerator::GenerateSerializedSizeCode(io::Printer* printer) { printer->Print( variables_, @@ -253,6 +270,12 @@ void WrapperOneofFieldGenerator::GenerateParsingCode(io::Printer* printer) { "$property_name$ = _oneof_$name$_codec.Read(input);\n"); } +void WrapperOneofFieldGenerator::GenerateBufferParsingCode(io::Printer* printer) { + printer->Print( + variables_, + "$property_name$ = _oneof_$name$_codec.Read(ref input);\n"); +} + void WrapperOneofFieldGenerator::GenerateSerializationCode(io::Printer* printer) { // TODO: I suspect this is wrong... printer->Print( @@ -262,6 +285,15 @@ void WrapperOneofFieldGenerator::GenerateSerializationCode(io::Printer* printer) "}\n"); } +void WrapperOneofFieldGenerator::GenerateBufferSerializationCode(io::Printer* printer) { + // TODO: I suspect this is wrong... + printer->Print( + variables_, + "if ($has_property_check$) {\n" + " _oneof_$name$_codec.WriteTagAndValue(ref output, ($type_name$) $oneof_name$_);\n" + "}\n"); +} + void WrapperOneofFieldGenerator::GenerateSerializedSizeCode(io::Printer* printer) { // TODO: I suspect this is wrong... printer->Print( diff --git a/src/google/protobuf/compiler/csharp/csharp_wrapper_field.h b/src/google/protobuf/compiler/csharp/csharp_wrapper_field.h index 394e27de595d..33614d2c91dd 100644 --- a/src/google/protobuf/compiler/csharp/csharp_wrapper_field.h +++ b/src/google/protobuf/compiler/csharp/csharp_wrapper_field.h @@ -58,7 +58,9 @@ class WrapperFieldGenerator : public FieldGeneratorBase { virtual void GenerateMembers(io::Printer* printer); virtual void GenerateMergingCode(io::Printer* printer); virtual void GenerateParsingCode(io::Printer* printer); + virtual void GenerateBufferParsingCode(io::Printer* printer); virtual void GenerateSerializationCode(io::Printer* printer); + virtual void GenerateBufferSerializationCode(io::Printer* printer); virtual void GenerateSerializedSizeCode(io::Printer* printer); virtual void GenerateExtensionCode(io::Printer* printer); @@ -83,7 +85,9 @@ class WrapperOneofFieldGenerator : public WrapperFieldGenerator { virtual void GenerateMembers(io::Printer* printer); virtual void GenerateMergingCode(io::Printer* printer); virtual void GenerateParsingCode(io::Printer* printer); + virtual void GenerateBufferParsingCode(io::Printer* printer); virtual void GenerateSerializationCode(io::Printer* printer); + virtual void GenerateBufferSerializationCode(io::Printer* printer); virtual void GenerateSerializedSizeCode(io::Printer* printer); }; From 27f70b3baba7a7d2ead5c72e08bb7c2bfca320d0 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Tue, 21 Jan 2020 18:04:18 +1300 Subject: [PATCH 02/14] Write variable data in segments, PR feedback --- .../Google.Protobuf.Benchmarks.csproj | 1 + .../SerializationBenchmark.cs | 25 +++- .../Buffers/MaxSizeHintBufferWriter.cs | 14 +- .../CodedOutputStreamTest.cs | 11 ++ .../CodedOutputTestBase.cs | 26 ++++ .../CodedOutputWriterTest.cs | 14 +- .../Google.Protobuf.Test/JsonTokenizerTest.cs | 1 + .../src/Google.Protobuf/CodedOutputWriter.cs | 138 +++++++++++------- 8 files changed, 172 insertions(+), 58 deletions(-) diff --git a/csharp/src/Google.Protobuf.Benchmarks/Google.Protobuf.Benchmarks.csproj b/csharp/src/Google.Protobuf.Benchmarks/Google.Protobuf.Benchmarks.csproj index ea39409f0817..69b985ec97a5 100644 --- a/csharp/src/Google.Protobuf.Benchmarks/Google.Protobuf.Benchmarks.csproj +++ b/csharp/src/Google.Protobuf.Benchmarks/Google.Protobuf.Benchmarks.csproj @@ -9,6 +9,7 @@ + diff --git a/csharp/src/Google.Protobuf.Benchmarks/SerializationBenchmark.cs b/csharp/src/Google.Protobuf.Benchmarks/SerializationBenchmark.cs index 61edaf7c0fa4..b14b751054ca 100644 --- a/csharp/src/Google.Protobuf.Benchmarks/SerializationBenchmark.cs +++ b/csharp/src/Google.Protobuf.Benchmarks/SerializationBenchmark.cs @@ -33,9 +33,11 @@ using BenchmarkDotNet.Attributes; using Benchmarks; using Google.Protobuf.Buffers; +using System; using System.Buffers; using System.Collections.Generic; using System.IO; +using System.IO.Pipelines; using System.Linq; namespace Google.Protobuf.Benchmarks @@ -96,6 +98,15 @@ public void WriteToBufferWriter() } } + [Benchmark] + public void WriteToPipeWriter() + { + foreach (var subTest in subTests) + { + subTest.WriteToPipeWriter(); + } + } + [Benchmark] public void ToByteArray() { @@ -140,6 +151,7 @@ private class SubTest private readonly ReadOnlySequence readOnlySequence; private readonly ByteString data; private readonly IBufferMessage message; + private readonly Pipe pipe; public SubTest(ByteString data, IBufferMessage message) { @@ -147,18 +159,27 @@ public SubTest(ByteString data, IBufferMessage message) bufferWriter = new Google.Protobuf.Buffers.ArrayBufferWriter(); sourceStream = new MemoryStream(data.ToByteArray()); readOnlySequence = new ReadOnlySequence(data.ToByteArray()); + pipe = new Pipe(); this.data = data; this.message = message; } - public void Reset() => destinationStream.Position = 0; - public void WriteToStream() { destinationStream.Position = 0; message.WriteTo(destinationStream); } + public void WriteToPipeWriter() + { + var writer = new CodedOutputWriter(pipe.Writer); + message.WriteTo(ref writer); + + pipe.Writer.Complete(); + pipe.Reader.Complete(); + pipe.Reset(); + } + public void WriteToBufferWriter() { bufferWriter.Clear(); diff --git a/csharp/src/Google.Protobuf.Test/Buffers/MaxSizeHintBufferWriter.cs b/csharp/src/Google.Protobuf.Test/Buffers/MaxSizeHintBufferWriter.cs index 5c13d8110ec5..5b2b89972d80 100644 --- a/csharp/src/Google.Protobuf.Test/Buffers/MaxSizeHintBufferWriter.cs +++ b/csharp/src/Google.Protobuf.Test/Buffers/MaxSizeHintBufferWriter.cs @@ -54,12 +54,22 @@ public void Advance(int count) public Memory GetMemory(int sizeHint = 0) { - return bufferWriter.GetMemory(Math.Min(sizeHint, maxSizeHint)); + if (sizeHint == 0) + { + sizeHint = maxSizeHint; + } + // IBufferWriter contract defines that when a size is specified then that is the minimum size returned + return bufferWriter.GetMemory(sizeHint); } public Span GetSpan(int sizeHint = 0) { - return bufferWriter.GetSpan(Math.Min(sizeHint, maxSizeHint)); + if (sizeHint == 0) + { + sizeHint = maxSizeHint; + } + // IBufferWriter contract defines that when a size is specified then that is the minimum size returned + return bufferWriter.GetSpan(sizeHint); } } } diff --git a/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs b/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs index a56b40704583..17c12e596e01 100644 --- a/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs +++ b/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs @@ -295,6 +295,17 @@ protected override void AssertWriteEnum(byte[] data, int value) Assert.AreEqual(data, rawOutput.ToArray()); } + protected override void AssertWriteBytes(ByteString value) + { + MemoryStream rawOutput = new MemoryStream(); + CodedOutputStream output = new CodedOutputStream(rawOutput); + output.WriteBytes(value); + output.Flush(); + + CodedInputStream input = new CodedInputStream(rawOutput.ToArray()); + Assert.AreEqual(value, input.ReadBytes()); + } + protected override void AssertWriteString(string value) { MemoryStream rawOutput = new MemoryStream(); diff --git a/csharp/src/Google.Protobuf.Test/CodedOutputTestBase.cs b/csharp/src/Google.Protobuf.Test/CodedOutputTestBase.cs index d18611dc2489..004c2d635fc9 100644 --- a/csharp/src/Google.Protobuf.Test/CodedOutputTestBase.cs +++ b/csharp/src/Google.Protobuf.Test/CodedOutputTestBase.cs @@ -59,6 +59,8 @@ public abstract class CodedOutputTestBase protected abstract void AssertWriteString(string value); + protected abstract void AssertWriteBytes(ByteString value); + protected abstract void AssertWriteFloat(byte[] data, float value); protected abstract void AssertWriteDouble(byte[] data, double value); @@ -189,6 +191,30 @@ public void TestNegativeEnumNoTag() AssertWriteEnum(bytes, (int)SampleEnum.NegativeValue); } + [Test] + public void WriteSmallBytes() + { + byte[] data = new byte[32]; + for (int i = 0; i < data.Length; i++) + { + data[i] = (byte)i; + } + + AssertWriteBytes(ByteString.CopyFrom(data)); + } + + [Test] + public void WriteLargeBytes() + { + byte[] data = new byte[2048]; + for (int i = 0; i < data.Length; i++) + { + data[i] = (byte)i; + } + + AssertWriteBytes(ByteString.CopyFrom(data)); + } + [Test] public void WriteAsciiSmallString() { diff --git a/csharp/src/Google.Protobuf.Test/CodedOutputWriterTest.cs b/csharp/src/Google.Protobuf.Test/CodedOutputWriterTest.cs index 55b05b515443..6dc177f5313e 100644 --- a/csharp/src/Google.Protobuf.Test/CodedOutputWriterTest.cs +++ b/csharp/src/Google.Protobuf.Test/CodedOutputWriterTest.cs @@ -218,7 +218,7 @@ protected override void AssertWriteString(string value) { ArrayBufferWriter rawOutput = new ArrayBufferWriter(1024); // Limit the max span size to force string to be written in multiple parts - CodedOutputWriter output = new CodedOutputWriter(new MaxSizeHintBufferWriter(rawOutput, 1024)); + CodedOutputWriter output = new CodedOutputWriter(new MaxSizeHintBufferWriter(rawOutput, 128)); output.WriteString(value); output.Flush(); @@ -226,6 +226,18 @@ protected override void AssertWriteString(string value) Assert.AreEqual(value, input.ReadString()); } + protected override void AssertWriteBytes(ByteString value) + { + ArrayBufferWriter rawOutput = new ArrayBufferWriter(1024); + // Limit the max span size to force bytes to be written in multiple parts + CodedOutputWriter output = new CodedOutputWriter(new MaxSizeHintBufferWriter(rawOutput, 128)); + output.WriteBytes(value); + output.Flush(); + + CodedInputReader input = new CodedInputReader(ReadOnlySequenceFactory.SegmentPerByteFactory.CreateWithContent(rawOutput.WrittenSpan.ToArray())); + Assert.AreEqual(value, input.ReadBytes()); + } + protected override void AssertWriteFloat(byte[] data, float value) { ArrayBufferWriter rawOutput = new ArrayBufferWriter(1024); diff --git a/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs b/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs index 2d8b30fd7d24..4504086d4d25 100644 --- a/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs +++ b/csharp/src/Google.Protobuf.Test/JsonTokenizerTest.cs @@ -201,6 +201,7 @@ public void NumberValue(string json, double expectedValue) [TestCase("--1")] #if !NETCOREAPP3_0 // .NET Core 3.0 returns infinity + // https://github.com/dotnet/docs/issues/14705 [TestCase("-1.7977e308")] [TestCase("1.7977e308")] #endif diff --git a/csharp/src/Google.Protobuf/CodedOutputWriter.cs b/csharp/src/Google.Protobuf/CodedOutputWriter.cs index 4b1f6f311159..d1c91ef939f5 100644 --- a/csharp/src/Google.Protobuf/CodedOutputWriter.cs +++ b/csharp/src/Google.Protobuf/CodedOutputWriter.cs @@ -201,78 +201,100 @@ public void WriteString(string value) int length = Encoding.UTF8.GetByteCount(value); WriteLength(length); - Ensure(length); - Span buffer = span.Slice(buffered); - - if (buffer.Length >= length) + if (span.Length < length + buffered) { - // Can write string to a single buffer + // String doesn't fit in the remaining buffer. Refresh buffer without specifying a size + // to get the default sized buffer + EnsureMore(); - if (length == value.Length) // Must be all ASCII... + if (span.Length < length + buffered) { - for (int i = 0; i < length; i++) - { - buffer[i] = (byte)value[i]; - } - - buffered += length; + // String doesn't fit in refreshed buffer. Write across multiple + WriteStringMultiBuffer(value); } else { - ReadOnlySpan source = value.AsSpan(); - - int bytesUsed; - - unsafe - { - fixed (char* sourceChars = &MemoryMarshal.GetReference(source)) - fixed (byte* destinationBytes = &MemoryMarshal.GetReference(buffer)) - { - bytesUsed = Encoding.UTF8.GetBytes(sourceChars, source.Length, destinationBytes, buffer.Length); - } - } - - buffered += bytesUsed; + // String now fits in refreshed buffer + WriteStringSingleBuffer(value, length); } } else { - // The destination byte array might not be large enough so multiple writes are sometimes required - if (encoder == null) + // String fits in remaining buffer space + WriteStringSingleBuffer(value, length); + } + } + + private void WriteStringSingleBuffer(string value, int length) + { + // Can write string to a single buffer + Span buffer = span.Slice(buffered); + + if (length == value.Length) + { + // Fast path when all content is ASCII + for (int i = 0; i < length; i++) { - encoder = Encoding.UTF8.GetEncoder(); + buffer[i] = (byte)value[i]; } + buffered += length; + } + else + { ReadOnlySpan source = value.AsSpan(); - int written = 0; - while (true) - { - int bytesUsed; - int charsUsed; + int bytesUsed; - unsafe + unsafe + { + fixed (char* sourceChars = &MemoryMarshal.GetReference(source)) + fixed (byte* destinationBytes = &MemoryMarshal.GetReference(buffer)) { - fixed (char* sourceChars = &MemoryMarshal.GetReference(source)) - fixed (byte* destinationBytes = &MemoryMarshal.GetReference(buffer)) - { - encoder.Convert(sourceChars, source.Length, destinationBytes, buffer.Length, false, out charsUsed, out bytesUsed, out _); - } + bytesUsed = Encoding.UTF8.GetBytes(sourceChars, source.Length, destinationBytes, buffer.Length); } + } + + buffered += bytesUsed; + } + } + + private void WriteStringMultiBuffer(string value) + { + // The destination byte array might not be large enough so multiple writes are sometimes required + if (encoder == null) + { + encoder = Encoding.UTF8.GetEncoder(); + } - source = source.Slice(charsUsed); - written += bytesUsed; + ReadOnlySpan source = value.AsSpan(); + int written = 0; - buffered += bytesUsed; + while (true) + { + int bytesUsed; + int charsUsed; - if (source.Length == 0) + unsafe + { + fixed (char* sourceChars = &MemoryMarshal.GetReference(source)) + fixed (byte* destinationBytes = &MemoryMarshal.GetReference(span)) { - break; + encoder.Convert(sourceChars, source.Length, destinationBytes, span.Length, false, out charsUsed, out bytesUsed, out _); } + } + + source = source.Slice(charsUsed); + written += bytesUsed; - Ensure(length - written); - buffer = span.Slice(buffered); + buffered += bytesUsed; + + if (source.Length == 0) + { + break; } + + EnsureMore(); } } @@ -636,14 +658,24 @@ private void EnsureMore(int count = 0) /// The buffer to copy into this writer. private void WriteMultiBuffer(ReadOnlySpan source) { - while (source.Length > 0) + Span buffer = span.Slice(buffered); + + if (buffer.Length >= source.Length) { - Ensure(source.Length); + source.CopyTo(buffer); + buffered += source.Length; + } + else + { + while (source.Length > 0) + { + EnsureMore(); - var writable = Math.Min(source.Length, span.Length); - source.Slice(0, writable).CopyTo(span.Slice(buffered)); - source = source.Slice(writable); - buffered += writable; + var writable = Math.Min(source.Length, span.Length); + source.Slice(0, writable).CopyTo(span); + source = source.Slice(writable); + buffered += writable; + } } } From c43567640911f6313cc89bd14b0443d9cb0740f7 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Tue, 21 Jan 2020 18:55:23 +1300 Subject: [PATCH 03/14] PR feedback --- .../Buffers/ReadOnlySequenceFactory.cs | 94 ++++--------------- .../CodedInputReaderTest.cs | 19 ++++ .../CodedOutputStreamTest.cs | 2 +- .../CodedOutputWriterTest.cs | 24 ++++- .../MessageParsingHelpers.cs | 6 +- 5 files changed, 63 insertions(+), 82 deletions(-) diff --git a/csharp/src/Google.Protobuf.Test/Buffers/ReadOnlySequenceFactory.cs b/csharp/src/Google.Protobuf.Test/Buffers/ReadOnlySequenceFactory.cs index 0ca15e16c997..0112a6ece993 100644 --- a/csharp/src/Google.Protobuf.Test/Buffers/ReadOnlySequenceFactory.cs +++ b/csharp/src/Google.Protobuf.Test/Buffers/ReadOnlySequenceFactory.cs @@ -40,91 +40,33 @@ namespace Google.Protobuf.Buffers { - /// - /// ReadOnlySequenceFactory is originally from corefx, and has been contributed to Protobuf - /// https://github.com/dotnet/corefx/blob/e99ec129cfd594d53f4390bf97d1d736cff6f860/src/System.Memory/tests/ReadOnlyBuffer/ReadOnlySequenceFactory.byte.cs - /// - internal abstract class ReadOnlySequenceFactory + internal static class ReadOnlySequenceFactory { - public static ReadOnlySequenceFactory ArrayFactory { get; } = new ArrayTestSequenceFactory(); - public static ReadOnlySequenceFactory MemoryFactory { get; } = new MemoryTestSequenceFactory(); - public static ReadOnlySequenceFactory SingleSegmentFactory { get; } = new SingleSegmentTestSequenceFactory(); - public static ReadOnlySequenceFactory SegmentPerByteFactory { get; } = new BytePerSegmentTestSequenceFactory(); - - public abstract ReadOnlySequence CreateOfSize(int size); - public abstract ReadOnlySequence CreateWithContent(byte[] data); - - public ReadOnlySequence CreateWithContent(string data) - { - return CreateWithContent(Encoding.ASCII.GetBytes(data)); - } - - internal class ArrayTestSequenceFactory : ReadOnlySequenceFactory - { - public override ReadOnlySequence CreateOfSize(int size) - { - return new ReadOnlySequence(new byte[size + 20], 10, size); - } - - public override ReadOnlySequence CreateWithContent(byte[] data) - { - var startSegment = new byte[data.Length + 20]; - Array.Copy(data, 0, startSegment, 10, data.Length); - return new ReadOnlySequence(startSegment, 10, data.Length); - } - } - - internal class MemoryTestSequenceFactory : ReadOnlySequenceFactory - { - public override ReadOnlySequence CreateOfSize(int size) - { - return CreateWithContent(new byte[size]); - } - - public override ReadOnlySequence CreateWithContent(byte[] data) - { - var startSegment = new byte[data.Length + 20]; - Array.Copy(data, 0, startSegment, 10, data.Length); - return new ReadOnlySequence(new Memory(startSegment, 10, data.Length)); - } - } - - internal class SingleSegmentTestSequenceFactory : ReadOnlySequenceFactory - { - public override ReadOnlySequence CreateOfSize(int size) - { - return CreateWithContent(new byte[size]); - } - - public override ReadOnlySequence CreateWithContent(byte[] data) - { - return CreateSegments(data); - } - } - - internal class BytePerSegmentTestSequenceFactory : ReadOnlySequenceFactory + public static ReadOnlySequence CreateWithContent(byte[] data, int segmentSize = 1) { - public override ReadOnlySequence CreateOfSize(int size) - { - return CreateWithContent(new byte[size]); - } + var segments = new List(); - public override ReadOnlySequence CreateWithContent(byte[] data) + segments.Add(new byte[0]); + var currentIndex = 0; + while (currentIndex < data.Length) { - var segments = new List(); - - segments.Add(new byte[0]); - foreach (var b in data) + var segment = new List(); + for (; currentIndex < Math.Min(currentIndex + segmentSize, data.Length); currentIndex++) { - segments.Add(new[] { b }); - segments.Add(new byte[0]); + segment.Add(data[currentIndex]); } - - return CreateSegments(segments.ToArray()); + segments.Add(segment.ToArray()); + segments.Add(new byte[0]); } + + return CreateSegments(segments.ToArray()); } - public static ReadOnlySequence CreateSegments(params byte[][] inputs) + /// + /// Originally from corefx, and has been contributed to Protobuf + /// https://github.com/dotnet/corefx/blob/e99ec129cfd594d53f4390bf97d1d736cff6f860/src/System.Memory/tests/ReadOnlyBuffer/ReadOnlySequenceFactory.byte.cs + /// + private static ReadOnlySequence CreateSegments(params byte[][] inputs) { if (inputs == null || inputs.Length == 0) { diff --git a/csharp/src/Google.Protobuf.Test/CodedInputReaderTest.cs b/csharp/src/Google.Protobuf.Test/CodedInputReaderTest.cs index dd797831c1bd..5ffb3052563d 100644 --- a/csharp/src/Google.Protobuf.Test/CodedInputReaderTest.cs +++ b/csharp/src/Google.Protobuf.Test/CodedInputReaderTest.cs @@ -34,6 +34,7 @@ using System; using System.Buffers; using System.IO; +using Google.Protobuf.Buffers; using Google.Protobuf.TestProtos; using NUnit.Framework; @@ -41,6 +42,24 @@ namespace Google.Protobuf { public class CodedInputReaderTest : CodedInputTestBase { + [Test] + public void ReadWholeMessage_VaryingBlockSizes() + { + TestAllTypes message = SampleMessages.CreateFullTestAllTypes(); + + byte[] rawBytes = message.ToByteArray(); + Assert.AreEqual(rawBytes.Length, message.CalculateSize()); + TestAllTypes message2 = TestAllTypes.Parser.ParseFrom(new ReadOnlySequence(rawBytes)); + Assert.AreEqual(message, message2); + + // Try different block sizes. + for (int blockSize = 1; blockSize < 256; blockSize *= 2) + { + message2 = TestAllTypes.Parser.ParseFrom(ReadOnlySequenceFactory.CreateWithContent(rawBytes, blockSize)); + Assert.AreEqual(message, message2); + } + } + [Test] public void ReadMaliciouslyLargeBlob() { diff --git a/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs b/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs index 17c12e596e01..66c786547d5e 100644 --- a/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs +++ b/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs @@ -41,7 +41,7 @@ namespace Google.Protobuf public class CodedOutputStreamTest : CodedOutputTestBase { [Test] - public void WriteWholeMessage_VaryingBlockSizes() + public void WriteWholeMessage_VaryingSegementSizes() { TestAllTypes message = SampleMessages.CreateFullTestAllTypes(); diff --git a/csharp/src/Google.Protobuf.Test/CodedOutputWriterTest.cs b/csharp/src/Google.Protobuf.Test/CodedOutputWriterTest.cs index 6dc177f5313e..6688c0b27250 100644 --- a/csharp/src/Google.Protobuf.Test/CodedOutputWriterTest.cs +++ b/csharp/src/Google.Protobuf.Test/CodedOutputWriterTest.cs @@ -36,12 +36,32 @@ using System.IO; using System.Text; using Google.Protobuf.Buffers; +using Google.Protobuf.TestProtos; using NUnit.Framework; namespace Google.Protobuf { public class CodedOutputWriterTest : CodedOutputTestBase { + [Test] + public void WriteWholeMessage_VaryingSpanSizes() + { + TestAllTypes message = SampleMessages.CreateFullTestAllTypes(); + + byte[] rawBytes = message.ToByteArray(); + + // Try different block sizes. + for (int blockSize = 1; blockSize < 256; blockSize *= 2) + { + ArrayBufferWriter rawOutput = new ArrayBufferWriter(1024); + CodedOutputWriter output = new CodedOutputWriter(new MaxSizeHintBufferWriter(rawOutput, blockSize)); + + message.WriteTo(ref output); + output.Flush(); + Assert.AreEqual(rawBytes, rawOutput.WrittenSpan.ToArray()); + } + } + [Test] public void TestCodedInputOutputPosition() { @@ -222,7 +242,7 @@ protected override void AssertWriteString(string value) output.WriteString(value); output.Flush(); - CodedInputReader input = new CodedInputReader(ReadOnlySequenceFactory.SegmentPerByteFactory.CreateWithContent(rawOutput.WrittenSpan.ToArray())); + CodedInputReader input = new CodedInputReader(ReadOnlySequenceFactory.CreateWithContent(rawOutput.WrittenSpan.ToArray())); Assert.AreEqual(value, input.ReadString()); } @@ -234,7 +254,7 @@ protected override void AssertWriteBytes(ByteString value) output.WriteBytes(value); output.Flush(); - CodedInputReader input = new CodedInputReader(ReadOnlySequenceFactory.SegmentPerByteFactory.CreateWithContent(rawOutput.WrittenSpan.ToArray())); + CodedInputReader input = new CodedInputReader(ReadOnlySequenceFactory.CreateWithContent(rawOutput.WrittenSpan.ToArray())); Assert.AreEqual(value, input.ReadBytes()); } diff --git a/csharp/src/Google.Protobuf.Test/MessageParsingHelpers.cs b/csharp/src/Google.Protobuf.Test/MessageParsingHelpers.cs index 53c9dfb602ea..3b66d8827cd8 100644 --- a/csharp/src/Google.Protobuf.Test/MessageParsingHelpers.cs +++ b/csharp/src/Google.Protobuf.Test/MessageParsingHelpers.cs @@ -67,7 +67,7 @@ public static void AssertReadingMessage(MessageParser parser, byte[] bytes assert(parsedBuffer); // Load content as multiple segments - parsedBuffer = parser.ParseFrom(ReadOnlySequenceFactory.SegmentPerByteFactory.CreateWithContent(bytes)); + parsedBuffer = parser.ParseFrom(ReadOnlySequenceFactory.CreateWithContent(bytes)); assert(parsedBuffer); #endif assert(parsedStream); @@ -83,7 +83,7 @@ public static void AssertReadingMessage(MessageParser parser, byte[] bytes, Acti assert(parsedBuffer); // Load content as multiple segments - parsedBuffer = parser.ParseFrom(ReadOnlySequenceFactory.SegmentPerByteFactory.CreateWithContent(bytes)); + parsedBuffer = parser.ParseFrom(ReadOnlySequenceFactory.CreateWithContent(bytes)); assert(parsedBuffer); #endif assert(parsedStream); @@ -131,7 +131,7 @@ public static void AssertRoundtrip(MessageParser parser, T message, Action additionalAssert?.Invoke(parsedBuffer); // Load content as multiple segments - parsedBuffer = parser.ParseFrom(ReadOnlySequenceFactory.SegmentPerByteFactory.CreateWithContent(bufferWriter.WrittenMemory.ToArray())); + parsedBuffer = parser.ParseFrom(ReadOnlySequenceFactory.CreateWithContent(bufferWriter.WrittenMemory.ToArray())); Assert.AreEqual(message, parsedBuffer); additionalAssert?.Invoke(parsedBuffer); #endif From 096655e6f501fec30c75e95a46a28f8c4ccdc921 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 21 Jan 2020 04:00:43 -0500 Subject: [PATCH 04/14] make GenerateBufferParsingCode and GenerateBufferSerializationCode abstract --- .../protobuf/compiler/csharp/csharp_field_base.cc | 8 -------- .../protobuf/compiler/csharp/csharp_field_base.h | 4 ++-- .../protobuf/compiler/csharp/csharp_message_field.cc | 10 ++++++++++ .../protobuf/compiler/csharp/csharp_message_field.h | 2 ++ .../protobuf/compiler/csharp/csharp_primitive_field.cc | 10 ++++++++++ .../protobuf/compiler/csharp/csharp_primitive_field.h | 2 ++ 6 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/google/protobuf/compiler/csharp/csharp_field_base.cc b/src/google/protobuf/compiler/csharp/csharp_field_base.cc index f315560906d2..7bb947c0f765 100644 --- a/src/google/protobuf/compiler/csharp/csharp_field_base.cc +++ b/src/google/protobuf/compiler/csharp/csharp_field_base.cc @@ -161,14 +161,6 @@ void FieldGeneratorBase::GenerateExtensionCode(io::Printer* printer) { // and repeated fields need this default is to not generate any code } -void FieldGeneratorBase::GenerateBufferParsingCode(io::Printer* printer) { - GenerateParsingCode(printer); -} - -void FieldGeneratorBase::GenerateBufferSerializationCode(io::Printer* printer) { - GenerateSerializationCode(printer); -} - void FieldGeneratorBase::AddDeprecatedFlag(io::Printer* printer) { if (descriptor_->options().deprecated()) { printer->Print("[global::System.ObsoleteAttribute]\n"); diff --git a/src/google/protobuf/compiler/csharp/csharp_field_base.h b/src/google/protobuf/compiler/csharp/csharp_field_base.h index 8a28f45acebf..da3171e774e3 100644 --- a/src/google/protobuf/compiler/csharp/csharp_field_base.h +++ b/src/google/protobuf/compiler/csharp/csharp_field_base.h @@ -61,9 +61,9 @@ class FieldGeneratorBase : public SourceGeneratorBase { virtual void GenerateMembers(io::Printer* printer) = 0; virtual void GenerateMergingCode(io::Printer* printer) = 0; virtual void GenerateParsingCode(io::Printer* printer) = 0; - virtual void GenerateBufferParsingCode(io::Printer* printer); + virtual void GenerateBufferParsingCode(io::Printer* printer) = 0; virtual void GenerateSerializationCode(io::Printer* printer) = 0; - virtual void GenerateBufferSerializationCode(io::Printer* printer); + virtual void GenerateBufferSerializationCode(io::Printer* printer) = 0; virtual void GenerateSerializedSizeCode(io::Printer* printer) = 0; virtual void WriteHash(io::Printer* printer) = 0; diff --git a/src/google/protobuf/compiler/csharp/csharp_message_field.cc b/src/google/protobuf/compiler/csharp/csharp_message_field.cc index 412579831258..d40fa1308b42 100644 --- a/src/google/protobuf/compiler/csharp/csharp_message_field.cc +++ b/src/google/protobuf/compiler/csharp/csharp_message_field.cc @@ -123,6 +123,11 @@ void MessageFieldGenerator::GenerateParsingCode(io::Printer* printer) { } } +void MessageFieldGenerator::GenerateBufferParsingCode(io::Printer* printer) { + // same code as if parsing from CodedInputStream + GenerateParsingCode(printer); +} + void MessageFieldGenerator::GenerateSerializationCode(io::Printer* printer) { if (descriptor_->type() == FieldDescriptor::Type::TYPE_MESSAGE) { printer->Print( @@ -142,6 +147,11 @@ void MessageFieldGenerator::GenerateSerializationCode(io::Printer* printer) { } } +void MessageFieldGenerator::GenerateBufferSerializationCode(io::Printer* printer) { + // same code as if serializing to CodedOutputStream + GenerateSerializationCode(printer); +} + void MessageFieldGenerator::GenerateSerializedSizeCode(io::Printer* printer) { if (descriptor_->type() == FieldDescriptor::Type::TYPE_MESSAGE) { printer->Print( diff --git a/src/google/protobuf/compiler/csharp/csharp_message_field.h b/src/google/protobuf/compiler/csharp/csharp_message_field.h index 2463d912ba98..3a34e3e20c44 100644 --- a/src/google/protobuf/compiler/csharp/csharp_message_field.h +++ b/src/google/protobuf/compiler/csharp/csharp_message_field.h @@ -57,7 +57,9 @@ class MessageFieldGenerator : public FieldGeneratorBase { virtual void GenerateMembers(io::Printer* printer); virtual void GenerateMergingCode(io::Printer* printer); virtual void GenerateParsingCode(io::Printer* printer); + virtual void GenerateBufferParsingCode(io::Printer* printer); virtual void GenerateSerializationCode(io::Printer* printer); + virtual void GenerateBufferSerializationCode(io::Printer* printer); virtual void GenerateSerializedSizeCode(io::Printer* printer); virtual void GenerateExtensionCode(io::Printer* printer); diff --git a/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc b/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc index eb7f70dda6b5..34e3d17aebca 100644 --- a/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc +++ b/src/google/protobuf/compiler/csharp/csharp_primitive_field.cc @@ -164,6 +164,11 @@ void PrimitiveFieldGenerator::GenerateParsingCode(io::Printer* printer) { "$property_name$ = input.Read$capitalized_type_name$();\n"); } +void PrimitiveFieldGenerator::GenerateBufferParsingCode(io::Printer* printer) { + // same code as if parsing from CodedInputStream + GenerateParsingCode(printer); +} + void PrimitiveFieldGenerator::GenerateSerializationCode(io::Printer* printer) { printer->Print( variables_, @@ -173,6 +178,11 @@ void PrimitiveFieldGenerator::GenerateSerializationCode(io::Printer* printer) { "}\n"); } +void PrimitiveFieldGenerator::GenerateBufferSerializationCode(io::Printer* printer) { + // same code as if serializing to CodedOutputStream + GenerateSerializationCode(printer); +} + void PrimitiveFieldGenerator::GenerateSerializedSizeCode(io::Printer* printer) { printer->Print( variables_, diff --git a/src/google/protobuf/compiler/csharp/csharp_primitive_field.h b/src/google/protobuf/compiler/csharp/csharp_primitive_field.h index 5edcc42b7ba4..29c6b27110a2 100644 --- a/src/google/protobuf/compiler/csharp/csharp_primitive_field.h +++ b/src/google/protobuf/compiler/csharp/csharp_primitive_field.h @@ -58,7 +58,9 @@ class PrimitiveFieldGenerator : public FieldGeneratorBase { virtual void GenerateMembers(io::Printer* printer); virtual void GenerateMergingCode(io::Printer* printer); virtual void GenerateParsingCode(io::Printer* printer); + virtual void GenerateBufferParsingCode(io::Printer* printer); virtual void GenerateSerializationCode(io::Printer* printer); + virtual void GenerateBufferSerializationCode(io::Printer* printer); virtual void GenerateSerializedSizeCode(io::Printer* printer); virtual void GenerateExtensionCode(io::Printer* printer); From e146015e7accdfb2e5dbe3b5e54493c9e2f6b30f Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 21 Jan 2020 04:01:23 -0500 Subject: [PATCH 05/14] regenerate C# protos --- .../Unittest.cs | 2 +- csharp/src/Google.Protobuf.Test/testprotos.pb | Bin 330948 -> 327492 bytes 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/Unittest.cs b/csharp/src/Google.Protobuf.Test.TestProtos/Unittest.cs index 0cccc1c976ad..f4e57671c605 100644 --- a/csharp/src/Google.Protobuf.Test.TestProtos/Unittest.cs +++ b/csharp/src/Google.Protobuf.Test.TestProtos/Unittest.cs @@ -5023,7 +5023,7 @@ public void MergeFrom(ref pb::CodedInputReader input) { } /// - /// This proto includes a recusively nested message. + /// This proto includes a recursively nested message. /// public sealed partial class NestedTestAllTypes : pb::IMessage #if !GOOGLE_PROTOBUF_DISABLE_BUFFER_SERIALIZATION diff --git a/csharp/src/Google.Protobuf.Test/testprotos.pb b/csharp/src/Google.Protobuf.Test/testprotos.pb index d00db7fdeb7639fc7be4590acb156234abafd3f3..40523b972f8886871dfac1220ddc7923fd467247 100644 GIT binary patch delta 23791 zcmai+cbpg1{qFb749oIeK^S^p%F=r;QkGt&i2*@ifu%Pof>MSK3QBiviM^W}Ylvy; z{Uvr2yLp+I7=JM)zZlbQG|4X}zxQWmKIgOE`^WunpYNRKdCoa==A0?d*&p20=m-C5 z_(<&r?zfMZG^pLiz4v(i-bb5USWyTf7Z)FLMb|jjqW_s^2Q{w#!-PAc$}EBfC5C2$0R^Pg=ATRs<@ zc(r=|eNm_LLx)9&do_P=W1)6jtGwuJ;0n*wEw~Hfu)HYl_hjAk&rT02imNZ*7VR9} zxu{d2q~J>8uxn98p-v$vaoL~QkKKworayL!L-{lNv1d`M!Z=FSiNl`N&902bFX>&> zL5hWN`xJFa{|w@=Z&A1O&oB=AVIu{iIP724HT|4V?yNaleVTxB2N)1!Vih37%I)}$Zo&8}~EVxObUXtrMDbTdN6@Wjcyi-;+ zsveCGrsP$Nq-x`9H^{W3v}zNg3o@!e4o`?`8>Z_fP_?ur9Ov*vUwke&{lUsR%1^9O z9yrODFA9V|sfK(Y$0^=LItqCzKDoN$gQ#0FxkjmwQj=*-+SLr*Xj(8=+and2Ry)o* zK5__5kJ{wbbwaEGs-tbAG= zIIBi+q0g#OTpBy8Mseyo+xLx22kdNZb%MLpezxyR7cgGu)F@9!fVJy6Oz}B2iZjSA zsZqQZ#V@H*ycWeTp?FgnztS`Ff|e}`Wph?jymeWEh>1p)dLQjjJE%Y?$$%UR4L0g#85@{VJFZaA!Dbi|6mtO99 zwcuUu?YKr41#R=16hm7S)KLU&Q9))7=8B*g+M?EN^2XJU!^NJK)P}d%^J>Fe?0L1} zE%rR-%q2m)T(Sh(lAxdn+LF>%il8lNTbA1~YgPvB^Fwu@ReD+-7bjt*=hcB%*|uHI zE5zZ_KqU+Cmikj(z;3BOY#Ui zs6MpSLH!IRL4A0u8+6r!@K*QemGc_J;o3kY8^Bu|$P_7cZUAjXvIZ7R^nqyXKlr;&5}&BQM#6_H7Ol9ac>!xw)|{sM5Pl z5Z&Chdp>hEjl*q0IWy<%s!dguTdS7qb=Q;`XPdvAno`ScrTK{snj*NZfld!i5!}|k zV_uPFad>4=E?z7`K{HgY^eW9zxzejNL*+`Z(hQX=y-M>q-0nw5b40d#k>-eOFKv*w zra2W-%uhI&YtG!AqRIc_atx&nztF)pjS9_7xak$eD;?{`l z^dhYh*;$(3NCd4B*_kxd;n*6LoqkNWiNjr9r41^(yh*VF6dB5vZEc40;^O9r1rT|xjmMvu>(^3 zT>aJxk=p0VWKEORyJH;fw@P(H38+dPQQB{n>WI>Qt5iqEAK2HbJdO@Hx+$|QM+&G? zpw7WU*|YF?1CZr!OlnlRjM;mhh1rNJ&Mv{*P@?7ln%RrgL9=WadgxLYSRU!qlrm% zLF%Y0ZJcwvAa&F=>822=qpqhcV$$hd4_E3n@ zHLiExR4FM6y2a5k7mUk~c0&rNQr+nEV|Mn^SkV$6c(aw>wV9<@9Dw-ElhZ%KPU| z-Nos+>(sB%B<-CZade{kmBUf9l>{Pciw!ZpxA-2;OYGN?0y9vGZ(9s1=4 zJxT(>9kWg=3VO!TNf-3b3-_ccK<%@h7@f?F(&5z;r<3N?6Q`5r)Dx$Z=G0T1PMTA% zI6CEmfw@yJoPg@o3#U`oXT2~wWqsBwj1#c$v|c!!a^(Z^HuVyxQ?670{PgsWqtoWp z8z-PT^~UM6IrYZrv^n*rNvF-IH%6yZqa+;&y~XLYIrWL7Gv?F>C!jj@!Rd@S^}*?k zIrYKmj5+ne>5Mh0j~JaXqrOZpXU(ZEPC#|)i_=+i>WkA^bLxxJS##=((^+%sD^6$4 zsb3tObHU*JH1)#>SkURUA5P~SYgRV6`r&lWHPorOA5Q0F63ma{bk21il%J-4;&je+ z(dnpv9Nl0}{c!?nllo(HgBkTtaJs>q`r~wiIrYcs26O5!PB)m-fHZs3yG9)pVpQ!qbx9QCRPDMB$=ftQoT^kvkMZva0lZAR;R%@-E2c|Fitny&>M`?%{KG~<8-qPy}{yi zvkko=ade9d`sN)l1S4Q>lmtU?y2Y0AAvoRQ>bKO=INjpflqtmN7T2y%ewv1e(=D#O zE;>Ww=vEhu%nJ|238+mP%A#|tEnh=1y4593^u!Fs=~mahr;>5H)%6;YI}H`5TV3yq z3eD09d{`Xa#`4WA|J)6mDwnO5TmEdI4a1c~9@4zq?34||^)|aH7?$9AoAu-{TyJyb z19R75;(D9wG$5Y=hsV+FcGEB%C!jhF$LV%+8jjQL<}@6m+s$Y=Mz>>>2`Cv zD30#1dy0#20;27lxh11>UGzzD?&1sZ4 z-EB^zM29L%Gs7|ACy2s|)(HPz1coNAAV|0&8{KPaGr+Zx2q4{|lEl&5i zZbR~+R}n||no|W%Ky|9X>0WcH!0BFds=(=9n*l2@x>t?3y{izXd(CM~9Np)Fi}GrY z!3n5NV{p39=Grkh-RF3u$=Wmqr~4ewG&#iSKG%JC-lQ>Nbf4=nEN{}-IJ%$PTXh1(4kKXNBze3VhtmUg;f}-U z0lRR=;q-uAxZ`koz-EYX;`D%Bx8vjJL0hQC;{?>s8;{Y0e&_|`F-jh^p*J3<2VFk6EJ$nmB~m{Ht z^pNYQ_k9z@=^?p!&K@Nu#?iwr7?YpWi8uk(X(F@w!#1l=#OYysD4B@U!>*@3(M-hX zVb`}J9}p8u0`9*acKt>d8m6=Qq&WJ93%a(bRW`kHlR8YofnW7TViFGDu;qOc4&RW$ zoz-=696f?UUf0P`fl8eW^%0{^hMGKL+$nMNsN>~fHh8DN1?tn*6u6JNCVFzFz=8 zP=QLF4)qD6PKWx0Q7?|8C%Gxm`>%`Pg5`6W%w!kCebP1St`P2%u2-MDwKL-An|4Dn z11eCdGoXIcs578`)2K7!=)8^EnZ=xcus$8ngnQn#=$+fngnQog)75uY9DU2Uv#jVm4Hu42yL9&xZSyjf>fEpR!>wCyu`Dc)yeN%pADDMhc;R z+cnk+a1PXO%e0gYi%a6@JNCNb5~x6Z|8fb`?{NREPq3H3{f(IT)03z zw{zis*Us%+sNc17dubef&uV-rRG`-QQmEhaHBN#{;eOAm{FONRzRk&BfeUPvxArS= zzwcV>Ta&Lq{k|J2Zbac{_ZinhXOa1EpRw03m&MVuw%T6?71$!L@nuk-buINh$YoHUmG>?6#I>X- zPKy7-1+Tg=D_+8<*XTc7iM+6rS}lm9AGq{Wrd$*Ym{fr}FD;<#4_v8^`vpk0rT13AeZ#mb;J#tpm2vc@UCk@u0`-zy3H43a zW?*i+66%|7h+fUB;^-}-u7V0w>ME#jxi-z)p#}3 zx2?u&;^-Z-T>}-UwriliV>MnQPjBy-?bydiT zjToJu>J4%9Qx}ZQl{TORRHY3l{nVA}QnLZ2q&6b;GgI1#($7q3QyjhTg7LY{CX|4g660?ZQt!J`eK)lUsrOxHeFd-ysrOyQ zxV(K=#L>@9>I$TQTB$2g`nf4xfzr=S=?av7Zc3Zu=odUaYFBMW3anC_k@|(TZ!=QA zu=Z_6>KE3&EphaLRcZ@LKvmj;(g#+lEhv3pl}ffC^?}uDYaIR3q_!djRH>~<{nDhi zBK1p?+KSRIO=(*keQ2j|8%jV`+J@4H(!BiR%r>MxwDxU7>O*Vam2vbdd!uzFT%gYK zS3>=jYpE~juY~$5*SlYSzP88FM|Q`x9V$>KyzP#+#~-;?z4DQ<9qvc2uimZgh@)TI zioOFbP`Nv>{k3bQH+nmu{@V4^H<(w&(Z`O@@!7PVZ{CKwa^!hWi`WMBm|G4fQv!T%R3w#?f!>j%z1Wpf2w_q5jr2 z({a8N>Tg}*m+W0}^gEk+c5%LddcJlc^*dK8&s)-hT}b`Tb<}xx7gE2onP_($ePVY} zyHNtF(r%PKvDqZqjnpTud~mM38>vs+un~D*?1`h_o75hpfGV{Iso$H_9+ZA>N_$ZH zy(w{<{;Az#B`5*?+v^0WPhF|Lu9kPopSt$C63Qg~sjP%q>-ppu{XxD=W#54II>f*Q zj}iNWD{bR(TE1;}kCFR>>y@g@`QOL!KgvMM^!AA!SoQXi)B~56`QvH%cD+4D?~gL} zvg+~iG5V7WM&*b1iyTQOyBR&`;!|!valsR*#|iMS8ip` zeY4ie>RaxJN)wO-#^eLo0U`gDu%*Y4|LPj+SUF>f1VisknlfuC5?Om_@BF`IyoHX@ZV$^%=m|e4_5obLjRj9 zY3z?f|C`*MW%frn{CBJU5uyLxC7ypo_)rJVa!*zeecbMEL}7p8qP@MGtC;e*xwdZF(P{Lr~x=z9Y{bWU)1U%<^* z=5|8pVCdNwzZ1gW7m(u80`T_*&GnY+B!~AK|D^E2YJXDb`;C55?Drd;kDSqgz>nNh zLI(>ykqhsX@DBuj=$;b(fxr*l(;Pl%{L{h*tNm%AA2j-Dp&v9l-y@?#R{JwT2d8wI zv(5&f~D21?~Pg{*94j)s3Xt3!2HptP7yEvt_kACtRX=}ME!VBbUlIb zQk2E^xY)|`BGKJAx-JMZ9*8;uYo`}~n(GCYWY2LxYIt36fu!7mTJqR^GDvgi$kvhy zoD6D7E-R`fG1%x7FgqCXPm|5ChtaLsu8kYIS8xen=+*Oz38JBz zJeKr35u%}W^Vqdu=tCRI#GjWZMl`gktUFvD9Ov+`h|hdJ-j3d|8hVm{A6B=m=hOA! zurgVsGd)IRIILIxT~OlhBZ4t`)zkRy8*T4sB*CJ&3~u<_hBWXUh-{_#G+B`qB96I@&x;rR9)sDiwN;n0LY-T}&; zA~zqPf@ZLp2EqwmMcO^Vt4N1W@G8`CVxU<`39V1`Rgp0DL?6@>zllDmC)xjr9n15o z04Aj(=}S`Csxir{NalNzR|!#>MJ{nqz%1o~!A@iC31eGE()1M#-na}jm zP%`GT$Q)+9aseW-dvY`-1eF zn`k!V8d^Y>FkKcvQkE!TWieW@3bu=`Rk zLfCy-;5%8u?#sN2gx#0<&XTbEGJnBH*nOG5Uc3=wV&rD?7rI1^AdJn?dN&I?rXe=gx%M85ed5| zYrINZRMvQvwy3P}DumtF`Vl8#_qAT743)Kh#FZhk){nR{MArHd*Dhwqi*B1~hsZj+ z$!UkmI)8@Rp|Z}O=60y8^Czf1dtCf#LDn6lb5VOl*89bxJtFJ4?b2 zyjK{1<#Bk0Uo8l?gH)xQ8RZJUT9l)5gxX`=#0u%zgl!gWUF5+y2Nb0(Zzx^dyTC) zWZBt@qr2C-Ad+nJt3?-7w)xefYs|hGT`dT**VskVmA0rwhPY{<9Q*kaQS-VVQ7kZuomaQZSs!tLP>R*P)0 zkZgOngT*#wU*t)Lh&%gV0rzm1x9BN*Wpwc)-VW07LAsrtGrF~@Cl^J!%n1qCMQ>9eOkByhB2u zT{qp(ZRFY6bE6i-+1ZJrcL}7~^F24x!Gzhv#9K&|JxqLNo+SHT`+_1#cA&n3mn6I2 zkVF6X;g!T*3xr6NeXk|YB+9oe$bo-;B?TO2H~PKV)=4OvL8wF zqLN@gW}P+^hhvr$O%v?LEGbHY z{kVM}mDD;=n=%X|_Bx4CIxZx(e%zdf;Z$R@lcd(!?DVD7I-8yJODw7N>+Iv5q}GAz zB&qf5Y#>N#olgfkGmu(Oz})9#<3eKV*I67oO|4&NacENO*PD~1)`99IsrBp4NmA>4 zWKbtbtzU0Ol3Kq$HOjshq_Oqu&56|d33HOvI#8V?wa!K^9o&*y=X-=YNot*)TG}K@ zt)H+arK$B3W;BvdpC`>pV(UP4lGHjoxztHg>wLLTCrPcdQ%jvBwSLl^($xA%a~c)1 z*~(|hCAALp-&iHK&Q30!S4ZJ=%JI06otIHKu~SROx}?@mX~erINK@;lEa5#mX0w%d zlGHj-n=~4u(`GbUzUH1br_nf_HYZ7~pEjp7wSL;1DrC2nPk2}01XQOAoY=^v6L%Cog}pmRHrdGv5`xi#^7|;oFuh=*0SVd zFgj~SNg7)}YffWhc3b(Kqmo(&s*|MF*~q0c#8{lp*>x+a^>a2uNNW9@UAJj!{hVF5 z<7Bf{km&L!v30OINot*)Tsri|;dFxyJxQ&zkxS#sl3HiumVTs8Q|mWamVA87W-IQ5 zvcV*&bzp9k1QJ_kCzo#a9gkDBg~=tgUY&)>Ws#QDdbMTA)6{ykWyvSRY_{@Qa!IWN zwMi40z}d*9X^jaO-N+81Zh5^Vwtl09$tAUZqwA|-@-(%6qh-lSt>5zhWXUD1&aXNU zCgO05t>ltczeUD&mWP}av*Rd8G)yizbg*(K!M)YEl0(1Mxa82kYFQG=p#!yHlc9dq z(z}vF|Ei^TiJ^bZs8b|d0aor5xL-4_%Qct{Q%sNshhaPP7}xa839vOqXF^t+8Z6Dm-tGojwCRPM_q zhkmzl$)Vq45hKZ=19ezP4*eb*7Lr51$A$$t^m{FtEje_cCbMTlz1JtR1Bs#E>$)V} z^5IAh{XPqmOAZ~Vm;W5N_u2iMmpx$q%R$}P)+o_$) z`p0G&jlW9{9jH~79Qp%RWyzsGU|Di<=bIrK*@Oum3>0rk{N4*k(IOrAa^Ne=x{%aW5rf6Qzb zVhdDT$)P`Hwh}{s%p%gn&>weEq9;sp=wMA|OAh^UOJ++B{c%fXlS6;PvgDFO2WpmF za_CQ3mRxe^Y*f)K`Qn(pCO&k(IDre+Dldlnq*Zw_+$XKdOJX*g`1t!0s6egp5~$y_ z8ZUv$MiouJSIS-!Z(9i!h-+oqtCeuin{6drHmb=Le`+@}*F} zWm$5`p?^!VP{P{S=jKWGOnL-J|616hXq)2@MD?2=@ES{j{hqYWFWR*R&hY~|*S+cs^2V#xpJ|FI<>@@dr~4ez?GXpd!yWG6%i{iqE))ZR`gs^NeekX6Y6XJ7~n$ zXtrnYZ}yZT={tTfQ9gn5L*0f}BBeAcvmX$B)^+Gq*qol4v#U^g-ju3PdfqkAD@KC+&%3ti z|3Q((Gqb_}i6YNTFvzEZLa;AN{6y8vEs{8O~-hI9>5K$Tj9(krI42BlZ*^sPbZ z6+35|+enZt13;BpkJOJ%YCTdvwvixP27YWKfh_~CnUZW70IJdklwQk} z(q(i5Qm>iR2BcmyDYgu}Zc?&k0H{(Mk$T-KwGpM)O-Z&4ylzTt8F<4H*T_zvY#Dfi zWmKg$A@znyZ9?h|dq$Ei18=zY@-am&Kei08WkscA%K%W7u0ZKcQ@R4BH%&>l47{mI z+{UqIfGsS#e?qnl099%;Qg4~mW~AP-;VD}N-m>AzmVviTNwy3CRcQ-KZ=2E70tbMX&0H{)1k$T6Zwj%Y8wNJJTyrb81%*)s61Ny(OhcSWjC9w2wvDJ8YnKGe8rQ}*#p%!p`M+`OpNN|2VWNTH3!CP% zdE;~`AYelZN2#Kr&Vg5T(381k_^O8(OoWL@HMG~}Pi75~byxu8~V(WDrQ zk6iK8ToH`ouN>c^vPFj<=sHT&vmaRdK5`d!vmbEz$aNoWKhS?4xv^7HlLT8?9zS+b zYb}v3kNlu383kzi$F`F31EL>G%kp}pnaPh`3yEJ#7dMTI|H}n`@J;2De)M0~(x$ZZ zcaG40tvq2IHkGD+Voe3pR5l`LQ~80WQbL=`4>a`?YbrnB@`*K-A86_)+Ei*KE&bFH zJ#dY-z#O zj*I{4ivC6Q3WcCHef)*|3pL`hwZ;CQuD1MxO#mIhkwOOO=Pz7oQa?k8f8iR)zZs<* z9sGsd6-fsNaq-@uNb;;4ilh=GxwCuOKu#w??d-)72z_AI!9X1L1$qAhq3#R#oGslA z#AIL4KFR)vT$->Yvz@&^0U-rcDY=u|ALQ?^IEvK%Ab)iVL~4J~F?$sgNXHQ0&h{OH zPy(t_z?eM{@LfBrMIdi14+Le|z9dQ`bs*>~Z^t7l8OFsVxeo_nUOYsMA5<))S_iF# zBpZSGZ3<+x4hHSYGcEq(^p~_Gl*?hg)uK2xOW88}1rodEi%pPUD=EgDAF^2?{Q>(! zL4MPm{($76Aiq@7AE?5iAiY$iIS3pH@!f2}=&=lQxGDI}+sorw@qKk)SNQ i6AZ{$Mn~<;6S5Sj{X)tT=+8VcOQ1jVhJN*y$*wy<0 delta 24047 zcmai+cbFDM+U}?7ZDxjd1fj`!fEjYmNit?#S4CY#5n;#~1VOaPNE9WE1j*uu0To2l zU2}HN8aKMDd%j(>yJq*e>#lykr@Nni#&ezPI{(f6cHQ?~Rb5@x;jVf1`#R6=sC$1= zZTI2v;@U;c-5-wE>UvZCQ-|h#;KIUHu3)WmjeBf)s!zSbaiw!B#$Q|c?L1$);;*Al z{&kdFI?h#`oN%Z6KMmc|lVhHA=WcYzPaZkXm$gxWM_j>U|ChiT1WtZCFW2OG|MXjx z|Fth@b8_H-V0D+e8*j)Lh1EtB9P=)}vT@#>66Qu6f9=&X3jK*1Cu?7l8(vu1bXKr< z=%|7=`Qp4Q4s&M|49i!~`(l^;nf!QWL0SA`S(uYQlONA1Xqq2M$?9S5oXXPIg2ChA zwc?GSdbPkF03);nh`Y`vCf)4SYxiEJDZc-o!b3ZL;AOBe`%w0&?MET-^7V=|p zi!djD{?XHO1!1)-3;xTWj9v>achQx_jq|7EgP;Jv;3_{Z2dX9r&#Uqc@-^~>f;_bu z8`R3z%oimPo3TN4!xSHzFELEz#@0MFqjUJ`plx>86$-AOuNkF!P6{+=Wd-10UEU_C z8dVO)`^jn50;$^gqS}de5LazNa7scI$l(b=kzu-Q0#%D!!f_5)WW`5=;~%WNqkKh` z^1z8%`2sKeiB;si9H)3Y=_ur>_@v5n-wZlLld6=;QEC#ciMyJ?8%*`{v^`RRsYPMZ z@qt5NTF^YLt`lMvDCc2D5T=cDabsr$H4IaHMy6V;?mezRf<#B*;(JXc%aVKR!6u??Pq6w={)0fPL=X>1X#PC!xW!Wr8t9Z zZk6KIC_cAJ@oE&GOYsIWex+v?_$H0>r58<^IqBNz<0^kSKd2Ec@I^_-#$C0bxV|E) zzMxTK*uq74p>L8Na@a1+XwqW~Gn$;8g&7V1>wL46=Am8Zixok;u6n~rA-wCFG)?UQ zi!xpg-lB{r*ZQLB4O3c9N@g^AZ*fKope@d5(vyobS^#ZvOpBy-l)OIURf~~UQ@Zr} zj8_fb^_d;l=n~%|tw|xYCBC{MXiM@kb1+x?Ob!bsWtM0-m7iGNa@S+yt zAf1vAgQd+)552~1r{oVyWADkRS0#tYtSgA)(C?YW?KU)P;F~KU6I-P z8c|)mO{8|T;jVF=x}@CNVX)SD6|M~xcuHEfHq^DQ zMoWcI*SfNFx$t2ataCorWfJruTyTxFa0qvutJzv1+;y%^yVSN$7_3jZQ0qViDzy&O z^+v4&b-hvRhQUVX2d27p>En$q%1%&SxEoz{9W`~~ZgefR7IljSmJMJcXBqKzxoZHI z_fKn8FAO$0-!YZ0hcr-6eLc!WQq&K-{?NjOc zVX)cxPN{T#8VuACSf8?+UA;DX6zR>beaC#mcu+M6gDuXNGv!`bF}q^i{E7+rv|xiE zK9tW#$uMa^jkmZGJ@XBa-QsGu(9+0majnYI8Z``qt;nVa8zKc%<%TG2HKm3qZ8fEa zC~Y;RMvT90Hi#M_1yrd&7^&?h)g%lmO{xh}K$U8ORHaEZL8{U!)dZzVQ)(Ipx0zB?lz^(#6s6lD zlWL08Z6?(esoPAdSs3iFao-Fnph`7EYKJQc)1GRE(hgTg$8Ix}cGzXmJPdYbN|A4l z6j-I2Bem0{nj^K-q?#kO)1+F2!7dy2El>igQVW!Jxsp0*rCOl0%hlCk(*mVku3gk2 z9aN=Zu-l|ckpikzDN?&lsuZc+CRK{mZr4tgT86>xHauIR1XQJ#DBW(uvt@+T?KVDJ zB6Yis&sJfu$If3Xq<|{b3aLGI`dXp1$4*}>l=j%^YaIrAo!2wc8YLh~Q9QI;BemC+ z=%n2mslBdNv$W@0BemC+${H$5MOhf^vr3gA1=LEFp|sB`Rff_&t5g|E`>aysVG!-N zt|~_gs8Z!f?YFKfM{2+IR5?=nt*6?A!9nNyq&04X5>S=eFlilhCFzpu+n{vNHR>jX zW&Ur2)Iry?ciO(TVQ|R#eyLPjq<|{b7O6w7q>&y)>JX2Z3Q;=bdiPD0+J(Vk=VKpi z+MxtgrFJMCc2P;al-mxe!>)b@g-9KCox7$|?ZeWB+oPob>KF!hIo~TS+z}(78g<0zE>{xi?Aj6TT`trqzavg}$>~j;I^uMf zEAN>)brh$&T$>*G`tgwL6bAP?-?MRX=>_A)PqSsF6P_GU&rW#WYa^-?BGJ9BwvO{o zc-|}HJn`&==e@3VkJPhMu@_vX{n$ASj^ddX?u-*qojT)m)SNowbkvMGV{|kzis%2% zI2|>o&f;{`oVtX;ea`nzox0!zRHrUD-DfAP3r_c0H+I44KI_IV7~SW}d!9jCBoz`^~8K+EitV!K50;*B>YPA2DId#YBm^pRF z>6kfn$LW|kbr+{&=F}q$jyvBsJxx7u0;*FFnsnTjwH_E9cXe9o{Z9{^j?2WD480yW z9d~W}r01!JI30KGbcX5~1`nE3Pn>}2)Dx!%&8a6&4~kQw+!Lb*&8TOD(}U*JQ=A?& zr(R)j!ukFwxff1Ab?SxF30oC=;dH{))itIUPA6okPK`D(?jOe8>ffNsW(m!nNx3ZddPK9qdsA9(yrU64^Cip>Vwls zyKwv9bkZ)|J~*AU8KMtPC+)iJBTgsny6qbV58Ke|ixE(b`eO8OmHDqPP7mAA>x)2{A^6HuM{;q-_t?)@-&#MMe}{|h4D52r_5^HL?_ z^oVQOEj>^D#OV>&O4p(OVeqK)gVVzOaRRDSf7YQ#UACh2$LUd5Uq?WHj2?9z^+B;e zMvuCv%W0`oe{p)$bsdyGJPZhf$5_#Mco;o%_K#-u0l0EVT?f#<$Ly31!1Xb^PZ)sf zW7d%aaDB{`_fAa*MB@6GYtt*80SAV`<8~i05GSBI4aDhja~g=#8c=!4uqNL}^bB!U?QSgK&Dn=A}V6J>jxPk3l#+VHfcroStxP`=)IgBu-Db zc74(&ofZa9+WpLF7y;ENIt`~M&FM6po;0V^aC*|5PQ&R*b2?3&o;0VyVephW4aNzm zPJ=Oe%8UkM^pp!DotOsW^prUb#_1_@8Z1svnbVLkc-owX-~?2sAvis4PD5~d+L|;3 zqo*^Y$PdBkX>%GPPEVWD&@gz$`2p!^8j2H8ordD{jLo$}aeBrcR)*sAjLl0!F?z?@RF?`r{e@vr_*tI$!7J_aeB!f*-ppl zC0D9z@##3dU0LP`pY(}pMlfM_MCDC zPA|L8`jB%5PA|Le!_on9hB&?KdJN6iiH*(-gJ1FN-?&=odE;h_L45yvCJy|p1K~^@ zer3!1nK=AP26yuKc~%&_lD$6gXF&xj^(?5b81*cuuNd|0FnHD8RGtm>)yR2$06QD* ztFFGDowMP-YOgBK34_;+dk$QnQqO_dM;F8N{#%va9=m>xo}@M z?s;MGhH=k>3sl?lpuS<$^Ps+A)bqpOO}i;LA1Y8j*vTuW^P#@!8g|t6=X|(tx-Q+) zPX0+4{MxubfeTdbPvHIo^>;QbE`<8KWLU)CKQ0P` z-`l&Ni{JwF73W28fA8w)d!vis{@z~pTpR{}us0YNLj~$H?Zr_4VE1$vL;ZuyGs!?6 z9R_dl{#WmZM#Fu}&h2QpZ`rvW4ficOx0i&$AFalhKm}@zFM;|;tMMgJ|7bP7Gz|V^ zb8>VkT(ExUxD@W6Tr+)cQ*Td>+* z3HM#Iy%O%bW_wi_yypTvUspi|R!^_RtDwH;@;X6W1@%4GP`^u!4TJYxpdB|B>idxk z^fSR&xbM5_dd-Z5`@XBMAD6BUgAc5uu7(TL8ea|d1FP}XP(QF5j|+njt;XY^0@E5t zejMBnt;*xzerQ#`CJa6@+iTzg)%F^wADQhnP(L!;@nP_>3-q~WJm&{kGwrDHP(OC3 z@})MJ568p(*fnjDFOAo!31RSQP7?qs-M8h1(-?~^8_8D))KNGCsc&70zN(yo)VHo& zpBQE!^{qQ?XgcA{41<3$JL+N{~)I5~Fw@O9xkow+gH9rh~Fsb=S0aa=~ zQa_l~e58Ibsre}VU`p2#8SvRixE3X#DqV}xQqM?8zmHyv)KZ^~glmyn>a&rsfEa+! zUPUi}3)Goy0o3KbiN3R60Cl-!ZrUXs84KaA@ZI%p z?K)xrKKtf!9bBMtufukwZ>o2C*FjzBd*~a?MPabYXW#u7K?UmfnMF`n`9|@3BY8es z1b3D1s2~0p6Cv=)*Lw~wh6~gcZ!z4}zP`T0Ukr7%FV|;>>q!v!?2hYts6bubuZOzE zH`H-{J=8Tm%GT^9L))J)F`ZAq6mmsy)XY=k21PXli z4($e%fU0x@O6zx)G`MCUql9>rLrK zl-8RPH$oeH_SGvw37CDKkC58nOY~)pe6`%*Tj@$Dlk^79N|>yZOF6pH^RX()DlBz~ zf%6$gY@;t}p5eHBi;fvaZlmuKtIPRc#_>%u&=S36q6b#JWrPL6C8gQ%xO~g58AflD zjJ>3K%Q<|r_e0Xd%S8^Xa?3^TX6ZJuYggcxyO>a}kLk-DdN=!lgY)y^N2wJY-r_5l z?F{BeTRfqeq?#*)w#64q7EdA@D}=Vi*V9qHlEYi&GEEMzBvmF@=_`f4)pMt+$Dwca z+>a%#SjFLOa=9gkR|$PvWc*da-{yo&_-BuNFR7?NA#68dds zzm~&0JkJkF?biw&94VjNul$g8{#xPhu+Cq{;hn}`Cw#Ed*9m>6(boxmr_tAQc$c+) zz0ko$QCgq%!rx`BUoZS!*7^+`-fbsugYdy>zd`7`?c8k;`ffXS8##Qt(KiYmT$GQJ z?${{&+l{|b__rH>6NmR0f0OXRYQIV7dyKwG=zENQGl%zjZo3kpX5X5sJk zq~o*z{Jp-B-fV5=@IK>j7Cu<*Hw%5A(Kn0zKBM2l;r%vrZV@_I=#gA#w+Mf~jh$PB zzu(5rtsFjJ{9A<&R{L9pe!%Fr3jKi5w{ZBN)qac6!7*KCt1ZGmXw}~${DW5gtsFjN z{H?+VtNm7?A2Rw@p&t@@k9;mDsLr>1@9Q@%CsH-9V(x;938fQf%`Kf@F>gMp*2?L7 zgT~RFUO&N9m&aXT`qWdMtQ#<_$Kvk;67qNXf_uoTm!K@RcZsdMoFF$G26ua(@IcfN zSQKCUai|zroIJt-so~xJlp3O1tssmFkNP+Uk8Cxmz)@eVmdI9<3~q2A8DY^8#6e)3 zo)bvz?(?LFld>GV-^xn;fLfMZGB7I(dO*vT6?ji!uomVBuvYDB3TMxqHGfvm{Kqe! zB)WfNySkq&N>clG(hJ`=s+!v0Q6;rszq0bx;Hr-QpXmPCmeN04Qu-sCoNMWN`BT&N zqYE}^x_)%kbp0j%XI0bnm;5+ge`z4IU7D^Z>3gXLpCx=xto70wY3f_B1J{wMKP^wP z_0k5i@^FE0oWqv|eB#T}_2^wzMNi`Qm(^&I@#*~BWu>w}Cwh#@++|(TZ-SD(zrtUw zX?5|w;>YRxF)GdFA&19kMq92I&U$VPL$FHx{>m!l#rjGuPjLyPUs4nM9wE=DoilBNtsH3%A~9+6r7xiR6}HPRu##gPtHWDAu?G+ zlAwqL&?jdqjM6Dy?(L;l3Q?JosYo1s3W3D*7%Efhv{r=3ls0YCULlS?H4`a9WNIcN z+4QNY2oJ&%PM?~oNH~3Jrb0MAZnkeLL3Qcd8mP?9R0z4}W@lBYfy(Tx zDn#6Kv$LwyWamiMD>V_BlZlXa&&|ntr6wYCvR)zUo|_}RlDr5yHO$T9K_sclsi@4$ zR0zK3=8-W>kD)S;h+&FQnMc4d>6KbxZa$BH$)Q?^%+Ewfz~|6Iq$52^7t}sQ2EFe~xh=gHoArF1Yp%9UU znFy))+`?>cM93pwZecTdZ6IeML}ei_*%OsIVQvwL!sJjLR2F3_b?Dng*$JwH$Rg5& zX-PyD#d`rnvJRKfBC>?>IslTQLYz?3vV$o!n7n7 zi#dHM!eTLBJrfJb(B~GDAxtdlg}EiX2uVuT!(mD0P>-(Yw4_9bXFYgJn#<}Z^{$7- z624$1D@J{;6kon&*5C$_?K7!Q4Wn#;)rTHs1FSyuD6XNb79{4E+UF!m$piIyUPAIq z?K5@*ZgQ4d{G1`%c{usb%(^T2k`MBqEV~sA|L; zBU6%)JW!P+B){C08lkj2R!SypNy#raDN^z)OiEJnK$Vh|{0ftjlswPY`p!W@@+(Y< zko-zhl8`)5l_Vq|tu!e~$@9FeQj(HiX;P%*SJ|gSNy!6MN>cKxEO;Ry`BjcZAbAXy zko+q9z)VPfwJNb-NJ<{8Qj(HiZBmkwUu{y7l3#67q~zDw7d{Ee164^v@@p(P(Hx~U zmYk4~{2CW!f%Fz(aFa<%N*<_El9Ip4q*@?#lS#Ee>L&YkSQ^SE8+|`5A$g!Gm7=uP zhG$fY)LI*#l9FF*V>{2db2$d7w&3N`A9r@kxfZq~td{R-Y82wAnuA5|Y2wqU{or2da{U z3H0-aJZ59;i~1l4oO(zB*`!(iX=ulvJu6N?R;% zPe^`S7HyBbq~yUW)t*kTvYn?rQrj%rE-CqK@_{{3ZcmP7n?>8(vsQq!XgeYL?G|m9 z3_VbdBtyTQWWRn3?f`eY#Q-EkzgnWaxLsM#=myA^M%>6o=?{niC=VT^9I|5Isqg1Y z@3Mq!=i-Pq?Xrk0A^P3sBq4gBI!TD0{XOc`1*hHSBq93U<|HBd-R4AyUU1b6{q16u zez}nlJy@M2M9=;ob&?SM?dBvQ`gr?Ka+)MWf4e!wA^O|Ri4grBYm#K>fojx^2L^EF z)D5RS<|HBdJ=P`((eE**I7Gk4oCwkHwZOTA=z;3g9izRrtVxD`FM)GS7DjH&I!@)Gbahr1Jy}F^lUDQUmtO^Bq92J7H#i=QM|b*F^VKazt5cF z5dA)LB1FI6a(oh^2da~V=-GRuS%{uE?YI1pgy{FnQk^*U#Av?-&f^UIeivnlb3*h7 z%t=D@Ky{K3{Q-08h0_6Zk`Vm?bCMAK0dtB&^am{3PKN$qcHKr^LiAvDk`O(+p!CA+ zjnhH9aC_r)&}Ik;(I2$yHV)ArwCk1-{UIBAlA#Bxk!0u(Rhj?#;B?4_o`mQR+0c^^ z{UIBAaftqq4Lw5icUTflLi9j&k`VnJwzx}%{tk_{bN?kF`a3MzE+P6mEZQE2=&kypq5?JFl|9yv%m&ywY#LM9x|Q4Ps8b6bCSF~d&G3Ilf3-B)}%Nuf3F!0<{9m%IZ0q1 zs7?}?XAhY=4aVuHIZ0lgJ!0x4dHJK}6zAoSn$r;3=9Q(`B`*)m?vaP!#2zx8SBKzq zpFNli!HGR$I@TpGf1icR@M@(=l_By!CpZr82k<&WD8A$j@ZcHPE#`Qvuoj+AX)KGL0C5|{_8lLY43L#9J- zBu)>y>``YVPV6DmXE({qvt>*_kH>lW2Q9@uO7?kW2@}c715=~OOJJToWV-Ws6iz4X z@k|2qCoIM;f%y{_V~_LlC*l};{HpzQ+2@s|*d;Fy)Fz$I1kM&ReI${*{6j9vw%bZz z{vnI8OJM#X*Ii@mabW%-i?NfJe}w0Ji?Pd#Aj!$|s}8v{aCpR4a>>a*B4aywr*fw3 zbs}Aojtfb^gOz(G+((To3HV2iO9KAqmI;>xJWv~U7Sx|xZdelVKeya43HV z+_)s*pRgMMNx%a&vvVHQCoGCC3HT>0icSLlNux>v9;npwp+-*{R}%0~8kYq8Q#NcR z0T0yhg(TpgvM9PF;GeQ6ItlovjVcLvpi(b@`m|EHN4Ws*)5awM|BSvtD)5qk2kNkp z1pG5LEF=LR?=MP*6bble?KO`i;DMS6zYyxPmI=QQ>a$h;`vD2~=j?5TB;bL1`CkP0 zIlF(81pIR{(ImDc;Geg1D+zd@4vUMSK5wU167bL4sU6Mw$2J|^NFWJ#pjLS_+!w6M zqv5__ucAo6v+qWuk&=K1>T7~apuT7+c1gg$Xeo9Q@NA@!9q{q}k0jv1`T|K3@a&b* zmn4#af5{CSk+zlu{L3~$O9CFK=T;K%FI$RT67VnE%NG*xzqI>HNx=Uya$fVvl7RoE zYpJhWBmw_RdEJu5*nj2x?|u|x|CPnq3CO=9FH#x4o?S1ra)0{%6#9fK`UZO1@;&1@wB|C)ufNx;AEf=Ex8 zB;dgsW4{va>y`J%L z9NgcS?KrsXk*kNexMwqER# zp?_N%9sl>ATwT>_92J*Nnmg;-+4EAJ93N?ZM5Ix%PMjCY)s>jYJ1!{CpBm>4z*K`D zPO%@T$UBb2LskOCcU+z3_5+o9$F+=8d{+>9sOu^5XUG2-REp&O_`yW^9?uUo>R5@G zQn%E8K=jY9b({QL-6imDWzVn3{k>~_GyxTMZ|Ggx1T@}twKX?40fl#6bNwe{6|z4g zn|dm!5m0-(0;Ts%sRE_RcR7RZ1vFQO+x7d7u9Z_jzHOB@PTxDA~jhyb7bwC zj1*9%CL{HsNlixTLu;RGIQTGaAI)RK!ADl9DJTI|DVl;5J3+KoQ;_<|WtEZ*2p?Ic z*nse{<6puhx8zfi0;<$hls-14sVIGHr*A4sAKU3;JHjWTl)memh7?$(rXlr-NlioQ z6O)qd37?o0+Y|m~JvALApejvA>2Ibq9i_inPfeFybbqt1Vz66_GpRuf3eQpm)vRmPE*Gke6 z^0}4W3hb6qDcP+6RHZp6ePK$nTj2{+lHCels1o;aY*+Zw#;5F70IJknq`ow%xk!C! z!*ecDU)u0wx58JZB)b)Wsx%L!uS{tkN?*C!kzRhXTj48{Vz&Z&YqWi`TLGw2^O5@6 zq~;^_wY5)nD}1f(EAZ@A_{NlEw*pX=u9dgi-UH#T)nXHJLi9>?DEf`ZSY?cnfI%GE*Wb% zzT5}VGM|@)i6_1s{|v8ixo2NPwbY`1Ar>oq;W?=y7{%qD?^nsH!w+;FC2HCaEPgBe zsU7SGTvqswL+uCpZ-pOmc5D)1E9>JbA2ibv@%qRQx|C6XrmynZQpOL6uJWw&X+7f5 z<|^M<^54?M4Z^~kyx*8LRl)@~SxXzx(zTxb0@c!pbFP6jb)7X8OjFqdp-trnno0?6 zDnHQFb=FjVz-65^l^tBVgpY^5!v@?#H}&hg3= ztc4{7yWI+d$mDBbx#0n7Sq=b6%$DR`QCPUs7wo2b`MfWpK7`jL50@(v`<=e1Q3B`y zj^q!s-=#gjKj zAoPJr2Lo}~>(l-PLfz{L%1CzuG1==|MM)~fi|{_(1_VM1s8Vt(x6h|9us9kQPG4XF zk=p0Wl6Ns)I%dD_V*;TBR3*=t-S5+{;vAJ%miv8avLy^;V1G)GTJp^v1sfm(D$? z*Gh~r=Z9ogh=0KTpk6BR4@e%=OC|n+DjZBM6=@Cvclb2#0TQ^_T0`8E!|9~WVZ`q6 s>3 Date: Tue, 21 Jan 2020 22:47:27 +1300 Subject: [PATCH 06/14] PR feedback --- csharp/src/Google.Protobuf.Test/CodedInputReaderTest.cs | 2 +- csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs | 2 +- csharp/src/Google.Protobuf.Test/CodedOutputTestBase.cs | 2 +- csharp/src/Google.Protobuf.Test/CodedOutputWriterTest.cs | 2 +- csharp/src/Google.Protobuf/CodedOutputWriter.cs | 8 ++++++-- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/csharp/src/Google.Protobuf.Test/CodedInputReaderTest.cs b/csharp/src/Google.Protobuf.Test/CodedInputReaderTest.cs index 5ffb3052563d..3105f90e1894 100644 --- a/csharp/src/Google.Protobuf.Test/CodedInputReaderTest.cs +++ b/csharp/src/Google.Protobuf.Test/CodedInputReaderTest.cs @@ -43,7 +43,7 @@ namespace Google.Protobuf public class CodedInputReaderTest : CodedInputTestBase { [Test] - public void ReadWholeMessage_VaryingBlockSizes() + public void ReadWholeMessage_VaryingSegmentSizes() { TestAllTypes message = SampleMessages.CreateFullTestAllTypes(); diff --git a/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs b/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs index 66c786547d5e..17c12e596e01 100644 --- a/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs +++ b/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs @@ -41,7 +41,7 @@ namespace Google.Protobuf public class CodedOutputStreamTest : CodedOutputTestBase { [Test] - public void WriteWholeMessage_VaryingSegementSizes() + public void WriteWholeMessage_VaryingBlockSizes() { TestAllTypes message = SampleMessages.CreateFullTestAllTypes(); diff --git a/csharp/src/Google.Protobuf.Test/CodedOutputTestBase.cs b/csharp/src/Google.Protobuf.Test/CodedOutputTestBase.cs index 004c2d635fc9..cf00b89e0ce1 100644 --- a/csharp/src/Google.Protobuf.Test/CodedOutputTestBase.cs +++ b/csharp/src/Google.Protobuf.Test/CodedOutputTestBase.cs @@ -206,7 +206,7 @@ public void WriteSmallBytes() [Test] public void WriteLargeBytes() { - byte[] data = new byte[2048]; + byte[] data = new byte[1024 * 100]; for (int i = 0; i < data.Length; i++) { data[i] = (byte)i; diff --git a/csharp/src/Google.Protobuf.Test/CodedOutputWriterTest.cs b/csharp/src/Google.Protobuf.Test/CodedOutputWriterTest.cs index 6688c0b27250..fcc995e90b38 100644 --- a/csharp/src/Google.Protobuf.Test/CodedOutputWriterTest.cs +++ b/csharp/src/Google.Protobuf.Test/CodedOutputWriterTest.cs @@ -44,7 +44,7 @@ namespace Google.Protobuf public class CodedOutputWriterTest : CodedOutputTestBase { [Test] - public void WriteWholeMessage_VaryingSpanSizes() + public void WriteWholeMessage_VaryingSegmentSizes() { TestAllTypes message = SampleMessages.CreateFullTestAllTypes(); diff --git a/csharp/src/Google.Protobuf/CodedOutputWriter.cs b/csharp/src/Google.Protobuf/CodedOutputWriter.cs index d1c91ef939f5..db5e88f179ab 100644 --- a/csharp/src/Google.Protobuf/CodedOutputWriter.cs +++ b/csharp/src/Google.Protobuf/CodedOutputWriter.cs @@ -203,8 +203,10 @@ public void WriteString(string value) if (span.Length < length + buffered) { - // String doesn't fit in the remaining buffer. Refresh buffer without specifying a size - // to get the default sized buffer + // String doesn't fit in the remaining buffer. + + // Refresh span with default size. + // We don't want to specify an exact size because a very large span won't be pooled. EnsureMore(); if (span.Length < length + buffered) @@ -669,6 +671,8 @@ private void WriteMultiBuffer(ReadOnlySpan source) { while (source.Length > 0) { + // Refresh span with default size. + // We don't want to specify an exact size because a very large span won't be pooled. EnsureMore(); var writable = Math.Min(source.Length, span.Length); From 575a7b816bea447a7d5daba9b43c6b13e55979bb Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Wed, 22 Jan 2020 21:01:55 +1300 Subject: [PATCH 07/14] Update benchmarks --- .../SerializationBenchmark.cs | 11 +++++++++++ .../Google.Protobuf.Benchmarks/WrapperBenchmark.cs | 12 ++++++++++++ 2 files changed, 23 insertions(+) diff --git a/csharp/src/Google.Protobuf.Benchmarks/SerializationBenchmark.cs b/csharp/src/Google.Protobuf.Benchmarks/SerializationBenchmark.cs index b14b751054ca..34f3a9167fe8 100644 --- a/csharp/src/Google.Protobuf.Benchmarks/SerializationBenchmark.cs +++ b/csharp/src/Google.Protobuf.Benchmarks/SerializationBenchmark.cs @@ -125,6 +125,15 @@ public void ParseFromByteString() } } + [Benchmark] + public void ParseFromNewByteString() + { + foreach (var subTest in subTests) + { + subTest.ParseFromNewByteString(parser); + } + } + [Benchmark] public void ParseFromStream() { @@ -191,6 +200,8 @@ public void WriteToBufferWriter() public void ParseFromByteString(MessageParser parser) => parser.ParseFrom(data); + public void ParseFromNewByteString(MessageParser parser) => parser.ParseFrom(readOnlySequence.ToArray()); + public void ParseFromStream(MessageParser parser) { sourceStream.Position = 0; diff --git a/csharp/src/Google.Protobuf.Benchmarks/WrapperBenchmark.cs b/csharp/src/Google.Protobuf.Benchmarks/WrapperBenchmark.cs index 39256e24b37b..f9ca29bf7707 100644 --- a/csharp/src/Google.Protobuf.Benchmarks/WrapperBenchmark.cs +++ b/csharp/src/Google.Protobuf.Benchmarks/WrapperBenchmark.cs @@ -64,6 +64,12 @@ public ManyWrapperFieldsMessage ParseWrapperFieldsFromByteArray() return ManyWrapperFieldsMessage.Parser.ParseFrom(manyWrapperFieldsByteArray); } + [Benchmark] + public ManyWrapperFieldsMessage ParseWrapperFieldsFromNewByteArray() + { + return ManyWrapperFieldsMessage.Parser.ParseFrom(manyWrapperFieldsReadOnlySequence.ToArray()); + } + [Benchmark] public ManyWrapperFieldsMessage ParseWrapperFieldsFromReadOnlySequence() { @@ -77,6 +83,12 @@ public ManyPrimitiveFieldsMessage ParsePrimitiveFieldsFromByteArray() return ManyPrimitiveFieldsMessage.Parser.ParseFrom(manyPrimitiveFieldsByteArray); } + [Benchmark] + public ManyPrimitiveFieldsMessage ParsePrimitiveFieldsFromNewByteArray() + { + return ManyPrimitiveFieldsMessage.Parser.ParseFrom(manyPrimitiveFieldsByteArray.ToArray()); + } + [Benchmark] public ManyPrimitiveFieldsMessage ParsePrimitiveFieldsFromReadOnlySequence() { From 8142b586b7699c156b86df928c690bd5783be458 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Wed, 22 Jan 2020 22:13:45 +1300 Subject: [PATCH 08/14] Fix wrapper fast path --- csharp/src/Google.Protobuf/CodedInputReader.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/csharp/src/Google.Protobuf/CodedInputReader.cs b/csharp/src/Google.Protobuf/CodedInputReader.cs index 82194e058c4d..72f023432cc4 100644 --- a/csharp/src/Google.Protobuf/CodedInputReader.cs +++ b/csharp/src/Google.Protobuf/CodedInputReader.cs @@ -839,9 +839,9 @@ public bool MaybeConsumeTag(uint tag) { return ReadUInt32WrapperSlow(ref input); } - long finalBufferPos = input.reader.Consumed + length; + long finalBufferPos = input.reader.Consumed + length + 1; // field=1, type=varint = tag of 8 - if (remaining[2] != 8) + if (remaining[1] != 8) { return ReadUInt32WrapperSlow(ref input); } @@ -914,8 +914,8 @@ public bool MaybeConsumeTag(uint tag) { return ReadUInt64WrapperSlow(ref input); } - long finalBufferPos = input.reader.Consumed + length; - if (remaining[2] != expectedTag) + long finalBufferPos = input.reader.Consumed + length + 1; + if (remaining[1] != expectedTag) { return ReadUInt64WrapperSlow(ref input); } From aee5496b6c1ee328eaeee2dc7b56210ce910bc66 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Thu, 23 Jan 2020 15:43:23 +0100 Subject: [PATCH 09/14] more robust ParseFromWithLimits in tests --- csharp/src/Google.Protobuf.Test/CodedInputReaderTest.cs | 4 ++++ csharp/src/Google.Protobuf.Test/CodedInputTestBase.cs | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/csharp/src/Google.Protobuf.Test/CodedInputReaderTest.cs b/csharp/src/Google.Protobuf.Test/CodedInputReaderTest.cs index 3105f90e1894..a9da432ae4f6 100644 --- a/csharp/src/Google.Protobuf.Test/CodedInputReaderTest.cs +++ b/csharp/src/Google.Protobuf.Test/CodedInputReaderTest.cs @@ -407,6 +407,10 @@ protected override T ParseFrom(MessageParser messageParser, ByteString byt protected override T ParseFromWithLimits(MessageParser messageParser, ByteString bytes, int sizeLimit, int resursionLimits) { + if (sizeLimit != int.MaxValue) + { + throw new ArgumentException("sizeLimit not supported when parsing with CodedInputReader", nameof(sizeLimit)); + } CodedInputReader input = CodedInputReader.CreateWithLimits(new ReadOnlySequence(bytes.ToByteArray()), resursionLimits); return messageParser.ParseFrom(ref input); } diff --git a/csharp/src/Google.Protobuf.Test/CodedInputTestBase.cs b/csharp/src/Google.Protobuf.Test/CodedInputTestBase.cs index 3bc6eb3ff90d..95eac3e1c91d 100644 --- a/csharp/src/Google.Protobuf.Test/CodedInputTestBase.cs +++ b/csharp/src/Google.Protobuf.Test/CodedInputTestBase.cs @@ -125,10 +125,10 @@ public void MaliciousRecursion() Assert.Throws(() => ParseFrom(TestRecursiveMessage.Parser, beyondRecursiveLimit)); - CodedInputStream input = CodedInputStream.CreateWithLimits(new MemoryStream(atRecursiveLimit.ToByteArray()), 1000000, CodedInputStream.DefaultRecursionLimit - 1); + CodedInputStream input = CodedInputStream.CreateWithLimits(new MemoryStream(atRecursiveLimit.ToByteArray()), int.MaxValue, CodedInputStream.DefaultRecursionLimit - 1); Assert.Throws(() => TestRecursiveMessage.Parser.ParseFrom(input)); - Assert.Throws(() => ParseFromWithLimits(TestRecursiveMessage.Parser, atRecursiveLimit, sizeLimit: 1000000, resursionLimits: CodedInputStream.DefaultRecursionLimit - 1)); + Assert.Throws(() => ParseFromWithLimits(TestRecursiveMessage.Parser, atRecursiveLimit, sizeLimit: int.MaxValue, resursionLimits: CodedInputStream.DefaultRecursionLimit - 1)); } [Test] From 538d9b1980eaf812b29d9dbd940ddbc09c821af6 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Thu, 23 Jan 2020 20:01:36 +0100 Subject: [PATCH 10/14] test that limit is honored when parsing a nested message --- .../GeneratedMessageTest.cs | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs b/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs index 71867e3e4414..53ca3e4837c9 100644 --- a/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs +++ b/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs @@ -724,6 +724,68 @@ public void TruncatedMessageFieldThrows() MessageParsingHelpers.AssertReadingMessageThrows(TestAllTypes.Parser, data); } + [Test] + public void ParsingNestedMessageFailsIfOverLimit() + { + // when parsing length delimited byteString, parser must recognize it's over limit. + AssertReadingNestedMessageWithWrongLengthThrows(new TestAllTypes { SingleBytes = ByteString.CopyFrom(1, 2, 3, 4) }, -1, 10); + + // when parsing varint, parser must recognize it's over limit but hasn't yet finished reading the entire varint + AssertReadingNestedMessageWithWrongLengthThrows(new TestAllTypes { SingleInt64 = 123456789 }, -1, 10); + + // when parsing length delimited byteString, parser must recognize it's over limit. + AssertReadingNestedMessageWithWrongLengthThrows(new TestAllTypes { SingleString = "test" }, -1, 10); + + // when reading the fixed64 value, parser must recognize it's over limit + AssertReadingNestedMessageWithWrongLengthThrows(new TestAllTypes { SingleDouble = 1e-9 }, -1, 10); + + // when reading the fixed32 value, parser must recognize it's over limit + AssertReadingNestedMessageWithWrongLengthThrows(new TestAllTypes { SingleDouble = 1e-3 }, -1, 10); + + // packed repeated value + AssertReadingNestedMessageWithWrongLengthThrows(new TestAllTypes { RepeatedInt64 = { 1, 2, 3, 4 } }, -1, 10); + + // repeated string (non-packed) + AssertReadingNestedMessageWithWrongLengthThrows(new TestAllTypes { RepeatedString = { "abc", "def" } }, -1, 10); + + // TODO(jtattermusch): test for start and end group too? + + // TODO(jtattermusch): what if even the tag/length of the nested message is over the limit? + } + + private void AssertReadingNestedMessageWithWrongLengthThrows(TestAllTypes nestedMsg, int lengthModifier, int paddingMessageCount) + { + // construct a NestedTestAllTypes message with a nested message + // as a payload, followed by some padding. Tweak the serialized + // form of the message so that for payload, the length delimiter + // is set incorrectly. That will result it nested message's + // limit being too small and should result in parsing + // error. The padding is there to make sure we're actually testing + // the nested message limit rather than hitting the end of the buffer. + // var msg = new NestedTestAllTypes + // { + // Payload = nestedMsg, // our payload + // RepeatedChild = { new NestedTestAllTypes(), ... } // the padding + // }; + var stream = new MemoryStream(); + var output = new CodedOutputStream(stream); + output.WriteTag(2, WireFormat.WireType.LengthDelimited); // tag for "payload" field + output.WriteLength(nestedMsg.CalculateSize() + lengthModifier); // size of "payload" field, but artifically made incorrect + output.WriteRawBytes(nestedMsg.ToByteArray()); // write raw data of payload message + // write padding messages to make sure we don't approach the end of the buffer + for (int i = 0; i < paddingMessageCount; i++) + { + output.WriteTag(3, WireFormat.WireType.LengthDelimited); // "repeated_child" field + output.WriteMessage(new NestedTestAllTypes()); + } + output.Flush(); + + // TODO(jtattermusch): check that with unmodified length delimiter, message can be parsed ok? + //MessageParsingHelpers.AssertReadingMessage(NestedTestAllTypes.Parser, data, (msg) => { }); + + MessageParsingHelpers.AssertReadingMessageThrows(NestedTestAllTypes.Parser, stream.ToArray()); + } + /// /// Demonstrates current behaviour with an extraneous end group tag - see issue 688 /// for details; we may want to change this. From bb9815aa9f4697af1bba470567e62fdfa94d398f Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Thu, 23 Jan 2020 12:11:45 +1300 Subject: [PATCH 11/14] Protobuf reader perf --- .../src/Google.Protobuf/CodedInputReader.cs | 207 ++++++++++++++---- 1 file changed, 159 insertions(+), 48 deletions(-) diff --git a/csharp/src/Google.Protobuf/CodedInputReader.cs b/csharp/src/Google.Protobuf/CodedInputReader.cs index 72f023432cc4..71302dde009f 100644 --- a/csharp/src/Google.Protobuf/CodedInputReader.cs +++ b/csharp/src/Google.Protobuf/CodedInputReader.cs @@ -177,6 +177,12 @@ private static void ThrowEndOfInput() throw InvalidProtocolBufferException.TruncatedMessage(); } + [MethodImpl(MethodImplOptions.NoInlining)] + private static void ThrowInvalidTagException() + { + throw InvalidProtocolBufferException.InvalidTag(); + } + /// /// Reads a field tag, returning the tag of 0 for "end of input". /// @@ -194,50 +200,49 @@ public uint ReadTag() return 0; } - byte value; - - bool hasValue = reader.TryRead(out value); - if (!hasValue) - { - ThrowEndOfInputIfFalse(IsAtEnd); - - // End of input - lastTag = 0; - return 0; - } - - // Optimize for the incredibly common case of having at least two bytes left in the buffer, - // and those two bytes being enough to get the tag. This will be true for fields up to 4095. - if (value < 128) + // Optimize for common case of a 2 byte tag that is in the current span + var current = reader.UnreadSpan; + if (current.Length >= 2) { - lastTag = value; - } - else - { - int result = value & 0x7f; - ThrowEndOfInputIfFalse(reader.TryRead(out value)); - if (value < 128) + int tmp = current[0]; + if (tmp < 128) { - result |= value << 7; - lastTag = (uint)result; + lastTag = (uint)tmp; + reader.Advance(1); } else { - // Nope, rewind and go the potentially slow route. - reader.Rewind(2); - lastTag = ReadRawVarint32(); + int result = tmp & 0x7f; + if ((tmp = current[1]) < 128) + { + result |= tmp << 7; + lastTag = (uint)result; + reader.Advance(2); + } + else + { + // Nope, go the potentially slow route. + lastTag = ReadRawVarint32(); + } } } + else + { + if (IsAtEnd) + { + lastTag = 0; + return 0; + } + + lastTag = ReadRawVarint32(); + } if (WireFormat.GetTagFieldNumber(lastTag) == 0) { // If we actually read a tag with a field of 0, that's not a valid tag. - throw InvalidProtocolBufferException.InvalidTag(); - } - if (ReachedLimit) - { - return 0; + ThrowInvalidTagException(); } + return lastTag; } @@ -360,15 +365,15 @@ public float ReadFloat() { const int length = sizeof(float); - if (BitConverter.IsLittleEndian && reader.CurrentSpan.Length - reader.CurrentSpanIndex >= length) + ReadOnlySpan current = reader.UnreadSpan; + if (BitConverter.IsLittleEndian && current.Length >= length) { // Fast path. All data is in the current span and we're little endian architecture. - ReadOnlySpan data = reader.CurrentSpan.Slice(reader.CurrentSpanIndex, length); reader.Advance(length); // ReadUnaligned uses processor architecture for endianness. Content is little endian and // IsLittleEndian has been checked so this is safe to call. - return Unsafe.ReadUnaligned(ref MemoryMarshal.GetReference(data)); + return Unsafe.ReadUnaligned(ref MemoryMarshal.GetReference(current)); } else { @@ -973,12 +978,9 @@ public bool MaybeConsumeTag(uint tag) #region Underlying reading primitives /// - /// Reads a raw Varint from the input. If larger than 32 bits, discard the upper bits. - /// This method is optimised for the case where we've got lots of data in the buffer. - /// That means we can check the size just once, then just read directly from the buffer - /// without constant rechecking of the buffer length. + /// Same code as ReadRawVarint32, but read each byte from reader individually /// - internal uint ReadRawVarint32() + private uint SlowReadRawVarint32() { byte value; @@ -1043,9 +1045,80 @@ internal uint ReadRawVarint32() } /// - /// Reads a raw varint from the input. + /// Reads a raw Varint from the input. If larger than 32 bits, discard the upper bits. + /// This method is optimised for the case where we've got lots of data in the buffer. + /// That means we can check the size just once, then just read directly from the buffer + /// without constant rechecking of the buffer length. /// - internal ulong ReadRawVarint64() + internal uint ReadRawVarint32() + { + var current = reader.UnreadSpan; + + if (current.Length < 5) + { + return SlowReadRawVarint32(); + } + + int bufferPos = 0; + int tmp = current[bufferPos++]; + if (tmp < 128) + { + reader.Advance(bufferPos); + return (uint)tmp; + } + int result = tmp & 0x7f; + if ((tmp = current[bufferPos++]) < 128) + { + result |= tmp << 7; + } + else + { + result |= (tmp & 0x7f) << 7; + if ((tmp = current[bufferPos++]) < 128) + { + result |= tmp << 14; + } + else + { + result |= (tmp & 0x7f) << 14; + if ((tmp = current[bufferPos++]) < 128) + { + result |= tmp << 21; + } + else + { + result |= (tmp & 0x7f) << 21; + result |= (tmp = current[bufferPos++]) << 28; + if (tmp >= 128) + { + reader.Advance(bufferPos); + + // Discard upper 32 bits. + // Note that this has to use ReadRawByte() as we only ensure we've + // got at least 5 bytes at the start of the method. This lets us + // use the fast path in more cases, and we rarely hit this section of code. + for (int i = 0; i < 5; i++) + { + ThrowEndOfInputIfFalse(reader.TryRead(out var value)); + tmp = value; + if (tmp < 128) + { + return (uint)result; + } + } + throw InvalidProtocolBufferException.MalformedVarint(); + } + } + } + } + reader.Advance(bufferPos); + return (uint)result; + } + + /// + /// Same code as ReadRawVarint64, but read each byte from reader individually + /// + private ulong SlowReadRawVarint64() { int shift = 0; ulong result = 0; @@ -1062,6 +1135,43 @@ internal ulong ReadRawVarint64() throw InvalidProtocolBufferException.MalformedVarint(); } + /// + /// Reads a raw varint from the input. + /// + internal ulong ReadRawVarint64() + { + var current = reader.UnreadSpan; + + if (current.Length < 10) + { + return SlowReadRawVarint64(); + } + + int bufferPos = 0; + ulong result = current[bufferPos++]; + if (result < 128) + { + reader.Advance(bufferPos); + return result; + } + result &= 0x7f; + int shift = 7; + do + { + byte b = current[bufferPos++]; + result |= (ulong)(b & 0x7F) << shift; + if (b < 0x80) + { + reader.Advance(bufferPos); + return result; + } + shift += 7; + } + while (shift < 64); + + throw InvalidProtocolBufferException.MalformedVarint(); + } + /// /// Reads a 32-bit little-endian integer from the input. /// @@ -1069,13 +1179,13 @@ internal uint ReadRawLittleEndian32() { const int length = 4; - if (reader.CurrentSpan.Length - reader.CurrentSpanIndex >= length) + ReadOnlySpan current = reader.UnreadSpan; + if (current.Length >= length) { // Fast path. All data is in the current span. - ReadOnlySpan data = reader.CurrentSpan.Slice(reader.CurrentSpanIndex, length); reader.Advance(length); - return BinaryPrimitives.ReadUInt32LittleEndian(data); + return BinaryPrimitives.ReadUInt32LittleEndian(current); } else { @@ -1103,13 +1213,13 @@ internal unsafe ulong ReadRawLittleEndian64() { const int length = 8; - if (reader.CurrentSpan.Length - reader.CurrentSpanIndex >= length) + ReadOnlySpan current = reader.UnreadSpan; + if (current.Length >= length) { // Fast path. All data is in the current span. - ReadOnlySpan data = reader.CurrentSpan.Slice(reader.CurrentSpanIndex, length); reader.Advance(length); - return BinaryPrimitives.ReadUInt64LittleEndian(data); + return BinaryPrimitives.ReadUInt64LittleEndian(current); } else { @@ -1169,6 +1279,7 @@ internal void PopLimit(long oldLimit) /// internal bool ReachedLimit { + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { if (currentLimit == long.MaxValue) From 9847ddb54a56c0cf1a9046bb79818292fb733029 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Fri, 24 Jan 2020 21:34:22 +1300 Subject: [PATCH 12/14] Validate message limits --- .../src/Google.Protobuf/CodedInputReader.cs | 194 ++++++++++-------- .../Collections/RepeatedField.cs | 2 +- csharp/src/Google.Protobuf/FieldCodec.cs | 2 +- 3 files changed, 116 insertions(+), 82 deletions(-) diff --git a/csharp/src/Google.Protobuf/CodedInputReader.cs b/csharp/src/Google.Protobuf/CodedInputReader.cs index 71302dde009f..818ac8915831 100644 --- a/csharp/src/Google.Protobuf/CodedInputReader.cs +++ b/csharp/src/Google.Protobuf/CodedInputReader.cs @@ -67,7 +67,7 @@ public ref struct CodedInputReader private SequenceReader reader; private uint lastTag; private int recursionDepth; - private long currentLimit; + private int currentLimit; private Decoder decoder; private readonly int recursionLimit; @@ -86,7 +86,7 @@ internal CodedInputReader(ReadOnlySequence input, int recursionLimit) this.lastTag = 0; this.recursionDepth = 0; this.recursionLimit = recursionLimit; - this.currentLimit = long.MaxValue; + this.currentLimit = (int)this.reader.Length; this.decoder = null; this.DiscardUnknownFields = false; this.ExtensionRegistry = null; @@ -161,22 +161,6 @@ public uint PeekTag() return tag; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void ThrowEndOfInputIfFalse(bool condition) - { - if (!condition) - { - ThrowEndOfInput(); - return; - } - } - - [MethodImpl(MethodImplOptions.NoInlining)] - private static void ThrowEndOfInput() - { - throw InvalidProtocolBufferException.TruncatedMessage(); - } - [MethodImpl(MethodImplOptions.NoInlining)] private static void ThrowInvalidTagException() { @@ -201,7 +185,7 @@ public uint ReadTag() } // Optimize for common case of a 2 byte tag that is in the current span - var current = reader.UnreadSpan; + var current = LimitedUnreadSpan; if (current.Length >= 2) { int tmp = current[0]; @@ -242,6 +226,10 @@ public uint ReadTag() // If we actually read a tag with a field of 0, that's not a valid tag. ThrowInvalidTagException(); } + if (ReachedLimit) + { + return 0; + } return lastTag; } @@ -296,18 +284,7 @@ private void SkipRawBytes(int length) throw InvalidProtocolBufferException.NegativeSize(); } - if (length + reader.Consumed > currentLimit) - { - // Read to the end of the limit. - reader.Advance(currentLimit); - // Then fail. - throw InvalidProtocolBufferException.TruncatedMessage(); - } - if (reader.Remaining < length) - { - reader.Advance(reader.Remaining); - ThrowEndOfInput(); - } + ValidateRequestedDataAvaliable(length); reader.Advance(length); } @@ -365,7 +342,7 @@ public float ReadFloat() { const int length = sizeof(float); - ReadOnlySpan current = reader.UnreadSpan; + ReadOnlySpan current = LimitedUnreadSpan; if (BitConverter.IsLittleEndian && current.Length >= length) { // Fast path. All data is in the current span and we're little endian architecture. @@ -388,7 +365,7 @@ private unsafe float ReadFloatSlow() byte* buffer = stackalloc byte[length]; Span tempSpan = new Span(buffer, length); - ThrowEndOfInputIfFalse(reader.TryCopyTo(tempSpan)); + CopyToSlow(tempSpan); reader.Advance(length); // Content is little endian. Reverse if needed to match endianness of architecture. @@ -468,7 +445,7 @@ public string ReadString() } #if GOOGLE_PROTOBUF_SUPPORT_FAST_STRING - ReadOnlySpan unreadSpan = reader.UnreadSpan; + ReadOnlySpan unreadSpan = LimitedUnreadSpan; if (unreadSpan.Length >= length) { // Fast path: all bytes to decode appear in the same span. @@ -498,7 +475,7 @@ public string ReadString() /// The decoded string. private string ReadStringSlow(int byteLength) { - ThrowEndOfInputIfFalse(reader.Remaining >= byteLength); + ValidateRequestedDataAvaliable(byteLength); if (decoder == null) { @@ -515,13 +492,14 @@ private string ReadStringSlow(int byteLength) int initializedChars = 0; while (remainingByteLength > 0) { - int bytesRead = Math.Min(remainingByteLength, reader.UnreadSpan.Length); + var unreadSpan = LimitedUnreadSpan; + int bytesRead = Math.Min(remainingByteLength, unreadSpan.Length); remainingByteLength -= bytesRead; bool flush = remainingByteLength == 0; unsafe { - fixed (byte* pUnreadSpan = &MemoryMarshal.GetReference(reader.UnreadSpan)) + fixed (byte* pUnreadSpan = &MemoryMarshal.GetReference(unreadSpan)) fixed (char* pCharArray = &charArray[initializedChars]) { initializedChars += decoder.GetChars(pUnreadSpan, bytesRead, pCharArray, charArray.Length - initializedChars, flush); @@ -550,7 +528,7 @@ public void ReadMessage(IBufferMessage builder) { throw InvalidProtocolBufferException.RecursionLimitExceeded(); } - long oldLimit = PushLimit(length); + int oldLimit = PushLimit(length); ++recursionDepth; builder.MergeFrom(ref this); CheckReadEndOfInputTag(); @@ -589,24 +567,17 @@ public ByteString ReadBytes() return ByteString.Empty; } - ThrowEndOfInputIfFalse(reader.Remaining >= length); - if (length < 0) { throw InvalidProtocolBufferException.NegativeSize(); } - if (length + reader.Consumed > currentLimit) - { - // Read to the end of the limit. - reader.Advance(currentLimit); - // Then fail. - throw InvalidProtocolBufferException.TruncatedMessage(); - } + ValidateRequestedDataAvaliable(length); // Avoid creating a copy of Sequence if data is on current span - var data = (reader.UnreadSpan.Length >= length) - ? reader.UnreadSpan.Slice(0, length).ToArray() + var unreadSpan = LimitedUnreadSpan; + var data = (unreadSpan.Length >= length) + ? unreadSpan.Slice(0, length).ToArray() : reader.Sequence.Slice(reader.Position, length).ToArray(); reader.Advance(length); @@ -708,7 +679,7 @@ public bool MaybeConsumeTag(uint tag) // length:1 + tag:1 + value:4 = 6 bytes const int wrapperLength = 6; - var remaining = input.reader.UnreadSpan; + var remaining = input.LimitedUnreadSpan; if (remaining.Length >= wrapperLength) { // The entire wrapper message is already contained in `buffer`. @@ -766,7 +737,7 @@ public bool MaybeConsumeTag(uint tag) // length:1 + tag:1 + value:8 = 10 bytes const int wrapperLength = 10; - var remaining = input.reader.UnreadSpan; + var remaining = input.LimitedUnreadSpan; if (remaining.Length >= wrapperLength) { // The entire wrapper message is already contained in `buffer`. @@ -829,7 +800,7 @@ public bool MaybeConsumeTag(uint tag) // length:1 + tag:1 + value:5(varint32-max) = 7 bytes const int wrapperLength = 7; - var remaining = input.reader.UnreadSpan; + var remaining = input.LimitedUnreadSpan; if (remaining.Length >= wrapperLength) { // The entire wrapper message is already contained in `buffer`. @@ -904,7 +875,7 @@ public bool MaybeConsumeTag(uint tag) // length:1 + tag:1 + value:10(varint64-max) = 12 bytes const int wrapperLength = 12; - var remaining = input.reader.UnreadSpan; + var remaining = input.LimitedUnreadSpan; if (remaining.Length >= wrapperLength) { // The entire wrapper message is already contained in `buffer`. @@ -982,16 +953,14 @@ public bool MaybeConsumeTag(uint tag) /// private uint SlowReadRawVarint32() { - byte value; - - ThrowEndOfInputIfFalse(reader.TryRead(out value)); + byte value = ReadByteSlow(); int tmp = value; if (tmp < 128) { return (uint)tmp; } int result = tmp & 0x7f; - ThrowEndOfInputIfFalse(reader.TryRead(out value)); + value = ReadByteSlow(); tmp = value; if (tmp < 128) { @@ -1000,7 +969,7 @@ private uint SlowReadRawVarint32() else { result |= (tmp & 0x7f) << 7; - ThrowEndOfInputIfFalse(reader.TryRead(out value)); + value = ReadByteSlow(); tmp = value; if (tmp < 128) { @@ -1009,7 +978,7 @@ private uint SlowReadRawVarint32() else { result |= (tmp & 0x7f) << 14; - ThrowEndOfInputIfFalse(reader.TryRead(out value)); + value = ReadByteSlow(); tmp = value; if (tmp < 128) { @@ -1018,18 +987,18 @@ private uint SlowReadRawVarint32() else { result |= (tmp & 0x7f) << 21; - ThrowEndOfInputIfFalse(reader.TryRead(out value)); + value = ReadByteSlow(); tmp = value; result |= tmp << 28; if (tmp >= 128) { // Discard upper 32 bits. - // Note that this has to use ReadRawByte() as we only ensure we've + // Note that this has to use ReadByteSlow() as we only ensure we've // got at least 5 bytes at the start of the method. This lets us // use the fast path in more cases, and we rarely hit this section of code. for (int i = 0; i < 5; i++) { - ThrowEndOfInputIfFalse(reader.TryRead(out value)); + value = ReadByteSlow(); tmp = value; if (tmp < 128) { @@ -1052,7 +1021,7 @@ private uint SlowReadRawVarint32() /// internal uint ReadRawVarint32() { - var current = reader.UnreadSpan; + var current = LimitedUnreadSpan; if (current.Length < 5) { @@ -1094,12 +1063,12 @@ internal uint ReadRawVarint32() reader.Advance(bufferPos); // Discard upper 32 bits. - // Note that this has to use ReadRawByte() as we only ensure we've + // Note that this has to use ReadByteSlow() as we only ensure we've // got at least 5 bytes at the start of the method. This lets us // use the fast path in more cases, and we rarely hit this section of code. for (int i = 0; i < 5; i++) { - ThrowEndOfInputIfFalse(reader.TryRead(out var value)); + var value = ReadByteSlow(); tmp = value; if (tmp < 128) { @@ -1124,7 +1093,7 @@ private ulong SlowReadRawVarint64() ulong result = 0; while (shift < 64) { - ThrowEndOfInputIfFalse(reader.TryRead(out byte b)); + byte b = ReadByteSlow(); result |= (ulong)(b & 0x7F) << shift; if ((b & 0x80) == 0) { @@ -1140,7 +1109,7 @@ private ulong SlowReadRawVarint64() /// internal ulong ReadRawVarint64() { - var current = reader.UnreadSpan; + var current = LimitedUnreadSpan; if (current.Length < 10) { @@ -1179,7 +1148,7 @@ internal uint ReadRawLittleEndian32() { const int length = 4; - ReadOnlySpan current = reader.UnreadSpan; + ReadOnlySpan current = LimitedUnreadSpan; if (current.Length >= length) { // Fast path. All data is in the current span. @@ -1200,7 +1169,7 @@ private unsafe uint ReadRawLittleEndian32Slow() byte* buffer = stackalloc byte[length]; Span tempSpan = new Span(buffer, length); - ThrowEndOfInputIfFalse(reader.TryCopyTo(tempSpan)); + CopyToSlow(tempSpan); reader.Advance(length); return BinaryPrimitives.ReadUInt32LittleEndian(tempSpan); @@ -1213,7 +1182,7 @@ internal unsafe ulong ReadRawLittleEndian64() { const int length = 8; - ReadOnlySpan current = reader.UnreadSpan; + ReadOnlySpan current = LimitedUnreadSpan; if (current.Length >= length) { // Fast path. All data is in the current span. @@ -1234,7 +1203,7 @@ private unsafe ulong ReadRawLittleEndian64Slow() byte* buffer = stackalloc byte[length]; Span tempSpan = new Span(buffer, length); - ThrowEndOfInputIfFalse(reader.TryCopyTo(tempSpan)); + CopyToSlow(tempSpan); reader.Advance(length); return BinaryPrimitives.ReadUInt64LittleEndian(tempSpan); @@ -1247,15 +1216,15 @@ private unsafe ulong ReadRawLittleEndian64Slow() /// limit is returned. /// /// The old limit. - internal long PushLimit(long byteLimit) + internal int PushLimit(int byteLimit) { if (byteLimit < 0) { throw InvalidProtocolBufferException.NegativeSize(); } - byteLimit += reader.Consumed; - long oldLimit = currentLimit; + byteLimit += (int)reader.Consumed; + int oldLimit = currentLimit; if (byteLimit > oldLimit) { throw InvalidProtocolBufferException.TruncatedMessage(); @@ -1268,7 +1237,7 @@ internal long PushLimit(long byteLimit) /// /// Discards the current limit, returning the previous limit. /// - internal void PopLimit(long oldLimit) + internal void PopLimit(int oldLimit) { currentLimit = oldLimit; } @@ -1282,11 +1251,6 @@ internal bool ReachedLimit [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - if (currentLimit == long.MaxValue) - { - return false; - } - return reader.Consumed >= currentLimit; } } @@ -1304,6 +1268,76 @@ internal void CheckReadEndOfInputTag() throw InvalidProtocolBufferException.MoreDataAvailable(); } } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private void ThrowEndOfInputIfFalse(bool condition) + { + if (!condition) + { + ThrowEndOfInput(); + return; + } + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static void ThrowEndOfInput() + { + throw InvalidProtocolBufferException.TruncatedMessage(); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static void ThrowTruncatedMessage() + { + throw InvalidProtocolBufferException.TruncatedMessage(); + } + + private byte ReadByteSlow() + { + ThrowEndOfInputIfFalse(reader.TryRead(out byte b)); + + if (reader.Consumed > currentLimit) + { + ThrowTruncatedMessage(); + } + + return b; + } + + private void ValidateRequestedDataAvaliable(int length) + { + if (length + reader.Consumed > currentLimit) + { + // Read to the end of the limit. + reader.Advance(currentLimit); + // Then fail. + ThrowTruncatedMessage(); + } + if (reader.Remaining < length) + { + // Read to the end of the content. + reader.Advance(reader.Remaining); + // Then fail. + ThrowEndOfInput(); + } + } + + private void CopyToSlow(Span destination) + { + ValidateRequestedDataAvaliable(destination.Length); + + reader.TryCopyTo(destination); + } + + private ReadOnlySpan LimitedUnreadSpan + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { + // Get the current unread span content. This content is limited to content for the current message. + // When all the content we want to read is within the span's length then we can go down a fast path. + return reader.CurrentSpan.Slice(reader.CurrentSpanIndex, Math.Min(currentLimit, reader.CurrentSpan.Length) - reader.CurrentSpanIndex); + } + } } } #endif \ No newline at end of file diff --git a/csharp/src/Google.Protobuf/Collections/RepeatedField.cs b/csharp/src/Google.Protobuf/Collections/RepeatedField.cs index 392b5f4beb4a..3de33b817414 100644 --- a/csharp/src/Google.Protobuf/Collections/RepeatedField.cs +++ b/csharp/src/Google.Protobuf/Collections/RepeatedField.cs @@ -142,7 +142,7 @@ public void AddEntriesFrom(ref CodedInputReader input, FieldCodec codec) int length = input.ReadLength(); if (length > 0) { - long oldLimit = input.PushLimit(length); + int oldLimit = input.PushLimit(length); while (!input.ReachedLimit) { Add(reader(ref input)); diff --git a/csharp/src/Google.Protobuf/FieldCodec.cs b/csharp/src/Google.Protobuf/FieldCodec.cs index e292824d5a8a..a09cf59b62b4 100644 --- a/csharp/src/Google.Protobuf/FieldCodec.cs +++ b/csharp/src/Google.Protobuf/FieldCodec.cs @@ -891,7 +891,7 @@ internal static void Write(CodedOutputStream output, T value, FieldCodec c internal static T Read(ref CodedInputReader input, FieldCodec codec) { int length = input.ReadLength(); - long oldLimit = input.PushLimit(length); + int oldLimit = input.PushLimit(length); uint tag; T value = codec.DefaultValue; From bdf9f1abf7a085eb2b12e22777c3dc482359db69 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Sat, 25 Jan 2020 06:29:29 +1300 Subject: [PATCH 13/14] Fix tests --- csharp/src/Google.Protobuf/CodedInputReader.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/csharp/src/Google.Protobuf/CodedInputReader.cs b/csharp/src/Google.Protobuf/CodedInputReader.cs index 818ac8915831..525820741131 100644 --- a/csharp/src/Google.Protobuf/CodedInputReader.cs +++ b/csharp/src/Google.Protobuf/CodedInputReader.cs @@ -226,10 +226,6 @@ public uint ReadTag() // If we actually read a tag with a field of 0, that's not a valid tag. ThrowInvalidTagException(); } - if (ReachedLimit) - { - return 0; - } return lastTag; } @@ -1308,7 +1304,7 @@ private void ValidateRequestedDataAvaliable(int length) if (length + reader.Consumed > currentLimit) { // Read to the end of the limit. - reader.Advance(currentLimit); + reader.Advance(Math.Min(currentLimit, reader.Remaining)); // Then fail. ThrowTruncatedMessage(); } From 155774996be69135c05b30960e6ef016c530894c Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 27 Jan 2020 14:53:17 +0100 Subject: [PATCH 14/14] fix typo --- csharp/src/Google.Protobuf/CodedInputReader.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/csharp/src/Google.Protobuf/CodedInputReader.cs b/csharp/src/Google.Protobuf/CodedInputReader.cs index 525820741131..51a64cf45b8f 100644 --- a/csharp/src/Google.Protobuf/CodedInputReader.cs +++ b/csharp/src/Google.Protobuf/CodedInputReader.cs @@ -280,7 +280,7 @@ private void SkipRawBytes(int length) throw InvalidProtocolBufferException.NegativeSize(); } - ValidateRequestedDataAvaliable(length); + CheckRequestedDataAvailable(length); reader.Advance(length); } @@ -471,7 +471,7 @@ public string ReadString() /// The decoded string. private string ReadStringSlow(int byteLength) { - ValidateRequestedDataAvaliable(byteLength); + CheckRequestedDataAvailable(byteLength); if (decoder == null) { @@ -568,7 +568,7 @@ public ByteString ReadBytes() throw InvalidProtocolBufferException.NegativeSize(); } - ValidateRequestedDataAvaliable(length); + CheckRequestedDataAvailable(length); // Avoid creating a copy of Sequence if data is on current span var unreadSpan = LimitedUnreadSpan; @@ -1299,7 +1299,7 @@ private byte ReadByteSlow() return b; } - private void ValidateRequestedDataAvaliable(int length) + private void CheckRequestedDataAvailable(int length) { if (length + reader.Consumed > currentLimit) { @@ -1319,7 +1319,7 @@ private void ValidateRequestedDataAvaliable(int length) private void CopyToSlow(Span destination) { - ValidateRequestedDataAvaliable(destination.Length); + CheckRequestedDataAvailable(destination.Length); reader.TryCopyTo(destination); }