New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[API Proposal]: Add Int128 and UInt128 BitConverter.GetBytes
support
#80337
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to this area: @dotnet/area-system-numerics Issue DetailsBackground and motivationGet the underlying bytes of 128 bit integers for use in binary serialization and others API Proposal// check usage API Usagepublic void Example(Int128 value)
{
var bytes = BitConverter.GetBytes(value);
var newValue = BitConverter.ToInt128(bytes, 0);
} Alternative DesignsNo response RisksNo response
|
@ctigrisht can you please add the API proposal containing the full signature of both APIs being asked for here? Once that's done, I can mark this ready for review. |
There you go :) byte[] GetBytes(Int128 value);
Int128 ToInt128(ReadOnlySpan<byte> value);
Int128 ToInt128(byte[] value, int startIndex);
byte[] GetBytes(UInt128 value);
UInt128 ToUInt128(ReadOnlySpan<byte> value);
UInt128 ToUInt128(byte[] value, int startIndex); |
Thanks! I tweaked it just slightly further to be in the format that API review expects (we require the namespace, class, and full signature to be displayed). I also ensured that namespace System;
public static partial class BitConverter
{
public static byte[] GetBytes(Int128 value);
public static Int128 ToInt128(ReadOnlySpan<byte> value);
public static Int128 ToInt128(byte[] value, int startIndex);
public static bool TryWriteBytes(Span<byte> destination, Int128 value);
public static byte[] GetBytes(UInt128 value);
public static UInt128 ToUInt128(ReadOnlySpan<byte> value);
public static UInt128 ToUInt128(byte[] value, int startIndex);
public static bool TryWriteBytes(Span<byte> destination, UInt128 value);
} |
@tannergooding Thanks! My bad, I've never done this before so I was unsure of the format. |
Looks good as proposed. namespace System;
public static partial class BitConverter
{
public static byte[] GetBytes(Int128 value);
public static Int128 ToInt128(ReadOnlySpan<byte> value);
public static Int128 ToInt128(byte[] value, int startIndex);
public static bool TryWriteBytes(Span<byte> destination, Int128 value);
public static byte[] GetBytes(UInt128 value);
public static UInt128 ToUInt128(ReadOnlySpan<byte> value);
public static UInt128 ToUInt128(byte[] value, int startIndex);
public static bool TryWriteBytes(Span<byte> destination, UInt128 value);
} |
Background and motivation
Get the underlying bytes of 128 bit integers for use in binary serialization and others
API Proposal
EDIT:
Signatures for the methods:
API Usage
Alternative Designs
No response
Risks
No response
The text was updated successfully, but these errors were encountered: