Пример #1
0
 protected override void OnReceived(byte[] content, int length)
 {
     this._lastReceivedTime = Time.realtimeSinceStartup;
     if (Pandora.Instance.IsDebug)
     {
         Logger.Log("收到ATM上报回包: " + Zlib.Decompress(content, length));
     }
 }
Пример #2
0
        public static byte[] Decompress(byte[] array, int offset, int count)
        {
            if (array == null)
            {
                throw new ArgumentNullException("array");
            }
            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException("offset");
            }
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException("count");
            }
            if (array.Length - offset < count)
            {
                throw new ArgumentException("Invalid argument offset count");
            }
            int num  = 2;
            int num2 = 4;

            if (Zlib.CheckZlibHead(array, offset, count) != 0)
            {
                throw new Exception("invalid zlib head");
            }
            MemoryStream memoryStream = new MemoryStream();

            memoryStream.Write(array, offset + num, count - num - num2);
            memoryStream.Seek(0L, SeekOrigin.Begin);
            MemoryStream memoryStream2 = new MemoryStream();

            byte[] result;
            using (DeflateStream deflateStream = new DeflateStream(memoryStream, CompressionMode.Decompress, true))
            {
                while (true)
                {
                    int num3 = deflateStream.Read(Zlib._decompressBuffer, 0, Zlib._decompressBuffer.Length);
                    if (num3 <= 0)
                    {
                        break;
                    }
                    memoryStream2.Write(Zlib._decompressBuffer, 0, num3);
                }
                memoryStream2.Seek(0L, SeekOrigin.Begin);
                byte[] array2 = memoryStream2.ToArray();
                if (Zlib.CheckZlibTail(array, offset, count, array2) != 0)
                {
                    throw new Exception("invalid zlib tail");
                }
                result = array2;
            }
            return(result);
        }
Пример #3
0
        private static int CheckZlibTail(byte[] array, int offset, int count, byte[] uncompressData)
        {
            ulong num = 1uL;

            num = Zlib.Adler32(num, uncompressData);
            byte[] bytes = BitConverter.GetBytes((uint)num);
            Array.Reverse(bytes);
            for (int i = 0; i < 4; i++)
            {
                if (array[offset + count - 1 - i] != bytes[3 - i])
                {
                    return(-1);
                }
            }
            return(0);
        }
Пример #4
0
        public static byte[] Compress(byte[] array, int offset, int count)
        {
            if (array == null)
            {
                throw new ArgumentNullException("array");
            }
            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException("offset");
            }
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException("count");
            }
            if (array.Length - offset < count)
            {
                throw new ArgumentException("Invalid argument offset count");
            }
            MemoryStream memoryStream = new MemoryStream();

            using (DeflateStream deflateStream = new DeflateStream(memoryStream, CompressionMode.Compress, true))
            {
                deflateStream.Write(array, offset, count);
            }
            byte[] array2 = new byte[memoryStream.Length];
            memoryStream.Seek(0L, SeekOrigin.Begin);
            memoryStream.Read(array2, 0, array2.Length);
            memoryStream.Dispose();
            ulong num = 1uL;

            num = Zlib.Adler32(num, array);
            byte[] array3 = new byte[]
            {
                120,
                1
            };
            byte[] bytes = BitConverter.GetBytes((uint)num);
            Array.Reverse(bytes);
            byte[] array4 = new byte[array3.Length + array2.Length + bytes.Length];
            array3.CopyTo(array4, 0);
            array2.CopyTo(array4, array3.Length);
            bytes.CopyTo(array4, array3.Length + array2.Length);
            return(array4);
        }
Пример #5
0
        protected override void OnReceived(byte[] content, int length)
        {
            string text = Zlib.Decompress(content, length);

            if (Pandora.Instance.IsDebug)
            {
                Logger.Log("Broker 收到回包: ");
                Logger.Log(text);
            }
            Dictionary <string, object> dictionary = Json.Deserialize(text) as Dictionary <string, object>;
            int  num       = (int)((long)dictionary["type"]);
            int  commandId = (int)((long)dictionary["cmd_id"]);
            uint callId    = (uint)((long)dictionary["seq_id"]);

            if (num == 2)
            {
                this.HandlePullMessage(callId, commandId, dictionary["body"] as string);
            }
            else if (num == 1)
            {
                this.HandlePushMessage(callId, commandId, dictionary["body"] as string);
            }
        }
Пример #6
0
 public static string Decompress(byte[] array, int length)
 {
     byte[] bytes = Zlib.Decompress(array, 0, length);
     return(Encoding.UTF8.GetString(bytes));
 }
Пример #7
0
 public static byte[] Compress(string content)
 {
     byte[] bytes = Encoding.UTF8.GetBytes(content);
     return(Zlib.Compress(bytes, 0, bytes.Length));
 }