-
-
Save terrajobst/6e1bea5bec4591edd7c5fe5416ce7f56 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string GetAsciiString(ReadOnlySequence<byte> buffer) | |
{ | |
if (buffer.IsSingleSegment) | |
{ | |
return Encoding.ASCII.GetString(buffer.First.Span); | |
} | |
return string.Create((int)buffer.Length, buffer, (span, sequence) => | |
{ | |
foreach (var segment in sequence) | |
{ | |
Encoding.ASCII.GetChars(segment.Span, span); | |
span = span.Slice(segment.Length); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like it should be yield returning span maybe?