mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-09 23:25:43 +00:00
Move ToHost/NetworkOrder to Net namespace (#7)
This commit is contained in:
parent
d5e6febd5c
commit
d1de1625f2
26
X10D.Tests/src/Net/Int16Tests.cs
Normal file
26
X10D.Tests/src/Net/Int16Tests.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using X10D.Net;
|
||||
|
||||
namespace X10D.Tests.Net;
|
||||
|
||||
[TestClass]
|
||||
public class Int16Tests
|
||||
{
|
||||
[TestMethod]
|
||||
public void HostToNetworkOrder_ReturnsCorrectValue()
|
||||
{
|
||||
const short hostOrder = 0x0102;
|
||||
const short networkOrder = 0x0201;
|
||||
|
||||
Assert.AreEqual(BitConverter.IsLittleEndian ? networkOrder : hostOrder, hostOrder.HostToNetworkOrder());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void NetworkToHostOrder_ReturnsCorrectValue()
|
||||
{
|
||||
const short hostOrder = 0x0102;
|
||||
const short networkOrder = 0x0201;
|
||||
|
||||
Assert.AreEqual(BitConverter.IsLittleEndian ? hostOrder : networkOrder, networkOrder.NetworkToHostOrder());
|
||||
}
|
||||
}
|
26
X10D.Tests/src/Net/Int32Tests.cs
Normal file
26
X10D.Tests/src/Net/Int32Tests.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using X10D.Net;
|
||||
|
||||
namespace X10D.Tests.Net;
|
||||
|
||||
[TestClass]
|
||||
public class Int32Tests
|
||||
{
|
||||
[TestMethod]
|
||||
public void HostToNetworkOrder_ReturnsCorrectValue()
|
||||
{
|
||||
const int hostOrder = 0x01020304;
|
||||
const int networkOrder = 0x04030201;
|
||||
|
||||
Assert.AreEqual(BitConverter.IsLittleEndian ? networkOrder : hostOrder, hostOrder.HostToNetworkOrder());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void NetworkToHostOrder_ReturnsCorrectValue()
|
||||
{
|
||||
const int hostOrder = 0x01020304;
|
||||
const int networkOrder = 0x04030201;
|
||||
|
||||
Assert.AreEqual(BitConverter.IsLittleEndian ? hostOrder : networkOrder, networkOrder.NetworkToHostOrder());
|
||||
}
|
||||
}
|
26
X10D.Tests/src/Net/Int64Tests.cs
Normal file
26
X10D.Tests/src/Net/Int64Tests.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using X10D.Net;
|
||||
|
||||
namespace X10D.Tests.Net;
|
||||
|
||||
[TestClass]
|
||||
public class Int64Tests
|
||||
{
|
||||
[TestMethod]
|
||||
public void HostToNetworkOrder_ReturnsCorrectValue()
|
||||
{
|
||||
const long hostOrder = 0x0102030405060708;
|
||||
const long networkOrder = 0x0807060504030201;
|
||||
|
||||
Assert.AreEqual(BitConverter.IsLittleEndian ? networkOrder : hostOrder, hostOrder.HostToNetworkOrder());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void NetworkToHostOrder_ReturnsCorrectValue()
|
||||
{
|
||||
const long hostOrder = 0x0102030405060708;
|
||||
const long networkOrder = 0x0807060504030201;
|
||||
|
||||
Assert.AreEqual(BitConverter.IsLittleEndian ? hostOrder : networkOrder, networkOrder.NetworkToHostOrder());
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
using System.Net;
|
||||
using X10D.Math;
|
||||
using X10D.Math;
|
||||
|
||||
namespace X10D;
|
||||
|
||||
@ -69,24 +68,4 @@ public static class Int32Extensions
|
||||
{
|
||||
return ((float)value).DegreesToRadians();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts an integer value from network byte order to host byte order.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to convert, expressed in network byte order.</param>
|
||||
/// <returns>An integer value, expressed in host byte order.</returns>
|
||||
public static int ToHostOrder(this int value)
|
||||
{
|
||||
return IPAddress.NetworkToHostOrder(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts an integer value from host byte order to network byte order.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to convert, expressed in host byte order.</param>
|
||||
/// <returns>An integer value, expressed in network byte order.</returns>
|
||||
public static int ToNetworkOrder(this int value)
|
||||
{
|
||||
return IPAddress.HostToNetworkOrder(value);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,4 @@
|
||||
using System.Net;
|
||||
|
||||
namespace X10D;
|
||||
namespace X10D;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="long" />.
|
||||
@ -50,24 +48,4 @@ public static class Int64Extensions
|
||||
|
||||
return persistence;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts an integer value from network byte order to host byte order.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to convert, expressed in network byte order.</param>
|
||||
/// <returns>An integer value, expressed in host byte order.</returns>
|
||||
public static long ToHostOrder(this long value)
|
||||
{
|
||||
return IPAddress.NetworkToHostOrder(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts an integer value from host byte order to network byte order.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to convert, expressed in host byte order.</param>
|
||||
/// <returns>An integer value, expressed in network byte order.</returns>
|
||||
public static long ToNetworkOrder(this long value)
|
||||
{
|
||||
return IPAddress.HostToNetworkOrder(value);
|
||||
}
|
||||
}
|
||||
|
@ -1,29 +1,29 @@
|
||||
using System.Net;
|
||||
|
||||
namespace X10D;
|
||||
namespace X10D.Net;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="short" />.
|
||||
/// Network-related extension methods for <see cref="short" />.
|
||||
/// </summary>
|
||||
public static class Int16Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts an integer value from network byte order to host byte order.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to convert, expressed in network byte order.</param>
|
||||
/// <returns>An integer value, expressed in host byte order.</returns>
|
||||
public static short ToHostOrder(this short value)
|
||||
{
|
||||
return IPAddress.NetworkToHostOrder(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts an integer value from host byte order to network byte order.
|
||||
/// Converts a 16-bit signed integer value from host byte order to network byte order.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to convert, expressed in host byte order.</param>
|
||||
/// <returns>An integer value, expressed in network byte order.</returns>
|
||||
public static short ToNetworkOrder(this short value)
|
||||
public static short HostToNetworkOrder(this short value)
|
||||
{
|
||||
return IPAddress.HostToNetworkOrder(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a 16-bit signed integer value from network byte order to host byte order.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to convert, expressed in network byte order.</param>
|
||||
/// <returns>An integer value, expressed in host byte order.</returns>
|
||||
public static short NetworkToHostOrder(this short value)
|
||||
{
|
||||
return IPAddress.NetworkToHostOrder(value);
|
||||
}
|
||||
}
|
29
X10D/src/Net/Int32Extensions.cs
Normal file
29
X10D/src/Net/Int32Extensions.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System.Net;
|
||||
|
||||
namespace X10D.Net;
|
||||
|
||||
/// <summary>
|
||||
/// IO-related extension methods for <see cref="int" />.
|
||||
/// </summary>
|
||||
public static class Int32Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts a 32-bit signed integer value from host byte order to network byte order.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to convert, expressed in host byte order.</param>
|
||||
/// <returns>An integer value, expressed in network byte order.</returns>
|
||||
public static int HostToNetworkOrder(this int value)
|
||||
{
|
||||
return IPAddress.HostToNetworkOrder(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a 32-bit signed integer value from network byte order to host byte order.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to convert, expressed in network byte order.</param>
|
||||
/// <returns>An integer value, expressed in host byte order.</returns>
|
||||
public static int NetworkToHostOrder(this int value)
|
||||
{
|
||||
return IPAddress.NetworkToHostOrder(value);
|
||||
}
|
||||
}
|
29
X10D/src/Net/Int64Extensions.cs
Normal file
29
X10D/src/Net/Int64Extensions.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System.Net;
|
||||
|
||||
namespace X10D.Net;
|
||||
|
||||
/// <summary>
|
||||
/// IO-related extension methods for <see cref="long" />.
|
||||
/// </summary>
|
||||
public static class Int64Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts a 64-bit signed integer value from host byte order to network byte order.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to convert, expressed in host byte order.</param>
|
||||
/// <returns>An integer value, expressed in network byte order.</returns>
|
||||
public static long HostToNetworkOrder(this long value)
|
||||
{
|
||||
return IPAddress.HostToNetworkOrder(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a 64-bit signed integer value from network byte order to host byte order.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to convert, expressed in network byte order.</param>
|
||||
/// <returns>An integer value, expressed in host byte order.</returns>
|
||||
public static long NetworkToHostOrder(this long value)
|
||||
{
|
||||
return IPAddress.NetworkToHostOrder(value);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user