Commit c671a4b3 authored by csharptest's avatar csharptest Committed by rogerk

A few performance tweaks of the ICodedOutputStream interface/implementation

parent c2a1f9b5
......@@ -154,10 +154,10 @@ namespace Google.ProtocolBuffers.Examples.AddressBook {
public override void WriteTo(pb::ICodedOutputStream output) {
int size = SerializedSize;
if (HasNumber) {
if (hasNumber) {
output.WriteString(1, "number", Number);
}
if (HasType) {
if (hasType) {
output.WriteEnum(2, "type", (int) Type, Type.ToString());
}
UnknownFields.WriteTo(output);
......@@ -170,10 +170,10 @@ namespace Google.ProtocolBuffers.Examples.AddressBook {
if (size != -1) return size;
size = 0;
if (HasNumber) {
if (hasNumber) {
size += pb::CodedOutputStream.ComputeStringSize(1, Number);
}
if (HasType) {
if (hasType) {
size += pb::CodedOutputStream.ComputeEnumSize(2, (int) Type);
}
size += UnknownFields.SerializedSize;
......@@ -334,7 +334,7 @@ namespace Google.ProtocolBuffers.Examples.AddressBook {
public bool HasNumber {
get { return result.HasNumber; }
get { return result.hasNumber; }
}
public string Number {
get { return result.Number; }
......@@ -353,7 +353,7 @@ namespace Google.ProtocolBuffers.Examples.AddressBook {
}
public bool HasType {
get { return result.HasType; }
get { return result.hasType; }
}
public global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneType Type {
get { return result.Type; }
......@@ -433,13 +433,13 @@ namespace Google.ProtocolBuffers.Examples.AddressBook {
public override void WriteTo(pb::ICodedOutputStream output) {
int size = SerializedSize;
if (HasName) {
if (hasName) {
output.WriteString(1, "name", Name);
}
if (HasId) {
if (hasId) {
output.WriteInt32(2, "id", Id);
}
if (HasEmail) {
if (hasEmail) {
output.WriteString(3, "email", Email);
}
if (phone_.Count > 0) {
......@@ -455,13 +455,13 @@ namespace Google.ProtocolBuffers.Examples.AddressBook {
if (size != -1) return size;
size = 0;
if (HasName) {
if (hasName) {
size += pb::CodedOutputStream.ComputeStringSize(1, Name);
}
if (HasId) {
if (hasId) {
size += pb::CodedOutputStream.ComputeInt32Size(2, Id);
}
if (HasEmail) {
if (hasEmail) {
size += pb::CodedOutputStream.ComputeStringSize(3, Email);
}
foreach (global::Google.ProtocolBuffers.Examples.AddressBook.Person.Types.PhoneNumber element in PhoneList) {
......@@ -632,7 +632,7 @@ namespace Google.ProtocolBuffers.Examples.AddressBook {
public bool HasName {
get { return result.HasName; }
get { return result.hasName; }
}
public string Name {
get { return result.Name; }
......@@ -651,7 +651,7 @@ namespace Google.ProtocolBuffers.Examples.AddressBook {
}
public bool HasId {
get { return result.HasId; }
get { return result.hasId; }
}
public int Id {
get { return result.Id; }
......@@ -669,7 +669,7 @@ namespace Google.ProtocolBuffers.Examples.AddressBook {
}
public bool HasEmail {
get { return result.HasEmail; }
get { return result.hasEmail; }
}
public string Email {
get { return result.Email; }
......
......@@ -35,8 +35,10 @@
#endregion
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Threading;
namespace Google.ProtocolBuffers.ProtoBench
{
......@@ -45,20 +47,37 @@ namespace Google.ProtocolBuffers.ProtoBench
/// </summary>
public sealed class Program
{
private static readonly TimeSpan MinSampleTime = TimeSpan.FromSeconds(2);
private static readonly TimeSpan TargetTime = TimeSpan.FromSeconds(30);
private static TimeSpan MinSampleTime = TimeSpan.FromSeconds(2);
private static TimeSpan TargetTime = TimeSpan.FromSeconds(30);
private static bool FastTest = false;
private static bool Verbose = false;
// Avoid a .NET 3.5 dependency
private delegate void Action();
private delegate void BenchmarkTest(string name, long dataSize, Action action);
private static BenchmarkTest RunBenchmark;
public static int Main(string[] args)
{
List<string> temp = new List<string>(args);
FastTest = temp.Remove("/fast") || temp.Remove("-fast");
Verbose = temp.Remove("/verbose") || temp.Remove("-verbose");
RunBenchmark = BenchmarkV1;
if (temp.Remove("/v2") || temp.Remove("-v2"))
RunBenchmark = BenchmarkV2;
args = temp.ToArray();
if (args.Length < 2 || (args.Length%2) != 0)
{
Console.Error.WriteLine("Usage: ProtoBench <descriptor type name> <input data>");
Console.Error.WriteLine("Usage: ProtoBench [/fast] <descriptor type name> <input data>");
Console.Error.WriteLine("The descriptor type name is the fully-qualified message name,");
Console.Error.WriteLine(
"including assembly - e.g. Google.ProtocolBuffers.BenchmarkProtos.Message1,ProtoBench");
Console.Error.WriteLine("including assembly - e.g. Google.ProtocolBuffers.BenchmarkProtos.Message1,ProtoBench");
Console.Error.WriteLine("(You can specify multiple pairs of descriptor type name and input data.)");
return 1;
}
......@@ -94,31 +113,27 @@ namespace Google.ProtocolBuffers.ProtoBench
ByteString inputString = ByteString.CopyFrom(inputData);
IMessage sampleMessage =
defaultMessage.WeakCreateBuilderForType().WeakMergeFrom(inputString).WeakBuild();
Benchmark("Serialize to byte string", inputData.Length, () => sampleMessage.ToByteString());
Benchmark("Serialize to byte array", inputData.Length, () => sampleMessage.ToByteArray());
Benchmark("Serialize to memory stream", inputData.Length,
if(!FastTest) RunBenchmark("Serialize to byte string", inputData.Length, () => sampleMessage.ToByteString());
RunBenchmark("Serialize to byte array", inputData.Length, () => sampleMessage.ToByteArray());
if (!FastTest) RunBenchmark("Serialize to memory stream", inputData.Length,
() => sampleMessage.WriteTo(new MemoryStream()));
Benchmark("Deserialize from byte string", inputData.Length,
if (!FastTest) RunBenchmark("Deserialize from byte string", inputData.Length,
() => defaultMessage.WeakCreateBuilderForType()
.WeakMergeFrom(inputString)
.WeakBuild()
);
Benchmark("Deserialize from byte array", inputData.Length,
RunBenchmark("Deserialize from byte array", inputData.Length,
() => defaultMessage.WeakCreateBuilderForType()
.WeakMergeFrom(CodedInputStream.CreateInstance(inputData))
.WeakBuild()
);
Benchmark("Deserialize from memory stream", inputData.Length, () =>
{
inputStream.Position = 0;
defaultMessage.
WeakCreateBuilderForType()
.WeakMergeFrom(
CodedInputStream.
CreateInstance(
inputStream))
.WeakBuild();
});
if (!FastTest) RunBenchmark("Deserialize from memory stream", inputData.Length,
() => {
inputStream.Position = 0;
defaultMessage.WeakCreateBuilderForType().WeakMergeFrom(
CodedInputStream.CreateInstance(inputStream))
.WeakBuild();
});
Console.WriteLine();
return true;
}
......@@ -131,7 +146,79 @@ namespace Google.ProtocolBuffers.ProtoBench
}
}
private static void Benchmark(string name, long dataSize, Action action)
private static void BenchmarkV2(string name, long dataSize, Action action)
{
TimeSpan elapsed = TimeSpan.Zero;
long runs = 0;
long totalCount = 0;
double best = double.MinValue, worst = double.MaxValue;
ThreadStart threadProc =
delegate()
{
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);
if (Verbose) Console.WriteLine("Round ---: Count = {1,6}, Bps = {2,8:f3}", 0, iterations, first);
elapsed = TimeSpan.Zero;
int max = FastTest ? 30 : 100;
while (runs < max)
{
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);
if (runs == 0 && bps > first * 1.1)
{
if (Verbose) Console.WriteLine("Warming up...");
iterations = (int)((target.Ticks * iterations) / (double)cycle.Ticks);
first = bps;
continue;//still warming up...
}
best = Math.Max(best, bps);
worst = Math.Min(worst, bps);
runs++;
elapsed += cycle;
totalCount += iterations;
iterations = (int) ((target.Ticks*totalCount)/(double) elapsed.Ticks);
}
};
Thread work = new Thread(threadProc);
work.Name = "Worker";
work.Priority = ThreadPriority.Highest;
work.SetApartmentState(ApartmentState.STA);
work.Start();
work.Join();
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,
(totalCount * dataSize) / (elapsed.TotalSeconds * 1024 * 1024), best, worst);
}
private static void BenchmarkV1(string name, long dataSize, Action action)
{
// Make sure it's JITted
action();
......@@ -156,7 +243,9 @@ namespace Google.ProtocolBuffers.ProtoBench
private static TimeSpan TimeAction(Action action, int iterations)
{
GC.Collect();
GC.GetTotalMemory(true);
GC.WaitForPendingFinalizers();
Stopwatch sw = Stopwatch.StartNew();
for (int i = 0; i < iterations; i++)
{
......
......@@ -66,6 +66,7 @@
<ProjectReference Include="..\ProtocolBuffers\ProtocolBuffers.csproj">
<Project>{6908BDCE-D925-43F3-94AC-A531E6DF2591}</Project>
<Name>ProtocolBuffers</Name>
<Private>True</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup>
......
<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
</configuration>
\ No newline at end of file
......@@ -61,7 +61,7 @@ namespace Google.ProtocolBuffers.ProtoGen
public void GenerateBuilderMembers(TextGenerator writer)
{
writer.WriteLine("public bool Has{0} {{", PropertyName);
writer.WriteLine(" get {{ return result.Has{0}; }}", PropertyName);
writer.WriteLine(" get {{ return result.has{0}; }}", PropertyName);
writer.WriteLine("}");
AddClsComplianceCheck(writer);
writer.WriteLine("public {0} {1} {{", TypeName, PropertyName);
......@@ -125,14 +125,14 @@ namespace Google.ProtocolBuffers.ProtoGen
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("}");
}
public void GenerateSerializedSizeCode(TextGenerator writer)
{
writer.WriteLine("if (Has{0}) {{", PropertyName);
writer.WriteLine("if (has{0}) {{", PropertyName);
writer.WriteLine(" size += pb::CodedOutputStream.ComputeEnumSize({0}, (int) {1});", Number, PropertyName);
writer.WriteLine("}");
}
......
......@@ -60,7 +60,7 @@ namespace Google.ProtocolBuffers.ProtoGen
public void GenerateBuilderMembers(TextGenerator writer)
{
writer.WriteLine("public bool Has{0} {{", PropertyName);
writer.WriteLine(" get {{ return result.Has{0}; }}", PropertyName);
writer.WriteLine(" get {{ return result.has{0}; }}", PropertyName);
writer.WriteLine("}");
writer.WriteLine("public {0} {1} {{", TypeName, PropertyName);
writer.WriteLine(" get {{ return result.{0}; }}", PropertyName);
......@@ -80,7 +80,7 @@ namespace Google.ProtocolBuffers.ProtoGen
writer.WriteLine("}");
writer.WriteLine("public Builder Merge{0}({1} value) {{", PropertyName, TypeName);
AddNullCheck(writer);
writer.WriteLine(" if (result.Has{0} &&", PropertyName);
writer.WriteLine(" if (result.has{0} &&", PropertyName);
writer.WriteLine(" result.{0}_ != {1}) {{", Name, DefaultValue);
writer.WriteLine(" result.{0}_ = {1}.CreateBuilder(result.{0}_).MergeFrom(value).BuildPartial();", Name,
TypeName);
......@@ -112,7 +112,7 @@ namespace Google.ProtocolBuffers.ProtoGen
public void GenerateParsingCode(TextGenerator writer)
{
writer.WriteLine("{0}.Builder subBuilder = {0}.CreateBuilder();", TypeName);
writer.WriteLine("if (Has{0}) {{", PropertyName);
writer.WriteLine("if (result.has{0}) {{", PropertyName);
writer.WriteLine(" subBuilder.MergeFrom({0});", PropertyName);
writer.WriteLine("}");
if (Descriptor.FieldType == FieldType.Group)
......@@ -128,14 +128,14 @@ namespace Google.ProtocolBuffers.ProtoGen
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("}");
}
public void GenerateSerializedSizeCode(TextGenerator writer)
{
writer.WriteLine("if (Has{0}) {{", PropertyName);
writer.WriteLine("if (has{0}) {{", PropertyName);
writer.WriteLine(" size += pb::CodedOutputStream.Compute{0}Size({1}, {2});",
MessageOrGroup, Number, PropertyName);
writer.WriteLine("}");
......
......@@ -62,7 +62,7 @@ namespace Google.ProtocolBuffers.ProtoGen
public void GenerateBuilderMembers(TextGenerator writer)
{
writer.WriteLine("public bool Has{0} {{", PropertyName);
writer.WriteLine(" get {{ return result.Has{0}; }}", PropertyName);
writer.WriteLine(" get {{ return result.has{0}; }}", PropertyName);
writer.WriteLine("}");
AddClsComplianceCheck(writer);
writer.WriteLine("public {0} {1} {{", TypeName, PropertyName);
......@@ -102,14 +102,14 @@ namespace Google.ProtocolBuffers.ProtoGen
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("}");
}
public void GenerateSerializedSizeCode(TextGenerator writer)
{
writer.WriteLine("if (Has{0}) {{", PropertyName);
writer.WriteLine("if (has{0}) {{", PropertyName);
writer.WriteLine(" size += pb::CodedOutputStream.Compute{0}Size({1}, {2});",
CapitalizedTypeName, Number, PropertyName);
writer.WriteLine("}");
......
......@@ -117,13 +117,13 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::ICodedOutputStream output) {
int size = SerializedSize;
if (HasNormal) {
if (hasNormal) {
output.WriteString(1, "normal", Normal);
}
if (HasOptionsMessage_) {
if (hasOptionsMessage_) {
output.WriteString(2, "options_message", OptionsMessage_);
}
if (HasCustomName) {
if (hasCustomName) {
output.WriteString(3, "customized", CustomName);
}
UnknownFields.WriteTo(output);
......@@ -136,13 +136,13 @@ namespace Google.ProtocolBuffers.TestProtos {
if (size != -1) return size;
size = 0;
if (HasNormal) {
if (hasNormal) {
size += pb::CodedOutputStream.ComputeStringSize(1, Normal);
}
if (HasOptionsMessage_) {
if (hasOptionsMessage_) {
size += pb::CodedOutputStream.ComputeStringSize(2, OptionsMessage_);
}
if (HasCustomName) {
if (hasCustomName) {
size += pb::CodedOutputStream.ComputeStringSize(3, CustomName);
}
size += UnknownFields.SerializedSize;
......@@ -302,7 +302,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public bool HasNormal {
get { return result.HasNormal; }
get { return result.hasNormal; }
}
public string Normal {
get { return result.Normal; }
......@@ -321,7 +321,7 @@ namespace Google.ProtocolBuffers.TestProtos {
}
public bool HasOptionsMessage_ {
get { return result.HasOptionsMessage_; }
get { return result.hasOptionsMessage_; }
}
public string OptionsMessage_ {
get { return result.OptionsMessage_; }
......@@ -340,7 +340,7 @@ namespace Google.ProtocolBuffers.TestProtos {
}
public bool HasCustomName {
get { return result.HasCustomName; }
get { return result.hasCustomName; }
}
public string CustomName {
get { return result.CustomName; }
......
......@@ -119,7 +119,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::ICodedOutputStream output) {
int size = SerializedSize;
if (HasOptionalMessage) {
if (hasOptionalMessage) {
output.WriteMessage(1, "optional_message", OptionalMessage);
}
if (repeatedMessage_.Count > 0) {
......@@ -135,7 +135,7 @@ namespace Google.ProtocolBuffers.TestProtos {
if (size != -1) return size;
size = 0;
if (HasOptionalMessage) {
if (hasOptionalMessage) {
size += pb::CodedOutputStream.ComputeMessageSize(1, OptionalMessage);
}
foreach (global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize element in RepeatedMessageList) {
......@@ -275,7 +275,7 @@ namespace Google.ProtocolBuffers.TestProtos {
}
case 10: {
global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize.Builder subBuilder = global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize.CreateBuilder();
if (HasOptionalMessage) {
if (result.hasOptionalMessage) {
subBuilder.MergeFrom(OptionalMessage);
}
input.ReadMessage(subBuilder, extensionRegistry);
......@@ -297,7 +297,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public bool HasOptionalMessage {
get { return result.HasOptionalMessage; }
get { return result.hasOptionalMessage; }
}
public global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize OptionalMessage {
get { return result.OptionalMessage; }
......@@ -317,7 +317,7 @@ namespace Google.ProtocolBuffers.TestProtos {
}
public Builder MergeOptionalMessage(global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize value) {
pb::ThrowHelper.ThrowIfNull(value, "value");
if (result.HasOptionalMessage &&
if (result.hasOptionalMessage &&
result.optionalMessage_ != global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize.DefaultInstance) {
result.optionalMessage_ = global::Google.ProtocolBuffers.TestProtos.TestOptimizedForSize.CreateBuilder(result.optionalMessage_).MergeFrom(value).BuildPartial();
} else {
......
......@@ -72,7 +72,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::ICodedOutputStream output) {
int size = SerializedSize;
if (HasD) {
if (hasD) {
output.WriteInt32(1, "d", D);
}
}
......@@ -84,7 +84,7 @@ namespace Google.ProtocolBuffers.TestProtos {
if (size != -1) return size;
size = 0;
if (HasD) {
if (hasD) {
size += pb::CodedOutputStream.ComputeInt32Size(1, D);
}
memoizedSerializedSize = size;
......@@ -233,7 +233,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public bool HasD {
get { return result.HasD; }
get { return result.hasD; }
}
public int D {
get { return result.D; }
......
......@@ -108,7 +108,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::ICodedOutputStream output) {
int size = SerializedSize;
if (HasD) {
if (hasD) {
output.WriteInt32(1, "d", D);
}
UnknownFields.WriteTo(output);
......@@ -121,7 +121,7 @@ namespace Google.ProtocolBuffers.TestProtos {
if (size != -1) return size;
size = 0;
if (HasD) {
if (hasD) {
size += pb::CodedOutputStream.ComputeInt32Size(1, D);
}
size += UnknownFields.SerializedSize;
......@@ -267,7 +267,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public bool HasD {
get { return result.HasD; }
get { return result.hasD; }
}
public int D {
get { return result.D; }
......
......@@ -328,7 +328,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::ICodedOutputStream output) {
int size = SerializedSize;
if (HasMessageSet) {
if (hasMessageSet) {
output.WriteMessage(1, "message_set", MessageSet);
}
UnknownFields.WriteTo(output);
......@@ -341,7 +341,7 @@ namespace Google.ProtocolBuffers.TestProtos {
if (size != -1) return size;
size = 0;
if (HasMessageSet) {
if (hasMessageSet) {
size += pb::CodedOutputStream.ComputeMessageSize(1, MessageSet);
}
size += UnknownFields.SerializedSize;
......@@ -474,7 +474,7 @@ namespace Google.ProtocolBuffers.TestProtos {
}
case 10: {
global::Google.ProtocolBuffers.TestProtos.TestMessageSet.Builder subBuilder = global::Google.ProtocolBuffers.TestProtos.TestMessageSet.CreateBuilder();
if (HasMessageSet) {
if (result.hasMessageSet) {
subBuilder.MergeFrom(MessageSet);
}
input.ReadMessage(subBuilder, extensionRegistry);
......@@ -492,7 +492,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public bool HasMessageSet {
get { return result.HasMessageSet; }
get { return result.hasMessageSet; }
}
public global::Google.ProtocolBuffers.TestProtos.TestMessageSet MessageSet {
get { return result.MessageSet; }
......@@ -512,7 +512,7 @@ namespace Google.ProtocolBuffers.TestProtos {
}
public Builder MergeMessageSet(global::Google.ProtocolBuffers.TestProtos.TestMessageSet value) {
pb::ThrowHelper.ThrowIfNull(value, "value");
if (result.HasMessageSet &&
if (result.hasMessageSet &&
result.messageSet_ != global::Google.ProtocolBuffers.TestProtos.TestMessageSet.DefaultInstance) {
result.messageSet_ = global::Google.ProtocolBuffers.TestProtos.TestMessageSet.CreateBuilder(result.messageSet_).MergeFrom(value).BuildPartial();
} else {
......@@ -577,7 +577,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::ICodedOutputStream output) {
int size = SerializedSize;
if (HasI) {
if (hasI) {
output.WriteInt32(15, "i", I);
}
UnknownFields.WriteTo(output);
......@@ -590,7 +590,7 @@ namespace Google.ProtocolBuffers.TestProtos {
if (size != -1) return size;
size = 0;
if (HasI) {
if (hasI) {
size += pb::CodedOutputStream.ComputeInt32Size(15, I);
}
size += UnknownFields.SerializedSize;
......@@ -736,7 +736,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public bool HasI {
get { return result.HasI; }
get { return result.hasI; }
}
public int I {
get { return result.I; }
......@@ -803,7 +803,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::ICodedOutputStream output) {
int size = SerializedSize;
if (HasStr) {
if (hasStr) {
output.WriteString(25, "str", Str);
}
UnknownFields.WriteTo(output);
......@@ -816,7 +816,7 @@ namespace Google.ProtocolBuffers.TestProtos {
if (size != -1) return size;
size = 0;
if (HasStr) {
if (hasStr) {
size += pb::CodedOutputStream.ComputeStringSize(25, Str);
}
size += UnknownFields.SerializedSize;
......@@ -962,7 +962,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public bool HasStr {
get { return result.HasStr; }
get { return result.hasStr; }
}
public string Str {
get { return result.Str; }
......@@ -1070,10 +1070,10 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::ICodedOutputStream output) {
int size = SerializedSize;
if (HasTypeId) {
if (hasTypeId) {
output.WriteInt32(2, "type_id", TypeId);
}
if (HasMessage) {
if (hasMessage) {
output.WriteBytes(3, "message", Message);
}
UnknownFields.WriteTo(output);
......@@ -1086,10 +1086,10 @@ namespace Google.ProtocolBuffers.TestProtos {
if (size != -1) return size;
size = 0;
if (HasTypeId) {
if (hasTypeId) {
size += pb::CodedOutputStream.ComputeInt32Size(2, TypeId);
}
if (HasMessage) {
if (hasMessage) {
size += pb::CodedOutputStream.ComputeBytesSize(3, Message);
}
size += UnknownFields.SerializedSize;
......@@ -1242,7 +1242,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public bool HasTypeId {
get { return result.HasTypeId; }
get { return result.hasTypeId; }
}
public int TypeId {
get { return result.TypeId; }
......@@ -1260,7 +1260,7 @@ namespace Google.ProtocolBuffers.TestProtos {
}
public bool HasMessage {
get { return result.HasMessage; }
get { return result.hasMessage; }
}
public pb::ByteString Message {
get { return result.Message; }
......
......@@ -120,7 +120,7 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService {
public override void WriteTo(pb::ICodedOutputStream output) {
int size = SerializedSize;
pb::ExtendableMessage<TestMessage, TestMessage.Builder>.ExtensionWriter extensionWriter = CreateExtensionWriter(this);
if (HasA) {
if (hasA) {
output.WriteInt32(1, "a", A);
}
extensionWriter.WriteUntil(536870912, output);
......@@ -134,7 +134,7 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService {
if (size != -1) return size;
size = 0;
if (HasA) {
if (hasA) {
size += pb::CodedOutputStream.ComputeInt32Size(1, A);
}
size += ExtensionsSerializedSize;
......@@ -282,7 +282,7 @@ namespace Google.ProtocolBuffers.TestProtos.NoGenericService {
public bool HasA {
get { return result.HasA; }
get { return result.hasA; }
}
public int A {
get { return result.A; }
......
......@@ -208,7 +208,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public bool HasI {
get { return result.HasI; }
get { return result.hasI; }
}
public int I {
get { return result.I; }
......@@ -226,7 +226,7 @@ namespace Google.ProtocolBuffers.TestProtos {
}
public bool HasMsg {
get { return result.HasMsg; }
get { return result.hasMsg; }
}
public global::Google.ProtocolBuffers.TestProtos.ForeignMessage Msg {
get { return result.Msg; }
......@@ -246,7 +246,7 @@ namespace Google.ProtocolBuffers.TestProtos {
}
public Builder MergeMsg(global::Google.ProtocolBuffers.TestProtos.ForeignMessage value) {
pb::ThrowHelper.ThrowIfNull(value, "value");
if (result.HasMsg &&
if (result.hasMsg &&
result.msg_ != global::Google.ProtocolBuffers.TestProtos.ForeignMessage.DefaultInstance) {
result.msg_ = global::Google.ProtocolBuffers.TestProtos.ForeignMessage.CreateBuilder(result.msg_).MergeFrom(value).BuildPartial();
} else {
......@@ -381,7 +381,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public bool HasX {
get { return result.HasX; }
get { return result.hasX; }
}
public int X {
get { return result.X; }
......@@ -518,7 +518,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public bool HasO {
get { return result.HasO; }
get { return result.hasO; }
}
public global::Google.ProtocolBuffers.TestProtos.TestRequiredOptimizedForSize O {
get { return result.O; }
......@@ -538,7 +538,7 @@ namespace Google.ProtocolBuffers.TestProtos {
}
public Builder MergeO(global::Google.ProtocolBuffers.TestProtos.TestRequiredOptimizedForSize value) {
pb::ThrowHelper.ThrowIfNull(value, "value");
if (result.HasO &&
if (result.hasO &&
result.o_ != global::Google.ProtocolBuffers.TestProtos.TestRequiredOptimizedForSize.DefaultInstance) {
result.o_ = global::Google.ProtocolBuffers.TestProtos.TestRequiredOptimizedForSize.CreateBuilder(result.o_).MergeFrom(value).BuildPartial();
} else {
......
......@@ -403,10 +403,10 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::ICodedOutputStream output) {
int size = SerializedSize;
if (HasUrl) {
if (hasUrl) {
output.WriteString(1, "url", Url);
}
if (HasName) {
if (hasName) {
output.WriteString(2, "name", Name);
}
UnknownFields.WriteTo(output);
......@@ -419,10 +419,10 @@ namespace Google.ProtocolBuffers.TestProtos {
if (size != -1) return size;
size = 0;
if (HasUrl) {
if (hasUrl) {
size += pb::CodedOutputStream.ComputeStringSize(1, Url);
}
if (HasName) {
if (hasName) {
size += pb::CodedOutputStream.ComputeStringSize(2, Name);
}
size += UnknownFields.SerializedSize;
......@@ -575,7 +575,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public bool HasUrl {
get { return result.HasUrl; }
get { return result.hasUrl; }
}
public string Url {
get { return result.Url; }
......@@ -594,7 +594,7 @@ namespace Google.ProtocolBuffers.TestProtos {
}
public bool HasName {
get { return result.HasName; }
get { return result.hasName; }
}
public string Name {
get { return result.Name; }
......@@ -905,7 +905,7 @@ namespace Google.ProtocolBuffers.TestProtos {
if (criteria_.Count > 0) {
output.WriteArray(pbd::FieldType.String, 1, "Criteria", criteria_);
}
if (HasPreviousResults) {
if (hasPreviousResults) {
output.WriteMessage(2, "previous_results", PreviousResults);
}
UnknownFields.WriteTo(output);
......@@ -926,7 +926,7 @@ namespace Google.ProtocolBuffers.TestProtos {
size += dataSize;
size += 1 * criteria_.Count;
}
if (HasPreviousResults) {
if (hasPreviousResults) {
size += pb::CodedOutputStream.ComputeMessageSize(2, PreviousResults);
}
size += UnknownFields.SerializedSize;
......@@ -1067,7 +1067,7 @@ namespace Google.ProtocolBuffers.TestProtos {
}
case 18: {
global::Google.ProtocolBuffers.TestProtos.SearchResponse.Builder subBuilder = global::Google.ProtocolBuffers.TestProtos.SearchResponse.CreateBuilder();
if (HasPreviousResults) {
if (result.hasPreviousResults) {
subBuilder.MergeFrom(PreviousResults);
}
input.ReadMessage(subBuilder, extensionRegistry);
......@@ -1113,7 +1113,7 @@ namespace Google.ProtocolBuffers.TestProtos {
}
public bool HasPreviousResults {
get { return result.HasPreviousResults; }
get { return result.hasPreviousResults; }
}
public global::Google.ProtocolBuffers.TestProtos.SearchResponse PreviousResults {
get { return result.PreviousResults; }
......@@ -1133,7 +1133,7 @@ namespace Google.ProtocolBuffers.TestProtos {
}
public Builder MergePreviousResults(global::Google.ProtocolBuffers.TestProtos.SearchResponse value) {
pb::ThrowHelper.ThrowIfNull(value, "value");
if (result.HasPreviousResults &&
if (result.hasPreviousResults &&
result.previousResults_ != global::Google.ProtocolBuffers.TestProtos.SearchResponse.DefaultInstance) {
result.previousResults_ = global::Google.ProtocolBuffers.TestProtos.SearchResponse.CreateBuilder(result.previousResults_).MergeFrom(value).BuildPartial();
} else {
......
......@@ -182,7 +182,7 @@ namespace Google.ProtocolBuffers.TestProtos {
if (options_.Count > 0) {
output.WriteArray(pbd::FieldType.Enum, 3, "options", options_);
}
if (HasBinary) {
if (hasBinary) {
output.WriteBytes(4, "binary", Binary);
}
UnknownFields.WriteTo(output);
......@@ -205,7 +205,7 @@ namespace Google.ProtocolBuffers.TestProtos {
size += 1 * options_.Count;
}
}
if (HasBinary) {
if (hasBinary) {
size += pb::CodedOutputStream.ComputeBytesSize(4, Binary);
}
size += UnknownFields.SerializedSize;
......@@ -395,7 +395,7 @@ namespace Google.ProtocolBuffers.TestProtos {
}
public bool HasBinary {
get { return result.HasBinary; }
get { return result.hasBinary; }
}
public pb::ByteString Binary {
get { return result.Binary; }
......@@ -689,7 +689,7 @@ namespace Google.ProtocolBuffers.TestProtos {
if (options_.Count > 0) {
output.WriteArray(pbd::FieldType.Enum, 3, "options", options_);
}
if (HasBinary) {
if (hasBinary) {
output.WriteBytes(4, "binary", Binary);
}
UnknownFields.WriteTo(output);
......@@ -712,7 +712,7 @@ namespace Google.ProtocolBuffers.TestProtos {
size += 1 * options_.Count;
}
}
if (HasBinary) {
if (hasBinary) {
size += pb::CodedOutputStream.ComputeBytesSize(4, Binary);
}
size += UnknownFields.SerializedSize;
......@@ -902,7 +902,7 @@ namespace Google.ProtocolBuffers.TestProtos {
}
public bool HasBinary {
get { return result.HasBinary; }
get { return result.hasBinary; }
}
public pb::ByteString Binary {
get { return result.Binary; }
......@@ -1014,19 +1014,19 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::ICodedOutputStream output) {
int size = SerializedSize;
pb::ExtendableMessage<TestXmlMessage, TestXmlMessage.Builder>.ExtensionWriter extensionWriter = CreateExtensionWriter(this);
if (HasChild) {
if (hasChild) {
output.WriteMessage(1, "child", Child);
}
if (numbers_.Count > 0) {
output.WriteArray(pbd::FieldType.Int32, 2, "numbers", numbers_);
}
if (HasText) {
if (hasText) {
output.WriteString(3, "text", Text);
}
if (HasValid) {
if (hasValid) {
output.WriteBool(5, "valid", Valid);
}
if (HasNumber) {
if (hasNumber) {
output.WriteInt64(6, "number", Number);
}
extensionWriter.WriteUntil(200, output);
......@@ -1046,7 +1046,7 @@ namespace Google.ProtocolBuffers.TestProtos {
if (size != -1) return size;
size = 0;
if (HasNumber) {
if (hasNumber) {
size += pb::CodedOutputStream.ComputeInt64Size(6, Number);
}
{
......@@ -1057,7 +1057,7 @@ namespace Google.ProtocolBuffers.TestProtos {
size += dataSize;
size += 1 * numbers_.Count;
}
if (HasText) {
if (hasText) {
size += pb::CodedOutputStream.ComputeStringSize(3, Text);
}
{
......@@ -1068,10 +1068,10 @@ namespace Google.ProtocolBuffers.TestProtos {
size += dataSize;
size += 2 * textlines_.Count;
}
if (HasValid) {
if (hasValid) {
size += pb::CodedOutputStream.ComputeBoolSize(5, Valid);
}
if (HasChild) {
if (hasChild) {
size += pb::CodedOutputStream.ComputeMessageSize(1, Child);
}
foreach (global::Google.ProtocolBuffers.TestProtos.TestXmlMessage.Types.Children element in ChildrenList) {
......@@ -1230,7 +1230,7 @@ namespace Google.ProtocolBuffers.TestProtos {
}
case 10: {
global::Google.ProtocolBuffers.TestProtos.TestXmlChild.Builder subBuilder = global::Google.ProtocolBuffers.TestProtos.TestXmlChild.CreateBuilder();
if (HasChild) {
if (result.hasChild) {
subBuilder.MergeFrom(Child);
}
input.ReadMessage(subBuilder, extensionRegistry);
......@@ -1273,7 +1273,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public bool HasNumber {
get { return result.HasNumber; }
get { return result.hasNumber; }
}
public long Number {
get { return result.Number; }
......@@ -1317,7 +1317,7 @@ namespace Google.ProtocolBuffers.TestProtos {
}
public bool HasText {
get { return result.HasText; }
get { return result.hasText; }
}
public string Text {
get { return result.Text; }
......@@ -1364,7 +1364,7 @@ namespace Google.ProtocolBuffers.TestProtos {
}
public bool HasValid {
get { return result.HasValid; }
get { return result.hasValid; }
}
public bool Valid {
get { return result.Valid; }
......@@ -1382,7 +1382,7 @@ namespace Google.ProtocolBuffers.TestProtos {
}
public bool HasChild {
get { return result.HasChild; }
get { return result.hasChild; }
}
public global::Google.ProtocolBuffers.TestProtos.TestXmlChild Child {
get { return result.Child; }
......@@ -1402,7 +1402,7 @@ namespace Google.ProtocolBuffers.TestProtos {
}
public Builder MergeChild(global::Google.ProtocolBuffers.TestProtos.TestXmlChild value) {
pb::ThrowHelper.ThrowIfNull(value, "value");
if (result.HasChild &&
if (result.hasChild &&
result.child_ != global::Google.ProtocolBuffers.TestProtos.TestXmlChild.DefaultInstance) {
result.child_ = global::Google.ProtocolBuffers.TestProtos.TestXmlChild.CreateBuilder(result.child_).MergeFrom(value).BuildPartial();
} else {
......@@ -1504,7 +1504,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::ICodedOutputStream output) {
int size = SerializedSize;
if (HasNumber) {
if (hasNumber) {
output.WriteInt32(1, "number", Number);
}
UnknownFields.WriteTo(output);
......@@ -1517,7 +1517,7 @@ namespace Google.ProtocolBuffers.TestProtos {
if (size != -1) return size;
size = 0;
if (HasNumber) {
if (hasNumber) {
size += pb::CodedOutputStream.ComputeInt32Size(1, Number);
}
size += UnknownFields.SerializedSize;
......@@ -1663,7 +1663,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public bool HasNumber {
get { return result.HasNumber; }
get { return result.hasNumber; }
}
public int Number {
get { return result.Number; }
......
This diff is collapsed.
......@@ -79,7 +79,8 @@ namespace Google.ProtocolBuffers
void WriteMessageSetExtension(int fieldNumber, string fieldName, ByteString value);
void WriteArray(FieldType fieldType, int fieldNumber, string fieldName, System.Collections.IEnumerable list);
void WritePackedArray(FieldType fieldType, int fieldNumber, string fieldName, System.Collections.IEnumerable list);
void WritePackedArray(FieldType fieldType, int fieldNumber, string fieldName, int calculatedSize, System.Collections.IEnumerable list);
void WriteArray<T>(FieldType fieldType, int fieldNumber, string fieldName, System.Collections.Generic.IEnumerable<T> list);
void WritePackedArray<T>(FieldType fieldType, int fieldNumber, string fieldName, int calculatedSize, System.Collections.Generic.IEnumerable<T> list);
void WriteField(FieldType fieldType, int fieldNumber, string fieldName, object value);
void Flush();
}
......
......@@ -72,7 +72,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::ICodedOutputStream output) {
int size = SerializedSize;
if (HasD) {
if (hasD) {
output.WriteInt32(1, "d", D);
}
}
......@@ -84,7 +84,7 @@ namespace Google.ProtocolBuffers.TestProtos {
if (size != -1) return size;
size = 0;
if (HasD) {
if (hasD) {
size += pb::CodedOutputStream.ComputeInt32Size(1, D);
}
memoizedSerializedSize = size;
......@@ -233,7 +233,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public bool HasD {
get { return result.HasD; }
get { return result.hasD; }
}
public int D {
get { return result.D; }
......
......@@ -108,7 +108,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::ICodedOutputStream output) {
int size = SerializedSize;
if (HasD) {
if (hasD) {
output.WriteInt32(1, "d", D);
}
UnknownFields.WriteTo(output);
......@@ -121,7 +121,7 @@ namespace Google.ProtocolBuffers.TestProtos {
if (size != -1) return size;
size = 0;
if (HasD) {
if (hasD) {
size += pb::CodedOutputStream.ComputeInt32Size(1, D);
}
size += UnknownFields.SerializedSize;
......@@ -267,7 +267,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public bool HasD {
get { return result.HasD; }
get { return result.hasD; }
}
public int D {
get { return result.D; }
......
......@@ -61,7 +61,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public override void WriteTo(pb::ICodedOutputStream output) {
int size = SerializedSize;
if (HasMessage) {
if (hasMessage) {
output.WriteMessage(1, "message", Message);
}
}
......@@ -73,7 +73,7 @@ namespace Google.ProtocolBuffers.TestProtos {
if (size != -1) return size;
size = 0;
if (HasMessage) {
if (hasMessage) {
size += pb::CodedOutputStream.ComputeMessageSize(1, Message);
}
memoizedSerializedSize = size;
......@@ -212,7 +212,7 @@ namespace Google.ProtocolBuffers.TestProtos {
}
case 10: {
global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Builder subBuilder = global::Google.ProtocolBuffers.TestProtos.TestAllTypes.CreateBuilder();
if (HasMessage) {
if (result.hasMessage) {
subBuilder.MergeFrom(Message);
}
input.ReadMessage(subBuilder, extensionRegistry);
......@@ -227,7 +227,7 @@ namespace Google.ProtocolBuffers.TestProtos {
public bool HasMessage {
get { return result.HasMessage; }
get { return result.hasMessage; }
}
public global::Google.ProtocolBuffers.TestProtos.TestAllTypes Message {
get { return result.Message; }
......@@ -247,7 +247,7 @@ namespace Google.ProtocolBuffers.TestProtos {
}
public Builder MergeMessage(global::Google.ProtocolBuffers.TestProtos.TestAllTypes value) {
pb::ThrowHelper.ThrowIfNull(value, "value");
if (result.HasMessage &&
if (result.hasMessage &&
result.message_ != global::Google.ProtocolBuffers.TestProtos.TestAllTypes.DefaultInstance) {
result.message_ = global::Google.ProtocolBuffers.TestProtos.TestAllTypes.CreateBuilder(result.message_).MergeFrom(value).BuildPartial();
} else {
......
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