Ejemplo n.º 1
0
        public unsafe static bool Decompress(byte[] inBuf, int inOffset, int inLength, byte[] outBuf, int outOffset, int expectedDecompressedLength)
        {
            if (expectedDecompressedLength == inLength)
            {
                Array.Copy(inBuf, inOffset, outBuf, outOffset, inLength);
                return(true);
            }
            int num = expectedDecompressedLength;

            fixed(byte *ptr = inBuf)
            {
                fixed(byte *ptr2 = outBuf)
                {
                    if (Xpress.EcDecompressEx(new IntPtr((void *)((byte *)ptr + inOffset)), inLength, new IntPtr((void *)((byte *)ptr2 + outOffset)), ref num) == 0)
                    {
                        bool result;
                        if (num != expectedDecompressedLength)
                        {
                            result = false;
                        }
                        else
                        {
                            result = true;
                        }
                        return(result);
                    }
                }
            }

            return(false);
        }
        protected void WriteXpressBlock(byte[] buf, int offset, int length)
        {
            int num;

            Xpress.Compress(buf, offset, length, this.CompressBuf, 5, 65536, out num);
            this.CompressBuf[0] = 2;
            int    num2 = 1;
            ushort val  = (ushort)(num - 1);

            Serialization.SerializeUInt16(this.CompressBuf, ref num2, val);
            val = (ushort)(length - 1);
            Serialization.SerializeUInt16(this.CompressBuf, ref num2, val);
            this.m_tcpChannel.Write(this.CompressBuf, 0, 5 + num);
        }
        private int ReadXpressBlock(byte[] buf, int off, int len)
        {
            if (this.m_xpressReadBuf == null)
            {
                this.m_xpressReadBuf = new byte[65536];
            }
            this.ReadChunk(this.m_readPacketHeaderBuf, 0, 4);
            ushort num  = BitConverter.ToUInt16(this.m_readPacketHeaderBuf, 0);
            int    num2 = (int)(num + 1);

            num = BitConverter.ToUInt16(this.m_readPacketHeaderBuf, 2);
            int num3 = (int)(num + 1);

            this.ReadChunk(this.m_xpressReadBuf, 0, num2);
            bool flag;

            if (num3 <= len)
            {
                flag = Xpress.Decompress(this.m_xpressReadBuf, 0, num2, buf, off, num3);
            }
            else
            {
                if (this.m_decompressBuf == null)
                {
                    this.m_decompressBuf = new byte[65536];
                }
                flag = Xpress.Decompress(this.m_xpressReadBuf, 0, num2, this.m_decompressBuf, 0, num3);
            }
            if (!flag)
            {
                NetworkPackagingLayer.Tracer.TraceError((long)this.GetHashCode(), "Decompression failed");
                throw new NetworkCorruptDataException(this.PartnerNodeName);
            }
            this.TotalDecompressedBytesReceived += (long)num3;
            this.TotalCompressedBytesReceived   += (long)num2;
            if (num3 <= len)
            {
                this.m_bytesRemainingToReadInCurrentBlock = 0;
                return(num3);
            }
            this.m_decompressBufContentLen            = num3;
            this.m_bytesRemainingToReadInCurrentBlock = num3 - len;
            Array.Copy(this.m_decompressBuf, 0, buf, off, len);
            NetworkPackagingLayer.Tracer.TraceError <int, int>((long)this.GetHashCode(), "NetPkg.ReadXpressBlock: Had to buffer 0x{0:X} uncompressed bytes for the next fetch since only 0x{1:X} were requested.", this.m_bytesRemainingToReadInCurrentBlock, len);
            return(len);
        }
Ejemplo n.º 4
0
        public unsafe static bool Compress(byte[] inBuf, int inOffset, int inLength, byte[] outBuf, int outOffset, int maxOutLength, out int compressedSize)
        {
            Dependencies.AssertRtl(outBuf.Length >= outOffset + maxOutLength, "BufferOverflow: Offset({0}) + Len({1}) exceeds buffer length({2})", new object[]
            {
                outOffset,
                maxOutLength,
                outBuf.Length
            });
            compressedSize = maxOutLength;
            fixed(byte *ptr = inBuf)
            {
                fixed(byte *ptr2 = outBuf)
                {
                    if (Xpress.EcCompressEx(new IntPtr((void *)((byte *)ptr + inOffset)), inLength, new IntPtr((void *)((byte *)ptr2 + outOffset)), ref compressedSize) == 0 && compressedSize < inLength)
                    {
                        return(true);
                    }
                }
            }

            compressedSize = inLength;
            Array.Copy(inBuf, inOffset, outBuf, outOffset, inLength);
            return(false);
        }
        public static int SerializeToBuffer(JET_EMITDATACTX emitContext, byte[] logdata, int cblogdata, byte[] targetBuffer, int targetBufferOffsetToStart, out int totalCompressedSize)
        {
            NetworkChannelPacket networkChannelPacket = new NetworkChannelPacket(targetBuffer, targetBufferOffsetToStart);

            networkChannelPacket.GrowthDisabled = true;
            int num = BlockModeCompressedDataMsg.CalculateBlockCount(cblogdata);

            int[] array = new int[num];
            int   num2  = 73 + 4 * num;
            int   num3  = num2 + targetBufferOffsetToStart;
            int   num4  = 0;

            totalCompressedSize = 0;
            int num5 = cblogdata;

            for (int i = 0; i < num; i++)
            {
                int num6 = Math.Min(num5, 65536);
                Xpress.Compress(logdata, num4, num6, targetBuffer, num3, num6, out array[i]);
                num4 += num6;
                num3 += array[i];
                totalCompressedSize += array[i];
                num5 -= num6;
            }
            networkChannelPacket.Append(1);
            int val = num2 - 5 + totalCompressedSize;

            networkChannelPacket.Append(val);
            val = 1145261378;
            networkChannelPacket.Append(val);
            val = num2 - 5;
            networkChannelPacket.Append(val);
            DateTime utcNow = DateTime.UtcNow;

            networkChannelPacket.Append(utcNow);
            long val2 = 0L;

            networkChannelPacket.Append(val2);
            val2 = Win32StopWatch.GetSystemPerformanceCounter();
            networkChannelPacket.Append(val2);
            networkChannelPacket.Append(cblogdata);
            val = emitContext.dwVersion;
            networkChannelPacket.Append(val);
            val2 = (long)emitContext.qwSequenceNum;
            networkChannelPacket.Append(val2);
            val = (int)emitContext.grbitOperationalFlags;
            networkChannelPacket.Append(val);
            DateTime time = DateTime.SpecifyKind(emitContext.logtimeEmit, DateTimeKind.Utc);

            networkChannelPacket.Append(time);
            val = emitContext.lgposLogData.lGeneration;
            networkChannelPacket.Append(val);
            ushort val3 = (ushort)emitContext.lgposLogData.isec;

            networkChannelPacket.Append(val3);
            val3 = (ushort)emitContext.lgposLogData.ib;
            networkChannelPacket.Append(val3);
            for (int j = 0; j < num; j++)
            {
                networkChannelPacket.Append(array[j]);
            }
            return(num2 + totalCompressedSize);
        }