hadashiA / VYaml

The extra fast, low memory footprint YAML library for C#, focued on .NET and Unity.
MIT License
309 stars 19 forks source link

Support Deserialize<T>(Stream) directly #1

Closed hadashiA closed 1 year ago

hadashiA commented 1 year ago
YamlSerializer.Deserialize<T>(Stream);

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