aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcsharptest <roger@csharptest.net>2011-06-02 17:02:41 -0500
committerrogerk <devnull@localhost>2011-06-02 17:02:41 -0500
commit8a2d0f48d70bd760bf26218f7107c86ca9f91cce (patch)
treeb0391746364a1f2b75c5a190296176798ca3342a /src
parent27bfcc5e1a7a3aacd828475c1996e114e34055d2 (diff)
downloadprotobuf-8a2d0f48d70bd760bf26218f7107c86ca9f91cce.tar.gz
protobuf-8a2d0f48d70bd760bf26218f7107c86ca9f91cce.tar.bz2
protobuf-8a2d0f48d70bd760bf26218f7107c86ca9f91cce.zip
big-endian support for float, and double on Silverlight
Diffstat (limited to 'src')
-rw-r--r--src/ProtocolBuffers/CodedOutputStream.cs15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/ProtocolBuffers/CodedOutputStream.cs b/src/ProtocolBuffers/CodedOutputStream.cs
index f30c8061..50a7f372 100644
--- a/src/ProtocolBuffers/CodedOutputStream.cs
+++ b/src/ProtocolBuffers/CodedOutputStream.cs
@@ -446,12 +446,13 @@ namespace Google.ProtocolBuffers
/// </summary>
public void WriteDoubleNoTag(double value)
{
- // TODO(jonskeet): Test this on different endiannesses
#if SILVERLIGHT2 || COMPACT_FRAMEWORK_35
- byte[] bytes = BitConverter.GetBytes(value);
- WriteRawBytes(bytes, 0, 8);
+ byte[] rawBytes = BitConverter.GetBytes(value);
+ if (!BitConverter.IsLittleEndian)
+ Array.Reverse(rawBytes);
+ WriteRawBytes(rawBytes, 0, 8);
#else
- WriteRawLittleEndian64((ulong)BitConverter.DoubleToInt64Bits(value));
+ WriteRawLittleEndian64((ulong)BitConverter.DoubleToInt64Bits(value));
#endif
}
@@ -460,10 +461,10 @@ namespace Google.ProtocolBuffers
/// </summary>
public void WriteFloatNoTag(float value)
{
- // TODO(jonskeet): Test this on different endiannesses
byte[] rawBytes = BitConverter.GetBytes(value);
- uint asInteger = BitConverter.ToUInt32(rawBytes, 0);
- WriteRawLittleEndian32(asInteger);
+ if (!BitConverter.IsLittleEndian)
+ Array.Reverse(rawBytes);
+ WriteRawBytes(rawBytes, 0, 4);
}
/// <summary>