private object _dummy;
private int _dummyPrimitive;
public JsonReaderState(System.Text.Json.JsonReaderOptions options = default(System.Text.Json.JsonReaderOptions)) { throw null; }
- public long BytesConsumed { get { throw null; } }
public System.Text.Json.JsonReaderOptions Options { get { throw null; } }
- public System.SequencePosition Position { get { throw null; } }
}
public static partial class JsonSerializer
{
{
internal long _lineNumber;
internal long _bytePositionInLine;
- internal long _bytesConsumed;
internal bool _inObject;
internal bool _isNotPrimitive;
internal char _numberFormat;
internal JsonTokenType _previousTokenType;
internal JsonReaderOptions _readerOptions;
internal BitStack _bitStack;
- internal SequencePosition _sequencePosition;
-
- /// <summary>
- /// Returns the total amount of bytes consumed by the <see cref="Utf8JsonReader"/> so far
- /// for the given UTF-8 encoded input text.
- /// </summary>
- public long BytesConsumed => _bytesConsumed;
-
- /// <summary>
- /// Returns the current <see cref="SequencePosition"/> within the provided UTF-8 encoded
- /// input ReadOnlySequence<byte>. If the <see cref="Utf8JsonReader"/> was constructed
- /// with a ReadOnlySpan<byte> instead, this will always return a default <see cref="SequencePosition"/>.
- /// </summary>
- public SequencePosition Position => _sequencePosition;
/// <summary>
/// Constructs a new <see cref="JsonReaderState"/> instance.
{
_lineNumber = default;
_bytePositionInLine = default;
- _bytesConsumed = default;
_inObject = default;
_isNotPrimitive = default;
_numberFormat = default;
// Only allocate if the user reads a JSON payload beyond the depth that the _allocationFreeContainer can handle.
// This way we avoid allocations in the common, default cases, and allocate lazily.
_bitStack = default;
-
- _sequencePosition = default;
}
/// <summary>
_isFinalBlock = isFinalBlock;
_isInputSequence = true;
- // Note: We do not retain _bytesConsumed or _sequencePosition as they reset with the new input data
_lineNumber = state._lineNumber;
_bytePositionInLine = state._bytePositionInLine;
_inObject = state._inObject;
{
_lineNumber = _lineNumber,
_bytePositionInLine = _bytePositionInLine,
- _bytesConsumed = BytesConsumed,
_inObject = _inObject,
_isNotPrimitive = _isNotPrimitive,
_numberFormat = _numberFormat,
_previousTokenType = _previousTokenType,
_readerOptions = _readerOptions,
_bitStack = _bitStack,
- _sequencePosition = Position,
};
/// <summary>
_isFinalBlock = isFinalBlock;
_isInputSequence = false;
- // Note: We do not retain _bytesConsumed or _sequencePosition as they reset with the new input data
_lineNumber = state._lineNumber;
_bytePositionInLine = state._bytePositionInLine;
_inObject = state._inObject;
if (reader.BytesConsumed != utf8Json.Length)
{
- readerState = reader.CurrentState;
- ThrowHelper.ThrowJsonException_DeserializeDataRemaining(utf8Json.Length, utf8Json.Length - readerState.BytesConsumed);
+ ThrowHelper.ThrowJsonException_DeserializeDataRemaining(utf8Json.Length, utf8Json.Length - reader.BytesConsumed);
}
return result;
if (reader.BytesConsumed != jsonBytes.Length)
{
- readerState = reader.CurrentState;
ThrowHelper.ThrowJsonException_DeserializeDataRemaining(
- jsonBytes.Length, jsonBytes.Length - readerState.BytesConsumed);
+ jsonBytes.Length, jsonBytes.Length - reader.BytesConsumed);
}
return result;
if (newReader.BytesConsumed != length)
{
- state = newReader.CurrentState;
- ThrowHelper.ThrowJsonException_DeserializeDataRemaining(length, length - state.BytesConsumed);
+ ThrowHelper.ThrowJsonException_DeserializeDataRemaining(length, length - newReader.BytesConsumed);
}
}
catch (JsonException)
try
{
JsonReaderState initialState = default;
+ long initialBytesConsumed = default;
while (true)
{
// as we don't know if the next token is an opening object or
// array brace.
initialState = reader.CurrentState;
+ initialBytesConsumed = reader.BytesConsumed;
}
if (!reader.Read())
}
else if (readStack.Current.IsProcessingValue(tokenType))
{
- if (!HandleObjectAsValue(tokenType, options, ref reader, ref readStack, ref initialState))
+ if (!HandleObjectAsValue(tokenType, options, ref reader, ref readStack, ref initialState, initialBytesConsumed))
{
// Need more data
break;
{
HandleStartArray(options, ref reader, ref readStack);
}
- else if (!HandleObjectAsValue(tokenType, options, ref reader, ref readStack, ref initialState))
+ else if (!HandleObjectAsValue(tokenType, options, ref reader, ref readStack, ref initialState, initialBytesConsumed))
{
// Need more data
break;
JsonSerializerOptions options,
ref Utf8JsonReader reader,
ref ReadStack readStack,
- ref JsonReaderState initialState)
+ ref JsonReaderState initialState,
+ long initialBytesConsumed)
{
if (readStack.ReadAhead)
{
// HandleValue below.
reader = new Utf8JsonReader(
- reader.OriginalSpan.Slice(checked((int)initialState.BytesConsumed)),
+ reader.OriginalSpan.Slice(checked((int)initialBytesConsumed)),
isFinalBlock: reader.IsFinalBlock,
state: initialState);
Debug.Assert(reader.BytesConsumed == 0);
- readStack.BytesConsumed += initialState.BytesConsumed;
+ readStack.BytesConsumed += initialBytesConsumed;
if (!complete)
{
public static void DefaultJsonReaderState()
{
JsonReaderState state = default;
- Assert.Equal(0, state.BytesConsumed);
var expectedOption = new JsonReaderOptions
{
public static void JsonReaderStateDefaultCtor()
{
var state = new JsonReaderState();
- Assert.Equal(0, state.BytesConsumed);
var expectedOption = new JsonReaderOptions
{
public static void JsonReaderStateCtor()
{
var state = new JsonReaderState(default);
- Assert.Equal(0, state.BytesConsumed);
var expectedOption = new JsonReaderOptions
{
Assert.Equal(expectedOption, state.Options);
state = new JsonReaderState(new JsonReaderOptions { CommentHandling = JsonCommentHandling.Disallow, MaxDepth = 0 });
- Assert.Equal(0, state.BytesConsumed);
Assert.Equal(expectedOption, state.Options);
expectedOption = new JsonReaderOptions
MaxDepth = 32
};
state = new JsonReaderState(new JsonReaderOptions { MaxDepth = 32 });
- Assert.Equal(0, state.BytesConsumed);
Assert.Equal(32, state.Options.MaxDepth);
Assert.Equal(expectedOption, state.Options);
}
Assert.True(json.ValueSpan.SequenceEqual(default));
Assert.True(json.ValueSequence.IsEmpty);
- Assert.Equal(0, json.CurrentState.BytesConsumed);
- Assert.NotEqual(default, json.CurrentState.Position);
Assert.Equal(64, json.CurrentState.Options.MaxDepth);
Assert.False(json.CurrentState.Options.AllowTrailingCommas);
Assert.Equal(JsonCommentHandling.Disallow, json.CurrentState.Options.CommentHandling);
Assert.True(json.ValueSpan.SequenceEqual(default));
Assert.True(json.ValueSequence.IsEmpty);
- Assert.Equal(0, json.CurrentState.BytesConsumed);
- Assert.NotEqual(default, json.CurrentState.Position);
Assert.Equal(64, json.CurrentState.Options.MaxDepth);
Assert.False(json.CurrentState.Options.AllowTrailingCommas);
Assert.Equal(JsonCommentHandling.Disallow, json.CurrentState.Options.CommentHandling);
Assert.True(json.ValueSpan.SequenceEqual(default));
Assert.True(json.ValueSequence.ToArray().AsSpan().SequenceEqual(new byte[] { (byte)'1' }));
- Assert.Equal(2, json.CurrentState.BytesConsumed);
- Assert.NotEqual(default, json.CurrentState.Position);
Assert.Equal(64, json.CurrentState.Options.MaxDepth);
Assert.False(json.CurrentState.Options.AllowTrailingCommas);
Assert.Equal(JsonCommentHandling.Disallow, json.CurrentState.Options.CommentHandling);
Assert.True(json.ValueSpan.SequenceEqual(default));
Assert.True(json.ValueSequence.IsEmpty);
- Assert.Equal(0, json.CurrentState.BytesConsumed);
- Assert.NotEqual(default, json.CurrentState.Position);
Assert.Equal(64, json.CurrentState.Options.MaxDepth);
Assert.False(json.CurrentState.Options.AllowTrailingCommas);
Assert.Equal(JsonCommentHandling.Disallow, json.CurrentState.Options.CommentHandling);
string actualStrSequence = Encoding.UTF8.GetString(resultSequence, 0, length);
long consumed = utf8JsonReader.BytesConsumed;
- Assert.Equal(consumed, utf8JsonReader.CurrentState.BytesConsumed);
utf8JsonReader = new Utf8JsonReader(sequence.Slice(consumed), isFinalBlock: true, utf8JsonReader.CurrentState);
resultSequence = JsonTestHelper.ReaderLoop(dataUtf8.Length, out length, ref utf8JsonReader);
actualStrSequence += Encoding.UTF8.GetString(resultSequence, 0, length);
string message = $"Expected consumed: {dataUtf8.Length - consumed}, Actual consumed: {utf8JsonReader.BytesConsumed}, Index: {j}";
- Assert.Equal(utf8JsonReader.BytesConsumed, utf8JsonReader.CurrentState.BytesConsumed);
Assert.True(dataUtf8.Length - consumed == utf8JsonReader.BytesConsumed, message);
Assert.Equal(expectedStr, actualStrSequence);
}
while (json.Read())
;
Assert.Equal(sequence.Length, json.BytesConsumed);
- Assert.Equal(sequence.Length, json.CurrentState.BytesConsumed);
Assert.True(sequence.Slice(json.Position).IsEmpty);
- Assert.True(sequence.Slice(json.CurrentState.Position).IsEmpty);
}
}
JsonReaderState jsonState = json.CurrentState;
byte[] consumedArray = sequence.Slice(0, consumed).ToArray();
Assert.Equal(consumedArray, sequence.Slice(0, json.Position).ToArray());
- Assert.True(json.Position.Equals(jsonState.Position));
json = new Utf8JsonReader(sequence.Slice(consumed), isFinalBlock: true, jsonState);
while (json.Read())
;
Assert.Equal(dataUtf8.Length - consumed, json.BytesConsumed);
- Assert.Equal(json.BytesConsumed, json.CurrentState.BytesConsumed);
}
}
}
string actualStrSequence = Encoding.UTF8.GetString(resultSequence, 0, length);
long consumed = utf8JsonReader.BytesConsumed;
- Assert.Equal(consumed, utf8JsonReader.CurrentState.BytesConsumed);
utf8JsonReader = new Utf8JsonReader(sequence.Slice(consumed), isFinalBlock: true, utf8JsonReader.CurrentState);
resultSequence = JsonTestHelper.ReaderLoop(dataUtf8.Length, out length, ref utf8JsonReader);
actualStrSequence += Encoding.UTF8.GetString(resultSequence, 0, length);
string message = $"Expected consumed: {dataUtf8.Length - consumed}, Actual consumed: {utf8JsonReader.BytesConsumed}, Index: {j}";
- Assert.Equal(utf8JsonReader.BytesConsumed, utf8JsonReader.CurrentState.BytesConsumed);
Assert.True(dataUtf8.Length - consumed == utf8JsonReader.BytesConsumed, message);
Assert.Equal(expectedString, actualStrSequence);
}
Assert.Equal(0, utf8JsonReader.TokenStartIndex);
long consumed = utf8JsonReader.BytesConsumed;
- Assert.Equal(consumed, utf8JsonReader.CurrentState.BytesConsumed);
utf8JsonReader = new Utf8JsonReader(sequence.Slice(consumed), isFinalBlock: true, utf8JsonReader.CurrentState);
resultSequence = JsonTestHelper.ReaderLoop(dataUtf8.Length, out length, ref utf8JsonReader);
actualStrSequence += Encoding.UTF8.GetString(resultSequence, 0, length);
string message = $"Expected consumed: {dataUtf8.Length - consumed}, Actual consumed: {utf8JsonReader.BytesConsumed}, Index: {j}";
- Assert.Equal(utf8JsonReader.BytesConsumed, utf8JsonReader.CurrentState.BytesConsumed);
Assert.True(dataUtf8.Length - consumed == utf8JsonReader.BytesConsumed, message);
Assert.Equal(expectedString, actualStrSequence);
Assert.Equal(expectedWithComments, builder.ToString());
Assert.Equal(inputData, sequence.Slice(0, json.Position).ToArray());
- Assert.True(json.Position.Equals(json.CurrentState.Position));
state = new JsonReaderState(options: new JsonReaderOptions { CommentHandling = JsonCommentHandling.Skip });
json = new Utf8JsonReader(sequence, isFinalBlock: true, state);
Assert.Equal(expectedWithoutComments, builder.ToString());
Assert.Equal(inputData, sequence.Slice(0, json.Position).ToArray());
- Assert.True(json.Position.Equals(json.CurrentState.Position));
}
[Theory]
Assert.Equal(2, json.TokenStartIndex);
}
- Assert.Equal(json.BytesConsumed, json.CurrentState.BytesConsumed);
Assert.Equal(inputData, sequence.Slice(0, json.Position).ToArray());
- Assert.True(json.Position.Equals(json.CurrentState.Position));
}
}
var json = new Utf8JsonReader(sequence.Slice(0, i), isFinalBlock: false, state);
VerifyReadLoop(ref json, expected);
- json = new Utf8JsonReader(sequence.Slice(state.BytesConsumed), isFinalBlock: true, state);
+ json = new Utf8JsonReader(sequence.Slice(json.BytesConsumed), isFinalBlock: true, json.CurrentState);
VerifyReadLoop(ref json, expected);
}
}
+ [ActiveIssue(38927)]
[Theory]
[MemberData(nameof(CommentTestLineSeparators))]
public static void SkipSingleLineCommentMultiSpanTest(string lineSeparator)
var json = new Utf8JsonReader(sequence.Slice(0, i), isFinalBlock: false, state);
VerifyReadLoop(ref json, null);
- json = new Utf8JsonReader(sequence.Slice(state.BytesConsumed), isFinalBlock: true, state);
+ json = new Utf8JsonReader(sequence.Slice(json.BytesConsumed), isFinalBlock: true, json.CurrentState);
VerifyReadLoop(ref json, null);
}
}
}
Assert.Equal(dataUtf8.Length, json.BytesConsumed);
- Assert.Equal(json.BytesConsumed, json.CurrentState.BytesConsumed);
}
[Fact]
}
Assert.Equal(dataUtf8.Length, json.BytesConsumed);
- Assert.Equal(json.BytesConsumed, json.CurrentState.BytesConsumed);
}
[Theory]
}
Assert.Equal(dataUtf8.Length, json.BytesConsumed);
- Assert.Equal(json.BytesConsumed, json.CurrentState.BytesConsumed);
}
[Theory]
}
Assert.Equal(dataUtf8.Length, json.BytesConsumed);
- Assert.Equal(json.BytesConsumed, json.CurrentState.BytesConsumed);
}
[Theory]
}
Assert.Equal(dataUtf8.Length, json.BytesConsumed);
- Assert.Equal(json.BytesConsumed, json.CurrentState.BytesConsumed);
}
[Theory]
}
Assert.Equal(dataUtf8.Length, json.BytesConsumed);
- Assert.Equal(json.BytesConsumed, json.CurrentState.BytesConsumed);
}
[Theory]
}
Assert.Equal(dataUtf8.Length, json.BytesConsumed);
- Assert.Equal(json.BytesConsumed, json.CurrentState.BytesConsumed);
}
[Theory]
}
Assert.Equal(dataUtf8.Length, json.BytesConsumed);
- Assert.Equal(json.BytesConsumed, json.CurrentState.BytesConsumed);
}
[Theory]
}
Assert.Equal(dataUtf8.Length, json.BytesConsumed);
- Assert.Equal(json.BytesConsumed, json.CurrentState.BytesConsumed);
}
[Theory]
}
Assert.Equal(dataUtf8.Length, json.BytesConsumed);
- Assert.Equal(json.BytesConsumed, json.CurrentState.BytesConsumed);
}
[Theory]
}
Assert.Equal(dataUtf8.Length, json.BytesConsumed);
- Assert.Equal(json.BytesConsumed, json.CurrentState.BytesConsumed);
}
[Theory]
}
Assert.Equal(dataUtf8.Length, json.BytesConsumed);
- Assert.Equal(json.BytesConsumed, json.CurrentState.BytesConsumed);
}
[Theory]
}
Assert.Equal(dataUtf8.Length, json.BytesConsumed);
- Assert.Equal(json.BytesConsumed, json.CurrentState.BytesConsumed);
}
[Fact]
}
Assert.Equal(dataUtf8.Length, json.BytesConsumed);
- Assert.Equal(json.BytesConsumed, json.CurrentState.BytesConsumed);
}
[Theory]
}
Assert.Equal(dataUtf8.Length, json.BytesConsumed);
- Assert.Equal(json.BytesConsumed, json.CurrentState.BytesConsumed);
}
[Theory]
}
Assert.Equal(dataUtf8.Length, json.BytesConsumed);
- Assert.Equal(json.BytesConsumed, json.CurrentState.BytesConsumed);
}
[Theory]
}
Assert.Equal(dataUtf8.Length, json.BytesConsumed);
- Assert.Equal(json.BytesConsumed, json.CurrentState.BytesConsumed);
}
[Theory]
}
Assert.Equal(dataUtf8.Length, json.BytesConsumed);
- Assert.Equal(json.BytesConsumed, json.CurrentState.BytesConsumed);
}
[Theory]
}
Assert.Equal(dataUtf8.Length, json.BytesConsumed);
- Assert.Equal(json.BytesConsumed, json.CurrentState.BytesConsumed);
}
[Theory]
Assert.Equal(expected, json.GetGuid());
Assert.Equal(dataUtf8.Length, json.BytesConsumed);
- Assert.Equal(json.BytesConsumed, json.CurrentState.BytesConsumed);
}
[Theory]
Assert.True(json.ValueSpan.SequenceEqual(default));
Assert.True(json.ValueSequence.IsEmpty);
- Assert.Equal(0, json.CurrentState.BytesConsumed);
- Assert.Equal(default, json.CurrentState.Position);
Assert.Equal(0, json.CurrentState.Options.MaxDepth);
Assert.False(json.CurrentState.Options.AllowTrailingCommas);
Assert.Equal(JsonCommentHandling.Disallow, json.CurrentState.Options.CommentHandling);
Assert.True(json.ValueSpan.SequenceEqual(default));
Assert.True(json.ValueSequence.IsEmpty);
- Assert.Equal(0, json.CurrentState.BytesConsumed);
- Assert.Equal(default, json.CurrentState.Position);
Assert.Equal(64, json.CurrentState.Options.MaxDepth);
Assert.False(json.CurrentState.Options.AllowTrailingCommas);
Assert.Equal(JsonCommentHandling.Disallow, json.CurrentState.Options.CommentHandling);
Assert.True(json.ValueSpan.SequenceEqual(default));
Assert.True(json.ValueSequence.IsEmpty);
- Assert.Equal(0, json.CurrentState.BytesConsumed);
- Assert.Equal(default, json.CurrentState.Position);
Assert.Equal(64, json.CurrentState.Options.MaxDepth);
Assert.False(json.CurrentState.Options.AllowTrailingCommas);
Assert.Equal(JsonCommentHandling.Disallow, json.CurrentState.Options.CommentHandling);
Assert.True(json.ValueSpan.SequenceEqual(new byte[] { (byte)'1' }));
Assert.True(json.ValueSequence.IsEmpty);
- Assert.Equal(2, json.CurrentState.BytesConsumed);
- Assert.Equal(default, json.CurrentState.Position);
Assert.Equal(64, json.CurrentState.Options.MaxDepth);
Assert.False(json.CurrentState.Options.AllowTrailingCommas);
Assert.Equal(JsonCommentHandling.Disallow, json.CurrentState.Options.CommentHandling);
Assert.True(json.ValueSpan.SequenceEqual(default));
Assert.True(json.ValueSequence.IsEmpty);
- Assert.Equal(0, json.CurrentState.BytesConsumed);
- Assert.Equal(default, json.CurrentState.Position);
Assert.Equal(64, json.CurrentState.Options.MaxDepth);
Assert.False(json.CurrentState.Options.AllowTrailingCommas);
Assert.Equal(JsonCommentHandling.Disallow, json.CurrentState.Options.CommentHandling);
int written = firstLength;
long consumed = json.BytesConsumed;
- Assert.Equal(consumed, json.CurrentState.BytesConsumed);
Assert.Equal(default, json.Position);
json = new Utf8JsonReader(dataUtf8.AsSpan((int)consumed), isFinalBlock: true, json.CurrentState);
output.AsSpan(0, length).CopyTo(outputSpan.Slice(written));
written += length;
Assert.Equal(dataUtf8.Length - consumed, json.BytesConsumed);
- Assert.Equal(json.BytesConsumed, json.CurrentState.BytesConsumed);
Assert.Equal(default, json.Position);
- Assert.Equal(default, json.CurrentState.Position);
Assert.Equal(outputSpan.Length, written);
string actualStr = Encoding.UTF8.GetString(outputArray);
int written = firstLength;
long consumed = json.BytesConsumed;
- Assert.Equal(consumed, json.CurrentState.BytesConsumed);
Assert.Equal(default, json.Position);
for (long j = consumed; j < dataUtf8.Length - consumed; j++)
written += length;
long consumedInner = json.BytesConsumed;
- Assert.Equal(consumedInner, json.CurrentState.BytesConsumed);
json = new Utf8JsonReader(dataUtf8.AsSpan((int)(consumed + consumedInner)), isFinalBlock: true, json.CurrentState);
output = JsonTestHelper.ReaderLoop(outputSpan.Length - written, out length, ref json);
output.AsSpan(0, length).CopyTo(outputSpan.Slice(written));
written += length;
Assert.Equal(dataUtf8.Length - consumedInner - consumed, json.BytesConsumed);
- Assert.Equal(json.BytesConsumed, json.CurrentState.BytesConsumed);
Assert.Equal(default, json.Position);
- Assert.Equal(default, json.CurrentState.Position);
Assert.Equal(outputSpan.Length, written);
string actualStr = Encoding.UTF8.GetString(outputArray);
int written = firstLength;
long consumed = json.BytesConsumed;
- Assert.Equal(consumed, json.CurrentState.BytesConsumed);
Assert.Equal(default, json.Position);
Assert.Equal(0, json.TokenStartIndex);
written += length;
long consumedInner = json.BytesConsumed;
- Assert.Equal(consumedInner, json.CurrentState.BytesConsumed);
json = new Utf8JsonReader(dataUtf8.AsSpan((int)(consumed + consumedInner)), isFinalBlock: true, json.CurrentState);
output = JsonTestHelper.ReaderLoop(outputSpan.Length - written, out length, ref json);
output.AsSpan(0, length).CopyTo(outputSpan.Slice(written));
written += length;
Assert.Equal(dataUtf8.Length - consumedInner - consumed, json.BytesConsumed);
- Assert.Equal(json.BytesConsumed, json.CurrentState.BytesConsumed);
Assert.Equal(default, json.Position);
- Assert.Equal(default, json.CurrentState.Position);
Assert.Equal(0, json.TokenStartIndex);
Assert.Equal(outputSpan.Length, written);
ValidateNextTrySkip(ref json);
long consumed = json.BytesConsumed;
- Assert.Equal(consumed, json.CurrentState.BytesConsumed);
json = new Utf8JsonReader(dataUtf8.AsSpan((int)consumed), isFinalBlock: true, json.CurrentState);
while (json.TrySkip())
ValidateNextTrySkip(ref json);
long consumed = json.BytesConsumed;
- Assert.Equal(consumed, json.CurrentState.BytesConsumed);
json = new Utf8JsonReader(dataUtf8.AsSpan((int)consumed), isFinalBlock: true, json.CurrentState);
long bytesConsumed = json.BytesConsumed;
ValidateNextTrySkip(ref json);
long consumed = json.BytesConsumed;
- Assert.Equal(consumed, json.CurrentState.BytesConsumed);
json = new Utf8JsonReader(dataUtf8.AsSpan((int)consumed), isFinalBlock: true, json.CurrentState);
while (json.Read())
}
long consumed = json.BytesConsumed;
- Assert.Equal(consumed, json.CurrentState.BytesConsumed);
json = new Utf8JsonReader(dataUtf8.AsSpan((int)consumed), isFinalBlock: true, json.CurrentState);
while (true)
;
long consumed = json.BytesConsumed;
- Assert.Equal(consumed, json.CurrentState.BytesConsumed);
json = new Utf8JsonReader(dataUtf8.AsSpan((int)consumed), isFinalBlock: true, json.CurrentState);
long bytesConsumed = json.BytesConsumed;
var json = new Utf8JsonReader(dataUtf8.AsSpan(0, i), isFinalBlock: false, state);
while (json.Read())
;
-
- long consumed = json.BytesConsumed;
- Assert.Equal(consumed, json.CurrentState.BytesConsumed);
}
}
}
;
long consumed = json.BytesConsumed;
- Assert.Equal(consumed, json.CurrentState.BytesConsumed);
for (long j = consumed; j < dataUtf8.Length - consumed; j++)
{
;
long consumedInner = json.BytesConsumed;
- Assert.Equal(consumedInner, json.CurrentState.BytesConsumed);
json = new Utf8JsonReader(dataUtf8.AsSpan((int)(consumed + consumedInner)), isFinalBlock: true, json.CurrentState);
while (json.Read())
;
Assert.Equal(dataUtf8.Length - consumedInner - consumed, json.BytesConsumed);
- Assert.Equal(json.BytesConsumed, json.CurrentState.BytesConsumed);
}
}
}
}
long consumed = json.BytesConsumed;
- Assert.Equal(consumed, json.CurrentState.BytesConsumed);
json = new Utf8JsonReader(data.AsSpan((int)consumed), true, json.CurrentState);
while (json.Read())
{
builder.Append(Encoding.UTF8.GetString(json.ValueSpan.ToArray()));
}
Assert.Equal(data.Length - consumed, json.BytesConsumed);
- Assert.Equal(json.BytesConsumed, json.CurrentState.BytesConsumed);
Assert.Equal(commentHandling == JsonCommentHandling.Allow ? expectedWithComments : expectedWithoutComments, builder.ToString());
}
}
long consumed = json.BytesConsumed;
- Assert.Equal(consumed, json.CurrentState.BytesConsumed);
json = new Utf8JsonReader(dataUtf8.AsSpan((int)consumed), true, json.CurrentState);
while (json.Read())
{
}
}
Assert.Equal(dataUtf8.Length - consumed, json.BytesConsumed);
- Assert.Equal(json.BytesConsumed, json.CurrentState.BytesConsumed);
}
}
}
while (json.Read())
;
Assert.Equal(consumed, json.BytesConsumed);
- Assert.Equal(consumed, json.CurrentState.BytesConsumed);
Assert.Equal(default, json.Position);
- Assert.Equal(default, json.CurrentState.Position);
json = new Utf8JsonReader(dataUtf8.AsSpan((int)json.BytesConsumed), true, json.CurrentState);
while (json.Read())
;
Assert.Equal(dataUtf8.Length - consumed, json.BytesConsumed);
- Assert.Equal(json.BytesConsumed, json.CurrentState.BytesConsumed);
Assert.Equal(default, json.Position);
- Assert.Equal(default, json.CurrentState.Position);
}
}
while (json.Read())
;
Assert.Equal(consumed, json.BytesConsumed);
- Assert.Equal(consumed, json.CurrentState.BytesConsumed);
json = new Utf8JsonReader(dataUtf8.AsSpan((int)json.BytesConsumed), true, json.CurrentState);
try
Assert.Equal(expectedlineNumber, ex.LineNumber);
Assert.Equal(expectedBytePosition, ex.BytePositionInLine);
Assert.Equal(default, json.Position);
- Assert.Equal(default, json.CurrentState.Position);
}
}
}
;
long consumed = jsonSlice.BytesConsumed;
- Assert.Equal(consumed, jsonSlice.CurrentState.BytesConsumed);
Assert.Equal(default, json.Position);
- Assert.Equal(default, json.CurrentState.Position);
JsonReaderState jsonState = jsonSlice.CurrentState;
errorMessage += " | " + firstSegmentString + " | " + secondSegmentString;
Assert.True(expectedBytePosition == ex.BytePositionInLine, errorMessage);
Assert.Equal(default, json.Position);
- Assert.Equal(default, json.CurrentState.Position);
}
}
}
break;
foundComment = true;
indexAfterFirstComment = json.BytesConsumed;
- Assert.Equal(indexAfterFirstComment, json.CurrentState.BytesConsumed);
string actualComment = json.GetComment();
Assert.Equal(expectedComment, actualComment);
break;
break;
foundComment = true;
indexAfterFirstComment = json.BytesConsumed;
- Assert.Equal(indexAfterFirstComment, json.CurrentState.BytesConsumed);
string actualComment = json.GetComment();
Assert.Equal(expectedComment, actualComment);
break;
break;
foundComment = true;
indexAfterFirstComment = jsonSlice.BytesConsumed;
- Assert.Equal(indexAfterFirstComment, jsonSlice.CurrentState.BytesConsumed);
string actualComment = jsonSlice.GetComment();
Assert.Equal(expectedComment, actualComment);
break;
}
int consumed = (int)jsonSlice.BytesConsumed;
- Assert.Equal(consumed, jsonSlice.CurrentState.BytesConsumed);
jsonSlice = new Utf8JsonReader(dataUtf8.AsSpan(consumed), isFinalBlock: true, jsonSlice.CurrentState);
if (!foundComment)
break;
foundComment = true;
indexAfterFirstComment = jsonSlice.BytesConsumed;
- Assert.Equal(indexAfterFirstComment, jsonSlice.CurrentState.BytesConsumed);
string actualComment = jsonSlice.GetComment();
Assert.Equal(expectedComment, actualComment);
break;
prevTokenType = tokenType;
}
Assert.Equal(dataUtf8.Length, json.BytesConsumed);
- Assert.Equal(dataUtf8.Length, json.CurrentState.BytesConsumed);
}
[Theory]
}
}
Assert.Equal(dataUtf8.Length, json.BytesConsumed);
- Assert.Equal(dataUtf8.Length, json.CurrentState.BytesConsumed);
for (int i = 0; i < dataUtf8.Length; i++)
{
}
int prevConsumed = (int)jsonSlice.BytesConsumed;
- Assert.Equal(prevConsumed, jsonSlice.CurrentState.BytesConsumed);
jsonSlice = new Utf8JsonReader(dataUtf8.AsSpan(prevConsumed), isFinalBlock: true, jsonSlice.CurrentState);
while (jsonSlice.Read())
}
Assert.Equal(dataUtf8.Length - prevConsumed, jsonSlice.BytesConsumed);
- Assert.Equal(jsonSlice.BytesConsumed, jsonSlice.CurrentState.BytesConsumed);
}
}
}
}
- Assert.Equal(jsonSlice.BytesConsumed, jsonSlice.CurrentState.BytesConsumed);
jsonSlice = new Utf8JsonReader(dataUtf8.AsSpan((int)jsonSlice.BytesConsumed), isFinalBlock: true, jsonSlice.CurrentState);
while (jsonSlice.Read())
{
var json = new Utf8JsonReader(dataUtf8.AsSpan(0, i), isFinalBlock: false, state);
VerifyReadLoop(ref json, expected);
- json = new Utf8JsonReader(dataUtf8.AsSpan((int)state.BytesConsumed), isFinalBlock: true, state);
+ json = new Utf8JsonReader(dataUtf8.AsSpan((int)json.BytesConsumed), isFinalBlock: true, json.CurrentState);
VerifyReadLoop(ref json, expected);
}
}
var json = new Utf8JsonReader(dataUtf8.AsSpan(0, i), isFinalBlock: false, state);
VerifyReadLoop(ref json, null);
- json = new Utf8JsonReader(dataUtf8.AsSpan((int)state.BytesConsumed), isFinalBlock: true, state);
+ json = new Utf8JsonReader(dataUtf8.AsSpan((int)json.BytesConsumed), isFinalBlock: true, json.CurrentState);
VerifyReadLoop(ref json, null);
}
}