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

◆ DecodeFromUtf8()

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

Definition at line 43 of file Base64.cs.

44 {
45 if (utf8.IsEmpty)
46 {
47 bytesConsumed = 0;
48 bytesWritten = 0;
49 return OperationStatus.Done;
50 }
51 fixed (byte* ptr = &MemoryMarshal.GetReference(utf8))
52 {
53 fixed (byte* ptr2 = &MemoryMarshal.GetReference(bytes))
54 {
55 int num = utf8.Length & -4;
56 int length = bytes.Length;
57 int num2 = num;
58 int maxDecodedFromUtf8Length = GetMaxDecodedFromUtf8Length(num);
59 if (length < maxDecodedFromUtf8Length - 2)
60 {
61 num2 = length / 3 * 4;
62 }
63 byte* srcBytes = ptr;
64 byte* destBytes = ptr2;
65 byte* ptr3 = ptr + (uint)num;
66 byte* ptr4 = ptr + (uint)num2;
67 if (num2 >= 24)
68 {
69 byte* ptr5 = ptr4 - 45;
70 if (Avx2.IsSupported && ptr5 >= srcBytes)
71 {
72 Avx2Decode(ref srcBytes, ref destBytes, ptr5, num2, length, ptr, ptr2);
73 if (srcBytes == ptr3)
74 {
75 goto IL_029d;
76 }
77 }
78 ptr5 = ptr4 - 24;
79 if (Ssse3.IsSupported && ptr5 >= srcBytes)
80 {
81 Ssse3Decode(ref srcBytes, ref destBytes, ptr5, num2, length, ptr, ptr2);
82 if (srcBytes == ptr3)
83 {
84 goto IL_029d;
85 }
86 }
87 }
88 int num3 = (isFinalBlock ? 4 : 0);
89 num2 = ((length < maxDecodedFromUtf8Length) ? (length / 3 * 4) : (num - num3));
90 ref sbyte reference = ref MemoryMarshal.GetReference(DecodingMap);
91 ptr4 = ptr + (uint)num2;
92 while (true)
93 {
94 if (srcBytes < ptr4)
95 {
96 int num4 = Decode(srcBytes, ref reference);
97 if (num4 >= 0)
98 {
99 WriteThreeLowOrderBytes(destBytes, num4);
100 srcBytes += 4;
101 destBytes += 3;
102 continue;
103 }
104 }
105 else
106 {
107 if (num2 != num - num3)
108 {
109 goto IL_02b3;
110 }
111 if (srcBytes == ptr3)
112 {
113 if (!isFinalBlock)
114 {
115 if (srcBytes == ptr + utf8.Length)
116 {
117 break;
118 }
119 bytesConsumed = (int)(srcBytes - ptr);
120 bytesWritten = (int)(destBytes - ptr2);
121 return OperationStatus.NeedMoreData;
122 }
123 }
124 else
125 {
126 uint num5 = ptr3[-4];
127 uint num6 = ptr3[-3];
128 uint num7 = ptr3[-2];
129 uint num8 = ptr3[-1];
130 int num9 = Internal.Runtime.CompilerServices.Unsafe.Add(ref reference, (IntPtr)num5);
131 int num10 = Internal.Runtime.CompilerServices.Unsafe.Add(ref reference, (IntPtr)num6);
132 num9 <<= 18;
133 num10 <<= 12;
134 num9 |= num10;
135 byte* ptr6 = ptr2 + (uint)length;
136 if (num8 != 61)
137 {
138 int num11 = Internal.Runtime.CompilerServices.Unsafe.Add(ref reference, (IntPtr)num7);
139 int num12 = Internal.Runtime.CompilerServices.Unsafe.Add(ref reference, (IntPtr)num8);
140 num11 <<= 6;
141 num9 |= num12;
142 num9 |= num11;
143 if (num9 >= 0)
144 {
145 if (destBytes + 3 <= ptr6)
146 {
147 WriteThreeLowOrderBytes(destBytes, num9);
148 destBytes += 3;
149 goto IL_028c;
150 }
151 goto IL_02b3;
152 }
153 }
154 else if (num7 != 61)
155 {
156 int num13 = Internal.Runtime.CompilerServices.Unsafe.Add(ref reference, (IntPtr)num7);
157 num13 <<= 6;
158 num9 |= num13;
159 if (num9 >= 0)
160 {
161 if (destBytes + 2 <= ptr6)
162 {
163 *destBytes = (byte)(num9 >> 16);
164 destBytes[1] = (byte)(num9 >> 8);
165 destBytes += 2;
166 goto IL_028c;
167 }
168 goto IL_02b3;
169 }
170 }
171 else if (num9 >= 0)
172 {
173 if (destBytes + 1 <= ptr6)
174 {
175 *destBytes = (byte)(num9 >> 16);
176 destBytes++;
177 goto IL_028c;
178 }
179 goto IL_02b3;
180 }
181 }
182 }
183 goto IL_02f2;
184 IL_028c:
185 srcBytes += 4;
186 if (num == utf8.Length)
187 {
188 break;
189 }
190 goto IL_02f2;
191 IL_02b3:
192 if (!(num != utf8.Length && isFinalBlock))
193 {
194 bytesConsumed = (int)(srcBytes - ptr);
195 bytesWritten = (int)(destBytes - ptr2);
196 return OperationStatus.DestinationTooSmall;
197 }
198 goto IL_02f2;
199 IL_02f2:
200 bytesConsumed = (int)(srcBytes - ptr);
201 bytesWritten = (int)(destBytes - ptr2);
202 return OperationStatus.InvalidData;
203 }
204 goto IL_029d;
205 IL_029d:
206 bytesConsumed = (int)(srcBytes - ptr);
207 bytesWritten = (int)(destBytes - ptr2);
208 return OperationStatus.Done;
209 }
210 }
211 }
static unsafe int Decode(byte *encodedBytes, ref sbyte decodingMap)
Definition Base64.cs:387
static int GetMaxDecodedFromUtf8Length(int length)
Definition Base64.cs:214
static ReadOnlySpan< sbyte > DecodingMap
Definition Base64.cs:11
static unsafe void Ssse3Decode(ref byte *srcBytes, ref byte *destBytes, byte *srcEnd, int sourceLength, int destLength, byte *srcStart, byte *destStart)
Definition Base64.cs:348
static unsafe void WriteThreeLowOrderBytes(byte *destination, int value)
Definition Base64.cs:406
static unsafe void Avx2Decode(ref byte *srcBytes, ref byte *destBytes, byte *srcEnd, int sourceLength, int destLength, byte *srcStart, byte *destStart)
Definition Base64.cs:308
static new bool IsSupported
Definition Avx2.cs:15

References System.Buffers.Text.Base64.Avx2Decode(), System.bytes, System.Buffers.Text.Base64.Decode(), System.Buffers.Text.Base64.DecodingMap, System.Buffers.Text.Base64.GetMaxDecodedFromUtf8Length(), System.ReadOnlySpan< T >.IsEmpty, System.Runtime.Intrinsics.X86.Avx2.IsSupported, System.Runtime.Intrinsics.X86.Ssse3.IsSupported, System.length, System.ReadOnlySpan< T >.Length, System.Buffers.Text.Base64.Ssse3Decode(), and System.Buffers.Text.Base64.WriteThreeLowOrderBytes().

Referenced by System.Security.Cryptography.FromBase64Transform.ConvertFromBase64(), and System.Text.Json.JsonReaderHelper.TryDecodeBase64().