Esempio n. 1
0
        public void DoTest()
        {
            byte[]     dat = Encoding.UTF8.GetBytes("测试");
            EaseString str = new EaseString {
                ESP_Length = (ushort)dat.Length, ESP_Data = dat
            };

            //Console.WriteLine("{0}={1}", str.ESP_Length, dat.ESP_Length);

            byte[] networkBytes = str.GetNetworkBytes();
            //Console.WriteLine("Len: {1}, Network Bytes: {0}", BitConverter.ToString(networkBytes), networkBytes.ESP_Length);
            //Console.WriteLine("Total:{0}\r\n{1}", networkBytes.ESP_Length, networkBytes.GetHexViewString());

            EaseString   str2 = new EaseString();
            MemoryStream ms   = new MemoryStream(networkBytes);

            ms.Position = 0;

            if (!HasImplementDataBind)
            {
                str2.BindFromNetworkStream(ms, 0, false);
            }
            else
            {
                str2.BindMappingWithStream(ms);
            }

            byte[] bytes2cmp = str2.GetNetworkBytes();
            //Console.WriteLine("Cmp Total:{0}\r\n{1}", bytes2cmp.ESP_Length, bytes2cmp.GetHexViewString());

            Assert.That(str.ESP_Length == str2.ESP_Length);
            Assert.That(SpecUtil.AreEqual(str.ESP_Data, str2.ESP_Data));
            Assert.That(str.Equals(str2));
        }
Esempio n. 2
0
        /// <summary>
        /// 创建整个包数据(包含应用数据)
        /// </summary>
        /// <param name="method">当前操作类型</param>
        /// <param name="command">当前操作命令</param>
        /// <param name="appBytes">整个数据业务数据</param>
        /// <param name="insertAppLen">是否在业务数据前插入4字节的数据长度</param>
        /// <returns></returns>
        public byte[] BuildWholePackageBytes(CommandType method, EaseString command, byte[] appBytes, bool insertAppLen)
        {
            byte[] cmdBytes   = command.GetNetworkBytes();
            int    cmdByteLen = cmdBytes.Length;
            long   totalLen   = 1L + (long)cmdByteLen
                                + ((insertAppLen) ? 4L : 0L)
                                + appBytes.LongLength;

            byte[] retBytes = new byte[totalLen];
            retBytes[0] = (byte)method;

            //命令数据
            Buffer.BlockCopy(cmdBytes, 0, retBytes, 1, cmdByteLen);

            //应用数据长度
            if (insertAppLen)
            {
                cmdBytes = BitConverter.GetBytes(appBytes.Length).ReverseBytes();
                Buffer.BlockCopy(cmdBytes, 0, retBytes, 1 + cmdByteLen, cmdBytes.Length);
            }

            //应用数据
            Buffer.BlockCopy(appBytes, 0, retBytes,
                             (1 + cmdByteLen + ((insertAppLen) ? 4 : 0)),
                             appBytes.Length);

            return(retBytes);
        }
Esempio n. 3
0
 /// <summary>
 /// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>.
 /// </summary>
 /// <param name="obj">The <see cref="T:System.Object"/> to compare with the current <see cref="T:System.Object"/>.</param>
 /// <returns>
 /// true if the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>; otherwise, false.
 /// </returns>
 /// <exception cref="T:System.NullReferenceException">
 /// The <paramref name="obj"/> parameter is null.
 /// </exception>
 public override bool Equals(object obj)
 {
     if (obj != null && obj.GetType() == this.GetType())
     {
         EaseString target = (EaseString)obj;
         return(target.ESP_Length == this.ESP_Length &&
                SpecUtil.AreEqual(target.ESP_Data, this.ESP_Data));
     }
     return(base.Equals(obj));
 }