Skip to content

Instantly share code, notes, and snippets.

@AldeRoberge
Created January 9, 2021 20:22
Show Gist options
  • Save AldeRoberge/0e03e1aacbe8f373b7e4c9dd677b6fd3 to your computer and use it in GitHub Desktop.
Save AldeRoberge/0e03e1aacbe8f373b7e4c9dd677b6fd3 to your computer and use it in GitHub Desktop.
using LiteNetLib.Utils;
namespace AG_LNL_Shared.Networking.World.Packets.DataObjects.Base.Utils
{
/// <summary>
/// Utils to serialize and deserialize arrays.
/// </summary>
public static class NetworkArray
{
public static T[] Deserialize<T>(NetDataReader rdr) where T : DataObject, new()
{
T[] t = new T[rdr.GetInt()];
for (int i = 0; i < t.Length; i++)
{
T value = new T();
value.ReadFromInput(rdr);
t[i] = value;
}
return t;
}
public static void Serialize<T>(T[] t, NetDataWriter wtr) where T : DataObject, new()
{
wtr.Put(t.Length);
foreach (T newObject in t)
{
newObject.WriteToOutput(wtr);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment