-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Open
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.Runtime.InteropServicesuntriagedNew issue has not been triaged by the area ownerNew issue has not been triaged by the area owner
Description
Background and motivation
Third-party libraries that need endianness-aware layout for a pair of fields must either:
- compile and distribute separate little-endian and big-endian builds, or
- implement complex conditional logic,
ref Tshims, or manual byte-swapping.
This increases maintenance, package size, and the chance of subtle bugs and performance regressions. A small BCL primitive that encodes endianness-aware semantics would let library authors write one build that behaves correctly and efficiently on all platforms.
API Proposal
namespace System.Runtime.InteropServices {
[StructLayout(LayoutKind.Sequential)]
public struct EndiannessAwarePair<TUpper, TLower>
where TUpper : unmanaged
where TLower : unmanaged {
#if BIGENDIAN
public TUpper Upper;
public TLower Lower;
#else
public TLower Lower;
public TUpper Upper;
#endif
public static EndianAwarePair<TLower, TUpper> FromUpperAndLower(TUpper upper, TUpper lower);
public static EndianAwarePair<TLower, TUpper> FromLowerAndUpper(TLower lower, TLower upper);
}
}API Usage
public readonly struct MyInt128 {
readonly EndiannessAwarePair<Int64, UInt64> bits;
}Alternative Designs
No response
Risks
No response
punchready
Metadata
Metadata
Assignees
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.Runtime.InteropServicesuntriagedNew issue has not been triaged by the area ownerNew issue has not been triaged by the area owner
Type
Projects
Status
No status