aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJon Skeet <skeet@pobox.com>2009-09-09 13:22:36 +0100
committerJon Skeet <skeet@pobox.com>2009-09-09 13:22:36 +0100
commit3c80886fa9043cba3b0ecc0362935b014066b89f (patch)
tree45bb5b6ae25875edf877bc59d3e071f3596d252a /src
parent79a8c010332d3255bc20ad2b8da463c6179bb422 (diff)
downloadprotobuf-3c80886fa9043cba3b0ecc0362935b014066b89f.tar.gz
protobuf-3c80886fa9043cba3b0ecc0362935b014066b89f.tar.bz2
protobuf-3c80886fa9043cba3b0ecc0362935b014066b89f.zip
Silverlight compatibility other than SortedList
Diffstat (limited to 'src')
-rw-r--r--src/ProtocolBuffers/CodedInputStream.cs6
-rw-r--r--src/ProtocolBuffers/CodedOutputStream.cs14
-rw-r--r--src/ProtocolBuffers/Descriptors/DescriptorPool.cs2
-rw-r--r--src/ProtocolBuffers/SilverlightCompatibility.cs50
-rw-r--r--src/ProtocolBuffers/TextTokenizer.cs23
5 files changed, 74 insertions, 21 deletions
diff --git a/src/ProtocolBuffers/CodedInputStream.cs b/src/ProtocolBuffers/CodedInputStream.cs
index e652af0d..ab0d32e1 100644
--- a/src/ProtocolBuffers/CodedInputStream.cs
+++ b/src/ProtocolBuffers/CodedInputStream.cs
@@ -160,8 +160,12 @@ namespace Google.ProtocolBuffers {
/// Read a double field from the stream.
/// </summary>
public double ReadDouble() {
- // TODO(jonskeet): Test this on different endiannesses
+#if SILVERLIGHT2
+ byte[] bytes = ReadRawBytes(8);
+ return BitConverter.ToDouble(bytes, 0);
+#else
return BitConverter.Int64BitsToDouble((long) ReadRawLittleEndian64());
+#endif
}
/// <summary>
diff --git a/src/ProtocolBuffers/CodedOutputStream.cs b/src/ProtocolBuffers/CodedOutputStream.cs
index e5f890f9..241c4acb 100644
--- a/src/ProtocolBuffers/CodedOutputStream.cs
+++ b/src/ProtocolBuffers/CodedOutputStream.cs
@@ -114,9 +114,8 @@ namespace Google.ProtocolBuffers {
/// Writes a double field value, including tag, to the stream.
/// </summary>
public void WriteDouble(int fieldNumber, double value) {
- // TODO(jonskeet): Test this on different endiannesses
WriteTag(fieldNumber, WireFormat.WireType.Fixed64);
- WriteRawLittleEndian64((ulong)BitConverter.DoubleToInt64Bits(value));
+ WriteDoubleNoTag(value);
}
/// <summary>
@@ -124,10 +123,7 @@ namespace Google.ProtocolBuffers {
/// </summary>
public void WriteFloat(int fieldNumber, float value) {
WriteTag(fieldNumber, WireFormat.WireType.Fixed32);
- // TODO(jonskeet): Test this on different endiannesses
- byte[] rawBytes = BitConverter.GetBytes(value);
- uint asInteger = BitConverter.ToUInt32(rawBytes, 0);
- WriteRawLittleEndian32(asInteger);
+ WriteFloatNoTag(value);
}
/// <summary>
@@ -332,7 +328,13 @@ namespace Google.ProtocolBuffers {
/// Writes a double field value, including tag, to the stream.
/// </summary>
public void WriteDoubleNoTag(double value) {
+ // TODO(jonskeet): Test this on different endiannesses
+#if SILVERLIGHT2
+ byte[] bytes = BitConverter.GetBytes(value);
+ WriteRawBytes(bytes, 0, 8);
+#else
WriteRawLittleEndian64((ulong)BitConverter.DoubleToInt64Bits(value));
+#endif
}
/// <summary>
diff --git a/src/ProtocolBuffers/Descriptors/DescriptorPool.cs b/src/ProtocolBuffers/Descriptors/DescriptorPool.cs
index 72dd1899..c8654572 100644
--- a/src/ProtocolBuffers/Descriptors/DescriptorPool.cs
+++ b/src/ProtocolBuffers/Descriptors/DescriptorPool.cs
@@ -139,7 +139,7 @@ namespace Google.ProtocolBuffers.Descriptors {
descriptorsByName[fullName] = descriptor;
}
- private static readonly Regex ValidationRegex = new Regex("^[_A-Za-z][_A-Za-z0-9]*$", RegexOptions.Compiled);
+ private static readonly Regex ValidationRegex = new Regex("^[_A-Za-z][_A-Za-z0-9]*$", SilverlightCompatibility.CompiledRegexWhereAvailable);
/// <summary>
/// Verifies that the descriptor's name is valid (i.e. it contains
diff --git a/src/ProtocolBuffers/SilverlightCompatibility.cs b/src/ProtocolBuffers/SilverlightCompatibility.cs
new file mode 100644
index 00000000..6a772174
--- /dev/null
+++ b/src/ProtocolBuffers/SilverlightCompatibility.cs
@@ -0,0 +1,50 @@
+// 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.
+
+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
+
+ }
+}
diff --git a/src/ProtocolBuffers/TextTokenizer.cs b/src/ProtocolBuffers/TextTokenizer.cs
index d25a5874..4090d1da 100644
--- a/src/ProtocolBuffers/TextTokenizer.cs
+++ b/src/ProtocolBuffers/TextTokenizer.cs
@@ -69,25 +69,22 @@ namespace Google.ProtocolBuffers {
/// </summary>
private int previousColumn = 0;
-#if SILVERLIGHT
- private const RegexOptions CompiledRegexWhereAvailable = RegexOptions.None;
-#else
- private const RegexOptions CompiledRegexWhereAvailable = RegexOptions.Compiled;
-#endif
-
// Note: atomic groups used to mimic possessive quantifiers in Java in both of these regexes
- private static readonly Regex WhitespaceAndCommentPattern = new Regex("\\G(?>(\\s|(#.*$))+)",
- CompiledRegexWhereAvailable | RegexOptions.Multiline);
+ internal static readonly Regex WhitespaceAndCommentPattern = new Regex("\\G(?>(\\s|(#.*$))+)",
+ SilverlightCompatibility.CompiledRegexWhereAvailable | RegexOptions.Multiline);
private static readonly Regex TokenPattern = new Regex(
"\\G[a-zA-Z_](?>[0-9a-zA-Z_+-]*)|" + // an identifier
"\\G[0-9+-](?>[0-9a-zA-Z_.+-]*)|" + // a number
"\\G\"(?>([^\"\\\n\\\\]|\\\\.)*)(\"|\\\\?$)|" + // a double-quoted string
"\\G\'(?>([^\"\\\n\\\\]|\\\\.)*)(\'|\\\\?$)", // a single-quoted string
- RegexOptions.Compiled | RegexOptions.Multiline);
-
- private static readonly Regex DoubleInfinity = new Regex("^-?inf(inity)?$", CompiledRegexWhereAvailable | RegexOptions.IgnoreCase);
- private static readonly Regex FloatInfinity = new Regex("^-?inf(inity)?f?$", CompiledRegexWhereAvailable | RegexOptions.IgnoreCase);
- private static readonly Regex FloatNan = new Regex("^nanf?$", CompiledRegexWhereAvailable | RegexOptions.IgnoreCase);
+ SilverlightCompatibility.CompiledRegexWhereAvailable | RegexOptions.Multiline);
+
+ private static readonly Regex DoubleInfinity = new Regex("^-?inf(inity)?$",
+ SilverlightCompatibility.CompiledRegexWhereAvailable | RegexOptions.IgnoreCase);
+ private static readonly Regex FloatInfinity = new Regex("^-?inf(inity)?f?$",
+ SilverlightCompatibility.CompiledRegexWhereAvailable | RegexOptions.IgnoreCase);
+ private static readonly Regex FloatNan = new Regex("^nanf?$",
+ SilverlightCompatibility.CompiledRegexWhereAvailable | RegexOptions.IgnoreCase);
/** Construct a tokenizer that parses tokens from the given text. */
public TextTokenizer(string text) {