-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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.Runtimeneeds-further-triageIssue has been initially triaged, but needs deeper consideration or reconsiderationIssue has been initially triaged, but needs deeper consideration or reconsideration
Milestone
Description
Background and motivation
.NET 5.0 added ToHexString
to allow computing Hex. However all the available APIs materialize into a string. In other words, there are no Try
span based APIs as there are for Base64, which forces the intermediate allocation of the string when you want to further process the result.
It's not clear to me if this was explicitly excluded from the public API or an oversight. My expectation since we introduced span and friends on the BCL and runtime is for non-allocating span based APIs to be available for all these types of low level operations.
(As an example here where we wanted to use something like this to call ToLowerInvariant on it afterwards)
API Proposal
namespace System;
public static class Convert
{
// Similar set of span based overloads as for Base64. Not including all for brevity.
public bool TryToHexChars(ReadOnlySpan<byte> bytes, Span<char> chars, out int written);
}
API Usage
Span<bytes> bytes = stackalloc byte[32];
Span<char> hexChars = stackalloc byte[64];
if(Convert.TryToHexChars(bytes, hexChars, out var written))
{
...
}
Risks
No response
scalablecory, GSPP, hrrrrustic, PaulusParssinen, Timovzl and 3 more
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.Runtimeneeds-further-triageIssue has been initially triaged, but needs deeper consideration or reconsiderationIssue has been initially triaged, but needs deeper consideration or reconsideration