@@ -13,20 +13,26 @@ namespace MLAPI.NetworkingManagerComponents.Binary
13
13
public sealed class BitStream : Stream
14
14
{
15
15
16
+ /// <summary>
17
+ /// A struct with a explicit memory layout. The struct has 4 fields. float,uint,double and ulong.
18
+ /// Every field has the same starting point in memory. If you insert a float value, it can be extracted as a uint.
19
+ /// This is to allow for lockless & garbage free conversion from float to uint and double to ulong.
20
+ /// This allows for VarInt encoding and other integer encodings.
21
+ /// </summary>
16
22
[ StructLayout ( LayoutKind . Explicit ) ]
17
23
internal struct UIntFloat
18
24
{
19
25
[ FieldOffset ( 0 ) ]
20
26
public float floatValue ;
21
27
22
28
[ FieldOffset ( 0 ) ]
23
- public uint intValue ;
29
+ public uint uintValue ;
24
30
25
31
[ FieldOffset ( 0 ) ]
26
32
public double doubleValue ;
27
33
28
34
[ FieldOffset ( 0 ) ]
29
- public ulong longValue ;
35
+ public ulong ulongValue ;
30
36
}
31
37
32
38
@@ -304,7 +310,7 @@ public void WriteSingle(float value)
304
310
WriteUInt32 ( new UIntFloat
305
311
{
306
312
floatValue = value
307
- } . intValue ) ;
313
+ } . uintValue ) ;
308
314
}
309
315
310
316
/// <summary>
@@ -316,7 +322,7 @@ public void WriteDouble(double value)
316
322
WriteUInt64 ( new UIntFloat
317
323
{
318
324
doubleValue = value
319
- } . longValue ) ;
325
+ } . ulongValue ) ;
320
326
321
327
}
322
328
@@ -329,7 +335,7 @@ public void WriteSinglePacked(float value)
329
335
WriteUInt32Packed ( new UIntFloat
330
336
{
331
337
floatValue = value
332
- } . intValue ) ;
338
+ } . uintValue ) ;
333
339
}
334
340
335
341
/// <summary>
@@ -341,7 +347,7 @@ public void WriteDoublePacked(double value)
341
347
WriteUInt64Packed ( new UIntFloat
342
348
{
343
349
doubleValue = value
344
- } . longValue ) ;
350
+ } . ulongValue ) ;
345
351
}
346
352
347
353
/// <summary>
@@ -522,7 +528,7 @@ public float ReadSingle()
522
528
{
523
529
return new UIntFloat
524
530
{
525
- intValue = ReadUInt32 ( )
531
+ uintValue = ReadUInt32 ( )
526
532
} . floatValue ;
527
533
}
528
534
@@ -535,7 +541,7 @@ public double ReadDouble()
535
541
{
536
542
return new UIntFloat
537
543
{
538
- longValue = ReadUInt64 ( )
544
+ ulongValue = ReadUInt64 ( )
539
545
} . doubleValue ;
540
546
}
541
547
@@ -548,7 +554,7 @@ public float ReadSinglePacked()
548
554
{
549
555
return new UIntFloat
550
556
{
551
- intValue = ReadUInt32Packed ( )
557
+ uintValue = ReadUInt32Packed ( )
552
558
} . floatValue ;
553
559
}
554
560
@@ -560,7 +566,7 @@ public double ReadDoublePacked()
560
566
{
561
567
return new UIntFloat
562
568
{
563
- longValue = ReadUInt64Packed ( )
569
+ ulongValue = ReadUInt64Packed ( )
564
570
} . doubleValue ;
565
571
}
566
572
0 commit comments