I am trying to deserialize a MsgPack packet that I have in a byte array like this:
47 52 209 0 144 209 0 144 72 86 54 195 209 66 73
And I want to get it into an object of this type:
public class Info
{
public byte wX;
public byte wY;
public Int16 wMXCount;
public Int16 wMYCount;
public byte wMZCount;
public byte wMRegionZ;
public byte wZ;
public bool m;
public Int16 tkn;
}
I am using MsgPack.CLI to try to deserialize it as seen here.
static public T Deserialize<T>(byte[] bytes)
{
var serializer = MessagePackSerializer.Get<T>();
using (var byteStream = new MemoryStream(bytes))
{
return serializer.Unpack(byteStream);
}
}
and then run it with
Info mi2;
mi2 = Deserialize<Info>(bytes); //bytes is the byte array that contains the MsgPack
Unfortunately mi2 is just like a newly created Info and does not contain any of the data from the MsgPacket. It would be really great if someone has an idea of how to get this working.
Thanks a lot!
Update
I made a dummy Info and tried to emulate something similar to the data above and serializing it myself. What I get is first of all a 153 in front (id for fixed array with 9 elements) which makes sense, I had forgotten that, but also the elements are in a different order.
It appears they are in alphabetical order! Is there a way to map/deserialize them like they are ordered in the class or do I have to change the names of my fields to awX, bwY, cwMXCount... Is there a flag somewhere to deserialize them in a specific way?