diff --git a/Message/Message.cs b/Message/Message.cs new file mode 100644 index 0000000..f60fe2e --- /dev/null +++ b/Message/Message.cs @@ -0,0 +1,59 @@ +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); + } + } + + +}