Add read ahead logic for streams. (dotnet/corefx#38039)
authorJeremy Kuhne <jkuhne@microsoft.com>
Fri, 31 May 2019 05:00:36 +0000 (22:00 -0700)
committerGitHub <noreply@github.com>
Fri, 31 May 2019 05:00:36 +0000 (22:00 -0700)
commitfed5acc4e1b8ac07d6dfe214a069f440a2673594
tree306333436755889fa4f96b4cc088368f5f22cb68
parent42c05cebd30f0dbc95ec36190bd0f08ae4a8d6aa
Add read ahead logic for streams. (dotnet/corefx#38039)

* Add read ahead logic for streams.

When reading a jaon object or array from a stream into an object we need to TrySkip to ensure that we have all the needed data for the JsonDocument to create a JsonElement. This is only necessary  if we haven't already drained the stream.

* Track state correctly

We need to track consumed separately so we can requeue the reader properly after skipping. Add more stream tests.

* Clarify comments and other feedback.

* Fix comment

Commit migrated from https://github.com/dotnet/corefx/commit/f6b010d2a0bdab94953d519a60d882ff805eea36
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Stream.cs
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.cs
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.cs
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/ReadStack.cs
src/libraries/System.Text.Json/tests/Serialization/JsonElementTests.cs
src/libraries/System.Text.Json/tests/Serialization/SpanTests.cs