diff --git a/Ragon.Client/Sources/Entity/RagonEntity.cs b/Ragon.Client/Sources/Entity/RagonEntity.cs index b76db76..9cd5287 100644 --- a/Ragon.Client/Sources/Entity/RagonEntity.cs +++ b/Ragon.Client/Sources/Entity/RagonEntity.cs @@ -84,17 +84,22 @@ namespace Ragon.Client internal T GetPayload(RagonPayload data) where T : IRagonPayload, new() { - var buffer = new RagonBuffer(); - data.Write(buffer); - var payload = new T(); + if (data.Size <= 0) return payload; + + var buffer = new RagonBuffer(); + + data.Write(buffer); + payload.Deserialize(buffer); - + return payload; } - public void PreAttach(IRagonPayload payload) + public void AttachPayload(IRagonPayload? payload) { + if (payload == null) return; + var buffer = new RagonBuffer(); payload.Serialize(buffer); diff --git a/Ragon.Client/Sources/Entity/RagonPayload.cs b/Ragon.Client/Sources/Entity/RagonPayload.cs index dcb7a77..d81dc23 100644 --- a/Ragon.Client/Sources/Entity/RagonPayload.cs +++ b/Ragon.Client/Sources/Entity/RagonPayload.cs @@ -21,8 +21,8 @@ namespace Ragon.Client; public struct RagonPayload { - private uint[] _data = new uint[128]; - private int _size = 0; + private readonly uint[] _data = new uint[128]; + private readonly int _size = 0; public RagonPayload(int capacity) {