Exemplo n.º 1
0
 /// <summary>
 /// Encodes all bytes currently stored in the encoder into target buffer.
 /// </summary>
 /// <param name="encoder">The encoder instance.</param>
 /// <param name="target">The target buffer.</param>
 /// <param name="offset">Offset in target buffer.</param>
 /// <param name="length">Length of target buffer.</param>
 /// <param name="allowCopy">If `true`, copying bytes is allowed.</param>
 /// <returns>
 /// Number of bytes encoded. If bytes were copied than this value is negative.
 /// </returns>
 public static unsafe int Encode(this ILZ4Encoder encoder, byte[] target, int offset, int length, bool allowCopy)
 {
     fixed(byte *targetPtr = target)
     {
         return(encoder.Encode(targetPtr + offset, length, allowCopy));
     }
 }
Exemplo n.º 2
0
        private static unsafe EncoderAction FlushAndEncode(
            this ILZ4Encoder encoder,
            byte *target, int targetLength,
            bool forceEncode, bool allowCopy,
            int loaded, out int encoded)
        {
            encoded = 0;

            var blockSize  = encoder.BlockSize;
            var bytesReady = encoder.BytesReady;

            if (bytesReady < (forceEncode ? 1 : blockSize))
            {
                return(loaded > 0 ? EncoderAction.Loaded : EncoderAction.None);
            }

            encoded = encoder.Encode(target, targetLength, allowCopy);
            if (allowCopy && encoded < 0)
            {
                encoded = -encoded;
                return(EncoderAction.Copied);
            }
            else
            {
                return(EncoderAction.Encoded);
            }
        }
        public static unsafe bool Encode(
            this ILZ4Encoder encoder, ref byte *target, int length, bool allowCopy)
        {
            var encoded = encoder.Encode(target, length, allowCopy);

            target += encoded;
            return(encoded != 0);
        }
        public static bool Encode(
            this ILZ4Encoder encoder, byte[] target, ref int index, int length, bool allowCopy)
        {
            var encoded = encoder.Encode(target, index, length, allowCopy);

            index += encoded;
            return(encoded != 0);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Encodes all bytes currently stored in encoder into target buffer.
        /// </summary>
        /// <param name="encoder">The encoder instance.</param>
        /// <param name="target">Target buffer.</param>
        /// <param name="offset">Offset in target buffer. Will be updated after operation.</param>
        /// <param name="length">Length of target buffer.</param>
        /// <param name="allowCopy">If `true`, copying bytes is allowed.</param>
        /// <returns>
        /// Result of this action. Bytes can be copied (<see cref="EncoderAction.Copied"/>),
        /// encoded (<see cref="EncoderAction.Encoded"/>) or nothing could have
        /// happened (<see cref="EncoderAction.None"/>).
        /// </returns>
        public static EncoderAction Encode(this ILZ4Encoder encoder, byte[] target, ref int offset, int length, bool allowCopy)
        {
            int encoded = encoder.Encode(target, offset, length, allowCopy);

            offset += Math.Abs(encoded);
            return(encoded == 0 ? EncoderAction.None :
                   encoded < 0 ? EncoderAction.Copied :
                   EncoderAction.Encoded);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Encodes all bytes currently stored in encoder into target buffer.
        /// </summary>
        /// <param name="encoder">The encoder instance.</param>
        /// <param name="target">Target buffer. Will be updated after operation.</param>
        /// <param name="length">Length of buffer.</param>
        /// <param name="allowCopy">If `true`, copying bytes is allowed.</param>
        /// <returns>
        /// Result of this action. Bytes can be copied (<see cref="EncoderAction.Copied"/>),
        /// encoded (<see cref="EncoderAction.Encoded"/>) or nothing could have
        /// happened (<see cref="EncoderAction.None"/>).
        /// </returns>
        public static unsafe EncoderAction Encode(this ILZ4Encoder encoder, ref byte *target, int length, bool allowCopy)
        {
            int encoded = encoder.Encode(target, length, allowCopy);

            target += Math.Abs(encoded);
            return(encoded == 0 ? EncoderAction.None :
                   encoded < 0 ? EncoderAction.Copied :
                   EncoderAction.Encoded);
        }
        private static void Flush(BinaryWriter outputWriter, ILZ4Encoder encoder, byte[] outputBuffer)
        {
            if (encoder.BytesReady <= 0)
            {
                return;
            }

            var encoded = encoder.Encode(outputBuffer, 0, outputBuffer.Length, false);

            outputWriter.Write(encoded);
            outputWriter.Write(outputBuffer, 0, encoded);
        }
 public static unsafe int Encode(
     this ILZ4Encoder encoder, byte[] target, int index, int length, bool allowCopy)
 {
     fixed(byte *targetP = target)
     return(encoder.Encode(targetP + index, length, allowCopy));
 }
Exemplo n.º 9
0
 public unsafe int Encode(byte *target, int length, bool allowCopy) =>
 _encoder.Encode(target, length, allowCopy);