Commit 90922db7 authored by csharptest's avatar csharptest Committed by rogerk

Added the field name to all CodedOutputStream.Write??? calls

Refactored 'speed' generated write of arrays to call Write???Array.  This may
have impacted speed write speeds for arrays of non-reference types due to the
use of non-generic IEnumerable and the subsequent boxing of value types.  This
could be addressed later if desired.
parent 8a2d0f48
@echo off
%WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild build.csproj /m /t:RunBenchmarks /p:BuildConfiguration=Release /p:Platform="Any CPU"
%WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild %~dp0\build.csproj /m /t:RunBenchmarks /p:BuildConfiguration=Release /p:Platform="Any CPU"
pause
\ No newline at end of file
......@@ -155,10 +155,10 @@ namespace Google.ProtocolBuffers.Examples.AddressBook {
public override void WriteTo(pb::CodedOutputStream output) {
int size = SerializedSize;
if (HasNumber) {
output.WriteString(1, Number);
output.WriteString(1, "number", Number);
}
if (HasType) {
output.WriteEnum(2, (int) Type);
output.WriteEnum(2, "type", (int) Type, Type.ToString());
}
UnknownFields.WriteTo(output);
}
......@@ -431,16 +431,16 @@ namespace Google.ProtocolBuffers.Examples.AddressBook {
public override void WriteTo(pb::CodedOutputStream output) {
int size = SerializedSize;
if (HasName) {
output.WriteString(1, Name);
output.WriteString(1, "name", Name);
}
if (HasId) {
output.WriteInt32(2, Id);
output.WriteInt32(2, "id", Id);
}
if (HasEmail) {
output.WriteString(3, Email);
output.WriteString(3, "email", Email);
}
foreach (global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneNumber element in PhoneList) {
output.WriteMessage(4, element);
if (phone_.Count > 0) {
output.WriteMessageArray(4, "phone", phone_);
}
UnknownFields.WriteTo(output);
}
......@@ -774,8 +774,8 @@ namespace Google.ProtocolBuffers.Examples.AddressBook {
public override void WriteTo(pb::CodedOutputStream output) {
int size = SerializedSize;
foreach (global::Google.ProtocolBuffers.Examples.AddressBook.Person element in PersonList) {
output.WriteMessage(1, element);
if (person_.Count > 0) {
output.WriteMessageArray(1, "person", person_);
}
UnknownFields.WriteTo(output);
}
......
......@@ -113,7 +113,7 @@ namespace Google.ProtocolBuffers.ProtoGen
public void GenerateSerializationCode(TextGenerator writer)
{
writer.WriteLine("if (Has{0}) {{", PropertyName);
writer.WriteLine(" output.WriteEnum({0}, (int) {1});", Number, PropertyName);
writer.WriteLine(" output.WriteEnum({0}, \"{2}\", (int) {1}, {1}.ToString());", Number, PropertyName, Descriptor.Name);
writer.WriteLine("}");
}
......
......@@ -129,7 +129,7 @@ namespace Google.ProtocolBuffers.ProtoGen
public void GenerateSerializationCode(TextGenerator writer)
{
writer.WriteLine("if (Has{0}) {{", PropertyName);
writer.WriteLine(" output.Write{0}({1}, {2});", MessageOrGroup, Number, PropertyName);
writer.WriteLine(" output.Write{0}({1}, \"{3}\", {2});", MessageOrGroup, Number, PropertyName, Descriptor.Name);
writer.WriteLine("}");
}
......
......@@ -103,7 +103,7 @@ namespace Google.ProtocolBuffers.ProtoGen
public void GenerateSerializationCode(TextGenerator writer)
{
writer.WriteLine("if (Has{0}) {{", PropertyName);
writer.WriteLine(" output.Write{0}({1}, {2});", CapitalizedTypeName, Number, PropertyName);
writer.WriteLine(" output.Write{0}({1}, \"{3}\", {2});", CapitalizedTypeName, Number, PropertyName, Descriptor.Name);
writer.WriteLine("}");
}
......
......@@ -149,19 +149,23 @@ namespace Google.ProtocolBuffers.ProtoGen
writer.WriteLine("if ({0}_.Count > 0) {{", Name);
writer.Indent();
if (Descriptor.IsPacked)
{
writer.WriteLine("output.WriteRawVarint32({0});", WireFormat.MakeTag(Descriptor));
writer.WriteLine("output.WriteRawVarint32((uint) {0}MemoizedSerializedSize);", Name);
writer.WriteLine("foreach (int element in {0}_) {{", Name);
writer.WriteLine(" output.WriteEnumNoTag(element);");
writer.WriteLine("}");
}
writer.WriteLine("output.WritePackedArray(pbd::FieldType.{3}, {0}, \"{2}\", {1}MemoizedSerializedSize, {1}_);", Number, Name, Descriptor.Name, Descriptor.FieldType);
else
{
writer.WriteLine("foreach (int element in {0}_) {{", Name);
writer.WriteLine(" output.WriteEnum({0}, element);", Number);
writer.WriteLine("}");
}
writer.WriteLine("output.WriteArray(pbd::FieldType.{3}, {0}, \"{2}\", {1}_);", Number, Name, Descriptor.Name, Descriptor.FieldType);
//if (Descriptor.IsPacked)
//{
// writer.WriteLine("output.WriteRawVarint32({0});", WireFormat.MakeTag(Descriptor));
// writer.WriteLine("output.WriteRawVarint32((uint) {0}MemoizedSerializedSize);", Name);
// writer.WriteLine("foreach (int element in {0}_) {{", Name);
// writer.WriteLine(" output.WriteEnumNoTag(element);");
// writer.WriteLine("}");
//}
//else
//{
// writer.WriteLine("foreach (int element in {0}_) {{", Name);
// writer.WriteLine(" output.WriteEnum({0}, element);", Number);
// writer.WriteLine("}");
//}
writer.Outdent();
writer.WriteLine("}");
}
......
......@@ -135,8 +135,13 @@ namespace Google.ProtocolBuffers.ProtoGen
public void GenerateSerializationCode(TextGenerator writer)
{
writer.WriteLine("foreach ({0} element in {1}List) {{", TypeName, PropertyName);
writer.WriteLine(" output.Write{0}({1}, element);", MessageOrGroup, Number);
writer.WriteLine("if ({0}_.Count > 0) {{", Name);
writer.Indent();
writer.WriteLine("output.Write{0}Array({1}, \"{3}\", {2}_);", MessageOrGroup, Number, Name, Descriptor.Name);
//writer.WriteLine("foreach ({0} element in {1}List) {{", TypeName, PropertyName);
//writer.WriteLine(" output.Write{0}({1}, element);", MessageOrGroup, Number);
//writer.WriteLine("}");
writer.Outdent();
writer.WriteLine("}");
}
......
......@@ -141,19 +141,23 @@ namespace Google.ProtocolBuffers.ProtoGen
writer.WriteLine("if ({0}_.Count > 0) {{", Name);
writer.Indent();
if (Descriptor.IsPacked)
{
writer.WriteLine("output.WriteRawVarint32({0});", WireFormat.MakeTag(Descriptor));
writer.WriteLine("output.WriteRawVarint32((uint) {0}MemoizedSerializedSize);", Name);
writer.WriteLine("foreach ({0} element in {1}_) {{", TypeName, Name);
writer.WriteLine(" output.Write{0}NoTag(element);", CapitalizedTypeName);
writer.WriteLine("}");
}
writer.WriteLine("output.WritePackedArray(pbd::FieldType.{3}, {0}, \"{2}\", {1}MemoizedSerializedSize, {1}_);", Number, Name, Descriptor.Name, Descriptor.FieldType);
else
{
writer.WriteLine("foreach ({0} element in {1}_) {{", TypeName, Name);
writer.WriteLine(" output.Write{0}({1}, element);", CapitalizedTypeName, Number);
writer.WriteLine("}");
}
writer.WriteLine("output.WriteArray(pbd::FieldType.{3}, {0}, \"{2}\", {1}_);", Number, Name, Descriptor.Name, Descriptor.FieldType);
//if (Descriptor.IsPacked)
//{
// writer.WriteLine("output.WriteRawVarint32({0});", WireFormat.MakeTag(Descriptor));
// writer.WriteLine("output.WriteRawVarint32((uint) {0}MemoizedSerializedSize);", Name);
// writer.WriteLine("foreach ({0} element in {1}_) {{", TypeName, Name);
// writer.WriteLine(" output.Write{0}NoTag(element);", CapitalizedTypeName);
// writer.WriteLine("}");
//}
//else
//{
// writer.WriteLine("foreach ({0} element in {1}_) {{", TypeName, Name);
// writer.WriteLine(" output.Write{0}({1}, element);", CapitalizedTypeName, Number);
// writer.WriteLine("}");
//}
writer.Outdent();
writer.WriteLine("}");
}
......
......@@ -118,13 +118,13 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::CodedOutputStream output) {
int size = SerializedSize;
if (HasNormal) {
output.WriteString(1, Normal);
output.WriteString(1, "normal", Normal);
}
if (HasOptionsMessage_) {
output.WriteString(2, OptionsMessage_);
output.WriteString(2, "options_message", OptionsMessage_);
}
if (HasCustomName) {
output.WriteString(3, CustomName);
output.WriteString(3, "customized", CustomName);
}
UnknownFields.WriteTo(output);
}
......
......@@ -453,7 +453,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::CodedOutputStream output) {
int size = SerializedSize;
if (HasField1) {
output.WriteString(1, Field1);
output.WriteString(1, "field1", Field1);
}
UnknownFields.WriteTo(output);
}
......@@ -2332,13 +2332,13 @@ namespace Google.ProtocolBuffers.TestProtos {
int size = SerializedSize;
pb::ExtendableMessage<ComplexOptionType1, ComplexOptionType1.Builder>.ExtensionWriter extensionWriter = CreateExtensionWriter(this);
if (HasFoo) {
output.WriteInt32(1, Foo);
output.WriteInt32(1, "foo", Foo);
}
if (HasFoo2) {
output.WriteInt32(2, Foo2);
output.WriteInt32(2, "foo2", Foo2);
}
if (HasFoo3) {
output.WriteInt32(3, Foo3);
output.WriteInt32(3, "foo3", Foo3);
}
extensionWriter.WriteUntil(536870912, output);
UnknownFields.WriteTo(output);
......@@ -2650,7 +2650,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::CodedOutputStream output) {
int size = SerializedSize;
if (HasWaldo) {
output.WriteInt32(1, Waldo);
output.WriteInt32(1, "waldo", Waldo);
}
UnknownFields.WriteTo(output);
}
......@@ -2874,13 +2874,13 @@ namespace Google.ProtocolBuffers.TestProtos {
int size = SerializedSize;
pb::ExtendableMessage<ComplexOptionType2, ComplexOptionType2.Builder>.ExtensionWriter extensionWriter = CreateExtensionWriter(this);
if (HasBar) {
output.WriteMessage(1, Bar);
output.WriteMessage(1, "bar", Bar);
}
if (HasBaz) {
output.WriteInt32(2, Baz);
output.WriteInt32(2, "baz", Baz);
}
if (HasFred) {
output.WriteMessage(3, Fred);
output.WriteMessage(3, "fred", Fred);
}
extensionWriter.WriteUntil(536870912, output);
UnknownFields.WriteTo(output);
......@@ -3236,7 +3236,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::CodedOutputStream output) {
int size = SerializedSize;
if (HasPlugh) {
output.WriteInt32(3, Plugh);
output.WriteInt32(3, "plugh", Plugh);
}
UnknownFields.WriteTo(output);
}
......@@ -3445,10 +3445,10 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::CodedOutputStream output) {
int size = SerializedSize;
if (HasQux) {
output.WriteInt32(1, Qux);
output.WriteInt32(1, "qux", Qux);
}
if (HasComplexOptionType5) {
output.WriteGroup(2, ComplexOptionType5);
output.WriteGroup(2, "complexoptiontype5", ComplexOptionType5);
}
UnknownFields.WriteTo(output);
}
......@@ -3720,7 +3720,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::CodedOutputStream output) {
int size = SerializedSize;
if (HasXyzzy) {
output.WriteInt32(7593951, Xyzzy);
output.WriteInt32(7593951, "xyzzy", Xyzzy);
}
UnknownFields.WriteTo(output);
}
......
......@@ -120,10 +120,10 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::CodedOutputStream output) {
int size = SerializedSize;
if (HasOptionalMessage) {
output.WriteMessage(1, OptionalMessage);
output.WriteMessage(1, "optional_message", OptionalMessage);
}
foreach (global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize element in RepeatedMessageList) {
output.WriteMessage(2, element);
if (repeatedMessage_.Count > 0) {
output.WriteMessageArray(2, "repeated_message", repeatedMessage_);
}
UnknownFields.WriteTo(output);
}
......
......@@ -73,7 +73,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::CodedOutputStream output) {
int size = SerializedSize;
if (HasD) {
output.WriteInt32(1, D);
output.WriteInt32(1, "d", D);
}
}
......
......@@ -109,7 +109,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::CodedOutputStream output) {
int size = SerializedSize;
if (HasD) {
output.WriteInt32(1, D);
output.WriteInt32(1, "d", D);
}
UnknownFields.WriteTo(output);
}
......
......@@ -326,7 +326,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::CodedOutputStream output) {
int size = SerializedSize;
if (HasMessageSet) {
output.WriteMessage(1, MessageSet);
output.WriteMessage(1, "message_set", MessageSet);
}
UnknownFields.WriteTo(output);
}
......@@ -572,7 +572,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::CodedOutputStream output) {
int size = SerializedSize;
if (HasI) {
output.WriteInt32(15, I);
output.WriteInt32(15, "i", I);
}
UnknownFields.WriteTo(output);
}
......@@ -795,7 +795,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::CodedOutputStream output) {
int size = SerializedSize;
if (HasStr) {
output.WriteString(25, Str);
output.WriteString(25, "str", Str);
}
UnknownFields.WriteTo(output);
}
......@@ -1059,10 +1059,10 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::CodedOutputStream output) {
int size = SerializedSize;
if (HasTypeId) {
output.WriteInt32(2, TypeId);
output.WriteInt32(2, "type_id", TypeId);
}
if (HasMessage) {
output.WriteBytes(3, Message);
output.WriteBytes(3, "message", Message);
}
UnknownFields.WriteTo(output);
}
......@@ -1291,8 +1291,8 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::CodedOutputStream output) {
int size = SerializedSize;
foreach (global::Google.ProtocolBuffers.TestProtos.RawMessageSet.Types.Item element in ItemList) {
output.WriteGroup(1, element);
if (item_.Count > 0) {
output.WriteGroupArray(1, "item", item_);
}
UnknownFields.WriteTo(output);
}
......
......@@ -121,7 +121,7 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService {
int size = SerializedSize;
pb::ExtendableMessage<TestMessage, TestMessage.Builder>.ExtensionWriter extensionWriter = CreateExtensionWriter(this);
if (HasA) {
output.WriteInt32(1, A);
output.WriteInt32(1, "a", A);
}
extensionWriter.WriteUntil(536870912, output);
UnknownFields.WriteTo(output);
......
......@@ -123,9 +123,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::CodedOutputStream output) {
int size = SerializedSize;
if (criteria_.Count > 0) {
foreach (string element in criteria_) {
output.WriteString(1, element);
}
output.WriteArray(pbd::FieldType.String, 1, "Criteria", criteria_);
}
UnknownFields.WriteTo(output);
}
......@@ -403,10 +401,10 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::CodedOutputStream output) {
int size = SerializedSize;
if (HasUrl) {
output.WriteString(1, Url);
output.WriteString(1, "url", Url);
}
if (HasName) {
output.WriteString(2, Name);
output.WriteString(2, "name", Name);
}
UnknownFields.WriteTo(output);
}
......@@ -639,8 +637,8 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::CodedOutputStream output) {
int size = SerializedSize;
foreach (global::Google.ProtocolBuffers.TestProtos.SearchResponse.Types.ResultItem element in ResultsList) {
output.WriteMessage(1, element);
if (results_.Count > 0) {
output.WriteMessageArray(1, "results", results_);
}
UnknownFields.WriteTo(output);
}
......@@ -898,12 +896,10 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::CodedOutputStream output) {
int size = SerializedSize;
if (criteria_.Count > 0) {
foreach (string element in criteria_) {
output.WriteString(1, element);
}
output.WriteArray(pbd::FieldType.String, 1, "Criteria", criteria_);
}
if (HasPreviousResults) {
output.WriteMessage(2, PreviousResults);
output.WriteMessage(2, "previous_results", PreviousResults);
}
UnknownFields.WriteTo(output);
}
......
......@@ -180,12 +180,10 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::CodedOutputStream output) {
int size = SerializedSize;
if (options_.Count > 0) {
foreach (int element in options_) {
output.WriteEnum(3, element);
}
output.WriteArray(pbd::FieldType.Enum, 3, "options", options_);
}
if (HasBinary) {
output.WriteBytes(4, Binary);
output.WriteBytes(4, "binary", Binary);
}
UnknownFields.WriteTo(output);
}
......@@ -681,12 +679,10 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::CodedOutputStream output) {
int size = SerializedSize;
if (options_.Count > 0) {
foreach (int element in options_) {
output.WriteEnum(3, element);
}
output.WriteArray(pbd::FieldType.Enum, 3, "options", options_);
}
if (HasBinary) {
output.WriteBytes(4, Binary);
output.WriteBytes(4, "binary", Binary);
}
UnknownFields.WriteTo(output);
}
......@@ -1006,30 +1002,26 @@ namespace Google.ProtocolBuffers.TestProtos {
int size = SerializedSize;
pb::ExtendableMessage<TestXmlMessage, TestXmlMessage.Builder>.ExtensionWriter extensionWriter = CreateExtensionWriter(this);
if (HasChild) {
output.WriteMessage(1, Child);
output.WriteMessage(1, "child", Child);
}
if (numbers_.Count > 0) {
foreach (int element in numbers_) {
output.WriteInt32(2, element);
}
output.WriteArray(pbd::FieldType.Int32, 2, "numbers", numbers_);
}
if (HasText) {
output.WriteString(3, Text);
output.WriteString(3, "text", Text);
}
if (HasValid) {
output.WriteBool(5, Valid);
output.WriteBool(5, "valid", Valid);
}
if (HasNumber) {
output.WriteInt64(6, Number);
output.WriteInt64(6, "number", Number);
}
extensionWriter.WriteUntil(200, output);
foreach (global::Google.ProtocolBuffers.TestProtos.TestXmlMessage.Types.Children element in ChildrenList) {
output.WriteGroup(401, element);
if (children_.Count > 0) {
output.WriteGroupArray(401, "children", children_);
}
if (textlines_.Count > 0) {
foreach (string element in textlines_) {
output.WriteString(700, element);
}
output.WriteArray(pbd::FieldType.String, 700, "textlines", textlines_);
}
UnknownFields.WriteTo(output);
}
......@@ -1498,7 +1490,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::CodedOutputStream output) {
int size = SerializedSize;
if (HasNumber) {
output.WriteInt32(1, Number);
output.WriteInt32(1, "number", Number);
}
UnknownFields.WriteTo(output);
}
......
......@@ -166,13 +166,13 @@ namespace Google.ProtocolBuffers
{
foreach (object element in valueList)
{
output.WriteField(field.FieldType, field.FieldNumber, element);
output.WriteField(field.FieldType, field.FieldNumber, field.Name, element);
}
}
}
else
{
output.WriteField(field.FieldType, field.FieldNumber, entry.Value);
output.WriteField(field.FieldType, field.FieldNumber, field.Name, entry.Value);
}
}
......
This diff is collapsed.
......@@ -283,43 +283,43 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
public override void WriteTo(pb::CodedOutputStream output) {
int size = SerializedSize;
if (HasNamespace) {
output.WriteString(1, Namespace);
output.WriteString(1, "namespace", Namespace);
}
if (HasUmbrellaClassname) {
output.WriteString(2, UmbrellaClassname);
output.WriteString(2, "umbrella_classname", UmbrellaClassname);
}
if (HasPublicClasses) {
output.WriteBool(3, PublicClasses);
output.WriteBool(3, "public_classes", PublicClasses);
}
if (HasMultipleFiles) {
output.WriteBool(4, MultipleFiles);
output.WriteBool(4, "multiple_files", MultipleFiles);
}
if (HasNestClasses) {
output.WriteBool(5, NestClasses);
output.WriteBool(5, "nest_classes", NestClasses);
}
if (HasCodeContracts) {
output.WriteBool(6, CodeContracts);
output.WriteBool(6, "code_contracts", CodeContracts);
}
if (HasExpandNamespaceDirectories) {
output.WriteBool(7, ExpandNamespaceDirectories);
output.WriteBool(7, "expand_namespace_directories", ExpandNamespaceDirectories);
}
if (HasClsCompliance) {
output.WriteBool(8, ClsCompliance);
output.WriteBool(8, "cls_compliance", ClsCompliance);
}
if (HasFileExtension) {
output.WriteString(221, FileExtension);
output.WriteString(221, "file_extension", FileExtension);
}
if (HasUmbrellaNamespace) {
output.WriteString(222, UmbrellaNamespace);
output.WriteString(222, "umbrella_namespace", UmbrellaNamespace);
}
if (HasOutputDirectory) {
output.WriteString(223, OutputDirectory);
output.WriteString(223, "output_directory", OutputDirectory);
}
if (HasIgnoreGoogleProtobuf) {
output.WriteBool(224, IgnoreGoogleProtobuf);
output.WriteBool(224, "ignore_google_protobuf", IgnoreGoogleProtobuf);
}
if (HasServiceGeneratorType) {
output.WriteEnum(225, (int) ServiceGeneratorType);
output.WriteEnum(225, "service_generator_type", (int) ServiceGeneratorType, ServiceGeneratorType.ToString());
}
UnknownFields.WriteTo(output);
}
......@@ -889,7 +889,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
public override void WriteTo(pb::CodedOutputStream output) {
int size = SerializedSize;
if (HasPropertyName) {
output.WriteString(1, PropertyName);
output.WriteString(1, "property_name", PropertyName);
}
UnknownFields.WriteTo(output);
}
......@@ -1111,7 +1111,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
public override void WriteTo(pb::CodedOutputStream output) {
int size = SerializedSize;
if (HasInterfaceId) {
output.WriteString(1, InterfaceId);
output.WriteString(1, "interface_id", InterfaceId);
}
UnknownFields.WriteTo(output);
}
......@@ -1333,7 +1333,7 @@ namespace Google.ProtocolBuffers.DescriptorProtos {
public override void WriteTo(pb::CodedOutputStream output) {
int size = SerializedSize;
if (HasDispatchId) {
output.WriteInt32(1, DispatchId);
output.WriteInt32(1, "dispatch_id", DispatchId);
}
UnknownFields.WriteTo(output);
}
......
......@@ -470,7 +470,7 @@ namespace Google.ProtocolBuffers
{
if (field.IsExtension && field.MessageSetWireFormat)
{
output.WriteMessageSetExtension(field.FieldNumber, (IMessageLite) value);
output.WriteMessageSetExtension(field.FieldNumber, field.Name, (IMessageLite)value);
}
else
{
......@@ -497,13 +497,13 @@ namespace Google.ProtocolBuffers
{
foreach (object element in valueList)
{
output.WriteField(field.FieldType, field.FieldNumber, element);
output.WriteField(field.FieldType, field.FieldNumber, field.Name, element);
}
}
}
else
{
output.WriteField(field.FieldType, field.FieldNumber, value);
output.WriteField(field.FieldType, field.FieldNumber, field.Name, value);
}
}
}
......
......@@ -59,7 +59,7 @@ namespace Google.ProtocolBuffers
public void Write(T message)
{
codedOutput.WriteMessage(1, message);
codedOutput.WriteMessage(1, "item", message);
}
public void Flush()
......
......@@ -60,6 +60,7 @@ namespace Google.ProtocolBuffers
/// </summary>
public sealed class UnknownField
{
public const string UnknownFieldName = "unknown_field";
private static readonly UnknownField defaultInstance = CreateBuilder().Build();
private readonly ReadOnlyCollection<ulong> varintList;
private readonly ReadOnlyCollection<uint> fixed32List;
......@@ -177,24 +178,24 @@ namespace Google.ProtocolBuffers
{
foreach (ulong value in varintList)
{
output.WriteUInt64(fieldNumber, value);
output.WriteUInt64(fieldNumber, UnknownFieldName, value);
}
foreach (uint value in fixed32List)
{
output.WriteFixed32(fieldNumber, value);
output.WriteFixed32(fieldNumber, UnknownFieldName, value);
}
foreach (ulong value in fixed64List)
{
output.WriteFixed64(fieldNumber, value);
output.WriteFixed64(fieldNumber, UnknownFieldName, value);
}
foreach (ByteString value in lengthDelimitedList)
{
output.WriteBytes(fieldNumber, value);
output.WriteBytes(fieldNumber, UnknownFieldName, value);
}
foreach (UnknownFieldSet value in groupList)
{
#pragma warning disable 0612
output.WriteUnknownGroup(fieldNumber, value);
output.WriteUnknownGroup(fieldNumber, UnknownFieldName, value);
#pragma warning restore 0612
}
}
......
......@@ -101,10 +101,10 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::CodedOutputStream output) {
int size = SerializedSize;
if (HasD) {
output.WriteInt32(1, D);
output.WriteInt32(1, "d", D);
}
if (HasEn) {
output.WriteEnum(2, (int) En);
output.WriteEnum(2, "en", (int) En, En.ToString());
}
}
......@@ -395,10 +395,10 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::CodedOutputStream output) {
int size = SerializedSize;
if (HasNumber) {
output.WriteString(1, Number);
output.WriteString(1, "number", Number);
}
if (HasType) {
output.WriteEnum(2, (int) Type);
output.WriteEnum(2, "type", (int) Type, Type.ToString());
}
}
......@@ -694,19 +694,19 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::CodedOutputStream output) {
int size = SerializedSize;
if (HasAddress) {
output.WriteString(1, Address);
output.WriteString(1, "address", Address);
}
if (HasAddress2) {
output.WriteString(2, Address2);
output.WriteString(2, "address2", Address2);
}
if (HasCity) {
output.WriteString(3, City);
output.WriteString(3, "city", City);
}
if (HasState) {
output.WriteString(4, State);
output.WriteString(4, "state", State);
}
if (HasZip) {
output.WriteFixed32(5, Zip);
output.WriteFixed32(5, "zip", Zip);
}
}
......@@ -1101,26 +1101,22 @@ namespace Google.ProtocolBuffers.TestProtos {
int size = SerializedSize;
pb::ExtendableMessageLite<TestInteropPersonLite, TestInteropPersonLite.Builder>.ExtensionWriter extensionWriter = CreateExtensionWriter(this);
if (HasName) {
output.WriteString(1, Name);
output.WriteString(1, "name", Name);
}
if (HasId) {
output.WriteInt32(2, Id);
output.WriteInt32(2, "id", Id);
}
if (HasEmail) {
output.WriteString(3, Email);
output.WriteString(3, "email", Email);
}
foreach (global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber element in PhoneList) {
output.WriteMessage(4, element);
if (phone_.Count > 0) {
output.WriteMessageArray(4, "phone", phone_);
}
foreach (global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses element in AddressesList) {
output.WriteGroup(5, element);
if (addresses_.Count > 0) {
output.WriteGroupArray(5, "addresses", addresses_);
}
if (codes_.Count > 0) {
output.WriteRawVarint32(82);
output.WriteRawVarint32((uint) codesMemoizedSerializedSize);
foreach (int element in codes_) {
output.WriteInt32NoTag(element);
}
output.WritePackedArray(pbd::FieldType.Int32, 10, "codes", codesMemoizedSerializedSize, codes_);
}
extensionWriter.WriteUntil(200, output);
}
......@@ -1576,7 +1572,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::CodedOutputStream output) {
int size = SerializedSize;
if (HasNumber) {
output.WriteString(1, Number);
output.WriteString(1, "number", Number);
}
}
......
......@@ -73,7 +73,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::CodedOutputStream output) {
int size = SerializedSize;
if (HasD) {
output.WriteInt32(1, D);
output.WriteInt32(1, "d", D);
}
}
......
......@@ -109,7 +109,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::CodedOutputStream output) {
int size = SerializedSize;
if (HasD) {
output.WriteInt32(1, D);
output.WriteInt32(1, "d", D);
}
UnknownFields.WriteTo(output);
}
......
......@@ -62,7 +62,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::CodedOutputStream output) {
int size = SerializedSize;
if (HasMessage) {
output.WriteMessage(1, Message);
output.WriteMessage(1, "message", Message);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment