24 lines
641 B
C#
24 lines
641 B
C#
using Newtonsoft.Json;
|
|
using Worker.Messaging.Messages;
|
|
using System.Text;
|
|
|
|
namespace Worker.Messaging
|
|
{
|
|
public class MessageHelper
|
|
{
|
|
public static byte[] ToData<TMessage>(TMessage message)
|
|
where TMessage : Message
|
|
{
|
|
var json = JsonConvert.SerializeObject(message);
|
|
return Encoding.Unicode.GetBytes(json);
|
|
}
|
|
|
|
public static TMessage FromData<TMessage>(byte[] data)
|
|
where TMessage : Message
|
|
{
|
|
var json = Encoding.Unicode.GetString(data);
|
|
return (TMessage)JsonConvert.DeserializeObject<TMessage>(json);
|
|
}
|
|
}
|
|
}
|