Exemplo n.º 1
0
 /// <summary>
 /// Drains decoder by reading all bytes which are ready.
 /// </summary>
 /// <param name="decoder">The decoder instance.</param>
 /// <param name="target">Target buffer.</param>
 /// <param name="targetOffset">Offset within target buffer.</param>
 /// <param name="offset">Offset in decoder relatively to decoder's head. This should be a negative value.</param>
 /// <param name="length">Number of bytes.</param>
 public static unsafe void Drain(this ILZ4Decoder decoder, byte[] target, int targetOffset, int offset, int length)
 {
     fixed(byte *targetPtr = target)
     {
         decoder.Drain(targetPtr + targetOffset, offset, length);
     }
 }
Exemplo n.º 2
0
 /// <summary>Drains decoder by reading all bytes which are ready.</summary>
 /// <param name="decoder">Decoder.</param>
 /// <param name="target">Target buffer.</param>
 /// <param name="offset">Offset in decoder relatively to decoder's head.
 /// Please note, it should be negative value.</param>
 /// <param name="length">Number of bytes.</param>
 public static unsafe void Drain(
     this ILZ4Decoder decoder,
     Span <byte> target,
     int offset, int length)
 {
     fixed(byte *targetP = target)
     decoder.Drain(targetP, offset, length);
 }
 public static unsafe void Drain(
     this ILZ4Decoder decoder,
     byte[] target, int targetIndex,
     int offset, int length)
 {
     fixed(byte *targetP = target)
     decoder.Drain(targetP + targetIndex, offset, length);
 }
Exemplo n.º 4
0
		private bool ReadDecoded(byte[] buffer, ref int offset, ref int count, ref int read)
		{
			if (_decoded <= 0)
				return true;

			int length = Math.Min(count, _decoded);
			_decoder.Drain(buffer, offset, -_decoded, length);
			_position += length;
			_decoded -= length;
			offset += length;
			count -= length;
			read += length;

			return _interactive;
		}
        private bool Drain(Span <byte> buffer, ref int offset, ref int count, ref int read)
        {
            if (_decoded <= 0)
            {
                return(true);
            }

            var length = Math.Min(count, _decoded);

            _decoder.Drain(buffer.Slice(offset), -_decoded, length);
            _position += length;
            _decoded  -= length;
            offset    += length;
            count     -= length;
            read      += length;

            return(_interactive);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Decodes data and immediately drains it into target buffer.
        /// </summary>
        /// <param name="decoder">The decoder instance.</param>
        /// <param name="source">Source buffer (with compressed data, to be decoded).</param>
        /// <param name="sourceLength">Source buffer length.</param>
        /// <param name="target">Target buffer (to drained into).</param>
        /// <param name="targetLength">Target buffer length.</param>
        /// <param name="decoded">Number of bytes actually decoded.</param>
        /// <returns>
        /// `true` if the decoder was drained; otherwise, `false`.
        /// </returns>
        public static unsafe bool DecodeAndDrain(this ILZ4Decoder decoder, byte *source, int sourceLength, byte *target, int targetLength, out int decoded)
        {
            decoded = 0;

            if (sourceLength <= 0)
            {
                return(false);
            }

            decoded = decoder.Decode(source, sourceLength);
            if (decoded <= 0 || targetLength < decoded)
            {
                return(false);
            }

            decoder.Drain(target, -decoded, decoded);

            return(true);
        }