public static byte[] ToBin(this object obj)
{
return MessagePack.MessagePackSerializer.Serialize(obj.GetType(), obj);
}
public static T FromBin(this byte[] bytes)
{
ReadOnlyMemory<byte> temp = new ReadOnlyMemory<byte>(bytes);
return (T)MessagePack.MessagePackSerializer.Deserialize(typeof(T), temp);
}
public static T ToObj(this object obj)
{
var opt = MessagePackSerializerOptions.Standard.WithResolver(
MessagePack.Resolvers.ContractlessStandardResolverAllowPrivate.Instance);
var bytes = MessagePack.MessagePackSerializer.Serialize(obj.GetType(), obj, opt);
ReadOnlyMemory<byte> temp = new ReadOnlyMemory<byte>(bytes);
return (T)MessagePack.MessagePackSerializer.Deserialize(typeof(T), temp, opt);
}