forked from Unity-Technologies/com.unity.netcode.gameobjects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUIntFloat.cs
More file actions
30 lines (26 loc) · 912 Bytes
/
Copy pathUIntFloat.cs
File metadata and controls
30 lines (26 loc) · 912 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
namespace MLAPI.Serialization
{
/// <summary>
/// A struct with a explicit memory layout. The struct has 4 fields. float,uint,double and ulong.
/// Every field has the same starting point in memory. If you insert a float value, it can be extracted as a uint.
/// This is to allow for lockless and garbage free conversion from float to uint and double to ulong.
/// This allows for VarInt encoding and other integer encodings.
/// </summary>
[StructLayout(LayoutKind.Explicit)]
internal struct UIntFloat
{
[FieldOffset(0)]
public float floatValue;
[FieldOffset(0)]
public uint uintValue;
[FieldOffset(0)]
public double doubleValue;
[FieldOffset(0)]
public ulong ulongValue;
}
}