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

line-ending-to-crlf

parent 62ce3a62
#region Copyright notice and license #region Copyright notice and license
// Protocol Buffers - Google's data interchange format // Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved. // Copyright 2008 Google Inc. All rights reserved.
// http://github.com/jskeet/dotnet-protobufs/ // http://github.com/jskeet/dotnet-protobufs/
// Original C++/Java/Python code: // Original C++/Java/Python code:
// http://code.google.com/p/protobuf/ // http://code.google.com/p/protobuf/
// //
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are // modification, are permitted provided that the following conditions are
// met: // met:
// //
// * Redistributions of source code must retain the above copyright // * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer. // notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above // * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer // copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the // in the documentation and/or other materials provided with the
// distribution. // distribution.
// * Neither the name of Google Inc. nor the names of its // * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from // contributors may be used to endorse or promote products derived from
// this software without specific prior written permission. // this software without specific prior written permission.
// //
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion #endregion
using System; using System;
namespace Google.ProtocolBuffers { namespace Google.ProtocolBuffers {
/// <summary> /// <summary>
/// Grab-bag of utility functions useful when dealing with RPCs. /// Grab-bag of utility functions useful when dealing with RPCs.
/// </summary> /// </summary>
public static class RpcUtil { public static class RpcUtil {
/// <summary> /// <summary>
/// Converts an Action[IMessage] to an Action[T]. /// Converts an Action[IMessage] to an Action[T].
/// </summary> /// </summary>
public static Action<T> SpecializeCallback<T>(Action<IMessage> action) public static Action<T> SpecializeCallback<T>(Action<IMessage> action)
where T : IMessage<T> { where T : IMessage<T> {
return message => action(message); return message => action(message);
} }
/// <summary> /// <summary>
/// Converts an Action[T] to an Action[IMessage]. /// Converts an Action[T] to an Action[IMessage].
/// The generalized action will accept any message object which has /// The generalized action will accept any message object which has
/// the same descriptor, and will convert it to the correct class /// the same descriptor, and will convert it to the correct class
/// before calling the original action. However, if the generalized /// before calling the original action. However, if the generalized
/// callback is given a message with a different descriptor, an /// callback is given a message with a different descriptor, an
/// exception will be thrown. /// exception will be thrown.
/// </summary> /// </summary>
public static Action<IMessage> GeneralizeCallback<TMessage, TBuilder>(Action<TMessage> action, TMessage defaultInstance) public static Action<IMessage> GeneralizeCallback<TMessage, TBuilder>(Action<TMessage> action, TMessage defaultInstance)
where TMessage : class, IMessage<TMessage, TBuilder> where TMessage : class, IMessage<TMessage, TBuilder>
where TBuilder : IBuilder<TMessage, TBuilder> { where TBuilder : IBuilder<TMessage, TBuilder> {
return message => { return message => {
TMessage castMessage = message as TMessage; TMessage castMessage = message as TMessage;
if (castMessage == null) { if (castMessage == null) {
castMessage = defaultInstance.CreateBuilderForType().MergeFrom(message).Build(); castMessage = defaultInstance.CreateBuilderForType().MergeFrom(message).Build();
} }
action(castMessage); action(castMessage);
}; };
} }
} }
} }
#region Copyright notice and license #region Copyright notice and license
// Protocol Buffers - Google's data interchange format // Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved. // Copyright 2008 Google Inc. All rights reserved.
// http://github.com/jskeet/dotnet-protobufs/ // http://github.com/jskeet/dotnet-protobufs/
// Original C++/Java/Python code: // Original C++/Java/Python code:
// http://code.google.com/p/protobuf/ // http://code.google.com/p/protobuf/
// //
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are // modification, are permitted provided that the following conditions are
// met: // met:
// //
// * Redistributions of source code must retain the above copyright // * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer. // notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above // * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer // copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the // in the documentation and/or other materials provided with the
// distribution. // distribution.
// * Neither the name of Google Inc. nor the names of its // * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from // contributors may be used to endorse or promote products derived from
// this software without specific prior written permission. // this software without specific prior written permission.
// //
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion #endregion
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace Google.ProtocolBuffers namespace Google.ProtocolBuffers
{ {
/// <summary> /// <summary>
/// Class containing helpful workarounds for Silverlight compatibility /// Class containing helpful workarounds for Silverlight compatibility
/// </summary> /// </summary>
internal static class SilverlightCompatibility internal static class SilverlightCompatibility
{ {
#if SILVERLIGHT2 #if SILVERLIGHT2
internal const RegexOptions CompiledRegexWhereAvailable = RegexOptions.None; internal const RegexOptions CompiledRegexWhereAvailable = RegexOptions.None;
#else #else
internal const RegexOptions CompiledRegexWhereAvailable = RegexOptions.Compiled; internal const RegexOptions CompiledRegexWhereAvailable = RegexOptions.Compiled;
#endif #endif
} }
} }
This diff is collapsed.
This diff is collapsed.
#region Copyright notice and license #region Copyright notice and license
// Protocol Buffers - Google's data interchange format // Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved. // Copyright 2008 Google Inc. All rights reserved.
// http://github.com/jskeet/dotnet-protobufs/ // http://github.com/jskeet/dotnet-protobufs/
// Original C++/Java/Python code: // Original C++/Java/Python code:
// http://code.google.com/p/protobuf/ // http://code.google.com/p/protobuf/
// //
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are // modification, are permitted provided that the following conditions are
// met: // met:
// //
// * Redistributions of source code must retain the above copyright // * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer. // notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above // * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer // copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the // in the documentation and/or other materials provided with the
// distribution. // distribution.
// * Neither the name of Google Inc. nor the names of its // * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from // contributors may be used to endorse or promote products derived from
// this software without specific prior written permission. // this software without specific prior written permission.
// //
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion #endregion
using System; using System;
using System.IO; using System.IO;
using System.Text; using System.Text;
namespace Google.ProtocolBuffers { namespace Google.ProtocolBuffers {
/// <summary> /// <summary>
/// Helper class to control indentation. Used for TextFormat and by ProtoGen. /// Helper class to control indentation. Used for TextFormat and by ProtoGen.
/// </summary> /// </summary>
public sealed class TextGenerator { public sealed class TextGenerator {
/// <summary> /// <summary>
/// The string to use at the end of each line. We assume that "Print" is only called using \n /// The string to use at the end of each line. We assume that "Print" is only called using \n
/// to indicate a line break; that's what we use to detect when we need to indent etc, and /// to indicate a line break; that's what we use to detect when we need to indent etc, and
/// *just* the \n is replaced with the contents of lineBreak. /// *just* the \n is replaced with the contents of lineBreak.
/// </summary> /// </summary>
private readonly string lineBreak; private readonly string lineBreak;
/// <summary> /// <summary>
/// Writer to write formatted text to. /// Writer to write formatted text to.
/// </summary> /// </summary>
private readonly TextWriter writer; private readonly TextWriter writer;
/// <summary> /// <summary>
/// Keeps track of whether the next piece of text should be indented /// Keeps track of whether the next piece of text should be indented
/// </summary> /// </summary>
bool atStartOfLine = true; bool atStartOfLine = true;
/// <summary> /// <summary>
/// Keeps track of the current level of indentation /// Keeps track of the current level of indentation
/// </summary> /// </summary>
readonly StringBuilder indent = new StringBuilder(); readonly StringBuilder indent = new StringBuilder();
/// <summary> /// <summary>
/// Creates a generator writing to the given writer. The writer /// Creates a generator writing to the given writer. The writer
/// is not closed by this class. /// is not closed by this class.
/// </summary> /// </summary>
public TextGenerator(TextWriter writer, string lineBreak) { public TextGenerator(TextWriter writer, string lineBreak) {
this.writer = writer; this.writer = writer;
this.lineBreak = lineBreak; this.lineBreak = lineBreak;
} }
/// <summary> /// <summary>
/// Indents text by two spaces. After calling Indent(), two spaces /// Indents text by two spaces. After calling Indent(), two spaces
/// will be inserted at the beginning of each line of text. Indent() may /// will be inserted at the beginning of each line of text. Indent() may
/// be called multiple times to produce deeper indents. /// be called multiple times to produce deeper indents.
/// </summary> /// </summary>
public void Indent() { public void Indent() {
indent.Append(" "); indent.Append(" ");
} }
/// <summary> /// <summary>
/// Reduces the current indent level by two spaces. /// Reduces the current indent level by two spaces.
/// </summary> /// </summary>
public void Outdent() { public void Outdent() {
if (indent.Length == 0) { if (indent.Length == 0) {
throw new InvalidOperationException("Too many calls to Outdent()"); throw new InvalidOperationException("Too many calls to Outdent()");
} }
indent.Length -= 2; indent.Length -= 2;
} }
public void WriteLine(string text) { public void WriteLine(string text) {
Print(text); Print(text);
Print("\n"); Print("\n");
} }
public void WriteLine(string format, params object[] args) { public void WriteLine(string format, params object[] args) {
WriteLine(string.Format(format, args)); WriteLine(string.Format(format, args));
} }
public void WriteLine() { public void WriteLine() {
WriteLine(""); WriteLine("");
} }
/// <summary> /// <summary>
/// Prints the given text to the output stream, indenting at line boundaries. /// Prints the given text to the output stream, indenting at line boundaries.
/// </summary> /// </summary>
/// <param name="text"></param> /// <param name="text"></param>
public void Print(string text) { public void Print(string text) {
int pos = 0; int pos = 0;
for (int i = 0; i < text.Length; i++) { for (int i = 0; i < text.Length; i++) {
if (text[i] == '\n') { if (text[i] == '\n') {
// Strip off the \n from what we write // Strip off the \n from what we write
Write(text.Substring(pos, i - pos)); Write(text.Substring(pos, i - pos));
Write(lineBreak); Write(lineBreak);
pos = i + 1; pos = i + 1;
atStartOfLine = true; atStartOfLine = true;
} }
} }
Write(text.Substring(pos)); Write(text.Substring(pos));
} }
public void Write(string format, params object[] args) { public void Write(string format, params object[] args) {
Write(string.Format(format, args)); Write(string.Format(format, args));
} }
private void Write(string data) { private void Write(string data) {
if (data.Length == 0) { if (data.Length == 0) {
return; return;
} }
if (atStartOfLine) { if (atStartOfLine) {
atStartOfLine = false; atStartOfLine = false;
writer.Write(indent); writer.Write(indent);
} }
writer.Write(data); writer.Write(data);
} }
} }
} }
This diff is collapsed.
#region Copyright notice and license #region Copyright notice and license
// Protocol Buffers - Google's data interchange format // Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved. // Copyright 2008 Google Inc. All rights reserved.
// http://github.com/jskeet/dotnet-protobufs/ // http://github.com/jskeet/dotnet-protobufs/
// Original C++/Java/Python code: // Original C++/Java/Python code:
// http://code.google.com/p/protobuf/ // http://code.google.com/p/protobuf/
// //
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are // modification, are permitted provided that the following conditions are
// met: // met:
// //
// * Redistributions of source code must retain the above copyright // * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer. // notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above // * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer // copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the // in the documentation and/or other materials provided with the
// distribution. // distribution.
// * Neither the name of Google Inc. nor the names of its // * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from // contributors may be used to endorse or promote products derived from
// this software without specific prior written permission. // this software without specific prior written permission.
// //
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion #endregion
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace Google.ProtocolBuffers { namespace Google.ProtocolBuffers {
/// <summary> /// <summary>
/// Helper methods for throwing exceptions /// Helper methods for throwing exceptions
/// </summary> /// </summary>
public static class ThrowHelper { public static class ThrowHelper {
/// <summary> /// <summary>
/// Throws an ArgumentNullException if the given value is null. /// Throws an ArgumentNullException if the given value is null.
/// </summary> /// </summary>
public static void ThrowIfNull(object value, string name) { public static void ThrowIfNull(object value, string name) {
if (value == null) { if (value == null) {
throw new ArgumentNullException(name); throw new ArgumentNullException(name);
} }
} }
/// <summary> /// <summary>
/// Throws an ArgumentNullException if the given value is null. /// Throws an ArgumentNullException if the given value is null.
/// </summary> /// </summary>
public static void ThrowIfNull(object value) { public static void ThrowIfNull(object value) {
if (value == null) { if (value == null) {
throw new ArgumentNullException(); throw new ArgumentNullException();
} }
} }
/// <summary> /// <summary>
/// Throws an ArgumentNullException if the given value or any element within it is null. /// Throws an ArgumentNullException if the given value or any element within it is null.
/// </summary> /// </summary>
public static void ThrowIfAnyNull<T>(IEnumerable<T> sequence) { public static void ThrowIfAnyNull<T>(IEnumerable<T> sequence) {
foreach (T t in sequence) { foreach (T t in sequence) {
if (t == null) { if (t == null) {
throw new ArgumentNullException(); throw new ArgumentNullException();
} }
} }
} }
} }
} }
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#region Copyright notice and license #region Copyright notice and license
// Protocol Buffers - Google's data interchange format // Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved. // Copyright 2008 Google Inc. All rights reserved.
// http://github.com/jskeet/dotnet-protobufs/ // http://github.com/jskeet/dotnet-protobufs/
// Original C++/Java/Python code: // Original C++/Java/Python code:
// http://code.google.com/p/protobuf/ // http://code.google.com/p/protobuf/
// //
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are // modification, are permitted provided that the following conditions are
// met: // met:
// //
// * Redistributions of source code must retain the above copyright // * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer. // notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above // * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer // copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the // in the documentation and/or other materials provided with the
// distribution. // distribution.
// * Neither the name of Google Inc. nor the names of its // * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from // contributors may be used to endorse or promote products derived from
// this software without specific prior written permission. // this software without specific prior written permission.
// //
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#endregion #endregion
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using Google.ProtocolBuffers; using Google.ProtocolBuffers;
using Google.ProtocolBuffers.TestProtos; using Google.ProtocolBuffers.TestProtos;
using NUnit.Framework; using NUnit.Framework;
namespace Google.ProtocolBuffers { namespace Google.ProtocolBuffers {
[TestFixture] [TestFixture]
public class AbstractMessageLiteTest { public class AbstractMessageLiteTest {
[Test] [Test]
public void TestMessageLiteToByteString() { public void TestMessageLiteToByteString() {
TestRequiredLite msg = TestRequiredLite.CreateBuilder() TestRequiredLite msg = TestRequiredLite.CreateBuilder()
.SetD(42) .SetD(42)
.SetEn(ExtraEnum.EXLITE_BAZ) .SetEn(ExtraEnum.EXLITE_BAZ)
.Build(); .Build();
ByteString b = msg.ToByteString(); ByteString b = msg.ToByteString();
Assert.AreEqual(4, b.Length); Assert.AreEqual(4, b.Length);
Assert.AreEqual(TestRequiredLite.DFieldNumber << 3, b[0]); Assert.AreEqual(TestRequiredLite.DFieldNumber << 3, b[0]);
Assert.AreEqual(42, b[1]); Assert.AreEqual(42, b[1]);
Assert.AreEqual(TestRequiredLite.EnFieldNumber << 3, b[2]); Assert.AreEqual(TestRequiredLite.EnFieldNumber << 3, b[2]);
Assert.AreEqual((int)ExtraEnum.EXLITE_BAZ, b[3]); Assert.AreEqual((int)ExtraEnum.EXLITE_BAZ, b[3]);
} }
[Test] [Test]
public void TestMessageLiteToByteArray() { public void TestMessageLiteToByteArray() {
TestRequiredLite msg = TestRequiredLite.CreateBuilder() TestRequiredLite msg = TestRequiredLite.CreateBuilder()
.SetD(42) .SetD(42)
.SetEn(ExtraEnum.EXLITE_BAZ) .SetEn(ExtraEnum.EXLITE_BAZ)
.Build(); .Build();
ByteString b = msg.ToByteString(); ByteString b = msg.ToByteString();
ByteString copy = ByteString.CopyFrom(msg.ToByteArray()); ByteString copy = ByteString.CopyFrom(msg.ToByteArray());
Assert.AreEqual(b, copy); Assert.AreEqual(b, copy);
} }
[Test] [Test]
public void TestMessageLiteWriteTo() { public void TestMessageLiteWriteTo() {
TestRequiredLite msg = TestRequiredLite.CreateBuilder() TestRequiredLite msg = TestRequiredLite.CreateBuilder()
.SetD(42) .SetD(42)
.SetEn(ExtraEnum.EXLITE_BAZ) .SetEn(ExtraEnum.EXLITE_BAZ)
.Build(); .Build();
MemoryStream ms = new MemoryStream(); MemoryStream ms = new MemoryStream();
msg.WriteTo(ms); msg.WriteTo(ms);
Assert.AreEqual(msg.ToByteArray(), ms.ToArray()); Assert.AreEqual(msg.ToByteArray(), ms.ToArray());
} }
[Test] [Test]
public void TestMessageLiteWriteDelimitedTo() { public void TestMessageLiteWriteDelimitedTo() {
TestRequiredLite msg = TestRequiredLite.CreateBuilder() TestRequiredLite msg = TestRequiredLite.CreateBuilder()
.SetD(42) .SetD(42)
.SetEn(ExtraEnum.EXLITE_BAZ) .SetEn(ExtraEnum.EXLITE_BAZ)
.Build(); .Build();
MemoryStream ms = new MemoryStream(); MemoryStream ms = new MemoryStream();
msg.WriteDelimitedTo(ms); msg.WriteDelimitedTo(ms);
byte[] buffer = ms.ToArray(); byte[] buffer = ms.ToArray();
Assert.AreEqual(5, buffer.Length); Assert.AreEqual(5, buffer.Length);
Assert.AreEqual(4, buffer[0]); Assert.AreEqual(4, buffer[0]);
byte[] msgBytes = new byte[4]; byte[] msgBytes = new byte[4];
Array.Copy(buffer, 1, msgBytes, 0, 4); Array.Copy(buffer, 1, msgBytes, 0, 4);
Assert.AreEqual(msg.ToByteArray(), msgBytes); Assert.AreEqual(msg.ToByteArray(), msgBytes);
} }
[Test] [Test]
public void TestIMessageLiteWeakCreateBuilderForType() { public void TestIMessageLiteWeakCreateBuilderForType() {
IMessageLite msg = TestRequiredLite.DefaultInstance; IMessageLite msg = TestRequiredLite.DefaultInstance;
Assert.AreEqual(typeof(TestRequiredLite.Builder), msg.WeakCreateBuilderForType().GetType()); Assert.AreEqual(typeof(TestRequiredLite.Builder), msg.WeakCreateBuilderForType().GetType());
} }
[Test] [Test]
public void TestMessageLiteWeakToBuilder() { public void TestMessageLiteWeakToBuilder() {
IMessageLite msg = TestRequiredLite.CreateBuilder() IMessageLite msg = TestRequiredLite.CreateBuilder()
.SetD(42) .SetD(42)
.SetEn(ExtraEnum.EXLITE_BAZ) .SetEn(ExtraEnum.EXLITE_BAZ)
.Build(); .Build();
IMessageLite copy = msg.WeakToBuilder().WeakBuild(); IMessageLite copy = msg.WeakToBuilder().WeakBuild();
Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray()); Assert.AreEqual(msg.ToByteArray(), copy.ToByteArray());
} }
[Test] [Test]
public void TestMessageLiteWeakDefaultInstanceForType() { public void TestMessageLiteWeakDefaultInstanceForType() {
IMessageLite msg = TestRequiredLite.DefaultInstance; IMessageLite msg = TestRequiredLite.DefaultInstance;
Assert.IsTrue(Object.ReferenceEquals(TestRequiredLite.DefaultInstance, msg.WeakDefaultInstanceForType)); Assert.IsTrue(Object.ReferenceEquals(TestRequiredLite.DefaultInstance, msg.WeakDefaultInstanceForType));
} }
} }
} }
This diff is collapsed.
This diff is collapsed.
Current task list (not in order) Current task list (not in order)
- Remove multifile support - Remove multifile support
- Docs - Docs
- Clean up protogen code - Clean up protogen code
- Avoid using reflection for messages which don't need it (is this - Avoid using reflection for messages which don't need it (is this
possible?) possible?)
- Bring service generation into line with Java - Bring service generation into line with Java
- Build protoc as a dll and use directly from protogen - Build protoc as a dll and use directly from protogen
- Check copyright is everywhere - Check copyright is everywhere
- Work out how to unit test Silverlight code - Work out how to unit test Silverlight code
- Reformat code - Reformat code
- Change generated format - Change generated format
- Add regions to copyright - Add regions to copyright
- Build and publish binaries - Build and publish binaries
- Work out why the Compact Framework 3.5 build fails under VS2010 - Work out why the Compact Framework 3.5 build fails under VS2010
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment