Got at least one data fetching method working; turns out, we can't use a patched LogicStack to get the data
This commit is contained in:
44
Vendor/EmbedIO-3.5.2/Net/Internal/NetExtensions.cs
vendored
Normal file
44
Vendor/EmbedIO-3.5.2/Net/Internal/NetExtensions.cs
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Swan;
|
||||
|
||||
namespace EmbedIO.Net.Internal
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents some System.NET custom extensions.
|
||||
/// </summary>
|
||||
internal static class NetExtensions
|
||||
{
|
||||
internal static byte[] ToByteArray(this ushort value, Endianness order)
|
||||
{
|
||||
var bytes = BitConverter.GetBytes(value);
|
||||
if (!order.IsHostOrder())
|
||||
{
|
||||
Array.Reverse(bytes);
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
internal static byte[] ToByteArray(this ulong value, Endianness order)
|
||||
{
|
||||
var bytes = BitConverter.GetBytes(value);
|
||||
if (!order.IsHostOrder())
|
||||
{
|
||||
Array.Reverse(bytes);
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
internal static byte[] ToHostOrder(this byte[] source, Endianness sourceOrder)
|
||||
=> source.Length < 1 ? source
|
||||
: sourceOrder.IsHostOrder() ? source
|
||||
: source.Reverse().ToArray();
|
||||
|
||||
// true: !(true ^ true) or !(false ^ false)
|
||||
// false: !(true ^ false) or !(false ^ true)
|
||||
private static bool IsHostOrder(this Endianness order)
|
||||
=> !(BitConverter.IsLittleEndian ^ (order == Endianness.Little));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user