Closed hadashiA closed 1 year ago
YamlSerializer.Deserialize<T>(Stream);
Currently, YamlParser can only read ReadOnlySequence. Therefore, we want to create a ReadOnlySequence from a Stream.
The easiest way to do this is to read the entire Stream and create a large byte array. (e.g. MemoryStream).
Stream
However, the way is not the best.
So, it is better to make chunks of Stream as ReadOnlySequenceSegment .
MemoryPack probably does exactly this. I implemented most of mine based on this.
https://github.com/Cysharp/MemoryPack/blob/main/src/MemoryPack.Core/Internal/ReusableReadOnlySequenceBuilder.cs
Implementation details
Currently, YamlParser can only read ReadOnlySequence. Therefore, we want to create a ReadOnlySequence from a Stream.
The easiest way to do this is to read the entire
Stream
and create a large byte array. (e.g. MemoryStream).However, the way is not the best.
So, it is better to make chunks of Stream as ReadOnlySequenceSegment .
MemoryPack probably does exactly this. I implemented most of mine based on this.
https://github.com/Cysharp/MemoryPack/blob/main/src/MemoryPack.Core/Internal/ReusableReadOnlySequenceBuilder.cs