using System.IO;

namespace ChatServer.util
{
  class MessageUtil
  {
    public static string ConvertToMessage(byte[] packet)
    {
      MemoryStream ms = new MemoryStream(packet);
      BinaryReader br = new BinaryReader(ms);

      string received = br.ReadString();

      ms.Close();
      br.Close();

      return received;
    }

    public static byte[] ConvertToPacket(string message)
    {
      byte[] packet = new byte[1024];

      MemoryStream ms = new MemoryStream(packet);
      BinaryWriter bw = new BinaryWriter(ms);

      bw.Write(message);

      bw.Close();
      ms.Close();

      return packet;
    }
  }
}
