
using System.IO;
using System.Text;

public interface IMessageHandler 
{
    /// <summary>
    /// 处理服务器发来的消息
    /// </summary>
    /// <param name="stream">消息正文</param>
    void Handle(MemoryStream stream);
}

public abstract class AMessageHandler : IMessageHandler
{
    public void Handle(MemoryStream stream)
    {
        string msg = Encoding.UTF8.GetString(stream.GetBuffer(), (int)stream.Position, (int)(stream.Length - stream.Position));
        Handle(msg);
    }

    protected abstract void Handle(string msg);
}
