public static bool TryCompress(ref SnappyByteBuffer data, int maxSizeInPercent)
        {
            var compressed       = SnappyByteBuffer.NewAsync(new byte[data.Length * (long)maxSizeInPercent / 100]);
            var compressedLength = Compress(compressed, data);

            if (compressedLength < 0)
            {
                return(false);
            }
            data = SnappyByteBuffer.NewAsync(compressed.Buffer, 0, compressedLength);
            return(true);
        }
Esempio n. 2
0
        public static SnappyByteBuffer Decompress(SnappyByteBuffer compressedBytes)
        {
            int ofs;
            var decompressedSize = DecompressedSize(compressedBytes, out ofs);

            if (decompressedSize < 0)
            {
                throw new InvalidDataException();
            }
            var dst    = new byte[decompressedSize];
            var dstBuf = SnappyByteBuffer.NewAsync(dst);

            if (!DecompressRaw(dstBuf, SnappyByteBuffer.NewSync(compressedBytes.Buffer, compressedBytes.Offset + ofs, compressedBytes.Length - ofs)))
            {
                throw new InvalidDataException();
            }
            return(dstBuf);
        }