﻿// Copyright (c) egmkang wang. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.


namespace SharpServer.SDK.Net
{
    using System;

    /// <summary>
    /// 客户端和服务器通讯的消息头(LittleEndian)
    /// 只有四个字节的长度, 其中高八位保留, 有效长度字段为低24bit
    /// </summary>
    public sealed class CSHead
    {
        public CSHead() { }
        public Int32 length;

        public Int32 RealLength()
        {
            return length & Constant.MSG_LEN_MASK;
        }

        public Boolean Compressed()
        {
            return (length & Constant.MSG_COMPRESS_FLAG) != 0;
        }

        public void Clear()
        {
            this.length = 0;
        }
    }

    /// <summary>
    /// 收到的客户端消息
    /// </summary>
    public struct CSMessage
    {
        public CSMessage(string msgName, byte[] buffer, long milliSeconds)
        {
            this.msgName = msgName;
            this.buffer = buffer;
            this.milliSeconds = milliSeconds;
        }
        public string msgName;     //消息名称
        public byte[] buffer;      //消息
        public long milliSeconds;  //收到消息的时间戳
    }
}
