-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Labels
Milestone
Description
There are some scenarios (see dotnet/coreclr#21948 (comment)) where we want to take a value in machine-endian order and convert it to little-endian. This is the opposite of normal APIs like htonl and ntohl, which convert between machine-endian and big-endian.
Proposed API additions
namespace System.Buffers.Binary
{
// NEW methods added to EXISTING type
public static class BinaryPrimitives
{
// convert from machine-endian to little-endian
public static uint ToLittleEndian(uint value);
// convert from little-endian to machine-endian
public static uint FromLittleEndian(uint value);
}
}There would be overloads matching the existing overloads on ReverseEndianness: byte, sbyte, short, ushort, int, uint, long, ulong.
Open question: Do we also have ToBigEndian / FromBigEndian for parity and discoverability? Those APIs already exist on IPAddress.HostToNetworkOrder and IPAddress.NetworkToHostOrder. But those APIs require your application to pull in the package System.Net.Primitives, whereas these would all be contained within a single type.
scalablecory, bbartels, juliusfriedman and alfredmyers