Пример #1
0
        public void DismantleData()
        {
            var headBytes = new byte[sizeof(short)];

            Buffer.BlockCopy(DataBuff, 0, headBytes, 0, headBytes.Length);
            var length = BitConverter.ToInt16(headBytes, 0);
            //var length = BitConverter.ToInt16(DataBuff, 0);
            var len = currentDataLength - length;

            if (len < 0)
            {
                return;
            }
            if (length <= 0 || length > DataBuff.Length)
            {
                Array.Clear(DataBuff, 0, DataBuff.Length);
                currentDataLength = 0;
                return;
            }
            byte[] msgData = new byte[length];
            Array.Copy(DataBuff, headBytes.Length, msgData, 0, length);

            MessageRespondEvent?.Invoke(msgData);

            Array.Clear(DataBuff, 0, length);
            if (len > 0)
            {
                byte[] DataBuffCopy = (byte[])DataBuff.Clone();
                Array.Clear(DataBuff, length, len);
                Array.Copy(DataBuffCopy, length, DataBuff, 0, len);
            }
            currentDataLength = len;
        }
Пример #2
0
 private void ProcessReceivedMessage()
 {
     while (true)
     {
         var message = receivedMessageQueue.Take();
         if (message != null)
         {
             MessageRespondEvent?.Invoke(message);
         }
     }
 }