Commit 920b09a3 authored by csharptest's avatar csharptest Committed by rogerk

Finished adding find tag by name

parent aef072a4
...@@ -67,6 +67,8 @@ namespace Google.ProtocolBuffers.Examples.AddressBook { ...@@ -67,6 +67,8 @@ namespace Google.ProtocolBuffers.Examples.AddressBook {
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.3.0.277")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.3.0.277")]
public sealed partial class Person : pb::GeneratedMessage<Person, Person.Builder> { public sealed partial class Person : pb::GeneratedMessage<Person, Person.Builder> {
private static readonly Person defaultInstance = new Builder().BuildPartial(); private static readonly Person defaultInstance = new Builder().BuildPartial();
private static readonly string[] _personFieldNames = new string[] { "email", "id", "name", "phone" };
private static readonly uint[] _personFieldTags = new uint[] { 26, 16, 10, 34 };
public static Person DefaultInstance { public static Person DefaultInstance {
get { return defaultInstance; } get { return defaultInstance; }
} }
...@@ -105,6 +107,8 @@ namespace Google.ProtocolBuffers.Examples.AddressBook { ...@@ -105,6 +107,8 @@ namespace Google.ProtocolBuffers.Examples.AddressBook {
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.3.0.277")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.3.0.277")]
public sealed partial class PhoneNumber : pb::GeneratedMessage<PhoneNumber, PhoneNumber.Builder> { public sealed partial class PhoneNumber : pb::GeneratedMessage<PhoneNumber, PhoneNumber.Builder> {
private static readonly PhoneNumber defaultInstance = new Builder().BuildPartial(); private static readonly PhoneNumber defaultInstance = new Builder().BuildPartial();
private static readonly string[] _phoneNumberFieldNames = new string[] { "number", "type" };
private static readonly uint[] _phoneNumberFieldTags = new uint[] { 10, 16 };
public static PhoneNumber DefaultInstance { public static PhoneNumber DefaultInstance {
get { return defaultInstance; } get { return defaultInstance; }
} }
...@@ -154,11 +158,12 @@ namespace Google.ProtocolBuffers.Examples.AddressBook { ...@@ -154,11 +158,12 @@ namespace Google.ProtocolBuffers.Examples.AddressBook {
public override void WriteTo(pb::ICodedOutputStream output) { public override void WriteTo(pb::ICodedOutputStream output) {
int size = SerializedSize; int size = SerializedSize;
string[] field_names = _phoneNumberFieldNames;
if (hasNumber) { if (hasNumber) {
output.WriteString(1, "number", Number); output.WriteString(1, field_names[0], Number);
} }
if (hasType) { if (hasType) {
output.WriteEnum(2, "type", (int) Type, Type.ToString()); output.WriteEnum(2, field_names[1], (int) Type, Type.ToString());
} }
UnknownFields.WriteTo(output); UnknownFields.WriteTo(output);
} }
...@@ -290,6 +295,18 @@ namespace Google.ProtocolBuffers.Examples.AddressBook { ...@@ -290,6 +295,18 @@ namespace Google.ProtocolBuffers.Examples.AddressBook {
uint tag; uint tag;
string field_name; string field_name;
while (input.ReadTag(out tag, out field_name)) { while (input.ReadTag(out tag, out field_name)) {
if(tag == 0 && field_name != null) {
int field_ordinal = global::System.Array.BinarySearch(_phoneNumberFieldNames, field_name, global::System.StringComparer.Ordinal);
if(field_ordinal >= 0)
tag = _phoneNumberFieldTags[field_ordinal];
else {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
continue;
}
}
switch (tag) { switch (tag) {
case 0: { case 0: {
throw pb::InvalidProtocolBufferException.InvalidTag(); throw pb::InvalidProtocolBufferException.InvalidTag();
...@@ -308,7 +325,7 @@ namespace Google.ProtocolBuffers.Examples.AddressBook { ...@@ -308,7 +325,7 @@ namespace Google.ProtocolBuffers.Examples.AddressBook {
break; break;
} }
case 10: { case 10: {
result.hasNumber |= input.ReadString(ref result.number_); result.hasNumber = input.ReadString(ref result.number_);
break; break;
} }
case 16: { case 16: {
...@@ -433,17 +450,18 @@ namespace Google.ProtocolBuffers.Examples.AddressBook { ...@@ -433,17 +450,18 @@ namespace Google.ProtocolBuffers.Examples.AddressBook {
public override void WriteTo(pb::ICodedOutputStream output) { public override void WriteTo(pb::ICodedOutputStream output) {
int size = SerializedSize; int size = SerializedSize;
string[] field_names = _personFieldNames;
if (hasName) { if (hasName) {
output.WriteString(1, "name", Name); output.WriteString(1, field_names[2], Name);
} }
if (hasId) { if (hasId) {
output.WriteInt32(2, "id", Id); output.WriteInt32(2, field_names[1], Id);
} }
if (hasEmail) { if (hasEmail) {
output.WriteString(3, "email", Email); output.WriteString(3, field_names[0], Email);
} }
if (phone_.Count > 0) { if (phone_.Count > 0) {
output.WriteArray(pbd::FieldType.Message, 4, "phone", phone_); output.WriteArray(pbd::FieldType.Message, 4, field_names[3], phone_);
} }
UnknownFields.WriteTo(output); UnknownFields.WriteTo(output);
} }
...@@ -588,6 +606,18 @@ namespace Google.ProtocolBuffers.Examples.AddressBook { ...@@ -588,6 +606,18 @@ namespace Google.ProtocolBuffers.Examples.AddressBook {
uint tag; uint tag;
string field_name; string field_name;
while (input.ReadTag(out tag, out field_name)) { while (input.ReadTag(out tag, out field_name)) {
if(tag == 0 && field_name != null) {
int field_ordinal = global::System.Array.BinarySearch(_personFieldNames, field_name, global::System.StringComparer.Ordinal);
if(field_ordinal >= 0)
tag = _personFieldTags[field_ordinal];
else {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
continue;
}
}
switch (tag) { switch (tag) {
case 0: { case 0: {
throw pb::InvalidProtocolBufferException.InvalidTag(); throw pb::InvalidProtocolBufferException.InvalidTag();
...@@ -606,15 +636,15 @@ namespace Google.ProtocolBuffers.Examples.AddressBook { ...@@ -606,15 +636,15 @@ namespace Google.ProtocolBuffers.Examples.AddressBook {
break; break;
} }
case 10: { case 10: {
result.hasName |= input.ReadString(ref result.name_); result.hasName = input.ReadString(ref result.name_);
break; break;
} }
case 16: { case 16: {
result.hasId |= input.ReadInt32(ref result.id_); result.hasId = input.ReadInt32(ref result.id_);
break; break;
} }
case 26: { case 26: {
result.hasEmail |= input.ReadString(ref result.email_); result.hasEmail = input.ReadString(ref result.email_);
break; break;
} }
case 34: { case 34: {
...@@ -735,6 +765,8 @@ namespace Google.ProtocolBuffers.Examples.AddressBook { ...@@ -735,6 +765,8 @@ namespace Google.ProtocolBuffers.Examples.AddressBook {
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.3.0.277")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.3.0.277")]
public sealed partial class AddressBook : pb::GeneratedMessage<AddressBook, AddressBook.Builder> { public sealed partial class AddressBook : pb::GeneratedMessage<AddressBook, AddressBook.Builder> {
private static readonly AddressBook defaultInstance = new Builder().BuildPartial(); private static readonly AddressBook defaultInstance = new Builder().BuildPartial();
private static readonly string[] _addressBookFieldNames = new string[] { "person" };
private static readonly uint[] _addressBookFieldTags = new uint[] { 10 };
public static AddressBook DefaultInstance { public static AddressBook DefaultInstance {
get { return defaultInstance; } get { return defaultInstance; }
} }
...@@ -778,8 +810,9 @@ namespace Google.ProtocolBuffers.Examples.AddressBook { ...@@ -778,8 +810,9 @@ namespace Google.ProtocolBuffers.Examples.AddressBook {
public override void WriteTo(pb::ICodedOutputStream output) { public override void WriteTo(pb::ICodedOutputStream output) {
int size = SerializedSize; int size = SerializedSize;
string[] field_names = _addressBookFieldNames;
if (person_.Count > 0) { if (person_.Count > 0) {
output.WriteArray(pbd::FieldType.Message, 1, "person", person_); output.WriteArray(pbd::FieldType.Message, 1, field_names[0], person_);
} }
UnknownFields.WriteTo(output); UnknownFields.WriteTo(output);
} }
...@@ -906,6 +939,18 @@ namespace Google.ProtocolBuffers.Examples.AddressBook { ...@@ -906,6 +939,18 @@ namespace Google.ProtocolBuffers.Examples.AddressBook {
uint tag; uint tag;
string field_name; string field_name;
while (input.ReadTag(out tag, out field_name)) { while (input.ReadTag(out tag, out field_name)) {
if(tag == 0 && field_name != null) {
int field_ordinal = global::System.Array.BinarySearch(_addressBookFieldNames, field_name, global::System.StringComparer.Ordinal);
if(field_ordinal >= 0)
tag = _addressBookFieldTags[field_ordinal];
else {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
continue;
}
}
switch (tag) { switch (tag) {
case 0: { case 0: {
throw pb::InvalidProtocolBufferException.InvalidTag(); throw pb::InvalidProtocolBufferException.InvalidTag();
......
...@@ -58,6 +58,7 @@ namespace Google.ProtocolBuffers.ProtoBench ...@@ -58,6 +58,7 @@ namespace Google.ProtocolBuffers.ProtoBench
private static BenchmarkTest RunBenchmark; private static BenchmarkTest RunBenchmark;
[STAThread]
public static int Main(string[] args) public static int Main(string[] args)
{ {
List<string> temp = new List<string>(args); List<string> temp = new List<string>(args);
...@@ -160,58 +161,47 @@ namespace Google.ProtocolBuffers.ProtoBench ...@@ -160,58 +161,47 @@ namespace Google.ProtocolBuffers.ProtoBench
long totalCount = 0; long totalCount = 0;
double best = double.MinValue, worst = double.MaxValue; double best = double.MinValue, worst = double.MaxValue;
ThreadStart threadProc = action();
delegate() // Run it progressively more times until we've got a reasonable sample
{
action();
// Run it progressively more times until we've got a reasonable sample
int iterations = 100;
elapsed = TimeAction(action, iterations);
while (elapsed.TotalMilliseconds < 1000)
{
elapsed += TimeAction(action, iterations);
iterations *= 2;
}
TimeSpan target = TimeSpan.FromSeconds(1);
elapsed = TimeAction(action, iterations);
iterations = (int)((target.Ticks * iterations) / (double)elapsed.Ticks);
elapsed = TimeAction(action, iterations);
iterations = (int)((target.Ticks * iterations) / (double)elapsed.Ticks);
elapsed = TimeAction(action, iterations);
iterations = (int)((target.Ticks * iterations) / (double)elapsed.Ticks);
double first = (iterations * dataSize) / (elapsed.TotalSeconds * 1024 * 1024); int iterations = 100;
if (Verbose) Console.WriteLine("Round ---: Count = {1,6}, Bps = {2,8:f3}", 0, iterations, first); elapsed = TimeAction(action, iterations);
elapsed = TimeSpan.Zero; while (elapsed.TotalMilliseconds < 1000)
int max = FastTest ? 10 : 30; {
elapsed += TimeAction(action, iterations);
iterations *= 2;
}
while (runs < max) TimeSpan target = TimeSpan.FromSeconds(1);
{
TimeSpan cycle = TimeAction(action, iterations);
// Accumulate and scale for next cycle.
double bps = (iterations * dataSize) / (cycle.TotalSeconds * 1024 * 1024);
if (Verbose) Console.WriteLine("Round {0,3}: Count = {1,6}, Bps = {2,8:f3}", runs, iterations, bps);
best = Math.Max(best, bps); elapsed = TimeAction(action, iterations);
worst = Math.Min(worst, bps); iterations = (int)((target.Ticks * iterations) / (double)elapsed.Ticks);
elapsed = TimeAction(action, iterations);
iterations = (int)((target.Ticks * iterations) / (double)elapsed.Ticks);
elapsed = TimeAction(action, iterations);
iterations = (int)((target.Ticks * iterations) / (double)elapsed.Ticks);
runs++; double first = (iterations * dataSize) / (elapsed.TotalSeconds * 1024 * 1024);
elapsed += cycle; if (Verbose) Console.WriteLine("Round ---: Count = {1,6}, Bps = {2,8:f3}", 0, iterations, first);
totalCount += iterations; elapsed = TimeSpan.Zero;
iterations = (int) ((target.Ticks*totalCount)/(double) elapsed.Ticks); int max = FastTest ? 10 : 30;
}
};
Thread work = new Thread(threadProc); while (runs < max)
work.Name = "Worker"; {
work.Priority = ThreadPriority.Highest; TimeSpan cycle = TimeAction(action, iterations);
work.SetApartmentState(ApartmentState.STA); // Accumulate and scale for next cycle.
work.Start();
work.Join(); double bps = (iterations * dataSize) / (cycle.TotalSeconds * 1024 * 1024);
if (Verbose) Console.WriteLine("Round {0,3}: Count = {1,6}, Bps = {2,8:f3}", runs, iterations, bps);
best = Math.Max(best, bps);
worst = Math.Min(worst, bps);
runs++;
elapsed += cycle;
totalCount += iterations;
iterations = (int) ((target.Ticks*totalCount)/(double) elapsed.Ticks);
}
Console.WriteLine("{0}: averages {1} per {2:f3}s for {3} runs; avg: {4:f3}mbps; best: {5:f3}mbps; worst: {6:f3}mbps", Console.WriteLine("{0}: averages {1} per {2:f3}s for {3} runs; avg: {4:f3}mbps; best: {5:f3}mbps; worst: {6:f3}mbps",
name, totalCount / runs, elapsed.TotalSeconds / runs, runs, name, totalCount / runs, elapsed.TotalSeconds / runs, runs,
......
...@@ -40,8 +40,8 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -40,8 +40,8 @@ namespace Google.ProtocolBuffers.ProtoGen
{ {
internal class EnumFieldGenerator : FieldGeneratorBase, IFieldSourceGenerator internal class EnumFieldGenerator : FieldGeneratorBase, IFieldSourceGenerator
{ {
internal EnumFieldGenerator(FieldDescriptor descriptor) internal EnumFieldGenerator(FieldDescriptor descriptor, int fieldOrdinal)
: base(descriptor) : base(descriptor, fieldOrdinal)
{ {
} }
...@@ -107,26 +107,12 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -107,26 +107,12 @@ namespace Google.ProtocolBuffers.ProtoGen
writer.WriteLine(" unknownFields.MergeVarintField({0}, (ulong)(int)unknown);", Number); writer.WriteLine(" unknownFields.MergeVarintField({0}, (ulong)(int)unknown);", Number);
} }
writer.WriteLine("}"); writer.WriteLine("}");
// TO DO(jonskeet): Make a more efficient way of doing this
//writer.WriteLine("int rawValue = input.ReadEnum();");
//writer.WriteLine("if (!global::System.Enum.IsDefined(typeof({0}), rawValue)) {{", TypeName);
//if (!UseLiteRuntime)
//{
// writer.WriteLine(" if (unknownFields == null) {"); // First unknown field - create builder now
// writer.WriteLine(" unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);");
// writer.WriteLine(" }");
// writer.WriteLine(" unknownFields.MergeVarintField({0}, (ulong) rawValue);", Number);
//}
//writer.WriteLine("} else {");
//writer.WriteLine(" {0} = ({1}) rawValue;", PropertyName, TypeName);
//writer.WriteLine("}");
} }
public void GenerateSerializationCode(TextGenerator writer) public void GenerateSerializationCode(TextGenerator writer)
{ {
writer.WriteLine("if (has{0}) {{", PropertyName); writer.WriteLine("if (has{0}) {{", PropertyName);
writer.WriteLine(" output.WriteEnum({0}, \"{2}\", (int) {1}, {1}.ToString());", Number, PropertyName, Descriptor.Name); writer.WriteLine(" output.WriteEnum({0}, field_names[{2}], (int) {1}, {1}.ToString());", Number, PropertyName, FieldOrdinal);
writer.WriteLine("}"); writer.WriteLine("}");
} }
......
...@@ -48,7 +48,7 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -48,7 +48,7 @@ namespace Google.ProtocolBuffers.ProtoGen
private readonly string name; private readonly string name;
internal ExtensionGenerator(FieldDescriptor descriptor) internal ExtensionGenerator(FieldDescriptor descriptor)
: base(descriptor) : base(descriptor, 0)
{ {
if (Descriptor.ExtensionScope != null) if (Descriptor.ExtensionScope != null)
{ {
......
...@@ -42,15 +42,20 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -42,15 +42,20 @@ namespace Google.ProtocolBuffers.ProtoGen
{ {
internal abstract class FieldGeneratorBase : SourceGeneratorBase<FieldDescriptor> internal abstract class FieldGeneratorBase : SourceGeneratorBase<FieldDescriptor>
{ {
protected FieldGeneratorBase(FieldDescriptor descriptor) private readonly int _fieldOrdinal;
protected FieldGeneratorBase(FieldDescriptor descriptor, int fieldOrdinal)
: base(descriptor) : base(descriptor)
{ {
_fieldOrdinal = fieldOrdinal;
} }
public abstract void WriteHash(TextGenerator writer); public abstract void WriteHash(TextGenerator writer);
public abstract void WriteEquals(TextGenerator writer); public abstract void WriteEquals(TextGenerator writer);
public abstract void WriteToString(TextGenerator writer); public abstract void WriteToString(TextGenerator writer);
public int FieldOrdinal { get { return _fieldOrdinal; } }
private static bool AllPrintableAscii(string text) private static bool AllPrintableAscii(string text)
{ {
foreach (char c in text) foreach (char c in text)
......
...@@ -40,8 +40,8 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -40,8 +40,8 @@ namespace Google.ProtocolBuffers.ProtoGen
{ {
internal class MessageFieldGenerator : FieldGeneratorBase, IFieldSourceGenerator internal class MessageFieldGenerator : FieldGeneratorBase, IFieldSourceGenerator
{ {
internal MessageFieldGenerator(FieldDescriptor descriptor) internal MessageFieldGenerator(FieldDescriptor descriptor, int fieldOrdinal)
: base(descriptor) : base(descriptor, fieldOrdinal)
{ {
} }
...@@ -129,7 +129,7 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -129,7 +129,7 @@ namespace Google.ProtocolBuffers.ProtoGen
public void GenerateSerializationCode(TextGenerator writer) public void GenerateSerializationCode(TextGenerator writer)
{ {
writer.WriteLine("if (has{0}) {{", PropertyName); writer.WriteLine("if (has{0}) {{", PropertyName);
writer.WriteLine(" output.Write{0}({1}, \"{3}\", {2});", MessageOrGroup, Number, PropertyName, Descriptor.Name); writer.WriteLine(" output.Write{0}({1}, field_names[{3}], {2});", MessageOrGroup, Number, PropertyName, FieldOrdinal);
writer.WriteLine("}"); writer.WriteLine("}");
} }
......
This diff is collapsed.
...@@ -41,8 +41,8 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -41,8 +41,8 @@ namespace Google.ProtocolBuffers.ProtoGen
// TODO(jonskeet): Refactor this. There's loads of common code here. // TODO(jonskeet): Refactor this. There's loads of common code here.
internal class PrimitiveFieldGenerator : FieldGeneratorBase, IFieldSourceGenerator internal class PrimitiveFieldGenerator : FieldGeneratorBase, IFieldSourceGenerator
{ {
internal PrimitiveFieldGenerator(FieldDescriptor descriptor) internal PrimitiveFieldGenerator(FieldDescriptor descriptor, int fieldOrdinal)
: base(descriptor) : base(descriptor, fieldOrdinal)
{ {
} }
...@@ -97,13 +97,13 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -97,13 +97,13 @@ namespace Google.ProtocolBuffers.ProtoGen
public void GenerateParsingCode(TextGenerator writer) public void GenerateParsingCode(TextGenerator writer)
{ {
writer.WriteLine("result.has{0} |= input.Read{1}(ref result.{2}_);", PropertyName, CapitalizedTypeName, Name); writer.WriteLine("result.has{0} = input.Read{1}(ref result.{2}_);", PropertyName, CapitalizedTypeName, Name);
} }
public void GenerateSerializationCode(TextGenerator writer) public void GenerateSerializationCode(TextGenerator writer)
{ {
writer.WriteLine("if (has{0}) {{", PropertyName); writer.WriteLine("if (has{0}) {{", PropertyName);
writer.WriteLine(" output.Write{0}({1}, \"{3}\", {2});", CapitalizedTypeName, Number, PropertyName, Descriptor.Name); writer.WriteLine(" output.Write{0}({1}, field_names[{3}], {2});", CapitalizedTypeName, Number, PropertyName, FieldOrdinal);
writer.WriteLine("}"); writer.WriteLine("}");
} }
......
...@@ -56,10 +56,6 @@ ...@@ -56,10 +56,6 @@
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Google.ProtocolBuffers, Version=2.3.0.277, Culture=neutral, PublicKeyToken=17b3b1f090c3ea48, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\build\2.3.0.304\Google.ProtocolBuffers.dll</HintPath>
</Reference>
<Reference Include="mscorlib" /> <Reference Include="mscorlib" />
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
...@@ -113,6 +109,12 @@ ...@@ -113,6 +109,12 @@
<Install>true</Install> <Install>true</Install>
</BootstrapperPackage> </BootstrapperPackage>
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ProtocolBuffers\ProtocolBuffers.csproj">
<Project>{6908BDCE-D925-43F3-94AC-A531E6DF2591}</Project>
<Name>ProtocolBuffers</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.
......
...@@ -41,8 +41,8 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -41,8 +41,8 @@ namespace Google.ProtocolBuffers.ProtoGen
{ {
internal class RepeatedEnumFieldGenerator : FieldGeneratorBase, IFieldSourceGenerator internal class RepeatedEnumFieldGenerator : FieldGeneratorBase, IFieldSourceGenerator
{ {
internal RepeatedEnumFieldGenerator(FieldDescriptor descriptor) internal RepeatedEnumFieldGenerator(FieldDescriptor descriptor, int fieldOrdinal)
: base(descriptor) : base(descriptor, fieldOrdinal)
{ {
} }
...@@ -125,37 +125,6 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -125,37 +125,6 @@ namespace Google.ProtocolBuffers.ProtoGen
writer.WriteLine(" unknownFields.MergeVarintField({0}, (ulong)(int)rawValue);", Number); writer.WriteLine(" unknownFields.MergeVarintField({0}, (ulong)(int)rawValue);", Number);
writer.WriteLine("}"); writer.WriteLine("}");
} }
//// If packed, set up the while loop
//if (Descriptor.IsPacked)
//{
// writer.WriteLine("int length = input.ReadInt32();");
// writer.WriteLine("int oldLimit = input.PushLimit(length);");
// writer.WriteLine("while (!input.ReachedLimit) {");
// writer.Indent();
//}
//// Read and store the enum
//// TO DO(jonskeet): Make a more efficient way of doing this
//writer.WriteLine("int rawValue = input.ReadEnum();");
//writer.WriteLine("if (!global::System.Enum.IsDefined(typeof({0}), rawValue)) {{", TypeName);
//if (!UseLiteRuntime)
//{
// writer.WriteLine(" if (unknownFields == null) {"); // First unknown field - create builder now
// writer.WriteLine(" unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);");
// writer.WriteLine(" }");
// writer.WriteLine(" unknownFields.MergeVarintField({0}, (ulong) rawValue);", Number);
//}
//writer.WriteLine("} else {");
//writer.WriteLine(" Add{0}(({1}) rawValue);", PropertyName, TypeName);
//writer.WriteLine("}");
//if (Descriptor.IsPacked)
//{
// writer.Outdent();
// writer.WriteLine("}");
// writer.WriteLine("input.PopLimit(oldLimit);");
//}
} }
public void GenerateSerializationCode(TextGenerator writer) public void GenerateSerializationCode(TextGenerator writer)
...@@ -163,23 +132,9 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -163,23 +132,9 @@ namespace Google.ProtocolBuffers.ProtoGen
writer.WriteLine("if ({0}_.Count > 0) {{", Name); writer.WriteLine("if ({0}_.Count > 0) {{", Name);
writer.Indent(); writer.Indent();
if (Descriptor.IsPacked) if (Descriptor.IsPacked)
writer.WriteLine("output.WritePackedArray(pbd::FieldType.{3}, {0}, \"{2}\", {1}MemoizedSerializedSize, {1}_);", Number, Name, Descriptor.Name, Descriptor.FieldType); writer.WriteLine("output.WritePackedArray(pbd::FieldType.{3}, {0}, field_names[{2}], {1}MemoizedSerializedSize, {1}_);", Number, Name, FieldOrdinal, Descriptor.FieldType);
else else
writer.WriteLine("output.WriteArray(pbd::FieldType.{3}, {0}, \"{2}\", {1}_);", Number, Name, Descriptor.Name, Descriptor.FieldType); writer.WriteLine("output.WriteArray(pbd::FieldType.{3}, {0}, field_names[{2}], {1}_);", Number, Name, FieldOrdinal, 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.Outdent();
writer.WriteLine("}"); writer.WriteLine("}");
} }
......
...@@ -41,8 +41,8 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -41,8 +41,8 @@ namespace Google.ProtocolBuffers.ProtoGen
{ {
internal class RepeatedMessageFieldGenerator : FieldGeneratorBase, IFieldSourceGenerator internal class RepeatedMessageFieldGenerator : FieldGeneratorBase, IFieldSourceGenerator
{ {
internal RepeatedMessageFieldGenerator(FieldDescriptor descriptor) internal RepeatedMessageFieldGenerator(FieldDescriptor descriptor, int fieldOrdinal)
: base(descriptor) : base(descriptor, fieldOrdinal)
{ {
} }
...@@ -123,33 +123,13 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -123,33 +123,13 @@ namespace Google.ProtocolBuffers.ProtoGen
public void GenerateParsingCode(TextGenerator writer) public void GenerateParsingCode(TextGenerator writer)
{ {
writer.WriteLine("input.Read{0}Array(tag, field_name, result.{1}_, {2}.DefaultInstance, extensionRegistry);", MessageOrGroup, Name, TypeName); writer.WriteLine("input.Read{0}Array(tag, field_name, result.{1}_, {2}.DefaultInstance, extensionRegistry);", MessageOrGroup, Name, TypeName);
//writer.WriteLine("{0}.Builder subBuilder = {0}.CreateBuilder();", TypeName);
//if (Descriptor.FieldType == FieldType.Group)
//{
// writer.WriteLine("input.ReadGroup({0}, subBuilder, extensionRegistry);", Number);
//}
//else
//{
// writer.WriteLine("input.ReadMessage(subBuilder, extensionRegistry);");
//}
//writer.WriteLine("Add{0}(subBuilder.BuildPartial());", PropertyName);
} }
public void GenerateSerializationCode(TextGenerator writer) public void GenerateSerializationCode(TextGenerator writer)
{ {
writer.WriteLine("if ({0}_.Count > 0) {{", Name); writer.WriteLine("if ({0}_.Count > 0) {{", Name);
writer.Indent(); writer.Indent();
writer.WriteLine("output.WriteArray(pbd::FieldType.{3}, {0}, field_names[{2}], {1}_);", Number, Name, FieldOrdinal, Descriptor.FieldType);
// Arrays of message types do not currently support 'packed' storage
//if (Descriptor.IsPacked)
// writer.WriteLine("output.WritePackedArray(pbd::FieldType.{3}, {0}, \"{2}\", {1}MemoizedSerializedSize, {1}_);", Number, Name, Descriptor.Name, Descriptor.FieldType);
//else
writer.WriteLine("output.WriteArray(pbd::FieldType.{3}, {0}, \"{2}\", {1}_);", Number, Name, Descriptor.Name, Descriptor.FieldType);
//writer.WriteLine("foreach ({0} element in {1}List) {{", TypeName, PropertyName);
//writer.WriteLine(" output.Write{0}({1}, element);", MessageOrGroup, Number);
//writer.WriteLine("}");
writer.Outdent(); writer.Outdent();
writer.WriteLine("}"); writer.WriteLine("}");
} }
......
...@@ -41,8 +41,8 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -41,8 +41,8 @@ namespace Google.ProtocolBuffers.ProtoGen
{ {
internal class RepeatedPrimitiveFieldGenerator : FieldGeneratorBase, IFieldSourceGenerator internal class RepeatedPrimitiveFieldGenerator : FieldGeneratorBase, IFieldSourceGenerator
{ {
internal RepeatedPrimitiveFieldGenerator(FieldDescriptor descriptor) internal RepeatedPrimitiveFieldGenerator(FieldDescriptor descriptor, int fieldOrdinal)
: base(descriptor) : base(descriptor, fieldOrdinal)
{ {
} }
...@@ -122,19 +122,6 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -122,19 +122,6 @@ namespace Google.ProtocolBuffers.ProtoGen
public void GenerateParsingCode(TextGenerator writer) public void GenerateParsingCode(TextGenerator writer)
{ {
writer.WriteLine("input.ReadPrimitiveArray(pbd::FieldType.{1}, tag, field_name, result.{0}_);", Name, Descriptor.FieldType); writer.WriteLine("input.ReadPrimitiveArray(pbd::FieldType.{1}, tag, field_name, result.{0}_);", Name, Descriptor.FieldType);
//if (Descriptor.IsPacked)
//{
// writer.WriteLine("int length = input.ReadInt32();");
// writer.WriteLine("int limit = input.PushLimit(length);");
// writer.WriteLine("while (!input.ReachedLimit) {");
// writer.WriteLine(" Add{0}(input.Read{1}());", PropertyName, CapitalizedTypeName);
// writer.WriteLine("}");
// writer.WriteLine("input.PopLimit(limit);");
//}
//else
//{
// writer.WriteLine("Add{0}(input.Read{1}());", PropertyName, CapitalizedTypeName);
//}
} }
public void GenerateSerializationCode(TextGenerator writer) public void GenerateSerializationCode(TextGenerator writer)
...@@ -142,23 +129,9 @@ namespace Google.ProtocolBuffers.ProtoGen ...@@ -142,23 +129,9 @@ namespace Google.ProtocolBuffers.ProtoGen
writer.WriteLine("if ({0}_.Count > 0) {{", Name); writer.WriteLine("if ({0}_.Count > 0) {{", Name);
writer.Indent(); writer.Indent();
if (Descriptor.IsPacked) if (Descriptor.IsPacked)
writer.WriteLine("output.WritePackedArray(pbd::FieldType.{3}, {0}, \"{2}\", {1}MemoizedSerializedSize, {1}_);", Number, Name, Descriptor.Name, Descriptor.FieldType); writer.WriteLine("output.WritePackedArray(pbd::FieldType.{3}, {0}, field_names[{2}], {1}MemoizedSerializedSize, {1}_);", Number, Name, FieldOrdinal, Descriptor.FieldType);
else else
writer.WriteLine("output.WriteArray(pbd::FieldType.{3}, {0}, \"{2}\", {1}_);", Number, Name, Descriptor.Name, Descriptor.FieldType); writer.WriteLine("output.WriteArray(pbd::FieldType.{3}, {0}, field_names[{2}], {1}_);", Number, Name, FieldOrdinal, 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.Outdent();
writer.WriteLine("}"); writer.WriteLine("}");
} }
......
This diff is collapsed.
...@@ -59,6 +59,8 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -59,6 +59,8 @@ namespace Google.ProtocolBuffers.TestProtos {
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.3.0.277")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.3.0.277")]
public sealed partial class OptionsMessage : pb::GeneratedMessage<OptionsMessage, OptionsMessage.Builder> { public sealed partial class OptionsMessage : pb::GeneratedMessage<OptionsMessage, OptionsMessage.Builder> {
private static readonly OptionsMessage defaultInstance = new Builder().BuildPartial(); private static readonly OptionsMessage defaultInstance = new Builder().BuildPartial();
private static readonly string[] _optionsMessageFieldNames = new string[] { "customized", "normal", "options_message" };
private static readonly uint[] _optionsMessageFieldTags = new uint[] { 26, 10, 18 };
public static OptionsMessage DefaultInstance { public static OptionsMessage DefaultInstance {
get { return defaultInstance; } get { return defaultInstance; }
} }
...@@ -117,14 +119,15 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -117,14 +119,15 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::ICodedOutputStream output) { public override void WriteTo(pb::ICodedOutputStream output) {
int size = SerializedSize; int size = SerializedSize;
string[] field_names = _optionsMessageFieldNames;
if (hasNormal) { if (hasNormal) {
output.WriteString(1, "normal", Normal); output.WriteString(1, field_names[1], Normal);
} }
if (hasOptionsMessage_) { if (hasOptionsMessage_) {
output.WriteString(2, "options_message", OptionsMessage_); output.WriteString(2, field_names[2], OptionsMessage_);
} }
if (hasCustomName) { if (hasCustomName) {
output.WriteString(3, "customized", CustomName); output.WriteString(3, field_names[0], CustomName);
} }
UnknownFields.WriteTo(output); UnknownFields.WriteTo(output);
} }
...@@ -262,6 +265,18 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -262,6 +265,18 @@ namespace Google.ProtocolBuffers.TestProtos {
uint tag; uint tag;
string field_name; string field_name;
while (input.ReadTag(out tag, out field_name)) { while (input.ReadTag(out tag, out field_name)) {
if(tag == 0 && field_name != null) {
int field_ordinal = global::System.Array.BinarySearch(_optionsMessageFieldNames, field_name, global::System.StringComparer.Ordinal);
if(field_ordinal >= 0)
tag = _optionsMessageFieldTags[field_ordinal];
else {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
continue;
}
}
switch (tag) { switch (tag) {
case 0: { case 0: {
throw pb::InvalidProtocolBufferException.InvalidTag(); throw pb::InvalidProtocolBufferException.InvalidTag();
...@@ -280,15 +295,15 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -280,15 +295,15 @@ namespace Google.ProtocolBuffers.TestProtos {
break; break;
} }
case 10: { case 10: {
result.hasNormal |= input.ReadString(ref result.normal_); result.hasNormal = input.ReadString(ref result.normal_);
break; break;
} }
case 18: { case 18: {
result.hasOptionsMessage_ |= input.ReadString(ref result.optionsMessage_); result.hasOptionsMessage_ = input.ReadString(ref result.optionsMessage_);
break; break;
} }
case 26: { case 26: {
result.hasCustomName |= input.ReadString(ref result.customized_); result.hasCustomName = input.ReadString(ref result.customized_);
break; break;
} }
} }
......
...@@ -63,6 +63,8 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -63,6 +63,8 @@ namespace Google.ProtocolBuffers.TestProtos {
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.3.0.277")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.3.0.277")]
public sealed partial class TestEmbedOptimizedForSize : pb::GeneratedMessage<TestEmbedOptimizedForSize, TestEmbedOptimizedForSize.Builder> { public sealed partial class TestEmbedOptimizedForSize : pb::GeneratedMessage<TestEmbedOptimizedForSize, TestEmbedOptimizedForSize.Builder> {
private static readonly TestEmbedOptimizedForSize defaultInstance = new Builder().BuildPartial(); private static readonly TestEmbedOptimizedForSize defaultInstance = new Builder().BuildPartial();
private static readonly string[] _testEmbedOptimizedForSizeFieldNames = new string[] { "optional_message", "repeated_message" };
private static readonly uint[] _testEmbedOptimizedForSizeFieldTags = new uint[] { 10, 18 };
public static TestEmbedOptimizedForSize DefaultInstance { public static TestEmbedOptimizedForSize DefaultInstance {
get { return defaultInstance; } get { return defaultInstance; }
} }
...@@ -119,11 +121,12 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -119,11 +121,12 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::ICodedOutputStream output) { public override void WriteTo(pb::ICodedOutputStream output) {
int size = SerializedSize; int size = SerializedSize;
string[] field_names = _testEmbedOptimizedForSizeFieldNames;
if (hasOptionalMessage) { if (hasOptionalMessage) {
output.WriteMessage(1, "optional_message", OptionalMessage); output.WriteMessage(1, field_names[0], OptionalMessage);
} }
if (repeatedMessage_.Count > 0) { if (repeatedMessage_.Count > 0) {
output.WriteArray(pbd::FieldType.Message, 2, "repeated_message", repeatedMessage_); output.WriteArray(pbd::FieldType.Message, 2, field_names[1], repeatedMessage_);
} }
UnknownFields.WriteTo(output); UnknownFields.WriteTo(output);
} }
...@@ -256,6 +259,18 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -256,6 +259,18 @@ namespace Google.ProtocolBuffers.TestProtos {
uint tag; uint tag;
string field_name; string field_name;
while (input.ReadTag(out tag, out field_name)) { while (input.ReadTag(out tag, out field_name)) {
if(tag == 0 && field_name != null) {
int field_ordinal = global::System.Array.BinarySearch(_testEmbedOptimizedForSizeFieldNames, field_name, global::System.StringComparer.Ordinal);
if(field_ordinal >= 0)
tag = _testEmbedOptimizedForSizeFieldTags[field_ordinal];
else {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
continue;
}
}
switch (tag) { switch (tag) {
case 0: { case 0: {
throw pb::InvalidProtocolBufferException.InvalidTag(); throw pb::InvalidProtocolBufferException.InvalidTag();
......
...@@ -42,6 +42,8 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -42,6 +42,8 @@ namespace Google.ProtocolBuffers.TestProtos {
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.3.0.277")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.3.0.277")]
public sealed partial class ImportMessageLite : pb::GeneratedMessageLite<ImportMessageLite, ImportMessageLite.Builder> { public sealed partial class ImportMessageLite : pb::GeneratedMessageLite<ImportMessageLite, ImportMessageLite.Builder> {
private static readonly ImportMessageLite defaultInstance = new Builder().BuildPartial(); private static readonly ImportMessageLite defaultInstance = new Builder().BuildPartial();
private static readonly string[] _importMessageLiteFieldNames = new string[] { "d" };
private static readonly uint[] _importMessageLiteFieldTags = new uint[] { 8 };
public static ImportMessageLite DefaultInstance { public static ImportMessageLite DefaultInstance {
get { return defaultInstance; } get { return defaultInstance; }
} }
...@@ -72,8 +74,9 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -72,8 +74,9 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::ICodedOutputStream output) { public override void WriteTo(pb::ICodedOutputStream output) {
int size = SerializedSize; int size = SerializedSize;
string[] field_names = _importMessageLiteFieldNames;
if (hasD) { if (hasD) {
output.WriteInt32(1, "d", D); output.WriteInt32(1, field_names[0], D);
} }
} }
...@@ -210,6 +213,15 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -210,6 +213,15 @@ namespace Google.ProtocolBuffers.TestProtos {
uint tag; uint tag;
string field_name; string field_name;
while (input.ReadTag(out tag, out field_name)) { while (input.ReadTag(out tag, out field_name)) {
if(tag == 0 && field_name != null) {
int field_ordinal = global::System.Array.BinarySearch(_importMessageLiteFieldNames, field_name, global::System.StringComparer.Ordinal);
if(field_ordinal >= 0)
tag = _importMessageLiteFieldTags[field_ordinal];
else {
ParseUnknownField(input, extensionRegistry, tag, field_name);
continue;
}
}
switch (tag) { switch (tag) {
case 0: { case 0: {
throw pb::InvalidProtocolBufferException.InvalidTag(); throw pb::InvalidProtocolBufferException.InvalidTag();
...@@ -222,7 +234,7 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -222,7 +234,7 @@ namespace Google.ProtocolBuffers.TestProtos {
break; break;
} }
case 8: { case 8: {
result.hasD |= input.ReadInt32(ref result.d_); result.hasD = input.ReadInt32(ref result.d_);
break; break;
} }
} }
......
...@@ -70,6 +70,8 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -70,6 +70,8 @@ namespace Google.ProtocolBuffers.TestProtos {
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.3.0.277")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.3.0.277")]
public sealed partial class ImportMessage : pb::GeneratedMessage<ImportMessage, ImportMessage.Builder> { public sealed partial class ImportMessage : pb::GeneratedMessage<ImportMessage, ImportMessage.Builder> {
private static readonly ImportMessage defaultInstance = new Builder().BuildPartial(); private static readonly ImportMessage defaultInstance = new Builder().BuildPartial();
private static readonly string[] _importMessageFieldNames = new string[] { "d" };
private static readonly uint[] _importMessageFieldTags = new uint[] { 8 };
public static ImportMessage DefaultInstance { public static ImportMessage DefaultInstance {
get { return defaultInstance; } get { return defaultInstance; }
} }
...@@ -108,8 +110,9 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -108,8 +110,9 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::ICodedOutputStream output) { public override void WriteTo(pb::ICodedOutputStream output) {
int size = SerializedSize; int size = SerializedSize;
string[] field_names = _importMessageFieldNames;
if (hasD) { if (hasD) {
output.WriteInt32(1, "d", D); output.WriteInt32(1, field_names[0], D);
} }
UnknownFields.WriteTo(output); UnknownFields.WriteTo(output);
} }
...@@ -235,6 +238,18 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -235,6 +238,18 @@ namespace Google.ProtocolBuffers.TestProtos {
uint tag; uint tag;
string field_name; string field_name;
while (input.ReadTag(out tag, out field_name)) { while (input.ReadTag(out tag, out field_name)) {
if(tag == 0 && field_name != null) {
int field_ordinal = global::System.Array.BinarySearch(_importMessageFieldNames, field_name, global::System.StringComparer.Ordinal);
if(field_ordinal >= 0)
tag = _importMessageFieldTags[field_ordinal];
else {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
continue;
}
}
switch (tag) { switch (tag) {
case 0: { case 0: {
throw pb::InvalidProtocolBufferException.InvalidTag(); throw pb::InvalidProtocolBufferException.InvalidTag();
...@@ -253,7 +268,7 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -253,7 +268,7 @@ namespace Google.ProtocolBuffers.TestProtos {
break; break;
} }
case 8: { case 8: {
result.hasD |= input.ReadInt32(ref result.d_); result.hasD = input.ReadInt32(ref result.d_);
break; break;
} }
} }
......
...@@ -80,6 +80,8 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService { ...@@ -80,6 +80,8 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService {
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.3.0.277")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.3.0.277")]
public sealed partial class TestMessage : pb::ExtendableMessage<TestMessage, TestMessage.Builder> { public sealed partial class TestMessage : pb::ExtendableMessage<TestMessage, TestMessage.Builder> {
private static readonly TestMessage defaultInstance = new Builder().BuildPartial(); private static readonly TestMessage defaultInstance = new Builder().BuildPartial();
private static readonly string[] _testMessageFieldNames = new string[] { "a" };
private static readonly uint[] _testMessageFieldTags = new uint[] { 8 };
public static TestMessage DefaultInstance { public static TestMessage DefaultInstance {
get { return defaultInstance; } get { return defaultInstance; }
} }
...@@ -119,9 +121,10 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService { ...@@ -119,9 +121,10 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService {
public override void WriteTo(pb::ICodedOutputStream output) { public override void WriteTo(pb::ICodedOutputStream output) {
int size = SerializedSize; int size = SerializedSize;
string[] field_names = _testMessageFieldNames;
pb::ExtendableMessage<TestMessage, TestMessage.Builder>.ExtensionWriter extensionWriter = CreateExtensionWriter(this); pb::ExtendableMessage<TestMessage, TestMessage.Builder>.ExtensionWriter extensionWriter = CreateExtensionWriter(this);
if (hasA) { if (hasA) {
output.WriteInt32(1, "a", A); output.WriteInt32(1, field_names[0], A);
} }
extensionWriter.WriteUntil(536870912, output); extensionWriter.WriteUntil(536870912, output);
UnknownFields.WriteTo(output); UnknownFields.WriteTo(output);
...@@ -250,6 +253,18 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService { ...@@ -250,6 +253,18 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService {
uint tag; uint tag;
string field_name; string field_name;
while (input.ReadTag(out tag, out field_name)) { while (input.ReadTag(out tag, out field_name)) {
if(tag == 0 && field_name != null) {
int field_ordinal = global::System.Array.BinarySearch(_testMessageFieldNames, field_name, global::System.StringComparer.Ordinal);
if(field_ordinal >= 0)
tag = _testMessageFieldTags[field_ordinal];
else {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
continue;
}
}
switch (tag) { switch (tag) {
case 0: { case 0: {
throw pb::InvalidProtocolBufferException.InvalidTag(); throw pb::InvalidProtocolBufferException.InvalidTag();
...@@ -268,7 +283,7 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService { ...@@ -268,7 +283,7 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService {
break; break;
} }
case 8: { case 8: {
result.hasA |= input.ReadInt32(ref result.a_); result.hasA = input.ReadInt32(ref result.a_);
break; break;
} }
} }
......
...@@ -82,6 +82,8 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -82,6 +82,8 @@ namespace Google.ProtocolBuffers.TestProtos {
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.3.0.277")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.3.0.277")]
public sealed partial class SearchRequest : pb::GeneratedMessage<SearchRequest, SearchRequest.Builder> { public sealed partial class SearchRequest : pb::GeneratedMessage<SearchRequest, SearchRequest.Builder> {
private static readonly SearchRequest defaultInstance = new Builder().BuildPartial(); private static readonly SearchRequest defaultInstance = new Builder().BuildPartial();
private static readonly string[] _searchRequestFieldNames = new string[] { "Criteria" };
private static readonly uint[] _searchRequestFieldTags = new uint[] { 10 };
public static SearchRequest DefaultInstance { public static SearchRequest DefaultInstance {
get { return defaultInstance; } get { return defaultInstance; }
} }
...@@ -122,8 +124,9 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -122,8 +124,9 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::ICodedOutputStream output) { public override void WriteTo(pb::ICodedOutputStream output) {
int size = SerializedSize; int size = SerializedSize;
string[] field_names = _searchRequestFieldNames;
if (criteria_.Count > 0) { if (criteria_.Count > 0) {
output.WriteArray(pbd::FieldType.String, 1, "Criteria", criteria_); output.WriteArray(pbd::FieldType.String, 1, field_names[0], criteria_);
} }
UnknownFields.WriteTo(output); UnknownFields.WriteTo(output);
} }
...@@ -255,6 +258,18 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -255,6 +258,18 @@ namespace Google.ProtocolBuffers.TestProtos {
uint tag; uint tag;
string field_name; string field_name;
while (input.ReadTag(out tag, out field_name)) { while (input.ReadTag(out tag, out field_name)) {
if(tag == 0 && field_name != null) {
int field_ordinal = global::System.Array.BinarySearch(_searchRequestFieldNames, field_name, global::System.StringComparer.Ordinal);
if(field_ordinal >= 0)
tag = _searchRequestFieldTags[field_ordinal];
else {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
continue;
}
}
switch (tag) { switch (tag) {
case 0: { case 0: {
throw pb::InvalidProtocolBufferException.InvalidTag(); throw pb::InvalidProtocolBufferException.InvalidTag();
...@@ -324,6 +339,8 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -324,6 +339,8 @@ namespace Google.ProtocolBuffers.TestProtos {
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.3.0.277")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.3.0.277")]
public sealed partial class SearchResponse : pb::GeneratedMessage<SearchResponse, SearchResponse.Builder> { public sealed partial class SearchResponse : pb::GeneratedMessage<SearchResponse, SearchResponse.Builder> {
private static readonly SearchResponse defaultInstance = new Builder().BuildPartial(); private static readonly SearchResponse defaultInstance = new Builder().BuildPartial();
private static readonly string[] _searchResponseFieldNames = new string[] { "results" };
private static readonly uint[] _searchResponseFieldTags = new uint[] { 10 };
public static SearchResponse DefaultInstance { public static SearchResponse DefaultInstance {
get { return defaultInstance; } get { return defaultInstance; }
} }
...@@ -354,6 +371,8 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -354,6 +371,8 @@ namespace Google.ProtocolBuffers.TestProtos {
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.3.0.277")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.3.0.277")]
public sealed partial class ResultItem : pb::GeneratedMessage<ResultItem, ResultItem.Builder> { public sealed partial class ResultItem : pb::GeneratedMessage<ResultItem, ResultItem.Builder> {
private static readonly ResultItem defaultInstance = new Builder().BuildPartial(); private static readonly ResultItem defaultInstance = new Builder().BuildPartial();
private static readonly string[] _resultItemFieldNames = new string[] { "name", "url" };
private static readonly uint[] _resultItemFieldTags = new uint[] { 18, 10 };
public static ResultItem DefaultInstance { public static ResultItem DefaultInstance {
get { return defaultInstance; } get { return defaultInstance; }
} }
...@@ -403,11 +422,12 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -403,11 +422,12 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::ICodedOutputStream output) { public override void WriteTo(pb::ICodedOutputStream output) {
int size = SerializedSize; int size = SerializedSize;
string[] field_names = _resultItemFieldNames;
if (hasUrl) { if (hasUrl) {
output.WriteString(1, "url", Url); output.WriteString(1, field_names[1], Url);
} }
if (hasName) { if (hasName) {
output.WriteString(2, "name", Name); output.WriteString(2, field_names[0], Name);
} }
UnknownFields.WriteTo(output); UnknownFields.WriteTo(output);
} }
...@@ -539,6 +559,18 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -539,6 +559,18 @@ namespace Google.ProtocolBuffers.TestProtos {
uint tag; uint tag;
string field_name; string field_name;
while (input.ReadTag(out tag, out field_name)) { while (input.ReadTag(out tag, out field_name)) {
if(tag == 0 && field_name != null) {
int field_ordinal = global::System.Array.BinarySearch(_resultItemFieldNames, field_name, global::System.StringComparer.Ordinal);
if(field_ordinal >= 0)
tag = _resultItemFieldTags[field_ordinal];
else {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
continue;
}
}
switch (tag) { switch (tag) {
case 0: { case 0: {
throw pb::InvalidProtocolBufferException.InvalidTag(); throw pb::InvalidProtocolBufferException.InvalidTag();
...@@ -557,11 +589,11 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -557,11 +589,11 @@ namespace Google.ProtocolBuffers.TestProtos {
break; break;
} }
case 10: { case 10: {
result.hasUrl |= input.ReadString(ref result.url_); result.hasUrl = input.ReadString(ref result.url_);
break; break;
} }
case 18: { case 18: {
result.hasName |= input.ReadString(ref result.name_); result.hasName = input.ReadString(ref result.name_);
break; break;
} }
} }
...@@ -643,8 +675,9 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -643,8 +675,9 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::ICodedOutputStream output) { public override void WriteTo(pb::ICodedOutputStream output) {
int size = SerializedSize; int size = SerializedSize;
string[] field_names = _searchResponseFieldNames;
if (results_.Count > 0) { if (results_.Count > 0) {
output.WriteArray(pbd::FieldType.Message, 1, "results", results_); output.WriteArray(pbd::FieldType.Message, 1, field_names[0], results_);
} }
UnknownFields.WriteTo(output); UnknownFields.WriteTo(output);
} }
...@@ -771,6 +804,18 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -771,6 +804,18 @@ namespace Google.ProtocolBuffers.TestProtos {
uint tag; uint tag;
string field_name; string field_name;
while (input.ReadTag(out tag, out field_name)) { while (input.ReadTag(out tag, out field_name)) {
if(tag == 0 && field_name != null) {
int field_ordinal = global::System.Array.BinarySearch(_searchResponseFieldNames, field_name, global::System.StringComparer.Ordinal);
if(field_ordinal >= 0)
tag = _searchResponseFieldTags[field_ordinal];
else {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
continue;
}
}
switch (tag) { switch (tag) {
case 0: { case 0: {
throw pb::InvalidProtocolBufferException.InvalidTag(); throw pb::InvalidProtocolBufferException.InvalidTag();
...@@ -850,6 +895,8 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -850,6 +895,8 @@ namespace Google.ProtocolBuffers.TestProtos {
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.3.0.277")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.3.0.277")]
public sealed partial class RefineSearchRequest : pb::GeneratedMessage<RefineSearchRequest, RefineSearchRequest.Builder> { public sealed partial class RefineSearchRequest : pb::GeneratedMessage<RefineSearchRequest, RefineSearchRequest.Builder> {
private static readonly RefineSearchRequest defaultInstance = new Builder().BuildPartial(); private static readonly RefineSearchRequest defaultInstance = new Builder().BuildPartial();
private static readonly string[] _refineSearchRequestFieldNames = new string[] { "Criteria", "previous_results" };
private static readonly uint[] _refineSearchRequestFieldTags = new uint[] { 10, 18 };
public static RefineSearchRequest DefaultInstance { public static RefineSearchRequest DefaultInstance {
get { return defaultInstance; } get { return defaultInstance; }
} }
...@@ -902,11 +949,12 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -902,11 +949,12 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::ICodedOutputStream output) { public override void WriteTo(pb::ICodedOutputStream output) {
int size = SerializedSize; int size = SerializedSize;
string[] field_names = _refineSearchRequestFieldNames;
if (criteria_.Count > 0) { if (criteria_.Count > 0) {
output.WriteArray(pbd::FieldType.String, 1, "Criteria", criteria_); output.WriteArray(pbd::FieldType.String, 1, field_names[0], criteria_);
} }
if (hasPreviousResults) { if (hasPreviousResults) {
output.WriteMessage(2, "previous_results", PreviousResults); output.WriteMessage(2, field_names[1], PreviousResults);
} }
UnknownFields.WriteTo(output); UnknownFields.WriteTo(output);
} }
...@@ -1044,6 +1092,18 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -1044,6 +1092,18 @@ namespace Google.ProtocolBuffers.TestProtos {
uint tag; uint tag;
string field_name; string field_name;
while (input.ReadTag(out tag, out field_name)) { while (input.ReadTag(out tag, out field_name)) {
if(tag == 0 && field_name != null) {
int field_ordinal = global::System.Array.BinarySearch(_refineSearchRequestFieldNames, field_name, global::System.StringComparer.Ordinal);
if(field_ordinal >= 0)
tag = _refineSearchRequestFieldTags[field_ordinal];
else {
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
ParseUnknownField(input, unknownFields, extensionRegistry, tag, field_name);
continue;
}
}
switch (tag) { switch (tag) {
case 0: { case 0: {
throw pb::InvalidProtocolBufferException.InvalidTag(); throw pb::InvalidProtocolBufferException.InvalidTag();
......
This diff is collapsed.
...@@ -31,6 +31,8 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -31,6 +31,8 @@ namespace Google.ProtocolBuffers.TestProtos {
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.3.0.277")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("ProtoGen", "2.3.0.277")]
public sealed partial class TestLiteImportsNonlite : pb::GeneratedMessageLite<TestLiteImportsNonlite, TestLiteImportsNonlite.Builder> { public sealed partial class TestLiteImportsNonlite : pb::GeneratedMessageLite<TestLiteImportsNonlite, TestLiteImportsNonlite.Builder> {
private static readonly TestLiteImportsNonlite defaultInstance = new Builder().BuildPartial(); private static readonly TestLiteImportsNonlite defaultInstance = new Builder().BuildPartial();
private static readonly string[] _testLiteImportsNonliteFieldNames = new string[] { "message" };
private static readonly uint[] _testLiteImportsNonliteFieldTags = new uint[] { 10 };
public static TestLiteImportsNonlite DefaultInstance { public static TestLiteImportsNonlite DefaultInstance {
get { return defaultInstance; } get { return defaultInstance; }
} }
...@@ -61,8 +63,9 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -61,8 +63,9 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::ICodedOutputStream output) { public override void WriteTo(pb::ICodedOutputStream output) {
int size = SerializedSize; int size = SerializedSize;
string[] field_names = _testLiteImportsNonliteFieldNames;
if (hasMessage) { if (hasMessage) {
output.WriteMessage(1, "message", Message); output.WriteMessage(1, field_names[0], Message);
} }
} }
...@@ -199,6 +202,15 @@ namespace Google.ProtocolBuffers.TestProtos { ...@@ -199,6 +202,15 @@ namespace Google.ProtocolBuffers.TestProtos {
uint tag; uint tag;
string field_name; string field_name;
while (input.ReadTag(out tag, out field_name)) { while (input.ReadTag(out tag, out field_name)) {
if(tag == 0 && field_name != null) {
int field_ordinal = global::System.Array.BinarySearch(_testLiteImportsNonliteFieldNames, field_name, global::System.StringComparer.Ordinal);
if(field_ordinal >= 0)
tag = _testLiteImportsNonliteFieldTags[field_ordinal];
else {
ParseUnknownField(input, extensionRegistry, tag, field_name);
continue;
}
}
switch (tag) { switch (tag) {
case 0: { case 0: {
throw pb::InvalidProtocolBufferException.InvalidTag(); throw pb::InvalidProtocolBufferException.InvalidTag();
......
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