using Newtonsoft.Json;
using System;
namespace Message
{
///
/// Message class to handle traffic between clients and server
///
public class Message
{
///
/// identifier for the message
///
public string Identifier
{
get;set;
}
///
/// payload of the message, the actual text
///
public string Payload
{
get;set;
}
///
/// constructs a new message with the given parameters
///
/// the identifier
/// the payload
public Message(string identifier, string payload)
{
this.Identifier = identifier;
this.Payload = payload;
}
///
/// serializes this object to a JSON string
///
/// a JSON representation of this object
public string Serialize()
{
return JsonConvert.SerializeObject(this);
}
///
/// deserializes a JSON string into a new Message object
///
/// the JSON string to deserialize
/// a new Message object from the JSON string
public static Message Deserialize(string json)
{
return (Message)JsonConvert.DeserializeObject(json);
}
}
}