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

line-ending-to-crlf

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