Пример #1
0
        /// <summary>Compresses input buffer into self-contained package.</summary>
        /// <param name="source">Input buffer.</param>
        /// <param name="sourceLength">Length of input data.</param>
        /// <param name="level">Compression level.</param>
        /// <returns>Output buffer.</returns>
        public static unsafe byte[] Pickle(
            byte *source, int sourceLength, LZ4Level level = LZ4Level.L00_FAST)
        {
            if (sourceLength <= 0)
            {
                return(Mem.Empty);
            }

            var targetLength = sourceLength - 1;
            var target       = (byte *)Mem.Alloc(sourceLength);

            try
            {
                var encodedLength = LZ4Codec.Encode(
                    source, sourceLength, target, targetLength, level);

                return(encodedLength <= 0
                    ? PickleV0(source, sourceLength, sourceLength)
                    : PickleV0(target, encodedLength, sourceLength));
            }
            finally
            {
                Mem.Free(target);
            }
        }
Пример #2
0
 /// <inheritdoc />
 protected override void ReleaseUnmanaged()
 {
     base.ReleaseUnmanaged();
     Mem.Free(_outputBuffer);
 }
Пример #3
0
 /// <inheritdoc />
 protected override void ReleaseUnmanaged()
 {
     base.ReleaseUnmanaged();
     Mem.Free(_context);
 }