Ejemplo n.º 1
0
 void UnPack()
 {
     lock (_receiveBuffer)
     {
         var bytes = _receiveBuffer.ReadAllBytes();
         _receiveArray.Write(bytes);
         if (_receiveArray.Length == 0)
         {
             return;
         }
         try
         {
             _iPackage.Unpack(_receiveArray, _receiveQueue);
         }
         catch (Exception e)
         {
             throw new Exception(e.ToString());
         }
     }
 }
Ejemplo n.º 2
0
 void UnPack()
 {
     if (_receiveBuffer.Reader.GetHowManyCountCanReadInThisBlock() > 0) // if there have bytes to read
     {
         var bytes = _receiveBuffer.ReadAllBytes();
         _receiveArray.Write(bytes);
     }
     if (_receiveArray.Length == 0)
     {
         return;
     }
     lock (_receiveQueue)
     {
         try
         {
             _iPackage.Unpack(_receiveArray, _receiveQueue);
         }
         catch (Exception e)
         {
             throw new Exception(e.ToString());
         }
     }
 }
Ejemplo n.º 3
0
        public void Write <T>(T t)
        {
            var bytes = Serialize(t);

            ByteArray.Write(bytes, bytes.Length);
        }
Ejemplo n.º 4
0
 public void Write <T>(T paramValue)
 {
     if (paramValue is byte)
     {
         var tempVelue = (byte)Convert.ChangeType(paramValue, typeof(byte));
         ByteArray.Write(new[] { tempVelue }, 1);
     }
     else if (paramValue is bool)
     {
         var tempVelue = (bool)Convert.ChangeType(paramValue, typeof(bool));
         var tempBytes = BitConverter.GetBytes(tempVelue);
         ByteArray.Write(tempBytes, tempBytes.Length);
     }
     else if (paramValue is char)
     {
         var tempVelue = (char)Convert.ChangeType(paramValue, typeof(char));
         var tempBytes = BitConverter.GetBytes(tempVelue);
         ByteArray.Write(tempBytes, tempBytes.Length);
     }
     else if (paramValue is double)
     {
         var tempVelue = (double)Convert.ChangeType(paramValue, typeof(double));
         var tempBytes = BitConverter.GetBytes(tempVelue);
         ByteArray.Write(tempBytes, tempBytes.Length);
     }
     else if (paramValue is short)
     {
         var tempVelue = (short)Convert.ChangeType(paramValue, typeof(short));
         var tempBytes = BitConverter.GetBytes(tempVelue);
         ByteArray.Write(tempBytes, tempBytes.Length);
     }
     else if (paramValue is int)
     {
         var tempVelue = (int)Convert.ChangeType(paramValue, typeof(int));
         var tempBytes = BitConverter.GetBytes(tempVelue);
         ByteArray.Write(tempBytes, tempBytes.Length);
     }
     else if (paramValue is long)
     {
         var tempVelue = (long)Convert.ChangeType(paramValue, typeof(long));
         var tempBytes = BitConverter.GetBytes(tempVelue);
         ByteArray.Write(tempBytes, tempBytes.Length);
     }
     else if (paramValue is float)
     {
         var tempVelue = (float)Convert.ChangeType(paramValue, typeof(float));
         var tempBytes = BitConverter.GetBytes(tempVelue);
         ByteArray.Write(tempBytes, tempBytes.Length);
     }
     else if (paramValue is ushort)
     {
         var tempVelue = (ushort)Convert.ChangeType(paramValue, typeof(ushort));
         var tempBytes = BitConverter.GetBytes(tempVelue);
         ByteArray.Write(tempBytes, tempBytes.Length);
     }
     else if (paramValue is uint)
     {
         var tempVelue = (uint)Convert.ChangeType(paramValue, typeof(uint));
         var tempBytes = BitConverter.GetBytes(tempVelue);
         ByteArray.Write(tempBytes, tempBytes.Length);
     }
     else if (paramValue is ulong)
     {
         var tempVelue = (ulong)Convert.ChangeType(paramValue, typeof(ulong));
         var tempBytes = BitConverter.GetBytes(tempVelue);
         ByteArray.Write(tempBytes, tempBytes.Length);
     }
     else if (paramValue is string)
     {
         var tempVelue = (string)Convert.ChangeType(paramValue, typeof(string));
         var tempBytes = Encoding.UTF8.GetBytes(tempVelue);
         ByteArray.Write(tempBytes, tempBytes.Length);
     }
     else
     {
         throw new Exception("Can not find type" + typeof(T));
     }
 }