I'm trying to use System.IO.Pipelines to parse large text files.
But I can't find no conversion function from ReadOnlySequence to ReadOnlySequence. For example like MemoryMarshal.Cast<byte,char>
.
IMHO it is pretty useless having a generic ReadOnlySequence<T>
if there is only one particular type (byte) applicable.
static async Task ReadPipeAsync(PipeReader reader, IStringValueFactory factory)
{
while (true)
{
ReadResult result = await reader.ReadAsync();
ReadOnlySequence<byte> buffer = result.Buffer;
//ReadOnlySequence<char> chars = buffer.CastTo<char>(); ???
}
}
You would have to write a conversion operator to achieve this cast. You cannot cast it explicitly. Be aware that a char[] is two bytes, so you need to choose your encoding algorithm.
While it's true that
System.IO.Pipelines
will only give you aReadOnlySequence<byte>
because of the fact that aPipeReader
is attached to a Stream which is just a stream of bytes, there are other use cases for aReadOnlySequence<T>
eg,Your conversion operator would have similar logic to the below, but you would set your encoding appropriately.