Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
JsonDocument.cs
Go to the documentation of this file.
4using System.IO;
8
9namespace System.Text.Json;
10
11public sealed class JsonDocument : IDisposable
12{
13 internal readonly struct DbRow
14 {
15 private readonly int _location;
16
17 private readonly int _sizeOrLengthUnion;
18
19 private readonly int _numberOfRowsAndTypeUnion;
20
21 internal int Location => _location;
22
23 internal int SizeOrLength => _sizeOrLengthUnion & 0x7FFFFFFF;
24
25 internal bool IsUnknownSize => _sizeOrLengthUnion == -1;
26
28
29 internal int NumberOfRows => _numberOfRowsAndTypeUnion & 0xFFFFFFF;
30
32
33 internal bool IsSimpleValue => (int)TokenType >= 5;
34
41 }
42
43 private struct MetadataDb : IDisposable
44 {
45 private byte[] _data;
46
47 private bool _convertToAlloc;
48
49 private bool _isLocked;
50
51 internal int Length { get; private set; }
52
53 private MetadataDb(byte[] initialDb, bool isLocked, bool convertToAlloc)
54 {
58 Length = 0;
59 }
60
61 internal MetadataDb(byte[] completeDb)
62 {
64 _isLocked = true;
65 _convertToAlloc = false;
66 Length = completeDb.Length;
67 }
68
70 {
71 int num = payloadLength + 12;
72 if (num > 1048576 && num <= 4194304)
73 {
74 num = 1048576;
75 }
76 byte[] initialDb = ArrayPool<byte>.Shared.Rent(num);
77 return new MetadataDb(initialDb, isLocked: false, convertToAlloc);
78 }
79
81 {
82 int num = payloadLength + 12;
83 byte[] initialDb = new byte[num];
84 return new MetadataDb(initialDb, isLocked: true, convertToAlloc: false);
85 }
86
87 public void Dispose()
88 {
89 byte[] array = Interlocked.Exchange(ref _data, null);
90 if (array != null)
91 {
93 Length = 0;
94 }
95 }
96
97 internal void CompleteAllocations()
98 {
99 if (_isLocked)
100 {
101 return;
102 }
103 if (_convertToAlloc)
104 {
105 byte[] data = _data;
106 _data = _data.AsSpan(0, Length).ToArray();
107 _isLocked = true;
108 _convertToAlloc = false;
109 ArrayPool<byte>.Shared.Return(data);
110 }
111 else if (Length <= _data.Length / 2)
112 {
113 byte[] array = ArrayPool<byte>.Shared.Rent(Length);
114 byte[] array2 = array;
115 if (array.Length < _data.Length)
116 {
118 array2 = _data;
119 _data = array;
120 }
122 }
123 }
124
125 internal void Append(JsonTokenType tokenType, int startLocation, int length)
126 {
127 if (Length >= _data.Length - 12)
128 {
129 Enlarge();
130 }
131 DbRow value = new DbRow(tokenType, startLocation, length);
132 MemoryMarshal.Write(_data.AsSpan(Length), ref value);
133 Length += 12;
134 }
135
136 private void Enlarge()
137 {
138 byte[] data = _data;
139 _data = ArrayPool<byte>.Shared.Rent(data.Length * 2);
140 Buffer.BlockCopy(data, 0, _data, 0, data.Length);
141 ArrayPool<byte>.Shared.Return(data);
142 }
143
144 internal void SetLength(int index, int length)
145 {
146 Span<byte> destination = _data.AsSpan(index + 4);
148 }
149
150 internal void SetNumberOfRows(int index, int numberOfRows)
151 {
152 Span<byte> span = _data.AsSpan(index + 8);
153 int num = MemoryMarshal.Read<int>(span);
154 int value = (num & -268435456) | numberOfRows;
155 MemoryMarshal.Write(span, ref value);
156 }
157
158 internal void SetHasComplexChildren(int index)
159 {
160 Span<byte> span = _data.AsSpan(index + 4);
161 int num = MemoryMarshal.Read<int>(span);
162 int value = num | int.MinValue;
163 MemoryMarshal.Write(span, ref value);
164 }
165
170
172 {
173 Span<byte> span = _data.AsSpan(0, Length);
174 for (int num = Length - 12; num >= 0; num -= 12)
175 {
176 DbRow dbRow = MemoryMarshal.Read<DbRow>(span.Slice(num));
177 if (dbRow.IsUnknownSize && dbRow.TokenType == lookupType)
178 {
179 return num;
180 }
181 }
182 return -1;
183 }
184
185 internal DbRow Get(int index)
186 {
187 return MemoryMarshal.Read<DbRow>(_data.AsSpan(index));
188 }
189
191 {
192 uint num = MemoryMarshal.Read<uint>(_data.AsSpan(index + 8));
193 return (JsonTokenType)(num >> 28);
194 }
195
197 {
199 int num = endIndex - startIndex;
200 byte[] array = new byte[num];
201 _data.AsSpan(startIndex, num).CopyTo(array);
202 Span<int> span = MemoryMarshal.Cast<byte, int>(array);
203 int num2 = span[0];
204 if (dbRow.TokenType == JsonTokenType.String)
205 {
206 num2--;
207 }
208 for (int num3 = (num - 12) / 4; num3 >= 0; num3 -= 3)
209 {
210 span[num3] -= num2;
211 }
212 return new MetadataDb(array);
213 }
214 }
215
216 private struct StackRow
217 {
218 internal int SizeOrLength;
219
220 internal int NumberOfRows;
221
222 internal StackRow(int sizeOrLength = 0, int numberOfRows = -1)
223 {
226 }
227 }
228
229 private struct StackRowStack : IDisposable
230 {
231 private byte[] _rentedBuffer;
232
233 private int _topOfStack;
234
240
241 public void Dispose()
242 {
244 _rentedBuffer = null;
245 _topOfStack = 0;
246 if (rentedBuffer != null)
247 {
249 }
250 }
251
252 internal void Push(StackRow row)
253 {
254 if (_topOfStack < 8)
255 {
256 Enlarge();
257 }
258 _topOfStack -= 8;
260 }
261
262 internal StackRow Pop()
263 {
265 _topOfStack += 8;
266 return result;
267 }
268
277 }
278
280
282
284
286
288
290
291 private (int, string) _lastIndexAndString = (-1, null);
292
294
296
298
299 internal bool IsDisposable { get; }
300
301 public JsonElement RootElement => new JsonElement(this, 0);
302
319
320 public void Dispose()
321 {
322 int length = _utf8Json.Length;
323 if (length == 0 || !IsDisposable)
324 {
325 return;
326 }
330 {
332 if (array != null)
333 {
334 array.AsSpan(0, length).Clear();
336 }
337 }
339 {
341 }
342 }
343
345 {
346 if (writer == null)
347 {
348 throw new ArgumentNullException("writer");
349 }
351 }
352
358
359 internal int GetArrayLength(int index)
360 {
363 CheckExpectedType(JsonTokenType.StartArray, dbRow.TokenType);
364 return dbRow.SizeOrLength;
365 }
366
367 internal JsonElement GetArrayIndexElement(int currentIndex, int arrayIndex)
368 {
370 DbRow dbRow = _parsedData.Get(currentIndex);
371 CheckExpectedType(JsonTokenType.StartArray, dbRow.TokenType);
372 int sizeOrLength = dbRow.SizeOrLength;
373 if ((uint)arrayIndex >= (uint)sizeOrLength)
374 {
375 throw new IndexOutOfRangeException();
376 }
377 if (!dbRow.HasComplexChildren)
378 {
379 return new JsonElement(this, currentIndex + (arrayIndex + 1) * 12);
380 }
381 int num = 0;
382 for (int i = currentIndex + 12; i < _parsedData.Length; i += 12)
383 {
384 if (arrayIndex == num)
385 {
386 return new JsonElement(this, i);
387 }
388 dbRow = _parsedData.Get(i);
389 if (!dbRow.IsSimpleValue)
390 {
391 i += 12 * dbRow.NumberOfRows;
392 }
393 num++;
394 }
395 throw new IndexOutOfRangeException();
396 }
397
398 internal int GetEndIndex(int index, bool includeEndElement)
399 {
402 if (dbRow.IsSimpleValue)
403 {
404 return index + 12;
405 }
406 int num = index + 12 * dbRow.NumberOfRows;
408 {
409 num += 12;
410 }
411 return num;
412 }
413
415 {
416 return GetRawValue(0, includeQuotes: true);
417 }
418
420 {
423 if (dbRow.IsSimpleValue)
424 {
425 if (includeQuotes && dbRow.TokenType == JsonTokenType.String)
426 {
427 return _utf8Json.Slice(dbRow.Location - 1, dbRow.SizeOrLength + 2);
428 }
429 return _utf8Json.Slice(dbRow.Location, dbRow.SizeOrLength);
430 }
432 int location = dbRow.Location;
434 return _utf8Json.Slice(location, dbRow.Location - location + dbRow.SizeOrLength);
435 }
436
438 {
440 int num = _parsedData.Get(valueIndex - 12).Location - 1;
442 int num2;
443 if (dbRow.IsSimpleValue)
444 {
446 if (dbRow.TokenType == JsonTokenType.String)
447 {
448 num2++;
449 }
450 return _utf8Json.Slice(num, num2 - num);
451 }
455 return _utf8Json.Slice(num, num2 - num);
456 }
457
459 {
461 int num;
462 string result;
463 (num, result) = _lastIndexAndString;
464 if (num == index)
465 {
466 return result;
467 }
469 JsonTokenType tokenType = dbRow.TokenType;
470 if (tokenType == JsonTokenType.Null)
471 {
472 return null;
473 }
475 ReadOnlySpan<byte> readOnlySpan = _utf8Json.Span.Slice(dbRow.Location, dbRow.SizeOrLength);
476 if (dbRow.HasComplexChildren)
477 {
478 int idx = readOnlySpan.IndexOf<byte>(92);
480 }
481 else
482 {
484 }
485 _lastIndexAndString = (index, result);
486 return result;
487 }
488
490 {
492 int num = (isPropertyName ? (index - 12) : index);
494 if (num2 == num)
495 {
496 return otherText.SequenceEqual(text.AsSpan());
497 }
498 byte[] array = null;
499 int num3 = checked(otherText.Length * 3);
500 Span<byte> span = ((num3 > 256) ? ((Span<byte>)(array = ArrayPool<byte>.Shared.Rent(num3))) : stackalloc byte[256]);
503 int bytesConsumed;
504 int bytesWritten;
507 if (array != null)
508 {
509 utf8Destination.Slice(0, bytesWritten).Clear();
511 }
512 return result;
513 }
514
516 {
518 int index2 = (isPropertyName ? (index - 12) : index);
520 CheckExpectedType(isPropertyName ? JsonTokenType.PropertyName : JsonTokenType.String, dbRow.TokenType);
521 ReadOnlySpan<byte> span = _utf8Json.Span.Slice(dbRow.Location, dbRow.SizeOrLength);
522 if (otherUtf8Text.Length > span.Length || (!shouldUnescape && otherUtf8Text.Length != span.Length))
523 {
524 return false;
525 }
526 if (dbRow.HasComplexChildren && shouldUnescape)
527 {
528 if (otherUtf8Text.Length < span.Length / 6)
529 {
530 return false;
531 }
532 int num = span.IndexOf<byte>(92);
533 if (!otherUtf8Text.StartsWith(span.Slice(0, num)))
534 {
535 return false;
536 }
537 return JsonReaderHelper.UnescapeAndCompare(span.Slice(num), otherUtf8Text.Slice(num));
538 }
539 return span.SequenceEqual(otherUtf8Text);
540 }
541
542 internal string GetNameOfPropertyValue(int index)
543 {
544 return GetString(index - 12, JsonTokenType.PropertyName);
545 }
546
547 internal bool TryGetValue(int index, [NotNullWhen(true)] out byte[] value)
548 {
551 CheckExpectedType(JsonTokenType.String, dbRow.TokenType);
552 ReadOnlySpan<byte> readOnlySpan = _utf8Json.Span.Slice(dbRow.Location, dbRow.SizeOrLength);
553 if (dbRow.HasComplexChildren)
554 {
555 int idx = readOnlySpan.IndexOf<byte>(92);
557 }
559 }
560
561 internal bool TryGetValue(int index, out sbyte value)
562 {
565 CheckExpectedType(JsonTokenType.Number, dbRow.TokenType);
566 ReadOnlySpan<byte> source = _utf8Json.Span.Slice(dbRow.Location, dbRow.SizeOrLength);
567 if (Utf8Parser.TryParse(source, out sbyte value2, out int bytesConsumed, '\0') && bytesConsumed == source.Length)
568 {
569 value = value2;
570 return true;
571 }
572 value = 0;
573 return false;
574 }
575
576 internal bool TryGetValue(int index, out byte value)
577 {
580 CheckExpectedType(JsonTokenType.Number, dbRow.TokenType);
581 ReadOnlySpan<byte> source = _utf8Json.Span.Slice(dbRow.Location, dbRow.SizeOrLength);
582 if (Utf8Parser.TryParse(source, out byte value2, out int bytesConsumed, '\0') && bytesConsumed == source.Length)
583 {
584 value = value2;
585 return true;
586 }
587 value = 0;
588 return false;
589 }
590
591 internal bool TryGetValue(int index, out short value)
592 {
595 CheckExpectedType(JsonTokenType.Number, dbRow.TokenType);
596 ReadOnlySpan<byte> source = _utf8Json.Span.Slice(dbRow.Location, dbRow.SizeOrLength);
597 if (Utf8Parser.TryParse(source, out short value2, out int bytesConsumed, '\0') && bytesConsumed == source.Length)
598 {
599 value = value2;
600 return true;
601 }
602 value = 0;
603 return false;
604 }
605
606 internal bool TryGetValue(int index, out ushort value)
607 {
610 CheckExpectedType(JsonTokenType.Number, dbRow.TokenType);
611 ReadOnlySpan<byte> source = _utf8Json.Span.Slice(dbRow.Location, dbRow.SizeOrLength);
612 if (Utf8Parser.TryParse(source, out ushort value2, out int bytesConsumed, '\0') && bytesConsumed == source.Length)
613 {
614 value = value2;
615 return true;
616 }
617 value = 0;
618 return false;
619 }
620
621 internal bool TryGetValue(int index, out int value)
622 {
625 CheckExpectedType(JsonTokenType.Number, dbRow.TokenType);
626 ReadOnlySpan<byte> source = _utf8Json.Span.Slice(dbRow.Location, dbRow.SizeOrLength);
627 if (Utf8Parser.TryParse(source, out int value2, out int bytesConsumed, '\0') && bytesConsumed == source.Length)
628 {
629 value = value2;
630 return true;
631 }
632 value = 0;
633 return false;
634 }
635
636 internal bool TryGetValue(int index, out uint value)
637 {
640 CheckExpectedType(JsonTokenType.Number, dbRow.TokenType);
641 ReadOnlySpan<byte> source = _utf8Json.Span.Slice(dbRow.Location, dbRow.SizeOrLength);
642 if (Utf8Parser.TryParse(source, out uint value2, out int bytesConsumed, '\0') && bytesConsumed == source.Length)
643 {
644 value = value2;
645 return true;
646 }
647 value = 0u;
648 return false;
649 }
650
651 internal bool TryGetValue(int index, out long value)
652 {
655 CheckExpectedType(JsonTokenType.Number, dbRow.TokenType);
656 ReadOnlySpan<byte> source = _utf8Json.Span.Slice(dbRow.Location, dbRow.SizeOrLength);
657 if (Utf8Parser.TryParse(source, out long value2, out int bytesConsumed, '\0') && bytesConsumed == source.Length)
658 {
659 value = value2;
660 return true;
661 }
662 value = 0L;
663 return false;
664 }
665
666 internal bool TryGetValue(int index, out ulong value)
667 {
670 CheckExpectedType(JsonTokenType.Number, dbRow.TokenType);
671 ReadOnlySpan<byte> source = _utf8Json.Span.Slice(dbRow.Location, dbRow.SizeOrLength);
672 if (Utf8Parser.TryParse(source, out ulong value2, out int bytesConsumed, '\0') && bytesConsumed == source.Length)
673 {
674 value = value2;
675 return true;
676 }
677 value = 0uL;
678 return false;
679 }
680
681 internal bool TryGetValue(int index, out double value)
682 {
685 CheckExpectedType(JsonTokenType.Number, dbRow.TokenType);
686 ReadOnlySpan<byte> source = _utf8Json.Span.Slice(dbRow.Location, dbRow.SizeOrLength);
687 if (Utf8Parser.TryParse(source, out double value2, out int bytesConsumed, '\0') && source.Length == bytesConsumed)
688 {
689 value = value2;
690 return true;
691 }
692 value = 0.0;
693 return false;
694 }
695
696 internal bool TryGetValue(int index, out float value)
697 {
700 CheckExpectedType(JsonTokenType.Number, dbRow.TokenType);
701 ReadOnlySpan<byte> source = _utf8Json.Span.Slice(dbRow.Location, dbRow.SizeOrLength);
702 if (Utf8Parser.TryParse(source, out float value2, out int bytesConsumed, '\0') && source.Length == bytesConsumed)
703 {
704 value = value2;
705 return true;
706 }
707 value = 0f;
708 return false;
709 }
710
711 internal bool TryGetValue(int index, out decimal value)
712 {
715 CheckExpectedType(JsonTokenType.Number, dbRow.TokenType);
716 ReadOnlySpan<byte> source = _utf8Json.Span.Slice(dbRow.Location, dbRow.SizeOrLength);
717 if (Utf8Parser.TryParse(source, out decimal value2, out int bytesConsumed, '\0') && source.Length == bytesConsumed)
718 {
719 value = value2;
720 return true;
721 }
722 value = default(decimal);
723 return false;
724 }
725
726 internal bool TryGetValue(int index, out DateTime value)
727 {
730 CheckExpectedType(JsonTokenType.String, dbRow.TokenType);
731 ReadOnlySpan<byte> source = _utf8Json.Span.Slice(dbRow.Location, dbRow.SizeOrLength);
733 {
734 value = default(DateTime);
735 return false;
736 }
737 if (dbRow.HasComplexChildren)
738 {
740 }
742 {
743 value = value2;
744 return true;
745 }
746 value = default(DateTime);
747 return false;
748 }
749
751 {
754 CheckExpectedType(JsonTokenType.String, dbRow.TokenType);
755 ReadOnlySpan<byte> source = _utf8Json.Span.Slice(dbRow.Location, dbRow.SizeOrLength);
757 {
758 value = default(DateTimeOffset);
759 return false;
760 }
761 if (dbRow.HasComplexChildren)
762 {
764 }
766 {
767 value = value2;
768 return true;
769 }
770 value = default(DateTimeOffset);
771 return false;
772 }
773
774 internal bool TryGetValue(int index, out Guid value)
775 {
778 CheckExpectedType(JsonTokenType.String, dbRow.TokenType);
779 ReadOnlySpan<byte> source = _utf8Json.Span.Slice(dbRow.Location, dbRow.SizeOrLength);
780 if (source.Length > 216)
781 {
782 value = default(Guid);
783 return false;
784 }
785 if (dbRow.HasComplexChildren)
786 {
788 }
789 if (source.Length == 36 && Utf8Parser.TryParse(source, out Guid value2, out int _, 'D'))
790 {
791 value = value2;
792 return true;
793 }
794 value = default(Guid);
795 return false;
796 }
797
798 internal string GetRawValueAsString(int index)
799 {
801 }
802
807
816
818 {
821 switch (row.TokenType)
822 {
823 case JsonTokenType.StartObject:
824 writer.WriteStartObject();
826 break;
827 case JsonTokenType.StartArray:
828 writer.WriteStartArray();
830 break;
831 case JsonTokenType.String:
833 break;
834 case JsonTokenType.Number:
835 writer.WriteNumberValue(_utf8Json.Slice(row.Location, row.SizeOrLength).Span);
836 break;
837 case JsonTokenType.True:
838 writer.WriteBooleanValue(value: true);
839 break;
840 case JsonTokenType.False:
841 writer.WriteBooleanValue(value: false);
842 break;
843 case JsonTokenType.Null:
844 writer.WriteNullValue();
845 break;
846 case JsonTokenType.EndObject:
847 case JsonTokenType.EndArray:
848 case JsonTokenType.PropertyName:
849 case JsonTokenType.Comment:
850 break;
851 }
852 }
853
855 {
857 for (int i = index + 12; i < endIndex; i += 12)
858 {
860 switch (row.TokenType)
861 {
862 case JsonTokenType.String:
864 break;
865 case JsonTokenType.Number:
866 writer.WriteNumberValue(_utf8Json.Slice(row.Location, row.SizeOrLength).Span);
867 break;
868 case JsonTokenType.True:
869 writer.WriteBooleanValue(value: true);
870 break;
871 case JsonTokenType.False:
872 writer.WriteBooleanValue(value: false);
873 break;
874 case JsonTokenType.Null:
875 writer.WriteNullValue();
876 break;
877 case JsonTokenType.StartObject:
878 writer.WriteStartObject();
879 break;
880 case JsonTokenType.EndObject:
881 writer.WriteEndObject();
882 break;
883 case JsonTokenType.StartArray:
884 writer.WriteStartArray();
885 break;
886 case JsonTokenType.EndArray:
887 writer.WriteEndArray();
888 break;
889 case JsonTokenType.PropertyName:
891 break;
892 }
893 }
894 }
895
897 {
898 int location = row.Location;
899 int sizeOrLength = row.SizeOrLength;
901 if (!row.HasComplexChildren)
902 {
903 rented = default(ArraySegment<byte>);
904 return span;
905 }
906 int num = span.IndexOf<byte>(92);
908 span.Slice(0, num).CopyTo(array);
911 return rented.AsSpan();
912 }
913
915 {
916 if (rented.Array != null)
917 {
918 rented.AsSpan().Clear();
919 ArrayPool<byte>.Shared.Return(rented.Array);
920 }
921 }
922
924 {
926 try
927 {
928 writer.WritePropertyName(UnescapeString(in row, out rented));
929 }
930 finally
931 {
933 }
934 }
935
937 {
939 try
940 {
941 writer.WriteStringValue(UnescapeString(in row, out rented));
942 }
943 finally
944 {
946 }
947 }
948
950 {
951 bool flag = false;
952 int num = 0;
953 int num2 = 0;
954 int num3 = 0;
956 while (utf8JsonReader.Read())
957 {
959 int num4 = (int)utf8JsonReader.TokenStartIndex;
960 switch (tokenType)
961 {
962 case JsonTokenType.StartObject:
963 {
964 if (flag)
965 {
966 num++;
967 }
968 num3++;
969 database.Append(tokenType, num4, -1);
970 StackRow row2 = new StackRow(num2 + 1);
971 stack.Push(row2);
972 num2 = 0;
973 break;
974 }
975 case JsonTokenType.EndObject:
976 {
977 int index = database.FindIndexOfFirstUnsetSizeOrLength(JsonTokenType.StartObject);
978 num3++;
979 num2++;
980 database.SetLength(index, num2);
981 int length2 = database.Length;
982 database.Append(tokenType, num4, utf8JsonReader.ValueSpan.Length);
983 database.SetNumberOfRows(index, num2);
984 database.SetNumberOfRows(length2, num2);
985 num2 += stack.Pop().SizeOrLength;
986 break;
987 }
988 case JsonTokenType.StartArray:
989 {
990 if (flag)
991 {
992 num++;
993 }
994 num2++;
995 database.Append(tokenType, num4, -1);
996 StackRow row = new StackRow(num, num3 + 1);
997 stack.Push(row);
998 num = 0;
999 num3 = 0;
1000 break;
1001 }
1002 case JsonTokenType.EndArray:
1003 {
1004 int num5 = database.FindIndexOfFirstUnsetSizeOrLength(JsonTokenType.StartArray);
1005 num3++;
1006 num2++;
1007 database.SetLength(num5, num);
1008 database.SetNumberOfRows(num5, num3);
1009 if (num + 1 != num3)
1010 {
1011 database.SetHasComplexChildren(num5);
1012 }
1013 int length = database.Length;
1014 database.Append(tokenType, num4, utf8JsonReader.ValueSpan.Length);
1015 database.SetNumberOfRows(length, num3);
1016 StackRow stackRow = stack.Pop();
1017 num = stackRow.SizeOrLength;
1018 num3 += stackRow.NumberOfRows;
1019 break;
1020 }
1021 case JsonTokenType.PropertyName:
1022 num3++;
1023 num2++;
1024 database.Append(tokenType, num4 + 1, utf8JsonReader.ValueSpan.Length);
1025 if (utf8JsonReader._stringHasEscaping)
1026 {
1027 database.SetHasComplexChildren(database.Length - 12);
1028 }
1029 break;
1030 default:
1031 num3++;
1032 num2++;
1033 if (flag)
1034 {
1035 num++;
1036 }
1037 if (tokenType == JsonTokenType.String)
1038 {
1039 database.Append(tokenType, num4 + 1, utf8JsonReader.ValueSpan.Length);
1040 if (utf8JsonReader._stringHasEscaping)
1041 {
1042 database.SetHasComplexChildren(database.Length - 12);
1043 }
1044 }
1045 else
1046 {
1047 database.Append(tokenType, num4, utf8JsonReader.ValueSpan.Length);
1048 }
1049 break;
1050 }
1051 flag = utf8JsonReader.IsInArray;
1052 }
1053 database.CompleteAllocations();
1054 }
1055
1056 private void CheckNotDisposed()
1057 {
1058 if (_utf8Json.IsEmpty)
1059 {
1060 throw new ObjectDisposedException("JsonDocument");
1061 }
1062 }
1063
1071
1073 {
1074 if (readerOptions.CommentHandling == JsonCommentHandling.Allow)
1075 {
1077 }
1078 }
1079
1081 {
1082 return Parse(utf8Json, options.GetReaderOptions());
1083 }
1084
1086 {
1087 JsonReaderOptions readerOptions = options.GetReaderOptions();
1088 if (utf8Json.IsSingleSegment)
1089 {
1090 return Parse(utf8Json.First, readerOptions);
1091 }
1092 int num = checked((int)utf8Json.Length);
1093 byte[] array = ArrayPool<byte>.Shared.Rent(num);
1094 try
1095 {
1096 utf8Json.CopyTo(array.AsSpan());
1097 return Parse(array.AsMemory(0, num), readerOptions, array);
1098 }
1099 catch
1100 {
1101 array.AsSpan(0, num).Clear();
1103 throw;
1104 }
1105 }
1106
1108 {
1109 if (utf8Json == null)
1110 {
1111 throw new ArgumentNullException("utf8Json");
1112 }
1114 try
1115 {
1116 return Parse(segment.AsMemory(), options.GetReaderOptions(), segment.Array);
1117 }
1118 catch
1119 {
1120 segment.AsSpan().Clear();
1121 ArrayPool<byte>.Shared.Return(segment.Array);
1122 throw;
1123 }
1124 }
1125
1127 {
1128 return Parse(utf8Json.WrittenMemory, options.GetReaderOptions(), null, utf8Json);
1129 }
1130
1132 {
1134 byte[] array = new byte[segment.Count];
1135 Buffer.BlockCopy(segment.Array, 0, array, 0, segment.Count);
1136 segment.AsSpan().Clear();
1137 ArrayPool<byte>.Shared.Return(segment.Array);
1138 return ParseUnrented(array.AsMemory(), options.GetReaderOptions());
1139 }
1140
1142 {
1143 byte[] array = new byte[utf8Json.Length];
1144 utf8Json.CopyTo(array);
1145 return ParseUnrented(array.AsMemory(), options.GetReaderOptions());
1146 }
1147
1149 {
1150 return ParseValue(json.AsMemory(), options);
1151 }
1152
1154 {
1155 if (utf8Json == null)
1156 {
1157 throw new ArgumentNullException("utf8Json");
1158 }
1160 }
1161
1163 {
1165 try
1166 {
1167 return Parse(segment.AsMemory(), options.GetReaderOptions(), segment.Array);
1168 }
1169 catch
1170 {
1171 segment.AsSpan().Clear();
1172 ArrayPool<byte>.Shared.Return(segment.Array);
1173 throw;
1174 }
1175 }
1176
1178 {
1182 try
1183 {
1185 return Parse(array.AsMemory(0, utf8FromText), options.GetReaderOptions(), array);
1186 }
1187 catch
1188 {
1189 array.AsSpan(0, utf8ByteCount).Clear();
1191 throw;
1192 }
1193 }
1194
1196 {
1200 byte[] array2;
1201 try
1202 {
1204 array2 = new byte[utf8FromText];
1206 }
1207 finally
1208 {
1209 array.AsSpan(0, utf8ByteCount).Clear();
1211 }
1212 return ParseUnrented(array2.AsMemory(), options.GetReaderOptions());
1213 }
1214
1216 {
1217 if (json == null)
1218 {
1219 throw new ArgumentNullException("json");
1220 }
1221 return Parse(json.AsMemory(), options);
1222 }
1223
1225 {
1226 return TryParseValue(ref reader, out document, shouldThrow: false, useArrayPools: true);
1227 }
1228
1230 {
1232 bool flag = TryParseValue(ref reader, out document, shouldThrow: true, useArrayPools: true);
1233 return document;
1234 }
1235
1237 {
1238 JsonReaderState currentState = reader.CurrentState;
1239 CheckSupportedOptions(currentState.Options, "reader");
1243 try
1244 {
1245 JsonTokenType tokenType = reader.TokenType;
1247 if ((tokenType == JsonTokenType.None || tokenType == JsonTokenType.PropertyName) && !reader.Read())
1248 {
1249 if (shouldThrow)
1250 {
1251 bytes = default(ReadOnlySpan<byte>);
1252 ThrowHelper.ThrowJsonReaderException(ref reader, ExceptionResource.ExpectedJsonTokens, 0, bytes);
1253 }
1254 reader = utf8JsonReader;
1255 document = null;
1256 return false;
1257 }
1258 switch (reader.TokenType)
1259 {
1260 case JsonTokenType.StartObject:
1261 case JsonTokenType.StartArray:
1262 {
1263 long tokenStartIndex = reader.TokenStartIndex;
1264 if (!reader.TrySkip())
1265 {
1266 if (shouldThrow)
1267 {
1268 bytes = default(ReadOnlySpan<byte>);
1269 ThrowHelper.ThrowJsonReaderException(ref reader, ExceptionResource.ExpectedJsonTokens, 0, bytes);
1270 }
1271 reader = utf8JsonReader;
1272 document = null;
1273 return false;
1274 }
1276 ReadOnlySequence<byte> originalSequence2 = reader.OriginalSequence;
1277 if (originalSequence2.IsEmpty)
1278 {
1279 bytes = reader.OriginalSpan;
1280 readOnlySpan = checked(bytes.Slice((int)tokenStartIndex, (int)num3));
1281 }
1282 else
1283 {
1285 }
1286 break;
1287 }
1288 case JsonTokenType.True:
1289 case JsonTokenType.False:
1290 case JsonTokenType.Null:
1291 if (useArrayPools)
1292 {
1293 if (reader.HasValueSequence)
1294 {
1295 sequence = reader.ValueSequence;
1296 }
1297 else
1298 {
1299 readOnlySpan = reader.ValueSpan;
1300 }
1301 break;
1302 }
1303 document = CreateForLiteral(reader.TokenType);
1304 return true;
1305 case JsonTokenType.Number:
1306 if (reader.HasValueSequence)
1307 {
1308 sequence = reader.ValueSequence;
1309 }
1310 else
1311 {
1312 readOnlySpan = reader.ValueSpan;
1313 }
1314 break;
1315 case JsonTokenType.String:
1316 {
1317 ReadOnlySequence<byte> originalSequence = reader.OriginalSequence;
1318 if (originalSequence.IsEmpty)
1319 {
1320 bytes = reader.ValueSpan;
1321 int length = bytes.Length + 2;
1322 readOnlySpan = reader.OriginalSpan.Slice((int)reader.TokenStartIndex, length);
1323 break;
1324 }
1325 long num = 2L;
1326 if (reader.HasValueSequence)
1327 {
1328 num += reader.ValueSequence.Length;
1329 }
1330 else
1331 {
1332 long num2 = num;
1333 bytes = reader.ValueSpan;
1334 num = num2 + bytes.Length;
1335 }
1336 sequence = originalSequence.Slice(reader.TokenStartIndex, num);
1337 break;
1338 }
1339 default:
1340 if (shouldThrow)
1341 {
1342 bytes = reader.ValueSpan;
1343 byte nextByte = bytes[0];
1344 bytes = default(ReadOnlySpan<byte>);
1345 ThrowHelper.ThrowJsonReaderException(ref reader, ExceptionResource.ExpectedStartOfValueNotFound, nextByte, bytes);
1346 }
1347 reader = utf8JsonReader;
1348 document = null;
1349 return false;
1350 }
1351 }
1352 catch
1353 {
1354 reader = utf8JsonReader;
1355 throw;
1356 }
1357 int num4 = (readOnlySpan.IsEmpty ? checked((int)sequence.Length) : readOnlySpan.Length);
1358 if (useArrayPools)
1359 {
1360 byte[] array = ArrayPool<byte>.Shared.Rent(num4);
1361 Span<byte> destination = array.AsSpan(0, num4);
1362 try
1363 {
1364 if (readOnlySpan.IsEmpty)
1365 {
1367 }
1368 else
1369 {
1370 readOnlySpan.CopyTo(destination);
1371 }
1372 document = Parse(array.AsMemory(0, num4), currentState.Options, array);
1373 }
1374 catch
1375 {
1376 destination.Clear();
1378 throw;
1379 }
1380 }
1381 else
1382 {
1383 byte[] array2 = ((!readOnlySpan.IsEmpty) ? readOnlySpan.ToArray() : BuffersExtensions.ToArray(in sequence));
1384 document = ParseUnrented(array2, currentState.Options, reader.TokenType);
1385 }
1386 return true;
1387 }
1388
1390 {
1391 switch (tokenType)
1392 {
1393 case JsonTokenType.False:
1394 if (s_falseLiteral == null)
1395 {
1397 }
1398 return s_falseLiteral;
1399 case JsonTokenType.True:
1400 if (s_trueLiteral == null)
1401 {
1403 }
1404 return s_trueLiteral;
1405 default:
1406 if (s_nullLiteral == null)
1407 {
1409 }
1410 return s_nullLiteral;
1411 }
1413 {
1415 parsedData.Append(tokenType, 0, utf8Json.Length);
1416 return new JsonDocument(utf8Json, parsedData);
1417 }
1418 }
1419
1421 {
1424 StackRowStack stack = new StackRowStack(512);
1425 try
1426 {
1428 }
1429 catch
1430 {
1431 database.Dispose();
1432 throw;
1433 }
1434 finally
1435 {
1436 stack.Dispose();
1437 }
1439 }
1440
1442 {
1445 if (tokenType == JsonTokenType.String || tokenType == JsonTokenType.Number)
1446 {
1448 StackRowStack stack = default(StackRowStack);
1450 }
1451 else
1452 {
1455 try
1456 {
1458 }
1459 finally
1460 {
1461 stack2.Dispose();
1462 }
1463 }
1464 return new JsonDocument(utf8Json, database);
1465 }
1466
1468 {
1469 int num = 0;
1470 byte[] array = null;
1472 try
1473 {
1474 if (stream.CanSeek)
1475 {
1476 long num2 = Math.Max(utf8Bom.Length, stream.Length - stream.Position) + 1;
1477 array = ArrayPool<byte>.Shared.Rent(checked((int)num2));
1478 }
1479 else
1480 {
1481 array = ArrayPool<byte>.Shared.Rent(4096);
1482 }
1483 int num3;
1484 do
1485 {
1486 num3 = stream.Read(array, num, utf8Bom.Length - num);
1487 num += num3;
1488 }
1489 while (num3 > 0 && num < utf8Bom.Length);
1490 if (num == utf8Bom.Length && utf8Bom.SequenceEqual(array.AsSpan(0, utf8Bom.Length)))
1491 {
1492 num = 0;
1493 }
1494 do
1495 {
1496 if (array.Length == num)
1497 {
1498 byte[] array2 = array;
1499 array = ArrayPool<byte>.Shared.Rent(checked(array2.Length * 2));
1500 Buffer.BlockCopy(array2, 0, array, 0, array2.Length);
1501 ArrayPool<byte>.Shared.Return(array2, clearArray: true);
1502 }
1503 num3 = stream.Read(array, num, array.Length - num);
1504 num += num3;
1505 }
1506 while (num3 > 0);
1507 return new ArraySegment<byte>(array, 0, num);
1508 }
1509 catch
1510 {
1511 if (array != null)
1512 {
1513 array.AsSpan(0, num).Clear();
1515 }
1516 throw;
1517 }
1518 }
1519
1521 {
1522 int written = 0;
1523 byte[] rented = null;
1524 try
1525 {
1526 int utf8BomLength = JsonConstants.Utf8Bom.Length;
1527 if (stream.CanSeek)
1528 {
1529 long num = Math.Max(utf8BomLength, stream.Length - stream.Position) + 1;
1530 rented = ArrayPool<byte>.Shared.Rent(checked((int)num));
1531 }
1532 else
1533 {
1534 rented = ArrayPool<byte>.Shared.Rent(4096);
1535 }
1536 int num2;
1537 do
1538 {
1539 num2 = await stream.ReadAsync(rented.AsMemory(written, utf8BomLength - written), cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
1540 written += num2;
1541 }
1542 while (num2 > 0 && written < utf8BomLength);
1543 if (written == utf8BomLength && JsonConstants.Utf8Bom.SequenceEqual(rented.AsSpan(0, utf8BomLength)))
1544 {
1545 written = 0;
1546 }
1547 do
1548 {
1549 if (rented.Length == written)
1550 {
1551 byte[] array = rented;
1552 rented = ArrayPool<byte>.Shared.Rent(array.Length * 2);
1553 Buffer.BlockCopy(array, 0, rented, 0, array.Length);
1554 ArrayPool<byte>.Shared.Return(array, clearArray: true);
1555 }
1556 num2 = await stream.ReadAsync(rented.AsMemory(written), cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
1557 written += num2;
1558 }
1559 while (num2 > 0);
1560 return new ArraySegment<byte>(rented, 0, written);
1561 }
1562 catch
1563 {
1564 if (rented != null)
1565 {
1566 rented.AsSpan(0, written).Clear();
1568 }
1569 throw;
1570 }
1571 }
1572
1574 {
1577 CheckExpectedType(JsonTokenType.StartObject, dbRow.TokenType);
1578 if (dbRow.NumberOfRows == 1)
1579 {
1580 value = default(JsonElement);
1581 return false;
1582 }
1583 int maxByteCount = JsonReaderHelper.s_utf8Encoding.GetMaxByteCount(propertyName.Length);
1584 int startIndex = index + 12;
1585 int num = checked(dbRow.NumberOfRows * 12 + index);
1586 if (maxByteCount < 256)
1587 {
1588 Span<byte> span = stackalloc byte[256];
1591 }
1592 int length = propertyName.Length;
1593 int num2;
1594 for (num2 = num - 12; num2 > index; num2 -= 12)
1595 {
1596 int num3 = num2;
1598 num2 = ((!dbRow.IsSimpleValue) ? (num2 - 12 * (dbRow.NumberOfRows + 1)) : (num2 - 12));
1600 {
1602 Span<byte> span2 = default(Span<byte>);
1603 try
1604 {
1606 span2 = array.AsSpan(0, utf8FromText);
1608 }
1609 finally
1610 {
1611 span2.Clear();
1613 }
1614 }
1615 }
1616 value = default(JsonElement);
1617 return false;
1618 }
1619
1621 {
1624 CheckExpectedType(JsonTokenType.StartObject, dbRow.TokenType);
1625 if (dbRow.NumberOfRows == 1)
1626 {
1627 value = default(JsonElement);
1628 return false;
1629 }
1630 int endIndex = checked(dbRow.NumberOfRows * 12 + index);
1632 }
1633
1635 {
1637 Span<byte> span2 = stackalloc byte[256];
1638 int num;
1639 for (num = endIndex - 12; num > startIndex; num -= 12)
1640 {
1641 DbRow dbRow = _parsedData.Get(num);
1642 num = ((!dbRow.IsSimpleValue) ? (num - 12 * (dbRow.NumberOfRows + 1)) : (num - 12));
1643 dbRow = _parsedData.Get(num);
1644 ReadOnlySpan<byte> span3 = span.Slice(dbRow.Location, dbRow.SizeOrLength);
1645 if (dbRow.HasComplexChildren)
1646 {
1647 if (span3.Length > propertyName.Length)
1648 {
1649 int num2 = span3.IndexOf<byte>(92);
1650 if (propertyName.Length > num2 && span3.Slice(0, num2).SequenceEqual(propertyName.Slice(0, num2)))
1651 {
1652 int num3 = span3.Length - num2;
1653 int written = 0;
1654 byte[] array = null;
1655 try
1656 {
1657 Span<byte> destination = ((num3 <= span2.Length) ? span2 : ((Span<byte>)(array = ArrayPool<byte>.Shared.Rent(num3))));
1659 if (destination.Slice(0, written).SequenceEqual(propertyName.Slice(num2)))
1660 {
1661 value = new JsonElement(this, num + 12);
1662 return true;
1663 }
1664 }
1665 finally
1666 {
1667 if (array != null)
1668 {
1669 array.AsSpan(0, written).Clear();
1671 }
1672 }
1673 }
1674 }
1675 }
1676 else if (span3.SequenceEqual(propertyName))
1677 {
1678 value = new JsonElement(this, num + 12);
1679 return true;
1680 }
1681 }
1682 value = default(JsonElement);
1683 return false;
1684 }
1685}
static void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count)
Definition Buffer.cs:102
static ArrayPool< T > Shared
Definition ArrayPool.cs:7
T[] Rent(int minimumLength)
static bool TryParse(ReadOnlySpan< byte > source, out bool value, out int bytesConsumed, char standardFormat='\0')
static byte Max(byte val1, byte val2)
Definition Math.cs:738
static string JsonDocumentDoesNotSupportComments
Definition SR.cs:88
Definition SR.cs:7
static ReadOnlySpan< byte > NullValue
static ReadOnlySpan< byte > TrueValue
static ReadOnlySpan< byte > FalseValue
static ReadOnlySpan< byte > Utf8Bom
static JsonDocument Parse(ReadOnlySequence< byte > utf8Json, JsonDocumentOptions options=default(JsonDocumentOptions))
string GetRawValueAsString(int index)
bool TryGetNamedPropertyValue(int startIndex, int endIndex, ReadOnlySpan< byte > propertyName, out JsonElement value)
bool TryGetValue(int index, out sbyte value)
JsonElement GetArrayIndexElement(int currentIndex, int arrayIndex)
int GetEndIndex(int index, bool includeEndElement)
void WriteTo(Utf8JsonWriter writer)
bool TryGetValue(int index, out ushort value)
static JsonDocument s_falseLiteral
static JsonDocument CreateForLiteral(JsonTokenType tokenType)
static JsonDocument Parse(string json, JsonDocumentOptions options=default(JsonDocumentOptions))
bool TryGetValue(int index, out DateTime value)
static JsonDocument Parse(ReadOnlyMemory< char > json, JsonDocumentOptions options=default(JsonDocumentOptions))
string GetNameOfPropertyValue(int index)
bool TryGetNamedPropertyValue(int index, ReadOnlySpan< char > propertyName, out JsonElement value)
bool TryGetValue(int index, out long value)
ReadOnlySpan< byte > UnescapeString(in DbRow row, out ArraySegment< byte > rented)
ReadOnlyMemory< byte > GetRootRawValue()
void WriteComplexElement(int index, Utf8JsonWriter writer)
static Task< JsonDocument > ParseAsync(Stream utf8Json, JsonDocumentOptions options=default(JsonDocumentOptions), CancellationToken cancellationToken=default(CancellationToken))
bool TryGetValue(int index, out double value)
bool TryGetValue(int index, out Guid value)
static JsonDocument Parse(ReadOnlyMemory< byte > utf8Json, JsonReaderOptions readerOptions, byte[] extraRentedArrayPoolBytes=null, PooledByteBufferWriter extraPooledByteBufferWriter=null)
bool TryGetValue(int index, out int value)
bool TryGetValue(int index, [NotNullWhen(true)] out byte[] value)
static JsonDocument ParseValue(ReadOnlyMemory< char > json, JsonDocumentOptions options)
ReadOnlyMemory< byte > GetPropertyRawValue(int valueIndex)
static bool TryParseValue(ref Utf8JsonReader reader, [NotNullWhen(true)] out JsonDocument? document)
static void CheckSupportedOptions(JsonReaderOptions readerOptions, string paramName)
bool TryGetNamedPropertyValue(int index, ReadOnlySpan< byte > propertyName, out JsonElement value)
bool TryGetValue(int index, out uint value)
void CheckExpectedType(JsonTokenType expected, JsonTokenType actual)
void WriteElementTo(int index, Utf8JsonWriter writer)
static async ValueTask< ArraySegment< byte > > ReadToEndAsync(Stream stream, CancellationToken cancellationToken)
ReadOnlyMemory< byte > _utf8Json
bool TextEquals(int index, ReadOnlySpan< char > otherText, bool isPropertyName)
string GetPropertyRawValueAsString(int valueIndex)
static JsonDocument Parse(Stream utf8Json, JsonDocumentOptions options=default(JsonDocumentOptions))
bool TextEquals(int index, ReadOnlySpan< byte > otherUtf8Text, bool isPropertyName, bool shouldUnescape)
static JsonDocument ParseRented(PooledByteBufferWriter utf8Json, JsonDocumentOptions options=default(JsonDocumentOptions))
PooledByteBufferWriter _extraPooledByteBufferWriter
JsonElement CloneElement(int index)
ReadOnlyMemory< byte > GetRawValue(int index, bool includeQuotes)
static JsonDocument ParseValue(ref Utf8JsonReader reader)
bool TryGetValue(int index, out ulong value)
static void ClearAndReturn(ArraySegment< byte > rented)
bool TryGetValue(int index, out byte value)
static JsonDocument Parse(ReadOnlyMemory< byte > utf8Json, JsonDocumentOptions options=default(JsonDocumentOptions))
static JsonDocument ParseValue(Stream utf8Json, JsonDocumentOptions options)
string GetString(int index, JsonTokenType expectedType)
static async Task< JsonDocument > ParseAsyncCore(Stream utf8Json, JsonDocumentOptions options=default(JsonDocumentOptions), CancellationToken cancellationToken=default(CancellationToken))
void WritePropertyName(in DbRow row, Utf8JsonWriter writer)
bool TryGetValue(int index, out decimal value)
bool TryGetValue(int index, out DateTimeOffset value)
static JsonDocument ParseUnrented(ReadOnlyMemory< byte > utf8Json, JsonReaderOptions readerOptions, JsonTokenType tokenType=JsonTokenType.None)
bool TryGetValue(int index, out float value)
static ArraySegment< byte > ReadToEnd(Stream stream)
static JsonDocument ParseValue(ReadOnlySpan< byte > utf8Json, JsonDocumentOptions options)
static JsonDocument s_nullLiteral
JsonTokenType GetJsonTokenType(int index)
JsonDocument(ReadOnlyMemory< byte > utf8Json, MetadataDb parsedData, byte[] extraRentedArrayPoolBytes=null, PooledByteBufferWriter extraPooledByteBufferWriter=null, bool isDisposable=true)
static JsonDocument ParseValue(string json, JsonDocumentOptions options)
static bool TryParseValue(ref Utf8JsonReader reader, [NotNullWhen(true)] out JsonDocument document, bool shouldThrow, bool useArrayPools)
static JsonDocument s_trueLiteral
void WriteString(in DbRow row, Utf8JsonWriter writer)
bool TryGetValue(int index, out short value)
static void Parse(ReadOnlySpan< byte > utf8JsonSpan, JsonReaderOptions readerOptions, ref MetadataDb database, ref StackRowStack stack)
static bool IsValidDateTimeOffsetParseLength(int length)
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 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 int GetUtf8FromText(ReadOnlySpan< char > text, Span< byte > dest)
static void Unescape(ReadOnlySpan< byte > source, Span< byte > destination, int idx, out int written)
static bool TryGetUnescapedBase64Bytes(ReadOnlySpan< byte > utf8Source, int idx, [NotNullWhen(true)] out byte[] bytes)
static readonly UTF8Encoding s_utf8Encoding
static bool TryDecodeBase64(ReadOnlySpan< byte > utf8Unescaped, [NotNullWhen(true)] out byte[] bytes)
static int GetUtf8ByteCount(ReadOnlySpan< char > text)
static unsafe OperationStatus ToUtf8(ReadOnlySpan< byte > utf16Source, Span< byte > utf8Destination, out int bytesConsumed, out int bytesWritten)
static void ThrowJsonReaderException(ref Utf8JsonReader json, ExceptionResource resource, byte nextByte=0, ReadOnlySpan< byte > bytes=default(ReadOnlySpan< byte >))
static InvalidOperationException GetJsonElementWrongTypeException(JsonTokenType expectedType, JsonTokenType actualType)
static int Exchange(ref int location1, int value)
TokenType
Definition TokenType.cs:4
ReadOnlySequence< T > Slice(long start, long length)
unsafe ReadOnlySpan< T > Span
ReadOnlyMemory< T > Slice(int start)
static ReadOnlyMemory< T > Empty
ReadOnlySpan< T > Slice(int start)
void CopyTo(Span< T > destination)
Definition Span.cs:224
DbRow(JsonTokenType jsonTokenType, int location, int sizeOrLength)
void Append(JsonTokenType tokenType, int startLocation, int length)
static MetadataDb CreateLocked(int payloadLength)
MetadataDb CopySegment(int startIndex, int endIndex)
static MetadataDb CreateRented(int payloadLength, bool convertToAlloc)
int FindOpenElement(JsonTokenType lookupType)
void SetLength(int index, int length)
MetadataDb(byte[] initialDb, bool isLocked, bool convertToAlloc)
void SetNumberOfRows(int index, int numberOfRows)
int FindIndexOfFirstUnsetSizeOrLength(JsonTokenType lookupType)
JsonTokenType GetJsonTokenType(int index)
StackRow(int sizeOrLength=0, int numberOfRows=-1)
void WriteTo(Utf8JsonWriter writer)