Skip to content

Commit 4633163

Browse files
committed
Changed UIntFloat field names and added XML explanation
1 parent 757ac49 commit 4633163

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

MLAPI/NetworkingManagerComponents/Binary/BitStream.cs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,26 @@ namespace MLAPI.NetworkingManagerComponents.Binary
1313
public sealed class BitStream : Stream
1414
{
1515

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>
1622
[StructLayout(LayoutKind.Explicit)]
1723
internal struct UIntFloat
1824
{
1925
[FieldOffset(0)]
2026
public float floatValue;
2127

2228
[FieldOffset(0)]
23-
public uint intValue;
29+
public uint uintValue;
2430

2531
[FieldOffset(0)]
2632
public double doubleValue;
2733

2834
[FieldOffset(0)]
29-
public ulong longValue;
35+
public ulong ulongValue;
3036
}
3137

3238

@@ -304,7 +310,7 @@ public void WriteSingle(float value)
304310
WriteUInt32(new UIntFloat
305311
{
306312
floatValue = value
307-
}.intValue);
313+
}.uintValue);
308314
}
309315

310316
/// <summary>
@@ -316,7 +322,7 @@ public void WriteDouble(double value)
316322
WriteUInt64(new UIntFloat
317323
{
318324
doubleValue = value
319-
}.longValue);
325+
}.ulongValue);
320326

321327
}
322328

@@ -329,7 +335,7 @@ public void WriteSinglePacked(float value)
329335
WriteUInt32Packed(new UIntFloat
330336
{
331337
floatValue = value
332-
}.intValue);
338+
}.uintValue);
333339
}
334340

335341
/// <summary>
@@ -341,7 +347,7 @@ public void WriteDoublePacked(double value)
341347
WriteUInt64Packed(new UIntFloat
342348
{
343349
doubleValue = value
344-
}.longValue);
350+
}.ulongValue);
345351
}
346352

347353
/// <summary>
@@ -522,7 +528,7 @@ public float ReadSingle()
522528
{
523529
return new UIntFloat
524530
{
525-
intValue = ReadUInt32()
531+
uintValue = ReadUInt32()
526532
}.floatValue;
527533
}
528534

@@ -535,7 +541,7 @@ public double ReadDouble()
535541
{
536542
return new UIntFloat
537543
{
538-
longValue = ReadUInt64()
544+
ulongValue = ReadUInt64()
539545
}.doubleValue;
540546
}
541547

@@ -548,7 +554,7 @@ public float ReadSinglePacked()
548554
{
549555
return new UIntFloat
550556
{
551-
intValue = ReadUInt32Packed()
557+
uintValue = ReadUInt32Packed()
552558
}.floatValue;
553559
}
554560

@@ -560,7 +566,7 @@ public double ReadDoublePacked()
560566
{
561567
return new UIntFloat
562568
{
563-
longValue = ReadUInt64Packed()
569+
ulongValue = ReadUInt64Packed()
564570
}.doubleValue;
565571
}
566572

0 commit comments

Comments
 (0)