예제 #1
0
        public static ulong Decompress(byte[] inputBytes,
                                       int inputOffset,
                                       int inputCount,
                                       byte[] outputBytes,
                                       int outputOffset,
                                       int outputCount)
        {
            if (inputBytes == null)
            {
                throw new ArgumentNullException("inputBytes");
            }

            if (inputOffset < 0 || inputOffset >= inputBytes.Length)
            {
                throw new ArgumentOutOfRangeException("inputOffset");
            }

            if (inputCount <= 0 || inputOffset + inputCount > inputBytes.Length)
            {
                throw new ArgumentOutOfRangeException("inputCount");
            }

            if (outputBytes == null)
            {
                throw new ArgumentNullException("outputBytes");
            }

            if (outputOffset < 0 || outputOffset >= outputBytes.Length)
            {
                throw new ArgumentOutOfRangeException("outputOffset");
            }

            if (outputCount <= 0 || outputOffset + outputCount > outputBytes.Length)
            {
                throw new ArgumentOutOfRangeException("outputCount");
            }

            ulong result;
            var   outputHandle  = GCHandle.Alloc(outputBytes, GCHandleType.Pinned);
            var   outputAddress = outputHandle.AddrOfPinnedObject() + outputOffset;
            var   inputHandle   = GCHandle.Alloc(inputBytes, GCHandleType.Pinned);
            var   inputAddress  = inputHandle.AddrOfPinnedObject() + inputOffset;

            result = _Is64Bit == true
                         ? ZstdNative64.Decompress(outputAddress, (ulong)outputCount, inputAddress, (ulong)inputCount)
                         : ZstdNative32.Decompress(outputAddress, (uint)outputCount, inputAddress, (uint)inputCount);

            inputHandle.Free();
            outputHandle.Free();
            return(result);
        }