Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Base64Encoder.cs
Go to the documentation of this file.
2
3namespace System.Xml;
4
5internal abstract class Base64Encoder
6{
7 private byte[] _leftOverBytes;
8
9 private int _leftOverBytesCount;
10
11 private readonly char[] _charsLine;
12
13 internal Base64Encoder()
14 {
15 _charsLine = new char[1024];
16 }
17
18 internal abstract void WriteChars(char[] chars, int index, int count);
19
20 internal void Encode(byte[] buffer, int index, int count)
21 {
22 if (buffer == null)
23 {
24 throw new ArgumentNullException("buffer");
25 }
26 if (index < 0)
27 {
28 throw new ArgumentOutOfRangeException("index");
29 }
30 if (count < 0)
31 {
32 throw new ArgumentOutOfRangeException("count");
33 }
34 if (count > buffer.Length - index)
35 {
36 throw new ArgumentOutOfRangeException("count");
37 }
38 if (_leftOverBytesCount > 0)
39 {
42 {
44 count--;
45 }
46 if (count == 0 && leftOverBytesCount < 3)
47 {
49 return;
50 }
53 }
55 if (_leftOverBytesCount > 0)
56 {
58 if (_leftOverBytes == null)
59 {
60 _leftOverBytes = new byte[3];
61 }
62 for (int i = 0; i < _leftOverBytesCount; i++)
63 {
64 _leftOverBytes[i] = buffer[index + count + i];
65 }
66 }
67 int num = index + count;
68 int num2 = 768;
69 while (index < num)
70 {
71 if (index + num2 > num)
72 {
73 num2 = num - index;
74 }
77 index += num2;
78 }
79 }
80
81 internal void Flush()
82 {
83 if (_leftOverBytesCount > 0)
84 {
88 }
89 }
90
91 internal abstract Task WriteCharsAsync(char[] chars, int index, int count);
92
93 internal async Task EncodeAsync(byte[] buffer, int index, int count)
94 {
95 if (buffer == null)
96 {
97 throw new ArgumentNullException("buffer");
98 }
99 if (index < 0)
100 {
101 throw new ArgumentOutOfRangeException("index");
102 }
103 if (count < 0)
104 {
105 throw new ArgumentOutOfRangeException("count");
106 }
107 if (count > buffer.Length - index)
108 {
109 throw new ArgumentOutOfRangeException("count");
110 }
111 if (_leftOverBytesCount > 0)
112 {
115 {
117 count--;
118 }
119 if (count == 0 && leftOverBytesCount < 3)
120 {
122 return;
123 }
126 }
128 if (_leftOverBytesCount > 0)
129 {
131 if (_leftOverBytes == null)
132 {
133 _leftOverBytes = new byte[3];
134 }
135 for (int i = 0; i < _leftOverBytesCount; i++)
136 {
137 _leftOverBytes[i] = buffer[index + count + i];
138 }
139 }
140 int endIndex = index + count;
141 int chunkSize = 768;
142 while (index < endIndex)
143 {
144 if (index + chunkSize > endIndex)
145 {
147 }
150 index += chunkSize;
151 }
152 }
153
163}
static int ToBase64CharArray(byte[] inArray, int offsetIn, int length, char[] outArray, int offsetOut)
Definition Convert.cs:2741
new ConfiguredTaskAwaitable< TResult > ConfigureAwait(bool continueOnCapturedContext)
Definition Task.cs:226
void Encode(byte[] buffer, int index, int count)
readonly char[] _charsLine
void WriteChars(char[] chars, int index, int count)
Task WriteCharsAsync(char[] chars, int index, int count)
async Task EncodeAsync(byte[] buffer, int index, int count)