forked from Unity-Technologies/com.unity.netcode.gameobjects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathByteBool.cs
More file actions
33 lines (29 loc) · 815 Bytes
/
ByteBool.cs
File metadata and controls
33 lines (29 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System.Runtime.InteropServices;
namespace MLAPI.Serialization
{
[StructLayout(LayoutKind.Explicit)]
internal struct ByteBool
{
[FieldOffset(0)]
public bool BoolValue;
[FieldOffset(0)]
public byte ByteValue;
public byte Collapse() =>
ByteValue = (byte)((
// Collapse all bits to position 1 and reassign as bit
(ByteValue >> 7) |
(ByteValue >> 6) |
(ByteValue >> 5) |
(ByteValue >> 4) |
(ByteValue >> 3) |
(ByteValue >> 2) |
(ByteValue >> 1) |
ByteValue
) & 1);
public byte Collapse(bool b)
{
BoolValue = b;
return Collapse();
}
}
}