diff --git a/BUILD b/BUILD
index 996c334a37..224c8fce19 100644
--- a/BUILD
+++ b/BUILD
@@ -3,7 +3,6 @@
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test", "objc_library", native_cc_proto_library = "cc_proto_library")
load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain", "proto_library")
-load("@rules_proto//proto/private:native.bzl", "native_proto_common")
load("@rules_python//python:defs.bzl", "py_library")
load(":cc_proto_blacklist_test.bzl", "cc_proto_blacklist_test")
@@ -945,13 +944,9 @@ cc_library(
],
)
-# Note: We use `native_proto_common` here because we depend on an implementation-detail of
-# `proto_lang_toolchain`, which may not be available on `proto_common`.
-reject_blacklisted_files = hasattr(native_proto_common, "proto_lang_toolchain_rejects_files_do_not_use_or_we_will_break_you_without_mercy")
-cc_toolchain_blacklisted_protos = [proto + "_proto" for proto in WELL_KNOWN_PROTO_MAP.keys()] if reject_blacklisted_files else [":well_known_protos"]
proto_lang_toolchain(
name = "cc_toolchain",
- blacklisted_protos = cc_toolchain_blacklisted_protos,
+ blacklisted_protos = [proto + "_proto" for proto in WELL_KNOWN_PROTO_MAP.keys()],
command_line = "--cpp_out=$(OUT)",
runtime = ":protobuf",
visibility = ["//visibility:public"],
diff --git a/README.md b/README.md
index 2f42c6c934..d5155ae9ab 100644
--- a/README.md
+++ b/README.md
@@ -61,7 +61,7 @@ how to install protobuf runtime for that specific language:
| C# | [csharp](csharp) | [](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fcsharp%2Fcontinuous) | | [](https://ci.appveyor.com/project/protobuf/protobuf)
[](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fwindows%2Fcsharp_release%2Fcontinuous) |
| JavaScript | [js](js) | [](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fjavascript%2Fcontinuous) | [](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fmacos%2Fjavascript%2Fcontinuous) | |
| Ruby | [ruby](ruby) | [](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fruby23%2Fcontinuous)
[](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fruby24%2Fcontinuous)
[](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fruby25%2Fcontinuous)
[](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fruby26%2Fcontinuous)
[](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fruby_release%2Fcontinuous) | [](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fmacos%2Fruby23%2Fcontinuous)
[](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fmacos%2Fruby24%2Fcontinuous)
[](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fmacos%2Fruby25%2Fcontinuous)
[](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fmacos%2Fruby26%2Fcontinuous)
[](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fmacos%2Fruby_release%2Fcontinuous) | |
-| Go | [golang/protobuf](https://github.com/golang/protobuf) | | | |
+| Go | [protocolbuffers/protobuf-go](https://github.com/protocolbuffers/protobuf-go) | | | |
| PHP | [php](php) | [](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2Fphp_all%2Fcontinuous)
[](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fubuntu%2F32-bit%2Fcontinuous) | [](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fmacos%2Fphp5.6_mac%2Fcontinuous)
[](https://fusion.corp.google.com/projectanalysis/current/KOKORO/prod:protobuf%2Fgithub%2Fmaster%2Fmacos%2Fphp7.0_mac%2Fcontinuous) | |
| Dart | [dart-lang/protobuf](https://github.com/dart-lang/protobuf) | [](https://travis-ci.org/dart-lang/protobuf) | | |
diff --git a/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/CodedOutputStreamTest.cs b/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/CodedOutputStreamTest.cs
index f25e14e968..e9b4ea8cf0 100644
--- a/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/CodedOutputStreamTest.cs
+++ b/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/CodedOutputStreamTest.cs
@@ -211,35 +211,35 @@ namespace Google.Protobuf
[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)));
+ Assert.AreEqual(0u, WritingPrimitives.EncodeZigZag32(0));
+ Assert.AreEqual(1u, WritingPrimitives.EncodeZigZag32(-1));
+ Assert.AreEqual(2u, WritingPrimitives.EncodeZigZag32(1));
+ Assert.AreEqual(3u, WritingPrimitives.EncodeZigZag32(-2));
+ Assert.AreEqual(0x7FFFFFFEu, WritingPrimitives.EncodeZigZag32(0x3FFFFFFF));
+ Assert.AreEqual(0x7FFFFFFFu, WritingPrimitives.EncodeZigZag32(unchecked((int) 0xC0000000)));
+ Assert.AreEqual(0xFFFFFFFEu, WritingPrimitives.EncodeZigZag32(0x7FFFFFFF));
+ Assert.AreEqual(0xFFFFFFFFu, WritingPrimitives.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(0u, WritingPrimitives.EncodeZigZag64(0));
+ Assert.AreEqual(1u, WritingPrimitives.EncodeZigZag64(-1));
+ Assert.AreEqual(2u, WritingPrimitives.EncodeZigZag64(1));
+ Assert.AreEqual(3u, WritingPrimitives.EncodeZigZag64(-2));
Assert.AreEqual(0x000000007FFFFFFEuL,
- CodedOutputStream.EncodeZigZag64(unchecked((long) 0x000000003FFFFFFFUL)));
+ WritingPrimitives.EncodeZigZag64(unchecked((long) 0x000000003FFFFFFFUL)));
Assert.AreEqual(0x000000007FFFFFFFuL,
- CodedOutputStream.EncodeZigZag64(unchecked((long) 0xFFFFFFFFC0000000UL)));
+ WritingPrimitives.EncodeZigZag64(unchecked((long) 0xFFFFFFFFC0000000UL)));
Assert.AreEqual(0x00000000FFFFFFFEuL,
- CodedOutputStream.EncodeZigZag64(unchecked((long) 0x000000007FFFFFFFUL)));
+ WritingPrimitives.EncodeZigZag64(unchecked((long) 0x000000007FFFFFFFUL)));
Assert.AreEqual(0x00000000FFFFFFFFuL,
- CodedOutputStream.EncodeZigZag64(unchecked((long) 0xFFFFFFFF80000000UL)));
+ WritingPrimitives.EncodeZigZag64(unchecked((long) 0xFFFFFFFF80000000UL)));
Assert.AreEqual(0xFFFFFFFFFFFFFFFEL,
- CodedOutputStream.EncodeZigZag64(unchecked((long) 0x7FFFFFFFFFFFFFFFUL)));
+ WritingPrimitives.EncodeZigZag64(unchecked((long) 0x7FFFFFFFFFFFFFFFUL)));
Assert.AreEqual(0xFFFFFFFFFFFFFFFFL,
- CodedOutputStream.EncodeZigZag64(unchecked((long) 0x8000000000000000UL)));
+ WritingPrimitives.EncodeZigZag64(unchecked((long) 0x8000000000000000UL)));
}
[Test]
@@ -247,26 +247,26 @@ namespace Google.Protobuf
{
// Some easier-to-verify round-trip tests. The inputs (other than 0, 1, -1)
// were chosen semi-randomly via keyboard bashing.
- Assert.AreEqual(0, ParsingPrimitives.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(0)));
- Assert.AreEqual(1, ParsingPrimitives.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(1)));
- Assert.AreEqual(-1, ParsingPrimitives.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(-1)));
- Assert.AreEqual(14927, ParsingPrimitives.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(14927)));
- Assert.AreEqual(-3612, ParsingPrimitives.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(-3612)));
+ Assert.AreEqual(0, ParsingPrimitives.DecodeZigZag32(WritingPrimitives.EncodeZigZag32(0)));
+ Assert.AreEqual(1, ParsingPrimitives.DecodeZigZag32(WritingPrimitives.EncodeZigZag32(1)));
+ Assert.AreEqual(-1, ParsingPrimitives.DecodeZigZag32(WritingPrimitives.EncodeZigZag32(-1)));
+ Assert.AreEqual(14927, ParsingPrimitives.DecodeZigZag32(WritingPrimitives.EncodeZigZag32(14927)));
+ Assert.AreEqual(-3612, ParsingPrimitives.DecodeZigZag32(WritingPrimitives.EncodeZigZag32(-3612)));
}
[Test]
public void RoundTripZigZag64()
{
- Assert.AreEqual(0, ParsingPrimitives.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(0)));
- Assert.AreEqual(1, ParsingPrimitives.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(1)));
- Assert.AreEqual(-1, ParsingPrimitives.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(-1)));
- Assert.AreEqual(14927, ParsingPrimitives.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(14927)));
- Assert.AreEqual(-3612, ParsingPrimitives.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(-3612)));
+ Assert.AreEqual(0, ParsingPrimitives.DecodeZigZag64(WritingPrimitives.EncodeZigZag64(0)));
+ Assert.AreEqual(1, ParsingPrimitives.DecodeZigZag64(WritingPrimitives.EncodeZigZag64(1)));
+ Assert.AreEqual(-1, ParsingPrimitives.DecodeZigZag64(WritingPrimitives.EncodeZigZag64(-1)));
+ Assert.AreEqual(14927, ParsingPrimitives.DecodeZigZag64(WritingPrimitives.EncodeZigZag64(14927)));
+ Assert.AreEqual(-3612, ParsingPrimitives.DecodeZigZag64(WritingPrimitives.EncodeZigZag64(-3612)));
Assert.AreEqual(856912304801416L,
- ParsingPrimitives.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(856912304801416L)));
+ ParsingPrimitives.DecodeZigZag64(WritingPrimitives.EncodeZigZag64(856912304801416L)));
Assert.AreEqual(-75123905439571256L,
- ParsingPrimitives.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(-75123905439571256L)));
+ ParsingPrimitives.DecodeZigZag64(WritingPrimitives.EncodeZigZag64(-75123905439571256L)));
}
[Test]
@@ -395,7 +395,7 @@ namespace Google.Protobuf
Assert.IsTrue(memoryStream.CanWrite);
using (var cos = new CodedOutputStream(memoryStream))
{
- cos.WriteRawByte(0);
+ cos.WriteRawBytes(new byte[] {0});
Assert.AreEqual(0, memoryStream.Position); // Not flushed yet
}
Assert.AreEqual(1, memoryStream.ToArray().Length); // Flushed data from CodedOutputStream to MemoryStream
@@ -409,7 +409,7 @@ namespace Google.Protobuf
Assert.IsTrue(memoryStream.CanWrite);
using (var cos = new CodedOutputStream(memoryStream, true))
{
- cos.WriteRawByte(0);
+ cos.WriteRawBytes(new byte[] {0});
Assert.AreEqual(0, memoryStream.Position); // Not flushed yet
}
Assert.AreEqual(1, memoryStream.Position); // Flushed data from CodedOutputStream to MemoryStream
diff --git a/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/FieldCodecTest.cs b/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/FieldCodecTest.cs
index a5825a0708..18e8767217 100644
--- a/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/FieldCodecTest.cs
+++ b/csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/FieldCodecTest.cs
@@ -124,7 +124,16 @@ namespace Google.Protobuf
{
var stream = new MemoryStream();
var codedOutput = new CodedOutputStream(stream);
- codec.ValueWriter(codedOutput, sampleValue);
+ WriteContext.Initialize(codedOutput, out WriteContext ctx);
+ try
+ {
+ // only write the value using the codec
+ codec.ValueWriter(ref ctx, sampleValue);
+ }
+ finally
+ {
+ ctx.CopyStateTo(codedOutput);
+ }
codedOutput.Flush();
stream.Position = 0;
var codedInput = new CodedInputStream(stream);
@@ -172,7 +181,16 @@ namespace Google.Protobuf
if (codec.DefaultValue != null) // This part isn't appropriate for message types.
{
codedOutput = new CodedOutputStream(stream);
- codec.ValueWriter(codedOutput, codec.DefaultValue);
+ WriteContext.Initialize(codedOutput, out WriteContext ctx);
+ try
+ {
+ // only write the value using the codec
+ codec.ValueWriter(ref ctx, codec.DefaultValue);
+ }
+ finally
+ {
+ ctx.CopyStateTo(codedOutput);
+ }
codedOutput.Flush();
Assert.AreNotEqual(0, stream.Position);
Assert.AreEqual(stream.Position, codec.ValueSizeCalculator(codec.DefaultValue));
diff --git a/csharp/install_dotnet_sdk.ps1 b/csharp/install_dotnet_sdk.ps1
index 9e300eda06..8bc967c9f4 100755
--- a/csharp/install_dotnet_sdk.ps1
+++ b/csharp/install_dotnet_sdk.ps1
@@ -1,5 +1,5 @@
#!/usr/bin/env powershell
-# Install dotnet SDK based on the SDK version from global.json
+# Install dotnet SDK using the official dotnet-install.ps1 script
Set-StrictMode -Version 2
$ErrorActionPreference = 'Stop'
@@ -9,16 +9,12 @@ $ErrorActionPreference = 'Stop'
$InstallScriptUrl = 'https://dot.net/v1/dotnet-install.ps1'
$InstallScriptPath = Join-Path "$env:TEMP" 'dotnet-install.ps1'
-$GlobalJsonPath = Join-Path $PSScriptRoot '..' | Join-Path -ChildPath 'global.json'
-
-# Resolve SDK version from global.json file
-$GlobalJson = Get-Content -Raw $GlobalJsonPath | ConvertFrom-Json
-$SDKVersion = $GlobalJson.sdk.version
# Download install script
Write-Host "Downloading install script: $InstallScriptUrl => $InstallScriptPath"
Invoke-WebRequest -Uri $InstallScriptUrl -OutFile $InstallScriptPath
-&$InstallScriptPath -Version $SDKVersion
-# Also install dotnet SDK LTS which is required to run some of the tests
+# The SDK versions to install should be kept in sync with versions
+# installed by kokoro/linux/dockerfile/test/csharp/Dockerfile
&$InstallScriptPath -Version 2.1.802
+&$InstallScriptPath -Version 3.1.301
diff --git a/csharp/protos/unittest_issues.proto b/csharp/protos/unittest_issues.proto
index b4a88d8648..ef40d75fce 100644
--- a/csharp/protos/unittest_issues.proto
+++ b/csharp/protos/unittest_issues.proto
@@ -8,6 +8,8 @@ option csharp_namespace = "UnitTest.Issues.TestProtos";
package unittest_issues;
+import "google/protobuf/struct.proto";
+
// Issue 307: when generating doubly-nested types, any references
// should be of the form A.Types.B.Types.C.
message Issue307 {
@@ -137,4 +139,15 @@ message OneofMerging {
string text = 1;
Nested nested = 2;
}
-}
\ No newline at end of file
+}
+
+message NullValueOutsideStruct {
+ oneof value {
+ string string_value = 1;
+ google.protobuf.NullValue null_value = 2;
+ }
+}
+
+message NullValueNotInOneof {
+ google.protobuf.NullValue null_value = 2;
+}
diff --git a/csharp/src/AddressBook/Addressbook.cs b/csharp/src/AddressBook/Addressbook.cs
index 1b1c1b6c1f..042f69ee60 100644
--- a/csharp/src/AddressBook/Addressbook.cs
+++ b/csharp/src/AddressBook/Addressbook.cs
@@ -190,6 +190,9 @@ namespace Google.Protobuf.Examples.AddressBook {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Name.Length != 0) {
output.WriteRawTag(10);
output.WriteString(Name);
@@ -210,8 +213,35 @@ namespace Google.Protobuf.Examples.AddressBook {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
@@ -441,6 +471,9 @@ namespace Google.Protobuf.Examples.AddressBook {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Number.Length != 0) {
output.WriteRawTag(10);
output.WriteString(Number);
@@ -452,8 +485,26 @@ namespace Google.Protobuf.Examples.AddressBook {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
@@ -621,12 +672,26 @@ namespace Google.Protobuf.Examples.AddressBook {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
people_.WriteTo(output, _repeated_people_codec);
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
diff --git a/csharp/src/Google.Protobuf.Benchmarks/BenchmarkMessage1Proto3.cs b/csharp/src/Google.Protobuf.Benchmarks/BenchmarkMessage1Proto3.cs
index 6a213346a6..027da02a10 100644
--- a/csharp/src/Google.Protobuf.Benchmarks/BenchmarkMessage1Proto3.cs
+++ b/csharp/src/Google.Protobuf.Benchmarks/BenchmarkMessage1Proto3.cs
@@ -706,6 +706,9 @@ namespace Benchmarks.Proto3 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Field1.Length != 0) {
output.WriteRawTag(10);
output.WriteString(Field1);
@@ -870,7 +873,178 @@ namespace Benchmarks.Proto3 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -1851,6 +2025,9 @@ namespace Benchmarks.Proto3 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Field1 != 0) {
output.WriteRawTag(8);
output.WriteInt32(Field1);
@@ -1934,7 +2111,97 @@ namespace Benchmarks.Proto3 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
diff --git a/csharp/src/Google.Protobuf.Benchmarks/Benchmarks.cs b/csharp/src/Google.Protobuf.Benchmarks/Benchmarks.cs
index ce2248aed6..e2578f367f 100644
--- a/csharp/src/Google.Protobuf.Benchmarks/Benchmarks.cs
+++ b/csharp/src/Google.Protobuf.Benchmarks/Benchmarks.cs
@@ -176,6 +176,9 @@ namespace Benchmarks {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Name.Length != 0) {
output.WriteRawTag(10);
output.WriteString(Name);
@@ -188,7 +191,26 @@ namespace Benchmarks {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
diff --git a/csharp/src/Google.Protobuf.Benchmarks/Google.Protobuf.Benchmarks.csproj b/csharp/src/Google.Protobuf.Benchmarks/Google.Protobuf.Benchmarks.csproj
index 7432168210..e2fe2556f1 100644
--- a/csharp/src/Google.Protobuf.Benchmarks/Google.Protobuf.Benchmarks.csproj
+++ b/csharp/src/Google.Protobuf.Benchmarks/Google.Protobuf.Benchmarks.csproj
@@ -2,15 +2,17 @@
Exe
- netcoreapp2.1
+ netcoreapp3.1
../../keys/Google.Protobuf.snk
true
true
False
+ pdbonly
+ true
-
+
diff --git a/csharp/src/Google.Protobuf.Benchmarks/ParseMessagesBenchmark.cs b/csharp/src/Google.Protobuf.Benchmarks/ParseMessagesBenchmark.cs
index 92c3dbe5f0..8e6710b708 100644
--- a/csharp/src/Google.Protobuf.Benchmarks/ParseMessagesBenchmark.cs
+++ b/csharp/src/Google.Protobuf.Benchmarks/ParseMessagesBenchmark.cs
@@ -151,7 +151,7 @@ namespace Google.Protobuf.Benchmarks
repeatedFieldTest.ParseDelimitedMessagesFromReadOnlySequence(messageCount);
}
- private static ManyWrapperFieldsMessage CreateManyWrapperFieldsMessage()
+ public static ManyWrapperFieldsMessage CreateManyWrapperFieldsMessage()
{
// Example data match data of an internal benchmarks
return new ManyWrapperFieldsMessage()
@@ -168,7 +168,7 @@ namespace Google.Protobuf.Benchmarks
};
}
- private static ManyPrimitiveFieldsMessage CreateManyPrimitiveFieldsMessage()
+ public static ManyPrimitiveFieldsMessage CreateManyPrimitiveFieldsMessage()
{
// Example data match data of an internal benchmarks
return new ManyPrimitiveFieldsMessage()
@@ -185,7 +185,7 @@ namespace Google.Protobuf.Benchmarks
};
}
- private static GoogleMessage1 CreateRepeatedFieldMessage()
+ public static GoogleMessage1 CreateRepeatedFieldMessage()
{
// Message with a repeated fixed length item collection
var message = new GoogleMessage1();
diff --git a/csharp/src/Google.Protobuf.Benchmarks/ParseRawPrimitivesBenchmark.cs b/csharp/src/Google.Protobuf.Benchmarks/ParseRawPrimitivesBenchmark.cs
index 863e74dc49..2f226a323c 100644
--- a/csharp/src/Google.Protobuf.Benchmarks/ParseRawPrimitivesBenchmark.cs
+++ b/csharp/src/Google.Protobuf.Benchmarks/ParseRawPrimitivesBenchmark.cs
@@ -337,7 +337,7 @@ namespace Google.Protobuf.Benchmarks
CodedOutputStream cos = new CodedOutputStream(ms);
for (int i = 0; i < valueCount + paddingValueCount; i++)
{
- cos.WriteUInt64(RandomUnsignedVarint(random, encodedSize));
+ cos.WriteUInt64(RandomUnsignedVarint(random, encodedSize, false));
}
cos.Flush();
var buffer = ms.ToArray();
@@ -386,11 +386,11 @@ namespace Google.Protobuf.Benchmarks
///
/// Generate a random value that will take exactly "encodedSize" bytes when varint-encoded.
///
- private static ulong RandomUnsignedVarint(Random random, int encodedSize)
+ public static ulong RandomUnsignedVarint(Random random, int encodedSize, bool fitsIn32Bits)
{
Span randomBytesBuffer = stackalloc byte[8];
- if (encodedSize < 1 || encodedSize > 10)
+ if (encodedSize < 1 || encodedSize > 10 || (fitsIn32Bits && encodedSize > 5))
{
throw new ArgumentException("Illegal encodedSize value requested", nameof(encodedSize));
}
@@ -406,6 +406,12 @@ namespace Google.Protobuf.Benchmarks
ulong bitmask = encodedSize < 10 ? ((1UL << (encodedSize * bitsPerByte)) - 1) : ulong.MaxValue;
result = randomValue & bitmask;
+ if (fitsIn32Bits)
+ {
+ // make sure the resulting value is representable by a uint.
+ result &= uint.MaxValue;
+ }
+
if (encodedSize == 10)
{
// for 10-byte values the highest bit always needs to be set (7*9=63)
@@ -443,7 +449,7 @@ namespace Google.Protobuf.Benchmarks
return buffer;
}
- private static string CreateStringWithEncodedSize(int encodedSize)
+ public static string CreateStringWithEncodedSize(int encodedSize)
{
var str = new string('a', encodedSize);
while (CodedOutputStream.ComputeStringSize(str) > encodedSize)
@@ -457,5 +463,34 @@ namespace Google.Protobuf.Benchmarks
}
return str;
}
+
+ public static string CreateNonAsciiStringWithEncodedSize(int encodedSize)
+ {
+ if (encodedSize < 3)
+ {
+ throw new ArgumentException("Illegal encoded size for a string with non-ascii chars.");
+ }
+ var twoByteChar = '\u00DC'; // U-umlaut, UTF8 encoding has 2 bytes
+ var str = new string(twoByteChar, encodedSize / 2);
+ while (CodedOutputStream.ComputeStringSize(str) > encodedSize)
+ {
+ str = str.Substring(1);
+ }
+
+ // add padding of ascii characters to reach the desired encoded size.
+ while (CodedOutputStream.ComputeStringSize(str) < encodedSize)
+ {
+ str += 'a';
+ }
+
+ // Note that for a few specific encodedSize values, it might be impossible to generate
+ // the string with the desired encodedSize using the algorithm above. For testing purposes, checking that
+ // the encoded size we got is actually correct is good enough.
+ if (CodedOutputStream.ComputeStringSize(str) != encodedSize)
+ {
+ throw new InvalidOperationException($"Generated string with wrong encodedSize");
+ }
+ return str;
+ }
}
}
diff --git a/csharp/src/Google.Protobuf.Benchmarks/WrapperBenchmarkMessages.cs b/csharp/src/Google.Protobuf.Benchmarks/WrapperBenchmarkMessages.cs
index 95f613e1ba..9db92447ee 100644
--- a/csharp/src/Google.Protobuf.Benchmarks/WrapperBenchmarkMessages.cs
+++ b/csharp/src/Google.Protobuf.Benchmarks/WrapperBenchmarkMessages.cs
@@ -2073,6 +2073,9 @@ namespace Google.Protobuf.Benchmarks {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (doubleField1_ != null) {
_single_doubleField1_codec.WriteTagAndValue(output, DoubleField1);
}
@@ -2410,7 +2413,351 @@ namespace Google.Protobuf.Benchmarks {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -6495,6 +6842,9 @@ namespace Google.Protobuf.Benchmarks {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (DoubleField1 != 0D) {
output.WriteRawTag(9);
output.WriteDouble(DoubleField1);
@@ -6939,8 +7289,459 @@ namespace Google.Protobuf.Benchmarks {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (DoubleField1 != 0D) {
+ output.WriteRawTag(9);
+ output.WriteDouble(DoubleField1);
+ }
+ if (Int64Field2 != 0L) {
+ output.WriteRawTag(16);
+ output.WriteInt64(Int64Field2);
+ }
+ if (Int64Field3 != 0L) {
+ output.WriteRawTag(24);
+ output.WriteInt64(Int64Field3);
+ }
+ if (Int64Field4 != 0L) {
+ output.WriteRawTag(32);
+ output.WriteInt64(Int64Field4);
+ }
+ if (DoubleField7 != 0D) {
+ output.WriteRawTag(57);
+ output.WriteDouble(DoubleField7);
+ }
+ if (DoubleField8 != 0D) {
+ output.WriteRawTag(65);
+ output.WriteDouble(DoubleField8);
+ }
+ if (DoubleField9 != 0D) {
+ output.WriteRawTag(73);
+ output.WriteDouble(DoubleField9);
+ }
+ if (DoubleField10 != 0D) {
+ output.WriteRawTag(81);
+ output.WriteDouble(DoubleField10);
+ }
+ if (DoubleField11 != 0D) {
+ output.WriteRawTag(89);
+ output.WriteDouble(DoubleField11);
+ }
+ if (DoubleField14 != 0D) {
+ output.WriteRawTag(113);
+ output.WriteDouble(DoubleField14);
+ }
+ if (DoubleField15 != 0D) {
+ output.WriteRawTag(121);
+ output.WriteDouble(DoubleField15);
+ }
+ if (Int64Field19 != 0L) {
+ output.WriteRawTag(152, 1);
+ output.WriteInt64(Int64Field19);
+ }
+ if (DoubleField20 != 0D) {
+ output.WriteRawTag(161, 1);
+ output.WriteDouble(DoubleField20);
+ }
+ if (DoubleField21 != 0D) {
+ output.WriteRawTag(169, 1);
+ output.WriteDouble(DoubleField21);
+ }
+ if (DoubleField22 != 0D) {
+ output.WriteRawTag(177, 1);
+ output.WriteDouble(DoubleField22);
+ }
+ if (DoubleField25 != 0D) {
+ output.WriteRawTag(201, 1);
+ output.WriteDouble(DoubleField25);
+ }
+ if (Int64Field26 != 0L) {
+ output.WriteRawTag(208, 1);
+ output.WriteInt64(Int64Field26);
+ }
+ if (DoubleField28 != 0D) {
+ output.WriteRawTag(225, 1);
+ output.WriteDouble(DoubleField28);
+ }
+ if (DoubleField29 != 0D) {
+ output.WriteRawTag(233, 1);
+ output.WriteDouble(DoubleField29);
+ }
+ if (DoubleField30 != 0D) {
+ output.WriteRawTag(241, 1);
+ output.WriteDouble(DoubleField30);
+ }
+ if (DoubleField31 != 0D) {
+ output.WriteRawTag(249, 1);
+ output.WriteDouble(DoubleField31);
+ }
+ if (Int64Field32 != 0L) {
+ output.WriteRawTag(128, 2);
+ output.WriteInt64(Int64Field32);
+ }
+ if (Int64Field37 != 0L) {
+ output.WriteRawTag(168, 2);
+ output.WriteInt64(Int64Field37);
+ }
+ if (DoubleField38 != 0D) {
+ output.WriteRawTag(177, 2);
+ output.WriteDouble(DoubleField38);
+ }
+ if (Interactions != 0L) {
+ output.WriteRawTag(184, 2);
+ output.WriteInt64(Interactions);
+ }
+ if (DoubleField40 != 0D) {
+ output.WriteRawTag(193, 2);
+ output.WriteDouble(DoubleField40);
+ }
+ if (Int64Field41 != 0L) {
+ output.WriteRawTag(200, 2);
+ output.WriteInt64(Int64Field41);
+ }
+ if (DoubleField42 != 0D) {
+ output.WriteRawTag(209, 2);
+ output.WriteDouble(DoubleField42);
+ }
+ if (Int64Field43 != 0L) {
+ output.WriteRawTag(216, 2);
+ output.WriteInt64(Int64Field43);
+ }
+ if (Int64Field44 != 0L) {
+ output.WriteRawTag(224, 2);
+ output.WriteInt64(Int64Field44);
+ }
+ if (DoubleField45 != 0D) {
+ output.WriteRawTag(233, 2);
+ output.WriteDouble(DoubleField45);
+ }
+ if (DoubleField46 != 0D) {
+ output.WriteRawTag(241, 2);
+ output.WriteDouble(DoubleField46);
+ }
+ 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);
+ }
+ if (DoubleField50 != 0D) {
+ output.WriteRawTag(145, 3);
+ output.WriteDouble(DoubleField50);
+ }
+ if (DoubleField51 != 0D) {
+ output.WriteRawTag(153, 3);
+ output.WriteDouble(DoubleField51);
+ }
+ if (DoubleField52 != 0D) {
+ output.WriteRawTag(161, 3);
+ output.WriteDouble(DoubleField52);
+ }
+ if (DoubleField53 != 0D) {
+ output.WriteRawTag(169, 3);
+ output.WriteDouble(DoubleField53);
+ }
+ if (DoubleField54 != 0D) {
+ output.WriteRawTag(177, 3);
+ output.WriteDouble(DoubleField54);
+ }
+ if (DoubleField55 != 0D) {
+ output.WriteRawTag(185, 3);
+ output.WriteDouble(DoubleField55);
+ }
+ if (DoubleField56 != 0D) {
+ output.WriteRawTag(193, 3);
+ output.WriteDouble(DoubleField56);
+ }
+ if (DoubleField57 != 0D) {
+ output.WriteRawTag(201, 3);
+ output.WriteDouble(DoubleField57);
+ }
+ if (DoubleField58 != 0D) {
+ output.WriteRawTag(209, 3);
+ output.WriteDouble(DoubleField58);
+ }
+ if (Int64Field59 != 0L) {
+ output.WriteRawTag(216, 3);
+ output.WriteInt64(Int64Field59);
+ }
+ if (Int64Field60 != 0L) {
+ output.WriteRawTag(224, 3);
+ output.WriteInt64(Int64Field60);
+ }
+ if (DoubleField62 != 0D) {
+ output.WriteRawTag(241, 3);
+ output.WriteDouble(DoubleField62);
+ }
+ if (DoubleField65 != 0D) {
+ output.WriteRawTag(137, 4);
+ output.WriteDouble(DoubleField65);
+ }
+ if (DoubleField66 != 0D) {
+ output.WriteRawTag(145, 4);
+ output.WriteDouble(DoubleField66);
+ }
+ if (DoubleField67 != 0D) {
+ output.WriteRawTag(153, 4);
+ output.WriteDouble(DoubleField67);
+ }
+ if (DoubleField68 != 0D) {
+ output.WriteRawTag(161, 4);
+ output.WriteDouble(DoubleField68);
+ }
+ if (DoubleField69 != 0D) {
+ output.WriteRawTag(169, 4);
+ output.WriteDouble(DoubleField69);
+ }
+ if (DoubleField70 != 0D) {
+ output.WriteRawTag(177, 4);
+ output.WriteDouble(DoubleField70);
+ }
+ if (DoubleField71 != 0D) {
+ output.WriteRawTag(185, 4);
+ output.WriteDouble(DoubleField71);
+ }
+ if (DoubleField72 != 0D) {
+ output.WriteRawTag(193, 4);
+ output.WriteDouble(DoubleField72);
+ }
+ if (StringField73.Length != 0) {
+ output.WriteRawTag(202, 4);
+ output.WriteString(StringField73);
+ }
+ if (StringField74.Length != 0) {
+ output.WriteRawTag(210, 4);
+ output.WriteString(StringField74);
+ }
+ if (DoubleField75 != 0D) {
+ output.WriteRawTag(217, 4);
+ output.WriteDouble(DoubleField75);
+ }
+ if (DoubleField77 != 0D) {
+ output.WriteRawTag(233, 4);
+ output.WriteDouble(DoubleField77);
+ }
+ if (DoubleField78 != 0D) {
+ output.WriteRawTag(241, 4);
+ output.WriteDouble(DoubleField78);
+ }
+ if (DoubleField79 != 0D) {
+ output.WriteRawTag(249, 4);
+ output.WriteDouble(DoubleField79);
+ }
+ if (EnumField80 != 0) {
+ output.WriteRawTag(128, 5);
+ output.WriteInt32(EnumField80);
+ }
+ if (EnumField81 != 0) {
+ output.WriteRawTag(136, 5);
+ output.WriteInt32(EnumField81);
+ }
+ if (Int64Field82 != 0L) {
+ output.WriteRawTag(144, 5);
+ output.WriteInt64(Int64Field82);
+ }
+ if (EnumField83 != 0) {
+ output.WriteRawTag(152, 5);
+ output.WriteInt32(EnumField83);
+ }
+ if (DoubleField84 != 0D) {
+ output.WriteRawTag(161, 5);
+ output.WriteDouble(DoubleField84);
+ }
+ if (Int64Field85 != 0L) {
+ output.WriteRawTag(168, 5);
+ output.WriteInt64(Int64Field85);
+ }
+ if (Int64Field86 != 0L) {
+ output.WriteRawTag(176, 5);
+ output.WriteInt64(Int64Field86);
+ }
+ if (Int64Field87 != 0L) {
+ output.WriteRawTag(184, 5);
+ output.WriteInt64(Int64Field87);
+ }
+ if (DoubleField88 != 0D) {
+ output.WriteRawTag(193, 5);
+ output.WriteDouble(DoubleField88);
+ }
+ if (DoubleField89 != 0D) {
+ output.WriteRawTag(201, 5);
+ output.WriteDouble(DoubleField89);
+ }
+ if (DoubleField90 != 0D) {
+ output.WriteRawTag(209, 5);
+ output.WriteDouble(DoubleField90);
+ }
+ 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);
+ }
+ if (DoubleField94 != 0D) {
+ output.WriteRawTag(241, 5);
+ output.WriteDouble(DoubleField94);
+ }
+ if (DoubleField95 != 0D) {
+ output.WriteRawTag(249, 5);
+ output.WriteDouble(DoubleField95);
+ }
+ if (DoubleField96 != 0D) {
+ output.WriteRawTag(129, 6);
+ output.WriteDouble(DoubleField96);
+ }
+ if (DoubleField97 != 0D) {
+ output.WriteRawTag(137, 6);
+ output.WriteDouble(DoubleField97);
+ }
+ if (DoubleField98 != 0D) {
+ output.WriteRawTag(145, 6);
+ output.WriteDouble(DoubleField98);
+ }
+ if (DoubleField99 != 0D) {
+ output.WriteRawTag(153, 6);
+ output.WriteDouble(DoubleField99);
+ }
+ repeatedIntField100_.WriteTo(ref output, _repeated_repeatedIntField100_codec);
+ if (DoubleField101 != 0D) {
+ output.WriteRawTag(169, 6);
+ output.WriteDouble(DoubleField101);
+ }
+ if (DoubleField102 != 0D) {
+ output.WriteRawTag(177, 6);
+ output.WriteDouble(DoubleField102);
+ }
+ if (DoubleField103 != 0D) {
+ output.WriteRawTag(185, 6);
+ output.WriteDouble(DoubleField103);
+ }
+ if (DoubleField104 != 0D) {
+ output.WriteRawTag(193, 6);
+ output.WriteDouble(DoubleField104);
+ }
+ if (DoubleField105 != 0D) {
+ output.WriteRawTag(201, 6);
+ output.WriteDouble(DoubleField105);
+ }
+ if (DoubleField106 != 0D) {
+ output.WriteRawTag(209, 6);
+ output.WriteDouble(DoubleField106);
+ }
+ if (Int64Field107 != 0L) {
+ output.WriteRawTag(216, 6);
+ output.WriteInt64(Int64Field107);
+ }
+ if (DoubleField108 != 0D) {
+ output.WriteRawTag(225, 6);
+ output.WriteDouble(DoubleField108);
+ }
+ if (DoubleField109 != 0D) {
+ output.WriteRawTag(233, 6);
+ output.WriteDouble(DoubleField109);
+ }
+ if (Int64Field110 != 0L) {
+ output.WriteRawTag(240, 6);
+ output.WriteInt64(Int64Field110);
+ }
+ if (DoubleField111 != 0D) {
+ output.WriteRawTag(249, 6);
+ output.WriteDouble(DoubleField111);
+ }
+ if (Int64Field112 != 0L) {
+ output.WriteRawTag(128, 7);
+ output.WriteInt64(Int64Field112);
+ }
+ 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);
+ }
+ if (DoubleField116 != 0D) {
+ output.WriteRawTag(161, 7);
+ output.WriteDouble(DoubleField116);
+ }
+ 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 (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
+ }
+ #endif
+
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
diff --git a/csharp/src/Google.Protobuf.Benchmarks/WriteMessagesBenchmark.cs b/csharp/src/Google.Protobuf.Benchmarks/WriteMessagesBenchmark.cs
new file mode 100644
index 0000000000..5a3bba74d2
--- /dev/null
+++ b/csharp/src/Google.Protobuf.Benchmarks/WriteMessagesBenchmark.cs
@@ -0,0 +1,198 @@
+#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 BenchmarkDotNet.Attributes;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Buffers;
+using Google.Protobuf.WellKnownTypes;
+
+namespace Google.Protobuf.Benchmarks
+{
+ ///
+ /// Benchmark that tests writing performance for various messages.
+ ///
+ [MemoryDiagnoser]
+ public class WriteMessagesBenchmark
+ {
+ const int MaxMessages = 100;
+
+ SubTest manyWrapperFieldsTest = new SubTest(ParseMessagesBenchmark.CreateManyWrapperFieldsMessage(), MaxMessages);
+ SubTest manyPrimitiveFieldsTest = new SubTest(ParseMessagesBenchmark.CreateManyPrimitiveFieldsMessage(), MaxMessages);
+ SubTest emptyMessageTest = new SubTest(new Empty(), MaxMessages);
+
+ public IEnumerable MessageCountValues => new[] { 10, 100 };
+
+ [GlobalSetup]
+ public void GlobalSetup()
+ {
+ }
+
+ [Benchmark]
+ public byte[] ManyWrapperFieldsMessage_ToByteArray()
+ {
+ return manyWrapperFieldsTest.ToByteArray();
+ }
+
+ [Benchmark]
+ public byte[] ManyWrapperFieldsMessage_WriteToCodedOutputStream()
+ {
+ return manyWrapperFieldsTest.WriteToCodedOutputStream_PreAllocatedBuffer();
+ }
+
+ [Benchmark]
+ public byte[] ManyWrapperFieldsMessage_WriteToSpan()
+ {
+ return manyWrapperFieldsTest.WriteToSpan_PreAllocatedBuffer();
+ }
+
+
+ [Benchmark]
+ public byte[] ManyPrimitiveFieldsMessage_ToByteArray()
+ {
+ return manyPrimitiveFieldsTest.ToByteArray();
+ }
+
+ [Benchmark]
+ public byte[] ManyPrimitiveFieldsMessage_WriteToCodedOutputStream()
+ {
+ return manyPrimitiveFieldsTest.WriteToCodedOutputStream_PreAllocatedBuffer();
+ }
+
+ [Benchmark]
+ public byte[] ManyPrimitiveFieldsMessage_WriteToSpan()
+ {
+ return manyPrimitiveFieldsTest.WriteToSpan_PreAllocatedBuffer();
+ }
+
+ [Benchmark]
+ public byte[] EmptyMessage_ToByteArray()
+ {
+ return emptyMessageTest.ToByteArray();
+ }
+
+ [Benchmark]
+ public byte[] EmptyMessage_WriteToCodedOutputStream()
+ {
+ return emptyMessageTest.WriteToCodedOutputStream_PreAllocatedBuffer();
+ }
+
+ [Benchmark]
+ public byte[] EmptyMessage_WriteToSpan()
+ {
+ return emptyMessageTest.WriteToSpan_PreAllocatedBuffer();
+ }
+
+ [Benchmark]
+ [ArgumentsSource(nameof(MessageCountValues))]
+ public void ManyWrapperFieldsMessage_WriteDelimitedMessagesToCodedOutputStream(int messageCount)
+ {
+ manyWrapperFieldsTest.WriteDelimitedMessagesToCodedOutputStream_PreAllocatedBuffer(messageCount);
+ }
+
+ [Benchmark]
+ [ArgumentsSource(nameof(MessageCountValues))]
+ public void ManyWrapperFieldsMessage_WriteDelimitedMessagesToSpan(int messageCount)
+ {
+ manyWrapperFieldsTest.WriteDelimitedMessagesToSpan_PreAllocatedBuffer(messageCount);
+ }
+
+ [Benchmark]
+ [ArgumentsSource(nameof(MessageCountValues))]
+ public void ManyPrimitiveFieldsMessage_WriteDelimitedMessagesToCodedOutputStream(int messageCount)
+ {
+ manyPrimitiveFieldsTest.WriteDelimitedMessagesToCodedOutputStream_PreAllocatedBuffer(messageCount);
+ }
+
+ [Benchmark]
+ [ArgumentsSource(nameof(MessageCountValues))]
+ public void ManyPrimitiveFieldsMessage_WriteDelimitedMessagesToSpan(int messageCount)
+ {
+ manyPrimitiveFieldsTest.WriteDelimitedMessagesToSpan_PreAllocatedBuffer(messageCount);
+ }
+
+ private class SubTest
+ {
+ private readonly IMessage message;
+ private readonly byte[] outputBuffer;
+ private readonly byte[] multipleMessagesOutputBuffer;
+
+ public SubTest(IMessage message, int maxMessageCount)
+ {
+ this.message = message;
+
+ int messageSize = message.CalculateSize();
+ this.outputBuffer = new byte[messageSize];
+ this.multipleMessagesOutputBuffer = new byte[maxMessageCount * (messageSize + CodedOutputStream.ComputeLengthSize(messageSize))];
+ }
+
+ public byte[] ToByteArray() => message.ToByteArray();
+
+ public byte[] WriteToCodedOutputStream_PreAllocatedBuffer()
+ {
+ var cos = new CodedOutputStream(outputBuffer); // use pre-existing output buffer
+ message.WriteTo(cos);
+ return outputBuffer;
+ }
+
+ public byte[] WriteToSpan_PreAllocatedBuffer()
+ {
+ var span = new Span(outputBuffer); // use pre-existing output buffer
+ message.WriteTo(span);
+ return outputBuffer;
+ }
+
+ public byte[] WriteDelimitedMessagesToCodedOutputStream_PreAllocatedBuffer(int messageCount)
+ {
+ var cos = new CodedOutputStream(multipleMessagesOutputBuffer); // use pre-existing output buffer
+ for (int i = 0; i < messageCount; i++)
+ {
+ cos.WriteMessage(message);
+ }
+ return multipleMessagesOutputBuffer;
+ }
+
+ public byte[] WriteDelimitedMessagesToSpan_PreAllocatedBuffer(int messageCount)
+ {
+ var span = new Span(multipleMessagesOutputBuffer); // use pre-existing output buffer
+ WriteContext.Initialize(ref span, out WriteContext ctx);
+ for (int i = 0; i < messageCount; i++)
+ {
+ ctx.WriteMessage(message);
+ }
+ return multipleMessagesOutputBuffer;
+ }
+ }
+ }
+}
diff --git a/csharp/src/Google.Protobuf.Benchmarks/WriteRawPrimitivesBenchmark.cs b/csharp/src/Google.Protobuf.Benchmarks/WriteRawPrimitivesBenchmark.cs
new file mode 100644
index 0000000000..66b6b4a028
--- /dev/null
+++ b/csharp/src/Google.Protobuf.Benchmarks/WriteRawPrimitivesBenchmark.cs
@@ -0,0 +1,519 @@
+#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 BenchmarkDotNet.Attributes;
+using System;
+using System.Buffers.Binary;
+using System.Collections.Generic;
+using System.IO;
+using System.Buffers;
+using System.Text;
+
+namespace Google.Protobuf.Benchmarks
+{
+ ///
+ /// Benchmarks throughput when writing raw primitives.
+ ///
+ [MemoryDiagnoser]
+ public class WriteRawPrimitivesBenchmark
+ {
+ // key is the encodedSize of varint values
+ Dictionary varint32Values;
+ Dictionary varint64Values;
+
+ double[] doubleValues;
+ float[] floatValues;
+
+ // key is the encodedSize of string values
+ Dictionary stringValues;
+
+ // key is the encodedSize of string values
+ Dictionary nonAsciiStringValues;
+
+ // key is the encodedSize of string values
+ Dictionary byteStringValues;
+
+ // the buffer to which all the data will be written
+ byte[] outputBuffer;
+
+ Random random = new Random(417384220); // random but deterministic seed
+
+ public IEnumerable StringEncodedSizes => new[] { 1, 4, 10, 105, 10080 };
+
+ public IEnumerable NonAsciiStringEncodedSizes => new[] { 4, 10, 105, 10080 };
+
+ [GlobalSetup]
+ public void GlobalSetup()
+ {
+ outputBuffer = new byte[BytesToWrite];
+
+ varint32Values = new Dictionary();
+ varint64Values = new Dictionary();
+ for (int encodedSize = 1; encodedSize <= 10; encodedSize++)
+ {
+ if (encodedSize <= 5)
+ {
+ varint32Values.Add(encodedSize, CreateRandomVarints32(random, BytesToWrite / encodedSize, encodedSize));
+ }
+ varint64Values.Add(encodedSize, CreateRandomVarints64(random, BytesToWrite / encodedSize, encodedSize));
+ }
+
+ doubleValues = CreateRandomDoubles(random, BytesToWrite / sizeof(double));
+ floatValues = CreateRandomFloats(random, BytesToWrite / sizeof(float));
+
+ stringValues = new Dictionary();
+
+ byteStringValues = new Dictionary();
+ foreach(var encodedSize in StringEncodedSizes)
+ {
+ stringValues.Add(encodedSize, CreateStrings(BytesToWrite / encodedSize, encodedSize));
+ byteStringValues.Add(encodedSize, CreateByteStrings(BytesToWrite / encodedSize, encodedSize));
+ }
+
+ nonAsciiStringValues = new Dictionary();
+ foreach(var encodedSize in NonAsciiStringEncodedSizes)
+ {
+ nonAsciiStringValues.Add(encodedSize, CreateNonAsciiStrings(BytesToWrite / encodedSize, encodedSize));
+ }
+ }
+
+ // Total number of bytes that each benchmark will write.
+ // Measuring the time taken to write buffer of given size makes it easier to compare parsing speed for different
+ // types and makes it easy to calculate the througput (in MB/s)
+ // 10800 bytes is chosen because it is divisible by all possible encoded sizes for all primitive types {1..10}
+ [Params(10080)]
+ public int BytesToWrite { get; set; }
+
+ [Benchmark]
+ [Arguments(1)]
+ [Arguments(2)]
+ [Arguments(3)]
+ [Arguments(4)]
+ [Arguments(5)]
+ public void WriteRawVarint32_CodedOutputStream(int encodedSize)
+ {
+ var values = varint32Values[encodedSize];
+ var cos = new CodedOutputStream(outputBuffer);
+ for (int i = 0; i < values.Length; i++)
+ {
+ cos.WriteRawVarint32(values[i]);
+ }
+ cos.Flush();
+ cos.CheckNoSpaceLeft();
+ }
+
+ [Benchmark]
+ [Arguments(1)]
+ [Arguments(2)]
+ [Arguments(3)]
+ [Arguments(4)]
+ [Arguments(5)]
+ public void WriteRawVarint32_WriteContext(int encodedSize)
+ {
+ var values = varint32Values[encodedSize];
+ var span = new Span(outputBuffer);
+ WriteContext.Initialize(ref span, out WriteContext ctx);
+ for (int i = 0; i < values.Length; i++)
+ {
+ ctx.WriteUInt32(values[i]);
+ }
+ ctx.Flush();
+ ctx.CheckNoSpaceLeft();
+ }
+
+ [Benchmark]
+ [Arguments(1)]
+ [Arguments(2)]
+ [Arguments(3)]
+ [Arguments(4)]
+ [Arguments(5)]
+ [Arguments(6)]
+ [Arguments(7)]
+ [Arguments(8)]
+ [Arguments(9)]
+ [Arguments(10)]
+ public void WriteRawVarint64_CodedOutputStream(int encodedSize)
+ {
+ var values = varint64Values[encodedSize];
+ var cos = new CodedOutputStream(outputBuffer);
+ for (int i = 0; i < values.Length; i++)
+ {
+ cos.WriteRawVarint64(values[i]);
+ }
+ cos.Flush();
+ cos.CheckNoSpaceLeft();
+ }
+
+ [Benchmark]
+ [Arguments(1)]
+ [Arguments(2)]
+ [Arguments(3)]
+ [Arguments(4)]
+ [Arguments(5)]
+ [Arguments(6)]
+ [Arguments(7)]
+ [Arguments(8)]
+ [Arguments(9)]
+ [Arguments(10)]
+ public void WriteRawVarint64_WriteContext(int encodedSize)
+ {
+ var values = varint64Values[encodedSize];
+ var span = new Span(outputBuffer);
+ WriteContext.Initialize(ref span, out WriteContext ctx);
+ for (int i = 0; i < values.Length; i++)
+ {
+ ctx.WriteUInt64(values[i]);
+ }
+ ctx.Flush();
+ ctx.CheckNoSpaceLeft();
+ }
+
+ [Benchmark]
+ public void WriteFixed32_CodedOutputStream()
+ {
+ const int encodedSize = sizeof(uint);
+ var cos = new CodedOutputStream(outputBuffer);
+ for (int i = 0; i < BytesToWrite / encodedSize; i++)
+ {
+ cos.WriteFixed32(12345);
+ }
+ cos.Flush();
+ cos.CheckNoSpaceLeft();
+ }
+
+ [Benchmark]
+ public void WriteFixed32_WriteContext()
+ {
+ const int encodedSize = sizeof(uint);
+ var span = new Span(outputBuffer);
+ WriteContext.Initialize(ref span, out WriteContext ctx);
+ for (uint i = 0; i < BytesToWrite / encodedSize; i++)
+ {
+ ctx.WriteFixed32(12345);
+ }
+ ctx.Flush();
+ ctx.CheckNoSpaceLeft();
+ }
+
+ [Benchmark]
+ public void WriteFixed64_CodedOutputStream()
+ {
+ const int encodedSize = sizeof(ulong);
+ var cos = new CodedOutputStream(outputBuffer);
+ for(int i = 0; i < BytesToWrite / encodedSize; i++)
+ {
+ cos.WriteFixed64(123456789);
+ }
+ cos.Flush();
+ cos.CheckNoSpaceLeft();
+ }
+
+ [Benchmark]
+ public void WriteFixed64_WriteContext()
+ {
+ const int encodedSize = sizeof(ulong);
+ var span = new Span(outputBuffer);
+ WriteContext.Initialize(ref span, out WriteContext ctx);
+ for (uint i = 0; i < BytesToWrite / encodedSize; i++)
+ {
+ ctx.WriteFixed64(123456789);
+ }
+ ctx.Flush();
+ ctx.CheckNoSpaceLeft();
+ }
+
+ [Benchmark]
+ public void WriteRawTag_OneByte_WriteContext()
+ {
+ const int encodedSize = 1;
+ var span = new Span(outputBuffer);
+ WriteContext.Initialize(ref span, out WriteContext ctx);
+ for (uint i = 0; i < BytesToWrite / encodedSize; i++)
+ {
+ ctx.WriteRawTag(16);
+ }
+ ctx.Flush();
+ ctx.CheckNoSpaceLeft();
+ }
+
+ [Benchmark]
+ public void WriteRawTag_TwoBytes_WriteContext()
+ {
+ const int encodedSize = 2;
+ var span = new Span(outputBuffer);
+ WriteContext.Initialize(ref span, out WriteContext ctx);
+ for (uint i = 0; i < BytesToWrite / encodedSize; i++)
+ {
+ ctx.WriteRawTag(137, 6);
+ }
+ ctx.Flush();
+ ctx.CheckNoSpaceLeft();
+ }
+
+ [Benchmark]
+ public void WriteRawTag_ThreeBytes_WriteContext()
+ {
+ const int encodedSize = 3;
+ var span = new Span(outputBuffer);
+ WriteContext.Initialize(ref span, out WriteContext ctx);
+ for (uint i = 0; i < BytesToWrite / encodedSize; i++)
+ {
+ ctx.WriteRawTag(160, 131, 1);
+ }
+ ctx.Flush();
+ ctx.CheckNoSpaceLeft();
+ }
+
+ [Benchmark]
+ public void Baseline_WriteContext()
+ {
+ var span = new Span(outputBuffer);
+ WriteContext.Initialize(ref span, out WriteContext ctx);
+ ctx.state.position = outputBuffer.Length;
+ ctx.Flush();
+ ctx.CheckNoSpaceLeft();
+ }
+
+ [Benchmark]
+ public void WriteRawFloat_CodedOutputStream()
+ {
+ var cos = new CodedOutputStream(outputBuffer);
+ foreach (var value in floatValues)
+ {
+ cos.WriteFloat(value);
+ }
+ cos.Flush();
+ cos.CheckNoSpaceLeft();
+ }
+
+ [Benchmark]
+ public void WriteRawFloat_WriteContext()
+ {
+ var span = new Span(outputBuffer);
+ WriteContext.Initialize(ref span, out WriteContext ctx);
+ foreach (var value in floatValues)
+ {
+ ctx.WriteFloat(value);
+ }
+ ctx.Flush();
+ ctx.CheckNoSpaceLeft();
+ }
+
+ [Benchmark]
+ public void WriteRawDouble_CodedOutputStream()
+ {
+ var cos = new CodedOutputStream(outputBuffer);
+ foreach (var value in doubleValues)
+ {
+ cos.WriteDouble(value);
+ }
+ cos.Flush();
+ cos.CheckNoSpaceLeft();
+ }
+
+ [Benchmark]
+ public void WriteRawDouble_WriteContext()
+ {
+ var span = new Span(outputBuffer);
+ WriteContext.Initialize(ref span, out WriteContext ctx);
+ foreach (var value in doubleValues)
+ {
+ ctx.WriteDouble(value);
+ }
+ ctx.Flush();
+ ctx.CheckNoSpaceLeft();
+ }
+
+ [Benchmark]
+ [ArgumentsSource(nameof(StringEncodedSizes))]
+ public void WriteString_CodedOutputStream(int encodedSize)
+ {
+ var values = stringValues[encodedSize];
+ var cos = new CodedOutputStream(outputBuffer);
+ foreach (var value in values)
+ {
+ cos.WriteString(value);
+ }
+ cos.Flush();
+ cos.CheckNoSpaceLeft();
+ }
+
+ [Benchmark]
+ [ArgumentsSource(nameof(StringEncodedSizes))]
+ public void WriteString_WriteContext(int encodedSize)
+ {
+ var values = stringValues[encodedSize];
+ var span = new Span(outputBuffer);
+ WriteContext.Initialize(ref span, out WriteContext ctx);
+ foreach (var value in values)
+ {
+ ctx.WriteString(value);
+ }
+ ctx.Flush();
+ ctx.CheckNoSpaceLeft();
+ }
+
+ [Benchmark]
+ [ArgumentsSource(nameof(NonAsciiStringEncodedSizes))]
+ public void WriteNonAsciiString_CodedOutputStream(int encodedSize)
+ {
+ var values = nonAsciiStringValues[encodedSize];
+ var cos = new CodedOutputStream(outputBuffer);
+ foreach (var value in values)
+ {
+ cos.WriteString(value);
+ }
+ cos.Flush();
+ cos.CheckNoSpaceLeft();
+ }
+
+ [Benchmark]
+ [ArgumentsSource(nameof(NonAsciiStringEncodedSizes))]
+ public void WriteNonAsciiString_WriteContext(int encodedSize)
+ {
+ var values = nonAsciiStringValues[encodedSize];
+ var span = new Span(outputBuffer);
+ WriteContext.Initialize(ref span, out WriteContext ctx);
+ foreach (var value in values)
+ {
+ ctx.WriteString(value);
+ }
+ ctx.Flush();
+ ctx.CheckNoSpaceLeft();
+ }
+
+ [Benchmark]
+ [ArgumentsSource(nameof(StringEncodedSizes))]
+ public void WriteBytes_CodedOutputStream(int encodedSize)
+ {
+ var values = byteStringValues[encodedSize];
+ var cos = new CodedOutputStream(outputBuffer);
+ foreach (var value in values)
+ {
+ cos.WriteBytes(value);
+ }
+ cos.Flush();
+ cos.CheckNoSpaceLeft();
+ }
+
+ [Benchmark]
+ [ArgumentsSource(nameof(StringEncodedSizes))]
+ public void WriteBytes_WriteContext(int encodedSize)
+ {
+ var values = byteStringValues[encodedSize];
+ var span = new Span(outputBuffer);
+ WriteContext.Initialize(ref span, out WriteContext ctx);
+ foreach (var value in values)
+ {
+ ctx.WriteBytes(value);
+ }
+ ctx.Flush();
+ ctx.CheckNoSpaceLeft();
+ }
+
+ private static uint[] CreateRandomVarints32(Random random, int valueCount, int encodedSize)
+ {
+ var result = new uint[valueCount];
+ for (int i = 0; i < valueCount; i++)
+ {
+ result[i] = (uint) ParseRawPrimitivesBenchmark.RandomUnsignedVarint(random, encodedSize, true);
+ }
+ return result;
+ }
+
+ private static ulong[] CreateRandomVarints64(Random random, int valueCount, int encodedSize)
+ {
+ var result = new ulong[valueCount];
+ for (int i = 0; i < valueCount; i++)
+ {
+ result[i] = ParseRawPrimitivesBenchmark.RandomUnsignedVarint(random, encodedSize, false);
+ }
+ return result;
+ }
+
+ private static float[] CreateRandomFloats(Random random, int valueCount)
+ {
+ var result = new float[valueCount];
+ for (int i = 0; i < valueCount; i++)
+ {
+ result[i] = (float)random.NextDouble();
+ }
+ return result;
+ }
+
+ private static double[] CreateRandomDoubles(Random random, int valueCount)
+ {
+ var result = new double[valueCount];
+ for (int i = 0; i < valueCount; i++)
+ {
+ result[i] = random.NextDouble();
+ }
+ return result;
+ }
+
+ private static string[] CreateStrings(int valueCount, int encodedSize)
+ {
+ var str = ParseRawPrimitivesBenchmark.CreateStringWithEncodedSize(encodedSize);
+
+ var result = new string[valueCount];
+ for (int i = 0; i < valueCount; i++)
+ {
+ result[i] = str;
+ }
+ return result;
+ }
+
+ private static string[] CreateNonAsciiStrings(int valueCount, int encodedSize)
+ {
+ var str = ParseRawPrimitivesBenchmark.CreateNonAsciiStringWithEncodedSize(encodedSize);
+
+ var result = new string[valueCount];
+ for (int i = 0; i < valueCount; i++)
+ {
+ result[i] = str;
+ }
+ return result;
+ }
+
+ private static ByteString[] CreateByteStrings(int valueCount, int encodedSize)
+ {
+ var str = ParseRawPrimitivesBenchmark.CreateStringWithEncodedSize(encodedSize);
+
+ var result = new ByteString[valueCount];
+ for (int i = 0; i < valueCount; i++)
+ {
+ result[i] = ByteString.CopyFrom(Encoding.UTF8.GetBytes(str));
+ }
+ return result;
+ }
+ }
+}
diff --git a/csharp/src/Google.Protobuf.Conformance/Conformance.cs b/csharp/src/Google.Protobuf.Conformance/Conformance.cs
index 2c0846643e..f26d181a98 100644
--- a/csharp/src/Google.Protobuf.Conformance/Conformance.cs
+++ b/csharp/src/Google.Protobuf.Conformance/Conformance.cs
@@ -189,11 +189,25 @@ namespace Conformance {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
failure_.WriteTo(output, _repeated_failure_codec);
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ failure_.WriteTo(ref output, _repeated_failure_codec);
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -513,6 +527,9 @@ namespace Conformance {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (payloadCase_ == PayloadOneofCase.ProtobufPayload) {
output.WriteRawTag(10);
output.WriteBytes(ProtobufPayload);
@@ -552,7 +569,53 @@ namespace Conformance {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -1009,6 +1072,9 @@ namespace Conformance {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (resultCase_ == ResultOneofCase.ParseError) {
output.WriteRawTag(10);
output.WriteString(ParseError);
@@ -1044,7 +1110,49 @@ namespace Conformance {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -1299,6 +1407,9 @@ namespace Conformance {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (UseJspbArrayAnyFormat != false) {
output.WriteRawTag(8);
output.WriteBool(UseJspbArrayAnyFormat);
@@ -1306,7 +1417,21 @@ namespace Conformance {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/MapUnittestProto3.cs b/csharp/src/Google.Protobuf.Test.TestProtos/MapUnittestProto3.cs
index 308ccbd649..bbf0061f88 100644
--- a/csharp/src/Google.Protobuf.Test.TestProtos/MapUnittestProto3.cs
+++ b/csharp/src/Google.Protobuf.Test.TestProtos/MapUnittestProto3.cs
@@ -466,6 +466,9 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
mapInt32Int32_.WriteTo(output, _map_mapInt32Int32_codec);
mapInt64Int64_.WriteTo(output, _map_mapInt64Int64_codec);
mapUint32Uint32_.WriteTo(output, _map_mapUint32Uint32_codec);
@@ -486,7 +489,34 @@ namespace Google.Protobuf.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -790,6 +820,9 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (testMap_ != null) {
output.WriteRawTag(10);
output.WriteMessage(TestMap);
@@ -797,8 +830,22 @@ namespace Google.Protobuf.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
@@ -953,11 +1000,25 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
mapInt32Message_.WriteTo(output, _map_mapInt32Message_codec);
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ mapInt32Message_.WriteTo(ref output, _map_mapInt32Message_codec);
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -1116,12 +1177,27 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
map1_.WriteTo(output, _map_map1_codec);
map2_.WriteTo(output, _map_map2_codec);
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -1456,6 +1532,9 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
mapInt32Int32_.WriteTo(output, _map_mapInt32Int32_codec);
mapInt64Int64_.WriteTo(output, _map_mapInt64Int64_codec);
mapUint32Uint32_.WriteTo(output, _map_mapUint32Uint32_codec);
@@ -1474,8 +1553,33 @@ namespace Google.Protobuf.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
@@ -1761,12 +1865,26 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
type_.WriteTo(output, _map_type_codec);
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
@@ -1922,12 +2040,26 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
entry_.WriteTo(output, _map_entry_codec);
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto2.cs b/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto2.cs
index eb22955dc3..de1ece351a 100644
--- a/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto2.cs
+++ b/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto2.cs
@@ -2561,6 +2561,9 @@ namespace ProtobufTestMessages.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasOptionalInt32) {
output.WriteRawTag(8);
output.WriteInt32(OptionalInt32);
@@ -2836,7 +2839,289 @@ namespace ProtobufTestMessages.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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 (optionalNestedMessage_ != null) {
+ output.WriteRawTag(146, 1);
+ output.WriteMessage(OptionalNestedMessage);
+ }
+ if (optionalForeignMessage_ != null) {
+ 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 (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 (HasOneofUint32) {
+ output.WriteRawTag(248, 6);
+ output.WriteUInt32(OneofUint32);
+ }
+ if (oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage) {
+ 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() {
@@ -4561,6 +4846,9 @@ namespace ProtobufTestMessages.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasA) {
output.WriteRawTag(8);
output.WriteInt32(A);
@@ -4572,8 +4860,26 @@ namespace ProtobufTestMessages.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (HasA) {
+ 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;
@@ -4788,6 +5094,9 @@ namespace ProtobufTestMessages.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasGroupInt32) {
output.WriteRawTag(208, 12);
output.WriteInt32(GroupInt32);
@@ -4799,8 +5108,26 @@ namespace ProtobufTestMessages.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
@@ -4963,13 +5290,29 @@ namespace ProtobufTestMessages.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_extensions != null) {
_extensions.WriteTo(output);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_extensions != null) {
+ _extensions.WriteTo(ref output);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -5145,6 +5488,9 @@ namespace ProtobufTestMessages.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasStr) {
output.WriteRawTag(202, 1);
output.WriteString(Str);
@@ -5152,7 +5498,21 @@ namespace ProtobufTestMessages.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -5324,6 +5684,9 @@ namespace ProtobufTestMessages.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasI) {
output.WriteRawTag(72);
output.WriteInt32(I);
@@ -5331,7 +5694,21 @@ namespace ProtobufTestMessages.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (HasI) {
+ output.WriteRawTag(72);
+ output.WriteInt32(I);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -5508,6 +5885,9 @@ namespace ProtobufTestMessages.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasC) {
output.WriteRawTag(8);
output.WriteInt32(C);
@@ -5515,7 +5895,21 @@ namespace ProtobufTestMessages.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (HasC) {
+ output.WriteRawTag(8);
+ output.WriteInt32(C);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -5782,6 +6176,9 @@ namespace ProtobufTestMessages.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasOptionalInt32) {
output.WriteRawTag(200, 62);
output.WriteInt32(OptionalInt32);
@@ -5807,8 +6204,40 @@ namespace ProtobufTestMessages.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (HasOptionalInt32) {
+ output.WriteRawTag(200, 62);
+ output.WriteInt32(OptionalInt32);
+ }
+ if (HasOptionalString) {
+ output.WriteRawTag(210, 62);
+ output.WriteString(OptionalString);
+ }
+ if (nestedMessage_ != null) {
+ 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;
@@ -6058,6 +6487,9 @@ namespace ProtobufTestMessages.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasA) {
output.WriteRawTag(8);
output.WriteInt32(A);
@@ -6065,8 +6497,22 @@ namespace ProtobufTestMessages.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto3.cs b/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto3.cs
index ebdab60e4a..6f915cb79b 100644
--- a/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto3.cs
+++ b/csharp/src/Google.Protobuf.Test.TestProtos/TestMessagesProto3.cs
@@ -2452,6 +2452,9 @@ namespace ProtobufTestMessages.Proto3 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (OptionalInt32 != 0) {
output.WriteRawTag(8);
output.WriteInt32(OptionalInt32);
@@ -2798,8 +2801,361 @@ namespace ProtobufTestMessages.Proto3 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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 (oneofFieldCase_ == OneofFieldOneofCase.OneofNullValue) {
+ output.WriteRawTag(192, 7);
+ output.WriteEnum((int) OneofNullValue);
+ }
+ 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);
+ }
+ if (OptionalNullValue != global::Google.Protobuf.WellKnownTypes.NullValue.NullValue) {
+ output.WriteRawTag(152, 19);
+ output.WriteEnum((int) OptionalNullValue);
+ }
+ 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;
@@ -5004,6 +5360,9 @@ namespace ProtobufTestMessages.Proto3 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (A != 0) {
output.WriteRawTag(8);
output.WriteInt32(A);
@@ -5015,7 +5374,25 @@ namespace ProtobufTestMessages.Proto3 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -5191,6 +5568,9 @@ namespace ProtobufTestMessages.Proto3 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (C != 0) {
output.WriteRawTag(8);
output.WriteInt32(C);
@@ -5198,7 +5578,21 @@ namespace ProtobufTestMessages.Proto3 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/Unittest.cs b/csharp/src/Google.Protobuf.Test.TestProtos/Unittest.cs
index 373f569df3..a843c4ae8b 100644
--- a/csharp/src/Google.Protobuf.Test.TestProtos/Unittest.cs
+++ b/csharp/src/Google.Protobuf.Test.TestProtos/Unittest.cs
@@ -2822,6 +2822,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasOptionalInt32) {
output.WriteRawTag(8);
output.WriteInt32(OptionalInt32);
@@ -3051,7 +3054,243 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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 (optionalNestedMessage_ != null) {
+ output.WriteRawTag(146, 1);
+ output.WriteMessage(OptionalNestedMessage);
+ }
+ if (optionalForeignMessage_ != null) {
+ output.WriteRawTag(154, 1);
+ output.WriteMessage(OptionalForeignMessage);
+ }
+ if (optionalImportMessage_ != null) {
+ 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 (optionalPublicImportMessage_ != null) {
+ output.WriteRawTag(210, 1);
+ output.WriteMessage(OptionalPublicImportMessage);
+ }
+ if (optionalLazyMessage_ != null) {
+ 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 (oneofFieldCase_ == OneofFieldOneofCase.OneofNestedMessage) {
+ 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() {
@@ -4269,6 +4508,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasBb) {
output.WriteRawTag(8);
output.WriteInt32(Bb);
@@ -4276,7 +4518,21 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (HasBb) {
+ output.WriteRawTag(8);
+ output.WriteInt32(Bb);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -4439,6 +4695,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasA) {
output.WriteRawTag(136, 1);
output.WriteInt32(A);
@@ -4446,7 +4705,21 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -4613,6 +4886,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasA) {
output.WriteRawTag(248, 2);
output.WriteInt32(A);
@@ -4620,7 +4896,21 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -4807,6 +5097,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (child_ != null) {
output.WriteRawTag(10);
output.WriteMessage(Child);
@@ -4819,8 +5112,27 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
@@ -5081,6 +5393,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasDeprecatedInt32) {
output.WriteRawTag(8);
output.WriteInt32(DeprecatedInt32);
@@ -5092,8 +5407,26 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
@@ -5244,10 +5577,23 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -5427,6 +5773,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasC) {
output.WriteRawTag(8);
output.WriteInt32(C);
@@ -5438,7 +5787,25 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -5586,10 +5953,23 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -5718,14 +6098,30 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_extensions != null) {
_extensions.WriteTo(output);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
@@ -5903,6 +6299,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasA) {
output.WriteRawTag(136, 1);
output.WriteInt32(A);
@@ -5910,7 +6309,21 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -6077,6 +6490,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasA) {
output.WriteRawTag(248, 2);
output.WriteInt32(A);
@@ -6084,8 +6500,22 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
@@ -6275,6 +6705,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasOptionalGroup) {
output.WriteRawTag(131, 1);
output.WriteGroup(OptionalGroup);
@@ -6287,8 +6720,27 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
@@ -6475,6 +6927,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasA) {
output.WriteRawTag(136, 1);
output.WriteInt32(A);
@@ -6482,7 +6937,21 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -6634,13 +7103,29 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_extensions != null) {
_extensions.WriteTo(output);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_extensions != null) {
+ _extensions.WriteTo(ref output);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -6790,11 +7275,24 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
+ }
+ #endif
+
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
@@ -6944,6 +7442,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasA) {
output.WriteRawTag(136, 1);
output.WriteInt32(A);
@@ -6951,8 +7452,22 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
@@ -7913,116 +8428,260 @@ namespace Google.Protobuf.TestProtos.Proto2 {
_hasBits1 |= 1;
c_ = value;
}
- }
- /// Gets whether the "c" field is set
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
- public bool HasC {
- get { return (_hasBits1 & 1) != 0; }
- }
- /// Clears the value of the "c" field
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
- public void ClearC() {
- _hasBits1 &= ~1;
- }
-
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
- public override bool Equals(object other) {
- return Equals(other as TestRequired);
- }
-
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
- public bool Equals(TestRequired other) {
- if (ReferenceEquals(other, null)) {
- return false;
+ }
+ /// Gets whether the "c" field is set
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool HasC {
+ get { return (_hasBits1 & 1) != 0; }
+ }
+ /// Clears the value of the "c" field
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearC() {
+ _hasBits1 &= ~1;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as TestRequired);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(TestRequired other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (A != other.A) return false;
+ if (Dummy2 != other.Dummy2) return false;
+ if (B != other.B) return false;
+ if (Dummy4 != other.Dummy4) return false;
+ if (Dummy5 != other.Dummy5) return false;
+ if (Dummy6 != other.Dummy6) return false;
+ if (Dummy7 != other.Dummy7) return false;
+ if (Dummy8 != other.Dummy8) return false;
+ if (Dummy9 != other.Dummy9) return false;
+ if (Dummy10 != other.Dummy10) return false;
+ if (Dummy11 != other.Dummy11) return false;
+ if (Dummy12 != other.Dummy12) return false;
+ if (Dummy13 != other.Dummy13) return false;
+ if (Dummy14 != other.Dummy14) return false;
+ if (Dummy15 != other.Dummy15) return false;
+ if (Dummy16 != other.Dummy16) return false;
+ if (Dummy17 != other.Dummy17) return false;
+ if (Dummy18 != other.Dummy18) return false;
+ if (Dummy19 != other.Dummy19) return false;
+ if (Dummy20 != other.Dummy20) return false;
+ if (Dummy21 != other.Dummy21) return false;
+ if (Dummy22 != other.Dummy22) return false;
+ if (Dummy23 != other.Dummy23) return false;
+ if (Dummy24 != other.Dummy24) return false;
+ if (Dummy25 != other.Dummy25) return false;
+ if (Dummy26 != other.Dummy26) return false;
+ if (Dummy27 != other.Dummy27) return false;
+ if (Dummy28 != other.Dummy28) return false;
+ if (Dummy29 != other.Dummy29) return false;
+ if (Dummy30 != other.Dummy30) return false;
+ if (Dummy31 != other.Dummy31) return false;
+ if (Dummy32 != other.Dummy32) return false;
+ if (C != other.C) return false;
+ return Equals(_unknownFields, other._unknownFields);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (HasA) hash ^= A.GetHashCode();
+ if (HasDummy2) hash ^= Dummy2.GetHashCode();
+ if (HasB) hash ^= B.GetHashCode();
+ if (HasDummy4) hash ^= Dummy4.GetHashCode();
+ if (HasDummy5) hash ^= Dummy5.GetHashCode();
+ if (HasDummy6) hash ^= Dummy6.GetHashCode();
+ if (HasDummy7) hash ^= Dummy7.GetHashCode();
+ if (HasDummy8) hash ^= Dummy8.GetHashCode();
+ if (HasDummy9) hash ^= Dummy9.GetHashCode();
+ if (HasDummy10) hash ^= Dummy10.GetHashCode();
+ if (HasDummy11) hash ^= Dummy11.GetHashCode();
+ if (HasDummy12) hash ^= Dummy12.GetHashCode();
+ if (HasDummy13) hash ^= Dummy13.GetHashCode();
+ if (HasDummy14) hash ^= Dummy14.GetHashCode();
+ if (HasDummy15) hash ^= Dummy15.GetHashCode();
+ if (HasDummy16) hash ^= Dummy16.GetHashCode();
+ if (HasDummy17) hash ^= Dummy17.GetHashCode();
+ if (HasDummy18) hash ^= Dummy18.GetHashCode();
+ if (HasDummy19) hash ^= Dummy19.GetHashCode();
+ if (HasDummy20) hash ^= Dummy20.GetHashCode();
+ if (HasDummy21) hash ^= Dummy21.GetHashCode();
+ if (HasDummy22) hash ^= Dummy22.GetHashCode();
+ if (HasDummy23) hash ^= Dummy23.GetHashCode();
+ if (HasDummy24) hash ^= Dummy24.GetHashCode();
+ if (HasDummy25) hash ^= Dummy25.GetHashCode();
+ if (HasDummy26) hash ^= Dummy26.GetHashCode();
+ if (HasDummy27) hash ^= Dummy27.GetHashCode();
+ if (HasDummy28) hash ^= Dummy28.GetHashCode();
+ if (HasDummy29) hash ^= Dummy29.GetHashCode();
+ if (HasDummy30) hash ^= Dummy30.GetHashCode();
+ if (HasDummy31) hash ^= Dummy31.GetHashCode();
+ if (HasDummy32) hash ^= Dummy32.GetHashCode();
+ if (HasC) hash ^= C.GetHashCode();
+ if (_unknownFields != null) {
+ 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 !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
+ 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 (ReferenceEquals(other, this)) {
- return true;
+ 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 (A != other.A) return false;
- if (Dummy2 != other.Dummy2) return false;
- if (B != other.B) return false;
- if (Dummy4 != other.Dummy4) return false;
- if (Dummy5 != other.Dummy5) return false;
- if (Dummy6 != other.Dummy6) return false;
- if (Dummy7 != other.Dummy7) return false;
- if (Dummy8 != other.Dummy8) return false;
- if (Dummy9 != other.Dummy9) return false;
- if (Dummy10 != other.Dummy10) return false;
- if (Dummy11 != other.Dummy11) return false;
- if (Dummy12 != other.Dummy12) return false;
- if (Dummy13 != other.Dummy13) return false;
- if (Dummy14 != other.Dummy14) return false;
- if (Dummy15 != other.Dummy15) return false;
- if (Dummy16 != other.Dummy16) return false;
- if (Dummy17 != other.Dummy17) return false;
- if (Dummy18 != other.Dummy18) return false;
- if (Dummy19 != other.Dummy19) return false;
- if (Dummy20 != other.Dummy20) return false;
- if (Dummy21 != other.Dummy21) return false;
- if (Dummy22 != other.Dummy22) return false;
- if (Dummy23 != other.Dummy23) return false;
- if (Dummy24 != other.Dummy24) return false;
- if (Dummy25 != other.Dummy25) return false;
- if (Dummy26 != other.Dummy26) return false;
- if (Dummy27 != other.Dummy27) return false;
- if (Dummy28 != other.Dummy28) return false;
- if (Dummy29 != other.Dummy29) return false;
- if (Dummy30 != other.Dummy30) return false;
- if (Dummy31 != other.Dummy31) return false;
- if (Dummy32 != other.Dummy32) return false;
- if (C != other.C) return false;
- return Equals(_unknownFields, other._unknownFields);
- }
-
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
- public override int GetHashCode() {
- int hash = 1;
- if (HasA) hash ^= A.GetHashCode();
- if (HasDummy2) hash ^= Dummy2.GetHashCode();
- if (HasB) hash ^= B.GetHashCode();
- if (HasDummy4) hash ^= Dummy4.GetHashCode();
- if (HasDummy5) hash ^= Dummy5.GetHashCode();
- if (HasDummy6) hash ^= Dummy6.GetHashCode();
- if (HasDummy7) hash ^= Dummy7.GetHashCode();
- if (HasDummy8) hash ^= Dummy8.GetHashCode();
- if (HasDummy9) hash ^= Dummy9.GetHashCode();
- if (HasDummy10) hash ^= Dummy10.GetHashCode();
- if (HasDummy11) hash ^= Dummy11.GetHashCode();
- if (HasDummy12) hash ^= Dummy12.GetHashCode();
- if (HasDummy13) hash ^= Dummy13.GetHashCode();
- if (HasDummy14) hash ^= Dummy14.GetHashCode();
- if (HasDummy15) hash ^= Dummy15.GetHashCode();
- if (HasDummy16) hash ^= Dummy16.GetHashCode();
- if (HasDummy17) hash ^= Dummy17.GetHashCode();
- if (HasDummy18) hash ^= Dummy18.GetHashCode();
- if (HasDummy19) hash ^= Dummy19.GetHashCode();
- if (HasDummy20) hash ^= Dummy20.GetHashCode();
- if (HasDummy21) hash ^= Dummy21.GetHashCode();
- if (HasDummy22) hash ^= Dummy22.GetHashCode();
- if (HasDummy23) hash ^= Dummy23.GetHashCode();
- if (HasDummy24) hash ^= Dummy24.GetHashCode();
- if (HasDummy25) hash ^= Dummy25.GetHashCode();
- if (HasDummy26) hash ^= Dummy26.GetHashCode();
- if (HasDummy27) hash ^= Dummy27.GetHashCode();
- if (HasDummy28) hash ^= Dummy28.GetHashCode();
- if (HasDummy29) hash ^= Dummy29.GetHashCode();
- if (HasDummy30) hash ^= Dummy30.GetHashCode();
- if (HasDummy31) hash ^= Dummy31.GetHashCode();
- if (HasDummy32) hash ^= Dummy32.GetHashCode();
- if (HasC) hash ^= C.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);
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
- public void WriteTo(pb::CodedOutputStream output) {
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
if (HasA) {
output.WriteRawTag(8);
output.WriteInt32(A);
@@ -8156,9 +8815,10 @@ namespace Google.Protobuf.TestProtos.Proto2 {
output.WriteInt32(C);
}
if (_unknownFields != null) {
- _unknownFields.WriteTo(output);
+ _unknownFields.WriteTo(ref output);
}
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -8807,6 +9467,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (optionalMessage_ != null) {
output.WriteRawTag(10);
output.WriteMessage(OptionalMessage);
@@ -8819,7 +9482,26 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (optionalMessage_ != null) {
+ 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() {
@@ -9027,6 +9709,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (optionalMessage_ != null) {
output.WriteRawTag(10);
output.WriteMessage(OptionalMessage);
@@ -9039,7 +9724,26 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (optionalMessage_ != null) {
+ output.WriteRawTag(10);
+ output.WriteMessage(OptionalMessage);
+ }
+ repeatedMessage_.WriteTo(ref output, _repeated_repeatedMessage_codec);
+ if (requiredMessage_ != null) {
+ output.WriteRawTag(26);
+ output.WriteMessage(RequiredMessage);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -9232,6 +9936,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (foreignNested_ != null) {
output.WriteRawTag(10);
output.WriteMessage(ForeignNested);
@@ -9239,7 +9946,21 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -9385,10 +10106,23 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -9521,13 +10255,29 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_extensions != null) {
_extensions.WriteTo(output);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_extensions != null) {
+ _extensions.WriteTo(ref output);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -9686,13 +10436,29 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_extensions != null) {
_extensions.WriteTo(output);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_extensions != null) {
+ _extensions.WriteTo(ref output);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -9905,6 +10671,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasA) {
output.WriteRawTag(8);
output.WriteInt32(A);
@@ -9916,7 +10685,25 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -10106,7 +10893,27 @@ namespace Google.Protobuf.TestProtos.Proto2 {
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
- public void WriteTo(pb::CodedOutputStream output) {
+ public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
+ if (a_ != null) {
+ output.WriteRawTag(10);
+ output.WriteMessage(A);
+ }
+ if (HasI) {
+ output.WriteRawTag(16);
+ output.WriteInt32(I);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(output);
+ }
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
if (a_ != null) {
output.WriteRawTag(10);
output.WriteMessage(A);
@@ -10116,9 +10923,10 @@ namespace Google.Protobuf.TestProtos.Proto2 {
output.WriteInt32(I);
}
if (_unknownFields != null) {
- _unknownFields.WriteTo(output);
+ _unknownFields.WriteTo(ref output);
}
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -10316,6 +11124,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (bb_ != null) {
output.WriteRawTag(10);
output.WriteMessage(Bb);
@@ -10328,7 +11139,26 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (bb_ != null) {
+ 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() {
@@ -10510,6 +11340,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (b_ != null) {
output.WriteRawTag(10);
output.WriteMessage(B);
@@ -10517,7 +11350,21 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (b_ != null) {
+ output.WriteRawTag(10);
+ output.WriteMessage(B);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -10691,6 +11538,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (subMessage_ != null) {
output.WriteRawTag(26);
output.WriteMessage(SubMessage);
@@ -10702,7 +11552,25 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (subMessage_ != null) {
+ output.WriteRawTag(26);
+ output.WriteMessage(SubMessage);
+ }
+ if (notInThisScc_ != null) {
+ output.WriteRawTag(34);
+ output.WriteMessage(NotInThisScc);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -10920,6 +11788,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (a_ != null) {
output.WriteRawTag(10);
output.WriteMessage(A);
@@ -10931,7 +11802,25 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (a_ != null) {
+ 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() {
@@ -11102,6 +11991,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (subMessage_ != null) {
output.WriteRawTag(10);
output.WriteMessage(SubMessage);
@@ -11109,7 +12001,21 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (subMessage_ != null) {
+ output.WriteRawTag(10);
+ output.WriteMessage(SubMessage);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -11278,6 +12184,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasSubGroup) {
output.WriteRawTag(11);
output.WriteGroup(SubGroup);
@@ -11286,7 +12195,22 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -11460,6 +12384,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasI) {
output.WriteRawTag(16);
output.WriteInt32(I);
@@ -11467,7 +12394,21 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (HasI) {
+ output.WriteRawTag(16);
+ output.WriteInt32(I);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -11701,6 +12642,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasA) {
output.WriteRawTag(8);
output.WriteInt32(A);
@@ -11718,7 +12662,31 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -11929,6 +12897,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasA) {
output.WriteRawTag(8);
output.WriteInt32(A);
@@ -11936,7 +12907,21 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (HasA) {
+ output.WriteRawTag(8);
+ output.WriteInt32(A);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -12103,6 +13088,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasA) {
output.WriteRawTag(8);
output.WriteInt32(A);
@@ -12110,7 +13098,21 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (HasA) {
+ output.WriteRawTag(8);
+ output.WriteInt32(A);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -12270,6 +13272,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (subMessage_ != null) {
output.WriteRawTag(10);
output.WriteMessage(SubMessage);
@@ -12277,7 +13282,21 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (subMessage_ != null) {
+ output.WriteRawTag(10);
+ output.WriteMessage(SubMessage);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -12434,6 +13453,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (subMessage_ != null) {
output.WriteRawTag(10);
output.WriteMessage(SubMessage);
@@ -12441,7 +13463,21 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (subMessage_ != null) {
+ output.WriteRawTag(10);
+ output.WriteMessage(SubMessage);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -12601,6 +13637,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (optionalNestedMessage_ != null) {
output.WriteRawTag(10);
output.WriteMessage(OptionalNestedMessage);
@@ -12608,7 +13647,21 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (optionalNestedMessage_ != null) {
+ output.WriteRawTag(10);
+ output.WriteMessage(OptionalNestedMessage);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -12779,12 +13832,27 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
nestedmessageRepeatedInt32_.WriteTo(output, _repeated_nestedmessageRepeatedInt32_codec);
nestedmessageRepeatedForeignmessage_.WriteTo(output, _repeated_nestedmessageRepeatedForeignmessage_codec);
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -13161,6 +14229,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasPrimitiveField) {
output.WriteRawTag(8);
output.WriteInt32(PrimitiveField);
@@ -13194,7 +14265,47 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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 (messageField_ != null) {
+ 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() {
@@ -13580,6 +14691,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasMyInt) {
output.WriteRawTag(8);
output.WriteInt64(MyInt);
@@ -13602,7 +14716,36 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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 (optionalNestedMessage_ != null) {
+ output.WriteRawTag(194, 12);
+ output.WriteMessage(OptionalNestedMessage);
+ }
+ if (_extensions != null) {
+ _extensions.WriteTo(ref output);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -13880,6 +15023,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasBb) {
output.WriteRawTag(8);
output.WriteInt32(Bb);
@@ -13891,7 +15037,25 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -14070,6 +15234,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasMyString) {
output.WriteRawTag(10);
output.WriteString(MyString);
@@ -14077,7 +15244,21 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (HasMyString) {
+ output.WriteRawTag(10);
+ output.WriteString(MyString);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -14246,6 +15427,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasMyString) {
output.WriteRawTag(10);
output.WriteString(MyString);
@@ -14253,7 +15437,21 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (HasMyString) {
+ output.WriteRawTag(10);
+ output.WriteString(MyString);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -14415,6 +15613,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasMyString) {
output.WriteRawTag(10);
output.WriteString(MyString);
@@ -14422,7 +15623,21 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (HasMyString) {
+ output.WriteRawTag(10);
+ output.WriteString(MyString);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -15326,6 +16541,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasEscapedBytes) {
output.WriteRawTag(10);
output.WriteBytes(EscapedBytes);
@@ -15437,7 +16655,125 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -15964,6 +17300,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasSparseEnum) {
output.WriteRawTag(8);
output.WriteEnum((int) SparseEnum);
@@ -15971,7 +17310,21 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -16134,6 +17487,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasData) {
output.WriteRawTag(10);
output.WriteString(Data);
@@ -16141,7 +17497,21 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (HasData) {
+ output.WriteRawTag(10);
+ output.WriteString(Data);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -16288,11 +17658,25 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
data_.WriteTo(output, _repeated_data_codec);
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ data_.WriteTo(ref output, _repeated_data_codec);
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -16447,15 +17831,32 @@ namespace Google.Protobuf.TestProtos.Proto2 {
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
- public void WriteTo(pb::CodedOutputStream output) {
+ public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
+ if (HasData) {
+ output.WriteRawTag(10);
+ output.WriteBytes(Data);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(output);
+ }
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
if (HasData) {
output.WriteRawTag(10);
output.WriteBytes(Data);
}
if (_unknownFields != null) {
- _unknownFields.WriteTo(output);
+ _unknownFields.WriteTo(ref output);
}
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -16602,11 +18003,25 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
data_.WriteTo(output, _repeated_data_codec);
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ data_.WriteTo(ref output, _repeated_data_codec);
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -16768,6 +18183,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasData) {
output.WriteRawTag(8);
output.WriteInt32(Data);
@@ -16775,7 +18193,21 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (HasData) {
+ output.WriteRawTag(8);
+ output.WriteInt32(Data);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -16938,6 +18370,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasData) {
output.WriteRawTag(8);
output.WriteUInt32(Data);
@@ -16945,7 +18380,21 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (HasData) {
+ output.WriteRawTag(8);
+ output.WriteUInt32(Data);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -17108,6 +18557,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasData) {
output.WriteRawTag(8);
output.WriteInt64(Data);
@@ -17115,7 +18567,21 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (HasData) {
+ output.WriteRawTag(8);
+ output.WriteInt64(Data);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -17278,6 +18744,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasData) {
output.WriteRawTag(8);
output.WriteUInt64(Data);
@@ -17285,7 +18754,21 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (HasData) {
+ output.WriteRawTag(8);
+ output.WriteUInt64(Data);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -17448,6 +18931,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasData) {
output.WriteRawTag(8);
output.WriteBool(Data);
@@ -17455,7 +18941,21 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (HasData) {
+ output.WriteRawTag(8);
+ output.WriteBool(Data);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -17718,6 +19218,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasFooInt) {
output.WriteRawTag(8);
output.WriteInt32(FooInt);
@@ -17738,7 +19241,34 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (HasFooInt) {
+ output.WriteRawTag(8);
+ output.WriteInt32(FooInt);
+ }
+ if (HasFooString) {
+ output.WriteRawTag(18);
+ output.WriteString(FooString);
+ }
+ if (fooCase_ == FooOneofCase.FooMessage) {
+ 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() {
@@ -18000,6 +19530,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasA) {
output.WriteRawTag(40);
output.WriteInt32(A);
@@ -18011,7 +19544,25 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -18261,6 +19812,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasFooInt) {
output.WriteRawTag(8);
output.WriteInt32(FooInt);
@@ -18281,7 +19835,34 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (HasFooInt) {
+ output.WriteRawTag(8);
+ output.WriteInt32(FooInt);
+ }
+ if (HasFooString) {
+ output.WriteRawTag(18);
+ output.WriteString(FooString);
+ }
+ if (fooMessage_ != null) {
+ 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() {
@@ -18532,6 +20113,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasA) {
output.WriteRawTag(40);
output.WriteInt32(A);
@@ -18543,7 +20127,25 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -19209,7 +20811,88 @@ namespace Google.Protobuf.TestProtos.Proto2 {
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
- public void WriteTo(pb::CodedOutputStream output) {
+ public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
+ 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 (fooCase_ == FooOneofCase.FooMessage) {
+ output.WriteRawTag(58);
+ output.WriteMessage(FooMessage);
+ }
+ if (HasFooGroup) {
+ output.WriteRawTag(67);
+ output.WriteGroup(FooGroup);
+ output.WriteRawTag(68);
+ }
+ if (fooCase_ == FooOneofCase.FooLazyMessage) {
+ 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(output);
+ }
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
if (HasFooInt) {
output.WriteRawTag(8);
output.WriteInt32(FooInt);
@@ -19280,9 +20963,10 @@ namespace Google.Protobuf.TestProtos.Proto2 {
output.WriteString(BazString);
}
if (_unknownFields != null) {
- _unknownFields.WriteTo(output);
+ _unknownFields.WriteTo(ref output);
}
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -19752,6 +21436,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasA) {
output.WriteRawTag(72);
output.WriteInt32(A);
@@ -19763,7 +21450,25 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -19957,6 +21662,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasQuxInt) {
output.WriteRawTag(8);
output.WriteInt64(QuxInt);
@@ -19965,7 +21673,22 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -20213,6 +21936,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasFooInt) {
output.WriteRawTag(8);
output.WriteInt32(FooInt);
@@ -20228,7 +21954,29 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (HasFooInt) {
+ output.WriteRawTag(8);
+ output.WriteInt32(FooInt);
+ }
+ if (HasFooString) {
+ 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() {
@@ -20437,6 +22185,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasRequiredDouble) {
output.WriteRawTag(9);
output.WriteDouble(RequiredDouble);
@@ -20444,7 +22195,21 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (HasRequiredDouble) {
+ output.WriteRawTag(9);
+ output.WriteDouble(RequiredDouble);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -20596,11 +22361,25 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
foo_.WriteTo(output, _map_foo_codec);
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ foo_.WriteTo(ref output, _map_foo_codec);
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -20761,6 +22540,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasRequiredInt32) {
output.WriteRawTag(8);
output.WriteInt32(RequiredInt32);
@@ -20768,7 +22550,21 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (HasRequiredInt32) {
+ output.WriteRawTag(8);
+ output.WriteInt32(RequiredInt32);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -21089,6 +22885,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
packedInt32_.WriteTo(output, _repeated_packedInt32_codec);
packedInt64_.WriteTo(output, _repeated_packedInt64_codec);
packedUint32_.WriteTo(output, _repeated_packedUint32_codec);
@@ -21106,7 +22905,31 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -21580,6 +23403,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
unpackedInt32_.WriteTo(output, _repeated_unpackedInt32_codec);
unpackedInt64_.WriteTo(output, _repeated_unpackedInt64_codec);
unpackedUint32_.WriteTo(output, _repeated_unpackedUint32_codec);
@@ -21597,7 +23423,31 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -21894,13 +23744,29 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_extensions != null) {
_extensions.WriteTo(output);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_extensions != null) {
+ _extensions.WriteTo(ref output);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -22059,13 +23925,29 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_extensions != null) {
_extensions.WriteTo(output);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_extensions != null) {
+ _extensions.WriteTo(ref output);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -22357,6 +24239,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasScalarExtension) {
output.WriteRawTag(133, 125);
output.WriteFixed32(ScalarExtension);
@@ -22382,7 +24267,39 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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 (messageExtension_ != null) {
+ output.WriteRawTag(154, 125);
+ output.WriteMessage(MessageExtension);
+ }
+ if (dynamicMessageExtension_ != null) {
+ 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() {
@@ -22649,6 +24566,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasDynamicField) {
output.WriteRawTag(160, 131, 1);
output.WriteInt32(DynamicField);
@@ -22656,7 +24576,21 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -22887,6 +24821,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
repeatedFixed32_.WriteTo(output, _repeated_repeatedFixed32_codec);
repeatedInt32_.WriteTo(output, _repeated_repeatedInt32_codec);
repeatedFixed64_.WriteTo(output, _repeated_repeatedFixed64_codec);
@@ -22896,7 +24833,23 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -23179,6 +25132,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (requiredAllTypes_ != null) {
output.WriteRawTag(10);
output.WriteMessage(RequiredAllTypes);
@@ -23200,7 +25156,35 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (requiredAllTypes_ != null) {
+ output.WriteRawTag(10);
+ output.WriteMessage(RequiredAllTypes);
+ }
+ if (optionalAllTypes_ != null) {
+ 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() {
@@ -23539,6 +25523,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
field1_.WriteTo(output, _repeated_field1_codec);
field2_.WriteTo(output, _repeated_field2_codec);
field3_.WriteTo(output, _repeated_field3_codec);
@@ -23549,7 +25536,24 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -23755,6 +25759,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (field1_ != null) {
output.WriteRawTag(90);
output.WriteMessage(Field1);
@@ -23762,7 +25769,21 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (field1_ != null) {
+ output.WriteRawTag(90);
+ output.WriteMessage(Field1);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -23923,6 +25944,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (field1_ != null) {
output.WriteRawTag(170, 1);
output.WriteMessage(Field1);
@@ -23930,7 +25954,21 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (field1_ != null) {
+ output.WriteRawTag(170, 1);
+ output.WriteMessage(Field1);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -24096,6 +26134,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (optionalGroupAllTypes_ != null) {
output.WriteRawTag(90);
output.WriteMessage(OptionalGroupAllTypes);
@@ -24103,7 +26144,21 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (optionalGroupAllTypes_ != null) {
+ output.WriteRawTag(90);
+ output.WriteMessage(OptionalGroupAllTypes);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -24264,6 +26319,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (repeatedGroupAllTypes_ != null) {
output.WriteRawTag(170, 1);
output.WriteMessage(RepeatedGroupAllTypes);
@@ -24271,7 +26329,21 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (repeatedGroupAllTypes_ != null) {
+ output.WriteRawTag(170, 1);
+ output.WriteMessage(RepeatedGroupAllTypes);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -24463,6 +26535,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasA) {
output.WriteRawTag(10);
output.WriteString(A);
@@ -24470,7 +26545,21 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (HasA) {
+ output.WriteRawTag(10);
+ output.WriteString(A);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -24607,10 +26696,23 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -24730,10 +26832,23 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -24853,10 +26968,23 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -24976,10 +27104,23 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -25099,10 +27240,23 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -25222,10 +27376,23 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -25509,6 +27676,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasFieldName1) {
output.WriteRawTag(8);
output.WriteInt32(FieldName1);
@@ -25536,7 +27706,41 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -26087,6 +28291,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasOptionalInt32) {
output.WriteRawTag(128, 199, 255, 255, 15);
output.WriteInt32(OptionalInt32);
@@ -26141,7 +28348,68 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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 (optionalMessage_ != null) {
+ 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 (oneofFieldCase_ == OneofFieldOneofCase.OneofTestAllTypes) {
+ 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() {
@@ -26544,6 +28812,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasGroupA) {
output.WriteRawTag(200, 199, 255, 255, 15);
output.WriteInt32(GroupA);
@@ -26551,7 +28822,21 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -26948,6 +29233,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasField1) {
output.WriteRawTag(8);
output.WriteInt32(Field1);
@@ -26990,7 +29278,56 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestCustomOptionsProto3.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestCustomOptionsProto3.cs
index 26455da906..84a4a7eda2 100644
--- a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestCustomOptionsProto3.cs
+++ b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestCustomOptionsProto3.cs
@@ -379,6 +379,9 @@ namespace UnitTest.Issues.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Field1.Length != 0) {
output.WriteRawTag(10);
output.WriteString(Field1);
@@ -390,7 +393,25 @@ namespace UnitTest.Issues.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -558,11 +579,24 @@ namespace UnitTest.Issues.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
+ }
+ #endif
+
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
@@ -681,10 +715,23 @@ namespace UnitTest.Issues.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -804,11 +851,24 @@ namespace UnitTest.Issues.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
+ }
+ #endif
+
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
@@ -927,10 +987,23 @@ namespace UnitTest.Issues.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -1050,10 +1123,23 @@ namespace UnitTest.Issues.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -1186,11 +1272,24 @@ namespace UnitTest.Issues.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
+ }
+ #endif
+
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
@@ -1309,10 +1408,23 @@ namespace UnitTest.Issues.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -1432,11 +1544,24 @@ namespace UnitTest.Issues.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
+ }
+ #endif
+
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
@@ -1555,11 +1680,24 @@ namespace UnitTest.Issues.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
+ }
+ #endif
+
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
@@ -1678,11 +1816,24 @@ namespace UnitTest.Issues.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
+ }
+ #endif
+
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
@@ -1801,10 +1952,23 @@ namespace UnitTest.Issues.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -1979,6 +2143,9 @@ namespace UnitTest.Issues.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Foo != 0) {
output.WriteRawTag(8);
output.WriteInt32(Foo);
@@ -1995,7 +2162,30 @@ namespace UnitTest.Issues.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -2224,6 +2414,9 @@ namespace UnitTest.Issues.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (bar_ != null) {
output.WriteRawTag(10);
output.WriteMessage(Bar);
@@ -2240,7 +2433,30 @@ namespace UnitTest.Issues.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -2446,6 +2662,9 @@ namespace UnitTest.Issues.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Waldo != 0) {
output.WriteRawTag(8);
output.WriteInt32(Waldo);
@@ -2453,8 +2672,22 @@ namespace UnitTest.Issues.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
@@ -2615,6 +2848,9 @@ namespace UnitTest.Issues.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Qux != 0) {
output.WriteRawTag(8);
output.WriteInt32(Qux);
@@ -2622,8 +2858,22 @@ namespace UnitTest.Issues.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
@@ -2759,11 +3009,24 @@ namespace UnitTest.Issues.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
+ }
+ #endif
+
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
@@ -2930,6 +3193,9 @@ namespace UnitTest.Issues.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (I != 0) {
output.WriteRawTag(8);
output.WriteInt32(I);
@@ -2945,7 +3211,29 @@ namespace UnitTest.Issues.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -3130,6 +3418,9 @@ namespace UnitTest.Issues.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Fieldname != 0) {
output.WriteRawTag(8);
output.WriteInt32(Fieldname);
@@ -3137,8 +3428,22 @@ namespace UnitTest.Issues.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
@@ -3274,11 +3579,24 @@ namespace UnitTest.Issues.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
+ }
+ #endif
+
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
@@ -3418,6 +3736,9 @@ namespace UnitTest.Issues.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (NestedField != 0) {
output.WriteRawTag(8);
output.WriteInt32(NestedField);
@@ -3425,7 +3746,21 @@ namespace UnitTest.Issues.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImport.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImport.cs
index 6ac9f11069..14b054ccbb 100644
--- a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImport.cs
+++ b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImport.cs
@@ -157,6 +157,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasD) {
output.WriteRawTag(8);
output.WriteInt32(D);
@@ -164,7 +167,21 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (HasD) {
+ output.WriteRawTag(8);
+ output.WriteInt32(D);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportProto3.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportProto3.cs
index 99575b1a3d..ecdf40979c 100644
--- a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportProto3.cs
+++ b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportProto3.cs
@@ -133,6 +133,9 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (D != 0) {
output.WriteRawTag(8);
output.WriteInt32(D);
@@ -140,7 +143,21 @@ namespace Google.Protobuf.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportPublic.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportPublic.cs
index 9bdcf1d686..24c29e9708 100644
--- a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportPublic.cs
+++ b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportPublic.cs
@@ -135,6 +135,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasE) {
output.WriteRawTag(8);
output.WriteInt32(E);
@@ -142,7 +145,21 @@ namespace Google.Protobuf.TestProtos.Proto2 {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (HasE) {
+ output.WriteRawTag(8);
+ output.WriteInt32(E);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportPublicProto3.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportPublicProto3.cs
index dba9165f44..2d77a639fa 100644
--- a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportPublicProto3.cs
+++ b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestImportPublicProto3.cs
@@ -121,6 +121,9 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (E != 0) {
output.WriteRawTag(8);
output.WriteInt32(E);
@@ -128,7 +131,21 @@ namespace Google.Protobuf.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936B.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936B.cs
index 660dbbdda3..e22bf0f8ff 100644
--- a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936B.cs
+++ b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936B.cs
@@ -106,10 +106,23 @@ namespace UnitTest.Issues.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936C.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936C.cs
index b7498d6f23..21d36300f8 100644
--- a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936C.cs
+++ b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssue6936C.cs
@@ -122,6 +122,9 @@ namespace UnitTest.Issues.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (foo_ != null) {
output.WriteRawTag(10);
output.WriteMessage(Foo);
@@ -129,7 +132,21 @@ namespace UnitTest.Issues.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssues.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssues.cs
index f5c46a9503..e09191a65c 100644
--- a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssues.cs
+++ b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestIssues.cs
@@ -24,36 +24,41 @@ namespace UnitTest.Issues.TestProtos {
static UnittestIssuesReflection() {
byte[] descriptorData = global::System.Convert.FromBase64String(
string.Concat(
- "ChV1bml0dGVzdF9pc3N1ZXMucHJvdG8SD3VuaXR0ZXN0X2lzc3VlcyInCghJ",
- "c3N1ZTMwNxobCgpOZXN0ZWRPbmNlGg0KC05lc3RlZFR3aWNlIrABChNOZWdh",
- "dGl2ZUVudW1NZXNzYWdlEiwKBXZhbHVlGAEgASgOMh0udW5pdHRlc3RfaXNz",
- "dWVzLk5lZ2F0aXZlRW51bRIxCgZ2YWx1ZXMYAiADKA4yHS51bml0dGVzdF9p",
- "c3N1ZXMuTmVnYXRpdmVFbnVtQgIQABI4Cg1wYWNrZWRfdmFsdWVzGAMgAygO",
- "Mh0udW5pdHRlc3RfaXNzdWVzLk5lZ2F0aXZlRW51bUICEAEiEQoPRGVwcmVj",
- "YXRlZENoaWxkIrkCChdEZXByZWNhdGVkRmllbGRzTWVzc2FnZRIaCg5Qcmlt",
- "aXRpdmVWYWx1ZRgBIAEoBUICGAESGgoOUHJpbWl0aXZlQXJyYXkYAiADKAVC",
- "AhgBEjoKDE1lc3NhZ2VWYWx1ZRgDIAEoCzIgLnVuaXR0ZXN0X2lzc3Vlcy5E",
- "ZXByZWNhdGVkQ2hpbGRCAhgBEjoKDE1lc3NhZ2VBcnJheRgEIAMoCzIgLnVu",
- "aXR0ZXN0X2lzc3Vlcy5EZXByZWNhdGVkQ2hpbGRCAhgBEjYKCUVudW1WYWx1",
- "ZRgFIAEoDjIfLnVuaXR0ZXN0X2lzc3Vlcy5EZXByZWNhdGVkRW51bUICGAES",
- "NgoJRW51bUFycmF5GAYgAygOMh8udW5pdHRlc3RfaXNzdWVzLkRlcHJlY2F0",
- "ZWRFbnVtQgIYASIZCglJdGVtRmllbGQSDAoEaXRlbRgBIAEoBSJECg1SZXNl",
- "cnZlZE5hbWVzEg0KBXR5cGVzGAEgASgFEhIKCmRlc2NyaXB0b3IYAiABKAUa",
- "EAoOU29tZU5lc3RlZFR5cGUioAEKFVRlc3RKc29uRmllbGRPcmRlcmluZxIT",
- "CgtwbGFpbl9pbnQzMhgEIAEoBRITCglvMV9zdHJpbmcYAiABKAlIABISCghv",
- "MV9pbnQzMhgFIAEoBUgAEhQKDHBsYWluX3N0cmluZxgBIAEoCRISCghvMl9p",
- "bnQzMhgGIAEoBUgBEhMKCW8yX3N0cmluZxgDIAEoCUgBQgQKAm8xQgQKAm8y",
- "IksKDFRlc3RKc29uTmFtZRIMCgRuYW1lGAEgASgJEhkKC2Rlc2NyaXB0aW9u",
- "GAIgASgJUgRkZXNjEhIKBGd1aWQYAyABKAlSBGV4aWQifwoMT25lb2ZNZXJn",
- "aW5nEg4KBHRleHQYASABKAlIABI2CgZuZXN0ZWQYAiABKAsyJC51bml0dGVz",
- "dF9pc3N1ZXMuT25lb2ZNZXJnaW5nLk5lc3RlZEgAGh4KBk5lc3RlZBIJCgF4",
- "GAEgASgFEgkKAXkYAiABKAVCBwoFdmFsdWUqVQoMTmVnYXRpdmVFbnVtEhYK",
- "Ek5FR0FUSVZFX0VOVU1fWkVSTxAAEhYKCUZpdmVCZWxvdxD7//////////8B",
- "EhUKCE1pbnVzT25lEP///////////wEqLgoORGVwcmVjYXRlZEVudW0SEwoP",
- "REVQUkVDQVRFRF9aRVJPEAASBwoDb25lEAFCHaoCGlVuaXRUZXN0Lklzc3Vl",
- "cy5UZXN0UHJvdG9zYgZwcm90bzM="));
+ "ChV1bml0dGVzdF9pc3N1ZXMucHJvdG8SD3VuaXR0ZXN0X2lzc3VlcxocZ29v",
+ "Z2xlL3Byb3RvYnVmL3N0cnVjdC5wcm90byInCghJc3N1ZTMwNxobCgpOZXN0",
+ "ZWRPbmNlGg0KC05lc3RlZFR3aWNlIrABChNOZWdhdGl2ZUVudW1NZXNzYWdl",
+ "EiwKBXZhbHVlGAEgASgOMh0udW5pdHRlc3RfaXNzdWVzLk5lZ2F0aXZlRW51",
+ "bRIxCgZ2YWx1ZXMYAiADKA4yHS51bml0dGVzdF9pc3N1ZXMuTmVnYXRpdmVF",
+ "bnVtQgIQABI4Cg1wYWNrZWRfdmFsdWVzGAMgAygOMh0udW5pdHRlc3RfaXNz",
+ "dWVzLk5lZ2F0aXZlRW51bUICEAEiEQoPRGVwcmVjYXRlZENoaWxkIrkCChdE",
+ "ZXByZWNhdGVkRmllbGRzTWVzc2FnZRIaCg5QcmltaXRpdmVWYWx1ZRgBIAEo",
+ "BUICGAESGgoOUHJpbWl0aXZlQXJyYXkYAiADKAVCAhgBEjoKDE1lc3NhZ2VW",
+ "YWx1ZRgDIAEoCzIgLnVuaXR0ZXN0X2lzc3Vlcy5EZXByZWNhdGVkQ2hpbGRC",
+ "AhgBEjoKDE1lc3NhZ2VBcnJheRgEIAMoCzIgLnVuaXR0ZXN0X2lzc3Vlcy5E",
+ "ZXByZWNhdGVkQ2hpbGRCAhgBEjYKCUVudW1WYWx1ZRgFIAEoDjIfLnVuaXR0",
+ "ZXN0X2lzc3Vlcy5EZXByZWNhdGVkRW51bUICGAESNgoJRW51bUFycmF5GAYg",
+ "AygOMh8udW5pdHRlc3RfaXNzdWVzLkRlcHJlY2F0ZWRFbnVtQgIYASIZCglJ",
+ "dGVtRmllbGQSDAoEaXRlbRgBIAEoBSJECg1SZXNlcnZlZE5hbWVzEg0KBXR5",
+ "cGVzGAEgASgFEhIKCmRlc2NyaXB0b3IYAiABKAUaEAoOU29tZU5lc3RlZFR5",
+ "cGUioAEKFVRlc3RKc29uRmllbGRPcmRlcmluZxITCgtwbGFpbl9pbnQzMhgE",
+ "IAEoBRITCglvMV9zdHJpbmcYAiABKAlIABISCghvMV9pbnQzMhgFIAEoBUgA",
+ "EhQKDHBsYWluX3N0cmluZxgBIAEoCRISCghvMl9pbnQzMhgGIAEoBUgBEhMK",
+ "CW8yX3N0cmluZxgDIAEoCUgBQgQKAm8xQgQKAm8yIksKDFRlc3RKc29uTmFt",
+ "ZRIMCgRuYW1lGAEgASgJEhkKC2Rlc2NyaXB0aW9uGAIgASgJUgRkZXNjEhIK",
+ "BGd1aWQYAyABKAlSBGV4aWQifwoMT25lb2ZNZXJnaW5nEg4KBHRleHQYASAB",
+ "KAlIABI2CgZuZXN0ZWQYAiABKAsyJC51bml0dGVzdF9pc3N1ZXMuT25lb2ZN",
+ "ZXJnaW5nLk5lc3RlZEgAGh4KBk5lc3RlZBIJCgF4GAEgASgFEgkKAXkYAiAB",
+ "KAVCBwoFdmFsdWUiawoWTnVsbFZhbHVlT3V0c2lkZVN0cnVjdBIWCgxzdHJp",
+ "bmdfdmFsdWUYASABKAlIABIwCgpudWxsX3ZhbHVlGAIgASgOMhouZ29vZ2xl",
+ "LnByb3RvYnVmLk51bGxWYWx1ZUgAQgcKBXZhbHVlIkUKE051bGxWYWx1ZU5v",
+ "dEluT25lb2YSLgoKbnVsbF92YWx1ZRgCIAEoDjIaLmdvb2dsZS5wcm90b2J1",
+ "Zi5OdWxsVmFsdWUqVQoMTmVnYXRpdmVFbnVtEhYKEk5FR0FUSVZFX0VOVU1f",
+ "WkVSTxAAEhYKCUZpdmVCZWxvdxD7//////////8BEhUKCE1pbnVzT25lEP//",
+ "/////////wEqLgoORGVwcmVjYXRlZEVudW0SEwoPREVQUkVDQVRFRF9aRVJP",
+ "EAASBwoDb25lEAFCHaoCGlVuaXRUZXN0Lklzc3Vlcy5UZXN0UHJvdG9zYgZw",
+ "cm90bzM="));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
- new pbr::FileDescriptor[] { },
+ new pbr::FileDescriptor[] { global::Google.Protobuf.WellKnownTypes.StructReflection.Descriptor, },
new pbr::GeneratedClrTypeInfo(new[] {typeof(global::UnitTest.Issues.TestProtos.NegativeEnum), typeof(global::UnitTest.Issues.TestProtos.DeprecatedEnum), }, null, new pbr::GeneratedClrTypeInfo[] {
new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.Issue307), global::UnitTest.Issues.TestProtos.Issue307.Parser, null, null, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.Issue307.Types.NestedOnce), global::UnitTest.Issues.TestProtos.Issue307.Types.NestedOnce.Parser, null, null, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.Issue307.Types.NestedOnce.Types.NestedTwice), global::UnitTest.Issues.TestProtos.Issue307.Types.NestedOnce.Types.NestedTwice.Parser, null, null, null, null, null)})}),
new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.NegativeEnumMessage), global::UnitTest.Issues.TestProtos.NegativeEnumMessage.Parser, new[]{ "Value", "Values", "PackedValues" }, null, null, null, null),
@@ -63,7 +68,9 @@ namespace UnitTest.Issues.TestProtos {
new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.ReservedNames), global::UnitTest.Issues.TestProtos.ReservedNames.Parser, new[]{ "Types_", "Descriptor_" }, null, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.ReservedNames.Types.SomeNestedType), global::UnitTest.Issues.TestProtos.ReservedNames.Types.SomeNestedType.Parser, null, null, null, null, null)}),
new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.TestJsonFieldOrdering), global::UnitTest.Issues.TestProtos.TestJsonFieldOrdering.Parser, new[]{ "PlainInt32", "O1String", "O1Int32", "PlainString", "O2Int32", "O2String" }, new[]{ "O1", "O2" }, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.TestJsonName), global::UnitTest.Issues.TestProtos.TestJsonName.Parser, new[]{ "Name", "Description", "Guid" }, null, null, null, null),
- new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.OneofMerging), global::UnitTest.Issues.TestProtos.OneofMerging.Parser, new[]{ "Text", "Nested" }, new[]{ "Value" }, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.OneofMerging.Types.Nested), global::UnitTest.Issues.TestProtos.OneofMerging.Types.Nested.Parser, new[]{ "X", "Y" }, null, null, null, null)})
+ new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.OneofMerging), global::UnitTest.Issues.TestProtos.OneofMerging.Parser, new[]{ "Text", "Nested" }, new[]{ "Value" }, null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.OneofMerging.Types.Nested), global::UnitTest.Issues.TestProtos.OneofMerging.Types.Nested.Parser, new[]{ "X", "Y" }, null, null, null, null)}),
+ new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.NullValueOutsideStruct), global::UnitTest.Issues.TestProtos.NullValueOutsideStruct.Parser, new[]{ "StringValue", "NullValue" }, new[]{ "Value" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::UnitTest.Issues.TestProtos.NullValueNotInOneof), global::UnitTest.Issues.TestProtos.NullValueNotInOneof.Parser, new[]{ "NullValue" }, null, null, null, null)
}));
}
#endregion
@@ -157,10 +164,23 @@ namespace UnitTest.Issues.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -282,10 +302,23 @@ namespace UnitTest.Issues.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -407,10 +440,23 @@ namespace UnitTest.Issues.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -580,6 +626,9 @@ namespace UnitTest.Issues.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Value != global::UnitTest.Issues.TestProtos.NegativeEnum.Zero) {
output.WriteRawTag(8);
output.WriteEnum((int) Value);
@@ -589,7 +638,23 @@ namespace UnitTest.Issues.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -747,10 +812,23 @@ namespace UnitTest.Issues.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -957,6 +1035,9 @@ namespace UnitTest.Issues.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (PrimitiveValue != 0) {
output.WriteRawTag(8);
output.WriteInt32(PrimitiveValue);
@@ -975,7 +1056,32 @@ namespace UnitTest.Issues.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -1197,6 +1303,9 @@ namespace UnitTest.Issues.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Item != 0) {
output.WriteRawTag(8);
output.WriteInt32(Item);
@@ -1204,7 +1313,21 @@ namespace UnitTest.Issues.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -1366,6 +1489,9 @@ namespace UnitTest.Issues.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Types_ != 0) {
output.WriteRawTag(8);
output.WriteInt32(Types_);
@@ -1377,7 +1503,25 @@ namespace UnitTest.Issues.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -1530,10 +1674,23 @@ namespace UnitTest.Issues.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -1810,6 +1967,9 @@ namespace UnitTest.Issues.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (PlainString.Length != 0) {
output.WriteRawTag(10);
output.WriteString(PlainString);
@@ -1837,7 +1997,41 @@ namespace UnitTest.Issues.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -2092,6 +2286,9 @@ namespace UnitTest.Issues.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Name.Length != 0) {
output.WriteRawTag(10);
output.WriteString(Name);
@@ -2107,7 +2304,29 @@ namespace UnitTest.Issues.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -2330,6 +2549,9 @@ namespace UnitTest.Issues.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (valueCase_ == ValueOneofCase.Text) {
output.WriteRawTag(10);
output.WriteString(Text);
@@ -2341,7 +2563,25 @@ namespace UnitTest.Issues.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -2535,6 +2775,9 @@ namespace UnitTest.Issues.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (X != 0) {
output.WriteRawTag(8);
output.WriteInt32(X);
@@ -2546,7 +2789,25 @@ namespace UnitTest.Issues.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -2630,6 +2891,419 @@ namespace UnitTest.Issues.TestProtos {
}
+ public sealed partial class NullValueOutsideStruct : pb::IMessage
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ , pb::IBufferMessage
+ #endif
+ {
+ private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new NullValueOutsideStruct());
+ 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::UnitTest.Issues.TestProtos.UnittestIssuesReflection.Descriptor.MessageTypes[9]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NullValueOutsideStruct() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NullValueOutsideStruct(NullValueOutsideStruct other) : this() {
+ switch (other.ValueCase) {
+ case ValueOneofCase.StringValue:
+ StringValue = other.StringValue;
+ break;
+ case ValueOneofCase.NullValue:
+ NullValue = other.NullValue;
+ break;
+ }
+
+ _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NullValueOutsideStruct Clone() {
+ return new NullValueOutsideStruct(this);
+ }
+
+ /// Field number for the "string_value" field.
+ public const int StringValueFieldNumber = 1;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string StringValue {
+ get { return valueCase_ == ValueOneofCase.StringValue ? (string) value_ : ""; }
+ set {
+ value_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ valueCase_ = ValueOneofCase.StringValue;
+ }
+ }
+
+ /// Field number for the "null_value" field.
+ public const int NullValueFieldNumber = 2;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.NullValue NullValue {
+ get { return valueCase_ == ValueOneofCase.NullValue ? (global::Google.Protobuf.WellKnownTypes.NullValue) value_ : global::Google.Protobuf.WellKnownTypes.NullValue.NullValue; }
+ set {
+ value_ = value;
+ valueCase_ = ValueOneofCase.NullValue;
+ }
+ }
+
+ private object value_;
+ /// Enum of possible cases for the "value" oneof.
+ public enum ValueOneofCase {
+ None = 0,
+ StringValue = 1,
+ NullValue = 2,
+ }
+ private ValueOneofCase valueCase_ = ValueOneofCase.None;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public ValueOneofCase ValueCase {
+ get { return valueCase_; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void ClearValue() {
+ valueCase_ = ValueOneofCase.None;
+ value_ = null;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as NullValueOutsideStruct);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(NullValueOutsideStruct other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (StringValue != other.StringValue) return false;
+ if (NullValue != other.NullValue) return false;
+ if (ValueCase != other.ValueCase) return false;
+ return Equals(_unknownFields, other._unknownFields);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (valueCase_ == ValueOneofCase.StringValue) hash ^= StringValue.GetHashCode();
+ if (valueCase_ == ValueOneofCase.NullValue) hash ^= NullValue.GetHashCode();
+ hash ^= (int) valueCase_;
+ if (_unknownFields != null) {
+ 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 !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
+ if (valueCase_ == ValueOneofCase.StringValue) {
+ output.WriteRawTag(10);
+ output.WriteString(StringValue);
+ }
+ if (valueCase_ == ValueOneofCase.NullValue) {
+ output.WriteRawTag(16);
+ output.WriteEnum((int) NullValue);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(output);
+ }
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (valueCase_ == ValueOneofCase.StringValue) {
+ output.WriteRawTag(10);
+ output.WriteString(StringValue);
+ }
+ if (valueCase_ == ValueOneofCase.NullValue) {
+ output.WriteRawTag(16);
+ output.WriteEnum((int) NullValue);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
+ }
+ #endif
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (valueCase_ == ValueOneofCase.StringValue) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(StringValue);
+ }
+ if (valueCase_ == ValueOneofCase.NullValue) {
+ size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) NullValue);
+ }
+ if (_unknownFields != null) {
+ size += _unknownFields.CalculateSize();
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(NullValueOutsideStruct other) {
+ if (other == null) {
+ return;
+ }
+ switch (other.ValueCase) {
+ case ValueOneofCase.StringValue:
+ StringValue = other.StringValue;
+ break;
+ case ValueOneofCase.NullValue:
+ NullValue = other.NullValue;
+ break;
+ }
+
+ _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ input.ReadRawMessage(this);
+ #else
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ break;
+ case 10: {
+ StringValue = input.ReadString();
+ break;
+ }
+ case 16: {
+ value_ = input.ReadEnum();
+ valueCase_ = ValueOneofCase.NullValue;
+ break;
+ }
+ }
+ }
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
+ break;
+ case 10: {
+ StringValue = input.ReadString();
+ break;
+ }
+ case 16: {
+ value_ = input.ReadEnum();
+ valueCase_ = ValueOneofCase.NullValue;
+ break;
+ }
+ }
+ }
+ }
+ #endif
+
+ }
+
+ public sealed partial class NullValueNotInOneof : pb::IMessage
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ , pb::IBufferMessage
+ #endif
+ {
+ private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new NullValueNotInOneof());
+ 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::UnitTest.Issues.TestProtos.UnittestIssuesReflection.Descriptor.MessageTypes[10]; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NullValueNotInOneof() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NullValueNotInOneof(NullValueNotInOneof other) : this() {
+ nullValue_ = other.nullValue_;
+ _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public NullValueNotInOneof Clone() {
+ return new NullValueNotInOneof(this);
+ }
+
+ /// Field number for the "null_value" field.
+ public const int NullValueFieldNumber = 2;
+ private global::Google.Protobuf.WellKnownTypes.NullValue nullValue_ = global::Google.Protobuf.WellKnownTypes.NullValue.NullValue;
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public global::Google.Protobuf.WellKnownTypes.NullValue NullValue {
+ get { return nullValue_; }
+ set {
+ nullValue_ = value;
+ }
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override bool Equals(object other) {
+ return Equals(other as NullValueNotInOneof);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public bool Equals(NullValueNotInOneof other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (NullValue != other.NullValue) return false;
+ return Equals(_unknownFields, other._unknownFields);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public override int GetHashCode() {
+ int hash = 1;
+ if (NullValue != global::Google.Protobuf.WellKnownTypes.NullValue.NullValue) hash ^= NullValue.GetHashCode();
+ if (_unknownFields != null) {
+ 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 !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
+ if (NullValue != global::Google.Protobuf.WellKnownTypes.NullValue.NullValue) {
+ output.WriteRawTag(16);
+ output.WriteEnum((int) NullValue);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(output);
+ }
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (NullValue != global::Google.Protobuf.WellKnownTypes.NullValue.NullValue) {
+ output.WriteRawTag(16);
+ output.WriteEnum((int) NullValue);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
+ }
+ #endif
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public int CalculateSize() {
+ int size = 0;
+ if (NullValue != global::Google.Protobuf.WellKnownTypes.NullValue.NullValue) {
+ size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) NullValue);
+ }
+ if (_unknownFields != null) {
+ size += _unknownFields.CalculateSize();
+ }
+ return size;
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(NullValueNotInOneof other) {
+ if (other == null) {
+ return;
+ }
+ if (other.NullValue != global::Google.Protobuf.WellKnownTypes.NullValue.NullValue) {
+ NullValue = other.NullValue;
+ }
+ _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
+ }
+
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public void MergeFrom(pb::CodedInputStream input) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ input.ReadRawMessage(this);
+ #else
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
+ break;
+ case 16: {
+ NullValue = (global::Google.Protobuf.WellKnownTypes.NullValue) input.ReadEnum();
+ break;
+ }
+ }
+ }
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
+ break;
+ case 16: {
+ NullValue = (global::Google.Protobuf.WellKnownTypes.NullValue) input.ReadEnum();
+ break;
+ }
+ }
+ }
+ }
+ #endif
+
+ }
+
#endregion
}
diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3.cs
index 468e48bd05..b81eb57383 100644
--- a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3.cs
+++ b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3.cs
@@ -1019,6 +1019,9 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (SingleInt32 != 0) {
output.WriteRawTag(8);
output.WriteInt32(SingleInt32);
@@ -1148,8 +1151,144 @@ namespace Google.Protobuf.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
@@ -1968,6 +2107,9 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Bb != 0) {
output.WriteRawTag(8);
output.WriteInt32(Bb);
@@ -1975,7 +2117,21 @@ namespace Google.Protobuf.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -2158,6 +2314,9 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (child_ != null) {
output.WriteRawTag(10);
output.WriteMessage(Child);
@@ -2170,8 +2329,27 @@ namespace Google.Protobuf.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
@@ -2361,6 +2539,9 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (DeprecatedInt32 != 0) {
output.WriteRawTag(8);
output.WriteInt32(DeprecatedInt32);
@@ -2368,8 +2549,22 @@ namespace Google.Protobuf.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
@@ -2520,6 +2715,9 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (C != 0) {
output.WriteRawTag(8);
output.WriteInt32(C);
@@ -2527,8 +2725,22 @@ namespace Google.Protobuf.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
@@ -2661,10 +2873,23 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -2801,6 +3026,9 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (foreignNested_ != null) {
output.WriteRawTag(10);
output.WriteMessage(ForeignNested);
@@ -2808,7 +3036,21 @@ namespace Google.Protobuf.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -2986,6 +3228,9 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (A != 0) {
output.WriteRawTag(8);
output.WriteInt32(A);
@@ -2997,8 +3242,26 @@ namespace Google.Protobuf.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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(ref output);
+ }
+ }
+ #endif
+
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
@@ -3173,6 +3436,9 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (a_ != null) {
output.WriteRawTag(10);
output.WriteMessage(A);
@@ -3184,7 +3450,25 @@ namespace Google.Protobuf.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -3358,6 +3642,9 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (bb_ != null) {
output.WriteRawTag(10);
output.WriteMessage(Bb);
@@ -3365,8 +3652,22 @@ namespace Google.Protobuf.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
@@ -3536,6 +3837,9 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (a_ != null) {
output.WriteRawTag(10);
output.WriteMessage(A);
@@ -3547,8 +3851,26 @@ namespace Google.Protobuf.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
@@ -3718,6 +4040,9 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Value != global::Google.Protobuf.TestProtos.TestEnumWithDupValue.Unspecified) {
output.WriteRawTag(8);
output.WriteEnum((int) Value);
@@ -3725,7 +4050,21 @@ namespace Google.Protobuf.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -3971,6 +4310,9 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (PrimitiveField != 0) {
output.WriteRawTag(8);
output.WriteInt32(PrimitiveField);
@@ -3994,8 +4336,38 @@ namespace Google.Protobuf.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
@@ -4283,6 +4655,9 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (MyInt != 0L) {
output.WriteRawTag(8);
output.WriteInt64(MyInt);
@@ -4302,7 +4677,33 @@ namespace Google.Protobuf.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -4522,6 +4923,9 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Bb != 0) {
output.WriteRawTag(8);
output.WriteInt32(Bb);
@@ -4533,8 +4937,26 @@ namespace Google.Protobuf.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
@@ -4700,6 +5122,9 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (SparseEnum != global::Google.Protobuf.TestProtos.TestSparseEnum.Unspecified) {
output.WriteRawTag(8);
output.WriteEnum((int) SparseEnum);
@@ -4707,8 +5132,22 @@ namespace Google.Protobuf.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
@@ -4858,6 +5297,9 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Data.Length != 0) {
output.WriteRawTag(10);
output.WriteString(Data);
@@ -4865,8 +5307,22 @@ namespace Google.Protobuf.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
@@ -5012,11 +5468,25 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
data_.WriteTo(output, _repeated_data_codec);
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ data_.WriteTo(ref output, _repeated_data_codec);
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -5159,15 +5629,32 @@ namespace Google.Protobuf.TestProtos {
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
- public void WriteTo(pb::CodedOutputStream output) {
+ public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
+ if (Data.Length != 0) {
+ output.WriteRawTag(10);
+ output.WriteBytes(Data);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(output);
+ }
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
if (Data.Length != 0) {
output.WriteRawTag(10);
output.WriteBytes(Data);
}
if (_unknownFields != null) {
- _unknownFields.WriteTo(output);
+ _unknownFields.WriteTo(ref output);
}
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -5315,6 +5802,9 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Data.Length != 0) {
output.WriteRawTag(10);
output.WriteBytes(Data);
@@ -5322,7 +5812,21 @@ namespace Google.Protobuf.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -5473,6 +5977,9 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Data != 0) {
output.WriteRawTag(8);
output.WriteInt32(Data);
@@ -5480,7 +5987,21 @@ namespace Google.Protobuf.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -5628,6 +6149,9 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Data != 0) {
output.WriteRawTag(8);
output.WriteUInt32(Data);
@@ -5635,7 +6159,21 @@ namespace Google.Protobuf.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -5783,6 +6321,9 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Data != 0L) {
output.WriteRawTag(8);
output.WriteInt64(Data);
@@ -5790,7 +6331,21 @@ namespace Google.Protobuf.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -5938,6 +6493,9 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Data != 0UL) {
output.WriteRawTag(8);
output.WriteUInt64(Data);
@@ -5945,7 +6503,21 @@ namespace Google.Protobuf.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -6093,6 +6665,9 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Data != false) {
output.WriteRawTag(8);
output.WriteBool(Data);
@@ -6100,7 +6675,21 @@ namespace Google.Protobuf.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -6310,6 +6899,9 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (fooCase_ == FooOneofCase.FooInt) {
output.WriteRawTag(8);
output.WriteInt32(FooInt);
@@ -6325,7 +6917,29 @@ namespace Google.Protobuf.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -6685,6 +7299,9 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
packedInt32_.WriteTo(output, _repeated_packedInt32_codec);
packedInt64_.WriteTo(output, _repeated_packedInt64_codec);
packedUint32_.WriteTo(output, _repeated_packedUint32_codec);
@@ -6702,7 +7319,31 @@ namespace Google.Protobuf.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -7176,6 +7817,9 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
unpackedInt32_.WriteTo(output, _repeated_unpackedInt32_codec);
unpackedInt64_.WriteTo(output, _repeated_unpackedInt64_codec);
unpackedUint32_.WriteTo(output, _repeated_unpackedUint32_codec);
@@ -7193,7 +7837,31 @@ namespace Google.Protobuf.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -7573,6 +8241,9 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
repeatedFixed32_.WriteTo(output, _repeated_repeatedFixed32_codec);
repeatedInt32_.WriteTo(output, _repeated_repeatedInt32_codec);
repeatedFixed64_.WriteTo(output, _repeated_repeatedFixed64_codec);
@@ -7582,7 +8253,23 @@ namespace Google.Protobuf.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -7791,6 +8478,9 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (A.Length != 0) {
output.WriteRawTag(10);
output.WriteString(A);
@@ -7798,7 +8488,21 @@ namespace Google.Protobuf.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -7935,10 +8639,23 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -8058,10 +8775,23 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -8181,10 +8911,23 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -8304,10 +9047,23 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -8427,10 +9183,23 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -8550,10 +9319,23 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -8673,10 +9455,23 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -8816,6 +9611,9 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Text.Length != 0) {
output.WriteRawTag(10);
output.WriteString(Text);
@@ -8823,7 +9621,21 @@ namespace Google.Protobuf.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -8989,6 +9801,9 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (NestedText.Length != 0) {
output.WriteRawTag(10);
output.WriteString(NestedText);
@@ -8996,7 +9811,21 @@ namespace Google.Protobuf.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3Optional.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3Optional.cs
index c8cd7f7aa3..451709f4dd 100644
--- a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3Optional.cs
+++ b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestProto3Optional.cs
@@ -622,6 +622,9 @@ namespace ProtobufUnittest {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasOptionalInt32) {
output.WriteRawTag(8);
output.WriteInt32(OptionalInt32);
@@ -709,7 +712,101 @@ namespace ProtobufUnittest {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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 (HasOptionalCord) {
+ output.WriteRawTag(130, 1);
+ output.WriteString(OptionalCord);
+ }
+ if (optionalNestedMessage_ != null) {
+ output.WriteRawTag(146, 1);
+ output.WriteMessage(OptionalNestedMessage);
+ }
+ if (lazyNestedMessage_ != null) {
+ output.WriteRawTag(154, 1);
+ output.WriteMessage(LazyNestedMessage);
+ }
+ if (HasOptionalNestedEnum) {
+ output.WriteRawTag(168, 1);
+ output.WriteEnum((int) OptionalNestedEnum);
+ }
+ if (SingularInt32 != 0) {
+ output.WriteRawTag(176, 1);
+ output.WriteInt32(SingularInt32);
+ }
+ if (SingularInt64 != 0L) {
+ output.WriteRawTag(184, 1);
+ output.WriteInt64(SingularInt64);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -1186,6 +1283,9 @@ namespace ProtobufUnittest {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasBb) {
output.WriteRawTag(8);
output.WriteInt32(Bb);
@@ -1193,8 +1293,22 @@ namespace ProtobufUnittest {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestSelfreferentialOptions.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestSelfreferentialOptions.cs
index 4365368acc..7ed1580ab2 100644
--- a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestSelfreferentialOptions.cs
+++ b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestSelfreferentialOptions.cs
@@ -203,6 +203,9 @@ namespace UnitTest.Issues.TestProtos.SelfreferentialOptions {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasIntOpt) {
output.WriteRawTag(8);
output.WriteInt32(IntOpt);
@@ -217,7 +220,28 @@ namespace UnitTest.Issues.TestProtos.SelfreferentialOptions {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (HasIntOpt) {
+ output.WriteRawTag(8);
+ output.WriteInt32(IntOpt);
+ }
+ if (HasFoo) {
+ output.WriteRawTag(16);
+ output.WriteInt32(Foo);
+ }
+ if (_extensions != null) {
+ _extensions.WriteTo(ref output);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
diff --git a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestWellKnownTypes.cs b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestWellKnownTypes.cs
index 30c906cd40..996e928cfd 100644
--- a/csharp/src/Google.Protobuf.Test.TestProtos/UnittestWellKnownTypes.cs
+++ b/csharp/src/Google.Protobuf.Test.TestProtos/UnittestWellKnownTypes.cs
@@ -535,6 +535,9 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (anyField_ != null) {
output.WriteRawTag(10);
output.WriteMessage(AnyField);
@@ -605,7 +608,84 @@ namespace Google.Protobuf.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -1393,6 +1473,9 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
anyField_.WriteTo(output, _repeated_anyField_codec);
apiField_.WriteTo(output, _repeated_apiField_codec);
durationField_.WriteTo(output, _repeated_durationField_codec);
@@ -1414,7 +1497,35 @@ namespace Google.Protobuf.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -2051,6 +2162,9 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (oneofFieldCase_ == OneofFieldOneofCase.AnyField) {
output.WriteRawTag(10);
output.WriteMessage(AnyField);
@@ -2117,7 +2231,80 @@ namespace Google.Protobuf.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -2848,6 +3035,9 @@ namespace Google.Protobuf.TestProtos {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
anyField_.WriteTo(output, _map_anyField_codec);
apiField_.WriteTo(output, _map_apiField_codec);
durationField_.WriteTo(output, _map_durationField_codec);
@@ -2869,8 +3059,36 @@ namespace Google.Protobuf.TestProtos {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
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 0000000000..8e42d13dab
--- /dev/null
+++ b/csharp/src/Google.Protobuf.Test/Buffers/ArrayBufferWriter.cs
@@ -0,0 +1,225 @@
+#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;
+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;
+ }
+
+ ///
+ /// Userful for testing writing to buffer writer with a lot of small segments.
+ /// If set, it limits the max number of bytes by which the buffer grows by at once.
+ ///
+ public int? MaxGrowBy { get; set; }
+
+ ///
+ /// 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);
+ }
+
+ // enable tests that write to small buffer segments
+ if (MaxGrowBy.HasValue && growBy > MaxGrowBy.Value)
+ {
+ growBy = MaxGrowBy.Value;
+ }
+
+ int newSize = checked(_buffer.Length + growBy);
+
+ Array.Resize(ref _buffer, newSize);
+ }
+
+ Debug.Assert(FreeCapacity > 0 && FreeCapacity >= sizeHint);
+ }
+ }
+}
\ No newline at end of file
diff --git a/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs b/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs
index b9ff51521f..1c77e121d3 100644
--- a/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs
+++ b/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs
@@ -33,6 +33,7 @@
using System;
using System.IO;
using Google.Protobuf.TestProtos;
+using Google.Protobuf.Buffers;
using NUnit.Framework;
namespace Google.Protobuf
@@ -48,22 +49,39 @@ namespace Google.Protobuf
// Only do 32-bit write if the value fits in 32 bits.
if ((value >> 32) == 0)
{
+ // CodedOutputStream
MemoryStream rawOutput = new MemoryStream();
CodedOutputStream output = new CodedOutputStream(rawOutput);
output.WriteRawVarint32((uint) value);
output.Flush();
Assert.AreEqual(data, rawOutput.ToArray());
+
+ // IBufferWriter
+ var bufferWriter = new ArrayBufferWriter();
+ WriteContext.Initialize(bufferWriter, out WriteContext ctx);
+ ctx.WriteUInt32((uint) value);
+ ctx.Flush();
+ Assert.AreEqual(data, bufferWriter.WrittenSpan.ToArray());
+
// Also try computing size.
Assert.AreEqual(data.Length, CodedOutputStream.ComputeRawVarint32Size((uint) value));
}
{
+ // CodedOutputStream
MemoryStream rawOutput = new MemoryStream();
CodedOutputStream output = new CodedOutputStream(rawOutput);
output.WriteRawVarint64(value);
output.Flush();
Assert.AreEqual(data, rawOutput.ToArray());
+ // IBufferWriter
+ var bufferWriter = new ArrayBufferWriter();
+ WriteContext.Initialize(bufferWriter, out WriteContext ctx);
+ ctx.WriteUInt64(value);
+ ctx.Flush();
+ Assert.AreEqual(data, bufferWriter.WrittenSpan.ToArray());
+
// Also try computing size.
Assert.AreEqual(data.Length, CodedOutputStream.ComputeRawVarint64Size(value));
}
@@ -80,6 +98,13 @@ namespace Google.Protobuf
output.WriteRawVarint32((uint) value);
output.Flush();
Assert.AreEqual(data, rawOutput.ToArray());
+
+ var bufferWriter = new ArrayBufferWriter();
+ bufferWriter.MaxGrowBy = bufferSize;
+ WriteContext.Initialize(bufferWriter, out WriteContext ctx);
+ ctx.WriteUInt32((uint) value);
+ ctx.Flush();
+ Assert.AreEqual(data, bufferWriter.WrittenSpan.ToArray());
}
{
@@ -88,7 +113,15 @@ namespace Google.Protobuf
output.WriteRawVarint64(value);
output.Flush();
Assert.AreEqual(data, rawOutput.ToArray());
+
+ var bufferWriter = new ArrayBufferWriter();
+ bufferWriter.MaxGrowBy = bufferSize;
+ WriteContext.Initialize(bufferWriter, out WriteContext ctx);
+ ctx.WriteUInt64(value);
+ ctx.Flush();
+ Assert.AreEqual(data, bufferWriter.WrittenSpan.ToArray());
}
+
}
}
@@ -133,20 +166,35 @@ namespace Google.Protobuf
///
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());
+ {
+ var rawOutput = new MemoryStream();
+ var output = new CodedOutputStream(rawOutput);
+ output.WriteRawLittleEndian32(value);
+ output.Flush();
+ Assert.AreEqual(data, rawOutput.ToArray());
+
+ var bufferWriter = new ArrayBufferWriter();
+ WriteContext.Initialize(bufferWriter, out WriteContext ctx);
+ ctx.WriteFixed32(value);
+ ctx.Flush();
+ Assert.AreEqual(data, bufferWriter.WrittenSpan.ToArray());
+ }
// Try different buffer sizes.
for (int bufferSize = 1; bufferSize <= 16; bufferSize *= 2)
{
- rawOutput = new MemoryStream();
- output = new CodedOutputStream(rawOutput, bufferSize);
+ var rawOutput = new MemoryStream();
+ var output = new CodedOutputStream(rawOutput, bufferSize);
output.WriteRawLittleEndian32(value);
output.Flush();
Assert.AreEqual(data, rawOutput.ToArray());
+
+ var bufferWriter = new ArrayBufferWriter();
+ bufferWriter.MaxGrowBy = bufferSize;
+ WriteContext.Initialize(bufferWriter, out WriteContext ctx);
+ ctx.WriteFixed32(value);
+ ctx.Flush();
+ Assert.AreEqual(data, bufferWriter.WrittenSpan.ToArray());
}
}
@@ -156,20 +204,35 @@ namespace Google.Protobuf
///
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());
+ {
+ var rawOutput = new MemoryStream();
+ var output = new CodedOutputStream(rawOutput);
+ output.WriteRawLittleEndian64(value);
+ output.Flush();
+ Assert.AreEqual(data, rawOutput.ToArray());
+
+ var bufferWriter = new ArrayBufferWriter();
+ WriteContext.Initialize(bufferWriter, out WriteContext ctx);
+ ctx.WriteFixed64(value);
+ ctx.Flush();
+ Assert.AreEqual(data, bufferWriter.WrittenSpan.ToArray());
+ }
// Try different block sizes.
for (int blockSize = 1; blockSize <= 16; blockSize *= 2)
{
- rawOutput = new MemoryStream();
- output = new CodedOutputStream(rawOutput, blockSize);
+ var rawOutput = new MemoryStream();
+ var output = new CodedOutputStream(rawOutput, blockSize);
output.WriteRawLittleEndian64(value);
output.Flush();
Assert.AreEqual(data, rawOutput.ToArray());
+
+ var bufferWriter = new ArrayBufferWriter();
+ bufferWriter.MaxGrowBy = blockSize;
+ WriteContext.Initialize(bufferWriter, out WriteContext ctx);
+ ctx.WriteFixed64(value);
+ ctx.Flush();
+ Assert.AreEqual(data, bufferWriter.WrittenSpan.ToArray());
}
}
@@ -205,41 +268,72 @@ namespace Google.Protobuf
message.WriteTo(output);
output.Flush();
Assert.AreEqual(rawBytes, rawOutput.ToArray());
+
+ var bufferWriter = new ArrayBufferWriter();
+ bufferWriter.MaxGrowBy = blockSize;
+ message.WriteTo(bufferWriter);
+ Assert.AreEqual(rawBytes, bufferWriter.WrittenSpan.ToArray());
}
}
+
+ [Test]
+ public void WriteContext_WritesWithFlushes()
+ {
+ TestAllTypes message = SampleMessages.CreateFullTestAllTypes();
+
+ MemoryStream expectedOutput = new MemoryStream();
+ CodedOutputStream output = new CodedOutputStream(expectedOutput);
+ output.WriteMessage(message);
+ output.Flush();
+ byte[] expectedBytes1 = expectedOutput.ToArray();
+
+ output.WriteMessage(message);
+ output.Flush();
+ byte[] expectedBytes2 = expectedOutput.ToArray();
+
+ var bufferWriter = new ArrayBufferWriter();
+ WriteContext.Initialize(bufferWriter, out WriteContext ctx);
+ ctx.WriteMessage(message);
+ ctx.Flush();
+ Assert.AreEqual(expectedBytes1, bufferWriter.WrittenSpan.ToArray());
+
+ ctx.WriteMessage(message);
+ ctx.Flush();
+ Assert.AreEqual(expectedBytes2, bufferWriter.WrittenSpan.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)));
+ Assert.AreEqual(0u, WritingPrimitives.EncodeZigZag32(0));
+ Assert.AreEqual(1u, WritingPrimitives.EncodeZigZag32(-1));
+ Assert.AreEqual(2u, WritingPrimitives.EncodeZigZag32(1));
+ Assert.AreEqual(3u, WritingPrimitives.EncodeZigZag32(-2));
+ Assert.AreEqual(0x7FFFFFFEu, WritingPrimitives.EncodeZigZag32(0x3FFFFFFF));
+ Assert.AreEqual(0x7FFFFFFFu, WritingPrimitives.EncodeZigZag32(unchecked((int) 0xC0000000)));
+ Assert.AreEqual(0xFFFFFFFEu, WritingPrimitives.EncodeZigZag32(0x7FFFFFFF));
+ Assert.AreEqual(0xFFFFFFFFu, WritingPrimitives.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(0u, WritingPrimitives.EncodeZigZag64(0));
+ Assert.AreEqual(1u, WritingPrimitives.EncodeZigZag64(-1));
+ Assert.AreEqual(2u, WritingPrimitives.EncodeZigZag64(1));
+ Assert.AreEqual(3u, WritingPrimitives.EncodeZigZag64(-2));
Assert.AreEqual(0x000000007FFFFFFEuL,
- CodedOutputStream.EncodeZigZag64(unchecked((long) 0x000000003FFFFFFFUL)));
+ WritingPrimitives.EncodeZigZag64(unchecked((long) 0x000000003FFFFFFFUL)));
Assert.AreEqual(0x000000007FFFFFFFuL,
- CodedOutputStream.EncodeZigZag64(unchecked((long) 0xFFFFFFFFC0000000UL)));
+ WritingPrimitives.EncodeZigZag64(unchecked((long) 0xFFFFFFFFC0000000UL)));
Assert.AreEqual(0x00000000FFFFFFFEuL,
- CodedOutputStream.EncodeZigZag64(unchecked((long) 0x000000007FFFFFFFUL)));
+ WritingPrimitives.EncodeZigZag64(unchecked((long) 0x000000007FFFFFFFUL)));
Assert.AreEqual(0x00000000FFFFFFFFuL,
- CodedOutputStream.EncodeZigZag64(unchecked((long) 0xFFFFFFFF80000000UL)));
+ WritingPrimitives.EncodeZigZag64(unchecked((long) 0xFFFFFFFF80000000UL)));
Assert.AreEqual(0xFFFFFFFFFFFFFFFEL,
- CodedOutputStream.EncodeZigZag64(unchecked((long) 0x7FFFFFFFFFFFFFFFUL)));
+ WritingPrimitives.EncodeZigZag64(unchecked((long) 0x7FFFFFFFFFFFFFFFUL)));
Assert.AreEqual(0xFFFFFFFFFFFFFFFFL,
- CodedOutputStream.EncodeZigZag64(unchecked((long) 0x8000000000000000UL)));
+ WritingPrimitives.EncodeZigZag64(unchecked((long) 0x8000000000000000UL)));
}
[Test]
@@ -247,26 +341,26 @@ namespace Google.Protobuf
{
// Some easier-to-verify round-trip tests. The inputs (other than 0, 1, -1)
// were chosen semi-randomly via keyboard bashing.
- Assert.AreEqual(0, ParsingPrimitives.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(0)));
- Assert.AreEqual(1, ParsingPrimitives.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(1)));
- Assert.AreEqual(-1, ParsingPrimitives.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(-1)));
- Assert.AreEqual(14927, ParsingPrimitives.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(14927)));
- Assert.AreEqual(-3612, ParsingPrimitives.DecodeZigZag32(CodedOutputStream.EncodeZigZag32(-3612)));
+ Assert.AreEqual(0, ParsingPrimitives.DecodeZigZag32(WritingPrimitives.EncodeZigZag32(0)));
+ Assert.AreEqual(1, ParsingPrimitives.DecodeZigZag32(WritingPrimitives.EncodeZigZag32(1)));
+ Assert.AreEqual(-1, ParsingPrimitives.DecodeZigZag32(WritingPrimitives.EncodeZigZag32(-1)));
+ Assert.AreEqual(14927, ParsingPrimitives.DecodeZigZag32(WritingPrimitives.EncodeZigZag32(14927)));
+ Assert.AreEqual(-3612, ParsingPrimitives.DecodeZigZag32(WritingPrimitives.EncodeZigZag32(-3612)));
}
[Test]
public void RoundTripZigZag64()
{
- Assert.AreEqual(0, ParsingPrimitives.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(0)));
- Assert.AreEqual(1, ParsingPrimitives.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(1)));
- Assert.AreEqual(-1, ParsingPrimitives.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(-1)));
- Assert.AreEqual(14927, ParsingPrimitives.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(14927)));
- Assert.AreEqual(-3612, ParsingPrimitives.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(-3612)));
+ Assert.AreEqual(0, ParsingPrimitives.DecodeZigZag64(WritingPrimitives.EncodeZigZag64(0)));
+ Assert.AreEqual(1, ParsingPrimitives.DecodeZigZag64(WritingPrimitives.EncodeZigZag64(1)));
+ Assert.AreEqual(-1, ParsingPrimitives.DecodeZigZag64(WritingPrimitives.EncodeZigZag64(-1)));
+ Assert.AreEqual(14927, ParsingPrimitives.DecodeZigZag64(WritingPrimitives.EncodeZigZag64(14927)));
+ Assert.AreEqual(-3612, ParsingPrimitives.DecodeZigZag64(WritingPrimitives.EncodeZigZag64(-3612)));
Assert.AreEqual(856912304801416L,
- ParsingPrimitives.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(856912304801416L)));
+ ParsingPrimitives.DecodeZigZag64(WritingPrimitives.EncodeZigZag64(856912304801416L)));
Assert.AreEqual(-75123905439571256L,
- ParsingPrimitives.DecodeZigZag64(CodedOutputStream.EncodeZigZag64(-75123905439571256L)));
+ ParsingPrimitives.DecodeZigZag64(WritingPrimitives.EncodeZigZag64(-75123905439571256L)));
}
[Test]
@@ -395,7 +489,7 @@ namespace Google.Protobuf
Assert.IsTrue(memoryStream.CanWrite);
using (var cos = new CodedOutputStream(memoryStream))
{
- cos.WriteRawByte(0);
+ cos.WriteRawBytes(new byte[] {0});
Assert.AreEqual(0, memoryStream.Position); // Not flushed yet
}
Assert.AreEqual(1, memoryStream.ToArray().Length); // Flushed data from CodedOutputStream to MemoryStream
@@ -409,7 +503,7 @@ namespace Google.Protobuf
Assert.IsTrue(memoryStream.CanWrite);
using (var cos = new CodedOutputStream(memoryStream, true))
{
- cos.WriteRawByte(0);
+ cos.WriteRawBytes(new byte[] {0});
Assert.AreEqual(0, memoryStream.Position); // Not flushed yet
}
Assert.AreEqual(1, memoryStream.Position); // Flushed data from CodedOutputStream to MemoryStream
diff --git a/csharp/src/Google.Protobuf.Test/ExtensionSetTest.cs b/csharp/src/Google.Protobuf.Test/ExtensionSetTest.cs
index 934b780ccc..aceb4a68f7 100644
--- a/csharp/src/Google.Protobuf.Test/ExtensionSetTest.cs
+++ b/csharp/src/Google.Protobuf.Test/ExtensionSetTest.cs
@@ -34,6 +34,8 @@ namespace Google.Protobuf
message.SetExtension(OptionalBoolExtension, true);
var serialized = message.ToByteArray();
+ MessageParsingHelpers.AssertWritingMessage(message);
+
MessageParsingHelpers.AssertReadingMessage(
TestAllExtensions.Parser.WithExtensionRegistry(new ExtensionRegistry() { OptionalBoolExtension }),
serialized,
diff --git a/csharp/src/Google.Protobuf.Test/FieldCodecTest.cs b/csharp/src/Google.Protobuf.Test/FieldCodecTest.cs
index 5be0cecd99..7f366926fa 100644
--- a/csharp/src/Google.Protobuf.Test/FieldCodecTest.cs
+++ b/csharp/src/Google.Protobuf.Test/FieldCodecTest.cs
@@ -124,7 +124,17 @@ namespace Google.Protobuf
{
var stream = new MemoryStream();
var codedOutput = new CodedOutputStream(stream);
- codec.ValueWriter(codedOutput, sampleValue);
+ WriteContext.Initialize(codedOutput, out WriteContext ctx);
+ try
+ {
+ // only write the value using the codec
+ codec.ValueWriter(ref ctx, sampleValue);
+ }
+ finally
+ {
+ ctx.CopyStateTo(codedOutput);
+ }
+
codedOutput.Flush();
stream.Position = 0;
var codedInput = new CodedInputStream(stream);
@@ -175,7 +185,17 @@ namespace Google.Protobuf
if (codec.DefaultValue != null) // This part isn't appropriate for message types.
{
codedOutput = new CodedOutputStream(stream);
- codec.ValueWriter(codedOutput, codec.DefaultValue);
+ WriteContext.Initialize(codedOutput, out WriteContext ctx);
+ try
+ {
+ // only write the value using the codec
+ codec.ValueWriter(ref ctx, codec.DefaultValue);
+ }
+ finally
+ {
+ ctx.CopyStateTo(codedOutput);
+ }
+
codedOutput.Flush();
Assert.AreNotEqual(0, stream.Position);
Assert.AreEqual(stream.Position, codec.ValueSizeCalculator(codec.DefaultValue));
diff --git a/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.Proto2.cs b/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.Proto2.cs
index 5f90c94cce..1abed60563 100644
--- a/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.Proto2.cs
+++ b/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.Proto2.cs
@@ -344,6 +344,8 @@ namespace Google.Protobuf
}
};
+ MessageParsingHelpers.AssertWritingMessage(message);
+
MessageParsingHelpers.AssertRoundtrip(Proto2.TestAllTypes.Parser, message);
}
@@ -359,6 +361,8 @@ namespace Google.Protobuf
new RepeatedGroup_extension { A = 30 }
});
+ MessageParsingHelpers.AssertWritingMessage(message);
+
MessageParsingHelpers.AssertRoundtrip(
TestAllExtensions.Parser.WithExtensionRegistry(new ExtensionRegistry() { UnittestExtensions.OptionalGroupExtension, UnittestExtensions.RepeatedGroupExtension }),
message);
@@ -370,6 +374,8 @@ namespace Google.Protobuf
var message = new TestGroupExtension();
message.SetExtension(TestNestedExtension.Extensions.OptionalGroupExtension, new TestNestedExtension.Types.OptionalGroup_extension { A = 10 });
+ MessageParsingHelpers.AssertWritingMessage(message);
+
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 3499e6617d..06af5e9e9a 100644
--- a/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs
+++ b/csharp/src/Google.Protobuf.Test/GeneratedMessageTest.cs
@@ -132,6 +132,8 @@ namespace Google.Protobuf
byte[] bytes = message.ToByteArray();
Assert.AreEqual(0, bytes.Length);
+ MessageParsingHelpers.AssertWritingMessage(message);
+
MessageParsingHelpers.AssertRoundtrip(TestAllTypes.Parser, message);
}
@@ -164,7 +166,7 @@ namespace Google.Protobuf
SingleUint64 = ulong.MaxValue
};
- byte[] bytes = message.ToByteArray();
+ MessageParsingHelpers.AssertWritingMessage(message);
MessageParsingHelpers.AssertRoundtrip(TestAllTypes.Parser, message);
}
@@ -198,7 +200,7 @@ namespace Google.Protobuf
RepeatedUint64 = { ulong.MaxValue, uint.MinValue }
};
- byte[] bytes = message.ToByteArray();
+ MessageParsingHelpers.AssertWritingMessage(message);
MessageParsingHelpers.AssertRoundtrip(TestAllTypes.Parser, message);
}
@@ -230,7 +232,7 @@ namespace Google.Protobuf
}
};
- byte[] bytes = message.ToByteArray();
+ MessageParsingHelpers.AssertWritingMessage(message);
MessageParsingHelpers.AssertRoundtrip(TestMap.Parser, message);
}
@@ -246,6 +248,8 @@ namespace Google.Protobuf
byte[] bytes = message.ToByteArray();
Assert.AreEqual(2, bytes.Length); // Tag for field entry (1 byte), length of entry (0; 1 byte)
+ MessageParsingHelpers.AssertWritingMessage(message);
+
MessageParsingHelpers.AssertReadingMessage(
TestMap.Parser,
bytes,
@@ -660,6 +664,8 @@ namespace Google.Protobuf
var bytes = message.ToByteArray();
Assert.AreEqual(3, bytes.Length); // 2 bytes for the tag + 1 for the value - no string!
+ MessageParsingHelpers.AssertWritingMessage(message);
+
MessageParsingHelpers.AssertRoundtrip(TestAllTypes.Parser, message, parsedMessage =>
{
Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.OneofUint32, parsedMessage.OneofFieldCase);
@@ -675,6 +681,8 @@ namespace Google.Protobuf
var bytes = message.ToByteArray();
Assert.AreEqual(3, bytes.Length); // 2 bytes for the tag + 1 for the value - it's still serialized
+ MessageParsingHelpers.AssertWritingMessage(message);
+
MessageParsingHelpers.AssertRoundtrip(TestAllTypes.Parser, message, parsedMessage =>
{
Assert.AreEqual(TestAllTypes.OneofFieldOneofCase.OneofUint32, parsedMessage.OneofFieldCase);
diff --git a/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs b/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs
index 5e9730b2af..1a650933ef 100644
--- a/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs
+++ b/csharp/src/Google.Protobuf.Test/JsonFormatterTest.cs
@@ -226,6 +226,28 @@ namespace Google.Protobuf
JsonFormatter.Default.Format(new TestMap { MapBoolBool = { { false, true }, { true, false } } }));
}
+ [Test]
+ public void NullValueOutsideStruct()
+ {
+ var message = new NullValueOutsideStruct { NullValue = NullValue.NullValue };
+ AssertJson("{ 'nullValue': null }", JsonFormatter.Default.Format(message));
+ }
+
+ [Test]
+ public void NullValueNotInOneof()
+ {
+ var message = new NullValueNotInOneof();
+ AssertJson("{ }", JsonFormatter.Default.Format(message));
+ }
+
+ [Test]
+ public void NullValueNotInOneof_FormatDefaults()
+ {
+ var formatter = new JsonFormatter(JsonFormatter.Settings.Default.WithFormatDefaultValues(true));
+ var message = new NullValueNotInOneof();
+ AssertJson("{ 'nullValue': null }", formatter.Format(message));
+ }
+
[TestCase(1.0, "1")]
[TestCase(double.NaN, "'NaN'")]
[TestCase(double.PositiveInfinity, "'Infinity'")]
diff --git a/csharp/src/Google.Protobuf.Test/JsonParserTest.cs b/csharp/src/Google.Protobuf.Test/JsonParserTest.cs
index f9f8cde050..e170fcc5a0 100644
--- a/csharp/src/Google.Protobuf.Test/JsonParserTest.cs
+++ b/csharp/src/Google.Protobuf.Test/JsonParserTest.cs
@@ -36,6 +36,7 @@ using Google.Protobuf.WellKnownTypes;
using NUnit.Framework;
using ProtobufTestMessages.Proto2;
using System;
+using UnitTest.Issues.TestProtos;
namespace Google.Protobuf
{
@@ -974,6 +975,43 @@ namespace Google.Protobuf
Assert.AreEqual(expected, actual);
}
+ [Test]
+ public void NullValueOutsideStruct_NullLiteral()
+ {
+ string json = "{ \"nullValue\": null }";
+ var message = NullValueOutsideStruct.Parser.ParseJson(json);
+ Assert.AreEqual(NullValueOutsideStruct.ValueOneofCase.NullValue, message.ValueCase);
+ }
+
+ [Test]
+ public void NullValueNotInOneof_NullLiteral()
+ {
+ // We'd only normally see this with FormatDefaultValues set to true.
+ string json = "{ \"nullValue\": null }";
+ var message = NullValueNotInOneof.Parser.ParseJson(json);
+ Assert.AreEqual(NullValue.NullValue, message.NullValue);
+ }
+
+ // NullValue used to only be converted to the null literal when part of a struct.
+ // Otherwise, it would end up as a string "NULL_VALUE" (the name of the enum value).
+ // We still parse that form, for compatibility.
+ [Test]
+ public void NullValueOutsideStruct_Compatibility()
+ {
+ string json = "{ \"nullValue\": \"NULL_VALUE\" }";
+ var message = NullValueOutsideStruct.Parser.ParseJson(json);
+ Assert.AreEqual(NullValueOutsideStruct.ValueOneofCase.NullValue, message.ValueCase);
+ }
+
+ [Test]
+ public void NullValueNotInOneof_Compatibility()
+ {
+ // We'd only normally see this with FormatDefaultValues set to true.
+ string json = "{ \"nullValue\": \"NULL_VALUE\" }";
+ var message = NullValueNotInOneof.Parser.ParseJson(json);
+ Assert.AreEqual(NullValue.NullValue, message.NullValue);
+ }
+
///
/// Various tests use strings which have quotes round them for parsing or as the result
/// of formatting, but without those quotes being specified in the tests (for the sake of readability).
diff --git a/csharp/src/Google.Protobuf.Test/LegacyGeneratedCodeTest.cs b/csharp/src/Google.Protobuf.Test/LegacyGeneratedCodeTest.cs
index 9c9846c8f5..da7b4a8c07 100644
--- a/csharp/src/Google.Protobuf.Test/LegacyGeneratedCodeTest.cs
+++ b/csharp/src/Google.Protobuf.Test/LegacyGeneratedCodeTest.cs
@@ -35,7 +35,9 @@ using System.Buffers;
using pb = global::Google.Protobuf;
using pbr = global::Google.Protobuf.Reflection;
using NUnit.Framework;
-
+using System.IO;
+using System;
+using Google.Protobuf.Buffers;
namespace Google.Protobuf
{
@@ -46,14 +48,14 @@ namespace Google.Protobuf
{
var message = new ParseContextEnabledMessageB
{
- A = new LegacyGeneratedCodeMessageA
- {
- Bb = new ParseContextEnabledMessageB { OptionalInt32 = 12345 }
- },
- OptionalInt32 = 6789
+ A = new LegacyGeneratedCodeMessageA
+ {
+ Bb = new ParseContextEnabledMessageB { OptionalInt32 = 12345 }
+ },
+ OptionalInt32 = 6789
};
var data = message.ToByteArray();
-
+
// when parsing started using CodedInputStream and a message with legacy generated code
// is encountered somewhere in the parse tree, we still need to be able to use its
// MergeFrom(CodedInputStream) method to parse correctly.
@@ -71,11 +73,11 @@ namespace Google.Protobuf
{
var message = new ParseContextEnabledMessageB
{
- A = new LegacyGeneratedCodeMessageA
- {
- Bb = new ParseContextEnabledMessageB { OptionalInt32 = 12345 }
- },
- OptionalInt32 = 6789
+ A = new LegacyGeneratedCodeMessageA
+ {
+ Bb = new ParseContextEnabledMessageB { OptionalInt32 = 12345 }
+ },
+ OptionalInt32 = 6789
};
var data = message.ToByteArray();
@@ -86,13 +88,65 @@ namespace Google.Protobuf
// code up to date.
var exception = Assert.Throws(() =>
{
- ParseContext.Initialize(new ReadOnlySequence(data), out ParseContext parseCtx);
- var parsed = new ParseContextEnabledMessageB();
- ParsingPrimitivesMessages.ReadRawMessage(ref parseCtx, parsed);
+ ParseContext.Initialize(new ReadOnlySequence(data), out ParseContext parseCtx);
+ var parsed = new ParseContextEnabledMessageB();
+ ParsingPrimitivesMessages.ReadRawMessage(ref parseCtx, parsed);
});
Assert.AreEqual($"Message {typeof(LegacyGeneratedCodeMessageA).Name} doesn't provide the generated method that enables ParseContext-based parsing. You might need to regenerate the generated protobuf code.", exception.Message);
}
+ [Test]
+ public void IntermixingOfNewAndLegacyGeneratedCodeWorksWithCodedOutputStream()
+ {
+ // when serialization started using CodedOutputStream and a message with legacy generated code
+ // is encountered somewhere in the parse tree, we still need to be able to use its
+ // WriteTo(CodedOutputStream) method to serialize correctly.
+ var ms = new MemoryStream();
+ var codedOutput = new CodedOutputStream(ms);
+ var message = new ParseContextEnabledMessageB
+ {
+ A = new LegacyGeneratedCodeMessageA
+ {
+ Bb = new ParseContextEnabledMessageB { OptionalInt32 = 12345 }
+ },
+ OptionalInt32 = 6789
+ };
+ message.WriteTo(codedOutput);
+ codedOutput.Flush();
+
+ var codedInput = new CodedInputStream(ms.ToArray());
+ var parsed = new ParseContextEnabledMessageB();
+ codedInput.ReadRawMessage(parsed);
+ Assert.IsTrue(codedInput.IsAtEnd);
+
+ Assert.AreEqual(12345, parsed.A.Bb.OptionalInt32);
+ Assert.AreEqual(6789, parsed.OptionalInt32);
+ }
+
+ [Test]
+ public void LegacyGeneratedCodeThrowsWithIBufferWriter()
+ {
+ // if serialization started using IBufferWriter and we don't have a CodedOutputStream
+ // instance at hand, we cannot fall back to the legacy WriteTo(CodedOutputStream)
+ // method and serializatin will fail. As a consequence, one can only use serialization
+ // to IBufferWriter if all the messages in the parsing tree have their generated
+ // code up to date.
+ var message = new ParseContextEnabledMessageB
+ {
+ A = new LegacyGeneratedCodeMessageA
+ {
+ Bb = new ParseContextEnabledMessageB { OptionalInt32 = 12345 }
+ },
+ OptionalInt32 = 6789
+ };
+ var exception = Assert.Throws(() =>
+ {
+ WriteContext.Initialize(new ArrayBufferWriter(), out WriteContext writeCtx);
+ ((IBufferMessage)message).InternalWriteTo(ref writeCtx);
+ });
+ Assert.AreEqual($"Message {typeof(LegacyGeneratedCodeMessageA).Name} doesn't provide the generated method that enables WriteContext-based serialization. You might need to regenerate the generated protobuf code.", exception.Message);
+ }
+
// hand-modified version of a generated message that only provides the legacy
// MergeFrom(CodedInputStream) method and doesn't implement IBufferMessage.
private sealed partial class LegacyGeneratedCodeMessageA : pb::IMessage {
@@ -178,18 +232,27 @@ namespace Google.Protobuf
}
public void WriteTo(pb::CodedOutputStream output) {
- if (a_ != null) {
+ output.WriteRawMessage(this);
+ }
+
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output)
+ {
+ if (a_ != null)
+ {
output.WriteRawTag(10);
output.WriteMessage(A);
}
- if (OptionalInt32 != 0) {
+ if (OptionalInt32 != 0)
+ {
output.WriteRawTag(16);
output.WriteInt32(OptionalInt32);
}
- if (_unknownFields != null) {
- _unknownFields.WriteTo(output);
+ if (_unknownFields != null)
+ {
+ _unknownFields.WriteTo(ref output);
}
}
+
public int CalculateSize() {
int size = 0;
if (a_ != null) {
diff --git a/csharp/src/Google.Protobuf.Test/MessageParsingHelpers.cs b/csharp/src/Google.Protobuf.Test/MessageParsingHelpers.cs
index ec5f13abc3..36a2f02229 100644
--- a/csharp/src/Google.Protobuf.Test/MessageParsingHelpers.cs
+++ b/csharp/src/Google.Protobuf.Test/MessageParsingHelpers.cs
@@ -33,6 +33,7 @@
using NUnit.Framework;
using System;
using System.Buffers;
+using Google.Protobuf.Buffers;
namespace Google.Protobuf
{
@@ -81,6 +82,11 @@ namespace Google.Protobuf
{
var bytes = message.ToByteArray();
+ // also serialize using IBufferWriter and check it leads to the same data
+ var bufferWriter = new ArrayBufferWriter();
+ message.WriteTo(bufferWriter);
+ Assert.AreEqual(bytes, bufferWriter.WrittenSpan.ToArray(), "Both serialization approaches need to result in the same data.");
+
// Load content as single segment
var parsedBuffer = parser.ParseFrom(new ReadOnlySequence(bytes));
Assert.AreEqual(message, parsedBuffer);
@@ -96,5 +102,41 @@ namespace Google.Protobuf
Assert.AreEqual(message, parsedStream);
additionalAssert?.Invoke(parsedStream);
}
+
+ public static void AssertWritingMessage(IMessage message)
+ {
+ // serialize using CodedOutputStream
+ var bytes = message.ToByteArray();
+
+ int messageSize = message.CalculateSize();
+ Assert.AreEqual(message.CalculateSize(), bytes.Length);
+
+ // serialize using IBufferWriter and check it leads to the same output
+ var bufferWriter = new ArrayBufferWriter();
+ message.WriteTo(bufferWriter);
+ Assert.AreEqual(bytes, bufferWriter.WrittenSpan.ToArray());
+
+ // serialize into a single span and check it leads to the same output
+ var singleSpan = new Span(new byte[messageSize]);
+ message.WriteTo(singleSpan);
+ Assert.AreEqual(bytes, singleSpan.ToArray());
+
+ // test for different IBufferWriter.GetSpan() segment sizes
+ for (int blockSize = 1; blockSize < 256; blockSize *= 2)
+ {
+ var segmentedBufferWriter = new ArrayBufferWriter();
+ segmentedBufferWriter.MaxGrowBy = blockSize;
+ message.WriteTo(segmentedBufferWriter);
+ Assert.AreEqual(bytes, segmentedBufferWriter.WrittenSpan.ToArray());
+ }
+
+ // if the full message is small enough, try serializing directly into stack-allocated buffer
+ if (bytes.Length <= 256)
+ {
+ Span stackAllocBuffer = stackalloc byte[bytes.Length];
+ message.WriteTo(stackAllocBuffer);
+ Assert.AreEqual(bytes, stackAllocBuffer.ToArray());
+ }
+ }
}
}
\ No newline at end of file
diff --git a/csharp/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs b/csharp/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs
index 47ff2a18ed..94c4746a80 100644
--- a/csharp/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs
+++ b/csharp/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs
@@ -71,6 +71,8 @@ namespace Google.Protobuf.WellKnownTypes
Uint64Field = 4
};
+ MessageParsingHelpers.AssertWritingMessage(message);
+
MessageParsingHelpers.AssertRoundtrip(TestWellKnownTypes.Parser, message, parsed =>
{
Assert.AreEqual("x", parsed.StringField);
@@ -101,6 +103,8 @@ namespace Google.Protobuf.WellKnownTypes
Uint64Field = 0
};
+ MessageParsingHelpers.AssertWritingMessage(message);
+
MessageParsingHelpers.AssertRoundtrip(TestWellKnownTypes.Parser, message, parsed =>
{
Assert.AreEqual("", parsed.StringField);
@@ -144,6 +148,8 @@ namespace Google.Protobuf.WellKnownTypes
// Just to test a single value for sanity...
Assert.AreEqual("Second", message.StringField[1]);
+ MessageParsingHelpers.AssertWritingMessage(message);
+
MessageParsingHelpers.AssertRoundtrip(RepeatedWellKnownTypes.Parser, message);
}
@@ -169,6 +175,8 @@ namespace Google.Protobuf.WellKnownTypes
var message = new RepeatedWellKnownTypes { Int32Field = { 5, 0 } };
var actualBytes = message.ToByteArray();
Assert.AreEqual(expectedBytes, actualBytes);
+
+ MessageParsingHelpers.AssertWritingMessage(message);
}
[Test]
@@ -196,6 +204,8 @@ namespace Google.Protobuf.WellKnownTypes
// Just to test a single value for sanity...
Assert.AreEqual("Second", message.StringField[12]);
+ MessageParsingHelpers.AssertWritingMessage(message);
+
MessageParsingHelpers.AssertRoundtrip(MapWellKnownTypes.Parser, message);
}
diff --git a/csharp/src/Google.Protobuf.Test/testprotos.pb b/csharp/src/Google.Protobuf.Test/testprotos.pb
index 089ef7512a..f7313edc83 100644
Binary files a/csharp/src/Google.Protobuf.Test/testprotos.pb and b/csharp/src/Google.Protobuf.Test/testprotos.pb differ
diff --git a/csharp/src/Google.Protobuf/CodedOutputStream.ComputeSize.cs b/csharp/src/Google.Protobuf/CodedOutputStream.ComputeSize.cs
index aa7932470b..cb923549d4 100644
--- a/csharp/src/Google.Protobuf/CodedOutputStream.ComputeSize.cs
+++ b/csharp/src/Google.Protobuf/CodedOutputStream.ComputeSize.cs
@@ -132,7 +132,7 @@ namespace Google.Protobuf
///
public static int ComputeStringSize(String value)
{
- int byteArraySize = Utf8Encoding.GetByteCount(value);
+ int byteArraySize = WritingPrimitives.Utf8Encoding.GetByteCount(value);
return ComputeLengthSize(byteArraySize) + byteArraySize;
}
@@ -208,7 +208,7 @@ namespace Google.Protobuf
///
public static int ComputeSInt32Size(int value)
{
- return ComputeRawVarint32Size(EncodeZigZag32(value));
+ return ComputeRawVarint32Size(WritingPrimitives.EncodeZigZag32(value));
}
///
@@ -217,7 +217,7 @@ namespace Google.Protobuf
///
public static int ComputeSInt64Size(long value)
{
- return ComputeRawVarint64Size(EncodeZigZag64(value));
+ return ComputeRawVarint64Size(WritingPrimitives.EncodeZigZag64(value));
}
///
diff --git a/csharp/src/Google.Protobuf/CodedOutputStream.cs b/csharp/src/Google.Protobuf/CodedOutputStream.cs
index 1d76d27602..20d88ea7dc 100644
--- a/csharp/src/Google.Protobuf/CodedOutputStream.cs
+++ b/csharp/src/Google.Protobuf/CodedOutputStream.cs
@@ -33,6 +33,7 @@
using Google.Protobuf.Collections;
using System;
using System.IO;
+using System.Security;
using System.Text;
namespace Google.Protobuf
@@ -55,11 +56,9 @@ namespace Google.Protobuf
/// and MapField<TKey, TValue> to serialize such fields.
///
///
+ [SecuritySafeCritical]
public sealed partial class CodedOutputStream : IDisposable
{
- // "Local" copy of Encoding.UTF8, for efficiency. (Yes, it makes a difference.)
- internal static readonly Encoding Utf8Encoding = Encoding.UTF8;
-
///
/// The buffer size used by CreateInstance(Stream).
///
@@ -67,8 +66,8 @@ namespace Google.Protobuf
private readonly bool leaveOpen;
private readonly byte[] buffer;
- private readonly int limit;
- private int position;
+ private WriterInternalState state;
+
private readonly Stream output;
#region Construction
@@ -90,8 +89,9 @@ namespace Google.Protobuf
{
this.output = null;
this.buffer = ProtoPreconditions.CheckNotNull(buffer, nameof(buffer));
- this.position = offset;
- this.limit = offset + length;
+ this.state.position = offset;
+ this.state.limit = offset + length;
+ WriteBufferHelper.Initialize(this, out this.state.writeBufferHelper);
leaveOpen = true; // Simple way of avoiding trying to dispose of a null reference
}
@@ -99,8 +99,9 @@ namespace Google.Protobuf
{
this.output = ProtoPreconditions.CheckNotNull(output, nameof(output));
this.buffer = buffer;
- this.position = 0;
- this.limit = buffer.Length;
+ this.state.position = 0;
+ this.state.limit = buffer.Length;
+ WriteBufferHelper.Initialize(this, out this.state.writeBufferHelper);
this.leaveOpen = leaveOpen;
}
@@ -155,9 +156,9 @@ namespace Google.Protobuf
{
if (output != null)
{
- return output.Position + position;
+ return output.Position + state.position;
}
- return position;
+ return state.position;
}
}
@@ -169,7 +170,8 @@ namespace Google.Protobuf
/// The value to write
public void WriteDouble(double value)
{
- WriteRawLittleEndian64((ulong)BitConverter.DoubleToInt64Bits(value));
+ var span = new Span(buffer);
+ WritingPrimitives.WriteDouble(ref span, ref state, value);
}
///
@@ -178,23 +180,8 @@ namespace Google.Protobuf
/// The value to write
public void WriteFloat(float value)
{
- byte[] rawBytes = BitConverter.GetBytes(value);
- if (!BitConverter.IsLittleEndian)
- {
- ByteArray.Reverse(rawBytes);
- }
-
- if (limit - position >= 4)
- {
- buffer[position++] = rawBytes[0];
- buffer[position++] = rawBytes[1];
- buffer[position++] = rawBytes[2];
- buffer[position++] = rawBytes[3];
- }
- else
- {
- WriteRawBytes(rawBytes, 0, 4);
- }
+ var span = new Span(buffer);
+ WritingPrimitives.WriteFloat(ref span, ref state, value);
}
///
@@ -203,7 +190,8 @@ namespace Google.Protobuf
/// The value to write
public void WriteUInt64(ulong value)
{
- WriteRawVarint64(value);
+ var span = new Span(buffer);
+ WritingPrimitives.WriteUInt64(ref span, ref state, value);
}
///
@@ -212,7 +200,8 @@ namespace Google.Protobuf
/// The value to write
public void WriteInt64(long value)
{
- WriteRawVarint64((ulong) value);
+ var span = new Span(buffer);
+ WritingPrimitives.WriteInt64(ref span, ref state, value);
}
///
@@ -221,15 +210,8 @@ namespace Google.Protobuf
/// The value to write
public void WriteInt32(int value)
{
- if (value >= 0)
- {
- WriteRawVarint32((uint) value);
- }
- else
- {
- // Must sign-extend.
- WriteRawVarint64((ulong) value);
- }
+ var span = new Span(buffer);
+ WritingPrimitives.WriteInt32(ref span, ref state, value);
}
///
@@ -238,7 +220,8 @@ namespace Google.Protobuf
/// The value to write
public void WriteFixed64(ulong value)
{
- WriteRawLittleEndian64(value);
+ var span = new Span(buffer);
+ WritingPrimitives.WriteFixed64(ref span, ref state, value);
}
///
@@ -247,7 +230,8 @@ namespace Google.Protobuf
/// The value to write
public void WriteFixed32(uint value)
{
- WriteRawLittleEndian32(value);
+ var span = new Span(buffer);
+ WritingPrimitives.WriteFixed32(ref span, ref state, value);
}
///
@@ -256,7 +240,8 @@ namespace Google.Protobuf
/// The value to write
public void WriteBool(bool value)
{
- WriteRawByte(value ? (byte) 1 : (byte) 0);
+ var span = new Span(buffer);
+ WritingPrimitives.WriteBool(ref span, ref state, value);
}
///
@@ -266,41 +251,52 @@ namespace Google.Protobuf
/// The value to write
public void WriteString(string value)
{
- // Optimise the case where we have enough space to write
- // the string directly to the buffer, which should be common.
- int length = Utf8Encoding.GetByteCount(value);
- WriteLength(length);
- if (limit - position >= length)
+ var span = new Span(buffer);
+ WritingPrimitives.WriteString(ref span, ref state, value);
+ }
+
+ ///
+ /// Writes a message, without a tag, to the stream.
+ /// The data is length-prefixed.
+ ///
+ /// The value to write
+ public void WriteMessage(IMessage value)
+ {
+ // TODO(jtattermusch): if the message doesn't implement IBufferMessage (and thus does not provide the InternalWriteTo method),
+ // what we're doing here works fine, but could be more efficient.
+ // For now, this inefficiency is fine, considering this is only a backward-compatibility scenario (and regenerating the code fixes it).
+ var span = new Span(buffer);
+ WriteContext.Initialize(ref span, ref state, out WriteContext ctx);
+ try
{
- if (length == value.Length) // Must be all ASCII...
- {
- for (int i = 0; i < length; i++)
- {
- buffer[position + i] = (byte)value[i];
- }
- }
- else
- {
- Utf8Encoding.GetBytes(value, 0, value.Length, buffer, position);
- }
- position += length;
+ WritingPrimitivesMessages.WriteMessage(ref ctx, value);
}
- else
+ finally
{
- byte[] bytes = Utf8Encoding.GetBytes(value);
- WriteRawBytes(bytes);
+ ctx.CopyStateTo(this);
}
}
///
/// Writes a message, without a tag, to the stream.
- /// The data is length-prefixed.
+ /// Only the message data is written, without a length-delimiter.
///
/// The value to write
- public void WriteMessage(IMessage value)
- {
- WriteLength(value.CalculateSize());
- value.WriteTo(this);
+ public void WriteRawMessage(IMessage value)
+ {
+ // TODO(jtattermusch): if the message doesn't implement IBufferMessage (and thus does not provide the InternalWriteTo method),
+ // what we're doing here works fine, but could be more efficient.
+ // For now, this inefficiency is fine, considering this is only a backward-compatibility scenario (and regenerating the code fixes it).
+ var span = new Span(buffer);
+ WriteContext.Initialize(ref span, ref state, out WriteContext ctx);
+ try
+ {
+ WritingPrimitivesMessages.WriteRawMessage(ref ctx, value);
+ }
+ finally
+ {
+ ctx.CopyStateTo(this);
+ }
}
///
@@ -309,7 +305,16 @@ namespace Google.Protobuf
/// The value to write
public void WriteGroup(IMessage value)
{
- value.WriteTo(this);
+ var span = new Span(buffer);
+ WriteContext.Initialize(ref span, ref state, out WriteContext ctx);
+ try
+ {
+ WritingPrimitivesMessages.WriteGroup(ref ctx, value);
+ }
+ finally
+ {
+ ctx.CopyStateTo(this);
+ }
}
///
@@ -319,8 +324,8 @@ namespace Google.Protobuf
/// The value to write
public void WriteBytes(ByteString value)
{
- WriteLength(value.Length);
- value.WriteRawBytesTo(this);
+ var span = new Span(buffer);
+ WritingPrimitives.WriteBytes(ref span, ref state, value);
}
///
@@ -329,7 +334,8 @@ namespace Google.Protobuf
/// The value to write
public void WriteUInt32(uint value)
{
- WriteRawVarint32(value);
+ var span = new Span(buffer);
+ WritingPrimitives.WriteUInt32(ref span, ref state, value);
}
///
@@ -338,7 +344,8 @@ namespace Google.Protobuf
/// The value to write
public void WriteEnum(int value)
{
- WriteInt32(value);
+ var span = new Span(buffer);
+ WritingPrimitives.WriteEnum(ref span, ref state, value);
}
///
@@ -347,7 +354,8 @@ namespace Google.Protobuf
/// The value to write.
public void WriteSFixed32(int value)
{
- WriteRawLittleEndian32((uint) value);
+ var span = new Span(buffer);
+ WritingPrimitives.WriteSFixed32(ref span, ref state, value);
}
///
@@ -356,7 +364,8 @@ namespace Google.Protobuf
/// The value to write
public void WriteSFixed64(long value)
{
- WriteRawLittleEndian64((ulong) value);
+ var span = new Span(buffer);
+ WritingPrimitives.WriteSFixed64(ref span, ref state, value);
}
///
@@ -365,7 +374,8 @@ namespace Google.Protobuf
/// The value to write
public void WriteSInt32(int value)
{
- WriteRawVarint32(EncodeZigZag32(value));
+ var span = new Span(buffer);
+ WritingPrimitives.WriteSInt32(ref span, ref state, value);
}
///
@@ -374,7 +384,8 @@ namespace Google.Protobuf
/// The value to write
public void WriteSInt64(long value)
{
- WriteRawVarint64(EncodeZigZag64(value));
+ var span = new Span(buffer);
+ WritingPrimitives.WriteSInt64(ref span, ref state, value);
}
///
@@ -386,7 +397,8 @@ namespace Google.Protobuf
/// Length value, in bytes.
public void WriteLength(int length)
{
- WriteRawVarint32((uint) length);
+ var span = new Span(buffer);
+ WritingPrimitives.WriteLength(ref span, ref state, length);
}
#endregion
@@ -399,7 +411,8 @@ namespace Google.Protobuf
/// The wire format type of the tag to write
public void WriteTag(int fieldNumber, WireFormat.WireType type)
{
- WriteRawVarint32(WireFormat.MakeTag(fieldNumber, type));
+ var span = new Span(buffer);
+ WritingPrimitives.WriteTag(ref span, ref state, fieldNumber, type);
}
///
@@ -408,7 +421,8 @@ namespace Google.Protobuf
/// The encoded tag
public void WriteTag(uint tag)
{
- WriteRawVarint32(tag);
+ var span = new Span(buffer);
+ WritingPrimitives.WriteTag(ref span, ref state, tag);
}
///
@@ -417,7 +431,8 @@ namespace Google.Protobuf
/// The encoded tag
public void WriteRawTag(byte b1)
{
- WriteRawByte(b1);
+ var span = new Span(buffer);
+ WritingPrimitives.WriteRawTag(ref span, ref state, b1);
}
///
@@ -427,8 +442,8 @@ namespace Google.Protobuf
/// The second byte of the encoded tag
public void WriteRawTag(byte b1, byte b2)
{
- WriteRawByte(b1);
- WriteRawByte(b2);
+ var span = new Span(buffer);
+ WritingPrimitives.WriteRawTag(ref span, ref state, b1, b2);
}
///
@@ -439,9 +454,8 @@ namespace Google.Protobuf
/// The third byte of the encoded tag
public void WriteRawTag(byte b1, byte b2, byte b3)
{
- WriteRawByte(b1);
- WriteRawByte(b2);
- WriteRawByte(b3);
+ var span = new Span(buffer);
+ WritingPrimitives.WriteRawTag(ref span, ref state, b1, b2, b3);
}
///
@@ -453,10 +467,8 @@ namespace Google.Protobuf
/// The fourth byte of the encoded tag
public void WriteRawTag(byte b1, byte b2, byte b3, byte b4)
{
- WriteRawByte(b1);
- WriteRawByte(b2);
- WriteRawByte(b3);
- WriteRawByte(b4);
+ var span = new Span(buffer);
+ WritingPrimitives.WriteRawTag(ref span, ref state, b1, b2, b3, b4);
}
///
@@ -469,15 +481,13 @@ namespace Google.Protobuf
/// The fifth byte of the encoded tag
public void WriteRawTag(byte b1, byte b2, byte b3, byte b4, byte b5)
{
- WriteRawByte(b1);
- WriteRawByte(b2);
- WriteRawByte(b3);
- WriteRawByte(b4);
- WriteRawByte(b5);
+ var span = new Span(buffer);
+ WritingPrimitives.WriteRawTag(ref span, ref state, b1, b2, b3, b4, b5);
}
#endregion
#region Underlying writing primitives
+
///
/// Writes a 32 bit value as a varint. The fast route is taken when
/// there's enough buffer space left to whizz through without checking
@@ -485,112 +495,26 @@ namespace Google.Protobuf
///
internal void WriteRawVarint32(uint value)
{
- // Optimize for the common case of a single byte value
- if (value < 128 && position < limit)
- {
- buffer[position++] = (byte)value;
- return;
- }
-
- while (value > 127 && position < limit)
- {
- buffer[position++] = (byte) ((value & 0x7F) | 0x80);
- value >>= 7;
- }
- while (value > 127)
- {
- WriteRawByte((byte) ((value & 0x7F) | 0x80));
- value >>= 7;
- }
- if (position < limit)
- {
- buffer[position++] = (byte) value;
- }
- else
- {
- WriteRawByte((byte) value);
- }
+ var span = new Span(buffer);
+ WritingPrimitives.WriteRawVarint32(ref span, ref state, value);
}
internal void WriteRawVarint64(ulong value)
{
- while (value > 127 && position < limit)
- {
- buffer[position++] = (byte) ((value & 0x7F) | 0x80);
- value >>= 7;
- }
- while (value > 127)
- {
- WriteRawByte((byte) ((value & 0x7F) | 0x80));
- value >>= 7;
- }
- if (position < limit)
- {
- buffer[position++] = (byte) value;
- }
- else
- {
- WriteRawByte((byte) value);
- }
+ var span = new Span(buffer);
+ WritingPrimitives.WriteRawVarint64(ref span, ref state, value);
}
internal void WriteRawLittleEndian32(uint value)
{
- if (position + 4 > limit)
- {
- WriteRawByte((byte) value);
- WriteRawByte((byte) (value >> 8));
- WriteRawByte((byte) (value >> 16));
- WriteRawByte((byte) (value >> 24));
- }
- else
- {
- buffer[position++] = ((byte) value);
- buffer[position++] = ((byte) (value >> 8));
- buffer[position++] = ((byte) (value >> 16));
- buffer[position++] = ((byte) (value >> 24));
- }
+ var span = new Span(buffer);
+ WritingPrimitives.WriteRawLittleEndian32(ref span, ref state, value);
}
internal void WriteRawLittleEndian64(ulong value)
{
- if (position + 8 > limit)
- {
- WriteRawByte((byte) value);
- WriteRawByte((byte) (value >> 8));
- WriteRawByte((byte) (value >> 16));
- WriteRawByte((byte) (value >> 24));
- WriteRawByte((byte) (value >> 32));
- WriteRawByte((byte) (value >> 40));
- WriteRawByte((byte) (value >> 48));
- WriteRawByte((byte) (value >> 56));
- }
- else
- {
- buffer[position++] = ((byte) value);
- buffer[position++] = ((byte) (value >> 8));
- buffer[position++] = ((byte) (value >> 16));
- buffer[position++] = ((byte) (value >> 24));
- buffer[position++] = ((byte) (value >> 32));
- buffer[position++] = ((byte) (value >> 40));
- buffer[position++] = ((byte) (value >> 48));
- buffer[position++] = ((byte) (value >> 56));
- }
- }
-
- internal void WriteRawByte(byte value)
- {
- if (position == limit)
- {
- RefreshBuffer();
- }
-
- buffer[position++] = value;
- }
-
- internal void WriteRawByte(uint value)
- {
- WriteRawByte((byte) value);
+ var span = new Span(buffer);
+ WritingPrimitives.WriteRawLittleEndian64(ref span, ref state, value);
}
///
@@ -606,85 +530,12 @@ namespace Google.Protobuf
///
internal void WriteRawBytes(byte[] value, int offset, int length)
{
- if (limit - position >= length)
- {
- ByteArray.Copy(value, offset, buffer, position, length);
- // We have room in the current buffer.
- position += length;
- }
- else
- {
- // Write extends past current buffer. Fill the rest of this buffer and
- // flush.
- int bytesWritten = limit - position;
- ByteArray.Copy(value, offset, buffer, position, bytesWritten);
- offset += bytesWritten;
- length -= bytesWritten;
- position = limit;
- RefreshBuffer();
-
- // Now deal with the rest.
- // Since we have an output stream, this is our buffer
- // and buffer offset == 0
- if (length <= limit)
- {
- // Fits in new buffer.
- ByteArray.Copy(value, offset, buffer, 0, length);
- position = length;
- }
- else
- {
- // Write is very big. Let's do it all at once.
- output.Write(value, offset, length);
- }
- }
+ var span = new Span(buffer);
+ WritingPrimitives.WriteRawBytes(ref span, ref state, value, offset, length);
}
#endregion
- ///
- /// Encode a 32-bit value with ZigZag encoding.
- ///
- ///
- /// ZigZag encodes signed integers into values that can be efficiently
- /// encoded with varint. (Otherwise, negative values must be
- /// sign-extended to 64 bits to be varint encoded, thus always taking
- /// 10 bytes on the wire.)
- ///
- internal static uint EncodeZigZag32(int n)
- {
- // Note: the right-shift must be arithmetic
- return (uint) ((n << 1) ^ (n >> 31));
- }
-
- ///
- /// Encode a 64-bit value with ZigZag encoding.
- ///
- ///
- /// ZigZag encodes signed integers into values that can be efficiently
- /// encoded with varint. (Otherwise, negative values must be
- /// sign-extended to 64 bits to be varint encoded, thus always taking
- /// 10 bytes on the wire.)
- ///
- internal static ulong EncodeZigZag64(long n)
- {
- return (ulong) ((n << 1) ^ (n >> 63));
- }
-
- private void RefreshBuffer()
- {
- if (output == null)
- {
- // We're writing to a single buffer.
- throw new OutOfSpaceException();
- }
-
- // Since we have an output stream, this is our buffer
- // and buffer offset == 0
- output.Write(buffer, 0, position);
- position = 0;
- }
-
///
/// Indicates that a CodedOutputStream wrapping a flat byte array
/// ran out of space.
@@ -726,45 +577,31 @@ namespace Google.Protobuf
///
public void Flush()
{
- if (output != null)
- {
- RefreshBuffer();
- }
+ var span = new Span(buffer);
+ WriteBufferHelper.Flush(ref span, ref state);
}
///
/// Verifies that SpaceLeft returns zero. It's common to create a byte array
/// that is exactly big enough to hold a message, then write to it with
/// a CodedOutputStream. Calling CheckNoSpaceLeft after writing verifies that
- /// the message was actually as big as expected, which can help bugs.
+ /// the message was actually as big as expected, which can help finding bugs.
///
public void CheckNoSpaceLeft()
{
- if (SpaceLeft != 0)
- {
- throw new InvalidOperationException("Did not write as much data as expected.");
- }
+ WriteBufferHelper.CheckNoSpaceLeft(ref state);
}
///
/// If writing to a flat array, returns the space left in the array. Otherwise,
/// throws an InvalidOperationException.
///
- public int SpaceLeft
- {
- get
- {
- if (output == null)
- {
- return limit - position;
- }
- else
- {
- throw new InvalidOperationException(
- "SpaceLeft can only be called on CodedOutputStreams that are " +
- "writing to a flat array.");
- }
- }
- }
+ public int SpaceLeft => WriteBufferHelper.GetSpaceLeft(ref state);
+
+ internal byte[] InternalBuffer => buffer;
+
+ internal Stream InternalOutputStream => output;
+
+ internal ref WriterInternalState InternalState => ref state;
}
}
diff --git a/csharp/src/Google.Protobuf/Collections/MapField.cs b/csharp/src/Google.Protobuf/Collections/MapField.cs
index 48cd7ab445..d60ebc5a8a 100644
--- a/csharp/src/Google.Protobuf/Collections/MapField.cs
+++ b/csharp/src/Google.Protobuf/Collections/MapField.cs
@@ -464,14 +464,34 @@ namespace Google.Protobuf.Collections
/// The output stream to write to.
/// The codec to use for each entry.
public void WriteTo(CodedOutputStream output, Codec codec)
+ {
+ WriteContext.Initialize(output, out WriteContext ctx);
+ try
+ {
+ WriteTo(ref ctx, codec);
+ }
+ finally
+ {
+ ctx.CopyStateTo(output);
+ }
+ }
+
+ ///
+ /// Writes the contents of this map to the given write context, using the specified codec
+ /// to encode each entry.
+ ///
+ /// The write context to write to.
+ /// The codec to use for each entry.
+ [SecuritySafeCritical]
+ public void WriteTo(ref WriteContext ctx, 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);
+ ctx.WriteTag(codec.MapTag);
+ ctx.WriteMessage(message);
}
}
@@ -711,8 +731,15 @@ namespace Google.Protobuf.Collections
public void WriteTo(CodedOutputStream output)
{
- codec.keyCodec.WriteTagAndValue(output, Key);
- codec.valueCodec.WriteTagAndValue(output, Value);
+ // Message adapter is an internal class and we know that all the writing will happen via InternalWriteTo.
+ throw new NotImplementedException();
+ }
+
+ [SecuritySafeCritical]
+ public void InternalWriteTo(ref WriteContext ctx)
+ {
+ codec.keyCodec.WriteTagAndValue(ref ctx, Key);
+ codec.valueCodec.WriteTagAndValue(ref ctx, Value);
}
public int CalculateSize()
diff --git a/csharp/src/Google.Protobuf/Collections/RepeatedField.cs b/csharp/src/Google.Protobuf/Collections/RepeatedField.cs
index b1bd9b13d1..69adcdfafc 100644
--- a/csharp/src/Google.Protobuf/Collections/RepeatedField.cs
+++ b/csharp/src/Google.Protobuf/Collections/RepeatedField.cs
@@ -189,7 +189,7 @@ namespace Google.Protobuf.Collections
/// 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 an output by one of the WriteTo methods,
/// using the same codec.
public int CalculateSize(FieldCodec codec)
{
@@ -247,6 +247,26 @@ namespace Google.Protobuf.Collections
/// The output stream to write to.
/// The codec to use when encoding each value.
public void WriteTo(CodedOutputStream output, FieldCodec codec)
+ {
+ WriteContext.Initialize(output, out WriteContext ctx);
+ try
+ {
+ WriteTo(ref ctx, codec);
+ }
+ finally
+ {
+ ctx.CopyStateTo(output);
+ }
+ }
+
+ ///
+ /// Writes the contents of this collection to the given write context,
+ /// encoding each value using the specified codec.
+ ///
+ /// The write context to write to.
+ /// The codec to use when encoding each value.
+ [SecuritySafeCritical]
+ public void WriteTo(ref WriteContext ctx, FieldCodec codec)
{
if (count == 0)
{
@@ -257,12 +277,12 @@ namespace Google.Protobuf.Collections
if (codec.PackedRepeatedField)
{
// Packed primitive type
- uint size = (uint)CalculatePackedDataSize(codec);
- output.WriteTag(tag);
- output.WriteRawVarint32(size);
+ int size = CalculatePackedDataSize(codec);
+ ctx.WriteTag(tag);
+ ctx.WriteLength(size);
for (int i = 0; i < count; i++)
{
- writer(output, array[i]);
+ writer(ref ctx, array[i]);
}
}
else
@@ -271,11 +291,11 @@ namespace Google.Protobuf.Collections
// Can't use codec.WriteTagAndValue, as that omits default values.
for (int i = 0; i < count; i++)
{
- output.WriteTag(tag);
- writer(output, array[i]);
+ ctx.WriteTag(tag);
+ writer(ref ctx, array[i]);
if (codec.EndTag != 0)
{
- output.WriteTag(codec.EndTag);
+ ctx.WriteTag(codec.EndTag);
}
}
}
diff --git a/csharp/src/Google.Protobuf/ExtensionSet.cs b/csharp/src/Google.Protobuf/ExtensionSet.cs
index dd0b9a5519..895b9ae6ea 100644
--- a/csharp/src/Google.Protobuf/ExtensionSet.cs
+++ b/csharp/src/Google.Protobuf/ExtensionSet.cs
@@ -34,6 +34,7 @@ using Google.Protobuf.Collections;
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Security;
namespace Google.Protobuf
{
@@ -343,10 +344,28 @@ namespace Google.Protobuf
/// Writes the extension values in this set to the output stream
///
public void WriteTo(CodedOutputStream stream)
+ {
+
+ WriteContext.Initialize(stream, out WriteContext ctx);
+ try
+ {
+ WriteTo(ref ctx);
+ }
+ finally
+ {
+ ctx.CopyStateTo(stream);
+ }
+ }
+
+ ///
+ /// Writes the extension values in this set to the write context
+ ///
+ [SecuritySafeCritical]
+ public void WriteTo(ref WriteContext ctx)
{
foreach (var value in ValuesByNumber.Values)
{
- value.WriteTo(stream);
+ value.WriteTo(ref ctx);
}
}
diff --git a/csharp/src/Google.Protobuf/ExtensionValue.cs b/csharp/src/Google.Protobuf/ExtensionValue.cs
index df934ed7a1..ada5d79c80 100644
--- a/csharp/src/Google.Protobuf/ExtensionValue.cs
+++ b/csharp/src/Google.Protobuf/ExtensionValue.cs
@@ -41,7 +41,7 @@ namespace Google.Protobuf
void MergeFrom(ref ParseContext ctx);
void MergeFrom(IExtensionValue value);
- void WriteTo(CodedOutputStream output);
+ void WriteTo(ref WriteContext ctx);
int CalculateSize();
bool IsInitialized();
}
@@ -106,13 +106,13 @@ namespace Google.Protobuf
}
}
- public void WriteTo(CodedOutputStream output)
+ public void WriteTo(ref WriteContext ctx)
{
- output.WriteTag(codec.Tag);
- codec.ValueWriter(output, field);
+ ctx.WriteTag(codec.Tag);
+ codec.ValueWriter(ref ctx, field);
if (codec.EndTag != 0)
{
- output.WriteTag(codec.EndTag);
+ ctx.WriteTag(codec.EndTag);
}
}
@@ -181,11 +181,6 @@ namespace Google.Protobuf
}
}
- public void MergeFrom(CodedInputStream input)
- {
- field.AddEntriesFrom(input, codec);
- }
-
public void MergeFrom(ref ParseContext ctx)
{
field.AddEntriesFrom(ref ctx, codec);
@@ -199,9 +194,9 @@ namespace Google.Protobuf
}
}
- public void WriteTo(CodedOutputStream output)
+ public void WriteTo(ref WriteContext ctx)
{
- field.WriteTo(output, codec);
+ field.WriteTo(ref ctx, codec);
}
public RepeatedField GetValue() => field;
diff --git a/csharp/src/Google.Protobuf/FieldCodec.cs b/csharp/src/Google.Protobuf/FieldCodec.cs
index ee87736d1f..158739d50a 100644
--- a/csharp/src/Google.Protobuf/FieldCodec.cs
+++ b/csharp/src/Google.Protobuf/FieldCodec.cs
@@ -219,7 +219,7 @@ namespace Google.Protobuf
/// A codec for the given tag.
public static FieldCodec ForString(uint tag, string defaultValue)
{
- return new FieldCodec((ref ParseContext ctx) => ctx.ReadString(), (output, value) => output.WriteString(value), CodedOutputStream.ComputeStringSize, tag, defaultValue);
+ return new FieldCodec((ref ParseContext ctx) => ctx.ReadString(), (ref WriteContext ctx, string value) => ctx.WriteString(value), CodedOutputStream.ComputeStringSize, tag, defaultValue);
}
///
@@ -230,7 +230,7 @@ namespace Google.Protobuf
/// A codec for the given tag.
public static FieldCodec ForBytes(uint tag, ByteString defaultValue)
{
- return new FieldCodec((ref ParseContext ctx) => ctx.ReadBytes(), (output, value) => output.WriteBytes(value), CodedOutputStream.ComputeBytesSize, tag, defaultValue);
+ return new FieldCodec((ref ParseContext ctx) => ctx.ReadBytes(), (ref WriteContext ctx, ByteString value) => ctx.WriteBytes(value), CodedOutputStream.ComputeBytesSize, tag, defaultValue);
}
///
@@ -241,7 +241,7 @@ namespace Google.Protobuf
/// A codec for the given tag.
public static FieldCodec ForBool(uint tag, bool defaultValue)
{
- return new FieldCodec((ref ParseContext ctx) => ctx.ReadBool(), (output, value) => output.WriteBool(value), CodedOutputStream.BoolSize, tag, defaultValue);
+ return new FieldCodec((ref ParseContext ctx) => ctx.ReadBool(), (ref WriteContext ctx, bool value) => ctx.WriteBool(value), CodedOutputStream.BoolSize, tag, defaultValue);
}
///
@@ -252,7 +252,7 @@ namespace Google.Protobuf
/// A codec for the given tag.
public static FieldCodec ForInt32(uint tag, int defaultValue)
{
- return new FieldCodec((ref ParseContext ctx) => ctx.ReadInt32(), (output, value) => output.WriteInt32(value), CodedOutputStream.ComputeInt32Size, tag, defaultValue);
+ return new FieldCodec((ref ParseContext ctx) => ctx.ReadInt32(), (ref WriteContext output, int value) => output.WriteInt32(value), CodedOutputStream.ComputeInt32Size, tag, defaultValue);
}
///
@@ -263,7 +263,7 @@ namespace Google.Protobuf
/// A codec for the given tag.
public static FieldCodec ForSInt32(uint tag, int defaultValue)
{
- return new FieldCodec((ref ParseContext ctx) => ctx.ReadSInt32(), (output, value) => output.WriteSInt32(value), CodedOutputStream.ComputeSInt32Size, tag, defaultValue);
+ return new FieldCodec((ref ParseContext ctx) => ctx.ReadSInt32(), (ref WriteContext output, int value) => output.WriteSInt32(value), CodedOutputStream.ComputeSInt32Size, tag, defaultValue);
}
///
@@ -274,7 +274,7 @@ namespace Google.Protobuf
/// A codec for the given tag.
public static FieldCodec ForFixed32(uint tag, uint defaultValue)
{
- return new FieldCodec((ref ParseContext ctx) => ctx.ReadFixed32(), (output, value) => output.WriteFixed32(value), 4, tag, defaultValue);
+ return new FieldCodec((ref ParseContext ctx) => ctx.ReadFixed32(), (ref WriteContext output, uint value) => output.WriteFixed32(value), 4, tag, defaultValue);
}
///
@@ -285,7 +285,7 @@ namespace Google.Protobuf
/// A codec for the given tag.
public static FieldCodec ForSFixed32(uint tag, int defaultValue)
{
- return new FieldCodec((ref ParseContext ctx) => ctx.ReadSFixed32(), (output, value) => output.WriteSFixed32(value), 4, tag, defaultValue);
+ return new FieldCodec((ref ParseContext ctx) => ctx.ReadSFixed32(), (ref WriteContext output, int value) => output.WriteSFixed32(value), 4, tag, defaultValue);
}
///
@@ -296,7 +296,7 @@ namespace Google.Protobuf
/// A codec for the given tag.
public static FieldCodec ForUInt32(uint tag, uint defaultValue)
{
- return new FieldCodec((ref ParseContext ctx) => ctx.ReadUInt32(), (output, value) => output.WriteUInt32(value), CodedOutputStream.ComputeUInt32Size, tag, defaultValue);
+ return new FieldCodec((ref ParseContext ctx) => ctx.ReadUInt32(), (ref WriteContext output, uint value) => output.WriteUInt32(value), CodedOutputStream.ComputeUInt32Size, tag, defaultValue);
}
///
@@ -307,7 +307,7 @@ namespace Google.Protobuf
/// A codec for the given tag.
public static FieldCodec ForInt64(uint tag, long defaultValue)
{
- return new FieldCodec((ref ParseContext ctx) => ctx.ReadInt64(), (output, value) => output.WriteInt64(value), CodedOutputStream.ComputeInt64Size, tag, defaultValue);
+ return new FieldCodec((ref ParseContext ctx) => ctx.ReadInt64(), (ref WriteContext output, long value) => output.WriteInt64(value), CodedOutputStream.ComputeInt64Size, tag, defaultValue);
}
///
@@ -318,7 +318,7 @@ namespace Google.Protobuf
/// A codec for the given tag.
public static FieldCodec ForSInt64(uint tag, long defaultValue)
{
- return new FieldCodec((ref ParseContext ctx) => ctx.ReadSInt64(), (output, value) => output.WriteSInt64(value), CodedOutputStream.ComputeSInt64Size, tag, defaultValue);
+ return new FieldCodec((ref ParseContext ctx) => ctx.ReadSInt64(), (ref WriteContext output, long value) => output.WriteSInt64(value), CodedOutputStream.ComputeSInt64Size, tag, defaultValue);
}
///
@@ -329,7 +329,7 @@ namespace Google.Protobuf
/// A codec for the given tag.
public static FieldCodec ForFixed64(uint tag, ulong defaultValue)
{
- return new FieldCodec((ref ParseContext ctx) => ctx.ReadFixed64(), (output, value) => output.WriteFixed64(value), 8, tag, defaultValue);
+ return new FieldCodec((ref ParseContext ctx) => ctx.ReadFixed64(), (ref WriteContext output, ulong value) => output.WriteFixed64(value), 8, tag, defaultValue);
}
///
@@ -340,7 +340,7 @@ namespace Google.Protobuf
/// A codec for the given tag.
public static FieldCodec ForSFixed64(uint tag, long defaultValue)
{
- return new FieldCodec((ref ParseContext ctx) => ctx.ReadSFixed64(), (output, value) => output.WriteSFixed64(value), 8, tag, defaultValue);
+ return new FieldCodec((ref ParseContext ctx) => ctx.ReadSFixed64(), (ref WriteContext output, long value) => output.WriteSFixed64(value), 8, tag, defaultValue);
}
///
@@ -351,7 +351,7 @@ namespace Google.Protobuf
/// A codec for the given tag.
public static FieldCodec ForUInt64(uint tag, ulong defaultValue)
{
- return new FieldCodec((ref ParseContext ctx) => ctx.ReadUInt64(), (output, value) => output.WriteUInt64(value), CodedOutputStream.ComputeUInt64Size, tag, defaultValue);
+ return new FieldCodec((ref ParseContext ctx) => ctx.ReadUInt64(), (ref WriteContext output, ulong value) => output.WriteUInt64(value), CodedOutputStream.ComputeUInt64Size, tag, defaultValue);
}
///
@@ -362,7 +362,7 @@ namespace Google.Protobuf
/// A codec for the given tag.
public static FieldCodec ForFloat(uint tag, float defaultValue)
{
- return new FieldCodec((ref ParseContext ctx) => ctx.ReadFloat(), (output, value) => output.WriteFloat(value), CodedOutputStream.FloatSize, tag, defaultValue);
+ return new FieldCodec((ref ParseContext ctx) => ctx.ReadFloat(), (ref WriteContext output, float value) => output.WriteFloat(value), CodedOutputStream.FloatSize, tag, defaultValue);
}
///
@@ -373,7 +373,7 @@ namespace Google.Protobuf
/// A codec for the given tag.
public static FieldCodec ForDouble(uint tag, double defaultValue)
{
- return new FieldCodec((ref ParseContext ctx) => ctx.ReadDouble(), (output, value) => output.WriteDouble(value), CodedOutputStream.DoubleSize, tag, defaultValue);
+ return new FieldCodec((ref ParseContext ctx) => ctx.ReadDouble(), (ref WriteContext output, double value) => output.WriteDouble(value), CodedOutputStream.DoubleSize, tag, defaultValue);
}
// Enums are tricky. We can probably use expression trees to build these delegates automatically,
@@ -391,7 +391,7 @@ namespace Google.Protobuf
{
return new FieldCodec((ref ParseContext ctx) => fromInt32(
ctx.ReadEnum()),
- (output, value) => output.WriteEnum(toInt32(value)),
+ (ref WriteContext output, T value) => output.WriteEnum(toInt32(value)),
value => CodedOutputStream.ComputeEnumSize(toInt32(value)), tag, defaultValue);
}
@@ -410,7 +410,7 @@ namespace Google.Protobuf
ctx.ReadMessage(message);
return message;
},
- (output, value) => output.WriteMessage(value),
+ (ref WriteContext output, T value) => output.WriteMessage(value),
(ref ParseContext ctx, ref T v) =>
{
if (v == null)
@@ -455,7 +455,7 @@ namespace Google.Protobuf
ctx.ReadGroup(message);
return message;
},
- (output, value) => output.WriteGroup(value),
+ (ref WriteContext output, T value) => output.WriteGroup(value),
(ref ParseContext ctx, ref T v) =>
{
if (v == null)
@@ -492,7 +492,7 @@ namespace Google.Protobuf
var nestedCodec = WrapperCodecs.GetCodec();
return new FieldCodec(
(ref ParseContext ctx) => WrapperCodecs.Read(ref ctx, nestedCodec),
- (output, value) => WrapperCodecs.Write(output, value, nestedCodec),
+ (ref WriteContext output, T value) => WrapperCodecs.Write(ref output, value, nestedCodec),
(ref ParseContext ctx, ref T v) => v = WrapperCodecs.Read(ref ctx, nestedCodec),
(ref T v, T v2) => { v = v2; return v == null; },
value => WrapperCodecs.CalculateSize(value, nestedCodec),
@@ -509,7 +509,7 @@ namespace Google.Protobuf
var nestedCodec = WrapperCodecs.GetCodec();
return new FieldCodec(
WrapperCodecs.GetReader(),
- (output, value) => WrapperCodecs.Write(output, value.Value, nestedCodec),
+ (ref WriteContext output, T? value) => WrapperCodecs.Write(ref output, value.Value, nestedCodec),
(ref ParseContext ctx, ref T? v) => v = WrapperCodecs.Read(ref ctx, nestedCodec),
(ref T? v, T? v2) => { if (v2.HasValue) { v = v2; } return v.HasValue; },
value => value == null ? 0 : WrapperCodecs.CalculateSize(value.Value, nestedCodec),
@@ -616,10 +616,10 @@ namespace Google.Protobuf
return value;
}
- internal static void Write(CodedOutputStream output, T value, FieldCodec codec)
+ internal static void Write(ref WriteContext ctx, T value, FieldCodec codec)
{
- output.WriteLength(codec.CalculateSizeWithTag(value));
- codec.WriteTagAndValue(output, value);
+ ctx.WriteLength(codec.CalculateSizeWithTag(value));
+ codec.WriteTagAndValue(ref ctx, value);
}
internal static int CalculateSize(T value, FieldCodec codec)
@@ -631,6 +631,7 @@ namespace Google.Protobuf
}
internal delegate TValue ValueReader(ref ParseContext ctx);
+ internal delegate void ValueWriter(ref WriteContext ctx, T value);
///
///
@@ -685,7 +686,7 @@ namespace Google.Protobuf
///
/// Returns a delegate to write a value (unconditionally) to a coded output stream.
///
- internal Action ValueWriter { get; }
+ internal ValueWriter ValueWriter { get; }
///
/// Returns the size calculator for just a value.
@@ -744,7 +745,7 @@ namespace Google.Protobuf
internal FieldCodec(
ValueReader reader,
- Action writer,
+ ValueWriter writer,
int fixedSize,
uint tag,
T defaultValue) : this(reader, writer, _ => fixedSize, tag, defaultValue)
@@ -754,7 +755,7 @@ namespace Google.Protobuf
internal FieldCodec(
ValueReader reader,
- Action writer,
+ ValueWriter writer,
Func sizeCalculator,
uint tag,
T defaultValue) : this(reader, writer, (ref ParseContext ctx, ref T v) => v = reader(ref ctx), (ref T v, T v2) => { v = v2; return true; }, sizeCalculator, tag, 0, defaultValue)
@@ -763,7 +764,7 @@ namespace Google.Protobuf
internal FieldCodec(
ValueReader reader,
- Action writer,
+ ValueWriter writer,
InputMerger inputMerger,
ValuesMerger valuesMerger,
Func sizeCalculator,
@@ -774,7 +775,7 @@ namespace Google.Protobuf
internal FieldCodec(
ValueReader reader,
- Action writer,
+ ValueWriter writer,
InputMerger inputMerger,
ValuesMerger valuesMerger,
Func sizeCalculator,
@@ -802,14 +803,41 @@ namespace Google.Protobuf
/// Write a tag and the given value, *if* the value is not the default.
///
public void WriteTagAndValue(CodedOutputStream output, T value)
+ {
+ WriteContext.Initialize(output, out WriteContext ctx);
+ try
+ {
+ WriteTagAndValue(ref ctx, value);
+ }
+ finally
+ {
+ ctx.CopyStateTo(output);
+ }
+
+
+ //if (!IsDefault(value))
+ //{
+ // output.WriteTag(Tag);
+ // ValueWriter(output, value);
+ // if (EndTag != 0)
+ // {
+ // output.WriteTag(EndTag);
+ // }
+ //}
+ }
+
+ ///
+ /// Write a tag and the given value, *if* the value is not the default.
+ ///
+ public void WriteTagAndValue(ref WriteContext ctx, T value)
{
if (!IsDefault(value))
{
- output.WriteTag(Tag);
- ValueWriter(output, value);
+ ctx.WriteTag(Tag);
+ ValueWriter(ref ctx, value);
if (EndTag != 0)
{
- output.WriteTag(EndTag);
+ ctx.WriteTag(EndTag);
}
}
}
diff --git a/csharp/src/Google.Protobuf/IBufferMessage.cs b/csharp/src/Google.Protobuf/IBufferMessage.cs
index f6d174b3b7..c99a7d79fc 100644
--- a/csharp/src/Google.Protobuf/IBufferMessage.cs
+++ b/csharp/src/Google.Protobuf/IBufferMessage.cs
@@ -35,7 +35,7 @@ namespace Google.Protobuf
#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY
///
/// Interface for a Protocol Buffers message, supporting
- /// parsing from .
+ /// parsing from and writing to .
///
public interface IBufferMessage : IMessage
{
@@ -44,6 +44,12 @@ namespace Google.Protobuf
/// Users should never invoke this method directly.
///
void InternalMergeFrom(ref ParseContext ctx);
+
+ ///
+ /// Internal implementation of writing this message to a given write context.
+ /// Users should never invoke this method directly.
+ ///
+ void InternalWriteTo(ref WriteContext ctx);
}
#endif
}
diff --git a/csharp/src/Google.Protobuf/JsonFormatter.cs b/csharp/src/Google.Protobuf/JsonFormatter.cs
index 699a81de51..4bffd58c1f 100644
--- a/csharp/src/Google.Protobuf/JsonFormatter.cs
+++ b/csharp/src/Google.Protobuf/JsonFormatter.cs
@@ -357,7 +357,7 @@ namespace Google.Protobuf
/// The value to write. May be null.
public void WriteValue(TextWriter writer, object value)
{
- if (value == null)
+ if (value == null || value is NullValue)
{
WriteNull(writer);
}
diff --git a/csharp/src/Google.Protobuf/JsonParser.cs b/csharp/src/Google.Protobuf/JsonParser.cs
index 3f88ea38f1..cb5f5a8f21 100644
--- a/csharp/src/Google.Protobuf/JsonParser.cs
+++ b/csharp/src/Google.Protobuf/JsonParser.cs
@@ -37,6 +37,7 @@ using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
+using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
@@ -63,6 +64,7 @@ namespace Google.Protobuf
private static readonly Regex DurationRegex = new Regex(@"^(?-)?(?[0-9]{1,12})(?\.[0-9]{1,9})?s$", FrameworkPortability.CompiledRegexWhereAvailable);
private static readonly int[] SubsecondScalingFactors = { 0, 100000000, 100000000, 10000000, 1000000, 100000, 10000, 1000, 100, 10, 1 };
private static readonly char[] FieldMaskPathSeparators = new[] { ',' };
+ private static readonly EnumDescriptor NullValueDescriptor = StructReflection.Descriptor.EnumTypes.Single(ed => ed.ClrType == typeof(NullValue));
private static readonly JsonParser defaultInstance = new JsonParser(Settings.Default);
@@ -221,10 +223,11 @@ namespace Google.Protobuf
if (token.Type == JsonToken.TokenType.Null)
{
// Clear the field if we see a null token, unless it's for a singular field of type
- // google.protobuf.Value.
+ // google.protobuf.Value or google.protobuf.NullValue.
// Note: different from Java API, which just ignores it.
// TODO: Bring it more in line? Discuss...
- if (field.IsMap || field.IsRepeated || !IsGoogleProtobufValueField(field))
+ if (field.IsMap || field.IsRepeated ||
+ !(IsGoogleProtobufValueField(field) || IsGoogleProtobufNullValueField(field)))
{
field.Accessor.Clear(message);
return;
@@ -314,6 +317,12 @@ namespace Google.Protobuf
field.MessageType.FullName == Value.Descriptor.FullName;
}
+ private static bool IsGoogleProtobufNullValueField(FieldDescriptor field)
+ {
+ return field.FieldType == FieldType.Enum &&
+ field.EnumType.FullName == NullValueDescriptor.FullName;
+ }
+
private object ParseSingleValue(FieldDescriptor field, JsonTokenizer tokenizer)
{
var token = tokenizer.Next();
@@ -325,6 +334,10 @@ namespace Google.Protobuf
{
return Value.ForNull();
}
+ if (IsGoogleProtobufNullValueField(field))
+ {
+ return NullValue.NullValue;
+ }
return null;
}
diff --git a/csharp/src/Google.Protobuf/MessageExtensions.cs b/csharp/src/Google.Protobuf/MessageExtensions.cs
index 51e40915c8..36a9df7286 100644
--- a/csharp/src/Google.Protobuf/MessageExtensions.cs
+++ b/csharp/src/Google.Protobuf/MessageExtensions.cs
@@ -33,6 +33,7 @@
using Google.Protobuf.Reflection;
using System.Buffers;
using System.Collections;
+using System;
using System.IO;
using System.Linq;
using System.Security;
@@ -129,7 +130,7 @@ namespace Google.Protobuf
ProtoPreconditions.CheckNotNull(message, "message");
ProtoPreconditions.CheckNotNull(output, "output");
CodedOutputStream codedOutput = new CodedOutputStream(output);
- codedOutput.WriteRawVarint32((uint)message.CalculateSize());
+ codedOutput.WriteLength(message.CalculateSize());
message.WriteTo(codedOutput);
codedOutput.Flush();
}
@@ -145,6 +146,39 @@ namespace Google.Protobuf
return ByteString.AttachBytes(message.ToByteArray());
}
+ ///
+ /// Writes the given message data to the given buffer writer in protobuf encoding.
+ ///
+ /// The message to write to the stream.
+ /// The stream to write to.
+ [SecuritySafeCritical]
+ public static void WriteTo(this IMessage message, IBufferWriter output)
+ {
+ ProtoPreconditions.CheckNotNull(message, nameof(message));
+ ProtoPreconditions.CheckNotNull(output, nameof(output));
+
+ WriteContext.Initialize(output, out WriteContext ctx);
+ WritingPrimitivesMessages.WriteRawMessage(ref ctx, message);
+ ctx.Flush();
+ }
+
+ ///
+ /// Writes the given message data to the given span in protobuf encoding.
+ /// The size of the destination span needs to fit the serialized size
+ /// of the message exactly, otherwise an exception is thrown.
+ ///
+ /// The message to write to the stream.
+ /// The span to write to. Size must match size of the message exactly.
+ [SecuritySafeCritical]
+ public static void WriteTo(this IMessage message, Span output)
+ {
+ ProtoPreconditions.CheckNotNull(message, nameof(message));
+
+ WriteContext.Initialize(ref output, out WriteContext ctx);
+ WritingPrimitivesMessages.WriteRawMessage(ref ctx, message);
+ ctx.CheckNoSpaceLeft();
+ }
+
///
/// Checks if all required fields in a message have values set. For proto3 messages, this returns true
///
diff --git a/csharp/src/Google.Protobuf/ParserInternalState.cs b/csharp/src/Google.Protobuf/ParserInternalState.cs
index 4f0500b0a8..50d489dfc4 100644
--- a/csharp/src/Google.Protobuf/ParserInternalState.cs
+++ b/csharp/src/Google.Protobuf/ParserInternalState.cs
@@ -47,7 +47,7 @@ namespace Google.Protobuf
// warning: this is a mutable struct, so it needs to be only passed as a ref!
internal struct ParserInternalState
{
- // NOTE: the Span representing the current buffer is kept separate so that this doesn't have to be a ref struct and so it can live
+ // NOTE: the Span representing the current buffer is kept separate so that this doesn't have to be a ref struct and so it can
// be included in CodedInputStream's internal state
///
diff --git a/csharp/src/Google.Protobuf/ParsingPrimitives.cs b/csharp/src/Google.Protobuf/ParsingPrimitives.cs
index 28a19493d4..ebb40840aa 100644
--- a/csharp/src/Google.Protobuf/ParsingPrimitives.cs
+++ b/csharp/src/Google.Protobuf/ParsingPrimitives.cs
@@ -629,7 +629,7 @@ namespace Google.Protobuf
{
fixed (byte* sourceBytes = &MemoryMarshal.GetReference(data))
{
- value = CodedOutputStream.Utf8Encoding.GetString(sourceBytes, length);
+ value = WritingPrimitives.Utf8Encoding.GetString(sourceBytes, length);
}
}
@@ -638,7 +638,7 @@ namespace Google.Protobuf
}
#endif
- var decoder = CodedOutputStream.Utf8Encoding.GetDecoder();
+ var decoder = WritingPrimitives.Utf8Encoding.GetDecoder();
// TODO: even if GOOGLE_PROTOBUF_SUPPORT_FAST_STRING is not supported,
// we could still create a string efficiently by using Utf8Encoding.GetString(byte[] bytes, int index, int count)
@@ -649,7 +649,7 @@ namespace Google.Protobuf
// creating a string from that array might be more efficient than creating a string from the copied bytes.
// Slow path: Build a byte array first then copy it.
- return CodedOutputStream.Utf8Encoding.GetString(ReadRawBytes(ref buffer, ref state, length), 0, length);
+ return WritingPrimitives.Utf8Encoding.GetString(ReadRawBytes(ref buffer, ref state, length), 0, length);
}
[SecuritySafeCritical]
diff --git a/csharp/src/Google.Protobuf/Reflection/Descriptor.cs b/csharp/src/Google.Protobuf/Reflection/Descriptor.cs
index 91e457ebb8..0a1f4a7440 100644
--- a/csharp/src/Google.Protobuf/Reflection/Descriptor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/Descriptor.cs
@@ -275,12 +275,26 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
file_.WriteTo(output, _repeated_file_codec);
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
@@ -638,6 +652,9 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasName) {
output.WriteRawTag(10);
output.WriteString(Name);
@@ -668,7 +685,44 @@ namespace Google.Protobuf.Reflection {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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 (options_ != null) {
+ output.WriteRawTag(66);
+ output.WriteMessage(Options);
+ }
+ if (sourceCodeInfo_ != null) {
+ 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() {
@@ -1101,6 +1155,9 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasName) {
output.WriteRawTag(10);
output.WriteString(Name);
@@ -1120,8 +1177,34 @@ namespace Google.Protobuf.Reflection {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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 (options_ != null) {
+ 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;
@@ -1435,6 +1518,9 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasStart) {
output.WriteRawTag(8);
output.WriteInt32(Start);
@@ -1450,8 +1536,30 @@ namespace Google.Protobuf.Reflection {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (HasStart) {
+ output.WriteRawTag(8);
+ output.WriteInt32(Start);
+ }
+ if (HasEnd) {
+ output.WriteRawTag(16);
+ output.WriteInt32(End);
+ }
+ if (options_ != null) {
+ output.WriteRawTag(26);
+ output.WriteMessage(Options);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
+ }
+ #endif
+
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
@@ -1688,6 +1796,9 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasStart) {
output.WriteRawTag(8);
output.WriteInt32(Start);
@@ -1699,8 +1810,26 @@ namespace Google.Protobuf.Reflection {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
@@ -1877,6 +2006,9 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
uninterpretedOption_.WriteTo(output, _repeated_uninterpretedOption_codec);
if (_extensions != null) {
_extensions.WriteTo(output);
@@ -1884,7 +2016,21 @@ namespace Google.Protobuf.Reflection {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -2383,6 +2529,9 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasName) {
output.WriteRawTag(10);
output.WriteString(Name);
@@ -2430,8 +2579,62 @@ namespace Google.Protobuf.Reflection {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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 (options_ != null) {
+ output.WriteRawTag(66);
+ output.WriteMessage(Options);
+ }
+ if (HasOneofIndex) {
+ output.WriteRawTag(72);
+ output.WriteInt32(OneofIndex);
+ }
+ if (HasJsonName) {
+ output.WriteRawTag(82);
+ output.WriteString(JsonName);
+ }
+ if (HasProto3Optional) {
+ output.WriteRawTag(136, 1);
+ output.WriteBool(Proto3Optional);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
+ }
+ #endif
+
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
@@ -2823,6 +3026,9 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasName) {
output.WriteRawTag(10);
output.WriteString(Name);
@@ -2834,8 +3040,26 @@ namespace Google.Protobuf.Reflection {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (HasName) {
+ output.WriteRawTag(10);
+ output.WriteString(Name);
+ }
+ if (options_ != null) {
+ output.WriteRawTag(18);
+ output.WriteMessage(Options);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
+ }
+ #endif
+
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
@@ -3082,6 +3306,9 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasName) {
output.WriteRawTag(10);
output.WriteString(Name);
@@ -3096,8 +3323,29 @@ namespace Google.Protobuf.Reflection {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (HasName) {
+ output.WriteRawTag(10);
+ output.WriteString(Name);
+ }
+ value_.WriteTo(ref output, _repeated_value_codec);
+ if (options_ != null) {
+ 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;
@@ -3355,6 +3603,9 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasStart) {
output.WriteRawTag(8);
output.WriteInt32(Start);
@@ -3366,7 +3617,25 @@ namespace Google.Protobuf.Reflection {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -3591,6 +3860,9 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasName) {
output.WriteRawTag(10);
output.WriteString(Name);
@@ -3606,7 +3878,29 @@ namespace Google.Protobuf.Reflection {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (HasName) {
+ output.WriteRawTag(10);
+ output.WriteString(Name);
+ }
+ if (HasNumber) {
+ output.WriteRawTag(16);
+ output.WriteInt32(Number);
+ }
+ if (options_ != null) {
+ output.WriteRawTag(26);
+ output.WriteMessage(Options);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -3833,6 +4127,9 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasName) {
output.WriteRawTag(10);
output.WriteString(Name);
@@ -3845,7 +4142,26 @@ namespace Google.Protobuf.Reflection {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (HasName) {
+ output.WriteRawTag(10);
+ output.WriteString(Name);
+ }
+ method_.WriteTo(ref output, _repeated_method_codec);
+ if (options_ != null) {
+ output.WriteRawTag(26);
+ output.WriteMessage(Options);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -4173,6 +4489,9 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasName) {
output.WriteRawTag(10);
output.WriteString(Name);
@@ -4200,8 +4519,42 @@ namespace Google.Protobuf.Reflection {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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 (options_ != null) {
+ 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(ref output);
+ }
+ }
+ #endif
+
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
@@ -5067,6 +5420,9 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasJavaPackage) {
output.WriteRawTag(10);
output.WriteString(JavaPackage);
@@ -5154,7 +5510,101 @@ namespace Google.Protobuf.Reflection {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -5793,21 +6243,53 @@ namespace Google.Protobuf.Reflection {
if (HasMapEntry) hash ^= MapEntry.GetHashCode();
hash ^= uninterpretedOption_.GetHashCode();
if (_extensions != null) {
- hash ^= _extensions.GetHashCode();
+ hash ^= _extensions.GetHashCode();
+ }
+ if (_unknownFields != null) {
+ 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 !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
+ 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) {
- hash ^= _unknownFields.GetHashCode();
+ _unknownFields.WriteTo(output);
}
- return hash;
- }
-
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
- public override string ToString() {
- return pb::JsonFormatter.ToDiagnosticString(this);
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
- public void WriteTo(pb::CodedOutputStream output) {
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
if (HasMessageSetWireFormat) {
output.WriteRawTag(8);
output.WriteBool(MessageSetWireFormat);
@@ -5824,14 +6306,15 @@ namespace Google.Protobuf.Reflection {
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() {
@@ -6300,6 +6783,9 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasCtype) {
output.WriteRawTag(8);
output.WriteEnum((int) Ctype);
@@ -6331,7 +6817,45 @@ namespace Google.Protobuf.Reflection {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -6631,6 +7155,9 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
uninterpretedOption_.WriteTo(output, _repeated_uninterpretedOption_codec);
if (_extensions != null) {
_extensions.WriteTo(output);
@@ -6638,7 +7165,21 @@ namespace Google.Protobuf.Reflection {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -6889,6 +7430,9 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasAllowAlias) {
output.WriteRawTag(16);
output.WriteBool(AllowAlias);
@@ -6904,7 +7448,29 @@ namespace Google.Protobuf.Reflection {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -7152,6 +7718,9 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasDeprecated) {
output.WriteRawTag(8);
output.WriteBool(Deprecated);
@@ -7163,7 +7732,25 @@ namespace Google.Protobuf.Reflection {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -7397,6 +7984,9 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasDeprecated) {
output.WriteRawTag(136, 2);
output.WriteBool(Deprecated);
@@ -7408,7 +7998,25 @@ namespace Google.Protobuf.Reflection {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -7669,6 +8277,9 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasDeprecated) {
output.WriteRawTag(136, 2);
output.WriteBool(Deprecated);
@@ -7684,7 +8295,29 @@ namespace Google.Protobuf.Reflection {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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(ref output);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -8082,6 +8715,9 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
name_.WriteTo(output, _repeated_name_codec);
if (HasIdentifierValue) {
output.WriteRawTag(26);
@@ -8110,7 +8746,42 @@ namespace Google.Protobuf.Reflection {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -8388,6 +9059,9 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (HasNamePart_) {
output.WriteRawTag(10);
output.WriteString(NamePart_);
@@ -8399,7 +9073,25 @@ namespace Google.Protobuf.Reflection {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -8614,11 +9306,25 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
location_.WriteTo(output, _repeated_location_codec);
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ location_.WriteTo(ref output, _repeated_location_codec);
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -8922,6 +9628,9 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
path_.WriteTo(output, _repeated_path_codec);
span_.WriteTo(output, _repeated_span_codec);
if (HasLeadingComments) {
@@ -8936,7 +9645,28 @@ namespace Google.Protobuf.Reflection {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -9145,11 +9875,25 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
annotation_.WriteTo(output, _repeated_annotation_codec);
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ annotation_.WriteTo(ref output, _repeated_annotation_codec);
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -9392,6 +10136,9 @@ namespace Google.Protobuf.Reflection {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
path_.WriteTo(output, _repeated_path_codec);
if (HasSourceFile) {
output.WriteRawTag(18);
@@ -9408,7 +10155,30 @@ namespace Google.Protobuf.Reflection {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
diff --git a/csharp/src/Google.Protobuf/UnknownField.cs b/csharp/src/Google.Protobuf/UnknownField.cs
index e3ce0e86ef..63d89604a2 100644
--- a/csharp/src/Google.Protobuf/UnknownField.cs
+++ b/csharp/src/Google.Protobuf/UnknownField.cs
@@ -101,8 +101,8 @@ namespace Google.Protobuf
///
///
/// The unknown field number.
- /// The CodedOutputStream to write to.
- internal void WriteTo(int fieldNumber, CodedOutputStream output)
+ /// The write context to write to.
+ internal void WriteTo(int fieldNumber, ref WriteContext output)
{
if (varintList != null)
{
@@ -141,7 +141,7 @@ namespace Google.Protobuf
foreach (UnknownFieldSet value in groupList)
{
output.WriteTag(fieldNumber, WireFormat.WireType.StartGroup);
- value.WriteTo(output);
+ value.WriteTo(ref output);
output.WriteTag(fieldNumber, WireFormat.WireType.EndGroup);
}
}
diff --git a/csharp/src/Google.Protobuf/UnknownFieldSet.cs b/csharp/src/Google.Protobuf/UnknownFieldSet.cs
index 9ebe704065..9888dd1c3d 100644
--- a/csharp/src/Google.Protobuf/UnknownFieldSet.cs
+++ b/csharp/src/Google.Protobuf/UnknownFieldSet.cs
@@ -71,10 +71,27 @@ namespace Google.Protobuf
/// Serializes the set and writes it to .
///
public void WriteTo(CodedOutputStream output)
+ {
+ WriteContext.Initialize(output, out WriteContext ctx);
+ try
+ {
+ WriteTo(ref ctx);
+ }
+ finally
+ {
+ ctx.CopyStateTo(output);
+ }
+ }
+
+ ///
+ /// Serializes the set and writes it to .
+ ///
+ [SecuritySafeCritical]
+ public void WriteTo(ref WriteContext ctx)
{
foreach (KeyValuePair entry in fields)
{
- entry.Value.WriteTo(entry.Key, output);
+ entry.Value.WriteTo(entry.Key, ref ctx);
}
}
diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Any.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Any.cs
index 18520470d8..60ae03da94 100644
--- a/csharp/src/Google.Protobuf/WellKnownTypes/Any.cs
+++ b/csharp/src/Google.Protobuf/WellKnownTypes/Any.cs
@@ -78,10 +78,13 @@ namespace Google.Protobuf.WellKnownTypes {
/// Example 4: Pack and unpack a message in Go
///
/// foo := &pb.Foo{...}
- /// any, err := ptypes.MarshalAny(foo)
+ /// any, err := anypb.New(foo)
+ /// if err != nil {
+ /// ...
+ /// }
/// ...
/// foo := &pb.Foo{}
- /// if err := ptypes.UnmarshalAny(any, foo); err != nil {
+ /// if err := any.UnmarshalTo(foo); err != nil {
/// ...
/// }
///
@@ -248,6 +251,9 @@ namespace Google.Protobuf.WellKnownTypes {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (TypeUrl.Length != 0) {
output.WriteRawTag(10);
output.WriteString(TypeUrl);
@@ -259,7 +265,25 @@ namespace Google.Protobuf.WellKnownTypes {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Api.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Api.cs
index 4e9cf11c3c..50d79bf8e9 100644
--- a/csharp/src/Google.Protobuf/WellKnownTypes/Api.cs
+++ b/csharp/src/Google.Protobuf/WellKnownTypes/Api.cs
@@ -269,6 +269,9 @@ namespace Google.Protobuf.WellKnownTypes {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Name.Length != 0) {
output.WriteRawTag(10);
output.WriteString(Name);
@@ -291,8 +294,37 @@ namespace Google.Protobuf.WellKnownTypes {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
@@ -627,6 +659,9 @@ namespace Google.Protobuf.WellKnownTypes {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Name.Length != 0) {
output.WriteRawTag(10);
output.WriteString(Name);
@@ -655,7 +690,42 @@ namespace Google.Protobuf.WellKnownTypes {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -984,6 +1054,9 @@ namespace Google.Protobuf.WellKnownTypes {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Name.Length != 0) {
output.WriteRawTag(10);
output.WriteString(Name);
@@ -995,8 +1068,26 @@ namespace Google.Protobuf.WellKnownTypes {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs
index e686655697..2a653a3754 100644
--- a/csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs
+++ b/csharp/src/Google.Protobuf/WellKnownTypes/Duration.cs
@@ -210,6 +210,9 @@ namespace Google.Protobuf.WellKnownTypes {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Seconds != 0L) {
output.WriteRawTag(8);
output.WriteInt64(Seconds);
@@ -221,7 +224,25 @@ namespace Google.Protobuf.WellKnownTypes {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs
index 5e2d5a10df..e2e35182fd 100644
--- a/csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs
+++ b/csharp/src/Google.Protobuf/WellKnownTypes/Empty.cs
@@ -119,10 +119,23 @@ namespace Google.Protobuf.WellKnownTypes {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs b/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs
index c92be3c73d..d5da31441e 100644
--- a/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs
+++ b/csharp/src/Google.Protobuf/WellKnownTypes/FieldMask.cs
@@ -324,11 +324,25 @@ namespace Google.Protobuf.WellKnownTypes {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
paths_.WriteTo(output, _repeated_paths_codec);
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ paths_.WriteTo(ref output, _repeated_paths_codec);
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs b/csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs
index 7d46be1d93..5fe9b89536 100644
--- a/csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs
+++ b/csharp/src/Google.Protobuf/WellKnownTypes/SourceContext.cs
@@ -131,6 +131,9 @@ namespace Google.Protobuf.WellKnownTypes {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (FileName.Length != 0) {
output.WriteRawTag(10);
output.WriteString(FileName);
@@ -138,7 +141,21 @@ namespace Google.Protobuf.WellKnownTypes {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs
index c7ca9270ab..0bbb1fcdf9 100644
--- a/csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs
+++ b/csharp/src/Google.Protobuf/WellKnownTypes/Struct.cs
@@ -162,11 +162,25 @@ namespace Google.Protobuf.WellKnownTypes {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
fields_.WriteTo(output, _map_fields_codec);
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ fields_.WriteTo(ref output, _map_fields_codec);
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
}
+ #endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
@@ -446,6 +460,9 @@ namespace Google.Protobuf.WellKnownTypes {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (kindCase_ == KindOneofCase.NullValue) {
output.WriteRawTag(8);
output.WriteEnum((int) NullValue);
@@ -473,7 +490,41 @@ namespace Google.Protobuf.WellKnownTypes {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -729,12 +780,26 @@ namespace Google.Protobuf.WellKnownTypes {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
values_.WriteTo(output, _repeated_values_codec);
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs
index 849162f048..c75ef0f9a1 100644
--- a/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs
+++ b/csharp/src/Google.Protobuf/WellKnownTypes/Timestamp.cs
@@ -231,6 +231,9 @@ namespace Google.Protobuf.WellKnownTypes {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Seconds != 0L) {
output.WriteRawTag(8);
output.WriteInt64(Seconds);
@@ -242,7 +245,25 @@ namespace Google.Protobuf.WellKnownTypes {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Type.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Type.cs
index 8e92707476..f5dfdb7e3e 100644
--- a/csharp/src/Google.Protobuf/WellKnownTypes/Type.cs
+++ b/csharp/src/Google.Protobuf/WellKnownTypes/Type.cs
@@ -262,6 +262,9 @@ namespace Google.Protobuf.WellKnownTypes {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Name.Length != 0) {
output.WriteRawTag(10);
output.WriteString(Name);
@@ -280,7 +283,32 @@ namespace Google.Protobuf.WellKnownTypes {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -655,6 +683,9 @@ namespace Google.Protobuf.WellKnownTypes {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Kind != global::Google.Protobuf.WellKnownTypes.Field.Types.Kind.TypeUnknown) {
output.WriteRawTag(8);
output.WriteEnum((int) Kind);
@@ -695,7 +726,54 @@ namespace Google.Protobuf.WellKnownTypes {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -1148,6 +1226,9 @@ namespace Google.Protobuf.WellKnownTypes {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Name.Length != 0) {
output.WriteRawTag(10);
output.WriteString(Name);
@@ -1165,7 +1246,31 @@ namespace Google.Protobuf.WellKnownTypes {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -1409,6 +1514,9 @@ namespace Google.Protobuf.WellKnownTypes {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Name.Length != 0) {
output.WriteRawTag(10);
output.WriteString(Name);
@@ -1421,8 +1529,27 @@ namespace Google.Protobuf.WellKnownTypes {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
@@ -1623,6 +1750,9 @@ namespace Google.Protobuf.WellKnownTypes {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Name.Length != 0) {
output.WriteRawTag(10);
output.WriteString(Name);
@@ -1634,8 +1764,26 @@ namespace Google.Protobuf.WellKnownTypes {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
+ if (Name.Length != 0) {
+ output.WriteRawTag(10);
+ output.WriteString(Name);
+ }
+ if (value_ != null) {
+ output.WriteRawTag(18);
+ output.WriteMessage(Value);
+ }
+ if (_unknownFields != null) {
+ _unknownFields.WriteTo(ref output);
+ }
+ }
+ #endif
+
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
diff --git a/csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs b/csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs
index 1ccbc2a9c8..01d31216e8 100644
--- a/csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs
+++ b/csharp/src/Google.Protobuf/WellKnownTypes/Wrappers.cs
@@ -144,6 +144,9 @@ namespace Google.Protobuf.WellKnownTypes {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Value != 0D) {
output.WriteRawTag(9);
output.WriteDouble(Value);
@@ -151,7 +154,21 @@ namespace Google.Protobuf.WellKnownTypes {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -307,6 +324,9 @@ namespace Google.Protobuf.WellKnownTypes {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Value != 0F) {
output.WriteRawTag(13);
output.WriteFloat(Value);
@@ -314,7 +334,21 @@ namespace Google.Protobuf.WellKnownTypes {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -470,6 +504,9 @@ namespace Google.Protobuf.WellKnownTypes {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Value != 0L) {
output.WriteRawTag(8);
output.WriteInt64(Value);
@@ -477,8 +514,22 @@ namespace Google.Protobuf.WellKnownTypes {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
@@ -633,6 +684,9 @@ namespace Google.Protobuf.WellKnownTypes {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Value != 0UL) {
output.WriteRawTag(8);
output.WriteUInt64(Value);
@@ -640,8 +694,22 @@ namespace Google.Protobuf.WellKnownTypes {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
@@ -796,6 +864,9 @@ namespace Google.Protobuf.WellKnownTypes {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Value != 0) {
output.WriteRawTag(8);
output.WriteInt32(Value);
@@ -803,7 +874,21 @@ namespace Google.Protobuf.WellKnownTypes {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -959,6 +1044,9 @@ namespace Google.Protobuf.WellKnownTypes {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Value != 0) {
output.WriteRawTag(8);
output.WriteUInt32(Value);
@@ -966,7 +1054,21 @@ namespace Google.Protobuf.WellKnownTypes {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
+ }
+
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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() {
@@ -1122,6 +1224,9 @@ namespace Google.Protobuf.WellKnownTypes {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Value != false) {
output.WriteRawTag(8);
output.WriteBool(Value);
@@ -1129,8 +1234,22 @@ namespace Google.Protobuf.WellKnownTypes {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
@@ -1285,6 +1404,9 @@ namespace Google.Protobuf.WellKnownTypes {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Value.Length != 0) {
output.WriteRawTag(10);
output.WriteString(Value);
@@ -1292,8 +1414,22 @@ namespace Google.Protobuf.WellKnownTypes {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
@@ -1448,6 +1584,9 @@ namespace Google.Protobuf.WellKnownTypes {
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void WriteTo(pb::CodedOutputStream output) {
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ output.WriteRawMessage(this);
+ #else
if (Value.Length != 0) {
output.WriteRawTag(10);
output.WriteBytes(Value);
@@ -1455,8 +1594,22 @@ namespace Google.Protobuf.WellKnownTypes {
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}
+ #endif
}
+ #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext 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;
diff --git a/csharp/src/Google.Protobuf/WriteBufferHelper.cs b/csharp/src/Google.Protobuf/WriteBufferHelper.cs
new file mode 100644
index 0000000000..f2a59bc56f
--- /dev/null
+++ b/csharp/src/Google.Protobuf/WriteBufferHelper.cs
@@ -0,0 +1,166 @@
+#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;
+using System.Buffers;
+using System.IO;
+using System.Runtime.CompilerServices;
+using System.Security;
+
+namespace Google.Protobuf
+{
+ ///
+ /// Abstraction for writing to a steam / IBufferWriter
+ ///
+ [SecuritySafeCritical]
+ internal struct WriteBufferHelper
+ {
+ private IBufferWriter bufferWriter;
+ private CodedOutputStream codedOutputStream;
+
+ public CodedOutputStream CodedOutputStream => codedOutputStream;
+
+ ///
+ /// Initialize an instance with a coded output stream.
+ /// This approach is faster than using a constructor because the instance to initialize is passed by reference
+ /// and we can write directly into it without copying.
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static void Initialize(CodedOutputStream codedOutputStream, out WriteBufferHelper instance)
+ {
+ instance.bufferWriter = null;
+ instance.codedOutputStream = codedOutputStream;
+ }
+
+ ///
+ /// Initialize an instance with a buffer writer.
+ /// This approach is faster than using a constructor because the instance to initialize is passed by reference
+ /// and we can write directly into it without copying.
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static void Initialize(IBufferWriter bufferWriter, out WriteBufferHelper instance, out Span buffer)
+ {
+ instance.bufferWriter = bufferWriter;
+ instance.codedOutputStream = null;
+ buffer = default; // TODO: initialize the initial buffer so that the first write is not via slowpath.
+ }
+
+ ///
+ /// Initialize an instance with a buffer represented by a single span (i.e. buffer cannot be refreshed)
+ /// This approach is faster than using a constructor because the instance to initialize is passed by reference
+ /// and we can write directly into it without copying.
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static void InitializeNonRefreshable(out WriteBufferHelper instance)
+ {
+ instance.bufferWriter = null;
+ instance.codedOutputStream = null;
+ }
+
+ ///
+ /// Verifies that SpaceLeft returns zero.
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static void CheckNoSpaceLeft(ref WriterInternalState state)
+ {
+ if (GetSpaceLeft(ref state) != 0)
+ {
+ throw new InvalidOperationException("Did not write as much data as expected.");
+ }
+ }
+
+ ///
+ /// If writing to a flat array, returns the space left in the array. Otherwise,
+ /// throws an InvalidOperationException.
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static int GetSpaceLeft(ref WriterInternalState state)
+ {
+ if (state.writeBufferHelper.codedOutputStream?.InternalOutputStream == null && state.writeBufferHelper.bufferWriter == null)
+ {
+ return state.limit - state.position;
+ }
+ else
+ {
+ throw new InvalidOperationException(
+ "SpaceLeft can only be called on CodedOutputStreams that are " +
+ "writing to a flat array or when writing to a single span.");
+ }
+ }
+
+ [MethodImpl(MethodImplOptions.NoInlining)]
+ public static void RefreshBuffer(ref Span buffer, ref WriterInternalState state)
+ {
+ if (state.writeBufferHelper.codedOutputStream?.InternalOutputStream != null)
+ {
+ // because we're using coded output stream, we know that "buffer" and codedOutputStream.InternalBuffer are identical.
+ state.writeBufferHelper.codedOutputStream.InternalOutputStream.Write(state.writeBufferHelper.codedOutputStream.InternalBuffer, 0, state.position);
+ // reset position, limit stays the same because we are reusing the codedOutputStream's internal buffer.
+ state.position = 0;
+ }
+ else if (state.writeBufferHelper.bufferWriter != null)
+ {
+ // commit the bytes and get a new buffer to write to.
+ state.writeBufferHelper.bufferWriter.Advance(state.position);
+ state.position = 0;
+ buffer = state.writeBufferHelper.bufferWriter.GetSpan();
+ state.limit = buffer.Length;
+ }
+ else
+ {
+ // We're writing to a single buffer.
+ throw new CodedOutputStream.OutOfSpaceException();
+ }
+ }
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static void Flush(ref Span buffer, ref WriterInternalState state)
+ {
+ if (state.writeBufferHelper.codedOutputStream?.InternalOutputStream != null)
+ {
+ // because we're using coded output stream, we know that "buffer" and codedOutputStream.InternalBuffer are identical.
+ state.writeBufferHelper.codedOutputStream.InternalOutputStream.Write(state.writeBufferHelper.codedOutputStream.InternalBuffer, 0, state.position);
+ state.position = 0;
+ }
+ else if (state.writeBufferHelper.bufferWriter != null)
+ {
+ // calling Advance invalidates the current buffer and we must not continue writing to it,
+ // so we set the current buffer to point to an empty Span. If any subsequent writes happen,
+ // the first subsequent write will trigger refresing of the buffer.
+ state.writeBufferHelper.bufferWriter.Advance(state.position);
+ state.position = 0;
+ state.limit = 0;
+ buffer = default; // invalidate the current buffer
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/csharp/src/Google.Protobuf/WriteContext.cs b/csharp/src/Google.Protobuf/WriteContext.cs
new file mode 100644
index 0000000000..e822e1d6da
--- /dev/null
+++ b/csharp/src/Google.Protobuf/WriteContext.cs
@@ -0,0 +1,371 @@
+#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;
+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
+{
+ ///
+ /// An opaque struct that represents the current serialization state and is passed along
+ /// as the serialization proceeds.
+ /// All the public methods are intended to be invoked only by the generated code,
+ /// users should never invoke them directly.
+ ///
+ [SecuritySafeCritical]
+ public ref struct WriteContext
+ {
+ internal Span buffer;
+ internal WriterInternalState state;
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ internal static void Initialize(ref Span buffer, ref WriterInternalState state, out WriteContext ctx)
+ {
+ ctx.buffer = buffer;
+ ctx.state = state;
+ }
+
+ ///
+ /// Creates a WriteContext instance from CodedOutputStream.
+ /// WARNING: internally this copies the CodedOutputStream's state, so after done with the WriteContext,
+ /// the CodedOutputStream's state needs to be updated.
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ internal static void Initialize(CodedOutputStream output, out WriteContext ctx)
+ {
+ ctx.buffer = new Span(output.InternalBuffer);
+ // ideally we would use a reference to the original state, but that doesn't seem possible
+ // so we just copy the struct that holds the state. We will need to later store the state back
+ // into CodedOutputStream if we want to keep it usable.
+ ctx.state = output.InternalState;
+ }
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ internal static void Initialize(IBufferWriter output, out WriteContext ctx)
+ {
+ ctx.buffer = default;
+ ctx.state = default;
+ WriteBufferHelper.Initialize(output, out ctx.state.writeBufferHelper, out ctx.buffer);
+ ctx.state.limit = ctx.buffer.Length;
+ ctx.state.position = 0;
+ }
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ internal static void Initialize(ref Span buffer, out WriteContext ctx)
+ {
+ ctx.buffer = buffer;
+ ctx.state = default;
+ ctx.state.limit = ctx.buffer.Length;
+ ctx.state.position = 0;
+ WriteBufferHelper.InitializeNonRefreshable(out ctx.state.writeBufferHelper);
+ }
+
+ ///
+ /// Writes a double field value, without a tag.
+ ///
+ /// The value to write
+ public void WriteDouble(double value)
+ {
+ WritingPrimitives.WriteDouble(ref buffer, ref state, value);
+ }
+
+ ///
+ /// Writes a float field value, without a tag.
+ ///
+ /// The value to write
+ public void WriteFloat(float value)
+ {
+ WritingPrimitives.WriteFloat(ref buffer, ref state, value);
+ }
+
+ ///
+ /// Writes a uint64 field value, without a tag.
+ ///
+ /// The value to write
+ public void WriteUInt64(ulong value)
+ {
+ WritingPrimitives.WriteUInt64(ref buffer, ref state, value);
+ }
+
+ ///
+ /// Writes an int64 field value, without a tag.
+ ///
+ /// The value to write
+ public void WriteInt64(long value)
+ {
+ WritingPrimitives.WriteInt64(ref buffer, ref state, value);
+ }
+
+ ///
+ /// Writes an int32 field value, without a tag.
+ ///
+ /// The value to write
+ public void WriteInt32(int value)
+ {
+ WritingPrimitives.WriteInt32(ref buffer, ref state, value);
+ }
+
+ ///
+ /// Writes a fixed64 field value, without a tag.
+ ///
+ /// The value to write
+ public void WriteFixed64(ulong value)
+ {
+ WritingPrimitives.WriteFixed64(ref buffer, ref state, value);
+ }
+
+ ///
+ /// Writes a fixed32 field value, without a tag.
+ ///
+ /// The value to write
+ public void WriteFixed32(uint value)
+ {
+ WritingPrimitives.WriteFixed32(ref buffer, ref state, value);
+ }
+
+ ///
+ /// Writes a bool field value, without a tag.
+ ///
+ /// The value to write
+ public void WriteBool(bool value)
+ {
+ WritingPrimitives.WriteBool(ref buffer, ref state, value);
+ }
+
+ ///
+ /// Writes a string field value, without a tag.
+ /// The data is length-prefixed.
+ ///
+ /// The value to write
+ public void WriteString(string value)
+ {
+ WritingPrimitives.WriteString(ref buffer, ref state, value);
+ }
+
+ ///
+ /// Writes a message, without a tag.
+ /// The data is length-prefixed.
+ ///
+ /// The value to write
+ public void WriteMessage(IMessage value)
+ {
+ WritingPrimitivesMessages.WriteMessage(ref this, value);
+ }
+
+ ///
+ /// Writes a group, without a tag, to the stream.
+ ///
+ /// The value to write
+ public void WriteGroup(IMessage value)
+ {
+ WritingPrimitivesMessages.WriteGroup(ref this, value);
+ }
+
+ ///
+ /// Write a byte string, without a tag, to the stream.
+ /// The data is length-prefixed.
+ ///
+ /// The value to write
+ public void WriteBytes(ByteString value)
+ {
+ WritingPrimitives.WriteBytes(ref buffer, ref state, value);
+ }
+
+ ///
+ /// Writes a uint32 value, without a tag.
+ ///
+ /// The value to write
+ public void WriteUInt32(uint value)
+ {
+ WritingPrimitives.WriteUInt32(ref buffer, ref state, value);
+ }
+
+ ///
+ /// Writes an enum value, without a tag.
+ ///
+ /// The value to write
+ public void WriteEnum(int value)
+ {
+ WritingPrimitives.WriteEnum(ref buffer, ref state, value);
+ }
+
+ ///
+ /// Writes an sfixed32 value, without a tag.
+ ///
+ /// The value to write.
+ public void WriteSFixed32(int value)
+ {
+ WritingPrimitives.WriteSFixed32(ref buffer, ref state, value);
+ }
+
+ ///
+ /// Writes an sfixed64 value, without a tag.
+ ///
+ /// The value to write
+ public void WriteSFixed64(long value)
+ {
+ WritingPrimitives.WriteSFixed64(ref buffer, ref state, value);
+ }
+
+ ///
+ /// Writes an sint32 value, without a tag.
+ ///
+ /// The value to write
+ public void WriteSInt32(int value)
+ {
+ WritingPrimitives.WriteSInt32(ref buffer, ref state, value);
+ }
+
+ ///
+ /// Writes an sint64 value, without a tag.
+ ///
+ /// The value to write
+ public void WriteSInt64(long value)
+ {
+ WritingPrimitives.WriteSInt64(ref buffer, ref state, 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)
+ {
+ WritingPrimitives.WriteLength(ref buffer, ref state, length);
+ }
+
+ ///
+ /// 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)
+ {
+ WritingPrimitives.WriteTag(ref buffer, ref state, fieldNumber, type);
+ }
+
+ ///
+ /// Writes an already-encoded tag.
+ ///
+ /// The encoded tag
+ public void WriteTag(uint tag)
+ {
+ WritingPrimitives.WriteTag(ref buffer, ref state, tag);
+ }
+
+ ///
+ /// Writes the given single-byte tag.
+ ///
+ /// The encoded tag
+ public void WriteRawTag(byte b1)
+ {
+ WritingPrimitives.WriteRawTag(ref buffer, ref state, b1);
+ }
+
+ ///
+ /// Writes the given two-byte tag.
+ ///
+ /// The first byte of the encoded tag
+ /// The second byte of the encoded tag
+ public void WriteRawTag(byte b1, byte b2)
+ {
+ WritingPrimitives.WriteRawTag(ref buffer, ref state, b1, b2);
+ }
+
+ ///
+ /// Writes the given three-byte tag.
+ ///
+ /// 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)
+ {
+ WritingPrimitives.WriteRawTag(ref buffer, ref state, b1, b2, b3);
+ }
+
+ ///
+ /// Writes the given four-byte tag.
+ ///
+ /// 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)
+ {
+ WritingPrimitives.WriteRawTag(ref buffer, ref state, b1, b2, b3, b4);
+ }
+
+ ///
+ /// Writes the given five-byte tag.
+ ///
+ /// 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)
+ {
+ WritingPrimitives.WriteRawTag(ref buffer, ref state, b1, b2, b3, b4, b5);
+ }
+
+ internal void Flush()
+ {
+ WriteBufferHelper.Flush(ref buffer, ref state);
+ }
+
+ internal void CheckNoSpaceLeft()
+ {
+ WriteBufferHelper.CheckNoSpaceLeft(ref state);
+ }
+
+ internal void CopyStateTo(CodedOutputStream output)
+ {
+ output.InternalState = state;
+ }
+
+ internal void LoadStateFrom(CodedOutputStream output)
+ {
+ state = output.InternalState;
+ }
+ }
+}
\ No newline at end of file
diff --git a/csharp/src/Google.Protobuf/WriterInternalState.cs b/csharp/src/Google.Protobuf/WriterInternalState.cs
new file mode 100644
index 0000000000..a779305bb7
--- /dev/null
+++ b/csharp/src/Google.Protobuf/WriterInternalState.cs
@@ -0,0 +1,62 @@
+#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;
+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
+{
+
+ // warning: this is a mutable struct, so it needs to be only passed as a ref!
+ internal struct WriterInternalState
+ {
+ // NOTE: the Span representing the current buffer is kept separate so that this doesn't have to be a ref struct and so it can
+ // be included in CodedOutputStream's internal state
+
+ internal int limit; // the size of the current buffer
+ internal int position; // position in the current buffer
+
+ internal WriteBufferHelper writeBufferHelper;
+
+ // If non-null, the top level parse method was started with given coded output stream as an argument
+ // which also means we can potentially fallback to calling WriteTo(CodedOutputStream cos) if needed.
+ internal CodedOutputStream CodedOutputStream => writeBufferHelper.CodedOutputStream;
+ }
+}
\ No newline at end of file
diff --git a/csharp/src/Google.Protobuf/WritingPrimitives.cs b/csharp/src/Google.Protobuf/WritingPrimitives.cs
new file mode 100644
index 0000000000..846df73502
--- /dev/null
+++ b/csharp/src/Google.Protobuf/WritingPrimitives.cs
@@ -0,0 +1,628 @@
+#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;
+using System.Buffers.Binary;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Security;
+using System.Text;
+
+namespace Google.Protobuf
+{
+ ///
+ /// Primitives for encoding protobuf wire format.
+ ///
+ [SecuritySafeCritical]
+ internal static class WritingPrimitives
+ {
+ // "Local" copy of Encoding.UTF8, for efficiency. (Yes, it makes a difference.)
+ internal static readonly Encoding Utf8Encoding = Encoding.UTF8;
+
+ #region Writing of values (not including tags)
+
+ ///
+ /// Writes a double field value, without a tag, to the stream.
+ ///
+ public static void WriteDouble(ref Span buffer, ref WriterInternalState state, double value)
+ {
+ WriteRawLittleEndian64(ref buffer, ref state, (ulong)BitConverter.DoubleToInt64Bits(value));
+ }
+
+ ///
+ /// Writes a float field value, without a tag, to the stream.
+ ///
+ public static unsafe void WriteFloat(ref Span buffer, ref WriterInternalState state, float value)
+ {
+ const int length = sizeof(float);
+ if (buffer.Length - state.position >= length)
+ {
+ // if there's enough space in the buffer, write the float directly into the buffer
+ var floatSpan = buffer.Slice(state.position, length);
+ Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(floatSpan), value);
+
+ if (!BitConverter.IsLittleEndian)
+ {
+ floatSpan.Reverse();
+ }
+ state.position += length;
+ }
+ else
+ {
+ WriteFloatSlowPath(ref buffer, ref state, value);
+ }
+ }
+
+ [MethodImpl(MethodImplOptions.NoInlining)]
+ private static unsafe void WriteFloatSlowPath(ref Span buffer, ref WriterInternalState state, float value)
+ {
+ const int length = sizeof(float);
+
+ // TODO(jtattermusch): deduplicate the code. Populating the span is the same as for the fastpath.
+ Span floatSpan = stackalloc byte[length];
+ Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(floatSpan), value);
+ if (!BitConverter.IsLittleEndian)
+ {
+ floatSpan.Reverse();
+ }
+
+ WriteRawByte(ref buffer, ref state, floatSpan[0]);
+ WriteRawByte(ref buffer, ref state, floatSpan[1]);
+ WriteRawByte(ref buffer, ref state, floatSpan[2]);
+ WriteRawByte(ref buffer, ref state, floatSpan[3]);
+ }
+
+ ///
+ /// Writes a uint64 field value, without a tag, to the stream.
+ ///
+ public static void WriteUInt64(ref Span buffer, ref WriterInternalState state, ulong value)
+ {
+ WriteRawVarint64(ref buffer, ref state, value);
+ }
+
+ ///
+ /// Writes an int64 field value, without a tag, to the stream.
+ ///
+ public static void WriteInt64(ref Span buffer, ref WriterInternalState state, long value)
+ {
+ WriteRawVarint64(ref buffer, ref state, (ulong)value);
+ }
+
+ ///
+ /// Writes an int32 field value, without a tag, to the stream.
+ ///
+ public static void WriteInt32(ref Span buffer, ref WriterInternalState state, int value)
+ {
+ if (value >= 0)
+ {
+ WriteRawVarint32(ref buffer, ref state, (uint)value);
+ }
+ else
+ {
+ // Must sign-extend.
+ WriteRawVarint64(ref buffer, ref state, (ulong)value);
+ }
+ }
+
+ ///
+ /// Writes a fixed64 field value, without a tag, to the stream.
+ ///
+ public static void WriteFixed64(ref Span buffer, ref WriterInternalState state, ulong value)
+ {
+ WriteRawLittleEndian64(ref buffer, ref state, value);
+ }
+
+ ///
+ /// Writes a fixed32 field value, without a tag, to the stream.
+ ///
+ public static void WriteFixed32(ref Span buffer, ref WriterInternalState state, uint value)
+ {
+ WriteRawLittleEndian32(ref buffer, ref state, value);
+ }
+
+ ///
+ /// Writes a bool field value, without a tag, to the stream.
+ ///
+ public static void WriteBool(ref Span buffer, ref WriterInternalState state, bool value)
+ {
+ WriteRawByte(ref buffer, ref state, value ? (byte)1 : (byte)0);
+ }
+
+ ///
+ /// Writes a string field value, without a tag, to the stream.
+ /// The data is length-prefixed.
+ ///
+ public static void WriteString(ref Span buffer, ref WriterInternalState state, string value)
+ {
+ // Optimise the case where we have enough space to write
+ // the string directly to the buffer, which should be common.
+ int length = Utf8Encoding.GetByteCount(value);
+ WriteLength(ref buffer, ref state, length);
+ if (buffer.Length - state.position >= length)
+ {
+ if (length == value.Length) // Must be all ASCII...
+ {
+ for (int i = 0; i < length; i++)
+ {
+ buffer[state.position + i] = (byte)value[i];
+ }
+ state.position += length;
+ }
+ else
+ {
+#if NETSTANDARD1_1
+ // slowpath when Encoding.GetBytes(Char*, Int32, Byte*, Int32) is not available
+ byte[] bytes = Utf8Encoding.GetBytes(value);
+ WriteRawBytes(ref buffer, ref state, bytes);
+#else
+ ReadOnlySpan source = value.AsSpan();
+ int bytesUsed;
+ unsafe
+ {
+ fixed (char* sourceChars = &MemoryMarshal.GetReference(source))
+ fixed (byte* destinationBytes = &MemoryMarshal.GetReference(buffer.Slice(state.position)))
+ {
+ bytesUsed = Utf8Encoding.GetBytes(sourceChars, source.Length, destinationBytes, buffer.Length);
+ }
+ }
+ state.position += bytesUsed;
+#endif
+ }
+ }
+ else
+ {
+ // Opportunity for future optimization:
+ // Large strings that don't fit into the current buffer segment
+ // can probably be optimized by using Utf8Encoding.GetEncoder()
+ // but more benchmarks would need to be added as evidence.
+ byte[] bytes = Utf8Encoding.GetBytes(value);
+ WriteRawBytes(ref buffer, ref state, bytes);
+ }
+ }
+
+ ///
+ /// Write a byte string, without a tag, to the stream.
+ /// The data is length-prefixed.
+ ///
+ public static void WriteBytes(ref Span buffer, ref WriterInternalState state, ByteString value)
+ {
+ WriteLength(ref buffer, ref state, value.Length);
+ WriteRawBytes(ref buffer, ref state, value.Span);
+ }
+
+ ///
+ /// Writes a uint32 value, without a tag, to the stream.
+ ///
+ public static void WriteUInt32(ref Span buffer, ref WriterInternalState state, uint value)
+ {
+ WriteRawVarint32(ref buffer, ref state, value);
+ }
+
+ ///
+ /// Writes an enum value, without a tag, to the stream.
+ ///
+ public static void WriteEnum(ref Span buffer, ref WriterInternalState state, int value)
+ {
+ WriteInt32(ref buffer, ref state, value);
+ }
+
+ ///
+ /// Writes an sfixed32 value, without a tag, to the stream.
+ ///
+ public static void WriteSFixed32(ref Span buffer, ref WriterInternalState state, int value)
+ {
+ WriteRawLittleEndian32(ref buffer, ref state, (uint)value);
+ }
+
+ ///
+ /// Writes an sfixed64 value, without a tag, to the stream.
+ ///
+ public static void WriteSFixed64(ref Span buffer, ref WriterInternalState state, long value)
+ {
+ WriteRawLittleEndian64(ref buffer, ref state, (ulong)value);
+ }
+
+ ///
+ /// Writes an sint32 value, without a tag, to the stream.
+ ///
+ public static void WriteSInt32(ref Span buffer, ref WriterInternalState state, int value)
+ {
+ WriteRawVarint32(ref buffer, ref state, EncodeZigZag32(value));
+ }
+
+ ///
+ /// Writes an sint64 value, without a tag, to the stream.
+ ///
+ public static void WriteSInt64(ref Span buffer, ref WriterInternalState state, long value)
+ {
+ WriteRawVarint64(ref buffer, ref state, EncodeZigZag64(value));
+ }
+
+ ///
+ /// Writes a length (in bytes) for length-delimited data.
+ ///
+ ///
+ /// This method simply writes a rawint, but exists for clarity in calling code.
+ ///
+ public static void WriteLength(ref Span buffer, ref WriterInternalState state, int length)
+ {
+ WriteRawVarint32(ref buffer, ref state, (uint)length);
+ }
+
+ #endregion
+
+ #region Writing primitives
+ ///
+ /// Writes a 32 bit value as a varint. The fast route is taken when
+ /// there's enough buffer space left to whizz through without checking
+ /// for each byte; otherwise, we resort to calling WriteRawByte each time.
+ ///
+ public static void WriteRawVarint32(ref Span buffer, ref WriterInternalState state, uint value)
+ {
+ // Optimize for the common case of a single byte value
+ if (value < 128 && state.position < buffer.Length)
+ {
+ buffer[state.position++] = (byte)value;
+ return;
+ }
+
+ // Fast path when capacity is available
+ while (state.position < buffer.Length)
+ {
+ if (value > 127)
+ {
+ buffer[state.position++] = (byte)((value & 0x7F) | 0x80);
+ value >>= 7;
+ }
+ else
+ {
+ buffer[state.position++] = (byte)value;
+ return;
+ }
+ }
+
+ while (value > 127)
+ {
+ WriteRawByte(ref buffer, ref state, (byte)((value & 0x7F) | 0x80));
+ value >>= 7;
+ }
+
+ WriteRawByte(ref buffer, ref state, (byte)value);
+ }
+
+ public static void WriteRawVarint64(ref Span buffer, ref WriterInternalState state, ulong value)
+ {
+ // Optimize for the common case of a single byte value
+ if (value < 128 && state.position < buffer.Length)
+ {
+ buffer[state.position++] = (byte)value;
+ return;
+ }
+
+ // Fast path when capacity is available
+ while (state.position < buffer.Length)
+ {
+ if (value > 127)
+ {
+ buffer[state.position++] = (byte)((value & 0x7F) | 0x80);
+ value >>= 7;
+ }
+ else
+ {
+ buffer[state.position++] = (byte)value;
+ return;
+ }
+ }
+
+ while (value > 127)
+ {
+ WriteRawByte(ref buffer, ref state, (byte)((value & 0x7F) | 0x80));
+ value >>= 7;
+ }
+
+ WriteRawByte(ref buffer, ref state, (byte)value);
+ }
+
+ public static void WriteRawLittleEndian32(ref Span buffer, ref WriterInternalState state, uint value)
+ {
+ const int length = sizeof(uint);
+ if (state.position + length > buffer.Length)
+ {
+ WriteRawLittleEndian32SlowPath(ref buffer, ref state, value);
+ }
+ else
+ {
+ BinaryPrimitives.WriteUInt32LittleEndian(buffer.Slice(state.position), value);
+ state.position += length;
+ }
+ }
+
+ [MethodImpl(MethodImplOptions.NoInlining)]
+ private static void WriteRawLittleEndian32SlowPath(ref Span buffer, ref WriterInternalState state, uint value)
+ {
+ WriteRawByte(ref buffer, ref state, (byte)value);
+ WriteRawByte(ref buffer, ref state, (byte)(value >> 8));
+ WriteRawByte(ref buffer, ref state, (byte)(value >> 16));
+ WriteRawByte(ref buffer, ref state, (byte)(value >> 24));
+ }
+
+ public static void WriteRawLittleEndian64(ref Span buffer, ref WriterInternalState state, ulong value)
+ {
+ const int length = sizeof(ulong);
+ if (state.position + length > buffer.Length)
+ {
+ WriteRawLittleEndian64SlowPath(ref buffer, ref state, value);
+ }
+ else
+ {
+ BinaryPrimitives.WriteUInt64LittleEndian(buffer.Slice(state.position), value);
+ state.position += length;
+ }
+ }
+
+ [MethodImpl(MethodImplOptions.NoInlining)]
+ public static void WriteRawLittleEndian64SlowPath(ref Span buffer, ref WriterInternalState state, ulong value)
+ {
+ WriteRawByte(ref buffer, ref state, (byte)value);
+ WriteRawByte(ref buffer, ref state, (byte)(value >> 8));
+ WriteRawByte(ref buffer, ref state, (byte)(value >> 16));
+ WriteRawByte(ref buffer, ref state, (byte)(value >> 24));
+ WriteRawByte(ref buffer, ref state, (byte)(value >> 32));
+ WriteRawByte(ref buffer, ref state, (byte)(value >> 40));
+ WriteRawByte(ref buffer, ref state, (byte)(value >> 48));
+ WriteRawByte(ref buffer, ref state, (byte)(value >> 56));
+ }
+
+ private static void WriteRawByte(ref Span buffer, ref WriterInternalState state, byte value)
+ {
+ if (state.position == buffer.Length)
+ {
+ WriteBufferHelper.RefreshBuffer(ref buffer, ref state);
+ }
+
+ buffer[state.position++] = value;
+ }
+
+ ///
+ /// Writes out an array of bytes.
+ ///
+ public static void WriteRawBytes(ref Span buffer, ref WriterInternalState state, byte[] value)
+ {
+ WriteRawBytes(ref buffer, ref state, new ReadOnlySpan(value));
+ }
+
+ ///
+ /// Writes out part of an array of bytes.
+ ///
+ public static void WriteRawBytes(ref Span buffer, ref WriterInternalState state, byte[] value, int offset, int length)
+ {
+ WriteRawBytes(ref buffer, ref state, new ReadOnlySpan(value, offset, length));
+ }
+
+ ///
+ /// Writes out part of an array of bytes.
+ ///
+ public static void WriteRawBytes(ref Span buffer, ref WriterInternalState state, ReadOnlySpan value)
+ {
+ if (buffer.Length - state.position >= value.Length)
+ {
+ // We have room in the current buffer.
+ value.CopyTo(buffer.Slice(state.position, value.Length));
+ state.position += value.Length;
+ }
+ else
+ {
+ // When writing to a CodedOutputStream backed by a Stream, we could avoid
+ // copying the data twice (first copying to the current buffer and
+ // and later writing from the current buffer to the underlying Stream)
+ // in some circumstances by writing the data directly to the underlying Stream.
+ // Current this is not being done to avoid specialcasing the code for
+ // CodedOutputStream vs IBufferWriter.
+ int bytesWritten = 0;
+ while (buffer.Length - state.position < value.Length - bytesWritten)
+ {
+ int length = buffer.Length - state.position;
+ value.Slice(bytesWritten, length).CopyTo(buffer.Slice(state.position, length));
+ bytesWritten += length;
+ state.position += length;
+ WriteBufferHelper.RefreshBuffer(ref buffer, ref state);
+ }
+
+ // copy the remaining data
+ int remainderLength = value.Length - bytesWritten;
+ value.Slice(bytesWritten, remainderLength).CopyTo(buffer.Slice(state.position, remainderLength));
+ state.position += remainderLength;
+ }
+ }
+ #endregion
+
+ #region Raw tag writing
+ ///
+ /// Encodes and writes a tag.
+ ///
+ public static void WriteTag(ref Span buffer, ref WriterInternalState state, int fieldNumber, WireFormat.WireType type)
+ {
+ WriteRawVarint32(ref buffer, ref state, WireFormat.MakeTag(fieldNumber, type));
+ }
+
+ ///
+ /// Writes an already-encoded tag.
+ ///
+ public static void WriteTag(ref Span buffer, ref WriterInternalState state, uint tag)
+ {
+ WriteRawVarint32(ref buffer, ref state, tag);
+ }
+
+ ///
+ /// Writes the given single-byte tag directly to the stream.
+ ///
+ public static void WriteRawTag(ref Span buffer, ref WriterInternalState state, byte b1)
+ {
+ WriteRawByte(ref buffer, ref state, b1);
+ }
+
+ ///
+ /// Writes the given two-byte tag directly to the stream.
+ ///
+ public static void WriteRawTag(ref Span buffer, ref WriterInternalState state, byte b1, byte b2)
+ {
+ if (state.position + 2 > buffer.Length)
+ {
+ WriteRawTagSlowPath(ref buffer, ref state, b1, b2);
+ }
+ else
+ {
+ buffer[state.position++] = b1;
+ buffer[state.position++] = b2;
+ }
+ }
+
+ [MethodImpl(MethodImplOptions.NoInlining)]
+ private static void WriteRawTagSlowPath(ref Span buffer, ref WriterInternalState state, byte b1, byte b2)
+ {
+ WriteRawByte(ref buffer, ref state, b1);
+ WriteRawByte(ref buffer, ref state, b2);
+ }
+
+ ///
+ /// Writes the given three-byte tag directly to the stream.
+ ///
+ public static void WriteRawTag(ref Span buffer, ref WriterInternalState state, byte b1, byte b2, byte b3)
+ {
+ if (state.position + 3 > buffer.Length)
+ {
+ WriteRawTagSlowPath(ref buffer, ref state, b1, b2, b3);
+ }
+ else
+ {
+ buffer[state.position++] = b1;
+ buffer[state.position++] = b2;
+ buffer[state.position++] = b3;
+ }
+ }
+
+ [MethodImpl(MethodImplOptions.NoInlining)]
+ private static void WriteRawTagSlowPath(ref Span buffer, ref WriterInternalState state, byte b1, byte b2, byte b3)
+ {
+ WriteRawByte(ref buffer, ref state, b1);
+ WriteRawByte(ref buffer, ref state, b2);
+ WriteRawByte(ref buffer, ref state, b3);
+ }
+
+ ///
+ /// Writes the given four-byte tag directly to the stream.
+ ///
+ public static void WriteRawTag(ref Span buffer, ref WriterInternalState state, byte b1, byte b2, byte b3, byte b4)
+ {
+ if (state.position + 4 > buffer.Length)
+ {
+ WriteRawTagSlowPath(ref buffer, ref state, b1, b2, b3, b4);
+ }
+ else
+ {
+ buffer[state.position++] = b1;
+ buffer[state.position++] = b2;
+ buffer[state.position++] = b3;
+ buffer[state.position++] = b4;
+ }
+ }
+
+ [MethodImpl(MethodImplOptions.NoInlining)]
+
+ private static void WriteRawTagSlowPath(ref Span buffer, ref WriterInternalState state, byte b1, byte b2, byte b3, byte b4)
+ {
+ WriteRawByte(ref buffer, ref state, b1);
+ WriteRawByte(ref buffer, ref state, b2);
+ WriteRawByte(ref buffer, ref state, b3);
+ WriteRawByte(ref buffer, ref state, b4);
+ }
+
+ ///
+ /// Writes the given five-byte tag directly to the stream.
+ ///
+ public static void WriteRawTag(ref Span buffer, ref WriterInternalState state, byte b1, byte b2, byte b3, byte b4, byte b5)
+ {
+ if (state.position + 5 > buffer.Length)
+ {
+ WriteRawTagSlowPath(ref buffer, ref state, b1, b2, b3, b4, b5);
+ }
+ else
+ {
+ buffer[state.position++] = b1;
+ buffer[state.position++] = b2;
+ buffer[state.position++] = b3;
+ buffer[state.position++] = b4;
+ buffer[state.position++] = b5;
+ }
+ }
+
+ [MethodImpl(MethodImplOptions.NoInlining)]
+ private static void WriteRawTagSlowPath(ref Span buffer, ref WriterInternalState state, byte b1, byte b2, byte b3, byte b4, byte b5)
+ {
+ WriteRawByte(ref buffer, ref state, b1);
+ WriteRawByte(ref buffer, ref state, b2);
+ WriteRawByte(ref buffer, ref state, b3);
+ WriteRawByte(ref buffer, ref state, b4);
+ WriteRawByte(ref buffer, ref state, b5);
+ }
+ #endregion
+
+ ///
+ /// Encode a 32-bit value with ZigZag encoding.
+ ///
+ ///
+ /// ZigZag encodes signed integers into values that can be efficiently
+ /// encoded with varint. (Otherwise, negative values must be
+ /// sign-extended to 64 bits to be varint encoded, thus always taking
+ /// 10 bytes on the wire.)
+ ///
+ public static uint EncodeZigZag32(int n)
+ {
+ // Note: the right-shift must be arithmetic
+ return (uint)((n << 1) ^ (n >> 31));
+ }
+
+ ///
+ /// Encode a 64-bit value with ZigZag encoding.
+ ///
+ ///
+ /// ZigZag encodes signed integers into values that can be efficiently
+ /// encoded with varint. (Otherwise, negative values must be
+ /// sign-extended to 64 bits to be varint encoded, thus always taking
+ /// 10 bytes on the wire.)
+ ///
+ public static ulong EncodeZigZag64(long n)
+ {
+ return (ulong)((n << 1) ^ (n >> 63));
+ }
+ }
+}
\ No newline at end of file
diff --git a/csharp/src/Google.Protobuf/WritingPrimitivesMessages.cs b/csharp/src/Google.Protobuf/WritingPrimitivesMessages.cs
new file mode 100644
index 0000000000..cd2d437915
--- /dev/null
+++ b/csharp/src/Google.Protobuf/WritingPrimitivesMessages.cs
@@ -0,0 +1,112 @@
+#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;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices.ComTypes;
+using System.Security;
+
+namespace Google.Protobuf
+{
+ ///
+ /// Writing messages / groups.
+ ///
+ [SecuritySafeCritical]
+ internal static class WritingPrimitivesMessages
+ {
+ ///
+ /// Writes a message, without a tag.
+ /// The data is length-prefixed.
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static void WriteMessage(ref WriteContext ctx, IMessage value)
+ {
+ WritingPrimitives.WriteLength(ref ctx.buffer, ref ctx.state, value.CalculateSize());
+ WriteRawMessage(ref ctx, value);
+ }
+
+ ///
+ /// Writes a group, without a tag.
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static void WriteGroup(ref WriteContext ctx, IMessage value)
+ {
+ WriteRawMessage(ref ctx, value);
+ }
+
+ ///
+ /// Writes a message, without a tag.
+ /// Message will be written without a length prefix.
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static void WriteRawMessage(ref WriteContext ctx, IMessage message)
+ {
+ if (message is IBufferMessage bufferMessage)
+ {
+ bufferMessage.InternalWriteTo(ref ctx);
+ }
+ else
+ {
+ // If we reached here, it means we've ran into a nested message with older generated code
+ // which doesn't provide the InternalWriteTo method that takes a WriteContext.
+ // With a slight performance overhead, we can still serialize this message just fine,
+ // but we need to find the original CodedOutputStream instance that initiated this
+ // serialization process and make sure its internal state is up to date.
+ // Note that this performance overhead is not very high (basically copying contents of a struct)
+ // and it will only be incurred in case the application mixes older and newer generated code.
+ // Regenerating the code from .proto files will remove this overhead because it will
+ // generate the InternalWriteTo method we need.
+
+ if (ctx.state.CodedOutputStream == null)
+ {
+ // This can only happen when the serialization started without providing a CodedOutputStream instance
+ // (e.g. WriteContext was created directly from a IBufferWriter).
+ // That also means that one of the new parsing APIs was used at the top level
+ // and in such case it is reasonable to require that all the nested message provide
+ // up-to-date generated code with WriteContext support (and fail otherwise).
+ throw new InvalidProtocolBufferException($"Message {message.GetType().Name} doesn't provide the generated method that enables WriteContext-based serialization. You might need to regenerate the generated protobuf code.");
+ }
+
+ ctx.CopyStateTo(ctx.state.CodedOutputStream);
+ try
+ {
+ // fallback parse using the CodedOutputStream that started current serialization tree
+ message.WriteTo(ctx.state.CodedOutputStream);
+ }
+ finally
+ {
+ ctx.LoadStateFrom(ctx.state.CodedOutputStream);
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/docs/third_party.md b/docs/third_party.md
index 257f9d5952..c1726a0f17 100644
--- a/docs/third_party.md
+++ b/docs/third_party.md
@@ -36,6 +36,7 @@ These are projects we know about implementing Protocol Buffers for other program
* Delphi: http://fundementals.sourceforge.net/dl.html
* Elixir: https://github.com/jeremyong/exprotoc
* Elixir: https://github.com/tony612/protobuf-elixir
+* Elixir: https://github.com/ahamez/protox
* Elm: https://github.com/tiziano88/elm-protobuf
* Erlang: https://github.com/tomas-abrahamsson/gpb
* Erlang: http://piqi.org/
diff --git a/editors/protobuf-mode.el b/editors/protobuf-mode.el
index f73d4b2b45..8102771665 100644
--- a/editors/protobuf-mode.el
+++ b/editors/protobuf-mode.el
@@ -216,7 +216,11 @@ Key bindings:
(c-common-init 'protobuf-mode)
(easy-menu-add protobuf-menu)
(c-run-mode-hooks 'c-mode-common-hook 'protobuf-mode-hook)
- (c-update-modeline))
+ (c-update-modeline)
+ (setq imenu-generic-expression
+ '(("Message" "^[[:space:]]*message[[:space:]]+\\([[:alnum:]]+\\)" 1)
+ ("Enum" "^[[:space:]]*enum[[:space:]]+\\([[:alnum:]]+\\)" 1)
+ ("Service" "^[[:space:]]*service[[:space:]]+\\([[:alnum:]]+\\)" 1))))
(provide 'protobuf-mode)
diff --git a/kokoro/linux/dockerfile/test/csharp/Dockerfile b/kokoro/linux/dockerfile/test/csharp/Dockerfile
index 3d54436bac..95bd653152 100644
--- a/kokoro/linux/dockerfile/test/csharp/Dockerfile
+++ b/kokoro/linux/dockerfile/test/csharp/Dockerfile
@@ -29,7 +29,7 @@ RUN apt-get update && apt-get install -y libunwind8 libicu57 && apt-get clean
RUN wget -q https://dot.net/v1/dotnet-install.sh && \
chmod u+x dotnet-install.sh && \
./dotnet-install.sh --version 2.1.802 && \
- ./dotnet-install.sh --version 3.0.100 && \
+ ./dotnet-install.sh --version 3.1.301 && \
ln -s /root/.dotnet/dotnet /usr/local/bin
RUN wget -q www.nuget.org/NuGet.exe -O /usr/local/bin/nuget.exe
diff --git a/objectivec/GPBAny.pbobjc.h b/objectivec/GPBAny.pbobjc.h
index 288d552356..21b7dcf4af 100644
--- a/objectivec/GPBAny.pbobjc.h
+++ b/objectivec/GPBAny.pbobjc.h
@@ -94,10 +94,13 @@ typedef GPB_ENUM(GPBAny_FieldNumber) {
* Example 4: Pack and unpack a message in Go
*
* foo := &pb.Foo{...}
- * any, err := ptypes.MarshalAny(foo)
+ * any, err := anypb.New(foo)
+ * if err != nil {
+ * ...
+ * }
* ...
* foo := &pb.Foo{}
- * if err := ptypes.UnmarshalAny(any, foo); err != nil {
+ * if err := any.UnmarshalTo(foo); err != nil {
* ...
* }
*
diff --git a/php/ext/google/protobuf2/arena.c b/php/ext/google/protobuf2/arena.c
new file mode 100644
index 0000000000..035dfcad76
--- /dev/null
+++ b/php/ext/google/protobuf2/arena.c
@@ -0,0 +1,95 @@
+// 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.
+
+#include
+
+#include "php-upb.h"
+
+// -----------------------------------------------------------------------------
+// Arena
+// -----------------------------------------------------------------------------
+
+typedef struct Arena {
+ zend_object std;
+ upb_arena* arena;
+} Arena;
+
+zend_class_entry *Arena_class_entry;
+static zend_object_handlers Arena_object_handlers;
+
+// PHP Object Handlers /////////////////////////////////////////////////////////
+
+static zend_object* Arena_Create(zend_class_entry *class_type) {
+ Arena *intern = emalloc(sizeof(Arena));
+ zend_object_std_init(&intern->std, class_type);
+ intern->std.handlers = &Arena_object_handlers;
+ intern->arena = upb_arena_new();
+ // Skip object_properties_init(), we don't allow derived classes.
+ return &intern->std;
+}
+
+static void Arena_Free(zend_object* obj) {
+ Arena* intern = (Arena*)obj;
+ upb_arena_free(intern->arena);
+ zend_object_std_dtor(&intern->std);
+}
+
+// C Functions from arena.h ////////////////////////////////////////////////////
+
+void Arena_Init(zval* val) {
+ ZVAL_OBJ(val, Arena_Create(Arena_class_entry));
+}
+
+upb_arena *Arena_Get(zval *val) {
+ Arena *a = (Arena*)Z_OBJ_P(val);
+ return a->arena;
+}
+
+// -----------------------------------------------------------------------------
+// Module init.
+// -----------------------------------------------------------------------------
+
+// No public methods.
+static const zend_function_entry Arena_methods[] = {
+ ZEND_FE_END
+};
+
+void Arena_ModuleInit() {
+ zend_class_entry tmp_ce;
+
+ INIT_CLASS_ENTRY(tmp_ce, "Google\\Protobuf\\Internal\\Arena", Arena_methods);
+ Arena_class_entry = zend_register_internal_class(&tmp_ce);
+ Arena_class_entry->create_object = Arena_Create;
+ Arena_class_entry->ce_flags |= ZEND_ACC_FINAL;
+
+ memcpy(&Arena_object_handlers, &std_object_handlers,
+ sizeof(zend_object_handlers));
+ Arena_object_handlers.free_obj = Arena_Free;
+}
diff --git a/php/ext/google/protobuf2/arena.h b/php/ext/google/protobuf2/arena.h
new file mode 100644
index 0000000000..67e165d37d
--- /dev/null
+++ b/php/ext/google/protobuf2/arena.h
@@ -0,0 +1,47 @@
+// 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.
+
+#ifndef PHP_PROTOBUF_ARENA_H_
+#define PHP_PROTOBUF_ARENA_H_
+
+#include
+
+#include "php-upb.h"
+
+// Registers the PHP Arena class.
+void Arena_ModuleInit();
+
+// Creates and returns a new arena object that wraps a new upb_arena*.
+void Arena_Init(zval *val);
+
+// Gets the underlying upb_arena from this arena object.
+upb_arena *Arena_Get(zval *arena);
+
+#endif // PHP_PROTOBUF_ARENA_H_
diff --git a/php/ext/google/protobuf2/array.c b/php/ext/google/protobuf2/array.c
new file mode 100644
index 0000000000..571d3e41cd
--- /dev/null
+++ b/php/ext/google/protobuf2/array.c
@@ -0,0 +1,602 @@
+// 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.
+
+#include "array.h"
+
+#include
+#include
+
+#include
+
+// This is not self-contained: it must be after other Zend includes.
+#include
+
+#include "arena.h"
+#include "convert.h"
+#include "def.h"
+#include "php-upb.h"
+#include "protobuf.h"
+
+static void RepeatedFieldIter_make(zval *val, zval *repeated_field);
+
+// -----------------------------------------------------------------------------
+// RepeatedField
+// -----------------------------------------------------------------------------
+
+typedef struct {
+ zend_object std;
+ zval arena;
+ upb_array *array;
+ upb_fieldtype_t type;
+ const Descriptor* desc; // When values are messages.
+} RepeatedField;
+
+zend_class_entry *RepeatedField_class_entry;
+static zend_object_handlers RepeatedField_object_handlers;
+
+// PHP Object Handlers /////////////////////////////////////////////////////////
+
+/**
+ * RepeatedField_create()
+ *
+ * PHP class entry function to allocate and initialize a new RepeatedField
+ * object.
+ */
+static zend_object* RepeatedField_create(zend_class_entry *class_type) {
+ RepeatedField *intern = emalloc(sizeof(RepeatedField));
+ zend_object_std_init(&intern->std, class_type);
+ intern->std.handlers = &RepeatedField_object_handlers;
+ Arena_Init(&intern->arena);
+ intern->array = NULL;
+ intern->desc = NULL;
+ // Skip object_properties_init(), we don't allow derived classes.
+ return &intern->std;
+}
+
+/**
+ * RepeatedField_dtor()
+ *
+ * Object handler to destroy a RepeatedField. This releases all resources
+ * associated with the message. Note that it is possible to access a destroyed
+ * object from PHP in rare cases.
+ */
+static void RepeatedField_destructor(zend_object* obj) {
+ RepeatedField* intern = (RepeatedField*)obj;
+ ObjCache_Delete(intern->array);
+ zval_ptr_dtor(&intern->arena);
+ zend_object_std_dtor(&intern->std);
+}
+
+static HashTable *RepeatedField_GetProperties(zval *object TSRMLS_DC) {
+ return NULL; // We do not have a properties table.
+}
+
+static zval *RepeatedField_GetPropertyPtrPtr(zval *object, zval *member,
+ int type, void **cache_slot) {
+ return NULL; // We don't offer direct references to our properties.
+}
+
+// C Functions from array.h ////////////////////////////////////////////////////
+
+// These are documented in the header file.
+
+void RepeatedField_GetPhpWrapper(zval *val, upb_array *arr,
+ const upb_fielddef *f, zval *arena) {
+ if (!arr) {
+ ZVAL_NULL(val);
+ return;
+ }
+
+ if (!ObjCache_Get(arr, val)) {
+ RepeatedField *intern = emalloc(sizeof(RepeatedField));
+ zend_object_std_init(&intern->std, RepeatedField_class_entry);
+ intern->std.handlers = &RepeatedField_object_handlers;
+ ZVAL_COPY(&intern->arena, arena);
+ intern->array = arr;
+ intern->type = upb_fielddef_type(f);
+ intern->desc = Descriptor_GetFromFieldDef(f);
+ // Skip object_properties_init(), we don't allow derived classes.
+ ObjCache_Add(intern->array, &intern->std);
+ ZVAL_OBJ(val, &intern->std);
+ }
+}
+
+upb_array *RepeatedField_GetUpbArray(zval *val, const upb_fielddef *f,
+ upb_arena *arena) {
+ if (Z_ISREF_P(val)) {
+ ZVAL_DEREF(val);
+ }
+
+ if (Z_TYPE_P(val) == IS_ARRAY) {
+ // Auto-construct, eg. [1, 2, 3] -> upb_array([1, 2, 3]).
+ upb_array *arr = upb_array_new(arena, upb_fielddef_type(f));
+ HashTable *table = HASH_OF(val);
+ HashPosition pos;
+ upb_fieldtype_t type = upb_fielddef_type(f);
+ const Descriptor *desc = Descriptor_GetFromFieldDef(f);
+
+ zend_hash_internal_pointer_reset_ex(table, &pos);
+
+ while (true) {
+ zval *zv = zend_hash_get_current_data_ex(table, &pos);
+ upb_msgval val;
+
+ if (!zv) return arr;
+
+ if (!Convert_PhpToUpbAutoWrap(zv, &val, type, desc, arena)) {
+ return NULL;
+ }
+
+ upb_array_append(arr, val, arena);
+ zend_hash_move_forward_ex(table, &pos);
+ }
+ } else if (Z_TYPE_P(val) == IS_OBJECT &&
+ Z_OBJCE_P(val) == RepeatedField_class_entry) {
+ // Unwrap existing RepeatedField object to get the upb_array* inside.
+ RepeatedField *intern = (RepeatedField*)Z_OBJ_P(val);
+ const Descriptor *desc = Descriptor_GetFromFieldDef(f);
+
+ if (intern->type != upb_fielddef_type(f) || intern->desc != desc) {
+ php_error_docref(NULL, E_USER_ERROR,
+ "Wrong type for this repeated field.");
+ }
+
+ upb_arena_fuse(arena, Arena_Get(&intern->arena));
+ return intern->array;
+ } else {
+ php_error_docref(NULL, E_USER_ERROR, "Must be a repeated field");
+ return NULL;
+ }
+}
+
+// RepeatedField PHP methods ///////////////////////////////////////////////////
+
+/**
+ * RepeatedField::__construct()
+ *
+ * Constructs an instance of RepeatedField.
+ * @param long Type of the stored element.
+ * @param string Message/Enum class.
+ */
+PHP_METHOD(RepeatedField, __construct) {
+ RepeatedField *intern = (RepeatedField*)Z_OBJ_P(getThis());
+ upb_arena *arena = Arena_Get(&intern->arena);
+ zend_long type;
+ zend_class_entry* klass = NULL;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|C", &type, &klass) != SUCCESS) {
+ return;
+ }
+
+ intern->type = pbphp_dtype_to_type(type);
+ intern->desc = Descriptor_GetFromClassEntry(klass);
+
+ if (intern->type == UPB_TYPE_MESSAGE && klass == NULL) {
+ php_error_docref(NULL, E_USER_ERROR,
+ "Message/enum type must have concrete class.");
+ return;
+ }
+
+ intern->array = upb_array_new(arena, intern->type);
+ ObjCache_Add(intern->array, &intern->std);
+}
+
+/**
+ * RepeatedField::append()
+ *
+ * Append element to the end of the repeated field.
+ * @param object The element to be added.
+ */
+PHP_METHOD(RepeatedField, append) {
+ RepeatedField *intern = (RepeatedField*)Z_OBJ_P(getThis());
+ upb_arena *arena = Arena_Get(&intern->arena);
+ zval *php_val;
+ upb_msgval msgval;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &php_val) != SUCCESS ||
+ !Convert_PhpToUpb(php_val, &msgval, intern->type, intern->desc, arena)) {
+ return;
+ }
+
+ upb_array_append(intern->array, msgval, arena);
+}
+
+/**
+ * RepeatedField::offsetExists()
+ *
+ * Implements the ArrayAccess interface. Invoked when PHP code calls:
+ *
+ * isset($arr[$idx]);
+ * empty($arr[$idx]);
+ *
+ * @param long The index to be checked.
+ * @return bool True if the element at the given index exists.
+ */
+PHP_METHOD(RepeatedField, offsetExists) {
+ RepeatedField *intern = (RepeatedField*)Z_OBJ_P(getThis());
+ zend_long index;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
+ return;
+ }
+
+ RETURN_BOOL(index >= 0 && index < upb_array_size(intern->array));
+}
+
+/**
+ * RepeatedField::offsetGet()
+ *
+ * Implements the ArrayAccess interface. Invoked when PHP code calls:
+ *
+ * $x = $arr[$idx];
+ *
+ * @param long The index of the element to be fetched.
+ * @return object The stored element at given index.
+ * @exception Invalid type for index.
+ * @exception Non-existing index.
+ */
+PHP_METHOD(RepeatedField, offsetGet) {
+ RepeatedField *intern = (RepeatedField*)Z_OBJ_P(getThis());
+ zend_long index;
+ upb_msgval msgval;
+ zval ret;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
+ return;
+ }
+
+ if (index < 0 || index >= upb_array_size(intern->array)) {
+ zend_error(E_USER_ERROR, "Element at %ld doesn't exist.\n", index);
+ return;
+ }
+
+ msgval = upb_array_get(intern->array, index);
+ Convert_UpbToPhp(msgval, &ret, intern->type, intern->desc, &intern->arena);
+ RETURN_ZVAL(&ret, 0, 1);
+}
+
+/**
+ * RepeatedField::offsetSet()
+ *
+ * Implements the ArrayAccess interface. Invoked when PHP code calls:
+ *
+ * $arr[$idx] = $x;
+ * $arr []= $x; // Append
+ *
+ * @param long The index of the element to be assigned.
+ * @param object The element to be assigned.
+ * @exception Invalid type for index.
+ * @exception Non-existing index.
+ * @exception Incorrect type of the element.
+ */
+PHP_METHOD(RepeatedField, offsetSet) {
+ RepeatedField *intern = (RepeatedField*)Z_OBJ_P(getThis());
+ upb_arena *arena = Arena_Get(&intern->arena);
+ size_t size = upb_array_size(intern->array);
+ zval *offset, *val;
+ int64_t index;
+ upb_msgval msgval;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz", &offset, &val) != SUCCESS) {
+ return;
+ }
+
+ if (Z_TYPE_P(offset) == IS_NULL) {
+ index = size;
+ } else if (!Convert_PhpToInt64(offset, &index)) {
+ return;
+ }
+
+ if (!Convert_PhpToUpb(val, &msgval, intern->type, intern->desc, arena)) {
+ return;
+ }
+
+ if (index > size) {
+ zend_error(E_USER_ERROR, "Element at index %ld doesn't exist.\n", index);
+ } else if (index == size) {
+ upb_array_append(intern->array, msgval, Arena_Get(&intern->arena));
+ } else {
+ upb_array_set(intern->array, index, msgval);
+ }
+}
+
+/**
+ * RepeatedField::offsetUnset()
+ *
+ * Implements the ArrayAccess interface. Invoked when PHP code calls:
+ *
+ * unset($arr[$idx]);
+ *
+ * @param long The index of the element to be removed.
+ * @exception Invalid type for index.
+ * @exception The element to be removed is not at the end of the RepeatedField.
+ */
+PHP_METHOD(RepeatedField, offsetUnset) {
+ RepeatedField *intern = (RepeatedField*)Z_OBJ_P(getThis());
+ zend_long index;
+ zend_long size = upb_array_size(intern->array);
+
+ // Only the element at the end of the array can be removed.
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) != SUCCESS) {
+ return;
+ }
+
+ if (size == 0 || index != size - 1) {
+ php_error_docref(NULL, E_USER_ERROR, "Cannot remove element at %ld.\n",
+ index);
+ return;
+ }
+
+ upb_array_resize(intern->array, size - 1, Arena_Get(&intern->arena));
+}
+
+/**
+ * RepeatedField::count()
+ *
+ * Implements the Countable interface. Invoked when PHP code calls:
+ *
+ * $len = count($arr);
+ * Return the number of stored elements.
+ * This will also be called for: count($arr)
+ * @return long The number of stored elements.
+ */
+PHP_METHOD(RepeatedField, count) {
+ RepeatedField *intern = (RepeatedField*)Z_OBJ_P(getThis());
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ RETURN_LONG(upb_array_size(intern->array));
+}
+
+/**
+ * RepeatedField::getIterator()
+ *
+ * Implements the IteratorAggregate interface. Invoked when PHP code calls:
+ *
+ * foreach ($arr) {}
+ *
+ * @return object Beginning iterator.
+ */
+PHP_METHOD(RepeatedField, getIterator) {
+ zval ret;
+ RepeatedFieldIter_make(&ret, getThis());
+ RETURN_ZVAL(&ret, 0, 1);
+}
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetGet, 0, 0, 1)
+ ZEND_ARG_INFO(0, index)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetSet, 0, 0, 2)
+ ZEND_ARG_INFO(0, index)
+ ZEND_ARG_INFO(0, newval)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_void, 0)
+ZEND_END_ARG_INFO()
+
+static zend_function_entry repeated_field_methods[] = {
+ PHP_ME(RepeatedField, __construct, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(RepeatedField, append, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(RepeatedField, offsetExists, arginfo_offsetGet, ZEND_ACC_PUBLIC)
+ PHP_ME(RepeatedField, offsetGet, arginfo_offsetGet, ZEND_ACC_PUBLIC)
+ PHP_ME(RepeatedField, offsetSet, arginfo_offsetSet, ZEND_ACC_PUBLIC)
+ PHP_ME(RepeatedField, offsetUnset, arginfo_offsetGet, ZEND_ACC_PUBLIC)
+ PHP_ME(RepeatedField, count, arginfo_void, ZEND_ACC_PUBLIC)
+ PHP_ME(RepeatedField, getIterator, arginfo_void, ZEND_ACC_PUBLIC)
+ ZEND_FE_END
+};
+
+// -----------------------------------------------------------------------------
+// PHP RepeatedFieldIter
+// -----------------------------------------------------------------------------
+
+typedef struct {
+ zend_object std;
+ zval repeated_field;
+ zend_long position;
+} RepeatedFieldIter;
+
+zend_class_entry *RepeatedFieldIter_class_entry;
+static zend_object_handlers repeated_field_iter_object_handlers;
+
+/**
+ * RepeatedFieldIter_create()
+ *
+ * PHP class entry function to allocate and initialize a new RepeatedFieldIter
+ * object.
+ */
+zend_object* RepeatedFieldIter_create(zend_class_entry *class_type) {
+ RepeatedFieldIter *intern = emalloc(sizeof(RepeatedFieldIter));
+ zend_object_std_init(&intern->std, class_type);
+ intern->std.handlers = &repeated_field_iter_object_handlers;
+ ZVAL_NULL(&intern->repeated_field);
+ intern->position = 0;
+ // Skip object_properties_init(), we don't allow derived classes.
+ return &intern->std;
+}
+
+/**
+ * RepeatedFieldIter_dtor()
+ *
+ * Object handler to destroy a RepeatedFieldIter. This releases all resources
+ * associated with the message. Note that it is possible to access a destroyed
+ * object from PHP in rare cases.
+ */
+static void RepeatedFieldIter_dtor(zend_object* obj) {
+ RepeatedFieldIter* intern = (RepeatedFieldIter*)obj;
+ zval_ptr_dtor(&intern->repeated_field);
+ zend_object_std_dtor(&intern->std);
+}
+
+/**
+ * RepeatedFieldIter_make()
+ *
+ * C function to create a RepeatedFieldIter.
+ */
+static void RepeatedFieldIter_make(zval *val, zval *repeated_field) {
+ RepeatedFieldIter *iter;
+ ZVAL_OBJ(val, RepeatedFieldIter_class_entry->create_object(
+ RepeatedFieldIter_class_entry));
+ iter = (RepeatedFieldIter*)Z_OBJ_P(val);
+ ZVAL_COPY(&iter->repeated_field, repeated_field);
+}
+
+/*
+ * When a user writes:
+ *
+ * foreach($arr as $key => $val) {}
+ *
+ * PHP's iterator protocol is:
+ *
+ * $iter = $arr->getIterator();
+ * for ($iter->rewind(); $iter->valid(); $iter->next()) {
+ * $key = $iter->key();
+ * $val = $iter->current();
+ * }
+ */
+
+/**
+ * RepeatedFieldIter::rewind()
+ *
+ * Implements the Iterator interface. Sets the iterator to the first element.
+ */
+PHP_METHOD(RepeatedFieldIter, rewind) {
+ RepeatedFieldIter *intern = (RepeatedFieldIter*)Z_OBJ_P(getThis());
+ intern->position = 0;
+}
+
+/**
+ * RepeatedFieldIter::current()
+ *
+ * Implements the Iterator interface. Returns the current value.
+ */
+PHP_METHOD(RepeatedFieldIter, current) {
+ RepeatedFieldIter *intern = (RepeatedFieldIter*)Z_OBJ_P(getThis());
+ RepeatedField *field = (RepeatedField*)Z_OBJ_P(&intern->repeated_field);
+ upb_array *array = field->array;
+ zend_long index = intern->position;
+ upb_msgval msgval;
+ zval ret;
+
+ if (index < 0 || index >= upb_array_size(array)) {
+ zend_error(E_USER_ERROR, "Element at %ld doesn't exist.\n", index);
+ }
+
+ msgval = upb_array_get(array, index);
+
+ Convert_UpbToPhp(msgval, &ret, field->type, field->desc, &field->arena);
+ RETURN_ZVAL(&ret, 0, 1);
+}
+
+/**
+ * RepeatedFieldIter::key()
+ *
+ * Implements the Iterator interface. Returns the current key.
+ */
+PHP_METHOD(RepeatedFieldIter, key) {
+ RepeatedFieldIter *intern = (RepeatedFieldIter*)Z_OBJ_P(getThis());
+ RETURN_LONG(intern->position);
+}
+
+/**
+ * RepeatedFieldIter::next()
+ *
+ * Implements the Iterator interface. Advances to the next element.
+ */
+PHP_METHOD(RepeatedFieldIter, next) {
+ RepeatedFieldIter *intern = (RepeatedFieldIter*)Z_OBJ_P(getThis());
+ ++intern->position;
+}
+
+/**
+ * RepeatedFieldIter::valid()
+ *
+ * Implements the Iterator interface. Returns true if this is a valid element.
+ */
+PHP_METHOD(RepeatedFieldIter, valid) {
+ RepeatedFieldIter *intern = (RepeatedFieldIter*)Z_OBJ_P(getThis());
+ RepeatedField *field = (RepeatedField*)Z_OBJ_P(&intern->repeated_field);
+ RETURN_BOOL(intern->position < upb_array_size(field->array));
+}
+
+static zend_function_entry repeated_field_iter_methods[] = {
+ PHP_ME(RepeatedFieldIter, rewind, arginfo_void, ZEND_ACC_PUBLIC)
+ PHP_ME(RepeatedFieldIter, current, arginfo_void, ZEND_ACC_PUBLIC)
+ PHP_ME(RepeatedFieldIter, key, arginfo_void, ZEND_ACC_PUBLIC)
+ PHP_ME(RepeatedFieldIter, next, arginfo_void, ZEND_ACC_PUBLIC)
+ PHP_ME(RepeatedFieldIter, valid, arginfo_void, ZEND_ACC_PUBLIC)
+ ZEND_FE_END
+};
+
+// -----------------------------------------------------------------------------
+// Module init.
+// -----------------------------------------------------------------------------
+
+/**
+ * Array_ModuleInit()
+ *
+ * Called when the C extension is loaded to register all types.
+ */
+void Array_ModuleInit() {
+ zend_class_entry tmp_ce;
+ zend_object_handlers *h;
+
+ // RepeatedField.
+ INIT_CLASS_ENTRY(tmp_ce, "Google\\Protobuf\\Internal\\RepeatedField",
+ repeated_field_methods);
+
+ RepeatedField_class_entry = zend_register_internal_class(&tmp_ce);
+ zend_class_implements(RepeatedField_class_entry, 3, spl_ce_ArrayAccess,
+ zend_ce_aggregate, spl_ce_Countable);
+ RepeatedField_class_entry->ce_flags |= ZEND_ACC_FINAL;
+ RepeatedField_class_entry->create_object = RepeatedField_create;
+
+ h = &RepeatedField_object_handlers;
+ memcpy(h, &std_object_handlers, sizeof(zend_object_handlers));
+ h->dtor_obj = RepeatedField_destructor;
+ h->get_properties = RepeatedField_GetProperties;
+ h->get_property_ptr_ptr = RepeatedField_GetPropertyPtrPtr;
+
+ // RepeatedFieldIter
+ INIT_CLASS_ENTRY(tmp_ce, "Google\\Protobuf\\Internal\\RepeatedFieldIter",
+ repeated_field_iter_methods);
+
+ RepeatedFieldIter_class_entry = zend_register_internal_class(&tmp_ce);
+ zend_class_implements(RepeatedFieldIter_class_entry, 1, zend_ce_iterator);
+ RepeatedFieldIter_class_entry->ce_flags |= ZEND_ACC_FINAL;
+ RepeatedFieldIter_class_entry->create_object = RepeatedFieldIter_create;
+
+ h = &repeated_field_iter_object_handlers;
+ memcpy(h, &std_object_handlers, sizeof(zend_object_handlers));
+ h->dtor_obj = RepeatedFieldIter_dtor;
+}
diff --git a/php/ext/google/protobuf2/array.h b/php/ext/google/protobuf2/array.h
new file mode 100644
index 0000000000..5cf517c566
--- /dev/null
+++ b/php/ext/google/protobuf2/array.h
@@ -0,0 +1,61 @@
+// 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.
+
+#ifndef PHP_PROTOBUF_ARRAY_H_
+#define PHP_PROTOBUF_ARRAY_H_
+
+#include
+
+#include "php-upb.h"
+
+// Registers PHP classes for RepeatedField.
+void Array_ModuleInit();
+
+// Gets a upb_array* for the PHP object |val|:
+// * If |val| is a RepeatedField object, we first check its type and verify
+// that that the elements have the correct type for |f|. If so, we return the
+// wrapped upb_array*. We also make sure that this array's arena is fused to
+// |arena|, so the returned upb_array is guaranteed to live as long as
+// |arena|.
+// * If |val| is a PHP Array, we attempt to create a new upb_array using
+// |arena| and add all of the PHP elements to it.
+//
+// If an error occurs, we raise a PHP error and return NULL.
+upb_array *RepeatedField_GetUpbArray(zval *val, const upb_fielddef *f, upb_arena *arena);
+
+// Creates a PHP RepeatedField object for the given upb_array* and |f| and
+// returns it in |val|. The PHP object will keep a reference to this |arena| to
+// ensure the underlying array data stays alive.
+//
+// If |arr| is NULL, this will return a PHP null object.
+void RepeatedField_GetPhpWrapper(zval *val, upb_array *arr,
+ const upb_fielddef *f, zval *arena);
+
+#endif // PHP_PROTOBUF_ARRAY_H_
diff --git a/php/ext/google/protobuf2/bundled_php.h b/php/ext/google/protobuf2/bundled_php.h
new file mode 100644
index 0000000000..76147677a1
--- /dev/null
+++ b/php/ext/google/protobuf2/bundled_php.h
@@ -0,0 +1,46 @@
+// 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.
+
+#ifndef PHP_PROTOBUF_BUNDLED_PHP_H_
+#define PHP_PROTOBUF_BUNDLED_PHP_H_
+
+// We embed PHP source code into the binary for things we don't want to
+// implement in C. This struct serves as a table of contents for all of
+// the embedded files.
+typedef struct {
+ const char *filename;
+ const char *contents;
+} BundledPhp_File;
+
+// An array of all the embedded file structs. This array is terminated with a
+// {NULL, NULL} entry.
+extern BundledPhp_File *bundled_files;
+
+#endif // PHP_PROTOBUF_BUNDLED_PHP_H_
diff --git a/php/ext/google/protobuf2/config.m4 b/php/ext/google/protobuf2/config.m4
new file mode 100644
index 0000000000..3fdcb00480
--- /dev/null
+++ b/php/ext/google/protobuf2/config.m4
@@ -0,0 +1,10 @@
+PHP_ARG_ENABLE(protobuf, whether to enable Protobuf extension, [ --enable-protobuf Enable Protobuf extension])
+
+if test "$PHP_PROTOBUF" != "no"; then
+
+ PHP_NEW_EXTENSION(
+ protobuf,
+ arena.c array.c bundled_php.c convert.c def.c map.c message.c names.c php-upb.c protobuf.c,
+ $ext_shared)
+
+fi
diff --git a/php/ext/google/protobuf2/convert.c b/php/ext/google/protobuf2/convert.c
new file mode 100644
index 0000000000..dd076c5f1a
--- /dev/null
+++ b/php/ext/google/protobuf2/convert.c
@@ -0,0 +1,478 @@
+// 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.
+
+#include "convert.h"
+
+#include
+
+// This is not self-contained: it must be after other Zend includes.
+#include
+
+#include "array.h"
+#include "map.h"
+#include "message.h"
+#include "php-upb.h"
+#include "protobuf.h"
+
+// -----------------------------------------------------------------------------
+// GPBUtil
+// -----------------------------------------------------------------------------
+
+static zend_class_entry* GPBUtil_class_entry;
+
+// The implementation of type checking for primitive fields is empty. This is
+// because type checking is done when direct assigning message fields (e.g.,
+// foo->a = 1). Functions defined here are place holders in generated code for
+// pure PHP implementation (c extension and pure PHP share the same generated
+// code).
+
+PHP_METHOD(Util, checkInt32) {}
+PHP_METHOD(Util, checkUint32) {}
+PHP_METHOD(Util, checkInt64) {}
+PHP_METHOD(Util, checkUint64) {}
+PHP_METHOD(Util, checkEnum) {}
+PHP_METHOD(Util, checkFloat) {}
+PHP_METHOD(Util, checkDouble) {}
+PHP_METHOD(Util, checkBool) {}
+PHP_METHOD(Util, checkString) {}
+PHP_METHOD(Util, checkBytes) {}
+PHP_METHOD(Util, checkMessage) {}
+
+// The result of checkMapField() is assigned, so we need to return the first
+// param:
+// $arr = GPBUtil::checkMapField($var,
+// \Google\Protobuf\Internal\GPBType::INT64,
+// \Google\Protobuf\Internal\GPBType::INT32);
+PHP_METHOD(Util, checkMapField) {
+ zval *val, *key_type, *val_type, *klass;
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "zzz|z", &val, &key_type,
+ &val_type, &klass) == FAILURE) {
+ return;
+ }
+ RETURN_ZVAL(val, 1, 0);
+}
+
+// The result of checkRepeatedField() is assigned, so we need to return the
+// first param:
+// $arr = GPBUtil::checkRepeatedField(
+// $var, \Google\Protobuf\Internal\GPBType::STRING);
+PHP_METHOD(Util, checkRepeatedField) {
+ zval *val, *type, *klass;
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz|z", &val, &type, &klass) ==
+ FAILURE) {
+ return;
+ }
+ RETURN_ZVAL(val, 1, 0);
+}
+
+static zend_function_entry util_methods[] = {
+ PHP_ME(Util, checkInt32, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+ PHP_ME(Util, checkUint32, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+ PHP_ME(Util, checkInt64, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+ PHP_ME(Util, checkUint64, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+ PHP_ME(Util, checkEnum, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+ PHP_ME(Util, checkFloat, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+ PHP_ME(Util, checkDouble, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+ PHP_ME(Util, checkBool, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+ PHP_ME(Util, checkString, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+ PHP_ME(Util, checkBytes, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+ PHP_ME(Util, checkMessage, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+ PHP_ME(Util, checkMapField, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+ PHP_ME(Util, checkRepeatedField, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+ ZEND_FE_END
+};
+
+// -----------------------------------------------------------------------------
+// Conversion functions used from C
+// -----------------------------------------------------------------------------
+
+upb_fieldtype_t pbphp_dtype_to_type(upb_descriptortype_t type) {
+ switch (type) {
+#define CASE(descriptor_type, type) \
+ case UPB_DESCRIPTOR_TYPE_##descriptor_type: \
+ return UPB_TYPE_##type;
+
+ CASE(FLOAT, FLOAT);
+ CASE(DOUBLE, DOUBLE);
+ CASE(BOOL, BOOL);
+ CASE(STRING, STRING);
+ CASE(BYTES, BYTES);
+ CASE(MESSAGE, MESSAGE);
+ CASE(GROUP, MESSAGE);
+ CASE(ENUM, ENUM);
+ CASE(INT32, INT32);
+ CASE(INT64, INT64);
+ CASE(UINT32, UINT32);
+ CASE(UINT64, UINT64);
+ CASE(SINT32, INT32);
+ CASE(SINT64, INT64);
+ CASE(FIXED32, UINT32);
+ CASE(FIXED64, UINT64);
+ CASE(SFIXED32, INT32);
+ CASE(SFIXED64, INT64);
+
+#undef CASE
+
+ }
+
+ zend_error(E_ERROR, "Unknown field type.");
+ return 0;
+}
+
+static bool buftouint64(const char *ptr, const char *end, uint64_t *val) {
+ uint64_t u64 = 0;
+ while (ptr < end) {
+ unsigned ch = (unsigned)(*ptr - '0');
+ if (ch >= 10) break;
+ if (u64 > UINT64_MAX / 10 || u64 * 10 > UINT64_MAX - ch) {
+ return false;
+ }
+ u64 *= 10;
+ u64 += ch;
+ ptr++;
+ }
+
+ if (ptr != end) {
+ // In PHP tradition, we allow truncation: "1.1" -> 1.
+ // But we don't allow 'e', eg. '1.1e2' or any other non-numeric chars.
+ if (*ptr++ != '.') return false;
+
+ for (;ptr < end; ptr++) {
+ if (*ptr < '0' || *ptr > '9') {
+ return false;
+ }
+ }
+ }
+
+ *val = u64;
+ return true;
+}
+
+static bool buftoint64(const char *ptr, const char *end, int64_t *val) {
+ bool neg = false;
+ uint64_t u64;
+
+ if (ptr != end && *ptr == '-') {
+ ptr++;
+ neg = true;
+ }
+
+ if (!buftouint64(ptr, end, &u64) ||
+ u64 > (uint64_t)INT64_MAX + neg) {
+ return false;
+ }
+
+ *val = neg ? -u64 : u64;
+ return true;
+}
+
+static void throw_conversion_exception(const char *to, const zval *zv) {
+ zval tmp;
+ ZVAL_COPY(&tmp, zv);
+ convert_to_string(&tmp);
+
+ zend_throw_exception_ex(NULL, 0, "Cannot convert '%s' to %s",
+ Z_STRVAL_P(&tmp), to);
+
+ zval_ptr_dtor(&tmp);
+}
+
+bool Convert_PhpToInt64(const zval *php_val, int64_t *i64) {
+ switch (Z_TYPE_P(php_val)) {
+ case IS_LONG:
+ *i64 = Z_LVAL_P(php_val);
+ return true;
+ case IS_DOUBLE: {
+ double dbl = Z_DVAL_P(php_val);
+ if (dbl > 9223372036854774784.0 || dbl < -9223372036854775808.0) {
+ zend_throw_exception_ex(NULL, 0, "Out of range");
+ return false;
+ }
+ *i64 = dbl; /* must be guarded, overflow here is UB */
+ return true;
+ }
+ case IS_STRING: {
+ const char *buf = Z_STRVAL_P(php_val);
+ // PHP would accept scientific notation here, but we're going to be a
+ // little more discerning and only accept pure integers.
+ bool ok = buftoint64(buf, buf + Z_STRLEN_P(php_val), i64);
+ if (!ok) {
+ throw_conversion_exception("integer", php_val);
+ }
+ return ok;
+ }
+ default:
+ throw_conversion_exception("integer", php_val);
+ return false;
+ }
+}
+
+static bool to_double(zval *php_val, double *dbl) {
+ switch (Z_TYPE_P(php_val)) {
+ case IS_LONG:
+ *dbl = Z_LVAL_P(php_val);
+ return true;
+ case IS_DOUBLE:
+ *dbl = Z_DVAL_P(php_val);
+ return true;
+ case IS_STRING: {
+ zend_long lval;
+ switch (is_numeric_string(Z_STRVAL_P(php_val), Z_STRLEN_P(php_val), &lval,
+ dbl, false)) {
+ case IS_LONG:
+ *dbl = lval;
+ return true;
+ case IS_DOUBLE:
+ return true;
+ default:
+ goto fail;
+ }
+ }
+ default:
+ fail:
+ throw_conversion_exception("double", php_val);
+ return false;
+ }
+}
+
+static bool to_bool(zval* from, bool* to) {
+ switch (Z_TYPE_P(from)) {
+ case IS_TRUE:
+ *to = true;
+ return true;
+ case IS_FALSE:
+ *to = false;
+ return true;
+ case IS_LONG:
+ *to = (Z_LVAL_P(from) != 0);
+ return true;
+ case IS_DOUBLE:
+ *to = (Z_LVAL_P(from) != 0);
+ return true;
+ case IS_STRING:
+ if (Z_STRLEN_P(from) == 0 ||
+ (Z_STRLEN_P(from) == 1 && Z_STRVAL_P(from)[0] == '0')) {
+ *to = false;
+ } else {
+ *to = true;
+ }
+ return true;
+ default:
+ throw_conversion_exception("bool", from);
+ return false;
+ }
+}
+
+static bool to_string(zval* from) {
+ if (Z_ISREF_P(from)) {
+ ZVAL_DEREF(from);
+ }
+
+ switch (Z_TYPE_P(from)) {
+ case IS_STRING:
+ return true;
+ case IS_TRUE:
+ case IS_FALSE:
+ case IS_LONG:
+ case IS_DOUBLE: {
+ zval tmp;
+ zend_make_printable_zval(from, &tmp);
+ ZVAL_COPY_VALUE(from, &tmp);
+ return true;
+ }
+ default:
+ throw_conversion_exception("string", from);
+ return false;
+ }
+}
+
+bool Convert_PhpToUpb(zval *php_val, upb_msgval *upb_val, upb_fieldtype_t type,
+ const Descriptor *desc, upb_arena *arena) {
+ int64_t i64;
+
+ if (Z_ISREF_P(php_val)) {
+ ZVAL_DEREF(php_val);
+ }
+
+ switch (type) {
+ case UPB_TYPE_INT64:
+ return Convert_PhpToInt64(php_val, &upb_val->int64_val);
+ case UPB_TYPE_INT32:
+ case UPB_TYPE_ENUM:
+ if (!Convert_PhpToInt64(php_val, &i64)) {
+ return false;
+ }
+ upb_val->int32_val = i64;
+ return true;
+ case UPB_TYPE_UINT64:
+ if (!Convert_PhpToInt64(php_val, &i64)) {
+ return false;
+ }
+ upb_val->uint64_val = i64;
+ return true;
+ case UPB_TYPE_UINT32:
+ if (!Convert_PhpToInt64(php_val, &i64)) {
+ return false;
+ }
+ upb_val->uint32_val = i64;
+ return true;
+ case UPB_TYPE_DOUBLE:
+ return to_double(php_val, &upb_val->double_val);
+ case UPB_TYPE_FLOAT:
+ if (!to_double(php_val, &upb_val->double_val)) return false;
+ upb_val->float_val = upb_val->double_val;
+ return true;
+ case UPB_TYPE_BOOL:
+ return to_bool(php_val, &upb_val->bool_val);
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES: {
+ char *ptr;
+ size_t size;
+
+ if (!to_string(php_val)) return false;
+
+ size = Z_STRLEN_P(php_val);
+
+ // If arena is NULL we reference the input zval.
+ // The resulting upb_strview will only be value while the zval is alive.
+ if (arena) {
+ ptr = upb_arena_malloc(arena, size);
+ memcpy(ptr, Z_STRVAL_P(php_val), size);
+ } else {
+ ptr = Z_STRVAL_P(php_val);
+ }
+
+ upb_val->str_val = upb_strview_make(ptr, size);
+ return true;
+ }
+ case UPB_TYPE_MESSAGE:
+ PBPHP_ASSERT(desc);
+ return Message_GetUpbMessage(php_val, desc, arena,
+ (upb_msg **)&upb_val->msg_val);
+ }
+
+ return false;
+}
+
+void Convert_UpbToPhp(upb_msgval upb_val, zval *php_val, upb_fieldtype_t type,
+ const Descriptor *desc, zval *arena) {
+ switch (type) {
+ case UPB_TYPE_INT64:
+#if SIZEOF_ZEND_LONG == 8
+ ZVAL_LONG(php_val, upb_val.int64_val);
+#else
+ {
+ char buf[20];
+ int size = sprintf(buf, "%lld", upb_val.int64_val);
+ ZVAL_NEW_STR(php_val, zend_string_init(buf, size, 0));
+ }
+#endif
+ break;
+ case UPB_TYPE_UINT64:
+#if SIZEOF_ZEND_LONG == 8
+ ZVAL_LONG(php_val, upb_val.uint64_val);
+#else
+ {
+ char buf[20];
+ int size = sprintf(buf, "%lld", (int64_t)upb_val.uint64_val);
+ ZVAL_NEW_STR(php_val, zend_string_init(buf, size, 0));
+ }
+#endif
+ break;
+ case UPB_TYPE_INT32:
+ case UPB_TYPE_ENUM:
+ ZVAL_LONG(php_val, upb_val.int32_val);
+ break;
+ case UPB_TYPE_UINT32: {
+ // Sign-extend for consistency between 32/64-bit builds.
+ zend_long val = (int32_t)upb_val.uint32_val;
+ ZVAL_LONG(php_val, val);
+ break;
+ }
+ case UPB_TYPE_DOUBLE:
+ ZVAL_DOUBLE(php_val, upb_val.double_val);
+ break;
+ case UPB_TYPE_FLOAT:
+ ZVAL_DOUBLE(php_val, upb_val.float_val);
+ break;
+ case UPB_TYPE_BOOL:
+ ZVAL_BOOL(php_val, upb_val.bool_val);
+ break;
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES: {
+ upb_strview str = upb_val.str_val;
+ ZVAL_NEW_STR(php_val, zend_string_init(str.data, str.size, 0));
+ break;
+ }
+ case UPB_TYPE_MESSAGE:
+ PBPHP_ASSERT(desc);
+ Message_GetPhpWrapper(php_val, desc, (upb_msg*)upb_val.msg_val, arena);
+ break;
+ }
+}
+
+bool Convert_PhpToUpbAutoWrap(zval *val, upb_msgval *upb_val,
+ upb_fieldtype_t type, const Descriptor *desc,
+ upb_arena *arena) {
+ const upb_msgdef *subm = desc ? desc->msgdef : NULL;
+ if (subm && upb_msgdef_iswrapper(subm) && Z_TYPE_P(val) != IS_OBJECT) {
+ // Assigning a scalar to a wrapper-typed value. We will automatically wrap
+ // the value, so the user doesn't need to create a FooWrapper(['value': X])
+ // message manually.
+ upb_msg *wrapper = upb_msg_new(subm, arena);
+ const upb_fielddef *val_f = upb_msgdef_itof(subm, 1);
+ upb_fieldtype_t type_f = upb_fielddef_type(val_f);
+ upb_msgval msgval;
+ if (!Convert_PhpToUpb(val, &msgval, type_f, NULL, arena)) return false;
+ upb_msg_set(wrapper, val_f, msgval, arena);
+ upb_val->msg_val = wrapper;
+ return true;
+ } else {
+ // Convert_PhpToUpb doesn't auto-construct messages. This means that we only
+ // allow:
+ // ['foo_submsg': new Foo(['a' => 1])]
+ // not:
+ // ['foo_submsg': ['a' => 1]]
+ return Convert_PhpToUpb(val, upb_val, type, desc, arena);
+ }
+}
+
+void Convert_ModuleInit(void) {
+ const char *prefix_name = "TYPE_URL_PREFIX";
+ zend_class_entry class_type;
+
+ INIT_CLASS_ENTRY(class_type, "Google\\Protobuf\\Internal\\GPBUtil",
+ util_methods);
+ GPBUtil_class_entry = zend_register_internal_class(&class_type);
+
+ zend_declare_class_constant_string(GPBUtil_class_entry, prefix_name,
+ strlen(prefix_name),
+ "type.googleapis.com/");
+}
diff --git a/php/ext/google/protobuf2/convert.h b/php/ext/google/protobuf2/convert.h
new file mode 100644
index 0000000000..06c05c7275
--- /dev/null
+++ b/php/ext/google/protobuf2/convert.h
@@ -0,0 +1,73 @@
+// 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.
+
+#ifndef PHP_PROTOBUF_CONVERT_H_
+#define PHP_PROTOBUF_CONVERT_H_
+
+#include
+
+#include "php-upb.h"
+#include "def.h"
+
+upb_fieldtype_t pbphp_dtype_to_type(upb_descriptortype_t type);
+
+// Converts |php_val| to an int64_t. Returns false if the value cannot be
+// converted.
+bool Convert_PhpToInt64(const zval *php_val, int64_t *i64);
+
+// Converts |php_val| to a upb_msgval according to |type|. If type is
+// UPB_TYPE_MESSAGE, then |desc| must be the Descriptor for this message type.
+// If type is string, message, or bytes, then |arena| will be used to copy
+// string data or fuse this arena to the given message's arena.
+bool Convert_PhpToUpb(zval *php_val, upb_msgval *upb_val, upb_fieldtype_t type,
+ const Descriptor *desc, upb_arena *arena);
+
+// Similar to Convert_PhpToUpb, but supports automatically wrapping the wrapper
+// types if a primitive is specified:
+//
+// 5 -> Int64Wrapper(value=5)
+//
+// We currently allow this implicit conversion in initializers, but not for
+// assignment.
+bool Convert_PhpToUpbAutoWrap(zval *val, upb_msgval *upb_val,
+ upb_fieldtype_t type, const Descriptor *desc,
+ upb_arena *arena);
+
+// Converts |upb_val| to a PHP zval according to |type|. This may involve
+// creating a PHP wrapper object. If type == UPB_TYPE_MESSAGE, then |desc| must
+// be the Descriptor for this message type. Any newly created wrapper object
+// will reference |arena|.
+void Convert_UpbToPhp(upb_msgval upb_val, zval *php_val, upb_fieldtype_t type,
+ const Descriptor *desc, zval *arena);
+
+// Registers the GPBUtil class.
+void Convert_ModuleInit(void);
+
+#endif // PHP_PROTOBUF_CONVERT_H_
diff --git a/php/ext/google/protobuf2/def.c b/php/ext/google/protobuf2/def.c
new file mode 100644
index 0000000000..c76134d86b
--- /dev/null
+++ b/php/ext/google/protobuf2/def.c
@@ -0,0 +1,1085 @@
+// 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.
+
+#include "def.h"
+
+#include
+
+// This is not self-contained: it must be after other Zend includes.
+#include
+
+#include "names.h"
+#include "php-upb.h"
+#include "protobuf.h"
+
+static void CheckUpbStatus(const upb_status* status, const char* msg) {
+ if (!upb_ok(status)) {
+ zend_error(E_ERROR, "%s: %s\n", msg, upb_status_errmsg(status));
+ }
+}
+
+static void FieldDescriptor_FromFieldDef(zval *val, const upb_fielddef *f);
+
+// We use this for objects that should not be created directly from PHP.
+static zend_object *CreateHandler_ReturnNull(zend_class_entry *class_type) {
+ return NULL; // Nobody should call this.
+}
+
+
+// -----------------------------------------------------------------------------
+// EnumValueDescriptor
+// -----------------------------------------------------------------------------
+
+typedef struct {
+ zend_object std;
+ const char *name;
+ int32_t number;
+} EnumValueDescriptor;
+
+zend_class_entry *EnumValueDescriptor_class_entry;
+static zend_object_handlers EnumValueDescriptor_object_handlers;
+
+/*
+ * EnumValueDescriptor_Make()
+ *
+ * Function to create an EnumValueDescriptor object from C.
+ */
+static void EnumValueDescriptor_Make(zval *val, const char *name,
+ int32_t number) {
+ EnumValueDescriptor *intern = emalloc(sizeof(EnumValueDescriptor));
+ zend_object_std_init(&intern->std, EnumValueDescriptor_class_entry);
+ intern->std.handlers = &EnumValueDescriptor_object_handlers;
+ intern->name = name;
+ intern->number = number;
+ // Skip object_properties_init(), we don't allow derived classes.
+ ZVAL_OBJ(val, &intern->std);
+}
+
+/*
+ * EnumValueDescriptor::getName()
+ *
+ * Returns the name for this enum value.
+ */
+PHP_METHOD(EnumValueDescriptor, getName) {
+ EnumValueDescriptor *intern = (EnumValueDescriptor*)Z_OBJ_P(getThis());
+ RETURN_STRING(intern->name);
+}
+
+/*
+ * EnumValueDescriptor::getNumber()
+ *
+ * Returns the number for this enum value.
+ */
+PHP_METHOD(EnumValueDescriptor, getNumber) {
+ EnumValueDescriptor *intern = (EnumValueDescriptor*)Z_OBJ_P(getThis());
+ RETURN_LONG(intern->number);
+}
+
+static zend_function_entry EnumValueDescriptor_methods[] = {
+ PHP_ME(EnumValueDescriptor, getName, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(EnumValueDescriptor, getNumber, NULL, ZEND_ACC_PUBLIC)
+ ZEND_FE_END
+};
+
+// -----------------------------------------------------------------------------
+// EnumDescriptor
+// -----------------------------------------------------------------------------
+
+typedef struct {
+ zend_object std;
+ const upb_enumdef *enumdef;
+} EnumDescriptor;
+
+zend_class_entry *EnumDescriptor_class_entry;
+static zend_object_handlers EnumDescriptor_object_handlers;
+
+void EnumDescriptor_FromClassEntry(zval *val, zend_class_entry *ce) {
+ // To differentiate enums from classes, we pointer-tag the class entry.
+ void* key = (void*)((uintptr_t)ce | 1);
+ PBPHP_ASSERT(key != ce);
+
+ if (ce == NULL) {
+ ZVAL_NULL(val);
+ return;
+ }
+
+ if (!ObjCache_Get(key, val)) {
+ const upb_enumdef *e = NameMap_GetEnum(ce);
+ if (!e) {
+ ZVAL_NULL(val);
+ return;
+ }
+ EnumDescriptor* ret = emalloc(sizeof(EnumDescriptor));
+ zend_object_std_init(&ret->std, EnumDescriptor_class_entry);
+ ret->std.handlers = &EnumDescriptor_object_handlers;
+ ret->enumdef = e;
+ ObjCache_Add(key, &ret->std);
+
+ // Prevent this from ever being collected (within a request).
+ GC_ADDREF(&ret->std);
+
+ ZVAL_OBJ(val, &ret->std);
+ }
+}
+
+void EnumDescriptor_FromEnumDef(zval *val, const upb_enumdef *m) {
+ if (!m) {
+ ZVAL_NULL(val);
+ } else {
+ char *classname =
+ GetPhpClassname(upb_enumdef_file(m), upb_enumdef_fullname(m));
+ zend_string *str = zend_string_init(classname, strlen(classname), 0);
+ zend_class_entry *ce = zend_lookup_class(str); // May autoload the class.
+
+ zend_string_release (str);
+
+ if (!ce) {
+ zend_error(E_ERROR, "Couldn't load generated class %s", classname);
+ }
+
+ free(classname);
+ EnumDescriptor_FromClassEntry(val, ce);
+ }
+}
+
+/*
+ * EnumDescriptor::getValue()
+ *
+ * Returns an EnumValueDescriptor for this index. Note: we are not looking
+ * up by numeric enum value, but by the index in the list of enum values.
+ */
+PHP_METHOD(EnumDescriptor, getValue) {
+ EnumDescriptor *intern = (EnumDescriptor*)Z_OBJ_P(getThis());
+ zend_long index;
+ zval ret;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) ==
+ FAILURE) {
+ zend_error(E_USER_ERROR, "Expect integer for index.\n");
+ return;
+ }
+
+ int field_num = upb_enumdef_numvals(intern->enumdef);
+ if (index < 0 || index >= field_num) {
+ zend_error(E_USER_ERROR, "Cannot get element at %ld.\n", index);
+ return;
+ }
+
+ upb_enum_iter iter;
+ int i;
+ for(upb_enum_begin(&iter, intern->enumdef), i = 0;
+ !upb_enum_done(&iter) && i < index;
+ upb_enum_next(&iter), i++);
+
+ EnumValueDescriptor_Make(&ret, upb_enum_iter_name(&iter),
+ upb_enum_iter_number(&iter));
+ RETURN_ZVAL(&ret, 0, 1);
+}
+
+/*
+ * EnumDescriptor::getValueCount()
+ *
+ * Returns the number of values in this enum.
+ */
+PHP_METHOD(EnumDescriptor, getValueCount) {
+ EnumDescriptor *intern = (EnumDescriptor*)Z_OBJ_P(getThis());
+ RETURN_LONG(upb_enumdef_numvals(intern->enumdef));
+}
+
+/*
+ * EnumDescriptor::getPublicDescriptor()
+ *
+ * Returns this EnumDescriptor. Unlike the pure-PHP descriptor, we do not
+ * have two separate EnumDescriptor classes. We use a single class for both
+ * the public and private descriptor.
+ */
+PHP_METHOD(EnumDescriptor, getPublicDescriptor) {
+ RETURN_ZVAL(getThis(), 1, 0);
+}
+
+static zend_function_entry EnumDescriptor_methods[] = {
+ PHP_ME(EnumDescriptor, getPublicDescriptor, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(EnumDescriptor, getValueCount, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(EnumDescriptor, getValue, NULL, ZEND_ACC_PUBLIC)
+ ZEND_FE_END
+};
+
+// -----------------------------------------------------------------------------
+// Oneof
+// -----------------------------------------------------------------------------
+
+typedef struct {
+ zend_object std;
+ const upb_oneofdef *oneofdef;
+} OneofDescriptor;
+
+zend_class_entry *OneofDescriptor_class_entry;
+static zend_object_handlers OneofDescriptor_object_handlers;
+
+static void OneofDescriptor_FromOneofDef(zval *val, const upb_oneofdef *o) {
+ if (o == NULL) {
+ ZVAL_NULL(val);
+ return;
+ }
+
+ if (!ObjCache_Get(o, val)) {
+ OneofDescriptor* ret = emalloc(sizeof(OneofDescriptor));
+ zend_object_std_init(&ret->std, OneofDescriptor_class_entry);
+ ret->std.handlers = &OneofDescriptor_object_handlers;
+ ret->oneofdef = o;
+ ObjCache_Add(o, &ret->std);
+
+ // Prevent this from ever being collected (within a request).
+ GC_ADDREF(&ret->std);
+
+ ZVAL_OBJ(val, &ret->std);
+ }
+}
+
+/*
+ * OneofDescriptor::getName()
+ *
+ * Returns the name of this oneof.
+ */
+PHP_METHOD(OneofDescriptor, getName) {
+ OneofDescriptor *intern = (OneofDescriptor*)Z_OBJ_P(getThis());
+ RETURN_STRING(upb_oneofdef_name(intern->oneofdef));
+}
+
+/*
+ * OneofDescriptor::getField()
+ *
+ * Returns a field from this oneof. The given index must be in the range
+ * [0, getFieldCount() - 1].
+ */
+PHP_METHOD(OneofDescriptor, getField) {
+ OneofDescriptor *intern = (OneofDescriptor*)Z_OBJ_P(getThis());
+ zend_long index;
+ zval ret;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) ==
+ FAILURE) {
+ zend_error(E_USER_ERROR, "Expect integer for index.\n");
+ return;
+ }
+
+ int field_num = upb_oneofdef_numfields(intern->oneofdef);
+ if (index < 0 || index >= field_num) {
+ zend_error(E_USER_ERROR, "Cannot get element at %ld.\n", index);
+ return;
+ }
+
+ upb_oneof_iter iter;
+ int i;
+ for(upb_oneof_begin(&iter, intern->oneofdef), i = 0;
+ !upb_oneof_done(&iter) && i < index;
+ upb_oneof_next(&iter), i++);
+ const upb_fielddef *field = upb_oneof_iter_field(&iter);
+
+ FieldDescriptor_FromFieldDef(&ret, field);
+ RETURN_ZVAL(&ret, 1, 0);
+}
+
+/*
+ * OneofDescriptor::getFieldCount()
+ *
+ * Returns the number of fields in this oneof.
+ */
+PHP_METHOD(OneofDescriptor, getFieldCount) {
+ OneofDescriptor *intern = (OneofDescriptor*)Z_OBJ_P(getThis());
+ RETURN_LONG(upb_oneofdef_numfields(intern->oneofdef));
+}
+
+static zend_function_entry OneofDescriptor_methods[] = {
+ PHP_ME(OneofDescriptor, getName, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(OneofDescriptor, getField, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(OneofDescriptor, getFieldCount, NULL, ZEND_ACC_PUBLIC)
+ ZEND_FE_END
+};
+
+// -----------------------------------------------------------------------------
+// FieldDescriptor
+// -----------------------------------------------------------------------------
+
+typedef struct {
+ zend_object std;
+ const upb_fielddef *fielddef;
+} FieldDescriptor;
+
+zend_class_entry *FieldDescriptor_class_entry;
+static zend_object_handlers FieldDescriptor_object_handlers;
+
+static void FieldDescriptor_FromFieldDef(zval *val, const upb_fielddef *f) {
+ if (f == NULL) {
+ ZVAL_NULL(val);
+ return;
+ }
+
+ if (!ObjCache_Get(f, val)) {
+ FieldDescriptor* ret = emalloc(sizeof(FieldDescriptor));
+ zend_object_std_init(&ret->std, FieldDescriptor_class_entry);
+ ret->std.handlers = &FieldDescriptor_object_handlers;
+ ret->fielddef = f;
+ ObjCache_Add(f, &ret->std);
+
+ // Prevent this from ever being collected (within a request).
+ GC_ADDREF(&ret->std);
+
+ ZVAL_OBJ(val, &ret->std);
+ }
+}
+
+upb_fieldtype_t to_fieldtype(upb_descriptortype_t type) {
+ switch (type) {
+#define CASE(descriptor_type, type) \
+ case UPB_DESCRIPTOR_TYPE_##descriptor_type: \
+ return UPB_TYPE_##type;
+
+ CASE(FLOAT, FLOAT);
+ CASE(DOUBLE, DOUBLE);
+ CASE(BOOL, BOOL);
+ CASE(STRING, STRING);
+ CASE(BYTES, BYTES);
+ CASE(MESSAGE, MESSAGE);
+ CASE(GROUP, MESSAGE);
+ CASE(ENUM, ENUM);
+ CASE(INT32, INT32);
+ CASE(INT64, INT64);
+ CASE(UINT32, UINT32);
+ CASE(UINT64, UINT64);
+ CASE(SINT32, INT32);
+ CASE(SINT64, INT64);
+ CASE(FIXED32, UINT32);
+ CASE(FIXED64, UINT64);
+ CASE(SFIXED32, INT32);
+ CASE(SFIXED64, INT64);
+
+#undef CONVERT
+
+ }
+
+ zend_error(E_ERROR, "Unknown field type.");
+ return 0;
+}
+
+/*
+ * FieldDescriptor::getName()
+ *
+ * Returns the name of this field.
+ */
+PHP_METHOD(FieldDescriptor, getName) {
+ FieldDescriptor *intern = (FieldDescriptor*)Z_OBJ_P(getThis());
+ RETURN_STRING(upb_fielddef_name(intern->fielddef));
+}
+
+/*
+ * FieldDescriptor::getNumber()
+ *
+ * Returns the number of this field.
+ */
+PHP_METHOD(FieldDescriptor, getNumber) {
+ FieldDescriptor *intern = (FieldDescriptor*)Z_OBJ_P(getThis());
+ RETURN_LONG(upb_fielddef_number(intern->fielddef));
+}
+
+/*
+ * FieldDescriptor::getLabel()
+ *
+ * Returns the label of this field as an integer.
+ */
+PHP_METHOD(FieldDescriptor, getLabel) {
+ FieldDescriptor *intern = (FieldDescriptor*)Z_OBJ_P(getThis());
+ RETURN_LONG(upb_fielddef_label(intern->fielddef));
+}
+
+/*
+ * FieldDescriptor::getType()
+ *
+ * Returns the type of this field as an integer.
+ */
+PHP_METHOD(FieldDescriptor, getType) {
+ FieldDescriptor *intern = (FieldDescriptor*)Z_OBJ_P(getThis());
+ RETURN_LONG(upb_fielddef_descriptortype(intern->fielddef));
+}
+
+/*
+ * FieldDescriptor::isMap()
+ *
+ * Returns true if this field is a map.
+ */
+PHP_METHOD(FieldDescriptor, isMap) {
+ FieldDescriptor *intern = (FieldDescriptor*)Z_OBJ_P(getThis());
+ RETURN_BOOL(upb_fielddef_ismap(intern->fielddef));
+}
+
+/*
+ * FieldDescriptor::getEnumType()
+ *
+ * Returns the EnumDescriptor for this field, which must be an enum.
+ */
+PHP_METHOD(FieldDescriptor, getEnumType) {
+ FieldDescriptor *intern = (FieldDescriptor*)Z_OBJ_P(getThis());
+ const upb_enumdef *e = upb_fielddef_enumsubdef(intern->fielddef);
+ zval ret;
+
+ if (!e) {
+ zend_throw_exception_ex(NULL, 0,
+ "Cannot get enum type for non-enum field '%s'",
+ upb_fielddef_name(intern->fielddef));
+ return;
+ }
+
+ EnumDescriptor_FromEnumDef(&ret, e);
+ RETURN_ZVAL(&ret, 1, 0);
+}
+
+/*
+ * FieldDescriptor::getMessageType()
+ *
+ * Returns the Descriptor for this field, which must be a message.
+ */
+PHP_METHOD(FieldDescriptor, getMessageType) {
+ FieldDescriptor *intern = (FieldDescriptor*)Z_OBJ_P(getThis());
+ Descriptor* desc = Descriptor_GetFromFieldDef(intern->fielddef);
+ zval ret;
+
+ if (!desc) {
+ zend_throw_exception_ex(
+ NULL, 0, "Cannot get message type for non-message field '%s'",
+ upb_fielddef_name(intern->fielddef));
+ return;
+ }
+
+ ZVAL_OBJ(&ret, &desc->std);
+ RETURN_ZVAL(&ret, 1, 0);
+}
+
+static zend_function_entry FieldDescriptor_methods[] = {
+ PHP_ME(FieldDescriptor, getName, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(FieldDescriptor, getNumber, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(FieldDescriptor, getLabel, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(FieldDescriptor, getType, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(FieldDescriptor, isMap, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(FieldDescriptor, getEnumType, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(FieldDescriptor, getMessageType, NULL, ZEND_ACC_PUBLIC)
+ ZEND_FE_END
+};
+
+// -----------------------------------------------------------------------------
+// Descriptor
+// -----------------------------------------------------------------------------
+
+zend_class_entry *Descriptor_class_entry;
+static zend_object_handlers Descriptor_object_handlers;
+
+static void Descriptor_destructor(zend_object* obj) {
+ // We don't really need to do anything here, we don't allow this to be
+ // collected before the end of the request.
+}
+
+// C Functions from def.h //////////////////////////////////////////////////////
+
+// These are documented in the header file.
+
+void Descriptor_FromClassEntry(zval *val, zend_class_entry *ce) {
+ if (ce == NULL) {
+ ZVAL_NULL(val);
+ return;
+ }
+
+ if (!ObjCache_Get(ce, val)) {
+ const upb_msgdef *msgdef = NameMap_GetMessage(ce);
+ if (!msgdef) {
+ ZVAL_NULL(val);
+ return;
+ }
+ Descriptor* ret = emalloc(sizeof(Descriptor));
+ zend_object_std_init(&ret->std, Descriptor_class_entry);
+ ret->std.handlers = &Descriptor_object_handlers;
+ ret->class_entry = ce;
+ ret->msgdef = msgdef;
+ ObjCache_Add(ce, &ret->std);
+
+ // Prevent this from ever being collected (within a request).
+ GC_ADDREF(&ret->std);
+
+ ZVAL_OBJ(val, &ret->std);
+ }
+}
+
+Descriptor* Descriptor_GetFromClassEntry(zend_class_entry *ce) {
+ zval desc;
+ Descriptor_FromClassEntry(&desc, ce);
+ if (Z_TYPE_P(&desc) == IS_NULL) {
+ return NULL;
+ } else {
+ return (Descriptor*)Z_OBJ_P(&desc);
+ }
+}
+
+Descriptor* Descriptor_GetFromMessageDef(const upb_msgdef *m) {
+ if (m) {
+ if (upb_msgdef_mapentry(m)) {
+ // A bit of a hack, since map entries don't have classes.
+ Descriptor* ret = emalloc(sizeof(Descriptor));
+ zend_object_std_init(&ret->std, Descriptor_class_entry);
+ ret->std.handlers = &Descriptor_object_handlers;
+ ret->class_entry = NULL;
+ ret->msgdef = m;
+
+ // Prevent this from ever being collected (within a request).
+ GC_ADDREF(&ret->std);
+
+ return ret;
+ }
+
+ char *classname =
+ GetPhpClassname(upb_msgdef_file(m), upb_msgdef_fullname(m));
+ zend_string *str = zend_string_init(classname, strlen(classname), 0);
+ zend_class_entry *ce = zend_lookup_class(str); // May autoload the class.
+
+ zend_string_release (str);
+
+ if (!ce) {
+ zend_error(E_ERROR, "Couldn't load generated class %s", classname);
+ }
+
+ free(classname);
+ return Descriptor_GetFromClassEntry(ce);
+ } else {
+ return NULL;
+ }
+}
+
+Descriptor* Descriptor_GetFromFieldDef(const upb_fielddef *f) {
+ return Descriptor_GetFromMessageDef(upb_fielddef_msgsubdef(f));
+}
+
+/*
+ * Descriptor::getPublicDescriptor()
+ *
+ * Returns this EnumDescriptor. Unlike the pure-PHP descriptor, we do not
+ * have two separate EnumDescriptor classes. We use a single class for both
+ * the public and private descriptor.
+ */
+PHP_METHOD(Descriptor, getPublicDescriptor) {
+ RETURN_ZVAL(getThis(), 1, 0);
+}
+
+/*
+ * Descriptor::getFullName()
+ *
+ * Returns the full name for this message type.
+ */
+PHP_METHOD(Descriptor, getFullName) {
+ Descriptor *intern = (Descriptor*)Z_OBJ_P(getThis());
+ RETURN_STRING(upb_msgdef_fullname(intern->msgdef));
+}
+
+/*
+ * Descriptor::getField()
+ *
+ * Returns a FieldDescriptor for the given index, which must be in the range
+ * [0, getFieldCount()-1].
+ */
+PHP_METHOD(Descriptor, getField) {
+ Descriptor *intern = (Descriptor*)Z_OBJ_P(getThis());
+ int count = upb_msgdef_numfields(intern->msgdef);
+ zval ret;
+ zend_long index;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) ==
+ FAILURE) {
+ zend_error(E_USER_ERROR, "Expect integer for index.\n");
+ return;
+ }
+
+ if (index < 0 || index >= count) {
+ zend_error(E_USER_ERROR, "Cannot get element at %ld.\n", index);
+ return;
+ }
+
+ upb_msg_field_iter iter;
+ int i;
+ for(upb_msg_field_begin(&iter, intern->msgdef), i = 0;
+ !upb_msg_field_done(&iter) && i < index;
+ upb_msg_field_next(&iter), i++);
+ const upb_fielddef *field = upb_msg_iter_field(&iter);
+
+ FieldDescriptor_FromFieldDef(&ret, field);
+ RETURN_ZVAL(&ret, 1, 0);
+}
+
+/*
+ * Descriptor::getFieldCount()
+ *
+ * Returns the number of fields in this message.
+ */
+PHP_METHOD(Descriptor, getFieldCount) {
+ Descriptor *intern = (Descriptor*)Z_OBJ_P(getThis());
+ RETURN_LONG(upb_msgdef_numfields(intern->msgdef));
+}
+
+/*
+ * Descriptor::getOneofDecl()
+ *
+ * Returns a OneofDescriptor for the given index, which must be in the range
+ * [0, getOneofDeclCount()].
+ */
+PHP_METHOD(Descriptor, getOneofDecl) {
+ Descriptor *intern = (Descriptor*)Z_OBJ_P(getThis());
+ zend_long index;
+ zval ret;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) ==
+ FAILURE) {
+ zend_error(E_USER_ERROR, "Expect integer for index.\n");
+ return;
+ }
+
+ int field_num = upb_msgdef_numoneofs(intern->msgdef);
+ if (index < 0 || index >= field_num) {
+ zend_error(E_USER_ERROR, "Cannot get element at %ld.\n", index);
+ return;
+ }
+
+ upb_msg_oneof_iter iter;
+ int i;
+ for(upb_msg_oneof_begin(&iter, intern->msgdef), i = 0;
+ !upb_msg_oneof_done(&iter) && i < index;
+ upb_msg_oneof_next(&iter), i++);
+ const upb_oneofdef *oneof = upb_msg_iter_oneof(&iter);
+
+ OneofDescriptor_FromOneofDef(&ret, oneof);
+ RETURN_ZVAL(&ret, 1, 0);
+}
+
+/*
+ * Descriptor::getOneofDeclCount()
+ *
+ * Returns the number of oneofs in this message.
+ */
+PHP_METHOD(Descriptor, getOneofDeclCount) {
+ Descriptor *intern = (Descriptor*)Z_OBJ_P(getThis());
+ RETURN_LONG(upb_msgdef_numoneofs(intern->msgdef));
+}
+
+/*
+ * Descriptor::getClass()
+ *
+ * Returns the name of the PHP class for this message.
+ */
+PHP_METHOD(Descriptor, getClass) {
+ Descriptor *intern = (Descriptor*)Z_OBJ_P(getThis());
+ const char* classname = ZSTR_VAL(intern->class_entry->name);
+ RETURN_STRING(classname);
+}
+
+
+static zend_function_entry Descriptor_methods[] = {
+ PHP_ME(Descriptor, getClass, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Descriptor, getFullName, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Descriptor, getField, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Descriptor, getFieldCount, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Descriptor, getOneofDecl, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Descriptor, getOneofDeclCount, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Descriptor, getPublicDescriptor, NULL, ZEND_ACC_PUBLIC)
+ ZEND_FE_END
+};
+
+// -----------------------------------------------------------------------------
+// DescriptorPool
+// -----------------------------------------------------------------------------
+
+typedef struct DescriptorPool {
+ zend_object std;
+ upb_symtab *symtab;
+} DescriptorPool;
+
+zend_class_entry *DescriptorPool_class_entry;
+static zend_object_handlers DescriptorPool_object_handlers;
+
+static DescriptorPool *GetPool(const zval* this_ptr) {
+ return (DescriptorPool*)Z_OBJ_P(this_ptr);
+}
+
+/**
+ * Object handler to create an DescriptorPool.
+ */
+static zend_object* DescriptorPool_create(zend_class_entry *class_type) {
+ DescriptorPool *intern = emalloc(sizeof(DescriptorPool));
+ zend_object_std_init(&intern->std, class_type);
+ intern->std.handlers = &DescriptorPool_object_handlers;
+ intern->symtab = upb_symtab_new();
+ // Skip object_properties_init(), we don't allow derived classes.
+ return &intern->std;
+}
+
+/**
+ * Object handler to free an DescriptorPool.
+ */
+static void DescriptorPool_destructor(zend_object* obj) {
+ DescriptorPool* intern = (DescriptorPool*)obj;
+ if (intern->symtab) {
+ upb_symtab_free(intern->symtab);
+ }
+ intern->symtab = NULL;
+ zend_object_std_dtor(&intern->std);
+}
+
+void DescriptorPool_CreateWithSymbolTable(zval *zv, upb_symtab *symtab) {
+ ZVAL_OBJ(zv, DescriptorPool_create(DescriptorPool_class_entry));
+
+ if (symtab) {
+ DescriptorPool *intern = GetPool(zv);
+ upb_symtab_free(intern->symtab);
+ intern->symtab = symtab;
+ }
+}
+
+upb_symtab *DescriptorPool_Steal(zval *zv) {
+ DescriptorPool *intern = GetPool(zv);
+ upb_symtab *ret = intern->symtab;
+ intern->symtab = NULL;
+ return ret;
+}
+
+upb_symtab *DescriptorPool_GetSymbolTable() {
+ DescriptorPool *intern = GetPool(get_generated_pool());
+ return intern->symtab;
+}
+
+/*
+ * DescriptorPool::getGeneratedPool()
+ *
+ * Returns the generated DescriptorPool.
+ */
+PHP_METHOD(DescriptorPool, getGeneratedPool) {
+ zval ret;
+ ZVAL_COPY(&ret, get_generated_pool());
+ RETURN_ZVAL(&ret, 0, 1);
+}
+
+/*
+ * DescriptorPool::getDescriptorByClassName()
+ *
+ * Returns a Descriptor object for the given PHP class name.
+ */
+PHP_METHOD(DescriptorPool, getDescriptorByClassName) {
+ char *classname = NULL;
+ zend_long classname_len;
+ zend_class_entry *ce;
+ zend_string *str;
+ zval ret;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &classname,
+ &classname_len) == FAILURE) {
+ return;
+ }
+
+ str = zend_string_init(classname, strlen(classname), 0);
+ ce = zend_lookup_class(str); // May autoload the class.
+ zend_string_release (str);
+
+ if (!ce) {
+ RETURN_NULL();
+ }
+
+ Descriptor_FromClassEntry(&ret, ce);
+ RETURN_ZVAL(&ret, 1, 0);
+}
+
+/*
+ * DescriptorPool::getEnumDescriptorByClassName()
+ *
+ * Returns a EnumDescriptor object for the given PHP class name.
+ */
+PHP_METHOD(DescriptorPool, getEnumDescriptorByClassName) {
+ char *classname = NULL;
+ zend_long classname_len;
+ zend_class_entry *ce;
+ zend_string *str;
+ zval ret;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &classname,
+ &classname_len) == FAILURE) {
+ return;
+ }
+
+ str = zend_string_init(classname, strlen(classname), 0);
+ ce = zend_lookup_class(str); // May autoload the class.
+ zend_string_release (str);
+
+ if (!ce) {
+ RETURN_NULL();
+ }
+
+ EnumDescriptor_FromClassEntry(&ret, ce);
+ RETURN_ZVAL(&ret, 1, 0);
+}
+
+/*
+ * DescriptorPool::getEnumDescriptorByProtoName()
+ *
+ * Returns a Descriptor object for the given protobuf message name.
+ */
+PHP_METHOD(DescriptorPool, getDescriptorByProtoName) {
+ DescriptorPool *intern = GetPool(getThis());
+ char *protoname = NULL;
+ zend_long protoname_len;
+ const upb_msgdef *m;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &protoname,
+ &protoname_len) == FAILURE) {
+ return;
+ }
+
+ if (*protoname == '.') protoname++;
+
+ m = upb_symtab_lookupmsg(intern->symtab, protoname);
+
+ if (m) {
+ zval ret;
+ ZVAL_OBJ(&ret, &Descriptor_GetFromMessageDef(m)->std);
+ RETURN_ZVAL(&ret, 1, 0);
+ } else {
+ RETURN_NULL();
+ }
+}
+
+/*
+ * depends_on_descriptor()
+ *
+ * Returns true if this FileDescriptorProto depends on descriptor.proto.
+ */
+bool depends_on_descriptor(const google_protobuf_FileDescriptorProto* file) {
+ const upb_strview *deps;
+ upb_strview name = upb_strview_makez("google/protobuf/descriptor.proto");
+ size_t i, n;
+
+ deps = google_protobuf_FileDescriptorProto_dependency(file, &n);
+ for (i = 0; i < n; i++) {
+ if (upb_strview_eql(deps[i], name)) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+/*
+ * add_name_mappings()
+ *
+ * Adds the messages and enums in this file to the NameMap.
+ */
+static void add_name_mappings(const upb_filedef *file) {
+ size_t i;
+ for (i = 0; i < upb_filedef_msgcount(file); i++) {
+ NameMap_AddMessage(upb_filedef_msg(file, i));
+ }
+
+ for (i = 0; i < upb_filedef_enumcount(file); i++) {
+ NameMap_AddEnum(upb_filedef_enum(file, i));
+ }
+}
+
+/*
+ * add_name_mappings()
+ *
+ * Adds the given descriptor data to this DescriptorPool.
+ */
+static void add_descriptor(DescriptorPool *pool, const char *data,
+ int data_len, upb_arena *arena) {
+ size_t i, n;
+ google_protobuf_FileDescriptorSet *set;
+ const google_protobuf_FileDescriptorProto* const* files;
+
+ set = google_protobuf_FileDescriptorSet_parse(data, data_len, arena);
+
+ if (!set) {
+ zend_error(E_ERROR, "Failed to parse binary descriptor\n");
+ return;
+ }
+
+ files = google_protobuf_FileDescriptorSet_file(set, &n);
+
+ for (i = 0; i < n; i++) {
+ const google_protobuf_FileDescriptorProto* file = files[i];
+ upb_strview name = google_protobuf_FileDescriptorProto_name(file);
+ upb_status status;
+ const upb_filedef *file_def;
+ upb_status_clear(&status);
+
+ if (upb_symtab_lookupfile2(pool->symtab, name.data, name.size)) {
+ // Already added.
+ continue;
+ }
+
+ // The PHP code generator currently special-cases descriptor.proto. It
+ // doesn't add it as a dependency even if the proto file actually does
+ // depend on it.
+ if (depends_on_descriptor(file)) {
+ google_protobuf_FileDescriptorProto_getmsgdef(pool->symtab);
+ }
+
+ file_def = upb_symtab_addfile(pool->symtab, file, &status);
+ CheckUpbStatus(&status, "Unable to load descriptor");
+ add_name_mappings(file_def);
+ }
+}
+
+/*
+ * DescriptorPool::internalAddGeneratedFile()
+ *
+ * Adds the given descriptor data to this DescriptorPool.
+ */
+PHP_METHOD(DescriptorPool, internalAddGeneratedFile) {
+ DescriptorPool *intern = GetPool(getThis());
+ char *data = NULL;
+ zend_long data_len;
+ zend_bool use_nested_submsg = false;
+ upb_arena *arena;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|b", &data, &data_len,
+ &use_nested_submsg) != SUCCESS) {
+ return;
+ }
+
+ arena = upb_arena_new();
+ add_descriptor(intern, data, data_len, arena);
+ upb_arena_free(arena);
+}
+
+static zend_function_entry DescriptorPool_methods[] = {
+ PHP_ME(DescriptorPool, getGeneratedPool, NULL,
+ ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+ PHP_ME(DescriptorPool, getDescriptorByClassName, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(DescriptorPool, getDescriptorByProtoName, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(DescriptorPool, getEnumDescriptorByClassName, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(DescriptorPool, internalAddGeneratedFile, NULL, ZEND_ACC_PUBLIC)
+ ZEND_FE_END
+};
+
+// -----------------------------------------------------------------------------
+// GPBType
+// -----------------------------------------------------------------------------
+
+zend_class_entry* gpb_type_type;
+
+static zend_function_entry gpb_type_methods[] = {
+ ZEND_FE_END
+};
+
+// -----------------------------------------------------------------------------
+// Module Init
+// -----------------------------------------------------------------------------
+
+void Def_ModuleInit() {
+ zend_class_entry tmp_ce;
+ zend_object_handlers *h;
+
+ INIT_CLASS_ENTRY(tmp_ce, "Google\\Protobuf\\OneofDescriptor",
+ OneofDescriptor_methods);
+ OneofDescriptor_class_entry = zend_register_internal_class(&tmp_ce);
+ OneofDescriptor_class_entry->ce_flags |= ZEND_ACC_FINAL;
+ OneofDescriptor_class_entry->create_object = CreateHandler_ReturnNull;
+ h = &OneofDescriptor_object_handlers;
+ memcpy(h, &std_object_handlers, sizeof(zend_object_handlers));
+
+ INIT_CLASS_ENTRY(tmp_ce, "Google\\Protobuf\\EnumValueDescriptor",
+ EnumValueDescriptor_methods);
+ EnumValueDescriptor_class_entry = zend_register_internal_class(&tmp_ce);
+ EnumValueDescriptor_class_entry->ce_flags |= ZEND_ACC_FINAL;
+ EnumValueDescriptor_class_entry->create_object = CreateHandler_ReturnNull;
+ h = &EnumValueDescriptor_object_handlers;
+ memcpy(h, &std_object_handlers, sizeof(zend_object_handlers));
+
+
+ INIT_CLASS_ENTRY(tmp_ce, "Google\\Protobuf\\EnumDescriptor",
+ EnumDescriptor_methods);
+ EnumDescriptor_class_entry = zend_register_internal_class(&tmp_ce);
+ EnumDescriptor_class_entry->ce_flags |= ZEND_ACC_FINAL;
+ EnumDescriptor_class_entry->create_object = CreateHandler_ReturnNull;
+ h = &EnumDescriptor_object_handlers;
+ memcpy(h, &std_object_handlers, sizeof(zend_object_handlers));
+
+ INIT_CLASS_ENTRY(tmp_ce, "Google\\Protobuf\\Descriptor",
+ Descriptor_methods);
+
+ Descriptor_class_entry = zend_register_internal_class(&tmp_ce);
+ Descriptor_class_entry->ce_flags |= ZEND_ACC_FINAL;
+ Descriptor_class_entry->create_object = CreateHandler_ReturnNull;
+ h = &Descriptor_object_handlers;
+ memcpy(h, &std_object_handlers, sizeof(zend_object_handlers));
+ h->dtor_obj = Descriptor_destructor;
+
+ INIT_CLASS_ENTRY(tmp_ce, "Google\\Protobuf\\FieldDescriptor",
+ FieldDescriptor_methods);
+ FieldDescriptor_class_entry = zend_register_internal_class(&tmp_ce);
+ FieldDescriptor_class_entry->ce_flags |= ZEND_ACC_FINAL;
+ FieldDescriptor_class_entry->create_object = CreateHandler_ReturnNull;
+ h = &FieldDescriptor_object_handlers;
+ memcpy(h, &std_object_handlers, sizeof(zend_object_handlers));
+
+ INIT_CLASS_ENTRY(tmp_ce, "Google\\Protobuf\\Internal\\DescriptorPool",
+ DescriptorPool_methods);
+ DescriptorPool_class_entry = zend_register_internal_class(&tmp_ce);
+ DescriptorPool_class_entry->ce_flags |= ZEND_ACC_FINAL;
+ DescriptorPool_class_entry->create_object = DescriptorPool_create;
+ h = &DescriptorPool_object_handlers;
+ memcpy(h, &std_object_handlers, sizeof(zend_object_handlers));
+ h->dtor_obj = DescriptorPool_destructor;
+
+ // GPBType.
+#define STR(str) (str), strlen(str)
+ zend_class_entry class_type;
+ INIT_CLASS_ENTRY(class_type, "Google\\Protobuf\\Internal\\GPBType",
+ gpb_type_methods);
+ gpb_type_type = zend_register_internal_class(&class_type);
+ zend_declare_class_constant_long(gpb_type_type, STR("DOUBLE"), 1);
+ zend_declare_class_constant_long(gpb_type_type, STR("FLOAT"), 2);
+ zend_declare_class_constant_long(gpb_type_type, STR("INT64"), 3);
+ zend_declare_class_constant_long(gpb_type_type, STR("UINT64"), 4);
+ zend_declare_class_constant_long(gpb_type_type, STR("INT32"), 5);
+ zend_declare_class_constant_long(gpb_type_type, STR("FIXED64"), 6);
+ zend_declare_class_constant_long(gpb_type_type, STR("FIXED32"), 7);
+ zend_declare_class_constant_long(gpb_type_type, STR("BOOL"), 8);
+ zend_declare_class_constant_long(gpb_type_type, STR("STRING"), 9);
+ zend_declare_class_constant_long(gpb_type_type, STR("GROUP"), 10);
+ zend_declare_class_constant_long(gpb_type_type, STR("MESSAGE"), 11);
+ zend_declare_class_constant_long(gpb_type_type, STR("BYTES"), 12);
+ zend_declare_class_constant_long(gpb_type_type, STR("UINT32"), 13);
+ zend_declare_class_constant_long(gpb_type_type, STR("ENUM"), 14);
+ zend_declare_class_constant_long(gpb_type_type, STR("SFIXED32"), 15);
+ zend_declare_class_constant_long(gpb_type_type, STR("SFIXED64"), 16);
+ zend_declare_class_constant_long(gpb_type_type, STR("SINT32"), 17);
+ zend_declare_class_constant_long(gpb_type_type, STR("SINT64"), 18);
+#undef STR
+}
diff --git a/php/ext/google/protobuf2/def.h b/php/ext/google/protobuf2/def.h
new file mode 100644
index 0000000000..515a83eca7
--- /dev/null
+++ b/php/ext/google/protobuf2/def.h
@@ -0,0 +1,69 @@
+// 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.
+
+#ifndef PHP_PROTOBUF_DEF_H_
+#define PHP_PROTOBUF_DEF_H_
+
+#include
+
+#include "php-upb.h"
+
+// Initializes the Def module, which defines all of the descriptor classes.
+void Def_ModuleInit();
+
+// Creates a new DescriptorPool to wrap the given symtab. The DescriptorPool
+// takes ownership of the given symtab. If symtab is NULL, the DescriptorPool
+// will create an empty symtab instead.
+void DescriptorPool_CreateWithSymbolTable(zval *zv, upb_symtab *symtab);
+
+// Given a zval representing a DescriptorPool, steals and returns its symtab,
+// which is now owned by the caller.
+upb_symtab *DescriptorPool_Steal(zval *zv);
+
+upb_symtab *DescriptorPool_GetSymbolTable();
+
+typedef struct Descriptor {
+ zend_object std;
+ const upb_msgdef *msgdef;
+ zend_class_entry *class_entry;
+} Descriptor;
+
+// Gets or creates a PHP Descriptor object for a |ce| and stores it in |val|.
+// If this is not a protobuf generated class, |val| will be set to null.
+void Descriptor_FromClassEntry(zval *val, zend_class_entry *ce);
+
+// Gets or creates a Descriptor* for the given class entry, upb_msgdef, or
+// upb_fielddef. The returned Descriptor* will live for the entire request,
+// so no ref is necessary to keep it alive.
+Descriptor* Descriptor_GetFromClassEntry(zend_class_entry *ce);
+Descriptor* Descriptor_GetFromMessageDef(const upb_msgdef *m);
+Descriptor* Descriptor_GetFromFieldDef(const upb_fielddef *f);
+
+#endif // PHP_PROTOBUF_DEF_H_
diff --git a/php/ext/google/protobuf2/make-preload.php b/php/ext/google/protobuf2/make-preload.php
new file mode 100644
index 0000000000..c6043e2891
--- /dev/null
+++ b/php/ext/google/protobuf2/make-preload.php
@@ -0,0 +1,62 @@
+ Google\\Protobuf\\BoolValue
+ $ret = stripSuffix($filename, ".php");
+ return str_replace("/", "\\\\", $ret);
+}
+
+function toCSymbolName($filename) {
+ # Google/Protobuf/BoolValue.php -> Google__Protobuf__BoolValue
+ $ret = stripSuffix($filename, ".php");
+ return str_replace("/", "__", $ret);
+}
+
+$f = fopen($output, "w");
+
+fwrite($f, "#include \"bundled_php.h\"\n");
+fwrite($f, "#include \"stdlib.h\"\n");
+
+foreach ($filenames as $filename) {
+ print("Reading $filename...\n");
+ $contents = file_get_contents($filename);
+ $contents = substr($contents, 5); // Strip
diff --git a/php/ext/google/protobuf2/map.c b/php/ext/google/protobuf2/map.c
new file mode 100644
index 0000000000..0217c6491e
--- /dev/null
+++ b/php/ext/google/protobuf2/map.c
@@ -0,0 +1,590 @@
+// 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.
+
+#include "map.h"
+
+#include
+#include
+
+#include
+
+#include "arena.h"
+#include "convert.h"
+#include "php-upb.h"
+#include "protobuf.h"
+
+static void MapFieldIter_make(zval *val, zval *map_field);
+
+// -----------------------------------------------------------------------------
+// MapField
+// -----------------------------------------------------------------------------
+
+typedef struct {
+ zend_object std;
+ zval arena;
+ upb_map *map;
+ upb_fieldtype_t key_type;
+ upb_fieldtype_t val_type;
+ const Descriptor* desc; // When values are messages.
+} MapField;
+
+zend_class_entry *MapField_class_entry;
+static zend_object_handlers MapField_object_handlers;
+
+// PHP Object Handlers /////////////////////////////////////////////////////////
+
+/**
+ * MapField_create()
+ *
+ * PHP class entry function to allocate and initialize a new MapField
+ * object.
+ */
+static zend_object* MapField_create(zend_class_entry *class_type) {
+ MapField *intern = emalloc(sizeof(MapField));
+ zend_object_std_init(&intern->std, class_type);
+ intern->std.handlers = &MapField_object_handlers;
+ Arena_Init(&intern->arena);
+ intern->map = NULL;
+ // Skip object_properties_init(), we don't allow derived classes.
+ return &intern->std;
+}
+
+/**
+ * MapField_dtor()
+ *
+ * Object handler to destroy a MapField. This releases all resources
+ * associated with the message. Note that it is possible to access a destroyed
+ * object from PHP in rare cases.
+ */
+static void MapField_destructor(zend_object* obj) {
+ MapField* intern = (MapField*)obj;
+ ObjCache_Delete(intern->map);
+ zval_ptr_dtor(&intern->arena);
+ zend_object_std_dtor(&intern->std);
+}
+
+static zval *Map_GetPropertyPtrPtr(zval *object, zval *member, int type,
+ void **cache_slot) {
+ return NULL; // We don't offer direct references to our properties.
+}
+
+static HashTable *map_get_properties(zval *object TSRMLS_DC) {
+ return NULL; // We do not have a properties table.
+}
+
+// C Functions from map.h //////////////////////////////////////////////////////
+
+// These are documented in the header file.
+
+void MapField_GetPhpWrapper(zval *val, upb_map *map, const upb_fielddef *f,
+ zval *arena) {
+ if (!map) {
+ ZVAL_NULL(val);
+ return;
+ }
+
+ if (!ObjCache_Get(map, val)) {
+ const upb_msgdef *ent = upb_fielddef_msgsubdef(f);
+ const upb_fielddef *key_f = upb_msgdef_itof(ent, 1);
+ const upb_fielddef *val_f = upb_msgdef_itof(ent, 2);
+ MapField *intern = emalloc(sizeof(MapField));
+ zend_object_std_init(&intern->std, MapField_class_entry);
+ intern->std.handlers = &MapField_object_handlers;
+ ZVAL_COPY(&intern->arena, arena);
+ intern->map = map;
+ intern->key_type = upb_fielddef_type(key_f);
+ intern->val_type = upb_fielddef_type(val_f);
+ intern->desc = Descriptor_GetFromFieldDef(val_f);
+ // Skip object_properties_init(), we don't allow derived classes.
+ ObjCache_Add(intern->map, &intern->std);
+ ZVAL_OBJ(val, &intern->std);
+ }
+}
+
+upb_map *MapField_GetUpbMap(zval *val, const upb_fielddef *f, upb_arena *arena) {
+ const upb_msgdef *ent = upb_fielddef_msgsubdef(f);
+ const upb_fielddef *key_f = upb_msgdef_itof(ent, 1);
+ const upb_fielddef *val_f = upb_msgdef_itof(ent, 2);
+ upb_fieldtype_t key_type = upb_fielddef_type(key_f);
+ upb_fieldtype_t val_type = upb_fielddef_type(val_f);
+ const Descriptor *desc = Descriptor_GetFromFieldDef(val_f);
+
+ if (Z_ISREF_P(val)) {
+ ZVAL_DEREF(val);
+ }
+
+ if (Z_TYPE_P(val) == IS_ARRAY) {
+ upb_map *map = upb_map_new(arena, key_type, val_type);
+ HashTable *table = HASH_OF(val);
+ HashPosition pos;
+
+ zend_hash_internal_pointer_reset_ex(table, &pos);
+
+ while (true) {
+ zval php_key;
+ zval *php_val;
+ upb_msgval upb_key;
+ upb_msgval upb_val;
+
+ zend_hash_get_current_key_zval_ex(table, &php_key, &pos);
+ php_val = zend_hash_get_current_data_ex(table, &pos);
+
+ if (!php_val) return map;
+
+ if (!Convert_PhpToUpb(&php_key, &upb_key, key_type, NULL, arena) ||
+ !Convert_PhpToUpbAutoWrap(php_val, &upb_val, val_type, desc, arena)) {
+ return NULL;
+ }
+
+ upb_map_set(map, upb_key, upb_val, arena);
+ zend_hash_move_forward_ex(table, &pos);
+ zval_dtor(&php_key);
+ }
+ } else if (Z_TYPE_P(val) == IS_OBJECT &&
+ Z_OBJCE_P(val) == MapField_class_entry) {
+ MapField *intern = (MapField*)Z_OBJ_P(val);
+
+ if (intern->key_type != key_type || intern->val_type != val_type ||
+ intern->desc != desc) {
+ php_error_docref(NULL, E_USER_ERROR, "Wrong type for this map field.");
+ return NULL;
+ }
+
+ upb_arena_fuse(arena, Arena_Get(&intern->arena));
+ return intern->map;
+ } else {
+ php_error_docref(NULL, E_USER_ERROR, "Must be a map");
+ return NULL;
+ }
+}
+
+// MapField PHP methods ////////////////////////////////////////////////////////
+
+/**
+ * MapField::__construct()
+ *
+ * Constructs an instance of MapField.
+ * @param long Key type.
+ * @param long Value type.
+ * @param string Message/Enum class (message/enum value types only).
+ */
+PHP_METHOD(MapField, __construct) {
+ MapField *intern = (MapField*)Z_OBJ_P(getThis());
+ upb_arena *arena = Arena_Get(&intern->arena);
+ zend_long key_type, val_type;
+ zend_class_entry* klass = NULL;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|C", &key_type, &val_type,
+ &klass) != SUCCESS) {
+ return;
+ }
+
+ intern->key_type = pbphp_dtype_to_type(key_type);
+ intern->val_type = pbphp_dtype_to_type(val_type);
+ intern->desc = Descriptor_GetFromClassEntry(klass);
+
+ // Check that the key type is an allowed type.
+ switch (intern->key_type) {
+ case UPB_TYPE_INT32:
+ case UPB_TYPE_INT64:
+ case UPB_TYPE_UINT32:
+ case UPB_TYPE_UINT64:
+ case UPB_TYPE_BOOL:
+ case UPB_TYPE_STRING:
+ case UPB_TYPE_BYTES:
+ // These are OK.
+ break;
+ default:
+ zend_error(E_USER_ERROR, "Invalid key type for map.");
+ }
+
+ if (intern->val_type == UPB_TYPE_MESSAGE && klass == NULL) {
+ php_error_docref(NULL, E_USER_ERROR,
+ "Message/enum type must have concrete class.");
+ return;
+ }
+
+ intern->map = upb_map_new(arena, intern->key_type, intern->val_type);
+ ObjCache_Add(intern->map, &intern->std);
+}
+
+/**
+ * MapField::offsetExists()
+ *
+ * Implements the ArrayAccess interface. Invoked when PHP code calls:
+ *
+ * isset($map[$idx]);
+ * empty($map[$idx]);
+ *
+ * @param long The index to be checked.
+ * @return bool True if the element at the given index exists.
+ */
+PHP_METHOD(MapField, offsetExists) {
+ MapField *intern = (MapField*)Z_OBJ_P(getThis());
+ zval *key;
+ upb_msgval upb_key;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &key) != SUCCESS ||
+ !Convert_PhpToUpb(key, &upb_key, intern->key_type, intern->desc, NULL)) {
+ return;
+ }
+
+ RETURN_BOOL(upb_map_get(intern->map, upb_key, NULL));
+}
+
+/**
+ * MapField::offsetGet()
+ *
+ * Implements the ArrayAccess interface. Invoked when PHP code calls:
+ *
+ * $x = $map[$idx];
+ *
+ * @param long The index of the element to be fetched.
+ * @return object The stored element at given index.
+ * @exception Invalid type for index.
+ * @exception Non-existing index.
+ */
+PHP_METHOD(MapField, offsetGet) {
+ MapField *intern = (MapField*)Z_OBJ_P(getThis());
+ zval *key;
+ zval ret;
+ upb_msgval upb_key, upb_val;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &key) != SUCCESS ||
+ !Convert_PhpToUpb(key, &upb_key, intern->key_type, intern->desc, NULL)) {
+ return;
+ }
+
+ if (!upb_map_get(intern->map, upb_key, &upb_val)) {
+ zend_error(E_USER_ERROR, "Given key doesn't exist.");
+ return;
+ }
+
+ Convert_UpbToPhp(upb_val, &ret, intern->val_type, intern->desc, &intern->arena);
+ RETURN_ZVAL(&ret, 0, 1);
+}
+
+/**
+ * MapField::offsetSet()
+ *
+ * Implements the ArrayAccess interface. Invoked when PHP code calls:
+ *
+ * $map[$idx] = $x;
+ *
+ * @param long The index of the element to be assigned.
+ * @param object The element to be assigned.
+ * @exception Invalid type for index.
+ * @exception Non-existing index.
+ * @exception Incorrect type of the element.
+ */
+PHP_METHOD(MapField, offsetSet) {
+ MapField *intern = (MapField*)Z_OBJ_P(getThis());
+ upb_arena *arena = Arena_Get(&intern->arena);
+ zval *key, *val;
+ upb_msgval upb_key, upb_val;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz", &key, &val) != SUCCESS ||
+ !Convert_PhpToUpb(key, &upb_key, intern->key_type, NULL, NULL) ||
+ !Convert_PhpToUpb(val, &upb_val, intern->val_type, intern->desc, arena)) {
+ return;
+ }
+
+ upb_map_set(intern->map, upb_key, upb_val, arena);
+}
+
+/**
+ * MapField::offsetUnset()
+ *
+ * Implements the ArrayAccess interface. Invoked when PHP code calls:
+ *
+ * unset($map[$idx]);
+ *
+ * @param long The index of the element to be removed.
+ * @exception Invalid type for index.
+ * @exception The element to be removed is not at the end of the MapField.
+ */
+PHP_METHOD(MapField, offsetUnset) {
+ MapField *intern = (MapField*)Z_OBJ_P(getThis());
+ zval *key;
+ upb_msgval upb_key;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &key) != SUCCESS ||
+ !Convert_PhpToUpb(key, &upb_key, intern->key_type, NULL, NULL)) {
+ return;
+ }
+
+ upb_map_delete(intern->map, upb_key);
+}
+
+/**
+ * MapField::count()
+ *
+ * Implements the Countable interface. Invoked when PHP code calls:
+ *
+ * $len = count($map);
+ * Return the number of stored elements.
+ * This will also be called for: count($map)
+ * @return long The number of stored elements.
+ */
+PHP_METHOD(MapField, count) {
+ MapField *intern = (MapField*)Z_OBJ_P(getThis());
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ RETURN_LONG(upb_map_size(intern->map));
+}
+
+/**
+ * MapField::getIterator()
+ *
+ * Implements the IteratorAggregate interface. Invoked when PHP code calls:
+ *
+ * foreach ($arr) {}
+ *
+ * @return object Beginning iterator.
+ */
+PHP_METHOD(MapField, getIterator) {
+ zval ret;
+ MapFieldIter_make(&ret, getThis());
+ RETURN_ZVAL(&ret, 0, 1);
+}
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetGet, 0, 0, 1)
+ ZEND_ARG_INFO(0, index)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_offsetSet, 0, 0, 2)
+ ZEND_ARG_INFO(0, index)
+ ZEND_ARG_INFO(0, newval)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_void, 0)
+ZEND_END_ARG_INFO()
+
+static zend_function_entry MapField_methods[] = {
+ PHP_ME(MapField, __construct, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(MapField, offsetExists, arginfo_offsetGet, ZEND_ACC_PUBLIC)
+ PHP_ME(MapField, offsetGet, arginfo_offsetGet, ZEND_ACC_PUBLIC)
+ PHP_ME(MapField, offsetSet, arginfo_offsetSet, ZEND_ACC_PUBLIC)
+ PHP_ME(MapField, offsetUnset, arginfo_offsetGet, ZEND_ACC_PUBLIC)
+ PHP_ME(MapField, count, arginfo_void, ZEND_ACC_PUBLIC)
+ PHP_ME(MapField, getIterator, arginfo_void, ZEND_ACC_PUBLIC)
+ ZEND_FE_END
+};
+
+// -----------------------------------------------------------------------------
+// MapFieldIter
+// -----------------------------------------------------------------------------
+
+typedef struct {
+ zend_object std;
+ zval map_field;
+ size_t position;
+} MapFieldIter;
+
+zend_class_entry *MapFieldIter_class_entry;
+static zend_object_handlers MapFieldIter_object_handlers;
+
+/**
+ * MapFieldIter_create()
+ *
+ * PHP class entry function to allocate and initialize a new MapFieldIter
+ * object.
+ */
+zend_object* MapFieldIter_create(zend_class_entry *class_type) {
+ MapFieldIter *intern = emalloc(sizeof(MapFieldIter));
+ zend_object_std_init(&intern->std, class_type);
+ intern->std.handlers = &MapFieldIter_object_handlers;
+ ZVAL_NULL(&intern->map_field);
+ intern->position = 0;
+ // Skip object_properties_init(), we don't allow derived classes.
+ return &intern->std;
+}
+
+/**
+ * MapFieldIter_dtor()
+ *
+ * Object handler to destroy a MapFieldIter. This releases all resources
+ * associated with the message. Note that it is possible to access a destroyed
+ * object from PHP in rare cases.
+ */
+static void map_field_iter_dtor(zend_object* obj) {
+ MapFieldIter* intern = (MapFieldIter*)obj;
+ zval_ptr_dtor(&intern->map_field);
+ zend_object_std_dtor(&intern->std);
+}
+
+/**
+ * MapFieldIter_make()
+ *
+ * Function to create a MapFieldIter directly from C.
+ */
+static void MapFieldIter_make(zval *val, zval *map_field) {
+ MapFieldIter *iter;
+ ZVAL_OBJ(val,
+ MapFieldIter_class_entry->create_object(MapFieldIter_class_entry));
+ iter = (MapFieldIter*)Z_OBJ_P(val);
+ ZVAL_COPY(&iter->map_field, map_field);
+}
+
+// -----------------------------------------------------------------------------
+// PHP MapFieldIter Methods
+// -----------------------------------------------------------------------------
+
+/*
+ * When a user writes:
+ *
+ * foreach($arr as $key => $val) {}
+ *
+ * PHP translates this into:
+ *
+ * $iter = $arr->getIterator();
+ * for ($iter->rewind(); $iter->valid(); $iter->next()) {
+ * $key = $iter->key();
+ * $val = $iter->current();
+ * }
+ */
+
+/**
+ * MapFieldIter::rewind()
+ *
+ * Implements the Iterator interface. Sets the iterator to the first element.
+ */
+PHP_METHOD(MapFieldIter, rewind) {
+ MapFieldIter *intern = (MapFieldIter*)Z_OBJ_P(getThis());
+ MapField *map_field = (MapField*)Z_OBJ_P(&intern->map_field);
+ intern->position = UPB_MAP_BEGIN;
+ upb_mapiter_next(map_field->map, &intern->position);
+}
+
+/**
+ * MapFieldIter::current()
+ *
+ * Implements the Iterator interface. Returns the current value.
+ */
+PHP_METHOD(MapFieldIter, current) {
+ MapFieldIter *intern = (MapFieldIter*)Z_OBJ_P(getThis());
+ MapField *field = (MapField*)Z_OBJ_P(&intern->map_field);
+ upb_msgval upb_val = upb_mapiter_value(field->map, intern->position);
+ zval ret;
+ Convert_UpbToPhp(upb_val, &ret, field->val_type, field->desc, &field->arena);
+ RETURN_ZVAL(&ret, 0, 1);
+}
+
+/**
+ * MapFieldIter::key()
+ *
+ * Implements the Iterator interface. Returns the current key.
+ */
+PHP_METHOD(MapFieldIter, key) {
+ MapFieldIter *intern = (MapFieldIter*)Z_OBJ_P(getThis());
+ MapField *field = (MapField*)Z_OBJ_P(&intern->map_field);
+ upb_msgval upb_key = upb_mapiter_key(field->map, intern->position);
+ zval ret;
+ Convert_UpbToPhp(upb_key, &ret, field->key_type, NULL, NULL);
+ RETURN_ZVAL(&ret, 0, 1);
+}
+
+/**
+ * MapFieldIter::next()
+ *
+ * Implements the Iterator interface. Advances to the next element.
+ */
+PHP_METHOD(MapFieldIter, next) {
+ MapFieldIter *intern = (MapFieldIter*)Z_OBJ_P(getThis());
+ MapField *field = (MapField*)Z_OBJ_P(&intern->map_field);
+ upb_mapiter_next(field->map, &intern->position);
+}
+
+/**
+ * MapFieldIter::valid()
+ *
+ * Implements the Iterator interface. Returns true if this is a valid element.
+ */
+PHP_METHOD(MapFieldIter, valid) {
+ MapFieldIter *intern = (MapFieldIter*)Z_OBJ_P(getThis());
+ MapField *field = (MapField*)Z_OBJ_P(&intern->map_field);
+ bool done = upb_mapiter_done(field->map, intern->position);
+ RETURN_BOOL(!done);
+}
+
+static zend_function_entry map_field_iter_methods[] = {
+ PHP_ME(MapFieldIter, rewind, arginfo_void, ZEND_ACC_PUBLIC)
+ PHP_ME(MapFieldIter, current, arginfo_void, ZEND_ACC_PUBLIC)
+ PHP_ME(MapFieldIter, key, arginfo_void, ZEND_ACC_PUBLIC)
+ PHP_ME(MapFieldIter, next, arginfo_void, ZEND_ACC_PUBLIC)
+ PHP_ME(MapFieldIter, valid, arginfo_void, ZEND_ACC_PUBLIC)
+ ZEND_FE_END
+};
+
+// -----------------------------------------------------------------------------
+// Module init.
+// -----------------------------------------------------------------------------
+
+/**
+ * Map_ModuleInit()
+ *
+ * Called when the C extension is loaded to register all types.
+ */
+
+void Map_ModuleInit() {
+ zend_class_entry tmp_ce;
+ zend_object_handlers *h;
+
+ INIT_CLASS_ENTRY(tmp_ce, "Google\\Protobuf\\Internal\\MapField",
+ MapField_methods);
+
+ MapField_class_entry = zend_register_internal_class(&tmp_ce);
+ zend_class_implements(MapField_class_entry, 3, spl_ce_ArrayAccess,
+ zend_ce_aggregate, spl_ce_Countable);
+ MapField_class_entry->ce_flags |= ZEND_ACC_FINAL;
+ MapField_class_entry->create_object = MapField_create;
+
+ h = &MapField_object_handlers;
+ memcpy(h, &std_object_handlers, sizeof(zend_object_handlers));
+ h->dtor_obj = MapField_destructor;
+ h->get_properties = map_get_properties;
+ h->get_property_ptr_ptr = Map_GetPropertyPtrPtr;
+
+ INIT_CLASS_ENTRY(tmp_ce, "Google\\Protobuf\\Internal\\MapFieldIter",
+ map_field_iter_methods);
+
+ MapFieldIter_class_entry = zend_register_internal_class(&tmp_ce);
+ zend_class_implements(MapFieldIter_class_entry, 1, zend_ce_iterator);
+ MapFieldIter_class_entry->ce_flags |= ZEND_ACC_FINAL;
+ MapFieldIter_class_entry->ce_flags |= ZEND_ACC_FINAL;
+ MapFieldIter_class_entry->create_object = MapFieldIter_create;
+
+ h = &MapFieldIter_object_handlers;
+ memcpy(h, &std_object_handlers, sizeof(zend_object_handlers));
+ h->dtor_obj = map_field_iter_dtor;
+}
diff --git a/php/ext/google/protobuf2/map.h b/php/ext/google/protobuf2/map.h
new file mode 100644
index 0000000000..9b3c9c144c
--- /dev/null
+++ b/php/ext/google/protobuf2/map.h
@@ -0,0 +1,60 @@
+// 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.
+
+#ifndef PHP_PROTOBUF_MAP_H_
+#define PHP_PROTOBUF_MAP_H_
+
+#include
+
+#include "php-upb.h"
+
+void Map_ModuleInit();
+
+// Gets a upb_map* for the PHP object |val|:
+// * If |val| is a RepeatedField object, we first check its type and verify
+// that that the elements have the correct type for |f|. If so, we return the
+// wrapped upb_map*. We also make sure that this map's arena is fused to
+// |arena|, so the returned upb_map is guaranteed to live as long as
+// |arena|.
+// * If |val| is a PHP Map, we attempt to create a new upb_map using
+// |arena| and add all of the PHP elements to it.
+//
+// If an error occurs, we raise a PHP error and return NULL.
+upb_map *MapField_GetUpbMap(zval *val, const upb_fielddef *f, upb_arena *arena);
+
+// Creates a PHP MapField object for the given upb_map* and |f| and returns it
+// in |val|. The PHP object will keep a reference to this |arena| to ensure the
+// underlying array data stays alive.
+//
+// If |map| is NULL, this will return a PHP null object.
+void MapField_GetPhpWrapper(zval *val, upb_map *arr, const upb_fielddef *f,
+ zval *arena);
+
+#endif // PHP_PROTOBUF_MAP_H_
diff --git a/php/ext/google/protobuf2/message.c b/php/ext/google/protobuf2/message.c
new file mode 100644
index 0000000000..20dd37a76e
--- /dev/null
+++ b/php/ext/google/protobuf2/message.c
@@ -0,0 +1,841 @@
+// Protocol Buffers - Google's data interchange format
+// Copyright 2014 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.
+
+#include "message.h"
+
+#include
+#include
+#include
+
+// This is not self-contained: it must be after other Zend includes.
+#include
+
+#include "arena.h"
+#include "array.h"
+#include "convert.h"
+#include "def.h"
+#include "map.h"
+#include "php-upb.h"
+#include "protobuf.h"
+
+// -----------------------------------------------------------------------------
+// Message
+// -----------------------------------------------------------------------------
+
+typedef struct {
+ zend_object std;
+ zval arena;
+ const Descriptor* desc;
+ upb_msg *msg;
+} Message;
+
+zend_class_entry *message_ce;
+static zend_object_handlers message_object_handlers;
+
+// PHP Object Handlers /////////////////////////////////////////////////////////
+
+/**
+ * Message_create()
+ *
+ * PHP class entry function to allocate and initialize a new Message object.
+ */
+static zend_object* Message_create(zend_class_entry *class_type) {
+ Message *intern = emalloc(sizeof(Message));
+ // XXX(haberman): verify whether we actually want to take this route.
+ class_type->default_properties_count = 0;
+ zend_object_std_init(&intern->std, class_type);
+ intern->std.handlers = &message_object_handlers;
+ Arena_Init(&intern->arena);
+ return &intern->std;
+}
+
+/**
+ * Message_dtor()
+ *
+ * Object handler to destroy a Message. This releases all resources associated
+ * with the message. Note that it is possible to access a destroyed object from
+ * PHP in rare cases.
+ */
+static void Message_dtor(zend_object* obj) {
+ Message* intern = (Message*)obj;
+ ObjCache_Delete(intern->msg);
+ zval_dtor(&intern->arena);
+ zend_object_std_dtor(&intern->std);
+}
+
+/**
+ * get_field()
+ *
+ * Helper function to look up a field given a member name (as a string).
+ */
+static const upb_fielddef *get_field(Message *msg, zval *member) {
+ const upb_msgdef *m = msg->desc->msgdef;
+ const upb_fielddef *f =
+ upb_msgdef_ntof(m, Z_STRVAL_P(member), Z_STRLEN_P(member));
+
+ if (!f) {
+ zend_throw_exception_ex(NULL, 0, "No such property %s.",
+ ZSTR_VAL(msg->desc->class_entry->name));
+ }
+
+ return f;
+}
+
+/**
+ * Message_read_property()
+ *
+ * Object handler for reading a property in PHP. Called when PHP code does:
+ *
+ * $x = $message->foobar;
+ *
+ * Note that all properties of generated messages are private, so this should
+ * only be possible to invoke from generated code, which has accessors like:
+ *
+ * public function getOptionalInt32()
+ * {
+ * return $this->optional_int32;
+ * }
+ *
+ * We lookup the field and return the scalar, RepeatedField, or MapField for
+ * this field.
+ */
+static zval *Message_read_property(zval *obj, zval *member, int type,
+ void **cache_slot, zval *rv) {
+ Message* intern = (Message*)Z_OBJ_P(obj);
+ const upb_fielddef *f = get_field(intern, member);
+ upb_arena *arena = Arena_Get(&intern->arena);
+
+ if (!f) return NULL;
+
+ if (upb_fielddef_ismap(f)) {
+ upb_mutmsgval msgval = upb_msg_mutable(intern->msg, f, arena);
+ MapField_GetPhpWrapper(rv, msgval.map, f, &intern->arena);
+ } else if (upb_fielddef_isseq(f)) {
+ upb_mutmsgval msgval = upb_msg_mutable(intern->msg, f, arena);
+ RepeatedField_GetPhpWrapper(rv, msgval.array, f, &intern->arena);
+ } else {
+ upb_msgval msgval = upb_msg_get(intern->msg, f);
+ const Descriptor *subdesc = Descriptor_GetFromFieldDef(f);
+ Convert_UpbToPhp(msgval, rv, upb_fielddef_type(f), subdesc, &intern->arena);
+ }
+
+ return rv;
+}
+
+/**
+ * Message_write_property()
+ *
+ * Object handler for writing a property in PHP. Called when PHP code does:
+ *
+ * $message->foobar = $x;
+ *
+ * Note that all properties of generated messages are private, so this should
+ * only be possible to invoke from generated code, which has accessors like:
+ *
+ * public function setOptionalInt32($var)
+ * {
+ * GPBUtil::checkInt32($var);
+ * $this->optional_int32 = $var;
+ *
+ * return $this;
+ * }
+ *
+ * The C extension version of checkInt32() doesn't actually check anything, so
+ * we perform all checking and conversion in this function.
+ */
+static void Message_write_property(zval *obj, zval *member, zval *val,
+ void **cache_slot) {
+ Message* intern = (Message*)Z_OBJ_P(obj);
+ const upb_fielddef *f = get_field(intern, member);
+ upb_arena *arena = Arena_Get(&intern->arena);
+ upb_msgval msgval;
+
+ if (!f) return;
+
+ if (upb_fielddef_ismap(f)) {
+ msgval.map_val = MapField_GetUpbMap(val, f, arena);
+ if (!msgval.map_val) return;
+ } else if (upb_fielddef_isseq(f)) {
+ msgval.array_val = RepeatedField_GetUpbArray(val, f, arena);
+ if (!msgval.array_val) return;
+ } else {
+ upb_fieldtype_t type = upb_fielddef_type(f);
+ const Descriptor *subdesc = Descriptor_GetFromFieldDef(f);
+ bool ok = Convert_PhpToUpb(val, &msgval, type, subdesc, arena);
+ if (!ok) return;
+ }
+
+ upb_msg_set(intern->msg, f, msgval, arena);
+}
+
+/**
+ * Message_get_property_ptr_ptr()
+ *
+ * Object handler for the get_property_ptr_ptr event in PHP. This returns a
+ * reference to our internal properties. We don't support this, so we return
+ * NULL.
+ */
+static zval *Message_get_property_ptr_ptr(zval *object, zval *member, int type,
+ void **cache_slot) {
+ return NULL; // We do not have a properties table.
+}
+
+/**
+ * Message_get_properties()
+ *
+ * Object handler for the get_properties event in PHP. This returns a HashTable
+ * of our internal properties. We don't support this, so we return NULL.
+ */
+static HashTable* Message_get_properties(zval* object TSRMLS_DC) {
+ return NULL; // We don't offer direct references to our properties.
+}
+
+// C Functions from message.h. /////////////////////////////////////////////////
+
+// These are documented in the header file.
+
+void Message_GetPhpWrapper(zval *val, const Descriptor *desc, upb_msg *msg,
+ zval *arena) {
+ if (!msg) {
+ ZVAL_NULL(val);
+ return;
+ }
+
+ if (!ObjCache_Get(msg, val)) {
+ Message *intern = emalloc(sizeof(Message));
+ // XXX(haberman): verify whether we actually want to take this route.
+ desc->class_entry->default_properties_count = 0;
+ zend_object_std_init(&intern->std, desc->class_entry);
+ intern->std.handlers = &message_object_handlers;
+ ZVAL_COPY(&intern->arena, arena);
+ intern->desc = desc;
+ intern->msg = msg;
+ ZVAL_OBJ(val, &intern->std);
+ ObjCache_Add(intern->msg, &intern->std);
+ }
+}
+
+bool Message_GetUpbMessage(zval *val, const Descriptor *desc, upb_arena *arena,
+ upb_msg **msg) {
+ PBPHP_ASSERT(desc);
+
+ if (Z_ISREF_P(val)) {
+ ZVAL_DEREF(val);
+ }
+
+ if (Z_TYPE_P(val) == IS_NULL) {
+ *msg = NULL;
+ return true;
+ }
+
+ if (Z_TYPE_P(val) == IS_OBJECT &&
+ instanceof_function(Z_OBJCE_P(val), desc->class_entry)) {
+ Message *intern = (Message*)Z_OBJ_P(val);
+ upb_arena_fuse(arena, Arena_Get(&intern->arena));
+ *msg = intern->msg;
+ return true;
+ } else {
+ zend_throw_exception_ex(NULL, 0, "Given value is not an instance of %s.",
+ ZSTR_VAL(desc->class_entry->name));
+ return false;
+ }
+}
+
+// Message PHP methods /////////////////////////////////////////////////////////
+
+/**
+ * Message_InitFromPhp()
+ *
+ * Helper method to handle the initialization of a message from a PHP value, eg.
+ *
+ * $m = new TestMessage([
+ * 'optional_int32' => -42,
+ * 'optional_bool' => true,
+ * 'optional_string' => 'a',
+ * 'optional_enum' => TestEnum::ONE,
+ * 'optional_message' => new Sub([
+ * 'a' => 33
+ * ]),
+ * 'repeated_int32' => [-42, -52],
+ * 'repeated_enum' => [TestEnum::ZERO, TestEnum::ONE],
+ * 'repeated_message' => [new Sub(['a' => 34]),
+ * new Sub(['a' => 35])],
+ * 'map_int32_int32' => [-62 => -62],
+ * 'map_int32_enum' => [1 => TestEnum::ONE],
+ * 'map_int32_message' => [1 => new Sub(['a' => 36])],
+ * ]);
+ *
+ * The initializer must be an array.
+ */
+bool Message_InitFromPhp(upb_msg *msg, const upb_msgdef *m, zval *init,
+ upb_arena *arena) {
+ HashTable* table = HASH_OF(init);
+ HashPosition pos;
+
+ if (Z_ISREF_P(init)) {
+ ZVAL_DEREF(init);
+ }
+
+ if (Z_TYPE_P(init) != IS_ARRAY) {
+ zend_throw_exception_ex(NULL, 0,
+ "Initializer for a message %s must be an array.",
+ upb_msgdef_fullname(m));
+ return false;
+ }
+
+ zend_hash_internal_pointer_reset_ex(table, &pos);
+
+ while (true) { // Iterate over key/value pairs.
+ zval key;
+ zval *val;
+ const upb_fielddef *f;
+ upb_msgval msgval;
+
+ zend_hash_get_current_key_zval_ex(table, &key, &pos);
+ val = zend_hash_get_current_data_ex(table, &pos);
+
+ if (!val) return true; // Finished iteration.
+
+ if (Z_ISREF_P(val)) {
+ ZVAL_DEREF(val);
+ }
+
+ f = upb_msgdef_ntof(m, Z_STRVAL_P(&key), Z_STRLEN_P(&key));
+
+ if (!f) {
+ zend_throw_exception_ex(NULL, 0,
+ "No such field %s", Z_STRVAL_P(&key));
+ return false;
+ }
+
+ if (upb_fielddef_ismap(f)) {
+ msgval.map_val = MapField_GetUpbMap(val, f, arena);
+ if (!msgval.map_val) return false;
+ } else if (upb_fielddef_isseq(f)) {
+ msgval.array_val = RepeatedField_GetUpbArray(val, f, arena);
+ if (!msgval.array_val) return false;
+ } else {
+ const Descriptor *desc = Descriptor_GetFromFieldDef(f);
+ upb_fieldtype_t type = upb_fielddef_type(f);
+ if (!Convert_PhpToUpbAutoWrap(val, &msgval, type, desc, arena)) {
+ return false;
+ }
+ }
+
+ upb_msg_set(msg, f, msgval, arena);
+ zend_hash_move_forward_ex(table, &pos);
+ zval_dtor(&key);
+ }
+}
+
+/**
+ * Message::__construct()
+ *
+ * Constructor for Message.
+ * @param array Map of initial values ['k' = val]
+ */
+PHP_METHOD(Message, __construct) {
+ Message* intern = (Message*)Z_OBJ_P(getThis());
+ const Descriptor* desc = Descriptor_GetFromClassEntry(Z_OBJCE_P(getThis()));
+ const upb_msgdef *msgdef = desc->msgdef;
+ upb_arena *arena = Arena_Get(&intern->arena);
+ zval *init_arr = NULL;
+
+ intern->desc = desc;
+ intern->msg = upb_msg_new(msgdef, arena);
+ ObjCache_Add(intern->msg, &intern->std);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "|a!", &init_arr) == FAILURE) {
+ return;
+ }
+
+ if (init_arr) {
+ Message_InitFromPhp(intern->msg, desc->msgdef, init_arr, arena);
+ }
+}
+
+/**
+ * Message::discardUnknownFields()
+ *
+ * Discards any unknown fields for this message or any submessages.
+ */
+PHP_METHOD(Message, discardUnknownFields) {
+ Message* intern = (Message*)Z_OBJ_P(getThis());
+ upb_msg_discardunknown(intern->msg, intern->desc->msgdef, 64);
+}
+
+/**
+ * Message::clear()
+ *
+ * Clears all fields of this message.
+ */
+PHP_METHOD(Message, clear) {
+ Message* intern = (Message*)Z_OBJ_P(getThis());
+ upb_msg_clear(intern->msg, intern->desc->msgdef);
+}
+
+/**
+ * Message::mergeFrom()
+ *
+ * Merges from the given message, which must be of the same class as us.
+ * @param object Message to merge from.
+ */
+PHP_METHOD(Message, mergeFrom) {
+ Message* intern = (Message*)Z_OBJ_P(getThis());
+ Message* from;
+ upb_arena *arena = Arena_Get(&intern->arena);
+ const upb_msglayout *l = upb_msgdef_layout(intern->desc->msgdef);
+ zval* value;
+ char *pb;
+ size_t size;
+ bool ok;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &value,
+ intern->desc->class_entry) == FAILURE) {
+ return;
+ }
+
+ from = (Message*)Z_OBJ_P(value);
+
+ // Should be guaranteed since we passed the class type to
+ // zend_parse_parameters().
+ PBPHP_ASSERT(from->desc == intern->desc);
+
+ // TODO(haberman): use a temp arena for this once we can make upb_decode()
+ // copy strings.
+ pb = upb_encode(from->msg, l, arena, &size);
+
+ if (!pb) {
+ zend_throw_exception_ex(NULL, 0, "Max nesting exceeded");
+ return;
+ }
+
+ ok = upb_decode(pb, size, intern->msg, l, arena);
+ PBPHP_ASSERT(ok);
+}
+
+/**
+ * Message::mergeFromString()
+ *
+ * Merges from the given string.
+ * @param string Binary protobuf data to merge.
+ */
+PHP_METHOD(Message, mergeFromString) {
+ Message* intern = (Message*)Z_OBJ_P(getThis());
+ char *data = NULL;
+ char *data_copy = NULL;
+ zend_long data_len;
+ const upb_msglayout *l = upb_msgdef_layout(intern->desc->msgdef);
+ upb_arena *arena = Arena_Get(&intern->arena);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &data, &data_len) ==
+ FAILURE) {
+ return;
+ }
+
+ // TODO(haberman): avoid this copy when we can make the decoder copy.
+ data_copy = upb_arena_malloc(arena, data_len);
+ memcpy(data_copy, data, data_len);
+
+ if (!upb_decode(data_copy, data_len, intern->msg, l, arena)) {
+ zend_throw_exception_ex(NULL, 0, "Error occurred during parsing");
+ return;
+ }
+}
+
+/**
+ * Message::serializeToString()
+ *
+ * Serializes this message instance to protobuf data.
+ * @return string Serialized protobuf data.
+ */
+PHP_METHOD(Message, serializeToString) {
+ Message* intern = (Message*)Z_OBJ_P(getThis());
+ const upb_msglayout *l = upb_msgdef_layout(intern->desc->msgdef);
+ upb_arena *tmp_arena = upb_arena_new();
+ char *data;
+ size_t size;
+
+ data = upb_encode(intern->msg, l, tmp_arena, &size);
+
+ if (!data) {
+ zend_throw_exception_ex(NULL, 0, "Error occurred during serialization");
+ upb_arena_free(tmp_arena);
+ return;
+ }
+
+ RETVAL_STRINGL(data, size);
+ upb_arena_free(tmp_arena);
+}
+
+/**
+ * Message::mergeFromJsonString()
+ *
+ * Merges the JSON data parsed from the given string.
+ * @param string Serialized JSON data.
+ */
+PHP_METHOD(Message, mergeFromJsonString) {
+ Message* intern = (Message*)Z_OBJ_P(getThis());
+ char *data = NULL;
+ char *data_copy = NULL;
+ zend_long data_len;
+ upb_arena *arena = Arena_Get(&intern->arena);
+ upb_status status;
+ zend_bool ignore_json_unknown = false;
+ int options = 0;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|b", &data, &data_len,
+ &ignore_json_unknown) == FAILURE) {
+ return;
+ }
+
+ // TODO(haberman): avoid this copy when we can make the decoder copy.
+ data_copy = upb_arena_malloc(arena, data_len + 1);
+ memcpy(data_copy, data, data_len);
+ data_copy[data_len] = '\0';
+
+ if (ignore_json_unknown) {
+ options |= UPB_JSONDEC_IGNOREUNKNOWN;
+ }
+
+ upb_status_clear(&status);
+ if (!upb_json_decode(data_copy, data_len, intern->msg, intern->desc->msgdef,
+ DescriptorPool_GetSymbolTable(), options, arena,
+ &status)) {
+ zend_throw_exception_ex(NULL, 0, "Error occurred during parsing: %s",
+ upb_status_errmsg(&status));
+ return;
+ }
+}
+
+/**
+ * Message::serializeToJsonString()
+ *
+ * Serializes this object to JSON.
+ * @return string Serialized JSON data.
+ */
+PHP_METHOD(Message, serializeToJsonString) {
+ Message* intern = (Message*)Z_OBJ_P(getThis());
+ size_t size;
+ int options = 0;
+ char buf[1024];
+ zend_bool preserve_proto_fieldnames = false;
+ upb_status status;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b",
+ &preserve_proto_fieldnames) == FAILURE) {
+ return;
+ }
+
+ if (preserve_proto_fieldnames) {
+ options |= UPB_JSONENC_PROTONAMES;
+ }
+
+ upb_status_clear(&status);
+ size = upb_json_encode(intern->msg, intern->desc->msgdef,
+ DescriptorPool_GetSymbolTable(), options, buf,
+ sizeof(buf), &status);
+
+ if (!upb_ok(&status)) {
+ zend_throw_exception_ex(NULL, 0,
+ "Error occurred during JSON serialization: %s",
+ upb_status_errmsg(&status));
+ return;
+ }
+
+ if (size >= sizeof(buf)) {
+ char *buf2 = malloc(size + 1);
+ upb_json_encode(intern->msg, intern->desc->msgdef,
+ DescriptorPool_GetSymbolTable(), options, buf2, size + 1,
+ &status);
+ RETVAL_STRINGL(buf2, size);
+ free(buf2);
+ } else {
+ RETVAL_STRINGL(buf, size);
+ }
+}
+
+/**
+ * Message::readWrapperValue()
+ *
+ * Returns an unboxed value for the given field. This is called from generated
+ * methods for wrapper fields, eg.
+ *
+ * public function getDoubleValueUnwrapped()
+ * {
+ * return $this->readWrapperValue("double_value");
+ * }
+ *
+ * @return Unwrapped field value or null.
+ */
+PHP_METHOD(Message, readWrapperValue) {
+ Message* intern = (Message*)Z_OBJ_P(getThis());
+ char* member;
+ const upb_fielddef *f;
+ zend_long size;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &member, &size) == FAILURE) {
+ return;
+ }
+
+ f = upb_msgdef_ntof(intern->desc->msgdef, member, size);
+
+ if (!f || !upb_msgdef_iswrapper(upb_fielddef_msgsubdef(f))) {
+ zend_throw_exception_ex(NULL, 0, "Message %s has no field %s",
+ upb_msgdef_fullname(intern->desc->msgdef), member);
+ return;
+ }
+
+ if (upb_msg_has(intern->msg, f)) {
+ const upb_msg *wrapper = upb_msg_get(intern->msg, f).msg_val;
+ const upb_msgdef *m = upb_fielddef_msgsubdef(f);
+ const upb_fielddef *val_f = upb_msgdef_itof(m, 1);
+ const upb_fieldtype_t val_type = upb_fielddef_type(val_f);
+ upb_msgval msgval = upb_msg_get(wrapper, val_f);
+ zval ret;
+ Convert_UpbToPhp(msgval, &ret, val_type, NULL, &intern->arena);
+ RETURN_ZVAL(&ret, 1, 0);
+ } else {
+ RETURN_NULL();
+ }
+}
+
+/**
+ * Message::writeWrapperValue()
+ *
+ * Sets the given wrapper field to the given unboxed value. This is called from
+ * generated methods for wrapper fields, eg.
+ *
+ *
+ * public function setDoubleValueUnwrapped($var)
+ * {
+ * $this->writeWrapperValue("double_value", $var);
+ * return $this;
+ * }
+ *
+ * @param Unwrapped field value or null.
+ */
+PHP_METHOD(Message, writeWrapperValue) {
+ Message* intern = (Message*)Z_OBJ_P(getThis());
+ upb_arena *arena = Arena_Get(&intern->arena);
+ char* member;
+ const upb_fielddef *f;
+ upb_msgval msgval;
+ zend_long size;
+ zval* val;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "sz", &member, &size, &val) ==
+ FAILURE) {
+ return;
+ }
+
+ f = upb_msgdef_ntof(intern->desc->msgdef, member, size);
+
+ if (!f || !upb_msgdef_iswrapper(upb_fielddef_msgsubdef(f))) {
+ zend_throw_exception_ex(NULL, 0, "Message %s has no field %s",
+ upb_msgdef_fullname(intern->desc->msgdef), member);
+ return;
+ }
+
+ if (Z_ISREF_P(val)) {
+ ZVAL_DEREF(val);
+ }
+
+ if (Z_TYPE_P(val) == IS_NULL) {
+ upb_msg_clearfield(intern->msg, f);
+ } else {
+ const upb_msgdef *m = upb_fielddef_msgsubdef(f);
+ const upb_fielddef *val_f = upb_msgdef_itof(m, 1);
+ upb_fieldtype_t val_type = upb_fielddef_type(val_f);
+ upb_msg *wrapper;
+
+ if (!Convert_PhpToUpb(val, &msgval, val_type, NULL, arena)) {
+ return; // Error is already set.
+ }
+
+ wrapper = upb_msg_mutable(intern->msg, f, arena).msg;
+ upb_msg_set(wrapper, val_f, msgval, arena);
+ }
+}
+
+/**
+ * Message::whichOneof()
+ *
+ * Given a oneof name, returns the name of the field that is set for this oneof,
+ * or otherwise the empty string.
+ *
+ * @return string The field name in this oneof that is currently set.
+ */
+PHP_METHOD(Message, whichOneof) {
+ Message* intern = (Message*)Z_OBJ_P(getThis());
+ const upb_oneofdef* oneof;
+ const upb_fielddef* field;
+ char* name;
+ zend_long len;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &len) == FAILURE) {
+ return;
+ }
+
+ oneof = upb_msgdef_ntoo(intern->desc->msgdef, name, len);
+
+ if (!oneof) {
+ zend_throw_exception_ex(NULL, 0, "Message %s has no oneof %s",
+ upb_msgdef_fullname(intern->desc->msgdef), name);
+ return;
+ }
+
+ field = upb_msg_whichoneof(intern->msg, oneof);
+ RETURN_STRING(field ? upb_fielddef_name(field) : "");
+}
+
+/**
+ * Message::readOneof()
+ *
+ * Returns the contents of the given oneof field, given a field number. Called
+ * from generated code methods such as:
+ *
+ * public function getDoubleValueOneof()
+ * {
+ * return $this->readOneof(10);
+ * }
+ *
+ * @return object The oneof's field value.
+ */
+PHP_METHOD(Message, readOneof) {
+ Message* intern = (Message*)Z_OBJ_P(getThis());
+ zend_long field_num;
+ const upb_fielddef* f;
+ zval ret;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &field_num) == FAILURE) {
+ return;
+ }
+
+ f = upb_msgdef_itof(intern->desc->msgdef, field_num);
+
+ if (!f || !upb_fielddef_realcontainingoneof(f)) {
+ php_error_docref(NULL, E_USER_ERROR,
+ "Internal error, no such oneof field %d\n",
+ (int)field_num);
+ }
+
+ {
+ upb_msgval msgval = upb_msg_get(intern->msg, f);
+ const Descriptor *subdesc = Descriptor_GetFromFieldDef(f);
+ Convert_UpbToPhp(msgval, &ret, upb_fielddef_type(f), subdesc,
+ &intern->arena);
+ }
+
+ RETURN_ZVAL(&ret, 1, 0);
+}
+
+/**
+ * Message::writeOneof()
+ *
+ * Sets the contents of the given oneof field, given a field number. Called
+ * from generated code methods such as:
+ *
+ * public function setDoubleValueOneof($var)
+ * {
+ * GPBUtil::checkMessage($var, \Google\Protobuf\DoubleValue::class);
+ * $this->writeOneof(10, $var);
+ *
+ * return $this;
+ * }
+ *
+ * The C extension version of GPBUtil::check*() does nothing, so we perform
+ * all type checking and conversion here.
+ *
+ * @param integer The field number we are setting.
+ * @param object The field value we want to set.
+ */
+PHP_METHOD(Message, writeOneof) {
+ Message* intern = (Message*)Z_OBJ_P(getThis());
+ zend_long field_num;
+ const upb_fielddef* f;
+ upb_arena *arena = Arena_Get(&intern->arena);
+ upb_msgval msgval;
+ zval* val;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "lz", &field_num, &val) ==
+ FAILURE) {
+ return;
+ }
+
+ f = upb_msgdef_itof(intern->desc->msgdef, field_num);
+
+ if (!Convert_PhpToUpb(val, &msgval, upb_fielddef_type(f),
+ Descriptor_GetFromFieldDef(f), arena)) {
+ return;
+ }
+
+ upb_msg_set(intern->msg, f, msgval, arena);
+}
+
+static zend_function_entry Message_methods[] = {
+ PHP_ME(Message, clear, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Message, discardUnknownFields, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Message, serializeToString, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Message, mergeFromString, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Message, serializeToJsonString, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Message, mergeFromJsonString, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Message, mergeFrom, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(Message, readWrapperValue, NULL, ZEND_ACC_PROTECTED)
+ PHP_ME(Message, writeWrapperValue, NULL, ZEND_ACC_PROTECTED)
+ PHP_ME(Message, readOneof, NULL, ZEND_ACC_PROTECTED)
+ PHP_ME(Message, writeOneof, NULL, ZEND_ACC_PROTECTED)
+ PHP_ME(Message, whichOneof, NULL, ZEND_ACC_PROTECTED)
+ PHP_ME(Message, __construct, NULL, ZEND_ACC_PROTECTED)
+ ZEND_FE_END
+};
+
+/**
+ * Message_ModuleInit()
+ *
+ * Called when the C extension is loaded to register all types.
+ */
+void Message_ModuleInit() {
+ zend_class_entry tmp_ce;
+ zend_object_handlers *h = &message_object_handlers;
+
+ INIT_CLASS_ENTRY(tmp_ce, "Google\\Protobuf\\Internal\\Message",
+ Message_methods);
+
+ message_ce = zend_register_internal_class(&tmp_ce);
+ message_ce->create_object = Message_create;
+
+ memcpy(h, &std_object_handlers, sizeof(zend_object_handlers));
+ h->dtor_obj = Message_dtor;
+ h->read_property = Message_read_property;
+ h->write_property = Message_write_property;
+ h->get_properties = Message_get_properties;
+ h->get_property_ptr_ptr = Message_get_property_ptr_ptr;
+}
diff --git a/php/ext/google/protobuf2/message.h b/php/ext/google/protobuf2/message.h
new file mode 100644
index 0000000000..5083976016
--- /dev/null
+++ b/php/ext/google/protobuf2/message.h
@@ -0,0 +1,59 @@
+// 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.
+
+#ifndef PHP_PROTOBUF_MESSAGE_H_
+#define PHP_PROTOBUF_MESSAGE_H_
+
+#include
+
+#include "def.h"
+
+// Registers the PHP Message class.
+void Message_ModuleInit();
+
+// Gets a upb_msg* for the PHP object |val|, which must either be a Message
+// object or 'null'. Returns true and stores the message in |msg| if the
+// conversion succeeded (we can't return upb_msg* because null->NULL is a valid
+// conversion). Returns false and raises a PHP error if this isn't a Message
+// object or null, or if the Message object doesn't match this Descriptor.
+//
+// The given |arena| will be fused to this message's arena.
+bool Message_GetUpbMessage(zval *val, const Descriptor *desc, upb_arena *arena,
+ upb_msg **msg);
+
+// Gets or creates a PHP Message object to wrap the given upb_msg* and |desc|
+// and returns it in |val|. The PHP object will keep a reference to this |arena|
+// to ensure the underlying message data stays alive.
+//
+// If |msg| is NULL, this will return a PHP null.
+void Message_GetPhpWrapper(zval *val, const Descriptor *desc, upb_msg *msg,
+ zval *arena);
+
+#endif // PHP_PROTOBUF_MESSAGE_H_
diff --git a/php/ext/google/protobuf2/names.c b/php/ext/google/protobuf2/names.c
new file mode 100644
index 0000000000..ff04b3cbc3
--- /dev/null
+++ b/php/ext/google/protobuf2/names.c
@@ -0,0 +1,226 @@
+// 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.
+
+#include "names.h"
+
+#include
+
+#include "protobuf.h"
+
+/* stringsink *****************************************************************/
+
+typedef struct {
+ char *ptr;
+ size_t len, size;
+} stringsink;
+
+static size_t stringsink_string(stringsink *sink, const char *ptr, size_t len) {
+ size_t new_size = sink->size;
+
+ while (sink->len + len > new_size) {
+ new_size *= 2;
+ }
+
+ if (new_size != sink->size) {
+ sink->ptr = realloc(sink->ptr, new_size);
+ sink->size = new_size;
+ }
+
+ memcpy(sink->ptr + sink->len, ptr, len);
+ sink->len += len;
+
+ return len;
+}
+
+static void stringsink_init(stringsink *sink) {
+ sink->size = 32;
+ sink->ptr = malloc(sink->size);
+ PBPHP_ASSERT(sink->ptr != NULL);
+ sink->len = 0;
+}
+
+static void stringsink_uninit(stringsink *sink) { free(sink->ptr); }
+
+/* def name -> classname ******************************************************/
+
+const char *const kReservedNames[] = {
+ "abstract", "and", "array", "as", "break",
+ "callable", "case", "catch", "class", "clone",
+ "const", "continue", "declare", "default", "die",
+ "do", "echo", "else", "elseif", "empty",
+ "enddeclare", "endfor", "endforeach", "endif", "endswitch",
+ "endwhile", "eval", "exit", "extends", "final",
+ "for", "foreach", "function", "global", "goto",
+ "if", "implements", "include", "include_once", "instanceof",
+ "insteadof", "interface", "isset", "list", "namespace",
+ "new", "or", "print", "private", "protected",
+ "public", "require", "require_once", "return", "static",
+ "switch", "throw", "trait", "try", "unset",
+ "use", "var", "while", "xor", "int",
+ "float", "bool", "string", "true", "false",
+ "null", "void", "iterable", NULL};
+
+bool is_reserved_name(const char* name) {
+ int i;
+ for (i = 0; kReservedNames[i]; i++) {
+ if (strcmp(kReservedNames[i], name) == 0) {
+ return true;
+ }
+ }
+ return false;
+}
+
+static char nolocale_tolower(char ch) {
+ if (ch >= 'A' && ch <= 'Z') {
+ return ch - ('A' - 'a');
+ } else {
+ return ch;
+ }
+}
+
+static char nolocale_toupper(char ch) {
+ if (ch >= 'a' && ch <= 'z') {
+ return ch - ('a' - 'A');
+ } else {
+ return ch;
+ }
+}
+
+static bool is_reserved(const char *segment, int length) {
+ bool result;
+ char* lower = calloc(1, length + 1);
+ memcpy(lower, segment, length);
+ int i = 0;
+ while(lower[i]) {
+ lower[i] = nolocale_tolower(lower[i]);
+ i++;
+ }
+ lower[length] = 0;
+ result = is_reserved_name(lower);
+ free(lower);
+ return result;
+}
+
+static void fill_prefix(const char *segment, int length,
+ const char *prefix_given,
+ const char *package_name,
+ stringsink *classname) {
+ if (prefix_given != NULL && strcmp(prefix_given, "") != 0) {
+ stringsink_string(classname, prefix_given, strlen(prefix_given));
+ } else {
+ if (is_reserved(segment, length)) {
+ if (package_name != NULL &&
+ strcmp("google.protobuf", package_name) == 0) {
+ stringsink_string(classname, "GPB", 3);
+ } else {
+ stringsink_string(classname, "PB", 2);
+ }
+ }
+ }
+}
+
+static void fill_segment(const char *segment, int length,
+ stringsink *classname, bool use_camel) {
+ if (use_camel && (segment[0] < 'A' || segment[0] > 'Z')) {
+ char first = nolocale_toupper(segment[0]);
+ stringsink_string(classname, &first, 1);
+ stringsink_string(classname, segment + 1, length - 1);
+ } else {
+ stringsink_string(classname, segment, length);
+ }
+}
+
+static void fill_namespace(const char *package, const char *php_namespace,
+ stringsink *classname) {
+ if (php_namespace != NULL) {
+ if (strlen(php_namespace) != 0) {
+ stringsink_string(classname, php_namespace, strlen(php_namespace));
+ stringsink_string(classname, "\\", 1);
+ }
+ } else if (package != NULL) {
+ int i = 0, j = 0;
+ size_t package_len = strlen(package);
+ while (i < package_len) {
+ j = i;
+ while (j < package_len && package[j] != '.') {
+ j++;
+ }
+ fill_prefix(package + i, j - i, "", package, classname);
+ fill_segment(package + i, j - i, classname, true);
+ stringsink_string(classname, "\\", 1);
+ i = j + 1;
+ }
+ }
+}
+
+static void fill_classname(const char *fullname,
+ const char *package,
+ const char *prefix,
+ stringsink *classname) {
+ int classname_start = 0;
+ if (package != NULL) {
+ size_t package_len = strlen(package);
+ classname_start = package_len == 0 ? 0 : package_len + 1;
+ }
+ size_t fullname_len = strlen(fullname);
+
+ int i = classname_start, j;
+ while (i < fullname_len) {
+ j = i;
+ while (j < fullname_len && fullname[j] != '.') {
+ j++;
+ }
+ fill_prefix(fullname + i, j - i, prefix, package, classname);
+ fill_segment(fullname + i, j - i, classname, false);
+ if (j != fullname_len) {
+ stringsink_string(classname, "\\", 1);
+ }
+ i = j + 1;
+ }
+}
+
+char *GetPhpClassname(const upb_filedef *file, const char *fullname) {
+ // Prepend '.' to package name to make it absolute. In the 5 additional
+ // bytes allocated, one for '.', one for trailing 0, and 3 for 'GPB' if
+ // given message is google.protobuf.Empty.
+ const char *package = upb_filedef_package(file);
+ const char *php_namespace = upb_filedef_phpnamespace(file);
+ const char *prefix = upb_filedef_phpprefix(file);
+ char *ret;
+ stringsink namesink;
+ stringsink_init(&namesink);
+
+ fill_namespace(package, php_namespace, &namesink);
+ fill_classname(fullname, package, prefix, &namesink);
+ stringsink_string(&namesink, "\0", 1);
+ ret = strdup(namesink.ptr);
+ stringsink_uninit(&namesink);
+ return ret;
+}
diff --git a/php/ext/google/protobuf2/names.h b/php/ext/google/protobuf2/names.h
new file mode 100644
index 0000000000..75101c5a78
--- /dev/null
+++ b/php/ext/google/protobuf2/names.h
@@ -0,0 +1,40 @@
+// 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.
+
+#ifndef PHP_PROTOBUF_NAMES_H_
+#define PHP_PROTOBUF_NAMES_H_
+
+#include "php-upb.h"
+
+// Translates a protobuf symbol name (eg. foo.bar.Baz) into a PHP class name
+// (eg. \Foo\Bar\Baz).
+char *GetPhpClassname(const upb_filedef *file, const char *fullname);
+
+#endif // PHP_PROTOBUF_NAMES_H_
diff --git a/php/ext/google/protobuf2/php-upb.c b/php/ext/google/protobuf2/php-upb.c
new file mode 100644
index 0000000000..f5ea2ef20a
--- /dev/null
+++ b/php/ext/google/protobuf2/php-upb.c
@@ -0,0 +1,8077 @@
+/* Amalgamated source file */
+#include "php-upb.h"
+/*
+* This is where we define macros used across upb.
+*
+* All of these macros are undef'd in port_undef.inc to avoid leaking them to
+* users.
+*
+* The correct usage is:
+*
+* #include "upb/foobar.h"
+* #include "upb/baz.h"
+*
+* // MUST be last included header.
+* #include "upb/port_def.inc"
+*
+* // Code for this file.
+* // <...>
+*
+* // Can be omitted for .c files, required for .h.
+* #include "upb/port_undef.inc"
+*
+* This file is private and must not be included by users!
+*/
+#include
+#include
+
+#if UINTPTR_MAX == 0xffffffff
+#define UPB_SIZE(size32, size64) size32
+#else
+#define UPB_SIZE(size32, size64) size64
+#endif
+
+/* If we always read/write as a consistent type to each address, this shouldn't
+ * violate aliasing.
+ */
+#define UPB_PTR_AT(msg, ofs, type) ((type*)((char*)(msg) + (ofs)))
+
+#define UPB_READ_ONEOF(msg, fieldtype, offset, case_offset, case_val, default) \
+ *UPB_PTR_AT(msg, case_offset, int) == case_val \
+ ? *UPB_PTR_AT(msg, offset, fieldtype) \
+ : default
+
+#define UPB_WRITE_ONEOF(msg, fieldtype, offset, value, case_offset, case_val) \
+ *UPB_PTR_AT(msg, case_offset, int) = case_val; \
+ *UPB_PTR_AT(msg, offset, fieldtype) = value;
+
+#define UPB_MAPTYPE_STRING 0
+
+/* UPB_INLINE: inline if possible, emit standalone code if required. */
+#ifdef __cplusplus
+#define UPB_INLINE inline
+#elif defined (__GNUC__) || defined(__clang__)
+#define UPB_INLINE static __inline__
+#else
+#define UPB_INLINE static
+#endif
+
+#define UPB_ALIGN_UP(size, align) (((size) + (align) - 1) / (align) * (align))
+#define UPB_ALIGN_DOWN(size, align) ((size) / (align) * (align))
+#define UPB_ALIGN_MALLOC(size) UPB_ALIGN_UP(size, 16)
+#define UPB_ALIGN_OF(type) offsetof (struct { char c; type member; }, member)
+
+/* Hints to the compiler about likely/unlikely branches. */
+#if defined (__GNUC__) || defined(__clang__)
+#define UPB_LIKELY(x) __builtin_expect((x),1)
+#define UPB_UNLIKELY(x) __builtin_expect((x),0)
+#else
+#define UPB_LIKELY(x) (x)
+#define UPB_UNLIKELY(x) (x)
+#endif
+
+/* Define UPB_BIG_ENDIAN manually if you're on big endian and your compiler
+ * doesn't provide these preprocessor symbols. */
+#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
+#define UPB_BIG_ENDIAN
+#endif
+
+/* Macros for function attributes on compilers that support them. */
+#ifdef __GNUC__
+#define UPB_FORCEINLINE __inline__ __attribute__((always_inline))
+#define UPB_NOINLINE __attribute__((noinline))
+#define UPB_NORETURN __attribute__((__noreturn__))
+#else /* !defined(__GNUC__) */
+#define UPB_FORCEINLINE
+#define UPB_NOINLINE
+#define UPB_NORETURN
+#endif
+
+#if __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L
+/* C99/C++11 versions. */
+#include
+#define _upb_snprintf snprintf
+#define _upb_vsnprintf vsnprintf
+#define _upb_va_copy(a, b) va_copy(a, b)
+#elif defined(_MSC_VER)
+/* Microsoft C/C++ versions. */
+#include
+#include
+#if _MSC_VER < 1900
+int msvc_snprintf(char* s, size_t n, const char* format, ...);
+int msvc_vsnprintf(char* s, size_t n, const char* format, va_list arg);
+#define UPB_MSVC_VSNPRINTF
+#define _upb_snprintf msvc_snprintf
+#define _upb_vsnprintf msvc_vsnprintf
+#else
+#define _upb_snprintf snprintf
+#define _upb_vsnprintf vsnprintf
+#endif
+#define _upb_va_copy(a, b) va_copy(a, b)
+#elif defined __GNUC__
+/* A few hacky workarounds for functions not in C89.
+ * For internal use only!
+ * TODO(haberman): fix these by including our own implementations, or finding
+ * another workaround.
+ */
+#define _upb_snprintf __builtin_snprintf
+#define _upb_vsnprintf __builtin_vsnprintf
+#define _upb_va_copy(a, b) __va_copy(a, b)
+#else
+#error Need implementations of [v]snprintf and va_copy
+#endif
+
+#ifdef __cplusplus
+#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) || \
+ (defined(_MSC_VER) && _MSC_VER >= 1900)
+/* C++11 is present */
+#else
+#error upb requires C++11 for C++ support
+#endif
+#endif
+
+#define UPB_MAX(x, y) ((x) > (y) ? (x) : (y))
+#define UPB_MIN(x, y) ((x) < (y) ? (x) : (y))
+
+#define UPB_UNUSED(var) (void)var
+
+/* UPB_ASSUME(): in release mode, we tell the compiler to assume this is true.
+ */
+#ifdef NDEBUG
+#ifdef __GNUC__
+#define UPB_ASSUME(expr) if (!(expr)) __builtin_unreachable()
+#elif defined _MSC_VER
+#define UPB_ASSUME(expr) if (!(expr)) __assume(0)
+#else
+#define UPB_ASSUME(expr) do {} if (false && (expr))
+#endif
+#else
+#define UPB_ASSUME(expr) assert(expr)
+#endif
+
+/* UPB_ASSERT(): in release mode, we use the expression without letting it be
+ * evaluated. This prevents "unused variable" warnings. */
+#ifdef NDEBUG
+#define UPB_ASSERT(expr) do {} while (false && (expr))
+#else
+#define UPB_ASSERT(expr) assert(expr)
+#endif
+
+/* UPB_ASSERT_DEBUGVAR(): assert that uses functions or variables that only
+ * exist in debug mode. This turns into regular assert. */
+#define UPB_ASSERT_DEBUGVAR(expr) assert(expr)
+
+#if defined(__GNUC__) || defined(__clang__)
+#define UPB_UNREACHABLE() do { assert(0); __builtin_unreachable(); } while(0)
+#else
+#define UPB_UNREACHABLE() do { assert(0); } while(0)
+#endif
+
+/* UPB_INFINITY representing floating-point positive infinity. */
+#include
+#ifdef INFINITY
+#define UPB_INFINITY INFINITY
+#else
+#define UPB_INFINITY (1.0 / 0.0)
+#endif
+
+#include
+#include
+
+
+
+/* Maps descriptor type -> upb field type. */
+static const uint8_t desctype_to_fieldtype[] = {
+ -1, /* invalid descriptor type */
+ UPB_TYPE_DOUBLE, /* DOUBLE */
+ UPB_TYPE_FLOAT, /* FLOAT */
+ UPB_TYPE_INT64, /* INT64 */
+ UPB_TYPE_UINT64, /* UINT64 */
+ UPB_TYPE_INT32, /* INT32 */
+ UPB_TYPE_UINT64, /* FIXED64 */
+ UPB_TYPE_UINT32, /* FIXED32 */
+ UPB_TYPE_BOOL, /* BOOL */
+ UPB_TYPE_STRING, /* STRING */
+ UPB_TYPE_MESSAGE, /* GROUP */
+ UPB_TYPE_MESSAGE, /* MESSAGE */
+ UPB_TYPE_BYTES, /* BYTES */
+ UPB_TYPE_UINT32, /* UINT32 */
+ UPB_TYPE_ENUM, /* ENUM */
+ UPB_TYPE_INT32, /* SFIXED32 */
+ UPB_TYPE_INT64, /* SFIXED64 */
+ UPB_TYPE_INT32, /* SINT32 */
+ UPB_TYPE_INT64, /* SINT64 */
+};
+
+/* Maps descriptor type -> upb map size. */
+static const uint8_t desctype_to_mapsize[] = {
+ -1, /* invalid descriptor type */
+ 8, /* DOUBLE */
+ 4, /* FLOAT */
+ 8, /* INT64 */
+ 8, /* UINT64 */
+ 4, /* INT32 */
+ 8, /* FIXED64 */
+ 4, /* FIXED32 */
+ 1, /* BOOL */
+ UPB_MAPTYPE_STRING, /* STRING */
+ sizeof(void *), /* GROUP */
+ sizeof(void *), /* MESSAGE */
+ UPB_MAPTYPE_STRING, /* BYTES */
+ 4, /* UINT32 */
+ 4, /* ENUM */
+ 4, /* SFIXED32 */
+ 8, /* SFIXED64 */
+ 4, /* SINT32 */
+ 8, /* SINT64 */
+};
+
+static const unsigned fixed32_ok = (1 << UPB_DTYPE_FLOAT) |
+ (1 << UPB_DTYPE_FIXED32) |
+ (1 << UPB_DTYPE_SFIXED32);
+
+static const unsigned fixed64_ok = (1 << UPB_DTYPE_DOUBLE) |
+ (1 << UPB_DTYPE_FIXED64) |
+ (1 << UPB_DTYPE_SFIXED64);
+
+/* Op: an action to be performed for a wire-type/field-type combination. */
+#define OP_SCALAR_LG2(n) (n)
+#define OP_FIXPCK_LG2(n) (n + 4)
+#define OP_VARPCK_LG2(n) (n + 8)
+#define OP_STRING 4
+#define OP_SUBMSG 5
+
+static const int8_t varint_ops[19] = {
+ -1, /* field not found */
+ -1, /* DOUBLE */
+ -1, /* FLOAT */
+ OP_SCALAR_LG2(3), /* INT64 */
+ OP_SCALAR_LG2(3), /* UINT64 */
+ OP_SCALAR_LG2(2), /* INT32 */
+ -1, /* FIXED64 */
+ -1, /* FIXED32 */
+ OP_SCALAR_LG2(0), /* BOOL */
+ -1, /* STRING */
+ -1, /* GROUP */
+ -1, /* MESSAGE */
+ -1, /* BYTES */
+ OP_SCALAR_LG2(2), /* UINT32 */
+ OP_SCALAR_LG2(2), /* ENUM */
+ -1, /* SFIXED32 */
+ -1, /* SFIXED64 */
+ OP_SCALAR_LG2(2), /* SINT32 */
+ OP_SCALAR_LG2(3), /* SINT64 */
+};
+
+static const int8_t delim_ops[37] = {
+ /* For non-repeated field type. */
+ -1, /* field not found */
+ -1, /* DOUBLE */
+ -1, /* FLOAT */
+ -1, /* INT64 */
+ -1, /* UINT64 */
+ -1, /* INT32 */
+ -1, /* FIXED64 */
+ -1, /* FIXED32 */
+ -1, /* BOOL */
+ OP_STRING, /* STRING */
+ -1, /* GROUP */
+ OP_SUBMSG, /* MESSAGE */
+ OP_STRING, /* BYTES */
+ -1, /* UINT32 */
+ -1, /* ENUM */
+ -1, /* SFIXED32 */
+ -1, /* SFIXED64 */
+ -1, /* SINT32 */
+ -1, /* SINT64 */
+ /* For repeated field type. */
+ OP_FIXPCK_LG2(3), /* REPEATED DOUBLE */
+ OP_FIXPCK_LG2(2), /* REPEATED FLOAT */
+ OP_VARPCK_LG2(3), /* REPEATED INT64 */
+ OP_VARPCK_LG2(3), /* REPEATED UINT64 */
+ OP_VARPCK_LG2(2), /* REPEATED INT32 */
+ OP_FIXPCK_LG2(3), /* REPEATED FIXED64 */
+ OP_FIXPCK_LG2(2), /* REPEATED FIXED32 */
+ OP_VARPCK_LG2(0), /* REPEATED BOOL */
+ OP_STRING, /* REPEATED STRING */
+ OP_SUBMSG, /* REPEATED GROUP */
+ OP_SUBMSG, /* REPEATED MESSAGE */
+ OP_STRING, /* REPEATED BYTES */
+ OP_VARPCK_LG2(2), /* REPEATED UINT32 */
+ OP_VARPCK_LG2(2), /* REPEATED ENUM */
+ OP_FIXPCK_LG2(2), /* REPEATED SFIXED32 */
+ OP_FIXPCK_LG2(3), /* REPEATED SFIXED64 */
+ OP_VARPCK_LG2(2), /* REPEATED SINT32 */
+ OP_VARPCK_LG2(3), /* REPEATED SINT64 */
+};
+
+/* Data pertaining to the parse. */
+typedef struct {
+ const char *limit; /* End of delimited region or end of buffer. */
+ upb_arena *arena;
+ int depth;
+ uint32_t end_group; /* Set to field number of END_GROUP tag, if any. */
+ jmp_buf err;
+} upb_decstate;
+
+typedef union {
+ bool bool_val;
+ int32_t int32_val;
+ int64_t int64_val;
+ uint32_t uint32_val;
+ uint64_t uint64_val;
+ upb_strview str_val;
+} wireval;
+
+static const char *decode_msg(upb_decstate *d, const char *ptr, upb_msg *msg,
+ const upb_msglayout *layout);
+
+UPB_NORETURN static void decode_err(upb_decstate *d) { longjmp(d->err, 1); }
+
+static bool decode_reserve(upb_decstate *d, upb_array *arr, size_t elem) {
+ bool need_realloc = arr->size - arr->len < elem;
+ if (need_realloc && !_upb_array_realloc(arr, arr->len + elem, d->arena)) {
+ decode_err(d);
+ }
+ return need_realloc;
+}
+
+UPB_NOINLINE
+static const char *decode_longvarint64(upb_decstate *d, const char *ptr,
+ const char *limit, uint64_t *val) {
+ uint8_t byte;
+ int bitpos = 0;
+ uint64_t out = 0;
+
+ do {
+ if (bitpos >= 70 || ptr == limit) decode_err(d);
+ byte = *ptr;
+ out |= (uint64_t)(byte & 0x7F) << bitpos;
+ ptr++;
+ bitpos += 7;
+ } while (byte & 0x80);
+
+ *val = out;
+ return ptr;
+}
+
+UPB_FORCEINLINE
+static const char *decode_varint64(upb_decstate *d, const char *ptr,
+ const char *limit, uint64_t *val) {
+ if (UPB_LIKELY(ptr < limit && (*ptr & 0x80) == 0)) {
+ *val = (uint8_t)*ptr;
+ return ptr + 1;
+ } else {
+ return decode_longvarint64(d, ptr, limit, val);
+ }
+}
+
+static const char *decode_varint32(upb_decstate *d, const char *ptr,
+ const char *limit, uint32_t *val) {
+ uint64_t u64;
+ ptr = decode_varint64(d, ptr, limit, &u64);
+ if (u64 > UINT32_MAX) decode_err(d);
+ *val = (uint32_t)u64;
+ return ptr;
+}
+
+static void decode_munge(int type, wireval *val) {
+ switch (type) {
+ case UPB_DESCRIPTOR_TYPE_BOOL:
+ val->bool_val = val->uint64_val != 0;
+ break;
+ case UPB_DESCRIPTOR_TYPE_SINT32: {
+ uint32_t n = val->uint32_val;
+ val->int32_val = (n >> 1) ^ -(int32_t)(n & 1);
+ break;
+ }
+ case UPB_DESCRIPTOR_TYPE_SINT64: {
+ uint64_t n = val->uint64_val;
+ val->int64_val = (n >> 1) ^ -(int64_t)(n & 1);
+ break;
+ }
+ }
+}
+
+static const upb_msglayout_field *upb_find_field(const upb_msglayout *l,
+ uint32_t field_number) {
+ static upb_msglayout_field none = {0};
+
+ /* Lots of optimization opportunities here. */
+ int i;
+ if (l == NULL) return &none;
+ for (i = 0; i < l->field_count; i++) {
+ if (l->fields[i].number == field_number) {
+ return &l->fields[i];
+ }
+ }
+
+ return &none; /* Unknown field. */
+}
+
+static upb_msg *decode_newsubmsg(upb_decstate *d, const upb_msglayout *layout,
+ const upb_msglayout_field *field) {
+ const upb_msglayout *subl = layout->submsgs[field->submsg_index];
+ return _upb_msg_new(subl, d->arena);
+}
+
+static void decode_tosubmsg(upb_decstate *d, upb_msg *submsg,
+ const upb_msglayout *layout,
+ const upb_msglayout_field *field, upb_strview val) {
+ const upb_msglayout *subl = layout->submsgs[field->submsg_index];
+ const char *saved_limit = d->limit;
+ if (--d->depth < 0) decode_err(d);
+ d->limit = val.data + val.size;
+ decode_msg(d, val.data, submsg, subl);
+ d->limit = saved_limit;
+ if (d->end_group != 0) decode_err(d);
+ d->depth++;
+}
+
+static const char *decode_group(upb_decstate *d, const char *ptr,
+ upb_msg *submsg, const upb_msglayout *subl,
+ uint32_t number) {
+ if (--d->depth < 0) decode_err(d);
+ ptr = decode_msg(d, ptr, submsg, subl);
+ if (d->end_group != number) decode_err(d);
+ d->end_group = 0;
+ d->depth++;
+ return ptr;
+}
+
+static const char *decode_togroup(upb_decstate *d, const char *ptr,
+ upb_msg *submsg, const upb_msglayout *layout,
+ const upb_msglayout_field *field) {
+ const upb_msglayout *subl = layout->submsgs[field->submsg_index];
+ return decode_group(d, ptr, submsg, subl, field->number);
+}
+
+static const char *decode_toarray(upb_decstate *d, const char *ptr,
+ upb_msg *msg, const upb_msglayout *layout,
+ const upb_msglayout_field *field, wireval val,
+ int op) {
+ upb_array **arrp = UPB_PTR_AT(msg, field->offset, void);
+ upb_array *arr = *arrp;
+ void *mem;
+
+ if (!arr) {
+ upb_fieldtype_t type = desctype_to_fieldtype[field->descriptortype];
+ arr = _upb_array_new(d->arena, type);
+ if (!arr) decode_err(d);
+ *arrp = arr;
+ }
+
+ decode_reserve(d, arr, 1);
+
+ switch (op) {
+ case OP_SCALAR_LG2(0):
+ case OP_SCALAR_LG2(2):
+ case OP_SCALAR_LG2(3):
+ /* Append scalar value. */
+ mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->len << op, void);
+ arr->len++;
+ memcpy(mem, &val, 1 << op);
+ return ptr;
+ case OP_STRING:
+ /* Append string. */
+ mem =
+ UPB_PTR_AT(_upb_array_ptr(arr), arr->len * sizeof(upb_strview), void);
+ arr->len++;
+ memcpy(mem, &val, sizeof(upb_strview));
+ return ptr;
+ case OP_SUBMSG: {
+ /* Append submessage / group. */
+ upb_msg *submsg = decode_newsubmsg(d, layout, field);
+ *UPB_PTR_AT(_upb_array_ptr(arr), arr->len * sizeof(void *), upb_msg *) =
+ submsg;
+ arr->len++;
+ if (UPB_UNLIKELY(field->descriptortype == UPB_DTYPE_GROUP)) {
+ ptr = decode_togroup(d, ptr, submsg, layout, field);
+ } else {
+ decode_tosubmsg(d, submsg, layout, field, val.str_val);
+ }
+ return ptr;
+ }
+ case OP_FIXPCK_LG2(2):
+ case OP_FIXPCK_LG2(3): {
+ /* Fixed packed. */
+ int lg2 = op - OP_FIXPCK_LG2(0);
+ int mask = (1 << lg2) - 1;
+ size_t count = val.str_val.size >> lg2;
+ if ((val.str_val.size & mask) != 0) {
+ decode_err(d); /* Length isn't a round multiple of elem size. */
+ }
+ decode_reserve(d, arr, count);
+ mem = UPB_PTR_AT(_upb_array_ptr(arr), arr->len << lg2, void);
+ arr->len += count;
+ memcpy(mem, val.str_val.data, val.str_val.size);
+ return ptr;
+ }
+ case OP_VARPCK_LG2(0):
+ case OP_VARPCK_LG2(2):
+ case OP_VARPCK_LG2(3): {
+ /* Varint packed. */
+ int lg2 = op - OP_VARPCK_LG2(0);
+ int scale = 1 << lg2;
+ const char *ptr = val.str_val.data;
+ const char *end = ptr + val.str_val.size;
+ char *out = UPB_PTR_AT(_upb_array_ptr(arr), arr->len << lg2, void);
+ while (ptr < end) {
+ wireval elem;
+ ptr = decode_varint64(d, ptr, end, &elem.uint64_val);
+ decode_munge(field->descriptortype, &elem);
+ if (decode_reserve(d, arr, 1)) {
+ out = UPB_PTR_AT(_upb_array_ptr(arr), arr->len << lg2, void);
+ }
+ arr->len++;
+ memcpy(out, &elem, scale);
+ out += scale;
+ }
+ if (ptr != end) decode_err(d);
+ return ptr;
+ }
+ default:
+ UPB_UNREACHABLE();
+ }
+}
+
+static void decode_tomap(upb_decstate *d, upb_msg *msg,
+ const upb_msglayout *layout,
+ const upb_msglayout_field *field, wireval val) {
+ upb_map **map_p = UPB_PTR_AT(msg, field->offset, upb_map *);
+ upb_map *map = *map_p;
+ upb_map_entry ent;
+ const upb_msglayout *entry = layout->submsgs[field->submsg_index];
+
+ if (!map) {
+ /* Lazily create map. */
+ const upb_msglayout *entry = layout->submsgs[field->submsg_index];
+ const upb_msglayout_field *key_field = &entry->fields[0];
+ const upb_msglayout_field *val_field = &entry->fields[1];
+ char key_size = desctype_to_mapsize[key_field->descriptortype];
+ char val_size = desctype_to_mapsize[val_field->descriptortype];
+ UPB_ASSERT(key_field->offset == 0);
+ UPB_ASSERT(val_field->offset == sizeof(upb_strview));
+ map = _upb_map_new(d->arena, key_size, val_size);
+ *map_p = map;
+ }
+
+ /* Parse map entry. */
+ memset(&ent, 0, sizeof(ent));
+
+ if (entry->fields[1].descriptortype == UPB_DESCRIPTOR_TYPE_MESSAGE ||
+ entry->fields[1].descriptortype == UPB_DESCRIPTOR_TYPE_GROUP) {
+ /* Create proactively to handle the case where it doesn't appear. */
+ ent.v.val.val = (uint64_t)_upb_msg_new(entry->submsgs[0], d->arena);
+ }
+
+ decode_tosubmsg(d, &ent.k, layout, field, val.str_val);
+
+ /* Insert into map. */
+ _upb_map_set(map, &ent.k, map->key_size, &ent.v, map->val_size, d->arena);
+}
+
+static const char *decode_tomsg(upb_decstate *d, const char *ptr, upb_msg *msg,
+ const upb_msglayout *layout,
+ const upb_msglayout_field *field, wireval val,
+ int op) {
+ void *mem = UPB_PTR_AT(msg, field->offset, void);
+ int type = field->descriptortype;
+
+ /* Set presence if necessary. */
+ if (field->presence < 0) {
+ /* Oneof case */
+ uint32_t *oneof_case = _upb_oneofcase_field(msg, field);
+ if (op == OP_SUBMSG && *oneof_case != field->number) {
+ memset(mem, 0, sizeof(void*));
+ }
+ *oneof_case = field->number;
+ } else if (field->presence > 0) {
+ _upb_sethas_field(msg, field);
+ }
+
+ /* Store into message. */
+ switch (op) {
+ case OP_SUBMSG: {
+ upb_msg **submsgp = mem;
+ upb_msg *submsg = *submsgp;
+ if (!submsg) {
+ submsg = decode_newsubmsg(d, layout, field);
+ *submsgp = submsg;
+ }
+ if (UPB_UNLIKELY(type == UPB_DTYPE_GROUP)) {
+ ptr = decode_togroup(d, ptr, submsg, layout, field);
+ } else {
+ decode_tosubmsg(d, submsg, layout, field, val.str_val);
+ }
+ break;
+ }
+ case OP_STRING:
+ memcpy(mem, &val, sizeof(upb_strview));
+ break;
+ case OP_SCALAR_LG2(3):
+ memcpy(mem, &val, 8);
+ break;
+ case OP_SCALAR_LG2(2):
+ memcpy(mem, &val, 4);
+ break;
+ case OP_SCALAR_LG2(0):
+ memcpy(mem, &val, 1);
+ break;
+ default:
+ UPB_UNREACHABLE();
+ }
+
+ return ptr;
+}
+
+static const char *decode_msg(upb_decstate *d, const char *ptr, upb_msg *msg,
+ const upb_msglayout *layout) {
+ while (ptr < d->limit) {
+ uint32_t tag;
+ const upb_msglayout_field *field;
+ int field_number;
+ int wire_type;
+ const char *field_start = ptr;
+ wireval val;
+ int op;
+
+ ptr = decode_varint32(d, ptr, d->limit, &tag);
+ field_number = tag >> 3;
+ wire_type = tag & 7;
+
+ field = upb_find_field(layout, field_number);
+
+ switch (wire_type) {
+ case UPB_WIRE_TYPE_VARINT:
+ ptr = decode_varint64(d, ptr, d->limit, &val.uint64_val);
+ op = varint_ops[field->descriptortype];
+ decode_munge(field->descriptortype, &val);
+ break;
+ case UPB_WIRE_TYPE_32BIT:
+ if (d->limit - ptr < 4) decode_err(d);
+ memcpy(&val, ptr, 4);
+ ptr += 4;
+ op = OP_SCALAR_LG2(2);
+ if (((1 << field->descriptortype) & fixed32_ok) == 0) goto unknown;
+ break;
+ case UPB_WIRE_TYPE_64BIT:
+ if (d->limit - ptr < 8) decode_err(d);
+ memcpy(&val, ptr, 8);
+ ptr += 8;
+ op = OP_SCALAR_LG2(3);
+ if (((1 << field->descriptortype) & fixed64_ok) == 0) goto unknown;
+ break;
+ case UPB_WIRE_TYPE_DELIMITED: {
+ uint32_t size;
+ int ndx = field->descriptortype;
+ if (_upb_isrepeated(field)) ndx += 18;
+ ptr = decode_varint32(d, ptr, d->limit, &size);
+ if (size >= INT32_MAX || (size_t)(d->limit - ptr) < size) {
+ decode_err(d); /* Length overflow. */
+ }
+ val.str_val.data = ptr;
+ val.str_val.size = size;
+ ptr += size;
+ op = delim_ops[ndx];
+ break;
+ }
+ case UPB_WIRE_TYPE_START_GROUP:
+ val.int32_val = field_number;
+ op = OP_SUBMSG;
+ if (field->descriptortype != UPB_DTYPE_GROUP) goto unknown;
+ break;
+ case UPB_WIRE_TYPE_END_GROUP:
+ d->end_group = field_number;
+ return ptr;
+ default:
+ decode_err(d);
+ }
+
+ if (op >= 0) {
+ /* Parse, using op for dispatch. */
+ switch (field->label) {
+ case UPB_LABEL_REPEATED:
+ case _UPB_LABEL_PACKED:
+ ptr = decode_toarray(d, ptr, msg, layout, field, val, op);
+ break;
+ case _UPB_LABEL_MAP:
+ decode_tomap(d, msg, layout, field, val);
+ break;
+ default:
+ ptr = decode_tomsg(d, ptr, msg, layout, field, val, op);
+ break;
+ }
+ } else {
+ unknown:
+ /* Skip unknown field. */
+ if (field_number == 0) decode_err(d);
+ if (wire_type == UPB_WIRE_TYPE_START_GROUP) {
+ ptr = decode_group(d, ptr, NULL, NULL, field_number);
+ }
+ if (msg) {
+ if (!_upb_msg_addunknown(msg, field_start, ptr - field_start,
+ d->arena)) {
+ decode_err(d);
+ }
+ }
+ }
+ }
+
+ if (ptr != d->limit) decode_err(d);
+ return ptr;
+}
+
+bool upb_decode(const char *buf, size_t size, void *msg, const upb_msglayout *l,
+ upb_arena *arena) {
+ upb_decstate state;
+ state.limit = buf + size;
+ state.arena = arena;
+ state.depth = 64;
+ state.end_group = 0;
+
+ if (setjmp(state.err)) return false;
+
+ if (size == 0) return true;
+ decode_msg(&state, buf, msg, l);
+
+ return state.end_group == 0;
+}
+
+#undef OP_SCALAR_LG2
+#undef OP_FIXPCK_LG2
+#undef OP_VARPCK_LG2
+#undef OP_STRING
+#undef OP_SUBMSG
+/* We encode backwards, to avoid pre-computing lengths (one-pass encode). */
+
+
+#include
+
+
+
+#define UPB_PB_VARINT_MAX_LEN 10
+#define CHK(x) do { if (!(x)) { return false; } } while(0)
+
+static size_t upb_encode_varint(uint64_t val, char *buf) {
+ size_t i;
+ if (val < 128) { buf[0] = val; return 1; }
+ i = 0;
+ while (val) {
+ uint8_t byte = val & 0x7fU;
+ val >>= 7;
+ if (val) byte |= 0x80U;
+ buf[i++] = byte;
+ }
+ return i;
+}
+
+static uint32_t upb_zzencode_32(int32_t n) { return ((uint32_t)n << 1) ^ (n >> 31); }
+static uint64_t upb_zzencode_64(int64_t n) { return ((uint64_t)n << 1) ^ (n >> 63); }
+
+typedef struct {
+ upb_alloc *alloc;
+ char *buf, *ptr, *limit;
+} upb_encstate;
+
+static size_t upb_roundup_pow2(size_t bytes) {
+ size_t ret = 128;
+ while (ret < bytes) {
+ ret *= 2;
+ }
+ return ret;
+}
+
+static bool upb_encode_growbuffer(upb_encstate *e, size_t bytes) {
+ size_t old_size = e->limit - e->buf;
+ size_t new_size = upb_roundup_pow2(bytes + (e->limit - e->ptr));
+ char *new_buf = upb_realloc(e->alloc, e->buf, old_size, new_size);
+ CHK(new_buf);
+
+ /* We want previous data at the end, realloc() put it at the beginning. */
+ if (old_size > 0) {
+ memmove(new_buf + new_size - old_size, e->buf, old_size);
+ }
+
+ e->ptr = new_buf + new_size - (e->limit - e->ptr);
+ e->limit = new_buf + new_size;
+ e->buf = new_buf;
+ return true;
+}
+
+/* Call to ensure that at least "bytes" bytes are available for writing at
+ * e->ptr. Returns false if the bytes could not be allocated. */
+static bool upb_encode_reserve(upb_encstate *e, size_t bytes) {
+ CHK(UPB_LIKELY((size_t)(e->ptr - e->buf) >= bytes) ||
+ upb_encode_growbuffer(e, bytes));
+
+ e->ptr -= bytes;
+ return true;
+}
+
+/* Writes the given bytes to the buffer, handling reserve/advance. */
+static bool upb_put_bytes(upb_encstate *e, const void *data, size_t len) {
+ if (len == 0) return true;
+ CHK(upb_encode_reserve(e, len));
+ memcpy(e->ptr, data, len);
+ return true;
+}
+
+static bool upb_put_fixed64(upb_encstate *e, uint64_t val) {
+ /* TODO(haberman): byte-swap for big endian. */
+ return upb_put_bytes(e, &val, sizeof(uint64_t));
+}
+
+static bool upb_put_fixed32(upb_encstate *e, uint32_t val) {
+ /* TODO(haberman): byte-swap for big endian. */
+ return upb_put_bytes(e, &val, sizeof(uint32_t));
+}
+
+static bool upb_put_varint(upb_encstate *e, uint64_t val) {
+ size_t len;
+ char *start;
+ CHK(upb_encode_reserve(e, UPB_PB_VARINT_MAX_LEN));
+ len = upb_encode_varint(val, e->ptr);
+ start = e->ptr + UPB_PB_VARINT_MAX_LEN - len;
+ memmove(start, e->ptr, len);
+ e->ptr = start;
+ return true;
+}
+
+static bool upb_put_double(upb_encstate *e, double d) {
+ uint64_t u64;
+ UPB_ASSERT(sizeof(double) == sizeof(uint64_t));
+ memcpy(&u64, &d, sizeof(uint64_t));
+ return upb_put_fixed64(e, u64);
+}
+
+static bool upb_put_float(upb_encstate *e, float d) {
+ uint32_t u32;
+ UPB_ASSERT(sizeof(float) == sizeof(uint32_t));
+ memcpy(&u32, &d, sizeof(uint32_t));
+ return upb_put_fixed32(e, u32);
+}
+
+static bool upb_put_tag(upb_encstate *e, int field_number, int wire_type) {
+ return upb_put_varint(e, (field_number << 3) | wire_type);
+}
+
+static bool upb_put_fixedarray(upb_encstate *e, const upb_array *arr,
+ size_t elem_size, uint32_t tag) {
+ size_t bytes = arr->len * elem_size;
+ const char* data = _upb_array_constptr(arr);
+ const char* ptr = data + bytes - elem_size;
+ if (tag) {
+ while (true) {
+ CHK(upb_put_bytes(e, ptr, elem_size) && upb_put_varint(e, tag));
+ if (ptr == data) break;
+ ptr -= elem_size;
+ }
+ return true;
+ } else {
+ return upb_put_bytes(e, data, bytes) && upb_put_varint(e, bytes);
+ }
+}
+
+bool upb_encode_message(upb_encstate *e, const char *msg,
+ const upb_msglayout *m, size_t *size);
+
+static bool upb_encode_scalarfield(upb_encstate *e, const void *_field_mem,
+ const upb_msglayout *m,
+ const upb_msglayout_field *f,
+ bool skip_zero_value) {
+ const char *field_mem = _field_mem;
+#define CASE(ctype, type, wire_type, encodeval) do { \
+ ctype val = *(ctype*)field_mem; \
+ if (skip_zero_value && val == 0) { \
+ return true; \
+ } \
+ return upb_put_ ## type(e, encodeval) && \
+ upb_put_tag(e, f->number, wire_type); \
+} while(0)
+
+ switch (f->descriptortype) {
+ case UPB_DESCRIPTOR_TYPE_DOUBLE:
+ CASE(double, double, UPB_WIRE_TYPE_64BIT, val);
+ case UPB_DESCRIPTOR_TYPE_FLOAT:
+ CASE(float, float, UPB_WIRE_TYPE_32BIT, val);
+ case UPB_DESCRIPTOR_TYPE_INT64:
+ case UPB_DESCRIPTOR_TYPE_UINT64:
+ CASE(uint64_t, varint, UPB_WIRE_TYPE_VARINT, val);
+ case UPB_DESCRIPTOR_TYPE_UINT32:
+ CASE(uint32_t, varint, UPB_WIRE_TYPE_VARINT, val);
+ case UPB_DESCRIPTOR_TYPE_INT32:
+ case UPB_DESCRIPTOR_TYPE_ENUM:
+ CASE(int32_t, varint, UPB_WIRE_TYPE_VARINT, (int64_t)val);
+ case UPB_DESCRIPTOR_TYPE_SFIXED64:
+ case UPB_DESCRIPTOR_TYPE_FIXED64:
+ CASE(uint64_t, fixed64, UPB_WIRE_TYPE_64BIT, val);
+ case UPB_DESCRIPTOR_TYPE_FIXED32:
+ case UPB_DESCRIPTOR_TYPE_SFIXED32:
+ CASE(uint32_t, fixed32, UPB_WIRE_TYPE_32BIT, val);
+ case UPB_DESCRIPTOR_TYPE_BOOL:
+ CASE(bool, varint, UPB_WIRE_TYPE_VARINT, val);
+ case UPB_DESCRIPTOR_TYPE_SINT32:
+ CASE(int32_t, varint, UPB_WIRE_TYPE_VARINT, upb_zzencode_32(val));
+ case UPB_DESCRIPTOR_TYPE_SINT64:
+ CASE(int64_t, varint, UPB_WIRE_TYPE_VARINT, upb_zzencode_64(val));
+ case UPB_DESCRIPTOR_TYPE_STRING:
+ case UPB_DESCRIPTOR_TYPE_BYTES: {
+ upb_strview view = *(upb_strview*)field_mem;
+ if (skip_zero_value && view.size == 0) {
+ return true;
+ }
+ return upb_put_bytes(e, view.data, view.size) &&
+ upb_put_varint(e, view.size) &&
+ upb_put_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED);
+ }
+ case UPB_DESCRIPTOR_TYPE_GROUP: {
+ size_t size;
+ void *submsg = *(void **)field_mem;
+ const upb_msglayout *subm = m->submsgs[f->submsg_index];
+ if (submsg == NULL) {
+ return true;
+ }
+ return upb_put_tag(e, f->number, UPB_WIRE_TYPE_END_GROUP) &&
+ upb_encode_message(e, submsg, subm, &size) &&
+ upb_put_tag(e, f->number, UPB_WIRE_TYPE_START_GROUP);
+ }
+ case UPB_DESCRIPTOR_TYPE_MESSAGE: {
+ size_t size;
+ void *submsg = *(void **)field_mem;
+ const upb_msglayout *subm = m->submsgs[f->submsg_index];
+ if (submsg == NULL) {
+ return true;
+ }
+ return upb_encode_message(e, submsg, subm, &size) &&
+ upb_put_varint(e, size) &&
+ upb_put_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED);
+ }
+ }
+#undef CASE
+ UPB_UNREACHABLE();
+}
+
+static bool upb_encode_array(upb_encstate *e, const char *field_mem,
+ const upb_msglayout *m,
+ const upb_msglayout_field *f) {
+ const upb_array *arr = *(const upb_array**)field_mem;
+ bool packed = f->label == _UPB_LABEL_PACKED;
+
+ if (arr == NULL || arr->len == 0) {
+ return true;
+ }
+
+#define VARINT_CASE(ctype, encode) \
+ { \
+ const ctype *start = _upb_array_constptr(arr); \
+ const ctype *ptr = start + arr->len; \
+ size_t pre_len = e->limit - e->ptr; \
+ uint32_t tag = packed ? 0 : (f->number << 3) | UPB_WIRE_TYPE_VARINT; \
+ do { \
+ ptr--; \
+ CHK(upb_put_varint(e, encode)); \
+ if (tag) CHK(upb_put_varint(e, tag)); \
+ } while (ptr != start); \
+ if (!tag) CHK(upb_put_varint(e, e->limit - e->ptr - pre_len)); \
+ } \
+ break; \
+ do { \
+ ; \
+ } while (0)
+
+#define TAG(wire_type) (packed ? 0 : (f->number << 3 | wire_type))
+
+ switch (f->descriptortype) {
+ case UPB_DESCRIPTOR_TYPE_DOUBLE:
+ CHK(upb_put_fixedarray(e, arr, sizeof(double), TAG(UPB_WIRE_TYPE_64BIT)));
+ break;
+ case UPB_DESCRIPTOR_TYPE_FLOAT:
+ CHK(upb_put_fixedarray(e, arr, sizeof(float), TAG(UPB_WIRE_TYPE_32BIT)));
+ break;
+ case UPB_DESCRIPTOR_TYPE_SFIXED64:
+ case UPB_DESCRIPTOR_TYPE_FIXED64:
+ CHK(upb_put_fixedarray(e, arr, sizeof(uint64_t), TAG(UPB_WIRE_TYPE_64BIT)));
+ break;
+ case UPB_DESCRIPTOR_TYPE_FIXED32:
+ case UPB_DESCRIPTOR_TYPE_SFIXED32:
+ CHK(upb_put_fixedarray(e, arr, sizeof(uint32_t), TAG(UPB_WIRE_TYPE_32BIT)));
+ break;
+ case UPB_DESCRIPTOR_TYPE_INT64:
+ case UPB_DESCRIPTOR_TYPE_UINT64:
+ VARINT_CASE(uint64_t, *ptr);
+ case UPB_DESCRIPTOR_TYPE_UINT32:
+ VARINT_CASE(uint32_t, *ptr);
+ case UPB_DESCRIPTOR_TYPE_INT32:
+ case UPB_DESCRIPTOR_TYPE_ENUM:
+ VARINT_CASE(int32_t, (int64_t)*ptr);
+ case UPB_DESCRIPTOR_TYPE_BOOL:
+ VARINT_CASE(bool, *ptr);
+ case UPB_DESCRIPTOR_TYPE_SINT32:
+ VARINT_CASE(int32_t, upb_zzencode_32(*ptr));
+ case UPB_DESCRIPTOR_TYPE_SINT64:
+ VARINT_CASE(int64_t, upb_zzencode_64(*ptr));
+ case UPB_DESCRIPTOR_TYPE_STRING:
+ case UPB_DESCRIPTOR_TYPE_BYTES: {
+ const upb_strview *start = _upb_array_constptr(arr);
+ const upb_strview *ptr = start + arr->len;
+ do {
+ ptr--;
+ CHK(upb_put_bytes(e, ptr->data, ptr->size) &&
+ upb_put_varint(e, ptr->size) &&
+ upb_put_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED));
+ } while (ptr != start);
+ return true;
+ }
+ case UPB_DESCRIPTOR_TYPE_GROUP: {
+ const void *const*start = _upb_array_constptr(arr);
+ const void *const*ptr = start + arr->len;
+ const upb_msglayout *subm = m->submsgs[f->submsg_index];
+ do {
+ size_t size;
+ ptr--;
+ CHK(upb_put_tag(e, f->number, UPB_WIRE_TYPE_END_GROUP) &&
+ upb_encode_message(e, *ptr, subm, &size) &&
+ upb_put_tag(e, f->number, UPB_WIRE_TYPE_START_GROUP));
+ } while (ptr != start);
+ return true;
+ }
+ case UPB_DESCRIPTOR_TYPE_MESSAGE: {
+ const void *const*start = _upb_array_constptr(arr);
+ const void *const*ptr = start + arr->len;
+ const upb_msglayout *subm = m->submsgs[f->submsg_index];
+ do {
+ size_t size;
+ ptr--;
+ CHK(upb_encode_message(e, *ptr, subm, &size) &&
+ upb_put_varint(e, size) &&
+ upb_put_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED));
+ } while (ptr != start);
+ return true;
+ }
+ }
+#undef VARINT_CASE
+
+ if (packed) {
+ CHK(upb_put_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED));
+ }
+ return true;
+}
+
+static bool upb_encode_map(upb_encstate *e, const char *field_mem,
+ const upb_msglayout *m,
+ const upb_msglayout_field *f) {
+ const upb_map *map = *(const upb_map**)field_mem;
+ const upb_msglayout *entry = m->submsgs[f->submsg_index];
+ const upb_msglayout_field *key_field = &entry->fields[0];
+ const upb_msglayout_field *val_field = &entry->fields[1];
+ upb_strtable_iter i;
+ if (map == NULL) {
+ return true;
+ }
+
+ upb_strtable_begin(&i, &map->table);
+ for(; !upb_strtable_done(&i); upb_strtable_next(&i)) {
+ size_t pre_len = e->limit - e->ptr;
+ size_t size;
+ upb_strview key = upb_strtable_iter_key(&i);
+ const upb_value val = upb_strtable_iter_value(&i);
+ upb_map_entry ent;
+ _upb_map_fromkey(key, &ent.k, map->key_size);
+ _upb_map_fromvalue(val, &ent.v, map->val_size);
+ CHK(upb_encode_scalarfield(e, &ent.v, entry, val_field, false));
+ CHK(upb_encode_scalarfield(e, &ent.k, entry, key_field, false));
+ size = (e->limit - e->ptr) - pre_len;
+ CHK(upb_put_varint(e, size));
+ CHK(upb_put_tag(e, f->number, UPB_WIRE_TYPE_DELIMITED));
+ }
+
+ return true;
+}
+
+
+bool upb_encode_message(upb_encstate *e, const char *msg,
+ const upb_msglayout *m, size_t *size) {
+ int i;
+ size_t pre_len = e->limit - e->ptr;
+ const char *unknown;
+ size_t unknown_size;
+
+ unknown = upb_msg_getunknown(msg, &unknown_size);
+
+ if (unknown) {
+ upb_put_bytes(e, unknown, unknown_size);
+ }
+
+ for (i = m->field_count - 1; i >= 0; i--) {
+ const upb_msglayout_field *f = &m->fields[i];
+
+ if (_upb_isrepeated(f)) {
+ CHK(upb_encode_array(e, msg + f->offset, m, f));
+ } else if (f->label == _UPB_LABEL_MAP) {
+ CHK(upb_encode_map(e, msg + f->offset, m, f));
+ } else {
+ bool skip_empty = false;
+ if (f->presence == 0) {
+ /* Proto3 presence. */
+ skip_empty = true;
+ } else if (f->presence > 0) {
+ /* Proto2 presence: hasbit. */
+ if (!_upb_hasbit_field(msg, f)) {
+ continue;
+ }
+ } else {
+ /* Field is in a oneof. */
+ if (_upb_getoneofcase_field(msg, f) != f->number) {
+ continue;
+ }
+ }
+ CHK(upb_encode_scalarfield(e, msg + f->offset, m, f, skip_empty));
+ }
+ }
+
+ *size = (e->limit - e->ptr) - pre_len;
+ return true;
+}
+
+char *upb_encode(const void *msg, const upb_msglayout *m, upb_arena *arena,
+ size_t *size) {
+ upb_encstate e;
+ e.alloc = upb_arena_alloc(arena);
+ e.buf = NULL;
+ e.limit = NULL;
+ e.ptr = NULL;
+
+ if (!upb_encode_message(&e, msg, m, size)) {
+ *size = 0;
+ return NULL;
+ }
+
+ *size = e.limit - e.ptr;
+
+ if (*size == 0) {
+ static char ch;
+ return &ch;
+ } else {
+ UPB_ASSERT(e.ptr);
+ return e.ptr;
+ }
+}
+
+#undef CHK
+
+
+
+
+/** upb_msg *******************************************************************/
+
+static const char _upb_fieldtype_to_sizelg2[12] = {
+ 0,
+ 0, /* UPB_TYPE_BOOL */
+ 2, /* UPB_TYPE_FLOAT */
+ 2, /* UPB_TYPE_INT32 */
+ 2, /* UPB_TYPE_UINT32 */
+ 2, /* UPB_TYPE_ENUM */
+ UPB_SIZE(2, 3), /* UPB_TYPE_MESSAGE */
+ 3, /* UPB_TYPE_DOUBLE */
+ 3, /* UPB_TYPE_INT64 */
+ 3, /* UPB_TYPE_UINT64 */
+ UPB_SIZE(3, 4), /* UPB_TYPE_STRING */
+ UPB_SIZE(3, 4), /* UPB_TYPE_BYTES */
+};
+
+static uintptr_t tag_arrptr(void* ptr, int elem_size_lg2) {
+ UPB_ASSERT(elem_size_lg2 <= 4);
+ return (uintptr_t)ptr | elem_size_lg2;
+}
+
+static int upb_msg_internalsize(const upb_msglayout *l) {
+ return sizeof(upb_msg_internal) - l->extendable * sizeof(void *);
+}
+
+static size_t upb_msg_sizeof(const upb_msglayout *l) {
+ return l->size + upb_msg_internalsize(l);
+}
+
+static const upb_msg_internal *upb_msg_getinternal_const(const upb_msg *msg) {
+ ptrdiff_t size = sizeof(upb_msg_internal);
+ return UPB_PTR_AT(msg, -size, upb_msg_internal);
+}
+
+static upb_msg_internal *upb_msg_getinternal(upb_msg *msg) {
+ return (upb_msg_internal*)upb_msg_getinternal_const(msg);
+}
+
+void _upb_msg_clear(upb_msg *msg, const upb_msglayout *l) {
+ ptrdiff_t internal = upb_msg_internalsize(l);
+ void *mem = UPB_PTR_AT(msg, -internal, char);
+ memset(mem, 0, l->size + internal);
+}
+
+upb_msg *_upb_msg_new(const upb_msglayout *l, upb_arena *a) {
+ void *mem = upb_arena_malloc(a, upb_msg_sizeof(l));
+ upb_msg *msg;
+
+ if (!mem) {
+ return NULL;
+ }
+
+ msg = UPB_PTR_AT(mem, upb_msg_internalsize(l), upb_msg);
+ _upb_msg_clear(msg, l);
+ return msg;
+}
+
+bool _upb_msg_addunknown(upb_msg *msg, const char *data, size_t len,
+ upb_arena *arena) {
+ upb_msg_internal *in = upb_msg_getinternal(msg);
+ if (len > in->unknown_size - in->unknown_len) {
+ upb_alloc *alloc = upb_arena_alloc(arena);
+ size_t need = in->unknown_size + len;
+ size_t newsize = UPB_MAX(in->unknown_size * 2, need);
+ void *mem = upb_realloc(alloc, in->unknown, in->unknown_size, newsize);
+ if (!mem) return false;
+ in->unknown = mem;
+ in->unknown_size = newsize;
+ }
+ memcpy(in->unknown + in->unknown_len, data, len);
+ in->unknown_len += len;
+ return true;
+}
+
+void _upb_msg_discardunknown_shallow(upb_msg *msg) {
+ upb_msg_internal *in = upb_msg_getinternal(msg);
+ in->unknown_len = 0;
+}
+
+const char *upb_msg_getunknown(const upb_msg *msg, size_t *len) {
+ const upb_msg_internal *in = upb_msg_getinternal_const(msg);
+ *len = in->unknown_len;
+ return in->unknown;
+}
+
+/** upb_array *****************************************************************/
+
+upb_array *_upb_array_new(upb_arena *a, upb_fieldtype_t type) {
+ upb_array *arr = upb_arena_malloc(a, sizeof(upb_array));
+
+ if (!arr) {
+ return NULL;
+ }
+
+ arr->data = tag_arrptr(NULL, _upb_fieldtype_to_sizelg2[type]);
+ arr->len = 0;
+ arr->size = 0;
+
+ return arr;
+}
+
+bool _upb_array_realloc(upb_array *arr, size_t min_size, upb_arena *arena) {
+ size_t new_size = UPB_MAX(arr->size, 4);
+ int elem_size_lg2 = arr->data & 7;
+ size_t old_bytes = arr->size << elem_size_lg2;
+ size_t new_bytes;
+ void* ptr = _upb_array_ptr(arr);
+
+ /* Log2 ceiling of size. */
+ while (new_size < min_size) new_size *= 2;
+
+ new_bytes = new_size << elem_size_lg2;
+ ptr = upb_arena_realloc(arena, ptr, old_bytes, new_bytes);
+
+ if (!ptr) {
+ return false;
+ }
+
+ arr->data = tag_arrptr(ptr, elem_size_lg2);
+ arr->size = new_size;
+ return true;
+}
+
+static upb_array *getorcreate_array(upb_array **arr_ptr, upb_fieldtype_t type,
+ upb_arena *arena) {
+ upb_array *arr = *arr_ptr;
+ if (!arr) {
+ arr = _upb_array_new(arena, type);
+ if (!arr) return NULL;
+ *arr_ptr = arr;
+ }
+ return arr;
+}
+
+void *_upb_array_resize_fallback(upb_array **arr_ptr, size_t size,
+ upb_fieldtype_t type, upb_arena *arena) {
+ upb_array *arr = getorcreate_array(arr_ptr, type, arena);
+ return arr && _upb_array_resize(arr, size, arena) ? _upb_array_ptr(arr) : NULL;
+}
+
+bool _upb_array_append_fallback(upb_array **arr_ptr, const void *value,
+ upb_fieldtype_t type, upb_arena *arena) {
+ upb_array *arr = getorcreate_array(arr_ptr, type, arena);
+ size_t elem = arr->len;
+ int lg2 = _upb_fieldtype_to_sizelg2[type];
+ char *data;
+
+ if (!arr || !_upb_array_resize(arr, elem + 1, arena)) return false;
+
+ data = _upb_array_ptr(arr);
+ memcpy(data + (elem << lg2), value, 1 << lg2);
+ return true;
+}
+
+/** upb_map *******************************************************************/
+
+upb_map *_upb_map_new(upb_arena *a, size_t key_size, size_t value_size) {
+ upb_map *map = upb_arena_malloc(a, sizeof(upb_map));
+
+ if (!map) {
+ return NULL;
+ }
+
+ upb_strtable_init2(&map->table, UPB_CTYPE_INT32, upb_arena_alloc(a));
+ map->key_size = key_size;
+ map->val_size = value_size;
+
+ return map;
+}
+/*
+** upb_table Implementation
+**
+** Implementation is heavily inspired by Lua's ltable.c.
+*/
+
+
+#include
+
+
+#define UPB_MAXARRSIZE 16 /* 64k. */
+
+/* From Chromium. */
+#define ARRAY_SIZE(x) \
+ ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
+
+static const double MAX_LOAD = 0.85;
+
+/* The minimum utilization of the array part of a mixed hash/array table. This
+ * is a speed/memory-usage tradeoff (though it's not straightforward because of
+ * cache effects). The lower this is, the more memory we'll use. */
+static const double MIN_DENSITY = 0.1;
+
+bool is_pow2(uint64_t v) { return v == 0 || (v & (v - 1)) == 0; }
+
+int log2ceil(uint64_t v) {
+ int ret = 0;
+ bool pow2 = is_pow2(v);
+ while (v >>= 1) ret++;
+ ret = pow2 ? ret : ret + 1; /* Ceiling. */
+ return UPB_MIN(UPB_MAXARRSIZE, ret);
+}
+
+char *upb_strdup(const char *s, upb_alloc *a) {
+ return upb_strdup2(s, strlen(s), a);
+}
+
+char *upb_strdup2(const char *s, size_t len, upb_alloc *a) {
+ size_t n;
+ char *p;
+
+ /* Prevent overflow errors. */
+ if (len == SIZE_MAX) return NULL;
+ /* Always null-terminate, even if binary data; but don't rely on the input to
+ * have a null-terminating byte since it may be a raw binary buffer. */
+ n = len + 1;
+ p = upb_malloc(a, n);
+ if (p) {
+ memcpy(p, s, len);
+ p[len] = 0;
+ }
+ return p;
+}
+
+/* A type to represent the lookup key of either a strtable or an inttable. */
+typedef union {
+ uintptr_t num;
+ struct {
+ const char *str;
+ size_t len;
+ } str;
+} lookupkey_t;
+
+static lookupkey_t strkey2(const char *str, size_t len) {
+ lookupkey_t k;
+ k.str.str = str;
+ k.str.len = len;
+ return k;
+}
+
+static lookupkey_t intkey(uintptr_t key) {
+ lookupkey_t k;
+ k.num = key;
+ return k;
+}
+
+typedef uint32_t hashfunc_t(upb_tabkey key);
+typedef bool eqlfunc_t(upb_tabkey k1, lookupkey_t k2);
+
+/* Base table (shared code) ***************************************************/
+
+/* For when we need to cast away const. */
+static upb_tabent *mutable_entries(upb_table *t) {
+ return (upb_tabent*)t->entries;
+}
+
+static bool isfull(upb_table *t) {
+ if (upb_table_size(t) == 0) {
+ return true;
+ } else {
+ return ((double)(t->count + 1) / upb_table_size(t)) > MAX_LOAD;
+ }
+}
+
+static bool init(upb_table *t, uint8_t size_lg2, upb_alloc *a) {
+ size_t bytes;
+
+ t->count = 0;
+ t->size_lg2 = size_lg2;
+ t->mask = upb_table_size(t) ? upb_table_size(t) - 1 : 0;
+ bytes = upb_table_size(t) * sizeof(upb_tabent);
+ if (bytes > 0) {
+ t->entries = upb_malloc(a, bytes);
+ if (!t->entries) return false;
+ memset(mutable_entries(t), 0, bytes);
+ } else {
+ t->entries = NULL;
+ }
+ return true;
+}
+
+static void uninit(upb_table *t, upb_alloc *a) {
+ upb_free(a, mutable_entries(t));
+}
+
+static upb_tabent *emptyent(upb_table *t) {
+ upb_tabent *e = mutable_entries(t) + upb_table_size(t);
+ while (1) { if (upb_tabent_isempty(--e)) return e; UPB_ASSERT(e > t->entries); }
+}
+
+static upb_tabent *getentry_mutable(upb_table *t, uint32_t hash) {
+ return (upb_tabent*)upb_getentry(t, hash);
+}
+
+static const upb_tabent *findentry(const upb_table *t, lookupkey_t key,
+ uint32_t hash, eqlfunc_t *eql) {
+ const upb_tabent *e;
+
+ if (t->size_lg2 == 0) return NULL;
+ e = upb_getentry(t, hash);
+ if (upb_tabent_isempty(e)) return NULL;
+ while (1) {
+ if (eql(e->key, key)) return e;
+ if ((e = e->next) == NULL) return NULL;
+ }
+}
+
+static upb_tabent *findentry_mutable(upb_table *t, lookupkey_t key,
+ uint32_t hash, eqlfunc_t *eql) {
+ return (upb_tabent*)findentry(t, key, hash, eql);
+}
+
+static bool lookup(const upb_table *t, lookupkey_t key, upb_value *v,
+ uint32_t hash, eqlfunc_t *eql) {
+ const upb_tabent *e = findentry(t, key, hash, eql);
+ if (e) {
+ if (v) {
+ _upb_value_setval(v, e->val.val);
+ }
+ return true;
+ } else {
+ return false;
+ }
+}
+
+/* The given key must not already exist in the table. */
+static void insert(upb_table *t, lookupkey_t key, upb_tabkey tabkey,
+ upb_value val, uint32_t hash,
+ hashfunc_t *hashfunc, eqlfunc_t *eql) {
+ upb_tabent *mainpos_e;
+ upb_tabent *our_e;
+
+ UPB_ASSERT(findentry(t, key, hash, eql) == NULL);
+
+ t->count++;
+ mainpos_e = getentry_mutable(t, hash);
+ our_e = mainpos_e;
+
+ if (upb_tabent_isempty(mainpos_e)) {
+ /* Our main position is empty; use it. */
+ our_e->next = NULL;
+ } else {
+ /* Collision. */
+ upb_tabent *new_e = emptyent(t);
+ /* Head of collider's chain. */
+ upb_tabent *chain = getentry_mutable(t, hashfunc(mainpos_e->key));
+ if (chain == mainpos_e) {
+ /* Existing ent is in its main posisiton (it has the same hash as us, and
+ * is the head of our chain). Insert to new ent and append to this chain. */
+ new_e->next = mainpos_e->next;
+ mainpos_e->next = new_e;
+ our_e = new_e;
+ } else {
+ /* Existing ent is not in its main position (it is a node in some other
+ * chain). This implies that no existing ent in the table has our hash.
+ * Evict it (updating its chain) and use its ent for head of our chain. */
+ *new_e = *mainpos_e; /* copies next. */
+ while (chain->next != mainpos_e) {
+ chain = (upb_tabent*)chain->next;
+ UPB_ASSERT(chain);
+ }
+ chain->next = new_e;
+ our_e = mainpos_e;
+ our_e->next = NULL;
+ }
+ }
+ our_e->key = tabkey;
+ our_e->val.val = val.val;
+ UPB_ASSERT(findentry(t, key, hash, eql) == our_e);
+}
+
+static bool rm(upb_table *t, lookupkey_t key, upb_value *val,
+ upb_tabkey *removed, uint32_t hash, eqlfunc_t *eql) {
+ upb_tabent *chain = getentry_mutable(t, hash);
+ if (upb_tabent_isempty(chain)) return false;
+ if (eql(chain->key, key)) {
+ /* Element to remove is at the head of its chain. */
+ t->count--;
+ if (val) _upb_value_setval(val, chain->val.val);
+ if (removed) *removed = chain->key;
+ if (chain->next) {
+ upb_tabent *move = (upb_tabent*)chain->next;
+ *chain = *move;
+ move->key = 0; /* Make the slot empty. */
+ } else {
+ chain->key = 0; /* Make the slot empty. */
+ }
+ return true;
+ } else {
+ /* Element to remove is either in a non-head position or not in the
+ * table. */
+ while (chain->next && !eql(chain->next->key, key)) {
+ chain = (upb_tabent*)chain->next;
+ }
+ if (chain->next) {
+ /* Found element to remove. */
+ upb_tabent *rm = (upb_tabent*)chain->next;
+ t->count--;
+ if (val) _upb_value_setval(val, chain->next->val.val);
+ if (removed) *removed = rm->key;
+ rm->key = 0; /* Make the slot empty. */
+ chain->next = rm->next;
+ return true;
+ } else {
+ /* Element to remove is not in the table. */
+ return false;
+ }
+ }
+}
+
+static size_t next(const upb_table *t, size_t i) {
+ do {
+ if (++i >= upb_table_size(t))
+ return SIZE_MAX - 1; /* Distinct from -1. */
+ } while(upb_tabent_isempty(&t->entries[i]));
+
+ return i;
+}
+
+static size_t begin(const upb_table *t) {
+ return next(t, -1);
+}
+
+
+/* upb_strtable ***************************************************************/
+
+/* A simple "subclass" of upb_table that only adds a hash function for strings. */
+
+static upb_tabkey strcopy(lookupkey_t k2, upb_alloc *a) {
+ uint32_t len = (uint32_t) k2.str.len;
+ char *str = upb_malloc(a, k2.str.len + sizeof(uint32_t) + 1);
+ if (str == NULL) return 0;
+ memcpy(str, &len, sizeof(uint32_t));
+ if (k2.str.len) memcpy(str + sizeof(uint32_t), k2.str.str, k2.str.len);
+ str[sizeof(uint32_t) + k2.str.len] = '\0';
+ return (uintptr_t)str;
+}
+
+static uint32_t strhash(upb_tabkey key) {
+ uint32_t len;
+ char *str = upb_tabstr(key, &len);
+ return upb_murmur_hash2(str, len, 0);
+}
+
+static bool streql(upb_tabkey k1, lookupkey_t k2) {
+ uint32_t len;
+ char *str = upb_tabstr(k1, &len);
+ return len == k2.str.len && (len == 0 || memcmp(str, k2.str.str, len) == 0);
+}
+
+bool upb_strtable_init2(upb_strtable *t, upb_ctype_t ctype, upb_alloc *a) {
+ UPB_UNUSED(ctype); /* TODO(haberman): rm */
+ return init(&t->t, 2, a);
+}
+
+void upb_strtable_clear(upb_strtable *t) {
+ size_t bytes = upb_table_size(&t->t) * sizeof(upb_tabent);
+ t->t.count = 0;
+ memset((char*)t->t.entries, 0, bytes);
+}
+
+void upb_strtable_uninit2(upb_strtable *t, upb_alloc *a) {
+ size_t i;
+ for (i = 0; i < upb_table_size(&t->t); i++)
+ upb_free(a, (void*)t->t.entries[i].key);
+ uninit(&t->t, a);
+}
+
+bool upb_strtable_resize(upb_strtable *t, size_t size_lg2, upb_alloc *a) {
+ upb_strtable new_table;
+ upb_strtable_iter i;
+
+ if (!init(&new_table.t, size_lg2, a))
+ return false;
+ upb_strtable_begin(&i, t);
+ for ( ; !upb_strtable_done(&i); upb_strtable_next(&i)) {
+ upb_strview key = upb_strtable_iter_key(&i);
+ upb_strtable_insert3(
+ &new_table, key.data, key.size,
+ upb_strtable_iter_value(&i), a);
+ }
+ upb_strtable_uninit2(t, a);
+ *t = new_table;
+ return true;
+}
+
+bool upb_strtable_insert3(upb_strtable *t, const char *k, size_t len,
+ upb_value v, upb_alloc *a) {
+ lookupkey_t key;
+ upb_tabkey tabkey;
+ uint32_t hash;
+
+ if (isfull(&t->t)) {
+ /* Need to resize. New table of double the size, add old elements to it. */
+ if (!upb_strtable_resize(t, t->t.size_lg2 + 1, a)) {
+ return false;
+ }
+ }
+
+ key = strkey2(k, len);
+ tabkey = strcopy(key, a);
+ if (tabkey == 0) return false;
+
+ hash = upb_murmur_hash2(key.str.str, key.str.len, 0);
+ insert(&t->t, key, tabkey, v, hash, &strhash, &streql);
+ return true;
+}
+
+bool upb_strtable_lookup2(const upb_strtable *t, const char *key, size_t len,
+ upb_value *v) {
+ uint32_t hash = upb_murmur_hash2(key, len, 0);
+ return lookup(&t->t, strkey2(key, len), v, hash, &streql);
+}
+
+bool upb_strtable_remove3(upb_strtable *t, const char *key, size_t len,
+ upb_value *val, upb_alloc *alloc) {
+ uint32_t hash = upb_murmur_hash2(key, len, 0);
+ upb_tabkey tabkey;
+ if (rm(&t->t, strkey2(key, len), val, &tabkey, hash, &streql)) {
+ if (alloc) {
+ /* Arena-based allocs don't need to free and won't pass this. */
+ upb_free(alloc, (void*)tabkey);
+ }
+ return true;
+ } else {
+ return false;
+ }
+}
+
+/* Iteration */
+
+void upb_strtable_begin(upb_strtable_iter *i, const upb_strtable *t) {
+ i->t = t;
+ i->index = begin(&t->t);
+}
+
+void upb_strtable_next(upb_strtable_iter *i) {
+ i->index = next(&i->t->t, i->index);
+}
+
+bool upb_strtable_done(const upb_strtable_iter *i) {
+ if (!i->t) return true;
+ return i->index >= upb_table_size(&i->t->t) ||
+ upb_tabent_isempty(str_tabent(i));
+}
+
+upb_strview upb_strtable_iter_key(const upb_strtable_iter *i) {
+ upb_strview key;
+ uint32_t len;
+ UPB_ASSERT(!upb_strtable_done(i));
+ key.data = upb_tabstr(str_tabent(i)->key, &len);
+ key.size = len;
+ return key;
+}
+
+upb_value upb_strtable_iter_value(const upb_strtable_iter *i) {
+ UPB_ASSERT(!upb_strtable_done(i));
+ return _upb_value_val(str_tabent(i)->val.val);
+}
+
+void upb_strtable_iter_setdone(upb_strtable_iter *i) {
+ i->t = NULL;
+ i->index = SIZE_MAX;
+}
+
+bool upb_strtable_iter_isequal(const upb_strtable_iter *i1,
+ const upb_strtable_iter *i2) {
+ if (upb_strtable_done(i1) && upb_strtable_done(i2))
+ return true;
+ return i1->t == i2->t && i1->index == i2->index;
+}
+
+
+/* upb_inttable ***************************************************************/
+
+/* For inttables we use a hybrid structure where small keys are kept in an
+ * array and large keys are put in the hash table. */
+
+static uint32_t inthash(upb_tabkey key) { return upb_inthash(key); }
+
+static bool inteql(upb_tabkey k1, lookupkey_t k2) {
+ return k1 == k2.num;
+}
+
+static upb_tabval *mutable_array(upb_inttable *t) {
+ return (upb_tabval*)t->array;
+}
+
+static upb_tabval *inttable_val(upb_inttable *t, uintptr_t key) {
+ if (key < t->array_size) {
+ return upb_arrhas(t->array[key]) ? &(mutable_array(t)[key]) : NULL;
+ } else {
+ upb_tabent *e =
+ findentry_mutable(&t->t, intkey(key), upb_inthash(key), &inteql);
+ return e ? &e->val : NULL;
+ }
+}
+
+static const upb_tabval *inttable_val_const(const upb_inttable *t,
+ uintptr_t key) {
+ return inttable_val((upb_inttable*)t, key);
+}
+
+size_t upb_inttable_count(const upb_inttable *t) {
+ return t->t.count + t->array_count;
+}
+
+static void check(upb_inttable *t) {
+ UPB_UNUSED(t);
+#if defined(UPB_DEBUG_TABLE) && !defined(NDEBUG)
+ {
+ /* This check is very expensive (makes inserts/deletes O(N)). */
+ size_t count = 0;
+ upb_inttable_iter i;
+ upb_inttable_begin(&i, t);
+ for(; !upb_inttable_done(&i); upb_inttable_next(&i), count++) {
+ UPB_ASSERT(upb_inttable_lookup(t, upb_inttable_iter_key(&i), NULL));
+ }
+ UPB_ASSERT(count == upb_inttable_count(t));
+ }
+#endif
+}
+
+bool upb_inttable_sizedinit(upb_inttable *t, size_t asize, int hsize_lg2,
+ upb_alloc *a) {
+ size_t array_bytes;
+
+ if (!init(&t->t, hsize_lg2, a)) return false;
+ /* Always make the array part at least 1 long, so that we know key 0
+ * won't be in the hash part, which simplifies things. */
+ t->array_size = UPB_MAX(1, asize);
+ t->array_count = 0;
+ array_bytes = t->array_size * sizeof(upb_value);
+ t->array = upb_malloc(a, array_bytes);
+ if (!t->array) {
+ uninit(&t->t, a);
+ return false;
+ }
+ memset(mutable_array(t), 0xff, array_bytes);
+ check(t);
+ return true;
+}
+
+bool upb_inttable_init2(upb_inttable *t, upb_ctype_t ctype, upb_alloc *a) {
+ UPB_UNUSED(ctype); /* TODO(haberman): rm */
+ return upb_inttable_sizedinit(t, 0, 4, a);
+}
+
+void upb_inttable_uninit2(upb_inttable *t, upb_alloc *a) {
+ uninit(&t->t, a);
+ upb_free(a, mutable_array(t));
+}
+
+bool upb_inttable_insert2(upb_inttable *t, uintptr_t key, upb_value val,
+ upb_alloc *a) {
+ upb_tabval tabval;
+ tabval.val = val.val;
+ UPB_ASSERT(upb_arrhas(tabval)); /* This will reject (uint64_t)-1. Fix this. */
+
+ if (key < t->array_size) {
+ UPB_ASSERT(!upb_arrhas(t->array[key]));
+ t->array_count++;
+ mutable_array(t)[key].val = val.val;
+ } else {
+ if (isfull(&t->t)) {
+ /* Need to resize the hash part, but we re-use the array part. */
+ size_t i;
+ upb_table new_table;
+
+ if (!init(&new_table, t->t.size_lg2 + 1, a)) {
+ return false;
+ }
+
+ for (i = begin(&t->t); i < upb_table_size(&t->t); i = next(&t->t, i)) {
+ const upb_tabent *e = &t->t.entries[i];
+ uint32_t hash;
+ upb_value v;
+
+ _upb_value_setval(&v, e->val.val);
+ hash = upb_inthash(e->key);
+ insert(&new_table, intkey(e->key), e->key, v, hash, &inthash, &inteql);
+ }
+
+ UPB_ASSERT(t->t.count == new_table.count);
+
+ uninit(&t->t, a);
+ t->t = new_table;
+ }
+ insert(&t->t, intkey(key), key, val, upb_inthash(key), &inthash, &inteql);
+ }
+ check(t);
+ return true;
+}
+
+bool upb_inttable_lookup(const upb_inttable *t, uintptr_t key, upb_value *v) {
+ const upb_tabval *table_v = inttable_val_const(t, key);
+ if (!table_v) return false;
+ if (v) _upb_value_setval(v, table_v->val);
+ return true;
+}
+
+bool upb_inttable_replace(upb_inttable *t, uintptr_t key, upb_value val) {
+ upb_tabval *table_v = inttable_val(t, key);
+ if (!table_v) return false;
+ table_v->val = val.val;
+ return true;
+}
+
+bool upb_inttable_remove(upb_inttable *t, uintptr_t key, upb_value *val) {
+ bool success;
+ if (key < t->array_size) {
+ if (upb_arrhas(t->array[key])) {
+ upb_tabval empty = UPB_TABVALUE_EMPTY_INIT;
+ t->array_count--;
+ if (val) {
+ _upb_value_setval(val, t->array[key].val);
+ }
+ mutable_array(t)[key] = empty;
+ success = true;
+ } else {
+ success = false;
+ }
+ } else {
+ success = rm(&t->t, intkey(key), val, NULL, upb_inthash(key), &inteql);
+ }
+ check(t);
+ return success;
+}
+
+bool upb_inttable_push2(upb_inttable *t, upb_value val, upb_alloc *a) {
+ return upb_inttable_insert2(t, upb_inttable_count(t), val, a);
+}
+
+upb_value upb_inttable_pop(upb_inttable *t) {
+ upb_value val;
+ bool ok = upb_inttable_remove(t, upb_inttable_count(t) - 1, &val);
+ UPB_ASSERT(ok);
+ return val;
+}
+
+bool upb_inttable_insertptr2(upb_inttable *t, const void *key, upb_value val,
+ upb_alloc *a) {
+ return upb_inttable_insert2(t, (uintptr_t)key, val, a);
+}
+
+bool upb_inttable_lookupptr(const upb_inttable *t, const void *key,
+ upb_value *v) {
+ return upb_inttable_lookup(t, (uintptr_t)key, v);
+}
+
+bool upb_inttable_removeptr(upb_inttable *t, const void *key, upb_value *val) {
+ return upb_inttable_remove(t, (uintptr_t)key, val);
+}
+
+void upb_inttable_compact2(upb_inttable *t, upb_alloc *a) {
+ /* A power-of-two histogram of the table keys. */
+ size_t counts[UPB_MAXARRSIZE + 1] = {0};
+
+ /* The max key in each bucket. */
+ uintptr_t max[UPB_MAXARRSIZE + 1] = {0};
+
+ upb_inttable_iter i;
+ size_t arr_count;
+ int size_lg2;
+ upb_inttable new_t;
+
+ upb_inttable_begin(&i, t);
+ for (; !upb_inttable_done(&i); upb_inttable_next(&i)) {
+ uintptr_t key = upb_inttable_iter_key(&i);
+ int bucket = log2ceil(key);
+ max[bucket] = UPB_MAX(max[bucket], key);
+ counts[bucket]++;
+ }
+
+ /* Find the largest power of two that satisfies the MIN_DENSITY
+ * definition (while actually having some keys). */
+ arr_count = upb_inttable_count(t);
+
+ for (size_lg2 = ARRAY_SIZE(counts) - 1; size_lg2 > 0; size_lg2--) {
+ if (counts[size_lg2] == 0) {
+ /* We can halve again without losing any entries. */
+ continue;
+ } else if (arr_count >= (1 << size_lg2) * MIN_DENSITY) {
+ break;
+ }
+
+ arr_count -= counts[size_lg2];
+ }
+
+ UPB_ASSERT(arr_count <= upb_inttable_count(t));
+
+ {
+ /* Insert all elements into new, perfectly-sized table. */
+ size_t arr_size = max[size_lg2] + 1; /* +1 so arr[max] will fit. */
+ size_t hash_count = upb_inttable_count(t) - arr_count;
+ size_t hash_size = hash_count ? (hash_count / MAX_LOAD) + 1 : 0;
+ int hashsize_lg2 = log2ceil(hash_size);
+
+ upb_inttable_sizedinit(&new_t, arr_size, hashsize_lg2, a);
+ upb_inttable_begin(&i, t);
+ for (; !upb_inttable_done(&i); upb_inttable_next(&i)) {
+ uintptr_t k = upb_inttable_iter_key(&i);
+ upb_inttable_insert2(&new_t, k, upb_inttable_iter_value(&i), a);
+ }
+ UPB_ASSERT(new_t.array_size == arr_size);
+ UPB_ASSERT(new_t.t.size_lg2 == hashsize_lg2);
+ }
+ upb_inttable_uninit2(t, a);
+ *t = new_t;
+}
+
+/* Iteration. */
+
+static const upb_tabent *int_tabent(const upb_inttable_iter *i) {
+ UPB_ASSERT(!i->array_part);
+ return &i->t->t.entries[i->index];
+}
+
+static upb_tabval int_arrent(const upb_inttable_iter *i) {
+ UPB_ASSERT(i->array_part);
+ return i->t->array[i->index];
+}
+
+void upb_inttable_begin(upb_inttable_iter *i, const upb_inttable *t) {
+ i->t = t;
+ i->index = -1;
+ i->array_part = true;
+ upb_inttable_next(i);
+}
+
+void upb_inttable_next(upb_inttable_iter *iter) {
+ const upb_inttable *t = iter->t;
+ if (iter->array_part) {
+ while (++iter->index < t->array_size) {
+ if (upb_arrhas(int_arrent(iter))) {
+ return;
+ }
+ }
+ iter->array_part = false;
+ iter->index = begin(&t->t);
+ } else {
+ iter->index = next(&t->t, iter->index);
+ }
+}
+
+bool upb_inttable_done(const upb_inttable_iter *i) {
+ if (!i->t) return true;
+ if (i->array_part) {
+ return i->index >= i->t->array_size ||
+ !upb_arrhas(int_arrent(i));
+ } else {
+ return i->index >= upb_table_size(&i->t->t) ||
+ upb_tabent_isempty(int_tabent(i));
+ }
+}
+
+uintptr_t upb_inttable_iter_key(const upb_inttable_iter *i) {
+ UPB_ASSERT(!upb_inttable_done(i));
+ return i->array_part ? i->index : int_tabent(i)->key;
+}
+
+upb_value upb_inttable_iter_value(const upb_inttable_iter *i) {
+ UPB_ASSERT(!upb_inttable_done(i));
+ return _upb_value_val(
+ i->array_part ? i->t->array[i->index].val : int_tabent(i)->val.val);
+}
+
+void upb_inttable_iter_setdone(upb_inttable_iter *i) {
+ i->t = NULL;
+ i->index = SIZE_MAX;
+ i->array_part = false;
+}
+
+bool upb_inttable_iter_isequal(const upb_inttable_iter *i1,
+ const upb_inttable_iter *i2) {
+ if (upb_inttable_done(i1) && upb_inttable_done(i2))
+ return true;
+ return i1->t == i2->t && i1->index == i2->index &&
+ i1->array_part == i2->array_part;
+}
+
+#if defined(UPB_UNALIGNED_READS_OK) || defined(__s390x__)
+/* -----------------------------------------------------------------------------
+ * MurmurHash2, by Austin Appleby (released as public domain).
+ * Reformatted and C99-ified by Joshua Haberman.
+ * Note - This code makes a few assumptions about how your machine behaves -
+ * 1. We can read a 4-byte value from any address without crashing
+ * 2. sizeof(int) == 4 (in upb this limitation is removed by using uint32_t
+ * And it has a few limitations -
+ * 1. It will not work incrementally.
+ * 2. It will not produce the same results on little-endian and big-endian
+ * machines. */
+uint32_t upb_murmur_hash2(const void *key, size_t len, uint32_t seed) {
+ /* 'm' and 'r' are mixing constants generated offline.
+ * They're not really 'magic', they just happen to work well. */
+ const uint32_t m = 0x5bd1e995;
+ const int32_t r = 24;
+
+ /* Initialize the hash to a 'random' value */
+ uint32_t h = seed ^ len;
+
+ /* Mix 4 bytes at a time into the hash */
+ const uint8_t * data = (const uint8_t *)key;
+ while(len >= 4) {
+ uint32_t k;
+ memcpy(&k, data, sizeof(k));
+
+ k *= m;
+ k ^= k >> r;
+ k *= m;
+
+ h *= m;
+ h ^= k;
+
+ data += 4;
+ len -= 4;
+ }
+
+ /* Handle the last few bytes of the input array */
+ switch(len) {
+ case 3: h ^= data[2] << 16;
+ case 2: h ^= data[1] << 8;
+ case 1: h ^= data[0]; h *= m;
+ };
+
+ /* Do a few final mixes of the hash to ensure the last few
+ * bytes are well-incorporated. */
+ h ^= h >> 13;
+ h *= m;
+ h ^= h >> 15;
+
+ return h;
+}
+
+#else /* !UPB_UNALIGNED_READS_OK */
+
+/* -----------------------------------------------------------------------------
+ * MurmurHashAligned2, by Austin Appleby
+ * Same algorithm as MurmurHash2, but only does aligned reads - should be safer
+ * on certain platforms.
+ * Performance will be lower than MurmurHash2 */
+
+#define MIX(h,k,m) { k *= m; k ^= k >> r; k *= m; h *= m; h ^= k; }
+
+uint32_t upb_murmur_hash2(const void * key, size_t len, uint32_t seed) {
+ const uint32_t m = 0x5bd1e995;
+ const int32_t r = 24;
+ const uint8_t * data = (const uint8_t *)key;
+ uint32_t h = (uint32_t)(seed ^ len);
+ uint8_t align = (uintptr_t)data & 3;
+
+ if(align && (len >= 4)) {
+ /* Pre-load the temp registers */
+ uint32_t t = 0, d = 0;
+ int32_t sl;
+ int32_t sr;
+
+ switch(align) {
+ case 1: t |= data[2] << 16; /* fallthrough */
+ case 2: t |= data[1] << 8; /* fallthrough */
+ case 3: t |= data[0];
+ }
+
+ t <<= (8 * align);
+
+ data += 4-align;
+ len -= 4-align;
+
+ sl = 8 * (4-align);
+ sr = 8 * align;
+
+ /* Mix */
+
+ while(len >= 4) {
+ uint32_t k;
+
+ d = *(uint32_t *)data;
+ t = (t >> sr) | (d << sl);
+
+ k = t;
+
+ MIX(h,k,m);
+
+ t = d;
+
+ data += 4;
+ len -= 4;
+ }
+
+ /* Handle leftover data in temp registers */
+
+ d = 0;
+
+ if(len >= align) {
+ uint32_t k;
+
+ switch(align) {
+ case 3: d |= data[2] << 16; /* fallthrough */
+ case 2: d |= data[1] << 8; /* fallthrough */
+ case 1: d |= data[0]; /* fallthrough */
+ }
+
+ k = (t >> sr) | (d << sl);
+ MIX(h,k,m);
+
+ data += align;
+ len -= align;
+
+ /* ----------
+ * Handle tail bytes */
+
+ switch(len) {
+ case 3: h ^= data[2] << 16; /* fallthrough */
+ case 2: h ^= data[1] << 8; /* fallthrough */
+ case 1: h ^= data[0]; h *= m; /* fallthrough */
+ };
+ } else {
+ switch(len) {
+ case 3: d |= data[2] << 16; /* fallthrough */
+ case 2: d |= data[1] << 8; /* fallthrough */
+ case 1: d |= data[0]; /* fallthrough */
+ case 0: h ^= (t >> sr) | (d << sl); h *= m;
+ }
+ }
+
+ h ^= h >> 13;
+ h *= m;
+ h ^= h >> 15;
+
+ return h;
+ } else {
+ while(len >= 4) {
+ uint32_t k = *(uint32_t *)data;
+
+ MIX(h,k,m);
+
+ data += 4;
+ len -= 4;
+ }
+
+ /* ----------
+ * Handle tail bytes */
+
+ switch(len) {
+ case 3: h ^= data[2] << 16; /* fallthrough */
+ case 2: h ^= data[1] << 8; /* fallthrough */
+ case 1: h ^= data[0]; h *= m;
+ };
+
+ h ^= h >> 13;
+ h *= m;
+ h ^= h >> 15;
+
+ return h;
+ }
+}
+#undef MIX
+
+#endif /* UPB_UNALIGNED_READS_OK */
+
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+
+/* upb_status *****************************************************************/
+
+void upb_status_clear(upb_status *status) {
+ if (!status) return;
+ status->ok = true;
+ status->msg[0] = '\0';
+}
+
+bool upb_ok(const upb_status *status) { return status->ok; }
+
+const char *upb_status_errmsg(const upb_status *status) { return status->msg; }
+
+void upb_status_seterrmsg(upb_status *status, const char *msg) {
+ if (!status) return;
+ status->ok = false;
+ strncpy(status->msg, msg, UPB_STATUS_MAX_MESSAGE - 1);
+ status->msg[UPB_STATUS_MAX_MESSAGE - 1] = '\0';
+}
+
+void upb_status_seterrf(upb_status *status, const char *fmt, ...) {
+ va_list args;
+ va_start(args, fmt);
+ upb_status_vseterrf(status, fmt, args);
+ va_end(args);
+}
+
+void upb_status_vseterrf(upb_status *status, const char *fmt, va_list args) {
+ if (!status) return;
+ status->ok = false;
+ _upb_vsnprintf(status->msg, sizeof(status->msg), fmt, args);
+ status->msg[UPB_STATUS_MAX_MESSAGE - 1] = '\0';
+}
+
+void upb_status_vappenderrf(upb_status *status, const char *fmt, va_list args) {
+ size_t len;
+ if (!status) return;
+ status->ok = false;
+ len = strlen(status->msg);
+ _upb_vsnprintf(status->msg + len, sizeof(status->msg) - len, fmt, args);
+ status->msg[UPB_STATUS_MAX_MESSAGE - 1] = '\0';
+}
+
+/* upb_alloc ******************************************************************/
+
+static void *upb_global_allocfunc(upb_alloc *alloc, void *ptr, size_t oldsize,
+ size_t size) {
+ UPB_UNUSED(alloc);
+ UPB_UNUSED(oldsize);
+ if (size == 0) {
+ free(ptr);
+ return NULL;
+ } else {
+ return realloc(ptr, size);
+ }
+}
+
+upb_alloc upb_alloc_global = {&upb_global_allocfunc};
+
+/* upb_arena ******************************************************************/
+
+/* Be conservative and choose 16 in case anyone is using SSE. */
+
+typedef struct mem_block {
+ struct mem_block *next;
+ uint32_t size;
+ uint32_t cleanups;
+ /* Data follows. */
+} mem_block;
+
+typedef struct cleanup_ent {
+ upb_cleanup_func *cleanup;
+ void *ud;
+} cleanup_ent;
+
+struct upb_arena {
+ _upb_arena_head head;
+ uint32_t *cleanups;
+
+ /* Allocator to allocate arena blocks. We are responsible for freeing these
+ * when we are destroyed. */
+ upb_alloc *block_alloc;
+ uint32_t last_size;
+
+ /* When multiple arenas are fused together, each arena points to a parent
+ * arena (root points to itself). The root tracks how many live arenas
+ * reference it. */
+ uint32_t refcount; /* Only used when a->parent == a */
+ struct upb_arena *parent;
+
+ /* Linked list of blocks to free/cleanup. */
+ mem_block *freelist, *freelist_tail;
+};
+
+static const size_t memblock_reserve = UPB_ALIGN_UP(sizeof(mem_block), 16);
+
+static void upb_arena_addblock(upb_arena *a, void *ptr, size_t size) {
+ mem_block *block = ptr;
+
+ block->next = a->freelist;
+ block->size = (uint32_t)size;
+ block->cleanups = 0;
+ a->freelist = block;
+ a->last_size = block->size;
+ if (!a->freelist_tail) a->freelist_tail = block;
+
+ a->head.ptr = UPB_PTR_AT(block, memblock_reserve, char);
+ a->head.end = UPB_PTR_AT(block, size, char);
+ a->cleanups = &block->cleanups;
+
+ /* TODO(haberman): ASAN poison. */
+}
+
+static bool upb_arena_allocblock(upb_arena *a, size_t size) {
+ size_t block_size = UPB_MAX(size, a->last_size * 2) + memblock_reserve;
+ mem_block *block = upb_malloc(a->block_alloc, block_size);
+
+ if (!block) return false;
+ upb_arena_addblock(a, block, block_size);
+ return true;
+}
+
+static bool arena_has(upb_arena *a, size_t size) {
+ _upb_arena_head *h = (_upb_arena_head*)a;
+ return (size_t)(h->end - h->ptr) >= size;
+}
+
+void *_upb_arena_slowmalloc(upb_arena *a, size_t size) {
+ if (!upb_arena_allocblock(a, size)) return NULL; /* Out of memory. */
+ UPB_ASSERT(arena_has(a, size));
+ return upb_arena_malloc(a, size);
+}
+
+static void *upb_arena_doalloc(upb_alloc *alloc, void *ptr, size_t oldsize,
+ size_t size) {
+ upb_arena *a = (upb_arena*)alloc; /* upb_alloc is initial member. */
+ return upb_arena_realloc(a, ptr, oldsize, size);
+}
+
+static upb_arena *arena_findroot(upb_arena *a) {
+ /* Path splitting keeps time complexity down, see:
+ * https://en.wikipedia.org/wiki/Disjoint-set_data_structure */
+ while (a->parent != a) {
+ upb_arena *next = a->parent;
+ a->parent = next->parent;
+ a = next;
+ }
+ return a;
+}
+
+/* Public Arena API ***********************************************************/
+
+upb_arena *arena_initslow(void *mem, size_t n, upb_alloc *alloc) {
+ const size_t first_block_overhead = sizeof(upb_arena) + memblock_reserve;
+ upb_arena *a;
+
+ /* We need to malloc the initial block. */
+ n = first_block_overhead + 256;
+ if (!alloc || !(mem = upb_malloc(alloc, n))) {
+ return NULL;
+ }
+
+ a = UPB_PTR_AT(mem, n - sizeof(*a), upb_arena);
+ n -= sizeof(*a);
+
+ a->head.alloc.func = &upb_arena_doalloc;
+ a->block_alloc = alloc;
+ a->parent = a;
+ a->refcount = 1;
+ a->freelist = NULL;
+ a->freelist_tail = NULL;
+
+ upb_arena_addblock(a, mem, n);
+
+ return a;
+}
+
+upb_arena *upb_arena_init(void *mem, size_t n, upb_alloc *alloc) {
+ upb_arena *a;
+
+ /* Round block size down to alignof(*a) since we will allocate the arena
+ * itself at the end. */
+ n = UPB_ALIGN_DOWN(n, UPB_ALIGN_OF(upb_arena));
+
+ if (UPB_UNLIKELY(n < sizeof(upb_arena))) {
+ return arena_initslow(mem, n, alloc);
+ }
+
+ a = UPB_PTR_AT(mem, n - sizeof(*a), upb_arena);
+ n -= sizeof(*a);
+
+ a->head.alloc.func = &upb_arena_doalloc;
+ a->block_alloc = alloc;
+ a->parent = a;
+ a->refcount = 1;
+ a->last_size = 128;
+ a->head.ptr = mem;
+ a->head.end = UPB_PTR_AT(mem, n, char);
+ a->freelist = NULL;
+ a->cleanups = NULL;
+
+ return a;
+}
+
+static void arena_dofree(upb_arena *a) {
+ mem_block *block = a->freelist;
+ UPB_ASSERT(a->parent == a);
+ UPB_ASSERT(a->refcount == 0);
+
+ while (block) {
+ /* Load first since we are deleting block. */
+ mem_block *next = block->next;
+
+ if (block->cleanups > 0) {
+ cleanup_ent *end = UPB_PTR_AT(block, block->size, void);
+ cleanup_ent *ptr = end - block->cleanups;
+
+ for (; ptr < end; ptr++) {
+ ptr->cleanup(ptr->ud);
+ }
+ }
+
+ upb_free(a->block_alloc, block);
+ block = next;
+ }
+}
+
+void upb_arena_free(upb_arena *a) {
+ a = arena_findroot(a);
+ if (--a->refcount == 0) arena_dofree(a);
+}
+
+bool upb_arena_addcleanup(upb_arena *a, void *ud, upb_cleanup_func *func) {
+ cleanup_ent *ent;
+
+ if (!a->cleanups || !arena_has(a, sizeof(cleanup_ent))) {
+ if (!upb_arena_allocblock(a, 128)) return false; /* Out of memory. */
+ UPB_ASSERT(arena_has(a, sizeof(cleanup_ent)));
+ }
+
+ a->head.end -= sizeof(cleanup_ent);
+ ent = (cleanup_ent*)a->head.end;
+ (*a->cleanups)++;
+
+ ent->cleanup = func;
+ ent->ud = ud;
+
+ return true;
+}
+
+void upb_arena_fuse(upb_arena *a1, upb_arena *a2) {
+ upb_arena *r1 = arena_findroot(a1);
+ upb_arena *r2 = arena_findroot(a2);
+
+ if (r1 == r2) return; /* Already fused. */
+
+ /* We want to join the smaller tree to the larger tree.
+ * So swap first if they are backwards. */
+ if (r1->refcount < r2->refcount) {
+ upb_arena *tmp = r1;
+ r1 = r2;
+ r2 = tmp;
+ }
+
+ /* r1 takes over r2's freelist and refcount. */
+ r1->refcount += r2->refcount;
+ if (r2->freelist_tail) {
+ UPB_ASSERT(r2->freelist_tail->next == NULL);
+ r2->freelist_tail->next = r1->freelist;
+ r1->freelist = r2->freelist;
+ }
+ r2->parent = r1;
+}
+/* This file was generated by upbc (the upb compiler) from the input
+ * file:
+ *
+ * google/protobuf/descriptor.proto
+ *
+ * Do not edit -- your changes will be discarded when the file is
+ * regenerated. */
+
+#include
+
+
+static const upb_msglayout *const google_protobuf_FileDescriptorSet_submsgs[1] = {
+ &google_protobuf_FileDescriptorProto_msginit,
+};
+
+static const upb_msglayout_field google_protobuf_FileDescriptorSet__fields[1] = {
+ {1, UPB_SIZE(0, 0), 0, 0, 11, 3},
+};
+
+const upb_msglayout google_protobuf_FileDescriptorSet_msginit = {
+ &google_protobuf_FileDescriptorSet_submsgs[0],
+ &google_protobuf_FileDescriptorSet__fields[0],
+ UPB_SIZE(4, 8), 1, false,
+};
+
+static const upb_msglayout *const google_protobuf_FileDescriptorProto_submsgs[6] = {
+ &google_protobuf_DescriptorProto_msginit,
+ &google_protobuf_EnumDescriptorProto_msginit,
+ &google_protobuf_FieldDescriptorProto_msginit,
+ &google_protobuf_FileOptions_msginit,
+ &google_protobuf_ServiceDescriptorProto_msginit,
+ &google_protobuf_SourceCodeInfo_msginit,
+};
+
+static const upb_msglayout_field google_protobuf_FileDescriptorProto__fields[12] = {
+ {1, UPB_SIZE(4, 8), 1, 0, 9, 1},
+ {2, UPB_SIZE(12, 24), 2, 0, 9, 1},
+ {3, UPB_SIZE(36, 72), 0, 0, 9, 3},
+ {4, UPB_SIZE(40, 80), 0, 0, 11, 3},
+ {5, UPB_SIZE(44, 88), 0, 1, 11, 3},
+ {6, UPB_SIZE(48, 96), 0, 4, 11, 3},
+ {7, UPB_SIZE(52, 104), 0, 2, 11, 3},
+ {8, UPB_SIZE(28, 56), 4, 3, 11, 1},
+ {9, UPB_SIZE(32, 64), 5, 5, 11, 1},
+ {10, UPB_SIZE(56, 112), 0, 0, 5, 3},
+ {11, UPB_SIZE(60, 120), 0, 0, 5, 3},
+ {12, UPB_SIZE(20, 40), 3, 0, 9, 1},
+};
+
+const upb_msglayout google_protobuf_FileDescriptorProto_msginit = {
+ &google_protobuf_FileDescriptorProto_submsgs[0],
+ &google_protobuf_FileDescriptorProto__fields[0],
+ UPB_SIZE(64, 128), 12, false,
+};
+
+static const upb_msglayout *const google_protobuf_DescriptorProto_submsgs[8] = {
+ &google_protobuf_DescriptorProto_msginit,
+ &google_protobuf_DescriptorProto_ExtensionRange_msginit,
+ &google_protobuf_DescriptorProto_ReservedRange_msginit,
+ &google_protobuf_EnumDescriptorProto_msginit,
+ &google_protobuf_FieldDescriptorProto_msginit,
+ &google_protobuf_MessageOptions_msginit,
+ &google_protobuf_OneofDescriptorProto_msginit,
+};
+
+static const upb_msglayout_field google_protobuf_DescriptorProto__fields[10] = {
+ {1, UPB_SIZE(4, 8), 1, 0, 9, 1},
+ {2, UPB_SIZE(16, 32), 0, 4, 11, 3},
+ {3, UPB_SIZE(20, 40), 0, 0, 11, 3},
+ {4, UPB_SIZE(24, 48), 0, 3, 11, 3},
+ {5, UPB_SIZE(28, 56), 0, 1, 11, 3},
+ {6, UPB_SIZE(32, 64), 0, 4, 11, 3},
+ {7, UPB_SIZE(12, 24), 2, 5, 11, 1},
+ {8, UPB_SIZE(36, 72), 0, 6, 11, 3},
+ {9, UPB_SIZE(40, 80), 0, 2, 11, 3},
+ {10, UPB_SIZE(44, 88), 0, 0, 9, 3},
+};
+
+const upb_msglayout google_protobuf_DescriptorProto_msginit = {
+ &google_protobuf_DescriptorProto_submsgs[0],
+ &google_protobuf_DescriptorProto__fields[0],
+ UPB_SIZE(48, 96), 10, false,
+};
+
+static const upb_msglayout *const google_protobuf_DescriptorProto_ExtensionRange_submsgs[1] = {
+ &google_protobuf_ExtensionRangeOptions_msginit,
+};
+
+static const upb_msglayout_field google_protobuf_DescriptorProto_ExtensionRange__fields[3] = {
+ {1, UPB_SIZE(4, 4), 1, 0, 5, 1},
+ {2, UPB_SIZE(8, 8), 2, 0, 5, 1},
+ {3, UPB_SIZE(12, 16), 3, 0, 11, 1},
+};
+
+const upb_msglayout google_protobuf_DescriptorProto_ExtensionRange_msginit = {
+ &google_protobuf_DescriptorProto_ExtensionRange_submsgs[0],
+ &google_protobuf_DescriptorProto_ExtensionRange__fields[0],
+ UPB_SIZE(16, 24), 3, false,
+};
+
+static const upb_msglayout_field google_protobuf_DescriptorProto_ReservedRange__fields[2] = {
+ {1, UPB_SIZE(4, 4), 1, 0, 5, 1},
+ {2, UPB_SIZE(8, 8), 2, 0, 5, 1},
+};
+
+const upb_msglayout google_protobuf_DescriptorProto_ReservedRange_msginit = {
+ NULL,
+ &google_protobuf_DescriptorProto_ReservedRange__fields[0],
+ UPB_SIZE(12, 12), 2, false,
+};
+
+static const upb_msglayout *const google_protobuf_ExtensionRangeOptions_submsgs[1] = {
+ &google_protobuf_UninterpretedOption_msginit,
+};
+
+static const upb_msglayout_field google_protobuf_ExtensionRangeOptions__fields[1] = {
+ {999, UPB_SIZE(0, 0), 0, 0, 11, 3},
+};
+
+const upb_msglayout google_protobuf_ExtensionRangeOptions_msginit = {
+ &google_protobuf_ExtensionRangeOptions_submsgs[0],
+ &google_protobuf_ExtensionRangeOptions__fields[0],
+ UPB_SIZE(4, 8), 1, false,
+};
+
+static const upb_msglayout *const google_protobuf_FieldDescriptorProto_submsgs[1] = {
+ &google_protobuf_FieldOptions_msginit,
+};
+
+static const upb_msglayout_field google_protobuf_FieldDescriptorProto__fields[11] = {
+ {1, UPB_SIZE(36, 40), 6, 0, 9, 1},
+ {2, UPB_SIZE(44, 56), 7, 0, 9, 1},
+ {3, UPB_SIZE(24, 24), 3, 0, 5, 1},
+ {4, UPB_SIZE(8, 8), 1, 0, 14, 1},
+ {5, UPB_SIZE(16, 16), 2, 0, 14, 1},
+ {6, UPB_SIZE(52, 72), 8, 0, 9, 1},
+ {7, UPB_SIZE(60, 88), 9, 0, 9, 1},
+ {8, UPB_SIZE(76, 120), 11, 0, 11, 1},
+ {9, UPB_SIZE(28, 28), 4, 0, 5, 1},
+ {10, UPB_SIZE(68, 104), 10, 0, 9, 1},
+ {17, UPB_SIZE(32, 32), 5, 0, 8, 1},
+};
+
+const upb_msglayout google_protobuf_FieldDescriptorProto_msginit = {
+ &google_protobuf_FieldDescriptorProto_submsgs[0],
+ &google_protobuf_FieldDescriptorProto__fields[0],
+ UPB_SIZE(80, 128), 11, false,
+};
+
+static const upb_msglayout *const google_protobuf_OneofDescriptorProto_submsgs[1] = {
+ &google_protobuf_OneofOptions_msginit,
+};
+
+static const upb_msglayout_field google_protobuf_OneofDescriptorProto__fields[2] = {
+ {1, UPB_SIZE(4, 8), 1, 0, 9, 1},
+ {2, UPB_SIZE(12, 24), 2, 0, 11, 1},
+};
+
+const upb_msglayout google_protobuf_OneofDescriptorProto_msginit = {
+ &google_protobuf_OneofDescriptorProto_submsgs[0],
+ &google_protobuf_OneofDescriptorProto__fields[0],
+ UPB_SIZE(16, 32), 2, false,
+};
+
+static const upb_msglayout *const google_protobuf_EnumDescriptorProto_submsgs[3] = {
+ &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit,
+ &google_protobuf_EnumOptions_msginit,
+ &google_protobuf_EnumValueDescriptorProto_msginit,
+};
+
+static const upb_msglayout_field google_protobuf_EnumDescriptorProto__fields[5] = {
+ {1, UPB_SIZE(4, 8), 1, 0, 9, 1},
+ {2, UPB_SIZE(16, 32), 0, 2, 11, 3},
+ {3, UPB_SIZE(12, 24), 2, 1, 11, 1},
+ {4, UPB_SIZE(20, 40), 0, 0, 11, 3},
+ {5, UPB_SIZE(24, 48), 0, 0, 9, 3},
+};
+
+const upb_msglayout google_protobuf_EnumDescriptorProto_msginit = {
+ &google_protobuf_EnumDescriptorProto_submsgs[0],
+ &google_protobuf_EnumDescriptorProto__fields[0],
+ UPB_SIZE(32, 64), 5, false,
+};
+
+static const upb_msglayout_field google_protobuf_EnumDescriptorProto_EnumReservedRange__fields[2] = {
+ {1, UPB_SIZE(4, 4), 1, 0, 5, 1},
+ {2, UPB_SIZE(8, 8), 2, 0, 5, 1},
+};
+
+const upb_msglayout google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit = {
+ NULL,
+ &google_protobuf_EnumDescriptorProto_EnumReservedRange__fields[0],
+ UPB_SIZE(12, 12), 2, false,
+};
+
+static const upb_msglayout *const google_protobuf_EnumValueDescriptorProto_submsgs[1] = {
+ &google_protobuf_EnumValueOptions_msginit,
+};
+
+static const upb_msglayout_field google_protobuf_EnumValueDescriptorProto__fields[3] = {
+ {1, UPB_SIZE(8, 8), 2, 0, 9, 1},
+ {2, UPB_SIZE(4, 4), 1, 0, 5, 1},
+ {3, UPB_SIZE(16, 24), 3, 0, 11, 1},
+};
+
+const upb_msglayout google_protobuf_EnumValueDescriptorProto_msginit = {
+ &google_protobuf_EnumValueDescriptorProto_submsgs[0],
+ &google_protobuf_EnumValueDescriptorProto__fields[0],
+ UPB_SIZE(24, 32), 3, false,
+};
+
+static const upb_msglayout *const google_protobuf_ServiceDescriptorProto_submsgs[2] = {
+ &google_protobuf_MethodDescriptorProto_msginit,
+ &google_protobuf_ServiceOptions_msginit,
+};
+
+static const upb_msglayout_field google_protobuf_ServiceDescriptorProto__fields[3] = {
+ {1, UPB_SIZE(4, 8), 1, 0, 9, 1},
+ {2, UPB_SIZE(16, 32), 0, 0, 11, 3},
+ {3, UPB_SIZE(12, 24), 2, 1, 11, 1},
+};
+
+const upb_msglayout google_protobuf_ServiceDescriptorProto_msginit = {
+ &google_protobuf_ServiceDescriptorProto_submsgs[0],
+ &google_protobuf_ServiceDescriptorProto__fields[0],
+ UPB_SIZE(24, 48), 3, false,
+};
+
+static const upb_msglayout *const google_protobuf_MethodDescriptorProto_submsgs[1] = {
+ &google_protobuf_MethodOptions_msginit,
+};
+
+static const upb_msglayout_field google_protobuf_MethodDescriptorProto__fields[6] = {
+ {1, UPB_SIZE(4, 8), 3, 0, 9, 1},
+ {2, UPB_SIZE(12, 24), 4, 0, 9, 1},
+ {3, UPB_SIZE(20, 40), 5, 0, 9, 1},
+ {4, UPB_SIZE(28, 56), 6, 0, 11, 1},
+ {5, UPB_SIZE(1, 1), 1, 0, 8, 1},
+ {6, UPB_SIZE(2, 2), 2, 0, 8, 1},
+};
+
+const upb_msglayout google_protobuf_MethodDescriptorProto_msginit = {
+ &google_protobuf_MethodDescriptorProto_submsgs[0],
+ &google_protobuf_MethodDescriptorProto__fields[0],
+ UPB_SIZE(32, 64), 6, false,
+};
+
+static const upb_msglayout *const google_protobuf_FileOptions_submsgs[1] = {
+ &google_protobuf_UninterpretedOption_msginit,
+};
+
+static const upb_msglayout_field google_protobuf_FileOptions__fields[21] = {
+ {1, UPB_SIZE(28, 32), 11, 0, 9, 1},
+ {8, UPB_SIZE(36, 48), 12, 0, 9, 1},
+ {9, UPB_SIZE(8, 8), 1, 0, 14, 1},
+ {10, UPB_SIZE(16, 16), 2, 0, 8, 1},
+ {11, UPB_SIZE(44, 64), 13, 0, 9, 1},
+ {16, UPB_SIZE(17, 17), 3, 0, 8, 1},
+ {17, UPB_SIZE(18, 18), 4, 0, 8, 1},
+ {18, UPB_SIZE(19, 19), 5, 0, 8, 1},
+ {20, UPB_SIZE(20, 20), 6, 0, 8, 1},
+ {23, UPB_SIZE(21, 21), 7, 0, 8, 1},
+ {27, UPB_SIZE(22, 22), 8, 0, 8, 1},
+ {31, UPB_SIZE(23, 23), 9, 0, 8, 1},
+ {36, UPB_SIZE(52, 80), 14, 0, 9, 1},
+ {37, UPB_SIZE(60, 96), 15, 0, 9, 1},
+ {39, UPB_SIZE(68, 112), 16, 0, 9, 1},
+ {40, UPB_SIZE(76, 128), 17, 0, 9, 1},
+ {41, UPB_SIZE(84, 144), 18, 0, 9, 1},
+ {42, UPB_SIZE(24, 24), 10, 0, 8, 1},
+ {44, UPB_SIZE(92, 160), 19, 0, 9, 1},
+ {45, UPB_SIZE(100, 176), 20, 0, 9, 1},
+ {999, UPB_SIZE(108, 192), 0, 0, 11, 3},
+};
+
+const upb_msglayout google_protobuf_FileOptions_msginit = {
+ &google_protobuf_FileOptions_submsgs[0],
+ &google_protobuf_FileOptions__fields[0],
+ UPB_SIZE(112, 208), 21, false,
+};
+
+static const upb_msglayout *const google_protobuf_MessageOptions_submsgs[1] = {
+ &google_protobuf_UninterpretedOption_msginit,
+};
+
+static const upb_msglayout_field google_protobuf_MessageOptions__fields[5] = {
+ {1, UPB_SIZE(1, 1), 1, 0, 8, 1},
+ {2, UPB_SIZE(2, 2), 2, 0, 8, 1},
+ {3, UPB_SIZE(3, 3), 3, 0, 8, 1},
+ {7, UPB_SIZE(4, 4), 4, 0, 8, 1},
+ {999, UPB_SIZE(8, 8), 0, 0, 11, 3},
+};
+
+const upb_msglayout google_protobuf_MessageOptions_msginit = {
+ &google_protobuf_MessageOptions_submsgs[0],
+ &google_protobuf_MessageOptions__fields[0],
+ UPB_SIZE(12, 16), 5, false,
+};
+
+static const upb_msglayout *const google_protobuf_FieldOptions_submsgs[1] = {
+ &google_protobuf_UninterpretedOption_msginit,
+};
+
+static const upb_msglayout_field google_protobuf_FieldOptions__fields[7] = {
+ {1, UPB_SIZE(8, 8), 1, 0, 14, 1},
+ {2, UPB_SIZE(24, 24), 3, 0, 8, 1},
+ {3, UPB_SIZE(25, 25), 4, 0, 8, 1},
+ {5, UPB_SIZE(26, 26), 5, 0, 8, 1},
+ {6, UPB_SIZE(16, 16), 2, 0, 14, 1},
+ {10, UPB_SIZE(27, 27), 6, 0, 8, 1},
+ {999, UPB_SIZE(28, 32), 0, 0, 11, 3},
+};
+
+const upb_msglayout google_protobuf_FieldOptions_msginit = {
+ &google_protobuf_FieldOptions_submsgs[0],
+ &google_protobuf_FieldOptions__fields[0],
+ UPB_SIZE(32, 40), 7, false,
+};
+
+static const upb_msglayout *const google_protobuf_OneofOptions_submsgs[1] = {
+ &google_protobuf_UninterpretedOption_msginit,
+};
+
+static const upb_msglayout_field google_protobuf_OneofOptions__fields[1] = {
+ {999, UPB_SIZE(0, 0), 0, 0, 11, 3},
+};
+
+const upb_msglayout google_protobuf_OneofOptions_msginit = {
+ &google_protobuf_OneofOptions_submsgs[0],
+ &google_protobuf_OneofOptions__fields[0],
+ UPB_SIZE(4, 8), 1, false,
+};
+
+static const upb_msglayout *const google_protobuf_EnumOptions_submsgs[1] = {
+ &google_protobuf_UninterpretedOption_msginit,
+};
+
+static const upb_msglayout_field google_protobuf_EnumOptions__fields[3] = {
+ {2, UPB_SIZE(1, 1), 1, 0, 8, 1},
+ {3, UPB_SIZE(2, 2), 2, 0, 8, 1},
+ {999, UPB_SIZE(4, 8), 0, 0, 11, 3},
+};
+
+const upb_msglayout google_protobuf_EnumOptions_msginit = {
+ &google_protobuf_EnumOptions_submsgs[0],
+ &google_protobuf_EnumOptions__fields[0],
+ UPB_SIZE(8, 16), 3, false,
+};
+
+static const upb_msglayout *const google_protobuf_EnumValueOptions_submsgs[1] = {
+ &google_protobuf_UninterpretedOption_msginit,
+};
+
+static const upb_msglayout_field google_protobuf_EnumValueOptions__fields[2] = {
+ {1, UPB_SIZE(1, 1), 1, 0, 8, 1},
+ {999, UPB_SIZE(4, 8), 0, 0, 11, 3},
+};
+
+const upb_msglayout google_protobuf_EnumValueOptions_msginit = {
+ &google_protobuf_EnumValueOptions_submsgs[0],
+ &google_protobuf_EnumValueOptions__fields[0],
+ UPB_SIZE(8, 16), 2, false,
+};
+
+static const upb_msglayout *const google_protobuf_ServiceOptions_submsgs[1] = {
+ &google_protobuf_UninterpretedOption_msginit,
+};
+
+static const upb_msglayout_field google_protobuf_ServiceOptions__fields[2] = {
+ {33, UPB_SIZE(1, 1), 1, 0, 8, 1},
+ {999, UPB_SIZE(4, 8), 0, 0, 11, 3},
+};
+
+const upb_msglayout google_protobuf_ServiceOptions_msginit = {
+ &google_protobuf_ServiceOptions_submsgs[0],
+ &google_protobuf_ServiceOptions__fields[0],
+ UPB_SIZE(8, 16), 2, false,
+};
+
+static const upb_msglayout *const google_protobuf_MethodOptions_submsgs[1] = {
+ &google_protobuf_UninterpretedOption_msginit,
+};
+
+static const upb_msglayout_field google_protobuf_MethodOptions__fields[3] = {
+ {33, UPB_SIZE(16, 16), 2, 0, 8, 1},
+ {34, UPB_SIZE(8, 8), 1, 0, 14, 1},
+ {999, UPB_SIZE(20, 24), 0, 0, 11, 3},
+};
+
+const upb_msglayout google_protobuf_MethodOptions_msginit = {
+ &google_protobuf_MethodOptions_submsgs[0],
+ &google_protobuf_MethodOptions__fields[0],
+ UPB_SIZE(24, 32), 3, false,
+};
+
+static const upb_msglayout *const google_protobuf_UninterpretedOption_submsgs[1] = {
+ &google_protobuf_UninterpretedOption_NamePart_msginit,
+};
+
+static const upb_msglayout_field google_protobuf_UninterpretedOption__fields[7] = {
+ {2, UPB_SIZE(56, 80), 0, 0, 11, 3},
+ {3, UPB_SIZE(32, 32), 4, 0, 9, 1},
+ {4, UPB_SIZE(8, 8), 1, 0, 4, 1},
+ {5, UPB_SIZE(16, 16), 2, 0, 3, 1},
+ {6, UPB_SIZE(24, 24), 3, 0, 1, 1},
+ {7, UPB_SIZE(40, 48), 5, 0, 12, 1},
+ {8, UPB_SIZE(48, 64), 6, 0, 9, 1},
+};
+
+const upb_msglayout google_protobuf_UninterpretedOption_msginit = {
+ &google_protobuf_UninterpretedOption_submsgs[0],
+ &google_protobuf_UninterpretedOption__fields[0],
+ UPB_SIZE(64, 96), 7, false,
+};
+
+static const upb_msglayout_field google_protobuf_UninterpretedOption_NamePart__fields[2] = {
+ {1, UPB_SIZE(4, 8), 2, 0, 9, 2},
+ {2, UPB_SIZE(1, 1), 1, 0, 8, 2},
+};
+
+const upb_msglayout google_protobuf_UninterpretedOption_NamePart_msginit = {
+ NULL,
+ &google_protobuf_UninterpretedOption_NamePart__fields[0],
+ UPB_SIZE(16, 32), 2, false,
+};
+
+static const upb_msglayout *const google_protobuf_SourceCodeInfo_submsgs[1] = {
+ &google_protobuf_SourceCodeInfo_Location_msginit,
+};
+
+static const upb_msglayout_field google_protobuf_SourceCodeInfo__fields[1] = {
+ {1, UPB_SIZE(0, 0), 0, 0, 11, 3},
+};
+
+const upb_msglayout google_protobuf_SourceCodeInfo_msginit = {
+ &google_protobuf_SourceCodeInfo_submsgs[0],
+ &google_protobuf_SourceCodeInfo__fields[0],
+ UPB_SIZE(4, 8), 1, false,
+};
+
+static const upb_msglayout_field google_protobuf_SourceCodeInfo_Location__fields[5] = {
+ {1, UPB_SIZE(20, 40), 0, 0, 5, _UPB_LABEL_PACKED},
+ {2, UPB_SIZE(24, 48), 0, 0, 5, _UPB_LABEL_PACKED},
+ {3, UPB_SIZE(4, 8), 1, 0, 9, 1},
+ {4, UPB_SIZE(12, 24), 2, 0, 9, 1},
+ {6, UPB_SIZE(28, 56), 0, 0, 9, 3},
+};
+
+const upb_msglayout google_protobuf_SourceCodeInfo_Location_msginit = {
+ NULL,
+ &google_protobuf_SourceCodeInfo_Location__fields[0],
+ UPB_SIZE(32, 64), 5, false,
+};
+
+static const upb_msglayout *const google_protobuf_GeneratedCodeInfo_submsgs[1] = {
+ &google_protobuf_GeneratedCodeInfo_Annotation_msginit,
+};
+
+static const upb_msglayout_field google_protobuf_GeneratedCodeInfo__fields[1] = {
+ {1, UPB_SIZE(0, 0), 0, 0, 11, 3},
+};
+
+const upb_msglayout google_protobuf_GeneratedCodeInfo_msginit = {
+ &google_protobuf_GeneratedCodeInfo_submsgs[0],
+ &google_protobuf_GeneratedCodeInfo__fields[0],
+ UPB_SIZE(4, 8), 1, false,
+};
+
+static const upb_msglayout_field google_protobuf_GeneratedCodeInfo_Annotation__fields[4] = {
+ {1, UPB_SIZE(20, 32), 0, 0, 5, _UPB_LABEL_PACKED},
+ {2, UPB_SIZE(12, 16), 3, 0, 9, 1},
+ {3, UPB_SIZE(4, 4), 1, 0, 5, 1},
+ {4, UPB_SIZE(8, 8), 2, 0, 5, 1},
+};
+
+const upb_msglayout google_protobuf_GeneratedCodeInfo_Annotation_msginit = {
+ NULL,
+ &google_protobuf_GeneratedCodeInfo_Annotation__fields[0],
+ UPB_SIZE(24, 48), 4, false,
+};
+
+
+/* This file was generated by upbc (the upb compiler) from the input
+ * file:
+ *
+ * google/protobuf/descriptor.proto
+ *
+ * Do not edit -- your changes will be discarded when the file is
+ * regenerated. */
+
+
+extern const upb_msglayout google_protobuf_FileDescriptorSet_msginit;
+extern const upb_msglayout google_protobuf_FileDescriptorProto_msginit;
+extern const upb_msglayout google_protobuf_DescriptorProto_msginit;
+extern const upb_msglayout google_protobuf_DescriptorProto_ExtensionRange_msginit;
+extern const upb_msglayout google_protobuf_DescriptorProto_ReservedRange_msginit;
+extern const upb_msglayout google_protobuf_ExtensionRangeOptions_msginit;
+extern const upb_msglayout google_protobuf_FieldDescriptorProto_msginit;
+extern const upb_msglayout google_protobuf_OneofDescriptorProto_msginit;
+extern const upb_msglayout google_protobuf_EnumDescriptorProto_msginit;
+extern const upb_msglayout google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit;
+extern const upb_msglayout google_protobuf_EnumValueDescriptorProto_msginit;
+extern const upb_msglayout google_protobuf_ServiceDescriptorProto_msginit;
+extern const upb_msglayout google_protobuf_MethodDescriptorProto_msginit;
+extern const upb_msglayout google_protobuf_FileOptions_msginit;
+extern const upb_msglayout google_protobuf_MessageOptions_msginit;
+extern const upb_msglayout google_protobuf_FieldOptions_msginit;
+extern const upb_msglayout google_protobuf_OneofOptions_msginit;
+extern const upb_msglayout google_protobuf_EnumOptions_msginit;
+extern const upb_msglayout google_protobuf_EnumValueOptions_msginit;
+extern const upb_msglayout google_protobuf_ServiceOptions_msginit;
+extern const upb_msglayout google_protobuf_MethodOptions_msginit;
+extern const upb_msglayout google_protobuf_UninterpretedOption_msginit;
+extern const upb_msglayout google_protobuf_UninterpretedOption_NamePart_msginit;
+extern const upb_msglayout google_protobuf_SourceCodeInfo_msginit;
+extern const upb_msglayout google_protobuf_SourceCodeInfo_Location_msginit;
+extern const upb_msglayout google_protobuf_GeneratedCodeInfo_msginit;
+extern const upb_msglayout google_protobuf_GeneratedCodeInfo_Annotation_msginit;
+
+static const upb_msglayout *layouts[27] = {
+ &google_protobuf_FileDescriptorSet_msginit,
+ &google_protobuf_FileDescriptorProto_msginit,
+ &google_protobuf_DescriptorProto_msginit,
+ &google_protobuf_DescriptorProto_ExtensionRange_msginit,
+ &google_protobuf_DescriptorProto_ReservedRange_msginit,
+ &google_protobuf_ExtensionRangeOptions_msginit,
+ &google_protobuf_FieldDescriptorProto_msginit,
+ &google_protobuf_OneofDescriptorProto_msginit,
+ &google_protobuf_EnumDescriptorProto_msginit,
+ &google_protobuf_EnumDescriptorProto_EnumReservedRange_msginit,
+ &google_protobuf_EnumValueDescriptorProto_msginit,
+ &google_protobuf_ServiceDescriptorProto_msginit,
+ &google_protobuf_MethodDescriptorProto_msginit,
+ &google_protobuf_FileOptions_msginit,
+ &google_protobuf_MessageOptions_msginit,
+ &google_protobuf_FieldOptions_msginit,
+ &google_protobuf_OneofOptions_msginit,
+ &google_protobuf_EnumOptions_msginit,
+ &google_protobuf_EnumValueOptions_msginit,
+ &google_protobuf_ServiceOptions_msginit,
+ &google_protobuf_MethodOptions_msginit,
+ &google_protobuf_UninterpretedOption_msginit,
+ &google_protobuf_UninterpretedOption_NamePart_msginit,
+ &google_protobuf_SourceCodeInfo_msginit,
+ &google_protobuf_SourceCodeInfo_Location_msginit,
+ &google_protobuf_GeneratedCodeInfo_msginit,
+ &google_protobuf_GeneratedCodeInfo_Annotation_msginit,
+};
+
+static const char descriptor[7619] = {'\n', ' ', 'g', 'o', 'o', 'g', 'l', 'e', '/', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '/', 'd', 'e', 's', 'c', 'r', 'i', 'p',
+'t', 'o', 'r', '.', 'p', 'r', 'o', 't', 'o', '\022', '\017', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u',
+'f', '\"', 'M', '\n', '\021', 'F', 'i', 'l', 'e', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'S', 'e', 't', '\022', '8', '\n',
+'\004', 'f', 'i', 'l', 'e', '\030', '\001', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't',
+'o', 'b', 'u', 'f', '.', 'F', 'i', 'l', 'e', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 'R',
+'\004', 'f', 'i', 'l', 'e', '\"', '\344', '\004', '\n', '\023', 'F', 'i', 'l', 'e', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P',
+'r', 'o', 't', 'o', '\022', '\022', '\n', '\004', 'n', 'a', 'm', 'e', '\030', '\001', ' ', '\001', '(', '\t', 'R', '\004', 'n', 'a', 'm', 'e', '\022',
+'\030', '\n', '\007', 'p', 'a', 'c', 'k', 'a', 'g', 'e', '\030', '\002', ' ', '\001', '(', '\t', 'R', '\007', 'p', 'a', 'c', 'k', 'a', 'g', 'e',
+'\022', '\036', '\n', '\n', 'd', 'e', 'p', 'e', 'n', 'd', 'e', 'n', 'c', 'y', '\030', '\003', ' ', '\003', '(', '\t', 'R', '\n', 'd', 'e', 'p',
+'e', 'n', 'd', 'e', 'n', 'c', 'y', '\022', '+', '\n', '\021', 'p', 'u', 'b', 'l', 'i', 'c', '_', 'd', 'e', 'p', 'e', 'n', 'd', 'e',
+'n', 'c', 'y', '\030', '\n', ' ', '\003', '(', '\005', 'R', '\020', 'p', 'u', 'b', 'l', 'i', 'c', 'D', 'e', 'p', 'e', 'n', 'd', 'e', 'n',
+'c', 'y', '\022', '\'', '\n', '\017', 'w', 'e', 'a', 'k', '_', 'd', 'e', 'p', 'e', 'n', 'd', 'e', 'n', 'c', 'y', '\030', '\013', ' ', '\003',
+'(', '\005', 'R', '\016', 'w', 'e', 'a', 'k', 'D', 'e', 'p', 'e', 'n', 'd', 'e', 'n', 'c', 'y', '\022', 'C', '\n', '\014', 'm', 'e', 's',
+'s', 'a', 'g', 'e', '_', 't', 'y', 'p', 'e', '\030', '\004', ' ', '\003', '(', '\013', '2', ' ', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.',
+'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 'R',
+'\013', 'm', 'e', 's', 's', 'a', 'g', 'e', 'T', 'y', 'p', 'e', '\022', 'A', '\n', '\t', 'e', 'n', 'u', 'm', '_', 't', 'y', 'p', 'e',
+'\030', '\005', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.',
+'E', 'n', 'u', 'm', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', '\010', 'e', 'n', 'u', 'm',
+'T', 'y', 'p', 'e', '\022', 'A', '\n', '\007', 's', 'e', 'r', 'v', 'i', 'c', 'e', '\030', '\006', ' ', '\003', '(', '\013', '2', '\'', '.', 'g',
+'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 'D', 'e', 's',
+'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', '\007', 's', 'e', 'r', 'v', 'i', 'c', 'e', '\022', 'C', '\n', '\t',
+'e', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', '\030', '\007', ' ', '\003', '(', '\013', '2', '%', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.',
+'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P',
+'r', 'o', 't', 'o', 'R', '\t', 'e', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', '\022', '6', '\n', '\007', 'o', 'p', 't', 'i', 'o', 'n',
+'s', '\030', '\010', ' ', '\001', '(', '\013', '2', '\034', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f',
+'.', 'F', 'i', 'l', 'e', 'O', 'p', 't', 'i', 'o', 'n', 's', 'R', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\022', 'I', '\n', '\020',
+'s', 'o', 'u', 'r', 'c', 'e', '_', 'c', 'o', 'd', 'e', '_', 'i', 'n', 'f', 'o', '\030', '\t', ' ', '\001', '(', '\013', '2', '\037', '.',
+'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'S', 'o', 'u', 'r', 'c', 'e', 'C', 'o', 'd',
+'e', 'I', 'n', 'f', 'o', 'R', '\016', 's', 'o', 'u', 'r', 'c', 'e', 'C', 'o', 'd', 'e', 'I', 'n', 'f', 'o', '\022', '\026', '\n', '\006',
+'s', 'y', 'n', 't', 'a', 'x', '\030', '\014', ' ', '\001', '(', '\t', 'R', '\006', 's', 'y', 'n', 't', 'a', 'x', '\"', '\271', '\006', '\n', '\017',
+'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '\022', '\022', '\n', '\004', 'n', 'a', 'm', 'e', '\030', '\001',
+' ', '\001', '(', '\t', 'R', '\004', 'n', 'a', 'm', 'e', '\022', ';', '\n', '\005', 'f', 'i', 'e', 'l', 'd', '\030', '\002', ' ', '\003', '(', '\013',
+'2', '%', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', 'D',
+'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', '\005', 'f', 'i', 'e', 'l', 'd', '\022', 'C', '\n', '\t',
+'e', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', '\030', '\006', ' ', '\003', '(', '\013', '2', '%', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.',
+'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P',
+'r', 'o', 't', 'o', 'R', '\t', 'e', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', '\022', 'A', '\n', '\013', 'n', 'e', 's', 't', 'e', 'd',
+'_', 't', 'y', 'p', 'e', '\030', '\003', ' ', '\003', '(', '\013', '2', ' ', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't',
+'o', 'b', 'u', 'f', '.', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', '\n', 'n', 'e', 's',
+'t', 'e', 'd', 'T', 'y', 'p', 'e', '\022', 'A', '\n', '\t', 'e', 'n', 'u', 'm', '_', 't', 'y', 'p', 'e', '\030', '\004', ' ', '\003', '(',
+'\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'E', 'n', 'u', 'm', 'D',
+'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', '\010', 'e', 'n', 'u', 'm', 'T', 'y', 'p', 'e', '\022',
+'X', '\n', '\017', 'e', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', '_', 'r', 'a', 'n', 'g', 'e', '\030', '\005', ' ', '\003', '(', '\013', '2',
+'/', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'D', 'e', 's', 'c', 'r', 'i', 'p',
+'t', 'o', 'r', 'P', 'r', 'o', 't', 'o', '.', 'E', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', 'R', 'a', 'n', 'g', 'e', 'R', '\016',
+'e', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', 'R', 'a', 'n', 'g', 'e', '\022', 'D', '\n', '\n', 'o', 'n', 'e', 'o', 'f', '_', 'd',
+'e', 'c', 'l', '\030', '\010', ' ', '\003', '(', '\013', '2', '%', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b',
+'u', 'f', '.', 'O', 'n', 'e', 'o', 'f', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', '\t',
+'o', 'n', 'e', 'o', 'f', 'D', 'e', 'c', 'l', '\022', '9', '\n', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\030', '\007', ' ', '\001', '(',
+'\013', '2', '\037', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'M', 'e', 's', 's', 'a',
+'g', 'e', 'O', 'p', 't', 'i', 'o', 'n', 's', 'R', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\022', 'U', '\n', '\016', 'r', 'e', 's',
+'e', 'r', 'v', 'e', 'd', '_', 'r', 'a', 'n', 'g', 'e', '\030', '\t', ' ', '\003', '(', '\013', '2', '.', '.', 'g', 'o', 'o', 'g', 'l',
+'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't',
+'o', '.', 'R', 'e', 's', 'e', 'r', 'v', 'e', 'd', 'R', 'a', 'n', 'g', 'e', 'R', '\r', 'r', 'e', 's', 'e', 'r', 'v', 'e', 'd',
+'R', 'a', 'n', 'g', 'e', '\022', '#', '\n', '\r', 'r', 'e', 's', 'e', 'r', 'v', 'e', 'd', '_', 'n', 'a', 'm', 'e', '\030', '\n', ' ',
+'\003', '(', '\t', 'R', '\014', 'r', 'e', 's', 'e', 'r', 'v', 'e', 'd', 'N', 'a', 'm', 'e', '\032', 'z', '\n', '\016', 'E', 'x', 't', 'e',
+'n', 's', 'i', 'o', 'n', 'R', 'a', 'n', 'g', 'e', '\022', '\024', '\n', '\005', 's', 't', 'a', 'r', 't', '\030', '\001', ' ', '\001', '(', '\005',
+'R', '\005', 's', 't', 'a', 'r', 't', '\022', '\020', '\n', '\003', 'e', 'n', 'd', '\030', '\002', ' ', '\001', '(', '\005', 'R', '\003', 'e', 'n', 'd',
+'\022', '@', '\n', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\030', '\003', ' ', '\001', '(', '\013', '2', '&', '.', 'g', 'o', 'o', 'g', 'l',
+'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'E', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', 'R', 'a', 'n', 'g', 'e',
+'O', 'p', 't', 'i', 'o', 'n', 's', 'R', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\032', '7', '\n', '\r', 'R', 'e', 's', 'e', 'r',
+'v', 'e', 'd', 'R', 'a', 'n', 'g', 'e', '\022', '\024', '\n', '\005', 's', 't', 'a', 'r', 't', '\030', '\001', ' ', '\001', '(', '\005', 'R', '\005',
+'s', 't', 'a', 'r', 't', '\022', '\020', '\n', '\003', 'e', 'n', 'd', '\030', '\002', ' ', '\001', '(', '\005', 'R', '\003', 'e', 'n', 'd', '\"', '|',
+'\n', '\025', 'E', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', 'R', 'a', 'n', 'g', 'e', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', 'X',
+'\n', '\024', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007',
+' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n',
+'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e',
+'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', '\"',
+'\301', '\006', '\n', '\024', 'F', 'i', 'e', 'l', 'd', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '\022',
+'\022', '\n', '\004', 'n', 'a', 'm', 'e', '\030', '\001', ' ', '\001', '(', '\t', 'R', '\004', 'n', 'a', 'm', 'e', '\022', '\026', '\n', '\006', 'n', 'u',
+'m', 'b', 'e', 'r', '\030', '\003', ' ', '\001', '(', '\005', 'R', '\006', 'n', 'u', 'm', 'b', 'e', 'r', '\022', 'A', '\n', '\005', 'l', 'a', 'b',
+'e', 'l', '\030', '\004', ' ', '\001', '(', '\016', '2', '+', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u',
+'f', '.', 'F', 'i', 'e', 'l', 'd', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '.', 'L', 'a',
+'b', 'e', 'l', 'R', '\005', 'l', 'a', 'b', 'e', 'l', '\022', '>', '\n', '\004', 't', 'y', 'p', 'e', '\030', '\005', ' ', '\001', '(', '\016', '2',
+'*', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', 'D', 'e',
+'s', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '.', 'T', 'y', 'p', 'e', 'R', '\004', 't', 'y', 'p', 'e', '\022',
+'\033', '\n', '\t', 't', 'y', 'p', 'e', '_', 'n', 'a', 'm', 'e', '\030', '\006', ' ', '\001', '(', '\t', 'R', '\010', 't', 'y', 'p', 'e', 'N',
+'a', 'm', 'e', '\022', '\032', '\n', '\010', 'e', 'x', 't', 'e', 'n', 'd', 'e', 'e', '\030', '\002', ' ', '\001', '(', '\t', 'R', '\010', 'e', 'x',
+'t', 'e', 'n', 'd', 'e', 'e', '\022', '#', '\n', '\r', 'd', 'e', 'f', 'a', 'u', 'l', 't', '_', 'v', 'a', 'l', 'u', 'e', '\030', '\007',
+' ', '\001', '(', '\t', 'R', '\014', 'd', 'e', 'f', 'a', 'u', 'l', 't', 'V', 'a', 'l', 'u', 'e', '\022', '\037', '\n', '\013', 'o', 'n', 'e',
+'o', 'f', '_', 'i', 'n', 'd', 'e', 'x', '\030', '\t', ' ', '\001', '(', '\005', 'R', '\n', 'o', 'n', 'e', 'o', 'f', 'I', 'n', 'd', 'e',
+'x', '\022', '\033', '\n', '\t', 'j', 's', 'o', 'n', '_', 'n', 'a', 'm', 'e', '\030', '\n', ' ', '\001', '(', '\t', 'R', '\010', 'j', 's', 'o',
+'n', 'N', 'a', 'm', 'e', '\022', '7', '\n', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\030', '\010', ' ', '\001', '(', '\013', '2', '\035', '.',
+'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', 'O', 'p', 't', 'i',
+'o', 'n', 's', 'R', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\022', '\'', '\n', '\017', 'p', 'r', 'o', 't', 'o', '3', '_', 'o', 'p',
+'t', 'i', 'o', 'n', 'a', 'l', '\030', '\021', ' ', '\001', '(', '\010', 'R', '\016', 'p', 'r', 'o', 't', 'o', '3', 'O', 'p', 't', 'i', 'o',
+'n', 'a', 'l', '\"', '\266', '\002', '\n', '\004', 'T', 'y', 'p', 'e', '\022', '\017', '\n', '\013', 'T', 'Y', 'P', 'E', '_', 'D', 'O', 'U', 'B',
+'L', 'E', '\020', '\001', '\022', '\016', '\n', '\n', 'T', 'Y', 'P', 'E', '_', 'F', 'L', 'O', 'A', 'T', '\020', '\002', '\022', '\016', '\n', '\n', 'T',
+'Y', 'P', 'E', '_', 'I', 'N', 'T', '6', '4', '\020', '\003', '\022', '\017', '\n', '\013', 'T', 'Y', 'P', 'E', '_', 'U', 'I', 'N', 'T', '6',
+'4', '\020', '\004', '\022', '\016', '\n', '\n', 'T', 'Y', 'P', 'E', '_', 'I', 'N', 'T', '3', '2', '\020', '\005', '\022', '\020', '\n', '\014', 'T', 'Y',
+'P', 'E', '_', 'F', 'I', 'X', 'E', 'D', '6', '4', '\020', '\006', '\022', '\020', '\n', '\014', 'T', 'Y', 'P', 'E', '_', 'F', 'I', 'X', 'E',
+'D', '3', '2', '\020', '\007', '\022', '\r', '\n', '\t', 'T', 'Y', 'P', 'E', '_', 'B', 'O', 'O', 'L', '\020', '\010', '\022', '\017', '\n', '\013', 'T',
+'Y', 'P', 'E', '_', 'S', 'T', 'R', 'I', 'N', 'G', '\020', '\t', '\022', '\016', '\n', '\n', 'T', 'Y', 'P', 'E', '_', 'G', 'R', 'O', 'U',
+'P', '\020', '\n', '\022', '\020', '\n', '\014', 'T', 'Y', 'P', 'E', '_', 'M', 'E', 'S', 'S', 'A', 'G', 'E', '\020', '\013', '\022', '\016', '\n', '\n',
+'T', 'Y', 'P', 'E', '_', 'B', 'Y', 'T', 'E', 'S', '\020', '\014', '\022', '\017', '\n', '\013', 'T', 'Y', 'P', 'E', '_', 'U', 'I', 'N', 'T',
+'3', '2', '\020', '\r', '\022', '\r', '\n', '\t', 'T', 'Y', 'P', 'E', '_', 'E', 'N', 'U', 'M', '\020', '\016', '\022', '\021', '\n', '\r', 'T', 'Y',
+'P', 'E', '_', 'S', 'F', 'I', 'X', 'E', 'D', '3', '2', '\020', '\017', '\022', '\021', '\n', '\r', 'T', 'Y', 'P', 'E', '_', 'S', 'F', 'I',
+'X', 'E', 'D', '6', '4', '\020', '\020', '\022', '\017', '\n', '\013', 'T', 'Y', 'P', 'E', '_', 'S', 'I', 'N', 'T', '3', '2', '\020', '\021', '\022',
+'\017', '\n', '\013', 'T', 'Y', 'P', 'E', '_', 'S', 'I', 'N', 'T', '6', '4', '\020', '\022', '\"', 'C', '\n', '\005', 'L', 'a', 'b', 'e', 'l',
+'\022', '\022', '\n', '\016', 'L', 'A', 'B', 'E', 'L', '_', 'O', 'P', 'T', 'I', 'O', 'N', 'A', 'L', '\020', '\001', '\022', '\022', '\n', '\016', 'L',
+'A', 'B', 'E', 'L', '_', 'R', 'E', 'Q', 'U', 'I', 'R', 'E', 'D', '\020', '\002', '\022', '\022', '\n', '\016', 'L', 'A', 'B', 'E', 'L', '_',
+'R', 'E', 'P', 'E', 'A', 'T', 'E', 'D', '\020', '\003', '\"', 'c', '\n', '\024', 'O', 'n', 'e', 'o', 'f', 'D', 'e', 's', 'c', 'r', 'i',
+'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '\022', '\022', '\n', '\004', 'n', 'a', 'm', 'e', '\030', '\001', ' ', '\001', '(', '\t', 'R', '\004',
+'n', 'a', 'm', 'e', '\022', '7', '\n', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\030', '\002', ' ', '\001', '(', '\013', '2', '\035', '.', 'g',
+'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'O', 'n', 'e', 'o', 'f', 'O', 'p', 't', 'i', 'o',
+'n', 's', 'R', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\"', '\343', '\002', '\n', '\023', 'E', 'n', 'u', 'm', 'D', 'e', 's', 'c', 'r',
+'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '\022', '\022', '\n', '\004', 'n', 'a', 'm', 'e', '\030', '\001', ' ', '\001', '(', '\t', 'R',
+'\004', 'n', 'a', 'm', 'e', '\022', '?', '\n', '\005', 'v', 'a', 'l', 'u', 'e', '\030', '\002', ' ', '\003', '(', '\013', '2', ')', '.', 'g', 'o',
+'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'E', 'n', 'u', 'm', 'V', 'a', 'l', 'u', 'e', 'D', 'e',
+'s', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 'R', '\005', 'v', 'a', 'l', 'u', 'e', '\022', '6', '\n', '\007', 'o',
+'p', 't', 'i', 'o', 'n', 's', '\030', '\003', ' ', '\001', '(', '\013', '2', '\034', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o',
+'t', 'o', 'b', 'u', 'f', '.', 'E', 'n', 'u', 'm', 'O', 'p', 't', 'i', 'o', 'n', 's', 'R', '\007', 'o', 'p', 't', 'i', 'o', 'n',
+'s', '\022', ']', '\n', '\016', 'r', 'e', 's', 'e', 'r', 'v', 'e', 'd', '_', 'r', 'a', 'n', 'g', 'e', '\030', '\004', ' ', '\003', '(', '\013',
+'2', '6', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'E', 'n', 'u', 'm', 'D', 'e',
+'s', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '.', 'E', 'n', 'u', 'm', 'R', 'e', 's', 'e', 'r', 'v', 'e',
+'d', 'R', 'a', 'n', 'g', 'e', 'R', '\r', 'r', 'e', 's', 'e', 'r', 'v', 'e', 'd', 'R', 'a', 'n', 'g', 'e', '\022', '#', '\n', '\r',
+'r', 'e', 's', 'e', 'r', 'v', 'e', 'd', '_', 'n', 'a', 'm', 'e', '\030', '\005', ' ', '\003', '(', '\t', 'R', '\014', 'r', 'e', 's', 'e',
+'r', 'v', 'e', 'd', 'N', 'a', 'm', 'e', '\032', ';', '\n', '\021', 'E', 'n', 'u', 'm', 'R', 'e', 's', 'e', 'r', 'v', 'e', 'd', 'R',
+'a', 'n', 'g', 'e', '\022', '\024', '\n', '\005', 's', 't', 'a', 'r', 't', '\030', '\001', ' ', '\001', '(', '\005', 'R', '\005', 's', 't', 'a', 'r',
+'t', '\022', '\020', '\n', '\003', 'e', 'n', 'd', '\030', '\002', ' ', '\001', '(', '\005', 'R', '\003', 'e', 'n', 'd', '\"', '\203', '\001', '\n', '\030', 'E',
+'n', 'u', 'm', 'V', 'a', 'l', 'u', 'e', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '\022', '\022',
+'\n', '\004', 'n', 'a', 'm', 'e', '\030', '\001', ' ', '\001', '(', '\t', 'R', '\004', 'n', 'a', 'm', 'e', '\022', '\026', '\n', '\006', 'n', 'u', 'm',
+'b', 'e', 'r', '\030', '\002', ' ', '\001', '(', '\005', 'R', '\006', 'n', 'u', 'm', 'b', 'e', 'r', '\022', ';', '\n', '\007', 'o', 'p', 't', 'i',
+'o', 'n', 's', '\030', '\003', ' ', '\001', '(', '\013', '2', '!', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b',
+'u', 'f', '.', 'E', 'n', 'u', 'm', 'V', 'a', 'l', 'u', 'e', 'O', 'p', 't', 'i', 'o', 'n', 's', 'R', '\007', 'o', 'p', 't', 'i',
+'o', 'n', 's', '\"', '\247', '\001', '\n', '\026', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r',
+'P', 'r', 'o', 't', 'o', '\022', '\022', '\n', '\004', 'n', 'a', 'm', 'e', '\030', '\001', ' ', '\001', '(', '\t', 'R', '\004', 'n', 'a', 'm', 'e',
+'\022', '>', '\n', '\006', 'm', 'e', 't', 'h', 'o', 'd', '\030', '\002', ' ', '\003', '(', '\013', '2', '&', '.', 'g', 'o', 'o', 'g', 'l', 'e',
+'.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'M', 'e', 't', 'h', 'o', 'd', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o',
+'r', 'P', 'r', 'o', 't', 'o', 'R', '\006', 'm', 'e', 't', 'h', 'o', 'd', '\022', '9', '\n', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's',
+'\030', '\003', ' ', '\001', '(', '\013', '2', '\037', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.',
+'S', 'e', 'r', 'v', 'i', 'c', 'e', 'O', 'p', 't', 'i', 'o', 'n', 's', 'R', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\"', '\211',
+'\002', '\n', '\025', 'M', 'e', 't', 'h', 'o', 'd', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', '\022',
+'\022', '\n', '\004', 'n', 'a', 'm', 'e', '\030', '\001', ' ', '\001', '(', '\t', 'R', '\004', 'n', 'a', 'm', 'e', '\022', '\035', '\n', '\n', 'i', 'n',
+'p', 'u', 't', '_', 't', 'y', 'p', 'e', '\030', '\002', ' ', '\001', '(', '\t', 'R', '\t', 'i', 'n', 'p', 'u', 't', 'T', 'y', 'p', 'e',
+'\022', '\037', '\n', '\013', 'o', 'u', 't', 'p', 'u', 't', '_', 't', 'y', 'p', 'e', '\030', '\003', ' ', '\001', '(', '\t', 'R', '\n', 'o', 'u',
+'t', 'p', 'u', 't', 'T', 'y', 'p', 'e', '\022', '8', '\n', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\030', '\004', ' ', '\001', '(', '\013',
+'2', '\036', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'M', 'e', 't', 'h', 'o', 'd',
+'O', 'p', 't', 'i', 'o', 'n', 's', 'R', '\007', 'o', 'p', 't', 'i', 'o', 'n', 's', '\022', '0', '\n', '\020', 'c', 'l', 'i', 'e', 'n',
+'t', '_', 's', 't', 'r', 'e', 'a', 'm', 'i', 'n', 'g', '\030', '\005', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R',
+'\017', 'c', 'l', 'i', 'e', 'n', 't', 'S', 't', 'r', 'e', 'a', 'm', 'i', 'n', 'g', '\022', '0', '\n', '\020', 's', 'e', 'r', 'v', 'e',
+'r', '_', 's', 't', 'r', 'e', 'a', 'm', 'i', 'n', 'g', '\030', '\006', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R',
+'\017', 's', 'e', 'r', 'v', 'e', 'r', 'S', 't', 'r', 'e', 'a', 'm', 'i', 'n', 'g', '\"', '\221', '\t', '\n', '\013', 'F', 'i', 'l', 'e',
+'O', 'p', 't', 'i', 'o', 'n', 's', '\022', '!', '\n', '\014', 'j', 'a', 'v', 'a', '_', 'p', 'a', 'c', 'k', 'a', 'g', 'e', '\030', '\001',
+' ', '\001', '(', '\t', 'R', '\013', 'j', 'a', 'v', 'a', 'P', 'a', 'c', 'k', 'a', 'g', 'e', '\022', '0', '\n', '\024', 'j', 'a', 'v', 'a',
+'_', 'o', 'u', 't', 'e', 'r', '_', 'c', 'l', 'a', 's', 's', 'n', 'a', 'm', 'e', '\030', '\010', ' ', '\001', '(', '\t', 'R', '\022', 'j',
+'a', 'v', 'a', 'O', 'u', 't', 'e', 'r', 'C', 'l', 'a', 's', 's', 'n', 'a', 'm', 'e', '\022', '5', '\n', '\023', 'j', 'a', 'v', 'a',
+'_', 'm', 'u', 'l', 't', 'i', 'p', 'l', 'e', '_', 'f', 'i', 'l', 'e', 's', '\030', '\n', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a',
+'l', 's', 'e', 'R', '\021', 'j', 'a', 'v', 'a', 'M', 'u', 'l', 't', 'i', 'p', 'l', 'e', 'F', 'i', 'l', 'e', 's', '\022', 'D', '\n',
+'\035', 'j', 'a', 'v', 'a', '_', 'g', 'e', 'n', 'e', 'r', 'a', 't', 'e', '_', 'e', 'q', 'u', 'a', 'l', 's', '_', 'a', 'n', 'd',
+'_', 'h', 'a', 's', 'h', '\030', '\024', ' ', '\001', '(', '\010', 'B', '\002', '\030', '\001', 'R', '\031', 'j', 'a', 'v', 'a', 'G', 'e', 'n', 'e',
+'r', 'a', 't', 'e', 'E', 'q', 'u', 'a', 'l', 's', 'A', 'n', 'd', 'H', 'a', 's', 'h', '\022', ':', '\n', '\026', 'j', 'a', 'v', 'a',
+'_', 's', 't', 'r', 'i', 'n', 'g', '_', 'c', 'h', 'e', 'c', 'k', '_', 'u', 't', 'f', '8', '\030', '\033', ' ', '\001', '(', '\010', ':',
+'\005', 'f', 'a', 'l', 's', 'e', 'R', '\023', 'j', 'a', 'v', 'a', 'S', 't', 'r', 'i', 'n', 'g', 'C', 'h', 'e', 'c', 'k', 'U', 't',
+'f', '8', '\022', 'S', '\n', '\014', 'o', 'p', 't', 'i', 'm', 'i', 'z', 'e', '_', 'f', 'o', 'r', '\030', '\t', ' ', '\001', '(', '\016', '2',
+')', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'l', 'e', 'O', 'p', 't',
+'i', 'o', 'n', 's', '.', 'O', 'p', 't', 'i', 'm', 'i', 'z', 'e', 'M', 'o', 'd', 'e', ':', '\005', 'S', 'P', 'E', 'E', 'D', 'R',
+'\013', 'o', 'p', 't', 'i', 'm', 'i', 'z', 'e', 'F', 'o', 'r', '\022', '\035', '\n', '\n', 'g', 'o', '_', 'p', 'a', 'c', 'k', 'a', 'g',
+'e', '\030', '\013', ' ', '\001', '(', '\t', 'R', '\t', 'g', 'o', 'P', 'a', 'c', 'k', 'a', 'g', 'e', '\022', '5', '\n', '\023', 'c', 'c', '_',
+'g', 'e', 'n', 'e', 'r', 'i', 'c', '_', 's', 'e', 'r', 'v', 'i', 'c', 'e', 's', '\030', '\020', ' ', '\001', '(', '\010', ':', '\005', 'f',
+'a', 'l', 's', 'e', 'R', '\021', 'c', 'c', 'G', 'e', 'n', 'e', 'r', 'i', 'c', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 's', '\022', '9',
+'\n', '\025', 'j', 'a', 'v', 'a', '_', 'g', 'e', 'n', 'e', 'r', 'i', 'c', '_', 's', 'e', 'r', 'v', 'i', 'c', 'e', 's', '\030', '\021',
+' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\023', 'j', 'a', 'v', 'a', 'G', 'e', 'n', 'e', 'r', 'i', 'c', 'S',
+'e', 'r', 'v', 'i', 'c', 'e', 's', '\022', '5', '\n', '\023', 'p', 'y', '_', 'g', 'e', 'n', 'e', 'r', 'i', 'c', '_', 's', 'e', 'r',
+'v', 'i', 'c', 'e', 's', '\030', '\022', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\021', 'p', 'y', 'G', 'e', 'n',
+'e', 'r', 'i', 'c', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 's', '\022', '7', '\n', '\024', 'p', 'h', 'p', '_', 'g', 'e', 'n', 'e', 'r',
+'i', 'c', '_', 's', 'e', 'r', 'v', 'i', 'c', 'e', 's', '\030', '*', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R',
+'\022', 'p', 'h', 'p', 'G', 'e', 'n', 'e', 'r', 'i', 'c', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 's', '\022', '%', '\n', '\n', 'd', 'e',
+'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '\027', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\n', 'd', 'e',
+'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', '.', '\n', '\020', 'c', 'c', '_', 'e', 'n', 'a', 'b', 'l', 'e', '_', 'a', 'r', 'e',
+'n', 'a', 's', '\030', '\037', ' ', '\001', '(', '\010', ':', '\004', 't', 'r', 'u', 'e', 'R', '\016', 'c', 'c', 'E', 'n', 'a', 'b', 'l', 'e',
+'A', 'r', 'e', 'n', 'a', 's', '\022', '*', '\n', '\021', 'o', 'b', 'j', 'c', '_', 'c', 'l', 'a', 's', 's', '_', 'p', 'r', 'e', 'f',
+'i', 'x', '\030', '$', ' ', '\001', '(', '\t', 'R', '\017', 'o', 'b', 'j', 'c', 'C', 'l', 'a', 's', 's', 'P', 'r', 'e', 'f', 'i', 'x',
+'\022', ')', '\n', '\020', 'c', 's', 'h', 'a', 'r', 'p', '_', 'n', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\030', '%', ' ', '\001', '(',
+'\t', 'R', '\017', 'c', 's', 'h', 'a', 'r', 'p', 'N', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\022', '!', '\n', '\014', 's', 'w', 'i',
+'f', 't', '_', 'p', 'r', 'e', 'f', 'i', 'x', '\030', '\'', ' ', '\001', '(', '\t', 'R', '\013', 's', 'w', 'i', 'f', 't', 'P', 'r', 'e',
+'f', 'i', 'x', '\022', '(', '\n', '\020', 'p', 'h', 'p', '_', 'c', 'l', 'a', 's', 's', '_', 'p', 'r', 'e', 'f', 'i', 'x', '\030', '(',
+' ', '\001', '(', '\t', 'R', '\016', 'p', 'h', 'p', 'C', 'l', 'a', 's', 's', 'P', 'r', 'e', 'f', 'i', 'x', '\022', '#', '\n', '\r', 'p',
+'h', 'p', '_', 'n', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\030', ')', ' ', '\001', '(', '\t', 'R', '\014', 'p', 'h', 'p', 'N', 'a',
+'m', 'e', 's', 'p', 'a', 'c', 'e', '\022', '4', '\n', '\026', 'p', 'h', 'p', '_', 'm', 'e', 't', 'a', 'd', 'a', 't', 'a', '_', 'n',
+'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\030', ',', ' ', '\001', '(', '\t', 'R', '\024', 'p', 'h', 'p', 'M', 'e', 't', 'a', 'd', 'a',
+'t', 'a', 'N', 'a', 'm', 'e', 's', 'p', 'a', 'c', 'e', '\022', '!', '\n', '\014', 'r', 'u', 'b', 'y', '_', 'p', 'a', 'c', 'k', 'a',
+'g', 'e', '\030', '-', ' ', '\001', '(', '\t', 'R', '\013', 'r', 'u', 'b', 'y', 'P', 'a', 'c', 'k', 'a', 'g', 'e', '\022', 'X', '\n', '\024',
+'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003',
+'(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n',
+'t', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p',
+'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '\"', ':', '\n', '\014', 'O', 'p', 't', 'i', 'm', 'i', 'z', 'e', 'M', 'o',
+'d', 'e', '\022', '\t', '\n', '\005', 'S', 'P', 'E', 'E', 'D', '\020', '\001', '\022', '\r', '\n', '\t', 'C', 'O', 'D', 'E', '_', 'S', 'I', 'Z',
+'E', '\020', '\002', '\022', '\020', '\n', '\014', 'L', 'I', 'T', 'E', '_', 'R', 'U', 'N', 'T', 'I', 'M', 'E', '\020', '\003', '*', '\t', '\010', '\350',
+'\007', '\020', '\200', '\200', '\200', '\200', '\002', 'J', '\004', '\010', '&', '\020', '\'', '\"', '\321', '\002', '\n', '\016', 'M', 'e', 's', 's', 'a', 'g', 'e',
+'O', 'p', 't', 'i', 'o', 'n', 's', '\022', '<', '\n', '\027', 'm', 'e', 's', 's', 'a', 'g', 'e', '_', 's', 'e', 't', '_', 'w', 'i',
+'r', 'e', '_', 'f', 'o', 'r', 'm', 'a', 't', '\030', '\001', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\024', 'm',
+'e', 's', 's', 'a', 'g', 'e', 'S', 'e', 't', 'W', 'i', 'r', 'e', 'F', 'o', 'r', 'm', 'a', 't', '\022', 'L', '\n', '\037', 'n', 'o',
+'_', 's', 't', 'a', 'n', 'd', 'a', 'r', 'd', '_', 'd', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', '_', 'a', 'c', 'c', 'e',
+'s', 's', 'o', 'r', '\030', '\002', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\034', 'n', 'o', 'S', 't', 'a', 'n',
+'d', 'a', 'r', 'd', 'D', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'A', 'c', 'c', 'e', 's', 's', 'o', 'r', '\022', '%', '\n',
+'\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '\003', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R',
+'\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', '\033', '\n', '\t', 'm', 'a', 'p', '_', 'e', 'n', 't', 'r', 'y', '\030',
+'\007', ' ', '\001', '(', '\010', 'R', '\010', 'm', 'a', 'p', 'E', 'n', 't', 'r', 'y', '\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', 'e',
+'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', '2', '$', '.', 'g',
+'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e',
+'t', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O',
+'p', 't', 'i', 'o', 'n', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', 'J', '\004', '\010', '\010', '\020', '\t', 'J', '\004', '\010',
+'\t', '\020', '\n', '\"', '\342', '\003', '\n', '\014', 'F', 'i', 'e', 'l', 'd', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', 'A', '\n', '\005', 'c',
+'t', 'y', 'p', 'e', '\030', '\001', ' ', '\001', '(', '\016', '2', '#', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o',
+'b', 'u', 'f', '.', 'F', 'i', 'e', 'l', 'd', 'O', 'p', 't', 'i', 'o', 'n', 's', '.', 'C', 'T', 'y', 'p', 'e', ':', '\006', 'S',
+'T', 'R', 'I', 'N', 'G', 'R', '\005', 'c', 't', 'y', 'p', 'e', '\022', '\026', '\n', '\006', 'p', 'a', 'c', 'k', 'e', 'd', '\030', '\002', ' ',
+'\001', '(', '\010', 'R', '\006', 'p', 'a', 'c', 'k', 'e', 'd', '\022', 'G', '\n', '\006', 'j', 's', 't', 'y', 'p', 'e', '\030', '\006', ' ', '\001',
+'(', '\016', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'F', 'i', 'e', 'l',
+'d', 'O', 'p', 't', 'i', 'o', 'n', 's', '.', 'J', 'S', 'T', 'y', 'p', 'e', ':', '\t', 'J', 'S', '_', 'N', 'O', 'R', 'M', 'A',
+'L', 'R', '\006', 'j', 's', 't', 'y', 'p', 'e', '\022', '\031', '\n', '\004', 'l', 'a', 'z', 'y', '\030', '\005', ' ', '\001', '(', '\010', ':', '\005',
+'f', 'a', 'l', 's', 'e', 'R', '\004', 'l', 'a', 'z', 'y', '\022', '%', '\n', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd',
+'\030', '\003', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd',
+'\022', '\031', '\n', '\004', 'w', 'e', 'a', 'k', '\030', '\n', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\004', 'w', 'e',
+'a', 'k', '\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o',
+'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u',
+'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n',
+'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '\"', '/', '\n', '\005', 'C', 'T', 'y', 'p',
+'e', '\022', '\n', '\n', '\006', 'S', 'T', 'R', 'I', 'N', 'G', '\020', '\000', '\022', '\010', '\n', '\004', 'C', 'O', 'R', 'D', '\020', '\001', '\022', '\020',
+'\n', '\014', 'S', 'T', 'R', 'I', 'N', 'G', '_', 'P', 'I', 'E', 'C', 'E', '\020', '\002', '\"', '5', '\n', '\006', 'J', 'S', 'T', 'y', 'p',
+'e', '\022', '\r', '\n', '\t', 'J', 'S', '_', 'N', 'O', 'R', 'M', 'A', 'L', '\020', '\000', '\022', '\r', '\n', '\t', 'J', 'S', '_', 'S', 'T',
+'R', 'I', 'N', 'G', '\020', '\001', '\022', '\r', '\n', '\t', 'J', 'S', '_', 'N', 'U', 'M', 'B', 'E', 'R', '\020', '\002', '*', '\t', '\010', '\350',
+'\007', '\020', '\200', '\200', '\200', '\200', '\002', 'J', '\004', '\010', '\004', '\020', '\005', '\"', 's', '\n', '\014', 'O', 'n', 'e', 'o', 'f', 'O', 'p', 't',
+'i', 'o', 'n', 's', '\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't',
+'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o',
+'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023',
+'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '*', '\t', '\010', '\350', '\007', '\020',
+'\200', '\200', '\200', '\200', '\002', '\"', '\300', '\001', '\n', '\013', 'E', 'n', 'u', 'm', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', '\037', '\n', '\013',
+'a', 'l', 'l', 'o', 'w', '_', 'a', 'l', 'i', 'a', 's', '\030', '\002', ' ', '\001', '(', '\010', 'R', '\n', 'a', 'l', 'l', 'o', 'w', 'A',
+'l', 'i', 'a', 's', '\022', '%', '\n', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '\003', ' ', '\001', '(', '\010', ':',
+'\005', 'f', 'a', 'l', 's', 'e', 'R', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', 'X', '\n', '\024', 'u', 'n', 'i',
+'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', '2',
+'$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r',
+'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't',
+'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', 'J', '\004', '\010', '\005', '\020', '\006',
+'\"', '\236', '\001', '\n', '\020', 'E', 'n', 'u', 'm', 'V', 'a', 'l', 'u', 'e', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', '%', '\n', '\n',
+'d', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '\001', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\n',
+'d', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't',
+'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', '2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e',
+'.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p',
+'t', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n',
+'*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', '\"', '\234', '\001', '\n', '\016', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 'O', 'p',
+'t', 'i', 'o', 'n', 's', '\022', '%', '\n', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\030', '!', ' ', '\001', '(', '\010',
+':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't', 'e', 'd', '\022', 'X', '\n', '\024', 'u', 'n',
+'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', '(', '\013',
+'2', '$', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', 'e',
+'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e',
+'t', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002', '\"', '\340', '\002', '\n', '\r',
+'M', 'e', 't', 'h', 'o', 'd', 'O', 'p', 't', 'i', 'o', 'n', 's', '\022', '%', '\n', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't',
+'e', 'd', '\030', '!', ' ', '\001', '(', '\010', ':', '\005', 'f', 'a', 'l', 's', 'e', 'R', '\n', 'd', 'e', 'p', 'r', 'e', 'c', 'a', 't',
+'e', 'd', '\022', 'q', '\n', '\021', 'i', 'd', 'e', 'm', 'p', 'o', 't', 'e', 'n', 'c', 'y', '_', 'l', 'e', 'v', 'e', 'l', '\030', '\"',
+' ', '\001', '(', '\016', '2', '/', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'M', 'e',
+'t', 'h', 'o', 'd', 'O', 'p', 't', 'i', 'o', 'n', 's', '.', 'I', 'd', 'e', 'm', 'p', 'o', 't', 'e', 'n', 'c', 'y', 'L', 'e',
+'v', 'e', 'l', ':', '\023', 'I', 'D', 'E', 'M', 'P', 'O', 'T', 'E', 'N', 'C', 'Y', '_', 'U', 'N', 'K', 'N', 'O', 'W', 'N', 'R',
+'\020', 'i', 'd', 'e', 'm', 'p', 'o', 't', 'e', 'n', 'c', 'y', 'L', 'e', 'v', 'e', 'l', '\022', 'X', '\n', '\024', 'u', 'n', 'i', 'n',
+'t', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', '_', 'o', 'p', 't', 'i', 'o', 'n', '\030', '\347', '\007', ' ', '\003', '(', '\013', '2', '$',
+'.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p',
+'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', 'R', '\023', 'u', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e',
+'d', 'O', 'p', 't', 'i', 'o', 'n', '\"', 'P', '\n', '\020', 'I', 'd', 'e', 'm', 'p', 'o', 't', 'e', 'n', 'c', 'y', 'L', 'e', 'v',
+'e', 'l', '\022', '\027', '\n', '\023', 'I', 'D', 'E', 'M', 'P', 'O', 'T', 'E', 'N', 'C', 'Y', '_', 'U', 'N', 'K', 'N', 'O', 'W', 'N',
+'\020', '\000', '\022', '\023', '\n', '\017', 'N', 'O', '_', 'S', 'I', 'D', 'E', '_', 'E', 'F', 'F', 'E', 'C', 'T', 'S', '\020', '\001', '\022', '\016',
+'\n', '\n', 'I', 'D', 'E', 'M', 'P', 'O', 'T', 'E', 'N', 'T', '\020', '\002', '*', '\t', '\010', '\350', '\007', '\020', '\200', '\200', '\200', '\200', '\002',
+'\"', '\232', '\003', '\n', '\023', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o', 'n', '\022',
+'A', '\n', '\004', 'n', 'a', 'm', 'e', '\030', '\002', ' ', '\003', '(', '\013', '2', '-', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r',
+'o', 't', 'o', 'b', 'u', 'f', '.', 'U', 'n', 'i', 'n', 't', 'e', 'r', 'p', 'r', 'e', 't', 'e', 'd', 'O', 'p', 't', 'i', 'o',
+'n', '.', 'N', 'a', 'm', 'e', 'P', 'a', 'r', 't', 'R', '\004', 'n', 'a', 'm', 'e', '\022', ')', '\n', '\020', 'i', 'd', 'e', 'n', 't',
+'i', 'f', 'i', 'e', 'r', '_', 'v', 'a', 'l', 'u', 'e', '\030', '\003', ' ', '\001', '(', '\t', 'R', '\017', 'i', 'd', 'e', 'n', 't', 'i',
+'f', 'i', 'e', 'r', 'V', 'a', 'l', 'u', 'e', '\022', ',', '\n', '\022', 'p', 'o', 's', 'i', 't', 'i', 'v', 'e', '_', 'i', 'n', 't',
+'_', 'v', 'a', 'l', 'u', 'e', '\030', '\004', ' ', '\001', '(', '\004', 'R', '\020', 'p', 'o', 's', 'i', 't', 'i', 'v', 'e', 'I', 'n', 't',
+'V', 'a', 'l', 'u', 'e', '\022', ',', '\n', '\022', 'n', 'e', 'g', 'a', 't', 'i', 'v', 'e', '_', 'i', 'n', 't', '_', 'v', 'a', 'l',
+'u', 'e', '\030', '\005', ' ', '\001', '(', '\003', 'R', '\020', 'n', 'e', 'g', 'a', 't', 'i', 'v', 'e', 'I', 'n', 't', 'V', 'a', 'l', 'u',
+'e', '\022', '!', '\n', '\014', 'd', 'o', 'u', 'b', 'l', 'e', '_', 'v', 'a', 'l', 'u', 'e', '\030', '\006', ' ', '\001', '(', '\001', 'R', '\013',
+'d', 'o', 'u', 'b', 'l', 'e', 'V', 'a', 'l', 'u', 'e', '\022', '!', '\n', '\014', 's', 't', 'r', 'i', 'n', 'g', '_', 'v', 'a', 'l',
+'u', 'e', '\030', '\007', ' ', '\001', '(', '\014', 'R', '\013', 's', 't', 'r', 'i', 'n', 'g', 'V', 'a', 'l', 'u', 'e', '\022', '\'', '\n', '\017',
+'a', 'g', 'g', 'r', 'e', 'g', 'a', 't', 'e', '_', 'v', 'a', 'l', 'u', 'e', '\030', '\010', ' ', '\001', '(', '\t', 'R', '\016', 'a', 'g',
+'g', 'r', 'e', 'g', 'a', 't', 'e', 'V', 'a', 'l', 'u', 'e', '\032', 'J', '\n', '\010', 'N', 'a', 'm', 'e', 'P', 'a', 'r', 't', '\022',
+'\033', '\n', '\t', 'n', 'a', 'm', 'e', '_', 'p', 'a', 'r', 't', '\030', '\001', ' ', '\002', '(', '\t', 'R', '\010', 'n', 'a', 'm', 'e', 'P',
+'a', 'r', 't', '\022', '!', '\n', '\014', 'i', 's', '_', 'e', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', '\030', '\002', ' ', '\002', '(', '\010',
+'R', '\013', 'i', 's', 'E', 'x', 't', 'e', 'n', 's', 'i', 'o', 'n', '\"', '\247', '\002', '\n', '\016', 'S', 'o', 'u', 'r', 'c', 'e', 'C',
+'o', 'd', 'e', 'I', 'n', 'f', 'o', '\022', 'D', '\n', '\010', 'l', 'o', 'c', 'a', 't', 'i', 'o', 'n', '\030', '\001', ' ', '\003', '(', '\013',
+'2', '(', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'S', 'o', 'u', 'r', 'c', 'e',
+'C', 'o', 'd', 'e', 'I', 'n', 'f', 'o', '.', 'L', 'o', 'c', 'a', 't', 'i', 'o', 'n', 'R', '\010', 'l', 'o', 'c', 'a', 't', 'i',
+'o', 'n', '\032', '\316', '\001', '\n', '\010', 'L', 'o', 'c', 'a', 't', 'i', 'o', 'n', '\022', '\026', '\n', '\004', 'p', 'a', 't', 'h', '\030', '\001',
+' ', '\003', '(', '\005', 'B', '\002', '\020', '\001', 'R', '\004', 'p', 'a', 't', 'h', '\022', '\026', '\n', '\004', 's', 'p', 'a', 'n', '\030', '\002', ' ',
+'\003', '(', '\005', 'B', '\002', '\020', '\001', 'R', '\004', 's', 'p', 'a', 'n', '\022', ')', '\n', '\020', 'l', 'e', 'a', 'd', 'i', 'n', 'g', '_',
+'c', 'o', 'm', 'm', 'e', 'n', 't', 's', '\030', '\003', ' ', '\001', '(', '\t', 'R', '\017', 'l', 'e', 'a', 'd', 'i', 'n', 'g', 'C', 'o',
+'m', 'm', 'e', 'n', 't', 's', '\022', '+', '\n', '\021', 't', 'r', 'a', 'i', 'l', 'i', 'n', 'g', '_', 'c', 'o', 'm', 'm', 'e', 'n',
+'t', 's', '\030', '\004', ' ', '\001', '(', '\t', 'R', '\020', 't', 'r', 'a', 'i', 'l', 'i', 'n', 'g', 'C', 'o', 'm', 'm', 'e', 'n', 't',
+'s', '\022', ':', '\n', '\031', 'l', 'e', 'a', 'd', 'i', 'n', 'g', '_', 'd', 'e', 't', 'a', 'c', 'h', 'e', 'd', '_', 'c', 'o', 'm',
+'m', 'e', 'n', 't', 's', '\030', '\006', ' ', '\003', '(', '\t', 'R', '\027', 'l', 'e', 'a', 'd', 'i', 'n', 'g', 'D', 'e', 't', 'a', 'c',
+'h', 'e', 'd', 'C', 'o', 'm', 'm', 'e', 'n', 't', 's', '\"', '\321', '\001', '\n', '\021', 'G', 'e', 'n', 'e', 'r', 'a', 't', 'e', 'd',
+'C', 'o', 'd', 'e', 'I', 'n', 'f', 'o', '\022', 'M', '\n', '\n', 'a', 'n', 'n', 'o', 't', 'a', 't', 'i', 'o', 'n', '\030', '\001', ' ',
+'\003', '(', '\013', '2', '-', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'G', 'e', 'n',
+'e', 'r', 'a', 't', 'e', 'd', 'C', 'o', 'd', 'e', 'I', 'n', 'f', 'o', '.', 'A', 'n', 'n', 'o', 't', 'a', 't', 'i', 'o', 'n',
+'R', '\n', 'a', 'n', 'n', 'o', 't', 'a', 't', 'i', 'o', 'n', '\032', 'm', '\n', '\n', 'A', 'n', 'n', 'o', 't', 'a', 't', 'i', 'o',
+'n', '\022', '\026', '\n', '\004', 'p', 'a', 't', 'h', '\030', '\001', ' ', '\003', '(', '\005', 'B', '\002', '\020', '\001', 'R', '\004', 'p', 'a', 't', 'h',
+'\022', '\037', '\n', '\013', 's', 'o', 'u', 'r', 'c', 'e', '_', 'f', 'i', 'l', 'e', '\030', '\002', ' ', '\001', '(', '\t', 'R', '\n', 's', 'o',
+'u', 'r', 'c', 'e', 'F', 'i', 'l', 'e', '\022', '\024', '\n', '\005', 'b', 'e', 'g', 'i', 'n', '\030', '\003', ' ', '\001', '(', '\005', 'R', '\005',
+'b', 'e', 'g', 'i', 'n', '\022', '\020', '\n', '\003', 'e', 'n', 'd', '\030', '\004', ' ', '\001', '(', '\005', 'R', '\003', 'e', 'n', 'd', 'B', '\217',
+'\001', '\n', '\023', 'c', 'o', 'm', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', 'B', '\020', 'D',
+'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', 'P', 'r', 'o', 't', 'o', 's', 'H', '\001', 'Z', '>', 'g', 'i', 't', 'h', 'u', 'b',
+'.', 'c', 'o', 'm', '/', 'g', 'o', 'l', 'a', 'n', 'g', '/', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '/', 'p', 'r', 'o', 't',
+'o', 'c', '-', 'g', 'e', 'n', '-', 'g', 'o', '/', 'd', 'e', 's', 'c', 'r', 'i', 'p', 't', 'o', 'r', ';', 'd', 'e', 's', 'c',
+'r', 'i', 'p', 't', 'o', 'r', '\370', '\001', '\001', '\242', '\002', '\003', 'G', 'P', 'B', '\252', '\002', '\032', 'G', 'o', 'o', 'g', 'l', 'e', '.',
+'P', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'R', 'e', 'f', 'l', 'e', 'c', 't', 'i', 'o', 'n',
+};
+
+static upb_def_init *deps[1] = {
+ NULL
+};
+
+upb_def_init google_protobuf_descriptor_proto_upbdefinit = {
+ deps,
+ layouts,
+ "google/protobuf/descriptor.proto",
+ UPB_STRVIEW_INIT(descriptor, 7619)
+};
+
+
+#include
+#include