From ec79ca13415cc921feb9151efa88e7691da45c1e Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Tue, 14 Dec 2010 20:41:54 +0000 Subject: [PATCH] Fixed build for lite runtime --- build/build.csproj | 46 ++++-- .../TestProtos/UnitTestImportLiteProtoFile.cs | 142 ++++++++++++------ src/ProtocolBuffers.sln | 16 +- src/ProtocolBuffers/EnumLite.cs | 10 ++ src/ProtocolBuffers/ProtocolBuffers.csproj | 19 ++- .../ProtocolBuffersLite.Test.csproj | 21 --- .../ProtocolBuffersLiteMixed.Test.csproj | 21 --- src/ProtocolBuffersLite.Test/TestLiteByApi.cs | 3 - 8 files changed, 157 insertions(+), 121 deletions(-) diff --git a/build/build.csproj b/build/build.csproj index 7bc65894f2..c3b0ed2709 100644 --- a/build/build.csproj +++ b/build/build.csproj @@ -31,35 +31,36 @@ + + - + + + + + - + + $(SourceDirectory)\ProtocolBuffers\DescriptorProtos $(SourceDirectory)\ProtocolBuffers\DescriptorProtos - - $(SourceDirectory)\ProtocolBuffers.Test\TestProtos - - - $(SourceDirectory)\ProtocolBuffers.Test\TestProtos - - - $(SourceDirectory)\ProtocolBuffers.Test\TestProtos - + + $(SourceDirectory)\AddressBook + $(SourceDirectory)\ProtocolBuffers.Test\TestProtos @@ -69,14 +70,35 @@ $(SourceDirectory)\ProtocolBuffers.Test\TestProtos + + $(SourceDirectory)\ProtocolBuffers.Test\TestProtos + + + $(SourceDirectory)\ProtocolBuffers.Test\TestProtos + $(SourceDirectory)\ProtocolBuffers.Test\TestProtos - + + $(SourceDirectory)\ProtocolBuffers.Test\TestProtos + + + $(SourceDirectory)\ProtocolBuffers.Test\TestProtos + + + $(SourceDirectory)\ProtocolBuffers.Test\TestProtos + + + $(SourceDirectory)\ProtocolBuffers.Test\TestProtos + + + + + diff --git a/src/ProtocolBuffers.Test/TestProtos/UnitTestImportLiteProtoFile.cs b/src/ProtocolBuffers.Test/TestProtos/UnitTestImportLiteProtoFile.cs index a98fb9247e..498d686aa1 100644 --- a/src/ProtocolBuffers.Test/TestProtos/UnitTestImportLiteProtoFile.cs +++ b/src/ProtocolBuffers.Test/TestProtos/UnitTestImportLiteProtoFile.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; @@ -13,39 +13,11 @@ namespace Google.ProtocolBuffers.TestProtos { } #endregion #region Static variables - internal static pbd::MessageDescriptor internal__static_protobuf_unittest_import_ImportMessageLite__Descriptor; - internal static pb::FieldAccess.FieldAccessorTable internal__static_protobuf_unittest_import_ImportMessageLite__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 UnitTestImportLiteProtoFile() { - byte[] descriptorData = global::System.Convert.FromBase64String( - "Cipnb29nbGUvcHJvdG9idWYvdW5pdHRlc3RfaW1wb3J0X2xpdGUucHJvdG8S" + - "GHByb3RvYnVmX3VuaXR0ZXN0X2ltcG9ydBokZ29vZ2xlL3Byb3RvYnVmL2Nz" + - "aGFycF9vcHRpb25zLnByb3RvIh4KEUltcG9ydE1lc3NhZ2VMaXRlEgkKAWQY" + - "ASABKAUqTwoOSW1wb3J0RW51bUxpdGUSEwoPSU1QT1JUX0xJVEVfRk9PEAcS" + - "EwoPSU1QT1JUX0xJVEVfQkFSEAgSEwoPSU1QT1JUX0xJVEVfQkFaEAlCWgoT" + - "Y29tLmdvb2dsZS5wcm90b2J1ZkgDwj5ACiFHb29nbGUuUHJvdG9jb2xCdWZm" + - "ZXJzLlRlc3RQcm90b3MSG1VuaXRUZXN0SW1wb3J0TGl0ZVByb3RvRmlsZQ=="); - pbd::FileDescriptor.InternalDescriptorAssigner assigner = delegate(pbd::FileDescriptor root) { - descriptor = root; - internal__static_protobuf_unittest_import_ImportMessageLite__Descriptor = Descriptor.MessageTypes[0]; - internal__static_protobuf_unittest_import_ImportMessageLite__FieldAccessorTable = - new pb::FieldAccess.FieldAccessorTable(internal__static_protobuf_unittest_import_ImportMessageLite__Descriptor, - new string[] { "D", }); - pb::ExtensionRegistry registry = pb::ExtensionRegistry.CreateInstance(); - RegisterAllExtensions(registry); - global::Google.ProtocolBuffers.DescriptorProtos.CSharpOptions.RegisterAllExtensions(registry); - return registry; - }; - pbd::FileDescriptor.InternalBuildGeneratedFileFrom(descriptorData, - new pbd::FileDescriptor[] { - global::Google.ProtocolBuffers.DescriptorProtos.CSharpOptions.Descriptor, - }, assigner); + Descriptor = null; } #endregion @@ -60,7 +32,7 @@ namespace Google.ProtocolBuffers.TestProtos { #endregion #region Messages - public sealed partial class ImportMessageLite : pb::GeneratedMessage { + public sealed partial class ImportMessageLite : pb::GeneratedMessageLite { private static readonly ImportMessageLite defaultInstance = new Builder().BuildPartial(); public static ImportMessageLite DefaultInstance { get { return defaultInstance; } @@ -74,14 +46,6 @@ namespace Google.ProtocolBuffers.TestProtos { get { return this; } } - public static pbd::MessageDescriptor Descriptor { - get { return global::Google.ProtocolBuffers.TestProtos.UnitTestImportLiteProtoFile.internal__static_protobuf_unittest_import_ImportMessageLite__Descriptor; } - } - - protected override pb::FieldAccess.FieldAccessorTable InternalFieldAccessors { - get { return global::Google.ProtocolBuffers.TestProtos.UnitTestImportLiteProtoFile.internal__static_protobuf_unittest_import_ImportMessageLite__FieldAccessorTable; } - } - public const int DFieldNumber = 1; private bool hasD; private int d_ = 0; @@ -92,6 +56,53 @@ namespace Google.ProtocolBuffers.TestProtos { 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; + } + } + + #region Lite runtime methods + public override int GetHashCode() { + int hash = GetType().GetHashCode(); + if (hasD) hash ^= d_.GetHashCode(); + return hash; + } + + public override bool Equals(object obj) { + ImportMessageLite other = obj as ImportMessageLite; + if (other == null) return false; + if (hasD != other.hasD || (hasD && !d_.Equals(other.d_))) return false; + return true; + } + + public override void PrintTo(global::System.IO.TextWriter writer) { + PrintField("d", hasD, d_, writer); + } + #endregion + public static ImportMessageLite ParseFrom(pb::ByteString data) { return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed(); } @@ -129,7 +140,7 @@ namespace Google.ProtocolBuffers.TestProtos { return (Builder) new Builder().MergeFrom(prototype); } - public sealed partial class Builder : pb::GeneratedBuilder { + public sealed partial class Builder : pb::GeneratedBuilderLite { protected override Builder ThisBuilder { get { return this; } } @@ -150,10 +161,6 @@ namespace Google.ProtocolBuffers.TestProtos { return new Builder().MergeFrom(result); } - public override pbd::MessageDescriptor DescriptorForType { - get { return global::Google.ProtocolBuffers.TestProtos.ImportMessageLite.Descriptor; } - } - public override ImportMessageLite DefaultInstanceForType { get { return global::Google.ProtocolBuffers.TestProtos.ImportMessageLite.DefaultInstance; } } @@ -167,6 +174,49 @@ namespace Google.ProtocolBuffers.TestProtos { 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; } diff --git a/src/ProtocolBuffers.sln b/src/ProtocolBuffers.sln index 365662a722..ff27dd5c2d 100644 --- a/src/ProtocolBuffers.sln +++ b/src/ProtocolBuffers.sln @@ -131,20 +131,20 @@ Global {6969BDCE-D925-43F3-94AC-A531E6DF2591}.Release_Silverlight2|Any CPU.Build.0 = Release_Silverlight2|Any CPU {6969BDCE-D925-43F3-94AC-A531E6DF2591}.Release|Any CPU.ActiveCfg = Release|Any CPU {6969BDCE-D925-43F3-94AC-A531E6DF2591}.Release|Any CPU.Build.0 = Release|Any CPU - {EE01ED24-3750-4567-9A23-1DB676A15610}.Debug_Silverlight2|Any CPU.ActiveCfg = Debug_Silverlight2|Any CPU - {EE01ED24-3750-4567-9A23-1DB676A15610}.Debug_Silverlight2|Any CPU.Build.0 = Debug_Silverlight2|Any CPU + {EE01ED24-3750-4567-9A23-1DB676A15610}.Debug_Silverlight2|Any CPU.ActiveCfg = Debug|Any CPU + {EE01ED24-3750-4567-9A23-1DB676A15610}.Debug_Silverlight2|Any CPU.Build.0 = Debug|Any CPU {EE01ED24-3750-4567-9A23-1DB676A15610}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {EE01ED24-3750-4567-9A23-1DB676A15610}.Debug|Any CPU.Build.0 = Debug|Any CPU - {EE01ED24-3750-4567-9A23-1DB676A15610}.Release_Silverlight2|Any CPU.ActiveCfg = Release_Silverlight2|Any CPU - {EE01ED24-3750-4567-9A23-1DB676A15610}.Release_Silverlight2|Any CPU.Build.0 = Release_Silverlight2|Any CPU + {EE01ED24-3750-4567-9A23-1DB676A15610}.Release_Silverlight2|Any CPU.ActiveCfg = Release|Any CPU + {EE01ED24-3750-4567-9A23-1DB676A15610}.Release_Silverlight2|Any CPU.Build.0 = Release|Any CPU {EE01ED24-3750-4567-9A23-1DB676A15610}.Release|Any CPU.ActiveCfg = Release|Any CPU {EE01ED24-3750-4567-9A23-1DB676A15610}.Release|Any CPU.Build.0 = Release|Any CPU - {EEFFED24-3750-4567-9A23-1DB676A15610}.Debug_Silverlight2|Any CPU.ActiveCfg = Debug_Silverlight2|Any CPU - {EEFFED24-3750-4567-9A23-1DB676A15610}.Debug_Silverlight2|Any CPU.Build.0 = Debug_Silverlight2|Any CPU + {EEFFED24-3750-4567-9A23-1DB676A15610}.Debug_Silverlight2|Any CPU.ActiveCfg = Debug|Any CPU + {EEFFED24-3750-4567-9A23-1DB676A15610}.Debug_Silverlight2|Any CPU.Build.0 = Debug|Any CPU {EEFFED24-3750-4567-9A23-1DB676A15610}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {EEFFED24-3750-4567-9A23-1DB676A15610}.Debug|Any CPU.Build.0 = Debug|Any CPU - {EEFFED24-3750-4567-9A23-1DB676A15610}.Release_Silverlight2|Any CPU.ActiveCfg = Release_Silverlight2|Any CPU - {EEFFED24-3750-4567-9A23-1DB676A15610}.Release_Silverlight2|Any CPU.Build.0 = Release_Silverlight2|Any CPU + {EEFFED24-3750-4567-9A23-1DB676A15610}.Release_Silverlight2|Any CPU.ActiveCfg = Release|Any CPU + {EEFFED24-3750-4567-9A23-1DB676A15610}.Release_Silverlight2|Any CPU.Build.0 = Release|Any CPU {EEFFED24-3750-4567-9A23-1DB676A15610}.Release|Any CPU.ActiveCfg = Release|Any CPU {EEFFED24-3750-4567-9A23-1DB676A15610}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection diff --git a/src/ProtocolBuffers/EnumLite.cs b/src/ProtocolBuffers/EnumLite.cs index 12497d8eb5..3776297f46 100644 --- a/src/ProtocolBuffers/EnumLite.cs +++ b/src/ProtocolBuffers/EnumLite.cs @@ -35,6 +35,7 @@ using System; using System.Collections.Generic; using System.Globalization; +using System.Reflection; using System.Text; namespace Google.ProtocolBuffers { @@ -86,8 +87,17 @@ namespace Google.ProtocolBuffers { public EnumLiteMap() { items = new SortedList(); +#if SILVERLIGHT2 + // Silverlight doesn't support Enum.GetValues + // TODO(jonskeet): Validate that this reflection is permitted, e.g. in Windows Phone 7 + foreach (FieldInfo fi in typeof(TEnum).GetFields(BindingFlags.Static | BindingFlags.Public)) { + TEnum evalue = (TEnum) fi.GetValue(null); + items.Add(Convert.ToInt32(evalue), new EnumValue(evalue)); + } +#else foreach (TEnum evalue in Enum.GetValues(typeof(TEnum))) items.Add(Convert.ToInt32(evalue), new EnumValue(evalue)); +#endif } IEnumLite IEnumLiteMap.FindValueByNumber(int number) { diff --git a/src/ProtocolBuffers/ProtocolBuffers.csproj b/src/ProtocolBuffers/ProtocolBuffers.csproj index 715afe87fa..8da01c9abf 100644 --- a/src/ProtocolBuffers/ProtocolBuffers.csproj +++ b/src/ProtocolBuffers/ProtocolBuffers.csproj @@ -68,19 +68,18 @@ AllRules.ruleset - pdbonly - true - bin\Release_Silverlight2\ - TRACE;SILVERLIGHT2 - prompt - 4 - true - AllRules.ruleset + pdbonly + true + bin\Release_Silverlight2\ + TRACE;SILVERLIGHT2 + prompt + 4 + true + AllRules.ruleset - @@ -199,7 +198,7 @@ true - + diff --git a/src/ProtocolBuffersLite.Test/ProtocolBuffersLite.Test.csproj b/src/ProtocolBuffersLite.Test/ProtocolBuffersLite.Test.csproj index 7f89f64039..034274e536 100644 --- a/src/ProtocolBuffersLite.Test/ProtocolBuffersLite.Test.csproj +++ b/src/ProtocolBuffersLite.Test/ProtocolBuffersLite.Test.csproj @@ -38,27 +38,6 @@ 4 true - - true - full - false - bin\Debug_Silverlight2\ - DEBUG;TRACE;SILVERLIGHT2 - prompt - 4 - true - AllRules.ruleset - - - pdbonly - true - bin\Release_Silverlight2\ - TRACE;SILVERLIGHT2 - prompt - 4 - true - AllRules.ruleset - False diff --git a/src/ProtocolBuffersLite.Test/ProtocolBuffersLiteMixed.Test.csproj b/src/ProtocolBuffersLite.Test/ProtocolBuffersLiteMixed.Test.csproj index 3e4654685c..55350ec503 100644 --- a/src/ProtocolBuffersLite.Test/ProtocolBuffersLiteMixed.Test.csproj +++ b/src/ProtocolBuffersLite.Test/ProtocolBuffersLiteMixed.Test.csproj @@ -38,27 +38,6 @@ true 4 - - true - full - false - bin\Debug_Silverlight2\ - DEBUG;TRACE;SILVERLIGHT2 - prompt - 4 - true - AllRules.ruleset - - - pdbonly - true - bin\Release_Silverlight2\ - TRACE;SILVERLIGHT2 - prompt - 4 - true - AllRules.ruleset - False diff --git a/src/ProtocolBuffersLite.Test/TestLiteByApi.cs b/src/ProtocolBuffersLite.Test/TestLiteByApi.cs index dfa322211e..f3d8fd5077 100644 --- a/src/ProtocolBuffersLite.Test/TestLiteByApi.cs +++ b/src/ProtocolBuffersLite.Test/TestLiteByApi.cs @@ -32,9 +32,6 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #endregion -using System; -using System.Collections.Generic; -using Google.ProtocolBuffers; using Google.ProtocolBuffers.TestProtos; using NUnit.Framework;