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

◆ GetBytes() [5/10]

unsafe override int System.Text.Base64Encoding.GetBytes ( char[] chars,
int charIndex,
int charCount,
byte[] bytes,
int byteIndex )
inline

Definition at line 121 of file Base64Encoding.cs.

122 {
123 if (chars == null)
124 {
125 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("chars"));
126 }
127 if (charIndex < 0)
128 {
129 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("charIndex", System.SR.ValueMustBeNonNegative));
130 }
131 if (charIndex > chars.Length)
132 {
133 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("charIndex", System.SR.Format(System.SR.OffsetExceedsBufferSize, chars.Length)));
134 }
135 if (charCount < 0)
136 {
137 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("charCount", System.SR.ValueMustBeNonNegative));
138 }
139 if (charCount > chars.Length - charIndex)
140 {
141 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("charCount", System.SR.Format(System.SR.SizeExceedsRemainingBufferSpace, chars.Length - charIndex)));
142 }
143 if (bytes == null)
144 {
145 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("bytes"));
146 }
147 if (byteIndex < 0)
148 {
149 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("byteIndex", System.SR.ValueMustBeNonNegative));
150 }
151 if (byteIndex > bytes.Length)
152 {
153 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("byteIndex", System.SR.Format(System.SR.OffsetExceedsBufferSize, bytes.Length)));
154 }
155 if (charCount == 0)
156 {
157 return 0;
158 }
159 if (charCount % 4 != 0)
160 {
162 }
163 fixed (byte* ptr7 = &Char2val[0])
164 {
165 fixed (char* ptr = &chars[charIndex])
166 {
167 fixed (byte* ptr4 = &bytes[byteIndex])
168 {
169 char* ptr2 = ptr;
170 char* ptr3 = ptr + charCount;
171 byte* ptr5 = ptr4;
172 byte* ptr6 = ptr4 + bytes.Length - byteIndex;
173 for (; ptr2 < ptr3; ptr2 += 4)
174 {
175 char c = *ptr2;
176 char c2 = ptr2[1];
177 char c3 = ptr2[2];
178 char c4 = ptr2[3];
179 if ((c | c2 | c3 | c4) >= 128)
180 {
181 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(System.SR.Format(System.SR.XmlInvalidBase64Sequence, new string(ptr2, 0, 4), charIndex + (int)(ptr2 - ptr))));
182 }
183 int num = ptr7[(int)c];
184 int num2 = ptr7[(int)c2];
185 int num3 = ptr7[(int)c3];
186 int num4 = ptr7[(int)c4];
188 {
189 throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(System.SR.Format(System.SR.XmlInvalidBase64Sequence, new string(ptr2, 0, 4), charIndex + (int)(ptr2 - ptr))));
190 }
191 int num5 = ((num4 != 64) ? 3 : ((num3 == 64) ? 1 : 2));
192 if (ptr5 + num5 > ptr6)
193 {
195 }
196 *ptr5 = (byte)((uint)(num << 2) | ((uint)(num2 >> 4) & 3u));
197 if (num5 > 1)
198 {
199 ptr5[1] = (byte)((uint)(num2 << 4) | ((uint)(num3 >> 2) & 0xFu));
200 if (num5 > 2)
201 {
202 ptr5[2] = (byte)((uint)(num3 << 6) | ((uint)num4 & 0x3Fu));
203 }
204 }
205 ptr5 += num5;
206 }
207 return (int)(ptr5 - ptr4);
208 }
209 }
210 }
211 }
static string XmlInvalidBase64Sequence
Definition SR.cs:334
static string XmlInvalidBase64Length
Definition SR.cs:332
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string ValueMustBeNonNegative
Definition SR.cs:296
static string SizeExceedsRemainingBufferSpace
Definition SR.cs:324
static string OffsetExceedsBufferSize
Definition SR.cs:322
static string XmlArrayTooSmall
Definition SR.cs:348
Definition SR.cs:7
bool IsValidTailBytes(int v3, int v4)
static ReadOnlySpan< byte > Char2val
bool IsValidLeadBytes(int v1, int v2, int v3, int v4)

References System.byteIndex, System.bytes, System.Text.Base64Encoding.Char2val, System.charCount, System.charIndex, System.chars, System.Runtime.Serialization.Dictionary, System.SR.Format(), System.Text.Base64Encoding.IsValidLeadBytes(), System.Text.Base64Encoding.IsValidTailBytes(), System.SR.OffsetExceedsBufferSize, System.SR.SizeExceedsRemainingBufferSpace, System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(), System.SR.ValueMustBeNonNegative, System.SR.XmlArrayTooSmall, System.SR.XmlInvalidBase64Length, and System.SR.XmlInvalidBase64Sequence.

Referenced by System.Xml.ValueHandle.ToByteArray(), and System.Xml.ValueHandle.TryReadBase64().