Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Utf8JsonReader.cs
Go to the documentation of this file.
7
8namespace System.Text.Json;
9
10[DebuggerDisplay("{DebuggerDisplay,nq}")]
11public ref struct Utf8JsonReader
12{
36
38
39 private readonly bool _isFinalBlock;
40
41 private readonly bool _isInputSequence;
42
43 private long _lineNumber;
44
45 private long _bytePositionInLine;
46
47 private int _consumed;
48
49 private bool _inObject;
50
51 private bool _isNotPrimitive;
52
54
56
58
60
61 private long _totalConsumed;
62
63 private bool _isLastSegment;
64
65 internal bool _stringHasEscaping;
66
67 private readonly bool _isMultiSegment;
68
70
72
74
76
77 private bool IsLastSpan
78 {
79 get
80 {
81 if (_isFinalBlock)
82 {
84 {
85 return _isLastSegment;
86 }
87 return true;
88 }
89 return false;
90 }
91 }
92
94
96 {
97 get
98 {
99 if (!_sequence.IsEmpty)
100 {
101 return default(ReadOnlySpan<byte>);
102 }
103 return _buffer;
104 }
105 }
106
107 public ReadOnlySpan<byte> ValueSpan { get; private set; }
108
110
111 public long TokenStartIndex { get; private set; }
112
113 public int CurrentDepth
114 {
115 get
116 {
117 int num = _bitStack.CurrentDepth;
118 if (TokenType == JsonTokenType.StartArray || TokenType == JsonTokenType.StartObject)
119 {
120 num--;
121 }
122 return num;
123 }
124 }
125
126 internal bool IsInArray => !_inObject;
127
129
130 public bool HasValueSequence { get; private set; }
131
133
134 public ReadOnlySequence<byte> ValueSequence { get; private set; }
135
137 {
138 get
139 {
141 {
143 }
144 return default(SequencePosition);
145 }
146 }
147
166
168 private string DebuggerDisplay => $"TokenType = {DebugTokenType} (TokenStartIndex = {TokenStartIndex}) Consumed = {BytesConsumed}";
169
170 private string DebugTokenType => TokenType switch
171 {
172 JsonTokenType.Comment => "Comment",
173 JsonTokenType.EndArray => "EndArray",
174 JsonTokenType.EndObject => "EndObject",
175 JsonTokenType.False => "False",
176 JsonTokenType.None => "None",
177 JsonTokenType.Null => "Null",
178 JsonTokenType.Number => "Number",
179 JsonTokenType.PropertyName => "PropertyName",
180 JsonTokenType.StartArray => "StartArray",
181 JsonTokenType.StartObject => "StartObject",
182 JsonTokenType.String => "String",
183 JsonTokenType.True => "True",
184 _ => ((byte)TokenType).ToString(),
185 };
186
188 {
191 _isInputSequence = false;
192 _lineNumber = state._lineNumber;
193 _bytePositionInLine = state._bytePositionInLine;
194 _inObject = state._inObject;
195 _isNotPrimitive = state._isNotPrimitive;
196 _stringHasEscaping = state._stringHasEscaping;
197 _trailingCommaBeforeComment = state._trailingCommaBeforeComment;
198 _tokenType = state._tokenType;
199 _previousTokenType = state._previousTokenType;
200 _readerOptions = state._readerOptions;
201 if (_readerOptions.MaxDepth == 0)
202 {
204 }
205 _bitStack = state._bitStack;
206 _consumed = 0;
208 _totalConsumed = 0L;
210 _isMultiSegment = false;
215 HasValueSequence = false;
217 }
218
223
224 public bool Read()
225 {
227 if (!flag && _isFinalBlock && TokenType == JsonTokenType.None)
228 {
229 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedJsonTokens, 0);
230 }
231 return flag;
232 }
233
234 public void Skip()
235 {
236 if (!_isFinalBlock)
237 {
239 }
240 SkipHelper();
241 }
242
243 [MethodImpl(MethodImplOptions.AggressiveInlining)]
244 private void SkipHelper()
245 {
246 if (TokenType == JsonTokenType.PropertyName)
247 {
248 bool flag = Read();
249 }
250 if (TokenType == JsonTokenType.StartObject || TokenType == JsonTokenType.StartArray)
251 {
253 do
254 {
255 bool flag2 = Read();
256 }
257 while (currentDepth < CurrentDepth);
258 }
259 }
260
261 public bool TrySkip()
262 {
263 if (_isFinalBlock)
264 {
265 SkipHelper();
266 return true;
267 }
268 return TrySkipHelper();
269 }
270
271 private bool TrySkipHelper()
272 {
274 if (TokenType != JsonTokenType.PropertyName || Read())
275 {
276 if (TokenType != JsonTokenType.StartObject && TokenType != JsonTokenType.StartArray)
277 {
278 goto IL_0042;
279 }
281 while (Read())
282 {
284 {
285 continue;
286 }
287 goto IL_0042;
288 }
289 }
290 this = utf8JsonReader;
291 return false;
292 IL_0042:
293 return true;
294 }
295
304
305 public bool ValueTextEquals(string? text)
306 {
307 return ValueTextEquals(text.AsSpan());
308 }
309
310 [MethodImpl(MethodImplOptions.AggressiveInlining)]
312 {
314 {
316 }
318 {
320 }
321 return otherUtf8Text.SequenceEqual(ValueSpan);
322 }
323
325 {
327 {
329 }
330 if (MatchNotPossible(text.Length))
331 {
332 return false;
333 }
334 byte[] array = null;
335 int num = checked(text.Length * 3);
337 if (num > 256)
338 {
339 array = ArrayPool<byte>.Shared.Rent(num);
341 }
342 else
343 {
344 byte* pointer = stackalloc byte[256];
346 }
348 int bytesConsumed;
349 int bytesWritten;
352 if (array != null)
353 {
354 utf8Destination.Slice(0, bytesWritten).Clear();
356 }
357 return result;
358 }
359
361 {
363 {
365 }
367 if (valueSequence.Length != other.Length)
368 {
369 return false;
370 }
371 int num = 0;
373 while (enumerator.MoveNext())
374 {
375 ReadOnlySpan<byte> span = enumerator.Current.Span;
376 if (other.Slice(num).StartsWith(span))
377 {
378 num += span.Length;
379 continue;
380 }
381 return false;
382 }
383 return true;
384 }
385
387 {
389 if (valueSpan.Length < other.Length || valueSpan.Length / 6 > other.Length)
390 {
391 return false;
392 }
393 int num = valueSpan.IndexOf<byte>(92);
394 if (!other.StartsWith(valueSpan.Slice(0, num)))
395 {
396 return false;
397 }
398 return JsonReaderHelper.UnescapeAndCompare(valueSpan.Slice(num), other.Slice(num));
399 }
400
402 {
406 {
407 return false;
408 }
409 int num = 0;
410 bool result = false;
412 while (enumerator.MoveNext())
413 {
414 ReadOnlySpan<byte> span = enumerator.Current.Span;
415 int num2 = span.IndexOf<byte>(92);
416 if (num2 != -1)
417 {
418 if (other.Slice(num).StartsWith(span.Slice(0, num2)))
419 {
420 num += num2;
421 other = other.Slice(num);
422 valueSequence = valueSequence.Slice(num);
424 }
425 break;
426 }
427 if (!other.Slice(num).StartsWith(span))
428 {
429 break;
430 }
431 num += span.Length;
432 }
433 return result;
434 }
435
436 private static bool IsTokenTypeString(JsonTokenType tokenType)
437 {
438 if (tokenType != JsonTokenType.PropertyName)
439 {
440 return tokenType == JsonTokenType.String;
441 }
442 return true;
443 }
444
445 [MethodImpl(MethodImplOptions.AggressiveInlining)]
447 {
449 {
451 }
452 int length = ValueSpan.Length;
454 {
455 return true;
456 }
457 return false;
458 }
459
460 [MethodImpl(MethodImplOptions.NoInlining)]
462 {
465 {
466 return true;
467 }
468 return false;
469 }
470
471 private void StartObject()
472 {
474 {
475 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ObjectDepthTooLarge, 0);
476 }
479 _consumed++;
481 _tokenType = JsonTokenType.StartObject;
482 _inObject = true;
483 }
484
485 private void EndObject()
486 {
487 if (!_inObject || _bitStack.CurrentDepth <= 0)
488 {
489 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.MismatchedObjectArray, 125);
490 }
492 {
494 {
495 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.TrailingCommaNotAllowedBeforeObjectEnd, 0);
496 }
498 }
499 _tokenType = JsonTokenType.EndObject;
502 }
503
504 private void StartArray()
505 {
507 {
508 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ArrayDepthTooLarge, 0);
509 }
512 _consumed++;
514 _tokenType = JsonTokenType.StartArray;
515 _inObject = false;
516 }
517
518 private void EndArray()
519 {
520 if (_inObject || _bitStack.CurrentDepth <= 0)
521 {
522 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.MismatchedObjectArray, 93);
523 }
525 {
527 {
528 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.TrailingCommaNotAllowedBeforeArrayEnd, 0);
529 }
531 }
532 _tokenType = JsonTokenType.EndArray;
535 }
536
537 [MethodImpl(MethodImplOptions.AggressiveInlining)]
539 {
540 _consumed++;
543 }
544
545 private bool ReadSingleSegment()
546 {
547 bool flag = false;
548 ValueSpan = default(ReadOnlySpan<byte>);
549 if (HasMoreData())
550 {
551 byte b = _buffer[_consumed];
552 if (b <= 32)
553 {
555 if (!HasMoreData())
556 {
557 goto IL_0132;
558 }
560 }
562 if (_tokenType != 0)
563 {
564 if (b == 47)
565 {
567 }
568 else if (_tokenType == JsonTokenType.StartObject)
569 {
570 if (b == 125)
571 {
572 EndObject();
573 goto IL_0130;
574 }
575 if (b != 34)
576 {
577 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedStartOfPropertyNotFound, b);
578 }
579 int consumed = _consumed;
581 long lineNumber = _lineNumber;
582 flag = ConsumePropertyName();
583 if (!flag)
584 {
586 _tokenType = JsonTokenType.StartObject;
588 _lineNumber = lineNumber;
589 }
590 }
591 else if (_tokenType != JsonTokenType.StartArray)
592 {
593 flag = ((_tokenType != JsonTokenType.PropertyName) ? ConsumeNextTokenOrRollback(b) : ConsumeValue(b));
594 }
595 else
596 {
597 if (b == 93)
598 {
599 EndArray();
600 goto IL_0130;
601 }
602 flag = ConsumeValue(b);
603 }
604 }
605 else
606 {
607 flag = ReadFirstToken(b);
608 }
609 }
610 goto IL_0132;
611 IL_0132:
612 return flag;
613 IL_0130:
614 flag = true;
615 goto IL_0132;
616 }
617
618 [MethodImpl(MethodImplOptions.AggressiveInlining)]
619 private bool HasMoreData()
620 {
621 if (_consumed >= (uint)_buffer.Length)
622 {
624 {
625 if (_bitStack.CurrentDepth != 0)
626 {
628 }
630 {
631 return false;
632 }
633 if (_tokenType != JsonTokenType.EndArray && _tokenType != JsonTokenType.EndObject)
634 {
635 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.InvalidEndOfJsonNonPrimitive, 0);
636 }
637 }
638 return false;
639 }
640 return true;
641 }
642
643 [MethodImpl(MethodImplOptions.AggressiveInlining)]
645 {
646 if (_consumed >= (uint)_buffer.Length)
647 {
648 if (IsLastSpan)
649 {
651 }
652 return false;
653 }
654 return true;
655 }
656
657 private bool ReadFirstToken(byte first)
658 {
659 switch (first)
660 {
661 case 123:
663 _tokenType = JsonTokenType.StartObject;
665 _consumed++;
667 _inObject = true;
668 _isNotPrimitive = true;
669 break;
670 case 91:
672 _tokenType = JsonTokenType.StartArray;
674 _consumed++;
676 _isNotPrimitive = true;
677 break;
678 default:
679 {
681 if (JsonHelpers.IsDigit(first) || first == 45)
682 {
684 {
685 return false;
686 }
687 _tokenType = JsonTokenType.Number;
690 return true;
691 }
692 if (!ConsumeValue(first))
693 {
694 return false;
695 }
696 if (_tokenType == JsonTokenType.StartObject || _tokenType == JsonTokenType.StartArray)
697 {
698 _isNotPrimitive = true;
699 }
700 break;
701 }
702 }
703 return true;
704 }
705
706 private void SkipWhiteSpace()
707 {
709 while (_consumed < buffer.Length)
710 {
711 byte b = buffer[_consumed];
712 if (b == 32 || b == 13 || b == 10 || b == 9)
713 {
714 if (b == 10)
715 {
716 _lineNumber++;
718 }
719 else
720 {
722 }
723 _consumed++;
724 continue;
725 }
726 break;
727 }
728 }
729
730 private bool ConsumeValue(byte marker)
731 {
732 while (true)
733 {
735 switch (marker)
736 {
737 case 34:
738 return ConsumeString();
739 case 123:
740 StartObject();
741 break;
742 case 91:
743 StartArray();
744 break;
745 default:
746 if (JsonHelpers.IsDigit(marker) || marker == 45)
747 {
748 return ConsumeNumber();
749 }
750 switch (marker)
751 {
752 case 102:
754 case 116:
756 case 110:
758 }
760 {
761 case JsonCommentHandling.Allow:
762 if (marker == 47)
763 {
764 return ConsumeComment();
765 }
766 break;
767 default:
768 if (marker != 47)
769 {
770 break;
771 }
772 if (SkipComment())
773 {
774 if (_consumed >= (uint)_buffer.Length)
775 {
776 if (_isNotPrimitive && IsLastSpan && _tokenType != JsonTokenType.EndArray && _tokenType != JsonTokenType.EndObject)
777 {
778 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.InvalidEndOfJsonNonPrimitive, 0);
779 }
780 return false;
781 }
783 if (marker <= 32)
784 {
786 if (!HasMoreData())
787 {
788 return false;
789 }
791 }
792 goto IL_0140;
793 }
794 return false;
795 case JsonCommentHandling.Disallow:
796 break;
797 }
798 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedStartOfValueNotFound, marker);
799 break;
800 }
801 break;
802 IL_0140:
804 }
805 return true;
806 }
807
809 {
811 if (!span.StartsWith(literal))
812 {
813 return CheckLiteral(span, literal);
814 }
815 ValueSpan = span.Slice(0, literal.Length);
816 _tokenType = tokenType;
817 _consumed += literal.Length;
819 return true;
820 }
821
823 {
824 int num = 0;
825 for (int i = 1; i < literal.Length; i++)
826 {
827 if (span.Length > i)
828 {
829 if (span[i] != literal[i])
830 {
833 }
834 continue;
835 }
836 num = i;
837 break;
838 }
839 if (IsLastSpan)
840 {
841 _bytePositionInLine += num;
843 }
844 return false;
845 }
846
848 {
850 {
851 116 => ExceptionResource.ExpectedTrue,
852 102 => ExceptionResource.ExpectedFalse,
853 _ => ExceptionResource.ExpectedNull,
854 }, 0, span);
855 }
856
857 private bool ConsumeNumber()
858 {
860 {
861 return false;
862 }
863 _tokenType = JsonTokenType.Number;
866 if (_consumed >= (uint)_buffer.Length && _isNotPrimitive)
867 {
868 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedEndOfDigitNotFound, _buffer[_consumed - 1]);
869 }
870 return true;
871 }
872
873 private bool ConsumePropertyName()
874 {
876 if (!ConsumeString())
877 {
878 return false;
879 }
880 if (!HasMoreData(ExceptionResource.ExpectedValueAfterPropertyNameNotFound))
881 {
882 return false;
883 }
884 byte b = _buffer[_consumed];
885 if (b <= 32)
886 {
888 if (!HasMoreData(ExceptionResource.ExpectedValueAfterPropertyNameNotFound))
889 {
890 return false;
891 }
893 }
894 if (b != 58)
895 {
896 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedSeparatorAfterPropertyNameNotFound, b);
897 }
898 _consumed++;
900 _tokenType = JsonTokenType.PropertyName;
901 return true;
902 }
903
904 private bool ConsumeString()
905 {
907 int num = readOnlySpan.IndexOfQuoteOrAnyControlOrBackSlash();
908 if (num >= 0)
909 {
910 byte b = readOnlySpan[num];
911 if (b == 34)
912 {
913 _bytePositionInLine += num + 2;
914 ValueSpan = readOnlySpan.Slice(0, num);
915 _stringHasEscaping = false;
916 _tokenType = JsonTokenType.String;
917 _consumed += num + 2;
918 return true;
919 }
921 }
922 if (IsLastSpan)
923 {
925 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.EndOfStringNotFound, 0);
926 }
927 return false;
928 }
929
931 {
933 long lineNumber = _lineNumber;
935 bool flag = false;
936 while (true)
937 {
938 if (idx < data.Length)
939 {
940 byte b = data[idx];
941 if (b == 34)
942 {
943 if (!flag)
944 {
945 break;
946 }
947 flag = false;
948 }
949 else if (b == 92)
950 {
951 flag = !flag;
952 }
953 else if (flag)
954 {
955 int num = JsonConstants.EscapableChars.IndexOf(b);
956 if (num == -1)
957 {
958 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.InvalidCharacterAfterEscapeWithinString, b);
959 }
960 if (b == 117)
961 {
963 if (!ValidateHexDigits(data, idx + 1))
964 {
965 idx = data.Length;
966 goto IL_00e5;
967 }
968 idx += 4;
969 }
970 flag = false;
971 }
972 else if (b < 32)
973 {
974 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.InvalidCharacterWithinString, b);
975 }
977 idx++;
978 continue;
979 }
980 goto IL_00e5;
981 IL_00e5:
982 if (idx < data.Length)
983 {
984 break;
985 }
986 if (IsLastSpan)
987 {
988 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.EndOfStringNotFound, 0);
989 }
990 _lineNumber = lineNumber;
992 return false;
993 }
995 ValueSpan = data.Slice(0, idx);
996 _stringHasEscaping = true;
997 _tokenType = JsonTokenType.String;
998 _consumed += idx + 2;
999 return true;
1000 }
1001
1003 {
1004 for (int i = idx; i < data.Length; i++)
1005 {
1006 byte nextByte = data[i];
1008 {
1009 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.InvalidHexCharacterWithinString, nextByte);
1010 }
1011 if (i - idx >= 3)
1012 {
1013 return true;
1014 }
1016 }
1017 return false;
1018 }
1019
1021 {
1022 consumed = 0;
1023 int i = 0;
1025 if (consumeNumberResult == ConsumeNumberResult.NeedMoreData)
1026 {
1027 return false;
1028 }
1029 byte b = data[i];
1030 if (b == 48)
1031 {
1033 if (consumeNumberResult2 == ConsumeNumberResult.NeedMoreData)
1034 {
1035 return false;
1036 }
1037 if (consumeNumberResult2 != 0)
1038 {
1039 b = data[i];
1040 goto IL_00a3;
1041 }
1042 }
1043 else
1044 {
1045 i++;
1047 if (consumeNumberResult3 == ConsumeNumberResult.NeedMoreData)
1048 {
1049 return false;
1050 }
1051 if (consumeNumberResult3 != 0)
1052 {
1053 b = data[i];
1054 if (b != 46 && b != 69 && b != 101)
1055 {
1057 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedEndOfDigitNotFound, b);
1058 }
1059 goto IL_00a3;
1060 }
1061 }
1062 goto IL_0152;
1063 IL_00a3:
1064 if (b == 46)
1065 {
1066 i++;
1068 if (consumeNumberResult4 == ConsumeNumberResult.NeedMoreData)
1069 {
1070 return false;
1071 }
1073 {
1074 goto IL_0152;
1075 }
1076 b = data[i];
1077 if (b != 69 && b != 101)
1078 {
1080 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedNextDigitEValueNotFound, b);
1081 }
1082 }
1083 i++;
1085 if (consumeNumberResult == ConsumeNumberResult.NeedMoreData)
1086 {
1087 return false;
1088 }
1089 i++;
1090 switch (ConsumeIntegerDigits(ref data, ref i))
1091 {
1092 case ConsumeNumberResult.NeedMoreData:
1093 return false;
1094 default:
1096 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedEndOfDigitNotFound, data[i]);
1097 break;
1098 case ConsumeNumberResult.Success:
1099 break;
1100 }
1101 goto IL_0152;
1102 IL_0152:
1103 ValueSpan = data.Slice(0, i);
1104 consumed = i;
1105 return true;
1106 }
1107
1109 {
1110 byte b = data[i];
1111 if (b == 45)
1112 {
1113 i++;
1114 if (i >= data.Length)
1115 {
1116 if (IsLastSpan)
1117 {
1119 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.RequiredDigitNotFoundEndOfData, 0);
1120 }
1121 return ConsumeNumberResult.NeedMoreData;
1122 }
1123 b = data[i];
1124 if (!JsonHelpers.IsDigit(b))
1125 {
1127 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.RequiredDigitNotFoundAfterSign, b);
1128 }
1129 }
1130 return ConsumeNumberResult.OperationIncomplete;
1131 }
1132
1134 {
1135 i++;
1136 byte b = 0;
1137 if (i < data.Length)
1138 {
1139 b = data[i];
1140 if (JsonConstants.Delimiters.IndexOf(b) >= 0)
1141 {
1142 return ConsumeNumberResult.Success;
1143 }
1144 b = data[i];
1145 if (b != 46 && b != 69 && b != 101)
1146 {
1148 ThrowHelper.ThrowJsonReaderException(ref this, JsonHelpers.IsInRangeInclusive(b, 48, 57) ? ExceptionResource.InvalidLeadingZeroInNumber : ExceptionResource.ExpectedEndOfDigitNotFound, b);
1149 }
1150 return ConsumeNumberResult.OperationIncomplete;
1151 }
1152 if (IsLastSpan)
1153 {
1154 return ConsumeNumberResult.Success;
1155 }
1156 return ConsumeNumberResult.NeedMoreData;
1157 }
1158
1160 {
1161 byte value = 0;
1162 while (i < data.Length)
1163 {
1164 value = data[i];
1166 {
1167 break;
1168 }
1169 i++;
1170 }
1171 if (i >= data.Length)
1172 {
1173 if (IsLastSpan)
1174 {
1175 return ConsumeNumberResult.Success;
1176 }
1177 return ConsumeNumberResult.NeedMoreData;
1178 }
1179 if (JsonConstants.Delimiters.IndexOf(value) >= 0)
1180 {
1181 return ConsumeNumberResult.Success;
1182 }
1183 return ConsumeNumberResult.OperationIncomplete;
1184 }
1185
1187 {
1188 if (i >= data.Length)
1189 {
1190 if (IsLastSpan)
1191 {
1193 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.RequiredDigitNotFoundEndOfData, 0);
1194 }
1195 return ConsumeNumberResult.NeedMoreData;
1196 }
1197 byte b = data[i];
1198 if (!JsonHelpers.IsDigit(b))
1199 {
1201 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.RequiredDigitNotFoundAfterDecimal, b);
1202 }
1203 i++;
1204 return ConsumeIntegerDigits(ref data, ref i);
1205 }
1206
1208 {
1209 if (i >= data.Length)
1210 {
1211 if (IsLastSpan)
1212 {
1214 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.RequiredDigitNotFoundEndOfData, 0);
1215 }
1216 return ConsumeNumberResult.NeedMoreData;
1217 }
1218 byte b = data[i];
1219 if (b == 43 || b == 45)
1220 {
1221 i++;
1222 if (i >= data.Length)
1223 {
1224 if (IsLastSpan)
1225 {
1227 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.RequiredDigitNotFoundEndOfData, 0);
1228 }
1229 return ConsumeNumberResult.NeedMoreData;
1230 }
1231 b = data[i];
1232 }
1233 if (!JsonHelpers.IsDigit(b))
1234 {
1236 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.RequiredDigitNotFoundAfterSign, b);
1237 }
1238 return ConsumeNumberResult.OperationIncomplete;
1239 }
1240
1242 {
1243 int consumed = _consumed;
1245 long lineNumber = _lineNumber;
1246 JsonTokenType tokenType = _tokenType;
1248 switch (ConsumeNextToken(marker))
1249 {
1250 case ConsumeTokenResult.Success:
1251 return true;
1252 case ConsumeTokenResult.NotEnoughDataRollBackState:
1254 _tokenType = tokenType;
1256 _lineNumber = lineNumber;
1258 break;
1259 }
1260 return false;
1261 }
1262
1264 {
1266 {
1268 {
1270 }
1271 if (marker == 47)
1272 {
1273 if (!ConsumeComment())
1274 {
1275 return ConsumeTokenResult.NotEnoughDataRollBackState;
1276 }
1277 return ConsumeTokenResult.Success;
1278 }
1279 if (_tokenType == JsonTokenType.Comment)
1280 {
1282 }
1283 }
1284 if (_bitStack.CurrentDepth == 0)
1285 {
1286 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedEndAfterSingleJson, marker);
1287 }
1288 switch (marker)
1289 {
1290 case 44:
1291 {
1292 _consumed++;
1294 if (_consumed >= (uint)_buffer.Length)
1295 {
1296 if (IsLastSpan)
1297 {
1298 _consumed--;
1300 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedStartOfPropertyOrValueNotFound, 0);
1301 }
1302 return ConsumeTokenResult.NotEnoughDataRollBackState;
1303 }
1304 byte b = _buffer[_consumed];
1305 if (b <= 32)
1306 {
1308 if (!HasMoreData(ExceptionResource.ExpectedStartOfPropertyOrValueNotFound))
1309 {
1310 return ConsumeTokenResult.NotEnoughDataRollBackState;
1311 }
1312 b = _buffer[_consumed];
1313 }
1316 {
1318 if (!ConsumeComment())
1319 {
1320 return ConsumeTokenResult.NotEnoughDataRollBackState;
1321 }
1322 return ConsumeTokenResult.Success;
1323 }
1324 if (_inObject)
1325 {
1326 if (b != 34)
1327 {
1328 if (b == 125)
1329 {
1331 {
1332 EndObject();
1333 return ConsumeTokenResult.Success;
1334 }
1335 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.TrailingCommaNotAllowedBeforeObjectEnd, 0);
1336 }
1337 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedStartOfPropertyNotFound, b);
1338 }
1339 if (!ConsumePropertyName())
1340 {
1341 return ConsumeTokenResult.NotEnoughDataRollBackState;
1342 }
1343 return ConsumeTokenResult.Success;
1344 }
1345 if (b == 93)
1346 {
1348 {
1349 EndArray();
1350 return ConsumeTokenResult.Success;
1351 }
1352 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.TrailingCommaNotAllowedBeforeArrayEnd, 0);
1353 }
1354 if (!ConsumeValue(b))
1355 {
1356 return ConsumeTokenResult.NotEnoughDataRollBackState;
1357 }
1358 return ConsumeTokenResult.Success;
1359 }
1360 case 125:
1361 EndObject();
1362 break;
1363 case 93:
1364 EndArray();
1365 break;
1366 default:
1367 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.FoundInvalidCharacter, marker);
1368 break;
1369 }
1370 return ConsumeTokenResult.Success;
1371 }
1372
1374 {
1376 {
1378 }
1379 else
1380 {
1382 }
1383 if (HasMoreData())
1384 {
1385 byte b = _buffer[_consumed];
1386 if (b <= 32)
1387 {
1389 if (!HasMoreData())
1390 {
1391 goto IL_0343;
1392 }
1393 b = _buffer[_consumed];
1394 }
1395 if (_bitStack.CurrentDepth == 0 && _tokenType != 0)
1396 {
1397 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedEndAfterSingleJson, b);
1398 }
1400 if (b != 44)
1401 {
1402 if (b == 125)
1403 {
1404 EndObject();
1405 }
1406 else
1407 {
1408 if (b != 93)
1409 {
1410 if (_tokenType == JsonTokenType.None)
1411 {
1412 if (ReadFirstToken(b))
1413 {
1414 goto IL_0341;
1415 }
1416 }
1417 else if (_tokenType == JsonTokenType.StartObject)
1418 {
1419 if (b != 34)
1420 {
1421 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedStartOfPropertyNotFound, b);
1422 }
1423 int consumed = _consumed;
1425 long lineNumber = _lineNumber;
1426 if (ConsumePropertyName())
1427 {
1428 goto IL_0341;
1429 }
1431 _tokenType = JsonTokenType.StartObject;
1433 _lineNumber = lineNumber;
1434 }
1435 else if (_tokenType == JsonTokenType.StartArray)
1436 {
1437 if (ConsumeValue(b))
1438 {
1439 goto IL_0341;
1440 }
1441 }
1442 else if (_tokenType == JsonTokenType.PropertyName)
1443 {
1444 if (ConsumeValue(b))
1445 {
1446 goto IL_0341;
1447 }
1448 }
1449 else if (_inObject)
1450 {
1451 if (b != 34)
1452 {
1453 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedStartOfPropertyNotFound, b);
1454 }
1455 if (ConsumePropertyName())
1456 {
1457 goto IL_0341;
1458 }
1459 }
1460 else if (ConsumeValue(b))
1461 {
1462 goto IL_0341;
1463 }
1464 goto IL_0343;
1465 }
1466 EndArray();
1467 }
1468 goto IL_0341;
1469 }
1471 {
1472 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedStartOfPropertyOrValueAfterComment, b);
1473 }
1474 _consumed++;
1476 if (_consumed >= (uint)_buffer.Length)
1477 {
1478 if (IsLastSpan)
1479 {
1480 _consumed--;
1482 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedStartOfPropertyOrValueNotFound, 0);
1483 }
1484 }
1485 else
1486 {
1487 b = _buffer[_consumed];
1488 if (b <= 32)
1489 {
1491 if (!HasMoreData(ExceptionResource.ExpectedStartOfPropertyOrValueNotFound))
1492 {
1493 goto IL_0343;
1494 }
1495 b = _buffer[_consumed];
1496 }
1498 if (b == 47)
1499 {
1501 if (ConsumeComment())
1502 {
1503 goto IL_0341;
1504 }
1505 }
1506 else if (_inObject)
1507 {
1508 if (b != 34)
1509 {
1510 if (b == 125)
1511 {
1513 {
1514 EndObject();
1515 goto IL_0341;
1516 }
1517 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.TrailingCommaNotAllowedBeforeObjectEnd, 0);
1518 }
1519 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedStartOfPropertyNotFound, b);
1520 }
1521 if (ConsumePropertyName())
1522 {
1523 goto IL_0341;
1524 }
1525 }
1526 else
1527 {
1528 if (b == 93)
1529 {
1531 {
1532 EndArray();
1533 goto IL_0341;
1534 }
1535 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.TrailingCommaNotAllowedBeforeArrayEnd, 0);
1536 }
1537 if (ConsumeValue(b))
1538 {
1539 goto IL_0341;
1540 }
1541 }
1542 }
1543 }
1544 goto IL_0343;
1545 IL_0343:
1546 return ConsumeTokenResult.NotEnoughDataRollBackState;
1547 IL_0341:
1548 return ConsumeTokenResult.Success;
1549 }
1550
1551 private bool SkipAllComments(ref byte marker)
1552 {
1553 while (true)
1554 {
1555 if (marker == 47)
1556 {
1557 if (!SkipComment() || !HasMoreData())
1558 {
1559 break;
1560 }
1562 if (marker <= 32)
1563 {
1565 if (!HasMoreData())
1566 {
1567 break;
1568 }
1570 }
1571 continue;
1572 }
1573 return true;
1574 }
1575 return false;
1576 }
1577
1579 {
1580 while (true)
1581 {
1582 if (marker == 47)
1583 {
1584 if (!SkipComment() || !HasMoreData(resource))
1585 {
1586 break;
1587 }
1589 if (marker <= 32)
1590 {
1592 if (!HasMoreData(resource))
1593 {
1594 break;
1595 }
1597 }
1598 continue;
1599 }
1600 return true;
1601 }
1602 return false;
1603 }
1604
1606 {
1608 {
1610 if (_tokenType == JsonTokenType.StartObject)
1611 {
1612 if (marker == 125)
1613 {
1614 EndObject();
1615 }
1616 else
1617 {
1618 if (marker != 34)
1619 {
1620 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedStartOfPropertyNotFound, marker);
1621 }
1622 int consumed = _consumed;
1624 long lineNumber = _lineNumber;
1625 if (!ConsumePropertyName())
1626 {
1628 _tokenType = JsonTokenType.StartObject;
1630 _lineNumber = lineNumber;
1631 goto IL_0281;
1632 }
1633 }
1634 }
1635 else if (_tokenType == JsonTokenType.StartArray)
1636 {
1637 if (marker == 93)
1638 {
1639 EndArray();
1640 }
1641 else if (!ConsumeValue(marker))
1642 {
1643 goto IL_0281;
1644 }
1645 }
1646 else if (_tokenType == JsonTokenType.PropertyName)
1647 {
1648 if (!ConsumeValue(marker))
1649 {
1650 goto IL_0281;
1651 }
1652 }
1653 else if (_bitStack.CurrentDepth == 0)
1654 {
1655 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedEndAfterSingleJson, marker);
1656 }
1657 else
1658 {
1659 switch (marker)
1660 {
1661 case 44:
1662 _consumed++;
1664 if (_consumed >= (uint)_buffer.Length)
1665 {
1666 if (IsLastSpan)
1667 {
1668 _consumed--;
1670 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedStartOfPropertyOrValueNotFound, 0);
1671 }
1672 return ConsumeTokenResult.NotEnoughDataRollBackState;
1673 }
1675 if (marker <= 32)
1676 {
1678 if (!HasMoreData(ExceptionResource.ExpectedStartOfPropertyOrValueNotFound))
1679 {
1680 return ConsumeTokenResult.NotEnoughDataRollBackState;
1681 }
1683 }
1684 if (SkipAllComments(ref marker, ExceptionResource.ExpectedStartOfPropertyOrValueNotFound))
1685 {
1687 if (_inObject)
1688 {
1689 if (marker != 34)
1690 {
1691 if (marker == 125)
1692 {
1694 {
1695 EndObject();
1696 break;
1697 }
1698 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.TrailingCommaNotAllowedBeforeObjectEnd, 0);
1699 }
1700 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedStartOfPropertyNotFound, marker);
1701 }
1702 if (!ConsumePropertyName())
1703 {
1704 return ConsumeTokenResult.NotEnoughDataRollBackState;
1705 }
1706 return ConsumeTokenResult.Success;
1707 }
1708 if (marker == 93)
1709 {
1711 {
1712 EndArray();
1713 break;
1714 }
1715 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.TrailingCommaNotAllowedBeforeArrayEnd, 0);
1716 }
1717 if (!ConsumeValue(marker))
1718 {
1719 return ConsumeTokenResult.NotEnoughDataRollBackState;
1720 }
1721 return ConsumeTokenResult.Success;
1722 }
1723 return ConsumeTokenResult.NotEnoughDataRollBackState;
1724 case 125:
1725 EndObject();
1726 break;
1727 case 93:
1728 EndArray();
1729 break;
1730 default:
1731 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.FoundInvalidCharacter, marker);
1732 break;
1733 }
1734 }
1735 return ConsumeTokenResult.Success;
1736 }
1737 goto IL_0281;
1738 IL_0281:
1739 return ConsumeTokenResult.IncompleteNoRollBackNecessary;
1740 }
1741
1742 private bool SkipComment()
1743 {
1745 if (readOnlySpan.Length > 0)
1746 {
1747 int idx;
1748 switch (readOnlySpan[0])
1749 {
1750 case 47:
1751 return SkipSingleLineComment(readOnlySpan.Slice(1), out idx);
1752 case 42:
1753 return SkipMultiLineComment(readOnlySpan.Slice(1), out idx);
1754 }
1755 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedStartOfValueNotFound, 47);
1756 }
1757 if (IsLastSpan)
1758 {
1759 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedStartOfValueNotFound, 47);
1760 }
1761 return false;
1762 }
1763
1765 {
1767 int num = 0;
1768 if (idx != -1)
1769 {
1770 num = idx;
1771 if (localBuffer[idx] != 10)
1772 {
1773 if (idx < localBuffer.Length - 1)
1774 {
1775 if (localBuffer[idx + 1] == 10)
1776 {
1777 num++;
1778 }
1779 }
1780 else if (!IsLastSpan)
1781 {
1782 return false;
1783 }
1784 }
1785 num++;
1787 _lineNumber++;
1788 }
1789 else
1790 {
1791 if (!IsLastSpan)
1792 {
1793 return false;
1794 }
1795 idx = localBuffer.Length;
1796 num = idx;
1797 _bytePositionInLine += 2 + localBuffer.Length;
1798 }
1799 _consumed += 2 + num;
1800 return true;
1801 }
1802
1804 {
1805 int num = 0;
1806 while (true)
1807 {
1808 int num2 = localBuffer.IndexOfAny<byte>(10, 13, 226);
1809 if (num2 == -1)
1810 {
1811 return -1;
1812 }
1813 num += num2;
1814 if (localBuffer[num2] != 226)
1815 {
1816 break;
1817 }
1818 num++;
1819 localBuffer = localBuffer.Slice(num2 + 1);
1821 }
1822 return num;
1823 }
1824
1826 {
1827 if (localBuffer.Length >= 2)
1828 {
1829 byte b = localBuffer[1];
1830 if (localBuffer[0] == 128 && (b == 168 || b == 169))
1831 {
1832 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.UnexpectedEndOfLineSeparator, 0);
1833 }
1834 }
1835 }
1836
1838 {
1839 idx = 0;
1840 while (true)
1841 {
1842 int num = localBuffer.Slice(idx).IndexOf<byte>(47);
1843 switch (num)
1844 {
1845 case -1:
1846 if (IsLastSpan)
1847 {
1848 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.EndOfCommentNotFound, 0);
1849 }
1850 return false;
1851 default:
1852 if (localBuffer[num + idx - 1] == 42)
1853 {
1854 idx += num - 1;
1855 _consumed += 4 + idx;
1857 _lineNumber += num2;
1858 if (num3 != -1)
1859 {
1861 }
1862 else
1863 {
1864 _bytePositionInLine += 4 + idx;
1865 }
1866 return true;
1867 }
1868 break;
1869 case 0:
1870 break;
1871 }
1872 idx += num + 1;
1873 }
1874 }
1875
1876 private bool ConsumeComment()
1877 {
1879 if (readOnlySpan.Length > 0)
1880 {
1881 byte b = readOnlySpan[0];
1882 switch (b)
1883 {
1884 case 47:
1886 case 42:
1888 }
1889 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.InvalidCharacterAtStartOfComment, b);
1890 }
1891 if (IsLastSpan)
1892 {
1893 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.UnexpectedEndOfDataWhileReadingComment, 0);
1894 }
1895 return false;
1896 }
1897
1899 {
1901 {
1902 return false;
1903 }
1905 if (_tokenType != JsonTokenType.Comment)
1906 {
1908 }
1909 _tokenType = JsonTokenType.Comment;
1910 return true;
1911 }
1912
1914 {
1916 {
1917 return false;
1918 }
1920 if (_tokenType != JsonTokenType.Comment)
1921 {
1923 }
1924 _tokenType = JsonTokenType.Comment;
1925 return true;
1926 }
1927
1948
1950 {
1952 _buffer = memory.Span;
1954 _isInputSequence = true;
1955 _lineNumber = state._lineNumber;
1956 _bytePositionInLine = state._bytePositionInLine;
1957 _inObject = state._inObject;
1958 _isNotPrimitive = state._isNotPrimitive;
1959 _stringHasEscaping = state._stringHasEscaping;
1960 _trailingCommaBeforeComment = state._trailingCommaBeforeComment;
1961 _tokenType = state._tokenType;
1962 _previousTokenType = state._previousTokenType;
1963 _readerOptions = state._readerOptions;
1964 if (_readerOptions.MaxDepth == 0)
1965 {
1967 }
1968 _bitStack = state._bitStack;
1969 _consumed = 0;
1970 TokenStartIndex = 0L;
1971 _totalConsumed = 0L;
1974 HasValueSequence = false;
1976 if (jsonData.IsSingleSegment)
1977 {
1979 _currentPosition = jsonData.Start;
1981 _isMultiSegment = false;
1982 return;
1983 }
1984 _currentPosition = jsonData.Start;
1986 bool flag = _buffer.Length == 0;
1987 if (flag)
1988 {
1991 while (jsonData.TryGet(ref _nextPosition, out memory2))
1992 {
1994 if (memory2.Length != 0)
1995 {
1996 _buffer = memory2.Span;
1997 break;
1998 }
2000 }
2001 }
2003 _isMultiSegment = true;
2004 }
2005
2010
2011 private bool ReadMultiSegment()
2012 {
2013 bool flag = false;
2014 HasValueSequence = false;
2015 ValueSpan = default(ReadOnlySpan<byte>);
2018 {
2019 byte b = _buffer[_consumed];
2020 if (b <= 32)
2021 {
2024 {
2025 goto IL_016c;
2026 }
2027 b = _buffer[_consumed];
2028 }
2030 if (_tokenType != 0)
2031 {
2032 if (b == 47)
2033 {
2035 }
2036 else if (_tokenType == JsonTokenType.StartObject)
2037 {
2038 if (b == 125)
2039 {
2040 EndObject();
2041 goto IL_016a;
2042 }
2043 if (b != 34)
2044 {
2045 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedStartOfPropertyNotFound, b);
2046 }
2048 int consumed = _consumed;
2050 long lineNumber = _lineNumber;
2053 if (!flag)
2054 {
2056 _tokenType = JsonTokenType.StartObject;
2058 _lineNumber = lineNumber;
2061 }
2062 }
2063 else if (_tokenType != JsonTokenType.StartArray)
2064 {
2066 }
2067 else
2068 {
2069 if (b == 93)
2070 {
2071 EndArray();
2072 goto IL_016a;
2073 }
2075 }
2076 }
2077 else
2078 {
2080 }
2081 }
2082 goto IL_016c;
2083 IL_016c:
2084 return flag;
2085 IL_016a:
2086 flag = true;
2087 goto IL_016c;
2088 }
2089
2091 {
2092 if (_bitStack.CurrentDepth != 0)
2093 {
2095 }
2097 {
2098 return false;
2099 }
2100 if (_tokenType != JsonTokenType.EndArray && _tokenType != JsonTokenType.EndObject)
2101 {
2102 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.InvalidEndOfJsonNonPrimitive, 0);
2103 }
2104 return true;
2105 }
2106
2107 [MethodImpl(MethodImplOptions.AggressiveInlining)]
2109 {
2110 if (_consumed >= (uint)_buffer.Length)
2111 {
2113 {
2114 return false;
2115 }
2116 if (!GetNextSpan())
2117 {
2119 {
2121 }
2122 return false;
2123 }
2124 }
2125 return true;
2126 }
2127
2128 [MethodImpl(MethodImplOptions.AggressiveInlining)]
2130 {
2131 if (_consumed >= (uint)_buffer.Length)
2132 {
2133 if (IsLastSpan)
2134 {
2136 }
2137 if (!GetNextSpan())
2138 {
2139 if (IsLastSpan)
2140 {
2142 }
2143 return false;
2144 }
2145 }
2146 return true;
2147 }
2148
2149 private bool GetNextSpan()
2150 {
2152 while (true)
2153 {
2157 {
2159 _isLastSegment = true;
2160 return false;
2161 }
2162 if (memory.Length != 0)
2163 {
2164 break;
2165 }
2167 }
2168 if (_isFinalBlock)
2169 {
2171 }
2172 _buffer = memory.Span;
2174 _consumed = 0;
2175 return true;
2176 }
2177
2178 private bool ReadFirstTokenMultiSegment(byte first)
2179 {
2180 switch (first)
2181 {
2182 case 123:
2184 _tokenType = JsonTokenType.StartObject;
2186 _consumed++;
2188 _inObject = true;
2189 _isNotPrimitive = true;
2190 break;
2191 case 91:
2193 _tokenType = JsonTokenType.StartArray;
2195 _consumed++;
2197 _isNotPrimitive = true;
2198 break;
2199 default:
2200 if (JsonHelpers.IsDigit(first) || first == 45)
2201 {
2203 {
2204 return false;
2205 }
2206 _tokenType = JsonTokenType.Number;
2208 return true;
2209 }
2210 if (!ConsumeValueMultiSegment(first))
2211 {
2212 return false;
2213 }
2214 if (_tokenType == JsonTokenType.StartObject || _tokenType == JsonTokenType.StartArray)
2215 {
2216 _isNotPrimitive = true;
2217 }
2218 break;
2219 }
2220 return true;
2221 }
2222
2224 {
2225 do
2226 {
2228 }
2229 while (_consumed >= _buffer.Length && GetNextSpan());
2230 }
2231
2233 {
2234 while (true)
2235 {
2237 switch (marker)
2238 {
2239 case 34:
2241 case 123:
2242 StartObject();
2243 break;
2244 case 91:
2245 StartArray();
2246 break;
2247 default:
2248 if (JsonHelpers.IsDigit(marker) || marker == 45)
2249 {
2251 }
2252 switch (marker)
2253 {
2254 case 102:
2256 case 116:
2258 case 110:
2260 }
2262 {
2263 case JsonCommentHandling.Allow:
2264 if (marker == 47)
2265 {
2268 {
2270 return false;
2271 }
2272 return true;
2273 }
2274 break;
2275 default:
2276 {
2277 if (marker != 47)
2278 {
2279 break;
2280 }
2283 {
2284 if (_consumed >= (uint)_buffer.Length)
2285 {
2286 if (_isNotPrimitive && IsLastSpan && _tokenType != JsonTokenType.EndArray && _tokenType != JsonTokenType.EndObject)
2287 {
2288 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.InvalidEndOfJsonNonPrimitive, 0);
2289 }
2290 if (!GetNextSpan())
2291 {
2292 if (_isNotPrimitive && IsLastSpan && _tokenType != JsonTokenType.EndArray && _tokenType != JsonTokenType.EndObject)
2293 {
2294 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.InvalidEndOfJsonNonPrimitive, 0);
2295 }
2297 return false;
2298 }
2299 }
2301 if (marker <= 32)
2302 {
2305 {
2307 return false;
2308 }
2310 }
2311 goto IL_01a8;
2312 }
2314 return false;
2315 }
2316 case JsonCommentHandling.Disallow:
2317 break;
2318 }
2319 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedStartOfValueNotFound, marker);
2320 break;
2321 }
2322 break;
2323 IL_01a8:
2325 }
2326 return true;
2327 }
2328
2330 {
2332 int consumed = literal.Length;
2333 if (!span.StartsWith(literal))
2334 {
2335 int consumed2 = _consumed;
2337 {
2339 return false;
2340 }
2341 }
2342 else
2343 {
2344 ValueSpan = span.Slice(0, literal.Length);
2345 HasValueSequence = false;
2346 }
2347 _tokenType = tokenType;
2350 return true;
2351 }
2352
2354 {
2356 int num = 0;
2359 if (span.Length >= literal.Length || IsLastSpan)
2360 {
2362 int num2 = Math.Min(span.Length, (int)_bytePositionInLine + 1);
2363 span.Slice(0, num2).CopyTo(destination);
2364 num += num2;
2365 }
2366 else if (!literal.StartsWith(span))
2367 {
2369 int num3 = Math.Min(span.Length, (int)_bytePositionInLine + 1);
2370 span.Slice(0, num3).CopyTo(destination);
2371 num += num3;
2372 }
2373 else
2374 {
2377 int consumed2 = _consumed;
2378 int num4 = literal.Length - readOnlySpan.Length;
2379 while (true)
2380 {
2383 if (!GetNextSpan())
2384 {
2386 consumed = 0;
2388 if (IsLastSpan)
2389 {
2390 break;
2391 }
2392 return false;
2393 }
2394 int num5 = Math.Min(span.Length, destination.Length - num);
2395 span.Slice(0, num5).CopyTo(destination.Slice(num));
2396 num += num5;
2397 span = _buffer;
2398 if (span.StartsWith(readOnlySpan))
2399 {
2400 HasValueSequence = true;
2404 consumed = readOnlySpan.Length;
2405 return true;
2406 }
2407 if (!readOnlySpan.StartsWith(span))
2408 {
2410 num5 = Math.Min(span.Length, (int)_bytePositionInLine + 1);
2411 span.Slice(0, num5).CopyTo(destination.Slice(num));
2412 num += num5;
2413 break;
2414 }
2415 readOnlySpan = readOnlySpan.Slice(span.Length);
2416 num4 = span.Length;
2417 }
2418 }
2420 consumed = 0;
2422 throw GetInvalidLiteralMultiSegment(destination.Slice(0, num).ToArray());
2423 }
2424
2426 {
2427 int num = 0;
2428 int num2 = Math.Min(span.Length, literal.Length);
2429 int i;
2430 for (i = 0; i < num2 && span[i] == literal[i]; i++)
2431 {
2432 }
2433 return i;
2434 }
2435
2437 {
2438 return ThrowHelper.GetJsonReaderException(ref this, span[0] switch
2439 {
2440 116 => ExceptionResource.ExpectedTrue,
2441 102 => ExceptionResource.ExpectedFalse,
2442 _ => ExceptionResource.ExpectedNull,
2443 }, 0, span);
2444 }
2445
2447 {
2449 {
2450 return false;
2451 }
2452 _tokenType = JsonTokenType.Number;
2454 if (_consumed >= (uint)_buffer.Length && _isNotPrimitive)
2455 {
2456 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedEndOfDigitNotFound, _buffer[_consumed - 1]);
2457 }
2458 return true;
2459 }
2460
2462 {
2465 {
2466 return false;
2467 }
2468 if (!HasMoreDataMultiSegment(ExceptionResource.ExpectedValueAfterPropertyNameNotFound))
2469 {
2470 return false;
2471 }
2472 byte b = _buffer[_consumed];
2473 if (b <= 32)
2474 {
2476 if (!HasMoreDataMultiSegment(ExceptionResource.ExpectedValueAfterPropertyNameNotFound))
2477 {
2478 return false;
2479 }
2480 b = _buffer[_consumed];
2481 }
2482 if (b != 58)
2483 {
2484 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedSeparatorAfterPropertyNameNotFound, b);
2485 }
2486 _consumed++;
2488 _tokenType = JsonTokenType.PropertyName;
2489 return true;
2490 }
2491
2493 {
2495 int num = readOnlySpan.IndexOfQuoteOrAnyControlOrBackSlash();
2496 if (num >= 0)
2497 {
2498 byte b = readOnlySpan[num];
2499 if (b == 34)
2500 {
2501 _bytePositionInLine += num + 2;
2502 ValueSpan = readOnlySpan.Slice(0, num);
2503 HasValueSequence = false;
2504 _stringHasEscaping = false;
2505 _tokenType = JsonTokenType.String;
2506 _consumed += num + 2;
2507 return true;
2508 }
2510 }
2511 if (IsLastSpan)
2512 {
2514 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.EndOfStringNotFound, 0);
2515 }
2516 return ConsumeStringNextSegment();
2517 }
2518
2520 {
2522 HasValueSequence = true;
2523 int num = _buffer.Length - _consumed;
2525 int num2;
2526 while (true)
2527 {
2528 if (!GetNextSpan())
2529 {
2530 if (IsLastSpan)
2531 {
2532 _bytePositionInLine += num;
2533 RollBackState(in state, isError: true);
2534 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.EndOfStringNotFound, 0);
2535 }
2537 return false;
2538 }
2539 buffer = _buffer;
2540 num2 = buffer.IndexOfQuoteOrAnyControlOrBackSlash();
2541 if (num2 >= 0)
2542 {
2543 break;
2544 }
2545 _totalConsumed += buffer.Length;
2546 _bytePositionInLine += buffer.Length;
2547 }
2548 byte b = buffer[num2];
2549 SequencePosition end;
2550 if (b == 34)
2551 {
2553 _bytePositionInLine += num + num2 + 1;
2554 _totalConsumed += num;
2555 _consumed = num2 + 1;
2556 _stringHasEscaping = false;
2557 }
2558 else
2559 {
2560 _bytePositionInLine += num + num2;
2561 _stringHasEscaping = true;
2562 bool flag = false;
2563 while (true)
2564 {
2565 if (num2 < buffer.Length)
2566 {
2567 byte b2 = buffer[num2];
2568 if (b2 == 34)
2569 {
2570 if (!flag)
2571 {
2572 break;
2573 }
2574 flag = false;
2575 }
2576 else if (b2 == 92)
2577 {
2578 flag = !flag;
2579 }
2580 else if (flag)
2581 {
2582 int num3 = JsonConstants.EscapableChars.IndexOf(b2);
2583 if (num3 == -1)
2584 {
2585 RollBackState(in state, isError: true);
2586 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.InvalidCharacterAfterEscapeWithinString, b2);
2587 }
2588 if (b2 == 117)
2589 {
2591 int num4 = 0;
2592 int num5 = num2 + 1;
2593 while (true)
2594 {
2595 if (num5 < buffer.Length)
2596 {
2597 byte nextByte = buffer[num5];
2599 {
2600 RollBackState(in state, isError: true);
2601 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.InvalidHexCharacterWithinString, nextByte);
2602 }
2603 num4++;
2605 if (num4 >= 4)
2606 {
2607 break;
2608 }
2609 num5++;
2610 continue;
2611 }
2612 if (!GetNextSpan())
2613 {
2614 if (IsLastSpan)
2615 {
2616 RollBackState(in state, isError: true);
2617 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.EndOfStringNotFound, 0);
2618 }
2620 return false;
2621 }
2622 _totalConsumed += buffer.Length;
2623 buffer = _buffer;
2624 num5 = 0;
2625 }
2626 flag = false;
2627 num2 = num5 + 1;
2628 continue;
2629 }
2630 flag = false;
2631 }
2632 else if (b2 < 32)
2633 {
2634 RollBackState(in state, isError: true);
2635 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.InvalidCharacterWithinString, b2);
2636 }
2638 num2++;
2639 continue;
2640 }
2641 if (!GetNextSpan())
2642 {
2643 if (IsLastSpan)
2644 {
2645 RollBackState(in state, isError: true);
2646 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.EndOfStringNotFound, 0);
2647 }
2649 return false;
2650 }
2651 _totalConsumed += buffer.Length;
2652 buffer = _buffer;
2653 num2 = 0;
2654 }
2656 _consumed = num2 + 1;
2657 _totalConsumed += num;
2659 }
2660 SequencePosition startPosition = state.GetStartPosition(1);
2662 _tokenType = JsonTokenType.String;
2663 return true;
2664 }
2665
2667 {
2669 HasValueSequence = false;
2670 int num = _buffer.Length - _consumed;
2671 _bytePositionInLine += idx + 1;
2672 bool flag = false;
2673 while (true)
2674 {
2675 if (idx < data.Length)
2676 {
2677 byte b = data[idx];
2678 switch (b)
2679 {
2680 case 34:
2681 if (flag)
2682 {
2683 flag = false;
2684 goto IL_01b7;
2685 }
2686 if (HasValueSequence)
2687 {
2689 _consumed = idx + 1;
2690 _totalConsumed += num;
2692 SequencePosition startPosition = state.GetStartPosition(1);
2694 }
2695 else
2696 {
2698 _consumed += idx + 2;
2699 ValueSpan = data.Slice(0, idx);
2700 }
2701 _stringHasEscaping = true;
2702 _tokenType = JsonTokenType.String;
2703 return true;
2704 case 92:
2705 flag = !flag;
2706 goto IL_01b7;
2707 default:
2708 {
2709 if (flag)
2710 {
2711 int num2 = JsonConstants.EscapableChars.IndexOf(b);
2712 if (num2 == -1)
2713 {
2714 RollBackState(in state, isError: true);
2715 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.InvalidCharacterAfterEscapeWithinString, b);
2716 }
2717 if (b == 117)
2718 {
2720 int num3 = 0;
2721 int num4 = idx + 1;
2722 while (true)
2723 {
2724 if (num4 < data.Length)
2725 {
2726 byte nextByte = data[num4];
2728 {
2729 RollBackState(in state, isError: true);
2730 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.InvalidHexCharacterWithinString, nextByte);
2731 }
2732 num3++;
2734 if (num3 >= 4)
2735 {
2736 break;
2737 }
2738 num4++;
2739 continue;
2740 }
2741 if (!GetNextSpan())
2742 {
2743 if (IsLastSpan)
2744 {
2745 RollBackState(in state, isError: true);
2746 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.EndOfStringNotFound, 0);
2747 }
2749 return false;
2750 }
2751 if (HasValueSequence)
2752 {
2753 _totalConsumed += data.Length;
2754 }
2755 data = _buffer;
2756 num4 = 0;
2757 HasValueSequence = true;
2758 }
2759 flag = false;
2760 idx = num4 + 1;
2761 break;
2762 }
2763 flag = false;
2764 }
2765 else if (b < 32)
2766 {
2767 RollBackState(in state, isError: true);
2768 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.InvalidCharacterWithinString, b);
2769 }
2770 goto IL_01b7;
2771 }
2772 IL_01b7:
2774 idx++;
2775 break;
2776 }
2777 }
2778 else
2779 {
2780 if (!GetNextSpan())
2781 {
2782 break;
2783 }
2784 if (HasValueSequence)
2785 {
2786 _totalConsumed += data.Length;
2787 }
2788 data = _buffer;
2789 idx = 0;
2790 HasValueSequence = true;
2791 }
2792 }
2793 if (IsLastSpan)
2794 {
2795 RollBackState(in state, isError: true);
2796 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.EndOfStringNotFound, 0);
2797 }
2799 return false;
2800 }
2801
2803 {
2804 _totalConsumed = state._prevTotalConsumed;
2805 if (!isError)
2806 {
2807 _bytePositionInLine = state._prevBytePositionInLine;
2808 }
2809 _consumed = state._prevConsumed;
2810 _currentPosition = state._prevCurrentPosition;
2811 }
2812
2814 {
2816 consumed = 0;
2817 int i = 0;
2819 if (consumeNumberResult == ConsumeNumberResult.NeedMoreData)
2820 {
2822 return false;
2823 }
2824 byte b = data[i];
2825 if (b == 48)
2826 {
2828 if (consumeNumberResult2 == ConsumeNumberResult.NeedMoreData)
2829 {
2831 return false;
2832 }
2833 if (consumeNumberResult2 != 0)
2834 {
2835 b = data[i];
2836 goto IL_00bf;
2837 }
2838 }
2839 else
2840 {
2842 if (consumeNumberResult3 == ConsumeNumberResult.NeedMoreData)
2843 {
2845 return false;
2846 }
2847 if (consumeNumberResult3 != 0)
2848 {
2849 b = data[i];
2850 if (b != 46 && b != 69 && b != 101)
2851 {
2853 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedEndOfDigitNotFound, b);
2854 }
2855 goto IL_00bf;
2856 }
2857 }
2858 goto IL_01b1;
2859 IL_00bf:
2860 if (b == 46)
2861 {
2862 i++;
2865 if (consumeNumberResult4 == ConsumeNumberResult.NeedMoreData)
2866 {
2868 return false;
2869 }
2871 {
2872 goto IL_01b1;
2873 }
2874 b = data[i];
2875 if (b != 69 && b != 101)
2876 {
2878 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedNextDigitEValueNotFound, b);
2879 }
2880 }
2881 i++;
2884 if (consumeNumberResult == ConsumeNumberResult.NeedMoreData)
2885 {
2887 return false;
2888 }
2889 i++;
2891 switch (ConsumeIntegerDigitsMultiSegment(ref data, ref i))
2892 {
2893 case ConsumeNumberResult.NeedMoreData:
2895 return false;
2896 default:
2898 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedEndOfDigitNotFound, data[i]);
2899 break;
2900 case ConsumeNumberResult.Success:
2901 break;
2902 }
2903 goto IL_01b1;
2904 IL_01b1:
2905 if (HasValueSequence)
2906 {
2907 SequencePosition startPosition = rollBackState.GetStartPosition();
2910 consumed = i;
2911 }
2912 else
2913 {
2914 ValueSpan = data.Slice(0, i);
2915 consumed = i;
2916 }
2917 return true;
2918 }
2919
2921 {
2922 byte b = data[i];
2923 if (b == 45)
2924 {
2925 i++;
2927 if (i >= data.Length)
2928 {
2929 if (IsLastSpan)
2930 {
2932 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.RequiredDigitNotFoundEndOfData, 0);
2933 }
2934 if (!GetNextSpan())
2935 {
2936 if (IsLastSpan)
2937 {
2939 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.RequiredDigitNotFoundEndOfData, 0);
2940 }
2941 return ConsumeNumberResult.NeedMoreData;
2942 }
2943 _totalConsumed += i;
2944 HasValueSequence = true;
2945 i = 0;
2946 data = _buffer;
2947 }
2948 b = data[i];
2949 if (!JsonHelpers.IsDigit(b))
2950 {
2952 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.RequiredDigitNotFoundAfterSign, b);
2953 }
2954 }
2955 return ConsumeNumberResult.OperationIncomplete;
2956 }
2957
2959 {
2960 i++;
2962 byte value;
2963 if (i < data.Length)
2964 {
2965 value = data[i];
2966 if (JsonConstants.Delimiters.IndexOf(value) >= 0)
2967 {
2968 return ConsumeNumberResult.Success;
2969 }
2970 }
2971 else
2972 {
2973 if (IsLastSpan)
2974 {
2975 return ConsumeNumberResult.Success;
2976 }
2977 if (!GetNextSpan())
2978 {
2979 if (IsLastSpan)
2980 {
2981 return ConsumeNumberResult.Success;
2982 }
2983 return ConsumeNumberResult.NeedMoreData;
2984 }
2985 _totalConsumed += i;
2986 HasValueSequence = true;
2987 i = 0;
2988 data = _buffer;
2989 value = data[i];
2990 if (JsonConstants.Delimiters.IndexOf(value) >= 0)
2991 {
2992 return ConsumeNumberResult.Success;
2993 }
2994 }
2995 value = data[i];
2996 if (value != 46 && value != 69 && value != 101)
2997 {
3000 }
3001 return ConsumeNumberResult.OperationIncomplete;
3002 }
3003
3005 {
3006 byte value = 0;
3007 int num = 0;
3008 while (i < data.Length)
3009 {
3010 value = data[i];
3012 {
3013 break;
3014 }
3015 num++;
3016 i++;
3017 }
3018 if (i >= data.Length)
3019 {
3020 if (IsLastSpan)
3021 {
3022 _bytePositionInLine += num;
3023 return ConsumeNumberResult.Success;
3024 }
3025 while (true)
3026 {
3027 if (!GetNextSpan())
3028 {
3029 if (IsLastSpan)
3030 {
3031 _bytePositionInLine += num;
3032 return ConsumeNumberResult.Success;
3033 }
3034 return ConsumeNumberResult.NeedMoreData;
3035 }
3036 _totalConsumed += i;
3037 _bytePositionInLine += num;
3038 num = 0;
3039 HasValueSequence = true;
3040 i = 0;
3041 data = _buffer;
3042 while (i < data.Length)
3043 {
3044 value = data[i];
3046 {
3047 break;
3048 }
3049 i++;
3050 }
3052 if (i < data.Length)
3053 {
3054 break;
3055 }
3056 if (IsLastSpan)
3057 {
3058 return ConsumeNumberResult.Success;
3059 }
3060 }
3061 }
3062 else
3063 {
3064 _bytePositionInLine += num;
3065 }
3066 if (JsonConstants.Delimiters.IndexOf(value) >= 0)
3067 {
3068 return ConsumeNumberResult.Success;
3069 }
3070 return ConsumeNumberResult.OperationIncomplete;
3071 }
3072
3074 {
3075 if (i >= data.Length)
3076 {
3077 if (IsLastSpan)
3078 {
3080 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.RequiredDigitNotFoundEndOfData, 0);
3081 }
3082 if (!GetNextSpan())
3083 {
3084 if (IsLastSpan)
3085 {
3087 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.RequiredDigitNotFoundEndOfData, 0);
3088 }
3089 return ConsumeNumberResult.NeedMoreData;
3090 }
3091 _totalConsumed += i;
3092 HasValueSequence = true;
3093 i = 0;
3094 data = _buffer;
3095 }
3096 byte b = data[i];
3097 if (!JsonHelpers.IsDigit(b))
3098 {
3100 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.RequiredDigitNotFoundAfterDecimal, b);
3101 }
3102 i++;
3105 }
3106
3108 {
3109 if (i >= data.Length)
3110 {
3111 if (IsLastSpan)
3112 {
3114 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.RequiredDigitNotFoundEndOfData, 0);
3115 }
3116 if (!GetNextSpan())
3117 {
3118 if (IsLastSpan)
3119 {
3121 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.RequiredDigitNotFoundEndOfData, 0);
3122 }
3123 return ConsumeNumberResult.NeedMoreData;
3124 }
3125 _totalConsumed += i;
3126 HasValueSequence = true;
3127 i = 0;
3128 data = _buffer;
3129 }
3130 byte b = data[i];
3131 if (b == 43 || b == 45)
3132 {
3133 i++;
3135 if (i >= data.Length)
3136 {
3137 if (IsLastSpan)
3138 {
3140 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.RequiredDigitNotFoundEndOfData, 0);
3141 }
3142 if (!GetNextSpan())
3143 {
3144 if (IsLastSpan)
3145 {
3147 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.RequiredDigitNotFoundEndOfData, 0);
3148 }
3149 return ConsumeNumberResult.NeedMoreData;
3150 }
3151 _totalConsumed += i;
3152 HasValueSequence = true;
3153 i = 0;
3154 data = _buffer;
3155 }
3156 b = data[i];
3157 }
3158 if (!JsonHelpers.IsDigit(b))
3159 {
3161 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.RequiredDigitNotFoundAfterSign, b);
3162 }
3163 return ConsumeNumberResult.OperationIncomplete;
3164 }
3165
3167 {
3169 int consumed = _consumed;
3171 long lineNumber = _lineNumber;
3172 JsonTokenType tokenType = _tokenType;
3176 {
3177 case ConsumeTokenResult.Success:
3178 return true;
3179 case ConsumeTokenResult.NotEnoughDataRollBackState:
3181 _tokenType = tokenType;
3183 _lineNumber = lineNumber;
3187 break;
3188 }
3189 return false;
3190 }
3191
3193 {
3195 {
3197 {
3199 }
3200 if (marker == 47)
3201 {
3203 {
3204 return ConsumeTokenResult.NotEnoughDataRollBackState;
3205 }
3206 return ConsumeTokenResult.Success;
3207 }
3208 if (_tokenType == JsonTokenType.Comment)
3209 {
3211 }
3212 }
3213 if (_bitStack.CurrentDepth == 0)
3214 {
3215 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedEndAfterSingleJson, marker);
3216 }
3217 switch (marker)
3218 {
3219 case 44:
3220 {
3221 _consumed++;
3223 if (_consumed >= (uint)_buffer.Length)
3224 {
3225 if (IsLastSpan)
3226 {
3227 _consumed--;
3229 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedStartOfPropertyOrValueNotFound, 0);
3230 }
3231 if (!GetNextSpan())
3232 {
3233 if (IsLastSpan)
3234 {
3235 _consumed--;
3237 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedStartOfPropertyOrValueNotFound, 0);
3238 }
3239 return ConsumeTokenResult.NotEnoughDataRollBackState;
3240 }
3241 }
3242 byte b = _buffer[_consumed];
3243 if (b <= 32)
3244 {
3246 if (!HasMoreDataMultiSegment(ExceptionResource.ExpectedStartOfPropertyOrValueNotFound))
3247 {
3248 return ConsumeTokenResult.NotEnoughDataRollBackState;
3249 }
3250 b = _buffer[_consumed];
3251 }
3254 {
3257 {
3258 return ConsumeTokenResult.NotEnoughDataRollBackState;
3259 }
3260 return ConsumeTokenResult.Success;
3261 }
3262 if (_inObject)
3263 {
3264 if (b != 34)
3265 {
3266 if (b == 125)
3267 {
3269 {
3270 EndObject();
3271 return ConsumeTokenResult.Success;
3272 }
3273 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.TrailingCommaNotAllowedBeforeObjectEnd, 0);
3274 }
3275 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedStartOfPropertyNotFound, b);
3276 }
3278 {
3279 return ConsumeTokenResult.NotEnoughDataRollBackState;
3280 }
3281 return ConsumeTokenResult.Success;
3282 }
3283 if (b == 93)
3284 {
3286 {
3287 EndArray();
3288 return ConsumeTokenResult.Success;
3289 }
3290 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.TrailingCommaNotAllowedBeforeArrayEnd, 0);
3291 }
3293 {
3294 return ConsumeTokenResult.NotEnoughDataRollBackState;
3295 }
3296 return ConsumeTokenResult.Success;
3297 }
3298 case 125:
3299 EndObject();
3300 break;
3301 case 93:
3302 EndArray();
3303 break;
3304 default:
3305 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.FoundInvalidCharacter, marker);
3306 break;
3307 }
3308 return ConsumeTokenResult.Success;
3309 }
3310
3312 {
3314 {
3316 }
3317 else
3318 {
3320 }
3322 {
3323 byte b = _buffer[_consumed];
3324 if (b <= 32)
3325 {
3328 {
3329 goto IL_0393;
3330 }
3331 b = _buffer[_consumed];
3332 }
3333 if (_bitStack.CurrentDepth == 0 && _tokenType != 0)
3334 {
3335 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedEndAfterSingleJson, b);
3336 }
3338 if (b != 44)
3339 {
3340 if (b == 125)
3341 {
3342 EndObject();
3343 }
3344 else
3345 {
3346 if (b != 93)
3347 {
3348 if (_tokenType == JsonTokenType.None)
3349 {
3351 {
3352 goto IL_0391;
3353 }
3354 }
3355 else if (_tokenType == JsonTokenType.StartObject)
3356 {
3357 if (b != 34)
3358 {
3359 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedStartOfPropertyNotFound, b);
3360 }
3362 int consumed = _consumed;
3364 long lineNumber = _lineNumber;
3366 {
3367 goto IL_0391;
3368 }
3370 _tokenType = JsonTokenType.StartObject;
3372 _lineNumber = lineNumber;
3374 }
3375 else if (_tokenType == JsonTokenType.StartArray)
3376 {
3378 {
3379 goto IL_0391;
3380 }
3381 }
3382 else if (_tokenType == JsonTokenType.PropertyName)
3383 {
3385 {
3386 goto IL_0391;
3387 }
3388 }
3389 else if (_inObject)
3390 {
3391 if (b != 34)
3392 {
3393 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedStartOfPropertyNotFound, b);
3394 }
3396 {
3397 goto IL_0391;
3398 }
3399 }
3400 else if (ConsumeValueMultiSegment(b))
3401 {
3402 goto IL_0391;
3403 }
3404 goto IL_0393;
3405 }
3406 EndArray();
3407 }
3408 goto IL_0391;
3409 }
3411 {
3412 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedStartOfPropertyOrValueAfterComment, b);
3413 }
3414 _consumed++;
3416 if (_consumed >= (uint)_buffer.Length)
3417 {
3418 if (IsLastSpan)
3419 {
3420 _consumed--;
3422 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedStartOfPropertyOrValueNotFound, 0);
3423 }
3424 if (!GetNextSpan())
3425 {
3426 if (IsLastSpan)
3427 {
3428 _consumed--;
3430 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedStartOfPropertyOrValueNotFound, 0);
3431 }
3432 goto IL_0393;
3433 }
3434 }
3435 b = _buffer[_consumed];
3436 if (b <= 32)
3437 {
3439 if (!HasMoreDataMultiSegment(ExceptionResource.ExpectedStartOfPropertyOrValueNotFound))
3440 {
3441 goto IL_0393;
3442 }
3443 b = _buffer[_consumed];
3444 }
3446 if (b == 47)
3447 {
3450 {
3451 goto IL_0391;
3452 }
3453 }
3454 else if (_inObject)
3455 {
3456 if (b != 34)
3457 {
3458 if (b == 125)
3459 {
3461 {
3462 EndObject();
3463 goto IL_0391;
3464 }
3465 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.TrailingCommaNotAllowedBeforeObjectEnd, 0);
3466 }
3467 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedStartOfPropertyNotFound, b);
3468 }
3470 {
3471 goto IL_0391;
3472 }
3473 }
3474 else
3475 {
3476 if (b == 93)
3477 {
3479 {
3480 EndArray();
3481 goto IL_0391;
3482 }
3483 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.TrailingCommaNotAllowedBeforeArrayEnd, 0);
3484 }
3486 {
3487 goto IL_0391;
3488 }
3489 }
3490 }
3491 goto IL_0393;
3492 IL_0393:
3493 return ConsumeTokenResult.NotEnoughDataRollBackState;
3494 IL_0391:
3495 return ConsumeTokenResult.Success;
3496 }
3497
3499 {
3500 while (true)
3501 {
3502 if (marker == 47)
3503 {
3505 {
3506 break;
3507 }
3509 if (marker <= 32)
3510 {
3513 {
3514 break;
3515 }
3517 }
3518 continue;
3519 }
3520 return true;
3521 }
3522 return false;
3523 }
3524
3526 {
3527 while (true)
3528 {
3529 if (marker == 47)
3530 {
3532 {
3533 break;
3534 }
3536 if (marker <= 32)
3537 {
3540 {
3541 break;
3542 }
3544 }
3545 continue;
3546 }
3547 return true;
3548 }
3549 return false;
3550 }
3551
3553 {
3555 {
3557 if (_tokenType == JsonTokenType.StartObject)
3558 {
3559 if (marker == 125)
3560 {
3561 EndObject();
3562 }
3563 else
3564 {
3565 if (marker != 34)
3566 {
3567 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedStartOfPropertyNotFound, marker);
3568 }
3570 int consumed = _consumed;
3572 long lineNumber = _lineNumber;
3575 {
3577 _tokenType = JsonTokenType.StartObject;
3579 _lineNumber = lineNumber;
3582 goto IL_02e7;
3583 }
3584 }
3585 }
3586 else if (_tokenType == JsonTokenType.StartArray)
3587 {
3588 if (marker == 93)
3589 {
3590 EndArray();
3591 }
3593 {
3594 goto IL_02e7;
3595 }
3596 }
3597 else if (_tokenType == JsonTokenType.PropertyName)
3598 {
3600 {
3601 goto IL_02e7;
3602 }
3603 }
3604 else if (_bitStack.CurrentDepth == 0)
3605 {
3606 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedEndAfterSingleJson, marker);
3607 }
3608 else
3609 {
3610 switch (marker)
3611 {
3612 case 44:
3613 _consumed++;
3615 if (_consumed >= (uint)_buffer.Length)
3616 {
3617 if (IsLastSpan)
3618 {
3619 _consumed--;
3621 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedStartOfPropertyOrValueNotFound, 0);
3622 }
3623 if (!GetNextSpan())
3624 {
3625 if (IsLastSpan)
3626 {
3627 _consumed--;
3629 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedStartOfPropertyOrValueNotFound, 0);
3630 }
3631 return ConsumeTokenResult.NotEnoughDataRollBackState;
3632 }
3633 }
3635 if (marker <= 32)
3636 {
3638 if (!HasMoreDataMultiSegment(ExceptionResource.ExpectedStartOfPropertyOrValueNotFound))
3639 {
3640 return ConsumeTokenResult.NotEnoughDataRollBackState;
3641 }
3643 }
3644 if (SkipAllCommentsMultiSegment(ref marker, ExceptionResource.ExpectedStartOfPropertyOrValueNotFound))
3645 {
3647 if (_inObject)
3648 {
3649 if (marker != 34)
3650 {
3651 if (marker == 125)
3652 {
3654 {
3655 EndObject();
3656 break;
3657 }
3658 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.TrailingCommaNotAllowedBeforeObjectEnd, 0);
3659 }
3660 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.ExpectedStartOfPropertyNotFound, marker);
3661 }
3663 {
3664 return ConsumeTokenResult.NotEnoughDataRollBackState;
3665 }
3666 return ConsumeTokenResult.Success;
3667 }
3668 if (marker == 93)
3669 {
3671 {
3672 EndArray();
3673 break;
3674 }
3675 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.TrailingCommaNotAllowedBeforeArrayEnd, 0);
3676 }
3678 {
3679 return ConsumeTokenResult.NotEnoughDataRollBackState;
3680 }
3681 return ConsumeTokenResult.Success;
3682 }
3683 return ConsumeTokenResult.NotEnoughDataRollBackState;
3684 case 125:
3685 EndObject();
3686 break;
3687 case 93:
3688 EndArray();
3689 break;
3690 default:
3691 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.FoundInvalidCharacter, marker);
3692 break;
3693 }
3694 }
3695 return ConsumeTokenResult.Success;
3696 }
3697 goto IL_02e7;
3698 IL_02e7:
3699 return ConsumeTokenResult.IncompleteNoRollBackNecessary;
3700 }
3701
3703 {
3708 if (flag)
3709 {
3711 {
3715 HasValueSequence = !readOnlySequence.IsSingleSegment;
3716 if (HasValueSequence)
3717 {
3719 }
3720 else
3721 {
3722 ValueSpan = readOnlySequence.First.Span;
3723 }
3724 if (_tokenType != JsonTokenType.Comment)
3725 {
3727 }
3728 _tokenType = JsonTokenType.Comment;
3729 }
3730 }
3731 else
3732 {
3734 _consumed = 0;
3735 }
3736 return flag;
3737 }
3738
3740 {
3741 _consumed++;
3744 if (localBuffer.Length == 0)
3745 {
3746 if (IsLastSpan)
3747 {
3748 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.UnexpectedEndOfDataWhileReadingComment, 0);
3749 }
3750 if (!GetNextSpan())
3751 {
3752 if (IsLastSpan)
3753 {
3754 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.UnexpectedEndOfDataWhileReadingComment, 0);
3755 }
3757 return false;
3758 }
3760 }
3761 byte b = localBuffer[0];
3762 if (b != 47 && b != 42)
3763 {
3764 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.InvalidCharacterAtStartOfComment, b);
3765 }
3766 bool flag = b == 42;
3767 _consumed++;
3769 localBuffer = localBuffer.Slice(1);
3770 if (localBuffer.Length == 0)
3771 {
3772 if (IsLastSpan)
3773 {
3775 if (flag)
3776 {
3777 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.UnexpectedEndOfDataWhileReadingComment, 0);
3778 }
3779 return true;
3780 }
3781 if (!GetNextSpan())
3782 {
3784 if (IsLastSpan)
3785 {
3786 if (flag)
3787 {
3788 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.UnexpectedEndOfDataWhileReadingComment, 0);
3789 }
3790 return true;
3791 }
3792 return false;
3793 }
3795 }
3796 if (flag)
3797 {
3800 }
3802 }
3803
3805 {
3806 bool flag = false;
3808 tailBytesToSkip = 0;
3809 while (true)
3810 {
3811 if (flag)
3812 {
3813 if (localBuffer[0] == 10)
3814 {
3816 _consumed++;
3817 }
3818 break;
3819 }
3821 if (num != -1)
3822 {
3824 _consumed += num + 1;
3825 _bytePositionInLine += num + 1;
3826 if (localBuffer[num] == 10)
3827 {
3828 break;
3829 }
3830 if (num < localBuffer.Length - 1)
3831 {
3832 if (localBuffer[num + 1] == 10)
3833 {
3835 _consumed++;
3837 }
3838 break;
3839 }
3840 flag = true;
3841 }
3842 else
3843 {
3844 _consumed += localBuffer.Length;
3846 }
3847 if (IsLastSpan)
3848 {
3849 if (flag)
3850 {
3851 break;
3852 }
3853 return true;
3854 }
3855 if (!GetNextSpan())
3856 {
3857 if (IsLastSpan)
3858 {
3859 if (flag)
3860 {
3861 break;
3862 }
3863 return true;
3864 }
3865 return false;
3866 }
3868 }
3870 _lineNumber++;
3871 return true;
3872 }
3873
3875 {
3877 {
3880 {
3881 return -1;
3882 }
3883 }
3884 int num = 0;
3885 do
3886 {
3887 int num2 = localBuffer.IndexOfAny<byte>(10, 13, 226);
3889 if (num2 == -1)
3890 {
3891 return -1;
3892 }
3893 if (localBuffer[num2] != 226)
3894 {
3895 return num + num2;
3896 }
3897 int num3 = num2 + 1;
3898 localBuffer = localBuffer.Slice(num3);
3899 num += num3;
3902 }
3904 return -1;
3905 }
3906
3908 {
3909 if (localBuffer.IsEmpty)
3910 {
3911 return;
3912 }
3914 {
3915 if (localBuffer[0] != 128)
3916 {
3918 return;
3919 }
3920 localBuffer = localBuffer.Slice(1);
3922 if (localBuffer.IsEmpty)
3923 {
3924 return;
3925 }
3926 }
3928 {
3929 byte b = localBuffer[0];
3930 if (b == 168 || b == 169)
3931 {
3932 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.UnexpectedEndOfLineSeparator, 0);
3933 }
3934 else
3935 {
3937 }
3938 }
3939 }
3940
3942 {
3943 bool flag = false;
3944 bool flag2 = false;
3945 while (true)
3946 {
3947 if (flag)
3948 {
3949 if (localBuffer[0] == 47)
3950 {
3951 _consumed++;
3953 return true;
3954 }
3955 flag = false;
3956 }
3957 if (flag2)
3958 {
3959 if (localBuffer[0] == 10)
3960 {
3961 _consumed++;
3962 localBuffer = localBuffer.Slice(1);
3963 }
3964 flag2 = false;
3965 }
3966 int num = localBuffer.IndexOfAny<byte>(42, 10, 13);
3967 if (num != -1)
3968 {
3969 int num2 = num + 1;
3970 byte b = localBuffer[num];
3971 localBuffer = localBuffer.Slice(num2);
3972 _consumed += num2;
3973 switch (b)
3974 {
3975 case 42:
3976 flag = true;
3978 break;
3979 case 10:
3981 _lineNumber++;
3982 break;
3983 default:
3985 _lineNumber++;
3986 flag2 = true;
3987 break;
3988 }
3989 }
3990 else
3991 {
3992 _consumed += localBuffer.Length;
3995 }
3996 if (!localBuffer.IsEmpty)
3997 {
3998 continue;
3999 }
4000 if (IsLastSpan)
4001 {
4002 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.UnexpectedEndOfDataWhileReadingComment, 0);
4003 }
4004 if (!GetNextSpan())
4005 {
4006 if (!IsLastSpan)
4007 {
4008 break;
4009 }
4010 ThrowHelper.ThrowJsonReaderException(ref this, ExceptionResource.UnexpectedEndOfDataWhileReadingComment, 0);
4011 }
4013 }
4014 return false;
4015 }
4016
4021
4022 public string? GetString()
4023 {
4024 if (TokenType == JsonTokenType.Null)
4025 {
4026 return null;
4027 }
4028 if (TokenType != JsonTokenType.String && TokenType != JsonTokenType.PropertyName)
4029 {
4031 }
4033 if (!HasValueSequence)
4034 {
4036 }
4037 else
4038 {
4041 }
4044 {
4045 int idx = readOnlySpan2.IndexOf<byte>(92);
4047 }
4049 }
4050
4070
4071 public bool GetBoolean()
4072 {
4074 if (!HasValueSequence)
4075 {
4077 }
4078 else
4079 {
4082 }
4084 if (TokenType == JsonTokenType.True)
4085 {
4086 return true;
4087 }
4088 if (TokenType == JsonTokenType.False)
4089 {
4090 return false;
4091 }
4093 }
4094
4095 public byte[] GetBytesFromBase64()
4096 {
4097 if (!TryGetBytesFromBase64(out byte[] value))
4098 {
4099 throw ThrowHelper.GetFormatException(DataType.Base64String);
4100 }
4101 return value;
4102 }
4103
4104 public byte GetByte()
4105 {
4106 if (!TryGetByte(out var value))
4107 {
4109 }
4110 return value;
4111 }
4112
4113 internal byte GetByteWithQuotes()
4114 {
4117 {
4119 }
4120 return value;
4121 }
4122
4123 [CLSCompliant(false)]
4124 public sbyte GetSByte()
4125 {
4126 if (!TryGetSByte(out var value))
4127 {
4129 }
4130 return value;
4131 }
4132
4133 internal sbyte GetSByteWithQuotes()
4134 {
4137 {
4139 }
4140 return value;
4141 }
4142
4143 public short GetInt16()
4144 {
4145 if (!TryGetInt16(out var value))
4146 {
4148 }
4149 return value;
4150 }
4151
4152 internal short GetInt16WithQuotes()
4153 {
4156 {
4158 }
4159 return value;
4160 }
4161
4162 public int GetInt32()
4163 {
4164 if (!TryGetInt32(out var value))
4165 {
4167 }
4168 return value;
4169 }
4170
4171 internal int GetInt32WithQuotes()
4172 {
4175 {
4177 }
4178 return value;
4179 }
4180
4181 public long GetInt64()
4182 {
4183 if (!TryGetInt64(out var value))
4184 {
4186 }
4187 return value;
4188 }
4189
4190 internal long GetInt64WithQuotes()
4191 {
4194 {
4196 }
4197 return value;
4198 }
4199
4200 [CLSCompliant(false)]
4201 public ushort GetUInt16()
4202 {
4203 if (!TryGetUInt16(out var value))
4204 {
4206 }
4207 return value;
4208 }
4209
4210 internal ushort GetUInt16WithQuotes()
4211 {
4214 {
4216 }
4217 return value;
4218 }
4219
4220 [CLSCompliant(false)]
4221 public uint GetUInt32()
4222 {
4223 if (!TryGetUInt32(out var value))
4224 {
4226 }
4227 return value;
4228 }
4229
4230 internal uint GetUInt32WithQuotes()
4231 {
4234 {
4236 }
4237 return value;
4238 }
4239
4240 [CLSCompliant(false)]
4241 public ulong GetUInt64()
4242 {
4243 if (!TryGetUInt64(out var value))
4244 {
4246 }
4247 return value;
4248 }
4249
4250 internal ulong GetUInt64WithQuotes()
4251 {
4254 {
4256 }
4257 return value;
4258 }
4259
4260 public float GetSingle()
4261 {
4262 if (!TryGetSingle(out var value))
4263 {
4265 }
4266 return value;
4267 }
4268
4269 internal float GetSingleWithQuotes()
4270 {
4273 {
4274 return value;
4275 }
4277 {
4278 return value;
4279 }
4281 }
4282
4292
4293 public double GetDouble()
4294 {
4295 if (!TryGetDouble(out var value))
4296 {
4298 }
4299 return value;
4300 }
4301
4302 internal double GetDoubleWithQuotes()
4303 {
4306 {
4307 return value;
4308 }
4310 {
4311 return value;
4312 }
4314 }
4315
4325
4326 public decimal GetDecimal()
4327 {
4328 if (!TryGetDecimal(out var value))
4329 {
4331 }
4332 return value;
4333 }
4334
4335 internal decimal GetDecimalWithQuotes()
4336 {
4339 {
4341 }
4342 return value;
4343 }
4344
4346 {
4348 {
4349 throw ThrowHelper.GetFormatException(DataType.DateTime);
4350 }
4351 return value;
4352 }
4353
4355 {
4357 {
4358 throw ThrowHelper.GetFormatException(DataType.DateTime);
4359 }
4360 return value;
4361 }
4362
4364 {
4366 {
4367 throw ThrowHelper.GetFormatException(DataType.DateTimeOffset);
4368 }
4369 return value;
4370 }
4371
4373 {
4375 {
4376 throw ThrowHelper.GetFormatException(DataType.DateTimeOffset);
4377 }
4378 return value;
4379 }
4380
4381 public Guid GetGuid()
4382 {
4383 if (!TryGetGuid(out var value))
4384 {
4386 }
4387 return value;
4388 }
4389
4391 {
4393 {
4395 }
4396 return value;
4397 }
4398
4423
4424 public bool TryGetByte(out byte value)
4425 {
4426 if (TokenType != JsonTokenType.Number)
4427 {
4429 }
4431 if (!HasValueSequence)
4432 {
4434 }
4435 else
4436 {
4439 }
4441 return TryGetByteCore(out value, span);
4442 }
4443
4444 [MethodImpl(MethodImplOptions.AggressiveInlining)]
4446 {
4447 if (Utf8Parser.TryParse(span, out byte value2, out int bytesConsumed, '\0') && span.Length == bytesConsumed)
4448 {
4449 value = value2;
4450 return true;
4451 }
4452 value = 0;
4453 return false;
4454 }
4455
4456 [CLSCompliant(false)]
4457 public bool TryGetSByte(out sbyte value)
4458 {
4459 if (TokenType != JsonTokenType.Number)
4460 {
4462 }
4464 if (!HasValueSequence)
4465 {
4467 }
4468 else
4469 {
4472 }
4474 return TryGetSByteCore(out value, span);
4475 }
4476
4477 [MethodImpl(MethodImplOptions.AggressiveInlining)]
4479 {
4480 if (Utf8Parser.TryParse(span, out sbyte value2, out int bytesConsumed, '\0') && span.Length == bytesConsumed)
4481 {
4482 value = value2;
4483 return true;
4484 }
4485 value = 0;
4486 return false;
4487 }
4488
4489 public bool TryGetInt16(out short value)
4490 {
4491 if (TokenType != JsonTokenType.Number)
4492 {
4494 }
4496 if (!HasValueSequence)
4497 {
4499 }
4500 else
4501 {
4504 }
4506 return TryGetInt16Core(out value, span);
4507 }
4508
4509 [MethodImpl(MethodImplOptions.AggressiveInlining)]
4511 {
4512 if (Utf8Parser.TryParse(span, out short value2, out int bytesConsumed, '\0') && span.Length == bytesConsumed)
4513 {
4514 value = value2;
4515 return true;
4516 }
4517 value = 0;
4518 return false;
4519 }
4520
4521 public bool TryGetInt32(out int value)
4522 {
4523 if (TokenType != JsonTokenType.Number)
4524 {
4526 }
4528 if (!HasValueSequence)
4529 {
4531 }
4532 else
4533 {
4536 }
4538 return TryGetInt32Core(out value, span);
4539 }
4540
4541 [MethodImpl(MethodImplOptions.AggressiveInlining)]
4543 {
4544 if (Utf8Parser.TryParse(span, out int value2, out int bytesConsumed, '\0') && span.Length == bytesConsumed)
4545 {
4546 value = value2;
4547 return true;
4548 }
4549 value = 0;
4550 return false;
4551 }
4552
4553 public bool TryGetInt64(out long value)
4554 {
4555 if (TokenType != JsonTokenType.Number)
4556 {
4558 }
4560 if (!HasValueSequence)
4561 {
4563 }
4564 else
4565 {
4568 }
4570 return TryGetInt64Core(out value, span);
4571 }
4572
4573 [MethodImpl(MethodImplOptions.AggressiveInlining)]
4575 {
4576 if (Utf8Parser.TryParse(span, out long value2, out int bytesConsumed, '\0') && span.Length == bytesConsumed)
4577 {
4578 value = value2;
4579 return true;
4580 }
4581 value = 0L;
4582 return false;
4583 }
4584
4585 [CLSCompliant(false)]
4586 public bool TryGetUInt16(out ushort value)
4587 {
4588 if (TokenType != JsonTokenType.Number)
4589 {
4591 }
4593 if (!HasValueSequence)
4594 {
4596 }
4597 else
4598 {
4601 }
4603 return TryGetUInt16Core(out value, span);
4604 }
4605
4606 [MethodImpl(MethodImplOptions.AggressiveInlining)]
4608 {
4609 if (Utf8Parser.TryParse(span, out ushort value2, out int bytesConsumed, '\0') && span.Length == bytesConsumed)
4610 {
4611 value = value2;
4612 return true;
4613 }
4614 value = 0;
4615 return false;
4616 }
4617
4618 [CLSCompliant(false)]
4619 public bool TryGetUInt32(out uint value)
4620 {
4621 if (TokenType != JsonTokenType.Number)
4622 {
4624 }
4626 if (!HasValueSequence)
4627 {
4629 }
4630 else
4631 {
4634 }
4636 return TryGetUInt32Core(out value, span);
4637 }
4638
4639 [MethodImpl(MethodImplOptions.AggressiveInlining)]
4641 {
4642 if (Utf8Parser.TryParse(span, out uint value2, out int bytesConsumed, '\0') && span.Length == bytesConsumed)
4643 {
4644 value = value2;
4645 return true;
4646 }
4647 value = 0u;
4648 return false;
4649 }
4650
4651 [CLSCompliant(false)]
4652 public bool TryGetUInt64(out ulong value)
4653 {
4654 if (TokenType != JsonTokenType.Number)
4655 {
4657 }
4659 if (!HasValueSequence)
4660 {
4662 }
4663 else
4664 {
4667 }
4669 return TryGetUInt64Core(out value, span);
4670 }
4671
4672 [MethodImpl(MethodImplOptions.AggressiveInlining)]
4674 {
4675 if (Utf8Parser.TryParse(span, out ulong value2, out int bytesConsumed, '\0') && span.Length == bytesConsumed)
4676 {
4677 value = value2;
4678 return true;
4679 }
4680 value = 0uL;
4681 return false;
4682 }
4683
4684 public bool TryGetSingle(out float value)
4685 {
4686 if (TokenType != JsonTokenType.Number)
4687 {
4689 }
4691 if (!HasValueSequence)
4692 {
4694 }
4695 else
4696 {
4699 }
4701 if (Utf8Parser.TryParse(source, out float value2, out int bytesConsumed, '\0') && source.Length == bytesConsumed)
4702 {
4703 value = value2;
4704 return true;
4705 }
4706 value = 0f;
4707 return false;
4708 }
4709
4710 public bool TryGetDouble(out double value)
4711 {
4712 if (TokenType != JsonTokenType.Number)
4713 {
4715 }
4717 if (!HasValueSequence)
4718 {
4720 }
4721 else
4722 {
4725 }
4727 if (Utf8Parser.TryParse(source, out double value2, out int bytesConsumed, '\0') && source.Length == bytesConsumed)
4728 {
4729 value = value2;
4730 return true;
4731 }
4732 value = 0.0;
4733 return false;
4734 }
4735
4736 public bool TryGetDecimal(out decimal value)
4737 {
4738 if (TokenType != JsonTokenType.Number)
4739 {
4741 }
4743 if (!HasValueSequence)
4744 {
4746 }
4747 else
4748 {
4751 }
4754 }
4755
4756 [MethodImpl(MethodImplOptions.AggressiveInlining)]
4758 {
4759 if (Utf8Parser.TryParse(span, out decimal value2, out int bytesConsumed, '\0') && span.Length == bytesConsumed)
4760 {
4761 value = value2;
4762 return true;
4763 }
4764 value = default(decimal);
4765 return false;
4766 }
4767
4769 {
4770 if (TokenType != JsonTokenType.String)
4771 {
4773 }
4775 }
4776
4778 {
4780 int num = (_stringHasEscaping ? 252 : 42);
4781 if (HasValueSequence)
4782 {
4784 if (!JsonHelpers.IsInRangeInclusive(length, 10L, num))
4785 {
4786 value = default(DateTime);
4787 return false;
4788 }
4791 source.CopyTo(destination);
4793 }
4794 else
4795 {
4797 {
4798 value = default(DateTime);
4799 return false;
4800 }
4802 }
4804 {
4806 }
4808 {
4809 value = value2;
4810 return true;
4811 }
4812 value = default(DateTime);
4813 return false;
4814 }
4815
4824
4826 {
4828 int num = (_stringHasEscaping ? 252 : 42);
4829 if (HasValueSequence)
4830 {
4832 if (!JsonHelpers.IsInRangeInclusive(length, 10L, num))
4833 {
4834 value = default(DateTimeOffset);
4835 return false;
4836 }
4839 source.CopyTo(destination);
4841 }
4842 else
4843 {
4845 {
4846 value = default(DateTimeOffset);
4847 return false;
4848 }
4850 }
4852 {
4854 }
4856 {
4857 value = value2;
4858 return true;
4859 }
4860 value = default(DateTimeOffset);
4861 return false;
4862 }
4863
4865 {
4866 if (TokenType != JsonTokenType.String)
4867 {
4869 }
4870 return TryGetGuidCore(out value);
4871 }
4872
4874 {
4876 int num = (_stringHasEscaping ? 216 : 36);
4877 if (HasValueSequence)
4878 {
4880 if (length > num)
4881 {
4882 value = default(Guid);
4883 return false;
4884 }
4887 source.CopyTo(destination);
4889 }
4890 else
4891 {
4892 if (ValueSpan.Length > num)
4893 {
4894 value = default(Guid);
4895 return false;
4896 }
4898 }
4900 {
4902 }
4903 if (readOnlySpan.Length == 36 && Utf8Parser.TryParse(readOnlySpan, out Guid value2, out int _, 'D'))
4904 {
4905 value = value2;
4906 return true;
4907 }
4908 value = default(Guid);
4909 return false;
4910 }
4911}
static ArrayPool< T > Shared
Definition ArrayPool.cs:7
static bool TryParse(ReadOnlySpan< byte > source, out bool value, out int bytesConsumed, char standardFormat='\0')
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static ReadOnlySpan< byte > NullValue
static ReadOnlySpan< byte > TrueValue
static ReadOnlySpan< byte > FalseValue
static ReadOnlySpan< byte > Delimiters
static ReadOnlySpan< byte > EscapableChars
static bool IsFinite(double value)
static bool IsInRangeInclusive(uint value, uint lowerBound, uint upperBound)
static bool IsDigit(byte value)
static bool TryParseAsISO(ReadOnlySpan< byte > source, out DateTime value)
static bool TryGetEscapedDateTime(ReadOnlySpan< byte > source, out DateTime value)
static string TranscodeHelper(ReadOnlySpan< byte > utf8Unescaped)
static ReadOnlySpan< byte > GetUnescapedSpan(ReadOnlySpan< byte > utf8Source, int idx)
static string GetUnescapedString(ReadOnlySpan< byte > utf8Source, int idx)
static bool TryGetEscapedDateTimeOffset(ReadOnlySpan< byte > source, out DateTimeOffset value)
static bool UnescapeAndCompare(ReadOnlySpan< byte > utf8Source, ReadOnlySpan< byte > other)
static bool TryGetEscapedGuid(ReadOnlySpan< byte > source, out Guid value)
static bool IsHexDigit(byte nextByte)
static bool TryGetFloatingPointConstant(ReadOnlySpan< byte > span, out float value)
static bool TryGetUnescapedBase64Bytes(ReadOnlySpan< byte > utf8Source, int idx, [NotNullWhen(true)] out byte[] bytes)
static bool IsTokenTypePrimitive(JsonTokenType tokenType)
static bool TryDecodeBase64(ReadOnlySpan< byte > utf8Unescaped, [NotNullWhen(true)] out byte[] bytes)
static int CountNewLines(ReadOnlySpan< byte > data)
static unsafe OperationStatus ToUtf8(ReadOnlySpan< byte > utf16Source, Span< byte > utf8Destination, out int bytesConsumed, out int bytesWritten)
static InvalidOperationException GetInvalidOperationException_ExpectedNumber(JsonTokenType tokenType)
static void ThrowJsonReaderException(ref Utf8JsonReader json, ExceptionResource resource, byte nextByte=0, ReadOnlySpan< byte > bytes=default(ReadOnlySpan< byte >))
static FormatException GetFormatException()
static InvalidOperationException GetInvalidOperationException_ExpectedStringComparison(JsonTokenType tokenType)
static InvalidOperationException GetInvalidOperationException_ExpectedString(JsonTokenType tokenType)
static JsonException GetJsonReaderException(ref Utf8JsonReader json, ExceptionResource resource, byte nextByte, ReadOnlySpan< byte > bytes)
static InvalidOperationException GetInvalidOperationException_ExpectedComment(JsonTokenType tokenType)
static InvalidOperationException GetInvalidOperationException_ExpectedBoolean(JsonTokenType tokenType)
static InvalidOperationException GetInvalidOperationException_CannotSkipOnPartial()
TokenType
Definition TokenType.cs:4
SequencePosition GetPosition(long offset)
ReadOnlySequence< T > Slice(long start, long length)
static readonly ReadOnlySequence< T > Empty
bool TryGet(ref SequencePosition position, out ReadOnlyMemory< T > memory, bool advance=true)
static ReadOnlySpan< T > Empty
ReadOnlySpan< T > Slice(int start)
PartialStateForRollback(long totalConsumed, long bytePositionInLine, int consumed, SequencePosition currentPosition)
ConsumeNumberResult ConsumeDecimalDigitsMultiSegment(ref ReadOnlySpan< byte > data, ref int i, in PartialStateForRollback rollBackState)
PartialStateForRollback CaptureState()
bool ReadFirstTokenMultiSegment(byte first)
ConsumeTokenResult ConsumeNextTokenMultiSegment(byte marker)
void ThrowOnDangerousLineSeparator(ReadOnlySpan< byte > localBuffer)
ReadOnlySequence< byte > OriginalSequence
bool TryGetSByte(out sbyte value)
bool ConsumeStringAndValidateMultiSegment(ReadOnlySpan< byte > data, int idx)
bool TryGetBytesFromBase64([NotNullWhen(true)] out byte[]? value)
bool UnescapeAndCompare(ReadOnlySpan< byte > other)
bool TryGetUInt32(out uint value)
bool SkipCommentMultiSegment(out int tailBytesToIgnore)
bool TryGetDateTimeOffsetCore(out DateTimeOffset value)
bool ValueTextEquals(ReadOnlySpan< byte > utf8Text)
bool UnescapeSequenceAndCompare(ReadOnlySpan< byte > other)
bool ConsumeValueMultiSegment(byte marker)
ConsumeTokenResult ConsumeNextTokenUntilAfterAllCommentsAreSkippedMultiSegment(byte marker)
bool TryGetUInt32Core(out uint value, ReadOnlySpan< byte > span)
ConsumeNumberResult ConsumeNegativeSignMultiSegment(ref ReadOnlySpan< byte > data, ref int i, in PartialStateForRollback rollBackState)
JsonException GetInvalidLiteralMultiSegment(ReadOnlySpan< byte > span)
bool ConsumeSingleLineComment(ReadOnlySpan< byte > localBuffer, int previousConsumed)
bool ConsumeLiteral(ReadOnlySpan< byte > literal, JsonTokenType tokenType)
bool TryGetByteCore(out byte value, ReadOnlySpan< byte > span)
ConsumeTokenResult ConsumeNextTokenFromLastNonCommentToken()
bool ConsumeNextTokenOrRollback(byte marker)
bool SkipAllComments(ref byte marker, ExceptionResource resource)
bool TryGetUInt64(out ulong value)
bool TryGetDecimal(out decimal value)
ConsumeNumberResult ConsumeSign(ref ReadOnlySpan< byte > data, ref int i)
bool CheckLiteralMultiSegment(ReadOnlySpan< byte > span, ReadOnlySpan< byte > literal, out int consumed)
ConsumeNumberResult ConsumeNegativeSign(ref ReadOnlySpan< byte > data, ref int i)
bool TryGetInt16Core(out short value, ReadOnlySpan< byte > span)
ConsumeNumberResult ConsumeZero(ref ReadOnlySpan< byte > data, ref int i)
ConsumeNumberResult ConsumeIntegerDigits(ref ReadOnlySpan< byte > data, ref int i)
void ThrowOnDangerousLineSeparatorMultiSegment(ReadOnlySpan< byte > localBuffer, ref int dangerousLineSeparatorBytesConsumed)
bool ConsumeStringAndValidate(ReadOnlySpan< byte > data, int idx)
ConsumeNumberResult ConsumeDecimalDigits(ref ReadOnlySpan< byte > data, ref int i)
bool MatchNotPossible(int charTextLength)
ConsumeNumberResult ConsumeZeroMultiSegment(ref ReadOnlySpan< byte > data, ref int i, in PartialStateForRollback rollBackState)
unsafe bool ValueTextEquals(ReadOnlySpan< char > text)
Utf8JsonReader(ReadOnlySequence< byte > jsonData, JsonReaderOptions options=default(JsonReaderOptions))
bool TryGetInt64Core(out long value, ReadOnlySpan< byte > span)
bool TryGetUInt64Core(out ulong value, ReadOnlySpan< byte > span)
bool ConsumeMultiLineComment(ReadOnlySpan< byte > localBuffer, int previousConsumed)
bool SkipAllCommentsMultiSegment(ref byte marker, ExceptionResource resource)
bool SkipSingleLineCommentMultiSegment(ReadOnlySpan< byte > localBuffer, out int tailBytesToSkip)
bool MatchNotPossibleSequence(int charTextLength)
ReadOnlySpan< byte > OriginalSpan
bool TryGetDateTimeCore(out DateTime value)
bool SkipAllCommentsMultiSegment(ref byte marker)
int FindLineSeparatorMultiSegment(ReadOnlySpan< byte > localBuffer, ref int dangerousLineSeparatorBytesConsumed)
bool TryGetDecimalCore(out decimal value, ReadOnlySpan< byte > span)
bool TryGetDateTimeOffset(out DateTimeOffset value)
bool TryGetUInt16(out ushort value)
bool TryGetUInt16Core(out ushort value, ReadOnlySpan< byte > span)
ReadOnlySpan< byte > GetUnescapedSpan()
bool SkipAllComments(ref byte marker)
bool CompareToSequence(ReadOnlySpan< byte > other)
bool CheckLiteral(ReadOnlySpan< byte > span, ReadOnlySpan< byte > literal)
bool TryGetNumber(ReadOnlySpan< byte > data, out int consumed)
bool TryGetInt32Core(out int value, ReadOnlySpan< byte > span)
bool TryGetNumberMultiSegment(ReadOnlySpan< byte > data, out int consumed)
Utf8JsonReader(ReadOnlySpan< byte > jsonData, bool isFinalBlock, JsonReaderState state)
DateTimeOffset GetDateTimeOffsetNoValidation()
Utf8JsonReader(ReadOnlySequence< byte > jsonData, bool isFinalBlock, JsonReaderState state)
int FindLineSeparator(ReadOnlySpan< byte > localBuffer)
bool HasMoreData(ExceptionResource resource)
void ThrowInvalidLiteral(ReadOnlySpan< byte > span)
bool TryGetDateTime(out DateTime value)
bool ConsumeLiteralMultiSegment(ReadOnlySpan< byte > literal, JsonTokenType tokenType)
readonly ReadOnlySequence< byte > _sequence
ConsumeTokenResult ConsumeNextTokenUntilAfterAllCommentsAreSkipped(byte marker)
ConsumeTokenResult ConsumeNextToken(byte marker)
ConsumeNumberResult ConsumeIntegerDigitsMultiSegment(ref ReadOnlySpan< byte > data, ref int i)
bool ValidateHexDigits(ReadOnlySpan< byte > data, int idx)
bool TryGetDouble(out double value)
void RollBackState(in PartialStateForRollback state, bool isError=false)
int FindMismatch(ReadOnlySpan< byte > span, ReadOnlySpan< byte > literal)
static bool IsTokenTypeString(JsonTokenType tokenType)
bool TextEqualsHelper(ReadOnlySpan< byte > otherUtf8Text)
ConsumeTokenResult ConsumeNextTokenFromLastNonCommentTokenMultiSegment()
bool HasMoreDataMultiSegment(ExceptionResource resource)
bool TryGetGuidCore(out Guid value)
bool SkipSingleLineComment(ReadOnlySpan< byte > localBuffer, out int idx)
ReadOnlySequence< byte > ValueSequence
ConsumeNumberResult ConsumeSignMultiSegment(ref ReadOnlySpan< byte > data, ref int i, in PartialStateForRollback rollBackState)
bool ConsumeNextTokenOrRollbackMultiSegment(byte marker)
bool SkipMultiLineCommentMultiSegment(ReadOnlySpan< byte > localBuffer)
bool TryGetSByteCore(out sbyte value, ReadOnlySpan< byte > span)
bool TryGetInt16(out short value)
Utf8JsonReader(ReadOnlySpan< byte > jsonData, JsonReaderOptions options=default(JsonReaderOptions))
bool TryGetSingle(out float value)
bool SkipMultiLineComment(ReadOnlySpan< byte > localBuffer, out int idx)