【发布时间】:2022-02-01 19:28:19
【问题描述】:
我需要一种以最小分配写入数据的方法,尽可能从 ReadOnlySequence 读取数据。
我发现的最好方法是来自侧库的SpanWriter。
但可能有人知道更好的标准解决方案。
using System.IO.Pipelines
namespace WriteSample
{
public async Task Write()
{
var pipe = new Pipe();
var memory = pipe.Writer.GetMemory(2048);
var writer = new Writer???(memory.Span);
writer.Write((byte)0xFF);
writer.Write((long)12345);
writer.WriteBigEndian((long)12345);
await pipe.Writer.FlushAsync()
}
}
【问题讨论】:
-
请注意,您不是在呼叫
pipe.Writer.Advance(x)?