com.wallstop-studios.dxmessaging 2.0.0-rc26.7 → 2.0.0-rc26.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,29 +9,36 @@ namespace DxMessaging.Core.Extensions
9
9
  internal static bool HasFlagNoAlloc<T>(this T value, T flag)
10
10
  where T : unmanaged, Enum
11
11
  {
12
- ulong valueUnderlying = GetUInt64(value);
13
- ulong flagUnderlying = GetUInt64(flag);
14
- return (valueUnderlying & flagUnderlying) == flagUnderlying;
12
+ ulong? valueUnderlying = GetUInt64(value);
13
+ ulong? flagUnderlying = GetUInt64(flag);
14
+ if (valueUnderlying == null || flagUnderlying == null)
15
+ {
16
+ // Fallback for unsupported enum sizes
17
+ return value.HasFlag(flag);
18
+ }
19
+
20
+ return (valueUnderlying.Value & flagUnderlying.Value) == flagUnderlying.Value;
15
21
  }
16
22
 
17
23
  [MethodImpl(MethodImplOptions.AggressiveInlining)]
18
- private static unsafe ulong GetUInt64<T>(T value)
24
+ private static ulong? GetUInt64<T>(T value)
19
25
  where T : unmanaged
20
26
  {
21
- /*
22
- Works because T is constrained to unmanaged, so it's safe to reinterpret
23
- All enums are value types and have a fixed size
24
- */
25
- return sizeof(T) switch
27
+ try
28
+ {
29
+ return Unsafe.SizeOf<T>() switch
30
+ {
31
+ 1 => Unsafe.As<T, byte>(ref value),
32
+ 2 => Unsafe.As<T, ushort>(ref value),
33
+ 4 => Unsafe.As<T, uint>(ref value),
34
+ 8 => Unsafe.As<T, ulong>(ref value),
35
+ _ => null,
36
+ };
37
+ }
38
+ catch
26
39
  {
27
- 1 => *(byte*)&value,
28
- 2 => *(ushort*)&value,
29
- 4 => *(uint*)&value,
30
- 8 => *(ulong*)&value,
31
- _ => throw new ArgumentException(
32
- $"Unsupported enum size: {sizeof(T)} for type {typeof(T)}"
33
- ),
34
- };
40
+ return null;
41
+ }
35
42
  }
36
43
  }
37
44
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.wallstop-studios.dxmessaging",
3
- "version": "2.0.0-rc26.7",
3
+ "version": "2.0.0-rc26.8",
4
4
  "displayName": "DxMessaging",
5
5
  "description": "Synchronous Event Bus for Unity",
6
6
  "unity": "2021.3",
@@ -39,3 +39,4 @@
39
39
 
40
40
 
41
41
 
42
+