diff --git a/src/NexusMods.EventSourcing/Serialization/ArraySerializer.cs b/src/NexusMods.EventSourcing/Serialization/ArraySerializer.cs index 5d28cdf5..9f5f092b 100644 --- a/src/NexusMods.EventSourcing/Serialization/ArraySerializer.cs +++ b/src/NexusMods.EventSourcing/Serialization/ArraySerializer.cs @@ -119,15 +119,14 @@ public bool TryGetFixedSize(Type valueType, out int size) public void Serialize(TItem[] value, TWriter output) where TWriter : IBufferWriter { - var totalSize = sizeof(ushort) + (itemSize * value.Length); - var span = output.GetSpan(totalSize); - BinaryPrimitives.WriteUInt32BigEndian(span, (ushort)value.Length); + var span = output.GetSpan(sizeof(ushort)); + BinaryPrimitives.WriteUInt16BigEndian(span, (ushort)value.Length); + output.Advance(sizeof(ushort)); foreach (var item in value) { itemSerializer.Serialize(item, output); } - output.Advance(totalSize); } public int Deserialize(ReadOnlySpan from, out TItem[] value) @@ -135,7 +134,6 @@ public int Deserialize(ReadOnlySpan from, out TItem[] value) var size = BinaryPrimitives.ReadUInt16BigEndian(from); var array = GC.AllocateUninitializedArray(size); - from = from.SliceFast(sizeof(ushort)); var offset = sizeof(ushort); for (var i = 0; i < size; i++) {