Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
BlobWriterImpl.cs
Go to the documentation of this file.
2
3internal static class BlobWriterImpl
4{
5 internal const int SingleByteCompressedIntegerMaxValue = 127;
6
7 internal const int TwoByteCompressedIntegerMaxValue = 16383;
8
9 internal const int MaxCompressedIntegerValue = 536870911;
10
11 internal const int MinSignedCompressedIntegerValue = -268435456;
12
13 internal const int MaxSignedCompressedIntegerValue = 268435455;
14
15 internal static int GetCompressedIntegerSize(int value)
16 {
17 if (value <= 127)
18 {
19 return 1;
20 }
21 if (value <= 16383)
22 {
23 return 2;
24 }
25 return 4;
26 }
27
28 internal static void WriteCompressedInteger(ref BlobWriter writer, uint value)
29 {
30 if (value <= 127)
31 {
32 writer.WriteByte((byte)value);
33 }
34 else if (value <= 16383)
35 {
36 writer.WriteUInt16BE((ushort)(0x8000u | value));
37 }
38 else if (value <= 536870911)
39 {
40 writer.WriteUInt32BE(0xC0000000u | value);
41 }
42 else
43 {
45 }
46 }
47
48 internal static void WriteCompressedInteger(BlobBuilder writer, uint value)
49 {
50 if (value <= 127)
51 {
52 writer.WriteByte((byte)value);
53 }
54 else if (value <= 16383)
55 {
56 writer.WriteUInt16BE((ushort)(0x8000u | value));
57 }
58 else if (value <= 536870911)
59 {
60 writer.WriteUInt32BE(0xC0000000u | value);
61 }
62 else
63 {
65 }
66 }
67
68 internal static void WriteCompressedSignedInteger(ref BlobWriter writer, int value)
69 {
70 int num = value >> 31;
71 if ((value & -64) == (num & -64))
72 {
73 int num2 = ((value & 0x3F) << 1) | (num & 1);
74 writer.WriteByte((byte)num2);
75 }
76 else if ((value & -8192) == (num & -8192))
77 {
78 int num3 = ((value & 0x1FFF) << 1) | (num & 1);
79 writer.WriteUInt16BE((ushort)(0x8000u | (uint)num3));
80 }
81 else if ((value & -268435456) == (num & -268435456))
82 {
83 int num4 = ((value & 0xFFFFFFF) << 1) | (num & 1);
84 writer.WriteUInt32BE(0xC0000000u | (uint)num4);
85 }
86 else
87 {
89 }
90 }
91
93 {
94 int num = value >> 31;
95 if ((value & -64) == (num & -64))
96 {
97 int num2 = ((value & 0x3F) << 1) | (num & 1);
98 writer.WriteByte((byte)num2);
99 }
100 else if ((value & -8192) == (num & -8192))
101 {
102 int num3 = ((value & 0x1FFF) << 1) | (num & 1);
103 writer.WriteUInt16BE((ushort)(0x8000u | (uint)num3));
104 }
105 else if ((value & -268435456) == (num & -268435456))
106 {
107 int num4 = ((value & 0xFFFFFFF) << 1) | (num & 1);
108 writer.WriteUInt32BE(0xC0000000u | (uint)num4);
109 }
110 else
111 {
113 }
114 }
115
116 internal static void WriteConstant(ref BlobWriter writer, object? value)
117 {
118 if (value == null)
119 {
120 writer.WriteUInt32(0u);
121 return;
122 }
124 if (type.GetTypeInfo().IsEnum)
125 {
127 }
128 if (type == typeof(bool))
129 {
130 writer.WriteBoolean((bool)value);
131 return;
132 }
133 if (type == typeof(int))
134 {
135 writer.WriteInt32((int)value);
136 return;
137 }
138 if (type == typeof(string))
139 {
140 writer.WriteUTF16((string)value);
141 return;
142 }
143 if (type == typeof(byte))
144 {
145 writer.WriteByte((byte)value);
146 return;
147 }
148 if (type == typeof(char))
149 {
150 writer.WriteUInt16((char)value);
151 return;
152 }
153 if (type == typeof(double))
154 {
155 writer.WriteDouble((double)value);
156 return;
157 }
158 if (type == typeof(short))
159 {
160 writer.WriteInt16((short)value);
161 return;
162 }
163 if (type == typeof(long))
164 {
165 writer.WriteInt64((long)value);
166 return;
167 }
168 if (type == typeof(sbyte))
169 {
170 writer.WriteSByte((sbyte)value);
171 return;
172 }
173 if (type == typeof(float))
174 {
175 writer.WriteSingle((float)value);
176 return;
177 }
178 if (type == typeof(ushort))
179 {
180 writer.WriteUInt16((ushort)value);
181 return;
182 }
183 if (type == typeof(uint))
184 {
185 writer.WriteUInt32((uint)value);
186 return;
187 }
188 if (type == typeof(ulong))
189 {
190 writer.WriteUInt64((ulong)value);
191 return;
192 }
194 }
195
196 internal static void WriteConstant(BlobBuilder writer, object? value)
197 {
198 if (value == null)
199 {
200 writer.WriteUInt32(0u);
201 return;
202 }
204 if (type.GetTypeInfo().IsEnum)
205 {
207 }
208 if (type == typeof(bool))
209 {
210 writer.WriteBoolean((bool)value);
211 return;
212 }
213 if (type == typeof(int))
214 {
215 writer.WriteInt32((int)value);
216 return;
217 }
218 if (type == typeof(string))
219 {
220 writer.WriteUTF16((string)value);
221 return;
222 }
223 if (type == typeof(byte))
224 {
225 writer.WriteByte((byte)value);
226 return;
227 }
228 if (type == typeof(char))
229 {
230 writer.WriteUInt16((char)value);
231 return;
232 }
233 if (type == typeof(double))
234 {
235 writer.WriteDouble((double)value);
236 return;
237 }
238 if (type == typeof(short))
239 {
240 writer.WriteInt16((short)value);
241 return;
242 }
243 if (type == typeof(long))
244 {
245 writer.WriteInt64((long)value);
246 return;
247 }
248 if (type == typeof(sbyte))
249 {
250 writer.WriteSByte((sbyte)value);
251 return;
252 }
253 if (type == typeof(float))
254 {
255 writer.WriteSingle((float)value);
256 return;
257 }
258 if (type == typeof(ushort))
259 {
260 writer.WriteUInt16((ushort)value);
261 return;
262 }
263 if (type == typeof(uint))
264 {
265 writer.WriteUInt32((uint)value);
266 return;
267 }
268 if (type == typeof(ulong))
269 {
270 writer.WriteUInt64((ulong)value);
271 return;
272 }
274 }
275}
static Type GetUnderlyingType(Type enumType)
Definition Enum.cs:309
static void WriteCompressedSignedInteger(BlobBuilder writer, int value)
static void WriteConstant(BlobBuilder writer, object? value)
static void WriteCompressedSignedInteger(ref BlobWriter writer, int value)
static void WriteCompressedInteger(ref BlobWriter writer, uint value)
static void WriteCompressedInteger(BlobBuilder writer, uint value)
static void WriteConstant(ref BlobWriter writer, object? value)
static void ValueArgumentOutOfRange()
Definition Throw.cs:180
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string InvalidConstantValueOfType
Definition SR.cs:130
Definition SR.cs:7
static ? Type GetType(string typeName, bool throwOnError, bool ignoreCase)
Definition Type.cs:408