Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
EventPipePayloadDecoder.cs
Go to the documentation of this file.
4
6
7internal static class EventPipePayloadDecoder
8{
9 internal static object[] DecodePayload(ref EventSource.EventMetadata metadata, ReadOnlySpan<byte> payload)
10 {
11 ParameterInfo[] parameters = metadata.Parameters;
12 object[] array = new object[parameters.Length];
13 for (int i = 0; i < parameters.Length; i++)
14 {
15 if (payload.Length <= 0)
16 {
17 break;
18 }
19 Type parameterType = parameters[i].ParameterType;
20 Type type = (parameterType.IsEnum ? Enum.GetUnderlyingType(parameterType) : null);
21 if (parameterType == typeof(IntPtr))
22 {
23 _ = IntPtr.Size;
25 payload = payload.Slice(IntPtr.Size);
26 }
27 else if (parameterType == typeof(int) || type == typeof(int))
28 {
30 payload = payload.Slice(4);
31 }
32 else if (parameterType == typeof(uint) || type == typeof(uint))
33 {
35 payload = payload.Slice(4);
36 }
37 else if (parameterType == typeof(long) || type == typeof(long))
38 {
40 payload = payload.Slice(8);
41 }
42 else if (parameterType == typeof(ulong) || type == typeof(ulong))
43 {
45 payload = payload.Slice(8);
46 }
47 else if (parameterType == typeof(byte) || type == typeof(byte))
48 {
49 array[i] = MemoryMarshal.Read<byte>(payload);
50 payload = payload.Slice(1);
51 }
52 else if (parameterType == typeof(sbyte) || type == typeof(sbyte))
53 {
54 array[i] = MemoryMarshal.Read<sbyte>(payload);
55 payload = payload.Slice(1);
56 }
57 else if (parameterType == typeof(short) || type == typeof(short))
58 {
60 payload = payload.Slice(2);
61 }
62 else if (parameterType == typeof(ushort) || type == typeof(ushort))
63 {
65 payload = payload.Slice(2);
66 }
67 else if (parameterType == typeof(float))
68 {
70 payload = payload.Slice(4);
71 }
72 else if (parameterType == typeof(double))
73 {
75 payload = payload.Slice(8);
76 }
77 else if (parameterType == typeof(bool))
78 {
80 payload = payload.Slice(4);
81 }
82 else if (parameterType == typeof(Guid))
83 {
84 array[i] = new Guid(payload.Slice(0, 16));
85 payload = payload.Slice(16);
86 }
87 else if (parameterType == typeof(char))
88 {
90 payload = payload.Slice(2);
91 }
92 else
93 {
94 if (!(parameterType == typeof(string)))
95 {
96 continue;
97 }
98 int num = -1;
99 for (int j = 1; j < payload.Length; j += 2)
100 {
101 if (payload[j - 1] == 0 && payload[j] == 0)
102 {
103 num = j + 1;
104 break;
105 }
106 }
108 if (num < 0)
109 {
110 value = MemoryMarshal.Cast<byte, char>(payload);
111 payload = default(ReadOnlySpan<byte>);
112 }
113 else
114 {
115 value = MemoryMarshal.Cast<byte, char>(payload.Slice(0, num - 2));
116 payload = payload.Slice(num);
117 }
118 int num2 = i;
120 {
121 }
122 array[num2] = new string(value);
123 }
124 }
125 return array;
126 }
127}
static unsafe float Int32BitsToSingle(int value)
static unsafe double Int64BitsToDouble(long value)
static readonly bool IsLittleEndian
static short ReadInt16LittleEndian(ReadOnlySpan< byte > source)
static ulong ReadUInt64LittleEndian(ReadOnlySpan< byte > source)
static ushort ReadUInt16LittleEndian(ReadOnlySpan< byte > source)
static uint ReadUInt32LittleEndian(ReadOnlySpan< byte > source)
static int ReadInt32LittleEndian(ReadOnlySpan< byte > source)
static long ReadInt64LittleEndian(ReadOnlySpan< byte > source)
static object[] DecodePayload(ref EventSource.EventMetadata metadata, ReadOnlySpan< byte > payload)
static Type GetUnderlyingType(Type enumType)
Definition Enum.cs:309
static int Size
Definition IntPtr.cs:21
ReadOnlySpan< T > Slice(int start)