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

◆ EncodeToUtf8()

static unsafe OperationStatus System.Buffers.Text.Base64.EncodeToUtf8 ( ReadOnlySpan< byte > bytes,
Span< byte > utf8,
out int bytesConsumed,
out int bytesWritten,
bool isFinalBlock = true )
inlinestatic

Definition at line 413 of file Base64.cs.

414 {
415 if (bytes.IsEmpty)
416 {
417 bytesConsumed = 0;
418 bytesWritten = 0;
419 return OperationStatus.Done;
420 }
421 fixed (byte* ptr = &MemoryMarshal.GetReference(bytes))
422 {
423 fixed (byte* ptr2 = &MemoryMarshal.GetReference(utf8))
424 {
425 int length = bytes.Length;
426 int length2 = utf8.Length;
427 int num = ((length > 1610612733 || length2 < GetMaxEncodedToUtf8Length(length)) ? ((length2 >> 2) * 3) : length);
428 byte* srcBytes = ptr;
429 byte* destBytes = ptr2;
430 byte* ptr3 = ptr + (uint)length;
431 byte* ptr4 = ptr + (uint)num;
432 if (num >= 16)
433 {
434 byte* ptr5 = ptr4 - 32;
435 if (Avx2.IsSupported && ptr5 >= srcBytes)
436 {
437 Avx2Encode(ref srcBytes, ref destBytes, ptr5, num, length2, ptr, ptr2);
438 if (srcBytes == ptr3)
439 {
440 goto IL_0175;
441 }
442 }
443 ptr5 = ptr4 - 16;
444 if (Ssse3.IsSupported && ptr5 >= srcBytes)
445 {
446 Ssse3Encode(ref srcBytes, ref destBytes, ptr5, num, length2, ptr, ptr2);
447 if (srcBytes == ptr3)
448 {
449 goto IL_0175;
450 }
451 }
452 }
453 ref byte reference = ref MemoryMarshal.GetReference(EncodingMap);
454 uint num2 = 0u;
455 ptr4 -= 2;
456 while (srcBytes < ptr4)
457 {
458 num2 = Encode(srcBytes, ref reference);
459 Internal.Runtime.CompilerServices.Unsafe.WriteUnaligned(destBytes, num2);
460 srcBytes += 3;
461 destBytes += 4;
462 }
463 if (ptr4 + 2 == ptr3)
464 {
465 if (!isFinalBlock)
466 {
467 if (srcBytes != ptr3)
468 {
469 bytesConsumed = (int)(srcBytes - ptr);
470 bytesWritten = (int)(destBytes - ptr2);
471 return OperationStatus.NeedMoreData;
472 }
473 }
474 else if (srcBytes + 1 == ptr3)
475 {
476 num2 = EncodeAndPadTwo(srcBytes, ref reference);
477 Internal.Runtime.CompilerServices.Unsafe.WriteUnaligned(destBytes, num2);
478 srcBytes++;
479 destBytes += 4;
480 }
481 else if (srcBytes + 2 == ptr3)
482 {
483 num2 = EncodeAndPadOne(srcBytes, ref reference);
484 Internal.Runtime.CompilerServices.Unsafe.WriteUnaligned(destBytes, num2);
485 srcBytes += 2;
486 destBytes += 4;
487 }
488 goto IL_0175;
489 }
490 bytesConsumed = (int)(srcBytes - ptr);
491 bytesWritten = (int)(destBytes - ptr2);
492 return OperationStatus.DestinationTooSmall;
493 IL_0175:
494 bytesConsumed = (int)(srcBytes - ptr);
495 bytesWritten = (int)(destBytes - ptr2);
496 return OperationStatus.Done;
497 }
498 }
499 }
static unsafe uint Encode(byte *threeBytes, ref byte encodingMap)
Definition Base64.cs:627
static unsafe void Avx2Encode(ref byte *srcBytes, ref byte *destBytes, byte *srcEnd, int sourceLength, int destLength, byte *srcStart, byte *destStart)
Definition Base64.cs:551
static unsafe uint EncodeAndPadOne(byte *twoBytes, ref byte encodingMap)
Definition Base64.cs:645
static unsafe void Ssse3Encode(ref byte *srcBytes, ref byte *destBytes, byte *srcEnd, int sourceLength, int destLength, byte *srcStart, byte *destStart)
Definition Base64.cs:592
static int GetMaxEncodedToUtf8Length(int length)
Definition Base64.cs:502
static ReadOnlySpan< byte > EncodingMap
Definition Base64.cs:41
static unsafe uint EncodeAndPadTwo(byte *oneByte, ref byte encodingMap)
Definition Base64.cs:661
static new bool IsSupported
Definition Avx2.cs:15
int Length
Definition Span.cs:70

References System.Buffers.Text.Base64.Avx2Encode(), System.bytes, System.Buffers.Text.Base64.Encode(), System.Buffers.Text.Base64.EncodeAndPadOne(), System.Buffers.Text.Base64.EncodeAndPadTwo(), System.Buffers.Text.Base64.EncodingMap, System.Buffers.Text.Base64.GetMaxEncodedToUtf8Length(), System.Runtime.Intrinsics.X86.Avx2.IsSupported, System.Runtime.Intrinsics.X86.Ssse3.IsSupported, System.length, System.Span< T >.Length, System.length2, and System.Buffers.Text.Base64.Ssse3Encode().

Referenced by System.Text.Json.Utf8JsonWriter.Base64EncodeAndWrite(), System.Security.Cryptography.ToBase64Transform.TransformBlock(), and System.Security.Cryptography.ToBase64Transform.TransformFinalBlock().