Commit 8a2d0f48 authored by csharptest's avatar csharptest Committed by rogerk

big-endian support for float, and double on Silverlight

parent 27bfcc5e
...@@ -446,12 +446,13 @@ namespace Google.ProtocolBuffers ...@@ -446,12 +446,13 @@ namespace Google.ProtocolBuffers
/// </summary> /// </summary>
public void WriteDoubleNoTag(double value) public void WriteDoubleNoTag(double value)
{ {
// TODO(jonskeet): Test this on different endiannesses
#if SILVERLIGHT2 || COMPACT_FRAMEWORK_35 #if SILVERLIGHT2 || COMPACT_FRAMEWORK_35
byte[] bytes = BitConverter.GetBytes(value); byte[] rawBytes = BitConverter.GetBytes(value);
WriteRawBytes(bytes, 0, 8); if (!BitConverter.IsLittleEndian)
Array.Reverse(rawBytes);
WriteRawBytes(rawBytes, 0, 8);
#else #else
WriteRawLittleEndian64((ulong)BitConverter.DoubleToInt64Bits(value)); WriteRawLittleEndian64((ulong)BitConverter.DoubleToInt64Bits(value));
#endif #endif
} }
...@@ -460,10 +461,10 @@ namespace Google.ProtocolBuffers ...@@ -460,10 +461,10 @@ namespace Google.ProtocolBuffers
/// </summary> /// </summary>
public void WriteFloatNoTag(float value) public void WriteFloatNoTag(float value)
{ {
// TODO(jonskeet): Test this on different endiannesses
byte[] rawBytes = BitConverter.GetBytes(value); byte[] rawBytes = BitConverter.GetBytes(value);
uint asInteger = BitConverter.ToUInt32(rawBytes, 0); if (!BitConverter.IsLittleEndian)
WriteRawLittleEndian32(asInteger); Array.Reverse(rawBytes);
WriteRawBytes(rawBytes, 0, 4);
} }
/// <summary> /// <summary>
......
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