Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
BMPEncoding.cs
Go to the documentation of this file.
1
namespace
System.Formats.Asn1
;
2
3
internal
sealed
class
BMPEncoding
:
SpanBasedEncoding
4
{
5
protected
override
int
GetBytes
(
ReadOnlySpan<char>
chars
,
Span<byte>
bytes
,
bool
write)
6
{
7
if
(
chars
.IsEmpty)
8
{
9
return
0;
10
}
11
int
num = 0;
12
for
(
int
i = 0; i <
chars
.Length; i++)
13
{
14
char
c =
chars
[i];
15
if
(
char
.IsSurrogate(c))
16
{
17
base.EncoderFallback.CreateFallbackBuffer().Fallback(c, i);
18
throw
new
InvalidOperationException
();
19
}
20
ushort num2 = c;
21
if
(write)
22
{
23
bytes
[num + 1] = (byte)num2;
24
bytes
[num] = (byte)(num2 >> 8);
25
}
26
num += 2;
27
}
28
return
num;
29
}
30
31
protected
override
int
GetChars
(
ReadOnlySpan<byte>
bytes
,
Span<char>
chars
,
bool
write)
32
{
33
if
(
bytes
.IsEmpty)
34
{
35
return
0;
36
}
37
if
(
bytes
.Length % 2 != 0)
38
{
39
base.DecoderFallback.CreateFallbackBuffer().Fallback(
bytes
.Slice(
bytes
.Length - 1).ToArray(),
bytes
.Length - 1);
40
throw
new
InvalidOperationException
();
41
}
42
int
num = 0;
43
for
(
int
i = 0; i <
bytes
.Length; i += 2)
44
{
45
int
num2 = (
bytes
[i] << 8) |
bytes
[i + 1];
46
char
c = (char)num2;
47
if
(
char
.IsSurrogate(c))
48
{
49
base.DecoderFallback.CreateFallbackBuffer().Fallback(
bytes
.Slice(i, 2).ToArray(), i);
50
throw
new
InvalidOperationException
();
51
}
52
if
(write)
53
{
54
chars
[num] = c;
55
}
56
num++;
57
}
58
return
num;
59
}
60
61
public
override
int
GetMaxByteCount
(
int
charCount
)
62
{
63
return
checked(
charCount
* 2);
64
}
65
66
public
override
int
GetMaxCharCount
(
int
byteCount
)
67
{
68
return
byteCount
/ 2;
69
}
70
}
System.Formats.Asn1.BMPEncoding.GetMaxByteCount
override int GetMaxByteCount(int charCount)
Definition
BMPEncoding.cs:61
System.Formats.Asn1.BMPEncoding.GetBytes
override int GetBytes(ReadOnlySpan< char > chars, Span< byte > bytes, bool write)
Definition
BMPEncoding.cs:5
System.Formats.Asn1.BMPEncoding.GetMaxCharCount
override int GetMaxCharCount(int byteCount)
Definition
BMPEncoding.cs:66
System.Formats.Asn1.BMPEncoding.GetChars
override int GetChars(ReadOnlySpan< byte > bytes, Span< char > chars, bool write)
Definition
BMPEncoding.cs:31
System.Formats.Asn1.BMPEncoding
Definition
BMPEncoding.cs:4
System.Formats.Asn1.SpanBasedEncoding
Definition
SpanBasedEncoding.cs:6
System.InvalidOperationException
Definition
InvalidOperationException.cs:9
System.Formats.Asn1
Definition
Asn1Tag.cs:3
System.ExceptionArgument.bytes
@ bytes
System.ExceptionArgument.charCount
@ charCount
System.ExceptionArgument.byteCount
@ byteCount
System.ExceptionArgument.chars
@ chars
System.ReadOnlySpan
Definition
ReadOnlySpan.cs:14
System.Span
Definition
Span.cs:14
source
System.Formats.Asn1
System.Formats.Asn1
BMPEncoding.cs
Generated by
1.10.0