Skip to content

Commit

Permalink
Merge pull request #1575 from AArnott/fix1574
Browse files Browse the repository at this point in the history
Fix PrimitiveObjectResolver's ability to read strings
  • Loading branch information
AArnott committed Mar 14, 2023
2 parents 1d322ca + aa8acaf commit cb44cb8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ public void Serialize(ref MessagePackWriter writer, object? value, MessagePackSe
}

case MessagePackType.String:
var stringFormatter = options.Resolver.GetFormatterWithVerify<string?>();
return stringFormatter.Deserialize(ref reader, options);
IMessagePackFormatter<string?>? stringFormatter = options.Resolver.GetFormatter<string?>();
return stringFormatter is not null ? stringFormatter.Deserialize(ref reader, options) : reader.ReadString();
case MessagePackType.Binary:
// We must copy the sequence returned by ReadBytes since the reader's sequence is only valid during deserialization.
return reader.ReadBytes()?.ToArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ public void CompressibleIntegersRetainTypeInfo<T>(T value)
Assert.Equal(value, result);
}

[Fact]
public void StringType()
{
byte[] msgpack = MessagePackSerializer.Serialize<object>("message", PrimitiveObjectResolver.Options);
string result = (string)MessagePackSerializer.Deserialize<object>(msgpack, PrimitiveObjectResolver.Options);
}

[Fact]
public void IL2CPPHint()
{
Expand Down

0 comments on commit cb44cb8

Please sign in to comment.