Пример #1
0
 /// <summary>Tops encoder and encodes content.</summary>
 /// <param name="encoder">Encoder.</param>
 /// <param name="source">Source buffer (used to top up from).</param>
 /// <param name="target">Target buffer (used to encode into)</param>
 /// <param name="forceEncode">Forces encoding even if encoder is not full.</param>
 /// <param name="allowCopy">Allows to copy bytes if compression was not possible.</param>
 /// <param name="loaded">Number of bytes loaded (topped up)</param>
 /// <param name="encoded">Number if bytes encoded or copied.
 /// Value is 0 if no encoding was done.</param>
 /// <returns>Action performed.</returns>
 public static unsafe EncoderAction TopupAndEncode(
     this ILZ4Encoder encoder,
     ReadOnlySpan <byte> source,
     Span <byte> target,
     bool forceEncode, bool allowCopy,
     out int loaded, out int encoded)
 {
     fixed(byte *sourceP = source)
     fixed(byte *targetP = target)
     return(encoder.TopupAndEncode(
                sourceP, source.Length,
                targetP, target.Length,
                forceEncode, allowCopy,
                out loaded, out encoded));
 }
Пример #2
0
 /// <summary>Tops encoder and encodes content.</summary>
 /// <param name="encoder">Encoder.</param>
 /// <param name="source">Source buffer (used to top up from).</param>
 /// <param name="sourceOffset">Offset within source buffer.</param>
 /// <param name="sourceLength">Source buffer length.</param>
 /// <param name="target">Target buffer (used to encode into)</param>
 /// <param name="targetOffset">Offset within target buffer.</param>
 /// <param name="targetLength">Target buffer length.</param>
 /// <param name="forceEncode">Forces encoding even if encoder is not full.</param>
 /// <param name="allowCopy">Allows to copy bytes if compression was not possible.</param>
 /// <param name="loaded">Number of bytes loaded (topped up)</param>
 /// <param name="encoded">Number if bytes encoded or copied.
 /// Value is 0 if no encoding was done.</param>
 /// <returns>Action performed.</returns>
 public static unsafe EncoderAction TopupAndEncode(
     this ILZ4Encoder encoder,
     byte[] source, int sourceOffset, int sourceLength,
     byte[] target, int targetOffset, int targetLength,
     bool forceEncode, bool allowCopy,
     out int loaded, out int encoded)
 {
     fixed(byte *sourceP = source)
     fixed(byte *targetP = target)
     return(encoder.TopupAndEncode(
                sourceP + sourceOffset, sourceLength,
                targetP + targetOffset, targetLength,
                forceEncode, allowCopy,
                out loaded, out encoded));
 }
Пример #3
0
        private BlockInfo TopupAndEncode(
            ReadOnlySpan <byte> buffer, ref int offset, ref int count)
        {
            var action = _encoder.TopupAndEncode(
                buffer.Slice(offset, count),
                _buffer.AsSpan(),
                false, true,
                out var loaded,
                out var encoded);

            _position += loaded;
            offset    += loaded;
            count     -= loaded;

            return(new BlockInfo(_buffer, action, encoded));
        }
Пример #4
0
		/// <see cref="Stream.Write(byte[], int, int)"/>
		public override void Write(byte[] buffer, int offset, int count)
		{
			if (_encoder == null)
				WriteFrame();

			while (count > 0)
			{
				EncoderAction action = _encoder.TopupAndEncode(
					buffer, offset, count,
					_buffer, 0, _buffer.Length,
					false, true,
					out int loaded,
					out int encoded);

				WriteBlock(encoded, action);

				offset += loaded;
				count -= loaded;
			}
		}
        /// <inheritdoc />
        public override void Write(byte[] buffer, int offset, int count)
        {
            if (_encoder == null)
            {
                WriteFrame();
            }

            while (count > 0)
            {
                var action = _encoder.TopupAndEncode(
                    buffer, offset, count,
                    _buffer, 0, _buffer.Length,
                    false, true,
                    out var loaded,
                    out var encoded);
                WriteBlock(encoded, action);

                _position += loaded;

                offset += loaded;
                count  -= loaded;
            }
        }
        private static void Write(BinaryWriter outputWriter, ILZ4Encoder encoder, byte[] inputBuffer, int bytes, byte[] outputBuffer)
        {
            var offset = 0;

            while (bytes > 0)
            {
                encoder.TopupAndEncode(
                    inputBuffer, offset, bytes,
                    outputBuffer, 0, outputBuffer.Length,
                    false, false,
                    out var loaded,
                    out var encoded);

                if (encoded > 0)
                {
                    outputWriter.Write(encoded);
                    outputWriter.Write(outputBuffer, 0, encoded);
                }

                bytes  -= loaded;
                offset += loaded;
            }
        }