Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ GetBytes() [1/4]

static byte[] System.Text.EncodingExtensions.GetBytes ( this Encoding encoding,
in ReadOnlySequence< char > chars )
inlinestatic

Definition at line 74 of file EncodingExtensions.cs.

75 {
76 if (encoding == null)
77 {
78 throw new ArgumentNullException("encoding");
79 }
80 if (chars.IsSingleSegment)
81 {
83 byte[] array = new byte[encoding.GetByteCount(firstSpan)];
84 encoding.GetBytes(firstSpan, array);
85 return array;
86 }
87 Encoder encoder = encoding.GetEncoder();
88 List<(byte[], int)> list = new List<(byte[], int)>();
89 int num = 0;
91 bool isSingleSegment;
92 do
93 {
94 readOnlySequence.GetFirstSpan(out var first, out var next);
95 isSingleSegment = readOnlySequence.IsSingleSegment;
96 int byteCount = encoder.GetByteCount(first, isSingleSegment);
97 byte[] array2 = ArrayPool<byte>.Shared.Rent(byteCount);
98 int bytes = encoder.GetBytes(first, array2, isSingleSegment);
99 list.Add((array2, bytes));
100 num += bytes;
101 if (num < 0)
102 {
103 num = int.MaxValue;
104 break;
105 }
107 }
108 while (!isSingleSegment);
109 byte[] array3 = new byte[num];
111 foreach (var (array4, num2) in list)
112 {
113 array4.AsSpan(0, num2).CopyTo(destination);
114 ArrayPool<byte>.Shared.Return(array4);
116 }
117 return array3;
118 }
void CopyTo(KeyValuePair< TKey, TValue >[] array, int index)
void Add(TKey key, TValue value)

References System.array, System.byteCount, System.bytes, System.chars, System.Collections.Generic.Dictionary< TKey, TValue >.CopyTo(), System.destination, System.Text.Encoding.GetByteCount(), System.Text.Encoder.GetByteCount(), System.Text.Encoding.GetBytes(), System.Text.Encoder.GetBytes(), System.Text.Encoding.GetEncoder(), and System.list.