| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | namespace System.Text.Json |
| | | 5 | | { |
| | | 6 | | /// <summary> |
| | | 7 | | /// Defines an opaque type that holds and saves all the relevant state information which must be provided |
| | | 8 | | /// to the <see cref="Utf8JsonReader"/> to continue reading after processing incomplete data. |
| | | 9 | | /// This type is required to support reentrancy when reading incomplete data, and to continue |
| | | 10 | | /// reading once more data is available. Unlike the <see cref="Utf8JsonReader"/>, which is a ref struct, |
| | | 11 | | /// this type can survive across async/await boundaries and hence this type is required to provide |
| | | 12 | | /// support for reading in more data asynchronously before continuing with a new instance of the <see cref="Utf8Json |
| | | 13 | | /// </summary> |
| | | 14 | | public readonly struct JsonReaderState |
| | | 15 | | { |
| | | 16 | | internal readonly long _lineNumber; |
| | | 17 | | internal readonly long _bytePositionInLine; |
| | | 18 | | internal readonly bool _inObject; |
| | | 19 | | internal readonly bool _isNotPrimitive; |
| | | 20 | | internal readonly bool _valueIsEscaped; |
| | | 21 | | internal readonly bool _trailingCommaBeforeComment; |
| | | 22 | | internal readonly JsonTokenType _tokenType; |
| | | 23 | | internal readonly JsonTokenType _previousTokenType; |
| | | 24 | | internal readonly JsonReaderOptions _readerOptions; |
| | | 25 | | internal readonly BitStack _bitStack; |
| | | 26 | | |
| | | 27 | | /// <summary> |
| | | 28 | | /// Constructs a new <see cref="JsonReaderState"/> instance. |
| | | 29 | | /// </summary> |
| | | 30 | | /// <param name="options">Defines the customized behavior of the <see cref="Utf8JsonReader"/> |
| | | 31 | | /// that is different from the JSON RFC (for example how to handle comments or maximum depth allowed when readin |
| | | 32 | | /// By default, the <see cref="Utf8JsonReader"/> follows the JSON RFC strictly (i.e. comments within the JSON ar |
| | | 33 | | /// <remarks> |
| | | 34 | | /// An instance of this state must be passed to the <see cref="Utf8JsonReader"/> ctor with the JSON data. |
| | | 35 | | /// Unlike the <see cref="Utf8JsonReader"/>, which is a ref struct, the state can survive |
| | | 36 | | /// across async/await boundaries and hence this type is required to provide support for reading |
| | | 37 | | /// in more data asynchronously before continuing with a new instance of the <see cref="Utf8JsonReader"/>. |
| | | 38 | | /// </remarks> |
| | | 39 | | public JsonReaderState(JsonReaderOptions options = default) |
| | 57352 | 40 | | { |
| | 57352 | 41 | | _lineNumber = default; |
| | 57352 | 42 | | _bytePositionInLine = default; |
| | 57352 | 43 | | _inObject = default; |
| | 57352 | 44 | | _isNotPrimitive = default; |
| | 57352 | 45 | | _valueIsEscaped = default; |
| | 57352 | 46 | | _trailingCommaBeforeComment = default; |
| | 57352 | 47 | | _tokenType = default; |
| | 57352 | 48 | | _previousTokenType = default; |
| | 57352 | 49 | | _readerOptions = options; |
| | | 50 | | |
| | | 51 | | // Only allocate if the user reads a JSON payload beyond the depth that the _allocationFreeContainer can han |
| | | 52 | | // This way we avoid allocations in the common, default cases, and allocate lazily. |
| | 57352 | 53 | | _bitStack = default; |
| | 57352 | 54 | | } |
| | | 55 | | |
| | | 56 | | internal JsonReaderState( |
| | | 57 | | long lineNumber, |
| | | 58 | | long bytePositionInLine, |
| | | 59 | | bool inObject, |
| | | 60 | | bool isNotPrimitive, |
| | | 61 | | bool valueIsEscaped, |
| | | 62 | | bool trailingCommaBeforeComment, |
| | | 63 | | JsonTokenType tokenType, |
| | | 64 | | JsonTokenType previousTokenType, |
| | | 65 | | JsonReaderOptions readerOptions, |
| | | 66 | | BitStack bitStack) |
| | 116968 | 67 | | { |
| | 116968 | 68 | | _lineNumber = lineNumber; |
| | 116968 | 69 | | _bytePositionInLine = bytePositionInLine; |
| | 116968 | 70 | | _inObject = inObject; |
| | 116968 | 71 | | _isNotPrimitive = isNotPrimitive; |
| | 116968 | 72 | | _valueIsEscaped = valueIsEscaped; |
| | 116968 | 73 | | _trailingCommaBeforeComment = trailingCommaBeforeComment; |
| | 116968 | 74 | | _tokenType = tokenType; |
| | 116968 | 75 | | _previousTokenType = previousTokenType; |
| | 116968 | 76 | | _readerOptions = readerOptions; |
| | 116968 | 77 | | _bitStack = bitStack; |
| | 116968 | 78 | | } |
| | | 79 | | |
| | | 80 | | /// <summary> |
| | | 81 | | /// Gets the custom behavior when reading JSON using |
| | | 82 | | /// the <see cref="Utf8JsonReader"/> that may deviate from strict adherence |
| | | 83 | | /// to the JSON specification, which is the default behavior. |
| | | 84 | | /// </summary> |
| | 4042 | 85 | | public JsonReaderOptions Options => _readerOptions; |
| | | 86 | | } |
| | | 87 | | } |