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

◆ DecodeFromUtf8InPlace()

static unsafe OperationStatus System.Buffers.Text.Base64.DecodeFromUtf8InPlace ( Span< byte > buffer,
out int bytesWritten )
inlinestatic

Definition at line 223 of file Base64.cs.

224 {
225 if (buffer.IsEmpty)
226 {
227 bytesWritten = 0;
228 return OperationStatus.Done;
229 }
230 fixed (byte* ptr = &MemoryMarshal.GetReference(buffer))
231 {
232 int length = buffer.Length;
233 uint num = 0u;
234 uint num2 = 0u;
235 if (length == (length >> 2) * 4)
236 {
237 if (length == 0)
238 {
239 goto IL_0189;
240 }
241 ref sbyte reference = ref MemoryMarshal.GetReference(DecodingMap);
242 while (num < length - 4)
243 {
244 int num3 = Decode(ptr + num, ref reference);
245 if (num3 >= 0)
246 {
247 WriteThreeLowOrderBytes(ptr + num2, num3);
248 num2 += 3;
249 num += 4;
250 continue;
251 }
252 goto IL_018f;
253 }
254 uint num4 = ptr[length - 4];
255 uint num5 = ptr[length - 3];
256 uint num6 = ptr[length - 2];
257 uint num7 = ptr[length - 1];
258 int num8 = Internal.Runtime.CompilerServices.Unsafe.Add(ref reference, (IntPtr)num4);
259 int num9 = Internal.Runtime.CompilerServices.Unsafe.Add(ref reference, (IntPtr)num5);
260 num8 <<= 18;
261 num9 <<= 12;
262 num8 |= num9;
263 if (num7 != 61)
264 {
265 int num10 = Internal.Runtime.CompilerServices.Unsafe.Add(ref reference, (IntPtr)num6);
266 int num11 = Internal.Runtime.CompilerServices.Unsafe.Add(ref reference, (IntPtr)num7);
267 num10 <<= 6;
268 num8 |= num11;
269 num8 |= num10;
270 if (num8 >= 0)
271 {
272 WriteThreeLowOrderBytes(ptr + num2, num8);
273 num2 += 3;
274 goto IL_0189;
275 }
276 }
277 else if (num6 != 61)
278 {
279 int num12 = Internal.Runtime.CompilerServices.Unsafe.Add(ref reference, (IntPtr)num6);
280 num12 <<= 6;
281 num8 |= num12;
282 if (num8 >= 0)
283 {
284 ptr[num2] = (byte)(num8 >> 16);
285 ptr[num2 + 1] = (byte)(num8 >> 8);
286 num2 += 2;
287 goto IL_0189;
288 }
289 }
290 else if (num8 >= 0)
291 {
292 ptr[num2] = (byte)(num8 >> 16);
293 num2++;
294 goto IL_0189;
295 }
296 }
297 goto IL_018f;
298 IL_018f:
299 bytesWritten = (int)num2;
300 return OperationStatus.InvalidData;
301 IL_0189:
302 bytesWritten = (int)num2;
303 return OperationStatus.Done;
304 }
305 }
static unsafe int Decode(byte *encodedBytes, ref sbyte decodingMap)
Definition Base64.cs:387
static ReadOnlySpan< sbyte > DecodingMap
Definition Base64.cs:11
static unsafe void WriteThreeLowOrderBytes(byte *destination, int value)
Definition Base64.cs:406

References System.buffer, System.Buffers.Text.Base64.Decode(), System.Buffers.Text.Base64.DecodingMap, System.length, and System.Buffers.Text.Base64.WriteThreeLowOrderBytes().

Referenced by System.Text.Json.JsonReaderHelper.TryDecodeBase64InPlace().