示例#1
0
        protected override bool ParseBody(Packet _packet, ArraySegment <byte> datas, out Int32 giveupCount)
        {
            ZTProtocolPacket packet = _packet as ZTProtocolPacket;

            if (packet == null)
            {
                giveupCount = datas.Count;
                return(false);
            }
            giveupCount = 0;
            bool result = false;

            if ((datas.Count + packet.Count) >= packet.ContentLength)
            {
                giveupCount = packet.ContentLength - (Int32)packet.Count;
                result      = true;
            }
            else
            {
                giveupCount = datas.Count;
                result      = false;
            }
            //保存数据
            packet.Write(new ArraySegment <byte>(datas.Array, datas.Offset, giveupCount));
            return(result);
        }
示例#2
0
        /// <summary>
        /// 解析头部
        /// </summary>
        /// <param name="packet"></param>
        /// <param name="datas"></param>
        /// <param name="count"></param>
        /// <param name="giveupCount"></param>
        /// <returns></returns>
        protected override bool ParseHeader(Packet _packet, ArraySegment <byte> datas)
        {
            ZTProtocolPacket packet = _packet as ZTProtocolPacket;

            if (packet == null)
            {
                return(false);
            }


            if (datas.Array[datas.Offset] != 0x0d || datas.Array[datas.Offset + 1] != 0x0a)
            {
                return(false);
            }

            packet.ContentLength = NetworkBitConverter.ToInt32(
                datas.Array[datas.Offset + 2],
                datas.Array[datas.Offset + 3],
                datas.Array[datas.Offset + 4],
                datas.Array[datas.Offset + 5]);
            return(true);
        }