msgpack-cli
msgpack-cli copied to clipboard
context.GetSerializer with type in parameter not work well
hi, somes problem when you use serializer from context.GetSerializer
public class SimpleItem
{
public int Id;
public SimpleItem()
{
}
}
var item = new SimpleItem();
var stream = new MemoryStream();
var context = new SerializationContext();
classique use, is work well
var serializer = context.GetSerializer<SimpleItem>();
serializer .Pack(stream, items);
stream.Position = 0;
var cloneItems = serializer .Unpack(stream);
but when you try this
var serializer = context.GetSerializer(item.GetType() );
var packer = MsgPack.Packer.Create(stream, varcontext.CompatibilityOptions.PackerCompatibilityOptions);
serializer .PackTo(packer, item);
stream.Position = 0;
var cloneItems = serializer .UnpackFrom(MsgPack.Unpacker.Create(stream));
cloneItems is null. Does not seem normall!!
Thank you for reporting. I will investigate it too.
You must call Unpacker.Read()
before you pass it to UnpackFrom
.
This is by design for performance, but I found that there is no document of it.
I will consider convenient API for this in the future.