Full rutime working, Lite generator and runtime building but untested

pull/288/head
csharptest 14 years ago
parent 804b6d842e
commit 980ba8dcd4
  1. 4
      ProtocolBuffers.build
  2. 2
      src/AddressBook/AddressBookProtos.cs
  3. 10
      src/ProtoGen/EnumFieldGenerator.cs
  4. 42
      src/ProtoGen/ExtensionGenerator.cs
  5. 9
      src/ProtoGen/FieldGeneratorBase.cs
  6. 82
      src/ProtoGen/MessageGenerator.cs
  7. 12
      src/ProtoGen/RepeatedEnumFieldGenerator.cs
  8. 2
      src/ProtoGen/RepeatedPrimitiveFieldGenerator.cs
  9. 4
      src/ProtoGen/SourceGeneratorBase.cs
  10. 11
      src/ProtoGen/UmbrellaClassGenerator.cs
  11. 1
      src/ProtocolBuffers.Test/ProtocolBuffers.Test.csproj
  12. 2
      src/ProtocolBuffers.Test/TestProtos/UnitTestCSharpOptionsProtoFile.cs
  13. 2
      src/ProtocolBuffers.Test/TestProtos/UnitTestCustomOptionsProtoFile.cs
  14. 2
      src/ProtocolBuffers.Test/TestProtos/UnitTestEmbedOptimizeForProtoFile.cs
  15. 2
      src/ProtocolBuffers.Test/TestProtos/UnitTestEmptyProtoFile.cs
  16. 2
      src/ProtocolBuffers.Test/TestProtos/UnitTestEnormousDescriptorProtoFile.cs
  17. 2
      src/ProtocolBuffers.Test/TestProtos/UnitTestImportProtoFile.cs
  18. 99
      src/ProtocolBuffers.Test/TestProtos/UnitTestLiteImportNonLiteProtoFile.cs
  19. 2
      src/ProtocolBuffers.Test/TestProtos/UnitTestMessageSetProtoFile.cs
  20. 2
      src/ProtocolBuffers.Test/TestProtos/UnitTestNoGenericServicesProtoFile.cs
  21. 2
      src/ProtocolBuffers.Test/TestProtos/UnitTestOptimizeForProtoFile.cs
  22. 2
      src/ProtocolBuffers.Test/TestProtos/UnitTestProtoFile.cs
  23. 7
      src/ProtocolBuffers/ByteString.cs
  24. 2
      src/ProtocolBuffers/DescriptorProtos/CSharpOptions.cs
  25. 2
      src/ProtocolBuffers/DescriptorProtos/DescriptorProtoFile.cs
  26. 71
      src/ProtocolBuffers/EnumLite.cs
  27. 172
      src/ProtocolBuffers/ExtendableBuilderLite.cs
  28. 156
      src/ProtocolBuffers/ExtendableMessageLite.cs
  29. 117
      src/ProtocolBuffers/GeneratedBuilderLite.cs
  30. 137
      src/ProtocolBuffers/GeneratedExtensionLite.cs
  31. 52
      src/ProtocolBuffers/GeneratedMessageLite.cs
  32. 4
      src/ProtocolBuffers/ProtocolBuffers.csproj
  33. 5
      src/ProtocolBuffers/ProtocolBuffersLite.csproj
  34. 10
      src/ProtocolBuffers/UninitializedMessageException.cs
  35. 8
      src/ProtocolBuffersLite.Test/ProtocolBuffersLite.Test.csproj
  36. 227
      src/ProtocolBuffersLite.Test/TestProtos/UnitTestImportLiteProtoFile.cs
  37. 130
      src/ProtocolBuffersLite.Test/TestProtos/UnitTestLiteImportNonLiteProtoFile.cs
  38. 4107
      src/ProtocolBuffersLite.Test/TestProtos/UnitTestLiteProtoFile.cs
  39. 7605
      src/ProtocolBuffersLite.Test/TestProtos/UnittestLite.cs

@ -177,8 +177,8 @@
<include name="UnitTestEmbedOptimizeForProtoFile.cs" />
<include name="UnitTestEmptyProtoFile.cs" />
<include name="UnitTestEnormousDescriptorProtoFile.cs" />
<include name="UnitTestImportLiteProtoFile.cs" />
<include name="UnitTestImportProtoFile.cs" />
<include name="UnitTestLiteImportNonLiteProtoFile.cs" />
<include name="UnitTestMessageSetProtoFile.cs" />
<include name="UnitTestNoGenericServicesProtoFile.cs" />
<include name="UnitTestOptimizeForProtoFile.cs" />
@ -188,7 +188,7 @@
<copy todir="${src}/ProtocolBuffersLite.Test/TestProtos">
<fileset basedir="${tmp-dir}">
<include name="UnitTestLiteImportNonLiteProtoFile.cs" />
<include name="UnitTestImportLiteProtoFile.cs" />
<include name="UnitTestLiteProtoFile.cs" />
</fileset>
</copy>

@ -1,4 +1,4 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
// Generated by ProtoGen, Version=0.9.0.0, Culture=neutral, PublicKeyToken=8fd7408b07f8d2cd. DO NOT EDIT!
using pb = global::Google.ProtocolBuffers;
using pbc = global::Google.ProtocolBuffers.Collections;

@ -88,10 +88,12 @@ namespace Google.ProtocolBuffers.ProtoGen {
// TODO(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);
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);
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("}");

