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

◆ DecodeBytes()

unsafe int System.Net.Mime.QEncodedStream.DecodeBytes ( byte[] buffer,
int offset,
int count )
inline

Implements System.Net.Mime.IEncodableStream.

Definition at line 150 of file QEncodedStream.cs.

151 {
152 fixed (byte* ptr = buffer)
153 {
154 byte* ptr2 = ptr + offset;
155 byte* ptr3 = ptr2;
156 byte* ptr4 = ptr2;
157 byte* ptr5 = ptr2 + count;
158 if (ReadState.IsEscaped)
159 {
160 if (ReadState.Byte == -1)
161 {
162 if (count == 1)
163 {
164 ReadState.Byte = *ptr3;
165 return 0;
166 }
167 if (*ptr3 != 13 || ptr3[1] != 10)
168 {
169 byte b = HexDecodeMap[*ptr3];
170 byte b2 = HexDecodeMap[ptr3[1]];
171 if (b == byte.MaxValue)
172 {
173 throw new FormatException(System.SR.Format(System.SR.InvalidHexDigit, b));
174 }
175 if (b2 == byte.MaxValue)
176 {
177 throw new FormatException(System.SR.Format(System.SR.InvalidHexDigit, b2));
178 }
179 *(ptr4++) = (byte)((b << 4) + b2);
180 }
181 ptr3 += 2;
182 }
183 else
184 {
185 if (ReadState.Byte != 13 || *ptr3 != 10)
186 {
187 byte b3 = HexDecodeMap[ReadState.Byte];
188 byte b4 = HexDecodeMap[*ptr3];
189 if (b3 == byte.MaxValue)
190 {
191 throw new FormatException(System.SR.Format(System.SR.InvalidHexDigit, b3));
192 }
193 if (b4 == byte.MaxValue)
194 {
195 throw new FormatException(System.SR.Format(System.SR.InvalidHexDigit, b4));
196 }
197 *(ptr4++) = (byte)((b3 << 4) + b4);
198 }
199 ptr3++;
200 }
201 ReadState.IsEscaped = false;
202 ReadState.Byte = -1;
203 }
204 while (ptr3 < ptr5)
205 {
206 if (*ptr3 != 61)
207 {
208 if (*ptr3 == 95)
209 {
210 *(ptr4++) = 32;
211 ptr3++;
212 }
213 else
214 {
215 *(ptr4++) = *(ptr3++);
216 }
217 continue;
218 }
219 long num = ptr5 - ptr3;
220 if (num != 1)
221 {
222 if (num != 2)
223 {
224 if (ptr3[1] != 13 || ptr3[2] != 10)
225 {
226 byte b5 = HexDecodeMap[ptr3[1]];
227 byte b6 = HexDecodeMap[ptr3[2]];
228 if (b5 == byte.MaxValue)
229 {
230 throw new FormatException(System.SR.Format(System.SR.InvalidHexDigit, b5));
231 }
232 if (b6 == byte.MaxValue)
233 {
234 throw new FormatException(System.SR.Format(System.SR.InvalidHexDigit, b6));
235 }
236 *(ptr4++) = (byte)((b5 << 4) + b6);
237 }
238 ptr3 += 3;
239 continue;
240 }
241 ReadState.Byte = ptr3[1];
242 }
243 ReadState.IsEscaped = true;
244 break;
245 }
246 return (int)(ptr4 - ptr2);
247 }
248 }
static ReadOnlySpan< byte > HexDecodeMap
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string InvalidHexDigit
Definition SR.cs:46
Definition SR.cs:7

References System.buffer, System.count, System.SR.Format(), System.Net.Mime.QEncodedStream.HexDecodeMap, System.SR.InvalidHexDigit, and System.offset.