THRIFT-1037 Proposed changes to support Silverlight, Windows Phone and AsyncCTP v3
Patch: Damian Mehers & Jens Geyer
git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1211880 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/csharp/src/Protocol/TBinaryProtocol.cs b/lib/csharp/src/Protocol/TBinaryProtocol.cs
index 4b3980e..e6b69d6 100644
--- a/lib/csharp/src/Protocol/TBinaryProtocol.cs
+++ b/lib/csharp/src/Protocol/TBinaryProtocol.cs
@@ -201,7 +201,12 @@
public override void WriteDouble(double d)
{
+#if !SILVERLIGHT
WriteI64(BitConverter.DoubleToInt64Bits(d));
+#else
+ var bytes = BitConverter.GetBytes(d);
+ WriteI64(BitConverter.ToInt64(bytes, 0));
+#endif
}
public override void WriteBinary(byte[] b)
@@ -348,7 +353,13 @@
public override double ReadDouble()
{
+#if !SILVERLIGHT
return BitConverter.Int64BitsToDouble(ReadI64());
+#else
+ var value = ReadI64();
+ var bytes = BitConverter.GetBytes(value);
+ return BitConverter.ToDouble(bytes, 0);
+#endif
}
public void SetReadLength(int readLength)
@@ -382,7 +393,7 @@
CheckReadLength(size);
byte[] buf = new byte[size];
trans.ReadAll(buf, 0, size);
- return Encoding.UTF8.GetString(buf);
+ return Encoding.UTF8.GetString(buf, 0, buf.Length);
}
private int ReadAll(byte[] buf, int off, int len)
diff --git a/lib/csharp/src/Protocol/TJSONProtocol.cs b/lib/csharp/src/Protocol/TJSONProtocol.cs
index a35fcd3..ed6970e 100644
--- a/lib/csharp/src/Protocol/TJSONProtocol.cs
+++ b/lib/csharp/src/Protocol/TJSONProtocol.cs
@@ -841,7 +841,7 @@
if (reader.Peek() == QUOTE[0])
{
byte[] arr = ReadJSONString(true);
- double dub = Double.Parse(utf8Encoding.GetString(arr), CultureInfo.InvariantCulture);
+ double dub = Double.Parse(utf8Encoding.GetString(arr,0,arr.Length), CultureInfo.InvariantCulture);
if (!context.EscapeNumbers() && !Double.IsNaN(dub) &&
!Double.IsInfinity(dub))
@@ -938,7 +938,8 @@
"Message contained bad version.");
}
- message.Name = utf8Encoding.GetString(ReadJSONString(false));
+ var buf = ReadJSONString(false);
+ message.Name = utf8Encoding.GetString(buf,0,buf.Length);
message.Type = (TMessageType)ReadJSONInteger();
message.SeqID = (int)ReadJSONInteger();
return message;
@@ -1059,7 +1060,8 @@
public override String ReadString()
{
- return utf8Encoding.GetString(ReadJSONString(false));
+ var buf = ReadJSONString(false);
+ return utf8Encoding.GetString(buf,0,buf.Length);
}
public override byte[] ReadBinary()
diff --git a/lib/csharp/src/Protocol/TProtocol.cs b/lib/csharp/src/Protocol/TProtocol.cs
index 4f723dd..b6884c9 100644
--- a/lib/csharp/src/Protocol/TProtocol.cs
+++ b/lib/csharp/src/Protocol/TProtocol.cs
@@ -84,8 +84,9 @@
public abstract long ReadI64();
public abstract double ReadDouble();
public virtual string ReadString() {
- return Encoding.UTF8.GetString(ReadBinary());
- }
+ var buf = ReadBinary();
+ return Encoding.UTF8.GetString(buf, 0, buf.Length);
+ }
public abstract byte[] ReadBinary();
}
}