Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
XmlBufferReader.cs
Go to the documentation of this file.
3using System.IO;
6using System.Text;
7
8namespace System.Xml;
9
10internal sealed class XmlBufferReader
11{
12 private readonly XmlDictionaryReader _reader;
13
14 private Stream _stream;
15
16 private byte[] _streamBuffer;
17
18 private byte[] _buffer;
19
20 private int _offsetMin;
21
22 private int _offsetMax;
23
25
27
28 private byte[] _guid;
29
30 private int _offset;
31
32 private const int maxBytesPerChar = 3;
33
34 private char[] _chars;
35
36 private int _windowOffset;
37
38 private int _windowOffsetMax;
39
41
42 private static readonly XmlBufferReader s_empty = new XmlBufferReader(Array.Empty<byte>());
43
44 public static XmlBufferReader Empty => s_empty;
45
46 public byte[] Buffer => _buffer;
47
48 public bool IsStreamed => _stream != null;
49
50 public bool EndOfFile
51 {
52 get
53 {
54 if (_offset == _offsetMax)
55 {
56 return !TryEnsureByte();
57 }
58 return false;
59 }
60 }
61
62 public int Offset
63 {
64 get
65 {
66 return _offset;
67 }
68 set
69 {
70 _offset = value;
71 }
72 }
73
75 {
76 _reader = reader;
77 }
78
79 public XmlBufferReader(byte[] buffer)
80 {
81 _reader = null;
83 }
84
95
100
111
112 public void Close()
113 {
114 if (_streamBuffer != null && _streamBuffer.Length > 4096)
115 {
116 _streamBuffer = null;
117 }
118 if (_stream != null)
119 {
121 _stream = null;
122 }
123 _buffer = Array.Empty<byte>();
124 _offset = 0;
125 _offsetMax = 0;
126 _windowOffset = 0;
128 _dictionary = null;
129 _session = null;
130 }
131
132 public byte GetByte()
133 {
134 int offset = _offset;
135 if (offset < _offsetMax)
136 {
137 return _buffer[offset];
138 }
139 return GetByteHard();
140 }
141
142 public void SkipByte()
143 {
144 Advance(1);
145 }
146
147 private byte GetByteHard()
148 {
149 EnsureByte();
150 return _buffer[_offset];
151 }
152
153 public byte[] GetBuffer(int count, out int offset)
154 {
155 offset = _offset;
156 if (offset <= _offsetMax - count)
157 {
158 return _buffer;
159 }
160 return GetBufferHard(count, out offset);
161 }
162
163 public byte[] GetBuffer(int count, out int offset, out int offsetMax)
164 {
165 offset = _offset;
166 if (offset <= _offsetMax - count)
167 {
169 }
170 else
171 {
174 }
175 return _buffer;
176 }
177
178 public byte[] GetBuffer(out int offset, out int offsetMax)
179 {
180 offset = _offset;
182 return _buffer;
183 }
184
185 private byte[] GetBufferHard(int count, out int offset)
186 {
187 offset = _offset;
189 return _buffer;
190 }
191
192 private void EnsureByte()
193 {
194 if (!TryEnsureByte())
195 {
197 }
198 }
199
200 private bool TryEnsureByte()
201 {
202 if (_stream == null)
203 {
204 return false;
205 }
206 if (_offsetMax >= _buffer.Length)
207 {
208 return TryEnsureBytes(1);
209 }
210 int num = _stream.ReadByte();
211 if (num == -1)
212 {
213 return false;
214 }
215 _buffer[_offsetMax++] = (byte)num;
216 return true;
217 }
218
219 private void EnsureBytes(int count)
220 {
221 if (!TryEnsureBytes(count))
222 {
224 }
225 }
226
227 private bool TryEnsureBytes(int count)
228 {
229 if (_stream == null)
230 {
231 return false;
232 }
233 while (true)
234 {
235 int num = _offset + count;
236 if (num <= _offsetMax)
237 {
238 break;
239 }
240 if (num > _buffer.Length)
241 {
242 byte[] array = new byte[Math.Max(256, _buffer.Length * 2)];
244 num = Math.Min(num, array.Length);
245 _buffer = array;
247 }
248 int num2 = num - _offsetMax;
249 do
250 {
252 if (num3 == 0)
253 {
254 return false;
255 }
256 _offsetMax += num3;
257 num2 -= num3;
258 }
259 while (num2 > 0);
260 }
261 return true;
262 }
263
264 public void Advance(int count)
265 {
266 _offset += count;
267 }
268
269 public void InsertBytes(byte[] buffer, int offset, int count)
270 {
271 if (_offsetMax > buffer.Length - count)
272 {
273 byte[] array = new byte[_offsetMax + count];
275 _buffer = array;
277 }
279 _offsetMax += count;
281 }
282
298
299 public int ReadBytes(int count)
300 {
301 int offset = _offset;
302 if (offset > _offsetMax - count)
303 {
305 }
306 _offset += count;
307 return offset;
308 }
309
311 {
312 int @byte = GetByte();
313 Advance(1);
314 if ((@byte & 0x80) == 0)
315 {
316 return @byte;
317 }
318 @byte &= 0x7F;
319 int byte2 = GetByte();
320 Advance(1);
321 @byte |= (byte2 & 0x7F) << 7;
322 if ((byte2 & 0x80) == 0)
323 {
324 return @byte;
325 }
326 int byte3 = GetByte();
327 Advance(1);
328 @byte |= (byte3 & 0x7F) << 14;
329 if ((byte3 & 0x80) == 0)
330 {
331 return @byte;
332 }
333 int byte4 = GetByte();
334 Advance(1);
335 @byte |= (byte4 & 0x7F) << 21;
336 if ((byte4 & 0x80) == 0)
337 {
338 return @byte;
339 }
340 int byte5 = GetByte();
341 Advance(1);
342 @byte |= byte5 << 28;
343 if (((uint)byte5 & 0xF8u) != 0)
344 {
346 }
347 return @byte;
348 }
349
350 public int ReadUInt8()
351 {
352 byte @byte = GetByte();
353 Advance(1);
354 return @byte;
355 }
356
357 public int ReadInt8()
358 {
359 return (sbyte)ReadUInt8();
360 }
361
362 public int ReadUInt16()
363 {
364 int offset;
365 byte[] buffer = GetBuffer(2, out offset);
366 int result = buffer[offset] + (buffer[offset + 1] << 8);
367 Advance(2);
368 return result;
369 }
370
371 public int ReadInt16()
372 {
373 return (short)ReadUInt16();
374 }
375
376 public int ReadInt32()
377 {
378 int offset;
379 byte[] buffer = GetBuffer(4, out offset);
380 byte b = buffer[offset];
381 byte b2 = buffer[offset + 1];
382 byte b3 = buffer[offset + 2];
383 byte b4 = buffer[offset + 3];
384 Advance(4);
385 return (((b4 << 8) + b3 << 8) + b2 << 8) + b;
386 }
387
388 public int ReadUInt31()
389 {
390 int num = ReadInt32();
391 if (num < 0)
392 {
394 }
395 return num;
396 }
397
398 public long ReadInt64()
399 {
400 long num = (uint)ReadInt32();
401 long num2 = (uint)ReadInt32();
402 return (num2 << 32) + num;
403 }
404
405 public unsafe float ReadSingle()
406 {
407 int offset;
408 byte[] buffer = GetBuffer(4, out offset);
409 Unsafe.SkipInit(out float result);
410 byte* ptr = (byte*)(&result);
411 *ptr = buffer[offset];
412 ptr[1] = buffer[offset + 1];
413 ptr[2] = buffer[offset + 2];
414 ptr[3] = buffer[offset + 3];
415 Advance(4);
416 return result;
417 }
418
419 public unsafe double ReadDouble()
420 {
421 int offset;
422 byte[] buffer = GetBuffer(8, out offset);
423 Unsafe.SkipInit(out double result);
424 byte* ptr = (byte*)(&result);
425 *ptr = buffer[offset];
426 ptr[1] = buffer[offset + 1];
427 ptr[2] = buffer[offset + 2];
428 ptr[3] = buffer[offset + 3];
429 ptr[4] = buffer[offset + 4];
430 ptr[5] = buffer[offset + 5];
431 ptr[6] = buffer[offset + 6];
432 ptr[7] = buffer[offset + 7];
433 Advance(8);
434 return result;
435 }
436
437 public unsafe decimal ReadDecimal()
438 {
439 int offset;
440 byte[] buffer = GetBuffer(16, out offset);
441 Unsafe.SkipInit(out decimal result);
442 byte* ptr = (byte*)(&result);
443 for (int i = 0; i < 16; i++)
444 {
445 ptr[i] = buffer[offset + i];
446 }
447 Advance(16);
448 return result;
449 }
450
452 {
453 int offset;
454 byte[] buffer = GetBuffer(16, out offset);
455 UniqueId result = new UniqueId(buffer, offset);
456 Advance(16);
457 return result;
458 }
459
481
503
504 public Guid ReadGuid()
505 {
506 GetBuffer(16, out var offset);
507 Guid guid = GetGuid(offset);
508 Advance(16);
509 return guid;
510 }
511
512 public string ReadUTF8String(int length)
513 {
517 string result = new string(charBuffer, 0, chars);
519 return result;
520 }
521
522 public unsafe void UnsafeReadArray(byte* dst, byte* dstMax)
523 {
524 UnsafeReadArray(dst, (int)(dstMax - dst));
525 }
526
527 private unsafe void UnsafeReadArray(byte* dst, int length)
528 {
529 if (_stream != null)
530 {
531 while (length >= 256)
532 {
533 byte[] buffer = GetBuffer(256, out _offset);
534 for (int i = 0; i < 256; i++)
535 {
536 *(dst++) = buffer[_offset + i];
537 }
538 Advance(256);
539 length -= 256;
540 }
541 }
542 if (length <= 0)
543 {
544 return;
545 }
547 fixed (byte* ptr = &buffer2[_offset])
548 {
549 byte* ptr2 = ptr;
550 byte* ptr3 = dst + length;
551 while (dst < ptr3)
552 {
553 *dst = *ptr2;
554 dst++;
555 ptr2++;
556 }
557 }
559 }
560
561 private char[] GetCharBuffer(int count)
562 {
563 if (count > 1024)
564 {
565 return new char[count];
566 }
567 if (_chars == null || _chars.Length < count)
568 {
569 _chars = new char[count];
570 }
571 return _chars;
572 }
573
574 private int GetChars(int offset, int length, char[] chars)
575 {
576 byte[] buffer = _buffer;
577 for (int i = 0; i < length; i++)
578 {
579 byte b = buffer[offset + i];
580 if (b >= 128)
581 {
582 return i + XmlConverter.ToChars(buffer, offset + i, length - i, chars, i);
583 }
584 chars[i] = (char)b;
585 }
586 return length;
587 }
588
589 private int GetChars(int offset, int length, char[] chars, int charOffset)
590 {
591 byte[] buffer = _buffer;
592 for (int i = 0; i < length; i++)
593 {
594 byte b = buffer[offset + i];
595 if (b >= 128)
596 {
597 return i + XmlConverter.ToChars(buffer, offset + i, length - i, chars, charOffset + i);
598 }
599 chars[charOffset + i] = (char)b;
600 }
601 return length;
602 }
603
604 public string GetString(int offset, int length)
605 {
608 return new string(charBuffer, 0, chars);
609 }
610
611 public string GetUnicodeString(int offset, int length)
612 {
614 }
615
617 {
620 return nameTable.Add(charBuffer, 0, chars);
621 }
622
623 public int GetEscapedChars(int offset, int length, char[] chars)
624 {
625 byte[] buffer = _buffer;
626 int num = 0;
627 int num2 = offset;
628 int num3 = offset + length;
629 while (true)
630 {
632 {
633 offset++;
634 continue;
635 }
636 num += GetChars(num2, offset - num2, chars, num);
637 if (offset == num3)
638 {
639 break;
640 }
641 num2 = offset;
642 if (buffer[offset] == 38)
643 {
644 while (offset < num3 && buffer[offset] != 59)
645 {
646 offset++;
647 }
648 offset++;
650 num2 = offset;
651 if (charEntity > 65535)
652 {
654 chars[num++] = surrogateChar.HighChar;
655 chars[num++] = surrogateChar.LowChar;
656 }
657 else
658 {
659 chars[num++] = (char)charEntity;
660 }
661 }
662 else if (buffer[offset] == 10 || buffer[offset] == 9)
663 {
664 chars[num++] = ' ';
665 offset++;
666 num2 = offset;
667 }
668 else
669 {
670 chars[num++] = ' ';
671 offset++;
672 if (offset < num3 && buffer[offset] == 10)
673 {
674 offset++;
675 }
676 num2 = offset;
677 }
678 }
679 return num;
680 }
681
682 private bool IsAttrChar(int ch)
683 {
684 if ((uint)(ch - 9) <= 1u || ch == 13 || ch == 38)
685 {
686 return false;
687 }
688 return true;
689 }
690
691 public string GetEscapedString(int offset, int length)
692 {
695 return new string(charBuffer, 0, escapedChars);
696 }
697
698 private int GetLessThanCharEntity(int offset, int length)
699 {
700 byte[] buffer = _buffer;
701 if (length != 4 || buffer[offset + 1] != 108 || buffer[offset + 2] != 116)
702 {
704 }
705 return 60;
706 }
707
709 {
710 byte[] buffer = _buffer;
711 if (length != 4 || buffer[offset + 1] != 103 || buffer[offset + 2] != 116)
712 {
714 }
715 return 62;
716 }
717
718 private int GetQuoteCharEntity(int offset, int length)
719 {
720 byte[] buffer = _buffer;
721 if (length != 6 || buffer[offset + 1] != 113 || buffer[offset + 2] != 117 || buffer[offset + 3] != 111 || buffer[offset + 4] != 116)
722 {
724 }
725 return 34;
726 }
727
729 {
730 byte[] buffer = _buffer;
731 if (length != 5 || buffer[offset + 1] != 97 || buffer[offset + 2] != 109 || buffer[offset + 3] != 112)
732 {
734 }
735 return 38;
736 }
737
739 {
740 byte[] buffer = _buffer;
741 if (length != 6 || buffer[offset + 1] != 97 || buffer[offset + 2] != 112 || buffer[offset + 3] != 111 || buffer[offset + 4] != 115)
742 {
744 }
745 return 39;
746 }
747
748 private int GetDecimalCharEntity(int offset, int length)
749 {
750 byte[] buffer = _buffer;
751 int num = 0;
752 for (int i = 2; i < length - 1; i++)
753 {
754 byte b = buffer[offset + i];
755 if (b < 48 || b > 57)
756 {
758 }
759 num = num * 10 + (b - 48);
760 if (num > 1114111)
761 {
763 }
764 }
765 return num;
766 }
767
768 private int GetHexCharEntity(int offset, int length)
769 {
770 byte[] buffer = _buffer;
771 int num = 0;
772 for (int i = 3; i < length - 1; i++)
773 {
774 byte c = buffer[offset + i];
776 if (num2 == 255)
777 {
779 }
780 num = num * 16 + num2;
781 if (num > 1114111)
782 {
784 }
785 }
786 return num;
787 }
788
789 public int GetCharEntity(int offset, int length)
790 {
791 if (length < 3)
792 {
794 }
795 byte[] buffer = _buffer;
796 switch (buffer[offset + 1])
797 {
798 case 108:
800 case 103:
802 case 97:
803 if (buffer[offset + 2] == 109)
804 {
806 }
808 case 113:
810 case 35:
811 if (buffer[offset + 2] == 120)
812 {
814 }
816 default:
818 return 0;
819 }
820 }
821
822 public bool IsWhitespaceKey(int key)
823 {
825 for (int i = 0; i < value.Length; i++)
826 {
828 {
829 return false;
830 }
831 }
832 return true;
833 }
834
835 public bool IsWhitespaceUTF8(int offset, int length)
836 {
837 byte[] buffer = _buffer;
838 for (int i = 0; i < length; i++)
839 {
840 if (!XmlConverter.IsWhitespace((char)buffer[offset + i]))
841 {
842 return false;
843 }
844 }
845 return true;
846 }
847
848 public bool IsWhitespaceUnicode(int offset, int length)
849 {
850 for (int i = 0; i < length; i += 2)
851 {
852 char ch = (char)GetInt16(offset + i);
854 {
855 return false;
856 }
857 }
858 return true;
859 }
860
862 {
863 if (key1 == key2)
864 {
865 return true;
866 }
867 return GetDictionaryString(key1).Value == bufferReader2.GetDictionaryString(key2).Value;
868 }
869
871 {
872 if ((key1 & 1) == 0 && xmlString2.Dictionary == _dictionary)
873 {
874 return xmlString2.Key == key1 >> 1;
875 }
876 return GetDictionaryString(key1).Value == xmlString2.Value;
877 }
878
879 public bool Equals2(int offset1, int length1, byte[] buffer2)
880 {
881 int num = buffer2.Length;
882 if (length1 != num)
883 {
884 return false;
885 }
886 byte[] buffer3 = _buffer;
887 for (int i = 0; i < length1; i++)
888 {
889 if (buffer3[offset1 + i] != buffer2[i])
890 {
891 return false;
892 }
893 }
894 return true;
895 }
896
898 {
899 if (length1 != length2)
900 {
901 return false;
902 }
903 byte[] buffer = _buffer;
904 byte[] buffer2 = bufferReader2._buffer;
905 for (int i = 0; i < length1; i++)
906 {
907 if (buffer[offset1 + i] != buffer2[offset2 + i])
908 {
909 return false;
910 }
911 }
912 return true;
913 }
914
915 public bool Equals2(int offset1, int length1, int offset2, int length2)
916 {
917 if (length1 != length2)
918 {
919 return false;
920 }
921 if (offset1 == offset2)
922 {
923 return true;
924 }
925 byte[] buffer = _buffer;
926 for (int i = 0; i < length1; i++)
927 {
928 if (buffer[offset1 + i] != buffer[offset2 + i])
929 {
930 return false;
931 }
932 }
933 return true;
934 }
935
936 public unsafe bool Equals2(int offset1, int length1, string s2)
937 {
938 int length2 = s2.Length;
940 {
941 return false;
942 }
943 byte[] buffer = _buffer;
944 if (length1 < 8)
945 {
946 int num = Math.Min(length1, length2);
947 for (int i = 0; i < num; i++)
948 {
949 byte b = buffer[offset1 + i];
950 if (b >= 128)
951 {
953 }
954 if (s2[i] != b)
955 {
956 return false;
957 }
958 }
959 return length1 == length2;
960 }
961 int num2 = Math.Min(length1, length2);
962 fixed (byte* ptr = &buffer[offset1])
963 {
964 byte* ptr2 = ptr;
965 byte* ptr3 = ptr2 + num2;
966 fixed (char* ptr4 = s2)
967 {
968 char* ptr5 = ptr4;
969 int num3 = 0;
970 while (ptr2 < ptr3 && *ptr2 < 128)
971 {
972 num3 = *ptr2 - (byte)(*ptr5);
973 if (num3 != 0)
974 {
975 break;
976 }
977 ptr2++;
978 ptr5++;
979 }
980 if (num3 != 0)
981 {
982 return false;
983 }
984 if (ptr2 == ptr3)
985 {
986 return length1 == length2;
987 }
988 }
989 }
991 }
992
993 public int Compare(int offset1, int length1, int offset2, int length2)
994 {
995 byte[] buffer = _buffer;
996 int num = Math.Min(length1, length2);
997 for (int i = 0; i < num; i++)
998 {
999 int num2 = buffer[offset1 + i] - buffer[offset2 + i];
1000 if (num2 != 0)
1001 {
1002 return num2;
1003 }
1004 }
1005 return length1 - length2;
1006 }
1007
1008 public byte GetByte(int offset)
1009 {
1010 return _buffer[offset];
1011 }
1012
1013 public int GetInt8(int offset)
1014 {
1015 return (sbyte)GetByte(offset);
1016 }
1017
1018 public int GetInt16(int offset)
1019 {
1020 byte[] buffer = _buffer;
1021 return (short)(buffer[offset] + (buffer[offset + 1] << 8));
1022 }
1023
1024 public int GetInt32(int offset)
1025 {
1026 byte[] buffer = _buffer;
1027 byte b = buffer[offset];
1028 byte b2 = buffer[offset + 1];
1029 byte b3 = buffer[offset + 2];
1030 byte b4 = buffer[offset + 3];
1031 return (((b4 << 8) + b3 << 8) + b2 << 8) + b;
1032 }
1033
1034 public long GetInt64(int offset)
1035 {
1036 byte[] buffer = _buffer;
1037 byte b = buffer[offset];
1038 byte b2 = buffer[offset + 1];
1039 byte b3 = buffer[offset + 2];
1040 byte b4 = buffer[offset + 3];
1041 long num = (uint)((((b4 << 8) + b3 << 8) + b2 << 8) + b);
1042 b = buffer[offset + 4];
1043 b2 = buffer[offset + 5];
1044 b3 = buffer[offset + 6];
1045 b4 = buffer[offset + 7];
1046 long num2 = (uint)((((b4 << 8) + b3 << 8) + b2 << 8) + b);
1047 return (num2 << 32) + num;
1048 }
1049
1050 public ulong GetUInt64(int offset)
1051 {
1052 return (ulong)GetInt64(offset);
1053 }
1054
1055 public unsafe float GetSingle(int offset)
1056 {
1057 byte[] buffer = _buffer;
1058 Unsafe.SkipInit(out float result);
1059 byte* ptr = (byte*)(&result);
1060 *ptr = buffer[offset];
1061 ptr[1] = buffer[offset + 1];
1062 ptr[2] = buffer[offset + 2];
1063 ptr[3] = buffer[offset + 3];
1064 return result;
1065 }
1066
1067 public unsafe double GetDouble(int offset)
1068 {
1069 byte[] buffer = _buffer;
1070 Unsafe.SkipInit(out double result);
1071 byte* ptr = (byte*)(&result);
1072 *ptr = buffer[offset];
1073 ptr[1] = buffer[offset + 1];
1074 ptr[2] = buffer[offset + 2];
1075 ptr[3] = buffer[offset + 3];
1076 ptr[4] = buffer[offset + 4];
1077 ptr[5] = buffer[offset + 5];
1078 ptr[6] = buffer[offset + 6];
1079 ptr[7] = buffer[offset + 7];
1080 return result;
1081 }
1082
1083 public unsafe decimal GetDecimal(int offset)
1084 {
1085 byte[] buffer = _buffer;
1086 Unsafe.SkipInit(out decimal result);
1087 byte* ptr = (byte*)(&result);
1088 for (int i = 0; i < 16; i++)
1089 {
1090 ptr[i] = buffer[offset + i];
1091 }
1092 return result;
1093 }
1094
1096 {
1097 return new UniqueId(_buffer, offset);
1098 }
1099
1100 public Guid GetGuid(int offset)
1101 {
1102 if (_guid == null)
1103 {
1104 _guid = new byte[16];
1105 }
1107 return new Guid(_guid);
1108 }
1109
1110 public void GetBase64(int srcOffset, byte[] buffer, int dstOffset, int count)
1111 {
1113 }
1114
1116 {
1117 return (XmlBinaryNodeType)GetByte();
1118 }
1119
1120 public void SkipNodeType()
1121 {
1122 SkipByte();
1123 }
1124
1125 public object[] GetList(int offset, int count)
1126 {
1127 int offset2 = Offset;
1128 Offset = offset;
1129 try
1130 {
1131 object[] array = new object[count];
1132 for (int i = 0; i < count; i++)
1133 {
1134 XmlBinaryNodeType nodeType = GetNodeType();
1135 SkipNodeType();
1136 ReadValue(nodeType, _listValue);
1137 array[i] = _listValue.ToObject();
1138 }
1139 return array;
1140 }
1141 finally
1142 {
1143 Offset = offset2;
1144 }
1145 }
1146
1148 {
1150 if (!xmlDictionary.TryLookup(key >> 1, out XmlDictionaryString result))
1151 {
1153 }
1154 return result;
1155 }
1156
1158 {
1159 int num = ReadMultiByteUInt31();
1160 if (((uint)num & (true ? 1u : 0u)) != 0)
1161 {
1162 if (_session == null)
1163 {
1165 }
1166 int num2 = num >> 1;
1168 {
1169 if (num2 < 0 || num2 > 536870911)
1170 {
1172 }
1174 }
1175 }
1176 else
1177 {
1178 if (_dictionary == null)
1179 {
1181 }
1182 int num3 = num >> 1;
1184 {
1185 if (num3 < 0 || num3 > 536870911)
1186 {
1188 }
1190 }
1191 }
1192 return num;
1193 }
1194
1196 {
1197 switch (nodeType)
1198 {
1199 case XmlBinaryNodeType.EmptyText:
1200 value.SetValue(ValueHandleType.Empty);
1201 break;
1202 case XmlBinaryNodeType.MinText:
1203 value.SetValue(ValueHandleType.Zero);
1204 break;
1205 case XmlBinaryNodeType.OneText:
1206 value.SetValue(ValueHandleType.One);
1207 break;
1208 case XmlBinaryNodeType.TrueText:
1209 value.SetValue(ValueHandleType.True);
1210 break;
1211 case XmlBinaryNodeType.FalseText:
1212 value.SetValue(ValueHandleType.False);
1213 break;
1214 case XmlBinaryNodeType.BoolText:
1215 value.SetValue((ReadUInt8() != 0) ? ValueHandleType.True : ValueHandleType.False);
1216 break;
1217 case XmlBinaryNodeType.Chars8Text:
1219 break;
1220 case XmlBinaryNodeType.Chars16Text:
1222 break;
1223 case XmlBinaryNodeType.Chars32Text:
1225 break;
1226 case XmlBinaryNodeType.UnicodeChars8Text:
1228 break;
1229 case XmlBinaryNodeType.UnicodeChars16Text:
1231 break;
1232 case XmlBinaryNodeType.UnicodeChars32Text:
1234 break;
1235 case XmlBinaryNodeType.Bytes8Text:
1237 break;
1238 case XmlBinaryNodeType.Bytes16Text:
1240 break;
1241 case XmlBinaryNodeType.Bytes32Text:
1243 break;
1244 case XmlBinaryNodeType.DictionaryText:
1245 value.SetDictionaryValue(ReadDictionaryKey());
1246 break;
1247 case XmlBinaryNodeType.UniqueIdText:
1248 ReadValue(value, ValueHandleType.UniqueId, 16);
1249 break;
1250 case XmlBinaryNodeType.GuidText:
1251 ReadValue(value, ValueHandleType.Guid, 16);
1252 break;
1253 case XmlBinaryNodeType.DecimalText:
1254 ReadValue(value, ValueHandleType.Decimal, 16);
1255 break;
1256 case XmlBinaryNodeType.Int8Text:
1258 break;
1259 case XmlBinaryNodeType.Int16Text:
1260 ReadValue(value, ValueHandleType.Int16, 2);
1261 break;
1262 case XmlBinaryNodeType.Int32Text:
1263 ReadValue(value, ValueHandleType.Int32, 4);
1264 break;
1265 case XmlBinaryNodeType.Int64Text:
1266 ReadValue(value, ValueHandleType.Int64, 8);
1267 break;
1268 case XmlBinaryNodeType.UInt64Text:
1269 ReadValue(value, ValueHandleType.UInt64, 8);
1270 break;
1271 case XmlBinaryNodeType.FloatText:
1272 ReadValue(value, ValueHandleType.Single, 4);
1273 break;
1274 case XmlBinaryNodeType.DoubleText:
1275 ReadValue(value, ValueHandleType.Double, 8);
1276 break;
1277 case XmlBinaryNodeType.TimeSpanText:
1278 ReadValue(value, ValueHandleType.TimeSpan, 8);
1279 break;
1280 case XmlBinaryNodeType.DateTimeText:
1281 ReadValue(value, ValueHandleType.DateTime, 8);
1282 break;
1283 case XmlBinaryNodeType.StartListText:
1284 ReadList(value);
1285 break;
1286 case XmlBinaryNodeType.QNameDictionaryText:
1288 break;
1289 default:
1291 break;
1292 }
1293 }
1294
1296 {
1297 int offset = ReadBytes(length);
1298 value.SetValue(type, offset, length);
1299 }
1300
1302 {
1303 if (((uint)length & (true ? 1u : 0u)) != 0)
1304 {
1306 }
1308 }
1309
1311 {
1312 if (_listValue == null)
1313 {
1314 _listValue = new ValueHandle(this);
1315 }
1316 int num = 0;
1317 int offset = Offset;
1318 while (true)
1319 {
1320 XmlBinaryNodeType nodeType = GetNodeType();
1321 SkipNodeType();
1322 if (nodeType == XmlBinaryNodeType.StartListText)
1323 {
1325 }
1326 if (nodeType == XmlBinaryNodeType.EndListText)
1327 {
1328 break;
1329 }
1330 ReadValue(nodeType, _listValue);
1331 num++;
1332 }
1333 value.SetValue(ValueHandleType.List, offset, num);
1334 }
1335
1337 {
1338 int num = ReadUInt8();
1339 if (num >= 26)
1340 {
1342 }
1343 int key = ReadDictionaryKey();
1344 value.SetQNameValue(num, key);
1345 }
1346
1347 public int[] GetRows()
1348 {
1349 if (_buffer == null)
1350 {
1351 return new int[1];
1352 }
1353 List<int> list = new List<int>();
1354 list.Add(_offsetMin);
1355 for (int i = _offsetMin; i < _offsetMax; i++)
1356 {
1357 if (_buffer[i] == 13 || _buffer[i] == 10)
1358 {
1359 if (i + 1 < _offsetMax && _buffer[i + 1] == 10)
1360 {
1361 i++;
1362 }
1363 list.Add(i + 1);
1364 }
1365 }
1366 return list.ToArray();
1367 }
1368}
static void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count)
Definition Buffer.cs:102
void Add(TKey key, TValue value)
static CultureInfo InvariantCulture
static int FromChar(int c)
virtual int ReadByte()
Definition Stream.cs:994
int Read(byte[] buffer, int offset, int count)
void Dispose()
Definition Stream.cs:639
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static byte Max(byte val1, byte val2)
Definition Math.cs:738
bool TryLookup(int key, [NotNullWhen(true)] out XmlDictionaryString? result)
XmlBinaryNodeType GetNodeType()
XmlDictionaryString GetDictionaryString(int key)
bool Equals2(int key1, int key2, XmlBufferReader bufferReader2)
unsafe void UnsafeReadArray(byte *dst, int length)
int GetEscapedChars(int offset, int length, char[] chars)
int GetApostropheCharEntity(int offset, int length)
int GetCharEntity(int offset, int length)
bool IsWhitespaceUnicode(int offset, int length)
unsafe decimal GetDecimal(int offset)
unsafe float GetSingle(int offset)
int Compare(int offset1, int length1, int offset2, int length2)
object[] GetList(int offset, int count)
int GetDecimalCharEntity(int offset, int length)
string GetUnicodeString(int offset, int length)
int GetGreaterThanCharEntity(int offset, int length)
void ReadValue(ValueHandle value, ValueHandleType type, int length)
bool Equals2(int offset1, int length1, byte[] buffer2)
byte[] GetBuffer(out int offset, out int offsetMax)
string GetEscapedString(int offset, int length)
byte[] GetBufferHard(int count, out int offset)
string ReadUTF8String(int length)
void ReadValue(XmlBinaryNodeType nodeType, ValueHandle value)
int GetQuoteCharEntity(int offset, int length)
int GetChars(int offset, int length, char[] chars)
void InsertBytes(byte[] buffer, int offset, int count)
void ReadList(ValueHandle value)
static readonly XmlBufferReader s_empty
void ReadQName(ValueHandle value)
void ReadUnicodeValue(ValueHandle value, int length)
byte[] GetBuffer(int count, out int offset)
int GetAmpersandCharEntity(int offset, int length)
void SetBuffer(Stream stream, IXmlDictionary dictionary, XmlBinaryReaderSession session)
char[] GetCharBuffer(int count)
readonly XmlDictionaryReader _reader
unsafe double GetDouble(int offset)
bool Equals2(int offset1, int length1, XmlBufferReader bufferReader2, int offset2, int length2)
byte[] GetBuffer(int count, out int offset, out int offsetMax)
int GetHexCharEntity(int offset, int length)
int GetChars(int offset, int length, char[] chars, int charOffset)
void SetBuffer(byte[] buffer, int offset, int count, IXmlDictionary dictionary, XmlBinaryReaderSession session)
XmlBinaryReaderSession _session
XmlBufferReader(XmlDictionaryReader reader)
bool IsWhitespaceUTF8(int offset, int length)
string GetString(int offset, int length, XmlNameTable nameTable)
UniqueId GetUniqueId(int offset)
void SetWindow(int windowOffset, int windowLength)
int GetLessThanCharEntity(int offset, int length)
bool Equals2(int key1, XmlDictionaryString xmlString2)
bool Equals2(int offset1, int length1, int offset2, int length2)
void SetBuffer(Stream stream, byte[] buffer, int offset, int count, IXmlDictionary dictionary, XmlBinaryReaderSession session)
unsafe bool Equals2(int offset1, int length1, string s2)
void GetBase64(int srcOffset, byte[] buffer, int dstOffset, int count)
string GetString(int offset, int length)
unsafe void UnsafeReadArray(byte *dst, byte *dstMax)
static string ToStringUnicode(byte[] buffer, int offset, int count)
static bool IsWhitespace(string s)
static string ToString(byte[] buffer, int offset, int count)
static int ToChars(byte[] buffer, int offset, int count, char[] chars, int charOffset)
static void ThrowXmlDictionaryStringIDOutOfRange(XmlDictionaryReader reader)
static void ThrowUnexpectedEndOfFile(XmlDictionaryReader reader)
static void ThrowInvalidBinaryFormat(XmlDictionaryReader reader)
static void ThrowXmlDictionaryStringIDUndefinedStatic(XmlDictionaryReader reader, int key)
static void ThrowXmlDictionaryStringIDUndefinedSession(XmlDictionaryReader reader, int key)
static void ThrowInvalidCharRef(XmlDictionaryReader reader)
static XmlException CreateConversionException(string type, Exception exception)
bool TryLookup(string value, [NotNullWhen(true)] out XmlDictionaryString? result)
static DateTime FromBinary(long dateData)
Definition DateTime.cs:671
static TimeSpan FromTicks(long value)
Definition TimeSpan.cs:277