Skip to content

Commit

Permalink
Fix remaining tests
Browse files Browse the repository at this point in the history
  • Loading branch information
halgari committed Jan 10, 2024
1 parent d194b0f commit e093328
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/NexusMods.EventSourcing/Serialization/ArraySerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,23 +119,21 @@ public bool TryGetFixedSize(Type valueType, out int size)

public void Serialize<TWriter>(TItem[] value, TWriter output) where TWriter : IBufferWriter<byte>
{
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<byte> from, out TItem[] value)
{
var size = BinaryPrimitives.ReadUInt16BigEndian(from);
var array = GC.AllocateUninitializedArray<TItem>(size);

from = from.SliceFast(sizeof(ushort));
var offset = sizeof(ushort);
for (var i = 0; i < size; i++)
{
Expand Down

0 comments on commit e093328

Please sign in to comment.