diff options
Diffstat (limited to 'src/ProtocolBuffersLite.Test')
-rw-r--r-- | src/ProtocolBuffersLite.Test/AbstractBuilderLiteTest.cs | 536 | ||||
-rw-r--r-- | src/ProtocolBuffersLite.Test/AbstractMessageLiteTest.cs | 252 | ||||
-rw-r--r-- | src/ProtocolBuffersLite.Test/ExtendableBuilderLiteTest.cs | 534 | ||||
-rw-r--r-- | src/ProtocolBuffersLite.Test/ExtendableMessageLiteTest.cs | 608 | ||||
-rw-r--r-- | src/ProtocolBuffersLite.Test/InteropLiteTest.cs | 324 | ||||
-rw-r--r-- | src/ProtocolBuffersLite.Test/LiteTest.cs | 222 | ||||
-rw-r--r-- | src/ProtocolBuffersLite.Test/MissingFieldAndExtensionTest.cs | 436 | ||||
-rw-r--r-- | src/ProtocolBuffersLite.Test/ProtocolBuffersLite.Test.csproj | 166 | ||||
-rw-r--r-- | src/ProtocolBuffersLite.Test/ProtocolBuffersLiteMixed.Test.csproj | 176 | ||||
-rw-r--r-- | src/ProtocolBuffersLite.Test/TestLiteByApi.cs | 226 | ||||
-rw-r--r-- | src/ProtocolBuffersLite.Test/TestProtos/UnitTestExtrasLiteProtoFile.cs | 3442 |
11 files changed, 3461 insertions, 3461 deletions
diff --git a/src/ProtocolBuffersLite.Test/AbstractBuilderLiteTest.cs b/src/ProtocolBuffersLite.Test/AbstractBuilderLiteTest.cs index e5e278a4..b2c743f3 100644 --- a/src/ProtocolBuffersLite.Test/AbstractBuilderLiteTest.cs +++ b/src/ProtocolBuffersLite.Test/AbstractBuilderLiteTest.cs @@ -1,268 +1,268 @@ -#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.IO; -using Google.ProtocolBuffers; -using Google.ProtocolBuffers.TestProtos; -using NUnit.Framework; - -namespace Google.ProtocolBuffers { - [TestFixture] - public class AbstractBuilderLiteTest { - - [Test] - public void TestMergeFromCodedInputStream() { - TestAllTypesLite copy, msg = TestAllTypesLite.CreateBuilder() - .SetOptionalUint32(uint.MaxValue).Build(); - - copy = TestAllTypesLite.DefaultInstance; - Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray()); - - using (MemoryStream ms = new MemoryStream(msg.ToByteArray())) { - CodedInputStream ci = CodedInputStream.CreateInstance(ms); - copy = copy.ToBuilder().MergeFrom(ci).Build(); - } - - Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray()); - } - - [Test] - public void TestIBuilderLiteWeakClear() { - TestAllTypesLite copy, msg = TestAllTypesLite.DefaultInstance; - - copy = msg.ToBuilder().SetOptionalString("Should be removed.").Build(); - Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray()); - - copy = (TestAllTypesLite)((IBuilderLite)copy.ToBuilder()).WeakClear().WeakBuild(); - Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray()); - } - - [Test] - public void TestBuilderLiteMergeFromCodedInputStream() { - TestAllTypesLite copy, msg = TestAllTypesLite.CreateBuilder() - .SetOptionalString("Should be merged.").Build(); - - copy = TestAllTypesLite.DefaultInstance; - Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray()); - - copy = copy.ToBuilder().MergeFrom(CodedInputStream.CreateInstance(new MemoryStream(msg.ToByteArray()))).Build(); - Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray()); - } - - [Test] - public void TestBuilderLiteMergeDelimitedFrom() { - TestAllTypesLite copy, msg = TestAllTypesLite.CreateBuilder() - .SetOptionalString("Should be merged.").Build(); - - copy = TestAllTypesLite.DefaultInstance; - Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray()); - Stream s = new MemoryStream(); - msg.WriteDelimitedTo(s); - s.Position = 0; - copy = copy.ToBuilder().MergeDelimitedFrom(s).Build(); - Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray()); - } - - [Test] - public void TestBuilderLiteMergeDelimitedFromExtensions() { - TestAllExtensionsLite copy, msg = TestAllExtensionsLite.CreateBuilder() - .SetExtension(UnitTestLiteProtoFile.OptionalStringExtensionLite, "Should be merged.").Build(); - - copy = TestAllExtensionsLite.DefaultInstance; - Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray()); - - Stream s = new MemoryStream(); - msg.WriteDelimitedTo(s); - s.Position = 0; - - ExtensionRegistry registry = ExtensionRegistry.CreateInstance(); - UnitTestLiteProtoFile.RegisterAllExtensions(registry); - - copy = copy.ToBuilder().MergeDelimitedFrom(s, registry).Build(); - Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray()); - Assert.AreEqual("Should be merged.", copy.GetExtension(UnitTestLiteProtoFile.OptionalStringExtensionLite)); - } - - [Test] - public void TestBuilderLiteMergeFromStream() { - TestAllTypesLite copy, msg = TestAllTypesLite.CreateBuilder() - .SetOptionalString("Should be merged.").Build(); - - copy = TestAllTypesLite.DefaultInstance; - Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray()); - Stream s = new MemoryStream(); - msg.WriteTo(s); - s.Position = 0; - copy = copy.ToBuilder().MergeFrom(s).Build(); - Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray()); - } - - [Test] - public void TestBuilderLiteMergeFromStreamExtensions() { - TestAllExtensionsLite copy, msg = TestAllExtensionsLite.CreateBuilder() - .SetExtension(UnitTestLiteProtoFile.OptionalStringExtensionLite, "Should be merged.").Build(); - - copy = TestAllExtensionsLite.DefaultInstance; - Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray()); - - Stream s = new MemoryStream(); - msg.WriteTo(s); - s.Position = 0; - - ExtensionRegistry registry = ExtensionRegistry.CreateInstance(); - UnitTestLiteProtoFile.RegisterAllExtensions(registry); - - copy = copy.ToBuilder().MergeFrom(s, registry).Build(); - Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray()); - Assert.AreEqual("Should be merged.", copy.GetExtension(UnitTestLiteProtoFile.OptionalStringExtensionLite)); - } - - [Test] - public void TestIBuilderLiteWeakMergeFromIMessageLite() { - TestAllTypesLite copy, msg = TestAllTypesLite.CreateBuilder() - .SetOptionalString("Should be merged.").Build(); - - copy = TestAllTypesLite.DefaultInstance; - Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray()); - - copy = (TestAllTypesLite)((IBuilderLite)copy.ToBuilder()).WeakMergeFrom((IMessageLite)msg).WeakBuild(); - Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray()); - } - - [Test] - public void TestIBuilderLiteWeakMergeFromByteString() { - TestAllTypesLite copy, msg = TestAllTypesLite.CreateBuilder() - .SetOptionalString("Should be merged.").Build(); - - copy = TestAllTypesLite.DefaultInstance; - Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray()); - - copy = (TestAllTypesLite)((IBuilderLite)copy.ToBuilder()).WeakMergeFrom(msg.ToByteString()).WeakBuild(); - Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray()); - } - - [Test] - public void TestIBuilderLiteWeakMergeFromByteStringExtensions() { - TestAllExtensionsLite copy, msg = TestAllExtensionsLite.CreateBuilder() - .SetExtension(UnitTestLiteProtoFile.OptionalStringExtensionLite, "Should be merged.").Build(); - - copy = TestAllExtensionsLite.DefaultInstance; - Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray()); - - copy = (TestAllExtensionsLite)((IBuilderLite)copy.ToBuilder()).WeakMergeFrom(msg.ToByteString(), ExtensionRegistry.Empty).WeakBuild(); - Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray()); - - ExtensionRegistry registry = ExtensionRegistry.CreateInstance(); - UnitTestLiteProtoFile.RegisterAllExtensions(registry); - - copy = (TestAllExtensionsLite)((IBuilderLite)copy.ToBuilder()).WeakMergeFrom(msg.ToByteString(), registry).WeakBuild(); - Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray()); - Assert.AreEqual("Should be merged.", copy.GetExtension(UnitTestLiteProtoFile.OptionalStringExtensionLite)); - } - - [Test] - public void TestIBuilderLiteWeakMergeFromCodedInputStream() { - TestAllTypesLite copy, msg = TestAllTypesLite.CreateBuilder() - .SetOptionalUint32(uint.MaxValue).Build(); - - copy = TestAllTypesLite.DefaultInstance; - Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray()); - - using (MemoryStream ms = new MemoryStream(msg.ToByteArray())) { - CodedInputStream ci = CodedInputStream.CreateInstance(ms); - copy = (TestAllTypesLite)((IBuilderLite)copy.ToBuilder()).WeakMergeFrom(ci).WeakBuild(); - } - - Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray()); - } - - [Test] - public void TestIBuilderLiteWeakBuildPartial() { - IBuilderLite builder = TestRequiredLite.CreateBuilder(); - Assert.IsFalse(builder.IsInitialized); - - IMessageLite msg = builder.WeakBuildPartial(); - Assert.IsFalse(msg.IsInitialized); - - Assert.AreEqual(msg.ToByteArray(), TestRequiredLite.DefaultInstance.ToByteArray()); - } - - [Test, ExpectedException(typeof(UninitializedMessageException ))] - public void TestIBuilderLiteWeakBuildUninitialized() { - IBuilderLite builder = TestRequiredLite.CreateBuilder(); - Assert.IsFalse(builder.IsInitialized); - builder.WeakBuild(); - } - - [Test] - public void TestIBuilderLiteWeakBuild() { - IBuilderLite builder = TestRequiredLite.CreateBuilder() - .SetD(0) - .SetEn(ExtraEnum.EXLITE_BAZ); - Assert.IsTrue(builder.IsInitialized); - builder.WeakBuild(); - } - - [Test] - public void TestIBuilderLiteWeakClone() { - TestRequiredLite msg = TestRequiredLite.CreateBuilder() - .SetD(1).SetEn(ExtraEnum.EXLITE_BAR).Build(); - Assert.IsTrue(msg.IsInitialized); - - IMessageLite copy = ((IBuilderLite)msg.ToBuilder()).WeakClone().WeakBuild(); - Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray()); - } - - [Test] - public void TestIBuilderLiteWeakDefaultInstance() { - Assert.IsTrue(ReferenceEquals(TestRequiredLite.DefaultInstance, - ((IBuilderLite)TestRequiredLite.CreateBuilder()).WeakDefaultInstanceForType)); - } - - [Test] - public void TestGeneratedBuilderLiteAddRange() { - TestAllTypesLite copy, msg = TestAllTypesLite.CreateBuilder() - .SetOptionalUint32(123) - .AddRepeatedInt32(1) - .AddRepeatedInt32(2) - .AddRepeatedInt32(3) - .Build(); - - copy = msg.DefaultInstanceForType.ToBuilder().MergeFrom(msg).Build(); - Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray()); - } - } -} +#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.IO;
+using Google.ProtocolBuffers;
+using Google.ProtocolBuffers.TestProtos;
+using NUnit.Framework;
+
+namespace Google.ProtocolBuffers {
+ [TestFixture]
+ public class AbstractBuilderLiteTest {
+
+ [Test]
+ public void TestMergeFromCodedInputStream() {
+ TestAllTypesLite copy, msg = TestAllTypesLite.CreateBuilder()
+ .SetOptionalUint32(uint.MaxValue).Build();
+
+ copy = TestAllTypesLite.DefaultInstance;
+ Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray());
+
+ using (MemoryStream ms = new MemoryStream(msg.ToByteArray())) {
+ CodedInputStream ci = CodedInputStream.CreateInstance(ms);
+ copy = copy.ToBuilder().MergeFrom(ci).Build();
+ }
+
+ Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
+ }
+
+ [Test]
+ public void TestIBuilderLiteWeakClear() {
+ TestAllTypesLite copy, msg = TestAllTypesLite.DefaultInstance;
+
+ copy = msg.ToBuilder().SetOptionalString("Should be removed.").Build();
+ Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray());
+
+ copy = (TestAllTypesLite)((IBuilderLite)copy.ToBuilder()).WeakClear().WeakBuild();
+ Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
+ }
+
+ [Test]
+ public void TestBuilderLiteMergeFromCodedInputStream() {
+ TestAllTypesLite copy, msg = TestAllTypesLite.CreateBuilder()
+ .SetOptionalString("Should be merged.").Build();
+
+ copy = TestAllTypesLite.DefaultInstance;
+ Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray());
+
+ copy = copy.ToBuilder().MergeFrom(CodedInputStream.CreateInstance(new MemoryStream(msg.ToByteArray()))).Build();
+ Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
+ }
+
+ [Test]
+ public void TestBuilderLiteMergeDelimitedFrom() {
+ TestAllTypesLite copy, msg = TestAllTypesLite.CreateBuilder()
+ .SetOptionalString("Should be merged.").Build();
+
+ copy = TestAllTypesLite.DefaultInstance;
+ Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray());
+ Stream s = new MemoryStream();
+ msg.WriteDelimitedTo(s);
+ s.Position = 0;
+ copy = copy.ToBuilder().MergeDelimitedFrom(s).Build();
+ Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
+ }
+
+ [Test]
+ public void TestBuilderLiteMergeDelimitedFromExtensions() {
+ TestAllExtensionsLite copy, msg = TestAllExtensionsLite.CreateBuilder()
+ .SetExtension(UnitTestLiteProtoFile.OptionalStringExtensionLite, "Should be merged.").Build();
+
+ copy = TestAllExtensionsLite.DefaultInstance;
+ Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray());
+
+ Stream s = new MemoryStream();
+ msg.WriteDelimitedTo(s);
+ s.Position = 0;
+
+ ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
+ UnitTestLiteProtoFile.RegisterAllExtensions(registry);
+
+ copy = copy.ToBuilder().MergeDelimitedFrom(s, registry).Build();
+ Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
+ Assert.AreEqual("Should be merged.", copy.GetExtension(UnitTestLiteProtoFile.OptionalStringExtensionLite));
+ }
+
+ [Test]
+ public void TestBuilderLiteMergeFromStream() {
+ TestAllTypesLite copy, msg = TestAllTypesLite.CreateBuilder()
+ .SetOptionalString("Should be merged.").Build();
+
+ copy = TestAllTypesLite.DefaultInstance;
+ Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray());
+ Stream s = new MemoryStream();
+ msg.WriteTo(s);
+ s.Position = 0;
+ copy = copy.ToBuilder().MergeFrom(s).Build();
+ Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
+ }
+
+ [Test]
+ public void TestBuilderLiteMergeFromStreamExtensions() {
+ TestAllExtensionsLite copy, msg = TestAllExtensionsLite.CreateBuilder()
+ .SetExtension(UnitTestLiteProtoFile.OptionalStringExtensionLite, "Should be merged.").Build();
+
+ copy = TestAllExtensionsLite.DefaultInstance;
+ Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray());
+
+ Stream s = new MemoryStream();
+ msg.WriteTo(s);
+ s.Position = 0;
+
+ ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
+ UnitTestLiteProtoFile.RegisterAllExtensions(registry);
+
+ copy = copy.ToBuilder().MergeFrom(s, registry).Build();
+ Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
+ Assert.AreEqual("Should be merged.", copy.GetExtension(UnitTestLiteProtoFile.OptionalStringExtensionLite));
+ }
+
+ [Test]
+ public void TestIBuilderLiteWeakMergeFromIMessageLite() {
+ TestAllTypesLite copy, msg = TestAllTypesLite.CreateBuilder()
+ .SetOptionalString("Should be merged.").Build();
+
+ copy = TestAllTypesLite.DefaultInstance;
+ Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray());
+
+ copy = (TestAllTypesLite)((IBuilderLite)copy.ToBuilder()).WeakMergeFrom((IMessageLite)msg).WeakBuild();
+ Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
+ }
+
+ [Test]
+ public void TestIBuilderLiteWeakMergeFromByteString() {
+ TestAllTypesLite copy, msg = TestAllTypesLite.CreateBuilder()
+ .SetOptionalString("Should be merged.").Build();
+
+ copy = TestAllTypesLite.DefaultInstance;
+ Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray());
+
+ copy = (TestAllTypesLite)((IBuilderLite)copy.ToBuilder()).WeakMergeFrom(msg.ToByteString()).WeakBuild();
+ Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
+ }
+
+ [Test]
+ public void TestIBuilderLiteWeakMergeFromByteStringExtensions() {
+ TestAllExtensionsLite copy, msg = TestAllExtensionsLite.CreateBuilder()
+ .SetExtension(UnitTestLiteProtoFile.OptionalStringExtensionLite, "Should be merged.").Build();
+
+ copy = TestAllExtensionsLite.DefaultInstance;
+ Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray());
+
+ copy = (TestAllExtensionsLite)((IBuilderLite)copy.ToBuilder()).WeakMergeFrom(msg.ToByteString(), ExtensionRegistry.Empty).WeakBuild();
+ Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray());
+
+ ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
+ UnitTestLiteProtoFile.RegisterAllExtensions(registry);
+
+ copy = (TestAllExtensionsLite)((IBuilderLite)copy.ToBuilder()).WeakMergeFrom(msg.ToByteString(), registry).WeakBuild();
+ Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
+ Assert.AreEqual("Should be merged.", copy.GetExtension(UnitTestLiteProtoFile.OptionalStringExtensionLite));
+ }
+
+ [Test]
+ public void TestIBuilderLiteWeakMergeFromCodedInputStream() {
+ TestAllTypesLite copy, msg = TestAllTypesLite.CreateBuilder()
+ .SetOptionalUint32(uint.MaxValue).Build();
+
+ copy = TestAllTypesLite.DefaultInstance;
+ Assert.AreNotEqual(msg.ToByteArray(), copy.ToByteArray());
+
+ using (MemoryStream ms = new MemoryStream(msg.ToByteArray())) {
+ CodedInputStream ci = CodedInputStream.CreateInstance(ms);
+ copy = (TestAllTypesLite)((IBuilderLite)copy.ToBuilder()).WeakMergeFrom(ci).WeakBuild();
+ }
+
+ Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
+ }
+
+ [Test]
+ public void TestIBuilderLiteWeakBuildPartial() {
+ IBuilderLite builder = TestRequiredLite.CreateBuilder();
+ Assert.IsFalse(builder.IsInitialized);
+
+ IMessageLite msg = builder.WeakBuildPartial();
+ Assert.IsFalse(msg.IsInitialized);
+
+ Assert.AreEqual(msg.ToByteArray(), TestRequiredLite.DefaultInstance.ToByteArray());
+ }
+
+ [Test, ExpectedException(typeof(UninitializedMessageException ))]
+ public void TestIBuilderLiteWeakBuildUninitialized() {
+ IBuilderLite builder = TestRequiredLite.CreateBuilder();
+ Assert.IsFalse(builder.IsInitialized);
+ builder.WeakBuild();
+ }
+
+ [Test]
+ public void TestIBuilderLiteWeakBuild() {
+ IBuilderLite builder = TestRequiredLite.CreateBuilder()
+ .SetD(0)
+ .SetEn(ExtraEnum.EXLITE_BAZ);
+ Assert.IsTrue(builder.IsInitialized);
+ builder.WeakBuild();
+ }
+
+ [Test]
+ public void TestIBuilderLiteWeakClone() {
+ TestRequiredLite msg = TestRequiredLite.CreateBuilder()
+ .SetD(1).SetEn(ExtraEnum.EXLITE_BAR).Build();
+ Assert.IsTrue(msg.IsInitialized);
+
+ IMessageLite copy = ((IBuilderLite)msg.ToBuilder()).WeakClone().WeakBuild();
+ Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
+ }
+
+ [Test]
+ public void TestIBuilderLiteWeakDefaultInstance() {
+ Assert.IsTrue(ReferenceEquals(TestRequiredLite.DefaultInstance,
+ ((IBuilderLite)TestRequiredLite.CreateBuilder()).WeakDefaultInstanceForType));
+ }
+
+ [Test]
+ public void TestGeneratedBuilderLiteAddRange() {
+ TestAllTypesLite copy, msg = TestAllTypesLite.CreateBuilder()
+ .SetOptionalUint32(123)
+ .AddRepeatedInt32(1)
+ .AddRepeatedInt32(2)
+ .AddRepeatedInt32(3)
+ .Build();
+
+ copy = msg.DefaultInstanceForType.ToBuilder().MergeFrom(msg).Build();
+ Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
+ }
+ }
+}
diff --git a/src/ProtocolBuffersLite.Test/AbstractMessageLiteTest.cs b/src/ProtocolBuffersLite.Test/AbstractMessageLiteTest.cs index 2cd87816..0391308b 100644 --- a/src/ProtocolBuffersLite.Test/AbstractMessageLiteTest.cs +++ b/src/ProtocolBuffersLite.Test/AbstractMessageLiteTest.cs @@ -1,126 +1,126 @@ -#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.IO; -using Google.ProtocolBuffers; -using Google.ProtocolBuffers.TestProtos; -using NUnit.Framework; - -namespace Google.ProtocolBuffers { - [TestFixture] - public class AbstractMessageLiteTest { - - [Test] - public void TestMessageLiteToByteString() { - TestRequiredLite msg = TestRequiredLite.CreateBuilder() - .SetD(42) - .SetEn(ExtraEnum.EXLITE_BAZ) - .Build(); - - ByteString b = msg.ToByteString(); - Assert.AreEqual(4, b.Length); - Assert.AreEqual(TestRequiredLite.DFieldNumber << 3, b[0]); - Assert.AreEqual(42, b[1]); - Assert.AreEqual(TestRequiredLite.EnFieldNumber << 3, b[2]); - Assert.AreEqual((int)ExtraEnum.EXLITE_BAZ, b[3]); - } - - [Test] - public void TestMessageLiteToByteArray() { - TestRequiredLite msg = TestRequiredLite.CreateBuilder() - .SetD(42) - .SetEn(ExtraEnum.EXLITE_BAZ) - .Build(); - - ByteString b = msg.ToByteString(); - ByteString copy = ByteString.CopyFrom(msg.ToByteArray()); - Assert.AreEqual(b, copy); - } - - [Test] - public void TestMessageLiteWriteTo() { - TestRequiredLite msg = TestRequiredLite.CreateBuilder() - .SetD(42) - .SetEn(ExtraEnum.EXLITE_BAZ) - .Build(); - - MemoryStream ms = new MemoryStream(); - msg.WriteTo(ms); - Assert.AreEqual(msg.ToByteArray(), ms.ToArray()); - } - - [Test] - public void TestMessageLiteWriteDelimitedTo() { - TestRequiredLite msg = TestRequiredLite.CreateBuilder() - .SetD(42) - .SetEn(ExtraEnum.EXLITE_BAZ) - .Build(); - - MemoryStream ms = new MemoryStream(); - msg.WriteDelimitedTo(ms); - byte[] buffer = ms.ToArray(); - - Assert.AreEqual(5, buffer.Length); - Assert.AreEqual(4, buffer[0]); - byte[] msgBytes = new byte[4]; - Array.Copy(buffer, 1, msgBytes, 0, 4); - Assert.AreEqual(msg.ToByteArray(), msgBytes); - } - - [Test] - public void TestIMessageLiteWeakCreateBuilderForType() { - IMessageLite msg = TestRequiredLite.DefaultInstance; - Assert.AreEqual(typeof(TestRequiredLite.Builder), msg.WeakCreateBuilderForType().GetType()); - } - - [Test] - public void TestMessageLiteWeakToBuilder() { - IMessageLite msg = TestRequiredLite.CreateBuilder() - .SetD(42) - .SetEn(ExtraEnum.EXLITE_BAZ) - .Build(); - - IMessageLite copy = msg.WeakToBuilder().WeakBuild(); - Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray()); - } - - [Test] - public void TestMessageLiteWeakDefaultInstanceForType() { - IMessageLite msg = TestRequiredLite.DefaultInstance; - Assert.IsTrue(Object.ReferenceEquals(TestRequiredLite.DefaultInstance, msg.WeakDefaultInstanceForType)); - } - } -} +#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.IO;
+using Google.ProtocolBuffers;
+using Google.ProtocolBuffers.TestProtos;
+using NUnit.Framework;
+
+namespace Google.ProtocolBuffers {
+ [TestFixture]
+ public class AbstractMessageLiteTest {
+
+ [Test]
+ public void TestMessageLiteToByteString() {
+ TestRequiredLite msg = TestRequiredLite.CreateBuilder()
+ .SetD(42)
+ .SetEn(ExtraEnum.EXLITE_BAZ)
+ .Build();
+
+ ByteString b = msg.ToByteString();
+ Assert.AreEqual(4, b.Length);
+ Assert.AreEqual(TestRequiredLite.DFieldNumber << 3, b[0]);
+ Assert.AreEqual(42, b[1]);
+ Assert.AreEqual(TestRequiredLite.EnFieldNumber << 3, b[2]);
+ Assert.AreEqual((int)ExtraEnum.EXLITE_BAZ, b[3]);
+ }
+
+ [Test]
+ public void TestMessageLiteToByteArray() {
+ TestRequiredLite msg = TestRequiredLite.CreateBuilder()
+ .SetD(42)
+ .SetEn(ExtraEnum.EXLITE_BAZ)
+ .Build();
+
+ ByteString b = msg.ToByteString();
+ ByteString copy = ByteString.CopyFrom(msg.ToByteArray());
+ Assert.AreEqual(b, copy);
+ }
+
+ [Test]
+ public void TestMessageLiteWriteTo() {
+ TestRequiredLite msg = TestRequiredLite.CreateBuilder()
+ .SetD(42)
+ .SetEn(ExtraEnum.EXLITE_BAZ)
+ .Build();
+
+ MemoryStream ms = new MemoryStream();
+ msg.WriteTo(ms);
+ Assert.AreEqual(msg.ToByteArray(), ms.ToArray());
+ }
+
+ [Test]
+ public void TestMessageLiteWriteDelimitedTo() {
+ TestRequiredLite msg = TestRequiredLite.CreateBuilder()
+ .SetD(42)
+ .SetEn(ExtraEnum.EXLITE_BAZ)
+ .Build();
+
+ MemoryStream ms = new MemoryStream();
+ msg.WriteDelimitedTo(ms);
+ byte[] buffer = ms.ToArray();
+
+ Assert.AreEqual(5, buffer.Length);
+ Assert.AreEqual(4, buffer[0]);
+ byte[] msgBytes = new byte[4];
+ Array.Copy(buffer, 1, msgBytes, 0, 4);
+ Assert.AreEqual(msg.ToByteArray(), msgBytes);
+ }
+
+ [Test]
+ public void TestIMessageLiteWeakCreateBuilderForType() {
+ IMessageLite msg = TestRequiredLite.DefaultInstance;
+ Assert.AreEqual(typeof(TestRequiredLite.Builder), msg.WeakCreateBuilderForType().GetType());
+ }
+
+ [Test]
+ public void TestMessageLiteWeakToBuilder() {
+ IMessageLite msg = TestRequiredLite.CreateBuilder()
+ .SetD(42)
+ .SetEn(ExtraEnum.EXLITE_BAZ)
+ .Build();
+
+ IMessageLite copy = msg.WeakToBuilder().WeakBuild();
+ Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
+ }
+
+ [Test]
+ public void TestMessageLiteWeakDefaultInstanceForType() {
+ IMessageLite msg = TestRequiredLite.DefaultInstance;
+ Assert.IsTrue(Object.ReferenceEquals(TestRequiredLite.DefaultInstance, msg.WeakDefaultInstanceForType));
+ }
+ }
+}
diff --git a/src/ProtocolBuffersLite.Test/ExtendableBuilderLiteTest.cs b/src/ProtocolBuffersLite.Test/ExtendableBuilderLiteTest.cs index 9a495a9f..f4e7fccc 100644 --- a/src/ProtocolBuffersLite.Test/ExtendableBuilderLiteTest.cs +++ b/src/ProtocolBuffersLite.Test/ExtendableBuilderLiteTest.cs @@ -1,267 +1,267 @@ -#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; -using Google.ProtocolBuffers; -using Google.ProtocolBuffers.TestProtos; -using NUnit.Framework; - -namespace Google.ProtocolBuffers { - [TestFixture] - public class ExtendableBuilderLiteTest { - - [Test] - public void TestHasExtensionT() { - TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder() - .SetExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite, 123); - - Assert.IsTrue(builder.HasExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite)); - } - - [Test] - public void TestHasExtensionTMissing() { - TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder(); - Assert.IsFalse(builder.HasExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite)); - } - - [Test] - public void TestGetExtensionCountT() { - TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder() - .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 1) - .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 2) - .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 3); - - Assert.AreEqual(3, builder.GetExtensionCount(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite)); - } - - [Test] - public void TestGetExtensionCountTEmpty() { - TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder(); - Assert.AreEqual(0, builder.GetExtensionCount(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite)); - } - - [Test] - public void TestGetExtensionTNull() { - TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder(); - string value = builder.GetExtension(UnitTestLiteProtoFile.OptionalStringExtensionLite); - Assert.IsNull(value); - } - - [Test] - public void TestGetExtensionTValue() { - TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder() - .SetExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite, 3); - - Assert.AreEqual(3, builder.GetExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite)); - } - - [Test] - public void TestGetExtensionTEmpty() { - TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder(); - Assert.AreEqual(0, builder.GetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite).Count); - } - - [Test] - public void TestGetExtensionTList() { - TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder() - .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 1) - .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 2) - .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 3); - - IList<int> values = builder.GetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite); - Assert.AreEqual(3, values.Count); - } - - [Test] - public void TestGetExtensionTIndex() { - TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder() - .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 0) - .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 1) - .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 2); - - for(int i = 0; i < 3; i++ ) - Assert.AreEqual(i, builder.GetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, i)); - } - - [Test,ExpectedException(typeof(ArgumentOutOfRangeException))] - public void TestGetExtensionTIndexOutOfRange() { - TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder(); - builder.GetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 0); - } - - [Test] - public void TestSetExtensionTIndex() { - TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder() - .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 0) - .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 1) - .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 2); - - for (int i = 0; i < 3; i++) - Assert.AreEqual(i, builder.GetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, i)); - - builder.SetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 0, 5); - builder.SetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 1, 6); - builder.SetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 2, 7); - - for (int i = 0; i < 3; i++) - Assert.AreEqual(5 + i, builder.GetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, i)); - } - - [Test, ExpectedException(typeof(ArgumentOutOfRangeException))] - public void TestSetExtensionTIndexOutOfRange() { - TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder(); - builder.SetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 0, -1); - } - - [Test] - public void TestClearExtensionTList() { - TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder() - .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 0); - Assert.AreEqual(1, builder.GetExtensionCount(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite)); - - builder.ClearExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite); - Assert.AreEqual(0, builder.GetExtensionCount(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite)); - } - - [Test] - public void TestClearExtensionTValue() { - TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder() - .SetExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite, 0); - Assert.IsTrue(builder.HasExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite)); - - builder.ClearExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite); - Assert.IsFalse(builder.HasExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite)); - } - - [Test] - public void TestIndexedByDescriptor() { - TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder(); - Assert.IsFalse(builder.HasExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite)); - - builder[UnitTestLiteProtoFile.OptionalInt32ExtensionLite.Descriptor] = 123; - - Assert.IsTrue(builder.HasExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite)); - Assert.AreEqual(123, builder.GetExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite)); - } - - [Test] - public void TestIndexedByDescriptorAndOrdinal() { - TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder() - .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 0); - Assert.AreEqual(1, builder.GetExtensionCount(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite)); - - IFieldDescriptorLite f = UnitTestLiteProtoFile.RepeatedInt32ExtensionLite.Descriptor; - builder[f, 0] = 123; - - Assert.AreEqual(1, builder.GetExtensionCount(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite)); - Assert.AreEqual(123, builder.GetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 0)); - } - - [Test, ExpectedException(typeof(ArgumentOutOfRangeException))] - public void TestIndexedByDescriptorAndOrdinalOutOfRange() { - TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder(); - Assert.AreEqual(0, builder.GetExtensionCount(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite)); - - IFieldDescriptorLite f = UnitTestLiteProtoFile.RepeatedInt32ExtensionLite.Descriptor; - builder[f, 0] = 123; - } - - [Test] - public void TestClearFieldByDescriptor() { - TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder() - .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 0); - Assert.AreEqual(1, builder.GetExtensionCount(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite)); - - IFieldDescriptorLite f = UnitTestLiteProtoFile.RepeatedInt32ExtensionLite.Descriptor; - builder.ClearField(f); - Assert.AreEqual(0, builder.GetExtensionCount(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite)); - } - - [Test] - public void TestAddRepeatedFieldByDescriptor() { - TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder() - .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 0); - Assert.AreEqual(1, builder.GetExtensionCount(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite)); - - IFieldDescriptorLite f = UnitTestLiteProtoFile.RepeatedInt32ExtensionLite.Descriptor; - builder.AddRepeatedField(f, 123); - Assert.AreEqual(2, builder.GetExtensionCount(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite)); - Assert.AreEqual(123, builder.GetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 1)); - } - - [Test] - public void TestMissingExtensionsLite() - { - const int optionalInt32 = 12345678; - TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder(); - builder.SetExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite, optionalInt32); - builder.AddExtension(UnitTestLiteProtoFile.RepeatedDoubleExtensionLite, 1.1); - builder.AddExtension(UnitTestLiteProtoFile.RepeatedDoubleExtensionLite, 1.2); - builder.AddExtension(UnitTestLiteProtoFile.RepeatedDoubleExtensionLite, 1.3); - TestAllExtensionsLite msg = builder.Build(); - - Assert.IsTrue(msg.HasExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite)); - Assert.AreEqual(3, msg.GetExtensionCount(UnitTestLiteProtoFile.RepeatedDoubleExtensionLite)); - - byte[] bits = msg.ToByteArray(); - TestAllExtensionsLite copy = TestAllExtensionsLite.ParseFrom(bits); - Assert.IsFalse(copy.HasExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite)); - Assert.AreEqual(0, copy.GetExtensionCount(UnitTestLiteProtoFile.RepeatedDoubleExtensionLite)); - Assert.AreNotEqual(msg, copy); - - //The lite runtime removes all unknown fields and extensions - byte[] copybits = copy.ToByteArray(); - Assert.AreEqual(0, copybits.Length); - } - - [Test] - public void TestMissingFieldsLite() - { - TestAllTypesLite msg = TestAllTypesLite.CreateBuilder() - .SetOptionalInt32(123) - .SetOptionalString("123") - .Build(); - - byte[] bits = msg.ToByteArray(); - TestAllExtensionsLite copy = TestAllExtensionsLite.ParseFrom(bits); - Assert.AreNotEqual(msg, copy); - - //The lite runtime removes all unknown fields and extensions - byte[] copybits = copy.ToByteArray(); - Assert.AreEqual(0, copybits.Length); - } - } -} +#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;
+using Google.ProtocolBuffers;
+using Google.ProtocolBuffers.TestProtos;
+using NUnit.Framework;
+
+namespace Google.ProtocolBuffers {
+ [TestFixture]
+ public class ExtendableBuilderLiteTest {
+
+ [Test]
+ public void TestHasExtensionT() {
+ TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
+ .SetExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite, 123);
+
+ Assert.IsTrue(builder.HasExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite));
+ }
+
+ [Test]
+ public void TestHasExtensionTMissing() {
+ TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder();
+ Assert.IsFalse(builder.HasExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite));
+ }
+
+ [Test]
+ public void TestGetExtensionCountT() {
+ TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
+ .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 1)
+ .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 2)
+ .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 3);
+
+ Assert.AreEqual(3, builder.GetExtensionCount(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite));
+ }
+
+ [Test]
+ public void TestGetExtensionCountTEmpty() {
+ TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder();
+ Assert.AreEqual(0, builder.GetExtensionCount(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite));
+ }
+
+ [Test]
+ public void TestGetExtensionTNull() {
+ TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder();
+ string value = builder.GetExtension(UnitTestLiteProtoFile.OptionalStringExtensionLite);
+ Assert.IsNull(value);
+ }
+
+ [Test]
+ public void TestGetExtensionTValue() {
+ TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
+ .SetExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite, 3);
+
+ Assert.AreEqual(3, builder.GetExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite));
+ }
+
+ [Test]
+ public void TestGetExtensionTEmpty() {
+ TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder();
+ Assert.AreEqual(0, builder.GetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite).Count);
+ }
+
+ [Test]
+ public void TestGetExtensionTList() {
+ TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
+ .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 1)
+ .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 2)
+ .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 3);
+
+ IList<int> values = builder.GetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite);
+ Assert.AreEqual(3, values.Count);
+ }
+
+ [Test]
+ public void TestGetExtensionTIndex() {
+ TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
+ .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 0)
+ .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 1)
+ .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 2);
+
+ for(int i = 0; i < 3; i++ )
+ Assert.AreEqual(i, builder.GetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, i));
+ }
+
+ [Test,ExpectedException(typeof(ArgumentOutOfRangeException))]
+ public void TestGetExtensionTIndexOutOfRange() {
+ TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder();
+ builder.GetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 0);
+ }
+
+ [Test]
+ public void TestSetExtensionTIndex() {
+ TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
+ .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 0)
+ .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 1)
+ .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 2);
+
+ for (int i = 0; i < 3; i++)
+ Assert.AreEqual(i, builder.GetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, i));
+
+ builder.SetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 0, 5);
+ builder.SetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 1, 6);
+ builder.SetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 2, 7);
+
+ for (int i = 0; i < 3; i++)
+ Assert.AreEqual(5 + i, builder.GetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, i));
+ }
+
+ [Test, ExpectedException(typeof(ArgumentOutOfRangeException))]
+ public void TestSetExtensionTIndexOutOfRange() {
+ TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder();
+ builder.SetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 0, -1);
+ }
+
+ [Test]
+ public void TestClearExtensionTList() {
+ TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
+ .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 0);
+ Assert.AreEqual(1, builder.GetExtensionCount(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite));
+
+ builder.ClearExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite);
+ Assert.AreEqual(0, builder.GetExtensionCount(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite));
+ }
+
+ [Test]
+ public void TestClearExtensionTValue() {
+ TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
+ .SetExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite, 0);
+ Assert.IsTrue(builder.HasExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite));
+
+ builder.ClearExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite);
+ Assert.IsFalse(builder.HasExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite));
+ }
+
+ [Test]
+ public void TestIndexedByDescriptor() {
+ TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder();
+ Assert.IsFalse(builder.HasExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite));
+
+ builder[UnitTestLiteProtoFile.OptionalInt32ExtensionLite.Descriptor] = 123;
+
+ Assert.IsTrue(builder.HasExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite));
+ Assert.AreEqual(123, builder.GetExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite));
+ }
+
+ [Test]
+ public void TestIndexedByDescriptorAndOrdinal() {
+ TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
+ .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 0);
+ Assert.AreEqual(1, builder.GetExtensionCount(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite));
+
+ IFieldDescriptorLite f = UnitTestLiteProtoFile.RepeatedInt32ExtensionLite.Descriptor;
+ builder[f, 0] = 123;
+
+ Assert.AreEqual(1, builder.GetExtensionCount(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite));
+ Assert.AreEqual(123, builder.GetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 0));
+ }
+
+ [Test, ExpectedException(typeof(ArgumentOutOfRangeException))]
+ public void TestIndexedByDescriptorAndOrdinalOutOfRange() {
+ TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder();
+ Assert.AreEqual(0, builder.GetExtensionCount(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite));
+
+ IFieldDescriptorLite f = UnitTestLiteProtoFile.RepeatedInt32ExtensionLite.Descriptor;
+ builder[f, 0] = 123;
+ }
+
+ [Test]
+ public void TestClearFieldByDescriptor() {
+ TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
+ .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 0);
+ Assert.AreEqual(1, builder.GetExtensionCount(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite));
+
+ IFieldDescriptorLite f = UnitTestLiteProtoFile.RepeatedInt32ExtensionLite.Descriptor;
+ builder.ClearField(f);
+ Assert.AreEqual(0, builder.GetExtensionCount(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite));
+ }
+
+ [Test]
+ public void TestAddRepeatedFieldByDescriptor() {
+ TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
+ .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 0);
+ Assert.AreEqual(1, builder.GetExtensionCount(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite));
+
+ IFieldDescriptorLite f = UnitTestLiteProtoFile.RepeatedInt32ExtensionLite.Descriptor;
+ builder.AddRepeatedField(f, 123);
+ Assert.AreEqual(2, builder.GetExtensionCount(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite));
+ Assert.AreEqual(123, builder.GetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 1));
+ }
+
+ [Test]
+ public void TestMissingExtensionsLite()
+ {
+ const int optionalInt32 = 12345678;
+ TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder();
+ builder.SetExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite, optionalInt32);
+ builder.AddExtension(UnitTestLiteProtoFile.RepeatedDoubleExtensionLite, 1.1);
+ builder.AddExtension(UnitTestLiteProtoFile.RepeatedDoubleExtensionLite, 1.2);
+ builder.AddExtension(UnitTestLiteProtoFile.RepeatedDoubleExtensionLite, 1.3);
+ TestAllExtensionsLite msg = builder.Build();
+
+ Assert.IsTrue(msg.HasExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite));
+ Assert.AreEqual(3, msg.GetExtensionCount(UnitTestLiteProtoFile.RepeatedDoubleExtensionLite));
+
+ byte[] bits = msg.ToByteArray();
+ TestAllExtensionsLite copy = TestAllExtensionsLite.ParseFrom(bits);
+ Assert.IsFalse(copy.HasExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite));
+ Assert.AreEqual(0, copy.GetExtensionCount(UnitTestLiteProtoFile.RepeatedDoubleExtensionLite));
+ Assert.AreNotEqual(msg, copy);
+
+ //The lite runtime removes all unknown fields and extensions
+ byte[] copybits = copy.ToByteArray();
+ Assert.AreEqual(0, copybits.Length);
+ }
+
+ [Test]
+ public void TestMissingFieldsLite()
+ {
+ TestAllTypesLite msg = TestAllTypesLite.CreateBuilder()
+ .SetOptionalInt32(123)
+ .SetOptionalString("123")
+ .Build();
+
+ byte[] bits = msg.ToByteArray();
+ TestAllExtensionsLite copy = TestAllExtensionsLite.ParseFrom(bits);
+ Assert.AreNotEqual(msg, copy);
+
+ //The lite runtime removes all unknown fields and extensions
+ byte[] copybits = copy.ToByteArray();
+ Assert.AreEqual(0, copybits.Length);
+ }
+ }
+}
diff --git a/src/ProtocolBuffersLite.Test/ExtendableMessageLiteTest.cs b/src/ProtocolBuffersLite.Test/ExtendableMessageLiteTest.cs index 86b8f115..05ad064e 100644 --- a/src/ProtocolBuffersLite.Test/ExtendableMessageLiteTest.cs +++ b/src/ProtocolBuffersLite.Test/ExtendableMessageLiteTest.cs @@ -1,304 +1,304 @@ -#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.Text; -using Google.ProtocolBuffers; -using Google.ProtocolBuffers.TestProtos; -using NUnit.Framework; - -namespace Google.ProtocolBuffers { - [TestFixture] - public class ExtendableMessageLiteTest { - - [Test, Ignore("Not implemented, no assertion made"), ExpectedException(typeof(ArgumentException))] - public void ExtensionWriterInvalidExtension() { - TestPackedExtensionsLite.CreateBuilder()[UnitTestLiteProtoFile.OptionalForeignMessageExtensionLite.Descriptor] = - ForeignMessageLite.DefaultInstance; - } - - [Test] - public void ExtensionWriterTestMessages() { - TestAllExtensionsLite.Builder b = TestAllExtensionsLite.CreateBuilder().SetExtension( - UnitTestLiteProtoFile.OptionalForeignMessageExtensionLite, ForeignMessageLite.CreateBuilder().SetC(123).Build()); - TestAllExtensionsLite copy, msg = b.Build(); - - ExtensionRegistry registry = ExtensionRegistry.CreateInstance(); - UnitTestLiteProtoFile.RegisterAllExtensions(registry); - - copy = TestAllExtensionsLite.ParseFrom(msg.ToByteArray(), registry); - Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray()); - } - - [Test] - public void ExtensionWriterIsInitialized() { - Assert.IsTrue(ForeignMessageLite.DefaultInstance.IsInitialized); - Assert.IsTrue(TestPackedExtensionsLite.CreateBuilder().IsInitialized); - Assert.IsTrue(TestAllExtensionsLite.CreateBuilder().SetExtension( - UnitTestLiteProtoFile.OptionalForeignMessageExtensionLite, ForeignMessageLite.DefaultInstance) - .IsInitialized); - } - - [Test] - public void ExtensionWriterTestSetExtensionLists() { - TestAllExtensionsLite msg, copy; - TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder() - .SetExtension(UnitTestLiteProtoFile.RepeatedBoolExtensionLite, new[] { true, false }) - .SetExtension(UnitTestLiteProtoFile.RepeatedCordExtensionLite, new[] { "123", "456" }) - .SetExtension(UnitTestLiteProtoFile.RepeatedForeignEnumExtensionLite, new[] { ForeignEnumLite.FOREIGN_LITE_BAZ, ForeignEnumLite.FOREIGN_LITE_FOO }) - ; - - msg = builder.Build(); - ExtensionRegistry registry = ExtensionRegistry.CreateInstance(); - UnitTestLiteProtoFile.RegisterAllExtensions(registry); - - copy = TestAllExtensionsLite.ParseFrom(msg.ToByteArray(), registry); - Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray()); - - Assert.AreEqual(ForeignEnumLite.FOREIGN_LITE_FOO, copy.GetExtension(UnitTestLiteProtoFile.RepeatedForeignEnumExtensionLite, 1)); - } - - [Test] - public void ExtensionWriterTest() { - TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder() - .SetExtension(UnitTestLiteProtoFile.DefaultBoolExtensionLite, true) - .SetExtension(UnitTestLiteProtoFile.DefaultBytesExtensionLite, ByteString.CopyFromUtf8("123")) - .SetExtension(UnitTestLiteProtoFile.DefaultCordExtensionLite, "123") - .SetExtension(UnitTestLiteProtoFile.DefaultDoubleExtensionLite, 123) - .SetExtension(UnitTestLiteProtoFile.DefaultFixed32ExtensionLite, 123u) - .SetExtension(UnitTestLiteProtoFile.DefaultFixed64ExtensionLite, 123u) - .SetExtension(UnitTestLiteProtoFile.DefaultFloatExtensionLite, 123) - .SetExtension(UnitTestLiteProtoFile.DefaultForeignEnumExtensionLite, ForeignEnumLite.FOREIGN_LITE_BAZ) - .SetExtension(UnitTestLiteProtoFile.DefaultImportEnumExtensionLite, ImportEnumLite.IMPORT_LITE_BAZ) - .SetExtension(UnitTestLiteProtoFile.DefaultInt32ExtensionLite, 123) - .SetExtension(UnitTestLiteProtoFile.DefaultInt64ExtensionLite, 123) - .SetExtension(UnitTestLiteProtoFile.DefaultNestedEnumExtensionLite, TestAllTypesLite.Types.NestedEnum.FOO) - .SetExtension(UnitTestLiteProtoFile.DefaultSfixed32ExtensionLite, 123) - .SetExtension(UnitTestLiteProtoFile.DefaultSfixed64ExtensionLite, 123) - .SetExtension(UnitTestLiteProtoFile.DefaultSint32ExtensionLite, 123) - .SetExtension(UnitTestLiteProtoFile.DefaultSint64ExtensionLite, 123) - .SetExtension(UnitTestLiteProtoFile.DefaultStringExtensionLite, "123") - .SetExtension(UnitTestLiteProtoFile.DefaultStringPieceExtensionLite, "123") - .SetExtension(UnitTestLiteProtoFile.DefaultUint32ExtensionLite, 123u) - .SetExtension(UnitTestLiteProtoFile.DefaultUint64ExtensionLite, 123u) - //Optional - .SetExtension(UnitTestLiteProtoFile.OptionalBoolExtensionLite, true) - .SetExtension(UnitTestLiteProtoFile.OptionalBytesExtensionLite, ByteString.CopyFromUtf8("123")) - .SetExtension(UnitTestLiteProtoFile.OptionalCordExtensionLite, "123") - .SetExtension(UnitTestLiteProtoFile.OptionalDoubleExtensionLite, 123) - .SetExtension(UnitTestLiteProtoFile.OptionalFixed32ExtensionLite, 123u) - .SetExtension(UnitTestLiteProtoFile.OptionalFixed64ExtensionLite, 123u) - .SetExtension(UnitTestLiteProtoFile.OptionalFloatExtensionLite, 123) - .SetExtension(UnitTestLiteProtoFile.OptionalForeignEnumExtensionLite, ForeignEnumLite.FOREIGN_LITE_BAZ) - .SetExtension(UnitTestLiteProtoFile.OptionalImportEnumExtensionLite, ImportEnumLite.IMPORT_LITE_BAZ) - .SetExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite, 123) - .SetExtension(UnitTestLiteProtoFile.OptionalInt64ExtensionLite, 123) - .SetExtension(UnitTestLiteProtoFile.OptionalNestedEnumExtensionLite, TestAllTypesLite.Types.NestedEnum.FOO) - .SetExtension(UnitTestLiteProtoFile.OptionalSfixed32ExtensionLite, 123) - .SetExtension(UnitTestLiteProtoFile.OptionalSfixed64ExtensionLite, 123) - .SetExtension(UnitTestLiteProtoFile.OptionalSint32ExtensionLite, 123) - .SetExtension(UnitTestLiteProtoFile.OptionalSint64ExtensionLite, 123) - .SetExtension(UnitTestLiteProtoFile.OptionalStringExtensionLite, "123") - .SetExtension(UnitTestLiteProtoFile.OptionalStringPieceExtensionLite, "123") - .SetExtension(UnitTestLiteProtoFile.OptionalUint32ExtensionLite, 123u) - .SetExtension(UnitTestLiteProtoFile.OptionalUint64ExtensionLite, 123u) - //Repeated - .AddExtension(UnitTestLiteProtoFile.RepeatedBoolExtensionLite, true) - .AddExtension(UnitTestLiteProtoFile.RepeatedBytesExtensionLite, ByteString.CopyFromUtf8("123")) - .AddExtension(UnitTestLiteProtoFile.RepeatedCordExtensionLite, "123") - .AddExtension(UnitTestLiteProtoFile.RepeatedDoubleExtensionLite, 123) - .AddExtension(UnitTestLiteProtoFile.RepeatedFixed32ExtensionLite, 123u) - .AddExtension(UnitTestLiteProtoFile.RepeatedFixed64ExtensionLite, 123u) - .AddExtension(UnitTestLiteProtoFile.RepeatedFloatExtensionLite, 123) - .AddExtension(UnitTestLiteProtoFile.RepeatedForeignEnumExtensionLite, ForeignEnumLite.FOREIGN_LITE_BAZ) - .AddExtension(UnitTestLiteProtoFile.RepeatedImportEnumExtensionLite, ImportEnumLite.IMPORT_LITE_BAZ) - .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 123) - .AddExtension(UnitTestLiteProtoFile.RepeatedInt64ExtensionLite, 123) - .AddExtension(UnitTestLiteProtoFile.RepeatedNestedEnumExtensionLite, TestAllTypesLite.Types.NestedEnum.FOO) - .AddExtension(UnitTestLiteProtoFile.RepeatedSfixed32ExtensionLite, 123) - .AddExtension(UnitTestLiteProtoFile.RepeatedSfixed64ExtensionLite, 123) - .AddExtension(UnitTestLiteProtoFile.RepeatedSint32ExtensionLite, 123) - .AddExtension(UnitTestLiteProtoFile.RepeatedSint64ExtensionLite, 123) - .AddExtension(UnitTestLiteProtoFile.RepeatedStringExtensionLite, "123") - .AddExtension(UnitTestLiteProtoFile.RepeatedStringPieceExtensionLite, "123") - .AddExtension(UnitTestLiteProtoFile.RepeatedUint32ExtensionLite, 123u) - .AddExtension(UnitTestLiteProtoFile.RepeatedUint64ExtensionLite, 123u) - ; - TestAllExtensionsLite msg = builder.Build(); - - ExtensionRegistry registry = ExtensionRegistry.CreateInstance(); - UnitTestLiteProtoFile.RegisterAllExtensions(registry); - - TestAllExtensionsLite.Builder copyBuilder = TestAllExtensionsLite.CreateBuilder().MergeFrom(msg.ToByteArray(), registry); - TestAllExtensionsLite copy = copyBuilder.Build(); - - Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray()); - - Assert.AreEqual(true, copy.GetExtension(UnitTestLiteProtoFile.DefaultBoolExtensionLite)); - Assert.AreEqual(ByteString.CopyFromUtf8("123"), copy.GetExtension(UnitTestLiteProtoFile.DefaultBytesExtensionLite)); - Assert.AreEqual("123", copy.GetExtension(UnitTestLiteProtoFile.DefaultCordExtensionLite)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.DefaultDoubleExtensionLite)); - Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.DefaultFixed32ExtensionLite)); - Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.DefaultFixed64ExtensionLite)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.DefaultFloatExtensionLite)); - Assert.AreEqual(ForeignEnumLite.FOREIGN_LITE_BAZ, copy.GetExtension(UnitTestLiteProtoFile.DefaultForeignEnumExtensionLite)); - Assert.AreEqual(ImportEnumLite.IMPORT_LITE_BAZ, copy.GetExtension(UnitTestLiteProtoFile.DefaultImportEnumExtensionLite)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.DefaultInt32ExtensionLite)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.DefaultInt64ExtensionLite)); - Assert.AreEqual(TestAllTypesLite.Types.NestedEnum.FOO, copy.GetExtension(UnitTestLiteProtoFile.DefaultNestedEnumExtensionLite)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.DefaultSfixed32ExtensionLite)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.DefaultSfixed64ExtensionLite)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.DefaultSint32ExtensionLite)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.DefaultSint64ExtensionLite)); - Assert.AreEqual("123", copy.GetExtension(UnitTestLiteProtoFile.DefaultStringExtensionLite)); - Assert.AreEqual("123", copy.GetExtension(UnitTestLiteProtoFile.DefaultStringPieceExtensionLite)); - Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.DefaultUint32ExtensionLite)); - Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.DefaultUint64ExtensionLite)); - - Assert.AreEqual(true, copy.GetExtension(UnitTestLiteProtoFile.OptionalBoolExtensionLite)); - Assert.AreEqual(ByteString.CopyFromUtf8("123"), copy.GetExtension(UnitTestLiteProtoFile.OptionalBytesExtensionLite)); - Assert.AreEqual("123", copy.GetExtension(UnitTestLiteProtoFile.OptionalCordExtensionLite)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.OptionalDoubleExtensionLite)); - Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.OptionalFixed32ExtensionLite)); - Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.OptionalFixed64ExtensionLite)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.OptionalFloatExtensionLite)); - Assert.AreEqual(ForeignEnumLite.FOREIGN_LITE_BAZ, copy.GetExtension(UnitTestLiteProtoFile.OptionalForeignEnumExtensionLite)); - Assert.AreEqual(ImportEnumLite.IMPORT_LITE_BAZ, copy.GetExtension(UnitTestLiteProtoFile.OptionalImportEnumExtensionLite)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.OptionalInt64ExtensionLite)); - Assert.AreEqual(TestAllTypesLite.Types.NestedEnum.FOO, copy.GetExtension(UnitTestLiteProtoFile.OptionalNestedEnumExtensionLite)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.OptionalSfixed32ExtensionLite)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.OptionalSfixed64ExtensionLite)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.OptionalSint32ExtensionLite)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.OptionalSint64ExtensionLite)); - Assert.AreEqual("123", copy.GetExtension(UnitTestLiteProtoFile.OptionalStringExtensionLite)); - Assert.AreEqual("123", copy.GetExtension(UnitTestLiteProtoFile.OptionalStringPieceExtensionLite)); - Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.OptionalUint32ExtensionLite)); - Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.OptionalUint64ExtensionLite)); - - Assert.AreEqual(true, copy.GetExtension(UnitTestLiteProtoFile.RepeatedBoolExtensionLite, 0)); - Assert.AreEqual(ByteString.CopyFromUtf8("123"), copy.GetExtension(UnitTestLiteProtoFile.RepeatedBytesExtensionLite, 0)); - Assert.AreEqual("123", copy.GetExtension(UnitTestLiteProtoFile.RepeatedCordExtensionLite, 0)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.RepeatedDoubleExtensionLite, 0)); - Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.RepeatedFixed32ExtensionLite, 0)); - Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.RepeatedFixed64ExtensionLite, 0)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.RepeatedFloatExtensionLite, 0)); - Assert.AreEqual(ForeignEnumLite.FOREIGN_LITE_BAZ, copy.GetExtension(UnitTestLiteProtoFile.RepeatedForeignEnumExtensionLite, 0)); - Assert.AreEqual(ImportEnumLite.IMPORT_LITE_BAZ, copy.GetExtension(UnitTestLiteProtoFile.RepeatedImportEnumExtensionLite, 0)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 0)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.RepeatedInt64ExtensionLite, 0)); - Assert.AreEqual(TestAllTypesLite.Types.NestedEnum.FOO, copy.GetExtension(UnitTestLiteProtoFile.RepeatedNestedEnumExtensionLite, 0)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.RepeatedSfixed32ExtensionLite, 0)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.RepeatedSfixed64ExtensionLite, 0)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.RepeatedSint32ExtensionLite, 0)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.RepeatedSint64ExtensionLite, 0)); - Assert.AreEqual("123", copy.GetExtension(UnitTestLiteProtoFile.RepeatedStringExtensionLite, 0)); - Assert.AreEqual("123", copy.GetExtension(UnitTestLiteProtoFile.RepeatedStringPieceExtensionLite, 0)); - Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.RepeatedUint32ExtensionLite, 0)); - Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.RepeatedUint64ExtensionLite, 0)); - } - - [Test] - public void ExtensionWriterTestPacked() { - - TestPackedExtensionsLite.Builder builder = TestPackedExtensionsLite.CreateBuilder() - .AddExtension(UnitTestLiteProtoFile.PackedBoolExtensionLite, true) - .AddExtension(UnitTestLiteProtoFile.PackedDoubleExtensionLite, 123) - .AddExtension(UnitTestLiteProtoFile.PackedFixed32ExtensionLite, 123u) - .AddExtension(UnitTestLiteProtoFile.PackedFixed64ExtensionLite, 123u) - .AddExtension(UnitTestLiteProtoFile.PackedFloatExtensionLite, 123) - .AddExtension(UnitTestLiteProtoFile.PackedInt32ExtensionLite, 123) - .AddExtension(UnitTestLiteProtoFile.PackedInt64ExtensionLite, 123) - .AddExtension(UnitTestLiteProtoFile.PackedSfixed32ExtensionLite, 123) - .AddExtension(UnitTestLiteProtoFile.PackedSfixed64ExtensionLite, 123) - .AddExtension(UnitTestLiteProtoFile.PackedSint32ExtensionLite, 123) - .AddExtension(UnitTestLiteProtoFile.PackedSint64ExtensionLite, 123) - .AddExtension(UnitTestLiteProtoFile.PackedUint32ExtensionLite, 123u) - .AddExtension(UnitTestLiteProtoFile.PackedUint64ExtensionLite, 123u) - .AddExtension(UnitTestLiteProtoFile.PackedBoolExtensionLite, true) - .AddExtension(UnitTestLiteProtoFile.PackedDoubleExtensionLite, 123) - .AddExtension(UnitTestLiteProtoFile.PackedFixed32ExtensionLite, 123u) - .AddExtension(UnitTestLiteProtoFile.PackedFixed64ExtensionLite, 123u) - .AddExtension(UnitTestLiteProtoFile.PackedFloatExtensionLite, 123) - .AddExtension(UnitTestLiteProtoFile.PackedInt32ExtensionLite, 123) - .AddExtension(UnitTestLiteProtoFile.PackedInt64ExtensionLite, 123) - .AddExtension(UnitTestLiteProtoFile.PackedSfixed32ExtensionLite, 123) - .AddExtension(UnitTestLiteProtoFile.PackedSfixed64ExtensionLite, 123) - .AddExtension(UnitTestLiteProtoFile.PackedSint32ExtensionLite, 123) - .AddExtension(UnitTestLiteProtoFile.PackedSint64ExtensionLite, 123) - .AddExtension(UnitTestLiteProtoFile.PackedUint32ExtensionLite, 123u) - .AddExtension(UnitTestLiteProtoFile.PackedUint64ExtensionLite, 123u); - - TestPackedExtensionsLite msg = builder.Build(); - - ExtensionRegistry registry = ExtensionRegistry.CreateInstance(); - UnitTestLiteProtoFile.RegisterAllExtensions(registry); - - TestPackedExtensionsLite.Builder copyBuilder = TestPackedExtensionsLite.CreateBuilder().MergeFrom(msg.ToByteArray(), registry); - TestPackedExtensionsLite copy = copyBuilder.Build(); - - Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray()); - - Assert.AreEqual(true, copy.GetExtension(UnitTestLiteProtoFile.PackedBoolExtensionLite, 0)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.PackedDoubleExtensionLite, 0)); - Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.PackedFixed32ExtensionLite, 0)); - Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.PackedFixed64ExtensionLite, 0)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.PackedFloatExtensionLite, 0)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.PackedInt32ExtensionLite, 0)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.PackedInt64ExtensionLite, 0)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.PackedSfixed32ExtensionLite, 0)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.PackedSfixed64ExtensionLite, 0)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.PackedSint32ExtensionLite, 0)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.PackedSint64ExtensionLite, 0)); - Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.PackedUint32ExtensionLite, 0)); - Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.PackedUint64ExtensionLite, 0)); - - Assert.AreEqual(true, copy.GetExtension(UnitTestLiteProtoFile.PackedBoolExtensionLite, 1)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.PackedDoubleExtensionLite, 1)); - Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.PackedFixed32ExtensionLite, 1)); - Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.PackedFixed64ExtensionLite, 1)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.PackedFloatExtensionLite, 1)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.PackedInt32ExtensionLite, 1)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.PackedInt64ExtensionLite, 1)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.PackedSfixed32ExtensionLite, 1)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.PackedSfixed64ExtensionLite, 1)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.PackedSint32ExtensionLite, 1)); - Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.PackedSint64ExtensionLite, 1)); - Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.PackedUint32ExtensionLite, 1)); - Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.PackedUint64ExtensionLite, 1)); - - } - } -} +#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.Text;
+using Google.ProtocolBuffers;
+using Google.ProtocolBuffers.TestProtos;
+using NUnit.Framework;
+
+namespace Google.ProtocolBuffers {
+ [TestFixture]
+ public class ExtendableMessageLiteTest {
+
+ [Test, Ignore("Not implemented, no assertion made"), ExpectedException(typeof(ArgumentException))]
+ public void ExtensionWriterInvalidExtension() {
+ TestPackedExtensionsLite.CreateBuilder()[UnitTestLiteProtoFile.OptionalForeignMessageExtensionLite.Descriptor] =
+ ForeignMessageLite.DefaultInstance;
+ }
+
+ [Test]
+ public void ExtensionWriterTestMessages() {
+ TestAllExtensionsLite.Builder b = TestAllExtensionsLite.CreateBuilder().SetExtension(
+ UnitTestLiteProtoFile.OptionalForeignMessageExtensionLite, ForeignMessageLite.CreateBuilder().SetC(123).Build());
+ TestAllExtensionsLite copy, msg = b.Build();
+
+ ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
+ UnitTestLiteProtoFile.RegisterAllExtensions(registry);
+
+ copy = TestAllExtensionsLite.ParseFrom(msg.ToByteArray(), registry);
+ Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
+ }
+
+ [Test]
+ public void ExtensionWriterIsInitialized() {
+ Assert.IsTrue(ForeignMessageLite.DefaultInstance.IsInitialized);
+ Assert.IsTrue(TestPackedExtensionsLite.CreateBuilder().IsInitialized);
+ Assert.IsTrue(TestAllExtensionsLite.CreateBuilder().SetExtension(
+ UnitTestLiteProtoFile.OptionalForeignMessageExtensionLite, ForeignMessageLite.DefaultInstance)
+ .IsInitialized);
+ }
+
+ [Test]
+ public void ExtensionWriterTestSetExtensionLists() {
+ TestAllExtensionsLite msg, copy;
+ TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
+ .SetExtension(UnitTestLiteProtoFile.RepeatedBoolExtensionLite, new[] { true, false })
+ .SetExtension(UnitTestLiteProtoFile.RepeatedCordExtensionLite, new[] { "123", "456" })
+ .SetExtension(UnitTestLiteProtoFile.RepeatedForeignEnumExtensionLite, new[] { ForeignEnumLite.FOREIGN_LITE_BAZ, ForeignEnumLite.FOREIGN_LITE_FOO })
+ ;
+
+ msg = builder.Build();
+ ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
+ UnitTestLiteProtoFile.RegisterAllExtensions(registry);
+
+ copy = TestAllExtensionsLite.ParseFrom(msg.ToByteArray(), registry);
+ Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
+
+ Assert.AreEqual(ForeignEnumLite.FOREIGN_LITE_FOO, copy.GetExtension(UnitTestLiteProtoFile.RepeatedForeignEnumExtensionLite, 1));
+ }
+
+ [Test]
+ public void ExtensionWriterTest() {
+ TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.CreateBuilder()
+ .SetExtension(UnitTestLiteProtoFile.DefaultBoolExtensionLite, true)
+ .SetExtension(UnitTestLiteProtoFile.DefaultBytesExtensionLite, ByteString.CopyFromUtf8("123"))
+ .SetExtension(UnitTestLiteProtoFile.DefaultCordExtensionLite, "123")
+ .SetExtension(UnitTestLiteProtoFile.DefaultDoubleExtensionLite, 123)
+ .SetExtension(UnitTestLiteProtoFile.DefaultFixed32ExtensionLite, 123u)
+ .SetExtension(UnitTestLiteProtoFile.DefaultFixed64ExtensionLite, 123u)
+ .SetExtension(UnitTestLiteProtoFile.DefaultFloatExtensionLite, 123)
+ .SetExtension(UnitTestLiteProtoFile.DefaultForeignEnumExtensionLite, ForeignEnumLite.FOREIGN_LITE_BAZ)
+ .SetExtension(UnitTestLiteProtoFile.DefaultImportEnumExtensionLite, ImportEnumLite.IMPORT_LITE_BAZ)
+ .SetExtension(UnitTestLiteProtoFile.DefaultInt32ExtensionLite, 123)
+ .SetExtension(UnitTestLiteProtoFile.DefaultInt64ExtensionLite, 123)
+ .SetExtension(UnitTestLiteProtoFile.DefaultNestedEnumExtensionLite, TestAllTypesLite.Types.NestedEnum.FOO)
+ .SetExtension(UnitTestLiteProtoFile.DefaultSfixed32ExtensionLite, 123)
+ .SetExtension(UnitTestLiteProtoFile.DefaultSfixed64ExtensionLite, 123)
+ .SetExtension(UnitTestLiteProtoFile.DefaultSint32ExtensionLite, 123)
+ .SetExtension(UnitTestLiteProtoFile.DefaultSint64ExtensionLite, 123)
+ .SetExtension(UnitTestLiteProtoFile.DefaultStringExtensionLite, "123")
+ .SetExtension(UnitTestLiteProtoFile.DefaultStringPieceExtensionLite, "123")
+ .SetExtension(UnitTestLiteProtoFile.DefaultUint32ExtensionLite, 123u)
+ .SetExtension(UnitTestLiteProtoFile.DefaultUint64ExtensionLite, 123u)
+ //Optional
+ .SetExtension(UnitTestLiteProtoFile.OptionalBoolExtensionLite, true)
+ .SetExtension(UnitTestLiteProtoFile.OptionalBytesExtensionLite, ByteString.CopyFromUtf8("123"))
+ .SetExtension(UnitTestLiteProtoFile.OptionalCordExtensionLite, "123")
+ .SetExtension(UnitTestLiteProtoFile.OptionalDoubleExtensionLite, 123)
+ .SetExtension(UnitTestLiteProtoFile.OptionalFixed32ExtensionLite, 123u)
+ .SetExtension(UnitTestLiteProtoFile.OptionalFixed64ExtensionLite, 123u)
+ .SetExtension(UnitTestLiteProtoFile.OptionalFloatExtensionLite, 123)
+ .SetExtension(UnitTestLiteProtoFile.OptionalForeignEnumExtensionLite, ForeignEnumLite.FOREIGN_LITE_BAZ)
+ .SetExtension(UnitTestLiteProtoFile.OptionalImportEnumExtensionLite, ImportEnumLite.IMPORT_LITE_BAZ)
+ .SetExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite, 123)
+ .SetExtension(UnitTestLiteProtoFile.OptionalInt64ExtensionLite, 123)
+ .SetExtension(UnitTestLiteProtoFile.OptionalNestedEnumExtensionLite, TestAllTypesLite.Types.NestedEnum.FOO)
+ .SetExtension(UnitTestLiteProtoFile.OptionalSfixed32ExtensionLite, 123)
+ .SetExtension(UnitTestLiteProtoFile.OptionalSfixed64ExtensionLite, 123)
+ .SetExtension(UnitTestLiteProtoFile.OptionalSint32ExtensionLite, 123)
+ .SetExtension(UnitTestLiteProtoFile.OptionalSint64ExtensionLite, 123)
+ .SetExtension(UnitTestLiteProtoFile.OptionalStringExtensionLite, "123")
+ .SetExtension(UnitTestLiteProtoFile.OptionalStringPieceExtensionLite, "123")
+ .SetExtension(UnitTestLiteProtoFile.OptionalUint32ExtensionLite, 123u)
+ .SetExtension(UnitTestLiteProtoFile.OptionalUint64ExtensionLite, 123u)
+ //Repeated
+ .AddExtension(UnitTestLiteProtoFile.RepeatedBoolExtensionLite, true)
+ .AddExtension(UnitTestLiteProtoFile.RepeatedBytesExtensionLite, ByteString.CopyFromUtf8("123"))
+ .AddExtension(UnitTestLiteProtoFile.RepeatedCordExtensionLite, "123")
+ .AddExtension(UnitTestLiteProtoFile.RepeatedDoubleExtensionLite, 123)
+ .AddExtension(UnitTestLiteProtoFile.RepeatedFixed32ExtensionLite, 123u)
+ .AddExtension(UnitTestLiteProtoFile.RepeatedFixed64ExtensionLite, 123u)
+ .AddExtension(UnitTestLiteProtoFile.RepeatedFloatExtensionLite, 123)
+ .AddExtension(UnitTestLiteProtoFile.RepeatedForeignEnumExtensionLite, ForeignEnumLite.FOREIGN_LITE_BAZ)
+ .AddExtension(UnitTestLiteProtoFile.RepeatedImportEnumExtensionLite, ImportEnumLite.IMPORT_LITE_BAZ)
+ .AddExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 123)
+ .AddExtension(UnitTestLiteProtoFile.RepeatedInt64ExtensionLite, 123)
+ .AddExtension(UnitTestLiteProtoFile.RepeatedNestedEnumExtensionLite, TestAllTypesLite.Types.NestedEnum.FOO)
+ .AddExtension(UnitTestLiteProtoFile.RepeatedSfixed32ExtensionLite, 123)
+ .AddExtension(UnitTestLiteProtoFile.RepeatedSfixed64ExtensionLite, 123)
+ .AddExtension(UnitTestLiteProtoFile.RepeatedSint32ExtensionLite, 123)
+ .AddExtension(UnitTestLiteProtoFile.RepeatedSint64ExtensionLite, 123)
+ .AddExtension(UnitTestLiteProtoFile.RepeatedStringExtensionLite, "123")
+ .AddExtension(UnitTestLiteProtoFile.RepeatedStringPieceExtensionLite, "123")
+ .AddExtension(UnitTestLiteProtoFile.RepeatedUint32ExtensionLite, 123u)
+ .AddExtension(UnitTestLiteProtoFile.RepeatedUint64ExtensionLite, 123u)
+ ;
+ TestAllExtensionsLite msg = builder.Build();
+
+ ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
+ UnitTestLiteProtoFile.RegisterAllExtensions(registry);
+
+ TestAllExtensionsLite.Builder copyBuilder = TestAllExtensionsLite.CreateBuilder().MergeFrom(msg.ToByteArray(), registry);
+ TestAllExtensionsLite copy = copyBuilder.Build();
+
+ Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
+
+ Assert.AreEqual(true, copy.GetExtension(UnitTestLiteProtoFile.DefaultBoolExtensionLite));
+ Assert.AreEqual(ByteString.CopyFromUtf8("123"), copy.GetExtension(UnitTestLiteProtoFile.DefaultBytesExtensionLite));
+ Assert.AreEqual("123", copy.GetExtension(UnitTestLiteProtoFile.DefaultCordExtensionLite));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.DefaultDoubleExtensionLite));
+ Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.DefaultFixed32ExtensionLite));
+ Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.DefaultFixed64ExtensionLite));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.DefaultFloatExtensionLite));
+ Assert.AreEqual(ForeignEnumLite.FOREIGN_LITE_BAZ, copy.GetExtension(UnitTestLiteProtoFile.DefaultForeignEnumExtensionLite));
+ Assert.AreEqual(ImportEnumLite.IMPORT_LITE_BAZ, copy.GetExtension(UnitTestLiteProtoFile.DefaultImportEnumExtensionLite));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.DefaultInt32ExtensionLite));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.DefaultInt64ExtensionLite));
+ Assert.AreEqual(TestAllTypesLite.Types.NestedEnum.FOO, copy.GetExtension(UnitTestLiteProtoFile.DefaultNestedEnumExtensionLite));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.DefaultSfixed32ExtensionLite));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.DefaultSfixed64ExtensionLite));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.DefaultSint32ExtensionLite));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.DefaultSint64ExtensionLite));
+ Assert.AreEqual("123", copy.GetExtension(UnitTestLiteProtoFile.DefaultStringExtensionLite));
+ Assert.AreEqual("123", copy.GetExtension(UnitTestLiteProtoFile.DefaultStringPieceExtensionLite));
+ Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.DefaultUint32ExtensionLite));
+ Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.DefaultUint64ExtensionLite));
+
+ Assert.AreEqual(true, copy.GetExtension(UnitTestLiteProtoFile.OptionalBoolExtensionLite));
+ Assert.AreEqual(ByteString.CopyFromUtf8("123"), copy.GetExtension(UnitTestLiteProtoFile.OptionalBytesExtensionLite));
+ Assert.AreEqual("123", copy.GetExtension(UnitTestLiteProtoFile.OptionalCordExtensionLite));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.OptionalDoubleExtensionLite));
+ Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.OptionalFixed32ExtensionLite));
+ Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.OptionalFixed64ExtensionLite));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.OptionalFloatExtensionLite));
+ Assert.AreEqual(ForeignEnumLite.FOREIGN_LITE_BAZ, copy.GetExtension(UnitTestLiteProtoFile.OptionalForeignEnumExtensionLite));
+ Assert.AreEqual(ImportEnumLite.IMPORT_LITE_BAZ, copy.GetExtension(UnitTestLiteProtoFile.OptionalImportEnumExtensionLite));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.OptionalInt64ExtensionLite));
+ Assert.AreEqual(TestAllTypesLite.Types.NestedEnum.FOO, copy.GetExtension(UnitTestLiteProtoFile.OptionalNestedEnumExtensionLite));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.OptionalSfixed32ExtensionLite));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.OptionalSfixed64ExtensionLite));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.OptionalSint32ExtensionLite));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.OptionalSint64ExtensionLite));
+ Assert.AreEqual("123", copy.GetExtension(UnitTestLiteProtoFile.OptionalStringExtensionLite));
+ Assert.AreEqual("123", copy.GetExtension(UnitTestLiteProtoFile.OptionalStringPieceExtensionLite));
+ Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.OptionalUint32ExtensionLite));
+ Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.OptionalUint64ExtensionLite));
+
+ Assert.AreEqual(true, copy.GetExtension(UnitTestLiteProtoFile.RepeatedBoolExtensionLite, 0));
+ Assert.AreEqual(ByteString.CopyFromUtf8("123"), copy.GetExtension(UnitTestLiteProtoFile.RepeatedBytesExtensionLite, 0));
+ Assert.AreEqual("123", copy.GetExtension(UnitTestLiteProtoFile.RepeatedCordExtensionLite, 0));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.RepeatedDoubleExtensionLite, 0));
+ Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.RepeatedFixed32ExtensionLite, 0));
+ Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.RepeatedFixed64ExtensionLite, 0));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.RepeatedFloatExtensionLite, 0));
+ Assert.AreEqual(ForeignEnumLite.FOREIGN_LITE_BAZ, copy.GetExtension(UnitTestLiteProtoFile.RepeatedForeignEnumExtensionLite, 0));
+ Assert.AreEqual(ImportEnumLite.IMPORT_LITE_BAZ, copy.GetExtension(UnitTestLiteProtoFile.RepeatedImportEnumExtensionLite, 0));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.RepeatedInt32ExtensionLite, 0));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.RepeatedInt64ExtensionLite, 0));
+ Assert.AreEqual(TestAllTypesLite.Types.NestedEnum.FOO, copy.GetExtension(UnitTestLiteProtoFile.RepeatedNestedEnumExtensionLite, 0));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.RepeatedSfixed32ExtensionLite, 0));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.RepeatedSfixed64ExtensionLite, 0));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.RepeatedSint32ExtensionLite, 0));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.RepeatedSint64ExtensionLite, 0));
+ Assert.AreEqual("123", copy.GetExtension(UnitTestLiteProtoFile.RepeatedStringExtensionLite, 0));
+ Assert.AreEqual("123", copy.GetExtension(UnitTestLiteProtoFile.RepeatedStringPieceExtensionLite, 0));
+ Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.RepeatedUint32ExtensionLite, 0));
+ Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.RepeatedUint64ExtensionLite, 0));
+ }
+
+ [Test]
+ public void ExtensionWriterTestPacked() {
+
+ TestPackedExtensionsLite.Builder builder = TestPackedExtensionsLite.CreateBuilder()
+ .AddExtension(UnitTestLiteProtoFile.PackedBoolExtensionLite, true)
+ .AddExtension(UnitTestLiteProtoFile.PackedDoubleExtensionLite, 123)
+ .AddExtension(UnitTestLiteProtoFile.PackedFixed32ExtensionLite, 123u)
+ .AddExtension(UnitTestLiteProtoFile.PackedFixed64ExtensionLite, 123u)
+ .AddExtension(UnitTestLiteProtoFile.PackedFloatExtensionLite, 123)
+ .AddExtension(UnitTestLiteProtoFile.PackedInt32ExtensionLite, 123)
+ .AddExtension(UnitTestLiteProtoFile.PackedInt64ExtensionLite, 123)
+ .AddExtension(UnitTestLiteProtoFile.PackedSfixed32ExtensionLite, 123)
+ .AddExtension(UnitTestLiteProtoFile.PackedSfixed64ExtensionLite, 123)
+ .AddExtension(UnitTestLiteProtoFile.PackedSint32ExtensionLite, 123)
+ .AddExtension(UnitTestLiteProtoFile.PackedSint64ExtensionLite, 123)
+ .AddExtension(UnitTestLiteProtoFile.PackedUint32ExtensionLite, 123u)
+ .AddExtension(UnitTestLiteProtoFile.PackedUint64ExtensionLite, 123u)
+ .AddExtension(UnitTestLiteProtoFile.PackedBoolExtensionLite, true)
+ .AddExtension(UnitTestLiteProtoFile.PackedDoubleExtensionLite, 123)
+ .AddExtension(UnitTestLiteProtoFile.PackedFixed32ExtensionLite, 123u)
+ .AddExtension(UnitTestLiteProtoFile.PackedFixed64ExtensionLite, 123u)
+ .AddExtension(UnitTestLiteProtoFile.PackedFloatExtensionLite, 123)
+ .AddExtension(UnitTestLiteProtoFile.PackedInt32ExtensionLite, 123)
+ .AddExtension(UnitTestLiteProtoFile.PackedInt64ExtensionLite, 123)
+ .AddExtension(UnitTestLiteProtoFile.PackedSfixed32ExtensionLite, 123)
+ .AddExtension(UnitTestLiteProtoFile.PackedSfixed64ExtensionLite, 123)
+ .AddExtension(UnitTestLiteProtoFile.PackedSint32ExtensionLite, 123)
+ .AddExtension(UnitTestLiteProtoFile.PackedSint64ExtensionLite, 123)
+ .AddExtension(UnitTestLiteProtoFile.PackedUint32ExtensionLite, 123u)
+ .AddExtension(UnitTestLiteProtoFile.PackedUint64ExtensionLite, 123u);
+
+ TestPackedExtensionsLite msg = builder.Build();
+
+ ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
+ UnitTestLiteProtoFile.RegisterAllExtensions(registry);
+
+ TestPackedExtensionsLite.Builder copyBuilder = TestPackedExtensionsLite.CreateBuilder().MergeFrom(msg.ToByteArray(), registry);
+ TestPackedExtensionsLite copy = copyBuilder.Build();
+
+ Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
+
+ Assert.AreEqual(true, copy.GetExtension(UnitTestLiteProtoFile.PackedBoolExtensionLite, 0));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.PackedDoubleExtensionLite, 0));
+ Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.PackedFixed32ExtensionLite, 0));
+ Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.PackedFixed64ExtensionLite, 0));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.PackedFloatExtensionLite, 0));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.PackedInt32ExtensionLite, 0));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.PackedInt64ExtensionLite, 0));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.PackedSfixed32ExtensionLite, 0));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.PackedSfixed64ExtensionLite, 0));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.PackedSint32ExtensionLite, 0));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.PackedSint64ExtensionLite, 0));
+ Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.PackedUint32ExtensionLite, 0));
+ Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.PackedUint64ExtensionLite, 0));
+
+ Assert.AreEqual(true, copy.GetExtension(UnitTestLiteProtoFile.PackedBoolExtensionLite, 1));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.PackedDoubleExtensionLite, 1));
+ Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.PackedFixed32ExtensionLite, 1));
+ Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.PackedFixed64ExtensionLite, 1));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.PackedFloatExtensionLite, 1));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.PackedInt32ExtensionLite, 1));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.PackedInt64ExtensionLite, 1));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.PackedSfixed32ExtensionLite, 1));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.PackedSfixed64ExtensionLite, 1));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.PackedSint32ExtensionLite, 1));
+ Assert.AreEqual(123, copy.GetExtension(UnitTestLiteProtoFile.PackedSint64ExtensionLite, 1));
+ Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.PackedUint32ExtensionLite, 1));
+ Assert.AreEqual(123u, copy.GetExtension(UnitTestLiteProtoFile.PackedUint64ExtensionLite, 1));
+
+ }
+ }
+}
diff --git a/src/ProtocolBuffersLite.Test/InteropLiteTest.cs b/src/ProtocolBuffersLite.Test/InteropLiteTest.cs index bd4dba59..48537e56 100644 --- a/src/ProtocolBuffersLite.Test/InteropLiteTest.cs +++ b/src/ProtocolBuffersLite.Test/InteropLiteTest.cs @@ -1,162 +1,162 @@ -#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; -using Google.ProtocolBuffers.TestProtos; -using NUnit.Framework; - -namespace Google.ProtocolBuffers { - [TestFixture] - public class InteropLiteTest { - - [Test] - public void TestConvertFromFullMinimal() { - TestInteropPerson person = TestInteropPerson.CreateBuilder() - .SetId(123) - .SetName("abc") - .Build(); - Assert.IsTrue(person.IsInitialized); - - TestInteropPersonLite copy = TestInteropPersonLite.ParseFrom(person.ToByteArray()); - - Assert.AreEqual(person.ToByteArray(), copy.ToByteArray()); - } - - [Test] - public void TestConvertFromFullComplete() { - TestInteropPerson person = TestInteropPerson.CreateBuilder() - .SetId(123) - .SetName("abc") - .SetEmail("abc@123.com") - .AddRangeCodes(new[] { 1, 2, 3 }) - .AddPhone(TestInteropPerson.Types.PhoneNumber.CreateBuilder().SetNumber("555-1234").Build()) - .AddPhone(TestInteropPerson.Types.PhoneNumber.CreateBuilder().SetNumber("555-5678").Build()) - .AddAddresses(TestInteropPerson.Types.Addresses.CreateBuilder().SetAddress("123 Seseme").SetCity("Wonderland").SetState("NA").SetZip(12345).Build()) - .SetExtension(UnitTestExtrasFullProtoFile.EmployeeId, TestInteropEmployeeId.CreateBuilder().SetNumber("123").Build()) - .Build(); - Assert.IsTrue(person.IsInitialized); - - ExtensionRegistry registry = ExtensionRegistry.CreateInstance(); - UnitTestExtrasLiteProtoFile.RegisterAllExtensions(registry); - - TestInteropPersonLite copy = TestInteropPersonLite.ParseFrom(person.ToByteArray(), registry); - - Assert.AreEqual(person.ToByteArray(), copy.ToByteArray()); - } - - [Test] - public void TestConvertFromLiteMinimal() { - TestInteropPersonLite person = TestInteropPersonLite.CreateBuilder() - .SetId(123) - .SetName("abc") - .Build(); - Assert.IsTrue(person.IsInitialized); - - TestInteropPerson copy = TestInteropPerson.ParseFrom(person.ToByteArray()); - - Assert.AreEqual(person.ToByteArray(), copy.ToByteArray()); - } - - [Test] - public void TestConvertFromLiteComplete() { - TestInteropPersonLite person = TestInteropPersonLite.CreateBuilder() - .SetId(123) - .SetName("abc") - .SetEmail("abc@123.com") - .AddRangeCodes(new[] { 1, 2, 3 }) - .AddPhone(TestInteropPersonLite.Types.PhoneNumber.CreateBuilder().SetNumber("555-1234").Build()) - .AddPhone(TestInteropPersonLite.Types.PhoneNumber.CreateBuilder().SetNumber("555-5678").Build()) - .AddAddresses(TestInteropPersonLite.Types.Addresses.CreateBuilder().SetAddress("123 Seseme").SetCity("Wonderland").SetState("NA").SetZip(12345).Build()) - .SetExtension(UnitTestExtrasLiteProtoFile.EmployeeIdLite, TestInteropEmployeeIdLite.CreateBuilder().SetNumber("123").Build()) - .Build(); - Assert.IsTrue(person.IsInitialized); - - ExtensionRegistry registry = ExtensionRegistry.CreateInstance(); - UnitTestExtrasFullProtoFile.RegisterAllExtensions(registry); - - TestInteropPerson copy = TestInteropPerson.ParseFrom(person.ToByteArray(), registry); - - Assert.AreEqual(person.ToByteArray(), copy.ToByteArray()); - } - - public ByteString AllBytes { - get { - byte[] bytes = new byte[256]; - for (int i = 0; i < bytes.Length; i++) - bytes[i] = (byte)i; - return ByteString.CopyFrom(bytes); - } - } - - [Test] - public void TestCompareStringValues() { - TestInteropPersonLite person = TestInteropPersonLite.CreateBuilder() - .SetId(123) - .SetName("abc") - .SetEmail("abc@123.com") - .AddRangeCodes(new[] { 1, 2, 3 }) - .AddPhone(TestInteropPersonLite.Types.PhoneNumber.CreateBuilder().SetNumber("555-1234").Build()) - .AddPhone(TestInteropPersonLite.Types.PhoneNumber.CreateBuilder().SetNumber(System.Text.Encoding.ASCII.GetString(AllBytes.ToByteArray())).Build()) - .AddAddresses(TestInteropPersonLite.Types.Addresses.CreateBuilder().SetAddress("123 Seseme").SetCity("Wonderland").SetState("NA").SetZip(12345).Build()) - .SetExtension(UnitTestExtrasLiteProtoFile.EmployeeIdLite, TestInteropEmployeeIdLite.CreateBuilder().SetNumber("123").Build()) - .Build(); - Assert.IsTrue(person.IsInitialized); - - ExtensionRegistry registry = ExtensionRegistry.CreateInstance(); - UnitTestExtrasFullProtoFile.RegisterAllExtensions(registry); - - TestInteropPerson copy = TestInteropPerson.ParseFrom(person.ToByteArray(), registry); - - Assert.AreEqual(person.ToByteArray(), copy.ToByteArray()); - - TestInteropPerson.Builder copyBuilder = TestInteropPerson.CreateBuilder(); - TextFormat.Merge(person.ToString().Replace("[protobuf_unittest_extra.employee_id_lite]", "[protobuf_unittest_extra.employee_id]"), registry, copyBuilder); - - copy = copyBuilder.Build(); - Assert.AreEqual(person.ToByteArray(), copy.ToByteArray()); - - string liteText = person.ToString().TrimEnd().Replace("\r", ""); - string fullText = copy.ToString().TrimEnd().Replace("\r", ""); - //map the extension type - liteText = liteText.Replace("[protobuf_unittest_extra.employee_id_lite]", "[protobuf_unittest_extra.employee_id]"); - //lite version does not indent - while (fullText.IndexOf("\n ") >= 0) - fullText = fullText.Replace("\n ", "\n"); - - Assert.AreEqual(fullText, liteText); - } - } -} +#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;
+using Google.ProtocolBuffers.TestProtos;
+using NUnit.Framework;
+
+namespace Google.ProtocolBuffers {
+ [TestFixture]
+ public class InteropLiteTest {
+
+ [Test]
+ public void TestConvertFromFullMinimal() {
+ TestInteropPerson person = TestInteropPerson.CreateBuilder()
+ .SetId(123)
+ .SetName("abc")
+ .Build();
+ Assert.IsTrue(person.IsInitialized);
+
+ TestInteropPersonLite copy = TestInteropPersonLite.ParseFrom(person.ToByteArray());
+
+ Assert.AreEqual(person.ToByteArray(), copy.ToByteArray());
+ }
+
+ [Test]
+ public void TestConvertFromFullComplete() {
+ TestInteropPerson person = TestInteropPerson.CreateBuilder()
+ .SetId(123)
+ .SetName("abc")
+ .SetEmail("abc@123.com")
+ .AddRangeCodes(new[] { 1, 2, 3 })
+ .AddPhone(TestInteropPerson.Types.PhoneNumber.CreateBuilder().SetNumber("555-1234").Build())
+ .AddPhone(TestInteropPerson.Types.PhoneNumber.CreateBuilder().SetNumber("555-5678").Build())
+ .AddAddresses(TestInteropPerson.Types.Addresses.CreateBuilder().SetAddress("123 Seseme").SetCity("Wonderland").SetState("NA").SetZip(12345).Build())
+ .SetExtension(UnitTestExtrasFullProtoFile.EmployeeId, TestInteropEmployeeId.CreateBuilder().SetNumber("123").Build())
+ .Build();
+ Assert.IsTrue(person.IsInitialized);
+
+ ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
+ UnitTestExtrasLiteProtoFile.RegisterAllExtensions(registry);
+
+ TestInteropPersonLite copy = TestInteropPersonLite.ParseFrom(person.ToByteArray(), registry);
+
+ Assert.AreEqual(person.ToByteArray(), copy.ToByteArray());
+ }
+
+ [Test]
+ public void TestConvertFromLiteMinimal() {
+ TestInteropPersonLite person = TestInteropPersonLite.CreateBuilder()
+ .SetId(123)
+ .SetName("abc")
+ .Build();
+ Assert.IsTrue(person.IsInitialized);
+
+ TestInteropPerson copy = TestInteropPerson.ParseFrom(person.ToByteArray());
+
+ Assert.AreEqual(person.ToByteArray(), copy.ToByteArray());
+ }
+
+ [Test]
+ public void TestConvertFromLiteComplete() {
+ TestInteropPersonLite person = TestInteropPersonLite.CreateBuilder()
+ .SetId(123)
+ .SetName("abc")
+ .SetEmail("abc@123.com")
+ .AddRangeCodes(new[] { 1, 2, 3 })
+ .AddPhone(TestInteropPersonLite.Types.PhoneNumber.CreateBuilder().SetNumber("555-1234").Build())
+ .AddPhone(TestInteropPersonLite.Types.PhoneNumber.CreateBuilder().SetNumber("555-5678").Build())
+ .AddAddresses(TestInteropPersonLite.Types.Addresses.CreateBuilder().SetAddress("123 Seseme").SetCity("Wonderland").SetState("NA").SetZip(12345).Build())
+ .SetExtension(UnitTestExtrasLiteProtoFile.EmployeeIdLite, TestInteropEmployeeIdLite.CreateBuilder().SetNumber("123").Build())
+ .Build();
+ Assert.IsTrue(person.IsInitialized);
+
+ ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
+ UnitTestExtrasFullProtoFile.RegisterAllExtensions(registry);
+
+ TestInteropPerson copy = TestInteropPerson.ParseFrom(person.ToByteArray(), registry);
+
+ Assert.AreEqual(person.ToByteArray(), copy.ToByteArray());
+ }
+
+ public ByteString AllBytes {
+ get {
+ byte[] bytes = new byte[256];
+ for (int i = 0; i < bytes.Length; i++)
+ bytes[i] = (byte)i;
+ return ByteString.CopyFrom(bytes);
+ }
+ }
+
+ [Test]
+ public void TestCompareStringValues() {
+ TestInteropPersonLite person = TestInteropPersonLite.CreateBuilder()
+ .SetId(123)
+ .SetName("abc")
+ .SetEmail("abc@123.com")
+ .AddRangeCodes(new[] { 1, 2, 3 })
+ .AddPhone(TestInteropPersonLite.Types.PhoneNumber.CreateBuilder().SetNumber("555-1234").Build())
+ .AddPhone(TestInteropPersonLite.Types.PhoneNumber.CreateBuilder().SetNumber(System.Text.Encoding.ASCII.GetString(AllBytes.ToByteArray())).Build())
+ .AddAddresses(TestInteropPersonLite.Types.Addresses.CreateBuilder().SetAddress("123 Seseme").SetCity("Wonderland").SetState("NA").SetZip(12345).Build())
+ .SetExtension(UnitTestExtrasLiteProtoFile.EmployeeIdLite, TestInteropEmployeeIdLite.CreateBuilder().SetNumber("123").Build())
+ .Build();
+ Assert.IsTrue(person.IsInitialized);
+
+ ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
+ UnitTestExtrasFullProtoFile.RegisterAllExtensions(registry);
+
+ TestInteropPerson copy = TestInteropPerson.ParseFrom(person.ToByteArray(), registry);
+
+ Assert.AreEqual(person.ToByteArray(), copy.ToByteArray());
+
+ TestInteropPerson.Builder copyBuilder = TestInteropPerson.CreateBuilder();
+ TextFormat.Merge(person.ToString().Replace("[protobuf_unittest_extra.employee_id_lite]", "[protobuf_unittest_extra.employee_id]"), registry, copyBuilder);
+
+ copy = copyBuilder.Build();
+ Assert.AreEqual(person.ToByteArray(), copy.ToByteArray());
+
+ string liteText = person.ToString().TrimEnd().Replace("\r", "");
+ string fullText = copy.ToString().TrimEnd().Replace("\r", "");
+ //map the extension type
+ liteText = liteText.Replace("[protobuf_unittest_extra.employee_id_lite]", "[protobuf_unittest_extra.employee_id]");
+ //lite version does not indent
+ while (fullText.IndexOf("\n ") >= 0)
+ fullText = fullText.Replace("\n ", "\n");
+
+ Assert.AreEqual(fullText, liteText);
+ }
+ }
+}
diff --git a/src/ProtocolBuffersLite.Test/LiteTest.cs b/src/ProtocolBuffersLite.Test/LiteTest.cs index df26053d..ca5c4bff 100644 --- a/src/ProtocolBuffersLite.Test/LiteTest.cs +++ b/src/ProtocolBuffersLite.Test/LiteTest.cs @@ -1,112 +1,112 @@ -#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.IO; -using Google.ProtocolBuffers.Descriptors; -using Google.ProtocolBuffers.TestProtos; -using NUnit.Framework; - -namespace Google.ProtocolBuffers { - /// <summary> - /// Miscellaneous tests for message operations that apply to both - /// generated and dynamic messages. - /// </summary> - [TestFixture] - public class LiteTest { - [Test] - public void TestLite() { - // Since lite messages are a subset of regular messages, we can mostly - // assume that the functionality of lite messages is already thoroughly - // tested by the regular tests. All this test really verifies is that - // a proto with optimize_for = LITE_RUNTIME compiles correctly when - // linked only against the lite library. That is all tested at compile - // time, leaving not much to do in this method. Let's just do some random - // stuff to make sure the lite message is actually here and usable. - - TestAllTypesLite message = - TestAllTypesLite.CreateBuilder() - .SetOptionalInt32(123) - .AddRepeatedString("hello") - .SetOptionalNestedMessage( - TestAllTypesLite.Types.NestedMessage.CreateBuilder().SetBb(7)) - .Build(); - - ByteString data = message.ToByteString(); - - TestAllTypesLite message2 = TestAllTypesLite.ParseFrom(data); - - Assert.AreEqual(123, message2.OptionalInt32); - Assert.AreEqual(1, message2.RepeatedStringCount); - Assert.AreEqual("hello", message2.RepeatedStringList[0]); - Assert.AreEqual(7, message2.OptionalNestedMessage.Bb); - } - - [Test] - public void TestLiteExtensions() { - // TODO(kenton): Unlike other features of the lite library, extensions are - // implemented completely differently from the regular library. We - // should probably test them more thoroughly. - - TestAllExtensionsLite message = - TestAllExtensionsLite.CreateBuilder() - .SetExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite, 123) - .AddExtension(UnitTestLiteProtoFile.RepeatedStringExtensionLite, "hello") - .SetExtension(UnitTestLiteProtoFile.OptionalNestedEnumExtensionLite, - TestAllTypesLite.Types.NestedEnum.BAZ) - .SetExtension(UnitTestLiteProtoFile.OptionalNestedMessageExtensionLite, - TestAllTypesLite.Types.NestedMessage.CreateBuilder().SetBb(7).Build()) - .Build(); - - // Test copying a message, since coping extensions actually does use a - // different code path between lite and regular libraries, and as of this - // writing, parsing hasn't been implemented yet. - TestAllExtensionsLite message2 = message.ToBuilder().Build(); - - Assert.AreEqual(123, (int)message2.GetExtension( - UnitTestLiteProtoFile.OptionalInt32ExtensionLite)); - Assert.AreEqual(1, message2.GetExtensionCount( - UnitTestLiteProtoFile.RepeatedStringExtensionLite)); - Assert.AreEqual(1, message2.GetExtension( - UnitTestLiteProtoFile.RepeatedStringExtensionLite).Count); - Assert.AreEqual("hello", message2.GetExtension( - UnitTestLiteProtoFile.RepeatedStringExtensionLite, 0)); - Assert.AreEqual(TestAllTypesLite.Types.NestedEnum.BAZ, message2.GetExtension( - UnitTestLiteProtoFile.OptionalNestedEnumExtensionLite)); - Assert.AreEqual(7, message2.GetExtension( - UnitTestLiteProtoFile.OptionalNestedMessageExtensionLite).Bb); - } - } +#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.IO;
+using Google.ProtocolBuffers.Descriptors;
+using Google.ProtocolBuffers.TestProtos;
+using NUnit.Framework;
+
+namespace Google.ProtocolBuffers {
+ /// <summary>
+ /// Miscellaneous tests for message operations that apply to both
+ /// generated and dynamic messages.
+ /// </summary>
+ [TestFixture]
+ public class LiteTest {
+ [Test]
+ public void TestLite() {
+ // Since lite messages are a subset of regular messages, we can mostly
+ // assume that the functionality of lite messages is already thoroughly
+ // tested by the regular tests. All this test really verifies is that
+ // a proto with optimize_for = LITE_RUNTIME compiles correctly when
+ // linked only against the lite library. That is all tested at compile
+ // time, leaving not much to do in this method. Let's just do some random
+ // stuff to make sure the lite message is actually here and usable.
+
+ TestAllTypesLite message =
+ TestAllTypesLite.CreateBuilder()
+ .SetOptionalInt32(123)
+ .AddRepeatedString("hello")
+ .SetOptionalNestedMessage(
+ TestAllTypesLite.Types.NestedMessage.CreateBuilder().SetBb(7))
+ .Build();
+
+ ByteString data = message.ToByteString();
+
+ TestAllTypesLite message2 = TestAllTypesLite.ParseFrom(data);
+
+ Assert.AreEqual(123, message2.OptionalInt32);
+ Assert.AreEqual(1, message2.RepeatedStringCount);
+ Assert.AreEqual("hello", message2.RepeatedStringList[0]);
+ Assert.AreEqual(7, message2.OptionalNestedMessage.Bb);
+ }
+
+ [Test]
+ public void TestLiteExtensions() {
+ // TODO(kenton): Unlike other features of the lite library, extensions are
+ // implemented completely differently from the regular library. We
+ // should probably test them more thoroughly.
+
+ TestAllExtensionsLite message =
+ TestAllExtensionsLite.CreateBuilder()
+ .SetExtension(UnitTestLiteProtoFile.OptionalInt32ExtensionLite, 123)
+ .AddExtension(UnitTestLiteProtoFile.RepeatedStringExtensionLite, "hello")
+ .SetExtension(UnitTestLiteProtoFile.OptionalNestedEnumExtensionLite,
+ TestAllTypesLite.Types.NestedEnum.BAZ)
+ .SetExtension(UnitTestLiteProtoFile.OptionalNestedMessageExtensionLite,
+ TestAllTypesLite.Types.NestedMessage.CreateBuilder().SetBb(7).Build())
+ .Build();
+
+ // Test copying a message, since coping extensions actually does use a
+ // different code path between lite and regular libraries, and as of this
+ // writing, parsing hasn't been implemented yet.
+ TestAllExtensionsLite message2 = message.ToBuilder().Build();
+
+ Assert.AreEqual(123, (int)message2.GetExtension(
+ UnitTestLiteProtoFile.OptionalInt32ExtensionLite));
+ Assert.AreEqual(1, message2.GetExtensionCount(
+ UnitTestLiteProtoFile.RepeatedStringExtensionLite));
+ Assert.AreEqual(1, message2.GetExtension(
+ UnitTestLiteProtoFile.RepeatedStringExtensionLite).Count);
+ Assert.AreEqual("hello", message2.GetExtension(
+ UnitTestLiteProtoFile.RepeatedStringExtensionLite, 0));
+ Assert.AreEqual(TestAllTypesLite.Types.NestedEnum.BAZ, message2.GetExtension(
+ UnitTestLiteProtoFile.OptionalNestedEnumExtensionLite));
+ Assert.AreEqual(7, message2.GetExtension(
+ UnitTestLiteProtoFile.OptionalNestedMessageExtensionLite).Bb);
+ }
+ }
}
\ No newline at end of file diff --git a/src/ProtocolBuffersLite.Test/MissingFieldAndExtensionTest.cs b/src/ProtocolBuffersLite.Test/MissingFieldAndExtensionTest.cs index b34f3af3..f43f709d 100644 --- a/src/ProtocolBuffersLite.Test/MissingFieldAndExtensionTest.cs +++ b/src/ProtocolBuffersLite.Test/MissingFieldAndExtensionTest.cs @@ -1,219 +1,219 @@ -#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.IO; -using NUnit.Framework; -using System.Collections.Generic; -using Google.ProtocolBuffers.TestProtos; - -namespace Google.ProtocolBuffers { - [TestFixture] - public class MissingFieldAndExtensionTest { - [Test] - public void TestRecoverMissingExtensions() { - const int optionalInt32 = 12345678; - TestAllExtensions.Builder builder = TestAllExtensions.CreateBuilder(); - builder.SetExtension(UnitTestProtoFile.OptionalInt32Extension, optionalInt32); - builder.AddExtension(UnitTestProtoFile.RepeatedDoubleExtension, 1.1); - builder.AddExtension(UnitTestProtoFile.RepeatedDoubleExtension, 1.2); - builder.AddExtension(UnitTestProtoFile.RepeatedDoubleExtension, 1.3); - TestAllExtensions msg = builder.Build(); - - Assert.IsTrue(msg.HasExtension(UnitTestProtoFile.OptionalInt32Extension)); - Assert.AreEqual(3, msg.GetExtensionCount(UnitTestProtoFile.RepeatedDoubleExtension)); - - byte[] bits = msg.ToByteArray(); - TestAllExtensions copy = TestAllExtensions.ParseFrom(bits); - Assert.IsFalse(copy.HasExtension(UnitTestProtoFile.OptionalInt32Extension)); - Assert.AreEqual(0, copy.GetExtensionCount(UnitTestProtoFile.RepeatedDoubleExtension)); - Assert.AreNotEqual(msg, copy); - - //Even though copy does not understand the typees they serialize correctly - byte[] copybits = copy.ToByteArray(); - Assert.AreEqual(bits, copybits); - - ExtensionRegistry registry = ExtensionRegistry.CreateInstance(); - UnitTestProtoFile.RegisterAllExtensions(registry); - - //Now we can take those copy bits and restore the full message with extensions - copy = TestAllExtensions.ParseFrom(copybits, registry); - Assert.IsTrue(copy.HasExtension(UnitTestProtoFile.OptionalInt32Extension)); - Assert.AreEqual(3, copy.GetExtensionCount(UnitTestProtoFile.RepeatedDoubleExtension)); - - Assert.AreEqual(msg, copy); - Assert.AreEqual(bits, copy.ToByteArray()); - - //If we modify the object this should all continue to work as before - copybits = copy.ToBuilder().Build().ToByteArray(); - Assert.AreEqual(bits, copybits); - - //If we replace extension the object this should all continue to work as before - copybits = copy.ToBuilder() - .SetExtension(UnitTestProtoFile.OptionalInt32Extension, optionalInt32) - .Build().ToByteArray(); - Assert.AreEqual(bits, copybits); - } - - [Test] - public void TestRecoverMissingFields() { - TestMissingFieldsA msga = TestMissingFieldsA.CreateBuilder() - .SetId(1001) - .SetName("Name") - .SetEmail("missing@field.value") - .Build(); - - //serialize to type B and verify all fields exist - TestMissingFieldsB msgb = TestMissingFieldsB.ParseFrom(msga.ToByteArray()); - Assert.AreEqual(1001, msgb.Id); - Assert.AreEqual("Name", msgb.Name); - Assert.IsFalse(msgb.HasWebsite); - Assert.AreEqual(1, msgb.UnknownFields.FieldDictionary.Count); - Assert.AreEqual("missing@field.value", msgb.UnknownFields[TestMissingFieldsA.EmailFieldNumber].LengthDelimitedList[0].ToStringUtf8()); - - //serializes exactly the same (at least for this simple example) - Assert.AreEqual(msga.ToByteArray(), msgb.ToByteArray()); - Assert.AreEqual(msga, TestMissingFieldsA.ParseFrom(msgb.ToByteArray())); - - //now re-create an exact copy of A from serialized B - TestMissingFieldsA copya = TestMissingFieldsA.ParseFrom(msgb.ToByteArray()); - Assert.AreEqual(msga, copya); - Assert.AreEqual(1001, copya.Id); - Assert.AreEqual("Name", copya.Name); - Assert.AreEqual("missing@field.value", copya.Email); - - //Now we modify B... and try again - msgb = msgb.ToBuilder().SetWebsite("http://new.missing.field").Build(); - //Does B still have the missing field? - Assert.AreEqual(1, msgb.UnknownFields.FieldDictionary.Count); - - //Convert back to A and see if all fields are there? - copya = TestMissingFieldsA.ParseFrom(msgb.ToByteArray()); - Assert.AreNotEqual(msga, copya); - Assert.AreEqual(1001, copya.Id); - Assert.AreEqual("Name", copya.Name); - Assert.AreEqual("missing@field.value", copya.Email); - Assert.AreEqual(1, copya.UnknownFields.FieldDictionary.Count); - Assert.AreEqual("http://new.missing.field", copya.UnknownFields[TestMissingFieldsB.WebsiteFieldNumber].LengthDelimitedList[0].ToStringUtf8()); - - //Lastly we can even still trip back to type B and see all fields: - TestMissingFieldsB copyb = TestMissingFieldsB.ParseFrom(copya.ToByteArray()); - Assert.AreEqual(copya.ToByteArray().Length, copyb.ToByteArray().Length); //not exact order. - Assert.AreEqual(1001, copyb.Id); - Assert.AreEqual("Name", copyb.Name); - Assert.AreEqual("http://new.missing.field", copyb.Website); - Assert.AreEqual(1, copyb.UnknownFields.FieldDictionary.Count); - Assert.AreEqual("missing@field.value", copyb.UnknownFields[TestMissingFieldsA.EmailFieldNumber].LengthDelimitedList[0].ToStringUtf8()); - } - - [Test] - public void TestRecoverMissingMessage() { - TestMissingFieldsA.Types.SubA suba = TestMissingFieldsA.Types.SubA.CreateBuilder().SetCount(3).AddValues("a").AddValues("b").AddValues("c").Build(); - TestMissingFieldsA msga = TestMissingFieldsA.CreateBuilder() - .SetId(1001) - .SetName("Name") - .SetTestA(suba) - .Build(); - - //serialize to type B and verify all fields exist - TestMissingFieldsB msgb = TestMissingFieldsB.ParseFrom(msga.ToByteArray()); - Assert.AreEqual(1001, msgb.Id); - Assert.AreEqual("Name", msgb.Name); - Assert.AreEqual(1, msgb.UnknownFields.FieldDictionary.Count); - Assert.AreEqual(suba.ToString(), TestMissingFieldsA.Types.SubA.ParseFrom(msgb.UnknownFields[TestMissingFieldsA.TestAFieldNumber].LengthDelimitedList[0]).ToString()); - - //serializes exactly the same (at least for this simple example) - Assert.AreEqual(msga.ToByteArray(), msgb.ToByteArray()); - Assert.AreEqual(msga, TestMissingFieldsA.ParseFrom(msgb.ToByteArray())); - - //now re-create an exact copy of A from serialized B - TestMissingFieldsA copya = TestMissingFieldsA.ParseFrom(msgb.ToByteArray()); - Assert.AreEqual(msga, copya); - Assert.AreEqual(1001, copya.Id); - Assert.AreEqual("Name", copya.Name); - Assert.AreEqual(suba, copya.TestA); - - //Now we modify B... and try again - TestMissingFieldsB.Types.SubB subb = TestMissingFieldsB.Types.SubB.CreateBuilder().AddValues("test-b").Build(); - msgb = msgb.ToBuilder().SetTestB(subb).Build(); - //Does B still have the missing field? - Assert.AreEqual(1, msgb.UnknownFields.FieldDictionary.Count); - - //Convert back to A and see if all fields are there? - copya = TestMissingFieldsA.ParseFrom(msgb.ToByteArray()); - Assert.AreNotEqual(msga, copya); - Assert.AreEqual(1001, copya.Id); - Assert.AreEqual("Name", copya.Name); - Assert.AreEqual(suba, copya.TestA); - Assert.AreEqual(1, copya.UnknownFields.FieldDictionary.Count); - Assert.AreEqual(subb.ToByteArray(), copya.UnknownFields[TestMissingFieldsB.TestBFieldNumber].LengthDelimitedList[0].ToByteArray()); - - //Lastly we can even still trip back to type B and see all fields: - TestMissingFieldsB copyb = TestMissingFieldsB.ParseFrom(copya.ToByteArray()); - Assert.AreEqual(copya.ToByteArray().Length, copyb.ToByteArray().Length); //not exact order. - Assert.AreEqual(1001, copyb.Id); - Assert.AreEqual("Name", copyb.Name); - Assert.AreEqual(subb, copyb.TestB); - Assert.AreEqual(1, copyb.UnknownFields.FieldDictionary.Count); - } - - [Test] - public void TestRestoreFromOtherType() { - TestInteropPerson person = TestInteropPerson.CreateBuilder() - .SetId(123) - .SetName("abc") - .SetEmail("abc@123.com") - .AddRangeCodes(new[] {1, 2, 3}) - .AddPhone(TestInteropPerson.Types.PhoneNumber.CreateBuilder().SetNumber("555-1234").Build()) - .AddPhone(TestInteropPerson.Types.PhoneNumber.CreateBuilder().SetNumber("555-5678").Build()) - .AddAddresses(TestInteropPerson.Types.Addresses.CreateBuilder().SetAddress("123 Seseme").SetCity("Wonderland").SetState("NA").SetZip(12345).Build()) - .SetExtension(UnitTestExtrasFullProtoFile.EmployeeId, TestInteropEmployeeId.CreateBuilder().SetNumber("123").Build()) - .Build(); - Assert.IsTrue(person.IsInitialized); - - TestEmptyMessage temp = TestEmptyMessage.ParseFrom(person.ToByteArray()); - Assert.AreEqual(7, temp.UnknownFields.FieldDictionary.Count); - temp = temp.ToBuilder().Build(); - Assert.AreEqual(7, temp.UnknownFields.FieldDictionary.Count); - - ExtensionRegistry registry = ExtensionRegistry.CreateInstance(); - UnitTestExtrasFullProtoFile.RegisterAllExtensions(registry); - - TestInteropPerson copy = TestInteropPerson.ParseFrom(temp.ToByteArray(), registry); - Assert.AreEqual(person, copy); - Assert.AreEqual(person.ToByteArray(), copy.ToByteArray()); - } - } +#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.IO;
+using NUnit.Framework;
+using System.Collections.Generic;
+using Google.ProtocolBuffers.TestProtos;
+
+namespace Google.ProtocolBuffers {
+ [TestFixture]
+ public class MissingFieldAndExtensionTest {
+ [Test]
+ public void TestRecoverMissingExtensions() {
+ const int optionalInt32 = 12345678;
+ TestAllExtensions.Builder builder = TestAllExtensions.CreateBuilder();
+ builder.SetExtension(UnitTestProtoFile.OptionalInt32Extension, optionalInt32);
+ builder.AddExtension(UnitTestProtoFile.RepeatedDoubleExtension, 1.1);
+ builder.AddExtension(UnitTestProtoFile.RepeatedDoubleExtension, 1.2);
+ builder.AddExtension(UnitTestProtoFile.RepeatedDoubleExtension, 1.3);
+ TestAllExtensions msg = builder.Build();
+
+ Assert.IsTrue(msg.HasExtension(UnitTestProtoFile.OptionalInt32Extension));
+ Assert.AreEqual(3, msg.GetExtensionCount(UnitTestProtoFile.RepeatedDoubleExtension));
+
+ byte[] bits = msg.ToByteArray();
+ TestAllExtensions copy = TestAllExtensions.ParseFrom(bits);
+ Assert.IsFalse(copy.HasExtension(UnitTestProtoFile.OptionalInt32Extension));
+ Assert.AreEqual(0, copy.GetExtensionCount(UnitTestProtoFile.RepeatedDoubleExtension));
+ Assert.AreNotEqual(msg, copy);
+
+ //Even though copy does not understand the typees they serialize correctly
+ byte[] copybits = copy.ToByteArray();
+ Assert.AreEqual(bits, copybits);
+
+ ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
+ UnitTestProtoFile.RegisterAllExtensions(registry);
+
+ //Now we can take those copy bits and restore the full message with extensions
+ copy = TestAllExtensions.ParseFrom(copybits, registry);
+ Assert.IsTrue(copy.HasExtension(UnitTestProtoFile.OptionalInt32Extension));
+ Assert.AreEqual(3, copy.GetExtensionCount(UnitTestProtoFile.RepeatedDoubleExtension));
+
+ Assert.AreEqual(msg, copy);
+ Assert.AreEqual(bits, copy.ToByteArray());
+
+ //If we modify the object this should all continue to work as before
+ copybits = copy.ToBuilder().Build().ToByteArray();
+ Assert.AreEqual(bits, copybits);
+
+ //If we replace extension the object this should all continue to work as before
+ copybits = copy.ToBuilder()
+ .SetExtension(UnitTestProtoFile.OptionalInt32Extension, optionalInt32)
+ .Build().ToByteArray();
+ Assert.AreEqual(bits, copybits);
+ }
+
+ [Test]
+ public void TestRecoverMissingFields() {
+ TestMissingFieldsA msga = TestMissingFieldsA.CreateBuilder()
+ .SetId(1001)
+ .SetName("Name")
+ .SetEmail("missing@field.value")
+ .Build();
+
+ //serialize to type B and verify all fields exist
+ TestMissingFieldsB msgb = TestMissingFieldsB.ParseFrom(msga.ToByteArray());
+ Assert.AreEqual(1001, msgb.Id);
+ Assert.AreEqual("Name", msgb.Name);
+ Assert.IsFalse(msgb.HasWebsite);
+ Assert.AreEqual(1, msgb.UnknownFields.FieldDictionary.Count);
+ Assert.AreEqual("missing@field.value", msgb.UnknownFields[TestMissingFieldsA.EmailFieldNumber].LengthDelimitedList[0].ToStringUtf8());
+
+ //serializes exactly the same (at least for this simple example)
+ Assert.AreEqual(msga.ToByteArray(), msgb.ToByteArray());
+ Assert.AreEqual(msga, TestMissingFieldsA.ParseFrom(msgb.ToByteArray()));
+
+ //now re-create an exact copy of A from serialized B
+ TestMissingFieldsA copya = TestMissingFieldsA.ParseFrom(msgb.ToByteArray());
+ Assert.AreEqual(msga, copya);
+ Assert.AreEqual(1001, copya.Id);
+ Assert.AreEqual("Name", copya.Name);
+ Assert.AreEqual("missing@field.value", copya.Email);
+
+ //Now we modify B... and try again
+ msgb = msgb.ToBuilder().SetWebsite("http://new.missing.field").Build();
+ //Does B still have the missing field?
+ Assert.AreEqual(1, msgb.UnknownFields.FieldDictionary.Count);
+
+ //Convert back to A and see if all fields are there?
+ copya = TestMissingFieldsA.ParseFrom(msgb.ToByteArray());
+ Assert.AreNotEqual(msga, copya);
+ Assert.AreEqual(1001, copya.Id);
+ Assert.AreEqual("Name", copya.Name);
+ Assert.AreEqual("missing@field.value", copya.Email);
+ Assert.AreEqual(1, copya.UnknownFields.FieldDictionary.Count);
+ Assert.AreEqual("http://new.missing.field", copya.UnknownFields[TestMissingFieldsB.WebsiteFieldNumber].LengthDelimitedList[0].ToStringUtf8());
+
+ //Lastly we can even still trip back to type B and see all fields:
+ TestMissingFieldsB copyb = TestMissingFieldsB.ParseFrom(copya.ToByteArray());
+ Assert.AreEqual(copya.ToByteArray().Length, copyb.ToByteArray().Length); //not exact order.
+ Assert.AreEqual(1001, copyb.Id);
+ Assert.AreEqual("Name", copyb.Name);
+ Assert.AreEqual("http://new.missing.field", copyb.Website);
+ Assert.AreEqual(1, copyb.UnknownFields.FieldDictionary.Count);
+ Assert.AreEqual("missing@field.value", copyb.UnknownFields[TestMissingFieldsA.EmailFieldNumber].LengthDelimitedList[0].ToStringUtf8());
+ }
+
+ [Test]
+ public void TestRecoverMissingMessage() {
+ TestMissingFieldsA.Types.SubA suba = TestMissingFieldsA.Types.SubA.CreateBuilder().SetCount(3).AddValues("a").AddValues("b").AddValues("c").Build();
+ TestMissingFieldsA msga = TestMissingFieldsA.CreateBuilder()
+ .SetId(1001)
+ .SetName("Name")
+ .SetTestA(suba)
+ .Build();
+
+ //serialize to type B and verify all fields exist
+ TestMissingFieldsB msgb = TestMissingFieldsB.ParseFrom(msga.ToByteArray());
+ Assert.AreEqual(1001, msgb.Id);
+ Assert.AreEqual("Name", msgb.Name);
+ Assert.AreEqual(1, msgb.UnknownFields.FieldDictionary.Count);
+ Assert.AreEqual(suba.ToString(), TestMissingFieldsA.Types.SubA.ParseFrom(msgb.UnknownFields[TestMissingFieldsA.TestAFieldNumber].LengthDelimitedList[0]).ToString());
+
+ //serializes exactly the same (at least for this simple example)
+ Assert.AreEqual(msga.ToByteArray(), msgb.ToByteArray());
+ Assert.AreEqual(msga, TestMissingFieldsA.ParseFrom(msgb.ToByteArray()));
+
+ //now re-create an exact copy of A from serialized B
+ TestMissingFieldsA copya = TestMissingFieldsA.ParseFrom(msgb.ToByteArray());
+ Assert.AreEqual(msga, copya);
+ Assert.AreEqual(1001, copya.Id);
+ Assert.AreEqual("Name", copya.Name);
+ Assert.AreEqual(suba, copya.TestA);
+
+ //Now we modify B... and try again
+ TestMissingFieldsB.Types.SubB subb = TestMissingFieldsB.Types.SubB.CreateBuilder().AddValues("test-b").Build();
+ msgb = msgb.ToBuilder().SetTestB(subb).Build();
+ //Does B still have the missing field?
+ Assert.AreEqual(1, msgb.UnknownFields.FieldDictionary.Count);
+
+ //Convert back to A and see if all fields are there?
+ copya = TestMissingFieldsA.ParseFrom(msgb.ToByteArray());
+ Assert.AreNotEqual(msga, copya);
+ Assert.AreEqual(1001, copya.Id);
+ Assert.AreEqual("Name", copya.Name);
+ Assert.AreEqual(suba, copya.TestA);
+ Assert.AreEqual(1, copya.UnknownFields.FieldDictionary.Count);
+ Assert.AreEqual(subb.ToByteArray(), copya.UnknownFields[TestMissingFieldsB.TestBFieldNumber].LengthDelimitedList[0].ToByteArray());
+
+ //Lastly we can even still trip back to type B and see all fields:
+ TestMissingFieldsB copyb = TestMissingFieldsB.ParseFrom(copya.ToByteArray());
+ Assert.AreEqual(copya.ToByteArray().Length, copyb.ToByteArray().Length); //not exact order.
+ Assert.AreEqual(1001, copyb.Id);
+ Assert.AreEqual("Name", copyb.Name);
+ Assert.AreEqual(subb, copyb.TestB);
+ Assert.AreEqual(1, copyb.UnknownFields.FieldDictionary.Count);
+ }
+
+ [Test]
+ public void TestRestoreFromOtherType() {
+ TestInteropPerson person = TestInteropPerson.CreateBuilder()
+ .SetId(123)
+ .SetName("abc")
+ .SetEmail("abc@123.com")
+ .AddRangeCodes(new[] {1, 2, 3})
+ .AddPhone(TestInteropPerson.Types.PhoneNumber.CreateBuilder().SetNumber("555-1234").Build())
+ .AddPhone(TestInteropPerson.Types.PhoneNumber.CreateBuilder().SetNumber("555-5678").Build())
+ .AddAddresses(TestInteropPerson.Types.Addresses.CreateBuilder().SetAddress("123 Seseme").SetCity("Wonderland").SetState("NA").SetZip(12345).Build())
+ .SetExtension(UnitTestExtrasFullProtoFile.EmployeeId, TestInteropEmployeeId.CreateBuilder().SetNumber("123").Build())
+ .Build();
+ Assert.IsTrue(person.IsInitialized);
+
+ TestEmptyMessage temp = TestEmptyMessage.ParseFrom(person.ToByteArray());
+ Assert.AreEqual(7, temp.UnknownFields.FieldDictionary.Count);
+ temp = temp.ToBuilder().Build();
+ Assert.AreEqual(7, temp.UnknownFields.FieldDictionary.Count);
+
+ ExtensionRegistry registry = ExtensionRegistry.CreateInstance();
+ UnitTestExtrasFullProtoFile.RegisterAllExtensions(registry);
+
+ TestInteropPerson copy = TestInteropPerson.ParseFrom(temp.ToByteArray(), registry);
+ Assert.AreEqual(person, copy);
+ Assert.AreEqual(person.ToByteArray(), copy.ToByteArray());
+ }
+ }
}
\ No newline at end of file diff --git a/src/ProtocolBuffersLite.Test/ProtocolBuffersLite.Test.csproj b/src/ProtocolBuffersLite.Test/ProtocolBuffersLite.Test.csproj index 079855e9..2b8fe7ce 100644 --- a/src/ProtocolBuffersLite.Test/ProtocolBuffersLite.Test.csproj +++ b/src/ProtocolBuffersLite.Test/ProtocolBuffersLite.Test.csproj @@ -1,84 +1,84 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <PropertyGroup> - <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> - <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> - <ProductVersion>9.0.30729</ProductVersion> - <SchemaVersion>2.0</SchemaVersion> - <ProjectGuid>{EE01ED24-3750-4567-9A23-1DB676A15610}</ProjectGuid> - <OutputType>Library</OutputType> - <AppDesignerFolder>Properties</AppDesignerFolder> - <RootNamespace>Google.ProtocolBuffers</RootNamespace> - <AssemblyName>Google.ProtocolBuffersLite.Test</AssemblyName> - <TargetFrameworkVersion>v2.0</TargetFrameworkVersion> - <FileAlignment>512</FileAlignment> - <SignAssembly>true</SignAssembly> - <AssemblyOriginatorKeyFile>..\..\keys\Google.ProtocolBuffers.snk</AssemblyOriginatorKeyFile> - <FileUpgradeFlags> - </FileUpgradeFlags> - <OldToolsVersion>3.5</OldToolsVersion> - <UpgradeBackupLocation /> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> - <DebugSymbols>true</DebugSymbols> - <DebugType>full</DebugType> - <Optimize>false</Optimize> - <OutputPath>bin\Debug\</OutputPath> - <DefineConstants>DEBUG;TRACE</DefineConstants> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - <NoStdLib>true</NoStdLib> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> - <DebugType>pdbonly</DebugType> - <Optimize>true</Optimize> - <OutputPath>bin\Release\</OutputPath> - <DefineConstants>TRACE</DefineConstants> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - <NoStdLib>true</NoStdLib> - </PropertyGroup> - <ItemGroup> - <Reference Include="nunit.framework, Version=2.2.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77"> - <SpecificVersion>False</SpecificVersion> - <HintPath>..\..\lib\NUnit 2.2.8.0\nunit.framework.dll</HintPath> - </Reference> - <Reference Include="Rhino.Mocks, Version=3.5.0.2, Culture=neutral, PublicKeyToken=0b3305902db7183f, processorArchitecture=MSIL"> - <SpecificVersion>False</SpecificVersion> - <HintPath>..\..\lib\Rhino.Mocks.dll</HintPath> - </Reference> - <Reference Include="mscorlib" /> - <Reference Include="System" /> - <Reference Include="System.Data" /> - <Reference Include="System.Xml" /> - </ItemGroup> - <ItemGroup> - <Compile Include="..\ProtocolBuffers.Test\Properties\AssemblyInfo.cs"> - <Link>Properties\AssemblyInfo.cs</Link> - </Compile> - <Compile Include="AbstractBuilderLiteTest.cs" /> - <Compile Include="AbstractMessageLiteTest.cs" /> - <Compile Include="ExtendableBuilderLiteTest.cs" /> - <Compile Include="ExtendableMessageLiteTest.cs" /> - <Compile Include="LiteTest.cs" /> - <Compile Include="TestLiteByApi.cs" /> - <Compile Include="TestProtos\UnitTestExtrasLiteProtoFile.cs" /> - <Compile Include="TestProtos\UnitTestImportLiteProtoFile.cs" /> - <Compile Include="TestProtos\UnitTestLiteProtoFile.cs" /> - </ItemGroup> - <ItemGroup> - <ProjectReference Include="..\ProtocolBuffers\ProtocolBuffersLite.csproj"> - <Project>{6969BDCE-D925-43F3-94AC-A531E6DF2591}</Project> - <Name>ProtocolBuffersLite</Name> - <Private>True</Private> - </ProjectReference> - </ItemGroup> - <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> - <!-- To modify your build process, add your task inside one of the targets below and uncomment it. - Other similar extension points exist, see Microsoft.Common.targets. - <Target Name="BeforeBuild"> - </Target> - <Target Name="AfterBuild"> - </Target> - --> +<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.30729</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{EE01ED24-3750-4567-9A23-1DB676A15610}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Google.ProtocolBuffers</RootNamespace>
+ <AssemblyName>Google.ProtocolBuffersLite.Test</AssemblyName>
+ <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <SignAssembly>true</SignAssembly>
+ <AssemblyOriginatorKeyFile>..\..\keys\Google.ProtocolBuffers.snk</AssemblyOriginatorKeyFile>
+ <FileUpgradeFlags>
+ </FileUpgradeFlags>
+ <OldToolsVersion>3.5</OldToolsVersion>
+ <UpgradeBackupLocation />
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ <NoStdLib>true</NoStdLib>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="nunit.framework, Version=2.2.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\lib\NUnit 2.2.8.0\nunit.framework.dll</HintPath>
+ </Reference>
+ <Reference Include="Rhino.Mocks, Version=3.5.0.2, Culture=neutral, PublicKeyToken=0b3305902db7183f, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\lib\Rhino.Mocks.dll</HintPath>
+ </Reference>
+ <Reference Include="mscorlib" />
+ <Reference Include="System" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="..\ProtocolBuffers.Test\Properties\AssemblyInfo.cs">
+ <Link>Properties\AssemblyInfo.cs</Link>
+ </Compile>
+ <Compile Include="AbstractBuilderLiteTest.cs" />
+ <Compile Include="AbstractMessageLiteTest.cs" />
+ <Compile Include="ExtendableBuilderLiteTest.cs" />
+ <Compile Include="ExtendableMessageLiteTest.cs" />
+ <Compile Include="LiteTest.cs" />
+ <Compile Include="TestLiteByApi.cs" />
+ <Compile Include="TestProtos\UnitTestExtrasLiteProtoFile.cs" />
+ <Compile Include="TestProtos\UnitTestImportLiteProtoFile.cs" />
+ <Compile Include="TestProtos\UnitTestLiteProtoFile.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\ProtocolBuffers\ProtocolBuffersLite.csproj">
+ <Project>{6969BDCE-D925-43F3-94AC-A531E6DF2591}</Project>
+ <Name>ProtocolBuffersLite</Name>
+ <Private>True</Private>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
</Project>
\ No newline at end of file diff --git a/src/ProtocolBuffersLite.Test/ProtocolBuffersLiteMixed.Test.csproj b/src/ProtocolBuffersLite.Test/ProtocolBuffersLiteMixed.Test.csproj index 64296c9b..d61d6651 100644 --- a/src/ProtocolBuffersLite.Test/ProtocolBuffersLiteMixed.Test.csproj +++ b/src/ProtocolBuffersLite.Test/ProtocolBuffersLiteMixed.Test.csproj @@ -1,89 +1,89 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <PropertyGroup> - <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> - <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> - <ProductVersion>9.0.30729</ProductVersion> - <SchemaVersion>2.0</SchemaVersion> - <ProjectGuid>{EEFFED24-3750-4567-9A23-1DB676A15610}</ProjectGuid> - <OutputType>Library</OutputType> - <AppDesignerFolder>Properties</AppDesignerFolder> - <RootNamespace>Google.ProtocolBuffers</RootNamespace> - <AssemblyName>Google.ProtocolBuffersMixedLite.Test</AssemblyName> - <TargetFrameworkVersion>v2.0</TargetFrameworkVersion> - <FileAlignment>512</FileAlignment> - <SignAssembly>true</SignAssembly> - <AssemblyOriginatorKeyFile>..\..\keys\Google.ProtocolBuffers.snk</AssemblyOriginatorKeyFile> - <FileUpgradeFlags> - </FileUpgradeFlags> - <OldToolsVersion>3.5</OldToolsVersion> - <UpgradeBackupLocation /> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> - <DebugSymbols>true</DebugSymbols> - <DebugType>full</DebugType> - <Optimize>false</Optimize> - <OutputPath>bin\Debug\</OutputPath> - <DefineConstants>DEBUG;TRACE</DefineConstants> - <ErrorReport>prompt</ErrorReport> - <NoStdLib>true</NoStdLib> - <WarningLevel>4</WarningLevel> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> - <DebugType>pdbonly</DebugType> - <Optimize>true</Optimize> - <OutputPath>bin\Release\</OutputPath> - <DefineConstants>TRACE</DefineConstants> - <ErrorReport>prompt</ErrorReport> - <NoStdLib>true</NoStdLib> - <WarningLevel>4</WarningLevel> - </PropertyGroup> - <ItemGroup> - <Reference Include="nunit.framework, Version=2.2.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77"> - <SpecificVersion>False</SpecificVersion> - <HintPath>..\..\lib\NUnit 2.2.8.0\nunit.framework.dll</HintPath> - </Reference> - <Reference Include="Rhino.Mocks, Version=3.5.0.2, Culture=neutral, PublicKeyToken=0b3305902db7183f, processorArchitecture=MSIL"> - <SpecificVersion>False</SpecificVersion> - <HintPath>..\..\lib\Rhino.Mocks.dll</HintPath> - </Reference> - <Reference Include="mscorlib" /> - <Reference Include="System" /> - <Reference Include="System.Data" /> - <Reference Include="System.Xml" /> - </ItemGroup> - <ItemGroup> - <Compile Include="..\ProtocolBuffers.Test\Properties\AssemblyInfo.cs"> - <Link>Properties\AssemblyInfo.cs</Link> - </Compile> - <Compile Include="AbstractBuilderLiteTest.cs" /> - <Compile Include="AbstractMessageLiteTest.cs" /> - <Compile Include="ExtendableBuilderLiteTest.cs" /> - <Compile Include="ExtendableMessageLiteTest.cs" /> - <Compile Include="InteropLiteTest.cs" /> - <Compile Include="LiteTest.cs" /> - <Compile Include="MissingFieldAndExtensionTest.cs" /> - <Compile Include="TestLiteByApi.cs" /> - <Compile Include="TestProtos\UnitTestExtrasFullProtoFile.cs" /> - <Compile Include="TestProtos\UnitTestExtrasLiteProtoFile.cs" /> - <Compile Include="TestProtos\UnitTestImportLiteProtoFile.cs" /> - <Compile Include="TestProtos\UnitTestImportProtoFile.cs" /> - <Compile Include="TestProtos\UnitTestLiteImportNonLiteProtoFile.cs" /> - <Compile Include="TestProtos\UnitTestLiteProtoFile.cs" /> - <Compile Include="TestProtos\UnitTestProtoFile.cs" /> - </ItemGroup> - <ItemGroup> - <ProjectReference Include="..\ProtocolBuffers\ProtocolBuffers.csproj"> - <Project>{6908BDCE-D925-43F3-94AC-A531E6DF2591}</Project> - <Name>ProtocolBuffers</Name> - </ProjectReference> - </ItemGroup> - <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> - <!-- To modify your build process, add your task inside one of the targets below and uncomment it. - Other similar extension points exist, see Microsoft.Common.targets. - <Target Name="BeforeBuild"> - </Target> - <Target Name="AfterBuild"> - </Target> - --> +<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.30729</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{EEFFED24-3750-4567-9A23-1DB676A15610}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Google.ProtocolBuffers</RootNamespace>
+ <AssemblyName>Google.ProtocolBuffersMixedLite.Test</AssemblyName>
+ <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <SignAssembly>true</SignAssembly>
+ <AssemblyOriginatorKeyFile>..\..\keys\Google.ProtocolBuffers.snk</AssemblyOriginatorKeyFile>
+ <FileUpgradeFlags>
+ </FileUpgradeFlags>
+ <OldToolsVersion>3.5</OldToolsVersion>
+ <UpgradeBackupLocation />
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <NoStdLib>true</NoStdLib>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <NoStdLib>true</NoStdLib>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="nunit.framework, Version=2.2.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\lib\NUnit 2.2.8.0\nunit.framework.dll</HintPath>
+ </Reference>
+ <Reference Include="Rhino.Mocks, Version=3.5.0.2, Culture=neutral, PublicKeyToken=0b3305902db7183f, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\lib\Rhino.Mocks.dll</HintPath>
+ </Reference>
+ <Reference Include="mscorlib" />
+ <Reference Include="System" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="..\ProtocolBuffers.Test\Properties\AssemblyInfo.cs">
+ <Link>Properties\AssemblyInfo.cs</Link>
+ </Compile>
+ <Compile Include="AbstractBuilderLiteTest.cs" />
+ <Compile Include="AbstractMessageLiteTest.cs" />
+ <Compile Include="ExtendableBuilderLiteTest.cs" />
+ <Compile Include="ExtendableMessageLiteTest.cs" />
+ <Compile Include="InteropLiteTest.cs" />
+ <Compile Include="LiteTest.cs" />
+ <Compile Include="MissingFieldAndExtensionTest.cs" />
+ <Compile Include="TestLiteByApi.cs" />
+ <Compile Include="TestProtos\UnitTestExtrasFullProtoFile.cs" />
+ <Compile Include="TestProtos\UnitTestExtrasLiteProtoFile.cs" />
+ <Compile Include="TestProtos\UnitTestImportLiteProtoFile.cs" />
+ <Compile Include="TestProtos\UnitTestImportProtoFile.cs" />
+ <Compile Include="TestProtos\UnitTestLiteImportNonLiteProtoFile.cs" />
+ <Compile Include="TestProtos\UnitTestLiteProtoFile.cs" />
+ <Compile Include="TestProtos\UnitTestProtoFile.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\ProtocolBuffers\ProtocolBuffers.csproj">
+ <Project>{6908BDCE-D925-43F3-94AC-A531E6DF2591}</Project>
+ <Name>ProtocolBuffers</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
</Project>
\ No newline at end of file diff --git a/src/ProtocolBuffersLite.Test/TestLiteByApi.cs b/src/ProtocolBuffersLite.Test/TestLiteByApi.cs index f3d8fd50..5fc00a45 100644 --- a/src/ProtocolBuffersLite.Test/TestLiteByApi.cs +++ b/src/ProtocolBuffersLite.Test/TestLiteByApi.cs @@ -1,113 +1,113 @@ -#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 Google.ProtocolBuffers.TestProtos; -using NUnit.Framework; - -namespace Google.ProtocolBuffers { - [TestFixture] - public class TestLiteByApi { - - [Test] - public void TestAllTypesEquality() { - TestAllTypesLite msg = TestAllTypesLite.DefaultInstance; - TestAllTypesLite copy = msg.ToBuilder().Build(); - Assert.AreEqual(msg.GetHashCode(), copy.GetHashCode()); - Assert.IsTrue(msg.Equals(copy)); - msg = msg.ToBuilder().SetOptionalString("Hi").Build(); - Assert.AreNotEqual(msg.GetHashCode(), copy.GetHashCode()); - Assert.IsFalse(msg.Equals(copy)); - copy = copy.ToBuilder().SetOptionalString("Hi").Build(); - Assert.AreEqual(msg.GetHashCode(), copy.GetHashCode()); - Assert.IsTrue(msg.Equals(copy)); - } - - [Test] - public void TestEqualityOnExtensions() { - TestAllExtensionsLite msg = TestAllExtensionsLite.DefaultInstance; - TestAllExtensionsLite copy = msg.ToBuilder().Build(); - Assert.AreEqual(msg.GetHashCode(), copy.GetHashCode()); - Assert.IsTrue(msg.Equals(copy)); - msg = msg.ToBuilder().SetExtension(UnitTestLiteProtoFile.OptionalStringExtensionLite, "Hi").Build(); - Assert.AreNotEqual(msg.GetHashCode(), copy.GetHashCode()); - Assert.IsFalse(msg.Equals(copy)); - copy = copy.ToBuilder().SetExtension(UnitTestLiteProtoFile.OptionalStringExtensionLite, "Hi").Build(); - Assert.AreEqual(msg.GetHashCode(), copy.GetHashCode()); - Assert.IsTrue(msg.Equals(copy)); - } - - [Test] - public void TestAllTypesToString() { - TestAllTypesLite msg = TestAllTypesLite.DefaultInstance; - TestAllTypesLite copy = msg.ToBuilder().Build(); - Assert.AreEqual(msg.ToString(), copy.ToString()); - Assert.IsEmpty(msg.ToString()); - msg = msg.ToBuilder().SetOptionalInt32(-1).Build(); - Assert.AreEqual("optional_int32: -1", msg.ToString().TrimEnd()); - msg = msg.ToBuilder().SetOptionalString("abc123").Build(); - Assert.AreEqual("optional_int32: -1\noptional_string: \"abc123\"", msg.ToString().Replace("\r", "").TrimEnd()); - } - - [Test] - public void TestAllTypesDefaultedRoundTrip() { - TestAllTypesLite msg = TestAllTypesLite.DefaultInstance; - Assert.IsTrue(msg.IsInitialized); - TestAllTypesLite copy = TestAllTypesLite.CreateBuilder().MergeFrom(msg.ToByteArray()).Build(); - Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray()); - } - - [Test] - public void TestAllTypesModifiedRoundTrip() { - TestAllTypesLite msg = TestAllTypesLite.DefaultInstance; - msg.ToBuilder() - .SetOptionalBool(true) - .SetOptionalCord("Hi") - .SetOptionalDouble(1.123) - .SetOptionalForeignEnum(ForeignEnumLite.FOREIGN_LITE_FOO) - .SetOptionalForeignMessage(ForeignMessageLite.CreateBuilder().SetC('c').Build()) - .SetOptionalGroup(TestAllTypesLite.Types.OptionalGroup.CreateBuilder().SetA('a').Build()) - .SetOptionalImportEnum(ImportEnumLite.IMPORT_LITE_BAR) - .SetOptionalInt32(32) - .SetOptionalInt64(64) - .SetOptionalNestedEnum(TestAllTypesLite.Types.NestedEnum.FOO) - .SetOptionalString("SetOptionalString") - .AddRepeatedGroup(TestAllTypesLite.Types.RepeatedGroup.CreateBuilder().SetA('a').Build()) - .AddRepeatedGroup(TestAllTypesLite.Types.RepeatedGroup.CreateBuilder().SetA('A').Build()) - ; - TestAllTypesLite copy = TestAllTypesLite.CreateBuilder().MergeFrom(msg.ToByteArray()).Build(); - Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray()); - } - - } -} +#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 Google.ProtocolBuffers.TestProtos;
+using NUnit.Framework;
+
+namespace Google.ProtocolBuffers {
+ [TestFixture]
+ public class TestLiteByApi {
+
+ [Test]
+ public void TestAllTypesEquality() {
+ TestAllTypesLite msg = TestAllTypesLite.DefaultInstance;
+ TestAllTypesLite copy = msg.ToBuilder().Build();
+ Assert.AreEqual(msg.GetHashCode(), copy.GetHashCode());
+ Assert.IsTrue(msg.Equals(copy));
+ msg = msg.ToBuilder().SetOptionalString("Hi").Build();
+ Assert.AreNotEqual(msg.GetHashCode(), copy.GetHashCode());
+ Assert.IsFalse(msg.Equals(copy));
+ copy = copy.ToBuilder().SetOptionalString("Hi").Build();
+ Assert.AreEqual(msg.GetHashCode(), copy.GetHashCode());
+ Assert.IsTrue(msg.Equals(copy));
+ }
+
+ [Test]
+ public void TestEqualityOnExtensions() {
+ TestAllExtensionsLite msg = TestAllExtensionsLite.DefaultInstance;
+ TestAllExtensionsLite copy = msg.ToBuilder().Build();
+ Assert.AreEqual(msg.GetHashCode(), copy.GetHashCode());
+ Assert.IsTrue(msg.Equals(copy));
+ msg = msg.ToBuilder().SetExtension(UnitTestLiteProtoFile.OptionalStringExtensionLite, "Hi").Build();
+ Assert.AreNotEqual(msg.GetHashCode(), copy.GetHashCode());
+ Assert.IsFalse(msg.Equals(copy));
+ copy = copy.ToBuilder().SetExtension(UnitTestLiteProtoFile.OptionalStringExtensionLite, "Hi").Build();
+ Assert.AreEqual(msg.GetHashCode(), copy.GetHashCode());
+ Assert.IsTrue(msg.Equals(copy));
+ }
+
+ [Test]
+ public void TestAllTypesToString() {
+ TestAllTypesLite msg = TestAllTypesLite.DefaultInstance;
+ TestAllTypesLite copy = msg.ToBuilder().Build();
+ Assert.AreEqual(msg.ToString(), copy.ToString());
+ Assert.IsEmpty(msg.ToString());
+ msg = msg.ToBuilder().SetOptionalInt32(-1).Build();
+ Assert.AreEqual("optional_int32: -1", msg.ToString().TrimEnd());
+ msg = msg.ToBuilder().SetOptionalString("abc123").Build();
+ Assert.AreEqual("optional_int32: -1\noptional_string: \"abc123\"", msg.ToString().Replace("\r", "").TrimEnd());
+ }
+
+ [Test]
+ public void TestAllTypesDefaultedRoundTrip() {
+ TestAllTypesLite msg = TestAllTypesLite.DefaultInstance;
+ Assert.IsTrue(msg.IsInitialized);
+ TestAllTypesLite copy = TestAllTypesLite.CreateBuilder().MergeFrom(msg.ToByteArray()).Build();
+ Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
+ }
+
+ [Test]
+ public void TestAllTypesModifiedRoundTrip() {
+ TestAllTypesLite msg = TestAllTypesLite.DefaultInstance;
+ msg.ToBuilder()
+ .SetOptionalBool(true)
+ .SetOptionalCord("Hi")
+ .SetOptionalDouble(1.123)
+ .SetOptionalForeignEnum(ForeignEnumLite.FOREIGN_LITE_FOO)
+ .SetOptionalForeignMessage(ForeignMessageLite.CreateBuilder().SetC('c').Build())
+ .SetOptionalGroup(TestAllTypesLite.Types.OptionalGroup.CreateBuilder().SetA('a').Build())
+ .SetOptionalImportEnum(ImportEnumLite.IMPORT_LITE_BAR)
+ .SetOptionalInt32(32)
+ .SetOptionalInt64(64)
+ .SetOptionalNestedEnum(TestAllTypesLite.Types.NestedEnum.FOO)
+ .SetOptionalString("SetOptionalString")
+ .AddRepeatedGroup(TestAllTypesLite.Types.RepeatedGroup.CreateBuilder().SetA('a').Build())
+ .AddRepeatedGroup(TestAllTypesLite.Types.RepeatedGroup.CreateBuilder().SetA('A').Build())
+ ;
+ TestAllTypesLite copy = TestAllTypesLite.CreateBuilder().MergeFrom(msg.ToByteArray()).Build();
+ Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
+ }
+
+ }
+}
diff --git a/src/ProtocolBuffersLite.Test/TestProtos/UnitTestExtrasLiteProtoFile.cs b/src/ProtocolBuffersLite.Test/TestProtos/UnitTestExtrasLiteProtoFile.cs index 82492165..f01da226 100644 --- a/src/ProtocolBuffersLite.Test/TestProtos/UnitTestExtrasLiteProtoFile.cs +++ b/src/ProtocolBuffersLite.Test/TestProtos/UnitTestExtrasLiteProtoFile.cs @@ -1,1721 +1,1721 @@ -// 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 UnitTestExtrasLiteProtoFile { - - #region Extension registration - public static void RegisterAllExtensions(pb::ExtensionRegistry registry) { - registry.Add(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasLiteProtoFile.EmployeeIdLite); - } - #endregion - #region Extensions - public const int EmployeeIdLiteFieldNumber = 126; - public static pb::GeneratedExtensionLite<global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite, global::Google.ProtocolBuffers.TestProtos.TestInteropEmployeeIdLite> EmployeeIdLite; - #endregion - - #region Static variables - #endregion - #region Extensions - internal static readonly object Descriptor; - static UnitTestExtrasLiteProtoFile() { - Descriptor = null; - global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasLiteProtoFile.EmployeeIdLite = - new pb::GeneratedExtensionLite<global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite, global::Google.ProtocolBuffers.TestProtos.TestInteropEmployeeIdLite>( - "protobuf_unittest_extra.employee_id_lite", - global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.DefaultInstance, - null, - global::Google.ProtocolBuffers.TestProtos.TestInteropEmployeeIdLite.DefaultInstance, - null, - global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasLiteProtoFile.EmployeeIdLiteFieldNumber, - pbd::FieldType.Message); - } - #endregion - - } - #region Enums - public enum ExtraEnum { - DEFAULT = 10, - EXLITE_FOO = 7, - EXLITE_BAR = 8, - EXLITE_BAZ = 9, - } - - #endregion - - #region Messages - public sealed partial class TestRequiredLite : pb::GeneratedMessageLite<TestRequiredLite, TestRequiredLite.Builder> { - private static readonly TestRequiredLite defaultInstance = new Builder().BuildPartial(); - public static TestRequiredLite DefaultInstance { - get { return defaultInstance; } - } - - public override TestRequiredLite DefaultInstanceForType { - get { return defaultInstance; } - } - - protected override TestRequiredLite 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 const int EnFieldNumber = 2; - private bool hasEn; - private global::Google.ProtocolBuffers.TestProtos.ExtraEnum en_ = global::Google.ProtocolBuffers.TestProtos.ExtraEnum.DEFAULT; - public bool HasEn { - get { return hasEn; } - } - public global::Google.ProtocolBuffers.TestProtos.ExtraEnum En { - get { return en_; } - } - - public override bool IsInitialized { - get { - if (!hasD) return false; - if (!hasEn) return false; - return true; - } - } - - public override void WriteTo(pb::CodedOutputStream output) { - int size = SerializedSize; - if (HasD) { - output.WriteInt32(1, D); - } - if (HasEn) { - output.WriteEnum(2, (int) En); - } - } - - 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); - } - if (HasEn) { - size += pb::CodedOutputStream.ComputeEnumSize(2, (int) En); - } - memoizedSerializedSize = size; - return size; - } - } - - #region Lite runtime methods - public override int GetHashCode() { - int hash = GetType().GetHashCode(); - if (hasD) hash ^= d_.GetHashCode(); - if (hasEn) hash ^= en_.GetHashCode(); - return hash; - } - - public override bool Equals(object obj) { - TestRequiredLite other = obj as TestRequiredLite; - if (other == null) return false; - if (hasD != other.hasD || (hasD && !d_.Equals(other.d_))) return false; - if (hasEn != other.hasEn || (hasEn && !en_.Equals(other.en_))) return false; - return true; - } - - public override void PrintTo(global::System.IO.TextWriter writer) { - PrintField("d", hasD, d_, writer); - PrintField("en", hasEn, en_, writer); - } - #endregion - - public static TestRequiredLite ParseFrom(pb::ByteString data) { - return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed(); - } - public static TestRequiredLite ParseFrom(pb::ByteString data, pb::ExtensionRegistry extensionRegistry) { - return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed(); - } - public static TestRequiredLite ParseFrom(byte[] data) { - return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed(); - } - public static TestRequiredLite ParseFrom(byte[] data, pb::ExtensionRegistry extensionRegistry) { - return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed(); - } - public static TestRequiredLite ParseFrom(global::System.IO.Stream input) { - return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed(); - } - public static TestRequiredLite ParseFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) { - return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed(); - } - public static TestRequiredLite ParseDelimitedFrom(global::System.IO.Stream input) { - return CreateBuilder().MergeDelimitedFrom(input).BuildParsed(); - } - public static TestRequiredLite ParseDelimitedFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) { - return CreateBuilder().MergeDelimitedFrom(input, extensionRegistry).BuildParsed(); - } - public static TestRequiredLite ParseFrom(pb::CodedInputStream input) { - return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed(); - } - public static TestRequiredLite 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(TestRequiredLite prototype) { - return (Builder) new Builder().MergeFrom(prototype); - } - - public sealed partial class Builder : pb::GeneratedBuilderLite<TestRequiredLite, Builder> { - protected override Builder ThisBuilder { - get { return this; } - } - public Builder() {} - - TestRequiredLite result = new TestRequiredLite(); - - protected override TestRequiredLite MessageBeingBuilt { - get { return result; } - } - - public override Builder Clear() { - result = new TestRequiredLite(); - return this; - } - - public override Builder Clone() { - return new Builder().MergeFrom(result); - } - - public override TestRequiredLite DefaultInstanceForType { - get { return global::Google.ProtocolBuffers.TestProtos.TestRequiredLite.DefaultInstance; } - } - - public override TestRequiredLite BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); - } - TestRequiredLite returnMe = result; - result = null; - return returnMe; - } - - public override Builder MergeFrom(pb::IMessageLite other) { - if (other is TestRequiredLite) { - return MergeFrom((TestRequiredLite) other); - } else { - base.MergeFrom(other); - return this; - } - } - - public override Builder MergeFrom(TestRequiredLite other) { - if (other == global::Google.ProtocolBuffers.TestProtos.TestRequiredLite.DefaultInstance) return this; - if (other.HasD) { - D = other.D; - } - if (other.HasEn) { - En = other.En; - } - 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; - } - case 16: { - int rawValue = input.ReadEnum(); - if (!global::System.Enum.IsDefined(typeof(global::Google.ProtocolBuffers.TestProtos.ExtraEnum), rawValue)) { - } else { - En = (global::Google.ProtocolBuffers.TestProtos.ExtraEnum) rawValue; - } - 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; - } - - public bool HasEn { - get { return result.HasEn; } - } - public global::Google.ProtocolBuffers.TestProtos.ExtraEnum En { - get { return result.En; } - set { SetEn(value); } - } - public Builder SetEn(global::Google.ProtocolBuffers.TestProtos.ExtraEnum value) { - result.hasEn = true; - result.en_ = value; - return this; - } - public Builder ClearEn() { - result.hasEn = false; - result.en_ = global::Google.ProtocolBuffers.TestProtos.ExtraEnum.DEFAULT; - return this; - } - } - static TestRequiredLite() { - object.ReferenceEquals(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasLiteProtoFile.Descriptor, null); - } - } - - public sealed partial class TestInteropPersonLite : pb::ExtendableMessageLite<TestInteropPersonLite, TestInteropPersonLite.Builder> { - private static readonly TestInteropPersonLite defaultInstance = new Builder().BuildPartial(); - public static TestInteropPersonLite DefaultInstance { - get { return defaultInstance; } - } - - public override TestInteropPersonLite DefaultInstanceForType { - get { return defaultInstance; } - } - - protected override TestInteropPersonLite ThisMessage { - get { return this; } - } - - #region Nested types - public static class Types { - public enum PhoneType { - MOBILE = 0, - HOME = 1, - WORK = 2, - } - - public sealed partial class PhoneNumber : pb::GeneratedMessageLite<PhoneNumber, PhoneNumber.Builder> { - private static readonly PhoneNumber defaultInstance = new Builder().BuildPartial(); - public static PhoneNumber DefaultInstance { - get { return defaultInstance; } - } - - public override PhoneNumber DefaultInstanceForType { - get { return defaultInstance; } - } - - protected override PhoneNumber ThisMessage { - get { return this; } - } - - public const int NumberFieldNumber = 1; - private bool hasNumber; - private string number_ = ""; - public bool HasNumber { - get { return hasNumber; } - } - public string Number { - get { return number_; } - } - - public const int TypeFieldNumber = 2; - private bool hasType; - private global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneType type_ = global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneType.HOME; - public bool HasType { - get { return hasType; } - } - public global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneType Type { - get { return type_; } - } - - public override bool IsInitialized { - get { - if (!hasNumber) return false; - return true; - } - } - - public override void WriteTo(pb::CodedOutputStream output) { - int size = SerializedSize; - if (HasNumber) { - output.WriteString(1, Number); - } - if (HasType) { - output.WriteEnum(2, (int) Type); - } - } - - private int memoizedSerializedSize = -1; - public override int SerializedSize { - get { - int size = memoizedSerializedSize; - if (size != -1) return size; - - size = 0; - if (HasNumber) { - size += pb::CodedOutputStream.ComputeStringSize(1, Number); - } - if (HasType) { - size += pb::CodedOutputStream.ComputeEnumSize(2, (int) Type); - } - memoizedSerializedSize = size; - return size; - } - } - - #region Lite runtime methods - public override int GetHashCode() { - int hash = GetType().GetHashCode(); - if (hasNumber) hash ^= number_.GetHashCode(); - if (hasType) hash ^= type_.GetHashCode(); - return hash; - } - - public override bool Equals(object obj) { - PhoneNumber other = obj as PhoneNumber; - if (other == null) return false; - if (hasNumber != other.hasNumber || (hasNumber && !number_.Equals(other.number_))) return false; - if (hasType != other.hasType || (hasType && !type_.Equals(other.type_))) return false; - return true; - } - - public override void PrintTo(global::System.IO.TextWriter writer) { - PrintField("number", hasNumber, number_, writer); - PrintField("type", hasType, type_, writer); - } - #endregion - - public static PhoneNumber ParseFrom(pb::ByteString data) { - return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed(); - } - public static PhoneNumber ParseFrom(pb::ByteString data, pb::ExtensionRegistry extensionRegistry) { - return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed(); - } - public static PhoneNumber ParseFrom(byte[] data) { - return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed(); - } - public static PhoneNumber ParseFrom(byte[] data, pb::ExtensionRegistry extensionRegistry) { - return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed(); - } - public static PhoneNumber ParseFrom(global::System.IO.Stream input) { - return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed(); - } - public static PhoneNumber ParseFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) { - return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed(); - } - public static PhoneNumber ParseDelimitedFrom(global::System.IO.Stream input) { - return CreateBuilder().MergeDelimitedFrom(input).BuildParsed(); - } - public static PhoneNumber ParseDelimitedFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) { - return CreateBuilder().MergeDelimitedFrom(input, extensionRegistry).BuildParsed(); - } - public static PhoneNumber ParseFrom(pb::CodedInputStream input) { - return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed(); - } - public static PhoneNumber 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(PhoneNumber prototype) { - return (Builder) new Builder().MergeFrom(prototype); - } - - public sealed partial class Builder : pb::GeneratedBuilderLite<PhoneNumber, Builder> { - protected override Builder ThisBuilder { - get { return this; } - } - public Builder() {} - - PhoneNumber result = new PhoneNumber(); - - protected override PhoneNumber MessageBeingBuilt { - get { return result; } - } - - public override Builder Clear() { - result = new PhoneNumber(); - return this; - } - - public override Builder Clone() { - return new Builder().MergeFrom(result); - } - - public override PhoneNumber DefaultInstanceForType { - get { return global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber.DefaultInstance; } - } - - public override PhoneNumber BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); - } - PhoneNumber returnMe = result; - result = null; - return returnMe; - } - - public override Builder MergeFrom(pb::IMessageLite other) { - if (other is PhoneNumber) { - return MergeFrom((PhoneNumber) other); - } else { - base.MergeFrom(other); - return this; - } - } - - public override Builder MergeFrom(PhoneNumber other) { - if (other == global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber.DefaultInstance) return this; - if (other.HasNumber) { - Number = other.Number; - } - if (other.HasType) { - Type = other.Type; - } - 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: { - Number = input.ReadString(); - break; - } - case 16: { - int rawValue = input.ReadEnum(); - if (!global::System.Enum.IsDefined(typeof(global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneType), rawValue)) { - } else { - Type = (global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneType) rawValue; - } - break; - } - } - } - } - - - public bool HasNumber { - get { return result.HasNumber; } - } - public string Number { - get { return result.Number; } - set { SetNumber(value); } - } - public Builder SetNumber(string value) { - pb::ThrowHelper.ThrowIfNull(value, "value"); - result.hasNumber = true; - result.number_ = value; - return this; - } - public Builder ClearNumber() { - result.hasNumber = false; - result.number_ = ""; - return this; - } - - public bool HasType { - get { return result.HasType; } - } - public global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneType Type { - get { return result.Type; } - set { SetType(value); } - } - public Builder SetType(global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneType value) { - result.hasType = true; - result.type_ = value; - return this; - } - public Builder ClearType() { - result.hasType = false; - result.type_ = global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneType.HOME; - return this; - } - } - static PhoneNumber() { - object.ReferenceEquals(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasLiteProtoFile.Descriptor, null); - } - } - - public sealed partial class Addresses : pb::GeneratedMessageLite<Addresses, Addresses.Builder> { - private static readonly Addresses defaultInstance = new Builder().BuildPartial(); - public static Addresses DefaultInstance { - get { return defaultInstance; } - } - - public override Addresses DefaultInstanceForType { - get { return defaultInstance; } - } - - protected override Addresses ThisMessage { - get { return this; } - } - - public const int AddressFieldNumber = 1; - private bool hasAddress; - private string address_ = ""; - public bool HasAddress { - get { return hasAddress; } - } - public string Address { - get { return address_; } - } - - public const int Address2FieldNumber = 2; - private bool hasAddress2; - private string address2_ = ""; - public bool HasAddress2 { - get { return hasAddress2; } - } - public string Address2 { - get { return address2_; } - } - - public const int CityFieldNumber = 3; - private bool hasCity; - private string city_ = ""; - public bool HasCity { - get { return hasCity; } - } - public string City { - get { return city_; } - } - - public const int StateFieldNumber = 4; - private bool hasState; - private string state_ = ""; - public bool HasState { - get { return hasState; } - } - public string State { - get { return state_; } - } - - public const int ZipFieldNumber = 5; - private bool hasZip; - private uint zip_ = 0; - public bool HasZip { - get { return hasZip; } - } - [global::System.CLSCompliant(false)] - public uint Zip { - get { return zip_; } - } - - public override bool IsInitialized { - get { - if (!hasAddress) return false; - if (!hasCity) return false; - if (!hasState) return false; - if (!hasZip) return false; - return true; - } - } - - public override void WriteTo(pb::CodedOutputStream output) { - int size = SerializedSize; - if (HasAddress) { - output.WriteString(1, Address); - } - if (HasAddress2) { - output.WriteString(2, Address2); - } - if (HasCity) { - output.WriteString(3, City); - } - if (HasState) { - output.WriteString(4, State); - } - if (HasZip) { - output.WriteFixed32(5, Zip); - } - } - - private int memoizedSerializedSize = -1; - public override int SerializedSize { - get { - int size = memoizedSerializedSize; - if (size != -1) return size; - - size = 0; - if (HasAddress) { - size += pb::CodedOutputStream.ComputeStringSize(1, Address); - } - if (HasAddress2) { - size += pb::CodedOutputStream.ComputeStringSize(2, Address2); - } - if (HasCity) { - size += pb::CodedOutputStream.ComputeStringSize(3, City); - } - if (HasState) { - size += pb::CodedOutputStream.ComputeStringSize(4, State); - } - if (HasZip) { - size += pb::CodedOutputStream.ComputeFixed32Size(5, Zip); - } - memoizedSerializedSize = size; - return size; - } - } - - #region Lite runtime methods - public override int GetHashCode() { - int hash = GetType().GetHashCode(); - if (hasAddress) hash ^= address_.GetHashCode(); - if (hasAddress2) hash ^= address2_.GetHashCode(); - if (hasCity) hash ^= city_.GetHashCode(); - if (hasState) hash ^= state_.GetHashCode(); - if (hasZip) hash ^= zip_.GetHashCode(); - return hash; - } - - public override bool Equals(object obj) { - Addresses other = obj as Addresses; - if (other == null) return false; - if (hasAddress != other.hasAddress || (hasAddress && !address_.Equals(other.address_))) return false; - if (hasAddress2 != other.hasAddress2 || (hasAddress2 && !address2_.Equals(other.address2_))) return false; - if (hasCity != other.hasCity || (hasCity && !city_.Equals(other.city_))) return false; - if (hasState != other.hasState || (hasState && !state_.Equals(other.state_))) return false; - if (hasZip != other.hasZip || (hasZip && !zip_.Equals(other.zip_))) return false; - return true; - } - - public override void PrintTo(global::System.IO.TextWriter writer) { - PrintField("address", hasAddress, address_, writer); - PrintField("address2", hasAddress2, address2_, writer); - PrintField("city", hasCity, city_, writer); - PrintField("state", hasState, state_, writer); - PrintField("zip", hasZip, zip_, writer); - } - #endregion - - public static Addresses ParseFrom(pb::ByteString data) { - return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed(); - } - public static Addresses ParseFrom(pb::ByteString data, pb::ExtensionRegistry extensionRegistry) { - return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed(); - } - public static Addresses ParseFrom(byte[] data) { - return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed(); - } - public static Addresses ParseFrom(byte[] data, pb::ExtensionRegistry extensionRegistry) { - return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed(); - } - public static Addresses ParseFrom(global::System.IO.Stream input) { - return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed(); - } - public static Addresses ParseFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) { - return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed(); - } - public static Addresses ParseDelimitedFrom(global::System.IO.Stream input) { - return CreateBuilder().MergeDelimitedFrom(input).BuildParsed(); - } - public static Addresses ParseDelimitedFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) { - return CreateBuilder().MergeDelimitedFrom(input, extensionRegistry).BuildParsed(); - } - public static Addresses ParseFrom(pb::CodedInputStream input) { - return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed(); - } - public static Addresses 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(Addresses prototype) { - return (Builder) new Builder().MergeFrom(prototype); - } - - public sealed partial class Builder : pb::GeneratedBuilderLite<Addresses, Builder> { - protected override Builder ThisBuilder { - get { return this; } - } - public Builder() {} - - Addresses result = new Addresses(); - - protected override Addresses MessageBeingBuilt { - get { return result; } - } - - public override Builder Clear() { - result = new Addresses(); - return this; - } - - public override Builder Clone() { - return new Builder().MergeFrom(result); - } - - public override Addresses DefaultInstanceForType { - get { return global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses.DefaultInstance; } - } - - public override Addresses BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); - } - Addresses returnMe = result; - result = null; - return returnMe; - } - - public override Builder MergeFrom(pb::IMessageLite other) { - if (other is Addresses) { - return MergeFrom((Addresses) other); - } else { - base.MergeFrom(other); - return this; - } - } - - public override Builder MergeFrom(Addresses other) { - if (other == global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses.DefaultInstance) return this; - if (other.HasAddress) { - Address = other.Address; - } - if (other.HasAddress2) { - Address2 = other.Address2; - } - if (other.HasCity) { - City = other.City; - } - if (other.HasState) { - State = other.State; - } - if (other.HasZip) { - Zip = other.Zip; - } - 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: { - Address = input.ReadString(); - break; - } - case 18: { - Address2 = input.ReadString(); - break; - } - case 26: { - City = input.ReadString(); - break; - } - case 34: { - State = input.ReadString(); - break; - } - case 45: { - Zip = input.ReadFixed32(); - break; - } - } - } - } - - - public bool HasAddress { - get { return result.HasAddress; } - } - public string Address { - get { return result.Address; } - set { SetAddress(value); } - } - public Builder SetAddress(string value) { - pb::ThrowHelper.ThrowIfNull(value, "value"); - result.hasAddress = true; - result.address_ = value; - return this; - } - public Builder ClearAddress() { - result.hasAddress = false; - result.address_ = ""; - return this; - } - - public bool HasAddress2 { - get { return result.HasAddress2; } - } - public string Address2 { - get { return result.Address2; } - set { SetAddress2(value); } - } - public Builder SetAddress2(string value) { - pb::ThrowHelper.ThrowIfNull(value, "value"); - result.hasAddress2 = true; - result.address2_ = value; - return this; - } - public Builder ClearAddress2() { - result.hasAddress2 = false; - result.address2_ = ""; - return this; - } - - public bool HasCity { - get { return result.HasCity; } - } - public string City { - get { return result.City; } - set { SetCity(value); } - } - public Builder SetCity(string value) { - pb::ThrowHelper.ThrowIfNull(value, "value"); - result.hasCity = true; - result.city_ = value; - return this; - } - public Builder ClearCity() { - result.hasCity = false; - result.city_ = ""; - return this; - } - - public bool HasState { - get { return result.HasState; } - } - public string State { - get { return result.State; } - set { SetState(value); } - } - public Builder SetState(string value) { - pb::ThrowHelper.ThrowIfNull(value, "value"); - result.hasState = true; - result.state_ = value; - return this; - } - public Builder ClearState() { - result.hasState = false; - result.state_ = ""; - return this; - } - - public bool HasZip { - get { return result.HasZip; } - } - [global::System.CLSCompliant(false)] - public uint Zip { - get { return result.Zip; } - set { SetZip(value); } - } - [global::System.CLSCompliant(false)] - public Builder SetZip(uint value) { - result.hasZip = true; - result.zip_ = value; - return this; - } - public Builder ClearZip() { - result.hasZip = false; - result.zip_ = 0; - return this; - } - } - static Addresses() { - object.ReferenceEquals(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasLiteProtoFile.Descriptor, null); - } - } - - } - #endregion - - public const int NameFieldNumber = 1; - private bool hasName; - private string name_ = ""; - public bool HasName { - get { return hasName; } - } - public string Name { - get { return name_; } - } - - public const int IdFieldNumber = 2; - private bool hasId; - private int id_ = 0; - public bool HasId { - get { return hasId; } - } - public int Id { - get { return id_; } - } - - public const int EmailFieldNumber = 3; - private bool hasEmail; - private string email_ = ""; - public bool HasEmail { - get { return hasEmail; } - } - public string Email { - get { return email_; } - } - - public const int CodesFieldNumber = 10; - private int codesMemoizedSerializedSize; - private pbc::PopsicleList<int> codes_ = new pbc::PopsicleList<int>(); - public scg::IList<int> CodesList { - get { return pbc::Lists.AsReadOnly(codes_); } - } - public int CodesCount { - get { return codes_.Count; } - } - public int GetCodes(int index) { - return codes_[index]; - } - - public const int PhoneFieldNumber = 4; - private pbc::PopsicleList<global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber> phone_ = new pbc::PopsicleList<global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber>(); - public scg::IList<global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber> PhoneList { - get { return phone_; } - } - public int PhoneCount { - get { return phone_.Count; } - } - public global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber GetPhone(int index) { - return phone_[index]; - } - - public const int AddressesFieldNumber = 5; - private pbc::PopsicleList<global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses> addresses_ = new pbc::PopsicleList<global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses>(); - public scg::IList<global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses> AddressesList { - get { return addresses_; } - } - public int AddressesCount { - get { return addresses_.Count; } - } - public global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses GetAddresses(int index) { - return addresses_[index]; - } - - public override bool IsInitialized { - get { - if (!hasName) return false; - if (!hasId) return false; - foreach (global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber element in PhoneList) { - if (!element.IsInitialized) return false; - } - if (!ExtensionsAreInitialized) return false; - return true; - } - } - - public override void WriteTo(pb::CodedOutputStream output) { - int size = SerializedSize; - pb::ExtendableMessageLite<TestInteropPersonLite, TestInteropPersonLite.Builder>.ExtensionWriter extensionWriter = CreateExtensionWriter(this); - if (HasName) { - output.WriteString(1, Name); - } - if (HasId) { - output.WriteInt32(2, Id); - } - if (HasEmail) { - output.WriteString(3, Email); - } - foreach (global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber element in PhoneList) { - output.WriteMessage(4, element); - } - foreach (global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses element in AddressesList) { - output.WriteGroup(5, element); - } - if (codes_.Count > 0) { - output.WriteRawVarint32(82); - output.WriteRawVarint32((uint) codesMemoizedSerializedSize); - foreach (int element in codes_) { - output.WriteInt32NoTag(element); - } - } - extensionWriter.WriteUntil(200, output); - } - - private int memoizedSerializedSize = -1; - public override int SerializedSize { - get { - int size = memoizedSerializedSize; - if (size != -1) return size; - - size = 0; - if (HasName) { - size += pb::CodedOutputStream.ComputeStringSize(1, Name); - } - if (HasId) { - size += pb::CodedOutputStream.ComputeInt32Size(2, Id); - } - if (HasEmail) { - size += pb::CodedOutputStream.ComputeStringSize(3, Email); - } - { - int dataSize = 0; - foreach (int element in CodesList) { - dataSize += pb::CodedOutputStream.ComputeInt32SizeNoTag(element); - } - size += dataSize; - if (codes_.Count != 0) { - size += 1 + pb::CodedOutputStream.ComputeInt32SizeNoTag(dataSize); - } - codesMemoizedSerializedSize = dataSize; - } - foreach (global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber element in PhoneList) { - size += pb::CodedOutputStream.ComputeMessageSize(4, element); - } - foreach (global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses element in AddressesList) { - size += pb::CodedOutputStream.ComputeGroupSize(5, element); - } - size += ExtensionsSerializedSize; - memoizedSerializedSize = size; - return size; - } - } - - #region Lite runtime methods - public override int GetHashCode() { - int hash = GetType().GetHashCode(); - if (hasName) hash ^= name_.GetHashCode(); - if (hasId) hash ^= id_.GetHashCode(); - if (hasEmail) hash ^= email_.GetHashCode(); - foreach(int i in codes_) - hash ^= i.GetHashCode(); - foreach(global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber i in phone_) - hash ^= i.GetHashCode(); - foreach(global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses i in addresses_) - hash ^= i.GetHashCode(); - hash ^= base.GetHashCode(); - return hash; - } - - public override bool Equals(object obj) { - TestInteropPersonLite other = obj as TestInteropPersonLite; - if (other == null) return false; - if (hasName != other.hasName || (hasName && !name_.Equals(other.name_))) return false; - if (hasId != other.hasId || (hasId && !id_.Equals(other.id_))) return false; - if (hasEmail != other.hasEmail || (hasEmail && !email_.Equals(other.email_))) return false; - if(codes_.Count != other.codes_.Count) return false; - for(int ix=0; ix < codes_.Count; ix++) - if(!codes_[ix].Equals(other.codes_[ix])) return false; - if(phone_.Count != other.phone_.Count) return false; - for(int ix=0; ix < phone_.Count; ix++) - if(!phone_[ix].Equals(other.phone_[ix])) return false; - if(addresses_.Count != other.addresses_.Count) return false; - for(int ix=0; ix < addresses_.Count; ix++) - if(!addresses_[ix].Equals(other.addresses_[ix])) return false; - if (!base.Equals(other)) return false; - return true; - } - - public override void PrintTo(global::System.IO.TextWriter writer) { - PrintField("name", hasName, name_, writer); - PrintField("id", hasId, id_, writer); - PrintField("email", hasEmail, email_, writer); - PrintField("phone", phone_, writer); - PrintField("Addresses", addresses_, writer); - PrintField("codes", codes_, writer); - base.PrintTo(writer); - } - #endregion - - public static TestInteropPersonLite ParseFrom(pb::ByteString data) { - return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed(); - } - public static TestInteropPersonLite ParseFrom(pb::ByteString data, pb::ExtensionRegistry extensionRegistry) { - return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed(); - } - public static TestInteropPersonLite ParseFrom(byte[] data) { - return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed(); - } - public static TestInteropPersonLite ParseFrom(byte[] data, pb::ExtensionRegistry extensionRegistry) { - return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed(); - } - public static TestInteropPersonLite ParseFrom(global::System.IO.Stream input) { - return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed(); - } - public static TestInteropPersonLite ParseFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) { - return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed(); - } - public static TestInteropPersonLite ParseDelimitedFrom(global::System.IO.Stream input) { - return CreateBuilder().MergeDelimitedFrom(input).BuildParsed(); - } - public static TestInteropPersonLite ParseDelimitedFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) { - return CreateBuilder().MergeDelimitedFrom(input, extensionRegistry).BuildParsed(); - } - public static TestInteropPersonLite ParseFrom(pb::CodedInputStream input) { - return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed(); - } - public static TestInteropPersonLite 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(TestInteropPersonLite prototype) { - return (Builder) new Builder().MergeFrom(prototype); - } - - public sealed partial class Builder : pb::ExtendableBuilderLite<TestInteropPersonLite, Builder> { - protected override Builder ThisBuilder { - get { return this; } - } - public Builder() {} - - TestInteropPersonLite result = new TestInteropPersonLite(); - - protected override TestInteropPersonLite MessageBeingBuilt { - get { return result; } - } - - public override Builder Clear() { - result = new TestInteropPersonLite(); - return this; - } - - public override Builder Clone() { - return new Builder().MergeFrom(result); - } - - public override TestInteropPersonLite DefaultInstanceForType { - get { return global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.DefaultInstance; } - } - - public override TestInteropPersonLite BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); - } - result.codes_.MakeReadOnly(); - result.phone_.MakeReadOnly(); - result.addresses_.MakeReadOnly(); - TestInteropPersonLite returnMe = result; - result = null; - return returnMe; - } - - public override Builder MergeFrom(pb::IMessageLite other) { - if (other is TestInteropPersonLite) { - return MergeFrom((TestInteropPersonLite) other); - } else { - base.MergeFrom(other); - return this; - } - } - - public override Builder MergeFrom(TestInteropPersonLite other) { - if (other == global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.DefaultInstance) return this; - if (other.HasName) { - Name = other.Name; - } - if (other.HasId) { - Id = other.Id; - } - if (other.HasEmail) { - Email = other.Email; - } - if (other.codes_.Count != 0) { - base.AddRange(other.codes_, result.codes_); - } - if (other.phone_.Count != 0) { - base.AddRange(other.phone_, result.phone_); - } - if (other.addresses_.Count != 0) { - base.AddRange(other.addresses_, result.addresses_); - } - this.MergeExtensionFields(other); - 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: { - Name = input.ReadString(); - break; - } - case 16: { - Id = input.ReadInt32(); - break; - } - case 26: { - Email = input.ReadString(); - break; - } - case 34: { - global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber.Builder subBuilder = global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber.CreateBuilder(); - input.ReadMessage(subBuilder, extensionRegistry); - AddPhone(subBuilder.BuildPartial()); - break; - } - case 43: { - global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses.Builder subBuilder = global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses.CreateBuilder(); - input.ReadGroup(5, subBuilder, extensionRegistry); - AddAddresses(subBuilder.BuildPartial()); - break; - } - case 82: { - int length = input.ReadInt32(); - int limit = input.PushLimit(length); - while (!input.ReachedLimit) { - AddCodes(input.ReadInt32()); - } - input.PopLimit(limit); - break; - } - } - } - } - - - public bool HasName { - get { return result.HasName; } - } - public string Name { - get { return result.Name; } - set { SetName(value); } - } - public Builder SetName(string value) { - pb::ThrowHelper.ThrowIfNull(value, "value"); - result.hasName = true; - result.name_ = value; - return this; - } - public Builder ClearName() { - result.hasName = false; - result.name_ = ""; - return this; - } - - public bool HasId { - get { return result.HasId; } - } - public int Id { - get { return result.Id; } - set { SetId(value); } - } - public Builder SetId(int value) { - result.hasId = true; - result.id_ = value; - return this; - } - public Builder ClearId() { - result.hasId = false; - result.id_ = 0; - return this; - } - - public bool HasEmail { - get { return result.HasEmail; } - } - public string Email { - get { return result.Email; } - set { SetEmail(value); } - } - public Builder SetEmail(string value) { - pb::ThrowHelper.ThrowIfNull(value, "value"); - result.hasEmail = true; - result.email_ = value; - return this; - } - public Builder ClearEmail() { - result.hasEmail = false; - result.email_ = ""; - return this; - } - - public pbc::IPopsicleList<int> CodesList { - get { return result.codes_; } - } - public int CodesCount { - get { return result.CodesCount; } - } - public int GetCodes(int index) { - return result.GetCodes(index); - } - public Builder SetCodes(int index, int value) { - result.codes_[index] = value; - return this; - } - public Builder AddCodes(int value) { - result.codes_.Add(value); - return this; - } - public Builder AddRangeCodes(scg::IEnumerable<int> values) { - base.AddRange(values, result.codes_); - return this; - } - public Builder ClearCodes() { - result.codes_.Clear(); - return this; - } - - public pbc::IPopsicleList<global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber> PhoneList { - get { return result.phone_; } - } - public int PhoneCount { - get { return result.PhoneCount; } - } - public global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber GetPhone(int index) { - return result.GetPhone(index); - } - public Builder SetPhone(int index, global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber value) { - pb::ThrowHelper.ThrowIfNull(value, "value"); - result.phone_[index] = value; - return this; - } - public Builder SetPhone(int index, global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber.Builder builderForValue) { - pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); - result.phone_[index] = builderForValue.Build(); - return this; - } - public Builder AddPhone(global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber value) { - pb::ThrowHelper.ThrowIfNull(value, "value"); - result.phone_.Add(value); - return this; - } - public Builder AddPhone(global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber.Builder builderForValue) { - pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); - result.phone_.Add(builderForValue.Build()); - return this; - } - public Builder AddRangePhone(scg::IEnumerable<global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber> values) { - base.AddRange(values, result.phone_); - return this; - } - public Builder ClearPhone() { - result.phone_.Clear(); - return this; - } - - public pbc::IPopsicleList<global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses> AddressesList { - get { return result.addresses_; } - } - public int AddressesCount { - get { return result.AddressesCount; } - } - public global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses GetAddresses(int index) { - return result.GetAddresses(index); - } - public Builder SetAddresses(int index, global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses value) { - pb::ThrowHelper.ThrowIfNull(value, "value"); - result.addresses_[index] = value; - return this; - } - public Builder SetAddresses(int index, global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses.Builder builderForValue) { - pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); - result.addresses_[index] = builderForValue.Build(); - return this; - } - public Builder AddAddresses(global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses value) { - pb::ThrowHelper.ThrowIfNull(value, "value"); - result.addresses_.Add(value); - return this; - } - public Builder AddAddresses(global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses.Builder builderForValue) { - pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue"); - result.addresses_.Add(builderForValue.Build()); - return this; - } - public Builder AddRangeAddresses(scg::IEnumerable<global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses> values) { - base.AddRange(values, result.addresses_); - return this; - } - public Builder ClearAddresses() { - result.addresses_.Clear(); - return this; - } - } - static TestInteropPersonLite() { - object.ReferenceEquals(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasLiteProtoFile.Descriptor, null); - } - } - - public sealed partial class TestInteropEmployeeIdLite : pb::GeneratedMessageLite<TestInteropEmployeeIdLite, TestInteropEmployeeIdLite.Builder> { - private static readonly TestInteropEmployeeIdLite defaultInstance = new Builder().BuildPartial(); - public static TestInteropEmployeeIdLite DefaultInstance { - get { return defaultInstance; } - } - - public override TestInteropEmployeeIdLite DefaultInstanceForType { - get { return defaultInstance; } - } - - protected override TestInteropEmployeeIdLite ThisMessage { - get { return this; } - } - - public const int NumberFieldNumber = 1; - private bool hasNumber; - private string number_ = ""; - public bool HasNumber { - get { return hasNumber; } - } - public string Number { - get { return number_; } - } - - public override bool IsInitialized { - get { - if (!hasNumber) return false; - return true; - } - } - - public override void WriteTo(pb::CodedOutputStream output) { - int size = SerializedSize; - if (HasNumber) { - output.WriteString(1, Number); - } - } - - private int memoizedSerializedSize = -1; - public override int SerializedSize { - get { - int size = memoizedSerializedSize; - if (size != -1) return size; - - size = 0; - if (HasNumber) { - size += pb::CodedOutputStream.ComputeStringSize(1, Number); - } - memoizedSerializedSize = size; - return size; - } - } - - #region Lite runtime methods - public override int GetHashCode() { - int hash = GetType().GetHashCode(); - if (hasNumber) hash ^= number_.GetHashCode(); - return hash; - } - - public override bool Equals(object obj) { - TestInteropEmployeeIdLite other = obj as TestInteropEmployeeIdLite; - if (other == null) return false; - if (hasNumber != other.hasNumber || (hasNumber && !number_.Equals(other.number_))) return false; - return true; - } - - public override void PrintTo(global::System.IO.TextWriter writer) { - PrintField("number", hasNumber, number_, writer); - } - #endregion - - public static TestInteropEmployeeIdLite ParseFrom(pb::ByteString data) { - return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed(); - } - public static TestInteropEmployeeIdLite ParseFrom(pb::ByteString data, pb::ExtensionRegistry extensionRegistry) { - return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed(); - } - public static TestInteropEmployeeIdLite ParseFrom(byte[] data) { - return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed(); - } - public static TestInteropEmployeeIdLite ParseFrom(byte[] data, pb::ExtensionRegistry extensionRegistry) { - return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed(); - } - public static TestInteropEmployeeIdLite ParseFrom(global::System.IO.Stream input) { - return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed(); - } - public static TestInteropEmployeeIdLite ParseFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) { - return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed(); - } - public static TestInteropEmployeeIdLite ParseDelimitedFrom(global::System.IO.Stream input) { - return CreateBuilder().MergeDelimitedFrom(input).BuildParsed(); - } - public static TestInteropEmployeeIdLite ParseDelimitedFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) { - return CreateBuilder().MergeDelimitedFrom(input, extensionRegistry).BuildParsed(); - } - public static TestInteropEmployeeIdLite ParseFrom(pb::CodedInputStream input) { - return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed(); - } - public static TestInteropEmployeeIdLite 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(TestInteropEmployeeIdLite prototype) { - return (Builder) new Builder().MergeFrom(prototype); - } - - public sealed partial class Builder : pb::GeneratedBuilderLite<TestInteropEmployeeIdLite, Builder> { - protected override Builder ThisBuilder { - get { return this; } - } - public Builder() {} - - TestInteropEmployeeIdLite result = new TestInteropEmployeeIdLite(); - - protected override TestInteropEmployeeIdLite MessageBeingBuilt { - get { return result; } - } - - public override Builder Clear() { - result = new TestInteropEmployeeIdLite(); - return this; - } - - public override Builder Clone() { - return new Builder().MergeFrom(result); - } - - public override TestInteropEmployeeIdLite DefaultInstanceForType { - get { return global::Google.ProtocolBuffers.TestProtos.TestInteropEmployeeIdLite.DefaultInstance; } - } - - public override TestInteropEmployeeIdLite BuildPartial() { - if (result == null) { - throw new global::System.InvalidOperationException("build() has already been called on this Builder"); - } - TestInteropEmployeeIdLite returnMe = result; - result = null; - return returnMe; - } - - public override Builder MergeFrom(pb::IMessageLite other) { - if (other is TestInteropEmployeeIdLite) { - return MergeFrom((TestInteropEmployeeIdLite) other); - } else { - base.MergeFrom(other); - return this; - } - } - - public override Builder MergeFrom(TestInteropEmployeeIdLite other) { - if (other == global::Google.ProtocolBuffers.TestProtos.TestInteropEmployeeIdLite.DefaultInstance) return this; - if (other.HasNumber) { - Number = other.Number; - } - 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: { - Number = input.ReadString(); - break; - } - } - } - } - - - public bool HasNumber { - get { return result.HasNumber; } - } - public string Number { - get { return result.Number; } - set { SetNumber(value); } - } - public Builder SetNumber(string value) { - pb::ThrowHelper.ThrowIfNull(value, "value"); - result.hasNumber = true; - result.number_ = value; - return this; - } - public Builder ClearNumber() { - result.hasNumber = false; - result.number_ = ""; - return this; - } - } - static TestInteropEmployeeIdLite() { - object.ReferenceEquals(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasLiteProtoFile.Descriptor, null); - } - } - - #endregion - -} +// 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 UnitTestExtrasLiteProtoFile {
+
+ #region Extension registration
+ public static void RegisterAllExtensions(pb::ExtensionRegistry registry) {
+ registry.Add(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasLiteProtoFile.EmployeeIdLite);
+ }
+ #endregion
+ #region Extensions
+ public const int EmployeeIdLiteFieldNumber = 126;
+ public static pb::GeneratedExtensionLite<global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite, global::Google.ProtocolBuffers.TestProtos.TestInteropEmployeeIdLite> EmployeeIdLite;
+ #endregion
+
+ #region Static variables
+ #endregion
+ #region Extensions
+ internal static readonly object Descriptor;
+ static UnitTestExtrasLiteProtoFile() {
+ Descriptor = null;
+ global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasLiteProtoFile.EmployeeIdLite =
+ new pb::GeneratedExtensionLite<global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite, global::Google.ProtocolBuffers.TestProtos.TestInteropEmployeeIdLite>(
+ "protobuf_unittest_extra.employee_id_lite",
+ global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.DefaultInstance,
+ null,
+ global::Google.ProtocolBuffers.TestProtos.TestInteropEmployeeIdLite.DefaultInstance,
+ null,
+ global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasLiteProtoFile.EmployeeIdLiteFieldNumber,
+ pbd::FieldType.Message);
+ }
+ #endregion
+
+ }
+ #region Enums
+ public enum ExtraEnum {
+ DEFAULT = 10,
+ EXLITE_FOO = 7,
+ EXLITE_BAR = 8,
+ EXLITE_BAZ = 9,
+ }
+
+ #endregion
+
+ #region Messages
+ public sealed partial class TestRequiredLite : pb::GeneratedMessageLite<TestRequiredLite, TestRequiredLite.Builder> {
+ private static readonly TestRequiredLite defaultInstance = new Builder().BuildPartial();
+ public static TestRequiredLite DefaultInstance {
+ get { return defaultInstance; }
+ }
+
+ public override TestRequiredLite DefaultInstanceForType {
+ get { return defaultInstance; }
+ }
+
+ protected override TestRequiredLite 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 const int EnFieldNumber = 2;
+ private bool hasEn;
+ private global::Google.ProtocolBuffers.TestProtos.ExtraEnum en_ = global::Google.ProtocolBuffers.TestProtos.ExtraEnum.DEFAULT;
+ public bool HasEn {
+ get { return hasEn; }
+ }
+ public global::Google.ProtocolBuffers.TestProtos.ExtraEnum En {
+ get { return en_; }
+ }
+
+ public override bool IsInitialized {
+ get {
+ if (!hasD) return false;
+ if (!hasEn) return false;
+ return true;
+ }
+ }
+
+ public override void WriteTo(pb::CodedOutputStream output) {
+ int size = SerializedSize;
+ if (HasD) {
+ output.WriteInt32(1, D);
+ }
+ if (HasEn) {
+ output.WriteEnum(2, (int) En);
+ }
+ }
+
+ 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);
+ }
+ if (HasEn) {
+ size += pb::CodedOutputStream.ComputeEnumSize(2, (int) En);
+ }
+ memoizedSerializedSize = size;
+ return size;
+ }
+ }
+
+ #region Lite runtime methods
+ public override int GetHashCode() {
+ int hash = GetType().GetHashCode();
+ if (hasD) hash ^= d_.GetHashCode();
+ if (hasEn) hash ^= en_.GetHashCode();
+ return hash;
+ }
+
+ public override bool Equals(object obj) {
+ TestRequiredLite other = obj as TestRequiredLite;
+ if (other == null) return false;
+ if (hasD != other.hasD || (hasD && !d_.Equals(other.d_))) return false;
+ if (hasEn != other.hasEn || (hasEn && !en_.Equals(other.en_))) return false;
+ return true;
+ }
+
+ public override void PrintTo(global::System.IO.TextWriter writer) {
+ PrintField("d", hasD, d_, writer);
+ PrintField("en", hasEn, en_, writer);
+ }
+ #endregion
+
+ public static TestRequiredLite ParseFrom(pb::ByteString data) {
+ return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
+ }
+ public static TestRequiredLite ParseFrom(pb::ByteString data, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
+ }
+ public static TestRequiredLite ParseFrom(byte[] data) {
+ return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
+ }
+ public static TestRequiredLite ParseFrom(byte[] data, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
+ }
+ public static TestRequiredLite ParseFrom(global::System.IO.Stream input) {
+ return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
+ }
+ public static TestRequiredLite ParseFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
+ }
+ public static TestRequiredLite ParseDelimitedFrom(global::System.IO.Stream input) {
+ return CreateBuilder().MergeDelimitedFrom(input).BuildParsed();
+ }
+ public static TestRequiredLite ParseDelimitedFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
+ return CreateBuilder().MergeDelimitedFrom(input, extensionRegistry).BuildParsed();
+ }
+ public static TestRequiredLite ParseFrom(pb::CodedInputStream input) {
+ return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
+ }
+ public static TestRequiredLite 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(TestRequiredLite prototype) {
+ return (Builder) new Builder().MergeFrom(prototype);
+ }
+
+ public sealed partial class Builder : pb::GeneratedBuilderLite<TestRequiredLite, Builder> {
+ protected override Builder ThisBuilder {
+ get { return this; }
+ }
+ public Builder() {}
+
+ TestRequiredLite result = new TestRequiredLite();
+
+ protected override TestRequiredLite MessageBeingBuilt {
+ get { return result; }
+ }
+
+ public override Builder Clear() {
+ result = new TestRequiredLite();
+ return this;
+ }
+
+ public override Builder Clone() {
+ return new Builder().MergeFrom(result);
+ }
+
+ public override TestRequiredLite DefaultInstanceForType {
+ get { return global::Google.ProtocolBuffers.TestProtos.TestRequiredLite.DefaultInstance; }
+ }
+
+ public override TestRequiredLite BuildPartial() {
+ if (result == null) {
+ throw new global::System.InvalidOperationException("build() has already been called on this Builder");
+ }
+ TestRequiredLite returnMe = result;
+ result = null;
+ return returnMe;
+ }
+
+ public override Builder MergeFrom(pb::IMessageLite other) {
+ if (other is TestRequiredLite) {
+ return MergeFrom((TestRequiredLite) other);
+ } else {
+ base.MergeFrom(other);
+ return this;
+ }
+ }
+
+ public override Builder MergeFrom(TestRequiredLite other) {
+ if (other == global::Google.ProtocolBuffers.TestProtos.TestRequiredLite.DefaultInstance) return this;
+ if (other.HasD) {
+ D = other.D;
+ }
+ if (other.HasEn) {
+ En = other.En;
+ }
+ 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;
+ }
+ case 16: {
+ int rawValue = input.ReadEnum();
+ if (!global::System.Enum.IsDefined(typeof(global::Google.ProtocolBuffers.TestProtos.ExtraEnum), rawValue)) {
+ } else {
+ En = (global::Google.ProtocolBuffers.TestProtos.ExtraEnum) rawValue;
+ }
+ 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;
+ }
+
+ public bool HasEn {
+ get { return result.HasEn; }
+ }
+ public global::Google.ProtocolBuffers.TestProtos.ExtraEnum En {
+ get { return result.En; }
+ set { SetEn(value); }
+ }
+ public Builder SetEn(global::Google.ProtocolBuffers.TestProtos.ExtraEnum value) {
+ result.hasEn = true;
+ result.en_ = value;
+ return this;
+ }
+ public Builder ClearEn() {
+ result.hasEn = false;
+ result.en_ = global::Google.ProtocolBuffers.TestProtos.ExtraEnum.DEFAULT;
+ return this;
+ }
+ }
+ static TestRequiredLite() {
+ object.ReferenceEquals(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasLiteProtoFile.Descriptor, null);
+ }
+ }
+
+ public sealed partial class TestInteropPersonLite : pb::ExtendableMessageLite<TestInteropPersonLite, TestInteropPersonLite.Builder> {
+ private static readonly TestInteropPersonLite defaultInstance = new Builder().BuildPartial();
+ public static TestInteropPersonLite DefaultInstance {
+ get { return defaultInstance; }
+ }
+
+ public override TestInteropPersonLite DefaultInstanceForType {
+ get { return defaultInstance; }
+ }
+
+ protected override TestInteropPersonLite ThisMessage {
+ get { return this; }
+ }
+
+ #region Nested types
+ public static class Types {
+ public enum PhoneType {
+ MOBILE = 0,
+ HOME = 1,
+ WORK = 2,
+ }
+
+ public sealed partial class PhoneNumber : pb::GeneratedMessageLite<PhoneNumber, PhoneNumber.Builder> {
+ private static readonly PhoneNumber defaultInstance = new Builder().BuildPartial();
+ public static PhoneNumber DefaultInstance {
+ get { return defaultInstance; }
+ }
+
+ public override PhoneNumber DefaultInstanceForType {
+ get { return defaultInstance; }
+ }
+
+ protected override PhoneNumber ThisMessage {
+ get { return this; }
+ }
+
+ public const int NumberFieldNumber = 1;
+ private bool hasNumber;
+ private string number_ = "";
+ public bool HasNumber {
+ get { return hasNumber; }
+ }
+ public string Number {
+ get { return number_; }
+ }
+
+ public const int TypeFieldNumber = 2;
+ private bool hasType;
+ private global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneType type_ = global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneType.HOME;
+ public bool HasType {
+ get { return hasType; }
+ }
+ public global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneType Type {
+ get { return type_; }
+ }
+
+ public override bool IsInitialized {
+ get {
+ if (!hasNumber) return false;
+ return true;
+ }
+ }
+
+ public override void WriteTo(pb::CodedOutputStream output) {
+ int size = SerializedSize;
+ if (HasNumber) {
+ output.WriteString(1, Number);
+ }
+ if (HasType) {
+ output.WriteEnum(2, (int) Type);
+ }
+ }
+
+ private int memoizedSerializedSize = -1;
+ public override int SerializedSize {
+ get {
+ int size = memoizedSerializedSize;
+ if (size != -1) return size;
+
+ size = 0;
+ if (HasNumber) {
+ size += pb::CodedOutputStream.ComputeStringSize(1, Number);
+ }
+ if (HasType) {
+ size += pb::CodedOutputStream.ComputeEnumSize(2, (int) Type);
+ }
+ memoizedSerializedSize = size;
+ return size;
+ }
+ }
+
+ #region Lite runtime methods
+ public override int GetHashCode() {
+ int hash = GetType().GetHashCode();
+ if (hasNumber) hash ^= number_.GetHashCode();
+ if (hasType) hash ^= type_.GetHashCode();
+ return hash;
+ }
+
+ public override bool Equals(object obj) {
+ PhoneNumber other = obj as PhoneNumber;
+ if (other == null) return false;
+ if (hasNumber != other.hasNumber || (hasNumber && !number_.Equals(other.number_))) return false;
+ if (hasType != other.hasType || (hasType && !type_.Equals(other.type_))) return false;
+ return true;
+ }
+
+ public override void PrintTo(global::System.IO.TextWriter writer) {
+ PrintField("number", hasNumber, number_, writer);
+ PrintField("type", hasType, type_, writer);
+ }
+ #endregion
+
+ public static PhoneNumber ParseFrom(pb::ByteString data) {
+ return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
+ }
+ public static PhoneNumber ParseFrom(pb::ByteString data, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
+ }
+ public static PhoneNumber ParseFrom(byte[] data) {
+ return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
+ }
+ public static PhoneNumber ParseFrom(byte[] data, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
+ }
+ public static PhoneNumber ParseFrom(global::System.IO.Stream input) {
+ return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
+ }
+ public static PhoneNumber ParseFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
+ }
+ public static PhoneNumber ParseDelimitedFrom(global::System.IO.Stream input) {
+ return CreateBuilder().MergeDelimitedFrom(input).BuildParsed();
+ }
+ public static PhoneNumber ParseDelimitedFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
+ return CreateBuilder().MergeDelimitedFrom(input, extensionRegistry).BuildParsed();
+ }
+ public static PhoneNumber ParseFrom(pb::CodedInputStream input) {
+ return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
+ }
+ public static PhoneNumber 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(PhoneNumber prototype) {
+ return (Builder) new Builder().MergeFrom(prototype);
+ }
+
+ public sealed partial class Builder : pb::GeneratedBuilderLite<PhoneNumber, Builder> {
+ protected override Builder ThisBuilder {
+ get { return this; }
+ }
+ public Builder() {}
+
+ PhoneNumber result = new PhoneNumber();
+
+ protected override PhoneNumber MessageBeingBuilt {
+ get { return result; }
+ }
+
+ public override Builder Clear() {
+ result = new PhoneNumber();
+ return this;
+ }
+
+ public override Builder Clone() {
+ return new Builder().MergeFrom(result);
+ }
+
+ public override PhoneNumber DefaultInstanceForType {
+ get { return global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber.DefaultInstance; }
+ }
+
+ public override PhoneNumber BuildPartial() {
+ if (result == null) {
+ throw new global::System.InvalidOperationException("build() has already been called on this Builder");
+ }
+ PhoneNumber returnMe = result;
+ result = null;
+ return returnMe;
+ }
+
+ public override Builder MergeFrom(pb::IMessageLite other) {
+ if (other is PhoneNumber) {
+ return MergeFrom((PhoneNumber) other);
+ } else {
+ base.MergeFrom(other);
+ return this;
+ }
+ }
+
+ public override Builder MergeFrom(PhoneNumber other) {
+ if (other == global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber.DefaultInstance) return this;
+ if (other.HasNumber) {
+ Number = other.Number;
+ }
+ if (other.HasType) {
+ Type = other.Type;
+ }
+ 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: {
+ Number = input.ReadString();
+ break;
+ }
+ case 16: {
+ int rawValue = input.ReadEnum();
+ if (!global::System.Enum.IsDefined(typeof(global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneType), rawValue)) {
+ } else {
+ Type = (global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneType) rawValue;
+ }
+ break;
+ }
+ }
+ }
+ }
+
+
+ public bool HasNumber {
+ get { return result.HasNumber; }
+ }
+ public string Number {
+ get { return result.Number; }
+ set { SetNumber(value); }
+ }
+ public Builder SetNumber(string value) {
+ pb::ThrowHelper.ThrowIfNull(value, "value");
+ result.hasNumber = true;
+ result.number_ = value;
+ return this;
+ }
+ public Builder ClearNumber() {
+ result.hasNumber = false;
+ result.number_ = "";
+ return this;
+ }
+
+ public bool HasType {
+ get { return result.HasType; }
+ }
+ public global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneType Type {
+ get { return result.Type; }
+ set { SetType(value); }
+ }
+ public Builder SetType(global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneType value) {
+ result.hasType = true;
+ result.type_ = value;
+ return this;
+ }
+ public Builder ClearType() {
+ result.hasType = false;
+ result.type_ = global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneType.HOME;
+ return this;
+ }
+ }
+ static PhoneNumber() {
+ object.ReferenceEquals(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasLiteProtoFile.Descriptor, null);
+ }
+ }
+
+ public sealed partial class Addresses : pb::GeneratedMessageLite<Addresses, Addresses.Builder> {
+ private static readonly Addresses defaultInstance = new Builder().BuildPartial();
+ public static Addresses DefaultInstance {
+ get { return defaultInstance; }
+ }
+
+ public override Addresses DefaultInstanceForType {
+ get { return defaultInstance; }
+ }
+
+ protected override Addresses ThisMessage {
+ get { return this; }
+ }
+
+ public const int AddressFieldNumber = 1;
+ private bool hasAddress;
+ private string address_ = "";
+ public bool HasAddress {
+ get { return hasAddress; }
+ }
+ public string Address {
+ get { return address_; }
+ }
+
+ public const int Address2FieldNumber = 2;
+ private bool hasAddress2;
+ private string address2_ = "";
+ public bool HasAddress2 {
+ get { return hasAddress2; }
+ }
+ public string Address2 {
+ get { return address2_; }
+ }
+
+ public const int CityFieldNumber = 3;
+ private bool hasCity;
+ private string city_ = "";
+ public bool HasCity {
+ get { return hasCity; }
+ }
+ public string City {
+ get { return city_; }
+ }
+
+ public const int StateFieldNumber = 4;
+ private bool hasState;
+ private string state_ = "";
+ public bool HasState {
+ get { return hasState; }
+ }
+ public string State {
+ get { return state_; }
+ }
+
+ public const int ZipFieldNumber = 5;
+ private bool hasZip;
+ private uint zip_ = 0;
+ public bool HasZip {
+ get { return hasZip; }
+ }
+ [global::System.CLSCompliant(false)]
+ public uint Zip {
+ get { return zip_; }
+ }
+
+ public override bool IsInitialized {
+ get {
+ if (!hasAddress) return false;
+ if (!hasCity) return false;
+ if (!hasState) return false;
+ if (!hasZip) return false;
+ return true;
+ }
+ }
+
+ public override void WriteTo(pb::CodedOutputStream output) {
+ int size = SerializedSize;
+ if (HasAddress) {
+ output.WriteString(1, Address);
+ }
+ if (HasAddress2) {
+ output.WriteString(2, Address2);
+ }
+ if (HasCity) {
+ output.WriteString(3, City);
+ }
+ if (HasState) {
+ output.WriteString(4, State);
+ }
+ if (HasZip) {
+ output.WriteFixed32(5, Zip);
+ }
+ }
+
+ private int memoizedSerializedSize = -1;
+ public override int SerializedSize {
+ get {
+ int size = memoizedSerializedSize;
+ if (size != -1) return size;
+
+ size = 0;
+ if (HasAddress) {
+ size += pb::CodedOutputStream.ComputeStringSize(1, Address);
+ }
+ if (HasAddress2) {
+ size += pb::CodedOutputStream.ComputeStringSize(2, Address2);
+ }
+ if (HasCity) {
+ size += pb::CodedOutputStream.ComputeStringSize(3, City);
+ }
+ if (HasState) {
+ size += pb::CodedOutputStream.ComputeStringSize(4, State);
+ }
+ if (HasZip) {
+ size += pb::CodedOutputStream.ComputeFixed32Size(5, Zip);
+ }
+ memoizedSerializedSize = size;
+ return size;
+ }
+ }
+
+ #region Lite runtime methods
+ public override int GetHashCode() {
+ int hash = GetType().GetHashCode();
+ if (hasAddress) hash ^= address_.GetHashCode();
+ if (hasAddress2) hash ^= address2_.GetHashCode();
+ if (hasCity) hash ^= city_.GetHashCode();
+ if (hasState) hash ^= state_.GetHashCode();
+ if (hasZip) hash ^= zip_.GetHashCode();
+ return hash;
+ }
+
+ public override bool Equals(object obj) {
+ Addresses other = obj as Addresses;
+ if (other == null) return false;
+ if (hasAddress != other.hasAddress || (hasAddress && !address_.Equals(other.address_))) return false;
+ if (hasAddress2 != other.hasAddress2 || (hasAddress2 && !address2_.Equals(other.address2_))) return false;
+ if (hasCity != other.hasCity || (hasCity && !city_.Equals(other.city_))) return false;
+ if (hasState != other.hasState || (hasState && !state_.Equals(other.state_))) return false;
+ if (hasZip != other.hasZip || (hasZip && !zip_.Equals(other.zip_))) return false;
+ return true;
+ }
+
+ public override void PrintTo(global::System.IO.TextWriter writer) {
+ PrintField("address", hasAddress, address_, writer);
+ PrintField("address2", hasAddress2, address2_, writer);
+ PrintField("city", hasCity, city_, writer);
+ PrintField("state", hasState, state_, writer);
+ PrintField("zip", hasZip, zip_, writer);
+ }
+ #endregion
+
+ public static Addresses ParseFrom(pb::ByteString data) {
+ return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
+ }
+ public static Addresses ParseFrom(pb::ByteString data, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
+ }
+ public static Addresses ParseFrom(byte[] data) {
+ return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
+ }
+ public static Addresses ParseFrom(byte[] data, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
+ }
+ public static Addresses ParseFrom(global::System.IO.Stream input) {
+ return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
+ }
+ public static Addresses ParseFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
+ }
+ public static Addresses ParseDelimitedFrom(global::System.IO.Stream input) {
+ return CreateBuilder().MergeDelimitedFrom(input).BuildParsed();
+ }
+ public static Addresses ParseDelimitedFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
+ return CreateBuilder().MergeDelimitedFrom(input, extensionRegistry).BuildParsed();
+ }
+ public static Addresses ParseFrom(pb::CodedInputStream input) {
+ return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
+ }
+ public static Addresses 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(Addresses prototype) {
+ return (Builder) new Builder().MergeFrom(prototype);
+ }
+
+ public sealed partial class Builder : pb::GeneratedBuilderLite<Addresses, Builder> {
+ protected override Builder ThisBuilder {
+ get { return this; }
+ }
+ public Builder() {}
+
+ Addresses result = new Addresses();
+
+ protected override Addresses MessageBeingBuilt {
+ get { return result; }
+ }
+
+ public override Builder Clear() {
+ result = new Addresses();
+ return this;
+ }
+
+ public override Builder Clone() {
+ return new Builder().MergeFrom(result);
+ }
+
+ public override Addresses DefaultInstanceForType {
+ get { return global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses.DefaultInstance; }
+ }
+
+ public override Addresses BuildPartial() {
+ if (result == null) {
+ throw new global::System.InvalidOperationException("build() has already been called on this Builder");
+ }
+ Addresses returnMe = result;
+ result = null;
+ return returnMe;
+ }
+
+ public override Builder MergeFrom(pb::IMessageLite other) {
+ if (other is Addresses) {
+ return MergeFrom((Addresses) other);
+ } else {
+ base.MergeFrom(other);
+ return this;
+ }
+ }
+
+ public override Builder MergeFrom(Addresses other) {
+ if (other == global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses.DefaultInstance) return this;
+ if (other.HasAddress) {
+ Address = other.Address;
+ }
+ if (other.HasAddress2) {
+ Address2 = other.Address2;
+ }
+ if (other.HasCity) {
+ City = other.City;
+ }
+ if (other.HasState) {
+ State = other.State;
+ }
+ if (other.HasZip) {
+ Zip = other.Zip;
+ }
+ 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: {
+ Address = input.ReadString();
+ break;
+ }
+ case 18: {
+ Address2 = input.ReadString();
+ break;
+ }
+ case 26: {
+ City = input.ReadString();
+ break;
+ }
+ case 34: {
+ State = input.ReadString();
+ break;
+ }
+ case 45: {
+ Zip = input.ReadFixed32();
+ break;
+ }
+ }
+ }
+ }
+
+
+ public bool HasAddress {
+ get { return result.HasAddress; }
+ }
+ public string Address {
+ get { return result.Address; }
+ set { SetAddress(value); }
+ }
+ public Builder SetAddress(string value) {
+ pb::ThrowHelper.ThrowIfNull(value, "value");
+ result.hasAddress = true;
+ result.address_ = value;
+ return this;
+ }
+ public Builder ClearAddress() {
+ result.hasAddress = false;
+ result.address_ = "";
+ return this;
+ }
+
+ public bool HasAddress2 {
+ get { return result.HasAddress2; }
+ }
+ public string Address2 {
+ get { return result.Address2; }
+ set { SetAddress2(value); }
+ }
+ public Builder SetAddress2(string value) {
+ pb::ThrowHelper.ThrowIfNull(value, "value");
+ result.hasAddress2 = true;
+ result.address2_ = value;
+ return this;
+ }
+ public Builder ClearAddress2() {
+ result.hasAddress2 = false;
+ result.address2_ = "";
+ return this;
+ }
+
+ public bool HasCity {
+ get { return result.HasCity; }
+ }
+ public string City {
+ get { return result.City; }
+ set { SetCity(value); }
+ }
+ public Builder SetCity(string value) {
+ pb::ThrowHelper.ThrowIfNull(value, "value");
+ result.hasCity = true;
+ result.city_ = value;
+ return this;
+ }
+ public Builder ClearCity() {
+ result.hasCity = false;
+ result.city_ = "";
+ return this;
+ }
+
+ public bool HasState {
+ get { return result.HasState; }
+ }
+ public string State {
+ get { return result.State; }
+ set { SetState(value); }
+ }
+ public Builder SetState(string value) {
+ pb::ThrowHelper.ThrowIfNull(value, "value");
+ result.hasState = true;
+ result.state_ = value;
+ return this;
+ }
+ public Builder ClearState() {
+ result.hasState = false;
+ result.state_ = "";
+ return this;
+ }
+
+ public bool HasZip {
+ get { return result.HasZip; }
+ }
+ [global::System.CLSCompliant(false)]
+ public uint Zip {
+ get { return result.Zip; }
+ set { SetZip(value); }
+ }
+ [global::System.CLSCompliant(false)]
+ public Builder SetZip(uint value) {
+ result.hasZip = true;
+ result.zip_ = value;
+ return this;
+ }
+ public Builder ClearZip() {
+ result.hasZip = false;
+ result.zip_ = 0;
+ return this;
+ }
+ }
+ static Addresses() {
+ object.ReferenceEquals(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasLiteProtoFile.Descriptor, null);
+ }
+ }
+
+ }
+ #endregion
+
+ public const int NameFieldNumber = 1;
+ private bool hasName;
+ private string name_ = "";
+ public bool HasName {
+ get { return hasName; }
+ }
+ public string Name {
+ get { return name_; }
+ }
+
+ public const int IdFieldNumber = 2;
+ private bool hasId;
+ private int id_ = 0;
+ public bool HasId {
+ get { return hasId; }
+ }
+ public int Id {
+ get { return id_; }
+ }
+
+ public const int EmailFieldNumber = 3;
+ private bool hasEmail;
+ private string email_ = "";
+ public bool HasEmail {
+ get { return hasEmail; }
+ }
+ public string Email {
+ get { return email_; }
+ }
+
+ public const int CodesFieldNumber = 10;
+ private int codesMemoizedSerializedSize;
+ private pbc::PopsicleList<int> codes_ = new pbc::PopsicleList<int>();
+ public scg::IList<int> CodesList {
+ get { return pbc::Lists.AsReadOnly(codes_); }
+ }
+ public int CodesCount {
+ get { return codes_.Count; }
+ }
+ public int GetCodes(int index) {
+ return codes_[index];
+ }
+
+ public const int PhoneFieldNumber = 4;
+ private pbc::PopsicleList<global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber> phone_ = new pbc::PopsicleList<global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber>();
+ public scg::IList<global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber> PhoneList {
+ get { return phone_; }
+ }
+ public int PhoneCount {
+ get { return phone_.Count; }
+ }
+ public global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber GetPhone(int index) {
+ return phone_[index];
+ }
+
+ public const int AddressesFieldNumber = 5;
+ private pbc::PopsicleList<global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses> addresses_ = new pbc::PopsicleList<global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses>();
+ public scg::IList<global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses> AddressesList {
+ get { return addresses_; }
+ }
+ public int AddressesCount {
+ get { return addresses_.Count; }
+ }
+ public global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses GetAddresses(int index) {
+ return addresses_[index];
+ }
+
+ public override bool IsInitialized {
+ get {
+ if (!hasName) return false;
+ if (!hasId) return false;
+ foreach (global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber element in PhoneList) {
+ if (!element.IsInitialized) return false;
+ }
+ if (!ExtensionsAreInitialized) return false;
+ return true;
+ }
+ }
+
+ public override void WriteTo(pb::CodedOutputStream output) {
+ int size = SerializedSize;
+ pb::ExtendableMessageLite<TestInteropPersonLite, TestInteropPersonLite.Builder>.ExtensionWriter extensionWriter = CreateExtensionWriter(this);
+ if (HasName) {
+ output.WriteString(1, Name);
+ }
+ if (HasId) {
+ output.WriteInt32(2, Id);
+ }
+ if (HasEmail) {
+ output.WriteString(3, Email);
+ }
+ foreach (global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber element in PhoneList) {
+ output.WriteMessage(4, element);
+ }
+ foreach (global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses element in AddressesList) {
+ output.WriteGroup(5, element);
+ }
+ if (codes_.Count > 0) {
+ output.WriteRawVarint32(82);
+ output.WriteRawVarint32((uint) codesMemoizedSerializedSize);
+ foreach (int element in codes_) {
+ output.WriteInt32NoTag(element);
+ }
+ }
+ extensionWriter.WriteUntil(200, output);
+ }
+
+ private int memoizedSerializedSize = -1;
+ public override int SerializedSize {
+ get {
+ int size = memoizedSerializedSize;
+ if (size != -1) return size;
+
+ size = 0;
+ if (HasName) {
+ size += pb::CodedOutputStream.ComputeStringSize(1, Name);
+ }
+ if (HasId) {
+ size += pb::CodedOutputStream.ComputeInt32Size(2, Id);
+ }
+ if (HasEmail) {
+ size += pb::CodedOutputStream.ComputeStringSize(3, Email);
+ }
+ {
+ int dataSize = 0;
+ foreach (int element in CodesList) {
+ dataSize += pb::CodedOutputStream.ComputeInt32SizeNoTag(element);
+ }
+ size += dataSize;
+ if (codes_.Count != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeInt32SizeNoTag(dataSize);
+ }
+ codesMemoizedSerializedSize = dataSize;
+ }
+ foreach (global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber element in PhoneList) {
+ size += pb::CodedOutputStream.ComputeMessageSize(4, element);
+ }
+ foreach (global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses element in AddressesList) {
+ size += pb::CodedOutputStream.ComputeGroupSize(5, element);
+ }
+ size += ExtensionsSerializedSize;
+ memoizedSerializedSize = size;
+ return size;
+ }
+ }
+
+ #region Lite runtime methods
+ public override int GetHashCode() {
+ int hash = GetType().GetHashCode();
+ if (hasName) hash ^= name_.GetHashCode();
+ if (hasId) hash ^= id_.GetHashCode();
+ if (hasEmail) hash ^= email_.GetHashCode();
+ foreach(int i in codes_)
+ hash ^= i.GetHashCode();
+ foreach(global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber i in phone_)
+ hash ^= i.GetHashCode();
+ foreach(global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses i in addresses_)
+ hash ^= i.GetHashCode();
+ hash ^= base.GetHashCode();
+ return hash;
+ }
+
+ public override bool Equals(object obj) {
+ TestInteropPersonLite other = obj as TestInteropPersonLite;
+ if (other == null) return false;
+ if (hasName != other.hasName || (hasName && !name_.Equals(other.name_))) return false;
+ if (hasId != other.hasId || (hasId && !id_.Equals(other.id_))) return false;
+ if (hasEmail != other.hasEmail || (hasEmail && !email_.Equals(other.email_))) return false;
+ if(codes_.Count != other.codes_.Count) return false;
+ for(int ix=0; ix < codes_.Count; ix++)
+ if(!codes_[ix].Equals(other.codes_[ix])) return false;
+ if(phone_.Count != other.phone_.Count) return false;
+ for(int ix=0; ix < phone_.Count; ix++)
+ if(!phone_[ix].Equals(other.phone_[ix])) return false;
+ if(addresses_.Count != other.addresses_.Count) return false;
+ for(int ix=0; ix < addresses_.Count; ix++)
+ if(!addresses_[ix].Equals(other.addresses_[ix])) return false;
+ if (!base.Equals(other)) return false;
+ return true;
+ }
+
+ public override void PrintTo(global::System.IO.TextWriter writer) {
+ PrintField("name", hasName, name_, writer);
+ PrintField("id", hasId, id_, writer);
+ PrintField("email", hasEmail, email_, writer);
+ PrintField("phone", phone_, writer);
+ PrintField("Addresses", addresses_, writer);
+ PrintField("codes", codes_, writer);
+ base.PrintTo(writer);
+ }
+ #endregion
+
+ public static TestInteropPersonLite ParseFrom(pb::ByteString data) {
+ return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
+ }
+ public static TestInteropPersonLite ParseFrom(pb::ByteString data, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
+ }
+ public static TestInteropPersonLite ParseFrom(byte[] data) {
+ return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
+ }
+ public static TestInteropPersonLite ParseFrom(byte[] data, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
+ }
+ public static TestInteropPersonLite ParseFrom(global::System.IO.Stream input) {
+ return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
+ }
+ public static TestInteropPersonLite ParseFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
+ }
+ public static TestInteropPersonLite ParseDelimitedFrom(global::System.IO.Stream input) {
+ return CreateBuilder().MergeDelimitedFrom(input).BuildParsed();
+ }
+ public static TestInteropPersonLite ParseDelimitedFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
+ return CreateBuilder().MergeDelimitedFrom(input, extensionRegistry).BuildParsed();
+ }
+ public static TestInteropPersonLite ParseFrom(pb::CodedInputStream input) {
+ return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
+ }
+ public static TestInteropPersonLite 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(TestInteropPersonLite prototype) {
+ return (Builder) new Builder().MergeFrom(prototype);
+ }
+
+ public sealed partial class Builder : pb::ExtendableBuilderLite<TestInteropPersonLite, Builder> {
+ protected override Builder ThisBuilder {
+ get { return this; }
+ }
+ public Builder() {}
+
+ TestInteropPersonLite result = new TestInteropPersonLite();
+
+ protected override TestInteropPersonLite MessageBeingBuilt {
+ get { return result; }
+ }
+
+ public override Builder Clear() {
+ result = new TestInteropPersonLite();
+ return this;
+ }
+
+ public override Builder Clone() {
+ return new Builder().MergeFrom(result);
+ }
+
+ public override TestInteropPersonLite DefaultInstanceForType {
+ get { return global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.DefaultInstance; }
+ }
+
+ public override TestInteropPersonLite BuildPartial() {
+ if (result == null) {
+ throw new global::System.InvalidOperationException("build() has already been called on this Builder");
+ }
+ result.codes_.MakeReadOnly();
+ result.phone_.MakeReadOnly();
+ result.addresses_.MakeReadOnly();
+ TestInteropPersonLite returnMe = result;
+ result = null;
+ return returnMe;
+ }
+
+ public override Builder MergeFrom(pb::IMessageLite other) {
+ if (other is TestInteropPersonLite) {
+ return MergeFrom((TestInteropPersonLite) other);
+ } else {
+ base.MergeFrom(other);
+ return this;
+ }
+ }
+
+ public override Builder MergeFrom(TestInteropPersonLite other) {
+ if (other == global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.DefaultInstance) return this;
+ if (other.HasName) {
+ Name = other.Name;
+ }
+ if (other.HasId) {
+ Id = other.Id;
+ }
+ if (other.HasEmail) {
+ Email = other.Email;
+ }
+ if (other.codes_.Count != 0) {
+ base.AddRange(other.codes_, result.codes_);
+ }
+ if (other.phone_.Count != 0) {
+ base.AddRange(other.phone_, result.phone_);
+ }
+ if (other.addresses_.Count != 0) {
+ base.AddRange(other.addresses_, result.addresses_);
+ }
+ this.MergeExtensionFields(other);
+ 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: {
+ Name = input.ReadString();
+ break;
+ }
+ case 16: {
+ Id = input.ReadInt32();
+ break;
+ }
+ case 26: {
+ Email = input.ReadString();
+ break;
+ }
+ case 34: {
+ global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber.Builder subBuilder = global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber.CreateBuilder();
+ input.ReadMessage(subBuilder, extensionRegistry);
+ AddPhone(subBuilder.BuildPartial());
+ break;
+ }
+ case 43: {
+ global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses.Builder subBuilder = global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses.CreateBuilder();
+ input.ReadGroup(5, subBuilder, extensionRegistry);
+ AddAddresses(subBuilder.BuildPartial());
+ break;
+ }
+ case 82: {
+ int length = input.ReadInt32();
+ int limit = input.PushLimit(length);
+ while (!input.ReachedLimit) {
+ AddCodes(input.ReadInt32());
+ }
+ input.PopLimit(limit);
+ break;
+ }
+ }
+ }
+ }
+
+
+ public bool HasName {
+ get { return result.HasName; }
+ }
+ public string Name {
+ get { return result.Name; }
+ set { SetName(value); }
+ }
+ public Builder SetName(string value) {
+ pb::ThrowHelper.ThrowIfNull(value, "value");
+ result.hasName = true;
+ result.name_ = value;
+ return this;
+ }
+ public Builder ClearName() {
+ result.hasName = false;
+ result.name_ = "";
+ return this;
+ }
+
+ public bool HasId {
+ get { return result.HasId; }
+ }
+ public int Id {
+ get { return result.Id; }
+ set { SetId(value); }
+ }
+ public Builder SetId(int value) {
+ result.hasId = true;
+ result.id_ = value;
+ return this;
+ }
+ public Builder ClearId() {
+ result.hasId = false;
+ result.id_ = 0;
+ return this;
+ }
+
+ public bool HasEmail {
+ get { return result.HasEmail; }
+ }
+ public string Email {
+ get { return result.Email; }
+ set { SetEmail(value); }
+ }
+ public Builder SetEmail(string value) {
+ pb::ThrowHelper.ThrowIfNull(value, "value");
+ result.hasEmail = true;
+ result.email_ = value;
+ return this;
+ }
+ public Builder ClearEmail() {
+ result.hasEmail = false;
+ result.email_ = "";
+ return this;
+ }
+
+ public pbc::IPopsicleList<int> CodesList {
+ get { return result.codes_; }
+ }
+ public int CodesCount {
+ get { return result.CodesCount; }
+ }
+ public int GetCodes(int index) {
+ return result.GetCodes(index);
+ }
+ public Builder SetCodes(int index, int value) {
+ result.codes_[index] = value;
+ return this;
+ }
+ public Builder AddCodes(int value) {
+ result.codes_.Add(value);
+ return this;
+ }
+ public Builder AddRangeCodes(scg::IEnumerable<int> values) {
+ base.AddRange(values, result.codes_);
+ return this;
+ }
+ public Builder ClearCodes() {
+ result.codes_.Clear();
+ return this;
+ }
+
+ public pbc::IPopsicleList<global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber> PhoneList {
+ get { return result.phone_; }
+ }
+ public int PhoneCount {
+ get { return result.PhoneCount; }
+ }
+ public global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber GetPhone(int index) {
+ return result.GetPhone(index);
+ }
+ public Builder SetPhone(int index, global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber value) {
+ pb::ThrowHelper.ThrowIfNull(value, "value");
+ result.phone_[index] = value;
+ return this;
+ }
+ public Builder SetPhone(int index, global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber.Builder builderForValue) {
+ pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue");
+ result.phone_[index] = builderForValue.Build();
+ return this;
+ }
+ public Builder AddPhone(global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber value) {
+ pb::ThrowHelper.ThrowIfNull(value, "value");
+ result.phone_.Add(value);
+ return this;
+ }
+ public Builder AddPhone(global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber.Builder builderForValue) {
+ pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue");
+ result.phone_.Add(builderForValue.Build());
+ return this;
+ }
+ public Builder AddRangePhone(scg::IEnumerable<global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.PhoneNumber> values) {
+ base.AddRange(values, result.phone_);
+ return this;
+ }
+ public Builder ClearPhone() {
+ result.phone_.Clear();
+ return this;
+ }
+
+ public pbc::IPopsicleList<global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses> AddressesList {
+ get { return result.addresses_; }
+ }
+ public int AddressesCount {
+ get { return result.AddressesCount; }
+ }
+ public global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses GetAddresses(int index) {
+ return result.GetAddresses(index);
+ }
+ public Builder SetAddresses(int index, global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses value) {
+ pb::ThrowHelper.ThrowIfNull(value, "value");
+ result.addresses_[index] = value;
+ return this;
+ }
+ public Builder SetAddresses(int index, global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses.Builder builderForValue) {
+ pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue");
+ result.addresses_[index] = builderForValue.Build();
+ return this;
+ }
+ public Builder AddAddresses(global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses value) {
+ pb::ThrowHelper.ThrowIfNull(value, "value");
+ result.addresses_.Add(value);
+ return this;
+ }
+ public Builder AddAddresses(global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses.Builder builderForValue) {
+ pb::ThrowHelper.ThrowIfNull(builderForValue, "builderForValue");
+ result.addresses_.Add(builderForValue.Build());
+ return this;
+ }
+ public Builder AddRangeAddresses(scg::IEnumerable<global::Google.ProtocolBuffers.TestProtos.TestInteropPersonLite.Types.Addresses> values) {
+ base.AddRange(values, result.addresses_);
+ return this;
+ }
+ public Builder ClearAddresses() {
+ result.addresses_.Clear();
+ return this;
+ }
+ }
+ static TestInteropPersonLite() {
+ object.ReferenceEquals(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasLiteProtoFile.Descriptor, null);
+ }
+ }
+
+ public sealed partial class TestInteropEmployeeIdLite : pb::GeneratedMessageLite<TestInteropEmployeeIdLite, TestInteropEmployeeIdLite.Builder> {
+ private static readonly TestInteropEmployeeIdLite defaultInstance = new Builder().BuildPartial();
+ public static TestInteropEmployeeIdLite DefaultInstance {
+ get { return defaultInstance; }
+ }
+
+ public override TestInteropEmployeeIdLite DefaultInstanceForType {
+ get { return defaultInstance; }
+ }
+
+ protected override TestInteropEmployeeIdLite ThisMessage {
+ get { return this; }
+ }
+
+ public const int NumberFieldNumber = 1;
+ private bool hasNumber;
+ private string number_ = "";
+ public bool HasNumber {
+ get { return hasNumber; }
+ }
+ public string Number {
+ get { return number_; }
+ }
+
+ public override bool IsInitialized {
+ get {
+ if (!hasNumber) return false;
+ return true;
+ }
+ }
+
+ public override void WriteTo(pb::CodedOutputStream output) {
+ int size = SerializedSize;
+ if (HasNumber) {
+ output.WriteString(1, Number);
+ }
+ }
+
+ private int memoizedSerializedSize = -1;
+ public override int SerializedSize {
+ get {
+ int size = memoizedSerializedSize;
+ if (size != -1) return size;
+
+ size = 0;
+ if (HasNumber) {
+ size += pb::CodedOutputStream.ComputeStringSize(1, Number);
+ }
+ memoizedSerializedSize = size;
+ return size;
+ }
+ }
+
+ #region Lite runtime methods
+ public override int GetHashCode() {
+ int hash = GetType().GetHashCode();
+ if (hasNumber) hash ^= number_.GetHashCode();
+ return hash;
+ }
+
+ public override bool Equals(object obj) {
+ TestInteropEmployeeIdLite other = obj as TestInteropEmployeeIdLite;
+ if (other == null) return false;
+ if (hasNumber != other.hasNumber || (hasNumber && !number_.Equals(other.number_))) return false;
+ return true;
+ }
+
+ public override void PrintTo(global::System.IO.TextWriter writer) {
+ PrintField("number", hasNumber, number_, writer);
+ }
+ #endregion
+
+ public static TestInteropEmployeeIdLite ParseFrom(pb::ByteString data) {
+ return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
+ }
+ public static TestInteropEmployeeIdLite ParseFrom(pb::ByteString data, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
+ }
+ public static TestInteropEmployeeIdLite ParseFrom(byte[] data) {
+ return ((Builder) CreateBuilder().MergeFrom(data)).BuildParsed();
+ }
+ public static TestInteropEmployeeIdLite ParseFrom(byte[] data, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(data, extensionRegistry)).BuildParsed();
+ }
+ public static TestInteropEmployeeIdLite ParseFrom(global::System.IO.Stream input) {
+ return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
+ }
+ public static TestInteropEmployeeIdLite ParseFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
+ return ((Builder) CreateBuilder().MergeFrom(input, extensionRegistry)).BuildParsed();
+ }
+ public static TestInteropEmployeeIdLite ParseDelimitedFrom(global::System.IO.Stream input) {
+ return CreateBuilder().MergeDelimitedFrom(input).BuildParsed();
+ }
+ public static TestInteropEmployeeIdLite ParseDelimitedFrom(global::System.IO.Stream input, pb::ExtensionRegistry extensionRegistry) {
+ return CreateBuilder().MergeDelimitedFrom(input, extensionRegistry).BuildParsed();
+ }
+ public static TestInteropEmployeeIdLite ParseFrom(pb::CodedInputStream input) {
+ return ((Builder) CreateBuilder().MergeFrom(input)).BuildParsed();
+ }
+ public static TestInteropEmployeeIdLite 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(TestInteropEmployeeIdLite prototype) {
+ return (Builder) new Builder().MergeFrom(prototype);
+ }
+
+ public sealed partial class Builder : pb::GeneratedBuilderLite<TestInteropEmployeeIdLite, Builder> {
+ protected override Builder ThisBuilder {
+ get { return this; }
+ }
+ public Builder() {}
+
+ TestInteropEmployeeIdLite result = new TestInteropEmployeeIdLite();
+
+ protected override TestInteropEmployeeIdLite MessageBeingBuilt {
+ get { return result; }
+ }
+
+ public override Builder Clear() {
+ result = new TestInteropEmployeeIdLite();
+ return this;
+ }
+
+ public override Builder Clone() {
+ return new Builder().MergeFrom(result);
+ }
+
+ public override TestInteropEmployeeIdLite DefaultInstanceForType {
+ get { return global::Google.ProtocolBuffers.TestProtos.TestInteropEmployeeIdLite.DefaultInstance; }
+ }
+
+ public override TestInteropEmployeeIdLite BuildPartial() {
+ if (result == null) {
+ throw new global::System.InvalidOperationException("build() has already been called on this Builder");
+ }
+ TestInteropEmployeeIdLite returnMe = result;
+ result = null;
+ return returnMe;
+ }
+
+ public override Builder MergeFrom(pb::IMessageLite other) {
+ if (other is TestInteropEmployeeIdLite) {
+ return MergeFrom((TestInteropEmployeeIdLite) other);
+ } else {
+ base.MergeFrom(other);
+ return this;
+ }
+ }
+
+ public override Builder MergeFrom(TestInteropEmployeeIdLite other) {
+ if (other == global::Google.ProtocolBuffers.TestProtos.TestInteropEmployeeIdLite.DefaultInstance) return this;
+ if (other.HasNumber) {
+ Number = other.Number;
+ }
+ 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: {
+ Number = input.ReadString();
+ break;
+ }
+ }
+ }
+ }
+
+
+ public bool HasNumber {
+ get { return result.HasNumber; }
+ }
+ public string Number {
+ get { return result.Number; }
+ set { SetNumber(value); }
+ }
+ public Builder SetNumber(string value) {
+ pb::ThrowHelper.ThrowIfNull(value, "value");
+ result.hasNumber = true;
+ result.number_ = value;
+ return this;
+ }
+ public Builder ClearNumber() {
+ result.hasNumber = false;
+ result.number_ = "";
+ return this;
+ }
+ }
+ static TestInteropEmployeeIdLite() {
+ object.ReferenceEquals(global::Google.ProtocolBuffers.TestProtos.UnitTestExtrasLiteProtoFile.Descriptor, null);
+ }
+ }
+
+ #endregion
+
+}
|