-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Add IPAddress Span-based APIs #22918
Comments
I'm interested in this one. I'm curious, what is |
Great
The same thing as GetAddressBytes, except instead of allocating an array and writing the bytes to that, it writes the bytes to the supplied span and stores the number of bytes written into the out int. If there's enough room to store the bytes, it returns true. If the span is too small, nothing is written, the out int is set to 0, and it returns false. |
Thank you. I was looking for a similarly named method and completely missed GetAddressBytes. Now I ran into an issue getting it to build after adding a reference to System.Memory for the Span. I guess I've missed adding the reference somewhere but haven't been able to figure out where. current test changes Paxxi/corefx@2f91bef error I get when building
|
You don't need/want to add a System.Memory reference; Span is now exposed from System.Runtime in corefx master, so the System.Net.Primitives src/ref projects already have access to it. For the test project, it's currently building against netstandard, so you'll want to add a netcoreapp build of the tests in order to test the new API that's being added only to .NET Core. You can see an example of doing that in dotnet/corefx#22689:
|
Thank you for the pointers, that got me going. Not sure about the etiquette since it's a large repo so I didn't want to post just a thank you. Now I have a new issue which I've been fighting with over the weekend.
The working code can be found at Paxxi/corefx@0b98780 and the invalid at Paxxi/corefx@553fe6b pay no attention to the weird conversions back and forth from string, it's just there trying to narrow down the issue. Here's a gist with the generated IL for the valid and invalid versions https://gist.github.com/Paxxi/3b3561ae3d1020898fb904db40b51ef2 |
ToString on a span doesn't do what you want it to (just as it doesn't on a char[]) and is likely the cause of the error. |
See issue #22607 This adds public IPAddress(ReadOnlySpan<byte> address) public IPAddress(ReadOnlySpan<byte> address, long scopeid) public bool TryWriteBytes(Span<byte> destination, out int bytesWritten) public static IPAddress Parse(ReadOnlySpan<char> ipSpan) public static bool TryParse(ReadOnlySpan<char> ipSpan, out IPAddress address) public static bool TryFormat(Span<char> destination, out int bytesWritten)
@Paxxi I sent you collaborator invite, so that we can assign the issue to you (let me know when you accept). Thanks for your contribution! |
I have accepted the invitation now. |
See issue #22607 This adds public IPAddress(ReadOnlySpan<byte> address) public IPAddress(ReadOnlySpan<byte> address, long scopeid) public bool TryWriteBytes(Span<byte> destination, out int bytesWritten) public static IPAddress Parse(ReadOnlySpan<char> ipSpan) public static bool TryParse(ReadOnlySpan<char> ipSpan, out IPAddress address) public static bool TryFormat(Span<char> destination, out int bytesWritten)
Separated out of https://github.com/dotnet/corefx/issues/21281 for tracking purposes.
The text was updated successfully, but these errors were encountered: