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
37 lines (33 loc) · 864 Bytes
/
Copy pathByteBool.cs
File metadata and controls
37 lines (33 loc) · 864 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
34
35
36
37
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
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();
}
}
}