Skip to content

Commit

Permalink
When deserialize length is 0, the return array should be Array.Empty<…
Browse files Browse the repository at this point in the history
…T>().
  • Loading branch information
pCYSl5EDgo committed Sep 14, 2020
1 parent ebdb29c commit f284088
Showing 1 changed file with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,30 @@ public T[] Deserialize(ref MessagePackReader reader, MessagePackSerializerOption
{
return default;
}
else

var len = reader.ReadArrayHeader();
if (len == 0)
{
IMessagePackFormatter<T> formatter = options.Resolver.GetFormatterWithVerify<T>();
return Array.Empty<T>();
}

var len = reader.ReadArrayHeader();
var array = new T[len];
options.Security.DepthStep(ref reader);
try
{
for (int i = 0; i < array.Length; i++)
{
reader.CancellationToken.ThrowIfCancellationRequested();
array[i] = formatter.Deserialize(ref reader, options);
}
}
finally
IMessagePackFormatter<T> formatter = options.Resolver.GetFormatterWithVerify<T>();
var array = new T[len];
options.Security.DepthStep(ref reader);
try
{
for (int i = 0; i < array.Length; i++)
{
reader.Depth--;
reader.CancellationToken.ThrowIfCancellationRequested();
array[i] = formatter.Deserialize(ref reader, options);
}

return array;
}
finally
{
reader.Depth--;
}

return array;
}
}

Expand Down

0 comments on commit f284088

Please sign in to comment.