mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-14 04:15:41 +00:00
Compare commits
No commits in common. "30b7a465a7c1ed9bb2cfb3f9bf1550f60d9d210a" and "ed46bcd0d8d6f9849d9e9ee06298e2b41a15f8fd" have entirely different histories.
30b7a465a7
...
ed46bcd0d8
@ -1,4 +1,4 @@
|
|||||||
using System.Diagnostics.Contracts;
|
using System.Diagnostics.Contracts;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
namespace X10D.IO;
|
namespace X10D.IO;
|
||||||
@ -97,22 +97,15 @@ public static class DecimalExtensions
|
|||||||
#else
|
#else
|
||||||
Span<byte> buffer = stackalloc byte[16];
|
Span<byte> buffer = stackalloc byte[16];
|
||||||
MemoryMarshal.Write(buffer, ref value);
|
MemoryMarshal.Write(buffer, ref value);
|
||||||
WriteBits(destination, buffer);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void WriteBits(Span<int> destination, Span<byte> buffer)
|
|
||||||
{
|
|
||||||
var flags = MemoryMarshal.Read<int>(buffer[..4]);
|
var flags = MemoryMarshal.Read<int>(buffer[..4]);
|
||||||
var hi = MemoryMarshal.Read<int>(buffer[4..8]);
|
var hi = MemoryMarshal.Read<int>(buffer[4..8]);
|
||||||
var lo = MemoryMarshal.Read<long>(buffer[8..]);
|
var lo = MemoryMarshal.Read<long>(buffer[8..]);
|
||||||
|
|
||||||
var low = (uint)lo;
|
destination[0] = flags;
|
||||||
var mid = (uint)(lo >> 32);
|
destination[1] = hi;
|
||||||
|
destination[2] = (int)(lo & 0xFFFFFFFF);
|
||||||
destination[0] = (int)low;
|
destination[3] = (int)(lo >> 32);
|
||||||
destination[1] = (int)mid;
|
#endif
|
||||||
destination[2] = hi;
|
|
||||||
destination[3] = flags;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,11 +48,11 @@ public static class DoubleExtensions
|
|||||||
#else
|
#else
|
||||||
if (BitConverter.IsLittleEndian)
|
if (BitConverter.IsLittleEndian)
|
||||||
{
|
{
|
||||||
long tmp = BinaryPrimitives.ReverseEndianness(BitConverter.DoubleToInt64Bits(value));
|
return MemoryMarshal.TryWrite(destination, ref value);
|
||||||
return MemoryMarshal.TryWrite(destination, ref tmp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return MemoryMarshal.TryWrite(destination, ref value);
|
long tmp = BinaryPrimitives.ReverseEndianness(BitConverter.DoubleToInt64Bits(value));
|
||||||
|
return MemoryMarshal.TryWrite(destination, ref tmp);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ public static class DoubleExtensions
|
|||||||
#if NET5_0_OR_GREATER
|
#if NET5_0_OR_GREATER
|
||||||
return BinaryPrimitives.TryWriteDoubleLittleEndian(destination, value);
|
return BinaryPrimitives.TryWriteDoubleLittleEndian(destination, value);
|
||||||
#else
|
#else
|
||||||
if (BitConverter.IsLittleEndian)
|
if (!BitConverter.IsLittleEndian)
|
||||||
{
|
{
|
||||||
return MemoryMarshal.TryWrite(destination, ref value);
|
return MemoryMarshal.TryWrite(destination, ref value);
|
||||||
}
|
}
|
||||||
|
@ -50,11 +50,11 @@ public static class SingleExtensions
|
|||||||
#else
|
#else
|
||||||
if (BitConverter.IsLittleEndian)
|
if (BitConverter.IsLittleEndian)
|
||||||
{
|
{
|
||||||
int tmp = BinaryPrimitives.ReverseEndianness(BitConverter.SingleToInt32Bits(value));
|
return MemoryMarshal.TryWrite(destination, ref value);
|
||||||
return MemoryMarshal.TryWrite(destination, ref tmp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return MemoryMarshal.TryWrite(destination, ref value);
|
int tmp = BinaryPrimitives.ReverseEndianness(BitConverter.SingleToInt32Bits(value));
|
||||||
|
return MemoryMarshal.TryWrite(destination, ref tmp);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ public static class SingleExtensions
|
|||||||
#if NET5_0_OR_GREATER
|
#if NET5_0_OR_GREATER
|
||||||
return BinaryPrimitives.TryWriteSingleLittleEndian(destination, value);
|
return BinaryPrimitives.TryWriteSingleLittleEndian(destination, value);
|
||||||
#else
|
#else
|
||||||
if (BitConverter.IsLittleEndian)
|
if (!BitConverter.IsLittleEndian)
|
||||||
{
|
{
|
||||||
return MemoryMarshal.TryWrite(destination, ref value);
|
return MemoryMarshal.TryWrite(destination, ref value);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user