1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-10 03:45:41 +00:00

(#32) Add (short/int/long).To(Host/Network)Order

Implementation calls IPAddress.(Host/Network)To(Network/Host)Order
This commit is contained in:
Oliver Booth 2021-07-19 11:46:38 +01:00
parent 61c122c9ea
commit 6e4a9882e9
No known key found for this signature in database
GPG Key ID: A4AC17007530E9B4
3 changed files with 66 additions and 3 deletions

View File

@ -1,4 +1,5 @@
using System;
using System;
using System.Net;
namespace X10D
{
@ -180,5 +181,25 @@ namespace X10D
{
return value != 0;
}
/// <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.
/// </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)
{
return IPAddress.HostToNetworkOrder(value);
}
}
}

View File

@ -1,4 +1,5 @@
using System;
using System;
using System.Net;
namespace X10D
{
@ -180,5 +181,25 @@ namespace X10D
{
return value != 0;
}
/// <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);
}
}
}

View File

@ -1,4 +1,5 @@
using System;
using System;
using System.Net;
namespace X10D
{
@ -206,5 +207,25 @@ namespace X10D
{
return value != 0;
}
/// <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);
}
}
}