Add Utf8JsonWriter along with unit tests (dotnet/corefx#34425)
authorAhson Khan <ahkha@microsoft.com>
Tue, 15 Jan 2019 22:42:39 +0000 (14:42 -0800)
committerGitHub <noreply@github.com>
Tue, 15 Jan 2019 22:42:39 +0000 (14:42 -0800)
commit923265fa8ac4c537f9173d0beaf9945f80756058
tree384ce6eec0a186d28906910d38d98a033bff702f
parent4ba0b79b0ed2d35b9523727665c63f1d0c3ebb96
Add Utf8JsonWriter along with unit tests (dotnet/corefx#34425)

* Move JsonReader related files to the Reader directory.

* Update S.T.Json ref to include new JsonWriter APIs.

* Port initial JsonWriter files from corefxlab.

* Auto-generate System.Text.Json ref to update the ordering for
consistency.

* Fixed some TODOs, delete dead code, and formatting cleanup.

* Make use of self-descriptive constants where possible.

* Fix leftover TODOs and update throw helper/exception messages.

* Add xml comments/docs to the public surface area.

* Add JsonWriter unit tests.

* Change GetCurrentState back to a property and explicitly Flush on the
callers behalf instead of throwing.

* Save current depth as part of state and update tests.

* Fix constant names, account for quotes in bytes needed, and add fixed buffer writer tests.

* Fix inconsistent use of braces by adding them for single line ifs

* Update parameter name to exclude encoding.

* Remove JsonWriterException and use InvalidOperationException instead.

* Use Rune and Utf8Formatter/TryFormat in more places and remove
UnicodeScalar.

* Fix nits, typos, and reorder field assignment and method calls.

* Pass spans by in (or by value) instead of by ref.

* Update comments and remove unnecessary test.

* Remove some aggressive inlining and pass spans by value rather than in

* Update comments, dont compute bytes needed, and use if instead of loop before advancing.

* Reduce code bloat by removing duplciate calls to ValidateX.

* Add details on how .NET types are formatted to comments.

* Reduce code duplication when writing values.

* Change the StandardFormat used for DateTime(Offset) to 'O'

* Refactor calculating the maximum escaped length to a helper.

* Remove unnecessary checks and rename locals to be more descriptive.

* Rename suppressEscaping to escape and flip default from false to true.

* Comment cleanup, add debug.asserts, and move transcoding helpers to a
separate file.

* Increase the deicmal max size to account for sign and add tests.

* Rename ROS<byte> property name and value params to include utf8 in the
name.

* Remove redundant code where idx is set to 0 unnecessarily.

* Remove dead code (dont escape forward slash) and make tests culture
invariant.

Commit migrated from https://github.com/dotnet/corefx/commit/f84927d4a85444e63ede2da38a49eff7116790db
52 files changed:
src/libraries/System.Text.Json/ref/System.Text.Json.cs
src/libraries/System.Text.Json/src/Resources/Strings.resx
src/libraries/System.Text.Json/src/System.Text.Json.csproj
src/libraries/System.Text.Json/src/System/Text/Json/JsonConstants.cs
src/libraries/System.Text.Json/src/System/Text/Json/Reader/ConsumeNumberResult.cs [moved from src/libraries/System.Text.Json/src/System/Text/Json/ConsumeNumberResult.cs with 100% similarity]
src/libraries/System.Text.Json/src/System/Text/Json/Reader/ConsumeTokenResult.cs [moved from src/libraries/System.Text.Json/src/System/Text/Json/ConsumeTokenResult.cs with 100% similarity]
src/libraries/System.Text.Json/src/System/Text/Json/Reader/JsonReaderException.cs [moved from src/libraries/System.Text.Json/src/System/Text/Json/JsonReaderException.cs with 100% similarity]
src/libraries/System.Text.Json/src/System/Text/Json/Reader/JsonReaderHelper.cs [moved from src/libraries/System.Text.Json/src/System/Text/Json/JsonReaderHelper.cs with 100% similarity]
src/libraries/System.Text.Json/src/System/Text/Json/Reader/JsonReaderOptions.cs [moved from src/libraries/System.Text.Json/src/System/Text/Json/JsonReaderOptions.cs with 100% similarity]
src/libraries/System.Text.Json/src/System/Text/Json/Reader/JsonReaderState.cs [moved from src/libraries/System.Text.Json/src/System/Text/Json/JsonReaderState.cs with 100% similarity]
src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.MultiSegment.cs [moved from src/libraries/System.Text.Json/src/System/Text/Json/Utf8JsonReader.MultiSegment.cs with 99% similarity]
src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.TryGet.cs [moved from src/libraries/System.Text.Json/src/System/Text/Json/Utf8JsonReader.TryGet.cs with 100% similarity]
src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.cs [moved from src/libraries/System.Text.Json/src/System/Text/Json/Utf8JsonReader.cs with 99% similarity]
src/libraries/System.Text.Json/src/System/Text/Json/ThrowHelper.cs
src/libraries/System.Text.Json/src/System/Text/Json/Writer/JsonWriterHelper.Escaping.cs [new file with mode: 0644]
src/libraries/System.Text.Json/src/System/Text/Json/Writer/JsonWriterHelper.Transcoding.cs [new file with mode: 0644]
src/libraries/System.Text.Json/src/System/Text/Json/Writer/JsonWriterHelper.cs [new file with mode: 0644]
src/libraries/System.Text.Json/src/System/Text/Json/Writer/JsonWriterOptions.cs [new file with mode: 0644]
src/libraries/System.Text.Json/src/System/Text/Json/Writer/JsonWriterState.cs [new file with mode: 0644]
src/libraries/System.Text.Json/src/System/Text/Json/Writer/SequenceValidity.cs [new file with mode: 0644]
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.DateTime.cs [new file with mode: 0644]
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.DateTimeOffset.cs [new file with mode: 0644]
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Decimal.cs [new file with mode: 0644]
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Double.cs [new file with mode: 0644]
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Float.cs [new file with mode: 0644]
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Guid.cs [new file with mode: 0644]
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Helpers.cs [new file with mode: 0644]
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Literal.cs [new file with mode: 0644]
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.SignedNumber.cs [new file with mode: 0644]
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.String.cs [new file with mode: 0644]
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.UnsignedNumber.cs [new file with mode: 0644]
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Comment.cs [new file with mode: 0644]
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.DateTime.cs [new file with mode: 0644]
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.DateTimeOffset.cs [new file with mode: 0644]
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Decimal.cs [new file with mode: 0644]
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Double.cs [new file with mode: 0644]
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Float.cs [new file with mode: 0644]
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Guid.cs [new file with mode: 0644]
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Helpers.cs [new file with mode: 0644]
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Literal.cs [new file with mode: 0644]
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.SignedNumber.cs [new file with mode: 0644]
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.String.cs [new file with mode: 0644]
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.UnsignedNumber.cs [new file with mode: 0644]
src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.cs [new file with mode: 0644]
src/libraries/System.Text.Json/tests/ArrayBufferWriter.cs [new file with mode: 0644]
src/libraries/System.Text.Json/tests/BitStackTests.cs
src/libraries/System.Text.Json/tests/FixedSizedBufferWriter.cs [new file with mode: 0644]
src/libraries/System.Text.Json/tests/InvalidBufferWriter.cs [new file with mode: 0644]
src/libraries/System.Text.Json/tests/JsonWriterStateTests.cs [new file with mode: 0644]
src/libraries/System.Text.Json/tests/ResizableArray.cs [new file with mode: 0644]
src/libraries/System.Text.Json/tests/System.Text.Json.Tests.csproj
src/libraries/System.Text.Json/tests/Utf8JsonWriterTests.cs [new file with mode: 0644]