Terraria v1.4.4.9
Terraria source code documentation
All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Macros
BinaryPrimitives.cs
Go to the documentation of this file.
4
6
7public static class BinaryPrimitives
8{
9 [MethodImpl(MethodImplOptions.AggressiveInlining)]
10 [CLSCompliant(false)]
11 public static sbyte ReverseEndianness(sbyte value)
12 {
13 return value;
14 }
15
16 [MethodImpl(MethodImplOptions.AggressiveInlining)]
17 [Intrinsic]
18 public static short ReverseEndianness(short value)
19 {
20 return (short)ReverseEndianness((ushort)value);
21 }
22
23 [MethodImpl(MethodImplOptions.AggressiveInlining)]
24 [Intrinsic]
25 public static int ReverseEndianness(int value)
26 {
27 return (int)ReverseEndianness((uint)value);
28 }
29
30 [MethodImpl(MethodImplOptions.AggressiveInlining)]
31 [Intrinsic]
32 public static long ReverseEndianness(long value)
33 {
34 return (long)ReverseEndianness((ulong)value);
35 }
36
37 [MethodImpl(MethodImplOptions.AggressiveInlining)]
38 public static byte ReverseEndianness(byte value)
39 {
40 return value;
41 }
42
43 [MethodImpl(MethodImplOptions.AggressiveInlining)]
44 [CLSCompliant(false)]
45 [Intrinsic]
46 public static ushort ReverseEndianness(ushort value)
47 {
48 return (ushort)((value >> 8) + (value << 8));
49 }
50
51 [MethodImpl(MethodImplOptions.AggressiveInlining)]
52 [CLSCompliant(false)]
53 [Intrinsic]
54 public static uint ReverseEndianness(uint value)
55 {
56 return BitOperations.RotateRight(value & 0xFF00FFu, 8) + BitOperations.RotateLeft(value & 0xFF00FF00u, 8);
57 }
58
59 [MethodImpl(MethodImplOptions.AggressiveInlining)]
60 [CLSCompliant(false)]
61 [Intrinsic]
62 public static ulong ReverseEndianness(ulong value)
63 {
64 return ((ulong)ReverseEndianness((uint)value) << 32) + ReverseEndianness((uint)(value >> 32));
65 }
66
67 [MethodImpl(MethodImplOptions.AggressiveInlining)]
75
76 [MethodImpl(MethodImplOptions.AggressiveInlining)]
84
85 [MethodImpl(MethodImplOptions.AggressiveInlining)]
87 {
88 short value = MemoryMarshal.Read<short>(source);
91 }
92
93 [MethodImpl(MethodImplOptions.AggressiveInlining)]
95 {
96 int value = MemoryMarshal.Read<int>(source);
99 }
100
101 [MethodImpl(MethodImplOptions.AggressiveInlining)]
103 {
104 long value = MemoryMarshal.Read<long>(source);
106 return ReverseEndianness(value);
107 }
108
109 [MethodImpl(MethodImplOptions.AggressiveInlining)]
117
118 [MethodImpl(MethodImplOptions.AggressiveInlining)]
119 [CLSCompliant(false)]
121 {
122 ushort value = MemoryMarshal.Read<ushort>(source);
124 return ReverseEndianness(value);
125 }
126
127 [MethodImpl(MethodImplOptions.AggressiveInlining)]
128 [CLSCompliant(false)]
130 {
131 uint value = MemoryMarshal.Read<uint>(source);
133 return ReverseEndianness(value);
134 }
135
136 [MethodImpl(MethodImplOptions.AggressiveInlining)]
137 [CLSCompliant(false)]
139 {
140 ulong value = MemoryMarshal.Read<ulong>(source);
142 return ReverseEndianness(value);
143 }
144
145 [MethodImpl(MethodImplOptions.AggressiveInlining)]
147 {
149 long value2;
150 bool result = MemoryMarshal.TryRead<long>(source, out value2);
152 return result;
153 }
154
155 [MethodImpl(MethodImplOptions.AggressiveInlining)]
157 {
159 short value2;
160 bool result = MemoryMarshal.TryRead<short>(source, out value2);
162 return result;
163 }
164
165 [MethodImpl(MethodImplOptions.AggressiveInlining)]
167 {
169 short value2;
170 bool result = MemoryMarshal.TryRead<short>(source, out value2);
171 value = ReverseEndianness(value2);
172 return result;
173 }
174
175 [MethodImpl(MethodImplOptions.AggressiveInlining)]
177 {
179 int value2;
180 bool result = MemoryMarshal.TryRead<int>(source, out value2);
181 value = ReverseEndianness(value2);
182 return result;
183 }
184
185 [MethodImpl(MethodImplOptions.AggressiveInlining)]
187 {
189 long value2;
190 bool result = MemoryMarshal.TryRead<long>(source, out value2);
191 value = ReverseEndianness(value2);
192 return result;
193 }
194
196 {
198 int value2;
199 bool result = MemoryMarshal.TryRead<int>(source, out value2);
201 return result;
202 }
203
204 [MethodImpl(MethodImplOptions.AggressiveInlining)]
205 [CLSCompliant(false)]
207 {
209 ushort value2;
210 bool result = MemoryMarshal.TryRead<ushort>(source, out value2);
211 value = ReverseEndianness(value2);
212 return result;
213 }
214
215 [MethodImpl(MethodImplOptions.AggressiveInlining)]
216 [CLSCompliant(false)]
218 {
220 uint value2;
221 bool result = MemoryMarshal.TryRead<uint>(source, out value2);
222 value = ReverseEndianness(value2);
223 return result;
224 }
225
226 [MethodImpl(MethodImplOptions.AggressiveInlining)]
227 [CLSCompliant(false)]
229 {
231 ulong value2;
232 bool result = MemoryMarshal.TryRead<ulong>(source, out value2);
233 value = ReverseEndianness(value2);
234 return result;
235 }
236
237 [MethodImpl(MethodImplOptions.AggressiveInlining)]
239 {
241 return MemoryMarshal.Read<double>(source);
242 }
243
244 [MethodImpl(MethodImplOptions.AggressiveInlining)]
250
251 [MethodImpl(MethodImplOptions.AggressiveInlining)]
253 {
254 short result = MemoryMarshal.Read<short>(source);
256 {
257 }
258 return result;
259 }
260
261 [MethodImpl(MethodImplOptions.AggressiveInlining)]
263 {
264 int result = MemoryMarshal.Read<int>(source);
266 {
267 }
268 return result;
269 }
270
271 [MethodImpl(MethodImplOptions.AggressiveInlining)]
273 {
274 long result = MemoryMarshal.Read<long>(source);
276 {
277 }
278 return result;
279 }
280
281 [MethodImpl(MethodImplOptions.AggressiveInlining)]
283 {
285 return MemoryMarshal.Read<float>(source);
286 }
287
288 [MethodImpl(MethodImplOptions.AggressiveInlining)]
289 [CLSCompliant(false)]
291 {
292 ushort result = MemoryMarshal.Read<ushort>(source);
294 {
295 }
296 return result;
297 }
298
299 [MethodImpl(MethodImplOptions.AggressiveInlining)]
300 [CLSCompliant(false)]
302 {
303 uint result = MemoryMarshal.Read<uint>(source);
305 {
306 }
307 return result;
308 }
309
310 [MethodImpl(MethodImplOptions.AggressiveInlining)]
311 [CLSCompliant(false)]
313 {
314 ulong result = MemoryMarshal.Read<ulong>(source);
316 {
317 }
318 return result;
319 }
320
321 [MethodImpl(MethodImplOptions.AggressiveInlining)]
323 {
325 {
326 }
327 return MemoryMarshal.TryRead<double>(source, out value);
328 }
329
330 [MethodImpl(MethodImplOptions.AggressiveInlining)]
332 {
334 {
335 }
336 return MemoryMarshal.TryRead<Half>(source, out value);
337 }
338
339 [MethodImpl(MethodImplOptions.AggressiveInlining)]
341 {
343 return MemoryMarshal.TryRead<short>(source, out value);
344 }
345
346 [MethodImpl(MethodImplOptions.AggressiveInlining)]
348 {
350 return MemoryMarshal.TryRead<int>(source, out value);
351 }
352
353 [MethodImpl(MethodImplOptions.AggressiveInlining)]
355 {
357 return MemoryMarshal.TryRead<long>(source, out value);
358 }
359
361 {
363 {
364 }
365 return MemoryMarshal.TryRead<float>(source, out value);
366 }
367
368 [MethodImpl(MethodImplOptions.AggressiveInlining)]
369 [CLSCompliant(false)]
371 {
373 return MemoryMarshal.TryRead<ushort>(source, out value);
374 }
375
376 [MethodImpl(MethodImplOptions.AggressiveInlining)]
377 [CLSCompliant(false)]
379 {
381 return MemoryMarshal.TryRead<uint>(source, out value);
382 }
383
384 [MethodImpl(MethodImplOptions.AggressiveInlining)]
385 [CLSCompliant(false)]
387 {
389 return MemoryMarshal.TryRead<ulong>(source, out value);
390 }
391
392 [MethodImpl(MethodImplOptions.AggressiveInlining)]
394 {
397 MemoryMarshal.Write(destination, ref value2);
398 }
399
400 [MethodImpl(MethodImplOptions.AggressiveInlining)]
402 {
405 MemoryMarshal.Write(destination, ref value2);
406 }
407
408 [MethodImpl(MethodImplOptions.AggressiveInlining)]
415
416 [MethodImpl(MethodImplOptions.AggressiveInlining)]
423
424 [MethodImpl(MethodImplOptions.AggressiveInlining)]
431
432 [MethodImpl(MethodImplOptions.AggressiveInlining)]
434 {
437 MemoryMarshal.Write(destination, ref value2);
438 }
439
440 [MethodImpl(MethodImplOptions.AggressiveInlining)]
441 [CLSCompliant(false)]
448
449 [MethodImpl(MethodImplOptions.AggressiveInlining)]
450 [CLSCompliant(false)]
457
458 [MethodImpl(MethodImplOptions.AggressiveInlining)]
459 [CLSCompliant(false)]
466
467 [MethodImpl(MethodImplOptions.AggressiveInlining)]
469 {
472 return MemoryMarshal.TryWrite(destination, ref value2);
473 }
474
475 [MethodImpl(MethodImplOptions.AggressiveInlining)]
477 {
480 return MemoryMarshal.TryWrite(destination, ref value2);
481 }
482
483 [MethodImpl(MethodImplOptions.AggressiveInlining)]
485 {
488 return MemoryMarshal.TryWrite(destination, ref value);
489 }
490
491 [MethodImpl(MethodImplOptions.AggressiveInlining)]
493 {
496 return MemoryMarshal.TryWrite(destination, ref value);
497 }
498
499 [MethodImpl(MethodImplOptions.AggressiveInlining)]
501 {
504 return MemoryMarshal.TryWrite(destination, ref value);
505 }
506
507 [MethodImpl(MethodImplOptions.AggressiveInlining)]
509 {
512 return MemoryMarshal.TryWrite(destination, ref value2);
513 }
514
515 [MethodImpl(MethodImplOptions.AggressiveInlining)]
516 [CLSCompliant(false)]
518 {
521 return MemoryMarshal.TryWrite(destination, ref value);
522 }
523
524 [MethodImpl(MethodImplOptions.AggressiveInlining)]
525 [CLSCompliant(false)]
527 {
530 return MemoryMarshal.TryWrite(destination, ref value);
531 }
532
533 [MethodImpl(MethodImplOptions.AggressiveInlining)]
534 [CLSCompliant(false)]
536 {
539 return MemoryMarshal.TryWrite(destination, ref value);
540 }
541
542 [MethodImpl(MethodImplOptions.AggressiveInlining)]
544 {
546 {
547 }
548 MemoryMarshal.Write(destination, ref value);
549 }
550
551 [MethodImpl(MethodImplOptions.AggressiveInlining)]
553 {
555 {
556 }
557 MemoryMarshal.Write(destination, ref value);
558 }
559
560 [MethodImpl(MethodImplOptions.AggressiveInlining)]
562 {
564 {
565 }
566 MemoryMarshal.Write(destination, ref value);
567 }
568
569 [MethodImpl(MethodImplOptions.AggressiveInlining)]
571 {
573 {
574 }
575 MemoryMarshal.Write(destination, ref value);
576 }
577
578 [MethodImpl(MethodImplOptions.AggressiveInlining)]
580 {
582 {
583 }
584 MemoryMarshal.Write(destination, ref value);
585 }
586
587 [MethodImpl(MethodImplOptions.AggressiveInlining)]
589 {
591 {
592 }
593 MemoryMarshal.Write(destination, ref value);
594 }
595
596 [MethodImpl(MethodImplOptions.AggressiveInlining)]
597 [CLSCompliant(false)]
599 {
601 {
602 }
603 MemoryMarshal.Write(destination, ref value);
604 }
605
606 [MethodImpl(MethodImplOptions.AggressiveInlining)]
607 [CLSCompliant(false)]
609 {
611 {
612 }
613 MemoryMarshal.Write(destination, ref value);
614 }
615
616 [MethodImpl(MethodImplOptions.AggressiveInlining)]
617 [CLSCompliant(false)]
619 {
621 {
622 }
623 MemoryMarshal.Write(destination, ref value);
624 }
625
626 [MethodImpl(MethodImplOptions.AggressiveInlining)]
628 {
630 {
631 }
632 return MemoryMarshal.TryWrite(destination, ref value);
633 }
634
635 [MethodImpl(MethodImplOptions.AggressiveInlining)]
637 {
639 {
640 }
641 return MemoryMarshal.TryWrite(destination, ref value);
642 }
643
644 [MethodImpl(MethodImplOptions.AggressiveInlining)]
646 {
648 {
649 }
650 return MemoryMarshal.TryWrite(destination, ref value);
651 }
652
653 [MethodImpl(MethodImplOptions.AggressiveInlining)]
655 {
657 {
658 }
659 return MemoryMarshal.TryWrite(destination, ref value);
660 }
661
662 [MethodImpl(MethodImplOptions.AggressiveInlining)]
664 {
666 {
667 }
668 return MemoryMarshal.TryWrite(destination, ref value);
669 }
670
671 [MethodImpl(MethodImplOptions.AggressiveInlining)]
673 {
675 {
676 }
677 return MemoryMarshal.TryWrite(destination, ref value);
678 }
679
680 [MethodImpl(MethodImplOptions.AggressiveInlining)]
681 [CLSCompliant(false)]
683 {
685 {
686 }
687 return MemoryMarshal.TryWrite(destination, ref value);
688 }
689
690 [MethodImpl(MethodImplOptions.AggressiveInlining)]
691 [CLSCompliant(false)]
693 {
695 {
696 }
697 return MemoryMarshal.TryWrite(destination, ref value);
698 }
699
700 [MethodImpl(MethodImplOptions.AggressiveInlining)]
701 [CLSCompliant(false)]
703 {
705 {
706 }
707 return MemoryMarshal.TryWrite(destination, ref value);
708 }
709}
static unsafe float Int32BitsToSingle(int value)
static unsafe int SingleToInt32Bits(float value)
static unsafe double Int64BitsToDouble(long value)
static unsafe long DoubleToInt64Bits(double value)
static unsafe Half Int16BitsToHalf(short value)
static readonly bool IsLittleEndian
static unsafe short HalfToInt16Bits(Half value)
static short ReadInt16LittleEndian(ReadOnlySpan< byte > source)
static ulong ReadUInt64LittleEndian(ReadOnlySpan< byte > source)
static bool TryReadInt16LittleEndian(ReadOnlySpan< byte > source, out short value)
static void WriteUInt32LittleEndian(Span< byte > destination, uint value)
static bool TryWriteSingleBigEndian(Span< byte > destination, float value)
static uint ReadUInt32BigEndian(ReadOnlySpan< byte > source)
static bool TryReadUInt32BigEndian(ReadOnlySpan< byte > source, out uint value)
static bool TryReadSingleBigEndian(ReadOnlySpan< byte > source, out float value)
static ushort ReadUInt16LittleEndian(ReadOnlySpan< byte > source)
static int ReadInt32BigEndian(ReadOnlySpan< byte > source)
static bool TryWriteUInt32BigEndian(Span< byte > destination, uint value)
static void WriteInt32LittleEndian(Span< byte > destination, int value)
static bool TryWriteUInt64BigEndian(Span< byte > destination, ulong value)
static bool TryWriteInt32BigEndian(Span< byte > destination, int value)
static bool TryWriteHalfLittleEndian(Span< byte > destination, Half value)
static void WriteInt16BigEndian(Span< byte > destination, short value)
static bool TryReadUInt64BigEndian(ReadOnlySpan< byte > source, out ulong value)
static bool TryWriteInt16LittleEndian(Span< byte > destination, short value)
static void WriteUInt32BigEndian(Span< byte > destination, uint value)
static short ReverseEndianness(short value)
static bool TryWriteUInt32LittleEndian(Span< byte > destination, uint value)
static void WriteUInt16LittleEndian(Span< byte > destination, ushort value)
static bool TryWriteDoubleBigEndian(Span< byte > destination, double value)
static bool TryReadUInt32LittleEndian(ReadOnlySpan< byte > source, out uint value)
static bool TryWriteInt64LittleEndian(Span< byte > destination, long value)
static void WriteUInt16BigEndian(Span< byte > destination, ushort value)
static bool TryWriteInt32LittleEndian(Span< byte > destination, int value)
static void WriteInt64BigEndian(Span< byte > destination, long value)
static uint ReverseEndianness(uint value)
static void WriteInt16LittleEndian(Span< byte > destination, short value)
static bool TryReadInt64BigEndian(ReadOnlySpan< byte > source, out long value)
static bool TryReadHalfBigEndian(ReadOnlySpan< byte > source, out Half value)
static long ReverseEndianness(long value)
static sbyte ReverseEndianness(sbyte value)
static ushort ReadUInt16BigEndian(ReadOnlySpan< byte > source)
static bool TryReadSingleLittleEndian(ReadOnlySpan< byte > source, out float value)
static bool TryWriteUInt16LittleEndian(Span< byte > destination, ushort value)
static bool TryReadInt32BigEndian(ReadOnlySpan< byte > source, out int value)
static bool TryWriteInt64BigEndian(Span< byte > destination, long value)
static uint ReadUInt32LittleEndian(ReadOnlySpan< byte > source)
static Half ReadHalfBigEndian(ReadOnlySpan< byte > source)
static bool TryWriteDoubleLittleEndian(Span< byte > destination, double value)
static bool TryReadHalfLittleEndian(ReadOnlySpan< byte > source, out Half value)
static float ReadSingleLittleEndian(ReadOnlySpan< byte > source)
static void WriteSingleBigEndian(Span< byte > destination, float value)
static bool TryWriteHalfBigEndian(Span< byte > destination, Half value)
static void WriteUInt64LittleEndian(Span< byte > destination, ulong value)
static bool TryReadInt16BigEndian(ReadOnlySpan< byte > source, out short value)
static bool TryReadInt64LittleEndian(ReadOnlySpan< byte > source, out long value)
static void WriteHalfLittleEndian(Span< byte > destination, Half value)
static bool TryReadInt32LittleEndian(ReadOnlySpan< byte > source, out int value)
static double ReadDoubleBigEndian(ReadOnlySpan< byte > source)
static ushort ReverseEndianness(ushort value)
static long ReadInt64BigEndian(ReadOnlySpan< byte > source)
static bool TryReadUInt16BigEndian(ReadOnlySpan< byte > source, out ushort value)
static bool TryWriteSingleLittleEndian(Span< byte > destination, float value)
static double ReadDoubleLittleEndian(ReadOnlySpan< byte > source)
static bool TryReadUInt16LittleEndian(ReadOnlySpan< byte > source, out ushort value)
static Half ReadHalfLittleEndian(ReadOnlySpan< byte > source)
static bool TryWriteUInt16BigEndian(Span< byte > destination, ushort value)
static int ReadInt32LittleEndian(ReadOnlySpan< byte > source)
static long ReadInt64LittleEndian(ReadOnlySpan< byte > source)
static void WriteSingleLittleEndian(Span< byte > destination, float value)
static byte ReverseEndianness(byte value)
static bool TryReadDoubleBigEndian(ReadOnlySpan< byte > source, out double value)
static bool TryReadUInt64LittleEndian(ReadOnlySpan< byte > source, out ulong value)
static void WriteDoubleBigEndian(Span< byte > destination, double value)
static float ReadSingleBigEndian(ReadOnlySpan< byte > source)
static void WriteInt32BigEndian(Span< byte > destination, int value)
static void WriteInt64LittleEndian(Span< byte > destination, long value)
static void WriteHalfBigEndian(Span< byte > destination, Half value)
static bool TryWriteUInt64LittleEndian(Span< byte > destination, ulong value)
static ulong ReverseEndianness(ulong value)
static bool TryReadDoubleLittleEndian(ReadOnlySpan< byte > source, out double value)
static bool TryWriteInt16BigEndian(Span< byte > destination, short value)
static ulong ReadUInt64BigEndian(ReadOnlySpan< byte > source)
static short ReadInt16BigEndian(ReadOnlySpan< byte > source)
static void WriteDoubleLittleEndian(Span< byte > destination, double value)
static void WriteUInt64BigEndian(Span< byte > destination, ulong value)
static uint RotateRight(uint value, int offset)
static uint RotateLeft(uint value, int offset)