Skip to content

Commit

Permalink
fix: fixing span support UNITY_2021_3_OR_NEWER
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Frowen committed Mar 12, 2024
1 parent 3c48db8 commit 7bf28ed
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Assets/Mirage/Runtime/Serialization/CollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public static void WriteDictionary<TKey, TValue>(this NetworkWriter writer, Dict
}
}

#if UNITY_2021_3_OR_NEWER
[WeaverSerializeCollection]
public static void WriteSpan<T>(this NetworkWriter writer, Span<T> span) => WriteReadOnlySpan<T>(writer, span);
[WeaverSerializeCollection]
Expand All @@ -114,6 +115,7 @@ public static void WriteReadOnlySpan<T>(this NetworkWriter writer, ReadOnlySpan<
for (var i = 0; i < length; i++)
writer.Write(span[i]);
}
#endif

/// <returns>array or null</returns>
public static byte[] ReadBytesAndSize(this NetworkReader reader)
Expand Down Expand Up @@ -203,6 +205,7 @@ public static Dictionary<TKey, TValue> ReadDictionary<TKey, TValue>(this Network
return result;
}

#if UNITY_2021_3_OR_NEWER
[WeaverSerializeCollection]
public static Span<T> ReadSpan<T>(this NetworkReader reader)
{
Expand All @@ -218,7 +221,7 @@ public static Span<T> ReadSpan<T>(this NetworkReader reader)
}
[WeaverSerializeCollection]
public static ReadOnlySpan<T> ReadReadOnlySpan<T>(this NetworkReader reader) => ReadSpan<T>(reader);

#endif

/// <summary>Writes null as 0, and all over values as +1</summary>
/// <param name="count">The real count or null if collection is is null</param>
Expand Down

0 comments on commit 7bf28ed

Please sign in to comment.