@ -32,16 +32,20 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion
using System;
using System.Globalization;
using Google.ProtocolBuffers.Descriptors;
namespace Google.ProtocolBuffers.ProtoGen {
internal class ExtensionGenerator : SourceGeneratorBase<FieldDescriptor>, ISourceGenerator {
internal class ExtensionGenerator : FieldGeneratorBase, ISourceGenerator {
private readonly string extends;
private readonly string scope;
private readonly string type;
private readonly string name;
internal ExtensionGenerator(FieldDescriptor descriptor) : base(descriptor) {
internal ExtensionGenerator(FieldDescriptor descriptor)
: base(descriptor) {
if (Descriptor.ExtensionScope != null) {
scope = GetClassName(Descriptor.ExtensionScope);
} else {
@ -58,14 +62,20 @@ namespace Google.ProtocolBuffers.ProtoGen {
type = DescriptorUtil.GetMappedTypeName(Descriptor.MappedType);
break;
}
extends = GetClassName(Descriptor.ContainingType);
name = Descriptor.CSharpOptions.PropertyName;
}
public void Generate(TextGenerator writer) {
writer.WriteLine ("public const int {0} = {1};", GetFieldConstantName(Descriptor), Descriptor.FieldNumber);
if (Descriptor.IsRepeated) {
if (!Descriptor.IsCLSCompliant && Descriptor.File.CSharpOptions.ClsCompliance)
{
writer.WriteLine("public const int {0} = {1};", GetFieldConstantName(Descriptor), Descriptor.FieldNumber);
if (UseLiteRuntime) {
if (!Descriptor.IsCLSCompliant && Descriptor.File.CSharpOptions.ClsCompliance) {
writer.WriteLine("[global::System.CLSCompliant(false)]");
}
writer.WriteLine("{0} static pb::GeneratedExtensionLite<{1}, {2}> {3};", ClassAccessLevel, extends, type, name);
} else if (Descriptor.IsRepeated) {
if (!Descriptor.IsCLSCompliant && Descriptor.File.CSharpOptions.ClsCompliance) {
writer.WriteLine("[global::System.CLSCompliant(false)]");
}
writer.WriteLine("{0} static pb::GeneratedExtensionBase<scg::IList<{1}>> {2};", ClassAccessLevel, type, name);
@ -78,7 +88,25 @@ namespace Google.ProtocolBuffers.ProtoGen {
}
internal void GenerateStaticVariableInitializers(TextGenerator writer) {
if (Descriptor.IsRepeated) {
if (UseLiteRuntime) {
writer.WriteLine("{0}.{1} = ", scope, name);
writer.Indent();
writer.WriteLine("new pb::GeneratedExtensionLite<{0}, {1}>(", extends, type);
writer.Indent();
writer.WriteLine("{0}.DefaultInstance,", extends);
writer.WriteLine("{0},", Descriptor.HasDefaultValue ? DefaultValue : IsNullableType ? "null" : "default(" + type + ")");
writer.WriteLine("{0},", (Descriptor.MappedType == MappedType.Message) ? type + ".DefaultInstance" : "null");
writer.WriteLine("{0},", (Descriptor.MappedType == MappedType.Enum) ? "new EnumLiteMap<" + type + ">()" : "null");
writer.WriteLine("{0},", Descriptor.Index);
writer.Write("pbd::FieldType.{0}", Descriptor.FieldType);
if (Descriptor.IsRepeated) {
writer.WriteLine(",");
writer.Write(Descriptor.IsPacked ? "true" : "false");
}
writer.Outdent();
writer.WriteLine(");");
writer.Outdent();
} else if (Descriptor.IsRepeated) {
writer.WriteLine("{0}.{1} = pb::GeneratedRepeatExtension<{2}>.CreateInstance({0}.Descriptor.Extensions[{3}]);", scope, name, type, Descriptor.Index);
} else {
writer.WriteLine("{0}.{1} = pb::GeneratedSingleExtension<{2}>.CreateInstance({0}.Descriptor.Extensions[{3}]);", scope, name, type, Descriptor.Index);

@ -51,6 +51,7 @@ namespace Google.ProtocolBuffers.ProtoGen {
return true;
}
/// <remarks>Copy exists in ExtensionGenerator.cs</remarks>
protected string DefaultValue {
get {
string suffix = "";
@ -84,6 +85,10 @@ namespace Google.ProtocolBuffers.ProtoGen {
if (!Descriptor.HasDefaultValue) {
return "pb::ByteString.Empty";
}
if (UseLiteRuntime && Descriptor.DefaultValue is ByteString) {
string temp = Convert.ToBase64String(((ByteString)Descriptor.DefaultValue).ToByteArray());
return String.Format("ByteString.FromBase64(\"{0}\")", temp);
}
return string.Format("(pb::ByteString) {0}.Descriptor.Fields[{1}].DefaultValue", GetClassName(Descriptor.ContainingType), Descriptor.Index);
case FieldType.String:
if (AllPrintableAscii(Descriptor.Proto.DefaultValue)) {
@ -95,6 +100,10 @@ namespace Google.ProtocolBuffers.ProtoGen {
.Replace("\"", "\\\"")
+ "\"";
}
if (UseLiteRuntime && Descriptor.DefaultValue is String) {
string temp = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes((String)Descriptor.DefaultValue));
return String.Format("ByteString.FromBase64(\"{0}\").ToStringUtf8()", temp);
}
return string.Format("(string) {0}.Descriptor.Fields[{1}].DefaultValue", GetClassName(Descriptor.ContainingType), Descriptor.Index);
case FieldType.Enum:
return TypeName + "." + ((EnumValueDescriptor) Descriptor.DefaultValue).Name;

@ -117,7 +117,7 @@ namespace Google.ProtocolBuffers.ProtoGen {
writer.WriteLine("{0} sealed partial class {1} : pb::{2}Message{3}<{1}, {1}.Builder> {{",
ClassAccessLevel, ClassName,
Descriptor.Proto.ExtensionRangeCount > 0 ? "Extendable" : "Generated",
UseLiteRuntime ? "Lite" : "");
RuntimeSuffix);
writer.Indent();
// Must call BuildPartial() to make sure all lists are made read-only
writer.WriteLine("private static readonly {0} defaultInstance = new Builder().BuildPartial();", ClassName);
@ -168,7 +168,7 @@ namespace Google.ProtocolBuffers.ProtoGen {
writer.WriteLine();
}
if (Descriptor.File.Options.OptimizeFor == FileOptions.Types.OptimizeMode.SPEED) {
if (OptimizeSpeed) {
GenerateIsInitialized(writer);
GenerateMessageSerializationMethods(writer);
}
@ -203,8 +203,8 @@ namespace Google.ProtocolBuffers.ProtoGen {
// Make sure we've computed the serialized length, so that packed fields are generated correctly.
writer.WriteLine("int size = SerializedSize;");
if (Descriptor.Proto.ExtensionRangeList.Count > 0) {
writer.WriteLine("pb::ExtendableMessage<{0}, {0}.Builder>.ExtensionWriter extensionWriter = CreateExtensionWriter(this);",
ClassName);
writer.WriteLine("pb::ExtendableMessage{1}<{0}, {0}.Builder>.ExtensionWriter extensionWriter = CreateExtensionWriter(this);",
ClassName, RuntimeSuffix);
}
// Merge the fields and the extension ranges, both sorted by field number.
@ -220,10 +220,12 @@ namespace Google.ProtocolBuffers.ProtoGen {
}
}
if (Descriptor.Proto.Options.MessageSetWireFormat) {
writer.WriteLine("UnknownFields.WriteAsMessageSetTo(output);");
} else {
writer.WriteLine("UnknownFields.WriteTo(output);");
if (!UseLiteRuntime) {
if (Descriptor.Proto.Options.MessageSetWireFormat) {
writer.WriteLine("UnknownFields.WriteAsMessageSetTo(output);");
} else {
writer.WriteLine("UnknownFields.WriteTo(output);");
}
}
writer.Outdent();
@ -245,10 +247,12 @@ namespace Google.ProtocolBuffers.ProtoGen {
writer.WriteLine("size += ExtensionsSerializedSize;");
}
if (Descriptor.Options.MessageSetWireFormat) {
writer.WriteLine("size += UnknownFields.SerializedSizeAsMessageSet;");
} else {
writer.WriteLine("size += UnknownFields.SerializedSize;");
if (!UseLiteRuntime) {
if (Descriptor.Options.MessageSetWireFormat) {
writer.WriteLine("size += UnknownFields.SerializedSizeAsMessageSet;");
} else {
writer.WriteLine("size += UnknownFields.SerializedSize;");
}
}
writer.WriteLine("memoizedSerializedSize = size;");
writer.WriteLine("return size;");
@ -352,14 +356,14 @@ namespace Google.ProtocolBuffers.ProtoGen {
writer.WriteLine(" return (Builder) new Builder().MergeFrom(prototype);");
writer.WriteLine("}");
writer.WriteLine();
writer.WriteLine("{0} sealed partial class Builder : pb::{2}Builder<{1}, Builder> {{",
ClassAccessLevel, ClassName, Descriptor.Proto.ExtensionRangeCount > 0 ? "Extendable" : "Generated");
writer.WriteLine("{0} sealed partial class Builder : pb::{2}Builder{3}<{1}, Builder> {{",
ClassAccessLevel, ClassName, Descriptor.Proto.ExtensionRangeCount > 0 ? "Extendable" : "Generated", RuntimeSuffix);
writer.Indent();
writer.WriteLine("protected override Builder ThisBuilder {");
writer.WriteLine(" get { return this; }");
writer.WriteLine("}");
GenerateCommonBuilderMethods(writer);
if (Descriptor.File.Options.OptimizeFor == FileOptions.Types.OptimizeMode.SPEED) {
if (OptimizeSpeed) {
GenerateBuilderParsingMethods(writer);
}
foreach (FieldDescriptor field in Descriptor.Fields) {
@ -389,10 +393,12 @@ namespace Google.ProtocolBuffers.ProtoGen {
writer.WriteLine(" return new Builder().MergeFrom(result);");
writer.WriteLine("}");
writer.WriteLine();
writer.WriteLine("public override pbd::MessageDescriptor DescriptorForType {");
writer.WriteLine(" get {{ return {0}.Descriptor; }}", FullClassName);
writer.WriteLine("}");
writer.WriteLine();
if (!UseLiteRuntime) {
writer.WriteLine("public override pbd::MessageDescriptor DescriptorForType {");
writer.WriteLine(" get {{ return {0}.Descriptor; }}", FullClassName);
writer.WriteLine("}");
writer.WriteLine();
}
writer.WriteLine("public override {0} DefaultInstanceForType {{", ClassName);
writer.WriteLine(" get {{ return {0}.DefaultInstance; }}", FullClassName);
writer.WriteLine("}");
@ -413,8 +419,8 @@ namespace Google.ProtocolBuffers.ProtoGen {
writer.WriteLine("}");
writer.WriteLine();
if (Descriptor.File.Options.OptimizeFor == FileOptions.Types.OptimizeMode.SPEED) {
writer.WriteLine("public override Builder MergeFrom(pb::IMessage other) {");
if (OptimizeSpeed) {
writer.WriteLine("public override Builder MergeFrom(pb::IMessage{0} other) {{", RuntimeSuffix);
writer.WriteLine(" if (other is {0}) {{", ClassName);
writer.WriteLine(" return MergeFrom(({0}) other);", ClassName);
writer.WriteLine(" } else {");
@ -435,7 +441,9 @@ namespace Google.ProtocolBuffers.ProtoGen {
if (Descriptor.Proto.ExtensionRangeCount > 0) {
writer.WriteLine(" this.MergeExtensionFields(other);");
}
writer.WriteLine("this.MergeUnknownFields(other.UnknownFields);");
if (!UseLiteRuntime) {
writer.WriteLine("this.MergeUnknownFields(other.UnknownFields);");
}
writer.WriteLine("return this;");
writer.Outdent();
writer.WriteLine("}");
@ -453,29 +461,37 @@ namespace Google.ProtocolBuffers.ProtoGen {
writer.WriteLine();
writer.WriteLine("public override Builder MergeFrom(pb::CodedInputStream input, pb::ExtensionRegistry extensionRegistry) {");
writer.Indent();
writer.WriteLine("pb::UnknownFieldSet.Builder unknownFields = null;");
if (!UseLiteRuntime) {
writer.WriteLine("pb::UnknownFieldSet.Builder unknownFields = null;");
}
writer.WriteLine("while (true) {");
writer.Indent();
writer.WriteLine("uint tag = input.ReadTag();");
writer.WriteLine("switch (tag) {");
writer.Indent();
writer.WriteLine("case 0: {"); // 0 signals EOF / limit reached
writer.WriteLine(" if (unknownFields != null) {");
writer.WriteLine(" this.UnknownFields = unknownFields.Build();");
writer.WriteLine(" }");
if (!UseLiteRuntime) {
writer.WriteLine(" if (unknownFields != null) {");
writer.WriteLine(" this.UnknownFields = unknownFields.Build();");
writer.WriteLine(" }");
}
writer.WriteLine(" return this;");
writer.WriteLine("}");
writer.WriteLine("default: {");
writer.WriteLine(" if (pb::WireFormat.IsEndGroupTag(tag)) {");
writer.WriteLine(" if (unknownFields != null) {");
writer.WriteLine(" this.UnknownFields = unknownFields.Build();");
writer.WriteLine(" }");
if (!UseLiteRuntime) {
writer.WriteLine(" if (unknownFields != null) {");
writer.WriteLine(" this.UnknownFields = unknownFields.Build();");
writer.WriteLine(" }");
}
writer.WriteLine(" return this;"); // it's an endgroup tag
writer.WriteLine(" }");
writer.WriteLine(" if (unknownFields == null) {"); // First unknown field - create builder now
writer.WriteLine(" unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);");
writer.WriteLine(" }");
writer.WriteLine(" ParseUnknownField(input, unknownFields, extensionRegistry, tag);");
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(" ParseUnknownField(input, {0}extensionRegistry, tag);", UseLiteRuntime ? "" : "unknownFields, ");
writer.WriteLine(" break;");
writer.WriteLine("}");
foreach (FieldDescriptor field in sortedFields) {

@ -43,7 +43,7 @@ namespace Google.ProtocolBuffers.ProtoGen {
}
public void GenerateMembers(TextGenerator writer) {
if (Descriptor.IsPacked && Descriptor.File.Options.OptimizeFor == FileOptions.Types.OptimizeMode.SPEED) {
if (Descriptor.IsPacked && OptimizeSpeed) {
writer.WriteLine("private int {0}MemoizedSerializedSize;", Name);
}
writer.WriteLine("private pbc::PopsicleList<{0}> {1}_ = new pbc::PopsicleList<{0}>();", TypeName, Name);
@ -114,10 +114,12 @@ namespace Google.ProtocolBuffers.ProtoGen {
// TODO(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);
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);
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("}");

@ -43,7 +43,7 @@ namespace Google.ProtocolBuffers.ProtoGen {
}
public void GenerateMembers(TextGenerator writer) {
if (Descriptor.IsPacked && Descriptor.File.Options.OptimizeFor == FileOptions.Types.OptimizeMode.SPEED) {
if (Descriptor.IsPacked && OptimizeSpeed) {
writer.WriteLine("private int {0}MemoizedSerializedSize;", Name);
}
writer.WriteLine("private pbc::PopsicleList<{0}> {1}_ = new pbc::PopsicleList<{0}>();", TypeName, Name);

@ -43,6 +43,7 @@ namespace Google.ProtocolBuffers.ProtoGen {
protected readonly bool OptimizeSpeed;
protected readonly bool OptimizeSize;
protected readonly bool UseLiteRuntime;
protected readonly string RuntimeSuffix;
protected SourceGeneratorBase(T descriptor) {
this.descriptor = descriptor;
@ -50,6 +51,9 @@ namespace Google.ProtocolBuffers.ProtoGen {
OptimizeSize = descriptor.File.Options.OptimizeFor == Google.ProtocolBuffers.DescriptorProtos.FileOptions.Types.OptimizeMode.CODE_SIZE;
OptimizeSpeed = descriptor.File.Options.OptimizeFor == Google.ProtocolBuffers.DescriptorProtos.FileOptions.Types.OptimizeMode.SPEED;
UseLiteRuntime = descriptor.File.Options.OptimizeFor == Google.ProtocolBuffers.DescriptorProtos.FileOptions.Types.OptimizeMode.LITE_RUNTIME;
//Lite runtime uses OptimizeSpeed code branches
OptimizeSpeed |= UseLiteRuntime;
RuntimeSuffix = UseLiteRuntime ? "Lite" : "";
}
protected T Descriptor {

@ -113,13 +113,11 @@ namespace Google.ProtocolBuffers.ProtoGen {
}
private void WriteIntroduction(TextGenerator writer) {
writer.WriteLine("// Generated by the protocol buffer compiler. DO NOT EDIT!");
writer.WriteLine("// Generated by {0}. DO NOT EDIT!", this.GetType().Assembly.FullName);
writer.WriteLine();
writer.WriteLine("using pb = global::Google.ProtocolBuffers;");
if (!UseLiteRuntime) {
writer.WriteLine("using pbc = global::Google.ProtocolBuffers.Collections;");
writer.WriteLine("using pbd = global::Google.ProtocolBuffers.Descriptors;");
}
writer.WriteLine("using pbc = global::Google.ProtocolBuffers.Collections;");
writer.WriteLine("using pbd = global::Google.ProtocolBuffers.Descriptors;");
writer.WriteLine("using scg = global::System.Collections.Generic;");
if (Descriptor.CSharpOptions.Namespace != "") {
@ -223,9 +221,10 @@ namespace Google.ProtocolBuffers.ProtoGen {
private void WriteLiteExtensions(TextGenerator writer) {
writer.WriteLine("#region Extensions");
writer.WriteLine("internal static readonly object Descriptor;");
writer.WriteLine("static {0}() {{", Descriptor.CSharpOptions.UmbrellaClassname);
writer.Indent();
writer.WriteLine("Descriptor = null;");
foreach (MessageDescriptor message in Descriptor.MessageTypes) {
new MessageGenerator(message).GenerateStaticVariableInitializers(writer);

@ -80,6 +80,7 @@
<Compile Include="TestProtos\UnitTestEnormousDescriptorProtoFile.cs" />
<Compile Include="TestProtos\UnitTestImportLiteProtoFile.cs" />
<Compile Include="TestProtos\UnitTestImportProtoFile.cs" />
<Compile Include="TestProtos\UnitTestLiteImportNonLiteProtoFile.cs" />
<Compile Include="TestProtos\UnitTestMessageSetProtoFile.cs" />
<Compile Include="TestProtos\UnitTestNoGenericServicesProtoFile.cs" />
<Compile Include="TestProtos\UnitTestOptimizeForProtoFile.cs" />

@ -1,4 +1,4 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
// Generated by ProtoGen, Version=0.9.0.0, Culture=neutral, PublicKeyToken=8fd7408b07f8d2cd. DO NOT EDIT!
using pb = global::Google.ProtocolBuffers;
using pbc = global::Google.ProtocolBuffers.Collections;

@ -1,4 +1,4 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
// Generated by ProtoGen, Version=0.9.0.0, Culture=neutral, PublicKeyToken=8fd7408b07f8d2cd. DO NOT EDIT!
using pb = global::Google.ProtocolBuffers;
using pbc = global::Google.ProtocolBuffers.Collections;

@ -1,4 +1,4 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
// Generated by ProtoGen, Version=0.9.0.0, Culture=neutral, PublicKeyToken=8fd7408b07f8d2cd. DO NOT EDIT!
using pb = global::Google.ProtocolBuffers;
using pbc = global::Google.ProtocolBuffers.Collections;

@ -1,4 +1,4 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
// Generated by ProtoGen, Version=0.9.0.0, Culture=neutral, PublicKeyToken=8fd7408b07f8d2cd. DO NOT EDIT!
using pb = global::Google.ProtocolBuffers;
using pbc = global::Google.ProtocolBuffers.Collections;

@ -1,4 +1,4 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
// Generated by ProtoGen, Version=0.9.0.0, Culture=neutral, PublicKeyToken=8fd7408b07f8d2cd. DO NOT EDIT!
using pb = global::Google.ProtocolBuffers;
using pbc = global::Google.ProtocolBuffers.Collections;

@ -1,4 +1,4 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
// Generated by ProtoGen, Version=0.9.0.0, Culture=neutral, PublicKeyToken=8fd7408b07f8d2cd. DO NOT EDIT!
using pb = global::Google.ProtocolBuffers;
using pbc = global::Google.ProtocolBuffers.Collections;

@ -1,55 +1,29 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
// Generated by ProtoGen, Version=0.9.0.0, Culture=neutral, PublicKeyToken=8fd7408b07f8d2cd. DO NOT EDIT!
using pb = global::Google.ProtocolBuffers;
using pbc = global::Google.ProtocolBuffers.Collections;
using pbd = global::Google.ProtocolBuffers.Descriptors;
using scg = global::System.Collections.Generic;
namespace protobuf_unittest {
namespace Google.ProtocolBuffers.TestProtos {
public static partial class UnittestLiteImportsNonlite {
public static partial class UnitTestLiteImportNonLiteProtoFile {
#region Extension registration
public static void RegisterAllExtensions(pb::ExtensionRegistry registry) {
}
#endregion
#region Static variables
internal static pbd::MessageDescriptor internal__static_protobuf_unittest_TestLiteImportsNonlite__Descriptor;
internal static pb::FieldAccess.FieldAccessorTable<global::protobuf_unittest.TestLiteImportsNonlite, global::protobuf_unittest.TestLiteImportsNonlite.Builder> internal__static_protobuf_unittest_TestLiteImportsNonlite__FieldAccessorTable;
#endregion
#region Descriptor
public static pbd::FileDescriptor Descriptor {
get { return descriptor; }
}
private static pbd::FileDescriptor descriptor;
static UnittestLiteImportsNonlite() {
byte[] descriptorData = global::System.Convert.FromBase64String(
"CjNnb29nbGUvcHJvdG9idWYvdW5pdHRlc3RfbGl0ZV9pbXBvcnRzX25vbmxp" +
"dGUucHJvdG8SEXByb3RvYnVmX3VuaXR0ZXN0Gh5nb29nbGUvcHJvdG9idWYv" +
"dW5pdHRlc3QucHJvdG8iSgoWVGVzdExpdGVJbXBvcnRzTm9ubGl0ZRIwCgdt" +
"ZXNzYWdlGAEgASgLMh8ucHJvdG9idWZfdW5pdHRlc3QuVGVzdEFsbFR5cGVz" +
"QgJIAw==");
pbd::FileDescriptor.InternalDescriptorAssigner assigner = delegate(pbd::FileDescriptor root) {
descriptor = root;
internal__static_protobuf_unittest_TestLiteImportsNonlite__Descriptor = Descriptor.MessageTypes[0];
internal__static_protobuf_unittest_TestLiteImportsNonlite__FieldAccessorTable =
new pb::FieldAccess.FieldAccessorTable<global::protobuf_unittest.TestLiteImportsNonlite, global::protobuf_unittest.TestLiteImportsNonlite.Builder>(internal__static_protobuf_unittest_TestLiteImportsNonlite__Descriptor,
new string[] { "Message", });
pb::ExtensionRegistry registry = pb::ExtensionRegistry.CreateInstance();
RegisterAllExtensions(registry);
global::protobuf_unittest.Unittest.RegisterAllExtensions(registry);
return registry;
};
pbd::FileDescriptor.InternalBuildGeneratedFileFrom(descriptorData,
new pbd::FileDescriptor[] {
global::protobuf_unittest.Unittest.Descriptor,
}, assigner);
#region Extensions
internal static readonly object Descriptor;
static UnitTestLiteImportNonLiteProtoFile() {
Descriptor = null;
}
#endregion
}
#region Messages
public sealed partial class TestLiteImportsNonlite : pb::GeneratedMessage<TestLiteImportsNonlite, TestLiteImportsNonlite.Builder> {
public sealed partial class TestLiteImportsNonlite : pb::GeneratedMessageLite<TestLiteImportsNonlite, TestLiteImportsNonlite.Builder> {
private static readonly TestLiteImportsNonlite defaultInstance = new Builder().BuildPartial();
public static TestLiteImportsNonlite DefaultInstance {
get { return defaultInstance; }
@ -63,21 +37,13 @@ namespace protobuf_unittest {
get { return this; }
}
public static pbd::MessageDescriptor Descriptor {
get { return global::protobuf_unittest.UnittestLiteImportsNonlite.internal__static_protobuf_unittest_TestLiteImportsNonlite__Descriptor; }
}
protected override pb::FieldAccess.FieldAccessorTable<TestLiteImportsNonlite, TestLiteImportsNonlite.Builder> InternalFieldAccessors {
get { return global::protobuf_unittest.UnittestLiteImportsNonlite.internal__static_protobuf_unittest_TestLiteImportsNonlite__FieldAccessorTable; }
}
public const int MessageFieldNumber = 1;
private bool hasMessage;
private global::protobuf_unittest.TestAllTypes message_ = global::protobuf_unittest.TestAllTypes.DefaultInstance;
private global::Google.ProtocolBuffers.TestProtos.TestAllTypes message_ = global::Google.ProtocolBuffers.TestProtos.TestAllTypes.DefaultInstance;
public bool HasMessage {
get { return hasMessage; }
}
public global::protobuf_unittest.TestAllTypes Message {
public global::Google.ProtocolBuffers.TestProtos.TestAllTypes Message {
get { return message_; }
}
@ -92,7 +58,6 @@ namespace protobuf_unittest {
if (HasMessage) {
output.WriteMessage(1, Message);
}
UnknownFields.WriteTo(output);
}
private int memoizedSerializedSize = -1;
@ -105,7 +70,6 @@ namespace protobuf_unittest {
if (HasMessage) {
size += pb::CodedOutputStream.ComputeMessageSize(1, Message);
}
size += UnknownFields.SerializedSize;
memoizedSerializedSize = size;
return size;
}
@ -148,7 +112,7 @@ namespace protobuf_unittest {
return (Builder) new Builder().MergeFrom(prototype);
}
public sealed partial class Builder : pb::GeneratedBuilder<TestLiteImportsNonlite, Builder> {
public sealed partial class Builder : pb::GeneratedBuilderLite<TestLiteImportsNonlite, Builder> {
protected override Builder ThisBuilder {
get { return this; }
}
@ -169,12 +133,8 @@ namespace protobuf_unittest {
return new Builder().MergeFrom(result);
}
public override pbd::MessageDescriptor DescriptorForType {
get { return global::protobuf_unittest.TestLiteImportsNonlite.Descriptor; }
}
public override TestLiteImportsNonlite DefaultInstanceForType {
get { return global::protobuf_unittest.TestLiteImportsNonlite.DefaultInstance; }
get { return global::Google.ProtocolBuffers.TestProtos.TestLiteImportsNonlite.DefaultInstance; }
}
public override TestLiteImportsNonlite BuildPartial() {
@ -186,7 +146,7 @@ namespace protobuf_unittest {
return returnMe;
}
public override Builder MergeFrom(pb::IMessage other) {
public override Builder MergeFrom(pb::IMessageLite other) {
if (other is TestLiteImportsNonlite) {
return MergeFrom((TestLiteImportsNonlite) other);
} else {
@ -196,11 +156,10 @@ namespace protobuf_unittest {
}
public override Builder MergeFrom(TestLiteImportsNonlite other) {
if (other == global::protobuf_unittest.TestLiteImportsNonlite.DefaultInstance) return this;
if (other == global::Google.ProtocolBuffers.TestProtos.TestLiteImportsNonlite.DefaultInstance) return this;
if (other.HasMessage) {
MergeMessage(other.Message);
}
this.MergeUnknownFields(other.UnknownFields);
return this;
}
@ -209,31 +168,21 @@ namespace protobuf_unittest {
}
public override Builder MergeFrom(pb::CodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
pb::UnknownFieldSet.Builder unknownFields = null;
while (true) {
uint tag = input.ReadTag();
switch (tag) {
case 0: {
if (unknownFields != null) {
this.UnknownFields = unknownFields.Build();
}
return this;
}
default: {
if (pb::WireFormat.IsEndGroupTag(tag)) {
if (unknownFields != null) {
this.UnknownFields = unknownFields.Build();
}
return this;
}
if (unknownFields == null) {
unknownFields = pb::UnknownFieldSet.CreateBuilder(this.UnknownFields);
}
ParseUnknownField(input, unknownFields, extensionRegistry, tag);
ParseUnknownField(input, extensionRegistry, tag);
break;
}
case 10: {
global::protobuf_unittest.TestAllTypes.Builder subBuilder = global::protobuf_unittest.TestAllTypes.CreateBuilder();
global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Builder subBuilder = global::Google.ProtocolBuffers.TestProtos.TestAllTypes.CreateBuilder();
if (HasMessage) {
subBuilder.MergeFrom(Message);
}
@ -249,27 +198,27 @@ namespace protobuf_unittest {
public bool HasMessage {
get { return result.HasMessage; }
}
public global::protobuf_unittest.TestAllTypes Message {
public global::Google.ProtocolBuffers.TestProtos.TestAllTypes Message {
get { return result.Message; }
set { SetMessage(value); }
}
public Builder SetMessage(global::protobuf_unittest.TestAllTypes value) {
public Builder SetMessage(global::Google.ProtocolBuffers.TestProtos.TestAllTypes value) {
pb::ThrowHelper.ThrowIfNull(value, "value");
result.hasMessage = true;
result.message_ = value;
return this;
}
public Builder SetMessage(global::protobuf_unittest.TestAllTypes.Builder builderForValue) {
public Builder SetMessage(global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Builder builderForValue) {
pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue");
result.hasMessage = true;
result.message_ = builderForValue.Build();
return this;
}
public Builder MergeMessage(global::protobuf_unittest.TestAllTypes value) {
public Builder MergeMessage(global::Google.ProtocolBuffers.TestProtos.TestAllTypes value) {
pb::ThrowHelper.ThrowIfNull(value, "value");
if (result.HasMessage &&
result.message_ != global::protobuf_unittest.TestAllTypes.DefaultInstance) {
result.message_ = global::protobuf_unittest.TestAllTypes.CreateBuilder(result.message_).MergeFrom(value).BuildPartial();
result.message_ != global::Google.ProtocolBuffers.TestProtos.TestAllTypes.DefaultInstance) {
result.message_ = global::Google.ProtocolBuffers.TestProtos.TestAllTypes.CreateBuilder(result.message_).MergeFrom(value).BuildPartial();
} else {
result.message_ = value;
}
@ -278,12 +227,12 @@ namespace protobuf_unittest {
}
public Builder ClearMessage() {
result.hasMessage = false;
result.message_ = global::protobuf_unittest.TestAllTypes.DefaultInstance;
result.message_ = global::Google.ProtocolBuffers.TestProtos.TestAllTypes.DefaultInstance;
return this;
}
}
static TestLiteImportsNonlite() {
object.ReferenceEquals(global::protobuf_unittest.UnittestLiteImportsNonlite.Descriptor, null);
object.ReferenceEquals(global::Google.ProtocolBuffers.TestProtos.UnitTestLiteImportNonLiteProtoFile.Descriptor, null);
}
}

@ -1,4 +1,4 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
// Generated by ProtoGen, Version=0.9.0.0, Culture=neutral, PublicKeyToken=8fd7408b07f8d2cd. DO NOT EDIT!
using pb = global::Google.ProtocolBuffers;
using pbc = global::Google.ProtocolBuffers.Collections;

@ -1,4 +1,4 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
// Generated by ProtoGen, Version=0.9.0.0, Culture=neutral, PublicKeyToken=8fd7408b07f8d2cd. DO NOT EDIT!
using pb = global::Google.ProtocolBuffers;
using pbc = global::Google.ProtocolBuffers.Collections;

@ -1,4 +1,4 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
// Generated by ProtoGen, Version=0.9.0.0, Culture=neutral, PublicKeyToken=8fd7408b07f8d2cd. DO NOT EDIT!
using pb = global::Google.ProtocolBuffers;
using pbc = global::Google.ProtocolBuffers.Collections;

@ -1,4 +1,4 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
// Generated by ProtoGen, Version=0.9.0.0, Culture=neutral, PublicKeyToken=8fd7408b07f8d2cd. DO NOT EDIT!
using pb = global::Google.ProtocolBuffers;
using pbc = global::Google.ProtocolBuffers.Collections;

@ -78,6 +78,13 @@ namespace Google.ProtocolBuffers {
return (byte[])bytes.Clone();
}
/// <summary>
/// Constructs a ByteString from the Base64 Encoded String.
/// </summary>
public static ByteString FromBase64(string bytes) {
return new ByteString(System.Convert.FromBase64String(bytes));
}
/// <summary>
/// Constructs a ByteString from the given array. The contents
/// are copied, so further modifications to the array will not

@ -1,4 +1,4 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
// Generated by ProtoGen, Version=0.9.0.0, Culture=neutral, PublicKeyToken=8fd7408b07f8d2cd. DO NOT EDIT!
using pb = global::Google.ProtocolBuffers;
using pbc = global::Google.ProtocolBuffers.Collections;

@ -1,4 +1,4 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
// Generated by ProtoGen, Version=0.9.0.0, Culture=neutral, PublicKeyToken=8fd7408b07f8d2cd. DO NOT EDIT!
using pb = global::Google.ProtocolBuffers;
using pbc = global::Google.ProtocolBuffers.Collections;

@ -1,5 +1,40 @@
using System;
#region Copyright notice and license
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// http://github.com/jskeet/dotnet-protobufs/
// Original C++/Java/Python code:
// http://code.google.com/p/protobuf/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
namespace Google.ProtocolBuffers {
@ -28,4 +63,38 @@ namespace Google.ProtocolBuffers {
public interface IEnumLiteMap {
bool IsValidValue(IEnumLite value);
}
public class EnumLiteMap<TEnum> : IEnumLiteMap<IEnumLite>
where TEnum : struct, IComparable, IFormattable, IConvertible {
struct EnumValue : IEnumLite, IComparable<IEnumLite> {
int _value;
public EnumValue(int value) {
_value = value;
}
int IEnumLite.Number {
get { return _value; }
}
int IComparable<IEnumLite>.CompareTo(IEnumLite other) {
return _value.CompareTo(other.Number);
}
}
private readonly SortedList<int, IEnumLite> items;
public EnumLiteMap() {
items = new SortedList<int, IEnumLite>();
foreach (TEnum evalue in Enum.GetValues(typeof(TEnum)))
items.Add(evalue.ToInt32(CultureInfo.InvariantCulture), new EnumValue(evalue.ToInt32(CultureInfo.InvariantCulture)));
}
IEnumLite IEnumLiteMap<IEnumLite>.FindValueByNumber(int number) {
IEnumLite val;
return items.TryGetValue(number, out val) ? val : null;
}
bool IEnumLiteMap.IsValidValue(IEnumLite value) {
return items.ContainsKey(value.Number);
}
}
}

@ -0,0 +1,172 @@
#region Copyright notice and license
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// http://github.com/jskeet/dotnet-protobufs/
// Original C++/Java/Python code:
// http://code.google.com/p/protobuf/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion
using System;
using System.Collections.Generic;
namespace Google.ProtocolBuffers {
public abstract class ExtendableBuilderLite<TMessage, TBuilder> : GeneratedBuilderLite<TMessage, TBuilder>
where TMessage : ExtendableMessageLite<TMessage, TBuilder>
where TBuilder : GeneratedBuilderLite<TMessage, TBuilder> {
protected ExtendableBuilderLite() { }
/// <summary>
/// Checks if a singular extension is present
/// </summary>
public bool HasExtension<TExtension>(GeneratedExtensionLite<TMessage, TExtension> extension) {
return MessageBeingBuilt.HasExtension(extension);
}
/// <summary>
/// Returns the number of elements in a repeated extension.
/// </summary>
public int GetExtensionCount<TExtension>(GeneratedExtensionLite<TMessage, IList<TExtension>> extension) {
return MessageBeingBuilt.GetExtensionCount(extension);
}
/// <summary>
/// Returns the value of an extension.
/// </summary>
public TExtension GetExtension<TExtension>(GeneratedExtensionLite<TMessage, TExtension> extension) {
return MessageBeingBuilt.GetExtension(extension);
}
/// <summary>
/// Returns one element of a repeated extension.
/// </summary>
public TExtension GetExtension<TExtension>(GeneratedExtensionLite<TMessage, IList<TExtension>> extension, int index) {
return MessageBeingBuilt.GetExtension(extension, index);
}
/// <summary>
/// Sets the value of an extension.
/// </summary>
public TBuilder SetExtension<TExtension>(GeneratedExtensionLite<TMessage, TExtension> extension, TExtension value) {
ExtendableMessageLite<TMessage, TBuilder> message = MessageBeingBuilt;
message.VerifyExtensionContainingType(extension);
message.Extensions[extension.Descriptor] = (value);
return ThisBuilder;
}
/// <summary>
/// Sets the value of one element of a repeated extension.
/// </summary>
public TBuilder SetExtension<TExtension>(GeneratedExtensionLite<TMessage, IList<TExtension>> extension, int index, TExtension value) {
ExtendableMessageLite<TMessage, TBuilder> message = MessageBeingBuilt;
message.VerifyExtensionContainingType(extension);
message.Extensions[extension.Descriptor, index] = (value);
return ThisBuilder;
}
/// <summary>
/// Appends a value to a repeated extension.
/// </summary>
public ExtendableBuilderLite<TMessage, TBuilder> AddExtension<TExtension>(GeneratedExtensionLite<TMessage, IList<TExtension>> extension, TExtension value) {
ExtendableMessageLite<TMessage, TBuilder> message = MessageBeingBuilt;
message.VerifyExtensionContainingType(extension);
message.Extensions.AddRepeatedField(extension.Descriptor, (value));
return this;
}
/// <summary>
/// Clears an extension.
/// </summary>
public ExtendableBuilderLite<TMessage, TBuilder> ClearExtension<TExtension>(GeneratedExtensionLite<TMessage, TExtension> extension) {
ExtendableMessageLite<TMessage, TBuilder> message = MessageBeingBuilt;
message.VerifyExtensionContainingType(extension);
message.Extensions.ClearField(extension.Descriptor);
return this;
}
/// <summary>
/// Called by subclasses to parse an unknown field or an extension.
/// </summary>
/// <returns>true unless the tag is an end-group tag</returns>
[CLSCompliant(false)]
protected override bool ParseUnknownField(CodedInputStream input,
ExtensionRegistry extensionRegistry, uint tag) {
return input.SkipField(tag);
}
// ---------------------------------------------------------------
// Reflection
public object this[IFieldDescriptorLite field, int index] {
set {
if (field.IsExtension) {
ExtendableMessageLite<TMessage, TBuilder> message = MessageBeingBuilt;
message.Extensions[field, index] = value;
} else {
throw new NotSupportedException("Not supported in the lite runtime.");
}
}
}
public object this[IFieldDescriptorLite field] {
set {
if (field.IsExtension) {
ExtendableMessageLite<TMessage, TBuilder> message = MessageBeingBuilt;
message.Extensions[field] = value;
} else {
throw new NotSupportedException("Not supported in the lite runtime.");
}
}
}
public TBuilder ClearField(IFieldDescriptorLite field) {
if (field.IsExtension) {
ExtendableMessageLite<TMessage, TBuilder> message = MessageBeingBuilt;
message.Extensions.ClearField(field);
return ThisBuilder;
} else {
throw new NotSupportedException("Not supported in the lite runtime.");
}
}
public TBuilder AddRepeatedField(IFieldDescriptorLite field, object value) {
if (field.IsExtension) {
ExtendableMessageLite<TMessage, TBuilder> message = MessageBeingBuilt;
message.Extensions.AddRepeatedField(field, value);
return ThisBuilder;
} else {
throw new NotSupportedException("Not supported in the lite runtime.");
}
}
protected void MergeExtensionFields(ExtendableMessageLite<TMessage, TBuilder> other) {
MessageBeingBuilt.Extensions.MergeFrom(other.Extensions);
}
}
}

@ -0,0 +1,156 @@
#region Copyright notice and license
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// http://github.com/jskeet/dotnet-protobufs/
// Original C++/Java/Python code:
// http://code.google.com/p/protobuf/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion
using System;
using System.Collections.Generic;
namespace Google.ProtocolBuffers {
public abstract class ExtendableMessageLite<TMessage, TBuilder> : GeneratedMessageLite<TMessage, TBuilder>
where TMessage : GeneratedMessageLite<TMessage, TBuilder>
where TBuilder : GeneratedBuilderLite<TMessage, TBuilder> {
protected ExtendableMessageLite() { }
private readonly FieldSet extensions = FieldSet.CreateInstance();
/// <summary>
/// Access for the builder.
/// </summary>
internal FieldSet Extensions {
get { return extensions; }
}
/// <summary>
/// Checks if a singular extension is present.
/// </summary>
public bool HasExtension<TExtension>(GeneratedExtensionLite<TMessage, TExtension> extension) {
VerifyExtensionContainingType(extension);
return extensions.HasField(extension.Descriptor);
}
/// <summary>
/// Returns the number of elements in a repeated extension.
/// </summary>
public int GetExtensionCount<TExtension>(GeneratedExtensionLite<TMessage, IList<TExtension>> extension) {
VerifyExtensionContainingType(extension);
return extensions.GetRepeatedFieldCount(extension.Descriptor);
}
/// <summary>
/// Returns the value of an extension.
/// </summary>
public TExtension GetExtension<TExtension>(GeneratedExtensionLite<TMessage, TExtension> extension) {
VerifyExtensionContainingType(extension);
object value = extensions[extension.Descriptor];
if (value == null) {
return extension.DefaultValue;
} else {
return (TExtension)value;
}
}
/// <summary>
/// Returns one element of a repeated extension.
/// </summary>
public TExtension GetExtension<TExtension>(GeneratedExtensionLite<TMessage, IList<TExtension>> extension, int index) {
VerifyExtensionContainingType(extension);
return (TExtension)extensions[extension.Descriptor, index];
}
/// <summary>
/// Called to check if all extensions are initialized.
/// </summary>
protected bool ExtensionsAreInitialized {
get { return extensions.IsInitialized; }
}
public override bool IsInitialized {
get {
return ExtensionsAreInitialized;
}
}
/// <summary>
/// Used by subclasses to serialize extensions. Extension ranges may be
/// interleaves with field numbers, but we must write them in canonical
/// (sorted by field number) order. This class helps us to write individual
/// ranges of extensions at once.
///
/// TODO(jonskeet): See if we can improve this in terms of readability.
/// </summary>
protected class ExtensionWriter {
readonly IEnumerator<KeyValuePair<IFieldDescriptorLite, object>> iterator;
readonly FieldSet extensions;
KeyValuePair<IFieldDescriptorLite, object>? next = null;
internal ExtensionWriter(ExtendableMessageLite<TMessage, TBuilder> message) {
extensions = message.extensions;
iterator = message.extensions.GetEnumerator();
if (iterator.MoveNext()) {
next = iterator.Current;
}
}
public void WriteUntil(int end, CodedOutputStream output) {
while (next != null && next.Value.Key.FieldNumber < end) {
extensions.WriteField(next.Value.Key, next.Value.Value, output);
if (iterator.MoveNext()) {
next = iterator.Current;
} else {
next = null;
}
}
}
}
protected ExtensionWriter CreateExtensionWriter(ExtendableMessageLite<TMessage, TBuilder> message) {
return new ExtensionWriter(message);
}
/// <summary>
/// Called by subclasses to compute the size of extensions.
/// </summary>
protected int ExtensionsSerializedSize {
get { return extensions.SerializedSize; }
}
internal void VerifyExtensionContainingType<TExtension>(GeneratedExtensionLite<TMessage, TExtension> extension) {
if (!ReferenceEquals(extension.ContainingTypeDefaultInstance, DefaultInstanceForType)) {
// This can only happen if someone uses unchecked operations.
throw new ArgumentException(
String.Format("Extension is for type \"{0}\" which does not match message type \"{1}\".",
extension.ContainingTypeDefaultInstance, DefaultInstanceForType
));
}
}
}
}

@ -0,0 +1,117 @@
#region Copyright notice and license
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// http://github.com/jskeet/dotnet-protobufs/
// Original C++/Java/Python code:
// http://code.google.com/p/protobuf/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion
using System;
using System.Collections;
using System.Collections.Generic;
namespace Google.ProtocolBuffers {
/// <summary>
/// All generated protocol message builder classes extend this class. It implements
/// most of the IBuilder interface using reflection. Users can ignore this class
/// as an implementation detail.
/// </summary>
public abstract class GeneratedBuilderLite<TMessage, TBuilder> : AbstractBuilderLite<TMessage, TBuilder>
where TMessage : GeneratedMessageLite<TMessage, TBuilder>
where TBuilder : GeneratedBuilderLite<TMessage, TBuilder> {
/// <summary>
/// Returns the message being built at the moment.
/// </summary>
protected abstract TMessage MessageBeingBuilt { get; }
public override TBuilder MergeFrom(IMessageLite other) {
//do nothing, Lite runtime does not support cross-message merges
return ThisBuilder;
}
public abstract TBuilder MergeFrom(TMessage other);
public override bool IsInitialized {
get { return MessageBeingBuilt.IsInitialized; }
}
/// <summary>
/// Adds all of the specified values to the given collection.
/// </summary>
/// <exception cref="ArgumentNullException">Any element of the list is null</exception>
protected void AddRange<T>(IEnumerable<T> source, IList<T> destination) {
ThrowHelper.ThrowIfNull(source);
// We only need to check this for nullable types.
if (default(T) == null) {
ThrowHelper.ThrowIfAnyNull(source);
}
List<T> list = destination as List<T>;
if (list != null) {
list.AddRange(source);
} else {
foreach (T element in source) {
destination.Add(element);
}
}
}
/// <summary>
/// Called by derived classes to parse an unknown field.
/// </summary>
/// <returns>true unless the tag is an end-group tag</returns>
[CLSCompliant(false)]
protected virtual bool ParseUnknownField(CodedInputStream input,
ExtensionRegistry extensionRegistry, uint tag) {
return input.SkipField(tag);
}
/// <summary>
/// Like Build(), but will wrap UninitializedMessageException in
/// InvalidProtocolBufferException.
/// </summary>
public TMessage BuildParsed() {
if (!IsInitialized) {
throw new UninitializedMessageException(MessageBeingBuilt).AsInvalidProtocolBufferException();
}
return BuildPartial();
}
/// <summary>
/// Implementation of <see cref="IBuilder{TMessage, TBuilder}.Build" />.
/// </summary>
public override TMessage Build() {
// If the message is null, we'll throw a more appropriate exception in BuildPartial.
if (MessageBeingBuilt != null && !IsInitialized) {
throw new UninitializedMessageException(MessageBeingBuilt);
}
return BuildPartial();
}
}
}

@ -1,4 +1,40 @@
using System;
#region Copyright notice and license
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// http://github.com/jskeet/dotnet-protobufs/
// Original C++/Java/Python code:
// http://code.google.com/p/protobuf/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion
using System;
using System.Collections.Generic;
using Google.ProtocolBuffers.Collections;
using Google.ProtocolBuffers.Descriptors;
namespace Google.ProtocolBuffers {
@ -9,28 +45,87 @@ namespace Google.ProtocolBuffers {
IMessageLite MessageDefaultInstance { get; }
}
public class ExtensionDescriptorLite {
private readonly EnumLiteMap enumTypeMap;
public class ExtensionDescriptorLite : IFieldDescriptorLite {
/// <summary>
/// Immutable mapping from field type to mapped type. Built using the attributes on
/// FieldType values.
/// </summary>
public static readonly IDictionary<FieldType, MappedType> FieldTypeToMappedTypeMap = MapFieldTypes();
private static IDictionary<FieldType, MappedType> MapFieldTypes() {
var map = new Dictionary<FieldType, MappedType>();
foreach (System.Reflection.FieldInfo field in typeof(FieldType).GetFields(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public)) {
FieldType fieldType = (FieldType)field.GetValue(null);
FieldMappingAttribute mapping = (FieldMappingAttribute)field.GetCustomAttributes(typeof(FieldMappingAttribute), false)[0];
map[fieldType] = mapping.MappedType;
}
return Dictionaries.AsReadOnly(map);
}
private readonly IEnumLiteMap enumTypeMap;
private readonly int number;
private readonly FieldType type;
private readonly bool isRepeated;
private readonly bool isPacked;
private readonly MappedType mapType;
private readonly object defaultValue;
public ExtensionDescriptorLite(EnumLiteMap enumTypeMap, int number, FieldType type, bool isRepeated, bool isPacked) {
public ExtensionDescriptorLite(IEnumLiteMap enumTypeMap, int number, FieldType type, object defaultValue, bool isRepeated, bool isPacked) {
this.enumTypeMap = enumTypeMap;
this.number = number;
this.type = type;
this.mapType = FieldTypeToMappedTypeMap[type];
this.isRepeated = isRepeated;
this.isPacked = isPacked;
this.defaultValue = defaultValue;
}
public int Number {
public bool IsRepeated {
get { return isRepeated; }
}
public bool IsRequired {
get { return false; }
}
public bool IsPacked {
get { return isPacked; }
}
public bool IsExtension {
get { return true; }
}
#warning ToDo - Discover the meaning and purpose of this durring serialization and return the correct value
public bool MessageSetWireFormat {
get { return true; }
}
public int FieldNumber {
get { return number; }
}
public IEnumLiteMap EnumType {
get { return enumTypeMap; }
}
public FieldType FieldType {
get { return type; }
}
public MappedType MappedType {
get { return mapType; }
}
public object DefaultValue {
get { return defaultValue; }
}
public int CompareTo(IFieldDescriptorLite other) {
return FieldNumber.CompareTo(other.FieldNumber);
}
}
public class EnumLiteMap { }
public class GeneratedExtensionLite<TContainingType, TExtensionType> : IGeneratedExtensionLite
where TContainingType : IMessageLite {
@ -62,11 +157,11 @@ namespace Google.ProtocolBuffers {
TContainingType containingTypeDefaultInstance,
TExtensionType defaultValue,
IMessageLite messageDefaultInstance,
EnumLiteMap enumTypeMap,
IEnumLiteMap enumTypeMap,
int number,
FieldType type)
: this(containingTypeDefaultInstance, defaultValue, messageDefaultInstance,
new ExtensionDescriptorLite(enumTypeMap, number, type,
new ExtensionDescriptorLite(enumTypeMap, number, type, defaultValue,
false /* isRepeated */, false /* isPacked */)) {
}
@ -75,15 +170,29 @@ namespace Google.ProtocolBuffers {
TContainingType containingTypeDefaultInstance,
TExtensionType defaultValue,
IMessageLite messageDefaultInstance,
EnumLiteMap enumTypeMap,
IEnumLiteMap enumTypeMap,
int number,
FieldType type,
bool isPacked)
: this(containingTypeDefaultInstance, defaultValue, messageDefaultInstance,
new ExtensionDescriptorLite(enumTypeMap, number, type,
new ExtensionDescriptorLite(enumTypeMap, number, type, defaultValue,
true /* isRepeated */, isPacked)) {
}
/// <summary>
/// Returns information about this extension
/// </summary>
public IFieldDescriptorLite Descriptor {
get { return descriptor; }
}
/// <summary>
/// Returns the default value for this extension
/// </summary>
public TExtensionType DefaultValue {
get { return defaultValue; }
}
/// <summary>
/// used for the extension registry
/// </summary>
@ -102,7 +211,7 @@ namespace Google.ProtocolBuffers {
/** Get the field number. */
public int Number {
get {
return descriptor.Number;
return descriptor.FieldNumber;
}
}
/**
@ -114,5 +223,9 @@ namespace Google.ProtocolBuffers {
return messageDefaultInstance;
}
}
public object SingularFromReflectionType(object value) {
return value;
}
}
}

@ -0,0 +1,52 @@
#region Copyright notice and license
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// http://github.com/jskeet/dotnet-protobufs/
// Original C++/Java/Python code:
// http://code.google.com/p/protobuf/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion
using System;
using System.Collections.Generic;
using System.Collections;
namespace Google.ProtocolBuffers {
/// <summary>
/// All generated protocol message classes extend this class. It implements
/// most of the IMessage interface using reflection. Users
/// can ignore this class as an implementation detail.
/// </summary>
public abstract class GeneratedMessageLite<TMessage, TBuilder> : AbstractMessageLite<TMessage, TBuilder>
where TMessage : GeneratedMessageLite<TMessage, TBuilder>
where TBuilder : GeneratedBuilderLite<TMessage, TBuilder> {
protected abstract TMessage ThisMessage { get; }
}
}

@ -92,7 +92,9 @@
<Compile Include="DynamicMessage.cs" />
<Compile Include="EnumLite.cs" />
<Compile Include="ExtendableBuilder.cs" />
<Compile Include="ExtendableBuilderLite.cs" />
<Compile Include="ExtendableMessage.cs" />
<Compile Include="ExtendableMessageLite.cs" />
<Compile Include="ExtensionInfo.cs">
<SubType>Code</SubType>
</Compile>
@ -109,7 +111,9 @@
<Compile Include="FieldAccess\RepeatedMessageAccessor.cs" />
<Compile Include="FieldSet.cs" />
<Compile Include="GeneratedBuilder.cs" />
<Compile Include="GeneratedBuilderLite.cs" />
<Compile Include="GeneratedExtensionLite.cs" />
<Compile Include="GeneratedMessageLite.cs" />
<Compile Include="GeneratedRepeatExtension.cs" />
<Compile Include="GeneratedSingleExtension.cs" />
<Compile Include="GeneratedMessage.cs" />

@ -58,11 +58,16 @@
<Compile Include="AbstractBuilderLite.cs" />
<Compile Include="AbstractMessageLite.cs" />
<Compile Include="Collections\Dictionaries.cs" />
<Compile Include="Collections\Enumerables.cs" />
<Compile Include="Collections\IPopsicleList.cs" />
<Compile Include="Collections\Lists.cs" />
<Compile Include="Collections\PopsicleList.cs" />
<Compile Include="Collections\ReadOnlyDictionary.cs" />
<Compile Include="Descriptors\FieldMappingAttribute.cs" />
<Compile Include="Descriptors\FieldType.cs" />
<Compile Include="Descriptors\MappedType.cs" />
<Compile Include="EnumLite.cs" />
<Compile Include="ExtendableBuilderLite.cs" />
<Compile Include="ExtendableMessageLite.cs" />
<Compile Include="FieldSet.cs" />
<Compile Include="GeneratedBuilderLite.cs" />

@ -53,8 +53,6 @@ namespace Google.ProtocolBuffers {
: base(BuildDescription(missingFields)) {
this.missingFields = new List<string>(missingFields);
}
/// <summary>
/// Returns a read-only list of human-readable names of
/// required fields missing from this message. Each name
@ -90,6 +88,14 @@ namespace Google.ProtocolBuffers {
return description.ToString();
}
/// <summary>
/// For Lite exceptions that do not known how to enumerate missing fields
/// </summary>
public UninitializedMessageException(IMessageLite message)
: base(String.Format("Message {0} is missing required fields", message.GetType())) {
missingFields = new List<string>();
}
#if !LITE
public UninitializedMessageException(IMessage message)
: this(FindMissingFields(message)) {

@ -54,15 +54,11 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\tmp\UnitTestLiteProtoFile.cs">
<Link>UnitTestLiteProtoFile.cs</Link>
</Compile>
<Compile Include="..\ProtocolBuffers.Test\Properties\AssemblyInfo.cs">
<Link>Properties\AssemblyInfo.cs</Link>
</Compile>
<Compile Include="Todo.cs" />
<None Include="TestProtos\UnittestLite.cs" />
<None Include="TestProtos\UnittestLiteImportsNonlite.cs" />
<Compile Include="TestProtos\UnitTestImportLiteProtoFile.cs" />
<Compile Include="TestProtos\UnitTestLiteProtoFile.cs" />
</ItemGroup>
<ItemGroup>
<None Include="..\ProtocolBuffers.Test\Properties\Google.ProtocolBuffers.Test.snk">

@ -0,0 +1,227 @@
// Generated by ProtoGen, Version=0.9.0.0, Culture=neutral, PublicKeyToken=8fd7408b07f8d2cd. DO NOT EDIT!
using pb = global::Google.ProtocolBuffers;
using pbc = global::Google.ProtocolBuffers.Collections;
using pbd = global::Google.ProtocolBuffers.Descriptors;
using scg = global::System.Collections.Generic;
namespace Google.ProtocolBuffers.TestProtos {
public static partial class UnitTestImportLiteProtoFile {
#region Extension registration
public static void RegisterAllExtensions(pb::ExtensionRegistry registry) {
}
#endregion
#region Static variables
#endregion
#region Extensions
internal static readonly object Descriptor;
static UnitTestImportLiteProtoFile() {
Descriptor = null;
}
#endregion
}
#region Enums
public enum ImportEnumLite {
IMPORT_LITE_FOO = 7,
IMPORT_LITE_BAR = 8,
IMPORT_LITE_BAZ = 9,
}
#endregion
#region Messages
public sealed partial class ImportMessageLite : pb::GeneratedMessageLite<ImportMessageLite, ImportMessageLite.Builder> {
private static readonly ImportMessageLite defaultInstance = new Builder().BuildPartial();
public static ImportMessageLite DefaultInstance {
get { return defaultInstance; }
}
public override ImportMessageLite DefaultInstanceForType {
get { return defaultInstance; }
}
protected override ImportMessageLite ThisMessage {
get { return this; }
}
public const int DFieldNumber = 1;
private bool hasD;
private int d_ = 0;
public bool HasD {
get { return hasD; }
}
public int D {
get { return d_; }
}
public override bool IsInitialized {
get {
return true;
}
}
public override void WriteTo(pb::CodedOutputStream output) {
int size = SerializedSize;
if (HasD) {
output.WriteInt32(1, D);
}
}
private int memoizedSerializedSize = -1;
public override int SerializedSize {
get {
int size = memoizedSerializedSize;
if (size != -1) return size;
size = 0;
if (HasD) {
size += pb::CodedOutputStream.ComputeInt32Size(1, D);
}
memoizedSerializedSize = size;
return size;
}
}
public static ImportMessageLite ParseFrom(pb::ByteString data) {
return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
}
public static ImportMessageLite ParseFrom(pb::ByteString data, pb::ExtensionRegistry extensionRegistry) {
return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
}
public static ImportMessageLite ParseFrom(byte[] data) {
return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
}
public static ImportMessageLite ParseFrom(byte[] data, pb::ExtensionRegistry extensionRegistry) {
return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
}
public static ImportMessageLite ParseFrom(global::System.IO.Stream input) {
return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
}
public static ImportMessageLite ParseFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static ImportMessageLite ParseDelimitedFrom(global::System.IO.Stream input) {
return CreateBuilder().MergeDelimitedFrom(input).BuildParsed();
}
public static ImportMessageLite ParseDelimitedFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
return CreateBuilder().MergeDelimitedFrom(input, extensionRegistry).BuildParsed();
}
public static ImportMessageLite ParseFrom(pb::CodedInputStream input) {
return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
}
public static ImportMessageLite ParseFrom(pb::CodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
}
public static Builder CreateBuilder() { return new Builder(); }
public override Builder ToBuilder() { return CreateBuilder(this); }
public override Builder CreateBuilderForType() { return new Builder(); }
public static Builder CreateBuilder(ImportMessageLite prototype) {
return (Builder) new Builder().MergeFrom(prototype);
}
public sealed partial class Builder : pb::GeneratedBuilderLite<ImportMessageLite, Builder> {
protected override Builder ThisBuilder {
get { return this; }
}
public Builder() {}
ImportMessageLite result = new ImportMessageLite();
protected override ImportMessageLite MessageBeingBuilt {
get { return result; }
}
public override Builder Clear() {
result = new ImportMessageLite();
return this;
}
public override Builder Clone() {
return new Builder().MergeFrom(result);
}
public override ImportMessageLite DefaultInstanceForType {
get { return global::Google.ProtocolBuffers.TestProtos.ImportMessageLite.DefaultInstance; }
}
public override ImportMessageLite BuildPartial() {
if (result == null) {
throw new global::System.InvalidOperationException("build() has already been called on this Builder");
}
ImportMessageLite returnMe = result;
result = null;
return returnMe;
}
public override Builder MergeFrom(pb::IMessageLite other) {
if (other is ImportMessageLite) {
return MergeFrom((ImportMessageLite) other);
} else {
base.MergeFrom(other);
return this;
}
}
public override Builder MergeFrom(ImportMessageLite other) {
if (other == global::Google.ProtocolBuffers.TestProtos.ImportMessageLite.DefaultInstance) return this;
if (other.HasD) {
D = other.D;
}
return this;
}
public override Builder MergeFrom(pb::CodedInputStream input) {
return MergeFrom(input, pb::ExtensionRegistry.Empty);
}
public override Builder MergeFrom(pb::CodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
while (true) {
uint tag = input.ReadTag();
switch (tag) {
case 0: {
return this;
}
default: {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return this;
}
ParseUnknownField(input, extensionRegistry, tag);
break;
}
case 8: {
D = input.ReadInt32();
break;
}
}
}
}
public bool HasD {
get { return result.HasD; }
}
public int D {
get { return result.D; }
set { SetD(value); }
}
public Builder SetD(int value) {
result.hasD = true;
result.d_ = value;
return this;
}
public Builder ClearD() {
result.hasD = false;
result.d_ = 0;
return this;
}
}
static ImportMessageLite() {
object.ReferenceEquals(global::Google.ProtocolBuffers.TestProtos.UnitTestImportLiteProtoFile.Descriptor, null);
}
}
#endregion
}

@ -1,4 +1,4 @@
// Generated by the protocol buffer compiler. DO NOT EDIT!
// Generated by ProtoGen, Version=0.9.0.0, Culture=neutral, PublicKeyToken=8fd7408b07f8d2cd. DO NOT EDIT!
using pb = global::Google.ProtocolBuffers;
using pbc = global::Google.ProtocolBuffers.Collections;
@ -13,47 +13,17 @@ namespace Google.ProtocolBuffers.TestProtos {
}
#endregion
#region Static variables
internal static pbd::MessageDescriptor internal__static_protobuf_unittest_TestLiteImportsNonlite__Descriptor;
internal static pb::FieldAccess.FieldAccessorTable<global::Google.ProtocolBuffers.TestProtos.TestLiteImportsNonlite, global::Google.ProtocolBuffers.TestProtos.TestLiteImportsNonlite.Builder> internal__static_protobuf_unittest_TestLiteImportsNonlite__FieldAccessorTable;
#endregion
#region Descriptor
public static pbd::FileDescriptor Descriptor {
get { return descriptor; }
}
private static pbd::FileDescriptor descriptor;
#region Extensions
internal static readonly object Descriptor;
static UnitTestLiteImportNonLiteProtoFile() {
byte[] descriptorData = global::System.Convert.FromBase64String(
"CjNnb29nbGUvcHJvdG9idWYvdW5pdHRlc3RfbGl0ZV9pbXBvcnRzX25vbmxp" +
"dGUucHJvdG8SEXByb3RvYnVmX3VuaXR0ZXN0GiRnb29nbGUvcHJvdG9idWYv" +
"Y3NoYXJwX29wdGlvbnMucHJvdG8aHmdvb2dsZS9wcm90b2J1Zi91bml0dGVz" +
"dC5wcm90byJKChZUZXN0TGl0ZUltcG9ydHNOb25saXRlEjAKB21lc3NhZ2UY" +
"ASABKAsyHy5wcm90b2J1Zl91bml0dGVzdC5UZXN0QWxsVHlwZXNCTEgDwj5H" +
"CiFHb29nbGUuUHJvdG9jb2xCdWZmZXJzLlRlc3RQcm90b3MSIlVuaXRUZXN0" +
"TGl0ZUltcG9ydE5vbkxpdGVQcm90b0ZpbGU=");
pbd::FileDescriptor.InternalDescriptorAssigner assigner = delegate(pbd::FileDescriptor root) {
descriptor = root;
internal__static_protobuf_unittest_TestLiteImportsNonlite__Descriptor = Descriptor.MessageTypes[0];
internal__static_protobuf_unittest_TestLiteImportsNonlite__FieldAccessorTable =
new pb::FieldAccess.FieldAccessorTable<global::Google.ProtocolBuffers.TestProtos.TestLiteImportsNonlite, global::Google.ProtocolBuffers.TestProtos.TestLiteImportsNonlite.Builder>(internal__static_protobuf_unittest_TestLiteImportsNonlite__Descriptor,
new string[] { "Message", });
pb::ExtensionRegistry registry = pb::ExtensionRegistry.CreateInstance();
RegisterAllExtensions(registry);
global::Google.ProtocolBuffers.DescriptorProtos.CSharpOptions.RegisterAllExtensions(registry);
global::Google.ProtocolBuffers.TestProtos.UnitTestProtoFile.RegisterAllExtensions(registry);
return registry;
};
pbd::FileDescriptor.InternalBuildGeneratedFileFrom(descriptorData,
new pbd::FileDescriptor[] {
global::Google.ProtocolBuffers.DescriptorProtos.CSharpOptions.Descriptor,
global::Google.ProtocolBuffers.TestProtos.UnitTestProtoFile.Descriptor,
}, assigner);
Descriptor = null;
}
#endregion
}
#region Messages
public sealed partial class TestLiteImportsNonlite : pb::GeneratedMessage<TestLiteImportsNonlite, TestLiteImportsNonlite.Builder> {
public sealed partial class TestLiteImportsNonlite : pb::GeneratedMessageLite<TestLiteImportsNonlite, TestLiteImportsNonlite.Builder> {
private static readonly TestLiteImportsNonlite defaultInstance = new Builder().BuildPartial();
public static TestLiteImportsNonlite DefaultInstance {
get { return defaultInstance; }
@ -67,14 +37,6 @@ namespace Google.ProtocolBuffers.TestProtos {
get { return this; }
}
public static pbd::MessageDescriptor Descriptor {
get { return global::Google.ProtocolBuffers.TestProtos.UnitTestLiteImportNonLiteProtoFile.internal__static_protobuf_unittest_TestLiteImportsNonlite__Descriptor; }
}
protected override pb::FieldAccess.FieldAccessorTable<TestLiteImportsNonlite, TestLiteImportsNonlite.Builder> InternalFieldAccessors {
get { return global::Google.ProtocolBuffers.TestProtos.UnitTestLiteImportNonLiteProtoFile.internal__static_protobuf_unittest_TestLiteImportsNonlite__FieldAccessorTable; }
}
public const int MessageFieldNumber = 1;
private bool hasMessage;
private global::Google.ProtocolBuffers.TestProtos.TestAllTypes message_ = global::Google.ProtocolBuffers.TestProtos.TestAllTypes.DefaultInstance;
@ -85,6 +47,34 @@ namespace Google.ProtocolBuffers.TestProtos {
get { return message_; }
}
public override bool IsInitialized {
get {
return true;
}
}
public override void WriteTo(pb::CodedOutputStream output) {
int size = SerializedSize;
if (HasMessage) {
output.WriteMessage(1, Message);
}
}
private int memoizedSerializedSize = -1;
public override int SerializedSize {
get {
int size = memoizedSerializedSize;
if (size != -1) return size;
size = 0;
if (HasMessage) {
size += pb::CodedOutputStream.ComputeMessageSize(1, Message);
}
memoizedSerializedSize = size;
return size;
}
}
public static TestLiteImportsNonlite ParseFrom(pb::ByteString data) {
return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
}
@ -122,7 +112,7 @@ namespace Google.ProtocolBuffers.TestProtos {
return (Builder) new Builder().MergeFrom(prototype);
}
public sealed partial class Builder : pb::GeneratedBuilder<TestLiteImportsNonlite, Builder> {
public sealed partial class Builder : pb::GeneratedBuilderLite<TestLiteImportsNonlite, Builder> {
protected override Builder ThisBuilder {
get { return this; }
}
@ -143,10 +133,6 @@ namespace Google.ProtocolBuffers.TestProtos {
return new Builder().MergeFrom(result);
}
public override pbd::MessageDescriptor DescriptorForType {
get { return global::Google.ProtocolBuffers.TestProtos.TestLiteImportsNonlite.Descriptor; }
}
public override TestLiteImportsNonlite DefaultInstanceForType {
get { return global::Google.ProtocolBuffers.TestProtos.TestLiteImportsNonlite.DefaultInstance; }
}
@ -160,6 +146,54 @@ namespace Google.ProtocolBuffers.TestProtos {
return returnMe;
}
public override Builder MergeFrom(pb::IMessageLite other) {
if (other is TestLiteImportsNonlite) {
return MergeFrom((TestLiteImportsNonlite) other);
} else {
base.MergeFrom(other);
return this;
}
}
public override Builder MergeFrom(TestLiteImportsNonlite other) {
if (other == global::Google.ProtocolBuffers.TestProtos.TestLiteImportsNonlite.DefaultInstance) return this;
if (other.HasMessage) {
MergeMessage(other.Message);
}
return this;
}
public override Builder MergeFrom(pb::CodedInputStream input) {
return MergeFrom(input, pb::ExtensionRegistry.Empty);
}
public override Builder MergeFrom(pb::CodedInputStream input, pb::ExtensionRegistry extensionRegistry) {
while (true) {
uint tag = input.ReadTag();
switch (tag) {
case 0: {
return this;
}
default: {
if (pb::WireFormat.IsEndGroupTag(tag)) {
return this;
}
ParseUnknownField(input, extensionRegistry, tag);
break;
}
case 10: {
global::Google.ProtocolBuffers.TestProtos.TestAllTypes.Builder subBuilder = global::Google.ProtocolBuffers.TestProtos.TestAllTypes.CreateBuilder();
if (HasMessage) {
subBuilder.MergeFrom(Message);
}
input.ReadMessage(subBuilder, extensionRegistry);
Message = subBuilder.BuildPartial();
break;
}
}
}
}
public bool HasMessage {
get { return result.HasMessage; }

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save