Open javiercn opened 2 years ago
Tagging subscribers to this area: @GrabYourPitchForks, @dotnet/area-system-memory See info in area-owners.md if you want to be subscribed.
Author: | javiercn |
---|---|
Assignees: | - |
Labels: | `api-suggestion`, `area-System.Memory`, `untriaged` |
Milestone: | - |
If you need it for byte[]
array you can do something like:
MemoryMarshal.Read<ulong>(byteArray).TryFormat(dst, out int written, "X");
in a loop.
Shouldn't bytes
be a ReadOnlySpan<byte>
if it is the input value? That is:
-public bool TryToHexChars(Span<byte> bytes, Span<char> chars, out int written);
+public bool TryToHexChars(ReadOnlySpan<byte> bytes, Span<char> chars, out int written);
Tagging subscribers to this area: @dotnet/area-system-runtime See info in area-owners.md if you want to be subscribed.
Author: | javiercn |
---|---|
Assignees: | - |
Labels: | `api-suggestion`, `area-System.Runtime`, `untriaged` |
Milestone: | - |
@nil4 that's correct.
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 noTry
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
API Usage
Risks
No response