我尝试像这样序列化和反序列化:
var mem = new MemoryStream();
MessagePackBinary.WriteInt64(mem, 1580358);
var result = MessagePackBinary.ReadInt64(mem);`
//System.InvalidOperationException: 'Invalid MessagePack code was detected, code:-1'
但是我有错误。 我做错了什么? 谢谢!
使用库:MessagePack repo
答案 0 :(得分:3)
您应将视频流倒回到初始位置,以回读您在此处写的内容:
var mem = new MemoryStream();
MessagePackBinary.WriteInt64(mem, 1580358);
mem.Seek(0, SeekOrigin.Begin); // added
var result = MessagePackBinary.ReadInt64(mem);
Console.WriteLine(result);